CodeSampleX

샘플

globalthis 1.0.4: globalThis

검증된 샘플 — npm globalthis 1.0.4: globalThis. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: getGlobalObject returns the runtime global object…

sha256:5917220d598439bf3e151a97e4b618e5cf1dc5d9cc688674a3f49487d315c07c

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

케이스

HOW
목표
verify globalThis in pkg:npm/globalthis@1.0.4
패키지
심벌
  • globalThis
환경
node 22.23.2
생성일
2026-09-02T07:36:27Z

컨트랙트

  1. getGlobalObject returns the runtime global object containing ECMAScript built-in globals
  2. getGlobalObject returns the same reference as runtime globalThis
  3. getPolyfill returns polyfill implementation for globalThis
  4. shimGlobalThis installs globalThis property on global object and returns global reference
  5. hasGlobalProperty checks existence of global built-ins and returns false for nonexistent keys
  6. setGlobalProperty writes and getGlobalProperty reads custom values on global scope
  7. deleteGlobalProperty removes custom properties from global scope
  8. globalthis exports fallback implementation object

파일

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

소스 아티팩트 내려받기 (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 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
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:4fb8da08df30713e87cf45b51b765eba5ec790be2653da9e04e58c212b2c28f7","constraints":{"executionContext":"node"},"contract":["getGlobalObject returns the runtime global object containing ECMAScript built-in globals","getGlobalObject returns the same reference as runtime globalThis","getPolyfill returns polyfill implementation for globalThis","shimGlobalThis installs globalThis property on global object and returns global reference","hasGlobalProperty checks existence of global built-ins and returns false for nonexistent keys","setGlobalProperty writes and getGlobalProperty reads custom values on global scope","deleteGlobalProperty removes custom properties from global scope","globalthis exports fallback implementation object"],"goal":"verify globalThis in pkg:npm/globalthis@1.0.4","kind":"HOW","packages":["pkg:npm/globalthis@1.0.4"],"schemaVersion":1,"symbols":["globalThis"]},"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/globalthis@1.0.4"],"schemaVersion":1,"subject":"pkg:npm/globalthis@1.0.4","symbols":["globalThis"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-globalthis",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-globalthis",
      "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",
  "version": "1.0.0",
  "private": true,
  "main": "src/index.js",
  "dependencies": {
    "globalthis": "1.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify globalThis in pkg:npm/globalthis@1.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/globalthis@1.0.4"
  ],
  "symbols": [
    "globalThis"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const globalThisPolyfill = require('globalthis');

/**
 * Returns the environment's global object.
 * @returns {object} The global object.
 */
function getGlobalObject() {
  return globalThisPolyfill();
}

/**
 * Returns the polyfill implementation for globalThis.
 * @returns {object} The resolved global object or polyfill implementation.
 */
function getPolyfill() {
  return globalThisPolyfill.getPolyfill();
}

/**
 * Shims globalThis onto the global object and returns the global reference.
 * @returns {object} The global object with globalThis guaranteed.
 */
function shimGlobalThis() {
  return globalThisPolyfill.shim();
}

/**
 * Checks if a property exists on the global object.
 * @param {string|symbol} key - Property key to check.
 * @returns {boolean} True if present.
 */
function hasGlobalProperty(key) {
  const globalObj = globalThisPolyfill();
  return Object.prototype.hasOwnProperty.call(globalObj, key) || key in globalObj;
}

/**
 * Reads a property value from the global scope.
 * @param {string|symbol} key - Property key to retrieve.
 * @returns {*} The property value.
 */
function getGlobalProperty(key) {
  const globalObj = globalThisPolyfill();
  return globalObj[key];
}

/**
 * Sets a property on the global scope.
 * @param {string|symbol} key - Property key.
 * @param {*} value - Value to set.
 * @returns {*} The set value.
 */
function setGlobalProperty(key, value) {
  const globalObj = globalThisPolyfill();
  globalObj[key] = value;
  return value;
}

/**
 * Deletes a property from the global scope.
 * @param {string|symbol} key - Property key to delete.
 * @returns {boolean} True if deleted successfully.
 */
function deleteGlobalProperty(key) {
  const globalObj = globalThisPolyfill();
  return delete globalObj[key];
}

module.exports = {
  getGlobalObject,
  getPolyfill,
  shimGlobalThis,
  hasGlobalProperty,
  getGlobalProperty,
  setGlobalProperty,
  deleteGlobalProperty,
};
test/contract.js
const assert = require('node:assert/strict');
const {
  getGlobalObject,
  getPolyfill,
  shimGlobalThis,
  hasGlobalProperty,
  getGlobalProperty,
  setGlobalProperty,
  deleteGlobalProperty,
} = require('../src/index.js');
const globalThisPolyfill = require('globalthis');

async function main() {
  // 1. getGlobalObject returns the runtime global object containing ECMAScript built-in globals
  const globalObj = getGlobalObject();
  assert.equal(typeof globalObj, 'object');
  assert.notEqual(globalObj, null);
  assert.equal(globalObj.Array, Array);
  assert.equal(globalObj.Object, Object);
  assert.equal(globalObj.Math, Math);
  assert.equal(globalObj.JSON, JSON);
  assert.equal(globalObj.Promise, Promise);

  // 2. getGlobalObject returns the same reference as runtime globalThis
  assert.equal(globalObj, globalThis);

  // 3. getPolyfill returns polyfill implementation for globalThis
  const polyfill = getPolyfill();
  assert.equal(typeof polyfill, 'object');
  assert.equal(polyfill.Array, Array);
  assert.equal(polyfill.Math, Math);

  // 4. shimGlobalThis installs globalThis property on global object and returns global reference
  const shimmed = shimGlobalThis();
  assert.equal(shimmed, globalObj);
  assert.equal(shimmed.globalThis, shimmed);

  // 5. hasGlobalProperty checks existence of global built-ins and returns false for nonexistent keys
  assert.equal(hasGlobalProperty('Array'), true);
  assert.equal(hasGlobalProperty('Math'), true);
  assert.equal(hasGlobalProperty('__csx_nonexistent_prop_xyz__'), false);

  // 6. setGlobalProperty writes and getGlobalProperty reads custom values on global scope
  const testKey = '__csx_sample_globalthis_prop__';
  const testValue = { sample: 'verified', active: true };
  setGlobalProperty(testKey, testValue);
  assert.equal(hasGlobalProperty(testKey), true);
  assert.deepEqual(getGlobalProperty(testKey), testValue);

  // 7. deleteGlobalProperty removes custom properties from global scope
  const deleted = deleteGlobalProperty(testKey);
  assert.equal(deleted, true);
  assert.equal(hasGlobalProperty(testKey), false);
  assert.equal(getGlobalProperty(testKey), undefined);

  // 8. globalthis exports fallback implementation object
  assert.equal(typeof globalThisPolyfill.implementation, 'object');
  assert.notEqual(globalThisPolyfill.implementation, null);

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

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

오리진 시더

익명