JS - support for Array.prototype.values()

This commit is contained in:
janekptacijarabaci 2018-02-20 21:21:56 +01:00 • committed by Roy Tam
commit f8591643c5
8 changed files with 32 additions and 9 deletions

View file

@ -301,7 +301,9 @@ LoadContextOptions(const char* aPrefName, void* /* aClosure */)
.setNativeRegExp(GetWorkerPref<bool>(NS_LITERAL_CSTRING("native_regexp"))) .setNativeRegExp(GetWorkerPref<bool>(NS_LITERAL_CSTRING("native_regexp")))
.setAsyncStack(GetWorkerPref<bool>(NS_LITERAL_CSTRING("asyncstack"))) .setAsyncStack(GetWorkerPref<bool>(NS_LITERAL_CSTRING("asyncstack")))
.setWerror(GetWorkerPref<bool>(NS_LITERAL_CSTRING("werror"))) .setWerror(GetWorkerPref<bool>(NS_LITERAL_CSTRING("werror")))
.setExtraWarnings(GetWorkerPref<bool>(NS_LITERAL_CSTRING("strict"))); .setExtraWarnings(GetWorkerPref<bool>(NS_LITERAL_CSTRING("strict")))
.setArrayProtoValues(GetWorkerPref<bool>(
NS_LITERAL_CSTRING("array_prototype_values")));
RuntimeService::SetDefaultContextOptions(contextOptions); RuntimeService::SetDefaultContextOptions(contextOptions);

View file

@ -1099,7 +1099,8 @@ class JS_PUBLIC_API(ContextOptions) {
dumpStackOnDebuggeeWouldRun_(false), dumpStackOnDebuggeeWouldRun_(false),
werror_(false), werror_(false),
strictMode_(false), strictMode_(false),
extraWarnings_(false) extraWarnings_(false),
arrayProtoValues_(true)
{ {
} }
@ -1223,6 +1224,12 @@ class JS_PUBLIC_API(ContextOptions) {
return *this; return *this;
} }
bool arrayProtoValues() const { return arrayProtoValues_; }
ContextOptions& setArrayProtoValues(bool flag) {
arrayProtoValues_ = flag;
return *this;
}
private: private:
bool baseline_ : 1; bool baseline_ : 1;
bool ion_ : 1; bool ion_ : 1;
@ -1238,6 +1245,7 @@ class JS_PUBLIC_API(ContextOptions) {
bool werror_ : 1; bool werror_ : 1;
bool strictMode_ : 1; bool strictMode_ : 1;
bool extraWarnings_ : 1; bool extraWarnings_ : 1;
bool arrayProtoValues_ : 1;
}; };
JS_PUBLIC_API(ContextOptions&) JS_PUBLIC_API(ContextOptions&)

View file

@ -3165,9 +3165,7 @@ static const JSFunctionSpec array_methods[] = {
JS_SELF_HOSTED_SYM_FN(iterator, "ArrayValues", 0,0), JS_SELF_HOSTED_SYM_FN(iterator, "ArrayValues", 0,0),
JS_SELF_HOSTED_FN("entries", "ArrayEntries", 0,0), JS_SELF_HOSTED_FN("entries", "ArrayEntries", 0,0),
JS_SELF_HOSTED_FN("keys", "ArrayKeys", 0,0), JS_SELF_HOSTED_FN("keys", "ArrayKeys", 0,0),
#ifdef NIGHTLY_BUILD
JS_SELF_HOSTED_FN("values", "ArrayValues", 0,0), JS_SELF_HOSTED_FN("values", "ArrayValues", 0,0),
#endif
/* ES7 additions */ /* ES7 additions */
JS_SELF_HOSTED_FN("includes", "ArrayIncludes", 2,0), JS_SELF_HOSTED_FN("includes", "ArrayIncludes", 2,0),

View file

@ -2936,6 +2936,11 @@ DefineFunctionFromSpec(JSContext* cx, HandleObject obj, const JSFunctionSpec* fs
if (!PropertySpecNameToId(cx, fs->name, &id)) if (!PropertySpecNameToId(cx, fs->name, &id))
return false; return false;
if (StandardProtoKeyOrNull(obj) == JSProto_Array && id == NameToId(cx->names().values)) {
if (!cx->options().arrayProtoValues())
return true;
}
JSFunction* fun = NewFunctionFromSpec(cx, fs, id); JSFunction* fun = NewFunctionFromSpec(cx, fs, id);
if (!fun) if (!fun)
return false; return false;

View file

@ -323,6 +323,7 @@ static bool enableNativeRegExp = false;
static bool enableUnboxedArrays = false; static bool enableUnboxedArrays = false;
static bool enableSharedMemory = SHARED_MEMORY_DEFAULT; static bool enableSharedMemory = SHARED_MEMORY_DEFAULT;
static bool enableWasmAlwaysBaseline = false; static bool enableWasmAlwaysBaseline = false;
static bool enableArrayProtoValues = true;
static bool printTiming = false; static bool printTiming = false;
static const char* jsCacheDir = nullptr; static const char* jsCacheDir = nullptr;
static const char* jsCacheAsmJSPath = nullptr; static const char* jsCacheAsmJSPath = nullptr;
@ -7264,6 +7265,7 @@ SetContextOptions(JSContext* cx, const OptionParser& op)
enableNativeRegExp = !op.getBoolOption("no-native-regexp"); enableNativeRegExp = !op.getBoolOption("no-native-regexp");
enableUnboxedArrays = op.getBoolOption("unboxed-arrays"); enableUnboxedArrays = op.getBoolOption("unboxed-arrays");
enableWasmAlwaysBaseline = op.getBoolOption("wasm-always-baseline"); enableWasmAlwaysBaseline = op.getBoolOption("wasm-always-baseline");
enableArrayProtoValues = !op.getBoolOption("no-array-proto-values");
JS::ContextOptionsRef(cx).setBaseline(enableBaseline) JS::ContextOptionsRef(cx).setBaseline(enableBaseline)
.setIon(enableIon) .setIon(enableIon)
@ -7271,7 +7273,8 @@ SetContextOptions(JSContext* cx, const OptionParser& op)
.setWasm(enableWasm) .setWasm(enableWasm)
.setWasmAlwaysBaseline(enableWasmAlwaysBaseline) .setWasmAlwaysBaseline(enableWasmAlwaysBaseline)
.setNativeRegExp(enableNativeRegExp) .setNativeRegExp(enableNativeRegExp)
.setUnboxedArrays(enableUnboxedArrays); .setUnboxedArrays(enableUnboxedArrays)
.setArrayProtoValues(enableArrayProtoValues);
if (op.getBoolOption("wasm-check-bce")) if (op.getBoolOption("wasm-check-bce"))
jit::JitOptions.wasmAlwaysCheckBounds = true; jit::JitOptions.wasmAlwaysCheckBounds = true;
@ -7542,7 +7545,8 @@ SetWorkerContextOptions(JSContext* cx)
.setWasm(enableWasm) .setWasm(enableWasm)
.setWasmAlwaysBaseline(enableWasmAlwaysBaseline) .setWasmAlwaysBaseline(enableWasmAlwaysBaseline)
.setNativeRegExp(enableNativeRegExp) .setNativeRegExp(enableNativeRegExp)
.setUnboxedArrays(enableUnboxedArrays); .setUnboxedArrays(enableUnboxedArrays)
.setArrayProtoValues(enableArrayProtoValues);
cx->setOffthreadIonCompilationEnabled(offthreadCompilation); cx->setOffthreadIonCompilationEnabled(offthreadCompilation);
cx->profilingScripts = enableCodeCoverage || enableDisassemblyDumps; cx->profilingScripts = enableCodeCoverage || enableDisassemblyDumps;
@ -7715,6 +7719,7 @@ main(int argc, char** argv, char** envp)
|| !op.addBoolOption('\0', "unboxed-arrays", "Allow creating unboxed arrays") || !op.addBoolOption('\0', "unboxed-arrays", "Allow creating unboxed arrays")
|| !op.addBoolOption('\0', "wasm-always-baseline", "Enable wasm baseline compiler when possible") || !op.addBoolOption('\0', "wasm-always-baseline", "Enable wasm baseline compiler when possible")
|| !op.addBoolOption('\0', "wasm-check-bce", "Always generate wasm bounds check, even redundant ones.") || !op.addBoolOption('\0', "wasm-check-bce", "Always generate wasm bounds check, even redundant ones.")
|| !op.addBoolOption('\0', "no-array-proto-values", "Remove Array.prototype.values")
#ifdef ENABLE_SHARED_ARRAY_BUFFER #ifdef ENABLE_SHARED_ARRAY_BUFFER
|| !op.addStringOption('\0', "shared-memory", "on/off", || !op.addStringOption('\0', "shared-memory", "on/off",
"SharedArrayBuffer and Atomics " "SharedArrayBuffer and Atomics "

View file

@ -1473,6 +1473,8 @@ ReloadPrefsCallback(const char* pref, void* data)
sExtraWarningsForSystemJS = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict.debug"); sExtraWarningsForSystemJS = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict.debug");
#endif #endif
bool arrayProtoValues = Preferences::GetBool(JS_OPTIONS_DOT_STR "array_prototype_values");
JS::ContextOptionsRef(cx).setBaseline(useBaseline) JS::ContextOptionsRef(cx).setBaseline(useBaseline)
.setIon(useIon) .setIon(useIon)
.setAsmJS(useAsmJS) .setAsmJS(useAsmJS)
@ -1484,7 +1486,8 @@ ReloadPrefsCallback(const char* pref, void* data)
.setThrowOnDebuggeeWouldRun(throwOnDebuggeeWouldRun) .setThrowOnDebuggeeWouldRun(throwOnDebuggeeWouldRun)
.setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun) .setDumpStackOnDebuggeeWouldRun(dumpStackOnDebuggeeWouldRun)
.setWerror(werror) .setWerror(werror)
.setExtraWarnings(extraWarnings); .setExtraWarnings(extraWarnings)
.setArrayProtoValues(arrayProtoValues);
JS_SetParallelParsingEnabled(cx, parallelParsing); JS_SetParallelParsingEnabled(cx, parallelParsing);
JS_SetOffthreadIonCompilationEnabled(cx, offthreadIonCompilation); JS_SetOffthreadIonCompilationEnabled(cx, offthreadIonCompilation);

View file

@ -198,9 +198,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
"pop", "shift", "unshift", "splice", "concat", "slice", "lastIndexOf", "indexOf", "pop", "shift", "unshift", "splice", "concat", "slice", "lastIndexOf", "indexOf",
"includes", "forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find", "includes", "forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find",
"findIndex", "copyWithin", "fill", Symbol.iterator, Symbol.unscopables, "entries", "keys", "findIndex", "copyWithin", "fill", Symbol.iterator, Symbol.unscopables, "entries", "keys",
"constructor"]; "values", "constructor"];
if (isNightlyBuild) { if (isNightlyBuild) {
gPrototypeProperties['Array'].push("values"); // ...nothing now
} }
gConstructorProperties['Array'] = gConstructorProperties['Array'] =
constructorProps(["join", "reverse", "sort", "push", "pop", "shift", constructorProps(["join", "reverse", "sort", "push", "pop", "shift",

View file

@ -1233,6 +1233,8 @@ pref("dom.webcomponents.enabled", false);
pref("dom.webcomponents.customelements.enabled", false); pref("dom.webcomponents.customelements.enabled", false);
pref("javascript.enabled", true); pref("javascript.enabled", true);
// Enable Array.prototype.values
pref("javascript.options.array_prototype_values", true);
pref("javascript.options.strict", false); pref("javascript.options.strict", false);
#ifdef DEBUG #ifdef DEBUG
pref("javascript.options.strict.debug", false); pref("javascript.options.strict.debug", false);