[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 <kustermann@google.com>
Reviewed-by: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Martin Kustermann
2025-10-28 06:57:54 -07:00
parent 6b4210d9ca
commit 36d9e4e77b
3 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -1860,13 +1860,13 @@ class Translator with KernelNodes {
// runtime.
final i = internalizedStringsForJSRuntime.length;
internalizedString = module.globals.import('s', '$i',
w.GlobalType(w.RefType.extern(nullable: true), mutable: false));
w.GlobalType(w.RefType.extern(nullable: false), mutable: false));
internalizedStringsForJSRuntime.add(s);
} else {
internalizedString = module.globals.import(
'S',
s,
w.GlobalType(w.RefType.extern(nullable: true), mutable: false),
w.GlobalType(w.RefType.extern(nullable: false), mutable: false),
);
}
_internalizedStringGlobals[(module, s)] = internalizedString;
@@ -25,8 +25,8 @@
(field $fun (ref $#Closure-0-1)))))
(type $type256 <...>)
(type $#DummyStruct <...>)
(global $S.globalH1Bar< (import "S" "globalH1Bar<") externref)
(global $S.globalH0Foo (import "S" "globalH0Foo") externref)
(global $S.globalH1Bar< (import "S" "globalH1Bar<") (ref extern))
(global $S.globalH0Foo (import "S" "globalH0Foo") (ref extern))
(global $global29 (ref $#DummyStruct) <...>)
(global $"C28 _InterfaceType" (ref $_InterfaceType) <...>)
(global $"C334 \"h0\"" (ref $JSStringImpl) <...>)
+1 -1
View File
@@ -4,7 +4,7 @@
(type $JSStringImpl (sub final $#Top (struct
(field $field0 i32)
(field $_ref externref))))
(global $"S.hello world" (import "S" "hello world") externref)
(global $"S.hello world" (import "S" "hello world") (ref extern))
(global $"C329 \"hello world\"" (ref $JSStringImpl)
(i32.const 4)
(global.get $"S.hello world")