Skip to content

createJSInteropWrapper should take in a proto object parameter to instantiate the JS object with #61567

@srujzs

Description

@srujzs

Currently, createJSInteropWrapper takes in a Dart object only (and its type as a type parameter) and wraps it with a JS object that is created with Object.create(). This is okay and at parity with createDartExport from js_util, but doesn't have the useful property of setting the prototype. We had this with createStaticInteropMock from js_util and it's useful for mocking JS values, especially when type checks are involved.

We could naturally set the prototype after the creation, but that'll deoptimize code (see the warning in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf).

Instead, we should add a parameter to pass in a prototype object to createJSInteropWrapper and use it in the underlying Object.create call.


This is also needed to remove dart:js_util from dart2wasm as well as we currently are using createStaticInteropMock to set the prototype of the object returned from List.toJSProxyOrRef. If the js_util API goes, we lost the ability to set the prototype. cc @fishythefish See #61550 for more details on that.

Metadata

Metadata

Assignees

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-js-interopIssues that impact all js interop

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions