CodeSampleX

Sample

@babel/runtime 7.29.15: wrap

Verified sample for npm @babel/runtime 7.29.15: wrap. The contract ran on node 22 · linux debian/x64 · docker and passed…

sha256:714cdf4544a27f54dc7800282c66242954c2601df93bc3db652aef349c8084fd

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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-11-22

Case

HOW
Goal
verify @babel/runtime.wrap in pkg:npm/%40babel/runtime@7.29.15
Packages
Symbols
  • @babel/runtime.wrap
Environment
node 22.23.2
Created
2026-11-22T16:21:31Z

Contract

  1. require('@babel/runtime/regenerator').wrap is a function, while bare require('@babel/runtime') throws ERR_PACKAGE_PATH_NOT_EXPORTED because the package has no root export
  2. regeneratorRuntime.wrap(innerFn, outerFn, self) binds `this` to `self`, links the generator prototype to a regeneratorRuntime.mark()-ed `outerFn`, forwards next(arg) values into `_context.sent`, and completes with `_context.abrupt('return', value)`
  3. Calling gen.return(value) terminates the wrapped generator immediately with { value, done: true } and subsequent next() calls return { value: undefined, done: true }
  4. Passing tryLocsList to wrap(innerFn, null, null, [[0, 5]]) catches gen.throw(err) via `_context.catch(0)` and yields a recovery value, whereas uncaught gen.throw(err) propagates and closes the generator
  5. _context.delegateYield(iterable, resultName, nextLoc) yields all elements from the inner iterable before resuming at nextLoc
  6. Re-entrant gen.next() while the wrapped generator is already executing throws TypeError('Generator is already running')
  7. require('@babel/runtime/helpers/regeneratorRuntime')().wrap returns a working generator matching @babel/runtime/regenerator

Files

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

Download the source artifact (tar.gz)

Source

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 @babel/runtime.wrap in pkg:npm/%40babel/runtime@7.29.15
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/runtime@7.29.15
Demonstrate these symbols/APIs:
  - @babel/runtime.wrap
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:4e252c70fe5c5a2952c72d0ebe2b6f92e5f74069a5381aa4f0875edb11abb76c","constraints":{"executionContext":"node"},"contract":["require('@babel/runtime/regenerator').wrap is a function, while bare require('@babel/runtime') throws ERR_PACKAGE_PATH_NOT_EXPORTED because the package has no root export","regeneratorRuntime.wrap(innerFn, outerFn, self) binds `this` to `self`, links the generator prototype to a regeneratorRuntime.mark()-ed `outerFn`, forwards next(arg) values into `_context.sent`, and completes with `_context.abrupt('return', value)`","Calling gen.return(value) terminates the wrapped generator immediately with { value, done: true } and subsequent next() calls return { value: undefined, done: true }","Passing tryLocsList to wrap(innerFn, null, null, [[0, 5]]) catches gen.throw(err) via `_context.catch(0)` and yields a recovery value, whereas uncaught gen.throw(err) propagates and closes the generator","_context.delegateYield(iterable, resultName, nextLoc) yields all elements from the inner iterable before resuming at nextLoc","Re-entrant gen.next() while the wrapped generator is already executing throws TypeError('Generator is already running')","require('@babel/runtime/helpers/regeneratorRuntime')().wrap returns a working generator matching @babel/runtime/regenerator"],"goal":"verify @babel/runtime.wrap in pkg:npm/%40babel/runtime@7.29.15","kind":"HOW","packages":["pkg:npm/%40babel/runtime@7.29.15"],"schemaVersion":1,"symbols":["@babel/runtime.wrap"]},"contractCommand":["node","test/contract.js"],"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/%40babel/runtime@7.29.15"],"schemaVersion":1,"subject":"pkg:npm/%40babel/runtime@7.29.15","symbols":["@babel/runtime.wrap"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "babel-runtime-wrap-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "babel-runtime-wrap-sample",
      "version": "1.0.0",
      "dependencies": {
        "@babel/runtime": "7.29.15"
      }
    },
    "node_modules/@babel/runtime": {
      "version": "7.29.15",
      "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.15.tgz",
      "integrity": "sha512-304gsbbGVmQc+cNGHzwHBlqepYdWLKj3VXCQBGt/EGcV7PUPfKI7kAUNW1FZEOCwlQiLvQjg1JEaAlRQ616h+Q==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    }
  }
}
package.json
{
  "name": "babel-runtime-wrap-sample",
  "version": "1.0.0",
  "private": true,
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@babel/runtime": "7.29.15"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @babel/runtime.wrap in pkg:npm/%40babel/runtime@7.29.15",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/runtime@7.29.15"
  ],
  "symbols": [
    "@babel/runtime.wrap"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
"use strict";

const regeneratorRuntime = require("@babel/runtime/regenerator");

const markedScaled = regeneratorRuntime.mark(function scaledSequence(initial) {
  return regeneratorRuntime.wrap(
    function scaledSequence$(_context) {
      while (1) {
        switch ((_context.prev = _context.next)) {
          case 0:
            _context.next = 2;
            return initial * this.factor;
          case 2:
            _context.next = 4;
            return (initial + _context.sent) * this.factor;
          case 4:
            return _context.abrupt("return", this.label + ":" + _context.sent);
          case 5:
          case "end":
            return _context.stop();
        }
      }
    },
    markedScaled,
    this
  );
});

function createRecoverableGenerator() {
  return regeneratorRuntime.wrap(
    function recoverable$(_context) {
      while (1) {
        switch ((_context.prev = _context.next)) {
          case 0:
            _context.prev = 0;
            _context.next = 3;
            return "ready";
          case 3:
            _context.next = 8;
            break;
          case 5:
            _context.prev = 5;
            _context.t0 = _context.catch(0);
            _context.next = 8;
            return "recovered:" + _context.t0.message;
          case 8:
          case "end":
            return _context.stop();
        }
      }
    },
    null,
    null,
    [[0, 5]]
  );
}

function createDelegatingGenerator(items) {
  return regeneratorRuntime.wrap(function delegating$(_context) {
    while (1) {
      switch ((_context.prev = _context.next)) {
        case 0:
          return _context.delegateYield(items, "t0", 2);
        case 2:
          _context.next = 4;
          return "after";
        case 4:
        case "end":
          return _context.stop();
      }
    }
  });
}

function createReentrantGenerator() {
  let gen;
  gen = regeneratorRuntime.wrap(function reentrant$(_context) {
    while (1) {
      switch ((_context.prev = _context.next)) {
        case 0:
          return gen.next();
        case 1:
        case "end":
          return _context.stop();
      }
    }
  });
  return gen;
}

module.exports = {
  regeneratorRuntime,
  markedScaled,
  createRecoverableGenerator,
  createDelegatingGenerator,
  createReentrantGenerator
};
test/contract.js
"use strict";

const assert = require("node:assert/strict");
const {
  regeneratorRuntime,
  markedScaled,
  createRecoverableGenerator,
  createDelegatingGenerator,
  createReentrantGenerator
} = require("../src/index.js");

// 1. Subpath import exposes wrap; bare package root is not exported in @babel/runtime@7.29.15.
assert.equal(typeof regeneratorRuntime.wrap, "function");
assert.throws(
  () => require("@babel/runtime"),
  (err) => err && err.code === "ERR_PACKAGE_PATH_NOT_EXPORTED"
);

// 2. wrap(innerFn, outerFn, self) binds `this`, links prototype to marked outerFn,
//    passes values via _context.sent, and finishes via _context.abrupt("return", val).
const ctx = { factor: 3, label: "done" };
const gen = markedScaled.call(ctx, 4);
assert.equal(regeneratorRuntime.isGeneratorFunction(markedScaled), true);
assert.equal(gen instanceof markedScaled, true);
assert.equal(Object.prototype.toString.call(gen), "[object Generator]");
assert.equal(gen[Symbol.iterator](), gen);

assert.deepEqual(gen.next(), { value: 12, done: false });
assert.deepEqual(gen.next(6), { value: 30, done: false });
assert.deepEqual(gen.next("ok"), { value: "done:ok", done: true });
assert.deepEqual(gen.next("ignored"), { value: undefined, done: true });

// 3. Early termination via gen.return(val) closes the generator immediately.
const early = markedScaled.call(ctx, 2);
assert.deepEqual(early.next(), { value: 6, done: false });
assert.deepEqual(early.return("stopped"), { value: "stopped", done: true });
assert.deepEqual(early.next(), { value: undefined, done: true });

// 4. wrap with tryLocsList handles gen.throw(err) via _context.catch(tryLoc).
const recoverable = createRecoverableGenerator();
assert.deepEqual(recoverable.next(), { value: "ready", done: false });
assert.deepEqual(recoverable.throw(new Error("boom")), {
  value: "recovered:boom",
  done: false
});
assert.deepEqual(recoverable.next(), { value: undefined, done: true });

// 5. Uncaught gen.throw(err) propagates and terminates the generator.
const uncaught = markedScaled.call(ctx, 1);
assert.deepEqual(uncaught.next(), { value: 3, done: false });
assert.throws(() => uncaught.throw(new Error("fatal")), /fatal/);
assert.deepEqual(uncaught.next(), { value: undefined, done: true });

// 6. _context.delegateYield iterates an inner iterable before continuing.
const delegated = createDelegatingGenerator(["a", "b"]);
assert.deepEqual(Array.from(delegated), ["a", "b", "after"]);

// 7. Re-entrant next() while running throws TypeError("Generator is already running").
const reentrant = createReentrantGenerator();
assert.throws(() => reentrant.next(), {
  name: "TypeError",
  message: "Generator is already running"
});

// 8. helpers/regeneratorRuntime() exposes an equivalent wrap function.
const helperRuntime = require("@babel/runtime/helpers/regeneratorRuntime")();
assert.equal(typeof helperRuntime.wrap, "function");
const helperGen = helperRuntime.wrap(function (_context) {
  while (1) {
    switch ((_context.prev = _context.next)) {
      case 0:
        _context.next = 2;
        return 42;
      case 2:
      case "end":
        return _context.stop();
    }
  }
});
assert.deepEqual(helperGen.next(), { value: 42, done: false });
assert.deepEqual(helperGen.next(), { value: undefined, done: true });

Origin Seeder

anonymous