Index: tools/dom/templates/html/dartium/html_dartium.darttemplate |
diff --git a/tools/dom/templates/html/dartium/html_dartium.darttemplate b/tools/dom/templates/html/dartium/html_dartium.darttemplate |
index b15dab237afe597501927d563a74b151841e4748..a7831cd343276e396045e23b1dfad759129b4f68 100644 |
--- a/tools/dom/templates/html/dartium/html_dartium.darttemplate |
+++ b/tools/dom/templates/html/dartium/html_dartium.darttemplate |
@@ -394,6 +394,17 @@ wrap_jso(jsObject) { |
// JS Interop converted the object to a Dart class e.g., Uint8ClampedList. |
return jsObject; |
} |
+ |
+ // To preserve identity, if we already have a wrapper for this, return it. |
+ var existing; |
+ if (jsObject is! js.JsArray) { |
+ var existing = jsObject['dartClass_instance']; |
+ try { |
+ if (unwrap_jso(existing) == jsObject) { |
+ return existing; |
+ } |
+ } catch(e) {} |
+ } |
// 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 +431,7 @@ wrap_jso(jsObject) { |
if (func != null) { |
dartClass_instance = func(); |
dartClass_instance.blink_jsObject = jsObject; |
+ jsObject['dartClass_instance'] = dartClass_instance; |
} |
} |
return dartClass_instance; |
@@ -435,6 +447,7 @@ wrap_jso(jsObject) { |
return null; |
} |
+ |
/** |
* Create Dart class that maps to the JS Type that is the JS type being |
* extended using JS interop createCallback (we need the base type of the |