diff --git a/js/public/RealmOptions.h b/js/public/RealmOptions.h index b8356292d0d9..0af1d7b2b2ce 100644 --- a/js/public/RealmOptions.h +++ b/js/public/RealmOptions.h @@ -228,6 +228,12 @@ class JS_PUBLIC_API RealmCreationOptions { return *this; } + bool getIteratorHelpersEnabled() const { return iteratorHelpers_; } + RealmCreationOptions& setIteratorHelpersEnabled(bool flag) { + iteratorHelpers_ = 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/ @@ -267,6 +273,7 @@ class JS_PUBLIC_API RealmCreationOptions { bool weakRefs_ = false; bool toSource_ = false; bool propertyErrorMessageFix_ = false; + bool iteratorHelpers_ = false; bool secureContext_ = false; }; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index a240ee155193..4b3f545e6df6 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -512,6 +512,7 @@ bool shell::enableReadableStreamPipeTo = false; bool shell::enableWeakRefs = false; bool shell::enableToSource = false; bool shell::enablePropertyErrorMessageFix = false; +bool shell::enableIteratorHelpers = false; #ifdef JS_GC_ZEAL uint32_t shell::gZealBits = 0; uint32_t shell::gZealFrequency = 0; @@ -3891,7 +3892,8 @@ static void SetStandardRealmOptions(JS::RealmOptions& options) { .setReadableStreamPipeToEnabled(enableReadableStreamPipeTo) .setWeakRefsEnabled(enableWeakRefs) .setToSourceEnabled(enableToSource) - .setPropertyErrorMessageFixEnabled(enablePropertyErrorMessageFix); + .setPropertyErrorMessageFixEnabled(enablePropertyErrorMessageFix) + .setIteratorHelpersEnabled(enableIteratorHelpers); } static MOZ_MUST_USE bool CheckRealmOptions(JSContext* cx, @@ -10258,6 +10260,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) { enableToSource = !op.getBoolOption("disable-tosource"); enablePropertyErrorMessageFix = !op.getBoolOption("disable-property-error-message-fix"); + enableIteratorHelpers = op.getBoolOption("enable-iterator-helpers"); JS::ContextOptionsRef(cx) .setAsmJS(enableAsmJS) @@ -11129,6 +11132,8 @@ int main(int argc, char** argv, char** envp) { !op.addBoolOption('\0', "disable-property-error-message-fix", "Disable fix for the error message when accessing " "property of null or undefined") || + !op.addBoolOption('\0', "enable-iterator-helpers", + "Enable iterator helpers") || !op.addStringOption('\0', "shared-memory", "on/off", "SharedArrayBuffer and Atomics " #if SHARED_MEMORY_DEFAULT diff --git a/js/src/shell/jsshell.h b/js/src/shell/jsshell.h index 728019f3b236..1d33728e318a 100644 --- a/js/src/shell/jsshell.h +++ b/js/src/shell/jsshell.h @@ -138,6 +138,7 @@ extern bool enableReadableStreamPipeTo; extern bool enableWeakRefs; extern bool enableToSource; extern bool enablePropertyErrorMessageFix; +extern bool enableIteratorHelpers; #ifdef JS_GC_ZEAL extern uint32_t gZealBits; extern uint32_t gZealFrequency; diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index bc0293b82a4e..48eb1f2724f6 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -758,6 +758,7 @@ static mozilla::Atomic sStreamsEnabled(false); static mozilla::Atomic sPropertyErrorMessageFixEnabled(false); static mozilla::Atomic sWeakRefsEnabled(false); +static mozilla::Atomic sIteratorHelpersEnabled(false); void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) { options.creationOptions() @@ -769,7 +770,8 @@ void xpc::SetPrefableRealmOptions(JS::RealmOptions& options) { .setWritableStreamsEnabled( StaticPrefs::javascript_options_writable_streams()) .setPropertyErrorMessageFixEnabled(sPropertyErrorMessageFixEnabled) - .setWeakRefsEnabled(sWeakRefsEnabled); + .setWeakRefsEnabled(sWeakRefsEnabled) + .setIteratorHelpersEnabled(sIteratorHelpersEnabled); } static void LoadStartupJSPrefs(XPCJSContext* xpccx) { @@ -947,6 +949,8 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) { #ifdef NIGHTLY_BUILD sWeakRefsEnabled = Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.weakrefs"); + sIteratorHelpersEnabled = + Preferences::GetBool(JS_OPTIONS_DOT_STR "experimental.iterator_helpers"); #endif #ifdef JS_GC_ZEAL diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 8a55ebd7cfef..b60b614d21fa 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -4715,6 +4715,12 @@ type: RelaxedAtomicBool value: false mirror: always + + # Experimental support for Iterator Helpers in JavaScript. +- name: javascript.options.experimental.iterator_helpers + type: RelaxedAtomicBool + value: false + mirror: always #endif # The amount of time we wait between a request to GC (due to leaving a page) and doing the actual GC, in ms.