dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
180 stars 33 forks source link

Polymer 1 Project works in Dartium but fails in Chrome #632

Closed zoechi closed 7 years ago

zoechi commented 9 years ago

When I load web/index.html in Chrome I get the exception when I select a demo from the left drawer:

Uncaught TypeError: J.getInterceptor$asx(...).$index is not a function J.$index$asx @ init.dart:31 (anonymous function) @ all_demos.dart:260 (anonymous function) @ VM900:2 dart.Primitives_applyFunctionWithPositionalArguments @ js_helper.dart:1457 dart._InstanceMirrorImpl.invoke$3 @ js_helper.dart:1424 dart._InstanceMirrorImpl.invoke$2 @ reflectable_transformer_based.dart:173 dart._setupReflectableMethods__closure.call$2 @ polymer_descriptor.dart:161 dart.Primitives_applyFunctionWithPositionalArguments @ js_helper.dart:1457 dart._callDartFunction @ js_helper.dart:1424 (anonymous function) @ js_dart2js.dart:106 (anonymous function) @ index.html:1405 handler @ index.html:4410 decorated @ index.html:9109 Polymer.Base._addFeature.fire @ index.html:5427 Gestures.fire @ index.html:4814 Gestures.register.forward @ index.html:5087 Gestures.register.click @ index.html:5068 Gestures.handleNative @ index.html:4693

https://github.com/bwu-dart/polymer_elements_demos/blob/master/web/all_demos.dart#L260

Works fine in Dartium bleeding edge.

zoechi commented 9 years ago

Same exception in Firefox 41.0.2

jakemac53 commented 9 years ago

Ah so this is really a dart2js bug, you can fix it by wrapping the return value of modelForElement in a js object (with new JsObject.fromBrowserObject(...))

jakemac53 commented 9 years ago

Basically if a js object has HTMLElement anywhere on its prototype chain then dart2js thinks its an html element instead of just a normal js object. The models for the template instances have Polymer.Base on their prototype chain, and the prototype of that is HTMLElement, so dart2js thinks these model objects are html elements, when they are not.

jakemac53 commented 9 years ago

This is also arguably a polymer js bug, since none of the methods from HTMLElement.prototype are going to be valid for the model object ;)

jakemac53 commented 9 years ago

cc @jacob314 @sigmundch

zoechi commented 9 years ago

Thanks a lot for that workaround (works now) and your super-fast response :+1: