1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | *
|
---|
14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
---|
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
---|
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include "APICast.h"
|
---|
28 | #include "JSCallbackFunction.h"
|
---|
29 | #include "JSCallbackObject.h"
|
---|
30 | #include "JSStringRef.h"
|
---|
31 | #include "JSClassRef.h"
|
---|
32 | #include "JSObjectRef.h"
|
---|
33 | #include "internal.h"
|
---|
34 | #include "PropertyNameArray.h"
|
---|
35 |
|
---|
36 | namespace KJS {
|
---|
37 |
|
---|
38 | const ClassInfo JSCallbackObject::info = { "CallbackObject", 0, 0, 0 };
|
---|
39 |
|
---|
40 | JSCallbackObject::JSCallbackObject(ExecState* exec, JSClassRef jsClass)
|
---|
41 | : JSObject()
|
---|
42 | {
|
---|
43 | init(exec, jsClass);
|
---|
44 | }
|
---|
45 |
|
---|
46 | JSCallbackObject::JSCallbackObject(ExecState* exec, JSClassRef jsClass, JSValue* prototype)
|
---|
47 | : JSObject(prototype)
|
---|
48 | {
|
---|
49 | init(exec, jsClass);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void JSCallbackObject::init(ExecState* exec, JSClassRef jsClass)
|
---|
53 | {
|
---|
54 | m_privateData = 0;
|
---|
55 | m_class = JSClassRetain(jsClass);
|
---|
56 |
|
---|
57 | Vector<JSObjectInitializeCallback, 16> initRoutines;
|
---|
58 | do {
|
---|
59 | if (JSObjectInitializeCallback initialize = jsClass->initialize)
|
---|
60 | initRoutines.append(initialize);
|
---|
61 | } while ((jsClass = jsClass->parentClass));
|
---|
62 |
|
---|
63 | // initialize from base to derived
|
---|
64 | for (int i = initRoutines.size() - 1; i >= 0; i--) {
|
---|
65 | JSObjectInitializeCallback initialize = initRoutines[i];
|
---|
66 | initialize(toRef(exec), toRef(this), toRef(exec->exceptionSlot()));
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | JSCallbackObject::~JSCallbackObject()
|
---|
71 | {
|
---|
72 | JSObjectRef thisRef = toRef(this);
|
---|
73 |
|
---|
74 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
75 | if (JSObjectFinalizeCallback finalize = jsClass->finalize)
|
---|
76 | finalize(thisRef);
|
---|
77 |
|
---|
78 | JSClassRelease(m_class);
|
---|
79 | }
|
---|
80 |
|
---|
81 | UString JSCallbackObject::className() const
|
---|
82 | {
|
---|
83 | if (!m_class->className.isNull())
|
---|
84 | return m_class->className;
|
---|
85 |
|
---|
86 | return JSObject::className();
|
---|
87 | }
|
---|
88 |
|
---|
89 | bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
|
---|
90 | {
|
---|
91 | JSContextRef ctx = toRef(exec);
|
---|
92 | JSObjectRef thisRef = toRef(this);
|
---|
93 | JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
|
---|
94 |
|
---|
95 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
96 | // optional optimization to bypass getProperty in cases when we only need to know if the property exists
|
---|
97 | if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
|
---|
98 | if (hasProperty(ctx, thisRef, propertyNameRef)) {
|
---|
99 | slot.setCustom(this, callbackGetter);
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 | } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
|
---|
103 | if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
|
---|
104 | // cache the value so we don't have to compute it again
|
---|
105 | // FIXME: This violates the PropertySlot design a little bit.
|
---|
106 | // We should either use this optimization everywhere, or nowhere.
|
---|
107 | slot.setCustom(reinterpret_cast<JSObject*>(toJS(value)), cachedValueGetter);
|
---|
108 | return true;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
|
---|
113 | if (staticValues->contains(propertyName.ustring().rep())) {
|
---|
114 | slot.setCustom(this, staticValueGetter);
|
---|
115 | return true;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
|
---|
120 | if (staticFunctions->contains(propertyName.ustring().rep())) {
|
---|
121 | slot.setCustom(this, staticFunctionGetter);
|
---|
122 | return true;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | return JSObject::getOwnPropertySlot(exec, propertyName, slot);
|
---|
128 | }
|
---|
129 |
|
---|
130 | bool JSCallbackObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
|
---|
131 | {
|
---|
132 | return getOwnPropertySlot(exec, Identifier::from(propertyName), slot);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void JSCallbackObject::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
|
---|
136 | {
|
---|
137 | JSContextRef ctx = toRef(exec);
|
---|
138 | JSObjectRef thisRef = toRef(this);
|
---|
139 | JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
|
---|
140 | JSValueRef valueRef = toRef(value);
|
---|
141 |
|
---|
142 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
143 | if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
|
---|
144 | if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
|
---|
145 | return;
|
---|
146 | }
|
---|
147 |
|
---|
148 | if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
|
---|
149 | if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
|
---|
150 | if (entry->attributes & kJSPropertyAttributeReadOnly)
|
---|
151 | return;
|
---|
152 | if (JSObjectSetPropertyCallback setProperty = entry->setProperty)
|
---|
153 | setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot()));
|
---|
154 | else
|
---|
155 | throwError(exec, ReferenceError, "Writable static value property defined with NULL setProperty callback.");
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
|
---|
160 | if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
|
---|
161 | if (entry->attributes & kJSPropertyAttributeReadOnly)
|
---|
162 | return;
|
---|
163 | putDirect(propertyName, value, attr); // put as override property
|
---|
164 | return;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | return JSObject::put(exec, propertyName, value, attr);
|
---|
170 | }
|
---|
171 |
|
---|
172 | void JSCallbackObject::put(ExecState* exec, unsigned propertyName, JSValue* value, int attr)
|
---|
173 | {
|
---|
174 | return put(exec, Identifier::from(propertyName), value, attr);
|
---|
175 | }
|
---|
176 |
|
---|
177 | bool JSCallbackObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
|
---|
178 | {
|
---|
179 | JSContextRef ctx = toRef(exec);
|
---|
180 | JSObjectRef thisRef = toRef(this);
|
---|
181 | JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
|
---|
182 |
|
---|
183 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
184 | if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
|
---|
185 | if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
|
---|
186 | return true;
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
|
---|
190 | if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
|
---|
191 | if (entry->attributes & kJSPropertyAttributeDontDelete)
|
---|
192 | return false;
|
---|
193 | return true;
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
|
---|
198 | if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
|
---|
199 | if (entry->attributes & kJSPropertyAttributeDontDelete)
|
---|
200 | return false;
|
---|
201 | return true;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | return JSObject::deleteProperty(exec, propertyName);
|
---|
207 | }
|
---|
208 |
|
---|
209 | bool JSCallbackObject::deleteProperty(ExecState* exec, unsigned propertyName)
|
---|
210 | {
|
---|
211 | return deleteProperty(exec, Identifier::from(propertyName));
|
---|
212 | }
|
---|
213 |
|
---|
214 | bool JSCallbackObject::implementsConstruct() const
|
---|
215 | {
|
---|
216 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
217 | if (jsClass->callAsConstructor)
|
---|
218 | return true;
|
---|
219 |
|
---|
220 | return false;
|
---|
221 | }
|
---|
222 |
|
---|
223 | JSObject* JSCallbackObject::construct(ExecState* exec, const List& args)
|
---|
224 | {
|
---|
225 | JSContextRef execRef = toRef(exec);
|
---|
226 | JSObjectRef thisRef = toRef(this);
|
---|
227 |
|
---|
228 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
229 | if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
|
---|
230 | size_t argumentCount = args.size();
|
---|
231 | JSValueRef arguments[argumentCount];
|
---|
232 | for (size_t i = 0; i < argumentCount; i++)
|
---|
233 | arguments[i] = toRef(args[i]);
|
---|
234 | return toJS(callAsConstructor(execRef, thisRef, argumentCount, arguments, toRef(exec->exceptionSlot())));
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | ASSERT(0); // implementsConstruct should prevent us from reaching here
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 |
|
---|
242 | bool JSCallbackObject::implementsHasInstance() const
|
---|
243 | {
|
---|
244 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
245 | if (jsClass->hasInstance)
|
---|
246 | return true;
|
---|
247 |
|
---|
248 | return false;
|
---|
249 | }
|
---|
250 |
|
---|
251 | bool JSCallbackObject::hasInstance(ExecState *exec, JSValue *value)
|
---|
252 | {
|
---|
253 | JSContextRef execRef = toRef(exec);
|
---|
254 | JSObjectRef thisRef = toRef(this);
|
---|
255 |
|
---|
256 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
257 | if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance)
|
---|
258 | return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
|
---|
259 |
|
---|
260 | ASSERT(0); // implementsHasInstance should prevent us from reaching here
|
---|
261 | return 0;
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | bool JSCallbackObject::implementsCall() const
|
---|
266 | {
|
---|
267 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
268 | if (jsClass->callAsFunction)
|
---|
269 | return true;
|
---|
270 |
|
---|
271 | return false;
|
---|
272 | }
|
---|
273 |
|
---|
274 | JSValue* JSCallbackObject::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args)
|
---|
275 | {
|
---|
276 | JSContextRef execRef = toRef(exec);
|
---|
277 | JSObjectRef thisRef = toRef(this);
|
---|
278 | JSObjectRef thisObjRef = toRef(thisObj);
|
---|
279 |
|
---|
280 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
281 | if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
|
---|
282 | size_t argumentCount = args.size();
|
---|
283 | JSValueRef arguments[argumentCount];
|
---|
284 | for (size_t i = 0; i < argumentCount; i++)
|
---|
285 | arguments[i] = toRef(args[i]);
|
---|
286 | return toJS(callAsFunction(execRef, thisRef, thisObjRef, argumentCount, arguments, toRef(exec->exceptionSlot())));
|
---|
287 | }
|
---|
288 | }
|
---|
289 |
|
---|
290 | ASSERT(0); // implementsCall should prevent us from reaching here
|
---|
291 | return 0;
|
---|
292 | }
|
---|
293 |
|
---|
294 | void JSCallbackObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
|
---|
295 | {
|
---|
296 | JSContextRef execRef = toRef(exec);
|
---|
297 | JSObjectRef thisRef = toRef(this);
|
---|
298 |
|
---|
299 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
300 | if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames)
|
---|
301 | getPropertyNames(execRef, thisRef, toRef(&propertyNames));
|
---|
302 |
|
---|
303 | if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
|
---|
304 | typedef OpaqueJSClass::StaticValuesTable::const_iterator iterator;
|
---|
305 | iterator end = staticValues->end();
|
---|
306 | for (iterator it = staticValues->begin(); it != end; ++it) {
|
---|
307 | UString::Rep* name = it->first.get();
|
---|
308 | StaticValueEntry* entry = it->second;
|
---|
309 | if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum))
|
---|
310 | propertyNames.add(Identifier(name));
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
|
---|
315 | typedef OpaqueJSClass::StaticFunctionsTable::const_iterator iterator;
|
---|
316 | iterator end = staticFunctions->end();
|
---|
317 | for (iterator it = staticFunctions->begin(); it != end; ++it) {
|
---|
318 | UString::Rep* name = it->first.get();
|
---|
319 | StaticFunctionEntry* entry = it->second;
|
---|
320 | if (!(entry->attributes & kJSPropertyAttributeDontEnum))
|
---|
321 | propertyNames.add(Identifier(name));
|
---|
322 | }
|
---|
323 | }
|
---|
324 | }
|
---|
325 |
|
---|
326 | JSObject::getPropertyNames(exec, propertyNames);
|
---|
327 | }
|
---|
328 |
|
---|
329 | double JSCallbackObject::toNumber(ExecState* exec) const
|
---|
330 | {
|
---|
331 | JSContextRef ctx = toRef(exec);
|
---|
332 | JSObjectRef thisRef = toRef(this);
|
---|
333 |
|
---|
334 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
335 | if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType)
|
---|
336 | if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
|
---|
337 | return toJS(value)->getNumber();
|
---|
338 |
|
---|
339 | return JSObject::toNumber(exec);
|
---|
340 | }
|
---|
341 |
|
---|
342 | UString JSCallbackObject::toString(ExecState* exec) const
|
---|
343 | {
|
---|
344 | JSContextRef ctx = toRef(exec);
|
---|
345 | JSObjectRef thisRef = toRef(this);
|
---|
346 |
|
---|
347 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
348 | if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType)
|
---|
349 | if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
|
---|
350 | return toJS(value)->getString();
|
---|
351 |
|
---|
352 | return JSObject::toString(exec);
|
---|
353 | }
|
---|
354 |
|
---|
355 | void JSCallbackObject::setPrivate(void* data)
|
---|
356 | {
|
---|
357 | m_privateData = data;
|
---|
358 | }
|
---|
359 |
|
---|
360 | void* JSCallbackObject::getPrivate()
|
---|
361 | {
|
---|
362 | return m_privateData;
|
---|
363 | }
|
---|
364 |
|
---|
365 | bool JSCallbackObject::inherits(JSClassRef c) const
|
---|
366 | {
|
---|
367 | for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
368 | if (jsClass == c)
|
---|
369 | return true;
|
---|
370 |
|
---|
371 | return false;
|
---|
372 | }
|
---|
373 |
|
---|
374 | JSValue* JSCallbackObject::cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
|
---|
375 | {
|
---|
376 | JSValue* v = slot.slotBase();
|
---|
377 | ASSERT(v);
|
---|
378 | return v;
|
---|
379 | }
|
---|
380 |
|
---|
381 | JSValue* JSCallbackObject::staticValueGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
|
---|
382 | {
|
---|
383 | ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info));
|
---|
384 | JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
|
---|
385 |
|
---|
386 | JSObjectRef thisRef = toRef(thisObj);
|
---|
387 | JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
|
---|
388 |
|
---|
389 | for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
390 | if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues)
|
---|
391 | if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
|
---|
392 | if (JSObjectGetPropertyCallback getProperty = entry->getProperty)
|
---|
393 | if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
|
---|
394 | return toJS(value);
|
---|
395 |
|
---|
396 | return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
|
---|
397 | }
|
---|
398 |
|
---|
399 | JSValue* JSCallbackObject::staticFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
|
---|
400 | {
|
---|
401 | ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info));
|
---|
402 | JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
|
---|
403 |
|
---|
404 | if (JSValue* cachedOrOverrideValue = thisObj->getDirect(propertyName))
|
---|
405 | return cachedOrOverrideValue;
|
---|
406 |
|
---|
407 | for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass) {
|
---|
408 | if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
|
---|
409 | if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
|
---|
410 | if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
|
---|
411 | JSObject* o = new JSCallbackFunction(exec, callAsFunction, propertyName);
|
---|
412 | thisObj->putDirect(propertyName, o, entry->attributes);
|
---|
413 | return o;
|
---|
414 | }
|
---|
415 | }
|
---|
416 | }
|
---|
417 | }
|
---|
418 |
|
---|
419 | return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
|
---|
420 | }
|
---|
421 |
|
---|
422 | JSValue* JSCallbackObject::callbackGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
|
---|
423 | {
|
---|
424 | ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info));
|
---|
425 | JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
|
---|
426 |
|
---|
427 | JSObjectRef thisRef = toRef(thisObj);
|
---|
428 | JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
|
---|
429 |
|
---|
430 | for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
|
---|
431 | if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty)
|
---|
432 | if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
|
---|
433 | return toJS(value);
|
---|
434 |
|
---|
435 | return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
|
---|
436 | }
|
---|
437 |
|
---|
438 | } // namespace KJS
|
---|