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