CodeSampleX

Пример

globalthis 1.0.4: shim

Проверенный пример — npm globalthis 1.0.4: shim. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден: globalthis.shim is a function exported…

sha256:4f28908a89f37abfb2fd3b4328ba7eb8b3e043dafa2c64baa3c35938e2e0bcc8

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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-09-03

Кейс

HOW
Цель
verify globalthis.shim in pkg:npm/globalthis@1.0.4
Пакеты
Символы
  • globalthis.shim
Окружение
node 22.23.2
Создан
2026-09-03T14:14:36Z

Контракт

  1. globalthis.shim is a function exported by the globalthis package
  2. globalthis.shim returns the global object
  3. globalthis.shim installs globalThis on the global object when called
  4. globalthis.shim defines globalThis with configurable and writable property descriptor but non-enumerable
  5. globalthis.shim is idempotent and returns the same global object on repeated invocations
  6. globalthis default export getGlobal returns the polyfilled global object matching shim

Файлы

  • 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 globalthis.shim in pkg:npm/globalthis@1.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/globalthis@1.0.4
Demonstrate these symbols/APIs:
  - globalthis.shim

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:913f22f9ee173fbbf1db53c02972005d40a42fa7db45955ad703a52f47e44ba9","contract":["globalthis.shim is a function exported by the globalthis package","globalthis.shim returns the global object","globalthis.shim installs globalThis on the global object when called","globalthis.shim defines globalThis with configurable and writable property descriptor but non-enumerable","globalthis.shim is idempotent and returns the same global object on repeated invocations","globalthis default export getGlobal returns the polyfilled global object matching shim"],"goal":"verify globalthis.shim in pkg:npm/globalthis@1.0.4","kind":"HOW","packages":["pkg:npm/globalthis@1.0.4"],"schemaVersion":1,"symbols":["globalthis.shim"]},"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/globalthis@1.0.4"],"schemaVersion":1,"subject":"pkg:npm/globalthis@1.0.4","symbols":["globalthis.shim"],"verifierAdapter":"node-typescript@1"}
index.mjs
import getGlobal from 'globalthis';

/**
 * Returns the global object polyfilled by globalthis.
 *
 * @returns {object} The global object
 */
export function getGlobalObject() {
  return getGlobal();
}

/**
 * Shims globalThis onto the global environment and returns the global object.
 *
 * @returns {object} The shimmed global object
 */
export function shimGlobalThis() {
  return getGlobal.shim();
}

/**
 * Direct reference to the shim function.
 */
export const shim = getGlobal.shim;

export { getGlobal };
export default getGlobal;
package-lock.json
{
  "name": "sample-globalthis-shim-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-globalthis-shim-verify",
      "version": "1.0.0",
      "dependencies": {
        "globalthis": "1.0.4"
      }
    },
    "node_modules/define-data-property": {
      "version": "1.1.4",
      "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz",
      "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==",
      "license": "MIT",
      "dependencies": {
        "es-define-property": "^1.0.0",
        "es-errors": "^1.3.0",
        "gopd": "^1.0.1"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/define-properties": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz",
      "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==",
      "license": "MIT",
      "dependencies": {
        "define-data-property": "^1.0.1",
        "has-property-descriptors": "^1.0.0",
        "object-keys": "^1.1.1"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/es-define-property": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
      "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/es-errors": {
      "version": "1.3.0",
      "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
      "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    },
    "node_modules/globalthis": {
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz",
      "integrity": "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ==",
      "license": "MIT",
      "dependencies": {
        "define-properties": "^1.2.1",
        "gopd": "^1.0.1"
      },
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/gopd": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
      "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/has-property-descriptors": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
      "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==",
      "license": "MIT",
      "dependencies": {
        "es-define-property": "^1.0.0"
      },
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/object-keys": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
      "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.4"
      }
    }
  }
}
package.json
{
  "name": "sample-globalthis-shim-verify",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "globalthis": "1.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify globalthis.shim in pkg:npm/globalthis@1.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/globalthis@1.0.4"
  ],
  "symbols": [
    "globalthis.shim"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import getGlobal, { shim, shimGlobalThis, getGlobalObject } from '../index.mjs';

// 1. globalthis.shim is a function exported by the globalthis package
{
  assert.strictEqual(typeof shim, 'function');
  assert.strictEqual(typeof getGlobal.shim, 'function');
  assert.strictEqual(typeof shimGlobalThis, 'function');
}

// 2. globalthis.shim returns the global object
{
  const result = shim();
  assert.strictEqual(typeof result, 'object');
  assert.ok(result !== null);
  assert.strictEqual(result.Array, Array);
  assert.strictEqual(result.Object, Object);
  assert.strictEqual(result.Math, Math);
}

// 3. globalthis.shim installs globalThis on the global object when called
{
  const result = shim();
  assert.strictEqual(result.globalThis, result);
  assert.strictEqual(globalThis, result);
}

// 4. globalthis.shim defines globalThis with configurable and writable property descriptor but non-enumerable
{
  const target = shim();
  const desc = Object.getOwnPropertyDescriptor(target, 'globalThis');
  assert.ok(desc, 'descriptor should exist');
  assert.strictEqual(desc.configurable, true);
  assert.strictEqual(desc.writable, true);
  assert.strictEqual(desc.enumerable, false);
}

// 5. globalthis.shim is idempotent and returns the same global object on repeated invocations
{
  const first = shim();
  const second = shim();
  const third = shimGlobalThis();
  assert.strictEqual(first, second);
  assert.strictEqual(second, third);
  assert.strictEqual(globalThis, first);
}

// 6. globalthis default export getGlobal returns the polyfilled global object matching shim
{
  const polyfill = getGlobal();
  const fromShim = shim();
  const fromHelper = getGlobalObject();
  assert.strictEqual(polyfill, fromShim);
  assert.strictEqual(polyfill, fromHelper);
  assert.strictEqual(polyfill.globalThis, polyfill);
}

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

аноним