CodeSampleX

샘플

@tootallnate/quickjs-emscripten 0.23.0

검증된 샘플 — npm @tootallnate/quickjs-emscripten 0.23.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: getQuickJS initializes and resolves a…

sha256:4ad8058f8fb7d8377056b9c118f10439e8130163548fe597dac1a9c025653bf3

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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-23

케이스

HOW
목표
verify pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0
패키지
생성일
2026-08-23T15:54:13Z

컨트랙트

  1. getQuickJS initializes and resolves a QuickJSWASMModule singleton instance
  2. evalCode evaluates Javascript expressions inside QuickJS WASM module and returns native results
  3. newContext creates an isolated QuickJS context capable of executing code and setting global functions
  4. evalCode interrupts execution and throws InternalError when interrupted by shouldInterruptAfterDeadline
  5. getQuickJSSync returns the initialized QuickJSWASMModule synchronously after getQuickJS resolves

파일

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

소스 아티팩트 내려받기 (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 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

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:c547eed3b2d585ee5233c06f1f25c5eb76ddc7f88d896349b2d73d8d92c46201","contract":["getQuickJS initializes and resolves a QuickJSWASMModule singleton instance","evalCode evaluates Javascript expressions inside QuickJS WASM module and returns native results","newContext creates an isolated QuickJS context capable of executing code and setting global functions","evalCode interrupts execution and throws InternalError when interrupted by shouldInterruptAfterDeadline","getQuickJSSync returns the initialized QuickJSWASMModule synchronously after getQuickJS resolves"],"goal":"verify pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0","kind":"HOW","packages":["pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","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","verifierAdapter":"node-typescript@1"}
index.mjs
import {
  getQuickJS,
  getQuickJSSync,
  shouldInterruptAfterDeadline
} from '@tootallnate/quickjs-emscripten';

/**
 * Initializes and retrieves the shared QuickJS WebAssembly module singleton.
 * @returns {Promise<import('@tootallnate/quickjs-emscripten').QuickJSWASMModule>}
 */
export async function getQuickJSInstance() {
  return await getQuickJS();
}

/**
 * Returns the shared QuickJS WebAssembly module singleton synchronously.
 * Note: Must be called after getQuickJS() has resolved at least once.
 * @returns {import('@tootallnate/quickjs-emscripten').QuickJSWASMModule}
 */
export function getQuickJSSyncInstance() {
  return getQuickJSSync();
}

/**
 * Evaluates JavaScript source code in a one-off QuickJS environment and returns the native result.
 * @param {string} code - JavaScript code to evaluate.
 * @param {import('@tootallnate/quickjs-emscripten').ModuleEvalOptions} [options] - Evaluation options.
 * @returns {Promise<unknown>} The evaluated result converted to native JS value.
 */
export async function evaluateExpression(code, options) {
  const QuickJS = await getQuickJS();
  return QuickJS.evalCode(code, options);
}

/**
 * Creates an isolated QuickJS context for advanced object manipulation and function binding.
 * @returns {Promise<import('@tootallnate/quickjs-emscripten').QuickJSContext>}
 */
export async function createIsolatedContext() {
  const QuickJS = await getQuickJS();
  return QuickJS.newContext();
}

/**
 * Evaluates JavaScript code with a strict execution deadline to prevent infinite loops.
 * @param {string} code - JavaScript code to evaluate.
 * @param {number} timeoutMs - Timeout deadline in milliseconds.
 * @returns {Promise<unknown>}
 */
export async function evaluateWithDeadline(code, timeoutMs = 100) {
  const QuickJS = await getQuickJS();
  const deadline = Date.now() + timeoutMs;
  return QuickJS.evalCode(code, {
    shouldInterrupt: shouldInterruptAfterDeadline(deadline)
  });
}

export { getQuickJS, getQuickJSSync, shouldInterruptAfterDeadline };
package-lock.json
{
  "name": "sample-quickjs-emscripten-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-quickjs-emscripten-verify",
      "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-verify",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "@tootallnate/quickjs-emscripten": "0.23.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40tootallnate/quickjs-emscripten@0.23.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  getQuickJS,
  getQuickJSSync,
  shouldInterruptAfterDeadline,
  getQuickJSInstance,
  getQuickJSSyncInstance,
  evaluateExpression,
  createIsolatedContext,
  evaluateWithDeadline
} from '../index.mjs';

// 1. getQuickJS initializes and resolves a QuickJSWASMModule singleton instance
const QuickJS = await getQuickJSInstance();
assert.ok(QuickJS, 'QuickJS module should be defined');
assert.equal(typeof QuickJS.evalCode, 'function', 'QuickJS.evalCode should be a function');
assert.equal(typeof QuickJS.newContext, 'function', 'QuickJS.newContext should be a function');
assert.equal(typeof QuickJS.newRuntime, 'function', 'QuickJS.newRuntime should be a function');

// 2. evalCode evaluates Javascript expressions inside QuickJS WASM module and returns native results
const arithmeticResult = await evaluateExpression('10 + 32');
assert.equal(arithmeticResult, 42, 'arithmetic evaluation should equal 42');

const objectResult = await evaluateExpression('({ message: "hello world", count: 3 })');
assert.deepEqual(objectResult, { message: 'hello world', count: 3 }, 'object evaluation should return matching object');

// 3. newContext creates an isolated QuickJS context capable of executing code and setting global functions
const vm = await createIsolatedContext();
try {
  const multiplyFn = vm.newFunction('multiply', (a, b) => {
    const valA = vm.getNumber(a);
    const valB = vm.getNumber(b);
    return vm.newNumber(valA * valB);
  });
  vm.setProp(vm.global, 'multiply', multiplyFn);
  multiplyFn.dispose();

  const evalHandle = vm.unwrapResult(vm.evalCode('multiply(6, 7)'));
  assert.equal(vm.getNumber(evalHandle), 42, 'custom guest function invocation should return 42');
  evalHandle.dispose();

  // Test error throwing inside VM
  const errResult = vm.evalCode('throw new TypeError("custom failure");');
  assert.ok('error' in errResult, 'evalCode should return an error result when guest throws');
  const dumpedError = vm.dump(errResult.error);
  assert.equal(dumpedError.name, 'TypeError');
  assert.equal(dumpedError.message, 'custom failure');
  errResult.error.dispose();
} finally {
  vm.dispose();
}

// 4. evalCode interrupts execution and throws InternalError when interrupted by shouldInterruptAfterDeadline
let interrupted = false;
try {
  await evaluateWithDeadline('while (true) {}', 50);
} catch (err) {
  interrupted = true;
  assert.equal(err.name, 'InternalError', 'Interrupted execution should throw InternalError');
  assert.equal(err.message, 'interrupted', 'Interrupted error message should be "interrupted"');
}
assert.ok(interrupted, 'Infinite loop execution should be interrupted by deadline');

// 5. getQuickJSSync returns the initialized QuickJSWASMModule synchronously after getQuickJS resolves
const syncModule = getQuickJSSyncInstance();
assert.equal(syncModule, QuickJS, 'getQuickJSSync should return the same singleton as getQuickJS');
const syncEval = syncModule.evalCode('["a", "b"].join("-")');
assert.equal(syncEval, 'a-b', 'syncModule.evalCode should evaluate synchronous expressions');

오리진 시더

익명