Index: Source/bindings/v8/V8AnyCallback.cpp |
diff --git a/Source/bindings/v8/V8AnyCallback.cpp b/Source/bindings/v8/V8AnyCallback.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ad609594f0e7b7a4850a25d5c28dc4ce23258d4 |
--- /dev/null |
+++ b/Source/bindings/v8/V8AnyCallback.cpp |
@@ -0,0 +1,109 @@ |
+/* |
+ * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "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 THE COPYRIGHT |
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+ |
+#include "bindings/v8/V8AnyCallback.h" |
+ |
+#include "V8Future.h" |
+ |
+#include "bindings/v8/ScriptController.h" |
+#include "bindings/v8/V8Binding.h" |
+#include "core/platform/Logging.h" |
+ |
+namespace WebCore { |
+ |
+V8AnyCallback::V8AnyCallback(v8::Handle<v8::Function> callback, ScriptExecutionContext* context) |
+ : ActiveDOMCallback(context) |
+ , m_callback(callback) |
+ , m_world(DOMWrapperWorld::current()) |
+{ |
+ // FIXME: Make the Persistent m_callback has weak? |
+} |
+ |
+ScriptValue V8AnyCallback::call(const ScriptValue& value, PassRefPtr<Future> future, bool* exceptionThrown) |
+{ |
+ LOG(Network, "V8AnyCallback::call0"); |
+ |
+ if (!canInvokeCallback()) |
+ return ScriptValue(); |
+ |
+ LOG(Network, "V8AnyCallback::call1"); |
+ |
+ v8::HandleScope handleScope; |
+ |
+ v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_world.get()); |
+ if (v8Context.IsEmpty()) |
+ return ScriptValue(); |
+ |
+ LOG(Network, "V8AnyCallback::call2"); |
+ |
+ // Enter the context. |
+ v8::Context::Scope scope(v8Context); |
+ |
+ // FIXME: Need to New with v8Context's isolate? |
+ |
+ if (m_callback.isEmpty()) |
+ return ScriptValue(); |
+ |
+ LOG(Network, "V8AnyCallback::call3"); |
+ |
+ v8::Handle<v8::Function> callback = m_callback.get(); |
+ |
+ v8::Handle<v8::Object> thisObject = v8Context->Global(); |
+ if (future) { |
+ v8::Handle<v8::Value> futureHandle = toV8(future.get(), v8::Handle<v8::Object>(), v8Context->GetIsolate()); |
+ if (!futureHandle->IsObject() || futureHandle.IsEmpty()) { |
+ if (!isScriptControllerTerminating()) |
+ CRASH(); |
+ return ScriptValue(); |
+ } |
+ thisObject = v8::Handle<v8::Object>::Cast(futureHandle); |
+ } |
+ |
+ // FIXME: Need to pass v8Context's isolate? |
+ v8::Handle<v8::Value> arg = v8::Undefined(); |
+ if (!value.hasNoValue()) |
+ arg = value.v8Value(); |
+ v8::Handle<v8::Value> argv[] = { arg }; |
+ |
+ LOG(Network, "V8AnyCallback::call4"); |
+ |
+ v8::TryCatch exceptionCatcher; |
+ exceptionCatcher.SetVerbose(true); // ? |
+ v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, thisObject, 1, argv); |
+ if (exceptionCatcher.HasCaught()) { |
+ *exceptionThrown = true; |
+ return exceptionCatcher.Exception(); |
+ } |
+ return result; |
+} |
+ |
+} // namespace WebCore |