mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
7adb8133f5
- missing bit of 989499 and some other files (23b0597ba6) - Bug 1233666 - Remove hacks for getting frame pointer for x86/x64 gcc. r=glandium (bfe8f59916) - Bug 1176266: In TimeStamp_posix.cpp, check for XP_LINUX instead of LINUX, and add missing #include, to allow strrchr usage. r=BenWa (56c725cffa) - Bug 1167230 - Don't pack ProfileEntry on ARM. r=shu (89f880e0cb) - Bug 1209779 - Ensure that all null elements are written when streaming profiler JSON; r=shu (2bae5addc6) - missing bit of Bug 1141712 - Make LUL (55f1276545) - Bug 1061800 - Add breakpad ids to profiler in Linux. r=BenWa (994fd1a941) - Bug 829621 - Compute the breakpad-id for OS X. r=BenWa. (e129580174) - missing of Bug 938157 - Lightweight CFI/EXIDX (b355dc3140) - Bug 1193838 - Allow ProfileGatherer to gather profiles from exiting processes. r=BenWa (5ab1a6a3c9) - align some missing stuff (5ebecd2364) - align some missing stuff (b8ff7aa361) - Bug 1164315 - Update key fingerprint for bitbucket.org; r=me (c1a3fbd930) - Bug 1178955 - Refactor config path selection; r=smacleod (89552bb0ac) - Bug 1195445 - Update host key fingerprint for bugzilla.mozilla.org (3783541088) - Bug 1218903 - Update bmo fingerprint. r=fubar, a=Tomcat (5b836fc585) - Bug 1178955 - Print config path on failure; r=smacleod (f5499f3771) - Bug 1185113 - Support setting more secure file permissions; r=smacleod (7dbf6b22fd) - Bug 1184229 - Detect multiple version-control-tools repos in Mercurial config; r=smacleod (16c24072a9) - Bug 978514 - mach mercurial-setup: Use mqext from the version-control-tools repo (1fa5765e8a) - Bug 1178955 - Don't pass config paths to updater; r=smacleod (80fcb05121) - Bug 1197527 - Don't unnecessarily attempt to create extensions directory in MercurialUpdater; r=gps (9b049c3ff8) - Bug 1164812 - mach mercurial-setup: Always mark the v-c-t repo as needing update (bd631208bd) - Bug 1197527 - Always clone version-control-tools in MercurialSetupWizard; r=gps (6990e8f589) - Bug 1197527 - Consolidate obtaining hg path into mozversioncontrol.get_hg_path; r=gps (e0b029a8e9) - Bug 1200458 - Skip permission check for .hgrc on Windows in hgsetup wizard. r=gps DONTBUILD (cc5b0d6daf) - Bug 1168466 - Bump minimum Mercurial version; r=smacleod (7fde47cfbe) - Bug 1185113 - Clarify language around Bugzilla credentials; r=smacleod (9166fdfbf9) - Bug 1185112 - Don't prompt for Bugzilla username/password if cookies defined; r=smacleod (cd87c96823) - Bug 1188931 - Fix hgsetup wizard. r=gps (68a6b46be4) - Bug 1200461 - Prompt for Bugzilla API Key instead of password; r=smacleod (780fb5d85d) - Bug 1228580 - ./mach mercurial-setup should use ~ to set up extension paths, not my literal home directory. r=gps (7a0c839880) - Bug 1231192 - Mark Mercurial 3.5.2 as oldest non-legacy version; r=smacleod (8f69483333) - Bug 1231192 - Bump some minimum Mercurial version; r=smacleod (916c56a852) - Bug 1162093 - Add "push-to-try" from version-control-tools to the mercurial setup wizard prompt.;r=gps (d29c7cf63a) - Bug 1168466 - Prompt to install bundleclone extension; r=smacleod (780ce90a08) - Bug 1185557 - Print relevant config options; r=smacleod (2f3f7e0161) - Bug 1231192 - Support clonebundles feature; r=smacleod (dcba1ccd34) - Bug 1231192 - Offer to install hg wip; r=smacleod (c42ebce5c8) - Bug 1231192 - Only install host fingerprints if not running secure Python+hg; r=smacleod (3154a2497b) - Bug 1178955 - Error when semicolon comments are seen; r=smacleod (e1f7081bb6) - Bug 1231989 - Prompt to install hgwatchman extension; r=ahal (0eddf0c1c8) - Bug 1178955 - Print line number for parse errors; r=smacleod (5369468cf1) - Bug 1185557 - Only prompt to install progress on Mercurial <3.5; r=smacleod (401f362265) - Bug 1232747 - Check for ssl.SSLContext existence; r=dminor (d505b07c5c) - Bug 1144629 - UnicodeDecodeError in ./mach mercurial-setup. r=gps, r=glandium (611d3ec83e) - Bug 1216970 - Make the copying more obvious in ProfilerImpl::GetStacktrace. r=froydnj (085625e113) - Bug 1190466 - tools/rb/find-leakers.pl re-written in Python r=mccr8 (4bfdcad13e) - Bug 1116478 - Open web content handlers in the proper tab in e10s. r=billm (ff8e11f45e) - Bug 1213437 - Less data copying when handling structured clones in MessageManager, r=baku (c4e2a13253) - const-var (69d17f312d) - Bug 1203090 - Ensure we always use '/' as the starting path separator for the DOM path of the Directorys initially returned by HTMLInputElement.getFilesAndDirectories. r=baku (1325bbc40c) - Bug 1209975 - Stop using dom::Promise::MaybeRejectBrokenly() in GetDirectoryListingTask. r=baku (2106790950) - Bug 1209924 - Implement a general filtering mechanism for Directory::GetFilesAndDirectories, and add filtering of sensitive files/directories. r=baku (27b4a26262) - Force a repaint after DXGI device resets. (bug 1188019, r=bas) (09c999e6e5) - Bug 1163911 - Make responsive images block the document load event while the load task is queued. r=jst (0ee0e3db79) - Bug 1166138 - Make img srcset react to resize/viewport changes, r=jdm (91674519e6) - Bug 1194893 - Pref for default file upload directory. r=smaug (ec6d33d983) - bug 1116409: switch update server to sha2 cert; update in-tree pinning. r=rstrong,snorp,mfinkle,dkeeler (7c8f631f27) - bug 1116409: fix cert pinning on backup cert for aus5.mozilla.org. r=typofix (3c690cbc6d) - Bug 1167048 - Change default font for Thai script from serif to sans-serif. r=smontagu (15dc86c389) - Bug 1205570 - fix up font prefs for x-math lang group. r=heycam (03f1820752) - Bug 1071769: Use DrawTargetTiled on B2G. r=Bas (b80ce768f1) - fix misspatch of 1149343 (541dd7aac8) - Bug 1199766 - Disable ICE TCP SO gathering via user pref. r=bwc (80cdc9c662) - Bug 1187472 - only log UDP and TCP candidate gathering failures. r=bwc (bc3dcb02d0) - Bug 1190615 - Skip non-UDP STUN servers for UDP sockets. r=bwc (a2d1d914b5) - Bug 1187775 - skip host and reflexive ICE candidates if relay-only. r=bwc (7e2cba1685) - Bug 1185198 - use port 9 for TCP active candidates. r=bwc (0a89cb199d) - Bug 1177921 - Fix typo in STUN server name. r=drno (1ad43ced6b) - Bug 1178349 - Enable ice_unittests on desktop linux on CI. r=bwc (ce5ece8264) - Bug 1189041 - Add option to only gather addresses for default route. r=bwc (3651f2ff06) - Bug 1189040: add a whitelist for network interfaces to use with ICE/webrtc r=ekr (6f693af72c) - Bug 1189198 - don't start STUN transactions with a protocol mis-match. r=mtseng (a3b410e2a8) - Bug 1208096 - Handle various failure cases for TURN gathering better. r=drno (1d8e173448) - Bug 1211389 - Make absolutely sure the relay->srflx pointer doesn't dangle. r=drno (d59b0bf08d) - Bug 1215616: use base address for server rflx ICE candidates r=bwc (89d07331ac) - Bug 1207451 - removed framing from multi_tcp API. r=bwc (317f40f490) - Bug 1186590 - Part 1 - Enable interface prioritizer on all platforms. r=drno (036a69fdb3) - Bug 1194019 - New defaults for gather tests. r=bwc (8343ceab56) - Bug 1144933: Only check that remote candidate is loopback in TestLoopbackOnlySortOf. r=drno (1f53d824e4) - Bug 1186590 - Part 2 - Move hard-coded interface priority list into nrinterfaceprioritizer, and simplify some functions. r=drno (9f20fad21b) - Bug 1152137 - Part 1: Test case. r=ekr (6b50f06d90) - Bug 1152137 - Part 2: Remove attributes that could not be initted properly instead of just freeing them. r=ekr (ccdf81294a) - Bug 1200763 - Remove hard-coded STUN IP address from ice_unittest, and do a DNS lookup instead. r=drno (ae54a83363) - Bug 1208176 - Part 1: Add a couple of interface names. r=drno (b7ead0b476) - Bug 1208176 - Part 2: Add a one-sided trickle test case to ice_unittest. r=drno (ad6afedb1c) - Bug 1037618 - Relax candidate verification for TCP. r=bwc (0cad14c89e) - Bug 1208176 - Part 3: Be forgiving when we see prflx instead of host candidates in ice_unittest. r=drno (50bdec2ba3) - Bug 1035428: Re-register writeable callback after partially servicing the send queue. r=drno (2fdb7880fa) - Bug 1135753 - Mark some overridden virtual functions in WebRTC as MOZ_OVERRIDE; r=mt (97f451c97d) - Bug 950660: Part 4: Bridge TCPSocketChild to nr_socket r=bwc,jdm (654587b321) - Bug 971357: Log STUN responses at INFO instead of DEBUG. r=ekr (81b500df17) - Bug 1006809 - update triggered check behavior to RFC 5245. r+bwc r=mjf (31b718b5e5) - Bug 1208278 - improved STUN request timeout handling. r=bwc (cf470fb12f) - Bug 1142964 - Fix ICE tiebreaker on Windows. r=bwc (0d2fd78252) - Bug 1219557 - don't pair candidates from different reserved networks. r=mt r=bwc (24d3e5106c) - Bug 1220441 - Improve gather trickle ice unit tests. r=bwc r=mjf (96f76c6c8c) - Bug 1205421 - fix DNS resolution of STUN server in ice_unittest. r=bwc (5d5b153358) - Bug 1206465 - removed ice_ctx from TestStunTcpServer. r=bwc (9a0df03894) - ug 1008792 - Check for valid pointer before using. r=bwc (7660fd0a71) - Bug 1233101 - Use MOZ_LIKELY in js_new etc to help branch prediction; r=terrence (31fb244734) - Bug 1225565 - Fix module import cycle detection r=shu (370dc26ee8) - Bug 1225558 - Improve module error messages r=shu (83b6038bb3) - Bug 1225561 - Don't allow a module to export non-existent local bindings r=shu (41f065891a) - Bug 1233124 - Remove mis-named duplicate typedefs for rooted import and export entries r=terrence (17a60bdb39) - Bug 1208464 - Implement proposed ES7 functions Object.values and Object.entries. r=evilpie (615193d0fb) - Bug 1226549 - added assert check for matches pointer in for prevent null dereference. r=hv1989 (d321ad0385) - Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=jcoppeard (7c58b79a53) - Bug 1232446 - Re-enable method calls in SelfHosted code using new anti-content checks. (r=till) (ba7dc22ff8) - Bug 1232159 - Stop using pseudo-Uint32Array in SelfHosted code. (r=till) (c325f8ff58) - Bug 1226235 - Print file and line info for failing assert in self-hosted code. r=efaust (4a8d54d38b) - fix misspatch (fca2efc1f1) - Bug 1186003 - Switch automated builds to Gtk+3. r=mshal (658ad843b7) - Bug 1181342 - tooltool manifests and build-clang config for clang 3.6 r=rail (6264b4df68) - Bug 1181342 - Follow up to use the unpack feature of tooltool instead of setup.sh r=glandium (96bb3b2062) - Bug 1181255 - Mozconfigs for tsan builds. r=glandium (19250f4cc1) - Bug 1181255 - Get tsan builds on gtk3. r=glandium (e5ffd1c02f) - Bug 1187664 - Create a fontconfig cache so that Firefox doesn't have to do it itself when run on build automation. r=mshal (8ce567bd4c) - Bug 1188780 - Include debug symbols in gtk3 tooltool package. r=mshal (a5b573aa58) - Bug 1188780: remove setup.sh invocations, as they fail outside the mock environment; r=glandium a=RyanVM (058e306cac) - Bug 1178513 - Fix non-unified bustage. r=wchen (543d1e5497) - Bug 1162789 - Add a comment explaining why mForm is not set to null during unlink (eaa2a82048) - Bug 1189655 - Define MOZ_HAVE_CXX11_CONSTEXPR on VS2015 or later. r=Waldo (2d134e3b41) - Bug 1231758 - Fix bogus assertion in BCE for Annex B function assignment. (r=jorendorff) (701b2530b9) - Bug 1233100 - Ensure that derived constructor bad return value errors are thrown before leaving the containing block. (r=shu) (52f5bcf0a5) - Bug 1232022, 1232449 - Address forgotten review nits and fix bogus error message. (rs=Waldo) (dfd9d5e388) - Bug 1233121 - Refactor ObjectBox tracing r=terrence (876a140535) - Bug 1231647 - Check for duplicate exported let and const in modules r=shu (99f53ad443)
723 lines
24 KiB
C++
723 lines
24 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "vm/GlobalObject.h"
|
|
|
|
#include "jscntxt.h"
|
|
#include "jsdate.h"
|
|
#include "jsexn.h"
|
|
#include "jsfriendapi.h"
|
|
#include "jsmath.h"
|
|
#include "json.h"
|
|
#include "jsprototypes.h"
|
|
#include "jsweakmap.h"
|
|
|
|
#include "builtin/AtomicsObject.h"
|
|
#include "builtin/Eval.h"
|
|
#if EXPOSE_INTL_API
|
|
# include "builtin/Intl.h"
|
|
#endif
|
|
#include "builtin/MapObject.h"
|
|
#include "builtin/ModuleObject.h"
|
|
#include "builtin/Object.h"
|
|
#include "builtin/RegExp.h"
|
|
#include "builtin/SIMD.h"
|
|
#include "builtin/SymbolObject.h"
|
|
#include "builtin/TypedObject.h"
|
|
#include "builtin/WeakMapObject.h"
|
|
#include "builtin/WeakSetObject.h"
|
|
#include "vm/HelperThreads.h"
|
|
#include "vm/PIC.h"
|
|
#include "vm/RegExpStatics.h"
|
|
#include "vm/RegExpStaticsObject.h"
|
|
#include "vm/ScopeObject.h"
|
|
#include "vm/StopIterationObject.h"
|
|
|
|
#include "jscompartmentinlines.h"
|
|
#include "jsobjinlines.h"
|
|
#include "jsscriptinlines.h"
|
|
|
|
#include "vm/NativeObject-inl.h"
|
|
|
|
using namespace js;
|
|
|
|
struct ProtoTableEntry {
|
|
const Class* clasp;
|
|
ClassInitializerOp init;
|
|
};
|
|
|
|
namespace js {
|
|
|
|
#define DECLARE_PROTOTYPE_CLASS_INIT(name,code,init,clasp) \
|
|
extern JSObject* init(JSContext* cx, Handle<JSObject*> obj);
|
|
JS_FOR_EACH_PROTOTYPE(DECLARE_PROTOTYPE_CLASS_INIT)
|
|
#undef DECLARE_PROTOTYPE_CLASS_INIT
|
|
|
|
} // namespace js
|
|
|
|
JSObject*
|
|
js::InitViaClassSpec(JSContext* cx, Handle<JSObject*> obj)
|
|
{
|
|
MOZ_CRASH("InitViaClassSpec() should not be called.");
|
|
}
|
|
|
|
static const ProtoTableEntry protoTable[JSProto_LIMIT] = {
|
|
#define INIT_FUNC(name,code,init,clasp) { clasp, init },
|
|
#define INIT_FUNC_DUMMY(name,code,init,clasp) { nullptr, nullptr },
|
|
JS_FOR_PROTOTYPES(INIT_FUNC, INIT_FUNC_DUMMY)
|
|
#undef INIT_FUNC_DUMMY
|
|
#undef INIT_FUNC
|
|
};
|
|
|
|
JS_FRIEND_API(const js::Class*)
|
|
js::ProtoKeyToClass(JSProtoKey key)
|
|
{
|
|
MOZ_ASSERT(key < JSProto_LIMIT);
|
|
return protoTable[key].clasp;
|
|
}
|
|
|
|
// This method is not in the header file to avoid having to include
|
|
// TypedObject.h from GlobalObject.h. It is not generally perf
|
|
// sensitive.
|
|
TypedObjectModuleObject&
|
|
js::GlobalObject::getTypedObjectModule() const {
|
|
Value v = getConstructor(JSProto_TypedObject);
|
|
// only gets called from contexts where TypedObject must be initialized
|
|
MOZ_ASSERT(v.isObject());
|
|
return v.toObject().as<TypedObjectModuleObject>();
|
|
}
|
|
|
|
|
|
|
|
|
|
/* static */ bool
|
|
GlobalObject::ensureConstructor(JSContext* cx, Handle<GlobalObject*> global, JSProtoKey key)
|
|
{
|
|
if (global->isStandardClassResolved(key))
|
|
return true;
|
|
return resolveConstructor(cx, global, key);
|
|
}
|
|
|
|
/* static*/ bool
|
|
GlobalObject::resolveConstructor(JSContext* cx, Handle<GlobalObject*> global, JSProtoKey key)
|
|
{
|
|
MOZ_ASSERT(!global->isStandardClassResolved(key));
|
|
|
|
// There are two different kinds of initialization hooks. One of them is
|
|
// the class js::InitFoo hook, defined in a JSProtoKey-keyed table at the
|
|
// top of this file. The other lives in the ClassSpec for classes that
|
|
// define it. Classes may use one or the other, but not both.
|
|
ClassInitializerOp init = protoTable[key].init;
|
|
if (init == InitViaClassSpec)
|
|
init = nullptr;
|
|
|
|
const Class* clasp = ProtoKeyToClass(key);
|
|
if (!init && !clasp)
|
|
return true; // JSProto_Null or a compile-time-disabled feature.
|
|
|
|
// Some classes have no init routine, which means that they're disabled at
|
|
// compile-time. We could try to enforce that callers never pass such keys
|
|
// to resolveConstructor, but that would cramp the style of consumers like
|
|
// GlobalObject::initStandardClasses that want to just carpet-bomb-call
|
|
// ensureConstructor with every JSProtoKey. So it's easier to just handle
|
|
// it here.
|
|
bool haveSpec = clasp && clasp->spec.defined();
|
|
if (!init && !haveSpec)
|
|
return true;
|
|
|
|
// See if there's an old-style initialization hook.
|
|
if (init) {
|
|
MOZ_ASSERT(!haveSpec);
|
|
return init(cx, global);
|
|
}
|
|
|
|
//
|
|
// Ok, we're doing it with a class spec.
|
|
//
|
|
|
|
// We need to create the prototype first, and immediately stash it in the
|
|
// slot. This is so the following bootstrap ordering is possible:
|
|
// * Object.prototype
|
|
// * Function.prototype
|
|
// * Function
|
|
// * Object
|
|
//
|
|
// We get the above when Object is resolved before Function. If Function
|
|
// is resolved before Object, we'll end up re-entering resolveConstructor
|
|
// for Function, which is a problem. So if Function is being resolved before
|
|
// Object.prototype exists, we just resolve Object instead, since we know that
|
|
// Function will also be resolved before we return.
|
|
if (key == JSProto_Function && global->getPrototype(JSProto_Object).isUndefined())
|
|
return resolveConstructor(cx, global, JSProto_Object);
|
|
|
|
// We don't always have a prototype (i.e. Math and JSON). If we don't,
|
|
// |createPrototype|, |prototypeFunctions|, and |prototypeProperties|
|
|
// should all be null.
|
|
RootedObject proto(cx);
|
|
if (clasp->spec.createPrototypeHook()) {
|
|
proto = clasp->spec.createPrototypeHook()(cx, key);
|
|
if (!proto)
|
|
return false;
|
|
|
|
global->setPrototype(key, ObjectValue(*proto));
|
|
}
|
|
|
|
// Create the constructor.
|
|
RootedObject ctor(cx, clasp->spec.createConstructorHook()(cx, key));
|
|
if (!ctor)
|
|
return false;
|
|
|
|
RootedId id(cx, NameToId(ClassName(key, cx)));
|
|
if (clasp->spec.shouldDefineConstructor()) {
|
|
if (!global->addDataProperty(cx, id, constructorPropertySlot(key), 0))
|
|
return false;
|
|
}
|
|
|
|
global->setConstructor(key, ObjectValue(*ctor));
|
|
global->setConstructorPropertySlot(key, ObjectValue(*ctor));
|
|
|
|
// Define any specified functions and properties, unless we're a dependent
|
|
// standard class (in which case they live on the prototype).
|
|
if (!StandardClassIsDependent(key)) {
|
|
if (const JSFunctionSpec* funs = clasp->spec.prototypeFunctions()) {
|
|
if (!JS_DefineFunctions(cx, proto, funs, DontDefineLateProperties))
|
|
return false;
|
|
}
|
|
if (const JSPropertySpec* props = clasp->spec.prototypeProperties()) {
|
|
if (!JS_DefineProperties(cx, proto, props))
|
|
return false;
|
|
}
|
|
if (const JSFunctionSpec* funs = clasp->spec.constructorFunctions()) {
|
|
if (!JS_DefineFunctions(cx, ctor, funs, DontDefineLateProperties))
|
|
return false;
|
|
}
|
|
if (const JSPropertySpec* props = clasp->spec.constructorProperties()) {
|
|
if (!JS_DefineProperties(cx, ctor, props))
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// If the prototype exists, link it with the constructor.
|
|
if (proto && !LinkConstructorAndPrototype(cx, ctor, proto))
|
|
return false;
|
|
|
|
// Call the post-initialization hook, if provided.
|
|
if (clasp->spec.finishInitHook() && !clasp->spec.finishInitHook()(cx, ctor, proto))
|
|
return false;
|
|
|
|
if (clasp->spec.shouldDefineConstructor()) {
|
|
// Stash type information, so that what we do here is equivalent to
|
|
// initBuiltinConstructor.
|
|
AddTypePropertyId(cx, global, id, ObjectValue(*ctor));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::initBuiltinConstructor(JSContext* cx, Handle<GlobalObject*> global,
|
|
JSProtoKey key, HandleObject ctor, HandleObject proto)
|
|
{
|
|
MOZ_ASSERT(!global->empty()); // reserved slots already allocated
|
|
MOZ_ASSERT(key != JSProto_Null);
|
|
MOZ_ASSERT(ctor);
|
|
MOZ_ASSERT(proto);
|
|
|
|
RootedId id(cx, NameToId(ClassName(key, cx)));
|
|
MOZ_ASSERT(!global->lookup(cx, id));
|
|
|
|
if (!global->addDataProperty(cx, id, constructorPropertySlot(key), 0))
|
|
return false;
|
|
|
|
global->setConstructor(key, ObjectValue(*ctor));
|
|
global->setPrototype(key, ObjectValue(*proto));
|
|
global->setConstructorPropertySlot(key, ObjectValue(*ctor));
|
|
|
|
AddTypePropertyId(cx, global, id, ObjectValue(*ctor));
|
|
return true;
|
|
}
|
|
|
|
GlobalObject*
|
|
GlobalObject::createInternal(JSContext* cx, const Class* clasp)
|
|
{
|
|
MOZ_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
|
|
MOZ_ASSERT(clasp->trace == JS_GlobalObjectTraceHook);
|
|
|
|
JSObject* obj = NewObjectWithGivenProto(cx, clasp, nullptr, SingletonObject);
|
|
if (!obj)
|
|
return nullptr;
|
|
|
|
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
|
|
MOZ_ASSERT(global->isUnqualifiedVarObj());
|
|
|
|
// Initialize the private slot to null if present, as GC can call class
|
|
// hooks before the caller gets to set this to a non-garbage value.
|
|
if (clasp->flags & JSCLASS_HAS_PRIVATE)
|
|
global->setPrivate(nullptr);
|
|
|
|
Rooted<ClonedBlockObject*> lexical(cx, ClonedBlockObject::createGlobal(cx, global));
|
|
if (!lexical)
|
|
return nullptr;
|
|
global->setReservedSlot(LEXICAL_SCOPE, ObjectValue(*lexical));
|
|
|
|
cx->compartment()->initGlobal(*global);
|
|
|
|
if (!global->setQualifiedVarObj(cx))
|
|
return nullptr;
|
|
if (!global->setDelegate(cx))
|
|
return nullptr;
|
|
|
|
return global;
|
|
}
|
|
|
|
GlobalObject*
|
|
GlobalObject::new_(JSContext* cx, const Class* clasp, JSPrincipals* principals,
|
|
JS::OnNewGlobalHookOption hookOption,
|
|
const JS::CompartmentOptions& options)
|
|
{
|
|
MOZ_ASSERT(!cx->isExceptionPending());
|
|
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
|
|
|
|
JSRuntime* rt = cx->runtime();
|
|
|
|
Zone* zone;
|
|
if (options.zoneSpecifier() == JS::SystemZone)
|
|
zone = rt->gc.systemZone;
|
|
else if (options.zoneSpecifier() == JS::FreshZone)
|
|
zone = nullptr;
|
|
else
|
|
zone = static_cast<Zone*>(options.zonePointer());
|
|
|
|
JSCompartment* compartment = NewCompartment(cx, zone, principals, options);
|
|
if (!compartment)
|
|
return nullptr;
|
|
|
|
// Lazily create the system zone.
|
|
if (!rt->gc.systemZone && options.zoneSpecifier() == JS::SystemZone) {
|
|
rt->gc.systemZone = compartment->zone();
|
|
rt->gc.systemZone->isSystem = true;
|
|
}
|
|
|
|
Rooted<GlobalObject*> global(cx);
|
|
{
|
|
AutoCompartment ac(cx, compartment);
|
|
global = GlobalObject::createInternal(cx, clasp);
|
|
if (!global)
|
|
return nullptr;
|
|
}
|
|
|
|
if (hookOption == JS::FireOnNewGlobalHook)
|
|
JS_FireOnNewGlobalObject(cx, global);
|
|
|
|
return global;
|
|
}
|
|
|
|
ClonedBlockObject&
|
|
GlobalObject::lexicalScope() const
|
|
{
|
|
return getReservedSlot(LEXICAL_SCOPE).toObject().as<ClonedBlockObject>();
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::getOrCreateEval(JSContext* cx, Handle<GlobalObject*> global,
|
|
MutableHandleObject eval)
|
|
{
|
|
if (!global->getOrCreateObjectPrototype(cx))
|
|
return false;
|
|
eval.set(&global->getSlot(EVAL).toObject());
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
GlobalObject::valueIsEval(Value val)
|
|
{
|
|
Value eval = getSlot(EVAL);
|
|
return eval.isObject() && eval == val;
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::initStandardClasses(JSContext* cx, Handle<GlobalObject*> global)
|
|
{
|
|
/* Define a top-level property 'undefined' with the undefined value. */
|
|
if (!DefineProperty(cx, global, cx->names().undefined, UndefinedHandleValue,
|
|
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY | JSPROP_RESOLVING))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for (size_t k = 0; k < JSProto_LIMIT; ++k) {
|
|
if (!ensureConstructor(cx, global, static_cast<JSProtoKey>(k)))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Initializes a builtin constructor and its prototype without defining any
|
|
* properties or functions on it.
|
|
*
|
|
* Used in self-hosting to install the few builtin constructors required by
|
|
* self-hosted builtins.
|
|
*/
|
|
static bool
|
|
InitBareBuiltinCtor(JSContext* cx, Handle<GlobalObject*> global, JSProtoKey protoKey)
|
|
{
|
|
MOZ_ASSERT(cx->runtime()->isSelfHostingGlobal(global));
|
|
const Class* clasp = ProtoKeyToClass(protoKey);
|
|
RootedObject proto(cx);
|
|
proto = clasp->spec.createPrototypeHook()(cx, protoKey);
|
|
if (!proto)
|
|
return false;
|
|
|
|
RootedObject ctor(cx, clasp->spec.createConstructorHook()(cx, protoKey));
|
|
if (!ctor)
|
|
return false;
|
|
|
|
return GlobalObject::initBuiltinConstructor(cx, global, protoKey, ctor, proto);
|
|
}
|
|
|
|
/**
|
|
* The self-hosting global only gets a small subset of all standard classes.
|
|
* Even those are only created as bare constructors without any properties
|
|
* or functions.
|
|
*/
|
|
/* static */ bool
|
|
GlobalObject::initSelfHostingBuiltins(JSContext* cx, Handle<GlobalObject*> global,
|
|
const JSFunctionSpec* builtins)
|
|
{
|
|
// Define a top-level property 'undefined' with the undefined value.
|
|
if (!DefineProperty(cx, global, cx->names().undefined, UndefinedHandleValue,
|
|
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Define a top-level property 'std_iterator' with the name of the method
|
|
// used by for-of loops to create an iterator.
|
|
RootedValue std_iterator(cx);
|
|
std_iterator.setSymbol(cx->wellKnownSymbols().get(JS::SymbolCode::iterator));
|
|
if (!JS_DefineProperty(cx, global, "std_iterator", std_iterator,
|
|
JSPROP_PERMANENT | JSPROP_READONLY))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
RootedValue std_species(cx);
|
|
std_species.setSymbol(cx->wellKnownSymbols().get(JS::SymbolCode::species));
|
|
if (!JS_DefineProperty(cx, global, "std_species", std_species,
|
|
JSPROP_PERMANENT | JSPROP_READONLY))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return InitBareBuiltinCtor(cx, global, JSProto_Array) &&
|
|
InitBareBuiltinCtor(cx, global, JSProto_TypedArray) &&
|
|
InitBareBuiltinCtor(cx, global, JSProto_Uint8Array) &&
|
|
InitBareWeakMapCtor(cx, global) &&
|
|
InitStopIterationClass(cx, global) &&
|
|
InitSelfHostingCollectionIteratorFunctions(cx, global) &&
|
|
DefineFunctions(cx, global, builtins, AsIntrinsic);
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::isRuntimeCodeGenEnabled(JSContext* cx, Handle<GlobalObject*> global)
|
|
{
|
|
HeapSlot& v = global->getSlotRef(RUNTIME_CODEGEN_ENABLED);
|
|
if (v.isUndefined()) {
|
|
/*
|
|
* If there are callbacks, make sure that the CSP callback is installed
|
|
* and that it permits runtime code generation, then cache the result.
|
|
*/
|
|
JSCSPEvalChecker allows = cx->runtime()->securityCallbacks->contentSecurityPolicyAllows;
|
|
Value boolValue = BooleanValue(!allows || allows(cx));
|
|
v.set(global, HeapSlot::Slot, RUNTIME_CODEGEN_ENABLED, boolValue);
|
|
}
|
|
return !v.isFalse();
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::warnOnceAbout(JSContext* cx, HandleObject obj, WarnOnceFlag flag,
|
|
unsigned errorNumber)
|
|
{
|
|
Rooted<GlobalObject*> global(cx, &obj->global());
|
|
HeapSlot& v = global->getSlotRef(WARNED_ONCE_FLAGS);
|
|
MOZ_ASSERT_IF(!v.isUndefined(), v.toInt32());
|
|
int32_t flags = v.isUndefined() ? 0 : v.toInt32();
|
|
if (!(flags & flag)) {
|
|
if (!JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
|
|
errorNumber))
|
|
{
|
|
return false;
|
|
}
|
|
if (v.isUndefined())
|
|
v.init(global, HeapSlot::Slot, WARNED_ONCE_FLAGS, Int32Value(flags | flag));
|
|
else
|
|
v.set(global, HeapSlot::Slot, WARNED_ONCE_FLAGS, Int32Value(flags | flag));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
JSFunction*
|
|
GlobalObject::createConstructor(JSContext* cx, Native ctor, JSAtom* nameArg, unsigned length,
|
|
gc::AllocKind kind, const JSJitInfo* jitInfo)
|
|
{
|
|
RootedAtom name(cx, nameArg);
|
|
JSFunction* fun = NewNativeConstructor(cx, ctor, length, name, kind);
|
|
if (!fun)
|
|
return nullptr;
|
|
|
|
if (jitInfo)
|
|
fun->setJitInfo(jitInfo);
|
|
|
|
return fun;
|
|
}
|
|
|
|
static NativeObject*
|
|
CreateBlankProto(JSContext* cx, const Class* clasp, HandleObject proto, HandleObject global)
|
|
{
|
|
MOZ_ASSERT(clasp != &JSFunction::class_);
|
|
|
|
RootedNativeObject blankProto(cx, NewNativeObjectWithGivenProto(cx, clasp, proto,
|
|
SingletonObject));
|
|
if (!blankProto || !blankProto->setDelegate(cx))
|
|
return nullptr;
|
|
|
|
return blankProto;
|
|
}
|
|
|
|
NativeObject*
|
|
GlobalObject::createBlankPrototype(JSContext* cx, const Class* clasp)
|
|
{
|
|
Rooted<GlobalObject*> self(cx, this);
|
|
RootedObject objectProto(cx, getOrCreateObjectPrototype(cx));
|
|
if (!objectProto)
|
|
return nullptr;
|
|
|
|
return CreateBlankProto(cx, clasp, objectProto, self);
|
|
}
|
|
|
|
NativeObject*
|
|
GlobalObject::createBlankPrototypeInheriting(JSContext* cx, const Class* clasp, HandleObject proto)
|
|
{
|
|
Rooted<GlobalObject*> self(cx, this);
|
|
return CreateBlankProto(cx, clasp, proto, self);
|
|
}
|
|
|
|
bool
|
|
js::LinkConstructorAndPrototype(JSContext* cx, JSObject* ctor_, JSObject* proto_)
|
|
{
|
|
RootedObject ctor(cx, ctor_), proto(cx, proto_);
|
|
|
|
RootedValue protoVal(cx, ObjectValue(*proto));
|
|
RootedValue ctorVal(cx, ObjectValue(*ctor));
|
|
|
|
return DefineProperty(cx, ctor, cx->names().prototype, protoVal,
|
|
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY) &&
|
|
DefineProperty(cx, proto, cx->names().constructor, ctorVal,
|
|
nullptr, nullptr, 0);
|
|
}
|
|
|
|
bool
|
|
js::DefinePropertiesAndFunctions(JSContext* cx, HandleObject obj,
|
|
const JSPropertySpec* ps, const JSFunctionSpec* fs)
|
|
{
|
|
if (ps && !JS_DefineProperties(cx, obj, ps))
|
|
return false;
|
|
if (fs && !JS_DefineFunctions(cx, obj, fs))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
static void
|
|
GlobalDebuggees_finalize(FreeOp* fop, JSObject* obj)
|
|
{
|
|
fop->delete_((GlobalObject::DebuggerVector*) obj->as<NativeObject>().getPrivate());
|
|
}
|
|
|
|
static const Class
|
|
GlobalDebuggees_class = {
|
|
"GlobalDebuggee", JSCLASS_HAS_PRIVATE,
|
|
nullptr, nullptr, nullptr, nullptr,
|
|
nullptr, nullptr, nullptr, GlobalDebuggees_finalize
|
|
};
|
|
|
|
GlobalObject::DebuggerVector*
|
|
GlobalObject::getDebuggers() const
|
|
{
|
|
Value debuggers = getReservedSlot(DEBUGGERS);
|
|
if (debuggers.isUndefined())
|
|
return nullptr;
|
|
MOZ_ASSERT(debuggers.toObject().getClass() == &GlobalDebuggees_class);
|
|
return (DebuggerVector*) debuggers.toObject().as<NativeObject>().getPrivate();
|
|
}
|
|
|
|
/* static */ GlobalObject::DebuggerVector*
|
|
GlobalObject::getOrCreateDebuggers(JSContext* cx, Handle<GlobalObject*> global)
|
|
{
|
|
assertSameCompartment(cx, global);
|
|
DebuggerVector* debuggers = global->getDebuggers();
|
|
if (debuggers)
|
|
return debuggers;
|
|
|
|
NativeObject* obj = NewNativeObjectWithGivenProto(cx, &GlobalDebuggees_class, nullptr);
|
|
if (!obj)
|
|
return nullptr;
|
|
debuggers = cx->new_<DebuggerVector>();
|
|
if (!debuggers)
|
|
return nullptr;
|
|
obj->setPrivate(debuggers);
|
|
global->setReservedSlot(DEBUGGERS, ObjectValue(*obj));
|
|
return debuggers;
|
|
}
|
|
|
|
/* static */ NativeObject*
|
|
GlobalObject::getOrCreateForOfPICObject(JSContext* cx, Handle<GlobalObject*> global)
|
|
{
|
|
assertSameCompartment(cx, global);
|
|
NativeObject* forOfPIC = global->getForOfPICObject();
|
|
if (forOfPIC)
|
|
return forOfPIC;
|
|
|
|
forOfPIC = ForOfPIC::createForOfPICObject(cx, global);
|
|
if (!forOfPIC)
|
|
return nullptr;
|
|
global->setReservedSlot(FOR_OF_PIC_CHAIN, ObjectValue(*forOfPIC));
|
|
return forOfPIC;
|
|
}
|
|
|
|
bool
|
|
GlobalObject::hasRegExpStatics() const
|
|
{
|
|
return !getSlot(REGEXP_STATICS).isUndefined();
|
|
}
|
|
|
|
RegExpStatics*
|
|
GlobalObject::getRegExpStatics(ExclusiveContext* cx) const
|
|
{
|
|
MOZ_ASSERT(cx);
|
|
Rooted<GlobalObject*> self(cx, const_cast<GlobalObject*>(this));
|
|
|
|
RegExpStaticsObject* resObj = nullptr;
|
|
const Value& val = this->getSlot(REGEXP_STATICS);
|
|
if (!val.isObject()) {
|
|
MOZ_ASSERT(val.isUndefined());
|
|
resObj = RegExpStatics::create(cx, self);
|
|
if (!resObj)
|
|
return nullptr;
|
|
|
|
self->initSlot(REGEXP_STATICS, ObjectValue(*resObj));
|
|
} else {
|
|
resObj = &val.toObject().as<RegExpStaticsObject>();
|
|
}
|
|
return static_cast<RegExpStatics*>(resObj->getPrivate(/* nfixed = */ 1));
|
|
}
|
|
|
|
RegExpStatics*
|
|
GlobalObject::getAlreadyCreatedRegExpStatics() const
|
|
{
|
|
const Value& val = this->getSlot(REGEXP_STATICS);
|
|
MOZ_ASSERT(val.isObject());
|
|
return static_cast<RegExpStatics*>(val.toObject().as<RegExpStaticsObject>().getPrivate(/* nfixed = */ 1));
|
|
}
|
|
|
|
/* static */ NativeObject*
|
|
GlobalObject::getIntrinsicsHolder(JSContext* cx, Handle<GlobalObject*> global)
|
|
{
|
|
Value slot = global->getReservedSlot(INTRINSICS);
|
|
MOZ_ASSERT(slot.isUndefined() || slot.isObject());
|
|
|
|
if (slot.isObject())
|
|
return &slot.toObject().as<NativeObject>();
|
|
|
|
Rooted<NativeObject*> intrinsicsHolder(cx);
|
|
bool isSelfHostingGlobal = cx->runtime()->isSelfHostingGlobal(global);
|
|
if (isSelfHostingGlobal) {
|
|
intrinsicsHolder = global;
|
|
} else {
|
|
intrinsicsHolder = NewObjectWithGivenProto<PlainObject>(cx, nullptr, TenuredObject);
|
|
if (!intrinsicsHolder)
|
|
return nullptr;
|
|
}
|
|
|
|
/* Define a property 'global' with the current global as its value. */
|
|
RootedValue globalValue(cx, ObjectValue(*global));
|
|
if (!DefineProperty(cx, intrinsicsHolder, cx->names().global, globalValue,
|
|
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
// Install the intrinsics holder in the intrinsics.
|
|
global->setReservedSlot(INTRINSICS, ObjectValue(*intrinsicsHolder));
|
|
return intrinsicsHolder;
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::getSelfHostedFunction(JSContext* cx, Handle<GlobalObject*> global,
|
|
HandlePropertyName selfHostedName, HandleAtom name,
|
|
unsigned nargs, MutableHandleValue funVal)
|
|
{
|
|
if (GlobalObject::maybeGetIntrinsicValue(cx, global, selfHostedName, funVal)) {
|
|
RootedFunction fun(cx, &funVal.toObject().as<JSFunction>());
|
|
if (fun->atom() == name)
|
|
return true;
|
|
|
|
if (fun->atom() == selfHostedName) {
|
|
// This function was initially cloned because it was called by
|
|
// other self-hosted code, so the clone kept its self-hosted name,
|
|
// instead of getting the name it's intended to have in content
|
|
// compartments. This can happen when a lazy builtin is initialized
|
|
// after self-hosted code for another builtin used the same
|
|
// function. In that case, we need to change the function's name,
|
|
// which is ok because it can't have been exposed to content
|
|
// before.
|
|
fun->initAtom(name);
|
|
return true;
|
|
}
|
|
|
|
|
|
// The function might be installed multiple times on the same or
|
|
// different builtins, under different property names, so its name
|
|
// might be neither "selfHostedName" nor "name". In that case, its
|
|
// canonical name must've been set using the `_SetCanonicalName`
|
|
// intrinsic.
|
|
cx->runtime()->assertSelfHostedFunctionHasCanonicalName(cx, selfHostedName);
|
|
return true;
|
|
}
|
|
|
|
RootedFunction fun(cx);
|
|
if (!cx->runtime()->createLazySelfHostedFunctionClone(cx, selfHostedName, name, nargs, &fun))
|
|
return false;
|
|
funVal.setObject(*fun);
|
|
|
|
return GlobalObject::addIntrinsicValue(cx, global, selfHostedName, funVal);
|
|
}
|
|
|
|
/* static */ bool
|
|
GlobalObject::addIntrinsicValue(JSContext* cx, Handle<GlobalObject*> global,
|
|
HandlePropertyName name, HandleValue value)
|
|
{
|
|
RootedNativeObject holder(cx, GlobalObject::getIntrinsicsHolder(cx, global));
|
|
if (!holder)
|
|
return false;
|
|
|
|
uint32_t slot = holder->slotSpan();
|
|
RootedShape last(cx, holder->lastProperty());
|
|
Rooted<UnownedBaseShape*> base(cx, last->base()->unowned());
|
|
|
|
RootedId id(cx, NameToId(name));
|
|
Rooted<StackShape> child(cx, StackShape(base, id, slot, 0, 0));
|
|
Shape* shape = cx->compartment()->propertyTree.getChild(cx, last, child);
|
|
if (!shape)
|
|
return false;
|
|
|
|
if (!holder->setLastProperty(cx, shape))
|
|
return false;
|
|
|
|
holder->setSlot(shape->slot(), value);
|
|
return true;
|
|
}
|