- JSObject* constructor = exec->callee();
- JSContextRef ctx = toRef(exec);
- JSObjectRef constructorRef = toRef(constructor);
-
- JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
- if (callback) {
- int argumentCount = static_cast<int>(exec->argumentCount());
- Vector<JSValueRef, 16> arguments(argumentCount);
- for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(exec, exec->argument(i));
-
- JSValueRef exception = 0;
- JSObjectRef result;
- {
- APICallbackShim callbackShim(exec);
- result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
- }
- if (exception)
- throwError(exec, toJS(exec, exception));
- return JSValue::encode(toJS(result));
- }
-
- return JSValue::encode(toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0)));