Index: Source/bindings/v8/custom/V8FutureResolverCustom.cpp |
diff --git a/Source/bindings/v8/custom/V8FutureResolverCustom.cpp b/Source/bindings/v8/custom/V8FutureResolverCustom.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..da69cbd1f66979e7b64f49d26d87e472a66d0827 |
--- /dev/null |
+++ b/Source/bindings/v8/custom/V8FutureResolverCustom.cpp |
@@ -0,0 +1,112 @@ |
+/* |
+ * 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 "V8FutureResolver.h" |
+ |
+// Include generated files. |
+#include "V8Future.h" |
+ |
+#include "bindings/v8/V8AnyCallback.h" |
+#include "bindings/v8/V8Binding.h" |
+#include "bindings/v8/V8DOMWrapper.h" |
+#include "bindings/v8/V8FutureInit.h" |
+#include "bindings/v8/V8Utilities.h" |
+#include "core/dom/AnyCallback.h" |
+#include "core/dom/Future.h" |
+#include "core/dom/FutureInit.h" |
+#include "core/platform/Logging.h" |
+#include "wtf/RefPtr.h" |
+ |
+namespace WebCore { |
+ |
+v8::Handle<v8::Value> V8FutureResolver::resolveMethodCustom(const v8::Arguments& args) |
+{ |
+ FutureResolver* impl = toNative(args.Holder()); |
+ |
+ if (impl->resolved()) |
+ return v8Undefined(); |
+ |
+ v8::HandleScope scope; |
+ |
+ v8::Handle<v8::Value> then; |
+ |
+ LOG(Network, "Get then"); |
+ |
+ if (args.Length() >= 1 && args[0]->IsObject()) { |
+ v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(args[0]); |
+ v8::Handle<v8::String> key = v8::String::NewSymbol("then"); |
+ if (object->Has(key)) { |
+ v8::TryCatch exceptionCatcher; |
+ exceptionCatcher.SetVerbose(true); // ? |
+ then = object->Get(key); |
+ if (exceptionCatcher.HasCaught()) { |
+ impl->rejectInternal(exceptionCatcher.Exception(), true); |
+ return v8Undefined(); |
+ } |
+ } |
+ } |
+ |
+ LOG(Network, "then is callable?"); |
+ |
+ if (!then.IsEmpty() && then->IsFunction()) { |
+ v8::TryCatch exceptionCatcher; |
+ exceptionCatcher.SetVerbose(true); // ? |
+ |
+ LOG(Network, "args[0] is Future?"); |
+ |
+ if (args.Length() <= 0 || !V8Future::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate()))) |
+ return v8Undefined(); |
+ Future* argFuture = V8Future::toNative(v8::Handle<v8::Object>::Cast(args[0])); |
+ argFuture->then(impl->getFuture()); |
+ |
+ // // FIXME |
+ // v8::Handle<v8::Value> argv[] = { }; |
+ |
+ // v8::Handle<v8::Value> result = ScriptController::callFunctionWithInstrumentation(getScriptExecutionContext(), v8::Handle<v8::Function>::Cast(then), v8::Handle<v8::Object>::Cast(value.v8Value()), 0, argv); |
+ if (exceptionCatcher.HasCaught()) |
+ impl->rejectInternal(exceptionCatcher.Exception(), true); |
+ return v8Undefined(); |
+ } |
+ |
+ LOG(Network, "resolve resulted in accept"); |
+ |
+ if (args.Length() >= 1 && !args[0].IsEmpty()) |
+ impl->acceptInternal(args[0], true); |
+ else |
+ impl->acceptInternal(v8Undefined(), true); |
+ |
+ LOG(Network, "resolve end"); |
+ |
+ return v8Undefined(); |
+} |
+ |
+} // namespace WebCore |