[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-107608":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":8,"language":10,"languages":8,"totalLinesOfCode":8,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":13,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":12,"compositeScore":18,"rankGlobal":8,"rankLanguage":8,"license":8,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":21,"topics":22,"createdAt":8,"pushedAt":23,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":15,"starSnapshotCount":15,"syncStatus":13,"lastSyncTime":27,"discoverSource":28},107608,"djs","earendil-works\u002Fdjs","earendil-works",null,"https:\u002F\u002Fearendil-works.github.io\u002Fdjs","Rust",359,8,2,1,0,12,196,56.86,false,"main",true,[],"2026-11-23 20:08:29","2026-11-23 08:13:01","# djs\n\ndjs is a small JavaScript and TypeScript engine written in `no_std` Rust. It is built\nmainly for wasm32, where it replaces QuickJS in pi's codemode: model-written scripts that\ncall tools, process their results and print or return data. Its design follows from that\nuse (ARCH.md):\n\n- **All VM state is one byte arena addressed by `u32` offsets**: objects, strings,\n  bytecode, frames, the job queue, pending host calls. Suspending a VM inside a process\n  is free; creating one is a copy of a prebuilt image.\n- **Suspend anywhere.** The interpreter never recurses on the Rust stack for JS calls.\n  It can stop between any two instructions (fuel, a host call) and resume,\n  also inside getters, callbacks of builtins, promise jobs, generators and async\n  functions.\n- **Cheap data passing.** Values go in through a compact wire format and come out through\n  direct reads of the heap from the host, with no serialization step in the VM.\n- **A compiler without an AST** (single pass to stack bytecode, like QuickJS), with\n  TypeScript erased while parsing.\n- **Builtins in a strict TypeScript subset**, compiled to bytecode for the base snapshot\n  and, for the hot ones, to resumable Rust state machines.\n- **Persistence as code**: a run waiting on its tools is written out as a continuation\n  dump, a plain JavaScript program that recreates it, which any later djs (or node)\n  runs (docs\u002Fcontinuation-dumps.md).\n- **Deterministic by construction**: the clock, randomness and weak references come from\n  the host, and the same inputs give byte-identical heap images, natively and in wasm.\n\nThe behavior reference and test oracle is dquickts (a QuickJS fork), including its error\nmessages.\n\n## Status\n\nThe numbers below are generated (`djs-docs regen`, D2101): counts from the repository\n(test262 grouping and ratchets, the corpus) on every merge, measurements from\n`tests\u002Fscores\u002Fstatus.tsv`, which `scripts\u002Fstatus.py` records with the commit they were\nmeasured at (`scripts\u002Fstatus.py` without arguments lists what it measures and how; the\nguide's status page lists every record). Figures inside sentences are generated too\n(inline `n` markers, D3070).\n\n**Conformance.**\n\n\u003C!-- gen:status conformance -->\n- test262 (at dquickts' pinned commit): djs passes **38,069 of the 38,109** tests in the\n  active group (99.9%; 53,597 tests in all, the rest skipped by design). The 40 known\n  failures are listed with reasons in `tests\u002Ftest262\u002Fexpected-failures.txt`; dquickts'\n  qjs fails 4 active tests under the same runner.\n- The differential corpus (codemode scripts, console and result formatting, error\n  messages, TypeScript, dquickts' own tests): **621 of 632** cases match qjs; 6 known\n  failures (`tests\u002Fcorpus\u002Fexpected-failures.txt`) and 5 skipped as non-goals.\n- pi's codemode test suite on djs: 221 of 226 tests pass in the default mode, in the\n  next mode and with a dump at every idle point (measured at 7167411f0f, 2026-11-05).\n\u003C!-- \u002Fgen -->\n\nSkipped by design: Intl, Temporal, SharedArrayBuffer\u002FAtomics, Annex B, sloppy mode,\ndirect eval, modules. Most known failures follow from djs being always strict (TESTING.md\n\"Known differences\"); pi's failures from that, or from tests that expect the quickjs-wasi\nfingerprint.\n\n**Speed in wasm** (node, V8's wasm tier). djs-wasm vs quickjs-wasi (pi's engine), from\n`scripts\u002Fperf\u002Fwmeasure.py`:\n\n\u003C!-- gen:status speed -->\n| workload | djs-wasm | quickjs-wasi | ratio |\n| --- | ---: | ---: | ---: |\n| tight loop | 5.6G | 15.3G | 0.37 |\n| property access (prop1) | 2.2G | 5.4G | 0.41 |\n| strings (split, slice, join, ...) | 2.0G | 5.8G | 0.34 |\n| arrays | 7.7G | 16.3G | 0.47 |\n| JSON round trips | 1.0G | 2.0G | 0.51 |\n| JSON with Dates | 0.8G | 1.7G | 0.46 |\n| for-of | 4.1G | 7.0G | 0.59 |\n| calls | 2.7G | 3.9G | 0.68 |\n| push\u002Fpop and string methods | 3.1G | 2.9G | 1.08 |\n| a pi-like script | 5.1G | 6.9G | 0.73 |\n| forEach | 4.5G | 5.8G | 0.77 |\n| map\u002Ffilter\u002Freduce (higher-order) | 6.3G | 4.5G | 1.40 |\n\nMachine instructions per workload (`scripts\u002Fperf\u002Fw\u002F`), measured at 669ce55099,\n2026-11-05; lower is better.\n\u003C!-- \u002Fgen -->\n\npi's own benchmark (`js\u002Fbench\u002Fpi.bench.ts`, through pi's adapter, `scripts\u002Fstatus.py pi`):\na tool-heavy script with 61 calls takes \u003C!--n pi\u002Fbench\u002Ftool-heavy\u002Fdjs .1-->2.4\u003C!--\u002Fn--> ms on djs (reusing the prelude image)\nvs \u003C!--n pi\u002Fbench\u002Ftool-heavy\u002Fqjs .1-->4.5\u003C!--\u002Fn--> ms on quickjs-wasi, a script start \u003C!--n pi\u002Fbench\u002Fstart\u002Fdjs .2-->0.14\u003C!--\u002Fn--> ms vs \u003C!--n pi\u002Fbench\u002Fstart\u002Fqjs .1-->2.9\u003C!--\u002Fn--> ms (\u003C!--n pi\u002Fbench\u002Fstart\u002Fdjs-prelude .1-->4.9\u003C!--\u002Fn--> ms on djs\nwhen it runs the prelude). Callback-heavy builtin code is the main remaining gap\n(work\u002Fissues\u002F0081-perf-anatomy.md).\n\n**Size and startup.**\n\n\u003C!-- gen:status size -->\n`djs_wasm.wasm` is 953 KB (414 KB gzip, 350 KB brotli): 806 KB of code, 98 KB of data,\nand the base snapshot (the initialized realm with all builtins, 186 KB) coded to 46 KB\nin a custom section. The slim build is 825 KB (349 KB gzip); the dump module, the\nshipped build with the dumper, 1,835 KB (754 KB gzip). Module sizes measured at\n31c4587e31, 2026-11-05.\n\u003C!-- \u002Fgen -->\n\nCreating a VM copies the base snapshot: about \u003C!--n startup\u002Fvm-new-us .1-->2.5\u003C!--\u002Fn--> µs in wasm (D1990). A `Sandbox`\n(instance plus VM) takes about \u003C!--n startup\u002Fsandbox-us .0-->113\u003C!--\u002Fn--> µs, \u003C!--n startup\u002Fsandbox-run-us .0-->142\u003C!--\u002Fn--> µs with its first run\n(`js\u002Fbench\u002Fsandbox.bench.ts`, `scripts\u002Fstatus.py startup`).\n\n## Building and running\n\nRequirements: stable Rust (edition 2024) with the `wasm32-unknown-unknown` target and the\n`rust-src` component (the wasm module builds core and alloc from source), node\n22.6 or newer for the JS host package (it runs TypeScript directly), and, for the\noracle-based tests, dquickts' `qjs` at `~\u002FDevelopment\u002Fdquickts\u002Fqjs` (or `$DJS_QJS`).\n\n```sh\ncargo build                                  # the workspace\ncargo run -p djs-cli -- run file.js          # run a Script (prints console output)\ncargo run -p djs-cli -- run --body file.js   # run a codemode async function body\ncargo run -p djs-cli -- run --ts file.ts     # TypeScript\ncargo run -p djs-cli -- repl                 # REPL with fuel, suspension and heap commands\ncargo run -p djs-cli -- disasm file.js       # bytecode listing\ncargo run -p djs-cli -- strip-types file.ts  # the source with its types blanked\nscripts\u002Fbuild-wasm.sh                        # target\u002Fwasm32-unknown-unknown\u002Fwasm\u002Fdjs_wasm.wasm\n```\n\n`djs run` also takes `--gc-stress`, `--suspend-every N` and `--backend bytecode|native`\n(docs\u002Fcli.md).\n\nFrom JavaScript (`js\u002F`, package `@djs\u002Fhost`, docs\u002Fhost.md):\n\n```ts\nimport { loadModule, Sandbox } from \"@djs\u002Fhost\";\n\nconst sb = await Sandbox.create({\n  asyncFunctions: { search: (q) => mySearch(q as string) },\n  memoryLimit: 64 \u003C\u003C 20,\n  frozenBuiltins: true,                           \u002F\u002F dumps need them (D2836)\n  dumpModule: await loadModule(\"djs-dump.wasm\"),  \u002F\u002F only to persist runs (scripts\u002Fbuild-wasm.sh --dump)\n});\nconst result = await sb.runAsync(\"const hits = await search(q); return hits.length;\", { q: \"djs\" });\nconst run = sb.begin(\"return (await search(q)).length\", { q: \"djs\" });  \u002F\u002F a run the host drives\nconst dump = run.dump();                     \u002F\u002F while it waits: a dump, a plain JavaScript Script\n```\n\n`js\u002Fpi\u002Fvm.ts` implements pi's codemode VM contract (`startVm`) on djs, running pi's\nunmodified prelude (docs\u002Fhost.md \"pi codemode\").\n\n## Testing\n\n```sh\ncargo test                                   # unit and integration tests\nscripts\u002Ffetch-test262.sh                     # once: vendor\u002Ftest262 at the pinned commit\ncargo run --release -p djs-test262 -- run --engine djs --group active \\\n    --expected tests\u002Ftest262\u002Fexpected-failures.txt       # test262 against the ratchet\ncargo run --release -p djs-difftest -- --engine djs --ratchet   # the corpus against qjs\nnode --test js\u002Ftest\u002F*.test.ts                # the JS host package (needs a djs-wasm build)\n```\n\nEverything that runs an engine should run under `scripts\u002Ftimeout.sh`. TESTING.md\nexplains the layers: test262 with skip\u002Flater\u002Factive groups and a ratchet, the\ndifferential corpus in pi's codemode model, and the stress modes (suspension through heap\nimages, GC stress, both builtin backends, heap-image determinism, native versus wasm).\n\n`scripts\u002Fgate.sh` runs everything that must pass before a change reaches `main`;\n`scripts\u002Fmerge-to-main.sh` rebases, regenerates generated files, runs the gate and\nfast-forwards `main` (work\u002FREADME.md). Benchmarks: `scripts\u002Fbench.sh` (engine track and\nsize), `scripts\u002Fperf\u002F` (instruction counts natively and in wasm).\n\n## Layout\n\n```\ncrates\u002Fdjs-core      the engine: lexer, compiler, heap, GC, interpreter, builtins' Rust parts (no_std)\ncrates\u002Fdjs-bgen      the builtin compiler: TS subset -> prelude JS and Rust state machines\ncrates\u002Fdjs-prelude   builds the base snapshot from bgen's output\ncrates\u002Fdjs-wasm      the wasm32 build and its integer ABI\ncrates\u002Fdjs-cli       the `djs` command\ncrates\u002Fdjs-test262   the test262 runner\ncrates\u002Fdjs-difftest  the differential corpus runner\ncrates\u002Fdjs-bench     benchmarks\ncrates\u002Fdjs-docs      the guide's generator and checker (docs\u002Fguide)\nbuiltins\u002F            the builtins in the TypeScript subset (builtins\u002FREADME.md)\njs\u002F                  the host package: Sandbox, wire encoder, heap reader, pi adapter\ntests\u002F               corpus, test262 lists, benchmarks, pi fixtures\nscripts\u002F             gate, merge, build, bench, perf and determinism tools\ndocs\u002F                design notes and the decision log\nwork\u002F                issues, board and process\n```\n\n## Documentation\n\n- **docs\u002Fguide\u002F**: *How djs works*, the guide for humans: the design and its trade-offs,\n  with live examples. `cargo run -p djs-docs -- build` writes the site to\n  `target\u002Fdocs-site\u002F` (live examples need `scripts\u002Fbuild-wasm.sh` first; serve the\n  directory over HTTP for them).\n- **ARCH.md**: the architecture: goals, the arena, values and heap, compiler,\n  interpreter, builtins, host interface, snapshots, and what was planned but replaced.\n- **TESTING.md**: test262, the differential corpus, stress modes, known differences, the\n  gate.\n- **docs\u002Fdecisions.md**: every design decision in order (append-only);\n  **docs\u002Fdecisions-index.md** groups them by topic.\n- **docs\u002Fcompiler.md**: the compiler and bytecode design note.\n- **docs\u002Fobjects.md**: property access, inline caches, shapes and dictionaries.\n- **docs\u002Fhost.md**: the Sandbox API, the wasm ABI, the pi adapter, numbers.\n- **docs\u002Fwire.md**: the inbound wire format and the outbound heap reader.\n- **docs\u002Fcli.md**: the `djs` command and the REPL.\n- **builtins\u002FREADME.md**: the builtin language and its tags.\n- **AGENTS.md** and **work\u002FREADME.md**: how work is organized (issues, worktrees, merging).\n","djs 是一个面向 WebAssembly 场景设计的轻量级 JavaScript\u002FTypeScript 运行时，用 no_std Rust 实现。核心特性包括：基于字节堆的统一内存模型（u32 偏移寻址）、全程非递归解释器（支持任意指令点挂起与恢复）、零序列化数据传递、单遍无 AST 编译器（TypeScript 类型擦除）、内置函数以 TypeScript 子集编写并预编译为字节码或 Rust 状态机，以及将运行中状态持久化为可执行的 JavaScript 续体转储。适用于需高确定性、低开销挂起\u002F恢复、WASM 部署及工具链脚本化（如 pi 的 codemode）的嵌入式 JS 执行场景。","2026-11-24 04:32:24","CREATED_QUERY"]