2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
28 #include "JSObjectRef.h"
29 #include "JSObjectRefPrivate.h"
32 #include "ButterflyInlines.h"
33 #include "CodeBlock.h"
34 #include "CopiedSpaceInlines.h"
35 #include "DateConstructor.h"
36 #include "ErrorConstructor.h"
37 #include "FunctionConstructor.h"
38 #include "Identifier.h"
39 #include "InitializeThreading.h"
40 #include "JSAPIWrapperObject.h"
42 #include "JSCallbackConstructor.h"
43 #include "JSCallbackFunction.h"
44 #include "JSCallbackObject.h"
45 #include "JSClassRef.h"
46 #include "JSFunction.h"
47 #include "JSGlobalObject.h"
49 #include "JSRetainPtr.h"
51 #include "JSValueRef.h"
52 #include "ObjectConstructor.h"
53 #include "ObjectPrototype.h"
54 #include "JSCInlines.h"
55 #include "PropertyNameArray.h"
56 #include "RegExpConstructor.h"
58 #if ENABLE(REMOTE_INSPECTOR)
59 #include "JSGlobalObjectInspectorController.h"
64 JSClassRef
JSClassCreate(const JSClassDefinition
* definition
)
66 initializeThreading();
67 RefPtr
<OpaqueJSClass
> jsClass
= (definition
->attributes
& kJSClassAttributeNoAutomaticPrototype
)
68 ? OpaqueJSClass::createNoAutomaticPrototype(definition
)
69 : OpaqueJSClass::create(definition
);
71 return jsClass
.release().leakRef();
74 JSClassRef
JSClassRetain(JSClassRef jsClass
)
80 void JSClassRelease(JSClassRef jsClass
)
85 JSObjectRef
JSObjectMake(JSContextRef ctx
, JSClassRef jsClass
, void* data
)
91 ExecState
* exec
= toJS(ctx
);
92 JSLockHolder
locker(exec
);
95 return toRef(constructEmptyObject(exec
));
97 JSCallbackObject
<JSDestructibleObject
>* object
= JSCallbackObject
<JSDestructibleObject
>::create(exec
, exec
->lexicalGlobalObject(), exec
->lexicalGlobalObject()->callbackObjectStructure(), jsClass
, data
);
98 if (JSObject
* prototype
= jsClass
->prototype(exec
))
99 object
->setPrototype(exec
->vm(), prototype
);
101 return toRef(object
);
104 JSObjectRef
JSObjectMakeFunctionWithCallback(JSContextRef ctx
, JSStringRef name
, JSObjectCallAsFunctionCallback callAsFunction
)
107 ASSERT_NOT_REACHED();
110 ExecState
* exec
= toJS(ctx
);
111 JSLockHolder
locker(exec
);
112 return toRef(JSCallbackFunction::create(exec
->vm(), exec
->lexicalGlobalObject(), callAsFunction
, name
? name
->string() : ASCIILiteral("anonymous")));
115 JSObjectRef
JSObjectMakeConstructor(JSContextRef ctx
, JSClassRef jsClass
, JSObjectCallAsConstructorCallback callAsConstructor
)
118 ASSERT_NOT_REACHED();
121 ExecState
* exec
= toJS(ctx
);
122 JSLockHolder
locker(exec
);
124 JSValue jsPrototype
= jsClass
? jsClass
->prototype(exec
) : 0;
126 jsPrototype
= exec
->lexicalGlobalObject()->objectPrototype();
128 JSCallbackConstructor
* constructor
= JSCallbackConstructor::create(exec
, exec
->lexicalGlobalObject(), exec
->lexicalGlobalObject()->callbackConstructorStructure(), jsClass
, callAsConstructor
);
129 constructor
->putDirect(exec
->vm(), exec
->propertyNames().prototype
, jsPrototype
, DontEnum
| DontDelete
| ReadOnly
);
130 return toRef(constructor
);
133 JSObjectRef
JSObjectMakeFunction(JSContextRef ctx
, JSStringRef name
, unsigned parameterCount
, const JSStringRef parameterNames
[], JSStringRef body
, JSStringRef sourceURL
, int startingLineNumber
, JSValueRef
* exception
)
136 ASSERT_NOT_REACHED();
139 ExecState
* exec
= toJS(ctx
);
140 JSLockHolder
locker(exec
);
142 startingLineNumber
= std::max(1, startingLineNumber
);
143 Identifier nameID
= name
? name
->identifier(&exec
->vm()) : Identifier(exec
, "anonymous");
145 MarkedArgumentBuffer args
;
146 for (unsigned i
= 0; i
< parameterCount
; i
++)
147 args
.append(jsString(exec
, parameterNames
[i
]->string()));
148 args
.append(jsString(exec
, body
->string()));
150 JSObject
* result
= constructFunction(exec
, exec
->lexicalGlobalObject(), args
, nameID
, sourceURL
->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber
), OrdinalNumber::first()));
151 if (exec
->hadException()) {
152 JSValue exceptionValue
= exec
->exception();
154 *exception
= toRef(exec
, exceptionValue
);
155 exec
->clearException();
156 #if ENABLE(REMOTE_INSPECTOR)
157 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
161 return toRef(result
);
164 JSObjectRef
JSObjectMakeArray(JSContextRef ctx
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
)
167 ASSERT_NOT_REACHED();
170 ExecState
* exec
= toJS(ctx
);
171 JSLockHolder
locker(exec
);
175 MarkedArgumentBuffer argList
;
176 for (size_t i
= 0; i
< argumentCount
; ++i
)
177 argList
.append(toJS(exec
, arguments
[i
]));
179 result
= constructArray(exec
, static_cast<ArrayAllocationProfile
*>(0), argList
);
181 result
= constructEmptyArray(exec
, 0);
183 if (exec
->hadException()) {
184 JSValue exceptionValue
= exec
->exception();
186 *exception
= toRef(exec
, exceptionValue
);
187 exec
->clearException();
188 #if ENABLE(REMOTE_INSPECTOR)
189 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
194 return toRef(result
);
197 JSObjectRef
JSObjectMakeDate(JSContextRef ctx
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
)
200 ASSERT_NOT_REACHED();
203 ExecState
* exec
= toJS(ctx
);
204 JSLockHolder
locker(exec
);
206 MarkedArgumentBuffer argList
;
207 for (size_t i
= 0; i
< argumentCount
; ++i
)
208 argList
.append(toJS(exec
, arguments
[i
]));
210 JSObject
* result
= constructDate(exec
, exec
->lexicalGlobalObject(), argList
);
211 if (exec
->hadException()) {
212 JSValue exceptionValue
= exec
->exception();
214 *exception
= toRef(exec
, exceptionValue
);
215 exec
->clearException();
216 #if ENABLE(REMOTE_INSPECTOR)
217 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
222 return toRef(result
);
225 JSObjectRef
JSObjectMakeError(JSContextRef ctx
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
)
228 ASSERT_NOT_REACHED();
231 ExecState
* exec
= toJS(ctx
);
232 JSLockHolder
locker(exec
);
234 JSValue message
= argumentCount
? toJS(exec
, arguments
[0]) : jsUndefined();
235 Structure
* errorStructure
= exec
->lexicalGlobalObject()->errorStructure();
236 JSObject
* result
= ErrorInstance::create(exec
, errorStructure
, message
);
238 if (exec
->hadException()) {
239 JSValue exceptionValue
= exec
->exception();
241 *exception
= toRef(exec
, exceptionValue
);
242 exec
->clearException();
243 #if ENABLE(REMOTE_INSPECTOR)
244 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
249 return toRef(result
);
252 JSObjectRef
JSObjectMakeRegExp(JSContextRef ctx
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
)
255 ASSERT_NOT_REACHED();
258 ExecState
* exec
= toJS(ctx
);
259 JSLockHolder
locker(exec
);
261 MarkedArgumentBuffer argList
;
262 for (size_t i
= 0; i
< argumentCount
; ++i
)
263 argList
.append(toJS(exec
, arguments
[i
]));
265 JSObject
* result
= constructRegExp(exec
, exec
->lexicalGlobalObject(), argList
);
266 if (exec
->hadException()) {
267 JSValue exceptionValue
= exec
->exception();
269 *exception
= toRef(exec
, exceptionValue
);
270 exec
->clearException();
271 #if ENABLE(REMOTE_INSPECTOR)
272 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
277 return toRef(result
);
280 JSValueRef
JSObjectGetPrototype(JSContextRef ctx
, JSObjectRef object
)
283 ASSERT_NOT_REACHED();
286 ExecState
* exec
= toJS(ctx
);
287 JSLockHolder
locker(exec
);
289 JSObject
* jsObject
= toJS(object
);
290 return toRef(exec
, jsObject
->prototype());
293 void JSObjectSetPrototype(JSContextRef ctx
, JSObjectRef object
, JSValueRef value
)
296 ASSERT_NOT_REACHED();
299 ExecState
* exec
= toJS(ctx
);
300 JSLockHolder
locker(exec
);
302 JSObject
* jsObject
= toJS(object
);
303 JSValue jsValue
= toJS(exec
, value
);
305 jsObject
->setPrototypeWithCycleCheck(exec
, jsValue
.isObject() ? jsValue
: jsNull());
308 bool JSObjectHasProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
)
311 ASSERT_NOT_REACHED();
314 ExecState
* exec
= toJS(ctx
);
315 JSLockHolder
locker(exec
);
317 JSObject
* jsObject
= toJS(object
);
319 return jsObject
->hasProperty(exec
, propertyName
->identifier(&exec
->vm()));
322 JSValueRef
JSObjectGetProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef
* exception
)
325 ASSERT_NOT_REACHED();
328 ExecState
* exec
= toJS(ctx
);
329 JSLockHolder
locker(exec
);
331 JSObject
* jsObject
= toJS(object
);
333 JSValue jsValue
= jsObject
->get(exec
, propertyName
->identifier(&exec
->vm()));
334 if (exec
->hadException()) {
335 JSValue exceptionValue
= exec
->exception();
337 *exception
= toRef(exec
, exceptionValue
);
338 exec
->clearException();
339 #if ENABLE(REMOTE_INSPECTOR)
340 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
343 return toRef(exec
, jsValue
);
346 void JSObjectSetProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef value
, JSPropertyAttributes attributes
, JSValueRef
* exception
)
349 ASSERT_NOT_REACHED();
352 ExecState
* exec
= toJS(ctx
);
353 JSLockHolder
locker(exec
);
355 JSObject
* jsObject
= toJS(object
);
356 Identifier
name(propertyName
->identifier(&exec
->vm()));
357 JSValue jsValue
= toJS(exec
, value
);
359 if (attributes
&& !jsObject
->hasProperty(exec
, name
)) {
360 PropertyDescriptor
desc(jsValue
, attributes
);
361 jsObject
->methodTable()->defineOwnProperty(jsObject
, exec
, name
, desc
, false);
363 PutPropertySlot
slot(jsObject
);
364 jsObject
->methodTable()->put(jsObject
, exec
, name
, jsValue
, slot
);
367 if (exec
->hadException()) {
368 JSValue exceptionValue
= exec
->exception();
370 *exception
= toRef(exec
, exceptionValue
);
371 exec
->clearException();
372 #if ENABLE(REMOTE_INSPECTOR)
373 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
378 JSValueRef
JSObjectGetPropertyAtIndex(JSContextRef ctx
, JSObjectRef object
, unsigned propertyIndex
, JSValueRef
* exception
)
381 ASSERT_NOT_REACHED();
384 ExecState
* exec
= toJS(ctx
);
385 JSLockHolder
locker(exec
);
387 JSObject
* jsObject
= toJS(object
);
389 JSValue jsValue
= jsObject
->get(exec
, propertyIndex
);
390 if (exec
->hadException()) {
391 JSValue exceptionValue
= exec
->exception();
393 *exception
= toRef(exec
, exceptionValue
);
394 exec
->clearException();
395 #if ENABLE(REMOTE_INSPECTOR)
396 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
399 return toRef(exec
, jsValue
);
403 void JSObjectSetPropertyAtIndex(JSContextRef ctx
, JSObjectRef object
, unsigned propertyIndex
, JSValueRef value
, JSValueRef
* exception
)
406 ASSERT_NOT_REACHED();
409 ExecState
* exec
= toJS(ctx
);
410 JSLockHolder
locker(exec
);
412 JSObject
* jsObject
= toJS(object
);
413 JSValue jsValue
= toJS(exec
, value
);
415 jsObject
->methodTable()->putByIndex(jsObject
, exec
, propertyIndex
, jsValue
, false);
416 if (exec
->hadException()) {
417 JSValue exceptionValue
= exec
->exception();
419 *exception
= toRef(exec
, exceptionValue
);
420 exec
->clearException();
421 #if ENABLE(REMOTE_INSPECTOR)
422 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
427 bool JSObjectDeleteProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef
* exception
)
430 ASSERT_NOT_REACHED();
433 ExecState
* exec
= toJS(ctx
);
434 JSLockHolder
locker(exec
);
436 JSObject
* jsObject
= toJS(object
);
438 bool result
= jsObject
->methodTable()->deleteProperty(jsObject
, exec
, propertyName
->identifier(&exec
->vm()));
439 if (exec
->hadException()) {
440 JSValue exceptionValue
= exec
->exception();
442 *exception
= toRef(exec
, exceptionValue
);
443 exec
->clearException();
444 #if ENABLE(REMOTE_INSPECTOR)
445 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
451 void* JSObjectGetPrivate(JSObjectRef object
)
453 JSObject
* jsObject
= uncheckedToJS(object
);
455 // Get wrapped object if proxied
456 if (jsObject
->inherits(JSProxy::info()))
457 jsObject
= jsCast
<JSProxy
*>(jsObject
)->target();
459 if (jsObject
->inherits(JSCallbackObject
<JSGlobalObject
>::info()))
460 return jsCast
<JSCallbackObject
<JSGlobalObject
>*>(jsObject
)->getPrivate();
461 if (jsObject
->inherits(JSCallbackObject
<JSDestructibleObject
>::info()))
462 return jsCast
<JSCallbackObject
<JSDestructibleObject
>*>(jsObject
)->getPrivate();
463 #if JSC_OBJC_API_ENABLED
464 if (jsObject
->inherits(JSCallbackObject
<JSAPIWrapperObject
>::info()))
465 return jsCast
<JSCallbackObject
<JSAPIWrapperObject
>*>(jsObject
)->getPrivate();
471 bool JSObjectSetPrivate(JSObjectRef object
, void* data
)
473 JSObject
* jsObject
= uncheckedToJS(object
);
475 // Get wrapped object if proxied
476 if (jsObject
->inherits(JSProxy::info()))
477 jsObject
= jsCast
<JSProxy
*>(jsObject
)->target();
479 if (jsObject
->inherits(JSCallbackObject
<JSGlobalObject
>::info())) {
480 jsCast
<JSCallbackObject
<JSGlobalObject
>*>(jsObject
)->setPrivate(data
);
483 if (jsObject
->inherits(JSCallbackObject
<JSDestructibleObject
>::info())) {
484 jsCast
<JSCallbackObject
<JSDestructibleObject
>*>(jsObject
)->setPrivate(data
);
487 #if JSC_OBJC_API_ENABLED
488 if (jsObject
->inherits(JSCallbackObject
<JSAPIWrapperObject
>::info())) {
489 jsCast
<JSCallbackObject
<JSAPIWrapperObject
>*>(jsObject
)->setPrivate(data
);
497 JSValueRef
JSObjectGetPrivateProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
)
499 ExecState
* exec
= toJS(ctx
);
500 JSLockHolder
locker(exec
);
501 JSObject
* jsObject
= toJS(object
);
503 Identifier
name(propertyName
->identifier(&exec
->vm()));
504 if (jsObject
->inherits(JSCallbackObject
<JSGlobalObject
>::info()))
505 result
= jsCast
<JSCallbackObject
<JSGlobalObject
>*>(jsObject
)->getPrivateProperty(name
);
506 else if (jsObject
->inherits(JSCallbackObject
<JSDestructibleObject
>::info()))
507 result
= jsCast
<JSCallbackObject
<JSDestructibleObject
>*>(jsObject
)->getPrivateProperty(name
);
508 #if JSC_OBJC_API_ENABLED
509 else if (jsObject
->inherits(JSCallbackObject
<JSAPIWrapperObject
>::info()))
510 result
= jsCast
<JSCallbackObject
<JSAPIWrapperObject
>*>(jsObject
)->getPrivateProperty(name
);
512 return toRef(exec
, result
);
515 bool JSObjectSetPrivateProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef value
)
517 ExecState
* exec
= toJS(ctx
);
518 JSLockHolder
locker(exec
);
519 JSObject
* jsObject
= toJS(object
);
520 JSValue jsValue
= value
? toJS(exec
, value
) : JSValue();
521 Identifier
name(propertyName
->identifier(&exec
->vm()));
522 if (jsObject
->inherits(JSCallbackObject
<JSGlobalObject
>::info())) {
523 jsCast
<JSCallbackObject
<JSGlobalObject
>*>(jsObject
)->setPrivateProperty(exec
->vm(), name
, jsValue
);
526 if (jsObject
->inherits(JSCallbackObject
<JSDestructibleObject
>::info())) {
527 jsCast
<JSCallbackObject
<JSDestructibleObject
>*>(jsObject
)->setPrivateProperty(exec
->vm(), name
, jsValue
);
530 #if JSC_OBJC_API_ENABLED
531 if (jsObject
->inherits(JSCallbackObject
<JSAPIWrapperObject
>::info())) {
532 jsCast
<JSCallbackObject
<JSAPIWrapperObject
>*>(jsObject
)->setPrivateProperty(exec
->vm(), name
, jsValue
);
539 bool JSObjectDeletePrivateProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
)
541 ExecState
* exec
= toJS(ctx
);
542 JSLockHolder
locker(exec
);
543 JSObject
* jsObject
= toJS(object
);
544 Identifier
name(propertyName
->identifier(&exec
->vm()));
545 if (jsObject
->inherits(JSCallbackObject
<JSGlobalObject
>::info())) {
546 jsCast
<JSCallbackObject
<JSGlobalObject
>*>(jsObject
)->deletePrivateProperty(name
);
549 if (jsObject
->inherits(JSCallbackObject
<JSDestructibleObject
>::info())) {
550 jsCast
<JSCallbackObject
<JSDestructibleObject
>*>(jsObject
)->deletePrivateProperty(name
);
553 #if JSC_OBJC_API_ENABLED
554 if (jsObject
->inherits(JSCallbackObject
<JSAPIWrapperObject
>::info())) {
555 jsCast
<JSCallbackObject
<JSAPIWrapperObject
>*>(jsObject
)->deletePrivateProperty(name
);
562 bool JSObjectIsFunction(JSContextRef ctx
, JSObjectRef object
)
566 JSLockHolder
locker(toJS(ctx
));
568 JSCell
* cell
= toJS(object
);
569 return cell
->methodTable()->getCallData(cell
, callData
) != CallTypeNone
;
572 JSValueRef
JSObjectCallAsFunction(JSContextRef ctx
, JSObjectRef object
, JSObjectRef thisObject
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
)
574 ExecState
* exec
= toJS(ctx
);
575 JSLockHolder
locker(exec
);
580 JSObject
* jsObject
= toJS(object
);
581 JSObject
* jsThisObject
= toJS(thisObject
);
584 jsThisObject
= exec
->globalThisValue();
586 MarkedArgumentBuffer argList
;
587 for (size_t i
= 0; i
< argumentCount
; i
++)
588 argList
.append(toJS(exec
, arguments
[i
]));
591 CallType callType
= jsObject
->methodTable()->getCallData(jsObject
, callData
);
592 if (callType
== CallTypeNone
)
595 JSValueRef result
= toRef(exec
, call(exec
, jsObject
, callType
, callData
, jsThisObject
, argList
));
596 if (exec
->hadException()) {
597 JSValue exceptionValue
= exec
->exception();
599 *exception
= toRef(exec
, exceptionValue
);
600 exec
->clearException();
601 #if ENABLE(REMOTE_INSPECTOR)
602 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
609 bool JSObjectIsConstructor(JSContextRef
, JSObjectRef object
)
613 JSObject
* jsObject
= toJS(object
);
614 ConstructData constructData
;
615 return jsObject
->methodTable()->getConstructData(jsObject
, constructData
) != ConstructTypeNone
;
618 JSObjectRef
JSObjectCallAsConstructor(JSContextRef ctx
, JSObjectRef object
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
)
620 ExecState
* exec
= toJS(ctx
);
621 JSLockHolder
locker(exec
);
626 JSObject
* jsObject
= toJS(object
);
628 ConstructData constructData
;
629 ConstructType constructType
= jsObject
->methodTable()->getConstructData(jsObject
, constructData
);
630 if (constructType
== ConstructTypeNone
)
633 MarkedArgumentBuffer argList
;
634 for (size_t i
= 0; i
< argumentCount
; i
++)
635 argList
.append(toJS(exec
, arguments
[i
]));
636 JSObjectRef result
= toRef(construct(exec
, jsObject
, constructType
, constructData
, argList
));
637 if (exec
->hadException()) {
638 JSValue exceptionValue
= exec
->exception();
640 *exception
= toRef(exec
, exceptionValue
);
641 exec
->clearException();
642 #if ENABLE(REMOTE_INSPECTOR)
643 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exceptionValue
);
650 struct OpaqueJSPropertyNameArray
{
651 WTF_MAKE_FAST_ALLOCATED
;
653 OpaqueJSPropertyNameArray(VM
* vm
)
661 Vector
<JSRetainPtr
<JSStringRef
>> array
;
664 JSPropertyNameArrayRef
JSObjectCopyPropertyNames(JSContextRef ctx
, JSObjectRef object
)
667 ASSERT_NOT_REACHED();
670 ExecState
* exec
= toJS(ctx
);
671 JSLockHolder
locker(exec
);
673 VM
* vm
= &exec
->vm();
675 JSObject
* jsObject
= toJS(object
);
676 JSPropertyNameArrayRef propertyNames
= new OpaqueJSPropertyNameArray(vm
);
677 PropertyNameArray
array(vm
);
678 jsObject
->methodTable()->getPropertyNames(jsObject
, exec
, array
, ExcludeDontEnumProperties
);
680 size_t size
= array
.size();
681 propertyNames
->array
.reserveInitialCapacity(size
);
682 for (size_t i
= 0; i
< size
; ++i
)
683 propertyNames
->array
.uncheckedAppend(JSRetainPtr
<JSStringRef
>(Adopt
, OpaqueJSString::create(array
[i
].string()).leakRef()));
685 return JSPropertyNameArrayRetain(propertyNames
);
688 JSPropertyNameArrayRef
JSPropertyNameArrayRetain(JSPropertyNameArrayRef array
)
694 void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array
)
696 if (--array
->refCount
== 0) {
697 JSLockHolder
locker(array
->vm
);
702 size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array
)
704 return array
->array
.size();
707 JSStringRef
JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array
, size_t index
)
709 return array
->array
[static_cast<unsigned>(index
)].get();
712 void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array
, JSStringRef propertyName
)
714 PropertyNameArray
* propertyNames
= toJS(array
);
715 JSLockHolder
locker(propertyNames
->vm());
716 propertyNames
->add(propertyName
->identifier(propertyNames
->vm()));