X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..14957cd040308e3eeec43d26bae5d76da13fcd85:/API/JSCallbackConstructor.cpp?ds=sidebyside diff --git a/API/JSCallbackConstructor.cpp b/API/JSCallbackConstructor.cpp index e10733e..fa9d216 100644 --- a/API/JSCallbackConstructor.cpp +++ b/API/JSCallbackConstructor.cpp @@ -26,7 +26,9 @@ #include "config.h" #include "JSCallbackConstructor.h" +#include "APIShims.h" #include "APICast.h" +#include #include #include #include @@ -34,13 +36,14 @@ namespace JSC { -const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 }; +const ClassInfo JSCallbackConstructor::s_info = { "CallbackConstructor", &JSObjectWithGlobalObject::s_info, 0, 0 }; -JSCallbackConstructor::JSCallbackConstructor(PassRefPtr structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback) - : JSObject(structure) +JSCallbackConstructor::JSCallbackConstructor(JSGlobalObject* globalObject, Structure* structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback) + : JSObjectWithGlobalObject(globalObject, structure) , m_class(jsClass) , m_callback(callback) { + ASSERT(inherits(&s_info)); if (m_class) JSClassRetain(jsClass); } @@ -51,23 +54,31 @@ JSCallbackConstructor::~JSCallbackConstructor() JSClassRelease(m_class); } -static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args) +static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec) { + JSObject* constructor = exec->callee(); JSContextRef ctx = toRef(exec); JSObjectRef constructorRef = toRef(constructor); JSObjectCallAsConstructorCallback callback = static_cast(constructor)->callback(); if (callback) { - int argumentCount = static_cast(args.size()); + int argumentCount = static_cast(exec->argumentCount()); Vector arguments(argumentCount); for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(args.at(exec, i)); - - JSLock::DropAllLocks dropAllLocks(exec); - return toJS(callback(ctx, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot()))); + 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 toJS(JSObjectMake(ctx, static_cast(constructor)->classRef(), 0)); + return JSValue::encode(toJS(JSObjectMake(ctx, static_cast(constructor)->classRef(), 0))); } ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData)