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

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

Issue 1383773003: Preserve identity on JsObject wrappers (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Whitespace cleanup Created 5 years, 3 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/core/dart/DartJsInterop.cpp
diff --git a/Source/bindings/core/dart/DartJsInterop.cpp b/Source/bindings/core/dart/DartJsInterop.cpp
index 0a2e39f1db8636c2e98069fd23acbed3d7688bd6..f7aa6c44b41e954b47c2ff65c33ee72bd95bde2a 100644
--- a/Source/bindings/core/dart/DartJsInterop.cpp
+++ b/Source/bindings/core/dart/DartJsInterop.cpp
@@ -431,19 +431,47 @@ Dart_Handle JsInterop::toDart(v8::Local<v8::Value> v8Handle)
Dart_Handle JsObject::toDart(v8::Local<v8::Object> object)
{
- // FIXME: perform caching so that === can be used.
- if (object->IsFunction()) {
- RefPtr<JsFunction> jsFunction = JsFunction::create(object.As<v8::Function>());
- return JsFunction::toDart(jsFunction);
+
+ Dart_Handle wrapper;
+ v8::Isolate* v8Isolate = v8::Isolate::GetCurrent();
+ // TODO(alanknight): This will fail for multiple isolates referencing the same JS object.
+ // We probably need to use a different property name for different isolates.
+ v8::Local<v8::Value> hiddenValue = object->GetHiddenValue(v8::String::NewFromUtf8(v8Isolate, "$existing_dart_wrapper"));
+
+ if (*hiddenValue && hiddenValue->IsObject()) {
+ DartPersistentValue* scriptValue = DartHandleProxy::readPointerFromProxy(hiddenValue.As<v8::Object>());
+ ASSERT(scriptValue->isIsolateAlive());
+ // If the isolate does not match we fall back to using the existing JS
+ // wrapper for the Dart object so that simple cases that would work in
+ // Dart2Js work. We could alternately throw an exception here.
+ if (scriptValue->isolate() == Dart_CurrentIsolate()) {
+ return scriptValue->value();
+ }
}
- if (object->IsArray()) {
+ if (object->IsFunction()) {
+ RefPtr<JsFunction> jsFunction = JsFunction::create(object.As<v8::Function>());
+ wrapper = JsFunction::toDart(jsFunction);
+ } else if (object->IsArray()) {
RefPtr<JsArray> jsArray = JsArray::create(object.As<v8::Array>());
- return JsArray::toDart(jsArray);
+ wrapper = JsArray::toDart(jsArray);
+ } else {
+ RefPtr<JsObject> jsObject = JsObject::create(object);
+ wrapper = JsObject::toDart(jsObject);
}
-
- RefPtr<JsObject> jsObject = JsObject::create(object);
- return JsObject::toDart(jsObject);
+ v8::Local<v8::Object> proxy;
+ ASSERT(Dart_IsInstance(wrapper));
+ // Simulate the behavior of the Dart dev compiler where new List() is
+ // equivalent to a JavaScript array. We accomplish this by creating a
+ // JavaScript object that fakes that it is a JavaScript array but is
+ // actually backed by a Dart list. This is not a breaking change as
+ // existing Dart-JS interop passed arrays as opaque Dart handles.
+ // The jsify method can still be called if you wish to create a copy
+ // of a json like Dart data structure.
+ proxy = dartObjectTemplate()->InstanceTemplate()->NewInstance();
+ DartHandleProxy::writePointerToProxy(proxy, wrapper);
+ object->SetHiddenValue(v8::String::NewFromUtf8(v8Isolate, "$existing_dart_wrapper"), proxy);
+ return wrapper;
}
static void maybeCreateJsObjectImplClass(DartDOMData* domData)
« 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