Issue 23574 in dart: Can't access properties of JsObject that wraps a javascript custom element prototype

43 views
Skip to first unread message

da...@googlecode.com

unread,
Jun 2, 2015, 3:10:31 PM6/2/15
to bu...@dartlang.org
Status: New
Owner: ----
Labels: Type-Defect Priority-Unassigned Area-Dart2JS Library-JS

New issue 23574 by jak...@google.com: Can't access properties of JsObject
that wraps a javascript custom element prototype
https://code.google.com/p/dart/issues/detail?id=23574

See https://gist.github.com/jakemac53/dc4d38ba20e9783f1581 for an example
which works in dartium but not in dart2js. The error message is the
following:

Uncaught TypeError: J.getInterceptor$asx(...).$index is not a function

This makes it so you can't modify or access properties on the prototype of
a javascript custom element, which limits pretty heavily what you can do.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

da...@googlecode.com

unread,
Jun 2, 2015, 3:42:27 PM6/2/15
to bu...@dartlang.org
Updates:
Labels: -Priority-Unassigned Priority-High Milestone-1.11

Comment #1 on issue 23574 by jak...@google.com: Can't access properties of
JsObject that wraps a javascript custom element prototype
https://code.google.com/p/dart/issues/detail?id=23574

This is currently a blocker for rolling polymer js 1.0 using js interop, so
I bumped the priority.

da...@googlecode.com

unread,
Jun 2, 2015, 4:55:17 PM6/2/15
to bu...@dartlang.org
Updates:
Status: Triaged
Owner: sig...@google.com
Cc: s...@google.com

Comment #2 on issue 23574 by sig...@google.com: Can't access properties of
JsObject that wraps a javascript custom element prototype
https://code.google.com/p/dart/issues/detail?id=23574

I'll take a look while Stephen is out.

da...@googlecode.com

unread,
Jun 2, 2015, 6:52:55 PM6/2/15
to bu...@dartlang.org
Updates:
Status: Accepted
Labels: -Area-Dart2JS Area-Library

Comment #3 on issue 23574 by sig...@google.com: Can't access properties of
JsObject that wraps a javascript custom element prototype
https://code.google.com/p/dart/issues/detail?id=23574

It looks like this could be a problem in dart:js.

In particular, consider these two lines in the example

var element = new
JsObject.fromBrowserObject(document.createElement('...'));
var proto = element['__proto__'];


Here `element` is a JsObject, but `proto` is not. We seem to be returning
the prototype as an object, and not a JsObject wrapper for it.

This comes down to this code in dart:js:

https://github.com/dart-lang/sdk/blob/c8fb46306c12e96b2a641e1cc0a70c342e40504b/sdk/lib/js/dart2js/js_dart2js.dart#L594

_isLocalObject is true and `o is Node` is true (o is the HtmlElement
prototype, whose interceptor contains $isNode). So we are returning `o`
instead of _wrapToDart(o)


While we fix this, there is a hacky workaround you could use:

import 'dart:html';
import 'dart:js';

main() {
var element = new
JsObject.fromBrowserObject(document.createElement('hello-world'));
var proto = element['__proto__'];
var message = proto is JsObject
? proto['message']
: new JsObject.fromBrowserObject(proto)['message']; // awful awful!
print(message);

da...@googlecode.com

unread,
Jun 3, 2015, 12:29:44 PM6/3/15
to bu...@dartlang.org

Comment #4 on issue 23574 by jak...@google.com: Can't access properties of
JsObject that wraps a javascript custom element prototype
https://code.google.com/p/dart/issues/detail?id=23574

Ah, thanks for the workaround, that has unblocked me for now at least :)
Reply all
Reply to author
Forward
0 new messages