CodeSampleX

サンプル

hasown 2.0.4: hasOwn

検証済みサンプル — npm hasown 2.0.4: hasOwn. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: hasOwn returns true for direct own properties on plain…

sha256:c886ab294bb3afe864b94927cf821cc736b627449a5bc3a9ae3c326afa5e51dd

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22 linux x64 node 22 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-19

ケース

HOW
ゴール
verify pkg:npm/hasown@2.0.4
パッケージ
シンボル
  • hasOwn
環境
node 22
作成日
2026-08-18T17:58:24Z

コントラクト

  1. hasOwn returns true for direct own properties on plain objects including undefined and null values
  2. hasOwn returns false for inherited prototype properties like toString and valueOf
  3. hasOwn returns true for valid array indices and length property while returning false for out of bounds indices and array prototype methods
  4. hasOwn works correctly on objects created with Object.create(null) lacking Object prototype methods
  5. hasOwn correctly identifies properties on objects where hasOwnProperty is shadowed or overridden
  6. hasOwn returns true for properties with falsy values such as false, empty string, and zero
  7. hasOwn supports Symbol properties when Symbol is available in the environment

ファイル

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/hasown@2.0.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/hasown@2.0.4
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@11.8.0
  - runtime: node@24.13.1

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:e872aa68f1629b728f550338c4935085a16e4c372bc9d43b5b985d89f7e22b95","constraints":{"executionContext":"node"},"contract":["hasOwn returns true for direct own properties on plain objects including undefined and null values","hasOwn returns false for inherited prototype properties like toString and valueOf","hasOwn returns true for valid array indices and length property while returning false for out of bounds indices and array prototype methods","hasOwn works correctly on objects created with Object.create(null) lacking Object prototype methods","hasOwn correctly identifies properties on objects where hasOwnProperty is shadowed or overridden","hasOwn returns true for properties with falsy values such as false, empty string, and zero","hasOwn supports Symbol properties when Symbol is available in the environment"],"goal":"verify pkg:npm/hasown@2.0.4","kind":"HOW","packages":["pkg:npm/hasown@2.0.4"],"schemaVersion":1,"symbols":["hasOwn"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"javascript","moduleSystem":"cjs","os":"linux","packageManager":"npm","packageManagerVersion":"10","runtime":"node","runtimeVersion":"22","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/hasown@2.0.4"],"schemaVersion":1,"symbols":["hasOwn"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

var hasOwn = require('hasown');

function checkProperty(object, property) {
  return hasOwn(object, property);
}

module.exports = {
  hasOwn: hasOwn,
  checkProperty: checkProperty
};
package-lock.json
{
  "name": "sample-hasown",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-hasown",
      "version": "1.0.0",
      "dependencies": {
        "hasown": "2.0.4"
      }
    },
    "node_modules/function-bind": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
      "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/hasown": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
      "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
      "license": "MIT",
      "dependencies": {
        "function-bind": "^1.1.2"
      },
      "engines": {
        "node": ">= 0.4"
      }
    }
  }
}
package.json
{
  "name": "sample-hasown",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of hasown package",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "hasown": "2.0.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/hasown@2.0.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/hasown@2.0.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@11.8.0",
    "runtime": "node@24.13.1"
  }
}
test/contract.js
'use strict';

var assert = require('assert');
var sample = require('../index.js');
var hasOwn = sample.hasOwn;

// 1. Direct own properties on plain objects
var obj = { a: 1, b: undefined, nullProp: null };
assert.strictEqual(hasOwn(obj, 'a'), true);
assert.strictEqual(hasOwn(obj, 'b'), true);
assert.strictEqual(hasOwn(obj, 'nullProp'), true);
assert.strictEqual(hasOwn(obj, 'c'), false);

// 2. Inherited properties return false
assert.strictEqual(hasOwn(obj, 'toString'), false);
assert.strictEqual(hasOwn(obj, 'valueOf'), false);
assert.strictEqual(hasOwn(obj, 'hasOwnProperty'), false);

// 3. Array indices and length property
var arr = [10, 20, 30];
assert.strictEqual(hasOwn(arr, 0), true);
assert.strictEqual(hasOwn(arr, '0'), true);
assert.strictEqual(hasOwn(arr, 2), true);
assert.strictEqual(hasOwn(arr, 3), false);
assert.strictEqual(hasOwn(arr, 'length'), true);
assert.strictEqual(hasOwn(arr, 'map'), false);

// 4. Objects created with Object.create(null) (no prototype)
var nullProtoObj = Object.create(null);
nullProtoObj.key = 'value';
assert.strictEqual(hasOwn(nullProtoObj, 'key'), true);
assert.strictEqual(hasOwn(nullProtoObj, 'missing'), false);

// 5. Objects with shadowed / overridden hasOwnProperty
var shadowed = {
  hasOwnProperty: function () {
    return false;
  },
  foo: 'bar'
};
assert.strictEqual(hasOwn(shadowed, 'foo'), true);
assert.strictEqual(hasOwn(shadowed, 'hasOwnProperty'), true);
assert.strictEqual(hasOwn(shadowed, 'nonexistent'), false);

// 6. Object with property having falsy or boolean values
var boolObj = { flag: false, empty: '', zero: 0 };
assert.strictEqual(hasOwn(boolObj, 'flag'), true);
assert.strictEqual(hasOwn(boolObj, 'empty'), true);
assert.strictEqual(hasOwn(boolObj, 'zero'), true);

// 7. Symbol properties
if (typeof Symbol === 'function') {
  var sym = Symbol('test');
  var symObj = {};
  symObj[sym] = 42;
  assert.strictEqual(hasOwn(symObj, sym), true);
}

// 8. Custom wrapper checkProperty
assert.strictEqual(sample.checkProperty(obj, 'a'), true);
assert.strictEqual(sample.checkProperty(obj, 'missing'), false);

console.log('PASS: hasown contract verified');

オリジンシーダー

匿名