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