[webkit-changes] cvs commit: JavaScriptCore/kjs grammar.y nodes.cpp
nodes.h
Geoffrey
ggaren at opensource.apple.com
Wed Aug 31 11:36:49 PDT 2005
ggaren 05/08/31 11:36:48
Modified: . ChangeLog
kjs grammar.y nodes.cpp nodes.h
Log:
-rolled in fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=4698
kjs does not allow named functions in function expressions
Fix by Arthur Langereis.
Reviewed by darin.
* kjs/grammar.y:
* kjs/nodes.cpp:
(FuncExprNode::evaluate):
* kjs/nodes.h:
(KJS::FuncExprNode::FuncExprNode):
Test cases added:
* layout-tests/fast/js/named-function-expression-expected.txt: Added.
* layout-tests/fast/js/named-function-expression.html: Added.
Revision Changes Path
1.812 +20 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.811
retrieving revision 1.812
diff -u -r1.811 -r1.812
--- ChangeLog 31 Aug 2005 07:57:55 -0000 1.811
+++ ChangeLog 31 Aug 2005 18:36:44 -0000 1.812
@@ -1,3 +1,23 @@
+2005-08-31 Geoffrey Garen <ggaren at apple.com>
+
+ -rolled in fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=4698
+ kjs does not allow named functions in function expressions
+
+ Fix by Arthur Langereis.
+
+ Reviewed by darin.
+
+ * kjs/grammar.y:
+ * kjs/nodes.cpp:
+ (FuncExprNode::evaluate):
+ * kjs/nodes.h:
+ (KJS::FuncExprNode::FuncExprNode):
+
+ Test cases added:
+
+ * layout-tests/fast/js/named-function-expression-expected.txt: Added.
+ * layout-tests/fast/js/named-function-expression.html: Added.
+
2005-08-31 Justin Haygood <justin at xiondigital.net>
Reviewed, tweaked, and landed by Darin.
1.27 +14 -6 JavaScriptCore/kjs/grammar.y
Index: grammar.y
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/grammar.y,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- grammar.y 26 Aug 2005 23:42:17 -0000 1.26
+++ grammar.y 31 Aug 2005 18:36:47 -0000 1.27
@@ -667,15 +667,23 @@
;
FunctionDeclaration:
- FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncDeclNode(*$2, $5); }
+ FUNCTION '(' ')' FunctionBody { YYABORT; }
+ | FUNCTION '(' FormalParameterList ')' FunctionBody
+ { YYABORT; }
+ | FUNCTION IDENT '(' ')' FunctionBody
+ { $$ = new FuncDeclNode(*$2, $5); }
| FUNCTION IDENT '(' FormalParameterList ')' FunctionBody
{ $$ = new FuncDeclNode(*$2, $4, $6); }
+;
FunctionExpr:
- FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode($4); }
+ FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode(Identifier::null(), $4); }
| FUNCTION '(' FormalParameterList ')' FunctionBody
- { $$ = new FuncExprNode($3, $5); }
-
+ { $$ = new FuncExprNode(Identifier::null(), $3, $5); }
+ | FUNCTION IDENT '(' ')' FunctionBody
+ { $$ = new FuncExprNode(*$2, $5); }
+ | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody
+ { $$ = new FuncExprNode(*$2, $4, $6); }
;
FormalParameterList:
@@ -703,8 +711,8 @@
;
SourceElement:
- Statement { $$ = $1; }
- | FunctionDeclaration { $$ = $1; }
+ FunctionDeclaration { $$ = $1; }
+ | Statement { $$ = $1; }
;
%%
1.79 +18 -1 JavaScriptCore/kjs/nodes.cpp
Index: nodes.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/nodes.cpp,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- nodes.cpp 26 Aug 2005 23:46:27 -0000 1.78
+++ nodes.cpp 31 Aug 2005 18:36:47 -0000 1.79
@@ -2117,7 +2117,19 @@
// ECMA 13
ValueImp *FuncExprNode::evaluate(ExecState *exec)
{
- FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body.get(), exec->context().imp()->scopeChain());
+ ContextImp *context = exec->context().imp();
+ bool named = !ident.isNull();
+ ObjectImp *functionScopeObject = NULL;
+
+ if (named) {
+ // named FunctionExpressions can recursively call themselves,
+ // but they won't register with the current scope chain and should
+ // be contained as single property in an anonymous object.
+ functionScopeObject = new ObjectImp;
+ context->pushScope(functionScopeObject);
+ }
+
+ FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain());
ValueImp *ret(fimp);
ValueImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty());
fimp->put(exec, prototypePropertyName, proto, Internal|DontDelete);
@@ -2126,6 +2138,11 @@
for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++)
fimp->addParameter(p->ident());
+ if (named) {
+ functionScopeObject->put(exec, ident, ret, Internal | ReadOnly | (context->codeType() == EvalCode ? 0 : DontDelete));
+ context->popScope();
+ }
+
return ret;
}
1.31 +5 -3 JavaScriptCore/kjs/nodes.h
Index: nodes.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/nodes.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- nodes.h 30 Aug 2005 23:56:14 -0000 1.30
+++ nodes.h 31 Aug 2005 18:36:47 -0000 1.31
@@ -970,12 +970,14 @@
class FuncExprNode : public Node {
public:
- FuncExprNode(FunctionBodyNode *b) : param(0), body(b) { }
- FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
- : param(p->next), body(b) { p->next = 0; }
+ FuncExprNode(const Identifier &i, FunctionBodyNode *b)
+ : ident(i), param(0), body(b) { }
+ FuncExprNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
+ : ident(i), param(p->next), body(b) { p->next = 0; }
ValueImp *evaluate(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
+ Identifier ident;
KXMLCore::SharedPtr<ParameterNode> param;
KXMLCore::SharedPtr<FunctionBodyNode> body;
};
More information about the webkit-changes
mailing list