Skip to content

[js interop] interop objects sometimes implement Dart types #56531

@sigmundch

Description

@sigmundch

Because we still support dart:html, implementation details escape and are visible in via JS interop (either in package:web or hand written interop that exposes browser APIs).

For example, this program:

import 'dart:html';
import 'dart:js_interop';

@JS('localStorage')
external JSObject myLocalStorage;

main() {
  Object? x1 = window.localStorage;
  print(x1 is Map);
  Object? x2 = myLocalStorage;
  print(x2 is Map);
}

Prints true twice in DDC and dart2js.

If the dart:html code is tree-shaken, then dart2js changes behavior:

import 'dart:js_interop';

@JS('localStorage')
external JSObject myLocalStorage;

main() {
  Object? x2 = myLocalStorage;
  print(x2 is Map); // prints false in dart2js, but true in DDC.
}

It's not clear if we want to change anything at this time, but this is also something we'd need to address in our process of deprecating and removing dart:html.

Note that, since dart2wasm doesn't support dart:html, it always prints false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.dart2js-ddc-discrepancyWhen dev and production compilations have different semanticsweb-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