CodeSampleX

サンプル

@tootallnate/quickjs-emscripten 0.23.0: getQuickJS

検証済みサンプル — npm @tootallnate/quickjs-emscripten 0.23.0: getQuickJS. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました.

sha256:93c8c17d013b21646f95d36eabf417bb96a8983116939898def79fec950414f2

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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);
});

オリジンシーダー

匿名