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

Unified Diff: Source/bindings/dart/DartJsInterop.cpp

Issue 231743006: Run Dart closures invoked from JS in the correct Zone Base URL: svn://svn.chromium.org/blink/branches/dart/1847
Patch Set: DO NOT SUBMIT: Non-working fix for round-trip functions Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/dart/DartJsInterop.cpp
diff --git a/Source/bindings/dart/DartJsInterop.cpp b/Source/bindings/dart/DartJsInterop.cpp
index ba91725a100f51edf6d2faf6e136f438f1d9ab7d..8cd32434c8c7e3baf28eeae0a450a419bc099447 100644
--- a/Source/bindings/dart/DartJsInterop.cpp
+++ b/Source/bindings/dart/DartJsInterop.cpp
@@ -80,23 +80,27 @@ static void functionInvocationCallback(const v8::FunctionCallbackInfo<v8::Value>
DartDOMData* domData = DartDOMData::current();
ASSERT(domData);
ASSERT(DartUtilities::isFunction(domData, handle));
-
- Vector<Dart_Handle> dartFunctionArgs;
ASSERT(args.Length() == 1 || args.Length() == 2);
+
+ v8::Local<v8::Array> argsList = args[args.Length()-1].As<v8::Array>();
+ uint32_t argsListLength = argsList->Length();
+ Dart_Handle dartFunctionArgs;
+ uint32_t offset = 0;
// If there is 1 argument, we assume it is a v8:Array or arguments, if
// there are 2 arguments, the first argument is "this" and the second
// argument is an array of arguments.
- if (args.Length() > 1) {
- dartFunctionArgs.append(JsInterop::toDart(args[0]));
+ if (args.Length() == 1) {
+ dartFunctionArgs = Dart_NewList(argsListLength);
+ } else {
+ dartFunctionArgs = Dart_NewList(argsListLength + 1);
+ Dart_ListSetAt(dartFunctionArgs, offset++, JsInterop::toDart(args[0]));
}
- v8::Local<v8::Array> argsList = args[args.Length()-1].As<v8::Array>();
- uint32_t argsListLength = argsList->Length();
for (uint32_t i = 0; i < argsListLength; i++) {
- dartFunctionArgs.append(JsInterop::toDart(argsList->Get(i)));
+ Dart_ListSetAt(dartFunctionArgs, i + offset, JsInterop::toDart(argsList->Get(i)));
Jacob 2014/04/16 22:27:55 nit: keep the style consistent and replace i + off
}
- setJsReturnValue(domData, args, Dart_InvokeClosure(handle, dartFunctionArgs.size(), dartFunctionArgs.data()));
+ setJsReturnValue(domData, args, Dart_InvokeClosure(handle, 1, &dartFunctionArgs));
}
static v8::Local<v8::ObjectTemplate> setupInstanceTemplate(v8::Local<v8::FunctionTemplate> proxyTemplate)
@@ -221,7 +225,11 @@ v8::Local<v8::Value> JsInterop::fromDart(DartDOMData* domData, Dart_Handle handl
DartHandleProxy::writePointerToProxy(functionProxy, handle);
// The raw functionProxy doesn't behave enough like a true JS function
// so we wrap it in a true JS function.
- return domData->jsInteropData()->wrapDartFunction()->Call(functionProxy, 0, 0);
+ v8::Local<v8::Function> jsFunction = v8::Local<v8::Function>::Cast(domData->jsInteropData()->wrapDartFunction()->Call(functionProxy, 0, 0));
+ DartHandleProxy::writePointerToProxy(jsFunction, handle);
+ v8::Isolate* v8Isolate = v8::Isolate::GetCurrent();
+ jsFunction->SetHiddenValue(v8::String::NewFromUtf8(v8Isolate, "dartProxy"), v8::Boolean::New(v8Isolate, true));
+ return jsFunction;
}
v8::Local<v8::Object> proxy;
@@ -260,11 +268,7 @@ Dart_Handle JsInterop::toDart(v8::Local<v8::Value> v8Handle)
if (handle)
return handle;
- // Unwrap objects passed from Dart to JS that are being passed back to
- // Dart. FIXME: we do not yet handle unwrapping JS functions passed
- // from Dart to JS as we have to wrap them with true JS Function objects.
- // If this use case is important we can support it at the cost of hanging
- // an extra expando off the JS function wrapping the Dart function.
+ // Unwrap objects passed from Dart to JS that are being passed back to Dart.
if (DartHandleProxy::isDartProxy(v8Handle)) {
DartScriptValue* scriptValue = DartHandleProxy::readPointerFromProxy(v8Handle);
ASSERT(scriptValue->isIsolateAlive());
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698