Bug 1641517 - Don't expose FinalizationRegistry.prototype.cleanupSome in the browser r=mccr8

This adds an extra pref for whether the cleanupSome method is exposed and renames the existing pref. We can turn on the pref to expose cleanupSome to get test262 coverage in the browser.

Differential Revision: https://phabricator.services.mozilla.com/D77267
This commit is contained in:
Jon Coppeard 2020-06-03 09:19:59 +00:00
parent 10441bbb03
commit 58b782e36e
10 changed files with 55 additions and 13 deletions

View file

@ -50,6 +50,16 @@ enum class CompartmentSpecifier {
ExistingCompartment,
};
/**
* Specification for whether weak refs should be enabled and if so whether the
* FinalizationRegistry.cleanupSome method should be present.
*/
enum class WeakRefSpecifier {
Disabled,
EnabledWithCleanupSome,
EnabledWithoutCleanupSome
};
/**
* RealmCreationOptions specifies options relevant to creating a new realm, that
* are either immutable characteristics of that realm or that are discarded
@ -208,9 +218,9 @@ class JS_PUBLIC_API RealmCreationOptions {
return *this;
}
bool getWeakRefsEnabled() const { return weakRefs_; }
RealmCreationOptions& setWeakRefsEnabled(bool flag) {
weakRefs_ = flag;
WeakRefSpecifier getWeakRefsEnabled() const { return weakRefs_; }
RealmCreationOptions& setWeakRefsEnabled(WeakRefSpecifier spec) {
weakRefs_ = spec;
return *this;
}
@ -264,6 +274,7 @@ class JS_PUBLIC_API RealmCreationOptions {
Zone* zone_;
};
uint64_t profilerRealmID_ = 0;
WeakRefSpecifier weakRefs_ = WeakRefSpecifier::Disabled;
bool invisibleToDebugger_ = false;
bool mergeable_ = false;
bool preserveJitCode_ = false;
@ -276,7 +287,6 @@ class JS_PUBLIC_API RealmCreationOptions {
bool byobStreamReaders_ = false;
bool writableStreams_ = false;
bool readableStreamPipeTo_ = false;
bool weakRefs_ = false;
bool toSource_ = false;
bool propertyErrorMessageFix_ = false;
bool iteratorHelpers_ = false;

View file

@ -31,7 +31,8 @@ static const JSClass* getGlobalClass() {
static JSObject* jsfuzz_createGlobal(JSContext* cx, JSPrincipals* principals) {
/* Create the global object. */
JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true).setWeakRefsEnabled(true);
options.creationOptions().setStreamsEnabled(true).setWeakRefsEnabled(
JS::WeakRefSpecifier::EnabledWithCleanupSome);
return JS_NewGlobalObject(cx, getGlobalClass(), principals,
JS::FireOnNewGlobalHook, options);
}

View file

@ -90,7 +90,7 @@ JSObject* JSAPITest::createGlobal(JSPrincipals* principals) {
JS::RealmOptions options;
options.creationOptions()
.setStreamsEnabled(true)
.setWeakRefsEnabled(true)
.setWeakRefsEnabled(JS::WeakRefSpecifier::EnabledWithCleanupSome)
.setSharedMemoryAndAtomicsEnabled(true);
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals,
JS::FireOnNewGlobalHook, options);

View file

@ -3891,7 +3891,9 @@ static void SetStandardRealmOptions(JS::RealmOptions& options) {
.setBYOBStreamReadersEnabled(enableBYOBStreamReaders)
.setWritableStreamsEnabled(enableWritableStreams)
.setReadableStreamPipeToEnabled(enableReadableStreamPipeTo)
.setWeakRefsEnabled(enableWeakRefs)
.setWeakRefsEnabled(enableWeakRefs
? JS::WeakRefSpecifier::EnabledWithCleanupSome
: JS::WeakRefSpecifier::Disabled)
.setToSourceEnabled(enableToSource)
.setPropertyErrorMessageFixEnabled(enablePropertyErrorMessageFix)
.setIteratorHelpersEnabled(enableIteratorHelpers)

View file

@ -30,5 +30,6 @@ user_pref("privacy.trackingprotection.enabled", false);
user_pref("privacy.trackingprotection.pbmode.enabled", false);
user_pref("general.useragent.updates.enabled", false);
user_pref("browser.webapps.checkForUpdates", 0);
user_pref("javascript.options.experimental.weakrefs", true);
user_pref("javascript.options.experimental.weakrefs.enabled", true);
user_pref("javascript.options.experimental.weakrefs.expose_cleanupSome", true);
user_pref("javascript.options.experimental.iterator_helpers", true);

View file

@ -208,7 +208,8 @@ bool GlobalObject::skipDeselectedConstructor(JSContext* cx, JSProtoKey key) {
case JSProto_WeakRef:
case JSProto_FinalizationRegistry:
return !cx->realm()->creationOptions().getWeakRefsEnabled();
return cx->realm()->creationOptions().getWeakRefsEnabled() ==
JS::WeakRefSpecifier::Disabled;
case JSProto_Iterator:
return !cx->realm()->creationOptions().getIteratorHelpersEnabled();

View file

@ -2844,6 +2844,12 @@ JS_FRIEND_API bool js::ShouldIgnorePropertyDefinition(JSContext* cx,
id == NameToId(cx->names().uneval);
}
if (key == JSProto_FinalizationRegistry &&
cx->realm()->creationOptions().getWeakRefsEnabled() ==
JS::WeakRefSpecifier::EnabledWithoutCleanupSome) {
return id == NameToId(cx->names().cleanupSome);
}
return false;
}

View file

@ -758,8 +758,21 @@ static mozilla::Atomic<bool> sStreamsEnabled(false);
static mozilla::Atomic<bool> sPropertyErrorMessageFixEnabled(false);
static mozilla::Atomic<bool> sWeakRefsEnabled(false);
static mozilla::Atomic<bool> sWeakRefsExposeCleanupSome(false);
static mozilla::Atomic<bool> sIteratorHelpersEnabled(false);
static JS::WeakRefSpecifier GetWeakRefsEnabled() {
if (!sWeakRefsEnabled) {
return JS::WeakRefSpecifier::Disabled;
}
if (sWeakRefsExposeCleanupSome) {
return JS::WeakRefSpecifier::EnabledWithCleanupSome;
}
return JS::WeakRefSpecifier::EnabledWithoutCleanupSome;
}
void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
options.creationOptions()
.setSharedMemoryAndAtomicsEnabled(sSharedMemoryEnabled)
@ -770,7 +783,7 @@ void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) {
.setWritableStreamsEnabled(
StaticPrefs::javascript_options_writable_streams())
.setPropertyErrorMessageFixEnabled(sPropertyErrorMessageFixEnabled)
.setWeakRefsEnabled(sWeakRefsEnabled)
.setWeakRefsEnabled(GetWeakRefsEnabled())
.setIteratorHelpersEnabled(sIteratorHelpersEnabled);
}
@ -948,7 +961,9 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
Preferences::GetBool(JS_OPTIONS_DOT_STR "property_error_message_fix");
#ifdef NIGHTLY_BUILD
sWeakRefsEnabled =
Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.weakrefs");
Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.weakrefs.enabled");
sWeakRefsExposeCleanupSome = Preferences::GetBool(
JS_OPTIONS_DOT_STR "experimental.weakrefs.expose_cleanupSome");
sIteratorHelpersEnabled =
Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.iterator_helpers");
#endif

View file

@ -38,7 +38,7 @@ support-files =
test2_bug629331.html
finalizationRegistry_worker.js
prefs =
javascript.options.experimental.weakrefs=true
javascript.options.experimental.weakrefs.enabled=true
[test_bug384632.html]
[test_bug390488.html]

View file

@ -4722,7 +4722,13 @@
#ifdef NIGHTLY_BUILD
# Experimental support for weak references in JavaScript (WeakRef and
# FinalizationRegistry).
- name: javascript.options.experimental.weakrefs
- name: javascript.options.experimental.weakrefs.enabled
type: RelaxedAtomicBool
value: false
mirror: always
# Whether to expose the FinalizationRegistry.prototype.cleanupSome method.
- name: javascript.options.experimental.weakrefs.expose_cleanupSome
type: RelaxedAtomicBool
value: false
mirror: always