├── .editorconfig ├── .eslintrc ├── .github └── workflows │ ├── node-aught.yml │ ├── node-pretest.yml │ ├── node-tens.yml │ ├── rebase.yml │ └── require-allow-edits.yml ├── .gitignore ├── .npmrc ├── .nycrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── auto.js ├── implementation.js ├── index.js ├── package.json ├── polyfill.js ├── shim.js └── test ├── implementation.js ├── index.js ├── shimmed.js └── tests.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab; 5 | insert_final_newline = true; 6 | quote_type = auto; 7 | space_after_anonymous_functions = true; 8 | space_after_control_statements = true; 9 | spaces_around_operators = true; 10 | trim_trailing_whitespace = true; 11 | spaces_in_brackets = false; 12 | end_of_line = lf; 13 | 14 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "@ljharb", 5 | 6 | "rules": { 7 | "id-length": [2, { "min": 1, "max": 30 }], 8 | "new-cap": [2, { 9 | "capIsNewExceptions": [ 10 | "CreateDataProperty", 11 | "IsCallable", 12 | "RequireObjectCoercible", 13 | "ToObject", 14 | ] 15 | }], 16 | }, 17 | 18 | "overrides": [ 19 | { 20 | "files": "test/**", 21 | "rules": { 22 | "max-lines-per-function": 0, 23 | "no-invalid-this": 1 24 | }, 25 | }, 26 | ], 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/node-aught.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js < 10' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '< 10' 10 | type: minors 11 | command: npm run tests-only 12 | -------------------------------------------------------------------------------- /.github/workflows/node-pretest.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: pretest/posttest' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/pretest.yml@main 8 | -------------------------------------------------------------------------------- /.github/workflows/node-tens.yml: -------------------------------------------------------------------------------- 1 | name: 'Tests: node.js >= 10' 2 | 3 | on: [pull_request, push] 4 | 5 | jobs: 6 | tests: 7 | uses: ljharb/actions/.github/workflows/node.yml@main 8 | with: 9 | range: '>= 10' 10 | type: minors 11 | command: npm run tests-only 12 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | name: Automatic Rebase 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | uses: ljharb/actions/.github/workflows/rebase.yml@main 8 | secrets: 9 | token: ${{ secrets.GITHUB_TOKEN }} 10 | -------------------------------------------------------------------------------- /.github/workflows/require-allow-edits.yml: -------------------------------------------------------------------------------- 1 | name: Require “Allow Edits” 2 | 3 | on: [pull_request_target] 4 | 5 | jobs: 6 | _: 7 | name: "Require “Allow Edits”" 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: ljharb/require-allow-edits@main 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage/ 15 | .nyc_output/ 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # Compiled binary addons (http://nodejs.org/api/addons.html) 21 | build/Release 22 | 23 | # Dependency directory 24 | # Commenting this out is preferred by some people, see 25 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 26 | node_modules 27 | 28 | # Users Environment Variables 29 | .lock-wscript 30 | 31 | # Only apps should have lockfiles 32 | npm-shrinkwrap.json 33 | package-lock.json 34 | yarn.lock 35 | 36 | .npmignore 37 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | allow-same-version=true 3 | message=v%s 4 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "all": true, 3 | "check-coverage": false, 4 | "reporter": ["text-summary", "text", "html", "json"], 5 | "exclude": [ 6 | "coverage", 7 | "test" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | ## [v2.1.8](https://github.com/ljharb/Object.getOwnPropertyDescriptors/compare/v2.1.7...v2.1.8) - 2024-03-19 9 | 10 | ### Commits 11 | 12 | - [actions] remove redundant finisher [`72e367f`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/72e367f708417284e465acb722ccaa0cff615a32) 13 | - [Refactor] use `es-object-atoms` where possible [`a403fd2`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/a403fd2d4651586309b3a31a31010ca74fa5aa47) 14 | - [Deps] update `call-bind`, `define-properties`, `es-abstract`, `safe-array-concat` [`fe4f40d`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/fe4f40d06ad1b877b1dd5aecb2e61c6d1c155c21) 15 | - [Refactor] use `gopd` [`a2d1344`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/a2d1344271aa98bd9aa5771ea8847605628bcf6e) 16 | - [Dev Deps] update `aud`, `mock-property`, `npmignore`, `tape` [`1852646`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/18526463da3df02dbc688e6897ab262245f85d99) 17 | 18 | ## [v2.1.7](https://github.com/ljharb/Object.getOwnPropertyDescriptors/compare/v2.1.6...v2.1.7) - 2023-08-31 19 | 20 | ### Commits 21 | 22 | - [Deps] update `array.prototype.reduce`, `es-abstract` [`a201ad2`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/a201ad21768bbd199c122fc8b51ded6667b07573) 23 | - [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `tape` [`f174ab1`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/f174ab14b2a816abac871d10747b1fcff179f0d8) 24 | 25 | ## [v2.1.6](https://github.com/ljharb/Object.getOwnPropertyDescriptors/compare/v2.1.5...v2.1.6) - 2023-04-20 26 | 27 | ### Commits 28 | 29 | - [Refactor] use `safe-array-concat` [`a717eb2`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/a717eb21bacdc01eaa17092fe93dd21e0c1ef320) 30 | - [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `tape` [`b08d70f`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/b08d70f9387aad6341d44d9216ffa36023973a66) 31 | - [Deps] update `define-properties`, `es-abstract` [`95c8479`](https://github.com/ljharb/Object.getOwnPropertyDescriptors/commit/95c84794c2a78bc78c8c5f540db150c30fe9aea2) 32 | 33 | 34 | 35 | 2.1.4 / 2022-05-19 36 | ================= 37 | * [Fix] `Array.prototype.reduce` isn’t present in ES3 engines 38 | * [meta] use `npmignore` to autogenerate an npmignore file 39 | * [Deps] update `define-properties`, `es-abstract` 40 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `auto-changelog`, `functions-have-names`, `safe-publish-latest`, `tape` 41 | * [Tests] use `mock-property` 42 | * [actions] reuse common workflows 43 | * [actions] update codecov uploader 44 | 45 | 2.1.3 / 2021-10-03 46 | ================= 47 | * [readme] remove travis badge; add actions and codecov badges 48 | * [Deps] update `es-abstract` 49 | * [meta] use `prepublishOnly` script for npm 7+ 50 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `tape` 51 | * [actions] update workflows 52 | * [actions] use `node/install` instead of `node/run`; use `codecov` action 53 | 54 | 2.1.2 / 2021-02-20 55 | ================= 56 | * [Deps] update `call-bind`, `es-abstract` 57 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `functions-have-names`, `has-strict-mode`, `tape` 58 | * [meta] do not publish github action workflow files 59 | * [meta] gitignore coverage output 60 | * [actions] update workflows 61 | 62 | 2.1.1 / 2020-11-26 63 | ================= 64 | * [Fix] do not mutate the native function when present 65 | * [Deps] update `es-abstract`; use `call-bind` where applicable 66 | * [meta] remove unused Makefile and associated utilities 67 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `functions-have-names`; add `aud` 68 | * [actions] add Require Allow Edits workflow 69 | * [actions] switch Automatic Rebase workflow to `pull_request_target` event 70 | * [Tests] migrate tests to Github Actions 71 | * [Tests] run `nyc` on all tests 72 | * [Tests] add `implementation` test; run `es-shim-api` in postlint; use `tape` runner 73 | * [Tests] only audit prod deps 74 | 75 | 2.1.0 / 2019-12-12 76 | ================= 77 | * [New] add auto entry point 78 | * [Refactor] use split-up `es-abstract` (78% bundle size decrease) 79 | * [readme] fix repo URLs, remove testling 80 | * [Docs] Fix formatting in the README (#30) 81 | * [Deps] update `define-properties`, `es-abstract` 82 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `functions-have-names`, `covert`, `replace`, `semver`, `tape`, `@es-shims/api`; add `safe-publish-latest` 83 | * [meta] add `funding` field 84 | * [meta] Only apps should have lockfiles. 85 | * [Tests] use shared travis-ci configs 86 | * [Tests] use `functions-have-names` 87 | * [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops 88 | * [Tests] remove `jscs` 89 | * [actions] add automatic rebasing / merge commit blocking 90 | 91 | 2.0.3 / 2016-07-26 92 | ================= 93 | * [Fix] Update implementation to not return `undefined` descriptors 94 | * [Deps] update `es-abstract` 95 | * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `jscs`, `nsp`, `tape`, `semver` 96 | * [Dev Deps] remove unused eccheck script + dep 97 | * [Tests] up to `node` `v6.3`, `v5.12`, `v4.4` 98 | * [Tests] use pretest/posttest for linting/security 99 | * Update to stage 4 100 | 101 | 2.0.2 / 2016-01-27 102 | ================= 103 | * [Fix] ensure that `Object.getOwnPropertyDescriptors` does not fail when `Object.prototype` has a poisoned setter (#1, #2) 104 | 105 | 2.0.1 / 2016-01-27 106 | ================= 107 | * [Deps] move `@es-shims/api` to dev deps 108 | 109 | 2.0.0 / 2016-01-27 110 | ================= 111 | * [Breaking] implement the es-shims API 112 | * [Deps] update `define-properties`, `es-abstract` 113 | * [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`, `semver` 114 | * [Tests] fix npm upgrades in older nodes 115 | * [Tests] up to `node` `v5.5` 116 | * [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG 117 | 118 | 1.0.4 / 2015-07-20 119 | ================= 120 | * [Tests] Test on `io.js` `v2.4` 121 | * [Deps, Dev Deps] Update `define-properties`, `tape`, `eslint`, `semver` 122 | 123 | 1.0.3 / 2015-06-28 124 | ================= 125 | * Increase robustness by caching `Array#{concat, reduce}` 126 | * [Deps] Update `define_properties` 127 | * [Dev Deps] Update `eslint`, `semver`, `nsp` 128 | * [Tests] Test up to `io.js` `v2.3` 129 | 130 | 1.0.2 / 2015-05-23 131 | ================= 132 | * Update `es-abstract`, `tape`, `eslint`, `jscs`, `semver`, `covert` 133 | * Test up to `io.js` `v2.0` 134 | 135 | 1.0.1 / 2015-03-20 136 | ================= 137 | * Update `es-abstract`, `editorconfig-tools`, `nsp`, `eslint`, `semver`, `replace` 138 | 139 | 1.0.0 / 2015-02-17 140 | ================= 141 | * v1.0.0 142 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jordan Harband 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # object.getownpropertydescriptors [![Version Badge][npm-version-svg]][package-url] 2 | 3 | [![github actions][actions-image]][actions-url] 4 | [![coverage][codecov-image]][codecov-url] 5 | [![dependency status][deps-svg]][deps-url] 6 | [![dev dependency status][dev-deps-svg]][dev-deps-url] 7 | [![License][license-image]][license-url] 8 | [![Downloads][downloads-image]][downloads-url] 9 | 10 | [![npm badge][npm-badge-png]][package-url] 11 | 12 | An ES2017 spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5. 13 | Invoke its "shim" method to shim `Object.getOwnPropertyDescriptors` if it is unavailable, and if `Object.getOwnPropertyDescriptor` is available. 14 | 15 | This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://github.com/tc39/ecma262/pull/582). 16 | 17 | ## Example 18 | 19 | ```js 20 | var getDescriptors = require('object.getownpropertydescriptors'); 21 | var assert = require('assert'); 22 | var obj = { normal: Infinity }; 23 | var enumDescriptor = { 24 | enumerable: false, 25 | writable: false, 26 | configurable: true, 27 | value: true 28 | }; 29 | var writableDescriptor = { 30 | enumerable: true, 31 | writable: true, 32 | configurable: true, 33 | value: 42 34 | }; 35 | var symbol = Symbol(); 36 | var symDescriptor = { 37 | enumerable: true, 38 | writable: true, 39 | configurable: false, 40 | value: [symbol] 41 | }; 42 | 43 | Object.defineProperty(obj, 'enumerable', enumDescriptor); 44 | Object.defineProperty(obj, 'writable', writableDescriptor); 45 | Object.defineProperty(obj, 'symbol', symDescriptor); 46 | 47 | var descriptors = getDescriptors(obj); 48 | 49 | assert.deepEqual(descriptors, { 50 | normal: { 51 | enumerable: true, 52 | writable: true, 53 | configurable: true, 54 | value: Infinity 55 | }, 56 | enumerable: enumDescriptor, 57 | writable: writableDescriptor, 58 | symbol: symDescriptor 59 | }); 60 | ``` 61 | 62 | ```js 63 | var getDescriptors = require('object.getownpropertydescriptors'); 64 | var assert = require('assert'); 65 | /* when Object.getOwnPropertyDescriptors is not present */ 66 | delete Object.getOwnPropertyDescriptors; 67 | var shimmedDescriptors = getDescriptors.shim(); 68 | assert.equal(shimmedDescriptors, getDescriptors); 69 | assert.deepEqual(shimmedDescriptors(obj), getDescriptors(obj)); 70 | ``` 71 | 72 | ```js 73 | var getDescriptors = require('object.getownpropertydescriptors'); 74 | var assert = require('assert'); 75 | /* when Object.getOwnPropertyDescriptors is present */ 76 | var shimmedDescriptors = getDescriptors.shim(); 77 | assert.notEqual(shimmedDescriptors, getDescriptors); 78 | assert.deepEqual(shimmedDescriptors(obj), getDescriptors(obj)); 79 | ``` 80 | 81 | ## Tests 82 | Simply clone the repo, `npm install`, and run `npm test` 83 | 84 | [package-url]: https://npmjs.org/package/object.getownpropertydescriptors 85 | [npm-version-svg]: http://versionbadg.es/es-shims/Object.getOwnPropertyDescriptors.svg 86 | [travis-svg]: https://travis-ci.org/es-shims/Object.getOwnPropertyDescriptors.svg 87 | [travis-url]: https://travis-ci.org/es-shims/Object.getOwnPropertyDescriptors 88 | [deps-svg]: https://david-dm.org/es-shims/Object.getOwnPropertyDescriptors.svg 89 | [deps-url]: https://david-dm.org/es-shims/Object.getOwnPropertyDescriptors 90 | [dev-deps-svg]: https://david-dm.org/es-shims/Object.getOwnPropertyDescriptors/dev-status.svg 91 | [dev-deps-url]: https://david-dm.org/es-shims/Object.getOwnPropertyDescriptors#info=devDependencies 92 | [npm-badge-png]: https://nodei.co/npm/object.getownpropertydescriptors.png?downloads=true&stars=true 93 | [license-image]: http://img.shields.io/npm/l/object.getownpropertydescriptors.svg 94 | [license-url]: LICENSE 95 | [downloads-image]: http://img.shields.io/npm/dm/object.getownpropertydescriptors.svg 96 | [downloads-url]: http://npm-stat.com/charts.html?package=object.getownpropertydescriptors 97 | [codecov-image]: https://codecov.io/gh/es-shims/Object.getOwnPropertyDescriptors/branch/main/graphs/badge.svg 98 | [codecov-url]: https://app.codecov.io/gh/es-shims/Object.getOwnPropertyDescriptors/ 99 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Object.getOwnPropertyDescriptors 100 | [actions-url]: https://github.com/es-shims/Object.getOwnPropertyDescriptors/actions 101 | -------------------------------------------------------------------------------- /auto.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('./shim')(); 4 | -------------------------------------------------------------------------------- /implementation.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var CreateDataProperty = require('es-abstract/2024/CreateDataProperty'); 4 | var RequireObjectCoercible = require('es-object-atoms/RequireObjectCoercible'); 5 | var ToObject = require('es-object-atoms/ToObject'); 6 | var safeConcat = require('safe-array-concat'); 7 | var reduce = require('array.prototype.reduce'); 8 | var gOPD = require('gopd'); 9 | var $Object = require('es-object-atoms'); 10 | 11 | var $getOwnNames = $Object.getOwnPropertyNames; 12 | var $getSymbols = $Object.getOwnPropertySymbols; 13 | 14 | var getAll = $getSymbols ? function (obj) { 15 | return safeConcat($getOwnNames(obj), $getSymbols(obj)); 16 | } : $getOwnNames; 17 | 18 | var isES5 = gOPD && typeof $getOwnNames === 'function'; 19 | 20 | module.exports = function getOwnPropertyDescriptors(value) { 21 | RequireObjectCoercible(value); 22 | if (!isES5) { 23 | throw new TypeError('getOwnPropertyDescriptors requires Object.getOwnPropertyDescriptor'); 24 | } 25 | 26 | var O = ToObject(value); 27 | return reduce( 28 | getAll(O), 29 | function (acc, key) { 30 | var descriptor = gOPD(O, key); 31 | if (typeof descriptor !== 'undefined') { 32 | CreateDataProperty(acc, key, descriptor); 33 | } 34 | return acc; 35 | }, 36 | {} 37 | ); 38 | }; 39 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var define = require('define-properties'); 4 | var callBind = require('call-bind'); 5 | 6 | var implementation = require('./implementation'); 7 | var getPolyfill = require('./polyfill'); 8 | var shim = require('./shim'); 9 | 10 | var bound = callBind(getPolyfill(), Object); 11 | 12 | define(bound, { 13 | getPolyfill: getPolyfill, 14 | implementation: implementation, 15 | shim: shim 16 | }); 17 | 18 | module.exports = bound; 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "object.getownpropertydescriptors", 3 | "version": "2.1.8", 4 | "author": "Jordan Harband ", 5 | "funding": { 6 | "url": "https://github.com/sponsors/ljharb" 7 | }, 8 | "description": "ES2017 spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5.", 9 | "license": "MIT", 10 | "main": "index.js", 11 | "scripts": { 12 | "prepack": "npmignore --auto --commentLines=autogenerated", 13 | "prepublish": "not-in-publish || npm run prepublishOnly", 14 | "prepublishOnly": "safe-publish-latest", 15 | "pretest": "npm run --silent lint", 16 | "test": "npm run --silent tests-only", 17 | "posttest": "aud --production", 18 | "tests-only": "nyc tape 'test/**/*.js'", 19 | "lint": "eslint --ext=js,mjs .", 20 | "postlint": "es-shim-api --bound", 21 | "version": "auto-changelog && git add CHANGELOG.md", 22 | "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git://github.com/es-shims/object.getownpropertydescriptors.git" 27 | }, 28 | "keywords": [ 29 | "Object.getOwnPropertyDescriptors", 30 | "descriptor", 31 | "property descriptor", 32 | "ES8", 33 | "ES2017", 34 | "shim", 35 | "polyfill", 36 | "getOwnPropertyDescriptor", 37 | "es-shim API" 38 | ], 39 | "dependencies": { 40 | "array.prototype.reduce": "^1.0.6", 41 | "call-bind": "^1.0.7", 42 | "define-properties": "^1.2.1", 43 | "es-abstract": "^1.23.2", 44 | "es-object-atoms": "^1.0.0", 45 | "gopd": "^1.0.1", 46 | "safe-array-concat": "^1.1.2" 47 | }, 48 | "devDependencies": { 49 | "@es-shims/api": "^2.4.2", 50 | "@ljharb/eslint-config": "^21.1.0", 51 | "aud": "^2.0.4", 52 | "auto-changelog": "^2.4.0", 53 | "eslint": "=8.8.0", 54 | "functions-have-names": "^1.2.3", 55 | "has-strict-mode": "^1.0.1", 56 | "in-publish": "^2.0.1", 57 | "mock-property": "^1.0.3", 58 | "npmignore": "^0.3.1", 59 | "nyc": "^10.3.2", 60 | "safe-publish-latest": "^2.0.0", 61 | "tape": "^5.7.5" 62 | }, 63 | "testling": { 64 | "files": [ 65 | "test/index.js", 66 | "test/shimmed.js" 67 | ], 68 | "browsers": [ 69 | "iexplore/9.0..latest", 70 | "firefox/4.0..6.0", 71 | "firefox/15.0..latest", 72 | "firefox/nightly", 73 | "chrome/5.0..10.0", 74 | "chrome/20.0..latest", 75 | "chrome/canary", 76 | "opera/12.0..latest", 77 | "opera/next", 78 | "safari/5.0..latest", 79 | "ipad/6.0..latest", 80 | "iphone/6.0..latest", 81 | "android-browser/4.2" 82 | ] 83 | }, 84 | "engines": { 85 | "node": ">= 0.8" 86 | }, 87 | "auto-changelog": { 88 | "output": "CHANGELOG.md", 89 | "template": "keepachangelog", 90 | "unreleased": false, 91 | "commitLimit": false, 92 | "backfillLimit": false, 93 | "hideCredit": true, 94 | "startingVersion": "2.1.6" 95 | }, 96 | "publishConfig": { 97 | "ignore": [ 98 | ".github/workflows" 99 | ] 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /polyfill.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var implementation = require('./implementation'); 4 | 5 | module.exports = function getPolyfill() { 6 | return typeof Object.getOwnPropertyDescriptors === 'function' ? Object.getOwnPropertyDescriptors : implementation; 7 | }; 8 | -------------------------------------------------------------------------------- /shim.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var getPolyfill = require('./polyfill'); 4 | var define = require('define-properties'); 5 | 6 | module.exports = function shimGetOwnPropertyDescriptors() { 7 | var polyfill = getPolyfill(); 8 | define( 9 | Object, 10 | { getOwnPropertyDescriptors: polyfill }, 11 | { getOwnPropertyDescriptors: function () { return Object.getOwnPropertyDescriptors !== polyfill; } } 12 | ); 13 | return polyfill; 14 | }; 15 | -------------------------------------------------------------------------------- /test/implementation.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var implementation = require('../implementation'); 4 | var callBind = require('call-bind'); 5 | var test = require('tape'); 6 | var hasStrictMode = require('has-strict-mode')(); 7 | var runTests = require('./tests'); 8 | 9 | test('as a function', function (t) { 10 | t.test('bad array/this value', { skip: !hasStrictMode }, function (st) { 11 | /* eslint no-useless-call: 0 */ 12 | st['throws'](function () { implementation.call(undefined); }, TypeError, 'undefined is not an object'); 13 | st['throws'](function () { implementation.call(null); }, TypeError, 'null is not an object'); 14 | st.end(); 15 | }); 16 | 17 | runTests(callBind(implementation, Object), t); 18 | 19 | t.end(); 20 | }); 21 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var getDescriptors = require('../'); 4 | var test = require('tape'); 5 | var runTests = require('./tests'); 6 | 7 | test('as a function', function (t) { 8 | t.test('bad object/this value', function (st) { 9 | st['throws'](function () { return getDescriptors(undefined); }, TypeError, 'undefined is not an object'); 10 | st['throws'](function () { return getDescriptors(null); }, TypeError, 'null is not an object'); 11 | st.end(); 12 | }); 13 | 14 | runTests(getDescriptors, t); 15 | 16 | t.end(); 17 | }); 18 | -------------------------------------------------------------------------------- /test/shimmed.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('../auto'); 4 | 5 | var getDescriptors = require('../'); 6 | 7 | var test = require('tape'); 8 | var defineProperties = require('define-properties'); 9 | var runTests = require('./tests'); 10 | var isEnumerable = Object.prototype.propertyIsEnumerable; 11 | var functionsHaveNames = require('functions-have-names')(); 12 | 13 | test('shimmed', function (t) { 14 | t.equal(Object.getOwnPropertyDescriptors.length, 1, 'Object.getOwnPropertyDescriptors has a length of 1'); 15 | t.test('Function name', { skip: !functionsHaveNames }, function (st) { 16 | st.equal(Object.getOwnPropertyDescriptors.name, 'getOwnPropertyDescriptors', 'Object.getOwnPropertyDescriptors has name "getOwnPropertyDescriptors"'); 17 | st.end(); 18 | }); 19 | 20 | t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) { 21 | et.equal(false, isEnumerable.call(Object, 'getOwnPropertyDescriptors'), 'Object.getOwnPropertyDescriptors is not enumerable'); 22 | et.end(); 23 | }); 24 | 25 | var supportsStrictMode = (function () { return typeof this === 'undefined'; }()); 26 | 27 | t.test('bad object/this value', { skip: !supportsStrictMode }, function (st) { 28 | st['throws'](function () { return getDescriptors(undefined, 'a'); }, TypeError, 'undefined is not an object'); 29 | st['throws'](function () { return getDescriptors(null, 'a'); }, TypeError, 'null is not an object'); 30 | st.end(); 31 | }); 32 | 33 | runTests(Object.getOwnPropertyDescriptors, t); 34 | 35 | t.end(); 36 | }); 37 | -------------------------------------------------------------------------------- /test/tests.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var mockProperty = require('mock-property'); 4 | 5 | module.exports = function (getDescriptors, t) { 6 | var enumDescriptor = { 7 | configurable: true, 8 | enumerable: false, 9 | value: true, 10 | writable: false 11 | }; 12 | var writableDescriptor = { 13 | configurable: true, 14 | enumerable: true, 15 | value: 42, 16 | writable: true 17 | }; 18 | 19 | t.test('works with Object.prototype poisoned setter', { skip: !Object.defineProperty }, function (st) { 20 | var key = 'foo'; 21 | 22 | var obj = {}; 23 | obj[key] = 42; 24 | 25 | var expected = {}; 26 | expected[key] = { 27 | configurable: true, 28 | enumerable: true, 29 | value: 42, 30 | writable: true 31 | }; 32 | 33 | st.teardown(mockProperty(Object.prototype, key, { set: function (v) { throw new Error(v); } })); 34 | 35 | var hasOwnNamesBug = false; 36 | try { 37 | Object.getOwnPropertyNames(obj); 38 | } catch (e) { 39 | // v8 in node 0.6 - 0.12 has a bug :-( 40 | hasOwnNamesBug = true; 41 | st.comment('SKIP: this engine has a bug with Object.getOwnPropertyNames: it can not handle a throwing setter on Object.prototype.'); 42 | } 43 | 44 | if (!hasOwnNamesBug) { 45 | st.doesNotThrow(function () { 46 | var result = getDescriptors(obj); 47 | st.deepEqual(result, expected, 'got expected descriptors'); 48 | }); 49 | } 50 | 51 | delete Object.prototype[key]; 52 | st.end(); 53 | }); 54 | 55 | t.test('gets all expected non-Symbol descriptors', function (st) { 56 | var obj = { normal: Infinity }; 57 | Object.defineProperty(obj, 'enumerable', enumDescriptor); 58 | Object.defineProperty(obj, 'writable', writableDescriptor); 59 | 60 | var descriptors = getDescriptors(obj); 61 | 62 | st.deepEqual(descriptors, { 63 | enumerable: enumDescriptor, 64 | normal: { 65 | configurable: true, 66 | enumerable: true, 67 | value: Infinity, 68 | writable: true 69 | }, 70 | writable: writableDescriptor 71 | }); 72 | st.end(); 73 | }); 74 | 75 | var supportsSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol'; 76 | t.test('gets Symbol descriptors too', { skip: !supportsSymbols }, function (st) { 77 | var symbol = Symbol('sym'); 78 | var symDescriptor = { 79 | configurable: false, 80 | enumerable: true, 81 | value: [symbol], 82 | writable: true 83 | }; 84 | var obj = { normal: Infinity }; 85 | Object.defineProperty(obj, 'enumerable', enumDescriptor); 86 | Object.defineProperty(obj, 'writable', writableDescriptor); 87 | Object.defineProperty(obj, 'symbol', symDescriptor); 88 | 89 | var descriptors = getDescriptors(obj); 90 | 91 | st.deepEqual(descriptors, { 92 | enumerable: enumDescriptor, 93 | normal: { 94 | configurable: true, 95 | enumerable: true, 96 | value: Infinity, 97 | writable: true 98 | }, 99 | symbol: symDescriptor, 100 | writable: writableDescriptor 101 | }); 102 | st.end(); 103 | }); 104 | 105 | var supportsProxy = typeof Proxy === 'function'; 106 | t.test('Proxies that return an undefined descriptor', { skip: !supportsProxy }, function (st) { 107 | var obj = { foo: true }; 108 | var fooDescriptor = Object.getOwnPropertyDescriptor(obj, 'foo'); 109 | 110 | var proxy = new Proxy(obj, { 111 | getOwnPropertyDescriptor: function (target, key) { 112 | return Object.getOwnPropertyDescriptor(target, key); 113 | }, 114 | ownKeys: function () { 115 | return ['foo', 'bar']; 116 | } 117 | }); 118 | st.deepEqual(getDescriptors(proxy), { foo: fooDescriptor }, 'object has no descriptors'); 119 | st.end(); 120 | }); 121 | }; 122 | --------------------------------------------------------------------------------