Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: Source/bindings/v8/V8FutureInit.cpp

Issue 15786003: WIP don't review: Implement Future (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/v8/V8FutureInit.cpp
diff --git a/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp b/Source/bindings/v8/V8FutureInit.cpp
similarity index 51%
copy from Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
copy to Source/bindings/v8/V8FutureInit.cpp
index 66d97e217f09100524a05cd718aac2e01ef0d3f1..baa00283653c6c37fca17eefb65bfc7eed2cb54a 100644
--- a/Source/bindings/v8/custom/V8CustomSQLStatementErrorCallback.cpp
+++ b/Source/bindings/v8/V8FutureInit.cpp
@@ -1,10 +1,10 @@
/*
- * Copyright (c) 2009, 2012 Google Inc. All rights reserved.
- *
+ * 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
@@ -14,7 +14,7 @@
* * 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
@@ -30,48 +30,67 @@
#include "config.h"
-#include "V8SQLStatementErrorCallback.h"
+#include "bindings/v8/V8FutureInit.h"
-#include "V8SQLError.h"
-#include "V8SQLTransaction.h"
-#include "bindings/v8/V8Callback.h"
-#include "core/dom/ScriptExecutionContext.h"
-#include "wtf/Assertions.h"
+// Include generated files.
+#include "V8Future.h"
+#include "V8FutureResolver.h"
+
+#include "bindings/v8/ScriptController.h"
+#include "bindings/v8/V8Binding.h"
+#include "core/platform/Logging.h"
namespace WebCore {
-bool V8SQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error)
+V8FutureInit::V8FutureInit(v8::Handle<v8::Function> callback, ScriptExecutionContext* context)
+ : ActiveDOMCallback(context)
+ , m_callback(callback)
+ , m_world(DOMWrapperWorld::current())
+{
+ // FIXME: Probably NO. Make the Persistent m_callback has weak?
+}
+
+ScriptValue V8FutureInit::call(PassRefPtr<FutureResolver> value, PassRefPtr<Future> future, ScriptExecutionContext*)
{
if (!canInvokeCallback())
- return true;
+ return ScriptValue();
v8::HandleScope handleScope;
v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_world.get());
if (v8Context.IsEmpty())
- return true;
+ return ScriptValue();
+ // Enter the context.
v8::Context::Scope scope(v8Context);
- v8::Handle<v8::Value> transactionHandle = toV8(transaction, v8::Handle<v8::Object>(), v8Context->GetIsolate());
- v8::Handle<v8::Value> errorHandle = toV8(error, v8::Handle<v8::Object>(), v8Context->GetIsolate());
- if (transactionHandle.IsEmpty() || errorHandle.IsEmpty()) {
+ // FIXME: Need to New with v8Context's isolate?
+
+ if (m_callback.isEmpty())
+ return ScriptValue();
+
+ v8::Handle<v8::Function> callback = m_callback.get();
+
+ // Call get() to disambiguate toV8 call.
+ v8::Handle<v8::Value> futureHandle = toV8(future.get(), v8::Handle<v8::Object>(), v8Context->GetIsolate());
+ if (!futureHandle->IsObject() || futureHandle.IsEmpty()) {
+ if (!isScriptControllerTerminating())
+ CRASH();
+ return ScriptValue();
+ }
+
+ v8::Handle<v8::Value> valueHandle = toV8(value.get(), v8::Handle<v8::Object>(), v8Context->GetIsolate());
+ if (valueHandle.IsEmpty()) {
if (!isScriptControllerTerminating())
CRASH();
- return true;
+ return ScriptValue();
}
+ v8::Handle<v8::Value> argv[] = { valueHandle };
- v8::Handle<v8::Value> argv[] = {
- transactionHandle,
- errorHandle
- };
-
- bool callbackReturnValue = false;
- // Step 6: If the error callback returns false, then move on to the next
- // statement, if any, or onto the next overall step otherwise. Otherwise,
- // the error callback did not return false, or there was no error callback.
- // Jump to the last step in the overall steps.
- return invokeCallback(m_callback.get(), 2, argv, callbackReturnValue, scriptExecutionContext()) || callbackReturnValue;
+ v8::TryCatch exceptionCatcher;
+ exceptionCatcher.SetVerbose(true); // ?
+ ScriptController::callFunctionWithInstrumentation(scriptExecutionContext(), callback, v8::Handle<v8::Function>::Cast(futureHandle), 1, argv);
+ return exceptionCatcher.Exception();
}
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698