Bug 1529758 - Add a pref for fields. r=tcampbell

This creates a shell command-line option, `--enable-experimental-fields`, and a
Gecko pref, `javascript.options.experimental.fields`.

Both are off by default everywhere, for now.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jason Orendorff 2019-03-12 16:42:41 +00:00
Родитель 9f4ebc07f7
Коммит 51eb0a44fd
11 изменённых файлов: 45 добавлений и 16 удалений

Просмотреть файл

@ -117,6 +117,7 @@ class JS_PUBLIC_API TransitiveCompileOptions {
bool isProbablySystemCode = false;
bool hideScriptFromDebugger = false;
bool bigIntEnabledOption = false;
bool fieldsEnabledOption = false;
/**
* |introductionType| is a statically allocated C string: one of "eval",

Просмотреть файл

@ -6779,11 +6779,10 @@ bool GeneralParser<ParseHandler, Unit>::classMember(
}
if (propType == PropertyType::Field) {
// TODO(khyperia): Delete the two lines below once fields are fully
// supported in the backend. We can't fail in BytecodeCompiler because of
// lazy parsing.
errorAt(propNameOffset, JSMSG_FIELDS_NOT_SUPPORTED);
return false;
if (!options().fieldsEnabledOption) {
errorAt(propNameOffset, JSMSG_FIELDS_NOT_SUPPORTED);
return null();
}
if (isStatic) {
errorAt(propNameOffset, JSMSG_BAD_METHOD_DEF);

Просмотреть файл

@ -1994,9 +1994,10 @@ MOZ_MUST_USE bool TokenStreamSpecific<Unit, AnyCharsAccess>::identifierName(
"Private identifier starts with #");
newPrivateNameToken(atom->asPropertyName(), start, modifier, out);
// TODO(khypera): Delete the below once private names are supported.
errorAt(start.offset(), JSMSG_FIELDS_NOT_SUPPORTED);
return false;
if (!anyCharsAccess().options().fieldsEnabledOption) {
errorAt(start.offset(), JSMSG_FIELDS_NOT_SUPPORTED);
return false;
}
} else {
newNameToken(atom->asPropertyName(), start, modifier, out);
}

Просмотреть файл

@ -42,8 +42,10 @@ static JSObject* jsfuzz_createGlobal(JSContext* cx, JSPrincipals* principals) {
/* Create the global object. */
JS::RootedObject newGlobal(cx);
JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true);
options.creationOptions().setBigIntEnabled(true);
options.creationOptions()
.setStreamsEnabled(true)
.setBigIntEnabled(true)
.setFieldsEnabled(false);
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals,
JS::FireOnNewGlobalHook, options);
if (!newGlobal) {

Просмотреть файл

@ -79,8 +79,10 @@ JSObject* JSAPITest::createGlobal(JSPrincipals* principals) {
/* Create the global object. */
JS::RootedObject newGlobal(cx);
JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true);
options.creationOptions().setBigIntEnabled(true);
options.creationOptions()
.setStreamsEnabled(true)
.setBigIntEnabled(true)
.setFieldsEnabled(true);
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals,
JS::FireOnNewGlobalHook, options);
if (!newGlobal) {

Просмотреть файл

@ -3425,6 +3425,7 @@ void JS::TransitiveCompileOptions::copyPODTransitiveOptions(
isProbablySystemCode = rhs.isProbablySystemCode;
hideScriptFromDebugger = rhs.hideScriptFromDebugger;
bigIntEnabledOption = rhs.bigIntEnabledOption;
fieldsEnabledOption = rhs.fieldsEnabledOption;
};
void JS::ReadOnlyCompileOptions::copyPODOptions(
@ -3552,6 +3553,7 @@ JS::CompileOptions::CompileOptions(JSContext* cx)
throwOnAsmJSValidationFailureOption =
cx->options().throwOnAsmJSValidationFailure();
bigIntEnabledOption = cx->realm()->creationOptions().getBigIntEnabled();
fieldsEnabledOption = cx->realm()->creationOptions().getFieldsEnabled();
}
CompileOptions& CompileOptions::setIntroductionInfoToCaller(

Просмотреть файл

@ -964,6 +964,7 @@ class JS_PUBLIC_API RealmCreationOptions {
sharedMemoryAndAtomics_(false),
streams_(false),
bigint_(false),
fields_(false),
secureContext_(false),
clampAndJitterTime_(true) {}
@ -1045,6 +1046,12 @@ class JS_PUBLIC_API RealmCreationOptions {
return *this;
}
bool getFieldsEnabled() const { return fields_; }
RealmCreationOptions& setFieldsEnabled(bool flag) {
fields_ = flag;
return *this;
}
// 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/
@ -1075,6 +1082,7 @@ class JS_PUBLIC_API RealmCreationOptions {
bool sharedMemoryAndAtomics_;
bool streams_;
bool bigint_;
bool fields_;
bool secureContext_;
bool clampAndJitterTime_;
};

Просмотреть файл

@ -503,6 +503,7 @@ static bool enableTestWasmAwaitTier2 = false;
static bool enableAsyncStacks = false;
static bool enableStreams = false;
static bool enableBigInt = false;
static bool enableFields = false;
#ifdef JS_GC_ZEAL
static uint32_t gZealBits = 0;
static uint32_t gZealFrequency = 0;
@ -3763,7 +3764,8 @@ static void SetStandardRealmOptions(JS::RealmOptions& options) {
options.creationOptions()
.setSharedMemoryAndAtomicsEnabled(enableSharedMemory)
.setBigIntEnabled(enableBigInt)
.setStreamsEnabled(enableStreams);
.setStreamsEnabled(enableStreams)
.setFieldsEnabled(enableFields);
}
static MOZ_MUST_USE bool CheckRealmOptions(JSContext* cx,
@ -10186,6 +10188,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
enableAsyncStacks = !op.getBoolOption("no-async-stacks");
enableStreams = !op.getBoolOption("no-streams");
enableBigInt = !op.getBoolOption("no-bigint");
enableFields = op.getBoolOption("enable-experimental-fields");
JS::ContextOptionsRef(cx)
.setBaseline(enableBaseline)
@ -10897,8 +10900,8 @@ int main(int argc, char** argv, char** envp) {
!op.addBoolOption('\0', "enable-streams",
"Enable WHATWG Streams (default)") ||
!op.addBoolOption('\0', "no-streams", "Disable WHATWG Streams") ||
!op.addBoolOption('\0', "no-bigint",
"Disable experimental BigInt support") ||
!op.addBoolOption('\0', "no-bigint", "Disable BigInt support") ||
!op.addBoolOption('\0', "enable-experimental-fields", "Enable fields in classes") ||
!op.addStringOption('\0', "shared-memory", "on/off",
"SharedArrayBuffer and Atomics "
#if SHARED_MEMORY_DEFAULT

Просмотреть файл

@ -760,12 +760,14 @@ bool xpc::ExtraWarningsForSystemJS() { return false; }
static mozilla::Atomic<bool> sSharedMemoryEnabled(false);
static mozilla::Atomic<bool> sStreamsEnabled(false);
static mozilla::Atomic<bool> sBigIntEnabled(false);
static mozilla::Atomic<bool> sFieldsEnabled(false);
void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
options.creationOptions()
.setSharedMemoryAndAtomicsEnabled(sSharedMemoryEnabled)
.setBigIntEnabled(sBigIntEnabled)
.setStreamsEnabled(sStreamsEnabled);
.setStreamsEnabled(sStreamsEnabled)
.setFieldsEnabled(sFieldsEnabled);
}
static void ReloadPrefsCallback(const char* pref, XPCJSContext* xpccx) {
@ -847,6 +849,7 @@ static void ReloadPrefsCallback(const char* pref, XPCJSContext* xpccx) {
sSharedMemoryEnabled =
Preferences::GetBool(JS_OPTIONS_DOT_STR "shared_memory");
sStreamsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "streams");
sFieldsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.fields");
#ifdef DEBUG
sExtraWarningsForSystemJS =

Просмотреть файл

@ -1113,6 +1113,12 @@ VARCACHE_PREF(
RelaxedAtomicBool, false
)
VARCACHE_PREF(
"javascript.options.experimental.fields",
javascript_options_experimental_fields,
RelaxedAtomicBool, false
)
//---------------------------------------------------------------------------
// Media prefs

Просмотреть файл

@ -1603,6 +1603,8 @@ pref("javascript.options.streams", true);
// BigInt API
pref("javascript.options.bigint", false);
pref("javascript.options.experimental.fields", false);
// Dynamic module import.
pref("javascript.options.dynamicImport", true);