source: webkit/trunk/JavaScriptCore/API/JSObjectRef.cpp@ 51174

Last change on this file since 51174 was 47412, checked in by [email protected], 16 years ago

No, silly runtime, AST nodes are not for you.

Reviewed by Sam Weinig.

We still use AST nodes (ScopeNodes, particularly FunctionBodyNodes) within
the runtime, which means that these nodes must be persisted outside of the
arena, contain both parser & runtime data, etc. This is all a bit of a mess.

Move functionality into a new FunctionExecutable class.

(JSC::CodeBlock::CodeBlock):
(JSC::CodeBlock::markAggregate):
(JSC::CodeBlock::reparseForExceptionInfoIfNecessary):
(JSC::CodeBlock::lineNumberForBytecodeOffset):
(JSC::CodeBlock::shrinkToFit):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::getBytecodeIndex):
(JSC::CodeBlock::discardBytecode):
(JSC::CodeBlock::instructionCount):
(JSC::CodeBlock::getJITCode):
(JSC::CodeBlock::executablePool):
(JSC::CodeBlock::ownerExecutable):
(JSC::CodeBlock::extractExceptionInfo):
(JSC::CodeBlock::addFunctionDecl):
(JSC::CodeBlock::functionDecl):
(JSC::CodeBlock::numberOfFunctionDecls):
(JSC::CodeBlock::addFunctionExpr):
(JSC::CodeBlock::functionExpr):
(JSC::GlobalCodeBlock::GlobalCodeBlock):
(JSC::ProgramCodeBlock::ProgramCodeBlock):
(JSC::EvalCodeBlock::EvalCodeBlock):
(JSC::FunctionCodeBlock::FunctionCodeBlock):
(JSC::NativeCodeBlock::NativeCodeBlock):

  • bytecode/EvalCodeCache.h:
  • bytecode/SamplingTool.cpp:

(JSC::SamplingTool::doRun):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitNewFunction):
(JSC::BytecodeGenerator::emitNewFunctionExpression):

  • bytecompiler/BytecodeGenerator.h:
  • debugger/Debugger.cpp:

(JSC::Debugger::recompileAllJSFunctions):

  • interpreter/CachedCall.h:

(JSC::CachedCall::CachedCall):

  • interpreter/CallFrameClosure.h:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::unwindCallFrame):
(JSC::Interpreter::throwException):
(JSC::Interpreter::execute):
(JSC::Interpreter::prepareForRepeatCall):
(JSC::Interpreter::debug):
(JSC::Interpreter::privateExecute):
(JSC::Interpreter::retrieveLastCaller):

  • interpreter/Interpreter.h:
  • jit/JIT.cpp:

(JSC::JIT::privateCompile):

  • jit/JIT.h:

(JSC::JIT::compile):

  • jit/JITOpcodes.cpp:

(JSC::JIT::privateCompileCTIMachineTrampolines):
(JSC::JIT::emit_op_new_func):
(JSC::JIT::emit_op_new_func_exp):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • jit/JITStubs.h:

(JSC::):

  • parser/Nodes.cpp:

(JSC::FunctionBodyNode::reparseDataIfNecessary):

  • parser/Nodes.h:

(JSC::EvalNode::partialDestroyData):

  • parser/Parser.h:
  • profiler/ProfileGenerator.cpp:
  • profiler/Profiler.cpp:

(JSC::Profiler::createCallIdentifier):
(JSC::createCallIdentifierFromFunctionImp):

  • runtime/Arguments.h:

(JSC::Arguments::getArgumentsData):
(JSC::Arguments::Arguments):
(JSC::JSActivation::copyRegisters):

  • runtime/ArrayPrototype.cpp:

(JSC::isNumericCompareFunction):

  • runtime/CallData.h:

(JSC::):

  • runtime/Collector.cpp:

(JSC::Heap::collect):

  • runtime/ConstructData.h:

(JSC::):

  • runtime/ExceptionHelpers.cpp:

(JSC::createUndefinedVariableError):
(JSC::createInvalidParamError):
(JSC::createNotAConstructorError):
(JSC::createNotAFunctionError):
(JSC::createNotAnObjectError):

  • runtime/Executable.cpp: Added.

(JSC::EvalExecutable::generateBytecode):
(JSC::ProgramExecutable::generateBytecode):
(JSC::FunctionExecutable::generateBytecode):
(JSC::EvalExecutable::generateJITCode):
(JSC::ProgramExecutable::generateJITCode):
(JSC::FunctionExecutable::generateJITCode):
(JSC::FunctionExecutable::isHostFunction):
(JSC::FunctionExecutable::markAggregate):
(JSC::FunctionExecutable::reparseExceptionInfo):
(JSC::EvalExecutable::reparseExceptionInfo):
(JSC::FunctionExecutable::recompile):
(JSC::FunctionExecutable::FunctionExecutable):

  • runtime/Executable.h:

(JSC::ExecutableBase::~ExecutableBase):
(JSC::ExecutableBase::ExecutableBase):
(JSC::ExecutableBase::source):
(JSC::ExecutableBase::sourceID):
(JSC::ExecutableBase::lastLine):
(JSC::ExecutableBase::usesEval):
(JSC::ExecutableBase::usesArguments):
(JSC::ExecutableBase::needsActivation):
(JSC::ExecutableBase::astNode):
(JSC::ExecutableBase::generatedJITCode):
(JSC::ExecutableBase::getExecutablePool):
(JSC::EvalExecutable::EvalExecutable):
(JSC::EvalExecutable::bytecode):
(JSC::EvalExecutable::varStack):
(JSC::EvalExecutable::evalNode):
(JSC::EvalExecutable::jitCode):
(JSC::ProgramExecutable::ProgramExecutable):
(JSC::ProgramExecutable::reparseExceptionInfo):
(JSC::ProgramExecutable::bytecode):
(JSC::ProgramExecutable::programNode):
(JSC::ProgramExecutable::jitCode):
(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::name):
(JSC::FunctionExecutable::bytecode):
(JSC::FunctionExecutable::generatedBytecode):
(JSC::FunctionExecutable::usesEval):
(JSC::FunctionExecutable::usesArguments):
(JSC::FunctionExecutable::parameterCount):
(JSC::FunctionExecutable::paramString):
(JSC::FunctionExecutable::isGenerated):
(JSC::FunctionExecutable::body):
(JSC::FunctionExecutable::jitCode):
(JSC::FunctionExecutable::createNativeThunk):

  • runtime/FunctionConstructor.cpp:

(JSC::constructFunction):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::JSActivation):
(JSC::JSActivation::markChildren):
(JSC::JSActivation::isDynamicScope):
(JSC::JSActivation::argumentsGetter):

  • runtime/JSActivation.h:

(JSC::JSActivation::JSActivationData::JSActivationData):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::isHostFunction):
(JSC::JSFunction::JSFunction):
(JSC::JSFunction::~JSFunction):
(JSC::JSFunction::markChildren):
(JSC::JSFunction::getCallData):
(JSC::JSFunction::call):
(JSC::JSFunction::lengthGetter):
(JSC::JSFunction::getConstructData):
(JSC::JSFunction::construct):

  • runtime/JSFunction.h:

(JSC::JSFunction::executable):
(JSC::FunctionExecutable::make):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::numericCompareFunction):

  • runtime/JSGlobalData.h:
  • Property svn:eol-style set to native
File size: 16.5 KB
Line 
1/*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Kelvin W Sherlock ([email protected])
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 "config.h"
28#include "JSObjectRef.h"
29
30#include "APICast.h"
31#include "CodeBlock.h"
32#include "DateConstructor.h"
33#include "ErrorConstructor.h"
34#include "FunctionConstructor.h"
35#include "Identifier.h"
36#include "InitializeThreading.h"
37#include "JSArray.h"
38#include "JSCallbackConstructor.h"
39#include "JSCallbackFunction.h"
40#include "JSCallbackObject.h"
41#include "JSClassRef.h"
42#include "JSFunction.h"
43#include "JSGlobalObject.h"
44#include "JSObject.h"
45#include "JSRetainPtr.h"
46#include "JSString.h"
47#include "JSValueRef.h"
48#include "ObjectPrototype.h"
49#include "PropertyNameArray.h"
50#include "RegExpConstructor.h"
51#include <wtf/Platform.h>
52
53using namespace JSC;
54
55JSClassRef JSClassCreate(const JSClassDefinition* definition)
56{
57 initializeThreading();
58 RefPtr<OpaqueJSClass> jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)
59 ? OpaqueJSClass::createNoAutomaticPrototype(definition)
60 : OpaqueJSClass::create(definition);
61
62 return jsClass.release().releaseRef();
63}
64
65JSClassRef JSClassRetain(JSClassRef jsClass)
66{
67 jsClass->ref();
68 return jsClass;
69}
70
71void JSClassRelease(JSClassRef jsClass)
72{
73 jsClass->deref();
74}
75
76JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data)
77{
78 ExecState* exec = toJS(ctx);
79 exec->globalData().heap.registerThread();
80 JSLock lock(exec);
81
82 if (!jsClass)
83 return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure())); // slightly more efficient
84
85 JSCallbackObject<JSObject>* object = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
86 if (JSObject* prototype = jsClass->prototype(exec))
87 object->setPrototype(prototype);
88
89 return toRef(object);
90}
91
92JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
93{
94 ExecState* exec = toJS(ctx);
95 exec->globalData().heap.registerThread();
96 JSLock lock(exec);
97
98 Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
99
100 return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID));
101}
102
103JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor)
104{
105 ExecState* exec = toJS(ctx);
106 exec->globalData().heap.registerThread();
107 JSLock lock(exec);
108
109 JSValue jsPrototype = jsClass ? jsClass->prototype(exec) : 0;
110 if (!jsPrototype)
111 jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
112
113 JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);
114 constructor->putDirect(exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);
115 return toRef(constructor);
116}
117
118JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
119{
120 ExecState* exec = toJS(ctx);
121 exec->globalData().heap.registerThread();
122 JSLock lock(exec);
123
124 Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
125
126 MarkedArgumentBuffer args;
127 for (unsigned i = 0; i < parameterCount; i++)
128 args.append(jsString(exec, parameterNames[i]->ustring()));
129 args.append(jsString(exec, body->ustring()));
130
131 JSObject* result = constructFunction(exec, args, nameID, sourceURL->ustring(), startingLineNumber);
132 if (exec->hadException()) {
133 if (exception)
134 *exception = toRef(exec, exec->exception());
135 exec->clearException();
136 result = 0;
137 }
138 return toRef(result);
139}
140
141JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
142{
143 ExecState* exec = toJS(ctx);
144 exec->globalData().heap.registerThread();
145 JSLock lock(exec);
146
147 JSObject* result;
148 if (argumentCount) {
149 MarkedArgumentBuffer argList;
150 for (size_t i = 0; i < argumentCount; ++i)
151 argList.append(toJS(exec, arguments[i]));
152
153 result = constructArray(exec, argList);
154 } else
155 result = constructEmptyArray(exec);
156
157 if (exec->hadException()) {
158 if (exception)
159 *exception = toRef(exec, exec->exception());
160 exec->clearException();
161 result = 0;
162 }
163
164 return toRef(result);
165}
166
167JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
168{
169 ExecState* exec = toJS(ctx);
170 exec->globalData().heap.registerThread();
171 JSLock lock(exec);
172
173 MarkedArgumentBuffer argList;
174 for (size_t i = 0; i < argumentCount; ++i)
175 argList.append(toJS(exec, arguments[i]));
176
177 JSObject* result = constructDate(exec, argList);
178 if (exec->hadException()) {
179 if (exception)
180 *exception = toRef(exec, exec->exception());
181 exec->clearException();
182 result = 0;
183 }
184
185 return toRef(result);
186}
187
188JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
189{
190 ExecState* exec = toJS(ctx);
191 exec->globalData().heap.registerThread();
192 JSLock lock(exec);
193
194 MarkedArgumentBuffer argList;
195 for (size_t i = 0; i < argumentCount; ++i)
196 argList.append(toJS(exec, arguments[i]));
197
198 JSObject* result = constructError(exec, argList);
199 if (exec->hadException()) {
200 if (exception)
201 *exception = toRef(exec, exec->exception());
202 exec->clearException();
203 result = 0;
204 }
205
206 return toRef(result);
207}
208
209JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
210{
211 ExecState* exec = toJS(ctx);
212 exec->globalData().heap.registerThread();
213 JSLock lock(exec);
214
215 MarkedArgumentBuffer argList;
216 for (size_t i = 0; i < argumentCount; ++i)
217 argList.append(toJS(exec, arguments[i]));
218
219 JSObject* result = constructRegExp(exec, argList);
220 if (exec->hadException()) {
221 if (exception)
222 *exception = toRef(exec, exec->exception());
223 exec->clearException();
224 result = 0;
225 }
226
227 return toRef(result);
228}
229
230JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object)
231{
232 ExecState* exec = toJS(ctx);
233 exec->globalData().heap.registerThread();
234 JSLock lock(exec);
235
236 JSObject* jsObject = toJS(object);
237 return toRef(exec, jsObject->prototype());
238}
239
240void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value)
241{
242 ExecState* exec = toJS(ctx);
243 exec->globalData().heap.registerThread();
244 JSLock lock(exec);
245
246 JSObject* jsObject = toJS(object);
247 JSValue jsValue = toJS(exec, value);
248
249 jsObject->setPrototype(jsValue.isObject() ? jsValue : jsNull());
250}
251
252bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
253{
254 ExecState* exec = toJS(ctx);
255 exec->globalData().heap.registerThread();
256 JSLock lock(exec);
257
258 JSObject* jsObject = toJS(object);
259
260 return jsObject->hasProperty(exec, propertyName->identifier(&exec->globalData()));
261}
262
263JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
264{
265 ExecState* exec = toJS(ctx);
266 exec->globalData().heap.registerThread();
267 JSLock lock(exec);
268
269 JSObject* jsObject = toJS(object);
270
271 JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->globalData()));
272 if (exec->hadException()) {
273 if (exception)
274 *exception = toRef(exec, exec->exception());
275 exec->clearException();
276 }
277 return toRef(exec, jsValue);
278}
279
280void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
281{
282 ExecState* exec = toJS(ctx);
283 exec->globalData().heap.registerThread();
284 JSLock lock(exec);
285
286 JSObject* jsObject = toJS(object);
287 Identifier name(propertyName->identifier(&exec->globalData()));
288 JSValue jsValue = toJS(exec, value);
289
290 if (attributes && !jsObject->hasProperty(exec, name))
291 jsObject->putWithAttributes(exec, name, jsValue, attributes);
292 else {
293 PutPropertySlot slot;
294 jsObject->put(exec, name, jsValue, slot);
295 }
296
297 if (exec->hadException()) {
298 if (exception)
299 *exception = toRef(exec, exec->exception());
300 exec->clearException();
301 }
302}
303
304JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
305{
306 ExecState* exec = toJS(ctx);
307 exec->globalData().heap.registerThread();
308 JSLock lock(exec);
309
310 JSObject* jsObject = toJS(object);
311
312 JSValue jsValue = jsObject->get(exec, propertyIndex);
313 if (exec->hadException()) {
314 if (exception)
315 *exception = toRef(exec, exec->exception());
316 exec->clearException();
317 }
318 return toRef(exec, jsValue);
319}
320
321
322void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
323{
324 ExecState* exec = toJS(ctx);
325 exec->globalData().heap.registerThread();
326 JSLock lock(exec);
327
328 JSObject* jsObject = toJS(object);
329 JSValue jsValue = toJS(exec, value);
330
331 jsObject->put(exec, propertyIndex, jsValue);
332 if (exec->hadException()) {
333 if (exception)
334 *exception = toRef(exec, exec->exception());
335 exec->clearException();
336 }
337}
338
339bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
340{
341 ExecState* exec = toJS(ctx);
342 exec->globalData().heap.registerThread();
343 JSLock lock(exec);
344
345 JSObject* jsObject = toJS(object);
346
347 bool result = jsObject->deleteProperty(exec, propertyName->identifier(&exec->globalData()));
348 if (exec->hadException()) {
349 if (exception)
350 *exception = toRef(exec, exec->exception());
351 exec->clearException();
352 }
353 return result;
354}
355
356void* JSObjectGetPrivate(JSObjectRef object)
357{
358 JSObject* jsObject = toJS(object);
359
360 if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info))
361 return static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivate();
362 else if (jsObject->inherits(&JSCallbackObject<JSObject>::info))
363 return static_cast<JSCallbackObject<JSObject>*>(jsObject)->getPrivate();
364
365 return 0;
366}
367
368bool JSObjectSetPrivate(JSObjectRef object, void* data)
369{
370 JSObject* jsObject = toJS(object);
371
372 if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
373 static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivate(data);
374 return true;
375 } else if (jsObject->inherits(&JSCallbackObject<JSObject>::info)) {
376 static_cast<JSCallbackObject<JSObject>*>(jsObject)->setPrivate(data);
377 return true;
378 }
379
380 return false;
381}
382
383bool JSObjectIsFunction(JSContextRef, JSObjectRef object)
384{
385 CallData callData;
386 return toJS(object)->getCallData(callData) != CallTypeNone;
387}
388
389JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
390{
391 ExecState* exec = toJS(ctx);
392 exec->globalData().heap.registerThread();
393 JSLock lock(exec);
394
395 JSObject* jsObject = toJS(object);
396 JSObject* jsThisObject = toJS(thisObject);
397
398 if (!jsThisObject)
399 jsThisObject = exec->globalThisValue();
400
401 MarkedArgumentBuffer argList;
402 for (size_t i = 0; i < argumentCount; i++)
403 argList.append(toJS(exec, arguments[i]));
404
405 CallData callData;
406 CallType callType = jsObject->getCallData(callData);
407 if (callType == CallTypeNone)
408 return 0;
409
410 JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
411 if (exec->hadException()) {
412 if (exception)
413 *exception = toRef(exec, exec->exception());
414 exec->clearException();
415 result = 0;
416 }
417 return result;
418}
419
420bool JSObjectIsConstructor(JSContextRef, JSObjectRef object)
421{
422 JSObject* jsObject = toJS(object);
423 ConstructData constructData;
424 return jsObject->getConstructData(constructData) != ConstructTypeNone;
425}
426
427JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
428{
429 ExecState* exec = toJS(ctx);
430 exec->globalData().heap.registerThread();
431 JSLock lock(exec);
432
433 JSObject* jsObject = toJS(object);
434
435 ConstructData constructData;
436 ConstructType constructType = jsObject->getConstructData(constructData);
437 if (constructType == ConstructTypeNone)
438 return 0;
439
440 MarkedArgumentBuffer argList;
441 for (size_t i = 0; i < argumentCount; i++)
442 argList.append(toJS(exec, arguments[i]));
443 JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList));
444 if (exec->hadException()) {
445 if (exception)
446 *exception = toRef(exec, exec->exception());
447 exec->clearException();
448 result = 0;
449 }
450 return result;
451}
452
453struct OpaqueJSPropertyNameArray : FastAllocBase {
454 OpaqueJSPropertyNameArray(JSGlobalData* globalData)
455 : refCount(0)
456 , globalData(globalData)
457 {
458 }
459
460 unsigned refCount;
461 JSGlobalData* globalData;
462 Vector<JSRetainPtr<JSStringRef> > array;
463};
464
465JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object)
466{
467 JSObject* jsObject = toJS(object);
468 ExecState* exec = toJS(ctx);
469 exec->globalData().heap.registerThread();
470 JSLock lock(exec);
471
472 JSGlobalData* globalData = &exec->globalData();
473
474 JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(globalData);
475 PropertyNameArray array(globalData);
476 jsObject->getPropertyNames(exec, array);
477
478 size_t size = array.size();
479 propertyNames->array.reserveInitialCapacity(size);
480 for (size_t i = 0; i < size; ++i)
481 propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].ustring()).releaseRef()));
482
483 return JSPropertyNameArrayRetain(propertyNames);
484}
485
486JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array)
487{
488 ++array->refCount;
489 return array;
490}
491
492void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array)
493{
494 if (--array->refCount == 0) {
495 JSLock lock(array->globalData->isSharedInstance ? LockForReal : SilenceAssertionsOnly);
496 delete array;
497 }
498}
499
500size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array)
501{
502 return array->array.size();
503}
504
505JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index)
506{
507 return array->array[static_cast<unsigned>(index)].get();
508}
509
510void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName)
511{
512 PropertyNameArray* propertyNames = toJS(array);
513
514 propertyNames->globalData()->heap.registerThread();
515 JSLock lock(propertyNames->globalData()->isSharedInstance ? LockForReal : SilenceAssertionsOnly);
516
517 propertyNames->add(propertyName->identifier(propertyNames->globalData()));
518}
Note: See TracBrowser for help on using the repository browser.