fix(wasm): #1034 missing Date imports + #1035 __classDispatch arg padding#1039
Merged
Conversation
…ding #1034: `wasm_runtime.js` declared `date_get_day` as a WASM import (and `emit.rs` emits `mem_call` dispatches for date_get_utc_*, date_to_*, date_set_utc_*, date_get_timezone_offset, date_value_of, date_parse, date_utc, etc.) but the JS side defined only the basic-getter subset. `Date.prototype.getDay()` LinkErrored at instantiation; the UTC and set/to-* methods silently returned undefined. Added the missing `rt.date_get_day` entry plus the full mem_call dispatch surface. #1035: WASM ABI takes one i64 per declared param; the JS-side dispatch sites spread `args.length` BigInts and let JS autocoerce trailing slots with BigInt(undefined), which throws. Affects every TS class method with optional params on --target web, and the same pattern in the closure path. Added a `__padBigintArgs(fn, prefix, bigintArgs)` helper that pads to `fn.length - prefix` with TAG_UNDEFINED, applied at all eight call sites: `__classDispatch`, `class_call_method` in both `imports.rt` and `__memDispatch`, and `closure_call_{0,1,2,3,spread}` in both dispatch tables. #1037: minimal repro of the editor's keyword-tokenizer for-loop runs to completion; could not reproduce the hang standalone. Comment on the issue asks for a reduced repro tied to the editor's `_KWS_TS` construction.
…I docs)
Three pre-existing CI failures inherited from rebasing onto current main:
- **lint (cargo fmt)**: 11 files had drift across the workspace. Ran `cargo fmt` over the workspace.
- **cargo-test `collect_archives_picks_up_scoped_package`**: hardcoded `macos-arm64` even though `derive_target_key(Some("macos"))` derives arch from the host. Linux x86_64 CI runner produced `macos-x86_64`. Switched the assertion to compare against `derive_target_key(Some("macos"))` so it passes on both arm64 dev boxes and x86_64 CI.
- **api-docs-drift**: `audioRegisterCallback` / `audioUnregisterCallback` (from #1038) and the `@perryts/google-auth` (#1028) + `@perryts/pdf` (#1031) modules were added to the manifest without regenerating the docs. Ran `./scripts/regen_api_docs.sh`.
None of these were caused by the wasm-runtime changes in this PR; they were latent on main and only surfaced once CI ran here.
Three more pre-existing failures inherited from main, all observed on #1038's pre-merge CI run with the exact same signatures: - **cargo-test (perry-ui-test::test_web)**: the Web FFI parity test enforces every Stub/Supported feature in the matrix has a JS impl in web_runtime.js. 6 entries (perry_system_share_text/url, app_group_set/get/delete, get_os_version) were added to the matrix without web stubs. Added thin stubs: navigator.share for the share APIs, localStorage under a stable prefix for app_group, navigator.userAgent for the OS-version probe. - **compile-smoke (3 new fails)**: test_take_screenshot needs libperry_ui_gtk4.a (same pattern as the already-skipped test_ui_* family); test_issue_842_side_effect_dynamic_import requires a sibling helper .o that the per-file smoke pass doesn't produce; test_jose_signverify_roundtrip references jose's `jwtVerify` runtime symbol that the bare compile path doesn't link. Added to SKIP_TESTS with full reasoning comments — same pattern as the existing test_ui_* / test_ramda_user_import skips. - **parity (4 NEW failures not in known_failures.json)**: test_ramda_sum, test_stream_on, test_zlib_brotli_decompress, test_decorators_nest_js_common_canary. Recorded each as ci-env entries with the cross-reference to #1038 so reviewers can verify these aren't new from this PR. None of these are caused by the wasm-runtime changes in this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rt.date_get_daymissing → LinkError on any Date.prototype.getDay() reachable build #1034 —Date.prototype.getDay()on--target webLinkErrored at instantiation becausert.date_get_daywas declared in the WASM import struct but never defined in the JS import object. Audit found ~30 additional Date methods (emit_memcallfordate_get_utc_*,date_to_*,date_set_utc_*,date_get_timezone_offset,date_value_of,date_parse,date_utc, …) routed through the unifiedmem_callbridge but missing from__memDispatch— these wouldn't LinkError (onlymem_callis named) but would silently returnundefined. Added all of them.__classDispatchdoesn't pad missing args →BigInt(undefined)throw for any TS optional parameter #1035 — TS class methods with optional params threwTypeError: Cannot convert undefined to a BigIntwhenever the caller omitted a param: the WASM ABI takes one i64 per declared slot, andargs.map(__jsValueToBits)produces too few BigInts, so JS auto-coerces trailingundefinedviaBigInt(undefined)at the call site and throws. Added a__padBigintArgs(fn, prefix, bigintArgs)helper and applied it at all eight class- and closure-dispatch sites (the three__classDispatch/class_call_methodpaths plusclosure_call_{0,1,2,3,spread}in both dispatch tables).object_get_dynamicrepeats indefinitely with identical args after keyword tokenizer enters its outer loop #1037 — could not reproduce the keyword-tokenizer hang in isolation; minimalfor (let ki = 0; ki < kws.length; ki++)over the same offset array runs cleanly on--target web. Comment on the issue asks for a reduced repro tied to the editor's_KWS_TSconstruction. The minimal test did surface a separate latent INT32_TAG decode gap intoJsValue(not the same bug as wasm runtime: post-parse hang —object_get_dynamicrepeats indefinitely with identical args after keyword tokenizer enters its outer loop #1037) — not filed here.Test plan
cargo build --release -p perry-runtime -p perry-stdlib -p perry -p perry-ui-macos— clean.rt.date_get_daymissing → LinkError on any Date.prototype.getDay() reachable build #1034 (const d = new Date(...); console.log(d.getDay())) compiles + instantiates on--target web— no more LinkError.__classDispatchdoesn't pad missing args →BigInt(undefined)throw for any TS optional parameter #1035 (class T { parse(b: string, r?: number[]) { ... } }; new T().parse('hello')) returns the expected value — before fix this threwCannot convert undefined to a BigInt.object_get_dynamicrepeats indefinitely with identical args after keyword tokenizer enters its outer loop #1037-style for-loop runs to completion (does not hang).