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

Last change on this file since 60631 was 60631, checked in by [email protected], 15 years ago

Bug 40094 - The return type of NativeFunction should be EncodedJSValue
On Windows & Linux, using JSVALUE32_64, EncodedJSValue is returned in registers, but JSValue is not.

Reviewed by Oliver Hunt.

JavaScriptCore:

  • API/JSCallbackFunction.cpp:

(JSC::JSCallbackFunction::call):

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

(JSC::::call):

(JSC::Interpreter::executeCall):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:
  • jsc.cpp:

(functionPrint):
(functionDebug):
(functionGC):
(functionVersion):
(functionRun):
(functionLoad):
(functionCheckSyntax):
(functionSetSamplingFlags):
(functionClearSamplingFlags):
(functionReadline):
(functionQuit):

  • runtime/ArrayConstructor.cpp:

(JSC::callArrayConstructor):
(JSC::arrayConstructorIsArray):

  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncToString):
(JSC::arrayProtoFuncToLocaleString):
(JSC::arrayProtoFuncJoin):
(JSC::arrayProtoFuncConcat):
(JSC::arrayProtoFuncPop):
(JSC::arrayProtoFuncPush):
(JSC::arrayProtoFuncReverse):
(JSC::arrayProtoFuncShift):
(JSC::arrayProtoFuncSlice):
(JSC::arrayProtoFuncSort):
(JSC::arrayProtoFuncSplice):
(JSC::arrayProtoFuncUnShift):
(JSC::arrayProtoFuncFilter):
(JSC::arrayProtoFuncMap):
(JSC::arrayProtoFuncEvery):
(JSC::arrayProtoFuncForEach):
(JSC::arrayProtoFuncSome):
(JSC::arrayProtoFuncReduce):
(JSC::arrayProtoFuncReduceRight):
(JSC::arrayProtoFuncIndexOf):
(JSC::arrayProtoFuncLastIndexOf):

  • runtime/BooleanConstructor.cpp:

(JSC::callBooleanConstructor):

  • runtime/BooleanPrototype.cpp:

(JSC::booleanProtoFuncToString):
(JSC::booleanProtoFuncValueOf):

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

(JSC::callDate):
(JSC::dateParse):
(JSC::dateNow):
(JSC::dateUTC):

  • runtime/DatePrototype.cpp:

(JSC::dateProtoFuncToString):
(JSC::dateProtoFuncToUTCString):
(JSC::dateProtoFuncToISOString):
(JSC::dateProtoFuncToDateString):
(JSC::dateProtoFuncToTimeString):
(JSC::dateProtoFuncToLocaleString):
(JSC::dateProtoFuncToLocaleDateString):
(JSC::dateProtoFuncToLocaleTimeString):
(JSC::dateProtoFuncGetTime):
(JSC::dateProtoFuncGetFullYear):
(JSC::dateProtoFuncGetUTCFullYear):
(JSC::dateProtoFuncToGMTString):
(JSC::dateProtoFuncGetMonth):
(JSC::dateProtoFuncGetUTCMonth):
(JSC::dateProtoFuncGetDate):
(JSC::dateProtoFuncGetUTCDate):
(JSC::dateProtoFuncGetDay):
(JSC::dateProtoFuncGetUTCDay):
(JSC::dateProtoFuncGetHours):
(JSC::dateProtoFuncGetUTCHours):
(JSC::dateProtoFuncGetMinutes):
(JSC::dateProtoFuncGetUTCMinutes):
(JSC::dateProtoFuncGetSeconds):
(JSC::dateProtoFuncGetUTCSeconds):
(JSC::dateProtoFuncGetMilliSeconds):
(JSC::dateProtoFuncGetUTCMilliseconds):
(JSC::dateProtoFuncGetTimezoneOffset):
(JSC::dateProtoFuncSetTime):
(JSC::dateProtoFuncSetMilliSeconds):
(JSC::dateProtoFuncSetUTCMilliseconds):
(JSC::dateProtoFuncSetSeconds):
(JSC::dateProtoFuncSetUTCSeconds):
(JSC::dateProtoFuncSetMinutes):
(JSC::dateProtoFuncSetUTCMinutes):
(JSC::dateProtoFuncSetHours):
(JSC::dateProtoFuncSetUTCHours):
(JSC::dateProtoFuncSetDate):
(JSC::dateProtoFuncSetUTCDate):
(JSC::dateProtoFuncSetMonth):
(JSC::dateProtoFuncSetUTCMonth):
(JSC::dateProtoFuncSetFullYear):
(JSC::dateProtoFuncSetUTCFullYear):
(JSC::dateProtoFuncSetYear):
(JSC::dateProtoFuncGetYear):
(JSC::dateProtoFuncToJSON):

  • runtime/ErrorConstructor.cpp:

(JSC::callErrorConstructor):

  • runtime/ErrorPrototype.cpp:

(JSC::errorProtoFuncToString):

  • runtime/FunctionConstructor.cpp:

(JSC::callFunctionConstructor):

  • runtime/FunctionPrototype.cpp:

(JSC::callFunctionPrototype):
(JSC::functionProtoFuncToString):
(JSC::functionProtoFuncApply):
(JSC::functionProtoFuncCall):

  • runtime/JSCell.h:

(JSC::getCallData):
(JSC::getConstructData):

  • runtime/JSFunction.cpp:

(JSC::callHostFunctionAsConstructor):

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

(JSC::globalFuncEval):
(JSC::globalFuncParseInt):
(JSC::globalFuncParseFloat):
(JSC::globalFuncIsNaN):
(JSC::globalFuncIsFinite):
(JSC::globalFuncDecodeURI):
(JSC::globalFuncDecodeURIComponent):
(JSC::globalFuncEncodeURI):
(JSC::globalFuncEncodeURIComponent):
(JSC::globalFuncEscape):
(JSC::globalFuncUnescape):
(JSC::globalFuncJSCPrint):

  • runtime/JSGlobalObjectFunctions.h:
  • runtime/JSONObject.cpp:

(JSC::JSONProtoFuncParse):
(JSC::JSONProtoFuncStringify):

  • runtime/JSObject.cpp:

(JSC::callDefaultValueFunction):

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

(JSC::mathProtoFuncAbs):
(JSC::mathProtoFuncACos):
(JSC::mathProtoFuncASin):
(JSC::mathProtoFuncATan):
(JSC::mathProtoFuncATan2):
(JSC::mathProtoFuncCeil):
(JSC::mathProtoFuncCos):
(JSC::mathProtoFuncExp):
(JSC::mathProtoFuncFloor):
(JSC::mathProtoFuncLog):
(JSC::mathProtoFuncMax):
(JSC::mathProtoFuncMin):
(JSC::mathProtoFuncPow):
(JSC::mathProtoFuncRandom):
(JSC::mathProtoFuncRound):
(JSC::mathProtoFuncSin):
(JSC::mathProtoFuncSqrt):
(JSC::mathProtoFuncTan):

  • runtime/NativeErrorConstructor.cpp:

(JSC::callNativeErrorConstructor):

  • runtime/NumberConstructor.cpp:

(JSC::callNumberConstructor):

  • runtime/NumberPrototype.cpp:

(JSC::numberProtoFuncToString):
(JSC::numberProtoFuncToLocaleString):
(JSC::numberProtoFuncValueOf):
(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToExponential):
(JSC::numberProtoFuncToPrecision):

  • runtime/ObjectConstructor.cpp:

(JSC::callObjectConstructor):
(JSC::objectConstructorGetPrototypeOf):
(JSC::objectConstructorGetOwnPropertyDescriptor):
(JSC::objectConstructorGetOwnPropertyNames):
(JSC::objectConstructorKeys):
(JSC::toPropertyDescriptor):
(JSC::objectConstructorDefineProperty):
(JSC::objectConstructorDefineProperties):
(JSC::objectConstructorCreate):

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncValueOf):
(JSC::objectProtoFuncHasOwnProperty):
(JSC::objectProtoFuncIsPrototypeOf):
(JSC::objectProtoFuncDefineGetter):
(JSC::objectProtoFuncDefineSetter):
(JSC::objectProtoFuncLookupGetter):
(JSC::objectProtoFuncLookupSetter):
(JSC::objectProtoFuncPropertyIsEnumerable):
(JSC::objectProtoFuncToLocaleString):
(JSC::objectProtoFuncToString):

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

(JSC::callRegExpConstructor):

  • runtime/RegExpObject.cpp:

(JSC::callRegExpObject):

  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncTest):
(JSC::regExpProtoFuncExec):
(JSC::regExpProtoFuncCompile):
(JSC::regExpProtoFuncToString):

  • runtime/StringConstructor.cpp:

(JSC::stringFromCharCode):
(JSC::callStringConstructor):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncReplace):
(JSC::stringProtoFuncToString):
(JSC::stringProtoFuncCharAt):
(JSC::stringProtoFuncCharCodeAt):
(JSC::stringProtoFuncConcat):
(JSC::stringProtoFuncIndexOf):
(JSC::stringProtoFuncLastIndexOf):
(JSC::stringProtoFuncMatch):
(JSC::stringProtoFuncSearch):
(JSC::stringProtoFuncSlice):
(JSC::stringProtoFuncSplit):
(JSC::stringProtoFuncSubstr):
(JSC::stringProtoFuncSubstring):
(JSC::stringProtoFuncToLowerCase):
(JSC::stringProtoFuncToUpperCase):
(JSC::stringProtoFuncLocaleCompare):
(JSC::stringProtoFuncBig):
(JSC::stringProtoFuncSmall):
(JSC::stringProtoFuncBlink):
(JSC::stringProtoFuncBold):
(JSC::stringProtoFuncFixed):
(JSC::stringProtoFuncItalics):
(JSC::stringProtoFuncStrike):
(JSC::stringProtoFuncSub):
(JSC::stringProtoFuncSup):
(JSC::stringProtoFuncFontcolor):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncAnchor):
(JSC::stringProtoFuncLink):
(JSC::stringProtoFuncTrim):
(JSC::stringProtoFuncTrimLeft):
(JSC::stringProtoFuncTrimRight):

JavaScriptGlue:

  • JSObject.cpp:

(nativeCallFunction):

WebCore:

  • bindings/js/JSCallbackData.cpp:

(WebCore::JSCallbackData::invokeCallback):

  • bindings/js/JSCustomXPathNSResolver.cpp:

(WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):

  • bindings/js/JSEventListener.cpp:

(WebCore::JSEventListener::handleEvent):

  • bindings/js/JSHTMLAllCollectionCustom.cpp:

(WebCore::callHTMLAllCollection):

  • bindings/js/JSHTMLCollectionCustom.cpp:

(WebCore::callHTMLCollection):

  • bindings/js/JSHTMLDocumentCustom.cpp:

(WebCore::JSHTMLDocument::open):

  • bindings/js/JSInjectedScriptHostCustom.cpp:

(WebCore::InjectedScriptHost::createInjectedScript):

  • bindings/js/JSNodeFilterCondition.cpp:

(WebCore::JSNodeFilterCondition::acceptNode):

  • bindings/js/JSNodeListCustom.cpp:

(WebCore::callNodeList):

  • bindings/js/JSPluginElementFunctions.cpp:

(WebCore::callPlugin):

  • bindings/js/ScheduledAction.cpp:

(WebCore::ScheduledAction::create):
(WebCore::ScheduledAction::executeFunctionInContext):

  • bindings/js/ScriptFunctionCall.cpp:

(WebCore::ScriptFunctionCall::call):

  • bindings/js/SerializedScriptValue.cpp:

(WebCore::SerializingTreeWalker::convertIfTerminal):

  • bindings/objc/WebScriptObject.mm:

(-[WebScriptObject callWebScriptMethod:withArguments:]):

  • bindings/scripts/CodeGeneratorJS.pm:
  • bridge/NP_jsobject.cpp:

(_NPN_InvokeDefault):
(_NPN_Invoke):
(_NPN_Construct):

  • bridge/jni/jni_jsobject.mm:

(JavaJSObject::call):

  • bridge/objc/objc_runtime.mm:

(JSC::Bindings::callObjCFallbackObject):

  • bridge/runtime_method.cpp:

(JSC::callRuntimeMethod):

  • bridge/runtime_object.cpp:

(JSC::Bindings::callRuntimeObject):

WebKit/mac:

  • Plugins/Hosted/NetscapePluginInstanceProxy.h:
  • Plugins/Hosted/NetscapePluginInstanceProxy.mm:

(WebKit::NetscapePluginInstanceProxy::invoke):

  • Property svn:eol-style set to native
File size: 23.4 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 "APIShims.h"
28#include "APICast.h"
29#include "Error.h"
30#include "JSCallbackFunction.h"
31#include "JSClassRef.h"
32#include "JSFunction.h"
33#include "JSGlobalObject.h"
34#include "JSLock.h"
35#include "JSObjectRef.h"
36#include "JSString.h"
37#include "JSStringRef.h"
38#include "OpaqueJSString.h"
39#include "PropertyNameArray.h"
40#include <wtf/Vector.h>
41
42namespace JSC {
43
44template <class Base>
45inline JSCallbackObject<Base>* JSCallbackObject<Base>::asCallbackObject(JSValue value)
46{
47 ASSERT(asObject(value)->inherits(&info));
48 return static_cast<JSCallbackObject*>(asObject(value));
49}
50
51template <class Base>
52JSCallbackObject<Base>::JSCallbackObject(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, JSClassRef jsClass, void* data)
53 : Base(globalObject, structure)
54 , m_callbackObjectData(new JSCallbackObjectData(data, jsClass))
55{
56 init(exec);
57}
58
59// Global object constructor.
60// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one.
61template <class Base>
62JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass, NonNullPassRefPtr<Structure> structure)
63 : Base(structure)
64 , m_callbackObjectData(new JSCallbackObjectData(0, jsClass))
65{
66 ASSERT(Base::isGlobalObject());
67 init(static_cast<JSGlobalObject*>(this)->globalExec());
68}
69
70template <class Base>
71void JSCallbackObject<Base>::init(ExecState* exec)
72{
73 ASSERT(exec);
74
75 Vector<JSObjectInitializeCallback, 16> initRoutines;
76 JSClassRef jsClass = classRef();
77 do {
78 if (JSObjectInitializeCallback initialize = jsClass->initialize)
79 initRoutines.append(initialize);
80 } while ((jsClass = jsClass->parentClass));
81
82 // initialize from base to derived
83 for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) {
84 APICallbackShim callbackShim(exec);
85 JSObjectInitializeCallback initialize = initRoutines[i];
86 initialize(toRef(exec), toRef(this));
87 }
88}
89
90template <class Base>
91JSCallbackObject<Base>::~JSCallbackObject()
92{
93 JSObjectRef thisRef = toRef(this);
94
95 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
96 if (JSObjectFinalizeCallback finalize = jsClass->finalize)
97 finalize(thisRef);
98}
99
100template <class Base>
101UString JSCallbackObject<Base>::className() const
102{
103 UString thisClassName = classRef()->className();
104 if (!thisClassName.isEmpty())
105 return thisClassName;
106
107 return Base::className();
108}
109
110template <class Base>
111bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
112{
113 JSContextRef ctx = toRef(exec);
114 JSObjectRef thisRef = toRef(this);
115 RefPtr<OpaqueJSString> propertyNameRef;
116
117 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
118 // optional optimization to bypass getProperty in cases when we only need to know if the property exists
119 if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
120 if (!propertyNameRef)
121 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
122 APICallbackShim callbackShim(exec);
123 if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
124 slot.setCustom(this, callbackGetter);
125 return true;
126 }
127 } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
128 if (!propertyNameRef)
129 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
130 JSValueRef exception = 0;
131 JSValueRef value;
132 {
133 APICallbackShim callbackShim(exec);
134 value = getProperty(ctx, thisRef, propertyNameRef.get(), &exception);
135 }
136 if (exception) {
137 exec->setException(toJS(exec, exception));
138 slot.setValue(jsUndefined());
139 return true;
140 }
141 if (value) {
142 slot.setValue(toJS(exec, value));
143 return true;
144 }
145 }
146
147 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
148 if (staticValues->contains(propertyName.ustring().rep())) {
149 slot.setCustom(this, staticValueGetter);
150 return true;
151 }
152 }
153
154 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
155 if (staticFunctions->contains(propertyName.ustring().rep())) {
156 slot.setCustom(this, staticFunctionGetter);
157 return true;
158 }
159 }
160 }
161
162 return Base::getOwnPropertySlot(exec, propertyName, slot);
163}
164
165template <class Base>
166bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
167{
168 return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
169}
170
171template <class Base>
172bool JSCallbackObject<Base>::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
173{
174 PropertySlot slot;
175 if (getOwnPropertySlot(exec, propertyName, slot)) {
176 // Ideally we should return an access descriptor, but returning a value descriptor is better than nothing.
177 JSValue value = slot.getValue(exec, propertyName);
178 if (!exec->hadException())
179 descriptor.setValue(value);
180 // We don't know whether the property is configurable, but assume it is.
181 descriptor.setConfigurable(true);
182 // We don't know whether the property is enumerable (we could call getOwnPropertyNames() to find out), but assume it isn't.
183 descriptor.setEnumerable(false);
184 return true;
185 }
186
187 return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
188}
189
190template <class Base>
191void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
192{
193 JSContextRef ctx = toRef(exec);
194 JSObjectRef thisRef = toRef(this);
195 RefPtr<OpaqueJSString> propertyNameRef;
196 JSValueRef valueRef = toRef(exec, value);
197
198 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
199 if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
200 if (!propertyNameRef)
201 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
202 JSValueRef exception = 0;
203 bool result;
204 {
205 APICallbackShim callbackShim(exec);
206 result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
207 }
208 if (exception)
209 exec->setException(toJS(exec, exception));
210 if (result || exception)
211 return;
212 }
213
214 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
215 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
216 if (entry->attributes & kJSPropertyAttributeReadOnly)
217 return;
218 if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
219 if (!propertyNameRef)
220 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
221 JSValueRef exception = 0;
222 bool result;
223 {
224 APICallbackShim callbackShim(exec);
225 result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
226 }
227 if (exception)
228 exec->setException(toJS(exec, exception));
229 if (result || exception)
230 return;
231 } else
232 throwError(exec, ReferenceError, "Attempt to set a property that is not settable.");
233 }
234 }
235
236 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
237 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
238 if (entry->attributes & kJSPropertyAttributeReadOnly)
239 return;
240 JSCallbackObject<Base>::putDirect(propertyName, value); // put as override property
241 return;
242 }
243 }
244 }
245
246 return Base::put(exec, propertyName, value, slot);
247}
248
249template <class Base>
250bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& propertyName)
251{
252 JSContextRef ctx = toRef(exec);
253 JSObjectRef thisRef = toRef(this);
254 RefPtr<OpaqueJSString> propertyNameRef;
255
256 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
257 if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
258 if (!propertyNameRef)
259 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
260 JSValueRef exception = 0;
261 bool result;
262 {
263 APICallbackShim callbackShim(exec);
264 result = deleteProperty(ctx, thisRef, propertyNameRef.get(), &exception);
265 }
266 if (exception)
267 exec->setException(toJS(exec, exception));
268 if (result || exception)
269 return true;
270 }
271
272 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
273 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
274 if (entry->attributes & kJSPropertyAttributeDontDelete)
275 return false;
276 return true;
277 }
278 }
279
280 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
281 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
282 if (entry->attributes & kJSPropertyAttributeDontDelete)
283 return false;
284 return true;
285 }
286 }
287 }
288
289 return Base::deleteProperty(exec, propertyName);
290}
291
292template <class Base>
293bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, unsigned propertyName)
294{
295 return deleteProperty(exec, Identifier::from(exec, propertyName));
296}
297
298template <class Base>
299ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructData)
300{
301 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
302 if (jsClass->callAsConstructor) {
303 constructData.native.function = construct;
304 return ConstructTypeHost;
305 }
306 }
307 return ConstructTypeNone;
308}
309
310template <class Base>
311JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args)
312{
313 JSContextRef execRef = toRef(exec);
314 JSObjectRef constructorRef = toRef(constructor);
315
316 for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
317 if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
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(exec, args.at(i));
322 JSValueRef exception = 0;
323 JSObject* result;
324 {
325 APICallbackShim callbackShim(exec);
326 result = toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), &exception));
327 }
328 if (exception)
329 exec->setException(toJS(exec, exception));
330 return result;
331 }
332 }
333
334 ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
335 return 0;
336}
337
338template <class Base>
339bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue value, JSValue)
340{
341 JSContextRef execRef = toRef(exec);
342 JSObjectRef thisRef = toRef(this);
343
344 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
345 if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
346 JSValueRef valueRef = toRef(exec, value);
347 JSValueRef exception = 0;
348 bool result;
349 {
350 APICallbackShim callbackShim(exec);
351 result = hasInstance(execRef, thisRef, valueRef, &exception);
352 }
353 if (exception)
354 exec->setException(toJS(exec, exception));
355 return result;
356 }
357 }
358 return false;
359}
360
361template <class Base>
362CallType JSCallbackObject<Base>::getCallData(CallData& callData)
363{
364 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
365 if (jsClass->callAsFunction) {
366 callData.native.function = call;
367 return CallTypeHost;
368 }
369 }
370 return CallTypeNone;
371}
372
373template <class Base>
374EncodedJSValue JSCallbackObject<Base>::call(ExecState* exec)
375{
376 JSContextRef execRef = toRef(exec);
377 JSObjectRef functionRef = toRef(exec->callee());
378 JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));
379
380 for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(toJS(functionRef))->classRef(); jsClass; jsClass = jsClass->parentClass) {
381 if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
382 int argumentCount = static_cast<int>(exec->argumentCount());
383 Vector<JSValueRef, 16> arguments(argumentCount);
384 for (int i = 0; i < argumentCount; i++)
385 arguments[i] = toRef(exec, exec->argument(i));
386 JSValueRef exception = 0;
387 JSValue result;
388 {
389 APICallbackShim callbackShim(exec);
390 result = toJS(exec, callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception));
391 }
392 if (exception)
393 exec->setException(toJS(exec, exception));
394 return JSValue::encode(result);
395 }
396 }
397
398 ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
399 return JSValue::encode(JSValue());
400}
401
402template <class Base>
403void JSCallbackObject<Base>::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
404{
405 JSContextRef execRef = toRef(exec);
406 JSObjectRef thisRef = toRef(this);
407
408 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
409 if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
410 APICallbackShim callbackShim(exec);
411 getPropertyNames(execRef, thisRef, toRef(&propertyNames));
412 }
413
414 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
415 typedef OpaqueJSClassStaticValuesTable::const_iterator iterator;
416 iterator end = staticValues->end();
417 for (iterator it = staticValues->begin(); it != end; ++it) {
418 UString::Rep* name = it->first.get();
419 StaticValueEntry* entry = it->second;
420 if (entry->getProperty && (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties)))
421 propertyNames.add(Identifier(exec, name));
422 }
423 }
424
425 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
426 typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator;
427 iterator end = staticFunctions->end();
428 for (iterator it = staticFunctions->begin(); it != end; ++it) {
429 UString::Rep* name = it->first.get();
430 StaticFunctionEntry* entry = it->second;
431 if (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties))
432 propertyNames.add(Identifier(exec, name));
433 }
434 }
435 }
436
437 Base::getOwnPropertyNames(exec, propertyNames, mode);
438}
439
440template <class Base>
441double JSCallbackObject<Base>::toNumber(ExecState* exec) const
442{
443 // We need this check to guard against the case where this object is rhs of
444 // a binary expression where lhs threw an exception in its conversion to
445 // primitive
446 if (exec->hadException())
447 return NaN;
448 JSContextRef ctx = toRef(exec);
449 JSObjectRef thisRef = toRef(this);
450
451 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
452 if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
453 JSValueRef exception = 0;
454 JSValueRef value;
455 {
456 APICallbackShim callbackShim(exec);
457 value = convertToType(ctx, thisRef, kJSTypeNumber, &exception);
458 }
459 if (exception) {
460 exec->setException(toJS(exec, exception));
461 return 0;
462 }
463
464 double dValue;
465 if (value)
466 return toJS(exec, value).getNumber(dValue) ? dValue : NaN;
467 }
468
469 return Base::toNumber(exec);
470}
471
472template <class Base>
473UString JSCallbackObject<Base>::toString(ExecState* exec) const
474{
475 JSContextRef ctx = toRef(exec);
476 JSObjectRef thisRef = toRef(this);
477
478 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
479 if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
480 JSValueRef exception = 0;
481 JSValueRef value;
482 {
483 APICallbackShim callbackShim(exec);
484 value = convertToType(ctx, thisRef, kJSTypeString, &exception);
485 }
486 if (exception) {
487 exec->setException(toJS(exec, exception));
488 return "";
489 }
490 if (value)
491 return toJS(exec, value).getString(exec);
492 }
493
494 return Base::toString(exec);
495}
496
497template <class Base>
498void JSCallbackObject<Base>::setPrivate(void* data)
499{
500 m_callbackObjectData->privateData = data;
501}
502
503template <class Base>
504void* JSCallbackObject<Base>::getPrivate()
505{
506 return m_callbackObjectData->privateData;
507}
508
509template <class Base>
510bool JSCallbackObject<Base>::inherits(JSClassRef c) const
511{
512 for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
513 if (jsClass == c)
514 return true;
515
516 return false;
517}
518
519template <class Base>
520JSValue JSCallbackObject<Base>::staticValueGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
521{
522 JSCallbackObject* thisObj = asCallbackObject(slotBase);
523
524 JSObjectRef thisRef = toRef(thisObj);
525 RefPtr<OpaqueJSString> propertyNameRef;
526
527 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
528 if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
529 if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
530 if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
531 if (!propertyNameRef)
532 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
533 JSValueRef exception = 0;
534 JSValueRef value;
535 {
536 APICallbackShim callbackShim(exec);
537 value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
538 }
539 if (exception) {
540 exec->setException(toJS(exec, exception));
541 return jsUndefined();
542 }
543 if (value)
544 return toJS(exec, value);
545 }
546
547 return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
548}
549
550template <class Base>
551JSValue JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
552{
553 JSCallbackObject* thisObj = asCallbackObject(slotBase);
554
555 // Check for cached or override property.
556 PropertySlot slot2(thisObj);
557 if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))
558 return slot2.getValue(exec, propertyName);
559
560 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
561 if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
562 if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
563 if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
564
565 JSObject* o = new (exec) JSCallbackFunction(exec, asGlobalObject(thisObj->getAnonymousValue(0)), callAsFunction, propertyName);
566 thisObj->putDirect(propertyName, o, entry->attributes);
567 return o;
568 }
569 }
570 }
571 }
572
573 return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
574}
575
576template <class Base>
577JSValue JSCallbackObject<Base>::callbackGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
578{
579 JSCallbackObject* thisObj = asCallbackObject(slotBase);
580
581 JSObjectRef thisRef = toRef(thisObj);
582 RefPtr<OpaqueJSString> propertyNameRef;
583
584 for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
585 if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
586 if (!propertyNameRef)
587 propertyNameRef = OpaqueJSString::create(propertyName.ustring());
588 JSValueRef exception = 0;
589 JSValueRef value;
590 {
591 APICallbackShim callbackShim(exec);
592 value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
593 }
594 if (exception) {
595 exec->setException(toJS(exec, exception));
596 return jsUndefined();
597 }
598 if (value)
599 return toJS(exec, value);
600 }
601
602 return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
603}
604
605} // namespace JSC
Note: See TracBrowser for help on using the repository browser.