Changeset 10416 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Aug 31, 2005, 11:36:47 AM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/grammar.y
r10352 r10416 668 668 669 669 FunctionDeclaration: 670 FUNCTION IDENT '(' ')' FunctionBody { $$ = new FuncDeclNode(*$2, $5); } 670 FUNCTION '(' ')' FunctionBody { YYABORT; } 671 | FUNCTION '(' FormalParameterList ')' FunctionBody 672 { YYABORT; } 673 | FUNCTION IDENT '(' ')' FunctionBody 674 { $$ = new FuncDeclNode(*$2, $5); } 671 675 | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody 672 676 { $$ = new FuncDeclNode(*$2, $4, $6); } 677 ; 673 678 674 679 FunctionExpr: 675 FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode( $4); }680 FUNCTION '(' ')' FunctionBody { $$ = new FuncExprNode(Identifier::null(), $4); } 676 681 | FUNCTION '(' FormalParameterList ')' FunctionBody 677 { $$ = new FuncExprNode($3, $5); } 678 682 { $$ = new FuncExprNode(Identifier::null(), $3, $5); } 683 | FUNCTION IDENT '(' ')' FunctionBody 684 { $$ = new FuncExprNode(*$2, $5); } 685 | FUNCTION IDENT '(' FormalParameterList ')' FunctionBody 686 { $$ = new FuncExprNode(*$2, $4, $6); } 679 687 ; 680 688 … … 704 712 705 713 SourceElement: 706 Statement{ $$ = $1; }707 | FunctionDeclaration{ $$ = $1; }714 FunctionDeclaration { $$ = $1; } 715 | Statement { $$ = $1; } 708 716 ; 709 717 -
trunk/JavaScriptCore/kjs/nodes.cpp
r10354 r10416 2118 2118 ValueImp *FuncExprNode::evaluate(ExecState *exec) 2119 2119 { 2120 FunctionImp *fimp = new DeclaredFunctionImp(exec, Identifier::null(), body.get(), exec->context().imp()->scopeChain()); 2120 ContextImp *context = exec->context().imp(); 2121 bool named = !ident.isNull(); 2122 ObjectImp *functionScopeObject = NULL; 2123 2124 if (named) { 2125 // named FunctionExpressions can recursively call themselves, 2126 // but they won't register with the current scope chain and should 2127 // be contained as single property in an anonymous object. 2128 functionScopeObject = new ObjectImp; 2129 context->pushScope(functionScopeObject); 2130 } 2131 2132 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2121 2133 ValueImp *ret(fimp); 2122 2134 ValueImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); … … 2126 2138 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 2127 2139 fimp->addParameter(p->ident()); 2140 2141 if (named) { 2142 functionScopeObject->put(exec, ident, ret, Internal | ReadOnly | (context->codeType() == EvalCode ? 0 : DontDelete)); 2143 context->popScope(); 2144 } 2128 2145 2129 2146 return ret; -
trunk/JavaScriptCore/kjs/nodes.h
r10399 r10416 971 971 class FuncExprNode : public Node { 972 972 public: 973 FuncExprNode(FunctionBodyNode *b) : param(0), body(b) { } 974 FuncExprNode(ParameterNode *p, FunctionBodyNode *b) 975 : param(p->next), body(b) { p->next = 0; } 976 ValueImp *evaluate(ExecState *exec); 977 virtual void streamTo(SourceStream &s) const; 978 private: 973 FuncExprNode(const Identifier &i, FunctionBodyNode *b) 974 : ident(i), param(0), body(b) { } 975 FuncExprNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b) 976 : ident(i), param(p->next), body(b) { p->next = 0; } 977 ValueImp *evaluate(ExecState *exec); 978 virtual void streamTo(SourceStream &s) const; 979 private: 980 Identifier ident; 979 981 KXMLCore::SharedPtr<ParameterNode> param; 980 982 KXMLCore::SharedPtr<FunctionBodyNode> body;
Note:
See TracChangeset
for help on using the changeset viewer.