Skip to content

js-interop: Breaking bug calling methods on JS class named 'Node' #28005

Closed
@theefer

Description

@theefer

I've encountered a confusing issue in Dartium when trying to interoperate with a JS library ProseMirror that exposes instances of a class named Node.

I've defined an interop definition around it like so:

@JS()
class Node {
  external bool get isText;
  external String get text;

Given node an instance of that Node class (let's call it pm.Node for clarity), calling node.isText works fine, however calling node.text throws the following exception:

EXCEPTION: Unhandled exception:
Not a valid Node
#0      BlinkNode.textContent_Getter_ (dart:_blink:11270)
#1      Node.text (dart:html:28048)

Apparently, the VM gets sufficiently confused about types that it tries to call the text method from dart:html's Node class (!?!), and then complains it's not an instance of that class. I can also confirm that this error occurs when trying to call any dart:html Node method on my pm.Node instance, regardless of whether it exists on pm.Node or not. In contrast, trying to call a method or getter that doesn't exists on either throws the expected NoSuchMethodError: Class 'Node' has no instance getter '___'..

Fortunately, after a few hours of head scratching I figured out that I can rename the getter to JS$text to work around this issue, but it's still a very confusing and annoying bug.

This may be related to #25785, which was fixed recently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions