source: webkit/trunk/JavaScriptCore/API/JSCallbackObjectFunctions.h@ 37684

Last change on this file since 37684 was 37684, checked in by Darin Adler, 17 years ago

JavaScriptCore:

2008-10-18 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Use JSValuePtr everywhere instead of JSValue*. In the future, we'll be
changing JSValuePtr to be a class, and then eventually renaming it
to JSValue once that's done.

  • JavaScriptCore.exp: Update entry points, since some now take JSValue* instead of const JSValue*.
  • API/APICast.h:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSValueRef.cpp:
  • VM/CTI.cpp:
  • VM/CTI.h:
  • VM/CodeBlock.cpp:
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp:
  • VM/CodeGenerator.h:
  • VM/ExceptionHelpers.cpp:
  • VM/ExceptionHelpers.h:
  • VM/JSPropertyNameIterator.cpp:
  • VM/JSPropertyNameIterator.h:
  • VM/Machine.cpp:
  • VM/Machine.h:
  • VM/Register.h:
  • kjs/ArgList.cpp:
  • kjs/ArgList.h:
  • kjs/Arguments.cpp:
  • kjs/Arguments.h:
  • kjs/ArrayConstructor.cpp:
  • kjs/ArrayPrototype.cpp:
  • kjs/BooleanConstructor.cpp:
  • kjs/BooleanConstructor.h:
  • kjs/BooleanObject.h:
  • kjs/BooleanPrototype.cpp:
  • kjs/CallData.cpp:
  • kjs/CallData.h:
  • kjs/ConstructData.cpp:
  • kjs/ConstructData.h:
  • kjs/DateConstructor.cpp:
  • kjs/DateInstance.h:
  • kjs/DatePrototype.cpp:
  • kjs/DebuggerCallFrame.cpp:
  • kjs/DebuggerCallFrame.h:
  • kjs/ErrorConstructor.cpp:
  • kjs/ErrorPrototype.cpp:
  • kjs/ExecState.cpp:
  • kjs/ExecState.h:
  • kjs/FunctionConstructor.cpp:
  • kjs/FunctionPrototype.cpp:
  • kjs/GetterSetter.cpp:
  • kjs/GetterSetter.h:
  • kjs/InternalFunction.h:
  • kjs/JSActivation.cpp:
  • kjs/JSActivation.h:
  • kjs/JSArray.cpp:
  • kjs/JSArray.h:
  • kjs/JSCell.cpp:
  • kjs/JSCell.h:
  • kjs/JSFunction.cpp:
  • kjs/JSFunction.h:
  • kjs/JSGlobalData.h:
  • kjs/JSGlobalObject.cpp:
  • kjs/JSGlobalObject.h:
  • kjs/JSGlobalObjectFunctions.cpp:
  • kjs/JSGlobalObjectFunctions.h:
  • kjs/JSImmediate.cpp:
  • kjs/JSImmediate.h:
  • kjs/JSNotAnObject.cpp:
  • kjs/JSNotAnObject.h:
  • kjs/JSNumberCell.cpp:
  • kjs/JSNumberCell.h:
  • kjs/JSObject.cpp:
  • kjs/JSObject.h:
  • kjs/JSStaticScopeObject.cpp:
  • kjs/JSStaticScopeObject.h:
  • kjs/JSString.cpp:
  • kjs/JSString.h:
  • kjs/JSValue.h:
  • kjs/JSVariableObject.h:
  • kjs/JSWrapperObject.h:
  • kjs/MathObject.cpp:
  • kjs/NativeErrorConstructor.cpp:
  • kjs/NumberConstructor.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.cpp:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.cpp:
  • kjs/ObjectConstructor.cpp:
  • kjs/ObjectPrototype.cpp:
  • kjs/ObjectPrototype.h:
  • kjs/PropertyMap.h:
  • kjs/PropertySlot.cpp:
  • kjs/PropertySlot.h:
  • kjs/RegExpConstructor.cpp:
  • kjs/RegExpConstructor.h:
  • kjs/RegExpMatchesArray.h:
  • kjs/RegExpObject.cpp:
  • kjs/RegExpObject.h:
  • kjs/RegExpPrototype.cpp:
  • kjs/Shell.cpp:
  • kjs/StringConstructor.cpp:
  • kjs/StringObject.cpp:
  • kjs/StringObject.h:
  • kjs/StringObjectThatMasqueradesAsUndefined.h:
  • kjs/StringPrototype.cpp:
  • kjs/StructureID.cpp:
  • kjs/StructureID.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/grammar.y:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/nodes.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/protect.h:
  • profiler/ProfileGenerator.cpp: Replace JSValue* with JSValuePtr.

JavaScriptGlue:

2008-10-18 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Use JSValuePtr everywhere instead of JSValue*. In the future, we'll be
changing JSValuePtr to be a class, and then eventually renaming it
to JSValue once that's done.

  • JSObject.cpp:
  • JSValueWrapper.cpp:
  • UserObjectImp.cpp:
  • UserObjectImp.h: Replace JSValue* with JSValuePtr.

WebCore:

2008-10-18 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Use JSValuePtr everywhere instead of JSValue*. In the future, we'll be
changing JSValuePtr to be a class, and then eventually renaming it
to JSValue once that's done.

  • bindings/js/JSAttrCustom.cpp:
  • bindings/js/JSCSSRuleCustom.cpp:
  • bindings/js/JSCSSStyleDeclarationCustom.cpp:
  • bindings/js/JSCSSValueCustom.cpp:
  • bindings/js/JSCanvasPixelArrayCustom.h:
  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:
  • bindings/js/JSClipboardCustom.cpp:
  • bindings/js/JSConsoleCustom.cpp:
  • bindings/js/JSCustomSQLStatementCallback.cpp:
  • bindings/js/JSCustomSQLStatementErrorCallback.cpp:
  • bindings/js/JSCustomSQLTransactionCallback.cpp:
  • bindings/js/JSCustomSQLTransactionErrorCallback.cpp:
  • bindings/js/JSCustomVoidCallback.cpp:
  • bindings/js/JSCustomVoidCallback.h:
  • bindings/js/JSCustomXPathNSResolver.cpp:
  • bindings/js/JSDOMApplicationCacheCustom.cpp:
  • bindings/js/JSDOMBinding.cpp:
  • bindings/js/JSDOMBinding.h:
  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWindowCustom.cpp:
  • bindings/js/JSDOMWindowCustom.h:
  • bindings/js/JSDOMWindowShell.cpp:
  • bindings/js/JSDOMWindowShell.h:
  • bindings/js/JSDatabaseCustom.cpp:
  • bindings/js/JSDocumentCustom.cpp:
  • bindings/js/JSElementCustom.cpp:
  • bindings/js/JSEventCustom.cpp:
  • bindings/js/JSEventListener.cpp:
  • bindings/js/JSEventTarget.cpp:
  • bindings/js/JSEventTargetBase.h:
  • bindings/js/JSEventTargetNodeCustom.cpp:
  • bindings/js/JSHTMLAllCollection.h:
  • bindings/js/JSHTMLAppletElementCustom.cpp:
  • bindings/js/JSHTMLCollectionCustom.cpp:
  • bindings/js/JSHTMLDocumentCustom.cpp:
  • bindings/js/JSHTMLEmbedElementCustom.cpp:
  • bindings/js/JSHTMLFormElementCustom.cpp:
  • bindings/js/JSHTMLFrameElementCustom.cpp:
  • bindings/js/JSHTMLFrameSetElementCustom.cpp:
  • bindings/js/JSHTMLIFrameElementCustom.cpp:
  • bindings/js/JSHTMLInputElementCustom.cpp:
  • bindings/js/JSHTMLObjectElementCustom.cpp:
  • bindings/js/JSHTMLOptionsCollectionCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.cpp:
  • bindings/js/JSHTMLSelectElementCustom.h:
  • bindings/js/JSHistoryCustom.cpp:
  • bindings/js/JSImageDataCustom.cpp:
  • bindings/js/JSInspectedObjectWrapper.cpp:
  • bindings/js/JSInspectedObjectWrapper.h:
  • bindings/js/JSInspectorCallbackWrapper.cpp:
  • bindings/js/JSInspectorCallbackWrapper.h:
  • bindings/js/JSJavaScriptCallFrameCustom.cpp:
  • bindings/js/JSLocationCustom.cpp:
  • bindings/js/JSMessagePortCustom.cpp:
  • bindings/js/JSMimeTypeArrayCustom.cpp:
  • bindings/js/JSNamedNodeMapCustom.cpp:
  • bindings/js/JSNamedNodesCollection.cpp:
  • bindings/js/JSNamedNodesCollection.h:
  • bindings/js/JSNavigatorCustom.cpp:
  • bindings/js/JSNodeCustom.cpp:
  • bindings/js/JSNodeFilterCondition.cpp:
  • bindings/js/JSNodeFilterCustom.cpp:
  • bindings/js/JSNodeIteratorCustom.cpp:
  • bindings/js/JSNodeListCustom.cpp:
  • bindings/js/JSPluginArrayCustom.cpp:
  • bindings/js/JSPluginCustom.cpp:
  • bindings/js/JSPluginElementFunctions.cpp:
  • bindings/js/JSPluginElementFunctions.h:
  • bindings/js/JSQuarantinedObjectWrapper.cpp:
  • bindings/js/JSQuarantinedObjectWrapper.h:
  • bindings/js/JSRGBColor.cpp:
  • bindings/js/JSRGBColor.h:
  • bindings/js/JSSQLResultSetRowListCustom.cpp:
  • bindings/js/JSSQLTransactionCustom.cpp:
  • bindings/js/JSSVGElementInstanceCustom.cpp:
  • bindings/js/JSSVGLengthCustom.cpp:
  • bindings/js/JSSVGMatrixCustom.cpp:
  • bindings/js/JSSVGPathSegCustom.cpp:
  • bindings/js/JSSVGPathSegListCustom.cpp:
  • bindings/js/JSSVGPointListCustom.cpp:
  • bindings/js/JSSVGTransformListCustom.cpp:
  • bindings/js/JSStorageCustom.cpp:
  • bindings/js/JSStyleSheetCustom.cpp:
  • bindings/js/JSStyleSheetListCustom.cpp:
  • bindings/js/JSTextCustom.cpp:
  • bindings/js/JSTreeWalkerCustom.cpp:
  • bindings/js/JSXMLHttpRequestCustom.cpp:
  • bindings/js/JSXMLHttpRequestUploadCustom.cpp:
  • bindings/js/JSXSLTProcessorCustom.cpp:
  • bindings/js/ScheduledAction.cpp:
  • bindings/js/ScheduledAction.h:
  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/objc/WebScriptObject.mm:
  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:
  • bridge/c/c_instance.cpp:
  • bridge/c/c_instance.h:
  • bridge/c/c_runtime.cpp:
  • bridge/c/c_runtime.h:
  • bridge/c/c_utility.cpp:
  • bridge/jni/jni_instance.cpp:
  • bridge/jni/jni_instance.h:
  • bridge/jni/jni_jsobject.mm:
  • bridge/jni/jni_objc.mm:
  • bridge/jni/jni_runtime.cpp:
  • bridge/jni/jni_runtime.h:
  • bridge/jni/jni_utility.cpp:
  • bridge/objc/objc_class.mm:
  • bridge/objc/objc_instance.h:
  • bridge/objc/objc_instance.mm:
  • bridge/objc/objc_runtime.h:
  • bridge/objc/objc_runtime.mm:
  • bridge/objc/objc_utility.h:
  • bridge/objc/objc_utility.mm:
  • bridge/runtime.h:
  • bridge/runtime_array.cpp:
  • bridge/runtime_array.h:
  • bridge/runtime_method.cpp:
  • bridge/runtime_method.h:
  • bridge/runtime_object.cpp:
  • bridge/runtime_object.h:
  • inspector/JavaScriptCallFrame.cpp:
  • inspector/JavaScriptCallFrame.h:
  • inspector/JavaScriptProfile.cpp:
  • inspector/JavaScriptProfileNode.cpp:
  • loader/FrameLoader.cpp:
  • loader/FrameLoader.h:
  • page/Console.cpp:
  • page/Console.h:
  • plugins/MimeTypeArray.h:
  • plugins/Plugin.h:
  • plugins/PluginArray.h:
  • xml/XMLHttpRequest.cpp: Replace JSValue* with JSValuePtr.
  • Property svn:eol-style set to native
File size: 20.3 KB
Line 
1/*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Eric Seidel <[email protected]>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "APICast.h"
28#include "Error.h"
29#include "JSCallbackFunction.h"
30#include "JSClassRef.h"
31#include "JSGlobalObject.h"
32#include "JSLock.h"
33#include "JSObjectRef.h"
34#include "JSString.h"
35#include "JSStringRef.h"
36#include "OpaqueJSString.h"
37#include "PropertyNameArray.h"
38#include <wtf/Vector.h>
39
40namespace JSC {
41
42template <class Base>
43inline JSCallbackObject<Base>* JSCallbackObject<Base>::asCallbackObject(JSValuePtr value)
44{
45 ASSERT(asObject(value)->inherits(&info));
46 return static_cast<JSCallbackObject*>(asObject(value));
47}
48
49template <class Base>
50JSCallbackObject<Base>::JSCallbackObject(ExecState* exec, PassRefPtr<StructureID> structure, JSClassRef jsClass, void* data)
51 : Base(structure)
52 , m_callbackObjectData(new JSCallbackObjectData(data, jsClass))
53{
54 init(exec);
55}
56
57// Global object constructor.
58// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one.
59template <class Base>
60JSCallbackObject<Base>::JSCallbackObject(JSGlobalData* globalData, JSClassRef jsClass)
61 : Base(globalData)
62 , m_callbackObjectData(new JSCallbackObjectData(0, jsClass))
63{
64 ASSERT(Base::isGlobalObject());
65 init(static_cast<JSGlobalObject*>(this)->globalExec());
66}
67
68template <class Base>
69void JSCallbackObject<Base>::init(ExecState* exec)
70{
71 ASSERT(exec);
72
73 Vector<JSObjectInitializeCallback, 16> initRoutines;
74 JSClassRef jsClass = classRef();
75 do {
76 if (JSObjectInitializeCallback initialize = jsClass->initialize)
77 initRoutines.append(initialize);
78 } while ((jsClass = jsClass->parentClass));
79
80 // initialize from base to derived
81 for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) {
82 JSLock::DropAllLocks dropAllLocks(exec);
83 JSObjectInitializeCallback initialize = initRoutines[i];
84 initialize(toRef(exec), toRef(this));
85 }
86}
87
88template <class Base>
89JSCallbackObject<Base>::~JSCallbackObject()
90{
91 JSObjectRef thisRef = toRef(this);
92
93 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
94 if (JSObjectFinalizeCallback finalize = jsClass->finalize)
95 finalize(thisRef);
96}
97
98template <class Base>
99UString JSCallbackObject<Base>::className() const
100{
101 UString thisClassName = classRef()->className();
102 if (!thisClassName.isNull())
103 return thisClassName;
104
105 return Base::className();
106}
107
108template <class Base>
109bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
110{
111 JSContextRef ctx = toRef(exec);
112 JSObjectRef thisRef = toRef(this);
113 RefPtr<OpaqueJSString> propertyNameRef;
114
115 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
116 // optional optimization to bypass getProperty in cases when we only need to know if the property exists
117 if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
118 if (!propertyNameRef)
119 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
120 JSLock::DropAllLocks dropAllLocks(exec);
121 if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
122 slot.setCustom(this, callbackGetter);
123 return true;
124 }
125 } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
126 if (!propertyNameRef)
127 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
128 JSLock::DropAllLocks dropAllLocks(exec);
129 if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) {
130 // cache the value so we don't have to compute it again
131 // FIXME: This violates the PropertySlot design a little bit.
132 // We should either use this optimization everywhere, or nowhere.
133 slot.setCustom(asObject(toJS(value)), cachedValueGetter);
134 return true;
135 }
136 }
137
138 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
139 if (staticValues->contains(propertyName.ustring().rep())) {
140 slot.setCustom(this, staticValueGetter);
141 return true;
142 }
143 }
144
145 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
146 if (staticFunctions->contains(propertyName.ustring().rep())) {
147 slot.setCustom(this, staticFunctionGetter);
148 return true;
149 }
150 }
151 }
152
153 return Base::getOwnPropertySlot(exec, propertyName, slot);
154}
155
156template <class Base>
157bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
158{
159 return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
160}
161
162template <class Base>
163void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot)
164{
165 JSContextRef ctx = toRef(exec);
166 JSObjectRef thisRef = toRef(this);
167 RefPtr<OpaqueJSString> propertyNameRef;
168 JSValueRef valueRef = toRef(value);
169
170 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
171 if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
172 if (!propertyNameRef)
173 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
174 JSLock::DropAllLocks dropAllLocks(exec);
175 if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
176 return;
177 }
178
179 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
180 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
181 if (entry->attributes & kJSPropertyAttributeReadOnly)
182 return;
183 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
184 if (!propertyNameRef)
185 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
186 JSLock::DropAllLocks dropAllLocks(exec);
187 if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
188 return;
189 } else
190 throwError(exec, ReferenceError, "Attempt to set a property that is not settable.");
191 }
192 }
193
194 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
195 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
196 if (entry->attributes & kJSPropertyAttributeReadOnly)
197 return;
198 JSCallbackObject<Base>::putDirect(propertyName, value); // put as override property
199 return;
200 }
201 }
202 }
203
204 return Base::put(exec, propertyName, value, slot);
205}
206
207template <class Base>
208bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& propertyName)
209{
210 JSContextRef ctx = toRef(exec);
211 JSObjectRef thisRef = toRef(this);
212 RefPtr<OpaqueJSString> propertyNameRef;
213
214 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
215 if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
216 if (!propertyNameRef)
217 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
218 JSLock::DropAllLocks dropAllLocks(exec);
219 if (deleteProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
220 return true;
221 }
222
223 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
224 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
225 if (entry->attributes & kJSPropertyAttributeDontDelete)
226 return false;
227 return true;
228 }
229 }
230
231 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
232 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
233 if (entry->attributes & kJSPropertyAttributeDontDelete)
234 return false;
235 return true;
236 }
237 }
238 }
239
240 return Base::deleteProperty(exec, propertyName);
241}
242
243template <class Base>
244bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, unsigned propertyName)
245{
246 return deleteProperty(exec, Identifier::from(exec, propertyName));
247}
248
249template <class Base>
250ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructData)
251{
252 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
253 if (jsClass->callAsConstructor) {
254 constructData.native.function = construct;
255 return ConstructTypeHost;
256 }
257 }
258 return ConstructTypeNone;
259}
260
261template <class Base>
262JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args)
263{
264 JSContextRef execRef = toRef(exec);
265 JSObjectRef constructorRef = toRef(constructor);
266
267 for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
268 if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
269 int argumentCount = static_cast<int>(args.size());
270 Vector<JSValueRef, 16> arguments(argumentCount);
271 for (int i = 0; i < argumentCount; i++)
272 arguments[i] = toRef(args.at(exec, i));
273 JSLock::DropAllLocks dropAllLocks(exec);
274 return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
275 }
276 }
277
278 ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
279 return 0;
280}
281
282template <class Base>
283bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValuePtr value, JSValuePtr)
284{
285 JSContextRef execRef = toRef(exec);
286 JSObjectRef thisRef = toRef(this);
287
288 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
289 if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
290 JSLock::DropAllLocks dropAllLocks(exec);
291 return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
292 }
293 }
294 return false;
295}
296
297template <class Base>
298CallType JSCallbackObject<Base>::getCallData(CallData& callData)
299{
300 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
301 if (jsClass->callAsFunction) {
302 callData.native.function = call;
303 return CallTypeHost;
304 }
305 }
306 return CallTypeNone;
307}
308
309template <class Base>
310JSValuePtr JSCallbackObject<Base>::call(ExecState* exec, JSObject* functionObject, JSValuePtr thisValue, const ArgList& args)
311{
312 JSContextRef execRef = toRef(exec);
313 JSObjectRef functionRef = toRef(functionObject);
314 JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec));
315
316 for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(functionObject)->classRef(); jsClass; jsClass = jsClass->parentClass) {
317 if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
318 int argumentCount = static_cast<int>(args.size());
319 Vector<JSValueRef, 16> arguments(argumentCount);
320 for (int i = 0; i < argumentCount; i++)
321 arguments[i] = toRef(args.at(exec, i));
322 JSLock::DropAllLocks dropAllLocks(exec);
323 return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
324 }
325 }
326
327 ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
328 return noValue();
329}
330
331template <class Base>
332void JSCallbackObject<Base>::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
333{
334 JSContextRef execRef = toRef(exec);
335 JSObjectRef thisRef = toRef(this);
336
337 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
338 if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
339 JSLock::DropAllLocks dropAllLocks(exec);
340 getPropertyNames(execRef, thisRef, toRef(&propertyNames));
341 }
342
343 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
344 typedef OpaqueJSClassStaticValuesTable::const_iterator iterator;
345 iterator end = staticValues->end();
346 for (iterator it = staticValues->begin(); it != end; ++it) {
347 UString::Rep* name = it->first.get();
348 StaticValueEntry* entry = it->second;
349 if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum))
350 propertyNames.add(Identifier(exec, name));
351 }
352 }
353
354 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
355 typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator;
356 iterator end = staticFunctions->end();
357 for (iterator it = staticFunctions->begin(); it != end; ++it) {
358 UString::Rep* name = it->first.get();
359 StaticFunctionEntry* entry = it->second;
360 if (!(entry->attributes & kJSPropertyAttributeDontEnum))
361 propertyNames.add(Identifier(exec, name));
362 }
363 }
364 }
365
366 Base::getPropertyNames(exec, propertyNames);
367}
368
369template <class Base>
370double JSCallbackObject<Base>::toNumber(ExecState* exec) const
371{
372 // We need this check to guard against the case where this object is rhs of
373 // a binary expression where lhs threw an exception in its conversion to
374 // primitive
375 if (exec->hadException())
376 return NaN;
377 JSContextRef ctx = toRef(exec);
378 JSObjectRef thisRef = toRef(this);
379
380 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
381 if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
382 JSLock::DropAllLocks dropAllLocks(exec);
383 if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
384 return toJS(value)->getNumber();
385 }
386
387 return Base::toNumber(exec);
388}
389
390template <class Base>
391UString JSCallbackObject<Base>::toString(ExecState* exec) const
392{
393 JSContextRef ctx = toRef(exec);
394 JSObjectRef thisRef = toRef(this);
395
396 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
397 if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
398 JSValueRef value;
399 {
400 JSLock::DropAllLocks dropAllLocks(exec);
401 value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot()));
402 }
403 if (value)
404 return toJS(value)->getString();
405 }
406
407 return Base::toString(exec);
408}
409
410template <class Base>
411void JSCallbackObject<Base>::setPrivate(void* data)
412{
413 m_callbackObjectData->privateData = data;
414}
415
416template <class Base>
417void* JSCallbackObject<Base>::getPrivate()
418{
419 return m_callbackObjectData->privateData;
420}
421
422template <class Base>
423bool JSCallbackObject<Base>::inherits(JSClassRef c) const
424{
425 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
426 if (jsClass == c)
427 return true;
428
429 return false;
430}
431
432template <class Base>
433JSValuePtr JSCallbackObject<Base>::cachedValueGetter(ExecState*, const Identifier&, const PropertySlot& slot)
434{
435 JSValuePtr v = slot.slotBase();
436 ASSERT(v);
437 return v;
438}
439
440template <class Base>
441JSValuePtr JSCallbackObject<Base>::staticValueGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
442{
443 JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
444
445 JSObjectRef thisRef = toRef(thisObj);
446 RefPtr<OpaqueJSString> propertyNameRef;
447
448 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
449 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
450 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
451 if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
452 if (!propertyNameRef)
453 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
454 JSLock::DropAllLocks dropAllLocks(exec);
455 if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
456 return toJS(value);
457 }
458
459 return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
460}
461
462template <class Base>
463JSValuePtr JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
464{
465 JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
466
467 // Check for cached or override property.
468 PropertySlot slot2(thisObj);
469 if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))
470 return slot2.getValue(exec, propertyName);
471
472 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
473 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
474 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
475 if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
476 JSObject* o = new (exec) JSCallbackFunction(exec, callAsFunction, propertyName);
477 thisObj->putDirect(propertyName, o, entry->attributes);
478 return o;
479 }
480 }
481 }
482 }
483
484 return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
485}
486
487template <class Base>
488JSValuePtr JSCallbackObject<Base>::callbackGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
489{
490 JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
491
492 JSObjectRef thisRef = toRef(thisObj);
493 RefPtr<OpaqueJSString> propertyNameRef;
494
495 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
496 if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
497 if (!propertyNameRef)
498 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
499 JSLock::DropAllLocks dropAllLocks(exec);
500 if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
501 return toJS(value);
502 }
503
504 return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
505}
506
507} // namespace JSC
Note: See TracBrowser for help on using the repository browser.