X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/b37bf2e156556c589aea3e1f58a377f2b1189665..14957cd040308e3eeec43d26bae5d76da13fcd85:/API/JSCallbackConstructor.cpp?ds=inline diff --git a/API/JSCallbackConstructor.cpp b/API/JSCallbackConstructor.cpp index 46c1823..fa9d216 100644 --- a/API/JSCallbackConstructor.cpp +++ b/API/JSCallbackConstructor.cpp @@ -1,6 +1,5 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,20 +26,24 @@ #include "config.h" #include "JSCallbackConstructor.h" +#include "APIShims.h" #include "APICast.h" -#include -#include +#include +#include +#include +#include #include -namespace KJS { +namespace JSC { -const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0}; +const ClassInfo JSCallbackConstructor::s_info = { "CallbackConstructor", &JSObjectWithGlobalObject::s_info, 0, 0 }; -JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback) - : JSObject(exec->lexicalGlobalObject()->objectPrototype()) +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,32 +54,37 @@ JSCallbackConstructor::~JSCallbackConstructor() JSClassRelease(m_class); } -bool JSCallbackConstructor::implementsHasInstance() const -{ - return true; -} - -bool JSCallbackConstructor::implementsConstruct() const -{ - return true; -} - -JSObject* JSCallbackConstructor::construct(ExecState* exec, const List &args) +static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec) { + JSObject* constructor = exec->callee(); JSContextRef ctx = toRef(exec); - JSObjectRef thisRef = toRef(this); + JSObjectRef constructorRef = toRef(constructor); - if (m_callback) { - int argumentCount = static_cast(args.size()); + JSObjectCallAsConstructorCallback callback = static_cast(constructor)->callback(); + if (callback) { + int argumentCount = static_cast(exec->argumentCount()); Vector arguments(argumentCount); for (int i = 0; i < argumentCount; i++) - arguments[i] = toRef(args[i]); - - JSLock::DropAllLocks dropAllLocks; - return toJS(m_callback(ctx, thisRef, 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, m_class, 0)); + return JSValue::encode(toJS(JSObjectMake(ctx, static_cast(constructor)->classRef(), 0))); +} + +ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructJSCallback; + return ConstructTypeHost; } -} // namespace KJS +} // namespace JSC