]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - API/JSCallbackFunction.cpp
JavaScriptCore-525.tar.gz
[apple/javascriptcore.git] / API / JSCallbackFunction.cpp
index fb3937dd0dc30d0d6347de9c12fe89b2a0327c0e..86a2ebcfb6ee0283fd02652b43471db4a423ca9d 100644 (file)
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
 /*
- * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006, 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
 #include "JSCallbackFunction.h"
 
 #include "APICast.h"
-#include "function.h"
-#include "function_object.h"
-#include <kjs/JSGlobalObject.h>
+#include "JSFunction.h"
+#include "FunctionPrototype.h"
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
 #include <wtf/Vector.h>
 
-namespace KJS {
+namespace JSC {
 
-const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0};
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackFunction);
+
+const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 };
 
 JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name)
-    : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name)
+    : InternalFunction(&exec->globalData(), exec->lexicalGlobalObject()->callbackFunctionStructure(), name)
     , m_callback(callback)
 {
 }
 
-// InternalFunctionImp mish-mashes constructor and function behavior -- we should 
-// refactor the code so this override isn't necessary
-bool JSCallbackFunction::implementsHasInstance() const { 
-    return false; 
-}
-
-JSValue* JSCallbackFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args)
+JSValuePtr JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValuePtr thisValue, const ArgList& args)
 {
     JSContextRef execRef = toRef(exec);
-    JSObjectRef thisRef = toRef(this);
-    JSObjectRef thisObjRef = toRef(thisObj);
+    JSObjectRef functionRef = toRef(functionObject);
+    JSObjectRef thisObjRef = toRef(thisValue.toThisObject(exec));
 
     int argumentCount = static_cast<int>(args.size());
     Vector<JSValueRef, 16> arguments(argumentCount);
     for (int i = 0; i < argumentCount; i++)
-        arguments[i] = toRef(args[i]);
+        arguments[i] = toRef(args.at(exec, i));
 
-    JSLock::DropAllLocks dropAllLocks;
-    return toJS(m_callback(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+    JSLock::DropAllLocks dropAllLocks(exec);
+    return toJS(static_cast<JSCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+}
+
+CallType JSCallbackFunction::getCallData(CallData& callData)
+{
+    callData.native.function = call;
+    return CallTypeHost;
 }
 
-} // namespace KJS
+} // namespace JSC