Skip to content

[CP] Handle object literal constructors with no library @JS annotation in dart2js #55057

Closed
@srujzs

Description

@srujzs

Commit(s) to merge

https://dart-review.googlesource.com/c/sdk/+/349840

Target

stable

Prepared changelist for beta/stable

https://dart-review.googlesource.com/c/sdk/+/355060

Issue Description

JS interop allows users to declare interop extension types with object literal constructors that create objects with a given set of properties. These constructors are lowered in the backends. However, in dart2js, the code to determine whether an external constructor is an object literal constructor relied on the library having an @JS annotation. Therefore, code that did not have this annotation would fail to compile as dart2js can not determine what that member is supposed to be. The workaround is to declare the library with an @JS annotation.

This occurs only on web and in dart2js. DDC and dart2wasm do not have this issue.

What is the fix

The fix is to align with DDC and assume external extension type constructors with named arguments are object literal constructors in dart2js, regardless of whether the library contains an @JS annotation.

Why cherry-pick

This results in confusing crashes, and affects any users using interop extension types. As we encourage more Flutter packages to migrate to Wasm-compatible interop, I expect more users to be affected. This has already resulted in two bugs since 3.3 released:

#54958
#55039

The second one resulted in a broken package version accidentally being released due to the discrepancy between DDC and dart2js here.

Risk

low

Issue link(s)

#54801

Extra Info

No response

Metadata

Metadata

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.cherry-pick-approvedLabel for approved cherrypick requestcherry-pick-reviewIssue that need cherry pick triage to approvemerge-to-stable

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions