Changeset 29810 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Jan 26, 2008, 10:55:52 AM (17 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/ExecState.cpp
r29710 r29810 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * This file is part of the KDE libraries4 3 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 5 4 * Copyright (C) 2001 Peter Kelly ([email protected]) 6 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.5 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved. 7 6 * 8 7 * This library is free software; you can redistribute it and/or … … 43 42 44 43 // The constructor for the globalExec pseudo-ExecState 45 ExecState::ExecState(JSGlobalObject* globalObject)44 inline ExecState::ExecState(JSGlobalObject* globalObject) 46 45 : m_globalObject(globalObject) 47 46 , m_exception(0) … … 55 54 , m_localStorage(&globalObject->localStorage()) 56 55 , m_variableObject(globalObject) 57 , m_thisVal (globalObject)56 , m_thisValue(globalObject) 58 57 , m_iterationDepth(0) 59 58 , m_switchDepth(0) … … 63 62 } 64 63 65 ExecState::ExecState(JSGlobalObject* globalObject, JSObject* /*thisObject*/, ProgramNode* programNode)64 inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* /*thisObject*/, ProgramNode* programNode) 66 65 : m_globalObject(globalObject) 67 66 , m_exception(0) … … 75 74 , m_localStorage(&globalObject->localStorage()) 76 75 , m_variableObject(globalObject) 77 , m_thisVal (globalObject)76 , m_thisValue(globalObject) 78 77 , m_iterationDepth(0) 79 78 , m_switchDepth(0) … … 84 83 // has been for some time. 85 84 ASSERT(m_scopeNode); 86 activeExecStates().append(this);87 85 m_scopeChain.push(globalObject); 88 86 } 89 87 90 ExecState::ExecState(JSGlobalObject* globalObject, EvalNode* evalNode, ExecState* callingExec)88 inline ExecState::ExecState(JSGlobalObject* globalObject, EvalNode* evalNode, ExecState* callingExec) 91 89 : m_globalObject(globalObject) 92 90 , m_exception(0) … … 101 99 , m_scopeChain(callingExec->m_scopeChain) 102 100 , m_variableObject(callingExec->m_variableObject) 103 , m_thisVal (callingExec->m_thisVal)101 , m_thisValue(callingExec->m_thisValue) 104 102 , m_iterationDepth(0) 105 103 , m_switchDepth(0) … … 107 105 { 108 106 ASSERT(m_scopeNode); 109 activeExecStates().append(this); 110 } 111 112 ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisObject, 113 FunctionBodyNode* functionBodyNode, ExecState* callingExec, 114 FunctionImp* func, const List& args) 107 } 108 109 inline ExecState::ExecState(JSGlobalObject* globalObject, JSObject* thisObject, 110 FunctionBodyNode* functionBodyNode, ExecState* callingExec, 111 FunctionImp* func, const List& args) 115 112 : m_globalObject(globalObject) 116 113 , m_exception(0) … … 122 119 , m_arguments(&args) 123 120 , m_scopeChain(func->scope()) 124 , m_thisVal (thisObject)121 , m_thisValue(thisObject) 125 122 , m_iterationDepth(0) 126 123 , m_switchDepth(0) … … 128 125 { 129 126 ASSERT(m_scopeNode); 130 activeExecStates().append(this);131 127 132 128 ActivationImp* activation = globalObject->pushActivation(this); … … 137 133 } 138 134 139 ExecState::~ExecState() 140 { 141 ASSERT(m_scopeNode && activeExecStates().last() == this || !m_scopeNode); 142 if (m_scopeNode) 143 activeExecStates().removeLast(); 144 145 if (m_activation && m_activation->needsPop()) 146 m_globalObject->popActivation(); 135 inline ExecState::~ExecState() 136 { 147 137 } 148 138 149 139 JSGlobalObject* ExecState::lexicalGlobalObject() const 150 140 { 151 if (scopeChain().isEmpty()) 152 return dynamicGlobalObject(); 153 154 JSObject* object = scopeChain().bottom(); 141 JSObject* object = m_scopeChain.bottom(); 155 142 if (object && object->isGlobalObject()) 156 143 return static_cast<JSGlobalObject*>(object); 157 158 return dynamicGlobalObject(); 144 return m_globalObject; 159 145 } 160 146 … … 166 152 } 167 153 168 ExecStateStack& ExecState::activeExecStates()154 static inline ExecStateStack& inlineActiveExecStates() 169 155 { 170 156 static ExecStateStack staticActiveExecStates; … … 172 158 } 173 159 160 ExecStateStack& ExecState::activeExecStates() 161 { 162 return inlineActiveExecStates(); 163 } 164 165 GlobalExecState::GlobalExecState(JSGlobalObject* globalObject) 166 : ExecState(globalObject) 167 { 168 } 169 170 GlobalExecState::~GlobalExecState() 171 { 172 } 173 174 InterpreterExecState::InterpreterExecState(JSGlobalObject* globalObject, JSObject* thisObject, ProgramNode* programNode) 175 : ExecState(globalObject, thisObject, programNode) 176 { 177 inlineActiveExecStates().append(this); 178 } 179 180 InterpreterExecState::~InterpreterExecState() 181 { 182 ASSERT(inlineActiveExecStates().last() == this); 183 inlineActiveExecStates().removeLast(); 184 } 185 186 EvalExecState::EvalExecState(JSGlobalObject* globalObject, EvalNode* evalNode, ExecState* callingExec) 187 : ExecState(globalObject, evalNode, callingExec) 188 { 189 inlineActiveExecStates().append(this); 190 } 191 192 EvalExecState::~EvalExecState() 193 { 194 ASSERT(inlineActiveExecStates().last() == this); 195 inlineActiveExecStates().removeLast(); 196 } 197 198 FunctionExecState::FunctionExecState(JSGlobalObject* globalObject, JSObject* thisObject, 199 FunctionBodyNode* functionBodyNode, ExecState* callingExec, 200 FunctionImp* func, const List& args) 201 : ExecState(globalObject, thisObject, functionBodyNode, callingExec, func, args) 202 { 203 inlineActiveExecStates().append(this); 204 } 205 206 FunctionExecState::~FunctionExecState() 207 { 208 ASSERT(inlineActiveExecStates().last() == this); 209 inlineActiveExecStates().removeLast(); 210 211 if (m_activation->needsPop()) 212 m_globalObject->popActivation(); 213 } 214 174 215 } // namespace KJS -
trunk/JavaScriptCore/kjs/ExecState.h
r29710 r29810 3 3 * Copyright (C) 1999-2001 Harri Porten ([email protected]) 4 4 * Copyright (C) 2001 Peter Kelly ([email protected]) 5 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.5 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved. 6 6 * 7 7 * This library is free software; you can redistribute it and/or … … 22 22 */ 23 23 24 #ifndef ExecState_ H25 #define ExecState_ H24 #ifndef ExecState_h 25 #define ExecState_h 26 26 27 27 #include "LabelStack.h" 28 28 #include "LocalStorage.h" 29 #include "completion.h" 30 #include "list.h" 29 31 #include "scope_chain.h" 30 #include "types.h"31 32 32 33 namespace KJS { 33 34 34 enum CodeType {35 GlobalCode,36 EvalCode,37 FunctionCode,38 };39 40 35 class ActivationImp; 41 36 class CommonIdentifiers; … … 48 43 class JSVariableObject; 49 44 class ProgramNode; 50 class ScopeChain;51 45 class ScopeNode; 52 struct LocalStorageEntry; 46 47 enum CodeType { GlobalCode, EvalCode, FunctionCode }; 53 48 54 49 typedef Vector<ExecState*, 16> ExecStateStack; 55 50 56 /** 57 * Represents the current state of script execution. This is 58 * passed as the first argument to most functions. 59 */ 60 class ExecState { 61 friend class Interpreter; 62 friend class FunctionImp; 63 friend class GlobalFuncImp; 64 public: 65 /** 66 * Returns the global object that was in scope when the current script started executing. 67 */ 51 // Represents the current state of script execution. 52 // Passed as the first argument to most functions. 53 class ExecState : Noncopyable { 54 public: 55 // Global object that was in scope when the current script started executing. 68 56 JSGlobalObject* dynamicGlobalObject() const { return m_globalObject; } 69 57 70 /** 71 * Returns the global object that was in scope when the current body of code was defined. 72 */ 58 // Global object that was in scope when the current body of code was defined. 73 59 JSGlobalObject* lexicalGlobalObject() const; 74 60 … … 80 66 81 67 const ScopeChain& scopeChain() const { return m_scopeChain; } 68 void pushScope(JSObject* s) { m_scopeChain.push(s); } 69 void popScope() { m_scopeChain.pop(); } 82 70 void replaceScopeChainTop(JSObject* o) { m_scopeChain.replaceTop(o); } 83 71 … … 85 73 void setVariableObject(JSVariableObject* v) { m_variableObject = v; } 86 74 87 JSObject* thisValue() const { return m_thisVal ; }75 JSObject* thisValue() const { return m_thisValue; } 88 76 89 77 ExecState* callingExecState() { return m_callingExec; } … … 96 84 const List* arguments() const { return m_arguments; } 97 85 98 void pushScope(JSObject* s) { m_scopeChain.push(s); } 99 void popScope() { m_scopeChain.pop(); } 100 LabelStack* seenLabels() { return &ls; } 86 LabelStack& seenLabels() { return m_labelStack; } 101 87 102 88 void pushIteration() { m_iterationDepth++; } … … 178 164 } 179 165 166 static void markActiveExecStates(); 167 static ExecStateStack& activeExecStates(); 168 169 protected: 180 170 ExecState(JSGlobalObject*); 181 171 ExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*); … … 185 175 ~ExecState(); 186 176 187 static void markActiveExecStates();188 static ExecStateStack& activeExecStates();189 190 private:191 177 // ExecStates are always stack-allocated, and the garbage collector 192 178 // marks the stack, so we don't need to protect the objects below from GC. … … 208 194 ScopeChain m_scopeChain; 209 195 JSVariableObject* m_variableObject; 210 JSObject* m_thisVal ;211 212 LabelStack ls;196 JSObject* m_thisValue; 197 198 LabelStack m_labelStack; 213 199 int m_iterationDepth; 214 200 int m_switchDepth; … … 219 205 }; 220 206 207 class GlobalExecState : public ExecState { 208 public: 209 GlobalExecState(JSGlobalObject*); 210 ~GlobalExecState(); 211 }; 212 213 class InterpreterExecState : public ExecState { 214 public: 215 InterpreterExecState(JSGlobalObject*, JSObject* thisObject, ProgramNode*); 216 ~InterpreterExecState(); 217 }; 218 219 class EvalExecState : public ExecState { 220 public: 221 EvalExecState(JSGlobalObject*, EvalNode*, ExecState* callingExecState); 222 ~EvalExecState(); 223 }; 224 225 class FunctionExecState : public ExecState { 226 public: 227 FunctionExecState(JSGlobalObject*, JSObject* thisObject, FunctionBodyNode*, 228 ExecState* callingExecState, FunctionImp*, const List& args); 229 ~FunctionExecState(); 230 }; 231 221 232 } // namespace KJS 222 233 223 #endif // ExecState_ H234 #endif // ExecState_h -
trunk/JavaScriptCore/kjs/JSGlobalObject.cpp
r29710 r29810 74 74 // It doesn't matter what "current time" is here, just as long as 75 75 // it's possible to measure the time difference correctly. 76 static inline unsigned getCurrentTime() { 76 static inline unsigned getCurrentTime() 77 { 77 78 #if HAVE(SYS_TIME_H) 78 79 struct timeval tv; … … 523 524 StackActivation* stackEntry = &d()->activations->data[d()->activationCount++]; 524 525 stackEntry->activationStorage.init(exec); 525 526 return &(stackEntry->activationStorage); 526 return &stackEntry->activationStorage; 527 527 } 528 528 … … 545 545 void JSGlobalObject::tearOffActivation(ExecState* exec, bool leaveRelic) 546 546 { 547 if (exec->codeType() == FunctionCode && static_cast<ActivationImp*>(exec->activationObject())->isOnStack()) { 548 ActivationImp* oldActivation = static_cast<ActivationImp*>(exec->activationObject()); 549 ActivationImp* newActivation = new ActivationImp(*oldActivation->d(), leaveRelic); 550 551 if (!leaveRelic) { 552 checkActivationCount(); 553 d()->activationCount--; 554 } 555 556 oldActivation->d()->localStorage.shrink(0); 557 558 exec->setActivationObject(newActivation); 559 exec->setVariableObject(newActivation); 560 exec->setLocalStorage(&(newActivation->localStorage())); 561 exec->replaceScopeChainTop(newActivation); 547 ActivationImp* oldActivation = exec->activationObject(); 548 if (!oldActivation || !oldActivation->isOnStack()) 549 return; 550 551 ASSERT(exec->codeType() == FunctionCode); 552 ActivationImp* newActivation = new ActivationImp(*oldActivation->d(), leaveRelic); 553 554 if (!leaveRelic) { 555 checkActivationCount(); 556 d()->activationCount--; 562 557 } 558 559 oldActivation->d()->localStorage.shrink(0); 560 561 exec->setActivationObject(newActivation); 562 exec->setVariableObject(newActivation); 563 exec->setLocalStorage(&newActivation->localStorage()); 564 exec->replaceScopeChainTop(newActivation); 563 565 } 564 566 -
trunk/JavaScriptCore/kjs/JSGlobalObject.h
r29710 r29810 87 87 CompatMode compatMode; 88 88 89 ExecState globalExec;89 GlobalExecState globalExec; 90 90 int recursion; 91 91 -
trunk/JavaScriptCore/kjs/function.cpp
r29588 r29810 73 73 JSValue* FunctionImp::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 74 74 { 75 ExecState newExec(exec->dynamicGlobalObject(), thisObj, body.get(), exec, this, args);75 FunctionExecState newExec(exec->dynamicGlobalObject(), thisObj, body.get(), exec, this, args); 76 76 JSValue* result = body->execute(&newExec); 77 77 if (newExec.completionType() == Throw) { … … 722 722 exec->dynamicGlobalObject()->tearOffActivation(exec); 723 723 JSGlobalObject* globalObject = switchGlobal ? static_cast<JSGlobalObject*>(thisObj) : exec->dynamicGlobalObject(); 724 E xecState newExec(globalObject, evalNode.get(), exec);724 EvalExecState newExec(globalObject, evalNode.get(), exec); 725 725 726 726 if (switchGlobal) { -
trunk/JavaScriptCore/kjs/interpreter.cpp
r28907 r29810 120 120 else { 121 121 // execute the code 122 ExecState newExec(globalObject, thisObj, progNode.get());122 InterpreterExecState newExec(globalObject, thisObj, progNode.get()); 123 123 JSValue* value = progNode->execute(&newExec); 124 124 res = Completion(newExec.completionType(), value); -
trunk/JavaScriptCore/kjs/nodes.cpp
r29428 r29810 1014 1014 KJS_CHECKEXCEPTIONVALUE 1015 1015 1016 JSObject *thisObj = base;1016 JSObject* thisObj = base; 1017 1017 // ECMA 11.2.3 says that in this situation the this value should be null. 1018 1018 // However, section 10.2.3 says that in the case where the value provided 1019 1019 // by the caller is null, the global object should be used. It also says 1020 // that the section does not apply to inter al functions, but for simplicity1020 // that the section does not apply to internal functions, but for simplicity 1021 1021 // of implementation we use the global object anyway here. This guarantees 1022 1022 // that in host objects you always get a valid object for this. … … 3954 3954 if (ident.isEmpty() && !exec->inIteration()) 3955 3955 return setErrorCompletion(exec, SyntaxError, "Invalid continue statement."); 3956 if (!ident.isEmpty() && !exec->seenLabels() ->contains(ident))3956 if (!ident.isEmpty() && !exec->seenLabels().contains(ident)) 3957 3957 return setErrorCompletion(exec, SyntaxError, "Label %s not found.", ident); 3958 3958 return exec->setContinueCompletion(&ident); … … 3966 3966 if (ident.isEmpty() && !exec->inIteration() && !exec->inSwitch()) 3967 3967 return setErrorCompletion(exec, SyntaxError, "Invalid break statement."); 3968 if (!ident.isEmpty() && !exec->seenLabels() ->contains(ident))3968 if (!ident.isEmpty() && !exec->seenLabels().contains(ident)) 3969 3969 return setErrorCompletion(exec, SyntaxError, "Label %s not found."); 3970 3970 return exec->setBreakCompletion(&ident); … … 4161 4161 JSValue* LabelNode::execute(ExecState *exec) 4162 4162 { 4163 if (!exec->seenLabels() ->push(label))4163 if (!exec->seenLabels().push(label)) 4164 4164 return setErrorCompletion(exec, SyntaxError, "Duplicated label %s found.", label); 4165 4165 JSValue* result = statement->execute(exec); 4166 exec->seenLabels() ->pop();4166 exec->seenLabels().pop(); 4167 4167 4168 4168 if (exec->completionType() == Break && exec->breakOrContinueTarget() == label)
Note:
See TracChangeset
for help on using the changeset viewer.