]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - API/JSCallbackConstructor.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / API / JSCallbackConstructor.cpp
index 46c1823d21e2cad982ab699ebe4d09d055853015..65e66dc13f170562ab8e43fde8a57db04f621469 100644 (file)
@@ -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
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 #include "config.h"
 #include "JSCallbackConstructor.h"
 
+#include "APICallbackFunction.h"
 #include "APICast.h"
-#include <kjs/JSGlobalObject.h>
-#include <kjs/object_object.h>
+#include "Error.h"
+#include "JSGlobalObject.h"
+#include "JSLock.h"
+#include "ObjectPrototype.h"
+#include "JSCInlines.h"
 #include <wtf/Vector.h>
 
-namespace KJS {
+namespace JSC {
 
-const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0};
+const ClassInfo JSCallbackConstructor::s_info = { "CallbackConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSCallbackConstructor) };
 
-JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
-    : JSObject(exec->lexicalGlobalObject()->objectPrototype())
+JSCallbackConstructor::JSCallbackConstructor(JSGlobalObject* globalObject, Structure* structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
+    : JSDestructibleObject(globalObject->vm(), structure)
     , m_class(jsClass)
     , m_callback(callback)
 {
+}
+
+void JSCallbackConstructor::finishCreation(JSGlobalObject* globalObject, JSClassRef jsClass)
+{
+    Base::finishCreation(globalObject->vm());
+    ASSERT(inherits(info()));
     if (m_class)
         JSClassRetain(jsClass);
 }
@@ -51,32 +60,15 @@ JSCallbackConstructor::~JSCallbackConstructor()
         JSClassRelease(m_class);
 }
 
-bool JSCallbackConstructor::implementsHasInstance() const
+void JSCallbackConstructor::destroy(JSCell* cell)
 {
-    return true;
+    static_cast<JSCallbackConstructor*>(cell)->JSCallbackConstructor::~JSCallbackConstructor();
 }
 
-bool JSCallbackConstructor::implementsConstruct() const
+ConstructType JSCallbackConstructor::getConstructData(JSCell*, ConstructData& constructData)
 {
-    return true;
-}
-
-JSObject* JSCallbackConstructor::construct(ExecState* exec, const List &args)
-{
-    JSContextRef ctx = toRef(exec);
-    JSObjectRef thisRef = toRef(this);
-
-    if (m_callback) {
-        int argumentCount = static_cast<int>(args.size());
-        Vector<JSValueRef, 16> 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())));
-    }
-    
-    return toJS(JSObjectMake(ctx, m_class, 0));
+    constructData.native.function = APICallbackFunction::construct<JSCallbackConstructor>;
+    return ConstructTypeHost;
 }
 
-} // namespace KJS
+} // namespace JSC