зеркало из https://github.com/mozilla/gecko-dev.git
Bug 568953 - Parser support for module declarations; r=jorendorff
This commit is contained in:
Родитель
ea7e486f59
Коммит
f54d765736
|
@ -412,7 +412,7 @@ FunctionBox::FunctionBox(JSContext *cx, ObjectBox* traceListHead, JSFunction *fu
|
|||
inWith = true;
|
||||
scope = scope->enclosingScope();
|
||||
}
|
||||
} else {
|
||||
} else if (outerpc->sc->isFunctionBox()) {
|
||||
// This is like the above case, but for more deeply nested functions.
|
||||
// For example:
|
||||
//
|
||||
|
@ -1845,6 +1845,41 @@ Parser::functionArgsAndBody(ParseNode *pn, HandleFunction fun, HandlePropertyNam
|
|||
return true;
|
||||
}
|
||||
|
||||
ParseNode *
|
||||
Parser::moduleDecl()
|
||||
{
|
||||
JS_ASSERT(tokenStream.currentToken().name() == context->runtime->atomState.module);
|
||||
if (!((pc->sc->isGlobalSharedContext() || pc->sc->isModuleBox()) && pc->atBodyLevel()))
|
||||
{
|
||||
reportError(NULL, JSMSG_MODULE_STATEMENT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ParseNode *pn = CodeNode::create(PNK_MODULE, this);
|
||||
if (!pn)
|
||||
return NULL;
|
||||
JS_ALWAYS_TRUE(tokenStream.matchToken(TOK_STRING));
|
||||
RootedAtom atom(context, tokenStream.currentToken().atom());
|
||||
Module *module = js_NewModule(context, atom);
|
||||
if (!module)
|
||||
return NULL;
|
||||
ModuleBox *modulebox = newModuleBox(module, pc);
|
||||
if (!modulebox)
|
||||
return NULL;
|
||||
pn->pn_modulebox = modulebox;
|
||||
|
||||
ParseContext modulepc(this, modulebox, pc->staticLevel + 1, pc->blockidGen);
|
||||
if (!modulepc.init())
|
||||
return NULL;
|
||||
MUST_MATCH_TOKEN(TOK_LC, JSMSG_CURLY_BEFORE_MODULE);
|
||||
pn->pn_body = statements();
|
||||
if (!pn->pn_body)
|
||||
return NULL;
|
||||
MUST_MATCH_TOKEN(TOK_RC, JSMSG_CURLY_AFTER_MODULE);
|
||||
|
||||
return pn;
|
||||
}
|
||||
|
||||
ParseNode *
|
||||
Parser::functionStmt()
|
||||
{
|
||||
|
@ -4047,6 +4082,13 @@ Parser::statement()
|
|||
case TOK_ERROR:
|
||||
return NULL;
|
||||
|
||||
case TOK_NAME:
|
||||
if (tokenStream.currentToken().name() == context->names().module &&
|
||||
tokenStream.peekTokenSameLine(TSF_OPERAND) == TOK_STRING)
|
||||
{
|
||||
return moduleDecl();
|
||||
}
|
||||
|
||||
default:
|
||||
return expressionStatement();
|
||||
}
|
||||
|
|
|
@ -374,6 +374,7 @@ struct Parser : private AutoGCRooter
|
|||
* Some parsers have two versions: an always-inlined version (with an 'i'
|
||||
* suffix) and a never-inlined version (with an 'n' suffix).
|
||||
*/
|
||||
ParseNode *moduleDecl();
|
||||
ParseNode *functionStmt();
|
||||
ParseNode *functionExpr();
|
||||
ParseNode *statements(bool *hasFunctionStmt = NULL);
|
||||
|
|
|
@ -388,3 +388,6 @@ MSG_DEF(JSMSG_INVALID_CURRENCY_CODE, 334, 1, JSEXN_RANGEERR, "invalid currency
|
|||
MSG_DEF(JSMSG_UNDEFINED_CURRENCY, 335, 0, JSEXN_TYPEERR, "undefined currency in NumberFormat() with currency style")
|
||||
MSG_DEF(JSMSG_INVALID_TIME_ZONE, 336, 1, JSEXN_RANGEERR, "invalid time zone in DateTimeFormat(): {0}")
|
||||
MSG_DEF(JSMSG_DATE_NOT_FINITE, 337, 0, JSEXN_RANGEERR, "date value is not finite in DateTimeFormat.format()")
|
||||
MSG_DEF(JSMSG_MODULE_STATEMENT, 338, 0, JSEXN_SYNTAXERR, "module declarations may only appear at the top level of a program or module body")
|
||||
MSG_DEF(JSMSG_CURLY_BEFORE_MODULE, 339, 0, JSEXN_SYNTAXERR, "missing { before module body")
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_MODULE, 340, 0, JSEXN_SYNTAXERR, "missing } after module body")
|
||||
|
|
|
@ -87,6 +87,7 @@
|
|||
macro(lookupGetter, lookupGetter, "__lookupGetter__") \
|
||||
macro(lookupSetter, lookupSetter, "__lookupSetter__") \
|
||||
macro(message, message, "message") \
|
||||
macro(module, module, "module") \
|
||||
macro(multiline, multiline, "multiline") \
|
||||
macro(name, name, "name") \
|
||||
macro(NaN, NaN, "NaN") \
|
||||
|
|
Загрузка…
Ссылка в новой задаче