aboutsummaryrefslogtreecommitdiff
path: root/lib/parse.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse.js')
-rw-r--r--lib/parse.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/parse.js b/lib/parse.js
index 03455348..001587bc 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -800,7 +800,7 @@ function parse($TEXT, options) {
function embed_tokens(parser) {
return function() {
var start = S.token;
- var expr = parser();
+ var expr = parser.apply(null, arguments);
var end = prev();
expr.start = start;
expr.end = end;
@@ -815,7 +815,7 @@ function parse($TEXT, options) {
}
};
- var statement = embed_tokens(function() {
+ var statement = embed_tokens(function(strict_defun) {
handle_regexp();
switch (S.token.type) {
case "string":
@@ -901,6 +901,9 @@ function parse($TEXT, options) {
return for_();
case "function":
+ if (!strict_defun && S.input.has_directive("use strict")) {
+ croak("In strict mode code, functions can only be declared at top level or immediately within another function.");
+ }
next();
return function_(AST_Defun);
@@ -1083,7 +1086,7 @@ function parse($TEXT, options) {
S.input.push_directives_stack();
S.in_loop = 0;
S.labels = [];
- var body = block_();
+ var body = block_(true);
if (S.input.has_directive("use strict")) {
if (name) strict_verify_symbol(name);
argnames.forEach(strict_verify_symbol);
@@ -1112,12 +1115,12 @@ function parse($TEXT, options) {
});
};
- function block_() {
+ function block_(strict_defun) {
expect("{");
var a = [];
while (!is("punc", "}")) {
if (is("eof")) unexpected();
- a.push(statement());
+ a.push(statement(strict_defun));
}
next();
return a;
@@ -1630,7 +1633,7 @@ function parse($TEXT, options) {
var body = [];
S.input.push_directives_stack();
while (!is("eof"))
- body.push(statement());
+ body.push(statement(true));
S.input.pop_directives_stack();
var end = prev();
var toplevel = options.toplevel;