source: webkit/trunk/JavaScriptCore/runtime/JSFunction.cpp@ 52075

Last change on this file since 52075 was 48836, checked in by [email protected], 16 years ago

NotNullPassRefPtr: smart pointer optimized for passing references that are not null
https://bugs.webkit.org/show_bug.cgi?id=29822

Patch by Geoffrey Garen <[email protected]> on 2009-09-28
Reviewed by Darin Adler.

JavaScriptCore:

Added NotNullPassRefPtr, and deployed it in all places that initialize
JavaScript objects.

2.2% speedup on bench-allocate-nonretained.js.

  • API/JSCallbackConstructor.cpp:

(JSC::JSCallbackConstructor::JSCallbackConstructor):

  • API/JSCallbackConstructor.h:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:

(JSC::JSCallbackObject::JSCallbackObject):

(JSC::CodeBlock::addFunctionDecl):
(JSC::CodeBlock::addFunctionExpr):

  • runtime/ArrayConstructor.cpp:

(JSC::ArrayConstructor::ArrayConstructor):

  • runtime/ArrayConstructor.h:
  • runtime/ArrayPrototype.cpp:

(JSC::ArrayPrototype::ArrayPrototype):

  • runtime/ArrayPrototype.h:
  • runtime/BooleanConstructor.cpp:

(JSC::BooleanConstructor::BooleanConstructor):

  • runtime/BooleanConstructor.h:
  • runtime/BooleanObject.cpp:

(JSC::BooleanObject::BooleanObject):

  • runtime/BooleanObject.h:
  • runtime/BooleanPrototype.cpp:

(JSC::BooleanPrototype::BooleanPrototype):

  • runtime/BooleanPrototype.h:
  • runtime/DateConstructor.cpp:

(JSC::DateConstructor::DateConstructor):

  • runtime/DateConstructor.h:
  • runtime/DateInstance.cpp:

(JSC::DateInstance::DateInstance):

  • runtime/DateInstance.h:
  • runtime/DatePrototype.cpp:

(JSC::DatePrototype::DatePrototype):

  • runtime/DatePrototype.h:
  • runtime/ErrorConstructor.cpp:

(JSC::ErrorConstructor::ErrorConstructor):

  • runtime/ErrorConstructor.h:
  • runtime/ErrorInstance.cpp:

(JSC::ErrorInstance::ErrorInstance):

  • runtime/ErrorInstance.h:
  • runtime/ErrorPrototype.cpp:

(JSC::ErrorPrototype::ErrorPrototype):

  • runtime/ErrorPrototype.h:
  • runtime/FunctionConstructor.cpp:

(JSC::FunctionConstructor::FunctionConstructor):

  • runtime/FunctionConstructor.h:
  • runtime/FunctionPrototype.cpp:

(JSC::FunctionPrototype::FunctionPrototype):

  • runtime/FunctionPrototype.h:
  • runtime/GlobalEvalFunction.cpp:

(JSC::GlobalEvalFunction::GlobalEvalFunction):

  • runtime/GlobalEvalFunction.h:
  • runtime/InternalFunction.cpp:

(JSC::InternalFunction::InternalFunction):

  • runtime/InternalFunction.h:

(JSC::InternalFunction::InternalFunction):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::JSActivation):

  • runtime/JSActivation.h:

(JSC::JSActivation::JSActivationData::JSActivationData):

  • runtime/JSArray.cpp:

(JSC::JSArray::JSArray):

  • runtime/JSArray.h:
  • runtime/JSByteArray.cpp:

(JSC::JSByteArray::JSByteArray):

  • runtime/JSByteArray.h:
  • runtime/JSFunction.cpp:

(JSC::JSFunction::JSFunction):

  • runtime/JSFunction.h:
  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::JSGlobalObject):

  • runtime/JSONObject.h:

(JSC::JSONObject::JSONObject):

  • runtime/JSObject.h:

(JSC::JSObject::JSObject):
(JSC::JSObject::setStructure):

  • runtime/JSVariableObject.h:

(JSC::JSVariableObject::JSVariableObject):

  • runtime/JSWrapperObject.h:

(JSC::JSWrapperObject::JSWrapperObject):

  • runtime/MathObject.cpp:

(JSC::MathObject::MathObject):

  • runtime/MathObject.h:
  • runtime/NativeErrorConstructor.cpp:

(JSC::NativeErrorConstructor::NativeErrorConstructor):

  • runtime/NativeErrorConstructor.h:
  • runtime/NativeErrorPrototype.cpp:

(JSC::NativeErrorPrototype::NativeErrorPrototype):

  • runtime/NativeErrorPrototype.h:
  • runtime/NumberConstructor.cpp:

(JSC::NumberConstructor::NumberConstructor):

  • runtime/NumberConstructor.h:
  • runtime/NumberObject.cpp:

(JSC::NumberObject::NumberObject):

  • runtime/NumberObject.h:
  • runtime/NumberPrototype.cpp:

(JSC::NumberPrototype::NumberPrototype):

  • runtime/NumberPrototype.h:
  • runtime/ObjectConstructor.cpp:

(JSC::ObjectConstructor::ObjectConstructor):

  • runtime/ObjectConstructor.h:
  • runtime/ObjectPrototype.cpp:

(JSC::ObjectPrototype::ObjectPrototype):

  • runtime/ObjectPrototype.h:
  • runtime/PropertyNameArray.h:

(JSC::PropertyNameArrayData::setCachedPrototypeChain):

  • runtime/PrototypeFunction.cpp:

(JSC::PrototypeFunction::PrototypeFunction):

  • runtime/PrototypeFunction.h:
  • runtime/RegExpConstructor.cpp:

(JSC::RegExpConstructor::RegExpConstructor):

  • runtime/RegExpConstructor.h:
  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::RegExpObject):

  • runtime/RegExpObject.h:

(JSC::RegExpObject::RegExpObjectData::RegExpObjectData):

  • runtime/RegExpPrototype.cpp:

(JSC::RegExpPrototype::RegExpPrototype):

  • runtime/RegExpPrototype.h:
  • runtime/StringConstructor.cpp:

(JSC::StringConstructor::StringConstructor):

  • runtime/StringConstructor.h:
  • runtime/StringObject.cpp:

(JSC::StringObject::StringObject):

  • runtime/StringObject.h:
  • runtime/StringObjectThatMasqueradesAsUndefined.h:

(JSC::StringObjectThatMasqueradesAsUndefined::StringObjectThatMasqueradesAsUndefined):

  • runtime/StringPrototype.cpp:

(JSC::StringPrototype::StringPrototype):

  • runtime/StringPrototype.h:
  • wtf/PassRefPtr.h:

(WTF::NotNullPassRefPtr::NotNullPassRefPtr):
(WTF::NotNullPassRefPtr::~NotNullPassRefPtr):
(WTF::NotNullPassRefPtr::get):
(WTF::NotNullPassRefPtr::clear):
(WTF::NotNullPassRefPtr::releaseRef):
(WTF::NotNullPassRefPtr::operator*):
(WTF::NotNullPassRefPtr::operator->):
(WTF::NotNullPassRefPtr::operator!):
(WTF::NotNullPassRefPtr::operator UnspecifiedBoolType):

  • wtf/RefPtr.h:

(WTF::RefPtr::RefPtr):
(WTF::operator==):

WebCore:

Added NotNullPassRefPtr, and deployed it in all places that initialize
JavaScript objects.

  • bindings/js/DOMObjectWithSVGContext.h:

(WebCore::DOMObjectWithSVGContext::DOMObjectWithSVGContext):

  • bindings/js/JSDOMBinding.cpp:

(WebCore::cacheDOMStructure):

  • bindings/js/JSDOMBinding.h:

(WebCore::DOMObject::DOMObject):
(WebCore::DOMObjectWithGlobalPointer::DOMObjectWithGlobalPointer):
(WebCore::DOMConstructorObject::DOMConstructorObject):
(WebCore::DOMConstructorWithDocument::DOMConstructorWithDocument):

  • bindings/js/JSDOMGlobalObject.cpp:

(WebCore::JSDOMGlobalObject::JSDOMGlobalObject):

  • bindings/js/JSDOMGlobalObject.h:
  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::JSDOMWindowBase):

  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSHTMLAllCollection.h:

(WebCore::JSHTMLAllCollection::JSHTMLAllCollection):

  • bindings/js/JSInspectedObjectWrapper.cpp:

(WebCore::JSInspectedObjectWrapper::JSInspectedObjectWrapper):

  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp:

(WebCore::JSInspectorCallbackWrapper::JSInspectorCallbackWrapper):

  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp:

(WebCore::JSQuarantinedObjectWrapper::JSQuarantinedObjectWrapper):

  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSWorkerContextBase.cpp:

(WebCore::JSWorkerContextBase::JSWorkerContextBase):

  • bindings/js/JSWorkerContextBase.h:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/runtime_object.cpp:

(JSC::RuntimeObjectImp::RuntimeObjectImp):

  • bridge/runtime_object.h:
  • Property svn:eol-style set to native
File size: 8.9 KB
Line 
1/*
2 * Copyright (C) 1999-2002 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Cameron Zwarich ([email protected])
6 * Copyright (C) 2007 Maks Orlovich
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "JSFunction.h"
27
28#include "CodeBlock.h"
29#include "CommonIdentifiers.h"
30#include "CallFrame.h"
31#include "FunctionPrototype.h"
32#include "JSGlobalObject.h"
33#include "Interpreter.h"
34#include "ObjectPrototype.h"
35#include "Parser.h"
36#include "PropertyNameArray.h"
37#include "ScopeChainMark.h"
38
39using namespace WTF;
40using namespace Unicode;
41
42namespace JSC {
43
44ASSERT_CLASS_FITS_IN_CELL(JSFunction);
45
46const ClassInfo JSFunction::info = { "Function", &InternalFunction::info, 0, 0 };
47
48bool JSFunction::isHostFunctionNonInline() const
49{
50 return isHostFunction();
51}
52
53JSFunction::JSFunction(NonNullPassRefPtr<Structure> structure)
54 : Base(structure)
55 , m_executable(adoptRef(new VPtrHackExecutable()))
56{
57}
58
59JSFunction::JSFunction(ExecState* exec, NonNullPassRefPtr<Structure> structure, int length, const Identifier& name, NativeFunction func)
60 : Base(&exec->globalData(), structure, name)
61#if ENABLE(JIT)
62 , m_executable(adoptRef(new NativeExecutable(exec)))
63#endif
64{
65#if ENABLE(JIT)
66 setNativeFunction(func);
67 putDirect(exec->propertyNames().length, jsNumber(exec, length), DontDelete | ReadOnly | DontEnum);
68#else
69 UNUSED_PARAM(length);
70 UNUSED_PARAM(func);
71 ASSERT_NOT_REACHED();
72#endif
73}
74
75JSFunction::JSFunction(ExecState* exec, NonNullPassRefPtr<FunctionExecutable> executable, ScopeChainNode* scopeChainNode)
76 : Base(&exec->globalData(), exec->lexicalGlobalObject()->functionStructure(), executable->name())
77 , m_executable(executable)
78{
79 setScopeChain(scopeChainNode);
80}
81
82JSFunction::~JSFunction()
83{
84 // JIT code for other functions may have had calls linked directly to the code for this function; these links
85 // are based on a check for the this pointer value for this JSFunction - which will no longer be valid once
86 // this memory is freed and may be reused (potentially for another, different JSFunction).
87 if (!isHostFunction()) {
88#if ENABLE(JIT_OPTIMIZE_CALL)
89 ASSERT(m_executable);
90 if (jsExecutable()->isGenerated())
91 jsExecutable()->generatedBytecode().unlinkCallers();
92#endif
93 scopeChain().~ScopeChain(); // FIXME: Don't we need to do this in the interpreter too?
94 }
95}
96
97void JSFunction::markChildren(MarkStack& markStack)
98{
99 Base::markChildren(markStack);
100 if (!isHostFunction()) {
101 jsExecutable()->markAggregate(markStack);
102 scopeChain().markAggregate(markStack);
103 }
104}
105
106CallType JSFunction::getCallData(CallData& callData)
107{
108 if (isHostFunction()) {
109 callData.native.function = nativeFunction();
110 return CallTypeHost;
111 }
112 callData.js.functionExecutable = jsExecutable();
113 callData.js.scopeChain = scopeChain().node();
114 return CallTypeJS;
115}
116
117JSValue JSFunction::call(ExecState* exec, JSValue thisValue, const ArgList& args)
118{
119 ASSERT(!isHostFunction());
120 return exec->interpreter()->execute(jsExecutable(), exec, this, thisValue.toThisObject(exec), args, scopeChain().node(), exec->exceptionSlot());
121}
122
123JSValue JSFunction::argumentsGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
124{
125 JSFunction* thisObj = asFunction(slot.slotBase());
126 ASSERT(!thisObj->isHostFunction());
127 return exec->interpreter()->retrieveArguments(exec, thisObj);
128}
129
130JSValue JSFunction::callerGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
131{
132 JSFunction* thisObj = asFunction(slot.slotBase());
133 ASSERT(!thisObj->isHostFunction());
134 return exec->interpreter()->retrieveCaller(exec, thisObj);
135}
136
137JSValue JSFunction::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
138{
139 JSFunction* thisObj = asFunction(slot.slotBase());
140 ASSERT(!thisObj->isHostFunction());
141 return jsNumber(exec, thisObj->jsExecutable()->parameterCount());
142}
143
144bool JSFunction::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
145{
146 if (isHostFunction())
147 return Base::getOwnPropertySlot(exec, propertyName, slot);
148
149 if (propertyName == exec->propertyNames().prototype) {
150 JSValue* location = getDirectLocation(propertyName);
151
152 if (!location) {
153 JSObject* prototype = new (exec) JSObject(scopeChain().globalObject()->emptyObjectStructure());
154 prototype->putDirect(exec->propertyNames().constructor, this, DontEnum);
155 putDirect(exec->propertyNames().prototype, prototype, DontDelete);
156 location = getDirectLocation(propertyName);
157 }
158
159 slot.setValueSlot(this, location, offsetForLocation(location));
160 }
161
162 if (propertyName == exec->propertyNames().arguments) {
163 slot.setCustom(this, argumentsGetter);
164 return true;
165 }
166
167 if (propertyName == exec->propertyNames().length) {
168 slot.setCustom(this, lengthGetter);
169 return true;
170 }
171
172 if (propertyName == exec->propertyNames().caller) {
173 slot.setCustom(this, callerGetter);
174 return true;
175 }
176
177 return Base::getOwnPropertySlot(exec, propertyName, slot);
178}
179
180 bool JSFunction::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
181 {
182 if (isHostFunction())
183 return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
184
185 if (propertyName == exec->propertyNames().prototype) {
186 PropertySlot slot;
187 getOwnPropertySlot(exec, propertyName, slot);
188 return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
189 }
190
191 if (propertyName == exec->propertyNames().arguments) {
192 descriptor.setDescriptor(exec->interpreter()->retrieveArguments(exec, this), ReadOnly | DontEnum | DontDelete);
193 return true;
194 }
195
196 if (propertyName == exec->propertyNames().length) {
197 descriptor.setDescriptor(jsNumber(exec, jsExecutable()->parameterCount()), ReadOnly | DontEnum | DontDelete);
198 return true;
199 }
200
201 if (propertyName == exec->propertyNames().caller) {
202 descriptor.setDescriptor(exec->interpreter()->retrieveCaller(exec, this), ReadOnly | DontEnum | DontDelete);
203 return true;
204 }
205
206 return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
207 }
208
209void JSFunction::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
210{
211 if (isHostFunction()) {
212 Base::put(exec, propertyName, value, slot);
213 return;
214 }
215 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length)
216 return;
217 Base::put(exec, propertyName, value, slot);
218}
219
220bool JSFunction::deleteProperty(ExecState* exec, const Identifier& propertyName)
221{
222 if (isHostFunction())
223 return Base::deleteProperty(exec, propertyName);
224 if (propertyName == exec->propertyNames().arguments || propertyName == exec->propertyNames().length)
225 return false;
226 return Base::deleteProperty(exec, propertyName);
227}
228
229// ECMA 13.2.2 [[Construct]]
230ConstructType JSFunction::getConstructData(ConstructData& constructData)
231{
232 if (isHostFunction())
233 return ConstructTypeNone;
234 constructData.js.functionExecutable = jsExecutable();
235 constructData.js.scopeChain = scopeChain().node();
236 return ConstructTypeJS;
237}
238
239JSObject* JSFunction::construct(ExecState* exec, const ArgList& args)
240{
241 ASSERT(!isHostFunction());
242 Structure* structure;
243 JSValue prototype = get(exec, exec->propertyNames().prototype);
244 if (prototype.isObject())
245 structure = asObject(prototype)->inheritorID();
246 else
247 structure = exec->lexicalGlobalObject()->emptyObjectStructure();
248 JSObject* thisObj = new (exec) JSObject(structure);
249
250 JSValue result = exec->interpreter()->execute(jsExecutable(), exec, this, thisObj, args, scopeChain().node(), exec->exceptionSlot());
251 if (exec->hadException() || !result.isObject())
252 return thisObj;
253 return asObject(result);
254}
255
256} // namespace JSC
Note: See TracBrowser for help on using the repository browser.