| 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)
|
|
|