Skip to content

Commit

Permalink
Fix nullability for string constants
Browse files Browse the repository at this point in the history
  • Loading branch information
eqrion committed May 21, 2024
1 parent f13f076 commit d73f306
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions proposals/js-string-builtins/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ The simplest way is to have a module import each string as an immutable global.

This proposal adds an extension to JS-API compile routine to support optimized 'imported string constants' to address this use-case.

The `WebAssemblyCompileOptions` is extended with a `boolean importedStringConstants` flag. When this is set, the module may define imports of the form `(import "'" "%stringConstant%"" (global externref))`, and the JS-API will use the provided `%stringConstant%` import field name to be the value of the global. This allows for any UTF-8 string to be imported with minimal overhead.
The `WebAssemblyCompileOptions` is extended with a `boolean importedStringConstants` flag. When this is set, the module may import globals of the form `(import "'" "%stringConstant%"" (global ...))`, and the JS-API will use the provided `%stringConstant%` import field name to be the value of the global. This allows for any UTF-8 string to be imported with minimal overhead.

The string namespace is chosen to be the single quote ASCII character `'`. We may revise this to be a longer name before this proposal is finalized.
This works by having the JS-API create a `(global (ref extern))` for each string constant, and provide that as the import value to the module. The [normal import checking for globals](https://webassembly.github.io/gc/core/valid/matching.html#match-globaltype) is performed, which allows for a user to specify either nullable or non-nullable externref, as long as the import global type is immutable. This check is eager, resulting in a compile error if it fails.

All imports that reference this namespace must be globals of type immutable externref. If they are not, an eager compile error is emitted.
The string namespace is chosen to be the single quote ASCII character `'`. This is to reduce binary size impact. We may revise this to be a longer name before this proposal is finalized, if we can mitigate the binary size increase.

## JS String Builtin API

Expand Down

0 comments on commit d73f306

Please sign in to comment.