Bug 1506542 - Add run-time flag to enable bigint support r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D11613

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andy Wingo 2018-11-13 09:11:06 +00:00
parent 582b645d9b
commit 1471c70fb7
8 changed files with 59 additions and 0 deletions

View File

@ -45,6 +45,9 @@ jsfuzz_createGlobal(JSContext* cx, JSPrincipals* principals)
JS::RootedObject newGlobal(cx);
JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true);
#ifdef ENABLE_BIGINT
options.creationOptions().setBigIntEnabled(true);
#endif
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
options);
if (!newGlobal) {

View File

@ -86,6 +86,9 @@ JSObject* JSAPITest::createGlobal(JSPrincipals* principals)
JS::RootedObject newGlobal(cx);
JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true);
#ifdef ENABLE_BIGINT
options.creationOptions().setBigIntEnabled(true);
#endif
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
options);
if (!newGlobal) {

View File

@ -1501,6 +1501,9 @@ class JS_PUBLIC_API(RealmCreationOptions)
cloneSingletons_(false),
sharedMemoryAndAtomics_(false),
streams_(false),
#ifdef ENABLE_BIGINT
bigint_(false),
#endif
secureContext_(false),
clampAndJitterTime_(true)
{}
@ -1572,6 +1575,14 @@ class JS_PUBLIC_API(RealmCreationOptions)
return *this;
}
#ifdef ENABLE_BIGINT
bool getBigIntEnabled() const { return bigint_; }
RealmCreationOptions& setBigIntEnabled(bool flag) {
bigint_ = flag;
return *this;
}
#endif
// This flag doesn't affect JS engine behavior. It is used by Gecko to
// mark whether content windows and workers are "Secure Context"s. See
// https://w3c.github.io/webappsec-secure-contexts/
@ -1601,6 +1612,9 @@ class JS_PUBLIC_API(RealmCreationOptions)
bool cloneSingletons_;
bool sharedMemoryAndAtomics_;
bool streams_;
#ifdef ENABLE_BIGINT
bool bigint_;
#endif
bool secureContext_;
bool clampAndJitterTime_;
};

View File

@ -522,6 +522,9 @@ static bool enableWasmGc = false;
static bool enableTestWasmAwaitTier2 = false;
static bool enableAsyncStacks = false;
static bool enableStreams = false;
#ifdef ENABLE_BIGINT
static bool enableBigInt = false;
#endif
#ifdef JS_GC_ZEAL
static uint32_t gZealBits = 0;
static uint32_t gZealFrequency = 0;
@ -3749,6 +3752,9 @@ static void
SetStandardRealmOptions(JS::RealmOptions& options)
{
options.creationOptions().setSharedMemoryAndAtomicsEnabled(enableSharedMemory)
#ifdef ENABLE_BIGINT
.setBigIntEnabled(enableBigInt)
#endif
.setStreamsEnabled(enableStreams);
}
@ -10366,6 +10372,9 @@ SetContextOptions(JSContext* cx, const OptionParser& op)
enableTestWasmAwaitTier2 = op.getBoolOption("test-wasm-await-tier2");
enableAsyncStacks = !op.getBoolOption("no-async-stacks");
enableStreams = !op.getBoolOption("no-streams");
#ifdef ENABLE_BIGINT
enableBigInt = !op.getBoolOption("no-bigint");
#endif
#if defined ENABLE_WASM_GC && defined ENABLE_WASM_CRANELIFT
// Note, once we remove --wasm-gc this test will no longer make any sense
@ -11001,6 +11010,9 @@ main(int argc, char** argv, char** envp)
|| !op.addBoolOption('\0', "no-unboxed-objects", "Disable creating unboxed plain objects")
|| !op.addBoolOption('\0', "enable-streams", "Enable WHATWG Streams (default)")
|| !op.addBoolOption('\0', "no-streams", "Disable WHATWG Streams")
#ifdef ENABLE_BIGINT
|| !op.addBoolOption('\0', "no-bigint", "Disable experimental BigInt support")
#endif
#ifdef ENABLE_SHARED_ARRAY_BUFFER
|| !op.addStringOption('\0', "shared-memory", "on/off",
"SharedArrayBuffer and Atomics "

View File

@ -110,6 +110,11 @@ GlobalObject::skipDeselectedConstructor(JSContext* cx, JSProtoKey key)
case JSProto_CountQueuingStrategy:
return !cx->realm()->creationOptions().getStreamsEnabled();
#ifdef ENABLE_BIGINT
case JSProto_BigInt:
return !cx->realm()->creationOptions().getBigIntEnabled();
#endif
// Return true if the given constructor has been disabled at run-time.
case JSProto_Atomics:
case JSProto_SharedArrayBuffer:

View File

@ -784,11 +784,17 @@ bool xpc::ExtraWarningsForSystemJS() { return false; }
static mozilla::Atomic<bool> sSharedMemoryEnabled(false);
static mozilla::Atomic<bool> sStreamsEnabled(false);
#ifdef ENABLE_BIGINT
static mozilla::Atomic<bool> sBigIntEnabled(false);
#endif
void
xpc::SetPrefableRealmOptions(JS::RealmOptions &options)
{
options.creationOptions().setSharedMemoryAndAtomicsEnabled(sSharedMemoryEnabled)
#ifdef ENABLE_BIGINT
.setBigIntEnabled(sBigIntEnabled)
#endif
.setStreamsEnabled(sStreamsEnabled);
}
@ -831,6 +837,10 @@ ReloadPrefsCallback(const char* pref, XPCJSContext* xpccx)
bool useAsyncStack = Preferences::GetBool(JS_OPTIONS_DOT_STR "asyncstack");
#ifdef ENABLE_BIGINT
sBigIntEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "bigint");
#endif
bool throwOnDebuggeeWouldRun = Preferences::GetBool(JS_OPTIONS_DOT_STR
"throw_on_debuggee_would_run");

View File

@ -894,6 +894,15 @@ VARCACHE_PREF(
RelaxedAtomicBool, false
)
#ifdef ENABLE_BIGINT
// BigInt API
VARCACHE_PREF(
"javascript.options.bigint",
javascript_options_bigint,
RelaxedAtomicBool, false
)
#endif
//---------------------------------------------------------------------------
// Media prefs

View File

@ -1569,6 +1569,9 @@ pref("javascript.options.streams", true);
pref("javascript.options.streams", false);
#endif
// BigInt API
pref("javascript.options.bigint", false);
// advanced prefs
pref("advanced.mailftp", false);
pref("image.animation_mode", "normal");