Changeset 10646 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp
- Timestamp:
- Sep 28, 2005, 11:51:15 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes.cpp
r10636 r10646 60 60 if (exec->hadException()) { \ 61 61 setExceptionDetailsIfNeeded(exec); \ 62 return Completion(Throw, exec->exception()); \ 62 ValueImp *ex = exec->exception(); \ 63 exec->clearException(); \ 64 return Completion(Throw, ex); \ 63 65 } \ 64 66 if (Collector::outOfMemory()) \ … … 68 70 if (exec->hadException()) { \ 69 71 setExceptionDetailsIfNeeded(exec); \ 70 return exec->exception(); \72 return Undefined(); \ 71 73 } \ 72 74 if (Collector::outOfMemory()) \ … … 81 83 return List(); // will be picked up by KJS_CHECKEXCEPTION 82 84 83 #ifdef KJS_DEBUG_MEM84 std::list<Node *> * Node::s_nodes = 0L;85 #endif86 87 85 // ------------------------------ Node ----------------------------------------- 88 86 … … 99 97 } 100 98 101 #ifdef KJS_DEBUG_MEM102 void Node::finalCheck()103 {104 fprintf( stderr, "Node::finalCheck(): list count : %d\n", (int)s_nodes.size() );105 std::list<Node *>::iterator it = s_nodes->begin();106 for ( unsigned i = 0; it != s_nodes->end() ; ++it, ++i )107 fprintf( stderr, "[%d] Still having node %p (%s) (refcount %d)\n", i, (void*)*it, typeid( **it ).name(), (*it)->refcount );108 delete s_nodes;109 s_nodes = 0L;110 }111 #endif112 113 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg)114 {115 return KJS::throwError(exec, e, msg, lineNo(), sourceId(), &sourceURL);116 }117 118 99 static void substitute(UString &string, const UString &substring) 119 100 { … … 121 102 assert(position != -1); 122 103 string = string.substr(0, position) + substring + string.substr(position + 2); 104 } 105 106 Completion Node::createErrorCompletion(ExecState *exec, ErrorType e, const char *msg) 107 { 108 return Completion(Throw, Error::create(exec, e, msg, lineNo(), sourceId(), &sourceURL)); 109 } 110 111 Completion Node::createErrorCompletion(ExecState *exec, ErrorType e, const char *msg, const Identifier &ident) 112 { 113 UString message = msg; 114 substitute(message, ident.ustring()); 115 return Completion(Throw, Error::create(exec, e, message, lineNo(), sourceId(), &sourceURL)); 116 } 117 118 ValueImp *Node::throwError(ExecState *exec, ErrorType e, const char *msg) 119 { 120 return KJS::throwError(exec, e, msg, lineNo(), sourceId(), &sourceURL); 123 121 } 124 122 … … 163 161 substitute(message, label.ustring()); 164 162 return KJS::throwError(exec, e, message, lineNo(), sourceId(), &sourceURL); 163 } 164 165 ValueImp *Node::throwUndefinedVariableError(ExecState *exec, const Identifier &ident) 166 { 167 return throwError(exec, ReferenceError, "Can't find variable: %s", ident); 165 168 } 166 169 … … 177 180 } 178 181 182 Node *Node::nodeInsideAllParens() 183 { 184 return this; 185 } 186 179 187 // ------------------------------ StatementNode -------------------------------- 180 188 … … 200 208 } 201 209 202 // return true if the debugger wants us to stop at this point203 bool StatementNode::abortStatement(ExecState *exec)204 {205 Debugger *dbg = exec->dynamicInterpreter()->imp()->debugger();206 if (dbg)207 return dbg->imp()->aborted();208 else209 return false;210 }211 212 210 void StatementNode::processFuncDecl(ExecState *exec) 213 211 { … … 216 214 // ------------------------------ NullNode ------------------------------------- 217 215 218 ValueImp *NullNode::evaluate(ExecState * /*exec*/)216 ValueImp *NullNode::evaluate(ExecState *) 219 217 { 220 218 return Null(); … … 223 221 // ------------------------------ BooleanNode ---------------------------------- 224 222 225 ValueImp *BooleanNode::evaluate(ExecState * /*exec*/)223 ValueImp *BooleanNode::evaluate(ExecState *) 226 224 { 227 225 return jsBoolean(value); … … 230 228 // ------------------------------ NumberNode ----------------------------------- 231 229 232 ValueImp *NumberNode::evaluate(ExecState * /*exec*/)230 ValueImp *NumberNode::evaluate(ExecState *) 233 231 { 234 232 return jsNumber(value); … … 237 235 // ------------------------------ StringNode ----------------------------------- 238 236 239 ValueImp *StringNode::evaluate(ExecState * /*exec*/)237 ValueImp *StringNode::evaluate(ExecState *) 240 238 { 241 239 return jsString(value); … … 263 261 264 262 // ------------------------------ ResolveNode ---------------------------------- 265 266 static ValueImp *undefinedVariableError(ExecState *exec, const Identifier &ident)267 {268 return throwError(exec, ReferenceError, "Can't find variable: " + ident.ustring());269 }270 263 271 264 // ECMA 11.1.2 & 10.1.4 … … 289 282 } while (iter != end); 290 283 291 return undefinedVariableError(exec, ident);284 return throwUndefinedVariableError(exec, ident); 292 285 } 293 286 … … 298 291 { 299 292 return group->evaluate(exec); 293 } 294 295 Node *GroupNode::nodeInsideAllParens() 296 { 297 Node *n = this; 298 do 299 n = static_cast<GroupNode *>(n)->group.get(); 300 while (n->isGroupNode()); 301 return n; 300 302 } 301 303 … … 373 375 374 376 // ECMA 11.1.5 375 ValueImp *PropertyNode::evaluate(ExecState * /*exec*/)377 ValueImp *PropertyNode::evaluate(ExecState *) 376 378 { 377 379 ValueImp *s; … … 415 417 // ------------------------------ ArgumentListNode ----------------------------- 416 418 417 ValueImp *ArgumentListNode::evaluate(ExecState * /*exec*/)419 ValueImp *ArgumentListNode::evaluate(ExecState *) 418 420 { 419 421 assert(0); 420 return NULL; // dummy, see evaluateList()422 return 0; // dummy, see evaluateList() 421 423 } 422 424 … … 437 439 // ------------------------------ ArgumentsNode -------------------------------- 438 440 439 ValueImp *ArgumentsNode::evaluate(ExecState * /*exec*/)441 ValueImp *ArgumentsNode::evaluate(ExecState *) 440 442 { 441 443 assert(0); 442 return NULL; // dummy, see evaluateList()444 return 0; // dummy, see evaluateList() 443 445 } 444 446 … … 549 551 } while (iter != end); 550 552 551 return undefinedVariableError(exec, ident);553 return throwUndefinedVariableError(exec, ident); 552 554 } 553 555 … … 672 674 } while (iter != end); 673 675 674 return undefinedVariableError(exec, m_ident);676 return throwUndefinedVariableError(exec, m_ident); 675 677 } 676 678 … … 903 905 } while (iter != end); 904 906 905 return undefinedVariableError(exec, m_ident);907 return throwUndefinedVariableError(exec, m_ident); 906 908 } 907 909 … … 978 980 KJS_CHECKEXCEPTIONVALUE 979 981 980 return jsNumber(v->toNumber(exec)); /* TODO: optimize */982 return jsNumber(v->toNumber(exec)); 981 983 } 982 984 … … 1292 1294 1293 1295 if (m_oper != OpEqual) 1294 return undefinedVariableError(exec, m_ident);1296 return throwUndefinedVariableError(exec, m_ident); 1295 1297 1296 1298 found: … … 1420 1422 Completion c = statement->execute(exec); 1421 1423 KJS_ABORTPOINT 1422 if (exec->hadException()) {1423 ValueImp *ex = exec->exception();1424 exec->clearException();1425 return Completion(Throw, ex);1426 }1427 1428 1424 if (c.complType() != Normal) 1429 1425 return c; … … 1437 1433 return c2; 1438 1434 1439 if (exec->hadException()) {1440 ValueImp *ex = exec->exception();1441 exec->clearException();1442 return Completion(Throw, ex);1443 }1444 1445 1435 if (c2.isValueCompletion()) 1446 1436 v = c2.value(); … … 1486 1476 // built-in properties of the global object with var declarations. 1487 1477 if (variable->getDirect(ident)) 1488 return NULL;1478 return 0; 1489 1479 val = Undefined(); 1490 1480 } … … 1590 1580 1591 1581 // ECMA 12.3 1592 Completion EmptyStatementNode::execute(ExecState * /*exec*/)1582 Completion EmptyStatementNode::execute(ExecState *) 1593 1583 { 1594 1584 return Completion(Normal); … … 1658 1648 if (!((c.complType() == Continue) && ls.contains(c.target()))) { 1659 1649 if ((c.complType() == Break) && ls.contains(c.target())) 1660 return Completion(Normal, NULL);1650 return Completion(Normal, 0); 1661 1651 if (c.complType() != Normal) 1662 1652 return c; … … 1666 1656 } while (bv->toBoolean(exec)); 1667 1657 1668 return Completion(Normal, NULL);1658 return Completion(Normal, 0); 1669 1659 } 1670 1660 … … 1684 1674 Completion c; 1685 1675 bool b(false); 1686 ValueImp *value = NULL;1676 ValueImp *value = 0; 1687 1677 1688 1678 while (1) { … … 1724 1714 Completion ForNode::execute(ExecState *exec) 1725 1715 { 1726 ValueImp *v, *cval = NULL;1716 ValueImp *v, *cval = 0; 1727 1717 1728 1718 if (expr1) { … … 1787 1777 { 1788 1778 ValueImp *e; 1789 ValueImp *retval = NULL;1779 ValueImp *retval = 0; 1790 1780 ObjectImp *v; 1791 1781 Completion c; … … 1804 1794 // access any property. 1805 1795 if (e->isUndefinedOrNull()) { 1806 return Completion(Normal, NULL);1796 return Completion(Normal, 0); 1807 1797 } 1808 1798 … … 1903 1893 1904 1894 if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration()) 1905 return Completion(Throw, 1906 throwError(exec, SyntaxError, "Invalid continue statement.")); 1895 return createErrorCompletion(exec, SyntaxError, "Invalid continue statement."); 1907 1896 else if (!ident.isEmpty() && !exec->context().imp()->seenLabels()->contains(ident)) 1908 return Completion(Throw, 1909 throwError(exec, SyntaxError, "Label %s not found.", ident)); 1897 return createErrorCompletion(exec, SyntaxError, "Label %s not found.", ident); 1910 1898 else 1911 return Completion(Continue, NULL, ident);1899 return Completion(Continue, 0, ident); 1912 1900 } 1913 1901 … … 1921 1909 if (ident.isEmpty() && !exec->context().imp()->seenLabels()->inIteration() && 1922 1910 !exec->context().imp()->seenLabels()->inSwitch()) 1923 return Completion(Throw, 1924 throwError(exec, SyntaxError, "Invalid break statement.")); 1911 return createErrorCompletion(exec, SyntaxError, "Invalid break statement."); 1925 1912 else if (!ident.isEmpty() && !exec->context().imp()->seenLabels()->contains(ident)) 1926 return Completion(Throw, 1927 throwError(exec, SyntaxError, "Label %s not found.", ident)); 1913 return createErrorCompletion(exec, SyntaxError, "Label %s not found."); 1928 1914 else 1929 return Completion(Break, NULL, ident);1915 return Completion(Break, 0, ident); 1930 1916 } 1931 1917 … … 1939 1925 CodeType codeType = exec->context().imp()->codeType(); 1940 1926 if (codeType != FunctionCode && codeType != AnonymousCode ) { 1941 return Completion(Throw, throwError(exec, SyntaxError, "Invalid return statement."));1927 return createErrorCompletion(exec, SyntaxError, "Invalid return statement."); 1942 1928 } 1943 1929 … … 2002 1988 // ------------------------------ ClauseListNode ------------------------------- 2003 1989 2004 ValueImp *ClauseListNode::evaluate(ExecState * /*exec*/)2005 { 2006 / * should never be called */1990 ValueImp *ClauseListNode::evaluate(ExecState *) 1991 { 1992 // should never be called 2007 1993 assert(false); 2008 return NULL;1994 return 0; 2009 1995 } 2010 1996 … … 2039 2025 } 2040 2026 2041 ValueImp *CaseBlockNode::evaluate(ExecState * /*exec*/)2042 { 2043 / * should never be called */2027 ValueImp *CaseBlockNode::evaluate(ExecState *) 2028 { 2029 // should never be called 2044 2030 assert(false); 2045 return NULL;2031 return 0; 2046 2032 } 2047 2033 … … 2148 2134 Completion LabelNode::execute(ExecState *exec) 2149 2135 { 2150 Completion e; 2151 2152 if (!exec->context().imp()->seenLabels()->push(label)) { 2153 return Completion( Throw, 2154 throwError(exec, SyntaxError, "Duplicated label %s found.", label)); 2155 }; 2156 e = statement->execute(exec); 2136 if (!exec->context().imp()->seenLabels()->push(label)) 2137 return createErrorCompletion(exec, SyntaxError, "Duplicated label %s found.", label); 2138 Completion e = statement->execute(exec); 2157 2139 exec->context().imp()->seenLabels()->pop(); 2158 2140 … … 2180 2162 } 2181 2163 2182 // ------------------------------ CatchNode ------------------------------------2183 2184 Completion CatchNode::execute(ExecState */*exec*/)2185 {2186 // should never be reached. execute(exec, arg) is used instead2187 assert(0L);2188 return Completion();2189 }2190 2191 // ECMA 12.142192 Completion CatchNode::execute(ExecState *exec, ValueImp *arg)2193 {2194 /* TODO: correct ? Not part of the spec */2195 2196 exec->clearException();2197 2198 ObjectImp *obj(new ObjectImp());2199 obj->put(exec, ident, arg, DontDelete);2200 exec->context().imp()->pushScope(obj);2201 Completion c = block->execute(exec);2202 exec->context().imp()->popScope();2203 2204 return c;2205 }2206 2207 void CatchNode::processVarDecls(ExecState *exec)2208 {2209 block->processVarDecls(exec);2210 }2211 2212 // ------------------------------ FinallyNode ----------------------------------2213 2214 // ECMA 12.142215 Completion FinallyNode::execute(ExecState *exec)2216 {2217 return block->execute(exec);2218 }2219 2220 void FinallyNode::processVarDecls(ExecState *exec)2221 {2222 block->processVarDecls(exec);2223 }2224 2225 2164 // ------------------------------ TryNode -------------------------------------- 2226 2165 … … 2230 2169 KJS_BREAKPOINT; 2231 2170 2232 Completion c, c2; 2233 2234 c = block->execute(exec); 2235 2236 if (!_final) { 2237 if (c.complType() != Throw) 2238 return c; 2239 return _catch->execute(exec,c.value()); 2240 } 2241 2242 if (!_catch) { 2243 ValueImp *lastException = exec->exception(); 2244 exec->clearException(); 2245 2246 c2 = _final->execute(exec); 2247 2248 if (!exec->hadException()) 2249 exec->setException(lastException); 2250 2251 return (c2.complType() == Normal) ? c : c2; 2252 } 2253 2254 if (c.complType() == Throw) 2255 c = _catch->execute(exec,c.value()); 2256 2257 c2 = _final->execute(exec); 2258 return (c2.complType() == Normal) ? c : c2; 2171 Completion c = tryBlock->execute(exec); 2172 2173 if (catchBlock && c.complType() == Throw) { 2174 ObjectImp *obj = new ObjectImp; 2175 obj->put(exec, exceptionIdent, c.value(), DontDelete); 2176 exec->context().imp()->pushScope(obj); 2177 c = catchBlock->execute(exec); 2178 exec->context().imp()->popScope(); 2179 } 2180 2181 if (finallyBlock) { 2182 Completion c2 = finallyBlock->execute(exec); 2183 if (c2.complType() != Normal) 2184 c = c2; 2185 } 2186 2187 return c; 2259 2188 } 2260 2189 2261 2190 void TryNode::processVarDecls(ExecState *exec) 2262 2191 { 2263 block->processVarDecls(exec);2264 if ( _final)2265 _final->processVarDecls(exec);2266 if ( _catch)2267 _catch->processVarDecls(exec);2192 tryBlock->processVarDecls(exec); 2193 if (catchBlock) 2194 catchBlock->processVarDecls(exec); 2195 if (finallyBlock) 2196 finallyBlock->processVarDecls(exec); 2268 2197 } 2269 2198 … … 2271 2200 2272 2201 // ECMA 13 2273 ValueImp *ParameterNode::evaluate(ExecState * /*exec*/)2202 ValueImp *ParameterNode::evaluate(ExecState *) 2274 2203 { 2275 2204 return Undefined(); … … 2282 2211 { 2283 2212 setLoc(-1, -1, -1); 2284 //fprintf(stderr,"FunctionBodyNode::FunctionBodyNode %p\n",this);2285 2213 } 2286 2214 … … 2299 2227 2300 2228 // TODO: let this be an object with [[Class]] property "Function" 2301 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2302 ObjectImp *func(fimp); // protect from GC 2229 FunctionImp *func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2303 2230 2304 2231 ObjectImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); … … 2308 2235 int plen = 0; 2309 2236 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 2310 f imp->addParameter(p->ident());2237 func->addParameter(p->ident()); 2311 2238 2312 2239 func->put(exec, lengthPropertyName, Number(plen), ReadOnly|DontDelete|DontEnum); … … 2327 2254 } 2328 2255 2256 Completion FuncDeclNode::execute(ExecState *) 2257 { 2258 return Completion(Normal); 2259 } 2260 2329 2261 // ------------------------------ FuncExprNode --------------------------------- 2330 2262 … … 2334 2266 ContextImp *context = exec->context().imp(); 2335 2267 bool named = !ident.isNull(); 2336 ObjectImp *functionScopeObject = NULL;2268 ObjectImp *functionScopeObject = 0; 2337 2269 2338 2270 if (named) { … … 2344 2276 } 2345 2277 2346 FunctionImp *fimp = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2347 ValueImp *ret(fimp); 2278 FunctionImp *func = new DeclaredFunctionImp(exec, ident, body.get(), context->scopeChain()); 2348 2279 ObjectImp *proto = exec->lexicalInterpreter()->builtinObject()->construct(exec, List::empty()); 2349 proto->put(exec, constructorPropertyName, ret, ReadOnly|DontDelete|DontEnum);2350 f imp->put(exec, prototypePropertyName, proto, Internal|DontDelete);2280 proto->put(exec, constructorPropertyName, func, ReadOnly|DontDelete|DontEnum); 2281 func->put(exec, prototypePropertyName, proto, Internal|DontDelete); 2351 2282 2352 2283 int plen = 0; 2353 2284 for(ParameterNode *p = param.get(); p != 0L; p = p->nextParam(), plen++) 2354 f imp->addParameter(p->ident());2285 func->addParameter(p->ident()); 2355 2286 2356 2287 if (named) { 2357 functionScopeObject->put(exec, ident, ret, Internal | ReadOnly | (context->codeType() == EvalCode ? 0 : DontDelete));2288 functionScopeObject->put(exec, ident, func, Internal | ReadOnly | (context->codeType() == EvalCode ? 0 : DontDelete)); 2358 2289 context->popScope(); 2359 2290 } 2360 2291 2361 return ret;2292 return func; 2362 2293 } 2363 2294
Note:
See TracChangeset
for help on using the changeset viewer.