Bug 1545751 - In BinAST, pass Context while parsing;r=arai

The Context 0.1 format specifies that the (de)compression of nodes is determined by:
- its node type;
- its parent type;
- the index in the parent node;
- whether the node is an element of an array.

This patch modifies the parser generator to pass the information during parsing.

Differential Revision: https://phabricator.services.mozilla.com/D28534
This commit is contained in:
David Teller
2019-04-29 17:24:55 +00:00
parent b86c18e75d
commit 1f9fc2902b
10 changed files with 1595 additions and 989 deletions

View File

@@ -132,7 +132,8 @@ JS::Result<ParseNode*> BinASTParserPerTokenizer<Tok>::parseAux(
MOZ_TRY(tokenizer_->readHeader());
ParseNode* result(nullptr);
MOZ_TRY_VAR(result, asFinalParser()->parseProgram());
const Context topContext(Context::topLevel());
MOZ_TRY_VAR(result, asFinalParser()->parseProgram(topContext));
mozilla::Maybe<GlobalScope::Data*> bindings =
NewGlobalScopeData(cx_, varScope, alloc_, pc_);
@@ -191,7 +192,12 @@ JS::Result<FunctionNode*> BinASTParserPerTokenizer<Tok>::parseLazyFunction(
ListNode* tmpBody;
auto parseFunc = isExpr ? &FinalParser::parseFunctionExpressionContents
: &FinalParser::parseFunctionOrMethodContents;
MOZ_TRY((asFinalParser()->*parseFunc)(func->nargs(), &params, &tmpBody));
// Inject a toplevel context (i.e. no parent) to parse the lazy content.
// In the future, we may move this to a more specific context.
const Context context(Context::topLevel());
MOZ_TRY(
(asFinalParser()->*parseFunc)(func->nargs(), &params, &tmpBody, context));
BINJS_TRY_DECL(lexicalScopeData,
NewLexicalScopeData(cx_, lexicalScope, alloc_, pc_));