pax_global_header00006660000000000000000000000064147301570250014516gustar00rootroot0000000000000052 comment=c6f4b69ab80c495777870f6a5f6a22db16ecaecb es-shims-dunder-proto-ba13098/000077500000000000000000000000001473015702500162175ustar00rootroot00000000000000es-shims-dunder-proto-ba13098/.eslintrc000066400000000000000000000000531473015702500200410ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", } es-shims-dunder-proto-ba13098/.github/000077500000000000000000000000001473015702500175575ustar00rootroot00000000000000es-shims-dunder-proto-ba13098/.github/FUNDING.yml000066400000000000000000000011071473015702500213730ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/dunder-proto community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] es-shims-dunder-proto-ba13098/.github/workflows/000077500000000000000000000000001473015702500216145ustar00rootroot00000000000000es-shims-dunder-proto-ba13098/.github/workflows/node-aught.yml000066400000000000000000000003221473015702500243670ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only es-shims-dunder-proto-ba13098/.github/workflows/node-noproto.yml000066400000000000000000000013751473015702500247700ustar00rootroot00000000000000name: 'Tests: node --disable-proto=throw' on: [pull_request, push] jobs: throw: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 12.17' type: minors skip-ls-check: true after_install: "npm link && npm link dunder-proto" command: "NODE_OPTIONS='--disable-proto=throw' npx tape 'tests/**/*.js'" delete: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 12.17' type: minors skip-ls-check: true after_install: "npm link && npm link dunder-proto" command: "NODE_OPTIONS='--disable-proto=delete' npx tape 'tests/**/*.js'" node: name: 'node --disable-proto' needs: [throw, delete] runs-on: ubuntu-latest steps: - run: true es-shims-dunder-proto-ba13098/.github/workflows/node-pretest.yml000066400000000000000000000002061473015702500247460ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main es-shims-dunder-proto-ba13098/.github/workflows/node-tens.yml000066400000000000000000000003721473015702500242350ustar00rootroot00000000000000name: 'Tests: node.js 10 - 20' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10 < 20' type: minors command: npm run tests-only es-shims-dunder-proto-ba13098/.github/workflows/node-twenties.yml000066400000000000000000000005401473015702500251230ustar00rootroot00000000000000name: 'Tests: node.js >= 20' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 20' type: minors command: npm run tests-only finisher: needs: tests name: 'node >= 20' runs-on: ubuntu-latest steps: - run: true es-shims-dunder-proto-ba13098/.github/workflows/rebase.yml000066400000000000000000000002571473015702500236040ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: uses: ljharb/actions/.github/workflows/rebase.yml@main secrets: token: ${{ secrets.GITHUB_TOKEN }} es-shims-dunder-proto-ba13098/.github/workflows/require-allow-edits.yml000066400000000000000000000003031473015702500262310ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main es-shims-dunder-proto-ba13098/.gitignore000066400000000000000000000041361473015702500202130ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* .pnpm-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage *.lcov # nyc test coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # Snowpack dependency directory (https://snowpack.dev/) web_modules/ # TypeScript cache *.tsbuildinfo # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional stylelint cache .stylelintcache # Microbundle cache .rpt2_cache/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variable files .env .env.development.local .env.test.local .env.production.local .env.local # parcel-bundler cache (https://parceljs.org/) .cache .parcel-cache # Next.js build output .next out # Nuxt.js build / generate output .nuxt dist # Gatsby files .cache/ # Comment in the public line in if your project uses Gatsby and not Next.js # https://nextjs.org/blog/next-9-1#public-directory-support # public # vuepress build output .vuepress/dist # vuepress v2.x temp and cache directory .temp .cache # Docusaurus cache and generated files .docusaurus # Serverless directories .serverless/ # FuseBox cache .fusebox/ # DynamoDB Local files .dynamodb/ # TernJS port file .tern-port # Stores VSCode versions used for testing VSCode extensions .vscode-test # yarn v2 .yarn/cache .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz .pnp.* # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore es-shims-dunder-proto-ba13098/.npmrc000066400000000000000000000000671473015702500173420ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s es-shims-dunder-proto-ba13098/.nycrc000066400000000000000000000003301473015702500173320ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "lines": 86, "statements": 85.93, "functions": 82.43, "branches": 76.06, "exclude": [ "coverage", "test" ] } es-shims-dunder-proto-ba13098/CHANGELOG.md000066400000000000000000000030131473015702500200250ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v1.0.1](https://github.com/es-shims/dunder-proto/compare/v1.0.0...v1.0.1) - 2024-12-16 ### Commits - [Fix] do not crash when `--disable-proto=throw` [`6c367d9`](https://github.com/es-shims/dunder-proto/commit/6c367d919bc1604778689a297bbdbfea65752847) - [Tests] ensure noproto tests only use the current version of dunder-proto [`b02365b`](https://github.com/es-shims/dunder-proto/commit/b02365b9cf889c4a2cac7be0c3cfc90a789af36c) - [Dev Deps] update `@arethetypeswrong/cli`, `@types/tape` [`e3c5c3b`](https://github.com/es-shims/dunder-proto/commit/e3c5c3bd81cf8cef7dff2eca19e558f0e307f666) - [Deps] update `call-bind-apply-helpers` [`19f1da0`](https://github.com/es-shims/dunder-proto/commit/19f1da028b8dd0d05c85bfd8f7eed2819b686450) ## v1.0.0 - 2024-12-06 ### Commits - Initial implementation, tests, readme, types [`a5b74b0`](https://github.com/es-shims/dunder-proto/commit/a5b74b0082f5270cb0905cd9a2e533cee7498373) - Initial commit [`73fb5a3`](https://github.com/es-shims/dunder-proto/commit/73fb5a353b51ac2ab00c9fdeb0114daffd4c07a8) - npm init [`80152dc`](https://github.com/es-shims/dunder-proto/commit/80152dc98155da4eb046d9f67a87ed96e8280a1d) - Only apps should have lockfiles [`03e6660`](https://github.com/es-shims/dunder-proto/commit/03e6660a1d70dc401f3e217a031475ec537243dd) es-shims-dunder-proto-ba13098/LICENSE000066400000000000000000000020611473015702500172230ustar00rootroot00000000000000MIT License Copyright (c) 2024 ECMAScript Shims Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. es-shims-dunder-proto-ba13098/README.md000066400000000000000000000035631473015702500175050ustar00rootroot00000000000000# dunder-proto [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] If available, the `Object.prototype.__proto__` accessor and mutator, call-bound. ## Getting started ```sh npm install --save dunder-proto ``` ## Usage/Examples ```js const assert = require('assert'); const getDunder = require('dunder-proto/get'); const setDunder = require('dunder-proto/set'); const obj = {}; assert.equal('toString' in obj, true); assert.equal(getDunder(obj), Object.prototype); setDunder(obj, null); assert.equal('toString' in obj, false); assert.equal(getDunder(obj), null); ``` ## Tests Clone the repo, `npm install`, and run `npm test` [package-url]: https://npmjs.org/package/dunder-proto [npm-version-svg]: https://versionbadg.es/es-shims/dunder-proto.svg [deps-svg]: https://david-dm.org/es-shims/dunder-proto.svg [deps-url]: https://david-dm.org/es-shims/dunder-proto [dev-deps-svg]: https://david-dm.org/es-shims/dunder-proto/dev-status.svg [dev-deps-url]: https://david-dm.org/es-shims/dunder-proto#info=devDependencies [npm-badge-png]: https://nodei.co/npm/dunder-proto.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/dunder-proto.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/dunder-proto.svg [downloads-url]: https://npm-stat.com/charts.html?package=dunder-proto [codecov-image]: https://codecov.io/gh/es-shims/dunder-proto/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/es-shims/dunder-proto/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/dunder-proto [actions-url]: https://github.com/es-shims/dunder-proto/actions es-shims-dunder-proto-ba13098/get.d.ts000066400000000000000000000001711473015702500175670ustar00rootroot00000000000000declare function getDunderProto(target: {}): object | null; declare const x: false | typeof getDunderProto; export = x;es-shims-dunder-proto-ba13098/get.js000066400000000000000000000017241473015702500173400ustar00rootroot00000000000000'use strict'; var callBind = require('call-bind-apply-helpers'); var gOPD = require('gopd'); var hasProtoAccessor; try { // eslint-disable-next-line no-extra-parens, no-proto hasProtoAccessor = /** @type {{ __proto__?: typeof Array.prototype }} */ ([]).__proto__ === Array.prototype; } catch (e) { if (!e || typeof e !== 'object' || !('code' in e) || e.code !== 'ERR_PROTO_ACCESS') { throw e; } } // eslint-disable-next-line no-extra-parens var desc = !!hasProtoAccessor && gOPD && gOPD(Object.prototype, /** @type {keyof typeof Object.prototype} */ ('__proto__')); var $Object = Object; var $getPrototypeOf = $Object.getPrototypeOf; /** @type {import('./get')} */ module.exports = desc && typeof desc.get === 'function' ? callBind([desc.get]) : typeof $getPrototypeOf === 'function' ? /** @type {import('./get')} */ function getDunder(value) { // eslint-disable-next-line eqeqeq return $getPrototypeOf(value == null ? value : $Object(value)); } : false; es-shims-dunder-proto-ba13098/package.json000066400000000000000000000040741473015702500205120ustar00rootroot00000000000000{ "name": "dunder-proto", "version": "1.0.1", "description": "If available, the `Object.prototype.__proto__` accessor and mutator, call-bound", "main": false, "exports": { "./get": "./get.js", "./set": "./set.js", "./package.json": "./package.json" }, "sideEffects": false, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "prelint": "evalmd README.md", "lint": "eslint --ext=.js,.mjs .", "postlint": "tsc -p . && attw -P", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "npx npm@'>= 10.2' audit --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "repository": { "type": "git", "url": "git+https://github.com/es-shims/dunder-proto.git" }, "author": "Jordan Harband ", "license": "MIT", "bugs": { "url": "https://github.com/es-shims/dunder-proto/issues" }, "homepage": "https://github.com/es-shims/dunder-proto#readme", "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" }, "devDependencies": { "@arethetypeswrong/cli": "^0.17.1", "@ljharb/eslint-config": "^21.1.1", "@ljharb/tsconfig": "^0.2.2", "@types/tape": "^5.7.0", "auto-changelog": "^2.5.0", "encoding": "^0.1.13", "eslint": "=8.8.0", "evalmd": "^0.0.19", "in-publish": "^2.0.1", "npmignore": "^0.3.1", "nyc": "^10.3.2", "safe-publish-latest": "^2.0.0", "tape": "^5.9.0", "typescript": "next" }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "testling": { "files": "test/index.js" }, "publishConfig": { "ignore": [ ".github/workflows" ] }, "engines": { "node": ">= 0.4" } } es-shims-dunder-proto-ba13098/set.d.ts000066400000000000000000000002201473015702500175760ustar00rootroot00000000000000declare function setDunderProto

(target: {}, proto: P): P; declare const x: false | typeof setDunderProto; export = x;es-shims-dunder-proto-ba13098/set.js000066400000000000000000000023741473015702500173560ustar00rootroot00000000000000'use strict'; var callBind = require('call-bind-apply-helpers'); var gOPD = require('gopd'); var $TypeError = require('es-errors/type'); /** @type {{ __proto__?: object | null }} */ var obj = {}; try { obj.__proto__ = null; // eslint-disable-line no-proto } catch (e) { if (!e || typeof e !== 'object' || !('code' in e) || e.code !== 'ERR_PROTO_ACCESS') { throw e; } } var hasProtoMutator = !('toString' in obj); // eslint-disable-next-line no-extra-parens var desc = gOPD && gOPD(Object.prototype, /** @type {keyof typeof Object.prototype} */ ('__proto__')); /** @type {import('./set')} */ module.exports = hasProtoMutator && ( // eslint-disable-next-line no-extra-parens (!!desc && typeof desc.set === 'function' && /** @type {import('./set')} */ (callBind([desc.set]))) || /** @type {import('./set')} */ function setDunder(object, proto) { // this is node v0.10 or older, which doesn't have Object.setPrototypeOf and has undeniable __proto__ if (object == null) { // eslint-disable-line eqeqeq throw new $TypeError('set Object.prototype.__proto__ called on null or undefined'); } // eslint-disable-next-line no-proto, no-param-reassign, no-extra-parens /** @type {{ __proto__?: object | null }} */ (object).__proto__ = proto; return proto; } ); es-shims-dunder-proto-ba13098/test/000077500000000000000000000000001473015702500171765ustar00rootroot00000000000000es-shims-dunder-proto-ba13098/test/get.js000066400000000000000000000021671473015702500203210ustar00rootroot00000000000000'use strict'; var test = require('tape'); var getDunderProto = require('../get'); test('getDunderProto', { skip: !getDunderProto }, function (t) { if (!getDunderProto) { throw 'should never happen; this is just for type narrowing'; // eslint-disable-line no-throw-literal } // @ts-expect-error t['throws'](function () { getDunderProto(); }, TypeError, 'throws if no argument'); // @ts-expect-error t['throws'](function () { getDunderProto(undefined); }, TypeError, 'throws with undefined'); // @ts-expect-error t['throws'](function () { getDunderProto(null); }, TypeError, 'throws with null'); t.equal(getDunderProto({}), Object.prototype); t.equal(getDunderProto([]), Array.prototype); t.equal(getDunderProto(function () {}), Function.prototype); t.equal(getDunderProto(/./g), RegExp.prototype); t.equal(getDunderProto(42), Number.prototype); t.equal(getDunderProto(true), Boolean.prototype); t.equal(getDunderProto('foo'), String.prototype); t.end(); }); test('no dunder proto', { skip: !!getDunderProto }, function (t) { t.notOk('__proto__' in Object.prototype, 'no __proto__ in Object.prototype'); t.end(); }); es-shims-dunder-proto-ba13098/test/index.js000066400000000000000000000000631473015702500206420ustar00rootroot00000000000000'use strict'; require('./get'); require('./set'); es-shims-dunder-proto-ba13098/test/set.js000066400000000000000000000032371473015702500203340ustar00rootroot00000000000000'use strict'; var test = require('tape'); var setDunderProto = require('../set'); test('setDunderProto', { skip: !setDunderProto }, function (t) { if (!setDunderProto) { throw 'should never happen; this is just for type narrowing'; // eslint-disable-line no-throw-literal } // @ts-expect-error t['throws'](function () { setDunderProto(); }, TypeError, 'throws if no arguments'); // @ts-expect-error t['throws'](function () { setDunderProto(undefined); }, TypeError, 'throws with undefined and nothing'); // @ts-expect-error t['throws'](function () { setDunderProto(undefined, undefined); }, TypeError, 'throws with undefined and undefined'); // @ts-expect-error t['throws'](function () { setDunderProto(null); }, TypeError, 'throws with null and undefined'); // @ts-expect-error t['throws'](function () { setDunderProto(null, undefined); }, TypeError, 'throws with null and undefined'); /** @type {{ inherited?: boolean }} */ var obj = {}; t.ok('toString' in obj, 'object initially has toString'); setDunderProto(obj, null); t.notOk('toString' in obj, 'object no longer has toString'); t.notOk('inherited' in obj, 'object lacks inherited property'); setDunderProto(obj, { inherited: true }); t.equal(obj.inherited, true, 'object has inherited property'); t.end(); }); test('no dunder proto', { skip: !!setDunderProto }, function (t) { if ('__proto__' in Object.prototype) { t['throws']( // @ts-expect-error function () { ({}).__proto__ = null; }, // eslint-disable-line no-proto Error, 'throws when setting Object.prototype.__proto__' ); } else { t.notOk('__proto__' in Object.prototype, 'no __proto__ in Object.prototype'); } t.end(); }); es-shims-dunder-proto-ba13098/tsconfig.json000066400000000000000000000001641473015702500207270ustar00rootroot00000000000000{ "extends": "@ljharb/tsconfig", "compilerOptions": { "target": "ES2021", }, "exclude": [ "coverage", ], }