summaryrefslogtreecommitdiffstats
path: root/js/src
diff options
context:
space:
mode:
Diffstat (limited to 'js/src')
-rw-r--r--js/src/frontend/BytecodeCompiler.cpp14
-rw-r--r--js/src/frontend/BytecodeEmitter.cpp4
-rw-r--r--js/src/frontend/Parser.cpp82
-rw-r--r--js/src/frontend/Parser.h18
-rw-r--r--js/src/frontend/SharedContext.h12
-rw-r--r--js/src/jsfun.cpp3
-rw-r--r--js/src/jsscript.cpp71
-rw-r--r--js/src/jsscript.h62
-rw-r--r--js/src/wasm/AsmJS.cpp14
9 files changed, 151 insertions, 129 deletions
diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp
index e0bb64e05..a1abbfeda 100644
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -248,11 +248,17 @@ BytecodeCompiler::createSourceAndParser(Maybe<uint32_t> parameterListEnd /* = No
}
bool
-BytecodeCompiler::createScript(uint32_t preludeStart /* = 0 */, uint32_t postludeEnd /* = 0 */)
+BytecodeCompiler::createScript()
+{
+ return createScript(0, sourceBuffer.length());
+}
+
+bool
+BytecodeCompiler::createScript(uint32_t toStringStart, uint32_t toStringEnd)
{
script = JSScript::Create(cx, options,
sourceObject, /* sourceStart = */ 0, sourceBuffer.length(),
- preludeStart, postludeEnd);
+ toStringStart, toStringEnd);
return script != nullptr;
}
@@ -464,7 +470,7 @@ BytecodeCompiler::compileStandaloneFunction(MutableHandleFunction fun,
if (fn->pn_funbox->function()->isInterpreted()) {
MOZ_ASSERT(fun == fn->pn_funbox->function());
- if (!createScript(fn->pn_funbox->preludeStart, fn->pn_funbox->postludeEnd))
+ if (!createScript(fn->pn_funbox->toStringStart, fn->pn_funbox->toStringEnd))
return false;
Maybe<BytecodeEmitter> emitter;
@@ -659,7 +665,7 @@ frontend::CompileLazyFunction(JSContext* cx, Handle<LazyScript*> lazy, const cha
Rooted<JSScript*> script(cx, JSScript::Create(cx, options, sourceObject,
lazy->begin(), lazy->end(),
- lazy->preludeStart(), lazy->postludeEnd()));
+ lazy->toStringStart(), lazy->toStringEnd()));
if (!script)
return false;
diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp
index c788e0086..7582e8df1 100644
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -7846,8 +7846,8 @@ BytecodeEmitter::emitFunction(ParseNode* pn, bool needsProto)
Rooted<JSObject*> sourceObject(cx, script->sourceObject());
Rooted<JSScript*> script(cx, JSScript::Create(cx, options, sourceObject,
funbox->bufStart, funbox->bufEnd,
- funbox->preludeStart,
- funbox->postludeEnd));
+ funbox->toStringStart,
+ funbox->toStringEnd));
if (!script)
return false;
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index 299b8b93a..1be57f8f5 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -458,7 +458,7 @@ UsedNameTracker::rewind(RewindToken token)
}
FunctionBox::FunctionBox(ExclusiveContext* cx, LifoAlloc& alloc, ObjectBox* traceListHead,
- JSFunction* fun, uint32_t preludeStart,
+ JSFunction* fun, uint32_t toStringStart,
Directives directives, bool extraWarnings,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind)
: ObjectBox(fun, traceListHead),
@@ -472,8 +472,8 @@ FunctionBox::FunctionBox(ExclusiveContext* cx, LifoAlloc& alloc, ObjectBox* trac
bufEnd(0),
startLine(1),
startColumn(0),
- preludeStart(preludeStart),
- postludeEnd(0),
+ toStringStart(toStringStart),
+ toStringEnd(0),
length(0),
generatorKindBits_(GeneratorKindAsBits(generatorKind)),
asyncKindBits_(AsyncKindAsBits(asyncKind)),
@@ -888,7 +888,7 @@ Parser<ParseHandler>::newObjectBox(JSObject* obj)
template <typename ParseHandler>
FunctionBox*
-Parser<ParseHandler>::newFunctionBox(Node fn, JSFunction* fun, uint32_t preludeStart,
+Parser<ParseHandler>::newFunctionBox(Node fn, JSFunction* fun, uint32_t toStringStart,
Directives inheritedDirectives,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
bool tryAnnexB)
@@ -904,7 +904,7 @@ Parser<ParseHandler>::newFunctionBox(Node fn, JSFunction* fun, uint32_t preludeS
* function.
*/
FunctionBox* funbox =
- alloc.new_<FunctionBox>(context, alloc, traceListHead, fun, preludeStart,
+ alloc.new_<FunctionBox>(context, alloc, traceListHead, fun, toStringStart,
inheritedDirectives, options().extraWarningsOption,
generatorKind, asyncKind);
if (!funbox) {
@@ -2404,7 +2404,7 @@ Parser<SyntaxParseHandler>::finishFunction(bool isStandaloneFunction /* = false
LazyScript* lazy = LazyScript::Create(context, fun, pc->closedOverBindingsForLazy(),
pc->innerFunctionsForLazy, versionNumber(),
funbox->bufStart, funbox->bufEnd,
- funbox->preludeStart,
+ funbox->toStringStart,
funbox->startLine, funbox->startColumn);
if (!lazy)
return false;
@@ -2495,7 +2495,7 @@ Parser<FullParseHandler>::standaloneFunction(HandleFunction fun,
return null();
fn->pn_body = argsbody;
- FunctionBox* funbox = newFunctionBox(fn, fun, /* preludeStart = */ 0, inheritedDirectives,
+ FunctionBox* funbox = newFunctionBox(fn, fun, /* toStringStart = */ 0, inheritedDirectives,
generatorKind, asyncKind, /* tryAnnexB = */ false);
if (!funbox)
return null();
@@ -3158,7 +3158,7 @@ Parser<ParseHandler>::functionArguments(YieldHandling yieldHandling, FunctionSyn
template <>
bool
-Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, uint32_t preludeStart,
+Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, uint32_t toStringStart,
FunctionSyntaxKind kind, bool tryAnnexB)
{
// When a lazily-parsed function is called, we only fully parse (and emit)
@@ -3168,7 +3168,7 @@ Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, uint32_t preludeS
RootedFunction fun(context, handler.nextLazyInnerFunction());
MOZ_ASSERT(!fun->isLegacyGenerator());
- FunctionBox* funbox = newFunctionBox(pn, fun, preludeStart, Directives(/* strict = */ false),
+ FunctionBox* funbox = newFunctionBox(pn, fun, toStringStart, Directives(/* strict = */ false),
fun->generatorKind(), fun->asyncKind(), tryAnnexB);
if (!funbox)
return false;
@@ -3205,7 +3205,7 @@ Parser<FullParseHandler>::skipLazyInnerFunction(ParseNode* pn, uint32_t preludeS
template <>
bool
-Parser<SyntaxParseHandler>::skipLazyInnerFunction(Node pn, uint32_t preludeStart,
+Parser<SyntaxParseHandler>::skipLazyInnerFunction(Node pn, uint32_t toStringStart,
FunctionSyntaxKind kind, bool tryAnnexB)
{
MOZ_CRASH("Cannot skip lazy inner functions when syntax parsing");
@@ -3282,7 +3282,7 @@ Parser<ParseHandler>::templateLiteral(YieldHandling yieldHandling)
template <typename ParseHandler>
typename ParseHandler::Node
-Parser<ParseHandler>::functionDefinition(uint32_t preludeStart, Node pn, InHandling inHandling,
+Parser<ParseHandler>::functionDefinition(uint32_t toStringStart, Node pn, InHandling inHandling,
YieldHandling yieldHandling,
HandleAtom funName, FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
@@ -3295,7 +3295,7 @@ Parser<ParseHandler>::functionDefinition(uint32_t preludeStart, Node pn, InHandl
// functions, which are also lazy. Instead, their free variables and
// source extents are recorded and may be skipped.
if (handler.canSkipLazyInnerFunctions()) {
- if (!skipLazyInnerFunction(pn, preludeStart, kind, tryAnnexB))
+ if (!skipLazyInnerFunction(pn, toStringStart, kind, tryAnnexB))
return null();
return pn;
}
@@ -3328,7 +3328,7 @@ Parser<ParseHandler>::functionDefinition(uint32_t preludeStart, Node pn, InHandl
// reparse a function due to failed syntax parsing and encountering new
// "use foo" directives.
while (true) {
- if (trySyntaxParseInnerFunction(pn, fun, preludeStart, inHandling, yieldHandling, kind,
+ if (trySyntaxParseInnerFunction(pn, fun, toStringStart, inHandling, yieldHandling, kind,
generatorKind, asyncKind, tryAnnexB, directives,
&newDirectives))
{
@@ -3357,7 +3357,7 @@ Parser<ParseHandler>::functionDefinition(uint32_t preludeStart, Node pn, InHandl
template <>
bool
Parser<FullParseHandler>::trySyntaxParseInnerFunction(ParseNode* pn, HandleFunction fun,
- uint32_t preludeStart,
+ uint32_t toStringStart,
InHandling inHandling,
YieldHandling yieldHandling,
FunctionSyntaxKind kind,
@@ -3391,13 +3391,13 @@ Parser<FullParseHandler>::trySyntaxParseInnerFunction(ParseNode* pn, HandleFunct
// Make a FunctionBox before we enter the syntax parser, because |pn|
// still expects a FunctionBox to be attached to it during BCE, and
// the syntax parser cannot attach one to it.
- FunctionBox* funbox = newFunctionBox(pn, fun, preludeStart, inheritedDirectives,
+ FunctionBox* funbox = newFunctionBox(pn, fun, toStringStart, inheritedDirectives,
generatorKind, asyncKind, tryAnnexB);
if (!funbox)
return false;
funbox->initWithEnclosingParseContext(pc, kind);
- if (!parser->innerFunction(SyntaxParseHandler::NodeGeneric, pc, funbox, preludeStart,
+ if (!parser->innerFunction(SyntaxParseHandler::NodeGeneric, pc, funbox, toStringStart,
inHandling, yieldHandling, kind,
inheritedDirectives, newDirectives))
{
@@ -3426,14 +3426,14 @@ Parser<FullParseHandler>::trySyntaxParseInnerFunction(ParseNode* pn, HandleFunct
} while (false);
// We failed to do a syntax parse above, so do the full parse.
- return innerFunction(pn, pc, fun, preludeStart, inHandling, yieldHandling, kind,
+ return innerFunction(pn, pc, fun, toStringStart, inHandling, yieldHandling, kind,
generatorKind, asyncKind, tryAnnexB, inheritedDirectives, newDirectives);
}
template <>
bool
Parser<SyntaxParseHandler>::trySyntaxParseInnerFunction(Node pn, HandleFunction fun,
- uint32_t preludeStart,
+ uint32_t toStringStart,
InHandling inHandling,
YieldHandling yieldHandling,
FunctionSyntaxKind kind,
@@ -3444,14 +3444,14 @@ Parser<SyntaxParseHandler>::trySyntaxParseInnerFunction(Node pn, HandleFunction
Directives* newDirectives)
{
// This is already a syntax parser, so just parse the inner function.
- return innerFunction(pn, pc, fun, preludeStart, inHandling, yieldHandling, kind,
+ return innerFunction(pn, pc, fun, toStringStart, inHandling, yieldHandling, kind,
generatorKind, asyncKind, tryAnnexB, inheritedDirectives, newDirectives);
}
template <typename ParseHandler>
bool
Parser<ParseHandler>::innerFunction(Node pn, ParseContext* outerpc, FunctionBox* funbox,
- uint32_t preludeStart,
+ uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind, Directives inheritedDirectives,
Directives* newDirectives)
@@ -3475,7 +3475,7 @@ Parser<ParseHandler>::innerFunction(Node pn, ParseContext* outerpc, FunctionBox*
template <typename ParseHandler>
bool
Parser<ParseHandler>::innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun,
- uint32_t preludeStart,
+ uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
@@ -3487,13 +3487,13 @@ Parser<ParseHandler>::innerFunction(Node pn, ParseContext* outerpc, HandleFuncti
// parser. In that case, outerpc is a ParseContext from the full parser
// instead of the current top of the stack of the syntax parser.
- FunctionBox* funbox = newFunctionBox(pn, fun, preludeStart, inheritedDirectives,
+ FunctionBox* funbox = newFunctionBox(pn, fun, toStringStart, inheritedDirectives,
generatorKind, asyncKind, tryAnnexB);
if (!funbox)
return false;
funbox->initWithEnclosingParseContext(outerpc, kind);
- return innerFunction(pn, outerpc, funbox, preludeStart, inHandling, yieldHandling, kind,
+ return innerFunction(pn, outerpc, funbox, toStringStart, inHandling, yieldHandling, kind,
inheritedDirectives, newDirectives);
}
@@ -3529,7 +3529,7 @@ Parser<FullParseHandler>::standaloneLazyFunction(HandleFunction fun, bool strict
return null();
Directives directives(strict);
- FunctionBox* funbox = newFunctionBox(pn, fun, /* preludeStart = */ 0, directives,
+ FunctionBox* funbox = newFunctionBox(pn, fun, /* toStringStart = */ 0, directives,
generatorKind, asyncKind, /* tryAnnexB = */ false);
if (!funbox)
return null();
@@ -3716,7 +3716,7 @@ Parser<ParseHandler>::functionFormalParametersAndBody(InHandling inHandling,
template <typename ParseHandler>
typename ParseHandler::Node
-Parser<ParseHandler>::functionStmt(uint32_t preludeStart, YieldHandling yieldHandling,
+Parser<ParseHandler>::functionStmt(uint32_t toStringStart, YieldHandling yieldHandling,
DefaultHandling defaultHandling, FunctionAsyncKind asyncKind)
{
MOZ_ASSERT(tokenStream.isCurrentTokenType(TOK_FUNCTION));
@@ -3800,13 +3800,13 @@ Parser<ParseHandler>::functionStmt(uint32_t preludeStart, YieldHandling yieldHan
return null();
YieldHandling newYieldHandling = GetYieldHandling(generatorKind, asyncKind);
- return functionDefinition(preludeStart, pn, InAllowed, newYieldHandling,
+ return functionDefinition(toStringStart, pn, InAllowed, newYieldHandling,
name, Statement, generatorKind, asyncKind, tryAnnexB);
}
template <typename ParseHandler>
typename ParseHandler::Node
-Parser<ParseHandler>::functionExpr(uint32_t preludeStart, InvokedPrediction invoked,
+Parser<ParseHandler>::functionExpr(uint32_t toStringStart, InvokedPrediction invoked,
FunctionAsyncKind asyncKind)
{
MOZ_ASSERT(tokenStream.isCurrentTokenType(TOK_FUNCTION));
@@ -3845,7 +3845,7 @@ Parser<ParseHandler>::functionExpr(uint32_t preludeStart, InvokedPrediction invo
if (invoked)
pn = handler.setLikelyIIFE(pn);
- return functionDefinition(preludeStart, pn, InAllowed, yieldHandling, name, Expression,
+ return functionDefinition(toStringStart, pn, InAllowed, yieldHandling, name, Expression,
generatorKind, asyncKind);
}
@@ -7122,13 +7122,13 @@ Parser<ParseHandler>::classDefinition(YieldHandling yieldHandling,
return null();
}
- // Amend the postlude offset for the constructor now that we've finished
- // parsing the class.
+ // Amend the toStringEnd offset for the constructor now that we've
+ // finished parsing the class.
uint32_t classEndOffset = pos().end;
if (FunctionBox* ctorbox = classStmt.constructorBox()) {
if (ctorbox->function()->isInterpretedLazy())
- ctorbox->function()->lazyScript()->setPostludeEnd(classEndOffset);
- ctorbox->postludeEnd = classEndOffset;
+ ctorbox->function()->lazyScript()->setToStringEnd(classEndOffset);
+ ctorbox->toStringEnd = classEndOffset;
}
Node nameNode = null();
@@ -7507,9 +7507,9 @@ Parser<ParseHandler>::statementListItem(YieldHandling yieldHandling,
if (!tokenStream.peekTokenSameLine(&nextSameLine))
return null();
if (nextSameLine == TOK_FUNCTION) {
- uint32_t preludeStart = pos().begin;
+ uint32_t toStringStart = pos().begin;
tokenStream.consumeKnownToken(TOK_FUNCTION);
- return functionStmt(preludeStart, yieldHandling, NameRequired, AsyncFunction);
+ return functionStmt(toStringStart, yieldHandling, NameRequired, AsyncFunction);
}
}
@@ -8053,7 +8053,7 @@ Parser<ParseHandler>::assignExpr(InHandling inHandling, YieldHandling yieldHandl
if (!tokenStream.getToken(&next, TokenStream::Operand))
return null();
- uint32_t preludeStart = pos().begin;
+ uint32_t toStringStart = pos().begin;
tokenStream.ungetToken();
GeneratorKind generatorKind = NotGenerator;
@@ -8078,7 +8078,7 @@ Parser<ParseHandler>::assignExpr(InHandling inHandling, YieldHandling yieldHandl
if (!pn)
return null();
- Node arrowFunc = functionDefinition(preludeStart, pn, inHandling, yieldHandling, nullptr,
+ Node arrowFunc = functionDefinition(toStringStart, pn, inHandling, yieldHandling, nullptr,
Arrow, generatorKind, asyncKind);
if (!arrowFunc)
return null();
@@ -8391,7 +8391,7 @@ Parser<ParseHandler>::generatorComprehensionLambda(unsigned begin)
// Create box for fun->object early to root it.
Directives directives(/* strict = */ outerpc->sc()->strict());
- FunctionBox* genFunbox = newFunctionBox(genfn, fun, /* preludeStart = */ 0, directives,
+ FunctionBox* genFunbox = newFunctionBox(genfn, fun, /* toStringStart = */ 0, directives,
StarGenerator, SyncFunction, /* tryAnnexB = */ false);
if (!genFunbox)
return null();
@@ -9662,7 +9662,7 @@ Parser<ParseHandler>::objectLiteral(YieldHandling yieldHandling, PossibleError*
template <typename ParseHandler>
typename ParseHandler::Node
-Parser<ParseHandler>::methodDefinition(uint32_t preludeStart, PropertyType propType,
+Parser<ParseHandler>::methodDefinition(uint32_t toStringStart, PropertyType propType,
HandleAtom funName)
{
FunctionSyntaxKind kind;
@@ -9716,7 +9716,7 @@ Parser<ParseHandler>::methodDefinition(uint32_t preludeStart, PropertyType propT
if (!pn)
return null();
- return functionDefinition(preludeStart, pn, InAllowed, yieldHandling, funName,
+ return functionDefinition(toStringStart, pn, InAllowed, yieldHandling, funName,
kind, generatorKind, asyncKind);
}
@@ -9845,9 +9845,9 @@ Parser<ParseHandler>::primaryExpr(YieldHandling yieldHandling, TripledotHandling
return null();
if (nextSameLine == TOK_FUNCTION) {
- uint32_t preludeStart = pos().begin;
+ uint32_t toStringStart = pos().begin;
tokenStream.consumeKnownToken(TOK_FUNCTION);
- return functionExpr(preludeStart, PredictUninvoked, AsyncFunction);
+ return functionExpr(toStringStart, PredictUninvoked, AsyncFunction);
}
}
diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h
index efb543efa..65e46a65e 100644
--- a/js/src/frontend/Parser.h
+++ b/js/src/frontend/Parser.h
@@ -1081,7 +1081,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
* cx->tempLifoAlloc.
*/
ObjectBox* newObjectBox(JSObject* obj);
- FunctionBox* newFunctionBox(Node fn, JSFunction* fun, uint32_t preludeStart,
+ FunctionBox* newFunctionBox(Node fn, JSFunction* fun, uint32_t toStringStart,
Directives directives,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
bool tryAnnexB);
@@ -1152,7 +1152,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
// Parse an inner function given an enclosing ParseContext and a
// FunctionBox for the inner function.
- bool innerFunction(Node pn, ParseContext* outerpc, FunctionBox* funbox, uint32_t preludeStart,
+ bool innerFunction(Node pn, ParseContext* outerpc, FunctionBox* funbox, uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
Directives inheritedDirectives, Directives* newDirectives);
@@ -1186,10 +1186,10 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
* Some parsers have two versions: an always-inlined version (with an 'i'
* suffix) and a never-inlined version (with an 'n' suffix).
*/
- Node functionStmt(uint32_t preludeStart,
+ Node functionStmt(uint32_t toStringStart,
YieldHandling yieldHandling, DefaultHandling defaultHandling,
FunctionAsyncKind asyncKind = SyncFunction);
- Node functionExpr(uint32_t preludeStart, InvokedPrediction invoked = PredictUninvoked,
+ Node functionExpr(uint32_t toStringStart, InvokedPrediction invoked = PredictUninvoked,
FunctionAsyncKind asyncKind = SyncFunction);
Node statementList(YieldHandling yieldHandling);
@@ -1338,7 +1338,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
bool tryNewTarget(Node& newTarget);
bool checkAndMarkSuperScope();
- Node methodDefinition(uint32_t preludeStart, PropertyType propType, HandleAtom funName);
+ Node methodDefinition(uint32_t toStringStart, PropertyType propType, HandleAtom funName);
/*
* Additional JS parsers.
@@ -1346,7 +1346,7 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
bool functionArguments(YieldHandling yieldHandling, FunctionSyntaxKind kind,
Node funcpn);
- Node functionDefinition(uint32_t preludeStart, Node pn,
+ Node functionDefinition(uint32_t toStringStart, Node pn,
InHandling inHandling, YieldHandling yieldHandling, HandleAtom name,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
@@ -1438,14 +1438,14 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
Node newDotGeneratorName();
bool declareDotGeneratorName();
- bool skipLazyInnerFunction(Node pn, uint32_t preludeStart, FunctionSyntaxKind kind,
+ bool skipLazyInnerFunction(Node pn, uint32_t toStringStart, FunctionSyntaxKind kind,
bool tryAnnexB);
- bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun, uint32_t preludeStart,
+ bool innerFunction(Node pn, ParseContext* outerpc, HandleFunction fun, uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind, bool tryAnnexB,
Directives inheritedDirectives, Directives* newDirectives);
- bool trySyntaxParseInnerFunction(Node pn, HandleFunction fun, uint32_t preludeStart,
+ bool trySyntaxParseInnerFunction(Node pn, HandleFunction fun, uint32_t toStringStart,
InHandling inHandling, YieldHandling yieldHandling,
FunctionSyntaxKind kind,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
diff --git a/js/src/frontend/SharedContext.h b/js/src/frontend/SharedContext.h
index 213a0a461..3499a53fb 100644
--- a/js/src/frontend/SharedContext.h
+++ b/js/src/frontend/SharedContext.h
@@ -451,8 +451,8 @@ class FunctionBox : public ObjectBox, public SharedContext
uint32_t bufEnd;
uint32_t startLine;
uint32_t startColumn;
- uint32_t preludeStart;
- uint32_t postludeEnd;
+ uint32_t toStringStart;
+ uint32_t toStringEnd;
uint16_t length;
uint8_t generatorKindBits_; /* The GeneratorKind of this function. */
@@ -482,7 +482,7 @@ class FunctionBox : public ObjectBox, public SharedContext
FunctionContextFlags funCxFlags;
FunctionBox(ExclusiveContext* cx, LifoAlloc& alloc, ObjectBox* traceListHead, JSFunction* fun,
- uint32_t preludeStart, Directives directives, bool extraWarnings,
+ uint32_t toStringStart, Directives directives, bool extraWarnings,
GeneratorKind generatorKind, FunctionAsyncKind asyncKind);
MutableHandle<LexicalScope::Data*> namedLambdaBindings() {
@@ -608,10 +608,10 @@ class FunctionBox : public ObjectBox, public SharedContext
void setEnd(uint32_t end) {
// For all functions except class constructors, the buffer and
- // postlude ending positions are the same. Class constructors override
- // the postlude ending position with the end of the class definition.
+ // toString ending positions are the same. Class constructors override
+ // the toString ending position with the end of the class definition.
bufEnd = end;
- postludeEnd = end;
+ toStringEnd = end;
}
void trace(JSTracer* trc) override;
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;
diff --git a/js/src/jsscript.cpp b/js/src/jsscript.cpp
index ad4cb2338..fc7438e3b 100644
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -235,8 +235,8 @@ XDRRelazificationInfo(XDRState<mode>* xdr, HandleFunction fun, HandleScript scri
{
uint32_t begin = script->sourceStart();
uint32_t end = script->sourceEnd();
- uint32_t preludeStart = script->preludeStart();
- uint32_t postludeEnd = script->postludeEnd();
+ uint32_t toStringStart = script->toStringStart();
+ uint32_t toStringEnd = script->toStringEnd();
uint32_t lineno = script->lineno();
uint32_t column = script->column();
@@ -244,8 +244,8 @@ XDRRelazificationInfo(XDRState<mode>* xdr, HandleFunction fun, HandleScript scri
packedFields = lazy->packedFields();
MOZ_ASSERT(begin == lazy->begin());
MOZ_ASSERT(end == lazy->end());
- MOZ_ASSERT(preludeStart == lazy->preludeStart());
- MOZ_ASSERT(postludeEnd == lazy->postludeEnd());
+ MOZ_ASSERT(toStringStart == lazy->toStringStart());
+ MOZ_ASSERT(toStringEnd == lazy->toStringEnd());
MOZ_ASSERT(lineno == lazy->lineno());
MOZ_ASSERT(column == lazy->column());
// We can assert we have no inner functions because we don't
@@ -259,12 +259,12 @@ XDRRelazificationInfo(XDRState<mode>* xdr, HandleFunction fun, HandleScript scri
if (mode == XDR_DECODE) {
lazy.set(LazyScript::Create(cx, fun, script, enclosingScope, script,
- packedFields, begin, end, preludeStart, lineno, column));
+ packedFields, begin, end, toStringStart, lineno, column));
if (!lazy)
return false;
- lazy->setPostludeEnd(postludeEnd);
+ lazy->setToStringEnd(toStringEnd);
// As opposed to XDRLazyScript, we need to restore the runtime bits
// of the script, as we are trying to match the fact this function
@@ -614,9 +614,9 @@ js::XDRScript(XDRState<mode>* xdr, HandleScope scriptEnclosingScope, HandleScrip
return false;
if (!xdr->codeUint32(&script->sourceEnd_))
return false;
- if (!xdr->codeUint32(&script->preludeStart_))
+ if (!xdr->codeUint32(&script->toStringStart_))
return false;
- if (!xdr->codeUint32(&script->postludeEnd_))
+ if (!xdr->codeUint32(&script->toStringEnd_))
return false;
if (!xdr->codeUint32(&lineno) ||
@@ -948,8 +948,8 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
{
uint32_t begin;
uint32_t end;
- uint32_t preludeStart;
- uint32_t postludeEnd;
+ uint32_t toStringStart;
+ uint32_t toStringEnd;
uint32_t lineno;
uint32_t column;
uint64_t packedFields;
@@ -963,16 +963,16 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
begin = lazy->begin();
end = lazy->end();
- preludeStart = lazy->preludeStart();
- postludeEnd = lazy->postludeEnd();
+ toStringStart = lazy->toStringStart();
+ toStringEnd = lazy->toStringEnd();
lineno = lazy->lineno();
column = lazy->column();
packedFields = lazy->packedFields();
}
if (!xdr->codeUint32(&begin) || !xdr->codeUint32(&end) ||
- !xdr->codeUint32(&preludeStart) ||
- !xdr->codeUint32(&postludeEnd) ||
+ !xdr->codeUint32(&toStringStart) ||
+ !xdr->codeUint32(&toStringEnd) ||
!xdr->codeUint32(&lineno) || !xdr->codeUint32(&column) ||
!xdr->codeUint64(&packedFields))
{
@@ -981,10 +981,10 @@ js::XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript
if (mode == XDR_DECODE) {
lazy.set(LazyScript::Create(cx, fun, nullptr, enclosingScope, enclosingScript,
- packedFields, begin, end, preludeStart, lineno, column));
+ packedFields, begin, end, toStringStart, lineno, column));
if (!lazy)
return false;
- lazy->setPostludeEnd(postludeEnd);
+ lazy->setToStringEnd(toStringEnd);
fun->initLazyScript(lazy);
}
}
@@ -1033,8 +1033,8 @@ JSScript::setDefaultClassConstructorSpan(JSObject* sourceObject, uint32_t start,
{
MOZ_ASSERT(isDefaultClassConstructor());
setSourceObject(sourceObject);
- preludeStart_ = start;
- postludeEnd_ = end;
+ toStringStart_ = start;
+ toStringEnd_ = end;
}
js::ScriptSourceObject&
@@ -1468,7 +1468,7 @@ JSScript::sourceData(JSContext* cx, HandleScript script)
JSScript::sourceDataForToString(JSContext* cx, HandleScript script)
{
MOZ_ASSERT(script->scriptSource()->hasSourceData());
- return script->scriptSource()->substring(cx, script->preludeStart(), script->postludeEnd());
+ return script->scriptSource()->substring(cx, script->toStringStart(), script->toStringEnd());
}
UncompressedSourceCache::AutoHoldEntry::AutoHoldEntry()
@@ -2470,9 +2470,15 @@ JSScript::initCompartment(ExclusiveContext* cx)
/* static */ JSScript*
JSScript::Create(ExclusiveContext* cx, const ReadOnlyCompileOptions& options,
HandleObject sourceObject, uint32_t bufStart, uint32_t bufEnd,
- uint32_t preludeStart, uint32_t postludeEnd)
+ uint32_t toStringStart, uint32_t toStringEnd)
{
+ // bufStart and bufEnd specify the range of characters parsed by the
+ // Parser to produce this script. toStringStart and toStringEnd specify
+ // the range of characters to be returned for Function.prototype.toString.
MOZ_ASSERT(bufStart <= bufEnd);
+ MOZ_ASSERT(toStringStart <= toStringEnd);
+ MOZ_ASSERT(toStringStart <= bufStart);
+ MOZ_ASSERT(toStringEnd >= bufEnd);
RootedScript script(cx, Allocate<JSScript>(cx));
if (!script)
@@ -2492,8 +2498,8 @@ JSScript::Create(ExclusiveContext* cx, const ReadOnlyCompileOptions& options,
script->setSourceObject(sourceObject);
script->sourceStart_ = bufStart;
script->sourceEnd_ = bufEnd;
- script->preludeStart_ = preludeStart;
- script->postludeEnd_ = postludeEnd;
+ script->toStringStart_ = toStringStart;
+ script->toStringEnd_ = toStringEnd;
return script;
}
@@ -3430,7 +3436,7 @@ CreateEmptyScriptForClone(JSContext* cx, HandleScript src)
.setVersion(src->getVersion());
return JSScript::Create(cx, options, sourceObject, src->sourceStart(), src->sourceEnd(),
- src->preludeStart(), src->postludeEnd());
+ src->toStringStart(), src->toStringEnd());
}
JSScript*
@@ -3981,7 +3987,7 @@ JSScript::formalLivesInArgumentsObject(unsigned argSlot)
LazyScript::LazyScript(JSFunction* fun, void* table, uint64_t packedFields,
uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column)
+ uint32_t toStringStart, uint32_t lineno, uint32_t column)
: script_(nullptr),
function_(fun),
enclosingScope_(nullptr),
@@ -3990,12 +3996,13 @@ LazyScript::LazyScript(JSFunction* fun, void* table, uint64_t packedFields,
packedFields_(packedFields),
begin_(begin),
end_(end),
- preludeStart_(preludeStart),
- postludeEnd_(end),
+ toStringStart_(toStringStart),
+ toStringEnd_(end),
lineno_(lineno),
column_(column)
{
MOZ_ASSERT(begin <= end);
+ MOZ_ASSERT(toStringStart <= begin);
}
void
@@ -4041,7 +4048,7 @@ LazyScript::maybeForwardedScriptSource() const
/* static */ LazyScript*
LazyScript::CreateRaw(ExclusiveContext* cx, HandleFunction fun,
uint64_t packedFields, uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column)
+ uint32_t toStringStart, uint32_t lineno, uint32_t column)
{
union {
PackedView p;
@@ -4070,7 +4077,7 @@ LazyScript::CreateRaw(ExclusiveContext* cx, HandleFunction fun,
cx->compartment()->scheduleDelazificationForDebugger();
return new (res) LazyScript(fun, table.forget(), packed, begin, end,
- preludeStart, lineno, column);
+ toStringStart, lineno, column);
}
/* static */ LazyScript*
@@ -4079,7 +4086,7 @@ LazyScript::Create(ExclusiveContext* cx, HandleFunction fun,
Handle<GCVector<JSFunction*, 8>> innerFunctions,
JSVersion version,
uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column)
+ uint32_t toStringStart, uint32_t lineno, uint32_t column)
{
union {
PackedView p;
@@ -4103,7 +4110,7 @@ LazyScript::Create(ExclusiveContext* cx, HandleFunction fun,
p.isDerivedClassConstructor = false;
p.needsHomeObject = false;
- LazyScript* res = LazyScript::CreateRaw(cx, fun, packedFields, begin, end, preludeStart,
+ LazyScript* res = LazyScript::CreateRaw(cx, fun, packedFields, begin, end, toStringStart,
lineno, column);
if (!res)
return nullptr;
@@ -4125,7 +4132,7 @@ LazyScript::Create(ExclusiveContext* cx, HandleFunction fun,
HandleScript script, HandleScope enclosingScope,
HandleScript enclosingScript,
uint64_t packedFields, uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column)
+ uint32_t toStringStart, uint32_t lineno, uint32_t column)
{
// Dummy atom which is not a valid property name.
RootedAtom dummyAtom(cx, cx->names().comma);
@@ -4134,7 +4141,7 @@ LazyScript::Create(ExclusiveContext* cx, HandleFunction fun,
// holding this lazy script.
HandleFunction dummyFun = fun;
- LazyScript* res = LazyScript::CreateRaw(cx, fun, packedFields, begin, end, preludeStart,
+ LazyScript* res = LazyScript::CreateRaw(cx, fun, packedFields, begin, end, toStringStart,
lineno, column);
if (!res)
return nullptr;
diff --git a/js/src/jsscript.h b/js/src/jsscript.h
index 8a21d394a..23ad44718 100644
--- a/js/src/jsscript.h
+++ b/js/src/jsscript.h
@@ -853,29 +853,36 @@ class JSScript : public js::gc::TenuredCell
uint32_t bodyScopeIndex_; /* index into the scopes array of the body scope */
- // Range of characters in scriptSource which contains this script's source.
- // each field points the following location.
+ // Range of characters in scriptSource which contains this script's
+ // source, that is, the range used by the Parser to produce this script.
+ //
+ // Most scripted functions have sourceStart_ == toStringStart_ and
+ // sourceEnd_ == toStringEnd_. However, for functions with extra
+ // qualifiers (e.g. generators, async) and for class constructors (which
+ // need to return the entire class source), their values differ.
+ //
+ // Each field points the following locations.
//
// function * f(a, b) { return a + b; }
// ^ ^ ^
// | | |
// | sourceStart_ sourceEnd_
- // |
- // preludeStart_
+ // | |
+ // toStringStart_ toStringEnd_
//
- // And, in the case of class constructors, an additional postlude offset
- // is used for use with toString.
+ // And, in the case of class constructors, an additional toStringEnd
+ // offset is used.
//
// class C { constructor() { this.field = 42; } }
// ^ ^ ^ ^
// | | | `---------`
// | sourceStart_ sourceEnd_ |
// | |
- // preludeStart_ postludeEnd_
+ // toStringStart_ toStringEnd_
uint32_t sourceStart_;
uint32_t sourceEnd_;
- uint32_t preludeStart_;
- uint32_t postludeEnd_;
+ uint32_t toStringStart_;
+ uint32_t toStringEnd_;
// Number of times the script has been called or has had backedges taken.
// When running in ion, also increased for any inlined scripts. Reset if
@@ -1049,7 +1056,7 @@ class JSScript : public js::gc::TenuredCell
const JS::ReadOnlyCompileOptions& options,
js::HandleObject sourceObject,
uint32_t sourceStart, uint32_t sourceEnd,
- uint32_t preludeStart, uint32_t postludeEnd);
+ uint32_t toStringStart, uint32_t toStringEnd);
void initCompartment(js::ExclusiveContext* cx);
@@ -1196,12 +1203,12 @@ class JSScript : public js::gc::TenuredCell
return sourceEnd_;
}
- uint32_t preludeStart() const {
- return preludeStart_;
+ uint32_t toStringStart() const {
+ return toStringStart_;
}
- uint32_t postludeEnd() const {
- return postludeEnd_;
+ uint32_t toStringEnd() const {
+ return toStringEnd_;
}
bool noScriptRval() const {
@@ -2004,15 +2011,15 @@ class LazyScript : public gc::TenuredCell
// See the comment in JSScript for the details.
uint32_t begin_;
uint32_t end_;
- uint32_t preludeStart_;
- uint32_t postludeEnd_;
+ uint32_t toStringStart_;
+ uint32_t toStringEnd_;
// Line and column of |begin_| position, that is the position where we
// start parsing.
uint32_t lineno_;
uint32_t column_;
LazyScript(JSFunction* fun, void* table, uint64_t packedFields,
- uint32_t begin, uint32_t end, uint32_t preludeStart,
+ uint32_t begin, uint32_t end, uint32_t toStringStart,
uint32_t lineno, uint32_t column);
// Create a LazyScript without initializing the closedOverBindings and the
@@ -2020,7 +2027,7 @@ class LazyScript : public gc::TenuredCell
// with valid atoms and functions.
static LazyScript* CreateRaw(ExclusiveContext* cx, HandleFunction fun,
uint64_t packedData, uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column);
+ uint32_t toStringStart, uint32_t lineno, uint32_t column);
public:
static const uint32_t NumClosedOverBindingsLimit = 1 << NumClosedOverBindingsBits;
@@ -2032,7 +2039,7 @@ class LazyScript : public gc::TenuredCell
const frontend::AtomVector& closedOverBindings,
Handle<GCVector<JSFunction*, 8>> innerFunctions,
JSVersion version, uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column);
+ uint32_t toStringStart, uint32_t lineno, uint32_t column);
// Create a LazyScript and initialize the closedOverBindings and the
// innerFunctions with dummy values to be replaced in a later initialization
@@ -2047,7 +2054,7 @@ class LazyScript : public gc::TenuredCell
HandleScript script, HandleScope enclosingScope,
HandleScript enclosingScript,
uint64_t packedData, uint32_t begin, uint32_t end,
- uint32_t preludeStart, uint32_t lineno, uint32_t column);
+ uint32_t toStringStart, uint32_t lineno, uint32_t column);
void initRuntimeFields(uint64_t packedFields);
@@ -2227,11 +2234,11 @@ class LazyScript : public gc::TenuredCell
uint32_t end() const {
return end_;
}
- uint32_t preludeStart() const {
- return preludeStart_;
+ uint32_t toStringStart() const {
+ return toStringStart_;
}
- uint32_t postludeEnd() const {
- return postludeEnd_;
+ uint32_t toStringEnd() const {
+ return toStringEnd_;
}
uint32_t lineno() const {
return lineno_;
@@ -2240,9 +2247,10 @@ class LazyScript : public gc::TenuredCell
return column_;
}
- void setPostludeEnd(uint32_t postludeEnd) {
- MOZ_ASSERT(postludeEnd_ >= end_);
- postludeEnd_ = postludeEnd;
+ void setToStringEnd(uint32_t toStringEnd) {
+ MOZ_ASSERT(toStringStart_ <= toStringEnd);
+ MOZ_ASSERT(toStringEnd_ >= end_);
+ toStringEnd_ = toStringEnd;
}
bool hasUncompiledEnclosingScript() const;
diff --git a/js/src/wasm/AsmJS.cpp b/js/src/wasm/AsmJS.cpp
index 51632a683..52b8eeed1 100644
--- a/js/src/wasm/AsmJS.cpp
+++ b/js/src/wasm/AsmJS.cpp
@@ -319,7 +319,7 @@ struct js::AsmJSMetadata : Metadata, AsmJSMetadataCacheablePod
// Function constructor, this will be the first character in the function
// source. Otherwise, it will be the opening parenthesis of the arguments
// list.
- uint32_t preludeStart;
+ uint32_t toStringStart;
uint32_t srcStart;
uint32_t srcBodyStart;
bool strict;
@@ -1760,7 +1760,7 @@ class MOZ_STACK_CLASS ModuleValidator
if (!asmJSMetadata_)
return false;
- asmJSMetadata_->preludeStart = moduleFunctionNode_->pn_funbox->preludeStart;
+ asmJSMetadata_->toStringStart = moduleFunctionNode_->pn_funbox->toStringStart;
asmJSMetadata_->srcStart = moduleFunctionNode_->pn_body->pn_pos.begin;
asmJSMetadata_->srcBodyStart = parser_.tokenStream.currentToken().pos.end;
asmJSMetadata_->strict = parser_.pc->sc()->strict() &&
@@ -7051,7 +7051,7 @@ ParseFunction(ModuleValidator& m, ParseNode** fnOut, unsigned* line)
TokenStream& tokenStream = m.tokenStream();
tokenStream.consumeKnownToken(TOK_FUNCTION, TokenStream::Operand);
- uint32_t preludeStart = tokenStream.currentToken().pos.begin;
+ uint32_t toStringStart = tokenStream.currentToken().pos.begin;
*line = tokenStream.srcCoords.lineNum(tokenStream.currentToken().pos.end);
TokenKind tk;
@@ -7074,7 +7074,7 @@ ParseFunction(ModuleValidator& m, ParseNode** fnOut, unsigned* line)
ParseContext* outerpc = m.parser().pc;
Directives directives(outerpc);
- FunctionBox* funbox = m.parser().newFunctionBox(fn, fun, preludeStart, directives, NotGenerator,
+ FunctionBox* funbox = m.parser().newFunctionBox(fn, fun, toStringStart, directives, NotGenerator,
SyncFunction, /* tryAnnexB = */ false);
if (!funbox)
return false;
@@ -8071,7 +8071,7 @@ HandleInstantiationFailure(JSContext* cx, CallArgs args, const AsmJSMetadata& me
return false;
}
- uint32_t begin = metadata.preludeStart;
+ uint32_t begin = metadata.toStringStart;
uint32_t end = metadata.srcEndAfterCurly();
Rooted<JSFlatString*> src(cx, source->substringDontDeflate(cx, begin, end));
if (!src)
@@ -8554,7 +8554,7 @@ LookupAsmJSModuleInCache(ExclusiveContext* cx, AsmJSParser& parser, bool* loaded
return true;
// See AsmJSMetadata comment as well as ModuleValidator::init().
- asmJSMetadata->preludeStart = parser.pc->functionBox()->preludeStart;
+ asmJSMetadata->toStringStart = parser.pc->functionBox()->toStringStart;
asmJSMetadata->srcStart = parser.pc->functionBox()->functionNode->pn_body->pn_pos.begin;
asmJSMetadata->srcBodyStart = parser.tokenStream.currentToken().pos.end;
asmJSMetadata->strict = parser.pc->sc()->strict() && !parser.pc->sc()->hasExplicitUseStrict();
@@ -8852,7 +8852,7 @@ js::AsmJSModuleToString(JSContext* cx, HandleFunction fun, bool addParenToLambda
MOZ_ASSERT(IsAsmJSModule(fun));
const AsmJSMetadata& metadata = AsmJSModuleFunctionToModule(fun).metadata().asAsmJS();
- uint32_t begin = metadata.preludeStart;
+ uint32_t begin = metadata.toStringStart;
uint32_t end = metadata.srcEndAfterCurly();
ScriptSource* source = metadata.scriptSource.get();