Skip to content

Commit 80d3d19

Browse files
authored
[js-api] Editorial improvements (#2126)
* [js-api] Fix Instance constructor variable shadowing |module| was overwritten with its [[Module]] slot before reading [[BuiltinSets]] and [[ImportedStringModule]], which are slots on the JS Module wrapper, not the internal module. * [js-api] Fix If/Else-if for objectkind in ToWebAssemblyValue * [js-api] Fix loop variable shadowing in Tag constructor * [js-api] Fix signed_31 variable in ToWebAssemblyValue i31ref conversion The condition used i31 on both sides of signed_31(), making it a circular tautology. Every other similar conversion in the algorithm uses the unsigned variable (e.g. signed_64(u64)). Change to u31. * [js-api] Fix create a builtin function: missing store and wrong variable name |store| was used without being retrieved first, and |functype| didn't match the parameter name |funcType|. * [js-api] Fix wrong index into maybeBuiltin in validate an import for builtins find a builtin returns (builtinSetName, builtin) where builtin is (name, funcType, steps). The funcType is at maybeBuiltin[1][1], not maybeBuiltin[0][1] which indexes into the string name. * [js-api] Use embedding spec tag_alloc instead of a local definition Remove the js-api's local tag_alloc(store, parameters) and replace all callers with the embedding spec's tag_alloc(store, tagtype), passing an inline functype as the tag type. * [js-api] Use ToJSValue to unwrap JSTag exception payload When re-throwing a JS exception that was caught by WebAssembly, the payload is a list of WebAssembly values from exn_read. For the JSTag, payload[0] is ref.extern (ref.host hostaddr), not a raw host address. Passing it directly to 'retrieving a host value' is wrong since that algorithm expects a host address integer. Use ToJSValue to correctly unwrap the value. * [js-api] Fix missing type argument to ToWebAssemblyValue in intoCharCodeArray ToWebAssemblyValue takes two arguments (value, type). The call was missing the element type. The array type is (array (mut i16)) whose elements are stored as i32. * [js-api] Fix Table.grow to return AddressValue via U64ToAddressValue table_size returns a raw u64. Table.grow's IDL signature returns AddressValue. The length getter and Memory.grow both use U64ToAddressValue for this conversion; Table.grow was missing it. * [js-api] Fix memory.grow hook to use instruction's memory index The hook previously hardcoded memaddrs[0], which is wrong for multi-memory modules where memory.grow x can target any memory index. Use the instruction's immediate x to index memaddrs. * [js-api] Fix memory.grow hook failure check for i64 memories For 64-bit memories, memory.grow pushes i64.const (-1) on failure, not i32.const (-1). The previous check only matched the i32 case, so for a failed i64 grow the hook incorrectly called Refresh the memory buffer, detaching the ArrayBuffer even though the memory size did not change. * [js-api] Fix exception check in call an Exported Function func_invoke returns (store, val* | exception | error) where exception is defined in the core embedding spec as EXCEPTION exnaddr. The check was using [=THROW=] [=ref.exn=] which is undefined notation. Use [=exception=] to match the core embedder spec's type. * [js-api] Read store before func_alloc in create a host function The outer algorithm used |store| in the func_alloc call without ever binding it. The |store| inside the hostfunc closure is a separate binding read at invocation time, not at definition time. * [js-api] Add missing ?/! on ToWebAssemblyValue calls * [js-api] Add missing ! to ToJSValue calls ToJSValue is infallible. Add ! to all call sites that are missing it for consistency with the existing pattern in run a host function and create a builtin function. * [js-api] Include [[ObjectKind]] in MakeBasicObject slot list Per ECMA-262, all internal slots must be declared in the MakeBasicObject call. [[ObjectKind]] was set immediately after but was missing from the initial slot list. * [js-api] Return after rejecting on compile error in asynchronously compile * [js-api] Fix read the imports assert to check qualified builtin set name The map is keyed by qualified names ("wasm:" prefix) but the assert checked for the unqualified name, which was never present and made the assert vacuously true. Compute the qualified name first and assert against that. * [js-api] Use HasProperty instead of map 'contains' for exports object The builtin/string exports object is a plain JS object, not an Infra ordered map. Use HasProperty to check for component name presence. * [js-api, web-api] Editorial fixes - Fix elementType case inconsistency in Table constructor - Fix "Let return" typo in ToJSValue - Fix missing "be" in ToWebAssemblyValue - Fix "fo" typo in instantiate a builtin set - Fix indentation of 'Return handled' in HostResizeArrayBuffer - Fix spurious space in get the JavaScript exception tag links - Fix 'a import' typo in validate builtins display text - Fix 'is' typo in Set [[ArrayBufferMaxByteLength]] step - Update WebIDL URL to webidl.spec.whatwg.org - Use [=/new=] consistently for Tag and Exception object creation - Use 'surrounding agent' consistently instead of 'current agent' - Update TC39 URL to tc39.es/ecma262 - Remove dead and duplicate ECMASCRIPT anchor entries - Fix 'appending' typo in embedding interface URL - Fix tag address pluralization in Tag object cache description - Use [=/new=] for Module object creation in construct a WebAssembly module object - Fix list item numbering in ToJSValue i32 branch - Remove unused 'instantiate a WebAssembly module' anchor - Rename Instance constructor parameter to moduleObject - Fix missing period in Exception constructor
1 parent 8cb8dc9 commit 80d3d19

3 files changed

Lines changed: 71 additions & 77 deletions

File tree

0 commit comments

Comments
 (0)