Preserve identity of Dart wrappers on DOM objects

BUG=

Review URL: https://codereview.chromium.org/1380963003 .
This commit is contained in:
Alan Knight 2015-10-01 14:04:01 -07:00
parent 1a11dbfc1c
commit 07b2ddd401
6 changed files with 36 additions and 12 deletions

View file

@ -1145,10 +1145,19 @@ unwrap_jso(dartClass_instance) {
*/
wrap_jso(jsObject) {
try {
if (jsObject is! js.JsObject) {
if (jsObject is! js.JsObject || jsObject == null) {
// JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
// or it's a simple type.
return jsObject;
}
// TODO(alanknight): With upgraded custom elements this causes a failure because
// we need a new wrapper after the type changes. We could possibly invalidate this
// if the constructor name didn't match?
if (jsObject.dartWrapper != null) {
return jsObject.dartWrapper;
}
// Try the most general type conversions on it.
// TODO(alanknight): We may be able to do better. This maintains identity,
// which is useful, but expensive. And if we nest something that only
@ -1175,6 +1184,7 @@ wrap_jso(jsObject) {
if (func != null) {
dartClass_instance = func();
dartClass_instance.blink_jsObject = jsObject;
jsObject.dartWrapper = dartClass_instance;
}
}
return dartClass_instance;
@ -37168,10 +37178,10 @@ class Url extends NativeFieldWrapperClass2 implements UrlUtils {
if ((blob_OR_source_OR_stream is Blob || blob_OR_source_OR_stream == null)) {
return _blink.BlinkURL.instance.createObjectURL_Callback_1_(unwrap_jso(blob_OR_source_OR_stream));
}
if ((blob_OR_source_OR_stream is MediaStream)) {
if ((blob_OR_source_OR_stream is MediaSource)) {
return _blink.BlinkURL.instance.createObjectURL_Callback_1_(unwrap_jso(blob_OR_source_OR_stream));
}
if ((blob_OR_source_OR_stream is MediaSource)) {
if ((blob_OR_source_OR_stream is MediaStream)) {
return _blink.BlinkURL.instance.createObjectURL_Callback_1_(unwrap_jso(blob_OR_source_OR_stream));
}
throw new ArgumentError("Incorrect number or type of arguments");

View file

@ -488,6 +488,12 @@ JsObject get context {
class JsObject extends NativeFieldWrapperClass2 {
JsObject.internal();
/**
* If this JsObject is wrapped, e.g. DOM objects, then we can save the
* wrapper here and preserve its identity.
*/
var dartWrapper;
/**
* Constructs a new JavaScript object from [constructor] and returns a proxy
* to it.

View file

@ -20,10 +20,7 @@ LayoutTests/fast/events/remove-event-listener_t01: RuntimeError # Dartium JSInte
LayoutTests/fast/xpath/4XPath/Core/test_parser_t01: RuntimeError # Dartium JSInterop failure
LayoutTests/fast/xpath/py-dom-xpath/abbreviations_t01: RuntimeError # Dartium JSInterop failure
LayoutTests/fast/xpath/py-dom-xpath/axes_t01: RuntimeError # Dartium JSInterop failure
LibTest/html/Element/offsetParent_A01_t01: RuntimeError # Dartium JSInterop failure
LibTest/html/Event/currentTarget_A01_t01: RuntimeError # Dartium JSInterop failure
LibTest/html/Event/matchingTarget_A01_t01: RuntimeError # Dartium JSInterop failure
LibTest/html/Event/target_A01_t01: RuntimeError # Dartium JSInterop failure
LayoutTests/fast/dom/custom/element-type_t01: RuntimeError # Dartium JsInterop failure (element upgrade)
[ $compiler == none && $runtime == dartium && $checked ]
LayoutTests/fast/css/style-scoped/style-scoped-scoping-nodes-different-order_t01: RuntimeError # Dartium JSInterop failure

View file

@ -18,7 +18,8 @@ custom/element_upgrade_test: RuntimeError # Dartium JSInterop failure
custom/js_custom_test: RuntimeError # Dartium JSInterop failure
custom_elements_test/register: RuntimeError # Dartium JSInterop failure
indexeddb_2_test: Skip # Dartium JSInterop failure
js_test: RuntimeError # Dartium JSInterop failure
js_test/transferrables: RuntimeError # Dartium JSInterop failure
js_test/JsArray: RuntimeError # Dartium JSInterop failure
native_gc_test: Skip # Dartium JSInterop failure
speechrecognition_test/types: RuntimeError # Dartium JSInterop failure
storage_quota_test/missingenumcheck: RuntimeError # Dartium JSInterop failure

View file

@ -11,7 +11,7 @@ import 'dart:indexed_db' show IdbFactory, KeyRange;
import 'dart:js';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:unittest/html_individual_config.dart';
_injectJs() {
final script = new ScriptElement();
@ -230,7 +230,7 @@ class Callable {
main() {
_injectJs();
useHtmlConfiguration();
useHtmlIndividualConfiguration();
group('identity', () {
@ -552,7 +552,7 @@ main() {
array.length = 3;
expect(array, [1, 2, null]);
});
test('add', () {
var array = new JsArray();
array.add('a');

View file

@ -390,10 +390,19 @@ unwrap_jso(dartClass_instance) {
*/
wrap_jso(jsObject) {
try {
if (jsObject is! js.JsObject) {
if (jsObject is! js.JsObject || jsObject == null) {
// JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
// or it's a simple type.
return jsObject;
}
// TODO(alanknight): With upgraded custom elements this causes a failure because
// we need a new wrapper after the type changes. We could possibly invalidate this
// if the constructor name didn't match?
if (jsObject.dartWrapper != null) {
return jsObject.dartWrapper;
}
// Try the most general type conversions on it.
// TODO(alanknight): We may be able to do better. This maintains identity,
// which is useful, but expensive. And if we nest something that only
@ -420,6 +429,7 @@ wrap_jso(jsObject) {
if (func != null) {
dartClass_instance = func();
dartClass_instance.blink_jsObject = jsObject;
jsObject.dartWrapper = dartClass_instance;
}
}
return dartClass_instance;