CodeSampleX

示例

@tootallnate/quickjs-emscripten 0.23.0: getQuickJS

已验证示例 — npm @tootallnate/quickjs-emscripten 0.23.0: getQuickJS. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: getQuickJS returns a Promise that…

sha256:93c8c17d013b21646f95d36eabf417bb96a8983116939898def79fec950414f2

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26

案例

HOW
目标
verify @tootallnate/quickjs-emscripten.getQuickJS in pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0
包
符号
  • @tootallnate/quickjs-emscripten.getQuickJS
环境
node 22.23.2
创建时间
2026-08-26T12:24:18Z

契约

  1. getQuickJS returns a Promise that resolves to a QuickJSWASMModule instance
  2. QuickJSWASMModule.evalCode evaluates JavaScript expressions and returns serialized primitive results
  3. QuickJSWASMModule.newContext creates an isolated execution context capable of evaluating code
  4. QuickJSContext.newFunction exposes host functions callable from within the guest VM
  5. QuickJSContext.evalCode captures syntax and runtime exceptions in guest execution
  6. QuickJSContext and value handles manage WebAssembly memory with explicit dispose
  7. getQuickJS resolves to the same singleton instance on repeated calls

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

下载源代码构件 (tar.gz)

源代码

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify @tootallnate/quickjs-emscripten.getQuickJS in pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0
Demonstrate these symbols/APIs:
  - @tootallnate/quickjs-emscripten.getQuickJS
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:c2c88e135bf7a3946d85c8deaf658cfde01d1c1823d4e3fef286f1dbe0d65c1f","constraints":{"executionContext":"node"},"contract":["getQuickJS returns a Promise that resolves to a QuickJSWASMModule instance","QuickJSWASMModule.evalCode evaluates JavaScript expressions and returns serialized primitive results","QuickJSWASMModule.newContext creates an isolated execution context capable of evaluating code","QuickJSContext.newFunction exposes host functions callable from within the guest VM","QuickJSContext.evalCode captures syntax and runtime exceptions in guest execution","QuickJSContext and value handles manage WebAssembly memory with explicit dispose","getQuickJS resolves to the same singleton instance on repeated calls"],"goal":"verify @tootallnate/quickjs-emscripten.getQuickJS in pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0","kind":"HOW","packages":["pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0"],"schemaVersion":1,"symbols":["@tootallnate/quickjs-emscripten.getQuickJS"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0"],"schemaVersion":1,"subject":"pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0","symbols":["@tootallnate/quickjs-emscripten.getQuickJS"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-quickjs-emscripten-getquickjs",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-quickjs-emscripten-getquickjs",
      "version": "1.0.0",
      "dependencies": {
        "@tootallnate/quickjs-emscripten": "0.23.0"
      }
    },
    "node_modules/@tootallnate/quickjs-emscripten": {
      "version": "0.23.0",
      "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz",
      "integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-quickjs-emscripten-getquickjs",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@tootallnate/quickjs-emscripten": "0.23.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @tootallnate/quickjs-emscripten.getQuickJS in pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0"
  ],
  "symbols": [
    "@tootallnate/quickjs-emscripten.getQuickJS"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert/strict');
const { getQuickJS, getQuickJSSync } = require('@tootallnate/quickjs-emscripten');

async function main() {
  // 1. getQuickJS returns a Promise that resolves to a QuickJSWASMModule instance
  const quickjs = await getQuickJS();
  assert.ok(quickjs);
  assert.equal(typeof quickjs.evalCode, 'function');
  assert.equal(typeof quickjs.newContext, 'function');
  assert.equal(typeof quickjs.newRuntime, 'function');

  // 2. QuickJSWASMModule.evalCode evaluates JavaScript expressions and returns serialized primitive results
  {
    const result = quickjs.evalCode('40 + 2');
    assert.equal(result, 42);

    const stringResult = quickjs.evalCode('`hello ${"world"}`');
    assert.equal(stringResult, 'hello world');

    const objResult = quickjs.evalCode('({ a: 1, b: [2, 3] })');
    assert.deepEqual(objResult, { a: 1, b: [2, 3] });
  }

  // 3. QuickJSWASMModule.newContext creates an isolated execution context capable of evaluating code
  {
    const vm = quickjs.newContext();
    const resultHandle = vm.evalCode('const x = 10; const y = 20; x * y;');
    assert.ok('value' in resultHandle);
    const value = vm.dump(resultHandle.value);
    assert.equal(value, 200);

    resultHandle.value.dispose();
    vm.dispose();
  }

  // 4. QuickJSContext.newFunction exposes host functions callable from within the guest VM
  {
    const vm = quickjs.newContext();
    let hostCalledWith = null;

    const fnHandle = vm.newFunction('sendToHost', (argHandle) => {
      hostCalledWith = vm.dump(argHandle);
      return vm.newNumber(hostCalledWith.length);
    });

    vm.setProp(vm.global, 'sendToHost', fnHandle);
    fnHandle.dispose();

    const callResult = vm.evalCode('sendToHost("codesamplex")');
    assert.ok('value' in callResult);
    const dumpedLen = vm.dump(callResult.value);
    assert.equal(dumpedLen, 11);
    assert.equal(hostCalledWith, 'codesamplex');

    callResult.value.dispose();
    vm.dispose();
  }

  // 5. QuickJSContext.evalCode captures syntax and runtime exceptions in guest execution
  {
    const vm = quickjs.newContext();

    const errResult = vm.evalCode('throw new TypeError("custom error message");');
    assert.ok('error' in errResult);
    const dumpedErr = vm.dump(errResult.error);
    assert.equal(typeof dumpedErr, 'object');
    assert.equal(dumpedErr.name, 'TypeError');
    assert.equal(dumpedErr.message, 'custom error message');

    errResult.error.dispose();
    vm.dispose();
  }

  // 6. QuickJSContext and value handles manage WebAssembly memory with explicit dispose
  {
    const vm = quickjs.newContext();
    const strHandle = vm.newString('disposable string');
    assert.equal(strHandle.alive, true);
    assert.equal(vm.alive, true);

    strHandle.dispose();
    assert.equal(strHandle.alive, false);

    vm.dispose();
    assert.equal(vm.alive, false);
  }

  // 7. getQuickJS resolves to the same singleton instance on repeated calls
  {
    const secondCall = await getQuickJS();
    assert.strictEqual(quickjs, secondCall);

    const syncInstance = getQuickJSSync();
    assert.strictEqual(quickjs, syncInstance);
  }
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});

原始种子者

匿名