CodeSampleX

Пример

@tybys/wasm-util 0.10.2: Memory

Проверенный пример — npm @tybys/wasm-util 0.10.2: Memory. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: Memory constructor initializes…

sha256:8c9d43269a7c53d4247f6b23e22f516d41bb3b47bce0c0313b03440033b0d78d

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-10-13

Кейс

HOW
Цель
verify @tybys/wasm-util.Memory in pkg:npm/%40tybys/wasm-util@0.10.2
Пакеты
Символы
  • @tybys/wasm-util.Memory
Окружение
node 22.23.2
Создан
2026-10-13T03:39:20Z

Контракт

  1. Memory constructor initializes an extended WebAssembly memory with the specified page descriptor
  2. Memory instance inherits from WebAssembly.Memory and provides typed array buffer views
  3. extendMemory attaches Memory prototype and getters to an existing WebAssembly.Memory instance
  4. Typed array views and DataView reflect shared buffer byte mutations across representations
  5. Typed array views remain accessible and dynamically re-reference the buffer after memory growth

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 @tybys/wasm-util.Memory in pkg:npm/%40tybys/wasm-util@0.10.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40tybys/wasm-util@0.10.2
Demonstrate these symbols/APIs:
  - @tybys/wasm-util.Memory

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:7c42c5f4a451d3a2ad5343f4c4846a87f47ece3ccff59d0bbae0a1f52514e47e","contract":["Memory constructor initializes an extended WebAssembly memory with the specified page descriptor","Memory instance inherits from WebAssembly.Memory and provides typed array buffer views","extendMemory attaches Memory prototype and getters to an existing WebAssembly.Memory instance","Typed array views and DataView reflect shared buffer byte mutations across representations","Typed array views remain accessible and dynamically re-reference the buffer after memory growth"],"goal":"verify @tybys/wasm-util.Memory in pkg:npm/%40tybys/wasm-util@0.10.2","kind":"HOW","packages":["pkg:npm/%40tybys/wasm-util@0.10.2"],"schemaVersion":1,"symbols":["@tybys/wasm-util.Memory"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40tybys/wasm-util@0.10.2"],"schemaVersion":1,"subject":"pkg:npm/%40tybys/wasm-util@0.10.2","symbols":["@tybys/wasm-util.Memory"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-tybys-wasm-util",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tybys-wasm-util",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@tybys/wasm-util": "0.10.2"
      }
    },
    "node_modules/@tybys/wasm-util": {
      "version": "0.10.2",
      "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz",
      "integrity": "sha512-RoBvJ2X0wuKlWFIjrwffGw1IqZHKQqzIchKaadZZfnNpsAYp2mM0h36JtPCjNDAHGgYez/15uMBpfGwchhiMgg==",
      "license": "MIT",
      "dependencies": {
        "tslib": "^2.4.0"
      }
    },
    "node_modules/tslib": {
      "version": "2.8.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
      "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "sample-tybys-wasm-util",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "description": "verify @tybys/wasm-util.Memory in pkg:npm/@tybys/wasm-util@0.10.2",
  "main": "src/index.mjs",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@tybys/wasm-util": "0.10.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @tybys/wasm-util.Memory in pkg:npm/%40tybys/wasm-util@0.10.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40tybys/wasm-util@0.10.2"
  ],
  "symbols": [
    "@tybys/wasm-util.Memory"
  ]
}
src/index.mjs
import { Memory, extendMemory } from '@tybys/wasm-util';

export function createMemory(descriptor = { initial: 1 }) {
  return new Memory(descriptor);
}

export function wrapMemory(wasmMemory) {
  return extendMemory(wasmMemory);
}

export function writeUint32(memory, offset, value, littleEndian = true) {
  memory.view.setUint32(offset, value, littleEndian);
}

export function readUint32(memory, offset, littleEndian = true) {
  return memory.view.getUint32(offset, littleEndian);
}

export { Memory, extendMemory };
test/contract.mjs
import assert from 'node:assert';
import {
  Memory,
  extendMemory,
  createMemory,
  wrapMemory,
  writeUint32,
  readUint32
} from '../src/index.mjs';

// 1. Memory constructor initializes an extended WebAssembly memory with the specified page descriptor
const mem = createMemory({ initial: 1, maximum: 2 });
assert(mem instanceof WebAssembly.Memory, 'Memory should be an instance of WebAssembly.Memory');
assert(mem instanceof Memory, 'Memory should be an instance of Memory');
assert.strictEqual(mem.buffer.byteLength, 65536, '1 page should equal 65536 bytes');

// 2. Memory instance inherits from WebAssembly.Memory and provides typed array buffer views
assert(mem.HEAP8 instanceof Int8Array, 'HEAP8 should be Int8Array');
assert(mem.HEAPU8 instanceof Uint8Array, 'HEAPU8 should be Uint8Array');
assert(mem.HEAP16 instanceof Int16Array, 'HEAP16 should be Int16Array');
assert(mem.HEAPU16 instanceof Uint16Array, 'HEAPU16 should be Uint16Array');
assert(mem.HEAP32 instanceof Int32Array, 'HEAP32 should be Int32Array');
assert(mem.HEAPU32 instanceof Uint32Array, 'HEAPU32 should be Uint32Array');
assert(mem.HEAP64 instanceof BigInt64Array, 'HEAP64 should be BigInt64Array');
assert(mem.HEAPU64 instanceof BigUint64Array, 'HEAPU64 should be BigUint64Array');
assert(mem.HEAPF32 instanceof Float32Array, 'HEAPF32 should be Float32Array');
assert(mem.HEAPF64 instanceof Float64Array, 'HEAPF64 should be Float64Array');
assert(mem.view instanceof DataView, 'view should be DataView');

// 3. extendMemory attaches Memory prototype and getters to an existing WebAssembly.Memory instance
const standardMem = new WebAssembly.Memory({ initial: 1 });
assert(!(standardMem instanceof Memory), 'standard WebAssembly.Memory does not inherit from Memory');
const extended = wrapMemory(standardMem);
assert.strictEqual(extended, standardMem, 'wrapMemory returns the same memory reference');
assert(extended instanceof Memory, 'wrapped memory inherits from Memory');
assert(extended.HEAPU8 instanceof Uint8Array, 'extended memory provides HEAPU8');
assert(extended.view instanceof DataView, 'extended memory provides DataView');

// 4. Typed array views and DataView reflect shared buffer byte mutations across representations
writeUint32(mem, 0, 0xdeadbeef, true);
assert.strictEqual(mem.HEAPU8[0], 0xef, 'byte 0 should match least significant byte');
assert.strictEqual(mem.HEAPU8[1], 0xbe, 'byte 1 should match');
assert.strictEqual(mem.HEAPU8[2], 0xad, 'byte 2 should match');
assert.strictEqual(mem.HEAPU8[3], 0xde, 'byte 3 should match most significant byte');
assert.strictEqual(readUint32(mem, 0, true), 0xdeadbeef, 'readUint32 should return written 32-bit value');
assert.strictEqual(mem.HEAP32[0], -559038737, 'HEAP32[0] should match signed 32-bit representation');

// 5. Typed array views remain accessible and dynamically re-reference the buffer after memory growth
assert.strictEqual(mem.grow(1), 1, 'grow should return previous page count');
assert.strictEqual(mem.buffer.byteLength, 131072, 'grown buffer should have 2 pages (131072 bytes)');
assert.strictEqual(mem.HEAPU8.length, 131072, 'HEAPU8 view should dynamically resize with buffer');
assert.strictEqual(readUint32(mem, 0, true), 0xdeadbeef, 'previously written data persists after grow');

console.log('Contract assertions passed.');
process.exit(0);

Исходный сидер

аноним