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