Commit Graph

5 Commits

Author SHA1 Message Date
CharlesKWON
efb2ce25c8 test(napi): napi_fuzz PRG — edge probes (large payload, NUL, binary)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 10:14:54 +09:00
CharlesKWON
5f019e76cb feat(napi): error handling — missing member, protected write, type errors
- raiseIfErr traps the JS error sentinel (\x01FNERR:) and raises a catchable
  PRG runtime error instead of handing back undefined/{error} as data.
- __GET__/__SET__ methods: explicit data read/write with existence +
  writability (getter-only/non-writable/non-extensible) checks.
- per-VM lastErr (FN_LASTERROR) so parallel requests don't cross messages.
- capi/napi_errtest.prg exercises the 4 cases via BEGIN SEQUENCE/RECOVER USING.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 09:56:07 +09:00
CharlesKWON
6a8ada16b2 feat(napi): VM pool + per-request isolation for serial/parallel handling
- fnode capi shim: single VM+mutex -> VM pool (FIVENODE_VM_POOL, default 4;
  1=serial, N=parallel). Each request checks out its own VM so PRG runs
  concurrently across libuv worker threads.
- per-request data keyed by VM (FN_NAPI_REQ via ctx.T.VM()) -- no shared
  capiReq race.
- napibridge: per-VM handle tracking; ReleaseAll(vm) auto-ends only that
  request's npm handles (parallel-safe auto-__end__). FN_AWAIT replaces the
  reserved Five AWAIT keyword (Clipper-compat, no gengo codegen -> NIL).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 08:57:31 +09:00
CharlesKWON
959b37e9cd feat(napi P3): PRG -> real Node/npm in-process via N-API object dispatch
hbrtl_ext/napibridge reimplements the C++ fivenode TFNModule in Go: it calls
the addon's registered C callbacks (npmRequire/npmCall/npmMethods/npmEnd) over
cgo. FN_REQUIRE(module) gets a handle, enumerates its methods, and builds a PRG
object whose method closures proxy oObj:method(args) to Node; results decode as
scalar / native array|hash / nested object handle (e.g. Buffer). The capi shim
forwards tfn_register_callbacks -> napibridge.StoreCallbacks. Calls run on the
node main thread (sync handleRequest), so the direct tfn_npm_* path needs no
marshaling.

Verified end-to-end (node -> addon -> Go libfivenode -> PRG):
- builtin: oOs:hostname()/platform()/arch() -> real values; oOs:cpus() -> native
  array, Len()=10.
- real npm: oQR:imageSync() on qr-image (which goja could NOT run) -> Buffer
  handle -> :toString("utf8") -> valid 1138-byte SVG.

Full npm is now reachable in-process. P4 (async/Promise via worker + npmAwait)
remains for async methods like qrcode.toString.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 23:04:04 +09:00
CharlesKWON
ce39c6c8e0 feat(napi P2): fnode capi mode — c-shared libfivenode runs real PRG
`fnode capi <entry.prg> -o libfivenode.dylib` generates all PRG as library
funcs + a cgo shim exporting the N-API C ABI, and builds buildmode=c-shared.
hb_bridge_handle_request stashes the request (read by PRG via FN_NAPI_REQ,
registered with HB_FUNC) and runs the PRG FN_HANDLE via capiVM.Run, returning
its JSON. capiEnsure calls RegisterLibModules so HB_FUNC/--rtl symbols install
into the VM (vm.Run drains libModules but not dynamicFuncs).

Verified: node → addon → Go libfivenode → PRG parses the request and runs
string/hash/JSON ops (Upper/Len/HB_ISHASH/hb_jsonDecode/Encode), round-trips a
200 response. Supersedes the P1 hand-written cmd/libfivenode (removed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 22:54:09 +09:00