From dcb43bda93f1f2cbe3da5ba1b7d3f783f1c8ad1c Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 13:04:58 -0400 Subject: 1317090: Remove js::FindBody; --- js/src/jsfun.cpp | 70 -------------------------------------------------------- 1 file changed, 70 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index e624aa415..3cba3434d 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -886,76 +886,6 @@ const Class JSFunction::class_ = { const Class* const js::FunctionClassPtr = &JSFunction::class_; -/* Find the body of a function (not including braces). */ -bool -js::FindBody(JSContext* cx, HandleFunction fun, HandleLinearString src, size_t* bodyStart, - size_t* bodyEnd) -{ - // We don't need principals, since those are only used for error reporting. - CompileOptions options(cx); - options.setFileAndLine("internal-findBody", 0); - - // For asm.js/wasm modules, there's no script. - if (fun->hasScript()) - options.setVersion(fun->nonLazyScript()->getVersion()); - - AutoKeepAtoms keepAtoms(cx->perThreadData); - - AutoStableStringChars stableChars(cx); - if (!stableChars.initTwoByte(cx, src)) - return false; - - const mozilla::Range srcChars = stableChars.twoByteRange(); - TokenStream ts(cx, options, srcChars.begin().get(), srcChars.length(), nullptr); - int nest = 0; - bool onward = true; - // Skip arguments list. - do { - TokenKind tt; - if (!ts.getToken(&tt)) - return false; - switch (tt) { - case TOK_NAME: - case TOK_YIELD: - if (nest == 0) - onward = false; - break; - case TOK_LP: - nest++; - break; - case TOK_RP: - if (--nest == 0) - onward = false; - break; - default: - break; - } - } while (onward); - TokenKind tt; - if (!ts.getToken(&tt)) - return false; - if (tt == TOK_ARROW) { - if (!ts.getToken(&tt)) - return false; - } - bool braced = tt == TOK_LC; - MOZ_ASSERT_IF(fun->isExprBody(), !braced); - *bodyStart = ts.currentToken().pos.begin; - if (braced) - *bodyStart += 1; - mozilla::RangedPtr end = srcChars.end(); - if (end[-1] == '}') { - end--; - } else { - MOZ_ASSERT(!braced); - for (; unicode::IsSpaceOrBOM2(end[-1]); end--) - ; - } - *bodyEnd = end - srcChars.begin(); - MOZ_ASSERT(*bodyStart <= *bodyEnd); - return true; -} - JSString* js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) { -- cgit v1.2.3 From 90d999c59a08bfc3145317aa4f0a92db0597632e Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 15:12:00 -0400 Subject: 1320403 - Move JSFunction::EXPR_BODY to JSScript, LazyScript, and FunctionBox. --- js/src/jsfun.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 3cba3434d..304700da2 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -980,8 +980,6 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) return nullptr; } } else { - MOZ_ASSERT(!fun->isExprBody()); - bool derived = fun->infallibleIsDefaultClassConstructor(cx); if (derived && fun->isDerivedClassConstructor()) { if (!AppendPrelude() || -- cgit v1.2.3 From 7535217e1b164417d9aa05c38e5c23048c8d47ce Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 15:15:05 -0400 Subject: 1325473 - A TypeError should be thrown when accessing 'arguments' or 'caller' on any of the new function types. --- js/src/jsfun.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 304700da2..ef5aea768 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -129,6 +129,11 @@ IsFunctionInStrictMode(JSFunction* fun) return IsAsmJSStrictModeModuleOrFunction(fun); } +static bool +IsNewerTypeFunction(JSFunction* fun) { + return fun->isArrow() || fun->isGenerator() || fun->isAsync() || fun->isMethod(); +} + // Beware: this function can be invoked on *any* function! That includes // natives, strict mode functions, bound functions, arrow functions, // self-hosted functions and constructors, asm.js functions, functions with @@ -142,7 +147,9 @@ ArgumentsRestrictions(JSContext* cx, HandleFunction fun) // a strict mode function, or a bound function. // TODO (bug 1057208): ensure semantics are correct for all possible // pairings of callee/caller. - if (fun->isBuiltin() || IsFunctionInStrictMode(fun) || fun->isBoundFunction()) { + if (fun->isBuiltin() || IsFunctionInStrictMode(fun) || + fun->isBoundFunction() || IsNewerTypeFunction(fun)) + { ThrowTypeErrorBehavior(cx); return false; } @@ -229,7 +236,9 @@ CallerRestrictions(JSContext* cx, HandleFunction fun) // a strict mode function, or a bound function. // TODO (bug 1057208): ensure semantics are correct for all possible // pairings of callee/caller. - if (fun->isBuiltin() || IsFunctionInStrictMode(fun) || fun->isBoundFunction()) { + if (fun->isBuiltin() || IsFunctionInStrictMode(fun) || + fun->isBoundFunction() || IsNewerTypeFunction(fun)) + { ThrowTypeErrorBehavior(cx); return false; } -- cgit v1.2.3 From af32c8553e54455ef8cbfe70a13f79f84c2163a4 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 16:16:14 -0400 Subject: 1325606 - Return wrapped async function from caller property. --- js/src/jsfun.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index ef5aea768..06d5cced7 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -284,6 +284,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args) } RootedObject caller(cx, iter.callee(cx)); + if (caller->is() && caller->as().isAsync()) + caller = GetWrappedAsyncFunction(&caller->as()); if (!cx->compartment()->wrap(cx, &caller)) return false; @@ -304,6 +306,8 @@ CallerGetterImpl(JSContext* cx, const CallArgs& args) } JSFunction* callerFun = &callerObj->as(); + if (IsWrappedAsyncFunction(callerFun)) + callerFun = GetUnwrappedAsyncFunction(callerFun); MOZ_ASSERT(!callerFun->isBuiltin(), "non-builtin iterator returned a builtin?"); if (callerFun->strict()) { -- cgit v1.2.3 From e5019fd4cf2142b7fe2cbfedaefcea300390393e Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 18:45:53 -0400 Subject: 1320408 - Part 1: Change JSFunction::getLength and JSFunction::getUnresolvedLength to static method. --- js/src/jsfun.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 06d5cced7..18ff875da 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -476,7 +476,7 @@ fun_resolve(JSContext* cx, HandleObject obj, HandleId id, bool* resolvedp) if (fun->hasResolvedLength()) return true; - if (!fun->getUnresolvedLength(cx, &v)) + if (!JSFunction::getUnresolvedLength(cx, fun, &v)) return false; } else { if (fun->hasResolvedName()) @@ -1242,34 +1242,33 @@ JSFunction::isDerivedClassConstructor() return derived; } -bool -JSFunction::getLength(JSContext* cx, uint16_t* length) +/* static */ bool +JSFunction::getLength(JSContext* cx, HandleFunction fun, uint16_t* length) { - JS::RootedFunction self(cx, this); - MOZ_ASSERT(!self->isBoundFunction()); - if (self->isInterpretedLazy() && !self->getOrCreateScript(cx)) + MOZ_ASSERT(!fun->isBoundFunction()); + if (fun->isInterpretedLazy() && !fun->getOrCreateScript(cx)) return false; - *length = self->isNative() ? self->nargs() : self->nonLazyScript()->funLength(); + *length = fun->isNative() ? fun->nargs() : fun->nonLazyScript()->funLength(); return true; } -bool -JSFunction::getUnresolvedLength(JSContext* cx, MutableHandleValue v) +/* static */ bool +JSFunction::getUnresolvedLength(JSContext* cx, HandleFunction fun, MutableHandleValue v) { - MOZ_ASSERT(!IsInternalFunctionObject(*this)); - MOZ_ASSERT(!hasResolvedLength()); + MOZ_ASSERT(!IsInternalFunctionObject(*fun)); + MOZ_ASSERT(!fun->hasResolvedLength()); // Bound functions' length can have values up to MAX_SAFE_INTEGER, so // they're handled differently from other functions. - if (isBoundFunction()) { - MOZ_ASSERT(getExtendedSlot(BOUND_FUN_LENGTH_SLOT).isNumber()); - v.set(getExtendedSlot(BOUND_FUN_LENGTH_SLOT)); + if (fun->isBoundFunction()) { + MOZ_ASSERT(fun->getExtendedSlot(BOUND_FUN_LENGTH_SLOT).isNumber()); + v.set(fun->getExtendedSlot(BOUND_FUN_LENGTH_SLOT)); return true; } uint16_t length; - if (!getLength(cx, &length)) + if (!JSFunction::getLength(cx, fun, &length)) return false; v.setInt32(length); -- cgit v1.2.3 From 739a81958035410ddd9b230354a56c909cc5c816 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 18:54:17 -0400 Subject: 1320408 - Part 2: Change JSFunction::getOrCreateScript to static method. --- js/src/jsfun.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 18ff875da..41f935080 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -902,7 +902,7 @@ const Class* const js::FunctionClassPtr = &JSFunction::class_; JSString* js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) { - if (fun->isInterpretedLazy() && !fun->getOrCreateScript(cx)) + if (fun->isInterpretedLazy() && !JSFunction::getOrCreateScript(cx, fun)) return nullptr; if (IsAsmJSModule(fun)) @@ -1246,7 +1246,7 @@ JSFunction::isDerivedClassConstructor() JSFunction::getLength(JSContext* cx, HandleFunction fun, uint16_t* length) { MOZ_ASSERT(!fun->isBoundFunction()); - if (fun->isInterpretedLazy() && !fun->getOrCreateScript(cx)) + if (fun->isInterpretedLazy() && !getOrCreateScript(cx, fun)) return false; *length = fun->isNative() ? fun->nargs() : fun->nonLazyScript()->funLength(); -- cgit v1.2.3 From c2b1e70b763660da2a41a826b4049360090ff373 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 19:05:28 -0400 Subject: 1320408 - Part 3: Remove JSContext* parameter from JSFunction::getBoundFunctionArgument. --- js/src/jsfun.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 41f935080..f032b822f 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1325,13 +1325,11 @@ GetBoundFunctionArguments(const JSFunction* boundFun) } const js::Value& -JSFunction::getBoundFunctionArgument(JSContext* cx, unsigned which) const +JSFunction::getBoundFunctionArgument(unsigned which) const { MOZ_ASSERT(which < getBoundFunctionArgumentCount()); - RootedArrayObject boundArgs(cx, GetBoundFunctionArguments(this)); - RootedValue res(cx); - return boundArgs->getDenseElement(which); + return GetBoundFunctionArguments(this)->getDenseElement(which); } size_t -- cgit v1.2.3 From af6768fb1f2e44b0bfe4136c79d8031028d073b1 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 19:20:00 -0400 Subject: 1320408 - Part 4: Change JSObject::getGroup to static method. --- js/src/jsfun.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index f032b822f..5a253217b 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -826,7 +826,7 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key) return nullptr; functionProto->initScript(script); - ObjectGroup* protoGroup = functionProto->getGroup(cx); + ObjectGroup* protoGroup = JSObject::getGroup(cx, functionProto); if (!protoGroup) return nullptr; -- cgit v1.2.3 From 4d88f48fdb51a29fd66001e87a74e2d6a130fe1f Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 19:52:00 -0400 Subject: 1320408 - Part 10: Change LazyScript::functionDelazifying to static method. --- js/src/jsfun.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 5a253217b..ea64aabe2 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1366,7 +1366,7 @@ JSFunction::createScriptForLazilyInterpretedFunction(JSContext* cx, HandleFuncti } if (fun != lazy->functionNonDelazifying()) { - if (!lazy->functionDelazifying(cx)) + if (!LazyScript::functionDelazifying(cx, lazy)) return false; script = lazy->functionNonDelazifying()->nonLazyScript(); if (!script) -- cgit v1.2.3 From 93335c3120968fac165a95978ef0dbdffe7900b4 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 21:10:15 -0400 Subject: 1320408 - Part 12: Change JSScript::sourceData to static method. --- js/src/jsfun.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index ea64aabe2..954fd47a0 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -973,7 +973,7 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) }; if (haveSource) { - Rooted src(cx, script->sourceDataWithPrelude(cx)); + Rooted src(cx, JSScript::sourceDataWithPrelude(cx, script)); if (!src) return nullptr; -- cgit v1.2.3 From 3a5176f4b25a2b90cefe14eb2c2de57113dc21ac Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 8 Jun 2019 23:28:04 -0400 Subject: 1320408 - Part 14: Change some GlobalObject methods to static method. --- js/src/jsfun.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 954fd47a0..3453a59e1 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -379,7 +379,7 @@ ResolveInterpretedFunctionPrototype(JSContext* cx, HandleFunction fun, HandleId if (isStarGenerator) objProto = GlobalObject::getOrCreateStarGeneratorObjectPrototype(cx, global); else - objProto = fun->global().getOrCreateObjectPrototype(cx); + objProto = GlobalObject::getOrCreateObjectPrototype(cx, global); if (!objProto) return false; -- cgit v1.2.3 From 50de15c3a64577f1523ec456df028dc20f539beb Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 7 Jul 2019 20:36:27 -0400 Subject: 1317387: The intrinsic %ThrowTypeError% function should be frozen. --- js/src/jsfun.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 3453a59e1..470746d50 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -861,6 +861,28 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key) if (!throwTypeError || !PreventExtensions(cx, throwTypeError)) return nullptr; + // The "length" property of %ThrowTypeError% is non-configurable, adjust + // the default property attributes accordingly. + Rooted nonConfigurableDesc(cx); + nonConfigurableDesc.setAttributes(JSPROP_PERMANENT | JSPROP_IGNORE_READONLY | + JSPROP_IGNORE_ENUMERATE | JSPROP_IGNORE_VALUE); + + RootedId lengthId(cx, NameToId(cx->names().length)); + ObjectOpResult lengthResult; + if (!NativeDefineProperty(cx, throwTypeError, lengthId, nonConfigurableDesc, lengthResult)) + return nullptr; + MOZ_ASSERT(lengthResult); + + // Non-standard: Also change "name" to non-configurable. ECMAScript defines + // %ThrowTypeError% as an anonymous function, i.e. it shouldn't actually + // get an own "name" property. To be consistent with other built-in, + // anonymous functions, we don't delete %ThrowTypeError%'s "name" property. + RootedId nameId(cx, NameToId(cx->names().name)); + ObjectOpResult nameResult; + if (!NativeDefineProperty(cx, throwTypeError, nameId, nonConfigurableDesc, nameResult)) + return nullptr; + MOZ_ASSERT(nameResult); + self->setThrowTypeError(throwTypeError); return functionProto; -- cgit v1.2.3 From 53e46b1e12ef01ccaabb3256738ea1eac74b7941 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 13 Jul 2019 21:33:52 -0400 Subject: 1216630 - Print class source when calling toString on the constructor. This is accomplished in the following ways. LazyScripts and JSScripts now have 4 offsets: - Source begin and end for the actual source. This is used for lazy parsing. - toString begin and end for toString. Some kinds of functions, like async, only have a different begin offset. Class constructors have different offsets for both begin and end. For syntactically present (i.e. non-default) constructors, the class source span is remembered directly on the LazyScript or JSScript. The toString implementation then splices out the substring directly. For default constructors, a new SRC_CLASS SrcNote type is added. It's binary and has as its arguments the begin and end offsets of the class expression or statement. MakeDefaultConstructor reads the note and overrides the cloned self-hosted function's source object. This is probably the least intrusive way to accomplish this. --- js/src/jsfun.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 470746d50..4f15e78c2 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -821,7 +821,7 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key) sourceObject, begin, ss->length(), - 0)); + 0, 0)); if (!script || !JSScript::initFunctionPrototype(cx, script, functionProto)) return nullptr; @@ -954,7 +954,13 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) } bool funIsNonArrowLambda = fun->isLambda() && !fun->isArrow(); - bool haveSource = fun->isInterpreted() && !fun->isSelfHostedBuiltin(); + + // Default class constructors are self-hosted, but have their source + // objects overridden to refer to the span of the class statement or + // expression. Non-default class constructors are never self-hosted. So, + // all class constructors always have source. + bool haveSource = fun->isInterpreted() && (fun->isClassConstructor() || + !fun->isSelfHostedBuiltin()); // If we're not in pretty mode, put parentheses around lambda functions // so that eval returns lambda, not function statement. @@ -995,7 +1001,7 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) }; if (haveSource) { - Rooted src(cx, JSScript::sourceDataWithPrelude(cx, script)); + Rooted src(cx, JSScript::sourceDataForToString(cx, script)); if (!src) return nullptr; @@ -1015,27 +1021,18 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) return nullptr; } } else { - bool derived = fun->infallibleIsDefaultClassConstructor(cx); - if (derived && fun->isDerivedClassConstructor()) { - if (!AppendPrelude() || - !out.append("(...args) {\n ") || - !out.append("super(...args);\n}")) - { - return nullptr; - } - } else { - if (!AppendPrelude() || - !out.append("() {\n ")) - return nullptr; + // Default class constructors should always haveSource. + MOZ_ASSERT(!fun->infallibleIsDefaultClassConstructor(cx)); - if (!derived) { - if (!out.append("[native code]")) - return nullptr; - } + if (!AppendPrelude() || + !out.append("() {\n ")) + return nullptr; - if (!out.append("\n}")) - return nullptr; - } + if (!out.append("[native code]")) + return nullptr; + + if (!out.append("\n}")) + return nullptr; } return out.finishString(); } -- cgit v1.2.3 From 22dba02b7bcab4d6dfe6b326ecc0a746e5a87191 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 13 Jul 2019 23:02:36 -0400 Subject: 1216630 - Rename preludeStart and postludeEnd to toStringStart and toStringEnd and misc fixes. --- js/src/jsfun.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 4f15e78c2..0886923fd 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -821,7 +821,8 @@ CreateFunctionPrototype(JSContext* cx, JSProtoKey key) sourceObject, begin, ss->length(), - 0, 0)); + 0, + ss->length())); if (!script || !JSScript::initFunctionPrototype(cx, script, functionProto)) return nullptr; -- cgit v1.2.3 From 7e510ee9b4dee7c2d15005baac89a2017f5673ef Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 13 Jul 2019 23:12:12 -0400 Subject: 1359622 - Fix assert for calling Function.toString on class constructors when the compartment has had source discarded. --- js/src/jsfun.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 0886923fd..06dc40162 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1022,8 +1022,10 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) return nullptr; } } else { - // Default class constructors should always haveSource. - MOZ_ASSERT(!fun->infallibleIsDefaultClassConstructor(cx)); + // Default class constructors should always haveSource unless source + // has been discarded for the whole compartment. + MOZ_ASSERT(!fun->infallibleIsDefaultClassConstructor(cx) || + fun->compartment()->behaviors().discardSource()); if (!AppendPrelude() || !out.append("() {\n ")) -- cgit v1.2.3 From 03df00e45ff4dd24b739a973d56edaf800313f7f Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 13 Jul 2019 23:21:45 -0400 Subject: 1367204 - Generate "[sourceless code]" for class constructors when sourceIsLazy and no source hook is set. --- js/src/jsfun.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'js/src/jsfun.cpp') diff --git a/js/src/jsfun.cpp b/js/src/jsfun.cpp index 06dc40162..9edf238ef 100644 --- a/js/src/jsfun.cpp +++ b/js/src/jsfun.cpp @@ -1013,7 +1013,20 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) if (!out.append(")")) return nullptr; } - } else if (fun->isInterpreted() && !fun->isSelfHostedBuiltin()) { + } else if (fun->isInterpreted() && + (!fun->isSelfHostedBuiltin() || + fun->infallibleIsDefaultClassConstructor(cx))) + { + // Default class constructors should always haveSource except; + // + // 1. Source has been discarded for the whole compartment. + // + // 2. The source is marked as "lazy", i.e., retrieved on demand, and + // the embedding has not provided a hook to retrieve sources. + MOZ_ASSERT_IF(fun->infallibleIsDefaultClassConstructor(cx), + !cx->runtime()->sourceHook || + !script->scriptSource()->sourceRetrievable() || + fun->compartment()->behaviors().discardSource()); if (!AppendPrelude() || !out.append("() {\n ") || !out.append("[sourceless code]") || @@ -1022,10 +1035,6 @@ js::FunctionToString(JSContext* cx, HandleFunction fun, bool prettyPrint) return nullptr; } } else { - // Default class constructors should always haveSource unless source - // has been discarded for the whole compartment. - MOZ_ASSERT(!fun->infallibleIsDefaultClassConstructor(cx) || - fun->compartment()->behaviors().discardSource()); if (!AppendPrelude() || !out.append("() {\n ")) -- cgit v1.2.3