function.prototype.name
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -0,1 +1,42 @@ | ||
# 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.1.6](https://github.com/es-shims/Function.prototype.name/compare/v1.1.5...v1.1.6) - 2023-08-28 | ||
### Commits | ||
- [actions] reuse common workflows [`5f6bfba`](https://github.com/es-shims/Function.prototype.name/commit/5f6bfba9d2c42fbac8f4812396bc71f79464846c) | ||
- [meta] use `npmignore` to autogenerate an npmignore file [`28ea2f9`](https://github.com/es-shims/Function.prototype.name/commit/28ea2f9a9dd48623cba04e94c491033f1c9d1e90) | ||
- [Fix] properly recognize `document.all` in IE 6-8 [`316d676`](https://github.com/es-shims/Function.prototype.name/commit/316d67641d54bf221ed5edfdb9e04af3b98caad8) | ||
- [Fix] only return an own `name` [`d647609`](https://github.com/es-shims/Function.prototype.name/commit/d6476090e110733b52a922f4d0dbfdbc9478c653) | ||
- [Tests] add browserstack browser tests [`67ae402`](https://github.com/es-shims/Function.prototype.name/commit/67ae402aabcad83df2f7d7e356d059a84fe71f44) | ||
- [meta] better `eccheck` command [`728df4c`](https://github.com/es-shims/Function.prototype.name/commit/728df4cc81a51a131a36c0768c4adb7668ad7569) | ||
- [meta] add `auto-changelog` [`dbb700b`](https://github.com/es-shims/Function.prototype.name/commit/dbb700b38ef4c18e0ce0670a2ffface9ffd251a0) | ||
- [readme] fix eclint [`c98fdf1`](https://github.com/es-shims/Function.prototype.name/commit/c98fdf1bc5451de667945c41187a67022f750001) | ||
- [readme] add tested browsers [`d41325c`](https://github.com/es-shims/Function.prototype.name/commit/d41325ceec61627f63281d0649e4e0004f3e0609) | ||
- [actions] update rebase action to use reusable workflow [`085f340`](https://github.com/es-shims/Function.prototype.name/commit/085f3400785cd4f3fb762b73b095f5dfb795a0b3) | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `safe-publish-latest`, `tape` [`3f071ce`](https://github.com/es-shims/Function.prototype.name/commit/3f071cef2e1feebfd7d0daea7d6392c2feada091) | ||
- [actions] update codecov uploader [`a187b4f`](https://github.com/es-shims/Function.prototype.name/commit/a187b4fd07dbbeee12e8dc60651f122ab3f41f8d) | ||
- [Deps] update `define-properties`, `es-abstract` [`3ca42ef`](https://github.com/es-shims/Function.prototype.name/commit/3ca42ef76d5d4016d1ea87d806dc7e4a09d9b4f8) | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`8de25d2`](https://github.com/es-shims/Function.prototype.name/commit/8de25d2b9b523bd385b0bf3bb9213c11ecf8f1ba) | ||
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `tape` [`8b04da7`](https://github.com/es-shims/Function.prototype.name/commit/8b04da71695a1b9cf285ee926ffeec55b543595b) | ||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`39d8538`](https://github.com/es-shims/Function.prototype.name/commit/39d853854136a749c94e10f9fb06ba73903671a6) | ||
- [meta] reorder scripts [`054f96b`](https://github.com/es-shims/Function.prototype.name/commit/054f96b5e88e08e65c4e27bcb799c7cea2bc3462) | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`bebee89`](https://github.com/es-shims/Function.prototype.name/commit/bebee894a7989aef6e9db0dc8b16cbd9134b629c) | ||
- [Dev Deps] update `aud`, `tape` [`8e68159`](https://github.com/es-shims/Function.prototype.name/commit/8e681599b4fbf26e921f61fd603da0524369b72c) | ||
- [Tests] handle Function.prototype in Opera 12.1 [`f3b8f9a`](https://github.com/es-shims/Function.prototype.name/commit/f3b8f9a40b88f6da5ad41b874c3f2acf6fb30378) | ||
- [Deps] update `es-abstract`, `functions-have-names` [`6a59889`](https://github.com/es-shims/Function.prototype.name/commit/6a598893f013182070479a8cc52afd44e556561f) | ||
- [Deps] update `define-properties`, `es-abstract` [`cd1c5e7`](https://github.com/es-shims/Function.prototype.name/commit/cd1c5e773c3740ec563a26e657d764aba7c35a8c) | ||
- [Deps] update `es-abstract` [`3584585`](https://github.com/es-shims/Function.prototype.name/commit/35845851109f767e3bc84ebef989ca93e5851276) | ||
- [Deps] update `es-abstract` [`0e2f6d9`](https://github.com/es-shims/Function.prototype.name/commit/0e2f6d99d554a8b6b7c835702c8408832f9a2684) | ||
- [Deps] update `es-abstract` [`b11748e`](https://github.com/es-shims/Function.prototype.name/commit/b11748ebbda2d840ac625ae6627cfdb090b94434) | ||
- [Dev Deps] update `tape` [`d787a81`](https://github.com/es-shims/Function.prototype.name/commit/d787a81a1e1ce6d00dda6272e93a43bb193b1286) | ||
- [Deps] update `es-abstract` [`4692639`](https://github.com/es-shims/Function.prototype.name/commit/469263915b07db8342f0aad29ad7eba083bea277) | ||
- [Dev Deps] add `in-publish` [`568e263`](https://github.com/es-shims/Function.prototype.name/commit/568e2635099de326768f40d9e0eacbd024861676) | ||
<!-- auto-changelog-above --> | ||
1.1.5 / 2021-10-01 | ||
@@ -2,0 +43,0 @@ ================= |
'use strict'; | ||
var IsCallable = require('es-abstract/2021/IsCallable'); | ||
var IsCallable = require('es-abstract/2023/IsCallable'); | ||
var HasOwnProperty = require('es-abstract/2023/HasOwnProperty'); | ||
var functionsHaveNames = require('functions-have-names')(); | ||
@@ -8,2 +9,3 @@ var callBound = require('call-bind/callBound'); | ||
var $stringMatch = callBound('String.prototype.match'); | ||
var toStr = callBound('Object.prototype.toString'); | ||
@@ -28,9 +30,36 @@ var classRegex = /^class /; | ||
var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing | ||
var objectClass = '[object Object]'; | ||
var ddaClass = '[object HTMLAllCollection]'; | ||
var functionProto = Function.prototype; | ||
var isDDA = function isDocumentDotAll() { | ||
return false; | ||
}; | ||
if (typeof document === 'object') { | ||
// Firefox 3 canonicalizes DDA to undefined when it's not accessed directly | ||
var all = document.all; | ||
if (toStr(all) === toStr(document.all)) { | ||
isDDA = function isDocumentDotAll(value) { | ||
/* globals document: false */ | ||
// in IE 6-8, typeof document.all is "object" and it's truthy | ||
if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) { | ||
try { | ||
var str = toStr(value); | ||
// IE 6-8 uses `objectClass` | ||
return (str === ddaClass || str === objectClass) && value('') == null; // eslint-disable-line eqeqeq | ||
} catch (e) { /**/ } | ||
} | ||
return false; | ||
}; | ||
} | ||
} | ||
module.exports = function getName() { | ||
if (!isClass(this) && !IsCallable(this)) { | ||
if (isDDA(this) || (!isClass(this) && !IsCallable(this))) { | ||
throw new TypeError('Function.prototype.name sham getter called on non-function'); | ||
} | ||
if (functionsHaveNames) { | ||
if (functionsHaveNames && HasOwnProperty(this, 'name')) { | ||
return this.name; | ||
@@ -37,0 +66,0 @@ } |
{ | ||
"name": "function.prototype.name", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"author": "Jordan Harband <ljharb@gmail.com>", | ||
@@ -12,2 +12,3 @@ "funding": { | ||
"scripts": { | ||
"prepack": "npmignore --auto --commentLines=autogenerated", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
@@ -19,6 +20,7 @@ "prepublishOnly": "safe-publish-latest", | ||
"tests-only": "nyc tape 'test/**/*.js'", | ||
"prelint": "npm run eccheck", | ||
"lint": "eslint .", | ||
"prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", | ||
"lint": "eslint --ext=js,mjs .", | ||
"postlint": "es-shim-api --bound", | ||
"eccheck": "eclint check '*.js' '**/*.js'" | ||
"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)\")\"" | ||
}, | ||
@@ -41,20 +43,23 @@ "repository": { | ||
"call-bind": "^1.0.2", | ||
"define-properties": "^1.1.3", | ||
"es-abstract": "^1.19.0", | ||
"functions-have-names": "^1.2.2" | ||
"define-properties": "^1.2.0", | ||
"es-abstract": "^1.22.1", | ||
"functions-have-names": "^1.2.3" | ||
}, | ||
"devDependencies": { | ||
"@es-shims/api": "^2.2.1", | ||
"@ljharb/eslint-config": "^18.0.0", | ||
"aud": "^1.1.5", | ||
"@es-shims/api": "^2.4.2", | ||
"@ljharb/eslint-config": "^21.1.0", | ||
"aud": "^2.0.3", | ||
"auto-changelog": "^2.4.0", | ||
"eclint": "^2.8.1", | ||
"eslint": "^7.32.0", | ||
"eslint": "=8.8.0", | ||
"for-each": "^0.3.3", | ||
"has-strict-mode": "^1.0.1", | ||
"in-publish": "^2.0.1", | ||
"make-arrow-function": "^1.2.0", | ||
"make-async-function": "^1.0.0", | ||
"make-generator-function": "^2.0.0", | ||
"npmignore": "^0.3.0", | ||
"nyc": "^10.3.2", | ||
"safe-publish-latest": "^1.1.4", | ||
"tape": "^5.3.1", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.6.6", | ||
"uglify-register": "^1.0.1" | ||
@@ -82,3 +87,17 @@ }, | ||
"node": ">= 0.4" | ||
}, | ||
"auto-changelog": { | ||
"output": "CHANGELOG.md", | ||
"template": "keepachangelog", | ||
"unreleased": false, | ||
"commitLimit": false, | ||
"backfillLimit": false, | ||
"hideCredit": true, | ||
"startingVersion": "v1.1.6" | ||
}, | ||
"publishConfig": { | ||
"ignore": [ | ||
".github/workflows" | ||
] | ||
} | ||
} |
@@ -29,2 +29,15 @@ # function.prototype.name <sup>[![Version Badge][2]][1]</sup> | ||
## Supported engines | ||
Automatically tested in every minor version of node. | ||
Manually tested in: | ||
- Safari: v4 - v15 <sub>(4, 5, 5.1, 6.0.5, 6.2, 7.1, 8, 9.1.3, 10.1.2, 11.1.2, 12.1, 13.1.2, 14.1.2, 15.3, 15.6.1)</sub> | ||
- Chrome: v15 - v81, v83 - v106<sub>(every integer version)</sub> | ||
- Note: This includes Edge v80+ and Opera v15+, which matches Chrome | ||
- Firefox: v3, v3.6, v4 - v105 <sub>(every integer version)</sub> | ||
- Note: in v42 - v63, `Function.prototype.toString` throws on HTML element constructors, or a Proxy to a function | ||
- Note: in v20 - v35, HTML element constructors are not callable, despite having typeof `function` | ||
- IE: v6 - v11<sub>(every integer version</sub> | ||
- Opera: v11.1, v11.5, v11.6, v12.0, v12.1, v12.14, v12.15, v12.16, v15+ <sub>v15+ matches Chrome</sub> | ||
## Tests | ||
@@ -31,0 +44,0 @@ Simply clone the repo, `npm install`, and run `npm test` |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var asyncs = require('make-async-function').list(); | ||
var IsCallable = require('es-abstract/2023/IsCallable'); | ||
var forEach = require('for-each'); | ||
@@ -55,4 +56,4 @@ | ||
var protoName = getName(Function.prototype); | ||
// on <= node v2.5, this is "Empty" - otherwise, the empty string | ||
st.equal(protoName === '' || protoName === 'Empty', true, 'Function.prototype has the right name'); | ||
// on <= node v2.5, this is "Empty"; on Opera 12.1, "Function.prototype" - otherwise, the empty string | ||
st.equal(protoName === '' || protoName === 'Empty' || protoName === 'Function.prototype', true, 'Function.prototype has the right name'); | ||
st.equal(getName(function after() {}), 'after', 'function after accessing Function.prototype has the right name'); | ||
@@ -62,2 +63,45 @@ | ||
}); | ||
t.test('DOM', function (st) { | ||
/* eslint-env browser */ | ||
st.test('document.all', { skip: typeof document !== 'object' }, function (s2t) { | ||
s2t['throws']( | ||
function () { getName(document.all); }, | ||
TypeError, | ||
'a document.all has no name' | ||
); | ||
s2t.end(); | ||
}); | ||
forEach([ | ||
'HTMLElement', | ||
'HTMLAnchorElement' | ||
], function (name) { | ||
var constructor = global[name]; | ||
st.test(name, { skip: !constructor }, function (s2t) { | ||
s2t.match(typeof constructor, /^(?:function|object)$/, name + ' is a function or an object'); | ||
if (IsCallable(constructor)) { | ||
try { | ||
s2t.equal(getName(constructor), name, name + ' has the right name'); | ||
} catch (e) { | ||
s2t.fail(e); | ||
} | ||
} else { | ||
s2t['throws']( | ||
function () { getName(constructor); }, | ||
TypeError, | ||
name + ' is not callable' | ||
); | ||
} | ||
s2t.end(); | ||
}); | ||
}); | ||
st.end(); | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25493
270
56
17
19
- Removedfunction.prototype.name@1.1.6(transitive)
Updateddefine-properties@^1.2.0
Updatedes-abstract@^1.22.1
Updatedfunctions-have-names@^1.2.3