-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix JS interop signatures to use only JS types. #45668
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1847,8 +1847,8 @@ void _paragraphTests() { | |
}, skip: isFirefox); // Intended: Headless firefox has no webgl support https://github.com/flutter/flutter/issues/109265 | ||
|
||
group('getCanvasKitJsFileNames', () { | ||
dynamic oldV8BreakIterator = v8BreakIterator; | ||
dynamic oldIntlSegmenter = intlSegmenter; | ||
JSAny? oldV8BreakIterator = v8BreakIterator; | ||
JSAny? oldIntlSegmenter = intlSegmenter; | ||
|
||
setUp(() { | ||
oldV8BreakIterator = v8BreakIterator; | ||
|
@@ -1861,8 +1861,8 @@ void _paragraphTests() { | |
}); | ||
|
||
test('in Chromium-based browsers', () { | ||
v8BreakIterator = Object(); // Any non-null value. | ||
intlSegmenter = Object(); // Any non-null value. | ||
v8BreakIterator = Object().toJSBox; // Any non-null value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In dart2wasm, all dart objects are wasm structs. There is a wasm opcode to externalize these structs and create an externref, and that externref can be passed to the JS host environment. To JS, that object is a sort of special opaque object with an immutable prototype, and that can be passed back to wasm and internalized again if needed. In dart2js, I think this actually creates some sort of secondary wrapper around the dart object, but that also might be changing soon to do nothing and just pass the dart object (which is just a JS object) around, and only really changes the static type of the object from the dart language perspective. In any case, it doesn't matter much in this scenario, just that it creates a non-null, non-falsey JS value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just +1'ing here. The desire was to avoid users attempting to interface with Dart objects on the JS side or accidentally passing it to different runtimes. For the JS backends, this does mean that we need an actual wrapper, which in practice is just an object literal with a runtime-specific symbol to store the object in. This may indeed change based on some internal feedback, but shouldn't affect how this code is being used. |
||
intlSegmenter = Object().toJSBox; // Any non-null value. | ||
browserSupportsImageDecoder = true; | ||
|
||
expect(getCanvasKitJsFileNames(CanvasKitVariant.full), <String>['canvaskit.js']); | ||
|
@@ -1874,7 +1874,7 @@ void _paragraphTests() { | |
}); | ||
|
||
test('in older versions of Chromium-based browsers', () { | ||
v8BreakIterator = Object(); // Any non-null value. | ||
v8BreakIterator = Object().toJSBox; // Any non-null value. | ||
intlSegmenter = null; // Older versions of Chromium didn't have the Intl.Segmenter API. | ||
browserSupportsImageDecoder = true; | ||
|
||
|
@@ -1884,15 +1884,15 @@ void _paragraphTests() { | |
}); | ||
|
||
test('in other browsers', () { | ||
intlSegmenter = Object(); // Any non-null value. | ||
intlSegmenter = Object().toJSBox; // Any non-null value. | ||
|
||
v8BreakIterator = null; | ||
browserSupportsImageDecoder = true; | ||
expect(getCanvasKitJsFileNames(CanvasKitVariant.full), <String>['canvaskit.js']); | ||
expect(getCanvasKitJsFileNames(CanvasKitVariant.chromium), <String>['chromium/canvaskit.js']); | ||
expect(getCanvasKitJsFileNames(CanvasKitVariant.auto), <String>['canvaskit.js']); | ||
|
||
v8BreakIterator = Object(); | ||
v8BreakIterator = Object().toJSBox; | ||
browserSupportsImageDecoder = false; | ||
// TODO(mdebbar): we don't check image codecs for now. | ||
// https://github.com/flutter/flutter/issues/122331 | ||
|
@@ -1935,13 +1935,13 @@ void _paragraphTests() { | |
|
||
|
||
@JS('window.Intl.v8BreakIterator') | ||
external dynamic get v8BreakIterator; | ||
external JSAny? get v8BreakIterator; | ||
|
||
@JS('window.Intl.v8BreakIterator') | ||
external set v8BreakIterator(dynamic x); | ||
external set v8BreakIterator(JSAny? x); | ||
|
||
@JS('window.Intl.Segmenter') | ||
external dynamic get intlSegmenter; | ||
external JSAny? get intlSegmenter; | ||
|
||
@JS('window.Intl.Segmenter') | ||
external set intlSegmenter(dynamic x); | ||
external set intlSegmenter(JSAny? x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this swallowing the parameters passed to the initializeEngine fn from JS?
I suspect this needs to be:
(testing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh dang, you're right. Let me fix that.