Skip to content

Commit 8c89088

Browse files
osa1Commit Queue
authored andcommitted
[dart2wasm] Return null in void typed interop functions
Instead of boxing the return values just return `null`. Also drop the result type from the imports when the return type is `void`. Change-Id: I871717480e516ac4cec260b2f9f4abe3dd5df535 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424742 Commit-Queue: Ömer Ağacan <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent b573667 commit 8c89088

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pkg/dart2wasm/lib/js/interop_specializer.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ abstract class _Specializer {
100100
'dart2wasm.$jsMethodName',
101101
FunctionNode(null,
102102
positionalParameters: dartPositionalParameters,
103-
returnType: _util.nullableWasmExternRefType),
103+
returnType: function.returnType is VoidType
104+
? VoidType()
105+
: _util.nullableWasmExternRefType),
104106
fileUri,
105107
AnnotationType.import,
106108
isExternal: true);

pkg/dart2wasm/lib/js/util.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,17 @@ class CoreTypesUtil {
326326
Expression castInvocationForReturn(
327327
Expression invocation, DartType returnType) {
328328
Expression expression;
329-
if (returnType is VoidType || isJSValueType(returnType)) {
329+
if (returnType is VoidType) {
330330
// Technically a `void` return value can still be used, by casting the
331331
// return type to `dynamic` or `Object?`. However this case should be
332-
// extremely rare, and `dartifyRaw` overhead for return values that will
332+
// extremely rare, and `dartifyRaw` overhead for return values that should
333333
// never be used in practice is too much, so we avoid `dartifyRaw` on
334-
// `void` returns. We still box the `externref` as the value can be passed
335-
// around as a Dart object.
334+
// `void` returns and always return `null`.
335+
return BlockExpression(
336+
Block([ExpressionStatement(invocation)]), NullLiteral());
337+
}
336338

339+
if (isJSValueType(returnType)) {
337340
// TODO(joshualitt): Expose boxed `JSNull` and `JSUndefined` to Dart
338341
// code after migrating existing users of js interop on Dart2Wasm.
339342
// expression = _createJSValue(invocation);

0 commit comments

Comments
 (0)