Skip to content

feat(runtime): add node:vm engine parity and CLI memory semantics coverage#30

Merged
DjDeveloperr merged 4 commits intomainfrom
node-vm-rebased
Apr 20, 2026
Merged

feat(runtime): add node:vm engine parity and CLI memory semantics coverage#30
DjDeveloperr merged 4 commits intomainfrom
node-vm-rebased

Conversation

@DjDeveloperr
Copy link
Copy Markdown
Collaborator

Summary

This PR brings the remaining runtime engine parity work for node:vm onto the current main base and adds a dedicated CLI memory semantics suite for the NativeScript runtime.

It focuses on three areas:

  1. node:vm support and runtime parity across engines
  2. Hermes / JSC / QuickJS runtime and Node-API bridge hardening
  3. CLI memory semantics coverage for Objective-C objects, blocks, pointers, references, and finalizers

What changed

node:vm support

  • adds and hardens the node:vm builtin implementation in the runtime
  • wires builtin module resolution through the module loader
  • adds CLI and runtime tests for vm, including:
    • require("vm")
    • require("node:vm")
    • dynamic import("node:vm")
    • compileFunction
    • Script
    • SourceTextModule
    • SyntheticModule

Engine parity and bridge fixes

  • extends Hermes parity for vm and related runtime behaviors
  • hardens JSC Node-API behavior, including context / wrapper / property handling and test coverage gaps
  • updates QuickJS integration for the new runtime behaviors and builtin loading paths
  • fixes Objective-C bridge and marshalling issues across:
    • objects and class wrappers
    • references and records
    • blocks / closures
    • type conversion and function dispatch
  • improves timer/runtime behavior needed by the cross-engine test suite

Memory semantics CLI suite

Adds a dedicated CLI memory test suite under cli_tests/memory/ covering:

  • weak refs and finalization behavior
  • Objective-C ownership rules
  • Objective-C wrapper finalization
  • block callback finalization / completion safety
  • C function pointer semantics
  • pointer-backed buffer semantics
  • reference lifecycle behavior

This also adds the supporting harnesses and runner scripts needed to execute the memory suite across engines.

Test updates

  • adds TestRunner coverage for vm
  • updates runtime tests that were engine-specific or timing-sensitive
  • improves JSC coverage for version checks and timer cleanup paths
  • updates the macOS test runner script and supporting build/runtime scripts where needed

Validation

Validated on JSC runtime test coverage:

  • macOS: full runtime suite passing
  • iOS: full runtime suite passing

This PR also includes the new CLI memory semantics coverage and the supporting runtime changes required for those tests.

Notes

  • this branch is rebased onto the current origin/main
  • the changes here represent the remaining runtime/engine-parity and memory-suite work that is not yet on main

Implement a NativeScript-backed node:vm builtin and land the runtime fixes
needed to keep both V8 and QuickJS aligned across CommonJS, ESM, and runtime
execution paths.

Node vm support
- add the NativeScript-backed vm runtime module and expose require("vm") /
  require("node:vm") from the internal Node loader
- implement vm.createContext(), vm.isContext(), runInContext(),
  runInNewContext(), runInThisContext(), Script, compileFunction(),
  SourceTextModule, SyntheticModule, measureMemory(), and vm.constants
- preserve caller-provided receivers in vm.compileFunction() while keeping plain
  calls strict so they do not leak the ambient global object into parsing
  contexts

ESM and module loader parity
- add builtin ESM bridges for node:vm in both the V8 and QuickJS loaders so
  dynamic import("node:vm") resolves the same surface as require("node:vm")
- initialize the QuickJS ES module loader during module bootstrap and resolve
  builtin/native modules through virtual module sources with import.meta support
- extend vm CLI coverage to assert compileFunction receiver semantics and
  dynamic import("node:vm") on both engines
- move the dynamic import coverage earlier in the CLI test to avoid a separate
  QuickJS logging quirk triggered after the module-evaluation block

QuickJS runtime and N-API fixes
- preserve exact script length when evaluating strings with embedded NUL bytes
- fix plain-call constructor handling in napi_define_class()
- switch internal wrap/type-tag storage to symbol-backed properties
- fix uint32/uint64 creation paths and string extraction behavior
- retain weakref targets until the host job completes
- normalize QuickJS property access errors to modern message text

Objective-C bridge and marshalling fixes
- thread napi_env through Closure construction
- harden bridge object lifetime/ref management and FunctionReference branding
- add Float16 conversion support and correct metadata encoding for UInt8

URL and web runtime fixes
- fix URL-backed URLSearchParams creation so V8 method dispatch works correctly
- reject invalid fetch inputs via promise rejection and clean up abort listeners

Verification
- macOS CLI vm test on V8: pass
- macOS CLI vm test on QuickJS: pass
- full runtime suites were previously exercised on macOS/iOS for both engines
- integrate prebuilt Hermes artifact downloads into the local build flow and macOS test harness
- switch the Hermes N-API runtime over to the thread-safe runtime path and drain microtasks fully
- harden bridge constructors, pointer/reference handling, closure teardown, timers, URL constructors, and object conversion for Hermes semantics
- add Hermes-compatible node:vm shims, keep compileFunction receiver behavior, and expose node:vm through the builtin ESM bridge
- extend runtime tests for vm import/receiver coverage and relax engine-specific expectations where Hermes lifetime behavior differs but runtime state is verified
Attach struct type encodings directly to generated struct constructors so JSC can resolve record types consistently during reference construction.

Stabilize the timer cleanup coverage by exposing the native active timer count and using that on iOS JSC instead of relying on weak reference collection timing.

Also replace NSString version comparison in VersionDiffTests with engine-agnostic numeric parsing so the coverage path no longer depends on platform-specific compare helpers.
Add the remaining runtime engine work across JSC, QuickJS, and the Objective-C bridge, including the node:vm implementation, builtin module resolution updates, object/class/reference marshalling fixes, and engine-specific Node-API hardening.

Also add the CLI memory semantics suite and harness updates covering weak references, finalization, Objective-C ownership rules, block callbacks, C function pointers, pointer buffers, and reference lifecycle behavior so the runtime’s memory model is exercised from JavaScript.
@DjDeveloperr DjDeveloperr merged commit 2bfb275 into main Apr 20, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant