Skip to content

Commit 36d9e4e

Browse files
committed
[dart2wasm] Make string globals non-nullable
Those globals should never be able to old a `null` value. Strictly speaking the `js-string-builtin` spec also says ``` If an import refers to the imported string namespace, then the import type is matched against an extern type of (global (ref extern)) ``` And `ref extern` is non-nullable (compared with `externref` which is shorthand for `ref null extern`) Change-Id: I0e2638fbfeb6d59f740320c7d4167fcff3d793e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457980 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Ömer Ağacan <[email protected]>
1 parent 6b4210d commit 36d9e4e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

pkg/dart2wasm/lib/translator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,13 +1860,13 @@ class Translator with KernelNodes {
18601860
// runtime.
18611861
final i = internalizedStringsForJSRuntime.length;
18621862
internalizedString = module.globals.import('s', '$i',
1863-
w.GlobalType(w.RefType.extern(nullable: true), mutable: false));
1863+
w.GlobalType(w.RefType.extern(nullable: false), mutable: false));
18641864
internalizedStringsForJSRuntime.add(s);
18651865
} else {
18661866
internalizedString = module.globals.import(
18671867
'S',
18681868
s,
1869-
w.GlobalType(w.RefType.extern(nullable: true), mutable: false),
1869+
w.GlobalType(w.RefType.extern(nullable: false), mutable: false),
18701870
);
18711871
}
18721872
_internalizedStringGlobals[(module, s)] = internalizedString;

pkg/dart2wasm/test/ir_tests/deferred.constant.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
(field $fun (ref $#Closure-0-1)))))
2626
(type $type256 <...>)
2727
(type $#DummyStruct <...>)
28-
(global $S.globalH1Bar< (import "S" "globalH1Bar<") externref)
29-
(global $S.globalH0Foo (import "S" "globalH0Foo") externref)
28+
(global $S.globalH1Bar< (import "S" "globalH1Bar<") (ref extern))
29+
(global $S.globalH0Foo (import "S" "globalH0Foo") (ref extern))
3030
(global $global29 (ref $#DummyStruct) <...>)
3131
(global $"C28 _InterfaceType" (ref $_InterfaceType) <...>)
3232
(global $"C334 \"h0\"" (ref $JSStringImpl) <...>)

pkg/dart2wasm/test/ir_tests/hello.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(type $JSStringImpl (sub final $#Top (struct
55
(field $field0 i32)
66
(field $_ref externref))))
7-
(global $"S.hello world" (import "S" "hello world") externref)
7+
(global $"S.hello world" (import "S" "hello world") (ref extern))
88
(global $"C329 \"hello world\"" (ref $JSStringImpl)
99
(i32.const 4)
1010
(global.get $"S.hello world")

0 commit comments

Comments
 (0)