CodeSampleX

示例

globalthis 1.0.4: getPolyfill

已验证示例 — npm globalthis 1.0.4: getPolyfill. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: globalthis.getPolyfill returns a function conforming to the…

sha256:fc0689bf9501836522e712fd2c56880bb0ce1ff49a8da2d76d4322b189460247

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
3
构建过它的签名密钥
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 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-04
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-04
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-04

案例

HOW
目标
verify globalthis.getPolyfill in pkg:npm/globalthis@1.0.4
包
符号
  • globalthis.getPolyfill
环境
node 22.23.2
创建时间
2026-09-04T01:06:23Z

契约

  1. globalthis.getPolyfill returns a function conforming to the es-shim specification
  2. globalthis.getPolyfill returns the runtime global object containing standard ECMAScript globals
  3. globalthis.getPolyfill returns the identical global reference across multiple calls
  4. globalthis.getPolyfill resolves to globalThis in modern ECMAScript environments
  5. globalthis/polyfill subpath exports the identical getPolyfill implementation function

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 globalthis.getPolyfill 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.getPolyfill

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:86f50528dbbce5029dccb2c904dfe058fcbd0283ea678d5b8f1c7e275f4b5cd4","contract":["globalthis.getPolyfill returns a function conforming to the es-shim specification","globalthis.getPolyfill returns the runtime global object containing standard ECMAScript globals","globalthis.getPolyfill returns the identical global reference across multiple calls","globalthis.getPolyfill resolves to globalThis in modern ECMAScript environments","globalthis/polyfill subpath exports the identical getPolyfill implementation function"],"goal":"verify globalthis.getPolyfill in pkg:npm/globalthis@1.0.4","kind":"HOW","packages":["pkg:npm/globalthis@1.0.4"],"schemaVersion":1,"symbols":["globalthis.getPolyfill"]},"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/globalthis@1.0.4"],"schemaVersion":1,"subject":"pkg:npm/globalthis@1.0.4","symbols":["globalthis.getPolyfill"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-globalthis-getpolyfill",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-globalthis-getpolyfill",
      "version": "1.0.0",
      "license": "MIT-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-getpolyfill",
  "version": "1.0.0",
  "private": true,
  "description": "verify globalthis.getPolyfill in pkg:npm/globalthis@1.0.4",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "globalthis": "1.0.4"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify globalthis.getPolyfill in pkg:npm/globalthis@1.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/globalthis@1.0.4"
  ],
  "symbols": [
    "globalthis.getPolyfill"
  ]
}
src/index.js
'use strict';

const globalThisPkg = require('globalthis');

/**
 * Returns the getPolyfill implementation function from the globalthis package.
 * @returns {Function}
 */
function getPolyfillFunction() {
  return globalThisPkg.getPolyfill;
}

/**
 * Invokes getPolyfill to resolve and return the environment's global object.
 * @returns {object} The resolved global object.
 */
function resolveGlobalObject() {
  const polyfillFn = globalThisPkg.getPolyfill();
  return polyfillFn;
}

/**
 * Checks whether getPolyfill returns the native globalThis in current environment.
 * @returns {boolean} True if polyfill matches native globalThis.
 */
function isNativeGlobalThis() {
  return globalThisPkg.getPolyfill() === globalThis;
}

/**
 * Retrieves a property from the global object resolved via getPolyfill.
 * @param {string} key
 * @returns {*}
 */
function getGlobalProperty(key) {
  const globalObj = globalThisPkg.getPolyfill();
  return globalObj[key];
}

module.exports = {
  getPolyfillFunction,
  resolveGlobalObject,
  isNativeGlobalThis,
  getGlobalProperty,
  globalThisPkg
};
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const globalThisPkg = require('globalthis');
const subpathPolyfill = require('globalthis/polyfill');
const {
  getPolyfillFunction,
  resolveGlobalObject,
  isNativeGlobalThis,
  getGlobalProperty
} = require('../src/index.js');

async function testContract() {
  // 1. globalthis.getPolyfill returns a function conforming to the es-shim specification
  assert.equal(typeof globalThisPkg.getPolyfill, 'function', 'getPolyfill must be a function');
  assert.equal(typeof getPolyfillFunction(), 'function', 'helper must return getPolyfill function');
  assert.strictEqual(getPolyfillFunction(), globalThisPkg.getPolyfill, 'helper getPolyfill matches package export');

  // 2. globalthis.getPolyfill returns the runtime global object containing standard ECMAScript globals
  const resolved = globalThisPkg.getPolyfill();
  assert.equal(typeof resolved, 'object', 'getPolyfill result must be an object');
  assert.notEqual(resolved, null, 'getPolyfill result must not be null');
  assert.strictEqual(resolved.Array, Array, 'global object must contain Array');
  assert.strictEqual(resolved.Object, Object, 'global object must contain Object');
  assert.strictEqual(resolved.Math, Math, 'global object must contain Math');
  assert.strictEqual(resolved.JSON, JSON, 'global object must contain JSON');
  assert.strictEqual(resolved.Promise, Promise, 'global object must contain Promise');

  // 3. globalthis.getPolyfill returns the identical global reference across multiple calls
  const secondCall = globalThisPkg.getPolyfill();
  assert.strictEqual(secondCall, resolved, 'repeated calls to getPolyfill must return the identical global reference');
  assert.strictEqual(resolveGlobalObject(), resolved, 'helper resolveGlobalObject must return the identical global reference');

  // 4. globalthis.getPolyfill resolves to globalThis in modern ECMAScript environments
  assert.strictEqual(resolved, globalThis, 'getPolyfill must resolve to globalThis');
  assert.strictEqual(isNativeGlobalThis(), true, 'isNativeGlobalThis helper must report true');
  assert.strictEqual(getGlobalProperty('Math'), Math, 'getGlobalProperty must access global properties correctly');

  // 5. globalthis/polyfill subpath exports the identical getPolyfill implementation function
  assert.strictEqual(typeof subpathPolyfill, 'function', 'subpath export must be a function');
  assert.strictEqual(subpathPolyfill, globalThisPkg.getPolyfill, 'subpath export must match globalthis.getPolyfill');
  assert.strictEqual(subpathPolyfill(), resolved, 'calling subpath export must return the same global reference');

  console.log('Contract assertions verified successfully.');
}

testContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

原始种子者

匿名