Repository navigation
feat(runtime): ns:worker_threads builtin module with typed iOS worker options - #494
edusperoni wants to merge 1 commit into
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 31 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (13)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (13)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe runtime adds the ChangesWorker threads builtin
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant WorkerInit
participant NsWorkerThreadsBinding
participant NsWorkerThreadsModule
participant NodeWorkerThreadsShim
WorkerInit->>NsWorkerThreadsBinding: store and retrieve context Worker constructor
NsWorkerThreadsBinding->>NsWorkerThreadsModule: provide binding.Worker
NsWorkerThreadsModule->>NodeWorkerThreadsShim: export Worker for shim import
Suggested reviewers: Merge Risk: ⚪ Minimal · up to This PR adds the experimental ns:worker_threads module and typed worker options. No concrete defect was found in the supplied context, so it is low risk to merge after the usual iOS build and test run. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 9 files. (4 skipped: 4 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit finds a Worker bright, Comment |
31753d7 to
a858caf
Compare
… options
Adds `ns:worker_threads`, exporting the runtime's own Worker constructor, so
typed code can name the constructor and its iOS options (`ios.priority`,
Node's `resourceLimits`) by specifier instead of through whatever
`globalThis.Worker` resolves to in the program's type environment. The name
pairs with the `node:worker_threads` shim the way `ns:util`/`node:util` and
`ns:module`/`node:module` do, and the shim now takes the constructor from the
module. The binding takes it from the template Worker::Init installed, which
V8 instantiates once per context, so the module hands out the very function
the global was created with even after an app reassigns the global.
types/ns-worker-threads.d.ts declares the module and, at script level,
merges the two options into the global WorkerOptions and declares the global
Worker the way @types/node declares its own globals: a program with a DOM lib
keeps the lib's declaration, so `new Worker(path, { ios })` type-checks
either way without a conflicting redeclaration. Verified with tsc against a
DOM and a non-DOM program.
Experimental, iOS-only until the Android runtime ships the module.
a858caf to
a38ff54
Compare
Stacked on #493 (base branch
fix/worker-terminate-during-entry); only the last commit is this PR.What
A new
ns:worker_threadsbuiltin exporting the runtime's ownWorkerconstructor, plus type declarations for the iOS constructor options that #470 (ios.priority) and #471 (resourceLimits) added but never typed. The name pairs with thenode:worker_threadsshim the wayns:util/node:utilandns:module/node:moduledo, and the shim now takes its constructor from the module instead of readingglobalThis.Worker.Why a module
The options live on the global
Worker, whose type comes from whichever lib a program includes. A specifier gives typed code one fixed place to name the constructor and its options. The binding takes the constructor from the templateWorker::Initinstalled, which V8 instantiates once per context, so the module hands out the very function the global was created with even after an app reassignsglobalThis.Worker.The export set is
Workeronly for now. The channel half (MessageChannel,MessagePort,BroadcastChannel) can join later the wayns:utilgrewTextEncoder; the shim already hands out the global objects for those.Types
types/ns-worker-threads.d.tsdeclares the module (Worker,WorkerOptions,WorkerIosOptions,WorkerResourceLimits,WorkerPriority, and the event shapes a standalone declaration needs). At script level it does what@types/nodedoes for its own globals:WorkerOptions, sonew Worker(path, { ios })on the DOM constructor type-checks;declare var Workeruses thetypeof globalThis extends { onmessage: any; Worker: infer T }probe, so a program with a DOM lib keeps the lib's own declaration (the twodeclare vars agree) and a program without one gets the module's constructor as the global.Verified with
tsc --strictagainst a DOM program and a non-DOM program: the DOM one is clean, including@ts-expect-errorchecks on a bad priority name and a string megabyte count; the non-DOM one reports only the pre-existingURLreferences inns-module.d.ts.Docs and tests
docs/ns-builtin-modules.mdgains the module's reference section (marked experimental, iOS-only until Android ships it), the public-row count, and a correctednode:worker_threadsrow;docs/worker-threads.mdpoints at it from "Worker options".NsWorkerThreadsTests.jspins the frozen export set, identity with the global, the per-realm singleton, distinctness from the shim's module object, construction with both options, and, through a worker fixture that reassignsglobalThis.Workerbefore its firstrequire("ns:worker_threads"), that the module still exports the original constructor.Summary by CodeRabbit
New Features
ns:worker_threadsmodule, exposing the runtime’sWorkerconstructor with support for iOS priority and resource limit options.Documentation
node:worker_threadsbridge.