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 25336a7e730db2f92f84b8e941f7189d3943a0de..222865b43a178372775c7fc42d88be8f5e4847e7 100644 |
--- a/tools/dom/templates/html/dartium/html_dartium.darttemplate |
+++ b/tools/dom/templates/html/dartium/html_dartium.darttemplate |
@@ -420,8 +420,9 @@ wrap_jso(jsObject) { |
var dartClass_instance; |
if (jsObject.hasProperty('dart_class')) { |
- // Got a dart_class (it's a custom element) use it it's already set up. |
- dartClass_instance = jsObject['dart_class']; |
+ // Got a dart_class (it's a custom element) use it it's already set up |
+ // make sure it's upgraded. |
+ dartClass_instance = _upgradeHtmlElement(jsObject['dart_class']); |
} else { |
var localName = jsObject['localName']; |
var customElementClass = _knownCustomeElements[localName]; |
@@ -495,6 +496,29 @@ wrap_jso_custom_element(jsObject) { |
} |
} |
+// Upgrade a Dart HtmlElement to the user's Dart custom element class. |
+_upgradeHtmlElement(dartInstance) { |
+ var dartInstanceMirror = reflect(dartInstance); |
+ if (dartInstanceMirror.type.qualifiedName == #dart.dom.html.HtmlElement) { |
Alan Knight
2015/10/07 16:21:29
Could you do this with dartInstance.runtimeType ==
|
+ // Must be exactly HtmlElement not something derived from it. |
+ var jsObject = dartInstance.blink_jsObject; |
+ var localName = dartInstance.localName; |
+ var customElementClass = _knownCustomeElements[localName]; |
+ // Custom Element to upgrade. |
+ if (customElementClass != null) { |
+ try { |
+ dartInstance = _blink.Blink_Utils.constructElement(customElementClass, jsObject); |
+ } finally { |
+ dartInstance.blink_jsObject = jsObject; |
+ jsObject['dart_class'] = dartInstance; |
+ js.setDartHtmlWrapperFor(jsObject, dartInstance); |
+ } |
+ } |
+ } |
+ |
+ return dartInstance; |
+} |
+ |
class DebugAssertException implements Exception { |
String message; |
DebugAssertException(this.message); |