init source
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab;
|
||||
insert_final_newline = true;
|
||||
quote_type = auto;
|
||||
space_after_anonymous_functions = true;
|
||||
space_after_control_statements = true;
|
||||
spaces_around_operators = true;
|
||||
trim_trailing_whitespace = true;
|
||||
spaces_in_brackets = false;
|
||||
end_of_line = lf;
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"env": {
|
||||
"es6": true,
|
||||
},
|
||||
|
||||
"rules": {
|
||||
"arrow-parens": [2, "always"],
|
||||
"array-bracket-newline": 0,
|
||||
"array-element-newline": 0,
|
||||
"complexity": 0,
|
||||
"eqeqeq": [2, "allow-null"],
|
||||
"func-name-matching": 0,
|
||||
"id-length": [2, { "min": 1, "max": 30 }],
|
||||
"max-params": [2, 4],
|
||||
"max-statements": [2, 24],
|
||||
"max-statements-per-line": [2, { "max": 2 }],
|
||||
"multiline-comment-style": 1,
|
||||
"no-magic-numbers": 0,
|
||||
"new-cap": 0,
|
||||
"no-extra-parens": 1,
|
||||
"operator-linebreak": [2, "before"],
|
||||
"sort-keys": 0,
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "./es5.js",
|
||||
"rules": {
|
||||
"max-lines": [2, 600],
|
||||
"max-statements": [2, 30],
|
||||
},
|
||||
},
|
||||
{
|
||||
"files": "./es2015.js",
|
||||
"rules": {
|
||||
"max-lines": [2, 1400],
|
||||
},
|
||||
},
|
||||
{
|
||||
"files": "operations/*",
|
||||
"rules": {
|
||||
"max-lines": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"files": "operations/*.js",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "2018",
|
||||
},
|
||||
"rules": {
|
||||
//camelcase
|
||||
//array-callback-return
|
||||
//consistent-return
|
||||
"no-console": 0,
|
||||
"no-multi-str": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"files": "operations/getOps.js",
|
||||
"rules": {
|
||||
"no-console": 0,
|
||||
"no-process-exit": 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
# 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/es-abstract
|
||||
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 a single custom sponsorship URL
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": true,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 86,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"operations",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
language: node_js
|
||||
os:
|
||||
- linux
|
||||
node_js:
|
||||
- "12.11"
|
||||
- "11.15"
|
||||
- "10.16"
|
||||
- "9.11"
|
||||
- "8.16"
|
||||
- "7.10"
|
||||
- "6.17"
|
||||
- "5.12"
|
||||
- "4.9"
|
||||
- "iojs-v3.3"
|
||||
- "iojs-v2.5"
|
||||
- "iojs-v1.8"
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
- "0.6"
|
||||
cache:
|
||||
directories:
|
||||
- "$HOME/.npm"
|
||||
- "$(nvm cache dir)"
|
||||
- "$(nvm_version_path $(nvm_version_remote 0.4))"
|
||||
- "$(nvm_version_path $(nvm_version_remote 0.6))"
|
||||
- "$(nvm_version_path $(nvm_version_remote 0.10))"
|
||||
before_install:
|
||||
- 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac'
|
||||
- 'nvm install-latest-npm'
|
||||
install:
|
||||
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
|
||||
script:
|
||||
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
|
||||
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
|
||||
- 'if [ -n "${COVERAGE-}" ]; then npm run coverage && bash <(curl -s https://codecov.io/bash) -f coverage/*.json; fi'
|
||||
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
|
||||
sudo: false
|
||||
env:
|
||||
- TEST=true
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- node_js: "lts/*"
|
||||
env: PRETEST=true
|
||||
- node_js: "lts/*"
|
||||
env: POSTTEST=true
|
||||
- node_js: "0.8"
|
||||
env: COVERAGE=true
|
||||
- node_js: "0.12"
|
||||
env: COVERAGE=true
|
||||
- node_js: "4"
|
||||
env: COVERAGE=true
|
||||
- node_js: "8"
|
||||
env: COVERAGE=true
|
||||
- node_js: "12.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.15"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.15"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.16"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.15"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v3.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v3.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v3.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
allow_failures:
|
||||
- os: osx
|
||||
- env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.6"
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
1.15.0 / 2019-10-02
|
||||
=================
|
||||
* [New] `ES2018`+: add `DateString`, `TimeString`
|
||||
* [New] `ES2015`+: add `ToDateString`
|
||||
* [New] `ES5`+: add `msFromTime`, `SecFromTime`, `MinFromTime`, `HourFromTime`, `TimeWithinDay`, `Day`, `DayFromYear`, `TimeFromYear`, `YearFromTime`, `WeekDay`, `DaysInYear`, `InLeapYear`, `DayWithinYear`, `MonthFromTime`, `DateFromTime`, `MakeDay`, `MakeDate`, `MakeTime`, `TimeClip`, `modulo`
|
||||
* [New] add `regexTester` helper
|
||||
* [New] add `callBound` helper
|
||||
* [New] add ES2020’s intrinsic dot notation
|
||||
* [New] add `isPrefixOf` helper
|
||||
* [New] add `maxSafeInteger` helper
|
||||
* [Deps] update `string.prototype.trimleft`, `string.prototype.trimright`
|
||||
* [Dev Deps] update `eslint`
|
||||
* [Tests] on `node` `v12.11`
|
||||
* [meta] npmignore operations scripts; add "deltas"
|
||||
|
||||
1.14.2 / 2019-09-08
|
||||
=================
|
||||
* [Fix] `ES2016`: `IterableToArrayLike`: add proper fallback for strings, pre-Symbols
|
||||
* [Tests] on `node` `v12.10`
|
||||
|
||||
1.14.1 / 2019-09-03
|
||||
=================
|
||||
* [meta] republish with some extra files removed
|
||||
|
||||
1.14.0 / 2019-09-02
|
||||
=================
|
||||
* [New] add ES2019
|
||||
* [New] `ES2017+`: add `IterableToList`
|
||||
* [New] `ES2016`: add `IterableToArrayLike`
|
||||
* [New] `ES2015+`: add `ArrayCreate`, `ArraySetLength`, `OrdinaryDefineOwnProperty`, `OrdinaryGetOwnProperty`, `OrdinaryHasProperty`, `CreateHTML`, `GetOwnPropertyKeys`, `InstanceofOperator`, `SymbolDescriptiveString`, `GetSubstitution`, `ValidateAndApplyPropertyDescriptor`, `IsPromise`, `OrdinaryHasInstance`, `TestIntegrityLevel`, `SetIntegrityLevel`
|
||||
* [New] add `callBind` helper, and use it
|
||||
* [New] add helpers: `isPropertyDescriptor`, `every`
|
||||
* [New] ES5+: add `Abstract Relational Comparison`
|
||||
* [New] ES5+: add `Abstract Equality Comparison`, `Strict Equality Comparison`
|
||||
* [Fix] `ES2015+`: `GetIterator`: only require native Symbols when `method` is omitted
|
||||
* [Fix] `ES2015`: `Call`: error message now properly displays Symbols using `object-inspect`
|
||||
* [Fix] `ES2015+`: `ValidateAndApplyPropertyDescriptor`: use ES2017 logic to bypass spec bugs
|
||||
* [Fix] `ES2015+`: `CreateDataProperty`, `DefinePropertyOrThrow`, `ValidateAndApplyPropertyDescriptor`: add fallbacks for ES3
|
||||
* [Fix] `ES2015+`: `FromPropertyDescriptor`: no longer requires a fully complete Property Descriptor
|
||||
* [Fix] `ES5`: `IsPropertyDescriptor`: call into `IsDataDescriptor` and `IsAccessorDescriptor`
|
||||
* [Refactor] use `has-symbols` for Symbol detection
|
||||
* [Fix] `helpers/assertRecord`: remove `console.log`
|
||||
* [Deps] update `object-keys`
|
||||
* [readme] add security note
|
||||
* [meta] change http URLs to https
|
||||
* [meta] linter cleanup
|
||||
* [meta] fix getOps script
|
||||
* [meta] add FUNDING.yml
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `semver`, `replace`, `cheerio`, `tape`
|
||||
* [Tests] up to `node` `v12.9`, `v11.15`, `v10.16`, `v8.16`, `v6.17`
|
||||
* [Tests] temporarily allow node 0.6 to fail; segfaulting in travis
|
||||
* [Tests] use the values helper more in es5 tests
|
||||
* [Tests] fix linting to apply to all files
|
||||
* [Tests] run `npx aud` only on prod deps
|
||||
* [Tests] add v.descriptors helpers
|
||||
* [Tests] use `npx aud` instead of `npm audit` with hoops
|
||||
* [Tests] use `eclint` instead of `editorconfig-tools`
|
||||
* [Tests] some intrinsic cleanup
|
||||
* [Tests] migrate es5 tests to use values helper
|
||||
* [Tests] add some missing ES2015 ops
|
||||
|
||||
1.13.0 / 2019-01-02
|
||||
=================
|
||||
* [New] add ES2018
|
||||
* [New] add ES2015/ES2016: EnumerableOwnNames; ES2017: EnumerableOwnProperties
|
||||
* [New] `ES2015+`: add `thisBooleanValue`, `thisNumberValue`, `thisStringValue`, `thisTimeValue`
|
||||
* [New] `ES2015+`: add `DefinePropertyOrThrow`, `DeletePropertyOrThrow`, `CreateMethodProperty`
|
||||
* [New] add `assertRecord` helper
|
||||
* [Deps] update `is-callable`, `has`, `object-keys`, `es-to-primitive`
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `semver`, `safe-publish-latest`, `replace`
|
||||
* [Tests] use `npm audit` instead of `nsp`
|
||||
* [Tests] remove `jscs`
|
||||
* [Tests] up to `node` `v11.6`, `v10.15`, `v8.15`, `v6.16`
|
||||
* [Tests] move descriptor factories to `values` helper
|
||||
* [Tests] add `getOps` to programmatically fetch abstract operation names
|
||||
|
||||
1.12.0 / 2018-05-31
|
||||
=================
|
||||
* [New] add `GetIntrinsic` entry point
|
||||
* [New] `ES2015`+: add `ObjectCreate`
|
||||
* [Robustness]: `ES2015+`: ensure `Math.{abs,floor}` and `Function.call` are cached
|
||||
|
||||
1.11.0 / 2018-03-21
|
||||
=================
|
||||
* [New] `ES2015+`: add iterator abstract ops
|
||||
* [Dev Deps] update `eslint`, `nsp`, `object.assign`, `semver`, `tape`
|
||||
* [Tests] up to `node` `v9.8`, `v8.10`, `v6.13`
|
||||
|
||||
1.10.0 / 2017-11-24
|
||||
=================
|
||||
* [New] ES2015+: `AdvanceStringIndex`
|
||||
* [Dev Deps] update `eslint`, `nsp`
|
||||
* [Tests] require node 0.6 to pass again
|
||||
* [Tests] up to `node` `v9.2`, `v8.9`, `v6.12`; use `nvm install-latest-npm`; pin included builds to LTS
|
||||
|
||||
1.9.0 / 2017-09-30
|
||||
=================
|
||||
* [New] `es2015+`: add `ArraySpeciesCreate`
|
||||
* [New] ES2015+: add `CreateDataProperty` and `CreateDataPropertyOrThrow`
|
||||
* [Tests] consolidate duplicated tests
|
||||
* [Tests] increase coverage
|
||||
* [Dev Deps] update `nsp`, `eslint`
|
||||
|
||||
1.8.2 / 2017-09-03
|
||||
=================
|
||||
* [Fix] `es2015`+: `ToNumber`: provide the proper hint for Date objects (#27)
|
||||
* [Dev Deps] update `eslint`
|
||||
|
||||
1.8.1 / 2017-08-30
|
||||
=================
|
||||
* [Fix] ES2015+: `ToPropertyKey`: should return a symbol for Symbols (#26)
|
||||
* [Deps] update `function-bind`
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`
|
||||
* [Docs] github broke markdown parsing
|
||||
|
||||
1.8.0 / 2017-08-04
|
||||
=================
|
||||
* [New] add ES2017
|
||||
* [New] move es6+ to es2015+; leave es6/es7 as aliases
|
||||
* [New] ES5+: add `IsPropertyDescriptor`, `IsAccessorDescriptor`, `IsDataDescriptor`, `IsGenericDescriptor`, `FromPropertyDescriptor`, `ToPropertyDescriptor`
|
||||
* [New] ES2015+: add `CompletePropertyDescriptor`, `Set`, `HasOwnProperty`, `HasProperty`, `IsConcatSpreadable`, `Invoke`, `CreateIterResultObject`, `RegExpExec`
|
||||
* [Fix] es7/es2016: do not mutate ES6
|
||||
* [Fix] assign helper only supports one source
|
||||
* [Deps] update `is-regex`
|
||||
* [Dev Deps] update `nsp`, `eslint`, `@ljharb/eslint-config`
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `nsp`, `semver`, `tape`
|
||||
* [Tests] add tests for missing and excess operations
|
||||
* [Tests] add codecov for coverage
|
||||
* [Tests] up to `node` `v8.2`, `v7.10`, `v6.11`, `v4.8`; newer npm breaks on older node
|
||||
* [Tests] use same lists of value types across tests; ensure tests are the same when ops are the same
|
||||
* [Tests] ES2015: add ToNumber symbol tests
|
||||
* [Tests] switch to `nyc` for code coverage
|
||||
* [Tests] make IsRegExp tests consistent across editions
|
||||
|
||||
1.7.0 / 2017-01-22
|
||||
=================
|
||||
* [New] ES6: Add `GetMethod` (#16)
|
||||
* [New] ES6: Add `GetV` (#16)
|
||||
* [New] ES6: Add `Get` (#17)
|
||||
* [Tests] up to `node` `v7.4`, `v6.9`, `v4.6`; improve test matrix
|
||||
* [Dev Deps] update `tape`, `nsp`, `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`
|
||||
|
||||
1.6.1 / 2016-08-21
|
||||
=================
|
||||
* [Fix] ES6: IsConstructor should return true for `class` constructors.
|
||||
|
||||
1.6.0 / 2016-08-20
|
||||
=================
|
||||
* [New] ES5 / ES6: add `Type`
|
||||
* [New] ES6: `SpeciesConstructor`
|
||||
* [Dev Deps] update `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`, `semver`; add `safe-publish-latest`
|
||||
* [Tests] up to `node` `v6.4`, `v5.12`, `v4.5`
|
||||
|
||||
1.5.1 / 2016-05-30
|
||||
=================
|
||||
* [Fix] `ES.IsRegExp`: actually look up `Symbol.match` on the argument
|
||||
* [Refactor] create `isNaN` helper
|
||||
* [Deps] update `is-callable`, `function-bind`
|
||||
* [Deps] update `es-to-primitive`, fix ES5 tests
|
||||
* [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config`, `tape`, `nsp`
|
||||
* [Tests] up to `node` `v6.2`, `v5.11`, `v4.4`
|
||||
* [Tests] use pretest/posttest for linting/security
|
||||
|
||||
1.5.0 / 2015-12-27
|
||||
=================
|
||||
* [New] adds `Symbol.toPrimitive` support via `es-to-primitive`
|
||||
* [Deps] update `is-callable`, `es-to-primitive`
|
||||
* [Dev Deps] update `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`, `semver`, `tape`
|
||||
* [Tests] up to `node` `v5.3`
|
||||
|
||||
1.4.3 / 2015-11-04
|
||||
=================
|
||||
* [Fix] `ES6.ToNumber`: should give `NaN` for explicitly signed hex strings (#4)
|
||||
* [Refactor] `ES6.ToNumber`: No need to double-trim
|
||||
* [Refactor] group tests better
|
||||
* [Tests] should still pass on `node` `v0.8`
|
||||
|
||||
1.4.2 / 2015-11-02
|
||||
=================
|
||||
* [Fix] ensure `ES.ToNumber` trims whitespace, and does not trim non-whitespace (#3)
|
||||
|
||||
1.4.1 / 2015-10-31
|
||||
=================
|
||||
* [Fix] ensure only 0-1 are valid binary and 0-7 are valid octal digits (#2)
|
||||
* [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`
|
||||
* [Tests] on `node` `v5.0`
|
||||
* [Tests] fix npm upgrades for older node versions
|
||||
* package.json: use object form of "authors", add "contributors"
|
||||
|
||||
1.4.0 / 2015-09-26
|
||||
=================
|
||||
* [Deps] update `is-callable`
|
||||
* [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config`
|
||||
* [Tests] on `node` `v4.2`
|
||||
* [New] Add `SameValueNonNumber` to ES7
|
||||
|
||||
1.3.2 / 2015-09-26
|
||||
=================
|
||||
* [Fix] Fix `ES6.IsRegExp` to properly handle `Symbol.match`, per spec.
|
||||
* [Tests] up to `io.js` `v3.3`, `node` `v4.1`
|
||||
* [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config`, `semver`
|
||||
|
||||
1.3.1 / 2015-08-15
|
||||
=================
|
||||
* [Fix] Ensure that objects that `toString` to a binary or octal literal also convert properly
|
||||
|
||||
1.3.0 / 2015-08-15
|
||||
=================
|
||||
* [New] ES6’s ToNumber now supports binary and octal literals.
|
||||
* [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config`, `tape`
|
||||
* [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
|
||||
* [Tests] up to `io.js` `v3.0`
|
||||
|
||||
1.2.2 / 2015-07-28
|
||||
=================
|
||||
* [Fix] Both `ES5.CheckObjectCoercible` and `ES6.RequireObjectCoercible` return the value if they don't throw.
|
||||
* [Tests] Test on latest `io.js` versions.
|
||||
* [Dev Deps] Update `eslint`, `jscs`, `tape`, `semver`, `covert`, `nsp`
|
||||
|
||||
1.2.1 / 2015-03-20
|
||||
=================
|
||||
* Fix `isFinite` helper.
|
||||
|
||||
1.2.0 / 2015-03-19
|
||||
=================
|
||||
* Use `es-to-primitive` for ToPrimitive methods.
|
||||
* Test on latest `io.js` versions; allow failures on all but 2 latest `node`/`io.js` versions.
|
||||
|
||||
1.1.2 / 2015-03-20
|
||||
=================
|
||||
* Fix isFinite helper.
|
||||
|
||||
1.1.1 / 2015-03-19
|
||||
=================
|
||||
* Fix isPrimitive check for functions
|
||||
* Update `eslint`, `editorconfig-tools`, `semver`, `nsp`
|
||||
|
||||
1.1.0 / 2015-02-17
|
||||
=================
|
||||
* Add ES7 export (non-default).
|
||||
* All grade A-supported `node`/`iojs` versions now ship with an `npm` that understands `^`.
|
||||
* Test on `iojs-v1.2`.
|
||||
|
||||
1.0.1 / 2015-01-30
|
||||
=================
|
||||
* Use `is-callable` instead of an internal function.
|
||||
* Update `tape`, `jscs`, `nsp`, `eslint`
|
||||
|
||||
1.0.0 / 2015-01-10
|
||||
=================
|
||||
* v1.0.0
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
'use strict';
|
||||
|
||||
/* globals
|
||||
Atomics,
|
||||
SharedArrayBuffer,
|
||||
*/
|
||||
|
||||
var undefined; // eslint-disable-line no-shadow-restricted-names
|
||||
|
||||
var $TypeError = TypeError;
|
||||
|
||||
var ThrowTypeError = Object.getOwnPropertyDescriptor
|
||||
? (function () { return Object.getOwnPropertyDescriptor(arguments, 'callee').get; }())
|
||||
: function () { throw new $TypeError(); };
|
||||
|
||||
var hasSymbols = require('has-symbols')();
|
||||
|
||||
var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto
|
||||
|
||||
var generator; // = function * () {};
|
||||
var generatorFunction = generator ? getProto(generator) : undefined;
|
||||
var asyncFn; // async function() {};
|
||||
var asyncFunction = asyncFn ? asyncFn.constructor : undefined;
|
||||
var asyncGen; // async function * () {};
|
||||
var asyncGenFunction = asyncGen ? getProto(asyncGen) : undefined;
|
||||
var asyncGenIterator = asyncGen ? asyncGen() : undefined;
|
||||
|
||||
var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array);
|
||||
|
||||
var INTRINSICS = {
|
||||
'$ %Array%': Array,
|
||||
'$ %ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,
|
||||
'$ %ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer.prototype,
|
||||
'$ %ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined,
|
||||
'$ %ArrayPrototype%': Array.prototype,
|
||||
'$ %ArrayProto_entries%': Array.prototype.entries,
|
||||
'$ %ArrayProto_forEach%': Array.prototype.forEach,
|
||||
'$ %ArrayProto_keys%': Array.prototype.keys,
|
||||
'$ %ArrayProto_values%': Array.prototype.values,
|
||||
'$ %AsyncFromSyncIteratorPrototype%': undefined,
|
||||
'$ %AsyncFunction%': asyncFunction,
|
||||
'$ %AsyncFunctionPrototype%': asyncFunction ? asyncFunction.prototype : undefined,
|
||||
'$ %AsyncGenerator%': asyncGen ? getProto(asyncGenIterator) : undefined,
|
||||
'$ %AsyncGeneratorFunction%': asyncGenFunction,
|
||||
'$ %AsyncGeneratorPrototype%': asyncGenFunction ? asyncGenFunction.prototype : undefined,
|
||||
'$ %AsyncIteratorPrototype%': asyncGenIterator && hasSymbols && Symbol.asyncIterator ? asyncGenIterator[Symbol.asyncIterator]() : undefined,
|
||||
'$ %Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,
|
||||
'$ %Boolean%': Boolean,
|
||||
'$ %BooleanPrototype%': Boolean.prototype,
|
||||
'$ %DataView%': typeof DataView === 'undefined' ? undefined : DataView,
|
||||
'$ %DataViewPrototype%': typeof DataView === 'undefined' ? undefined : DataView.prototype,
|
||||
'$ %Date%': Date,
|
||||
'$ %DatePrototype%': Date.prototype,
|
||||
'$ %decodeURI%': decodeURI,
|
||||
'$ %decodeURIComponent%': decodeURIComponent,
|
||||
'$ %encodeURI%': encodeURI,
|
||||
'$ %encodeURIComponent%': encodeURIComponent,
|
||||
'$ %Error%': Error,
|
||||
'$ %ErrorPrototype%': Error.prototype,
|
||||
'$ %eval%': eval, // eslint-disable-line no-eval
|
||||
'$ %EvalError%': EvalError,
|
||||
'$ %EvalErrorPrototype%': EvalError.prototype,
|
||||
'$ %Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,
|
||||
'$ %Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined : Float32Array.prototype,
|
||||
'$ %Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,
|
||||
'$ %Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined : Float64Array.prototype,
|
||||
'$ %Function%': Function,
|
||||
'$ %FunctionPrototype%': Function.prototype,
|
||||
'$ %Generator%': generator ? getProto(generator()) : undefined,
|
||||
'$ %GeneratorFunction%': generatorFunction,
|
||||
'$ %GeneratorPrototype%': generatorFunction ? generatorFunction.prototype : undefined,
|
||||
'$ %Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,
|
||||
'$ %Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined : Int8Array.prototype,
|
||||
'$ %Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,
|
||||
'$ %Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined : Int8Array.prototype,
|
||||
'$ %Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,
|
||||
'$ %Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined : Int32Array.prototype,
|
||||
'$ %isFinite%': isFinite,
|
||||
'$ %isNaN%': isNaN,
|
||||
'$ %IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined,
|
||||
'$ %JSON%': JSON,
|
||||
'$ %JSONParse%': JSON.parse,
|
||||
'$ %Map%': typeof Map === 'undefined' ? undefined : Map,
|
||||
'$ %MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()),
|
||||
'$ %MapPrototype%': typeof Map === 'undefined' ? undefined : Map.prototype,
|
||||
'$ %Math%': Math,
|
||||
'$ %Number%': Number,
|
||||
'$ %NumberPrototype%': Number.prototype,
|
||||
'$ %Object%': Object,
|
||||
'$ %ObjectPrototype%': Object.prototype,
|
||||
'$ %ObjProto_toString%': Object.prototype.toString,
|
||||
'$ %ObjProto_valueOf%': Object.prototype.valueOf,
|
||||
'$ %parseFloat%': parseFloat,
|
||||
'$ %parseInt%': parseInt,
|
||||
'$ %Promise%': typeof Promise === 'undefined' ? undefined : Promise,
|
||||
'$ %PromisePrototype%': typeof Promise === 'undefined' ? undefined : Promise.prototype,
|
||||
'$ %PromiseProto_then%': typeof Promise === 'undefined' ? undefined : Promise.prototype.then,
|
||||
'$ %Promise_all%': typeof Promise === 'undefined' ? undefined : Promise.all,
|
||||
'$ %Promise_reject%': typeof Promise === 'undefined' ? undefined : Promise.reject,
|
||||
'$ %Promise_resolve%': typeof Promise === 'undefined' ? undefined : Promise.resolve,
|
||||
'$ %Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,
|
||||
'$ %RangeError%': RangeError,
|
||||
'$ %RangeErrorPrototype%': RangeError.prototype,
|
||||
'$ %ReferenceError%': ReferenceError,
|
||||
'$ %ReferenceErrorPrototype%': ReferenceError.prototype,
|
||||
'$ %Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,
|
||||
'$ %RegExp%': RegExp,
|
||||
'$ %RegExpPrototype%': RegExp.prototype,
|
||||
'$ %Set%': typeof Set === 'undefined' ? undefined : Set,
|
||||
'$ %SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()),
|
||||
'$ %SetPrototype%': typeof Set === 'undefined' ? undefined : Set.prototype,
|
||||
'$ %SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,
|
||||
'$ %SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer.prototype,
|
||||
'$ %String%': String,
|
||||
'$ %StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined,
|
||||
'$ %StringPrototype%': String.prototype,
|
||||
'$ %Symbol%': hasSymbols ? Symbol : undefined,
|
||||
'$ %SymbolPrototype%': hasSymbols ? Symbol.prototype : undefined,
|
||||
'$ %SyntaxError%': SyntaxError,
|
||||
'$ %SyntaxErrorPrototype%': SyntaxError.prototype,
|
||||
'$ %ThrowTypeError%': ThrowTypeError,
|
||||
'$ %TypedArray%': TypedArray,
|
||||
'$ %TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined,
|
||||
'$ %TypeError%': $TypeError,
|
||||
'$ %TypeErrorPrototype%': $TypeError.prototype,
|
||||
'$ %Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,
|
||||
'$ %Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array.prototype,
|
||||
'$ %Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,
|
||||
'$ %Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray.prototype,
|
||||
'$ %Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,
|
||||
'$ %Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array.prototype,
|
||||
'$ %Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,
|
||||
'$ %Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array.prototype,
|
||||
'$ %URIError%': URIError,
|
||||
'$ %URIErrorPrototype%': URIError.prototype,
|
||||
'$ %WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,
|
||||
'$ %WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined : WeakMap.prototype,
|
||||
'$ %WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet,
|
||||
'$ %WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined : WeakSet.prototype
|
||||
};
|
||||
|
||||
var bind = require('function-bind');
|
||||
var $replace = bind.call(Function.call, String.prototype.replace);
|
||||
|
||||
/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
|
||||
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
||||
var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
|
||||
var stringToPath = function stringToPath(string) {
|
||||
var result = [];
|
||||
$replace(string, rePropName, function (match, number, quote, subString) {
|
||||
result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : (number || match);
|
||||
});
|
||||
return result;
|
||||
};
|
||||
/* end adaptation */
|
||||
|
||||
var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
|
||||
var key = '$ ' + name;
|
||||
if (!(key in INTRINSICS)) {
|
||||
throw new SyntaxError('intrinsic ' + name + ' does not exist!');
|
||||
}
|
||||
|
||||
// istanbul ignore if // hopefully this is impossible to test :-)
|
||||
if (typeof INTRINSICS[key] === 'undefined' && !allowMissing) {
|
||||
throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
|
||||
}
|
||||
|
||||
return INTRINSICS[key];
|
||||
};
|
||||
|
||||
module.exports = function GetIntrinsic(name, allowMissing) {
|
||||
if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
|
||||
throw new TypeError('"allowMissing" argument must be a boolean');
|
||||
}
|
||||
|
||||
var parts = stringToPath(name);
|
||||
|
||||
if (parts.length === 0) {
|
||||
return getBaseIntrinsic(name, allowMissing);
|
||||
}
|
||||
|
||||
var value = getBaseIntrinsic('%' + parts[0] + '%', allowMissing);
|
||||
for (var i = 1; i < parts.length; i += 1) {
|
||||
if (value != null) {
|
||||
value = value[parts[i]];
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (C) 2015 Jordan Harband
|
||||
|
||||
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.
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
|
||||
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
|
||||
|
||||
# The files that need updating when incrementing the version number.
|
||||
VERSIONED_FILES := *.js */*.js *.json README*
|
||||
|
||||
|
||||
# Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
|
||||
# Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment
|
||||
# where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests.
|
||||
export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH")
|
||||
UTILS := semver
|
||||
# Make sure that all required utilities can be located.
|
||||
UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS)))
|
||||
|
||||
# Default target (by virtue of being the first non '.'-prefixed in the file).
|
||||
.PHONY: _no-target-specified
|
||||
_no-target-specified:
|
||||
$(error Please specify the target to make - `make list` shows targets. Alternatively, use `npm test` to run the default tests; `npm run` shows all tests)
|
||||
|
||||
# Lists all targets defined in this makefile.
|
||||
.PHONY: list
|
||||
list:
|
||||
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | command grep -v -e '^[^[:alnum:]]' -e '^$@$$command ' | sort
|
||||
|
||||
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
|
||||
.PHONY: test
|
||||
test:
|
||||
@npm test
|
||||
|
||||
.PHONY: _ensure-tag
|
||||
_ensure-tag:
|
||||
ifndef TAG
|
||||
$(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number)
|
||||
endif
|
||||
|
||||
CHANGELOG_ERROR = $(error No CHANGELOG specified)
|
||||
.PHONY: _ensure-changelog
|
||||
_ensure-changelog:
|
||||
@ (git status -sb --porcelain | command grep -E '^( M|[MA] ) CHANGELOG.md' > /dev/null) || (echo no CHANGELOG.md specified && exit 2)
|
||||
|
||||
# Ensures that the git workspace is clean.
|
||||
.PHONY: _ensure-clean
|
||||
_ensure-clean:
|
||||
@[ -z "$$((git status --porcelain --untracked-files=no || echo err) | command grep -v 'CHANGELOG.md')" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }
|
||||
|
||||
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
|
||||
.PHONY: release
|
||||
release: _ensure-tag _ensure-changelog _ensure-clean
|
||||
@old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \
|
||||
new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
|
||||
if printf "$$new_ver" | command grep -q '^[0-9]'; then \
|
||||
semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \
|
||||
semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
|
||||
else \
|
||||
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
|
||||
fi; \
|
||||
printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
|
||||
replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
|
||||
git commit -m "v$$new_ver" $(VERSIONED_FILES) CHANGELOG.md && \
|
||||
git tag -a -m "v$$new_ver" "v$$new_ver"
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
# es-abstract <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[![Build Status][travis-svg]][travis-url]
|
||||
[![dependency status][deps-svg]][deps-url]
|
||||
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[![npm badge][npm-badge-png]][package-url]
|
||||
|
||||
[![browser support][testling-svg]][testling-url]
|
||||
|
||||
ECMAScript spec abstract operations.
|
||||
When different versions of the spec conflict, the default export will be the latest version of the abstract operation.
|
||||
All abstract operations will also be available under an `es5`/`es2015`/`es2016`/`es2017`/`es2018`/`es2019` entry point, and exported property, if you require a specific version.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var ES = require('es-abstract');
|
||||
var assert = require('assert');
|
||||
|
||||
assert(ES.isCallable(function () {}));
|
||||
assert(!ES.isCallable(/a/g));
|
||||
```
|
||||
|
||||
## Tests
|
||||
Simply clone the repo, `npm install`, and run `npm test`
|
||||
|
||||
## Security
|
||||
|
||||
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
||||
|
||||
[package-url]: https://npmjs.org/package/es-abstract
|
||||
[npm-version-svg]: http://versionbadg.es/ljharb/es-abstract.svg
|
||||
[travis-svg]: https://travis-ci.org/ljharb/es-abstract.svg
|
||||
[travis-url]: https://travis-ci.org/ljharb/es-abstract
|
||||
[deps-svg]: https://david-dm.org/ljharb/es-abstract.svg
|
||||
[deps-url]: https://david-dm.org/ljharb/es-abstract
|
||||
[dev-deps-svg]: https://david-dm.org/ljharb/es-abstract/dev-status.svg
|
||||
[dev-deps-url]: https://david-dm.org/ljharb/es-abstract#info=devDependencies
|
||||
[testling-svg]: https://ci.testling.com/ljharb/es-abstract.png
|
||||
[testling-url]: https://ci.testling.com/ljharb/es-abstract
|
||||
[npm-badge-png]: https://nodei.co/npm/es-abstract.png?downloads=true&stars=true
|
||||
[license-image]: https://img.shields.io/npm/l/es-abstract.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: https://img.shields.io/npm/dm/es-abstract.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=es-abstract
|
||||
+1395
File diff suppressed because it is too large
Load Diff
+77
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
var hasSymbols = require('has-symbols')();
|
||||
|
||||
var ES2015 = require('./es2015');
|
||||
var assign = require('./helpers/assign');
|
||||
|
||||
var callBound = require('./helpers/callBound');
|
||||
|
||||
var $arrayPush = callBound('Array.prototype.push');
|
||||
var $arraySlice = callBound('Array.prototype.slice');
|
||||
var $arrayJoin = callBound('Array.prototype.join');
|
||||
|
||||
var ES2016 = assign(assign({}, ES2015), {
|
||||
// https://www.ecma-international.org/ecma-262/7.0/#sec-samevaluenonnumber
|
||||
SameValueNonNumber: function SameValueNonNumber(x, y) {
|
||||
if (typeof x === 'number' || typeof x !== typeof y) {
|
||||
throw new TypeError('SameValueNonNumber requires two non-number values of the same type.');
|
||||
}
|
||||
return this.SameValue(x, y);
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/7.0/#sec-iterabletoarraylike
|
||||
IterableToArrayLike: function IterableToArrayLike(items) {
|
||||
var usingIterator;
|
||||
if (hasSymbols) {
|
||||
usingIterator = this.GetMethod(items, Symbol.iterator);
|
||||
} else if (this.IsArray(items)) {
|
||||
usingIterator = function () {
|
||||
var i = -1;
|
||||
var arr = this; // eslint-disable-line no-invalid-this
|
||||
return {
|
||||
next: function () {
|
||||
i += 1;
|
||||
return {
|
||||
done: i >= arr.length,
|
||||
value: arr[i]
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
} else if (this.Type(items) === 'String') {
|
||||
var ES = this;
|
||||
usingIterator = function () {
|
||||
var i = 0;
|
||||
return {
|
||||
next: function () {
|
||||
var nextIndex = ES.AdvanceStringIndex(items, i, true);
|
||||
var value = $arrayJoin($arraySlice(items, i, nextIndex), '');
|
||||
i = nextIndex;
|
||||
return {
|
||||
done: nextIndex > items.length,
|
||||
value: value
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
if (typeof usingIterator !== 'undefined') {
|
||||
var iterator = this.GetIterator(items, usingIterator);
|
||||
var values = [];
|
||||
var next = true;
|
||||
while (next) {
|
||||
next = this.IteratorStep(iterator);
|
||||
if (next) {
|
||||
var nextValue = this.IteratorValue(next);
|
||||
$arrayPush(values, nextValue);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
return this.ToObject(items);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ES2016;
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('./GetIntrinsic');
|
||||
|
||||
var ES2016 = require('./es2016');
|
||||
var assign = require('./helpers/assign');
|
||||
var forEach = require('./helpers/forEach');
|
||||
var callBind = require('./helpers/callBind');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
var callBound = require('./helpers/callBound');
|
||||
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
||||
var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
|
||||
var $arrayPush = callBound('Array.prototype.push');
|
||||
|
||||
var ES2017 = assign(assign({}, ES2016), {
|
||||
ToIndex: function ToIndex(value) {
|
||||
if (typeof value === 'undefined') {
|
||||
return 0;
|
||||
}
|
||||
var integerIndex = this.ToInteger(value);
|
||||
if (integerIndex < 0) {
|
||||
throw new RangeError('index must be >= 0');
|
||||
}
|
||||
var index = this.ToLength(integerIndex);
|
||||
if (!this.SameValueZero(integerIndex, index)) {
|
||||
throw new RangeError('index must be >= 0 and < 2 ** 53 - 1');
|
||||
}
|
||||
return index;
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/8.0/#sec-enumerableownproperties
|
||||
EnumerableOwnProperties: function EnumerableOwnProperties(O, kind) {
|
||||
var keys = ES2016.EnumerableOwnNames(O);
|
||||
if (kind === 'key') {
|
||||
return keys;
|
||||
}
|
||||
if (kind === 'value' || kind === 'key+value') {
|
||||
var results = [];
|
||||
forEach(keys, function (key) {
|
||||
if ($isEnumerable(O, key)) {
|
||||
$pushApply(results, [
|
||||
kind === 'value' ? O[key] : [key, O[key]]
|
||||
]);
|
||||
}
|
||||
});
|
||||
return results;
|
||||
}
|
||||
throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind);
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/8.0/#sec-iterabletolist
|
||||
IterableToList: function IterableToList(items, method) {
|
||||
var iterator = this.GetIterator(items, method);
|
||||
var values = [];
|
||||
var next = true;
|
||||
while (next) {
|
||||
next = this.IteratorStep(iterator);
|
||||
if (next) {
|
||||
var nextValue = this.IteratorValue(next);
|
||||
$arrayPush(values, nextValue);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
});
|
||||
|
||||
delete ES2017.EnumerableOwnNames; // replaced with EnumerableOwnProperties
|
||||
delete ES2017.IterableToArrayLike; // replaced with IterableToList
|
||||
|
||||
module.exports = ES2017;
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('./GetIntrinsic');
|
||||
|
||||
var keys = require('object-keys');
|
||||
var inspect = require('object-inspect');
|
||||
|
||||
var ES2017 = require('./es2017');
|
||||
var assign = require('./helpers/assign');
|
||||
var forEach = require('./helpers/forEach');
|
||||
var callBind = require('./helpers/callBind');
|
||||
var every = require('./helpers/every');
|
||||
var isPrefixOf = require('./helpers/isPrefixOf');
|
||||
|
||||
var $String = GetIntrinsic('%String%');
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var callBound = require('./helpers/callBound');
|
||||
var regexTester = require('./helpers/regexTester');
|
||||
var $isNaN = require('./helpers/isNaN');
|
||||
|
||||
var $SymbolValueOf = callBound('Symbol.prototype.valueOf', true);
|
||||
// var $charAt = callBound('String.prototype.charAt');
|
||||
var $strSlice = callBound('String.prototype.slice');
|
||||
var $indexOf = callBound('String.prototype.indexOf');
|
||||
var $parseInt = parseInt;
|
||||
|
||||
var isDigit = regexTester(/^[0-9]$/);
|
||||
|
||||
var $PromiseResolve = callBound('Promise.resolve', true);
|
||||
|
||||
var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
||||
var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
|
||||
var $gOPS = $SymbolValueOf ? GetIntrinsic('%Object.getOwnPropertySymbols%') : null;
|
||||
|
||||
var padTimeComponent = function padTimeComponent(c, count) {
|
||||
return $strSlice('00' + c, -(count || 2));
|
||||
};
|
||||
|
||||
var weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||
|
||||
var OwnPropertyKeys = function OwnPropertyKeys(ES, source) {
|
||||
var ownKeys = keys(source);
|
||||
if ($gOPS) {
|
||||
$pushApply(ownKeys, $gOPS(source));
|
||||
}
|
||||
return ownKeys;
|
||||
};
|
||||
|
||||
var ES2018 = assign(assign({}, ES2017), {
|
||||
EnumerableOwnPropertyNames: ES2017.EnumerableOwnProperties,
|
||||
|
||||
// https://ecma-international.org/ecma-262/9.0/#sec-thissymbolvalue
|
||||
thisSymbolValue: function thisSymbolValue(value) {
|
||||
if (!$SymbolValueOf) {
|
||||
throw new SyntaxError('Symbols are not supported; thisSymbolValue requires that `value` be a Symbol or a Symbol object');
|
||||
}
|
||||
if (this.Type(value) === 'Symbol') {
|
||||
return value;
|
||||
}
|
||||
return $SymbolValueOf(value);
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/9.0/#sec-isstringprefix
|
||||
IsStringPrefix: function IsStringPrefix(p, q) {
|
||||
if (this.Type(p) !== 'String') {
|
||||
throw new TypeError('Assertion failed: "p" must be a String');
|
||||
}
|
||||
|
||||
if (this.Type(q) !== 'String') {
|
||||
throw new TypeError('Assertion failed: "q" must be a String');
|
||||
}
|
||||
|
||||
return isPrefixOf(p, q);
|
||||
/*
|
||||
if (p === q || p === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
var pLength = p.length;
|
||||
var qLength = q.length;
|
||||
if (pLength >= qLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// assert: pLength < qLength
|
||||
|
||||
for (var i = 0; i < pLength; i += 1) {
|
||||
if ($charAt(p, i) !== $charAt(q, i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
*/
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/9.0/#sec-tostring-applied-to-the-number-type
|
||||
NumberToString: function NumberToString(m) {
|
||||
if (this.Type(m) !== 'Number') {
|
||||
throw new TypeError('Assertion failed: "m" must be a String');
|
||||
}
|
||||
|
||||
return $String(m);
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/9.0/#sec-copydataproperties
|
||||
CopyDataProperties: function CopyDataProperties(target, source, excludedItems) {
|
||||
if (this.Type(target) !== 'Object') {
|
||||
throw new TypeError('Assertion failed: "target" must be an Object');
|
||||
}
|
||||
|
||||
if (!this.IsArray(excludedItems)) {
|
||||
throw new TypeError('Assertion failed: "excludedItems" must be a List of Property Keys');
|
||||
}
|
||||
for (var i = 0; i < excludedItems.length; i += 1) {
|
||||
if (!this.IsPropertyKey(excludedItems[i])) {
|
||||
throw new TypeError('Assertion failed: "excludedItems" must be a List of Property Keys');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof source === 'undefined' || source === null) {
|
||||
return target;
|
||||
}
|
||||
|
||||
var ES = this;
|
||||
|
||||
var fromObj = ES.ToObject(source);
|
||||
|
||||
var sourceKeys = OwnPropertyKeys(ES, fromObj);
|
||||
forEach(sourceKeys, function (nextKey) {
|
||||
var excluded = false;
|
||||
|
||||
forEach(excludedItems, function (e) {
|
||||
if (ES.SameValue(e, nextKey) === true) {
|
||||
excluded = true;
|
||||
}
|
||||
});
|
||||
|
||||
var enumerable = $isEnumerable(fromObj, nextKey) || (
|
||||
// this is to handle string keys being non-enumerable in older engines
|
||||
typeof source === 'string'
|
||||
&& nextKey >= 0
|
||||
&& ES.IsInteger(ES.ToNumber(nextKey))
|
||||
);
|
||||
if (excluded === false && enumerable) {
|
||||
var propValue = ES.Get(fromObj, nextKey);
|
||||
ES.CreateDataProperty(target, nextKey, propValue);
|
||||
}
|
||||
});
|
||||
|
||||
return target;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/9.0/#sec-promise-resolve
|
||||
PromiseResolve: function PromiseResolve(C, x) {
|
||||
if (!$PromiseResolve) {
|
||||
throw new SyntaxError('This environment does not support Promises.');
|
||||
}
|
||||
return $PromiseResolve(C, x);
|
||||
},
|
||||
|
||||
// http://www.ecma-international.org/ecma-262/9.0/#sec-getsubstitution
|
||||
// eslint-disable-next-line max-statements, max-params, max-lines-per-function
|
||||
GetSubstitution: function GetSubstitution(matched, str, position, captures, namedCaptures, replacement) {
|
||||
if (this.Type(matched) !== 'String') {
|
||||
throw new $TypeError('Assertion failed: `matched` must be a String');
|
||||
}
|
||||
var matchLength = matched.length;
|
||||
|
||||
if (this.Type(str) !== 'String') {
|
||||
throw new $TypeError('Assertion failed: `str` must be a String');
|
||||
}
|
||||
var stringLength = str.length;
|
||||
|
||||
if (!this.IsInteger(position) || position < 0 || position > stringLength) {
|
||||
throw new $TypeError('Assertion failed: `position` must be a nonnegative integer, and less than or equal to the length of `string`, got ' + inspect(position));
|
||||
}
|
||||
|
||||
var ES = this;
|
||||
var isStringOrHole = function (capture, index, arr) { return ES.Type(capture) === 'String' || !(index in arr); };
|
||||
if (!this.IsArray(captures) || !every(captures, isStringOrHole)) {
|
||||
throw new $TypeError('Assertion failed: `captures` must be a List of Strings, got ' + inspect(captures));
|
||||
}
|
||||
|
||||
if (this.Type(replacement) !== 'String') {
|
||||
throw new $TypeError('Assertion failed: `replacement` must be a String');
|
||||
}
|
||||
|
||||
var tailPos = position + matchLength;
|
||||
var m = captures.length;
|
||||
if (this.Type(namedCaptures) !== 'Undefined') {
|
||||
namedCaptures = this.ToObject(namedCaptures); // eslint-disable-line no-param-reassign
|
||||
}
|
||||
|
||||
var result = '';
|
||||
for (var i = 0; i < replacement.length; i += 1) {
|
||||
// if this is a $, and it's not the end of the replacement
|
||||
var current = replacement[i];
|
||||
var isLast = (i + 1) >= replacement.length;
|
||||
var nextIsLast = (i + 2) >= replacement.length;
|
||||
if (current === '$' && !isLast) {
|
||||
var next = replacement[i + 1];
|
||||
if (next === '$') {
|
||||
result += '$';
|
||||
i += 1;
|
||||
} else if (next === '&') {
|
||||
result += matched;
|
||||
i += 1;
|
||||
} else if (next === '`') {
|
||||
result += position === 0 ? '' : $strSlice(str, 0, position - 1);
|
||||
i += 1;
|
||||
} else if (next === "'") {
|
||||
result += tailPos >= stringLength ? '' : $strSlice(str, tailPos);
|
||||
i += 1;
|
||||
} else {
|
||||
var nextNext = nextIsLast ? null : replacement[i + 2];
|
||||
if (isDigit(next) && next !== '0' && (nextIsLast || !isDigit(nextNext))) {
|
||||
// $1 through $9, and not followed by a digit
|
||||
var n = $parseInt(next, 10);
|
||||
// if (n > m, impl-defined)
|
||||
result += (n <= m && this.Type(captures[n - 1]) === 'Undefined') ? '' : captures[n - 1];
|
||||
i += 1;
|
||||
} else if (isDigit(next) && (nextIsLast || isDigit(nextNext))) {
|
||||
// $00 through $99
|
||||
var nn = next + nextNext;
|
||||
var nnI = $parseInt(nn, 10) - 1;
|
||||
// if nn === '00' or nn > m, impl-defined
|
||||
result += (nn <= m && this.Type(captures[nnI]) === 'Undefined') ? '' : captures[nnI];
|
||||
i += 2;
|
||||
} else if (next === '<') {
|
||||
// eslint-disable-next-line max-depth
|
||||
if (this.Type(namedCaptures) === 'Undefined') {
|
||||
result += '$<';
|
||||
i += 2;
|
||||
} else {
|
||||
var endIndex = $indexOf(replacement, '>', i);
|
||||
// eslint-disable-next-line max-depth
|
||||
if (endIndex > -1) {
|
||||
var groupName = $strSlice(replacement, i, endIndex);
|
||||
var capture = this.Get(namedCaptures, groupName);
|
||||
// eslint-disable-next-line max-depth
|
||||
if (this.Type(capture) !== 'Undefined') {
|
||||
result += this.ToString(capture);
|
||||
}
|
||||
i += '$<' + groupName + '>'.length;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result += '$';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// the final $, or else not a $
|
||||
result += replacement[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/9.0/#sec-datestring
|
||||
DateString: function DateString(tv) {
|
||||
if (this.Type(tv) !== 'Number' || $isNaN(tv)) {
|
||||
throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number');
|
||||
}
|
||||
var weekday = weekdays[this.WeekDay(tv)];
|
||||
var month = months[this.MonthFromTime(tv)];
|
||||
var day = padTimeComponent(this.DateFromTime(tv));
|
||||
var year = padTimeComponent(this.YearFromTime(tv), 4);
|
||||
return weekday + '\x20' + month + '\x20' + day + '\x20' + year;
|
||||
},
|
||||
|
||||
// https://www.ecma-international.org/ecma-262/9.0/#sec-timestring
|
||||
TimeString: function TimeString(tv) {
|
||||
if (this.Type(tv) !== 'Number' || $isNaN(tv)) {
|
||||
throw new $TypeError('Assertion failed: `tv` must be a non-NaN Number');
|
||||
}
|
||||
var hour = this.HourFromTime(tv);
|
||||
var minute = this.MinFromTime(tv);
|
||||
var second = this.SecFromTime(tv);
|
||||
return padTimeComponent(hour) + ':' + padTimeComponent(minute) + ':' + padTimeComponent(second) + '\x20GMT';
|
||||
}
|
||||
});
|
||||
|
||||
delete ES2018.EnumerableOwnProperties; // replaced with EnumerableOwnPropertyNames
|
||||
|
||||
delete ES2018.IsPropertyDescriptor; // not an actual abstract operation
|
||||
|
||||
module.exports = ES2018;
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
|
||||
var trimStart = require('string.prototype.trimleft');
|
||||
var trimEnd = require('string.prototype.trimright');
|
||||
var inspect = require('object-inspect');
|
||||
|
||||
var ES2018 = require('./es2018');
|
||||
var assign = require('./helpers/assign');
|
||||
var MAX_SAFE_INTEGER = require('./helpers/maxSafeInteger');
|
||||
|
||||
var GetIntrinsic = require('./GetIntrinsic');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
var ES2019 = assign(assign({}, ES2018), {
|
||||
// https://tc39.es/ecma262/#sec-add-entries-from-iterable
|
||||
AddEntriesFromIterable: function AddEntriesFromIterable(target, iterable, adder) {
|
||||
if (!this.IsCallable(adder)) {
|
||||
throw new $TypeError('Assertion failed: `adder` is not callable');
|
||||
}
|
||||
if (iterable == null) {
|
||||
throw new $TypeError('Assertion failed: `iterable` is present, and not nullish');
|
||||
}
|
||||
var iteratorRecord = this.GetIterator(iterable);
|
||||
while (true) { // eslint-disable-line no-constant-condition
|
||||
var next = this.IteratorStep(iteratorRecord);
|
||||
if (!next) {
|
||||
return target;
|
||||
}
|
||||
var nextItem = this.IteratorValue(next);
|
||||
if (this.Type(nextItem) !== 'Object') {
|
||||
var error = new $TypeError('iterator next must return an Object, got ' + inspect(nextItem));
|
||||
return this.IteratorClose(
|
||||
iteratorRecord,
|
||||
function () { throw error; } // eslint-disable-line no-loop-func
|
||||
);
|
||||
}
|
||||
try {
|
||||
var k = this.Get(nextItem, '0');
|
||||
var v = this.Get(nextItem, '1');
|
||||
this.Call(adder, target, [k, v]);
|
||||
} catch (e) {
|
||||
return this.IteratorClose(
|
||||
iteratorRecord,
|
||||
function () { throw e; } // eslint-disable-line no-loop-func
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/10.0/#sec-flattenintoarray
|
||||
// eslint-disable-next-line max-params, max-statements
|
||||
FlattenIntoArray: function FlattenIntoArray(target, source, sourceLen, start, depth) {
|
||||
var mapperFunction;
|
||||
if (arguments.length > 5) {
|
||||
mapperFunction = arguments[5];
|
||||
}
|
||||
|
||||
var targetIndex = start;
|
||||
var sourceIndex = 0;
|
||||
while (sourceIndex < sourceLen) {
|
||||
var P = this.ToString(sourceIndex);
|
||||
var exists = this.HasProperty(source, P);
|
||||
if (exists === true) {
|
||||
var element = this.Get(source, P);
|
||||
if (typeof mapperFunction !== 'undefined') {
|
||||
if (arguments.length <= 6) {
|
||||
throw new $TypeError('Assertion failed: thisArg is required when mapperFunction is provided');
|
||||
}
|
||||
element = this.Call(mapperFunction, arguments[6], [element, sourceIndex, source]);
|
||||
}
|
||||
var shouldFlatten = false;
|
||||
if (depth > 0) {
|
||||
shouldFlatten = this.IsArray(element);
|
||||
}
|
||||
if (shouldFlatten) {
|
||||
var elementLen = this.ToLength(this.Get(element, 'length'));
|
||||
targetIndex = this.FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1);
|
||||
} else {
|
||||
if (targetIndex >= MAX_SAFE_INTEGER) {
|
||||
throw new $TypeError('index too large');
|
||||
}
|
||||
this.CreateDataPropertyOrThrow(target, this.ToString(targetIndex), element);
|
||||
targetIndex += 1;
|
||||
}
|
||||
}
|
||||
sourceIndex += 1;
|
||||
}
|
||||
|
||||
return targetIndex;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/10.0/#sec-trimstring
|
||||
TrimString: function TrimString(string, where) {
|
||||
var str = this.RequireObjectCoercible(string);
|
||||
var S = this.ToString(str);
|
||||
var T;
|
||||
if (where === 'start') {
|
||||
T = trimStart(S);
|
||||
} else if (where === 'end') {
|
||||
T = trimEnd(S);
|
||||
} else if (where === 'start+end') {
|
||||
T = trimStart(trimEnd(S));
|
||||
} else {
|
||||
throw new $TypeError('Assertion failed: invalid `where` value; must be "start", "end", or "start+end"');
|
||||
}
|
||||
return T;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = ES2019;
|
||||
+544
@@ -0,0 +1,544 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('./GetIntrinsic');
|
||||
|
||||
var $Object = GetIntrinsic('%Object%');
|
||||
var $EvalError = GetIntrinsic('%EvalError%');
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
var $String = GetIntrinsic('%String%');
|
||||
var $Date = GetIntrinsic('%Date%');
|
||||
var $Number = GetIntrinsic('%Number%');
|
||||
var $floor = GetIntrinsic('%Math.floor%');
|
||||
var $DateUTC = GetIntrinsic('%Date.UTC%');
|
||||
var $abs = GetIntrinsic('%Math.abs%');
|
||||
|
||||
var assertRecord = require('./helpers/assertRecord');
|
||||
var isPropertyDescriptor = require('./helpers/isPropertyDescriptor');
|
||||
var $isNaN = require('./helpers/isNaN');
|
||||
var $isFinite = require('./helpers/isFinite');
|
||||
var sign = require('./helpers/sign');
|
||||
var mod = require('./helpers/mod');
|
||||
var isPrefixOf = require('./helpers/isPrefixOf');
|
||||
var callBound = require('./helpers/callBound');
|
||||
|
||||
var IsCallable = require('is-callable');
|
||||
var toPrimitive = require('es-to-primitive/es5');
|
||||
|
||||
var has = require('has');
|
||||
|
||||
var $getUTCFullYear = callBound('Date.prototype.getUTCFullYear');
|
||||
|
||||
var HoursPerDay = 24;
|
||||
var MinutesPerHour = 60;
|
||||
var SecondsPerMinute = 60;
|
||||
var msPerSecond = 1e3;
|
||||
var msPerMinute = msPerSecond * SecondsPerMinute;
|
||||
var msPerHour = msPerMinute * MinutesPerHour;
|
||||
var msPerDay = 86400000;
|
||||
|
||||
// https://es5.github.io/#x9
|
||||
var ES5 = {
|
||||
ToPrimitive: toPrimitive,
|
||||
|
||||
ToBoolean: function ToBoolean(value) {
|
||||
return !!value;
|
||||
},
|
||||
ToNumber: function ToNumber(value) {
|
||||
return +value; // eslint-disable-line no-implicit-coercion
|
||||
},
|
||||
ToInteger: function ToInteger(value) {
|
||||
var number = this.ToNumber(value);
|
||||
if ($isNaN(number)) { return 0; }
|
||||
if (number === 0 || !$isFinite(number)) { return number; }
|
||||
return sign(number) * Math.floor(Math.abs(number));
|
||||
},
|
||||
ToInt32: function ToInt32(x) {
|
||||
return this.ToNumber(x) >> 0;
|
||||
},
|
||||
ToUint32: function ToUint32(x) {
|
||||
return this.ToNumber(x) >>> 0;
|
||||
},
|
||||
ToUint16: function ToUint16(value) {
|
||||
var number = this.ToNumber(value);
|
||||
if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }
|
||||
var posInt = sign(number) * Math.floor(Math.abs(number));
|
||||
return mod(posInt, 0x10000);
|
||||
},
|
||||
ToString: function ToString(value) {
|
||||
return $String(value);
|
||||
},
|
||||
ToObject: function ToObject(value) {
|
||||
this.CheckObjectCoercible(value);
|
||||
return $Object(value);
|
||||
},
|
||||
CheckObjectCoercible: function CheckObjectCoercible(value, optMessage) {
|
||||
/* jshint eqnull:true */
|
||||
if (value == null) {
|
||||
throw new $TypeError(optMessage || 'Cannot call method on ' + value);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
IsCallable: IsCallable,
|
||||
SameValue: function SameValue(x, y) {
|
||||
if (x === y) { // 0 === -0, but they are not identical.
|
||||
if (x === 0) { return 1 / x === 1 / y; }
|
||||
return true;
|
||||
}
|
||||
return $isNaN(x) && $isNaN(y);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-8
|
||||
Type: function Type(x) {
|
||||
if (x === null) {
|
||||
return 'Null';
|
||||
}
|
||||
if (typeof x === 'undefined') {
|
||||
return 'Undefined';
|
||||
}
|
||||
if (typeof x === 'function' || typeof x === 'object') {
|
||||
return 'Object';
|
||||
}
|
||||
if (typeof x === 'number') {
|
||||
return 'Number';
|
||||
}
|
||||
if (typeof x === 'boolean') {
|
||||
return 'Boolean';
|
||||
}
|
||||
if (typeof x === 'string') {
|
||||
return 'String';
|
||||
}
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type
|
||||
IsPropertyDescriptor: function IsPropertyDescriptor(Desc) {
|
||||
return isPropertyDescriptor(this, Desc);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-8.10.1
|
||||
IsAccessorDescriptor: function IsAccessorDescriptor(Desc) {
|
||||
if (typeof Desc === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
assertRecord(this, 'Property Descriptor', 'Desc', Desc);
|
||||
|
||||
if (!has(Desc, '[[Get]]') && !has(Desc, '[[Set]]')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-8.10.2
|
||||
IsDataDescriptor: function IsDataDescriptor(Desc) {
|
||||
if (typeof Desc === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
assertRecord(this, 'Property Descriptor', 'Desc', Desc);
|
||||
|
||||
if (!has(Desc, '[[Value]]') && !has(Desc, '[[Writable]]')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-8.10.3
|
||||
IsGenericDescriptor: function IsGenericDescriptor(Desc) {
|
||||
if (typeof Desc === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
|
||||
assertRecord(this, 'Property Descriptor', 'Desc', Desc);
|
||||
|
||||
if (!this.IsAccessorDescriptor(Desc) && !this.IsDataDescriptor(Desc)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-8.10.4
|
||||
FromPropertyDescriptor: function FromPropertyDescriptor(Desc) {
|
||||
if (typeof Desc === 'undefined') {
|
||||
return Desc;
|
||||
}
|
||||
|
||||
assertRecord(this, 'Property Descriptor', 'Desc', Desc);
|
||||
|
||||
if (this.IsDataDescriptor(Desc)) {
|
||||
return {
|
||||
value: Desc['[[Value]]'],
|
||||
writable: !!Desc['[[Writable]]'],
|
||||
enumerable: !!Desc['[[Enumerable]]'],
|
||||
configurable: !!Desc['[[Configurable]]']
|
||||
};
|
||||
} else if (this.IsAccessorDescriptor(Desc)) {
|
||||
return {
|
||||
get: Desc['[[Get]]'],
|
||||
set: Desc['[[Set]]'],
|
||||
enumerable: !!Desc['[[Enumerable]]'],
|
||||
configurable: !!Desc['[[Configurable]]']
|
||||
};
|
||||
} else {
|
||||
throw new $TypeError('FromPropertyDescriptor must be called with a fully populated Property Descriptor');
|
||||
}
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-8.10.5
|
||||
ToPropertyDescriptor: function ToPropertyDescriptor(Obj) {
|
||||
if (this.Type(Obj) !== 'Object') {
|
||||
throw new $TypeError('ToPropertyDescriptor requires an object');
|
||||
}
|
||||
|
||||
var desc = {};
|
||||
if (has(Obj, 'enumerable')) {
|
||||
desc['[[Enumerable]]'] = this.ToBoolean(Obj.enumerable);
|
||||
}
|
||||
if (has(Obj, 'configurable')) {
|
||||
desc['[[Configurable]]'] = this.ToBoolean(Obj.configurable);
|
||||
}
|
||||
if (has(Obj, 'value')) {
|
||||
desc['[[Value]]'] = Obj.value;
|
||||
}
|
||||
if (has(Obj, 'writable')) {
|
||||
desc['[[Writable]]'] = this.ToBoolean(Obj.writable);
|
||||
}
|
||||
if (has(Obj, 'get')) {
|
||||
var getter = Obj.get;
|
||||
if (typeof getter !== 'undefined' && !this.IsCallable(getter)) {
|
||||
throw new TypeError('getter must be a function');
|
||||
}
|
||||
desc['[[Get]]'] = getter;
|
||||
}
|
||||
if (has(Obj, 'set')) {
|
||||
var setter = Obj.set;
|
||||
if (typeof setter !== 'undefined' && !this.IsCallable(setter)) {
|
||||
throw new $TypeError('setter must be a function');
|
||||
}
|
||||
desc['[[Set]]'] = setter;
|
||||
}
|
||||
|
||||
if ((has(desc, '[[Get]]') || has(desc, '[[Set]]')) && (has(desc, '[[Value]]') || has(desc, '[[Writable]]'))) {
|
||||
throw new $TypeError('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');
|
||||
}
|
||||
return desc;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-11.9.3
|
||||
'Abstract Equality Comparison': function AbstractEqualityComparison(x, y) {
|
||||
var xType = this.Type(x);
|
||||
var yType = this.Type(y);
|
||||
if (xType === yType) {
|
||||
return x === y; // ES6+ specified this shortcut anyways.
|
||||
}
|
||||
if (x == null && y == null) {
|
||||
return true;
|
||||
}
|
||||
if (xType === 'Number' && yType === 'String') {
|
||||
return this['Abstract Equality Comparison'](x, this.ToNumber(y));
|
||||
}
|
||||
if (xType === 'String' && yType === 'Number') {
|
||||
return this['Abstract Equality Comparison'](this.ToNumber(x), y);
|
||||
}
|
||||
if (xType === 'Boolean') {
|
||||
return this['Abstract Equality Comparison'](this.ToNumber(x), y);
|
||||
}
|
||||
if (yType === 'Boolean') {
|
||||
return this['Abstract Equality Comparison'](x, this.ToNumber(y));
|
||||
}
|
||||
if ((xType === 'String' || xType === 'Number') && yType === 'Object') {
|
||||
return this['Abstract Equality Comparison'](x, this.ToPrimitive(y));
|
||||
}
|
||||
if (xType === 'Object' && (yType === 'String' || yType === 'Number')) {
|
||||
return this['Abstract Equality Comparison'](this.ToPrimitive(x), y);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-11.9.6
|
||||
'Strict Equality Comparison': function StrictEqualityComparison(x, y) {
|
||||
var xType = this.Type(x);
|
||||
var yType = this.Type(y);
|
||||
if (xType !== yType) {
|
||||
return false;
|
||||
}
|
||||
if (xType === 'Undefined' || xType === 'Null') {
|
||||
return true;
|
||||
}
|
||||
return x === y; // shortcut for steps 4-7
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-11.8.5
|
||||
// eslint-disable-next-line max-statements
|
||||
'Abstract Relational Comparison': function AbstractRelationalComparison(x, y, LeftFirst) {
|
||||
if (this.Type(LeftFirst) !== 'Boolean') {
|
||||
throw new $TypeError('Assertion failed: LeftFirst argument must be a Boolean');
|
||||
}
|
||||
var px;
|
||||
var py;
|
||||
if (LeftFirst) {
|
||||
px = this.ToPrimitive(x, $Number);
|
||||
py = this.ToPrimitive(y, $Number);
|
||||
} else {
|
||||
py = this.ToPrimitive(y, $Number);
|
||||
px = this.ToPrimitive(x, $Number);
|
||||
}
|
||||
var bothStrings = this.Type(px) === 'String' && this.Type(py) === 'String';
|
||||
if (!bothStrings) {
|
||||
var nx = this.ToNumber(px);
|
||||
var ny = this.ToNumber(py);
|
||||
if ($isNaN(nx) || $isNaN(ny)) {
|
||||
return undefined;
|
||||
}
|
||||
if ($isFinite(nx) && $isFinite(ny) && nx === ny) {
|
||||
return false;
|
||||
}
|
||||
if (nx === 0 && ny === 0) {
|
||||
return false;
|
||||
}
|
||||
if (nx === Infinity) {
|
||||
return false;
|
||||
}
|
||||
if (ny === Infinity) {
|
||||
return true;
|
||||
}
|
||||
if (ny === -Infinity) {
|
||||
return false;
|
||||
}
|
||||
if (nx === -Infinity) {
|
||||
return true;
|
||||
}
|
||||
return nx < ny; // by now, these are both nonzero, finite, and not equal
|
||||
}
|
||||
if (isPrefixOf(py, px)) {
|
||||
return false;
|
||||
}
|
||||
if (isPrefixOf(px, py)) {
|
||||
return true;
|
||||
}
|
||||
return px < py; // both strings, neither a prefix of the other. shortcut for steps c-f
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10
|
||||
msFromTime: function msFromTime(t) {
|
||||
return mod(t, msPerSecond);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10
|
||||
SecFromTime: function SecFromTime(t) {
|
||||
return mod($floor(t / msPerSecond), SecondsPerMinute);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10
|
||||
MinFromTime: function MinFromTime(t) {
|
||||
return mod($floor(t / msPerMinute), MinutesPerHour);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.10
|
||||
HourFromTime: function HourFromTime(t) {
|
||||
return mod($floor(t / msPerHour), HoursPerDay);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.2
|
||||
Day: function Day(t) {
|
||||
return $floor(t / msPerDay);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.2
|
||||
TimeWithinDay: function TimeWithinDay(t) {
|
||||
return mod(t, msPerDay);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3
|
||||
DayFromYear: function DayFromYear(y) {
|
||||
return (365 * (y - 1970)) + $floor((y - 1969) / 4) - $floor((y - 1901) / 100) + $floor((y - 1601) / 400);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3
|
||||
TimeFromYear: function TimeFromYear(y) {
|
||||
return msPerDay * this.DayFromYear(y);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3
|
||||
YearFromTime: function YearFromTime(t) {
|
||||
// largest y such that this.TimeFromYear(y) <= t
|
||||
return $getUTCFullYear(new $Date(t));
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.6
|
||||
WeekDay: function WeekDay(t) {
|
||||
return mod(this.Day(t) + 4, 7);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3
|
||||
DaysInYear: function DaysInYear(y) {
|
||||
if (mod(y, 4) !== 0) {
|
||||
return 365;
|
||||
}
|
||||
if (mod(y, 100) !== 0) {
|
||||
return 366;
|
||||
}
|
||||
if (mod(y, 400) !== 0) {
|
||||
return 365;
|
||||
}
|
||||
return 366;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.3
|
||||
InLeapYear: function InLeapYear(t) {
|
||||
var days = this.DaysInYear(this.YearFromTime(t));
|
||||
if (days === 365) {
|
||||
return 0;
|
||||
}
|
||||
if (days === 366) {
|
||||
return 1;
|
||||
}
|
||||
throw new $EvalError('Assertion failed: there are not 365 or 366 days in a year, got: ' + days);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.4
|
||||
DayWithinYear: function DayWithinYear(t) {
|
||||
return this.Day(t) - this.DayFromYear(this.YearFromTime(t));
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.4
|
||||
MonthFromTime: function MonthFromTime(t) {
|
||||
var day = this.DayWithinYear(t);
|
||||
if (0 <= day && day < 31) {
|
||||
return 0;
|
||||
}
|
||||
var leap = this.InLeapYear(t);
|
||||
if (31 <= day && day < (59 + leap)) {
|
||||
return 1;
|
||||
}
|
||||
if ((59 + leap) <= day && day < (90 + leap)) {
|
||||
return 2;
|
||||
}
|
||||
if ((90 + leap) <= day && day < (120 + leap)) {
|
||||
return 3;
|
||||
}
|
||||
if ((120 + leap) <= day && day < (151 + leap)) {
|
||||
return 4;
|
||||
}
|
||||
if ((151 + leap) <= day && day < (181 + leap)) {
|
||||
return 5;
|
||||
}
|
||||
if ((181 + leap) <= day && day < (212 + leap)) {
|
||||
return 6;
|
||||
}
|
||||
if ((212 + leap) <= day && day < (243 + leap)) {
|
||||
return 7;
|
||||
}
|
||||
if ((243 + leap) <= day && day < (273 + leap)) {
|
||||
return 8;
|
||||
}
|
||||
if ((273 + leap) <= day && day < (304 + leap)) {
|
||||
return 9;
|
||||
}
|
||||
if ((304 + leap) <= day && day < (334 + leap)) {
|
||||
return 10;
|
||||
}
|
||||
if ((334 + leap) <= day && day < (365 + leap)) {
|
||||
return 11;
|
||||
}
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.5
|
||||
DateFromTime: function DateFromTime(t) {
|
||||
var m = this.MonthFromTime(t);
|
||||
var d = this.DayWithinYear(t);
|
||||
if (m === 0) {
|
||||
return d + 1;
|
||||
}
|
||||
if (m === 1) {
|
||||
return d - 30;
|
||||
}
|
||||
var leap = this.InLeapYear(t);
|
||||
if (m === 2) {
|
||||
return d - 58 - leap;
|
||||
}
|
||||
if (m === 3) {
|
||||
return d - 89 - leap;
|
||||
}
|
||||
if (m === 4) {
|
||||
return d - 119 - leap;
|
||||
}
|
||||
if (m === 5) {
|
||||
return d - 150 - leap;
|
||||
}
|
||||
if (m === 6) {
|
||||
return d - 180 - leap;
|
||||
}
|
||||
if (m === 7) {
|
||||
return d - 211 - leap;
|
||||
}
|
||||
if (m === 8) {
|
||||
return d - 242 - leap;
|
||||
}
|
||||
if (m === 9) {
|
||||
return d - 272 - leap;
|
||||
}
|
||||
if (m === 10) {
|
||||
return d - 303 - leap;
|
||||
}
|
||||
if (m === 11) {
|
||||
return d - 333 - leap;
|
||||
}
|
||||
throw new $EvalError('Assertion failed: MonthFromTime returned an impossible value: ' + m);
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.12
|
||||
MakeDay: function MakeDay(year, month, date) {
|
||||
if (!$isFinite(year) || !$isFinite(month) || !$isFinite(date)) {
|
||||
return NaN;
|
||||
}
|
||||
var y = this.ToInteger(year);
|
||||
var m = this.ToInteger(month);
|
||||
var dt = this.ToInteger(date);
|
||||
var ym = y + $floor(m / 12);
|
||||
var mn = mod(m, 12);
|
||||
var t = $DateUTC(ym, mn, 1);
|
||||
if (this.YearFromTime(t) !== ym || this.MonthFromTime(t) !== mn || this.DateFromTime(t) !== 1) {
|
||||
return NaN;
|
||||
}
|
||||
return this.Day(t) + dt - 1;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.13
|
||||
MakeDate: function MakeDate(day, time) {
|
||||
if (!$isFinite(day) || !$isFinite(time)) {
|
||||
return NaN;
|
||||
}
|
||||
return (day * msPerDay) + time;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.11
|
||||
MakeTime: function MakeTime(hour, min, sec, ms) {
|
||||
if (!$isFinite(hour) || !$isFinite(min) || !$isFinite(sec) || !$isFinite(ms)) {
|
||||
return NaN;
|
||||
}
|
||||
var h = this.ToInteger(hour);
|
||||
var m = this.ToInteger(min);
|
||||
var s = this.ToInteger(sec);
|
||||
var milli = this.ToInteger(ms);
|
||||
var t = (h * msPerHour) + (m * msPerMinute) + (s * msPerSecond) + milli;
|
||||
return t;
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-15.9.1.14
|
||||
TimeClip: function TimeClip(time) {
|
||||
if (!$isFinite(time) || $abs(time) > 8.64e15) {
|
||||
return NaN;
|
||||
}
|
||||
return $Number(new $Date(this.ToNumber(time)));
|
||||
},
|
||||
|
||||
// https://ecma-international.org/ecma-262/5.1/#sec-5.2
|
||||
modulo: function modulo(x, y) {
|
||||
return mod(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ES5;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./es2015');
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./es2016');
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
var $SyntaxError = GetIntrinsic('%SyntaxError%');
|
||||
|
||||
var has = require('has');
|
||||
|
||||
var predicates = {
|
||||
// https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type
|
||||
'Property Descriptor': function isPropertyDescriptor(ES, Desc) {
|
||||
if (ES.Type(Desc) !== 'Object') {
|
||||
return false;
|
||||
}
|
||||
var allowed = {
|
||||
'[[Configurable]]': true,
|
||||
'[[Enumerable]]': true,
|
||||
'[[Get]]': true,
|
||||
'[[Set]]': true,
|
||||
'[[Value]]': true,
|
||||
'[[Writable]]': true
|
||||
};
|
||||
|
||||
for (var key in Desc) { // eslint-disable-line
|
||||
if (has(Desc, key) && !allowed[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var isData = has(Desc, '[[Value]]');
|
||||
var IsAccessor = has(Desc, '[[Get]]') || has(Desc, '[[Set]]');
|
||||
if (isData && IsAccessor) {
|
||||
throw new $TypeError('Property Descriptors may not be both accessor and data descriptors');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function assertRecord(ES, recordType, argumentName, value) {
|
||||
var predicate = predicates[recordType];
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new $SyntaxError('unknown record type: ' + recordType);
|
||||
}
|
||||
if (!predicate(ES, value)) {
|
||||
throw new $TypeError(argumentName + ' must be a ' + recordType);
|
||||
}
|
||||
};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var has = require('has');
|
||||
|
||||
var $assign = GetIntrinsic('%Object%').assign;
|
||||
|
||||
module.exports = function assign(target, source) {
|
||||
if ($assign) {
|
||||
return $assign(target, source);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (var key in source) {
|
||||
if (has(source, key)) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var bind = require('function-bind');
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var $Function = GetIntrinsic('%Function%');
|
||||
var $apply = $Function.apply;
|
||||
var $call = $Function.call;
|
||||
|
||||
module.exports = function callBind() {
|
||||
return bind.apply($call, arguments);
|
||||
};
|
||||
|
||||
module.exports.apply = function applyBind() {
|
||||
return bind.apply($apply, arguments);
|
||||
};
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var callBind = require('./callBind');
|
||||
|
||||
var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
|
||||
|
||||
module.exports = function callBoundIntrinsic(name, allowMissing) {
|
||||
var intrinsic = GetIntrinsic(name, !!allowMissing);
|
||||
if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.')) {
|
||||
return callBind(intrinsic);
|
||||
}
|
||||
return intrinsic;
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function every(array, predicate) {
|
||||
for (var i = 0; i < array.length; i += 1) {
|
||||
if (!predicate(array[i], i, array)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function forEach(array, callback) {
|
||||
for (var i = 0; i < array.length; i += 1) {
|
||||
callback(array[i], i, array); // eslint-disable-line callback-return
|
||||
}
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var $isNaN = Number.isNaN || function (a) { return a !== a; };
|
||||
|
||||
module.exports = Number.isFinite || function (x) { return typeof x === 'number' && !$isNaN(x) && x !== Infinity && x !== -Infinity; };
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = Number.isNaN || function isNaN(a) {
|
||||
return a !== a;
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var $strSlice = require('../helpers/callBound')('String.prototype.slice');
|
||||
|
||||
module.exports = function isPrefixOf(prefix, string) {
|
||||
if (prefix === string) {
|
||||
return true;
|
||||
}
|
||||
if (prefix.length > string.length) {
|
||||
return false;
|
||||
}
|
||||
return $strSlice(string, 0, prefix.length) === prefix;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function isPrimitive(value) {
|
||||
return value === null || (typeof value !== 'function' && typeof value !== 'object');
|
||||
};
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var has = require('has');
|
||||
var $TypeError = GetIntrinsic('%TypeError%');
|
||||
|
||||
module.exports = function IsPropertyDescriptor(ES, Desc) {
|
||||
if (ES.Type(Desc) !== 'Object') {
|
||||
return false;
|
||||
}
|
||||
var allowed = {
|
||||
'[[Configurable]]': true,
|
||||
'[[Enumerable]]': true,
|
||||
'[[Get]]': true,
|
||||
'[[Set]]': true,
|
||||
'[[Value]]': true,
|
||||
'[[Writable]]': true
|
||||
};
|
||||
|
||||
for (var key in Desc) { // eslint-disable-line
|
||||
if (has(Desc, key) && !allowed[key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (ES.IsDataDescriptor(Desc) && ES.IsAccessorDescriptor(Desc)) {
|
||||
throw new $TypeError('Property Descriptors may not be both accessor and data descriptors');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var every = require('./every');
|
||||
|
||||
module.exports = function isSamePropertyDescriptor(ES, D1, D2) {
|
||||
var fields = [
|
||||
'[[Configurable]]',
|
||||
'[[Enumerable]]',
|
||||
'[[Get]]',
|
||||
'[[Set]]',
|
||||
'[[Value]]',
|
||||
'[[Writable]]'
|
||||
];
|
||||
return every(fields, function (field) {
|
||||
if ((field in D1) !== (field in D2)) {
|
||||
return false;
|
||||
}
|
||||
return ES.SameValue(D1[field], D2[field]);
|
||||
});
|
||||
};
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var $Math = GetIntrinsic('%Math%');
|
||||
var $Number = GetIntrinsic('%Number%');
|
||||
|
||||
module.exports = $Number.MAX_SAFE_INTEGER || $Math.pow(2, 53) - 1;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function mod(number, modulo) {
|
||||
var remain = number % modulo;
|
||||
return Math.floor(remain >= 0 ? remain : remain + modulo);
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var $test = GetIntrinsic('RegExp.prototype.test');
|
||||
|
||||
var callBind = require('./callBind');
|
||||
|
||||
module.exports = function regexTester(regex) {
|
||||
return callBind($test, regex);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function sign(number) {
|
||||
return number >= 0 ? 1 : -1;
|
||||
};
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var assign = require('./helpers/assign');
|
||||
|
||||
var ES5 = require('./es5');
|
||||
var ES2015 = require('./es2015');
|
||||
var ES2016 = require('./es2016');
|
||||
var ES2017 = require('./es2017');
|
||||
var ES2018 = require('./es2018');
|
||||
var ES2019 = require('./es2019');
|
||||
|
||||
var ES = {
|
||||
ES5: ES5,
|
||||
ES6: ES2015,
|
||||
ES2015: ES2015,
|
||||
ES7: ES2016,
|
||||
ES2016: ES2016,
|
||||
ES2017: ES2017,
|
||||
ES2018: ES2018,
|
||||
ES2019: ES2019
|
||||
};
|
||||
assign(ES, ES5);
|
||||
delete ES.CheckObjectCoercible; // renamed in ES6 to RequireObjectCoercible
|
||||
assign(ES, ES2015);
|
||||
|
||||
module.exports = ES;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"rules": {
|
||||
"id-length": 0,
|
||||
},
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"name": "es-abstract",
|
||||
"version": "1.15.0",
|
||||
"author": {
|
||||
"name": "Jordan Harband",
|
||||
"email": "ljharb@gmail.com",
|
||||
"url": "http://ljharb.codes"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Jordan Harband",
|
||||
"email": "ljharb@gmail.com",
|
||||
"url": "http://ljharb.codes"
|
||||
}
|
||||
],
|
||||
"description": "ECMAScript spec abstract operations.",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"prepublish": "safe-publish-latest",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run tests-only",
|
||||
"posttest": "npx aud --production",
|
||||
"tests-only": "node test",
|
||||
"coverage": "nyc npm run --silent tests-only >/dev/null",
|
||||
"postcoverage": "nyc report",
|
||||
"lint": "eslint .",
|
||||
"eccheck": "eclint check *.js **/*.js > /dev/null"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ljharb/es-abstract.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ECMAScript",
|
||||
"ES",
|
||||
"abstract",
|
||||
"operation",
|
||||
"abstract operation",
|
||||
"JavaScript",
|
||||
"ES5",
|
||||
"ES6",
|
||||
"ES7"
|
||||
],
|
||||
"dependencies": {
|
||||
"es-to-primitive": "^1.2.0",
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.3",
|
||||
"has-symbols": "^1.0.0",
|
||||
"is-callable": "^1.1.4",
|
||||
"is-regex": "^1.0.4",
|
||||
"object-inspect": "^1.6.0",
|
||||
"object-keys": "^1.1.1",
|
||||
"string.prototype.trimleft": "^2.1.0",
|
||||
"string.prototype.trimright": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ljharb/eslint-config": "^14.1.0",
|
||||
"cheerio": "^1.0.0-rc.3",
|
||||
"diff": "^4.0.1",
|
||||
"eclint": "^2.8.1",
|
||||
"eslint": "^6.5.1",
|
||||
"foreach": "^2.0.5",
|
||||
"nyc": "^10.3.2",
|
||||
"object-is": "^1.0.1",
|
||||
"object.assign": "^4.1.0",
|
||||
"object.fromentries": "^2.0.0",
|
||||
"replace": "^1.1.1",
|
||||
"safe-publish-latest": "^1.1.3",
|
||||
"semver": "^6.3.0",
|
||||
"tape": "^4.11.0"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/index.js",
|
||||
"browsers": [
|
||||
"iexplore/6.0..latest",
|
||||
"firefox/3.0..6.0",
|
||||
"firefox/15.0..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/4.0..10.0",
|
||||
"chrome/20.0..latest",
|
||||
"chrome/canary",
|
||||
"opera/10.0..latest",
|
||||
"opera/next",
|
||||
"safari/4.0..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"greenkeeper": {
|
||||
"//": "nyc is ignored because it requires node 4+, and we support older than that",
|
||||
"ignore": [
|
||||
"nyc"
|
||||
]
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"rules": {
|
||||
"id-length": 0,
|
||||
"max-lines": 0,
|
||||
"max-lines-per-function": 0,
|
||||
"max-statements-per-line": [2, { "max": 3 }],
|
||||
"max-nested-callbacks": [2, 4],
|
||||
"max-statements": 0,
|
||||
"no-implicit-coercion": 1,
|
||||
"no-invalid-this": 1,
|
||||
"object-curly-newline": 0,
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('../GetIntrinsic');
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('foreach');
|
||||
var debug = require('object-inspect');
|
||||
|
||||
var v = require('./helpers/values');
|
||||
|
||||
test('export', function (t) {
|
||||
t.equal(typeof GetIntrinsic, 'function', 'it is a function');
|
||||
t.equal(GetIntrinsic.length, 2, 'function has length of 2');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('throws', function (t) {
|
||||
t['throws'](
|
||||
function () { GetIntrinsic('not an intrinsic'); },
|
||||
SyntaxError,
|
||||
'nonexistent intrinsic throws a syntax error'
|
||||
);
|
||||
|
||||
forEach(v.nonBooleans, function (nonBoolean) {
|
||||
t['throws'](
|
||||
function () { GetIntrinsic('%', nonBoolean); },
|
||||
TypeError,
|
||||
debug(nonBoolean) + ' is not a Boolean'
|
||||
);
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('base intrinsics', function (t) {
|
||||
t.equal(GetIntrinsic('%Object%'), Object, '%Object% yields Object');
|
||||
t.equal(GetIntrinsic('%Array%'), Array, '%Array% yields Array');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('dotted paths', function (t) {
|
||||
t.equal(GetIntrinsic('%Object.prototype.toString%'), Object.prototype.toString, '%Object.prototype.toString% yields Object.prototype.toString');
|
||||
t.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push, '%Array.prototype.push% yields Array.prototype.push');
|
||||
|
||||
t.end();
|
||||
});
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var keys = require('object-keys');
|
||||
var forEach = require('foreach');
|
||||
|
||||
module.exports = function diffOperations(actual, expected, expectedMissing) {
|
||||
var actualKeys = keys(actual);
|
||||
var expectedKeys = keys(expected);
|
||||
|
||||
var extra = [];
|
||||
var missing = [];
|
||||
forEach(actualKeys, function (op) {
|
||||
if (!(op in expected)) {
|
||||
extra.push(op);
|
||||
} else if (expectedMissing.indexOf(op) !== -1) {
|
||||
extra.push(op);
|
||||
}
|
||||
});
|
||||
forEach(expectedKeys, function (op) {
|
||||
if (typeof actual[op] !== 'function' && expectedMissing.indexOf(op) === -1) {
|
||||
missing.push(op);
|
||||
}
|
||||
});
|
||||
|
||||
return { missing: missing, extra: extra };
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var ES = require('../').ES2015;
|
||||
|
||||
var ops = require('../operations/2015');
|
||||
|
||||
var expectedMissing = ['Construct', 'CreateArrayFromList', 'CreateListFromArrayLike', 'CreateListIterator', 'NormalCompletion', 'RegExpBuiltinExec'];
|
||||
|
||||
require('./tests').es2015(ES, ops, expectedMissing);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var ES = require('../').ES2016;
|
||||
|
||||
var ops = require('../operations/2016');
|
||||
|
||||
var expectedMissing = ['AddRestrictedFunctionProperties', 'AllocateArrayBuffer', 'AllocateTypedArray', 'AllocateTypedArrayBuffer', 'BlockDeclarationInstantiation', 'BoundFunctionCreate', 'Canonicalize', 'CharacterRange', 'CharacterRangeOrUnion', 'CharacterSetMatcher', 'CloneArrayBuffer', 'Completion', 'Construct', 'CopyDataBlockBytes', 'CreateArrayFromList', 'CreateArrayIterator', 'CreateBuiltinFunction', 'CreateByteDataBlock', 'CreateDynamicFunction', 'CreateIntrinsics', 'CreateListFromArrayLike', 'CreateListIterator', 'CreateMapIterator', 'CreateMappedArgumentsObject', 'CreatePerIterationEnvironment', 'CreateRealm', 'CreateResolvingFunctions', 'CreateSetIterator', 'CreateStringIterator', 'CreateUnmappedArgumentsObject', 'Decode', 'DetachArrayBuffer', 'Encode', 'EnqueueJob', 'EnumerateObjectProperties', 'EscapeRegExpPattern', 'EvalDeclarationInstantiation', 'EvaluateCall', 'EvaluateDirectCall', 'EvaluateNew', 'ForBodyEvaluation', 'ForIn/OfBodyEvaluation', 'ForIn/OfHeadEvaluation', 'FulfillPromise', 'FunctionAllocate', 'FunctionCreate', 'FunctionDeclarationInstantiation', 'FunctionInitialize', 'GeneratorFunctionCreate', 'GeneratorResume', 'GeneratorResumeAbrupt', 'GeneratorStart', 'GeneratorValidate', 'GeneratorYield', 'GetActiveScriptOrModule', 'GetFunctionRealm', 'GetGlobalObject', 'GetIdentifierReference', 'GetModuleNamespace', 'GetNewTarget', 'GetPrototypeFromConstructor', 'GetSuperConstructor', 'GetTemplateObject', 'GetThisEnvironment', 'GetThisValue', 'GetValue', 'GetValueFromBuffer', 'GetViewValue', 'GlobalDeclarationInstantiation', 'HostPromiseRejectionTracker', 'HostReportErrors', 'HostResolveImportedModule', 'IfAbruptRejectPromise', 'ImportedLocalNames', 'InitializeBoundName', 'InitializeHostDefinedRealm', 'InitializeReferencedBinding', 'IntegerIndexedElementGet', 'IntegerIndexedElementSet', 'IntegerIndexedObjectCreate', 'InternalizeJSONProperty', 'IsAnonymousFunctionDefinition', 'IsCompatiblePropertyDescriptor', 'IsDetachedBuffer', 'IsInTailPosition', 'IsLabelledFunction', 'IsWordChar', 'LocalTime', 'LoopContinues', 'MakeArgGetter', 'MakeArgSetter', 'MakeClassConstructor', 'MakeConstructor', 'MakeMethod', 'MakeSuperPropertyReference', 'ModuleNamespaceCreate', 'NewDeclarativeEnvironment', 'NewFunctionEnvironment', 'NewGlobalEnvironment', 'NewModuleEnvironment', 'NewObjectEnvironment', 'NewPromiseCapability', 'NextJob', 'NormalCompletion', 'ObjectDefineProperties', 'OrdinaryCallBindThis', 'OrdinaryCallEvaluateBody', 'OrdinaryCreateFromConstructor', 'OrdinaryDelete', 'OrdinaryGet', 'OrdinaryGetPrototypeOf', 'OrdinaryIsExtensible', 'OrdinaryOwnPropertyKeys', 'OrdinaryPreventExtensions', 'OrdinarySet', 'OrdinarySetPrototypeOf', 'ParseModule', 'ParseScript', 'PerformEval', 'PerformPromiseAll', 'PerformPromiseRace', 'PerformPromiseThen', 'PrepareForOrdinaryCall', 'PrepareForTailCall', 'PromiseReactionJob', 'PromiseResolveThenableJob', 'ProxyCreate', 'PutValue', 'QuoteJSONString', 'RegExpAlloc', 'RegExpBuiltinExec', 'RegExpCreate', 'RegExpInitialize', 'RejectPromise', 'RepeatMatcher', 'ResolveBinding', 'ResolveThisBinding', 'ReturnIfAbrupt', 'ScriptEvaluation', 'ScriptEvaluationJob', 'SerializeJSONArray', 'SerializeJSONObject', 'SerializeJSONProperty', 'SetDefaultGlobalBindings', 'SetFunctionName', 'SetRealmGlobalObject', 'SetValueInBuffer', 'SetViewValue', 'SortCompare', 'SplitMatch', 'StringCreate', 'ToString Applied to the Number Type', 'TopLevelModuleEvaluationJob', 'TriggerPromiseReactions', 'TypedArrayCreate', 'TypedArraySpeciesCreate', 'UTC', 'UTF16Decode', 'UTF16Encoding', 'UpdateEmpty', 'ValidateTypedArray', 'abs', 'floor', 'max', 'min'];
|
||||
|
||||
require('./tests').es2016(ES, ops, expectedMissing);
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
var ES = require('../').ES2017;
|
||||
|
||||
var ops = require('../operations/2017');
|
||||
|
||||
var expectedMissing = ['AddRestrictedFunctionProperties', 'AddWaiter', 'AgentCanSuspend', 'AgentSignifier', 'AllocateArrayBuffer', 'AllocateSharedArrayBuffer', 'AllocateTypedArray', 'AllocateTypedArrayBuffer', 'AsyncFunctionAwait', 'AsyncFunctionCreate', 'AsyncFunctionStart', 'AtomicLoad', 'AtomicReadModifyWrite', 'BlockDeclarationInstantiation', 'BoundFunctionCreate', 'Canonicalize', 'CharacterRange', 'CharacterRangeOrUnion', 'CharacterSetMatcher', 'CloneArrayBuffer', 'Completion', 'ComposeWriteEventBytes', 'Construct', 'CopyDataBlockBytes', 'CreateArrayFromList', 'CreateArrayIterator', 'CreateBuiltinFunction', 'CreateByteDataBlock', 'CreateDynamicFunction', 'CreateIntrinsics', 'CreateListFromArrayLike', 'CreateListIterator', 'CreateMapIterator', 'CreateMappedArgumentsObject', 'CreatePerIterationEnvironment', 'CreateRealm', 'CreateResolvingFunctions', 'CreateSetIterator', 'CreateSharedByteDataBlock', 'CreateStringIterator', 'CreateUnmappedArgumentsObject', 'Decode', 'DetachArrayBuffer', 'Encode', 'EnqueueJob', 'EnterCriticalSection', 'EnumerateObjectProperties', 'EscapeRegExpPattern', 'EvalDeclarationInstantiation', 'EvaluateCall', 'EvaluateDirectCall', 'EvaluateNew', 'EventSet', 'ForBodyEvaluation', 'ForIn/OfBodyEvaluation', 'ForIn/OfHeadEvaluation', 'FulfillPromise', 'FunctionAllocate', 'FunctionCreate', 'FunctionDeclarationInstantiation', 'FunctionInitialize', 'GeneratorFunctionCreate', 'GeneratorResume', 'GeneratorResumeAbrupt', 'GeneratorStart', 'GeneratorValidate', 'GeneratorYield', 'GetActiveScriptOrModule', 'GetBase', 'GetFunctionRealm', 'GetGlobalObject', 'GetIdentifierReference', 'GetModifySetValueInBuffer', 'GetModuleNamespace', 'GetNewTarget', 'GetPrototypeFromConstructor', 'GetReferencedName', 'GetSuperConstructor', 'GetTemplateObject', 'GetThisEnvironment', 'GetThisValue', 'GetValue', 'GetValueFromBuffer', 'GetViewValue', 'GetWaiterList', 'GlobalDeclarationInstantiation', 'HasPrimitiveBase', 'HostEnsureCanCompileStrings', 'HostEventSet', 'HostPromiseRejectionTracker', 'HostReportErrors', 'HostResolveImportedModule', 'IfAbruptRejectPromise', 'ImportedLocalNames', 'InitializeBoundName', 'InitializeHostDefinedRealm', 'InitializeReferencedBinding', 'IntegerIndexedElementGet', 'IntegerIndexedElementSet', 'IntegerIndexedObjectCreate', 'InternalizeJSONProperty', 'IsAnonymousFunctionDefinition', 'IsCompatiblePropertyDescriptor', 'IsDetachedBuffer', 'IsInTailPosition', 'IsLabelledFunction', 'IsPropertyReference', 'IsSharedArrayBuffer', 'IsStrictReference', 'IsSuperReference', 'IsUnresolvableReference', 'IsWordChar', 'LeaveCriticalSection', 'LocalTime', 'LoopContinues', 'MakeArgGetter', 'MakeArgSetter', 'MakeClassConstructor', 'MakeConstructor', 'MakeMethod', 'MakeSuperPropertyReference', 'ModuleNamespaceCreate', 'NewDeclarativeEnvironment', 'NewFunctionEnvironment', 'NewGlobalEnvironment', 'NewModuleEnvironment', 'NewObjectEnvironment', 'NewPromiseCapability', 'NormalCompletion', 'NumberToRawBytes', 'ObjectDefineProperties', 'OrdinaryCallBindThis', 'OrdinaryCallEvaluateBody', 'OrdinaryCreateFromConstructor', 'OrdinaryDelete', 'OrdinaryGet', 'OrdinaryGetPrototypeOf', 'OrdinaryIsExtensible', 'OrdinaryOwnPropertyKeys', 'OrdinaryPreventExtensions', 'OrdinarySet', 'OrdinarySetPrototypeOf', 'OrdinaryToPrimitive', 'ParseModule', 'ParseScript', 'PerformEval', 'PerformPromiseAll', 'PerformPromiseRace', 'PerformPromiseThen', 'PrepareForOrdinaryCall', 'PrepareForTailCall', 'PromiseReactionJob', 'PromiseResolveThenableJob', 'ProxyCreate', 'PutValue', 'QuoteJSONString', 'RawBytesToNumber', 'RegExpAlloc', 'RegExpBuiltinExec', 'RegExpCreate', 'RegExpInitialize', 'RejectPromise', 'RemoveWaiter', 'RemoveWaiters', 'RepeatMatcher', 'ResolveBinding', 'ResolveThisBinding', 'ReturnIfAbrupt', 'RunJobs', 'ScriptEvaluation', 'ScriptEvaluationJob', 'SerializeJSONArray', 'SerializeJSONObject', 'SerializeJSONProperty', 'SetDefaultGlobalBindings', 'SetFunctionName', 'SetImmutablePrototype', 'SetRealmGlobalObject', 'SetValueInBuffer', 'SetViewValue', 'SharedDataBlockEventSet', 'SortCompare', 'SplitMatch', 'StringCreate', 'StringGetOwnProperty', 'Suspend', 'ToString Applied to the Number Type', 'TopLevelModuleEvaluationJob', 'TriggerPromiseReactions', 'TypedArrayCreate', 'TypedArraySpeciesCreate', 'UTC', 'UTF16Decode', 'UTF16Encoding', 'UpdateEmpty', 'ValidateAtomicAccess', 'ValidateSharedIntegerTypedArray', 'ValidateTypedArray', 'ValueOfReadEvent', 'WakeWaiter', 'WordCharacters', 'abs', 'agent-order', 'floor', 'happens-before', 'host-synchronizes-with', 'max', 'memory-order', 'min', 'reads-bytes-from', 'reads-from', 'synchronizes-with'];
|
||||
|
||||
require('./tests').es2017(ES, ops, expectedMissing);
|
||||
+9
File diff suppressed because one or more lines are too long
+9
File diff suppressed because one or more lines are too long
+782
@@ -0,0 +1,782 @@
|
||||
'use strict';
|
||||
|
||||
var ES = require('../').ES5;
|
||||
var test = require('tape');
|
||||
|
||||
var forEach = require('foreach');
|
||||
var is = require('object-is');
|
||||
var debug = require('object-inspect');
|
||||
|
||||
var v = require('./helpers/values');
|
||||
|
||||
test('ToPrimitive', function (t) {
|
||||
t.test('primitives', function (st) {
|
||||
var testPrimitive = function (primitive) {
|
||||
st.ok(is(ES.ToPrimitive(primitive), primitive), debug(primitive) + ' is returned correctly');
|
||||
};
|
||||
forEach(v.primitives, testPrimitive);
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('objects', function (st) {
|
||||
st.equal(ES.ToPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject coerces to valueOf');
|
||||
st.equal(ES.ToPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf');
|
||||
st.equal(ES.ToPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to toString');
|
||||
st.equal(ES.ToPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to toString');
|
||||
st.equal(ES.ToPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns toString');
|
||||
st.equal(ES.ToPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');
|
||||
st.equal(ES.ToPrimitive({}), '[object Object]', '{} with no hint coerces to Object#toString');
|
||||
st.equal(ES.ToPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString');
|
||||
st.equal(ES.ToPrimitive({}, Number), '[object Object]', '{} with hint Number coerces to Object#toString');
|
||||
st['throws'](function () { return ES.ToPrimitive(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws a TypeError');
|
||||
st['throws'](function () { return ES.ToPrimitive(v.uncoercibleFnObject); }, TypeError, 'uncoercibleFnObject throws a TypeError');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToBoolean', function (t) {
|
||||
t.equal(false, ES.ToBoolean(undefined), 'undefined coerces to false');
|
||||
t.equal(false, ES.ToBoolean(null), 'null coerces to false');
|
||||
t.equal(false, ES.ToBoolean(false), 'false returns false');
|
||||
t.equal(true, ES.ToBoolean(true), 'true returns true');
|
||||
forEach([0, -0, NaN], function (falsyNumber) {
|
||||
t.equal(false, ES.ToBoolean(falsyNumber), 'falsy number ' + falsyNumber + ' coerces to false');
|
||||
});
|
||||
forEach([Infinity, 42, 1, -Infinity], function (truthyNumber) {
|
||||
t.equal(true, ES.ToBoolean(truthyNumber), 'truthy number ' + truthyNumber + ' coerces to true');
|
||||
});
|
||||
t.equal(false, ES.ToBoolean(''), 'empty string coerces to false');
|
||||
t.equal(true, ES.ToBoolean('foo'), 'nonempty string coerces to true');
|
||||
forEach(v.objects, function (obj) {
|
||||
t.equal(true, ES.ToBoolean(obj), 'object coerces to true');
|
||||
});
|
||||
t.equal(true, ES.ToBoolean(v.uncoercibleObject), 'uncoercibleObject coerces to true');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToNumber', function (t) {
|
||||
t.ok(is(NaN, ES.ToNumber(undefined)), 'undefined coerces to NaN');
|
||||
t.ok(is(ES.ToNumber(null), 0), 'null coerces to +0');
|
||||
t.ok(is(ES.ToNumber(false), 0), 'false coerces to +0');
|
||||
t.equal(1, ES.ToNumber(true), 'true coerces to 1');
|
||||
t.ok(is(NaN, ES.ToNumber(NaN)), 'NaN returns itself');
|
||||
forEach([0, -0, 42, Infinity, -Infinity], function (num) {
|
||||
t.equal(num, ES.ToNumber(num), num + ' returns itself');
|
||||
});
|
||||
forEach(['foo', '0', '4a', '2.0', 'Infinity', '-Infinity'], function (numString) {
|
||||
t.ok(is(+numString, ES.ToNumber(numString)), '"' + numString + '" coerces to ' + Number(numString));
|
||||
});
|
||||
forEach(v.objects, function (object) {
|
||||
t.ok(is(ES.ToNumber(object), ES.ToNumber(ES.ToPrimitive(object))), 'object ' + object + ' coerces to same as ToPrimitive of object does');
|
||||
});
|
||||
t['throws'](function () { return ES.ToNumber(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToInteger', function (t) {
|
||||
t.ok(is(0, ES.ToInteger(NaN)), 'NaN coerces to +0');
|
||||
forEach([0, Infinity, 42], function (num) {
|
||||
t.ok(is(num, ES.ToInteger(num)), num + ' returns itself');
|
||||
t.ok(is(-num, ES.ToInteger(-num)), '-' + num + ' returns itself');
|
||||
});
|
||||
t.equal(3, ES.ToInteger(Math.PI), 'pi returns 3');
|
||||
t['throws'](function () { return ES.ToInteger(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToInt32', function (t) {
|
||||
t.ok(is(0, ES.ToInt32(NaN)), 'NaN coerces to +0');
|
||||
forEach([0, Infinity], function (num) {
|
||||
t.ok(is(0, ES.ToInt32(num)), num + ' returns +0');
|
||||
t.ok(is(0, ES.ToInt32(-num)), '-' + num + ' returns +0');
|
||||
});
|
||||
t['throws'](function () { return ES.ToInt32(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
|
||||
t.ok(is(ES.ToInt32(0x100000000), 0), '2^32 returns +0');
|
||||
t.ok(is(ES.ToInt32(0x100000000 - 1), -1), '2^32 - 1 returns -1');
|
||||
t.ok(is(ES.ToInt32(0x80000000), -0x80000000), '2^31 returns -2^31');
|
||||
t.ok(is(ES.ToInt32(0x80000000 - 1), 0x80000000 - 1), '2^31 - 1 returns 2^31 - 1');
|
||||
forEach([0, Infinity, NaN, 0x100000000, 0x80000000, 0x10000, 0x42], function (num) {
|
||||
t.ok(is(ES.ToInt32(num), ES.ToInt32(ES.ToUint32(num))), 'ToInt32(x) === ToInt32(ToUint32(x)) for 0x' + num.toString(16));
|
||||
t.ok(is(ES.ToInt32(-num), ES.ToInt32(ES.ToUint32(-num))), 'ToInt32(x) === ToInt32(ToUint32(x)) for -0x' + num.toString(16));
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToUint32', function (t) {
|
||||
t.ok(is(0, ES.ToUint32(NaN)), 'NaN coerces to +0');
|
||||
forEach([0, Infinity], function (num) {
|
||||
t.ok(is(0, ES.ToUint32(num)), num + ' returns +0');
|
||||
t.ok(is(0, ES.ToUint32(-num)), '-' + num + ' returns +0');
|
||||
});
|
||||
t['throws'](function () { return ES.ToUint32(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
|
||||
t.ok(is(ES.ToUint32(0x100000000), 0), '2^32 returns +0');
|
||||
t.ok(is(ES.ToUint32(0x100000000 - 1), 0x100000000 - 1), '2^32 - 1 returns 2^32 - 1');
|
||||
t.ok(is(ES.ToUint32(0x80000000), 0x80000000), '2^31 returns 2^31');
|
||||
t.ok(is(ES.ToUint32(0x80000000 - 1), 0x80000000 - 1), '2^31 - 1 returns 2^31 - 1');
|
||||
forEach([0, Infinity, NaN, 0x100000000, 0x80000000, 0x10000, 0x42], function (num) {
|
||||
t.ok(is(ES.ToUint32(num), ES.ToUint32(ES.ToInt32(num))), 'ToUint32(x) === ToUint32(ToInt32(x)) for 0x' + num.toString(16));
|
||||
t.ok(is(ES.ToUint32(-num), ES.ToUint32(ES.ToInt32(-num))), 'ToUint32(x) === ToUint32(ToInt32(x)) for -0x' + num.toString(16));
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToUint16', function (t) {
|
||||
t.ok(is(0, ES.ToUint16(NaN)), 'NaN coerces to +0');
|
||||
forEach([0, Infinity], function (num) {
|
||||
t.ok(is(0, ES.ToUint16(num)), num + ' returns +0');
|
||||
t.ok(is(0, ES.ToUint16(-num)), '-' + num + ' returns +0');
|
||||
});
|
||||
t['throws'](function () { return ES.ToUint16(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
|
||||
t.ok(is(ES.ToUint16(0x100000000), 0), '2^32 returns +0');
|
||||
t.ok(is(ES.ToUint16(0x100000000 - 1), 0x10000 - 1), '2^32 - 1 returns 2^16 - 1');
|
||||
t.ok(is(ES.ToUint16(0x80000000), 0), '2^31 returns +0');
|
||||
t.ok(is(ES.ToUint16(0x80000000 - 1), 0x10000 - 1), '2^31 - 1 returns 2^16 - 1');
|
||||
t.ok(is(ES.ToUint16(0x10000), 0), '2^16 returns +0');
|
||||
t.ok(is(ES.ToUint16(0x10000 - 1), 0x10000 - 1), '2^16 - 1 returns 2^16 - 1');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToString', function (t) {
|
||||
t['throws'](function () { return ES.ToString(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToObject', function (t) {
|
||||
t['throws'](function () { return ES.ToObject(undefined); }, TypeError, 'undefined throws');
|
||||
t['throws'](function () { return ES.ToObject(null); }, TypeError, 'null throws');
|
||||
forEach(v.numbers, function (number) {
|
||||
var obj = ES.ToObject(number);
|
||||
t.equal(typeof obj, 'object', 'number ' + number + ' coerces to object');
|
||||
t.equal(true, obj instanceof Number, 'object of ' + number + ' is Number object');
|
||||
t.ok(is(obj.valueOf(), number), 'object of ' + number + ' coerces to ' + number);
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('CheckObjectCoercible', function (t) {
|
||||
t['throws'](function () { return ES.CheckObjectCoercible(undefined); }, TypeError, 'undefined throws');
|
||||
t['throws'](function () { return ES.CheckObjectCoercible(null); }, TypeError, 'null throws');
|
||||
var checkCoercible = function (value) {
|
||||
t.doesNotThrow(function () { return ES.CheckObjectCoercible(value); }, debug(value) + ' does not throw');
|
||||
};
|
||||
forEach(v.objects.concat(v.nonNullPrimitives), checkCoercible);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('IsCallable', function (t) {
|
||||
t.equal(true, ES.IsCallable(function () {}), 'function is callable');
|
||||
var nonCallables = [/a/g, {}, Object.prototype, NaN].concat(v.primitives);
|
||||
forEach(nonCallables, function (nonCallable) {
|
||||
t.equal(false, ES.IsCallable(nonCallable), debug(nonCallable) + ' is not callable');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('SameValue', function (t) {
|
||||
t.equal(true, ES.SameValue(NaN, NaN), 'NaN is SameValue as NaN');
|
||||
t.equal(false, ES.SameValue(0, -0), '+0 is not SameValue as -0');
|
||||
forEach(v.objects.concat(v.primitives), function (val) {
|
||||
t.equal(val === val, ES.SameValue(val, val), debug(val) + ' is SameValue to itself');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Type', function (t) {
|
||||
t.equal(ES.Type(), 'Undefined', 'Type() is Undefined');
|
||||
t.equal(ES.Type(undefined), 'Undefined', 'Type(undefined) is Undefined');
|
||||
t.equal(ES.Type(null), 'Null', 'Type(null) is Null');
|
||||
t.equal(ES.Type(true), 'Boolean', 'Type(true) is Boolean');
|
||||
t.equal(ES.Type(false), 'Boolean', 'Type(false) is Boolean');
|
||||
t.equal(ES.Type(0), 'Number', 'Type(0) is Number');
|
||||
t.equal(ES.Type(NaN), 'Number', 'Type(NaN) is Number');
|
||||
t.equal(ES.Type('abc'), 'String', 'Type("abc") is String');
|
||||
t.equal(ES.Type(function () {}), 'Object', 'Type(function () {}) is Object');
|
||||
t.equal(ES.Type({}), 'Object', 'Type({}) is Object');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('IsPropertyDescriptor', function (t) {
|
||||
forEach(v.primitives, function (primitive) {
|
||||
t.equal(ES.IsPropertyDescriptor(primitive), false, debug(primitive) + ' is not a Property Descriptor');
|
||||
});
|
||||
|
||||
t.equal(ES.IsPropertyDescriptor({ invalid: true }), false, 'invalid keys not allowed on a Property Descriptor');
|
||||
|
||||
t.equal(ES.IsPropertyDescriptor({}), true, 'empty object is an incomplete Property Descriptor');
|
||||
|
||||
t.equal(ES.IsPropertyDescriptor(v.accessorDescriptor()), true, 'accessor descriptor is a Property Descriptor');
|
||||
t.equal(ES.IsPropertyDescriptor(v.mutatorDescriptor()), true, 'mutator descriptor is a Property Descriptor');
|
||||
t.equal(ES.IsPropertyDescriptor(v.dataDescriptor()), true, 'data descriptor is a Property Descriptor');
|
||||
t.equal(ES.IsPropertyDescriptor(v.genericDescriptor()), true, 'generic descriptor is a Property Descriptor');
|
||||
|
||||
t['throws'](
|
||||
function () { ES.IsPropertyDescriptor(v.bothDescriptor()); },
|
||||
TypeError,
|
||||
'a Property Descriptor can not be both a Data and an Accessor Descriptor'
|
||||
);
|
||||
|
||||
t['throws'](
|
||||
function () { ES.IsPropertyDescriptor(v.bothDescriptorWritable()); },
|
||||
TypeError,
|
||||
'a Property Descriptor can not be both a Data and an Accessor Descriptor'
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('IsAccessorDescriptor', function (t) {
|
||||
forEach(v.nonNullPrimitives.concat(null), function (primitive) {
|
||||
t['throws'](function () { ES.IsAccessorDescriptor(primitive); }, TypeError, debug(primitive) + ' is not a Property Descriptor');
|
||||
});
|
||||
|
||||
t.equal(ES.IsAccessorDescriptor(), false, 'no value is not an Accessor Descriptor');
|
||||
t.equal(ES.IsAccessorDescriptor(undefined), false, 'undefined value is not an Accessor Descriptor');
|
||||
|
||||
t.equal(ES.IsAccessorDescriptor(v.accessorDescriptor()), true, 'accessor descriptor is an Accessor Descriptor');
|
||||
t.equal(ES.IsAccessorDescriptor(v.mutatorDescriptor()), true, 'mutator descriptor is an Accessor Descriptor');
|
||||
t.equal(ES.IsAccessorDescriptor(v.dataDescriptor()), false, 'data descriptor is not an Accessor Descriptor');
|
||||
t.equal(ES.IsAccessorDescriptor(v.genericDescriptor()), false, 'generic descriptor is not an Accessor Descriptor');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('IsDataDescriptor', function (t) {
|
||||
forEach(v.nonNullPrimitives.concat(null), function (primitive) {
|
||||
t['throws'](function () { ES.IsDataDescriptor(primitive); }, TypeError, debug(primitive) + ' is not a Property Descriptor');
|
||||
});
|
||||
|
||||
t.equal(ES.IsDataDescriptor(), false, 'no value is not a Data Descriptor');
|
||||
t.equal(ES.IsDataDescriptor(undefined), false, 'undefined value is not a Data Descriptor');
|
||||
|
||||
t.equal(ES.IsDataDescriptor(v.accessorDescriptor()), false, 'accessor descriptor is not a Data Descriptor');
|
||||
t.equal(ES.IsDataDescriptor(v.mutatorDescriptor()), false, 'mutator descriptor is not a Data Descriptor');
|
||||
t.equal(ES.IsDataDescriptor(v.dataDescriptor()), true, 'data descriptor is a Data Descriptor');
|
||||
t.equal(ES.IsDataDescriptor(v.genericDescriptor()), false, 'generic descriptor is not a Data Descriptor');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('IsGenericDescriptor', function (t) {
|
||||
forEach(v.nonNullPrimitives.concat(null), function (primitive) {
|
||||
t['throws'](
|
||||
function () { ES.IsGenericDescriptor(primitive); },
|
||||
TypeError,
|
||||
debug(primitive) + ' is not a Property Descriptor'
|
||||
);
|
||||
});
|
||||
|
||||
t.equal(ES.IsGenericDescriptor(), false, 'no value is not a Data Descriptor');
|
||||
t.equal(ES.IsGenericDescriptor(undefined), false, 'undefined value is not a Data Descriptor');
|
||||
|
||||
t.equal(ES.IsGenericDescriptor(v.accessorDescriptor()), false, 'accessor descriptor is not a generic Descriptor');
|
||||
t.equal(ES.IsGenericDescriptor(v.mutatorDescriptor()), false, 'mutator descriptor is not a generic Descriptor');
|
||||
t.equal(ES.IsGenericDescriptor(v.dataDescriptor()), false, 'data descriptor is not a generic Descriptor');
|
||||
|
||||
t.equal(ES.IsGenericDescriptor(v.genericDescriptor()), true, 'generic descriptor is a generic Descriptor');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('FromPropertyDescriptor', function (t) {
|
||||
t.equal(ES.FromPropertyDescriptor(), undefined, 'no value begets undefined');
|
||||
t.equal(ES.FromPropertyDescriptor(undefined), undefined, 'undefined value begets undefined');
|
||||
|
||||
forEach(v.nonNullPrimitives.concat(null), function (primitive) {
|
||||
t['throws'](
|
||||
function () { ES.FromPropertyDescriptor(primitive); },
|
||||
TypeError,
|
||||
debug(primitive) + ' is not a Property Descriptor'
|
||||
);
|
||||
});
|
||||
|
||||
var accessor = v.accessorDescriptor();
|
||||
t.deepEqual(ES.FromPropertyDescriptor(accessor), {
|
||||
get: accessor['[[Get]]'],
|
||||
set: accessor['[[Set]]'],
|
||||
enumerable: !!accessor['[[Enumerable]]'],
|
||||
configurable: !!accessor['[[Configurable]]']
|
||||
});
|
||||
|
||||
var mutator = v.mutatorDescriptor();
|
||||
t.deepEqual(ES.FromPropertyDescriptor(mutator), {
|
||||
get: mutator['[[Get]]'],
|
||||
set: mutator['[[Set]]'],
|
||||
enumerable: !!mutator['[[Enumerable]]'],
|
||||
configurable: !!mutator['[[Configurable]]']
|
||||
});
|
||||
var data = v.dataDescriptor();
|
||||
t.deepEqual(ES.FromPropertyDescriptor(data), {
|
||||
value: data['[[Value]]'],
|
||||
writable: data['[[Writable]]'],
|
||||
enumerable: !!data['[[Enumerable]]'],
|
||||
configurable: !!data['[[Configurable]]']
|
||||
});
|
||||
|
||||
t['throws'](
|
||||
function () { ES.FromPropertyDescriptor(v.genericDescriptor()); },
|
||||
TypeError,
|
||||
'a complete Property Descriptor is required'
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('ToPropertyDescriptor', function (t) {
|
||||
forEach(v.nonNullPrimitives.concat(null), function (primitive) {
|
||||
t['throws'](
|
||||
function () { ES.ToPropertyDescriptor(primitive); },
|
||||
TypeError,
|
||||
debug(primitive) + ' is not an Object'
|
||||
);
|
||||
});
|
||||
|
||||
var accessor = v.accessorDescriptor();
|
||||
t.deepEqual(ES.ToPropertyDescriptor({
|
||||
get: accessor['[[Get]]'],
|
||||
enumerable: !!accessor['[[Enumerable]]'],
|
||||
configurable: !!accessor['[[Configurable]]']
|
||||
}), accessor);
|
||||
|
||||
var mutator = v.mutatorDescriptor();
|
||||
t.deepEqual(ES.ToPropertyDescriptor({
|
||||
set: mutator['[[Set]]'],
|
||||
enumerable: !!mutator['[[Enumerable]]'],
|
||||
configurable: !!mutator['[[Configurable]]']
|
||||
}), mutator);
|
||||
|
||||
var data = v.descriptors.nonConfigurable(v.dataDescriptor());
|
||||
t.deepEqual(ES.ToPropertyDescriptor({
|
||||
value: data['[[Value]]'],
|
||||
writable: data['[[Writable]]'],
|
||||
configurable: !!data['[[Configurable]]']
|
||||
}), data);
|
||||
|
||||
var both = v.bothDescriptor();
|
||||
t['throws'](
|
||||
function () {
|
||||
ES.ToPropertyDescriptor({ get: both['[[Get]]'], value: both['[[Value]]'] });
|
||||
},
|
||||
TypeError,
|
||||
'data and accessor descriptors are mutually exclusive'
|
||||
);
|
||||
|
||||
t['throws'](
|
||||
function () { ES.ToPropertyDescriptor({ get: 'not callable' }); },
|
||||
TypeError,
|
||||
'"get" must be undefined or callable'
|
||||
);
|
||||
|
||||
t['throws'](
|
||||
function () { ES.ToPropertyDescriptor({ set: 'not callable' }); },
|
||||
TypeError,
|
||||
'"set" must be undefined or callable'
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Abstract Equality Comparison', function (t) {
|
||||
t.test('same types use ===', function (st) {
|
||||
forEach(v.primitives.concat(v.objects), function (value) {
|
||||
st.equal(ES['Abstract Equality Comparison'](value, value), value === value, debug(value) + ' is abstractly equal to itself');
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('different types coerce', function (st) {
|
||||
var pairs = [
|
||||
[null, undefined],
|
||||
[3, '3'],
|
||||
[true, '3'],
|
||||
[true, 3],
|
||||
[false, 0],
|
||||
[false, '0'],
|
||||
[3, [3]],
|
||||
['3', [3]],
|
||||
[true, [1]],
|
||||
[false, [0]],
|
||||
[String(v.coercibleObject), v.coercibleObject],
|
||||
[Number(String(v.coercibleObject)), v.coercibleObject],
|
||||
[Number(v.coercibleObject), v.coercibleObject],
|
||||
[String(Number(v.coercibleObject)), v.coercibleObject]
|
||||
];
|
||||
forEach(pairs, function (pair) {
|
||||
var a = pair[0];
|
||||
var b = pair[1];
|
||||
// eslint-disable-next-line eqeqeq
|
||||
st.equal(ES['Abstract Equality Comparison'](a, b), a == b, debug(a) + ' == ' + debug(b));
|
||||
// eslint-disable-next-line eqeqeq
|
||||
st.equal(ES['Abstract Equality Comparison'](b, a), b == a, debug(b) + ' == ' + debug(a));
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Strict Equality Comparison', function (t) {
|
||||
t.test('same types use ===', function (st) {
|
||||
forEach(v.primitives.concat(v.objects), function (value) {
|
||||
st.equal(ES['Strict Equality Comparison'](value, value), value === value, debug(value) + ' is strictly equal to itself');
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('different types are not ===', function (st) {
|
||||
var pairs = [
|
||||
[null, undefined],
|
||||
[3, '3'],
|
||||
[true, '3'],
|
||||
[true, 3],
|
||||
[false, 0],
|
||||
[false, '0'],
|
||||
[3, [3]],
|
||||
['3', [3]],
|
||||
[true, [1]],
|
||||
[false, [0]],
|
||||
[String(v.coercibleObject), v.coercibleObject],
|
||||
[Number(String(v.coercibleObject)), v.coercibleObject],
|
||||
[Number(v.coercibleObject), v.coercibleObject],
|
||||
[String(Number(v.coercibleObject)), v.coercibleObject]
|
||||
];
|
||||
forEach(pairs, function (pair) {
|
||||
var a = pair[0];
|
||||
var b = pair[1];
|
||||
st.equal(ES['Strict Equality Comparison'](a, b), a === b, debug(a) + ' === ' + debug(b));
|
||||
st.equal(ES['Strict Equality Comparison'](b, a), b === a, debug(b) + ' === ' + debug(a));
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Abstract Relational Comparison', function (t) {
|
||||
t.test('at least one operand is NaN', function (st) {
|
||||
st.equal(ES['Abstract Relational Comparison'](NaN, {}, true), undefined, 'LeftFirst: first is NaN, returns undefined');
|
||||
st.equal(ES['Abstract Relational Comparison']({}, NaN, true), undefined, 'LeftFirst: second is NaN, returns undefined');
|
||||
st.equal(ES['Abstract Relational Comparison'](NaN, {}, false), undefined, '!LeftFirst: first is NaN, returns undefined');
|
||||
st.equal(ES['Abstract Relational Comparison']({}, NaN, false), undefined, '!LeftFirst: second is NaN, returns undefined');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.equal(ES['Abstract Relational Comparison'](3, 4, true), true, 'LeftFirst: 3 is less than 4');
|
||||
t.equal(ES['Abstract Relational Comparison'](4, 3, true), false, 'LeftFirst: 3 is not less than 4');
|
||||
t.equal(ES['Abstract Relational Comparison'](3, 4, false), true, '!LeftFirst: 3 is less than 4');
|
||||
t.equal(ES['Abstract Relational Comparison'](4, 3, false), false, '!LeftFirst: 3 is not less than 4');
|
||||
|
||||
t.equal(ES['Abstract Relational Comparison']('3', '4', true), true, 'LeftFirst: "3" is less than "4"');
|
||||
t.equal(ES['Abstract Relational Comparison']('4', '3', true), false, 'LeftFirst: "3" is not less than "4"');
|
||||
t.equal(ES['Abstract Relational Comparison']('3', '4', false), true, '!LeftFirst: "3" is less than "4"');
|
||||
t.equal(ES['Abstract Relational Comparison']('4', '3', false), false, '!LeftFirst: "3" is not less than "4"');
|
||||
|
||||
t.equal(ES['Abstract Relational Comparison'](v.coercibleObject, 42, true), true, 'LeftFirst: coercible object is less than 42');
|
||||
t.equal(ES['Abstract Relational Comparison'](42, v.coercibleObject, true), false, 'LeftFirst: 42 is not less than coercible object');
|
||||
t.equal(ES['Abstract Relational Comparison'](v.coercibleObject, 42, false), true, '!LeftFirst: coercible object is less than 42');
|
||||
t.equal(ES['Abstract Relational Comparison'](42, v.coercibleObject, false), false, '!LeftFirst: 42 is not less than coercible object');
|
||||
|
||||
t.equal(ES['Abstract Relational Comparison'](v.coercibleObject, '3', true), false, 'LeftFirst: coercible object is not less than "3"');
|
||||
t.equal(ES['Abstract Relational Comparison']('3', v.coercibleObject, true), false, 'LeftFirst: "3" is not less than coercible object');
|
||||
t.equal(ES['Abstract Relational Comparison'](v.coercibleObject, '3', false), false, '!LeftFirst: coercible object is not less than "3"');
|
||||
t.equal(ES['Abstract Relational Comparison']('3', v.coercibleObject, false), false, '!LeftFirst: "3" is not less than coercible object');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('FromPropertyDescriptor', function (t) {
|
||||
t.equal(ES.FromPropertyDescriptor(), undefined, 'no value begets undefined');
|
||||
t.equal(ES.FromPropertyDescriptor(undefined), undefined, 'undefined value begets undefined');
|
||||
|
||||
forEach(v.nonUndefinedPrimitives, function (primitive) {
|
||||
t['throws'](
|
||||
function () { ES.FromPropertyDescriptor(primitive); },
|
||||
TypeError,
|
||||
debug(primitive) + ' is not a Property Descriptor'
|
||||
);
|
||||
});
|
||||
|
||||
var accessor = v.accessorDescriptor();
|
||||
t.deepEqual(ES.FromPropertyDescriptor(accessor), {
|
||||
get: accessor['[[Get]]'],
|
||||
set: accessor['[[Set]]'],
|
||||
enumerable: !!accessor['[[Enumerable]]'],
|
||||
configurable: !!accessor['[[Configurable]]']
|
||||
});
|
||||
|
||||
var mutator = v.mutatorDescriptor();
|
||||
t.deepEqual(ES.FromPropertyDescriptor(mutator), {
|
||||
get: mutator['[[Get]]'],
|
||||
set: mutator['[[Set]]'],
|
||||
enumerable: !!mutator['[[Enumerable]]'],
|
||||
configurable: !!mutator['[[Configurable]]']
|
||||
});
|
||||
var data = v.dataDescriptor();
|
||||
t.deepEqual(ES.FromPropertyDescriptor(data), {
|
||||
value: data['[[Value]]'],
|
||||
writable: data['[[Writable]]'],
|
||||
enumerable: !!data['[[Enumerable]]'],
|
||||
configurable: !!data['[[Configurable]]']
|
||||
});
|
||||
|
||||
t['throws'](
|
||||
function () { ES.FromPropertyDescriptor(v.genericDescriptor()); },
|
||||
TypeError,
|
||||
'a complete Property Descriptor is required'
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('SecFromTime', function (t) {
|
||||
var now = new Date();
|
||||
t.equal(ES.SecFromTime(now.getTime()), now.getUTCSeconds(), 'second from Date timestamp matches getUTCSeconds');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('MinFromTime', function (t) {
|
||||
var now = new Date();
|
||||
t.equal(ES.MinFromTime(now.getTime()), now.getUTCMinutes(), 'minute from Date timestamp matches getUTCMinutes');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('HourFromTime', function (t) {
|
||||
var now = new Date();
|
||||
t.equal(ES.HourFromTime(now.getTime()), now.getUTCHours(), 'hour from Date timestamp matches getUTCHours');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('msFromTime', function (t) {
|
||||
var now = new Date();
|
||||
t.equal(ES.msFromTime(now.getTime()), now.getUTCMilliseconds(), 'ms from Date timestamp matches getUTCMilliseconds');
|
||||
t.end();
|
||||
});
|
||||
|
||||
var msPerSecond = 1e3;
|
||||
var msPerMinute = 60 * msPerSecond;
|
||||
var msPerHour = 60 * msPerMinute;
|
||||
var msPerDay = 24 * msPerHour;
|
||||
|
||||
test('Day', function (t) {
|
||||
var time = Date.UTC(2019, 8, 10, 2, 3, 4, 5);
|
||||
var add = 2.5;
|
||||
var later = new Date(time + (add * msPerDay));
|
||||
|
||||
t.equal(ES.Day(later.getTime()), ES.Day(time) + Math.floor(add), 'adding 2.5 days worth of ms, gives a Day delta of 2');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('TimeWithinDay', function (t) {
|
||||
var time = Date.UTC(2019, 8, 10, 2, 3, 4, 5);
|
||||
var add = 2.5;
|
||||
var later = new Date(time + (add * msPerDay));
|
||||
|
||||
t.equal(ES.TimeWithinDay(later.getTime()), ES.TimeWithinDay(time) + (0.5 * msPerDay), 'adding 2.5 days worth of ms, gives a TimeWithinDay delta of +0.5');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('DayFromYear', function (t) {
|
||||
t.equal(ES.DayFromYear(2021) - ES.DayFromYear(2020), 366, '2021 is a leap year, has 366 days');
|
||||
t.equal(ES.DayFromYear(2020) - ES.DayFromYear(2019), 365, '2020 is not a leap year, has 365 days');
|
||||
t.equal(ES.DayFromYear(2019) - ES.DayFromYear(2018), 365, '2019 is not a leap year, has 365 days');
|
||||
t.equal(ES.DayFromYear(2018) - ES.DayFromYear(2017), 365, '2018 is not a leap year, has 365 days');
|
||||
t.equal(ES.DayFromYear(2017) - ES.DayFromYear(2016), 366, '2017 is a leap year, has 366 days');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('TimeFromYear', function (t) {
|
||||
for (var i = 1900; i < 2100; i += 1) {
|
||||
t.equal(ES.TimeFromYear(i), Date.UTC(i, 0, 1), 'TimeFromYear matches a Date object’s year: ' + i);
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('YearFromTime', function (t) {
|
||||
for (var i = 1900; i < 2100; i += 1) {
|
||||
t.equal(ES.YearFromTime(Date.UTC(i, 0, 1)), i, 'YearFromTime matches a Date object’s year on 1/1: ' + i);
|
||||
t.equal(ES.YearFromTime(Date.UTC(i, 10, 1)), i, 'YearFromTime matches a Date object’s year on 10/1: ' + i);
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('WeekDay', function (t) {
|
||||
var now = new Date();
|
||||
var today = now.getUTCDay();
|
||||
for (var i = 0; i < 7; i += 1) {
|
||||
var weekDay = ES.WeekDay(now.getTime() + (i * msPerDay));
|
||||
t.equal(weekDay, (today + i) % 7, i + ' days after today (' + today + '), WeekDay is ' + weekDay);
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('DaysInYear', function (t) {
|
||||
t.equal(ES.DaysInYear(2021), 365, '2021 is not a leap year');
|
||||
t.equal(ES.DaysInYear(2020), 366, '2020 is a leap year');
|
||||
t.equal(ES.DaysInYear(2019), 365, '2019 is not a leap year');
|
||||
t.equal(ES.DaysInYear(2018), 365, '2018 is not a leap year');
|
||||
t.equal(ES.DaysInYear(2017), 365, '2017 is not a leap year');
|
||||
t.equal(ES.DaysInYear(2016), 366, '2016 is a leap year');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('InLeapYear', function (t) {
|
||||
t.equal(ES.InLeapYear(Date.UTC(2021, 0, 1)), 0, '2021 is not a leap year');
|
||||
t.equal(ES.InLeapYear(Date.UTC(2020, 0, 1)), 1, '2020 is a leap year');
|
||||
t.equal(ES.InLeapYear(Date.UTC(2019, 0, 1)), 0, '2019 is not a leap year');
|
||||
t.equal(ES.InLeapYear(Date.UTC(2018, 0, 1)), 0, '2018 is not a leap year');
|
||||
t.equal(ES.InLeapYear(Date.UTC(2017, 0, 1)), 0, '2017 is not a leap year');
|
||||
t.equal(ES.InLeapYear(Date.UTC(2016, 0, 1)), 1, '2016 is a leap year');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('DayWithinYear', function (t) {
|
||||
t.equal(ES.DayWithinYear(Date.UTC(2019, 0, 1)), 0, '1/1 is the 1st day');
|
||||
t.equal(ES.DayWithinYear(Date.UTC(2019, 11, 31)), 364, '12/31 is the 365th day in a non leap year');
|
||||
t.equal(ES.DayWithinYear(Date.UTC(2016, 11, 31)), 365, '12/31 is the 366th day in a leap year');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('MonthFromTime', function (t) {
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 0, 1)), 0, 'non-leap: 1/1 gives January');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 0, 31)), 0, 'non-leap: 1/31 gives January');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 1, 1)), 1, 'non-leap: 2/1 gives February');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 1, 28)), 1, 'non-leap: 2/28 gives February');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 1, 29)), 2, 'non-leap: 2/29 gives March');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 2, 1)), 2, 'non-leap: 3/1 gives March');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 2, 31)), 2, 'non-leap: 3/31 gives March');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 3, 1)), 3, 'non-leap: 4/1 gives April');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 3, 30)), 3, 'non-leap: 4/30 gives April');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 4, 1)), 4, 'non-leap: 5/1 gives May');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 4, 31)), 4, 'non-leap: 5/31 gives May');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 5, 1)), 5, 'non-leap: 6/1 gives June');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 5, 30)), 5, 'non-leap: 6/30 gives June');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 6, 1)), 6, 'non-leap: 7/1 gives July');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 6, 31)), 6, 'non-leap: 7/31 gives July');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 7, 1)), 7, 'non-leap: 8/1 gives August');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 7, 30)), 7, 'non-leap: 8/30 gives August');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 8, 1)), 8, 'non-leap: 9/1 gives September');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 8, 30)), 8, 'non-leap: 9/30 gives September');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 9, 1)), 9, 'non-leap: 10/1 gives October');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 9, 31)), 9, 'non-leap: 10/31 gives October');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 10, 1)), 10, 'non-leap: 11/1 gives November');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 10, 30)), 10, 'non-leap: 11/30 gives November');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 11, 1)), 11, 'non-leap: 12/1 gives December');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2019, 11, 31)), 11, 'non-leap: 12/31 gives December');
|
||||
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 0, 1)), 0, 'leap: 1/1 gives January');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 0, 31)), 0, 'leap: 1/31 gives January');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 1, 1)), 1, 'leap: 2/1 gives February');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 1, 28)), 1, 'leap: 2/28 gives February');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 1, 29)), 1, 'leap: 2/29 gives February');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 2, 1)), 2, 'leap: 3/1 gives March');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 2, 31)), 2, 'leap: 3/31 gives March');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 3, 1)), 3, 'leap: 4/1 gives April');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 3, 30)), 3, 'leap: 4/30 gives April');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 4, 1)), 4, 'leap: 5/1 gives May');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 4, 31)), 4, 'leap: 5/31 gives May');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 5, 1)), 5, 'leap: 6/1 gives June');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 5, 30)), 5, 'leap: 6/30 gives June');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 6, 1)), 6, 'leap: 7/1 gives July');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 6, 31)), 6, 'leap: 7/31 gives July');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 7, 1)), 7, 'leap: 8/1 gives August');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 7, 30)), 7, 'leap: 8/30 gives August');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 8, 1)), 8, 'leap: 9/1 gives September');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 8, 30)), 8, 'leap: 9/30 gives September');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 9, 1)), 9, 'leap: 10/1 gives October');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 9, 31)), 9, 'leap: 10/31 gives October');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 10, 1)), 10, 'leap: 11/1 gives November');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 10, 30)), 10, 'leap: 11/30 gives November');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 11, 1)), 11, 'leap: 12/1 gives December');
|
||||
t.equal(ES.MonthFromTime(Date.UTC(2016, 11, 31)), 11, 'leap: 12/31 gives December');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('DateFromTime', function (t) {
|
||||
var i;
|
||||
for (i = 1; i <= 28; i += 1) {
|
||||
t.equal(ES.DateFromTime(Date.UTC(2019, 1, i)), i, '2019.02.' + i + ' is date ' + i);
|
||||
}
|
||||
for (i = 1; i <= 29; i += 1) {
|
||||
t.equal(ES.DateFromTime(Date.UTC(2016, 1, i)), i, '2016.02.' + i + ' is date ' + i);
|
||||
}
|
||||
for (i = 1; i <= 30; i += 1) {
|
||||
t.equal(ES.DateFromTime(Date.UTC(2019, 8, i)), i, '2019.09.' + i + ' is date ' + i);
|
||||
}
|
||||
for (i = 1; i <= 31; i += 1) {
|
||||
t.equal(ES.DateFromTime(Date.UTC(2019, 9, i)), i, '2019.10.' + i + ' is date ' + i);
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('MakeDay', function (t) {
|
||||
var day2015 = 16687;
|
||||
t.equal(ES.MakeDay(2015, 8, 9), day2015, '2015.09.09 is day 16687');
|
||||
var day2016 = day2015 + 366; // 2016 is a leap year
|
||||
t.equal(ES.MakeDay(2016, 8, 9), day2016, '2015.09.09 is day 17053');
|
||||
var day2017 = day2016 + 365;
|
||||
t.equal(ES.MakeDay(2017, 8, 9), day2017, '2017.09.09 is day 17418');
|
||||
var day2018 = day2017 + 365;
|
||||
t.equal(ES.MakeDay(2018, 8, 9), day2018, '2018.09.09 is day 17783');
|
||||
var day2019 = day2018 + 365;
|
||||
t.equal(ES.MakeDay(2019, 8, 9), day2019, '2019.09.09 is day 18148');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('MakeDate', function (t) {
|
||||
forEach(v.infinities.concat(NaN), function (nonFiniteNumber) {
|
||||
t.ok(is(ES.MakeDate(nonFiniteNumber, 0), NaN), debug(nonFiniteNumber) + ' is not a finite `day`');
|
||||
t.ok(is(ES.MakeDate(0, nonFiniteNumber), NaN), debug(nonFiniteNumber) + ' is not a finite `time`');
|
||||
});
|
||||
t.equal(ES.MakeDate(0, 0), 0, 'zero day and zero time is zero date');
|
||||
t.equal(ES.MakeDate(0, 123), 123, 'zero day and nonzero time is a date of the "time"');
|
||||
t.equal(ES.MakeDate(1, 0), msPerDay, 'day of 1 and zero time is a date of "ms per day"');
|
||||
t.equal(ES.MakeDate(3, 0), 3 * msPerDay, 'day of 3 and zero time is a date of thrice "ms per day"');
|
||||
t.equal(ES.MakeDate(1, 123), msPerDay + 123, 'day of 1 and nonzero time is a date of "ms per day" plus the "time"');
|
||||
t.equal(ES.MakeDate(3, 123), (3 * msPerDay) + 123, 'day of 3 and nonzero time is a date of thrice "ms per day" plus the "time"');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('MakeTime', function (t) {
|
||||
forEach(v.infinities.concat(NaN), function (nonFiniteNumber) {
|
||||
t.ok(is(ES.MakeTime(nonFiniteNumber, 0, 0, 0), NaN), debug(nonFiniteNumber) + ' is not a finite `hour`');
|
||||
t.ok(is(ES.MakeTime(0, nonFiniteNumber, 0, 0), NaN), debug(nonFiniteNumber) + ' is not a finite `min`');
|
||||
t.ok(is(ES.MakeTime(0, 0, nonFiniteNumber, 0), NaN), debug(nonFiniteNumber) + ' is not a finite `sec`');
|
||||
t.ok(is(ES.MakeTime(0, 0, 0, nonFiniteNumber), NaN), debug(nonFiniteNumber) + ' is not a finite `ms`');
|
||||
});
|
||||
|
||||
t.equal(
|
||||
ES.MakeTime(1.2, 2.3, 3.4, 4.5),
|
||||
(1 * msPerHour) + (2 * msPerMinute) + (3 * msPerSecond) + 4,
|
||||
'all numbers are converted to integer, multiplied by the right number of ms, and summed'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('TimeClip', function (t) {
|
||||
forEach(v.infinities.concat(NaN), function (nonFiniteNumber) {
|
||||
t.ok(is(ES.TimeClip(nonFiniteNumber), NaN), debug(nonFiniteNumber) + ' is not a finite `time`');
|
||||
});
|
||||
t.ok(is(ES.TimeClip(8.64e15 + 1), NaN), '8.64e15 is the largest magnitude considered "finite"');
|
||||
t.ok(is(ES.TimeClip(-8.64e15 - 1), NaN), '-8.64e15 is the largest magnitude considered "finite"');
|
||||
|
||||
forEach(v.zeroes.concat([-10, 10, Date.now()]), function (time) {
|
||||
t.equal(ES.TimeClip(time), time, debug(time) + ' is a time of ' + debug(time));
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('modulo', function (t) {
|
||||
t.equal(3 % 2, 1, '+3 % 2 is +1');
|
||||
t.equal(ES.modulo(3, 2), 1, '+3 mod 2 is +1');
|
||||
|
||||
t.equal(-3 % 2, -1, '-3 % 2 is -1');
|
||||
t.equal(ES.modulo(-3, 2), 1, '-3 mod 2 is +1');
|
||||
t.end();
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
|
||||
var ES = require('../');
|
||||
var ES6 = ES.ES6;
|
||||
var ES2015 = ES.ES2015;
|
||||
var ES6entry = require('../es6');
|
||||
|
||||
test('legacy es6 export', function (t) {
|
||||
t.equal(ES6, ES2015, 'main ES6 === main ES2015');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('legacy es6 entry point', function (t) {
|
||||
t.equal(ES6, ES6entry, 'main ES6 === ES6 entry point');
|
||||
t.end();
|
||||
});
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
|
||||
var ES = require('../');
|
||||
var ES7 = ES.ES7;
|
||||
var ES2016 = ES.ES2016;
|
||||
var ES7entry = require('../es7');
|
||||
|
||||
test('legacy es7 export', function (t) {
|
||||
t.equal(ES7, ES2016, 'main ES7 === main ES2016');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('legacy es7 entry point', function (t) {
|
||||
t.equal(ES7, ES7entry, 'main ES7 === ES7 entry point');
|
||||
t.end();
|
||||
});
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var forEach = require('foreach');
|
||||
var debug = require('object-inspect');
|
||||
|
||||
var assertRecord = require('../../helpers/assertRecord');
|
||||
var v = require('./values');
|
||||
|
||||
module.exports = function assertRecordTests(ES, test) {
|
||||
test('Property Descriptor', function (t) {
|
||||
var record = 'Property Descriptor';
|
||||
|
||||
forEach(v.nonUndefinedPrimitives, function (primitive) {
|
||||
t['throws'](
|
||||
function () { assertRecord(ES, record, 'arg', primitive); },
|
||||
TypeError,
|
||||
debug(primitive) + ' is not a Property Descriptor'
|
||||
);
|
||||
});
|
||||
|
||||
t['throws'](
|
||||
function () { assertRecord(ES, record, 'arg', { invalid: true }); },
|
||||
TypeError,
|
||||
'invalid keys not allowed on a Property Descriptor'
|
||||
);
|
||||
|
||||
t.doesNotThrow(
|
||||
function () { assertRecord(ES, record, 'arg', {}); },
|
||||
'empty object is an incomplete Property Descriptor'
|
||||
);
|
||||
|
||||
t.doesNotThrow(
|
||||
function () { assertRecord(ES, record, 'arg', v.accessorDescriptor()); },
|
||||
'accessor descriptor is a Property Descriptor'
|
||||
);
|
||||
|
||||
t.doesNotThrow(
|
||||
function () { assertRecord(ES, record, 'arg', v.mutatorDescriptor()); },
|
||||
'mutator descriptor is a Property Descriptor'
|
||||
);
|
||||
|
||||
t.doesNotThrow(
|
||||
function () { assertRecord(ES, record, 'arg', v.dataDescriptor()); },
|
||||
'data descriptor is a Property Descriptor'
|
||||
);
|
||||
|
||||
t.doesNotThrow(
|
||||
function () { assertRecord(ES, record, 'arg', v.genericDescriptor()); },
|
||||
'generic descriptor is a Property Descriptor'
|
||||
);
|
||||
|
||||
t['throws'](
|
||||
function () { assertRecord(ES, record, 'arg', v.bothDescriptor()); },
|
||||
TypeError,
|
||||
'a Property Descriptor can not be both a Data and an Accessor Descriptor'
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
};
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
'use strict';
|
||||
|
||||
var assign = require('../../helpers/assign');
|
||||
|
||||
var hasSymbols = require('has-symbols')();
|
||||
|
||||
var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
|
||||
var coercibleFnObject = {
|
||||
valueOf: function () { return function valueOfFn() {}; },
|
||||
toString: function () { return 42; }
|
||||
};
|
||||
var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
|
||||
var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
|
||||
var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
|
||||
var uncoercibleFnObject = {
|
||||
valueOf: function () { return function valueOfFn() {}; },
|
||||
toString: function () { return function toStrFn() {}; }
|
||||
};
|
||||
var objects = [{}, coercibleObject, coercibleFnObject, toStringOnlyObject, valueOfOnlyObject];
|
||||
var nullPrimitives = [undefined, null];
|
||||
var nonIntegerNumbers = [-1.3, 0.2, 1.8, 1 / 3];
|
||||
var zeroes = [0, -0];
|
||||
var infinities = [Infinity, -Infinity];
|
||||
var numbers = zeroes.concat([42], infinities, nonIntegerNumbers);
|
||||
var strings = ['', 'foo', 'a\uD83D\uDCA9c'];
|
||||
var booleans = [true, false];
|
||||
var symbols = hasSymbols ? [Symbol.iterator, Symbol('foo')] : [];
|
||||
var nonSymbolPrimitives = [].concat(nullPrimitives, booleans, strings, numbers);
|
||||
var nonNumberPrimitives = [].concat(nullPrimitives, booleans, strings, symbols);
|
||||
var nonNullPrimitives = [].concat(booleans, strings, numbers, symbols);
|
||||
var nonUndefinedPrimitives = [].concat(null, nonNullPrimitives);
|
||||
var nonStrings = [].concat(nullPrimitives, booleans, numbers, symbols, objects);
|
||||
var primitives = [].concat(nullPrimitives, nonNullPrimitives);
|
||||
var nonPropertyKeys = [].concat(nullPrimitives, booleans, numbers, objects);
|
||||
var propertyKeys = [].concat(strings, symbols);
|
||||
var nonBooleans = [].concat(nullPrimitives, strings, symbols, numbers, objects);
|
||||
var falsies = [].concat(nullPrimitives, false, '', 0, -0, NaN);
|
||||
var truthies = [].concat(true, 'foo', 42, symbols, objects);
|
||||
var timestamps = [].concat(0, 946713600000, 1546329600000);
|
||||
var nonFunctions = [].concat(primitives, objects, [42]);
|
||||
var nonArrays = [].concat(nonFunctions);
|
||||
|
||||
var descriptors = {
|
||||
configurable: function (descriptor) {
|
||||
return assign(assign({}, descriptor), { '[[Configurable]]': true });
|
||||
},
|
||||
nonConfigurable: function (descriptor) {
|
||||
return assign(assign({}, descriptor), { '[[Configurable]]': false });
|
||||
},
|
||||
enumerable: function (descriptor) {
|
||||
return assign(assign({}, descriptor), { '[[Enumerable]]': true });
|
||||
},
|
||||
nonEnumerable: function (descriptor) {
|
||||
return assign(assign({}, descriptor), { '[[Enumerable]]': false });
|
||||
},
|
||||
writable: function (descriptor) {
|
||||
return assign(assign({}, descriptor), { '[[Writable]]': true });
|
||||
},
|
||||
nonWritable: function (descriptor) {
|
||||
return assign(assign({}, descriptor), { '[[Writable]]': false });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
coercibleObject: coercibleObject,
|
||||
coercibleFnObject: coercibleFnObject,
|
||||
valueOfOnlyObject: valueOfOnlyObject,
|
||||
toStringOnlyObject: toStringOnlyObject,
|
||||
uncoercibleObject: uncoercibleObject,
|
||||
uncoercibleFnObject: uncoercibleFnObject,
|
||||
objects: objects,
|
||||
nonFunctions: nonFunctions,
|
||||
nonArrays: nonArrays,
|
||||
nullPrimitives: nullPrimitives,
|
||||
numbers: numbers,
|
||||
zeroes: zeroes,
|
||||
infinities: infinities,
|
||||
strings: strings,
|
||||
booleans: booleans,
|
||||
symbols: symbols,
|
||||
hasSymbols: hasSymbols,
|
||||
nonSymbolPrimitives: nonSymbolPrimitives,
|
||||
nonNumberPrimitives: nonNumberPrimitives,
|
||||
nonNullPrimitives: nonNullPrimitives,
|
||||
nonUndefinedPrimitives: nonUndefinedPrimitives,
|
||||
nonStrings: nonStrings,
|
||||
nonNumbers: nonNumberPrimitives.concat(objects),
|
||||
nonIntegerNumbers: nonIntegerNumbers,
|
||||
primitives: primitives,
|
||||
nonPropertyKeys: nonPropertyKeys,
|
||||
propertyKeys: propertyKeys,
|
||||
nonBooleans: nonBooleans,
|
||||
falsies: falsies,
|
||||
truthies: truthies,
|
||||
timestamps: timestamps,
|
||||
bothDescriptor: function () {
|
||||
return { '[[Get]]': function () {}, '[[Value]]': true };
|
||||
},
|
||||
bothDescriptorWritable: function () {
|
||||
return descriptors.writable({ '[[Get]]': function () {} });
|
||||
},
|
||||
accessorDescriptor: function (value) {
|
||||
return descriptors.enumerable(descriptors.configurable({
|
||||
'[[Get]]': function get() { return value; }
|
||||
}));
|
||||
},
|
||||
mutatorDescriptor: function () {
|
||||
return descriptors.enumerable(descriptors.configurable({
|
||||
'[[Set]]': function () {}
|
||||
}));
|
||||
},
|
||||
dataDescriptor: function (value) {
|
||||
return descriptors.nonWritable({
|
||||
'[[Value]]': arguments.length > 0 ? value : 42
|
||||
});
|
||||
},
|
||||
genericDescriptor: function () {
|
||||
return descriptors.configurable(descriptors.nonEnumerable());
|
||||
},
|
||||
descriptors: descriptors
|
||||
};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var ES = require('../');
|
||||
var test = require('tape');
|
||||
|
||||
var ESkeys = Object.keys(ES).sort();
|
||||
var ES6keys = Object.keys(ES.ES6).sort();
|
||||
|
||||
test('exposed properties', function (t) {
|
||||
t.deepEqual(ESkeys, ES6keys.concat(['ES2019', 'ES2018', 'ES2017', 'ES7', 'ES2016', 'ES6', 'ES2015', 'ES5']).sort(), 'main ES object keys match ES6 keys');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('methods match', function (t) {
|
||||
ES6keys.forEach(function (key) {
|
||||
t.equal(ES.ES6[key], ES[key], 'method ' + key + ' on main ES object is ES6 method');
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
require('./GetIntrinsic');
|
||||
|
||||
require('./es5');
|
||||
require('./es6');
|
||||
require('./es2015');
|
||||
require('./es7');
|
||||
require('./es2016');
|
||||
require('./es2017');
|
||||
require('./es2018');
|
||||
require('./es2019');
|
||||
+3880
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user