|
|
|
Lines 406-422
FunctionBox::FunctionBox(JSContext *cx,
|
Link Here
|
|---|
|
| 406 |
// eval(), so we have to look at |outerpc|'s scopeChain. |
406 |
// eval(), so we have to look at |outerpc|'s scopeChain. |
| 407 |
// |
407 |
// |
| 408 |
JSObject *scope = outerpc->sc->asGlobalSharedContext()->scopeChain(); |
408 |
JSObject *scope = outerpc->sc->asGlobalSharedContext()->scopeChain(); |
| 409 |
while (scope) { |
409 |
while (scope) { |
| 410 |
if (scope->isWith()) |
410 |
if (scope->isWith()) |
| 411 |
inWith = true; |
411 |
inWith = true; |
| 412 |
scope = scope->enclosingScope(); |
412 |
scope = scope->enclosingScope(); |
| 413 |
} |
413 |
} |
| 414 |
} else { |
414 |
} else if (outerpc->sc->isFunctionBox()) { |
| 415 |
// This is like the above case, but for more deeply nested functions. |
415 |
// This is like the above case, but for more deeply nested functions. |
| 416 |
// For example: |
416 |
// For example: |
| 417 |
// |
417 |
// |
| 418 |
// with (o) { eval("(function() { (function() { g(); })(); })();"); } } |
418 |
// with (o) { eval("(function() { (function() { g(); })(); })();"); } } |
| 419 |
// |
419 |
// |
| 420 |
// In this case, the inner anonymous function needs to inherit the |
420 |
// In this case, the inner anonymous function needs to inherit the |
| 421 |
// setting of |inWith| from the outer one. |
421 |
// setting of |inWith| from the outer one. |
| 422 |
FunctionBox *parent = outerpc->sc->asFunctionBox(); |
422 |
FunctionBox *parent = outerpc->sc->asFunctionBox(); |
|
Lines 1820-1835
Parser::functionArgsAndBody(ParseNode *p
|
Link Here
|
|---|
|
| 1820 |
|
1820 |
|
| 1821 |
if (!LeaveFunction(pn, this, funName, kind)) |
1821 |
if (!LeaveFunction(pn, this, funName, kind)) |
| 1822 |
return false; |
1822 |
return false; |
| 1823 |
|
1823 |
|
| 1824 |
return true; |
1824 |
return true; |
| 1825 |
} |
1825 |
} |
| 1826 |
|
1826 |
|
| 1827 |
ParseNode * |
1827 |
ParseNode * |
|
|
1828 |
Parser::moduleStmt() |
| 1829 |
{ |
| 1830 |
JS_ASSERT(versionNumber() == JSVERSION_ECMA_5); |
| 1831 |
JS_ASSERT(tokenStream.currentToken().name() == context->runtime->atomState.module); |
| 1832 |
if (!((pc->sc->isGlobalSharedContext() || pc->sc->isModuleBox()) && pc->atBodyLevel())) |
| 1833 |
{ |
| 1834 |
reportError(NULL, JSMSG_MODULE_STATEMENT); |
| 1835 |
return NULL; |
| 1836 |
} |
| 1837 |
|
| 1838 |
ParseNode *pn = ModuleNode::create(PNK_MODULE, this); |
| 1839 |
if (!pn) |
| 1840 |
return NULL; |
| 1841 |
JS_ALWAYS_TRUE(tokenStream.matchToken(TOK_STRING)); |
| 1842 |
Module *module = js_NewModule(context, tokenStream.currentToken().atom()); |
| 1843 |
if (!module) |
| 1844 |
return NULL; |
| 1845 |
ModuleBox *modulebox = newModuleBox(module, pc); |
| 1846 |
if (!modulebox) |
| 1847 |
return NULL; |
| 1848 |
pn->pn_modulebox = modulebox; |
| 1849 |
|
| 1850 |
ParseContext modulepc(this, modulebox, pc->staticLevel + 1, pc->blockidGen); |
| 1851 |
if (!modulepc.init()) |
| 1852 |
return NULL; |
| 1853 |
MUST_MATCH_TOKEN(TOK_LC, JSMSG_CURLY_BEFORE_MODULE); |
| 1854 |
pn->pn_body = statements(); |
| 1855 |
if (!pn->pn_body) |
| 1856 |
return NULL; |
| 1857 |
MUST_MATCH_TOKEN(TOK_RC, JSMSG_CURLY_AFTER_MODULE); |
| 1858 |
|
| 1859 |
return pn; |
| 1860 |
} |
| 1861 |
|
| 1862 |
ParseNode * |
| 1828 |
Parser::functionStmt() |
1863 |
Parser::functionStmt() |
| 1829 |
{ |
1864 |
{ |
| 1830 |
JS_ASSERT(tokenStream.currentToken().type == TOK_FUNCTION); |
1865 |
JS_ASSERT(tokenStream.currentToken().type == TOK_FUNCTION); |
| 1831 |
RootedPropertyName name(context); |
1866 |
RootedPropertyName name(context); |
| 1832 |
if (tokenStream.getToken(TSF_KEYWORD_IS_NAME) == TOK_NAME) { |
1867 |
if (tokenStream.getToken(TSF_KEYWORD_IS_NAME) == TOK_NAME) { |
| 1833 |
name = tokenStream.currentToken().name(); |
1868 |
name = tokenStream.currentToken().name(); |
| 1834 |
} else { |
1869 |
} else { |
| 1835 |
/* Unnamed function expressions are forbidden in statement context. */ |
1870 |
/* Unnamed function expressions are forbidden in statement context. */ |
|
Lines 4070-4085
Parser::statement()
|
Link Here
|
|---|
|
| 4070 |
pn->pn_kid = pn2; |
4105 |
pn->pn_kid = pn2; |
| 4071 |
break; |
4106 |
break; |
| 4072 |
} |
4107 |
} |
| 4073 |
#endif |
4108 |
#endif |
| 4074 |
|
4109 |
|
| 4075 |
case TOK_ERROR: |
4110 |
case TOK_ERROR: |
| 4076 |
return NULL; |
4111 |
return NULL; |
| 4077 |
|
4112 |
|
|
|
4113 |
case TOK_NAME: |
| 4114 |
if (versionNumber() == JSVERSION_ECMA_5 && |
| 4115 |
tokenStream.currentToken().name() == context->names().module && |
| 4116 |
tokenStream.peekTokenSameLine(TSF_OPERAND) == TOK_STRING) |
| 4117 |
{ |
| 4118 |
return moduleStmt(); |
| 4119 |
} |
| 4120 |
|
| 4078 |
default: |
4121 |
default: |
| 4079 |
return expressionStatement(); |
4122 |
return expressionStatement(); |
| 4080 |
} |
4123 |
} |
| 4081 |
|
4124 |
|
| 4082 |
/* Check termination of this primitive statement. */ |
4125 |
/* Check termination of this primitive statement. */ |
| 4083 |
return MatchOrInsertSemicolon(context, &tokenStream) ? pn : NULL; |
4126 |
return MatchOrInsertSemicolon(context, &tokenStream) ? pn : NULL; |
| 4084 |
} |
4127 |
} |
| 4085 |
|
4128 |
|