Skip to content

Need spec and compile-time errors of incorrect JS interop usage #32929

Closed
@jmesserly

Description

@jmesserly

There are many invalid things that can be done with JS interop, but we don't have static errors for this.

Here are some examples of things that should be reported (or else, need to be specified and fixed in the DDC/dart2js):

  • an anonymous JS class with positional arguments in the constructor. This is invalid, because it's supposed to create an object literal, and causes a DDC crash (see Error compiling dartdevc module #32031)
  • use of generic functions/methods (currently unsupported in JS interop)
  • use of generic classes (what is intended behavior?)
  • use of @JS on a class/library member without a @JS on the library
  • use of @JS on a class member instead of external
  • declaring Dart members on a @JS class (Dart code is silently ignored)
  • extends/mixin@JS classes from a Dart class (also unclear if implements is supported)
  • extends/mixin/implements Dart class from @JS class

Errors should be reported from Analyzer so people can see the problem sooner. (Once DDC migrates to Kernel, need a way of calling into Analyzer to produce these kinds of errors. Or we just have shared code between dart2js/DDC for validating JS interop usage.)


Also it would be lovely to have a specification. These would be useful:

  • where is @JS allowed to appear?
  • where is external allowed to appear?
  • inheritance implications of the various permutations of Dart and JS classes and member kinds
  • interaction with Dart generic classes
  • interaction with Dart generic methods/functions
  • meaning of Dart members on a JS class
  • semantics of anonymous JS types
  • how JS types fit into the Dart subtyping relation and Dart Type equality
  • how JS functions related to the Dart type system
  • static and dynamic call/get/set/index/operator/tearoff semantics
  • behavior of dart:core Object members (toString, hashCode, operator ==, noSuchMethod, runtimeType) for JS objects
  • interaction with the JS global namespace
  • interaction with JS modules

Metadata

Metadata

Assignees

Labels

EpicP1A high priority bug; for example, a single project is unusable or has many test failuresarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.customer-google3web-js-interopIssues that impact all js interop

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions