Skip to content

Commit

Permalink
Disallow anonymous function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bakker committed Nov 4, 2023
1 parent f085d50 commit b410fcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/org/mozilla/javascript/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,13 @@ private FunctionNode function(int type, boolean isGenerator) throws IOException
syntheticType = FunctionNode.FUNCTION_EXPRESSION;
}

if (syntheticType != FunctionNode.FUNCTION_EXPRESSION
&& name != null
&& name.length() > 0) {
// Function statements define a symbol in the enclosing scope
defineSymbol(Token.FUNCTION, name.getIdentifier());
if (syntheticType != FunctionNode.FUNCTION_EXPRESSION) {
if (name != null && name.length() > 0) {
// Function statements define a symbol in the enclosing scope
defineSymbol(Token.FUNCTION, name.getIdentifier());
} else {
reportError("msg.fn.missing.name");
}
}

FunctionNode fnNode = new FunctionNode(functionSourceStart, name);
Expand Down
3 changes: 3 additions & 0 deletions src/org/mozilla/javascript/resources/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ msg.let.decl.not.in.block =\
msg.bad.object.init =\
SyntaxError: invalid object initializer

msg.fn.missing.name =\
SyntaxError: function statements require a function name

# NodeTransformer
msg.dup.label =\
duplicated label
Expand Down

0 comments on commit b410fcb

Please sign in to comment.