Changeset 43220 in webkit for trunk/JavaScriptCore/runtime/JSFunction.cpp
- Timestamp:
- May 5, 2009, 4:34:23 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSFunction.cpp
r43122 r43220 46 46 const ClassInfo JSFunction::info = { "Function", &InternalFunction::info, 0, 0 }; 47 47 48 JSFunction::JSFunction(ExecState* exec, PassRefPtr<Structure> structure, int length, const Identifier& name, NativeFunction func) 49 : Base(&exec->globalData(), structure, name) 50 #if ENABLE(JIT) 51 , m_body(exec->globalData().nativeFunctionThunk()) 52 #else 53 , m_body(0) 54 #endif 55 { 56 #if ENABLE(JIT) 57 setNativeFunction(func); 58 putDirect(exec->propertyNames().length, jsNumber(exec, length), DontDelete | ReadOnly | DontEnum); 59 #else 60 UNUSED_PARAM(length); 61 UNUSED_PARAM(func); 62 ASSERT_NOT_REACHED(); 63 #endif 64 } 65 48 66 JSFunction::JSFunction(ExecState* exec, const Identifier& name, FunctionBodyNode* body, ScopeChainNode* scopeChainNode) 49 67 : Base(&exec->globalData(), exec->lexicalGlobalObject()->functionStructure(), name) 50 68 , m_body(body) 51 , m_scopeChain(scopeChainNode) 52 { 69 { 70 setScopeChain(scopeChainNode); 53 71 } 54 72 … … 59 77 // are based on a check for the this pointer value for this JSFunction - which will no longer be valid once 60 78 // this memory is freed and may be reused (potentially for another, different JSFunction). 61 if (m_body && m_body->isGenerated()) 62 m_body->generatedBytecode().unlinkCallers(); 79 if (!isHostFunction()) { 80 if (m_body && m_body->isGenerated()) 81 m_body->generatedBytecode().unlinkCallers(); 82 scopeChain().~ScopeChain(); 83 } 84 63 85 #endif 64 86 } … … 67 89 { 68 90 Base::mark(); 69 m_body->mark(); 70 m_scopeChain.mark(); 91 if (!isHostFunction()) { 92 m_body->mark(); 93 scopeChain().mark(); 94 } 71 95 } 72 96 73 97 CallType JSFunction::getCallData(CallData& callData) 74 98 { 99 if (isHostFunction()) { 100 callData.native.function = nativeFunction(); 101 return CallTypeHost; 102 } 75 103 callData.js.functionBody = m_body.get(); 76 callData.js.scopeChain = m_scopeChain.node();104 callData.js.scopeChain = scopeChain().node(); 77 105 return CallTypeJS; 78 106 } … … 80 108 JSValue JSFunction::call(ExecState* exec, JSValue thisValue, const ArgList& args) 81 109 { 82 return exec->interpreter()->execute(m_body.get(), exec, this, thisValue.toThisObject(exec), args, m_scopeChain.node(), exec->exceptionSlot()); 110 ASSERT(!isHostFunction()); 111 return exec->interpreter()->execute(m_body.get(), exec, this, thisValue.toThisObject(exec), args, scopeChain().node(), exec->exceptionSlot()); 83 112 } 84 113 … … 86 115 { 87 116 JSFunction* thisObj = asFunction(slot.slotBase()); 117 ASSERT(!thisObj->isHostFunction()); 88 118 return exec->interpreter()->retrieveArguments(exec, thisObj); 89 119 } … … 92 122 { 93 123 JSFunction* thisObj = asFunction(slot.slotBase()); 124 ASSERT(!thisObj->isHostFunction()); 94 125 return exec->interpreter()->retrieveCaller(exec, thisObj); 95 126 } … … 98 129 { 99 130 JSFunction* thisObj = asFunction(slot.slotBase()); 131 ASSERT(!thisObj->isHostFunction()); 100 132 return jsNumber(exec, thisObj->m_body->parameterCount()); 101 133 } … … 103 135 bool JSFunction::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) 104 136 { 137 if (isHostFunction()) 138 return Base::getOwnPropertySlot(exec, propertyName, slot); 139 105 140 if (propertyName == exec->propertyNames().prototype) { 106 141 JSValue* location = getDirectLocation(propertyName); 107 142 108 143 if (!location) { 109 JSObject* prototype = new (exec) JSObject( m_scopeChain.globalObject()->emptyObjectStructure());144 JSObject* prototype = new (exec) JSObject(scopeChain().globalObject()->emptyObjectStructure()); 110 145 prototype->putDirect(exec->propertyNames().constructor, this, DontEnum); 111 146 putDirect(exec->propertyNames().prototype, prototype, DontDelete); … … 136 171 void JSFunction::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) 137 172 { 173 if (isHostFunction()) { 174 Base::put(exec, propertyName, value, slot); 175 return; 176 } 138 177 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length) 139 178 return; … … 143 182 bool JSFunction::deleteProperty(ExecState* exec, const Identifier& propertyName) 144 183 { 184 if (isHostFunction()) 185 return Base::deleteProperty(exec, propertyName); 145 186 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length) 146 187 return false; … … 151 192 ConstructType JSFunction::getConstructData(ConstructData& constructData) 152 193 { 194 if (isHostFunction()) 195 return ConstructTypeNone; 153 196 constructData.js.functionBody = m_body.get(); 154 constructData.js.scopeChain = m_scopeChain.node();197 constructData.js.scopeChain = scopeChain().node(); 155 198 return ConstructTypeJS; 156 199 } … … 158 201 JSObject* JSFunction::construct(ExecState* exec, const ArgList& args) 159 202 { 203 ASSERT(!isHostFunction()); 160 204 Structure* structure; 161 205 JSValue prototype = get(exec, exec->propertyNames().prototype); … … 166 210 JSObject* thisObj = new (exec) JSObject(structure); 167 211 168 JSValue result = exec->interpreter()->execute(m_body.get(), exec, this, thisObj, args, m_scopeChain.node(), exec->exceptionSlot());212 JSValue result = exec->interpreter()->execute(m_body.get(), exec, this, thisObj, args, scopeChain().node(), exec->exceptionSlot()); 169 213 if (exec->hadException() || !result.isObject()) 170 214 return thisObj;
Note:
See TracChangeset
for help on using the changeset viewer.