[Pkg-javascript-commits] [node-es6-shim] 02/09: Imported Upstream version 0.35.0+ds
Julien Puydt
julien.puydt at laposte.net
Sun May 29 11:36:11 UTC 2016
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-es6-shim.
commit 819fc3d83f7015914147737d22a8862a42cb8c71
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Thu Apr 28 10:23:13 2016 +0200
Imported Upstream version 0.35.0+ds
---
.jscs.json | 10 ++-
.travis.yml | 10 +++
CHANGELOG.md | 34 +++++++++-
LICENSE | 2 +-
README.md | 5 +-
component.json | 2 +-
es6-sham.js | 42 ++++++++++++-
es6-sham.map | 2 +-
es6-sham.min.js | 8 +--
es6-shim.js | 166 ++++++++++++++++++++++++++++---------------------
es6-shim.map | 2 +-
es6-shim.min.js | 10 +--
package.json | 12 ++--
test-sham/function.js | 54 ++++++++++++++++
test-sham/index.html | 1 +
test/array.js | 34 ++++++++++
test/json.js | 4 ++
test/math.js | 5 +-
test/number.js | 30 +++++++++
test/promise/reject.js | 1 +
test/reflect.js | 105 -------------------------------
test/regexp.js | 29 +++++++++
22 files changed, 366 insertions(+), 202 deletions(-)
diff --git a/.jscs.json b/.jscs.json
index f00a97b..e457533 100644
--- a/.jscs.json
+++ b/.jscs.json
@@ -149,6 +149,14 @@
"requireObjectDestructuring": false,
- "requireEarlyReturn": false
+ "requireEarlyReturn": false,
+
+ "requireCapitalizedConstructorsNew": {
+ "allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array", "OrigNumber"]
+ },
+
+ "requireImportAlphabetized": false,
+
+ "disallowSpacesInsideTemplateStringPlaceholders": true
}
diff --git a/.travis.yml b/.travis.yml
index 3d0baf5..a96127e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,14 @@
language: node_js
node_js:
+ - "5.7"
+ - "5.6"
+ - "5.5"
+ - "5.4"
- "5.3"
- "5.2"
- "5.1"
- "5.0"
+ - "4.3"
- "4.2"
- "4.1"
- "4.0"
@@ -53,9 +58,14 @@ matrix:
- node_js: "0.12"
env: TRAVIS_RUN_SAUCE=false TRAVIS_RUN_LINT_ONLY=false
allow_failures:
+ - node_js: "5.6"
+ - node_js: "5.5"
+ - node_js: "5.4"
+ - node_js: "5.3"
- node_js: "5.2"
- node_js: "5.1"
- node_js: "5.0"
+ - node_js: "4.2"
- node_js: "4.1"
- node_js: "4.0"
- node_js: "iojs-v3.2"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5a57682..33d5312 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,36 @@
-# es6-shim x.x.x (not yet released)
+# es6-shim 0.35.0 (29 Feb 2016)
+* [Breaking] remove `Reflect.enumerate` (#405)
+* [New] Add `Array#indexOf` from post-ES6 errata
+* [New] Ensure `RegExp#toString` is compliant
+* [New] [sham] Add `Function#toString` to `es6-sham`
+* [Fix] ensure that a non-object `globals.Reflect` doesn’t break the shim (#392)
+* [Fix] In ES3 browsers (like Safari 4) `Reflect.getPrototypeOf` is undefined
+* [Fix] `Object.keys`: handle regexes in ES3 browsers (#287)
+* [Performance] Early exit from tanh for values outside of +-20 at limits of JS precision (#411)
+* [Tests] `Function#name` on `new Function`s is empty string in v8
+* [Tests] `Function#name` is non-configurable pre-ES6
+* [Tests] up to `node` `v5.7`, `v4.3`
+* [Docs] correct readme; we sham Function#name, not toString
+
+# es6-shim 0.34.4 (9 Feb 2016)
+* [Fix] 'Uncaught (in promise) TypeError' in Chrome 48 (#408, #407)
+* [Fix] handle the obscure case where `startsWith` throws on the second parameter (#399)
+* [Tests] silence a promise rejection error in Chrome
+
+# es6-shim 0.34.3 (8 Feb 2016)
+* [Fix] Suppress “uncaught rejection” warnings in Chrome 50 console (#403)
+* [Fix] ensure ES3 `Number` constants don’t get lost in ES3 browsers (#402)
+* [Dev Deps] update `chai`, `es5-shim`, `jscs`, `mocha`
+* [Tests] up to `node` `v5.5`
+
+# es6-shim 0.34.2 (22 Jan 2016)
+* [Fix] `JSON.stringify` should ignore a replacer arg unless it’s an array or function.
+* [Fix] `Array#copyWithin`: check for inherited properties as well
+* [Fix] `Array#copyWithin`: should delete the target key if the source key is not present
+* [Performance] Optimize Map/Set fast key path (#397)
+* [Tests] fix `Reflect.enumerate` tests to not call `next` too many times
+* [Dev Deps] update `jscs`, `jshint`
+* [Docs] update license year to 2016 (#400)
# es6-shim 0.34.1 (5 Jan 2016)
* [Fix] `RegExp#[Symbol.search]` was broken with a regex argument (#394)
diff --git a/LICENSE b/LICENSE
index 822c479..996ec8d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -4,7 +4,7 @@ Current maintainers are: [Paul Miller](http://paulmillr.com), [Jordan Harband](h
The MIT License (MIT)
-Copyright (c) 2013-2015 Paul Miller (http://paulmillr.com) and contributors
+Copyright (c) 2013-2016 Paul Miller (http://paulmillr.com) and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 6d37667..da3a2f8 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ In both browser and node you may also want to include `unorm`; see the [`String.
* `[Symbol.replace]` (requires native `Symbol`s)
* `[Symbol.search]` (requires native `Symbol`s)
* `[Symbol.split]` (requires native `Symbol`s)
+ * `toString`
* `Number`:
* binary and octal literals: `Number('0b1')` and `Number('0o7')`
* `EPSILON`
@@ -69,11 +70,14 @@ In both browser and node you may also want to include `unorm`; see the [`String.
* `findIndex()` ([a standalone shim is also available](https://github.com/paulmillr/Array.prototype.findIndex))
* `keys()` (note: keys/values/entries return an `ArrayIterator` object)
* `values()`
+ * `indexOf()` (ES6 errata)
* `Object`:
* `assign()` ([a standalone shim is also available](https://github.com/ljharb/object.assign))
* `is()` ([a standalone shim is also available](https://github.com/ljharb/object-is))
* `keys()` (in ES5, but no longer throws on non-object non-null/undefined values in ES6)
* `setPrototypeOf()` (IE >= 11)
+* `Function.prototype`:
+ * `name` (es6-sham, covers IE 9-11)
* `Math`:
* `acosh()`
* `asinh()`
@@ -100,7 +104,6 @@ Math functions’ accuracy is 1e-11.
* `construct()`
* `defineProperty()`
* `deleteProperty()`
- * `enumerate()`
* `get()`
* `getOwnPropertyDescriptor()`
* `getPrototypeOf()`
diff --git a/component.json b/component.json
index c971adf..14307f9 100644
--- a/component.json
+++ b/component.json
@@ -1,6 +1,6 @@
{
"name": "es6-shim",
- "version": "0.34.1",
+ "version": "0.35.0",
"repo": "paulmillr/es6-shim",
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines",
"keywords": [
diff --git a/es6-sham.js b/es6-sham.js
index 7e49121..ec8025a 100644
--- a/es6-sham.js
+++ b/es6-sham.js
@@ -1,9 +1,9 @@
/*!
* https://github.com/paulmillr/es6-shim
- * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com)
+ * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
* and contributors, MIT License
- * es6-sham: v0.34.1
- * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE
+ * es6-sham: v0.35.0
+ * see https://github.com/paulmillr/es6-shim/blob/0.35.0/LICENSE
* Details and documentation:
* https://github.com/paulmillr/es6-shim/
*/
@@ -35,6 +35,23 @@
var globals = getGlobal();
var Object = globals.Object;
+ var _call = Function.call.bind(Function.call);
+ var functionToString = Function.toString;
+ var _strMatch = String.prototype.match;
+
+ var throwsError = function (func) {
+ try {
+ func();
+ return false;
+ } catch (e) {
+ return true;
+ }
+ };
+ var arePropertyDescriptorsSupported = function () {
+ // if Object.defineProperty exists but throws, it's IE 8
+ return !throwsError(function () { Object.defineProperty({}, 'x', { get: function () {} }); });
+ };
+ var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
// NOTE: This versions needs object ownership
// because every promoted object needs to be reassigned
@@ -129,4 +146,23 @@
Object.setPrototypeOf = setPrototypeOf;
}());
+ if (supportsDescriptors && function foo() {}.name !== 'foo') {
+ /* eslint no-extend-native: 1 */
+ Object.defineProperty(Function.prototype, 'name', {
+ configurable: true,
+ enumerable: false,
+ get: function () {
+ var str = _call(functionToString, this);
+ var match = _call(_strMatch, str, /\s*function\s+([^\(\s]*)\s*/);
+ var name = match && match[1];
+ Object.defineProperty(this, 'name', {
+ configurable: true,
+ enumerable: false,
+ writable: false,
+ value: name
+ });
+ return name;
+ }
+ });
+ }
}));
diff --git a/es6-sham.map b/es6-sham.map
index 8f3589e..dbca586 100644
--- a/es6-sham.map
+++ b/es6-sham.map
@@ -1 +1 @@
-{"version":3,"sources":["es6-sham.js"],"names":["root","factory","define","amd","exports","module","returnExports","this","getGlobal","Function","globals","Object","setPrototypeOf","getOwnPropertyNames","getOwnPropertyDescriptor","create","defineProperty","getPrototypeOf","objProto","prototype","copyDescriptors","target","source","forEach","key","createAndCopy","origin","proto","set","call","e","__proto__"],"mappings":";;;;;;;;;CAYC,SAAUA,EAAMC,GAEf,SAAWC,UAAW,YAAcA,OAAOC,IAAK,CAE9CD,OAA [...]
\ No newline at end of file
+{"version":3,"sources":["es6-sham.js"],"names":["root","factory","define","amd","exports","module","returnExports","this","getGlobal","Function","globals","Object","_call","call","bind","functionToString","toString","_strMatch","String","prototype","match","throwsError","func","e","arePropertyDescriptorsSupported","defineProperty","get","supportsDescriptors","setPrototypeOf","getOwnPropertyNames","getOwnPropertyDescriptor","create","getPrototypeOf","objProto","copyDescriptors","target"," [...]
\ No newline at end of file
diff --git a/es6-sham.min.js b/es6-sham.min.js
index 1dda0d0..d8d3c36 100644
--- a/es6-sham.min.js
+++ b/es6-sham.min.js
@@ -1,11 +1,11 @@
/*!
* https://github.com/paulmillr/es6-shim
- * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com)
+ * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
* and contributors, MIT License
- * es6-sham: v0.34.1
- * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE
+ * es6-sham: v0.35.0
+ * see https://github.com/paulmillr/es6-shim/blob/0.35.0/LICENSE
* Details and documentation:
* https://github.com/paulmillr/es6-shim/
*/
-(function(t,e){if(typeof define==="function"&&define.amd){define(e)}else if(typeof exports==="object"){module.exports=e()}else{t.returnExports=e()}})(this,function(){"use strict";var t=new Function("return this;");var e=t();var r=e.Object;(function(){if(r.setPrototypeOf){return}var t=r.getOwnPropertyNames;var e=r.getOwnPropertyDescriptor;var n=r.create;var o=r.defineProperty;var f=r.getPrototypeOf;var i=r.prototype;var u=function(r,n){t(n).forEach(function(t){o(r,t,e(n,t))});return r};va [...]
+(function(t,e){if(typeof define==="function"&&define.amd){define(e)}else if(typeof exports==="object"){module.exports=e()}else{t.returnExports=e()}})(this,function(){"use strict";var t=new Function("return this;");var e=t();var r=e.Object;var n=Function.call.bind(Function.call);var o=Function.toString;var i=String.prototype.match;var f=function(t){try{t();return false}catch(e){return true}};var a=function(){return!f(function(){r.defineProperty({},"x",{get:function(){}})})};var u=!!r.defi [...]
//# sourceMappingURL=es6-sham.map
diff --git a/es6-shim.js b/es6-shim.js
index f6058ae..1f49f68 100644
--- a/es6-shim.js
+++ b/es6-shim.js
@@ -1,9 +1,9 @@
/*!
* https://github.com/paulmillr/es6-shim
- * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com)
+ * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
* and contributors, MIT License
- * es6-shim: v0.34.1
- * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE
+ * es6-shim: v0.35.0
+ * see https://github.com/paulmillr/es6-shim/blob/0.35.0/LICENSE
* Details and documentation:
* https://github.com/paulmillr/es6-shim/
*/
@@ -183,6 +183,7 @@
var globals = getGlobal();
var globalIsFinite = globals.isFinite;
var _indexOf = Function.call.bind(String.prototype.indexOf);
+ var _arrayIndexOfApply = Function.apply.bind(Array.prototype.indexOf);
var _concat = Function.call.bind(Array.prototype.concat);
var _sort = Function.call.bind(Array.prototype.sort);
var _strSlice = Function.call.bind(String.prototype.slice);
@@ -262,7 +263,7 @@
// Reflect
if (!globals.Reflect) {
- defineProperty(globals, 'Reflect', {});
+ defineProperty(globals, 'Reflect', {}, true);
}
var Reflect = globals.Reflect;
@@ -827,7 +828,9 @@
/* throws if spec-compliant */
'/a/'.startsWith(/a/);
});
- var startsWithHandlesInfinity = 'abc'.startsWith('a', Infinity) === false;
+ var startsWithHandlesInfinity = valueOrFalseIfThrows(function () {
+ return 'abc'.startsWith('a', Infinity) === false;
+ });
if (!startsWithRejectsRegex || !startsWithHandlesInfinity) {
// Firefox (< 37?) and IE 11 TP have a noncompliant startsWith implementation
overrideNative(String.prototype, 'startsWith', StringPrototypeShims.startsWith);
@@ -1057,48 +1060,6 @@
return _concat(ownKeys, keys);
};
- var ObjectIterator = function (object, kind) {
- defineProperties(this, {
- object: object,
- array: getAllKeys(object),
- kind: kind
- });
- };
-
- defineProperties(ObjectIterator.prototype, {
- next: function next() {
- var key;
- var array = this.array;
-
- if (!(this instanceof ObjectIterator)) {
- throw new TypeError('Not an ObjectIterator');
- }
-
- // Find next key in the object
- while (array.length > 0) {
- key = _shift(array);
-
- // The candidate key isn't defined on object.
- // Must have been deleted, or object[[Prototype]]
- // has been modified.
- if (!(key in this.object)) {
- continue;
- }
-
- if (this.kind === 'key') {
- return iteratorResult(key);
- } else if (this.kind === 'value') {
- return iteratorResult(this.object[key]);
- } else {
- return iteratorResult([key, this.object[key]]);
- }
- }
-
- return iteratorResult();
- }
- });
- addIterator(ObjectIterator.prototype);
-
// note: this is positioned here because it depends on ArrayIterator
var arrayOfSupportsSubclassing = Array.of === ArrayShims.of || (function () {
// Detects a bug in Webkit nightly r181886
@@ -1133,10 +1094,10 @@
to += count - 1;
}
while (count > 0) {
- if (_hasOwnProperty(o, from)) {
+ if (from in o) {
o[to] = o[from];
} else {
- delete o[from];
+ delete o[to];
}
from += direction;
to += direction;
@@ -1240,6 +1201,18 @@
}
defineProperties(Array.prototype, ArrayPrototypeShims);
+ if (1 / [true].indexOf(true, -0) < 0) {
+ // indexOf when given a position arg of -0 should return +0.
+ // https://github.com/tc39/ecma262/pull/316
+ defineProperty(Array.prototype, 'indexOf', function indexOf(searchElement) {
+ var value = _arrayIndexOfApply(this, arguments);
+ if (value === 0 && (1 / value) < 0) {
+ return 0;
+ }
+ return value;
+ }, true);
+ }
+
addIterator(Array.prototype, function () { return this.values(); });
// Chrome defines keys/values/entries on Array, but doesn't give us
// any way to identify its iterator. So add our own shimmed field.
@@ -1397,12 +1370,22 @@
return NumberShim;
}());
wrapConstructor(OrigNumber, NumberShim, {});
- /*globals Number: true */
+ // this is necessary for ES3 browsers, where these properties are non-enumerable.
+ defineProperties(NumberShim, {
+ NaN: OrigNumber.NaN,
+ MAX_VALUE: OrigNumber.MAX_VALUE,
+ MIN_VALUE: OrigNumber.MIN_VALUE,
+ NEGATIVE_INFINITY: OrigNumber.NEGATIVE_INFINITY,
+ POSITIVE_INFINITY: OrigNumber.POSITIVE_INFINITY
+ });
+ /* globals Number: true */
/* eslint-disable no-undef */
+ /* jshint -W020 */
Number = NumberShim;
Value.redefine(globals, 'Number', NumberShim);
+ /* jshint +W020 */
/* eslint-enable no-undef */
- /*globals Number: false */
+ /* globals Number: false */
}
var maxSafeInteger = Math.pow(2, 53) - 1;
@@ -1591,6 +1574,23 @@
});
keys = Object.keys;
}
+ var objectKeysRejectsRegex = throwsError(function () { Object.keys(/a/g); });
+ if (objectKeysRejectsRegex) {
+ var regexRejectingObjectKeys = Object.keys;
+ overrideNative(Object, 'keys', function keys(value) {
+ if (Type.regex(value)) {
+ var regexKeys = [];
+ for (var k in value) {
+ if (_hasOwnProperty(value, k)) {
+ _push(regexKeys, k);
+ }
+ }
+ return regexKeys;
+ }
+ return regexRejectingObjectKeys(value);
+ });
+ keys = Object.keys;
+ }
if (Object.getOwnPropertyNames) {
var objectGOPNAcceptsPrimitives = !throwsError(function () { Object.getOwnPropertyNames('foo'); });
@@ -1731,6 +1731,26 @@
return RegExp(regex) === regex;
}());
+ var regexToStringIsGeneric = valueOrFalseIfThrows(function () {
+ return RegExp.prototype.toString.call({ source: 'abc' }) === '/abc/';
+ });
+ var regexToStringSupportsGenericFlags = regexToStringIsGeneric && valueOrFalseIfThrows(function () {
+ return RegExp.prototype.toString.call({ source: 'a', flags: 'b' }) === '/a/b';
+ });
+ if (!regexToStringIsGeneric || !regexToStringSupportsGenericFlags) {
+ var origRegExpToString = RegExp.prototype.toString;
+ defineProperty(RegExp.prototype, 'toString', function toString() {
+ var R = ES.RequireObjectCoercible(this);
+ if (Type.regex(R)) {
+ return _call(origRegExpToString, R);
+ }
+ var pattern = $String(R.source);
+ var flags = $String(R.flags);
+ return '/' + pattern + '/' + flags;
+ }, true);
+ Value.preserveToString(RegExp.prototype.toString, origRegExpToString);
+ }
+
if (supportsDescriptors && (!regExpSupportsFlagsWithRegex || regExpNeedsToSupportSymbolMatch)) {
var flagsGetter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
var sourceDesc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source') || {};
@@ -1762,12 +1782,14 @@
wrapConstructor(OrigRegExp, RegExpShim, {
$input: true // Chrome < v39 & Opera < 26 have a nonstandard "$input" property
});
- /*globals RegExp: true */
+ /* globals RegExp: true */
/* eslint-disable no-undef */
+ /* jshint -W020 */
RegExp = RegExpShim;
Value.redefine(globals, 'RegExp', RegExpShim);
+ /* jshint +W020 */
/* eslint-enable no-undef */
- /*globals RegExp: false */
+ /* globals RegExp: false */
}
if (supportsDescriptors) {
@@ -1935,8 +1957,9 @@
tanh: function tanh(value) {
var x = Number(value);
if (Number.isNaN(x) || x === 0) { return x; }
- if (x === Infinity) { return 1; }
- if (x === -Infinity) { return -1; }
+ // can exit early at +-20 as JS loses precision for true value at this integer
+ if (x >= 20) { return 1; }
+ if (x <= -20) { return -1; }
var a = Math.expm1(x);
var b = Math.expm1(-x);
if (a === Infinity) { return 1; }
@@ -2546,7 +2569,12 @@
var p = Promise.resolve(5);
p.constructor = {};
var p2 = Promise.resolve(p);
- return (p === p2); // This *should* be false!
+ try {
+ p2.then(null, noop).then(null, noop); // avoid "uncaught rejection" warnings in console
+ } catch (e) {
+ return true; // v8 native Promises break here https://code.google.com/p/chromium/issues/detail?id=575314
+ }
+ return p === p2; // This *should* be false!
}(globals.Promise));
// Chrome 46 (probably older too) does not retrieve a thenable's .then synchronously
@@ -2573,11 +2601,13 @@
if (!promiseSupportsSubclassing || !promiseIgnoresNonFunctionThenCallbacks ||
!promiseRequiresObjectContext || promiseResolveBroken ||
!getsThenSynchronously || hasBadResolverPromise) {
- /*globals Promise: true */
+ /* globals Promise: true */
/* eslint-disable no-undef */
+ /* jshint -W020 */
Promise = PromiseShim;
+ /* jshint +W020 */
/* eslint-enable no-undef */
- /*globals Promise: false */
+ /* globals Promise: false */
overrideNative(globals, 'Promise', PromiseShim);
}
if (Promise.all.length !== 1) {
@@ -2631,18 +2661,17 @@
if (!preservesInsertionOrder) {
return null;
}
- var type = typeof key;
- if (type === 'undefined' || key === null) {
+ if (typeof key === 'undefined' || key === null) {
return '^' + ES.ToString(key);
- } else if (type === 'string') {
+ } else if (typeof key === 'string') {
return '$' + key;
- } else if (type === 'number') {
+ } else if (typeof key === 'number') {
// note that -0 will get coerced to "0" when used as a property key
if (!preservesNumericInsertionOrder) {
return 'n' + key;
}
return key;
- } else if (type === 'boolean') {
+ } else if (typeof key === 'boolean') {
return 'b' + key;
}
return null;
@@ -3359,11 +3388,6 @@
return delete target[key];
},
- enumerate: function enumerate(target) {
- throwUnlessTargetIsObject(target);
- return new ObjectIterator(target, 'key');
- },
-
has: function has(target, key) {
throwUnlessTargetIsObject(target);
return key in target;
@@ -3583,8 +3607,8 @@
Object.keys(ReflectShims).forEach(function (key) {
defineOrOverrideReflectProperty(key, ReflectShims[key]);
});
- if (functionsHaveNames && globals.Reflect.getPrototypeOf.name !== 'getPrototypeOf') {
- var originalReflectGetProto = globals.Reflect.getPrototypeOf;
+ var originalReflectGetProto = globals.Reflect.getPrototypeOf;
+ if (functionsHaveNames && originalReflectGetProto && originalReflectGetProto.name !== 'getPrototypeOf') {
overrideNative(globals.Reflect, 'getPrototypeOf', function getPrototypeOf(target) {
return _call(originalReflectGetProto, globals.Reflect, target);
});
@@ -3689,7 +3713,7 @@
if (!isArray(replacer)) {
var replaceFn = ES.IsCallable(replacer) ? replacer : null;
var wrappedReplacer = function (key, val) {
- var parsedValue = replacer ? _call(replacer, this, key, val) : val;
+ var parsedValue = replaceFn ? _call(replaceFn, this, key, val) : val;
if (typeof parsedValue !== 'symbol') {
if (Type.symbol(parsedValue)) {
return assignTo({})(parsedValue);
diff --git a/es6-shim.map b/es6-shim.map
index 00277e7..2fa4e11 100644
--- a/es6-shim.map
+++ b/es6-shim.map
@@ -1 +1 @@
-{"version":3,"sources":["es6-shim.js"],"names":["root","factory","define","amd","exports","module","returnExports","this","_apply","Function","call","bind","apply","_call","isArray","Array","keys","Object","not","notThunker","func","notThunk","arguments","throwsError","e","valueOrFalseIfThrows","isCallableWithoutNew","arePropertyDescriptorsSupported","defineProperty","get","supportsDescriptors","functionsHaveNames","foo","name","_forEach","prototype","forEach","_reduce","reduce","_filter [...]
\ No newline at end of file
+{"version":3,"sources":["es6-shim.js"],"names":["root","factory","define","amd","exports","module","returnExports","this","_apply","Function","call","bind","apply","_call","isArray","Array","keys","Object","not","notThunker","func","notThunk","arguments","throwsError","e","valueOrFalseIfThrows","isCallableWithoutNew","arePropertyDescriptorsSupported","defineProperty","get","supportsDescriptors","functionsHaveNames","foo","name","_forEach","prototype","forEach","_reduce","reduce","_filter [...]
\ No newline at end of file
diff --git a/es6-shim.min.js b/es6-shim.min.js
index 00241b8..6f0d3de 100644
--- a/es6-shim.min.js
+++ b/es6-shim.min.js
@@ -1,12 +1,12 @@
/*!
* https://github.com/paulmillr/es6-shim
- * @license es6-shim Copyright 2013-2015 by Paul Miller (http://paulmillr.com)
+ * @license es6-shim Copyright 2013-2016 by Paul Miller (http://paulmillr.com)
* and contributors, MIT License
- * es6-shim: v0.34.1
- * see https://github.com/paulmillr/es6-shim/blob/0.34.1/LICENSE
+ * es6-shim: v0.35.0
+ * see https://github.com/paulmillr/es6-shim/blob/0.35.0/LICENSE
* Details and documentation:
* https://github.com/paulmillr/es6-shim/
*/
-(function(e,t){if(typeof define==="function"&&define.amd){define(t)}else if(typeof exports==="object"){module.exports=t()}else{e.returnExports=t()}})(this,function(){"use strict";var e=Function.call.bind(Function.apply);var t=Function.call.bind(Function.call);var r=Array.isArray;var n=Object.keys;var o=function notThunker(t){return function notThunk(){return!e(t,this,arguments)}};var i=function(e){try{e();return false}catch(t){return true}};var a=function valueOrFalseIfThrows(e){try{retu [...]
-if(typeof e!=="function"&&typeof e!=="object"){return}ee.IsPromise=function(e){if(!ee.TypeIsObject(e)){return false}if(typeof e._promise==="undefined"){return false}return true};var r=function(e){if(!ee.IsConstructor(e)){throw new TypeError("Bad promise constructor")}var t=this;var r=function(e,r){if(t.resolve!==void 0||t.reject!==void 0){throw new TypeError("Bad Promise implementation!")}t.resolve=e;t.reject=r};t.resolve=void 0;t.reject=void 0;t.promise=new e(r);if(!(ee.IsCallable(t.res [...]
+(function(e,t){if(typeof define==="function"&&define.amd){define(t)}else if(typeof exports==="object"){module.exports=t()}else{e.returnExports=t()}})(this,function(){"use strict";var e=Function.call.bind(Function.apply);var t=Function.call.bind(Function.call);var r=Array.isArray;var n=Object.keys;var o=function notThunker(t){return function notThunk(){return!e(t,this,arguments)}};var i=function(e){try{e();return false}catch(t){return true}};var a=function valueOrFalseIfThrows(e){try{retu [...]
+var mr=Math.round;var wr=Math.round(.5-Number.EPSILON/4)===0&&Math.round(-.5+Number.EPSILON/3.99)===1;var jr=pr+1;var Sr=2*pr-1;var Tr=[jr,Sr].every(function(e){return Math.round(e)===e});h(Math,"round",function round(e){var t=k(e);var r=t===-1?-0:t+1;return e-t<.5?t:r},!wr||!Tr);O.preserveToString(Math.round,mr);var Ir=Math.imul;if(Math.imul(4294967295,5)!==-5){Math.imul=dr.imul;O.preserveToString(Math.imul,Ir)}if(Math.imul.length!==2){X(Math,"imul",function imul(e,t){return te.Call(Ir, [...]
//# sourceMappingURL=es6-shim.map
diff --git a/package.json b/package.json
index feca237..6d28eea 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "es6-shim",
- "version": "0.34.1",
+ "version": "0.35.0",
"author": "Paul Miller (http://paulmillr.com)",
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines",
"keywords": [
@@ -67,17 +67,17 @@
},
"dependencies": {},
"devDependencies": {
- "chai": "^3.4.1",
- "es5-shim": "^4.4.1",
+ "chai": "^3.5.0",
+ "es5-shim": "^4.5.2",
"eslint": "^1.10.3",
"@ljharb/eslint-config": "^1.6.1",
"grunt": "^0.4.5",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-watch": "^0.6.1",
"grunt-saucelabs": "^8.6.2",
- "jscs": "^2.7.0",
- "jshint": "^2.8.0",
- "mocha": "^2.3.4",
+ "jscs": "^2.9.0",
+ "jshint": "^2.9.1",
+ "mocha": "^2.4.5",
"promises-aplus-tests": "^2.1.1",
"promises-es6-tests": "^0.5.0",
"uglify-js": "^2.6.1",
diff --git a/test-sham/function.js b/test-sham/function.js
new file mode 100644
index 0000000..43d8459
--- /dev/null
+++ b/test-sham/function.js
@@ -0,0 +1,54 @@
+/* global describe, it, xit, expect, require, beforeEach, afterEach */
+
+describe('Function', function () {
+ describe('#name', function () {
+ it('returns the name for named functions', function () {
+ var foo = function bar() {};
+ expect(foo.name).to.equal('bar');
+
+ // pre-ES6, this property is nonconfigurable.
+ var configurable = Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(foo, 'name').configurable : false;
+
+ expect(foo).to.have.ownPropertyDescriptor('name', {
+ configurable: !!configurable,
+ enumerable: false,
+ writable: false,
+ value: 'bar'
+ });
+ });
+
+ it('returns empty string for anonymous functions', function () {
+ var anon = function () {};
+ expect(anon.name).to.equal('');
+
+ // pre-ES6, this property is nonconfigurable.
+ var configurable = Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(anon, 'name').configurable : false;
+
+ expect(anon).to.have.ownPropertyDescriptor('name', {
+ configurable: !!configurable,
+ enumerable: false,
+ writable: false,
+ value: ''
+ });
+ });
+
+ it('returns "anomymous" for Function functions', function () {
+ /* eslint no-new-func: 1 */
+ /* jshint evil: true */
+ var func = Function('');
+ /* jshint evil: false */
+ expect(typeof func.name).to.equal('string');
+ expect(func.name === 'anonymous' || func.name === '').to.equal(true);
+
+ // pre-ES6, this property is nonconfigurable.
+ var configurable = Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(func, 'name').configurable : false;
+
+ expect(func).to.have.ownPropertyDescriptor('name', {
+ configurable: !!configurable,
+ enumerable: false,
+ writable: false,
+ value: func.name
+ });
+ });
+ });
+});
diff --git a/test-sham/index.html b/test-sham/index.html
index e83204d..2919ad4 100644
--- a/test-sham/index.html
+++ b/test-sham/index.html
@@ -13,6 +13,7 @@
<script src="../es6-sham.js"></script>
<script src="../test/browser-setup.js"></script>
<script src="set-prototype-of.js"></script>
+ <script src="function.js"></script>
<script src="../test/browser-onload.js"></script>
</head>
<body>
diff --git a/test/array.js b/test/array.js
index b0bf118..b8c2a4e 100644
--- a/test/array.js
+++ b/test/array.js
@@ -14,6 +14,10 @@ var runArrayTests = function (it) {
var ifSymbolUnscopablesIt = isSymbol(Sym.unscopables) ? it : xit;
var ifShimIt = (typeof process !== 'undefined' && process.env.NO_ES6_SHIM) ? it.skip : it;
+ var isNegativeZero = function (x) {
+ return (1 / x) < 0;
+ };
+
describe('Array', function () {
var list = [5, 10, 15, 20];
@@ -363,6 +367,30 @@ var runArrayTests = function (it) {
expect(!!unscopables).to.equal(true);
expect(unscopables.copyWithin).to.equal(true);
});
+
+ it('should delete the target key if the source key is not present', function () {
+ /* jshint elision: true */
+ /* jscs:disable disallowSpaceBeforeComma */
+ /* eslint-disable no-sparse-arrays */
+ expect([, 1, 2].copyWithin(1, 0)).to.eql([, , 1]);
+ /* jshint elision: false */
+ /* jscs:enable disallowSpaceBeforeComma */
+ /* eslint-enable no-sparse-arrays */
+ });
+
+ it('should check inherited properties as well', function () {
+ var Parent = function Parent() {};
+ Parent.prototype[0] = 'foo';
+ var sparse = new Parent();
+ sparse[1] = 1;
+ sparse[2] = 2;
+ sparse.length = 3;
+ var result = Array.prototype.copyWithin.call(sparse, 1, 0);
+ expect(result).to.have.property('0');
+ expect(result).not.to.have.ownProperty('0');
+ expect(result).to.have.ownProperty('1');
+ expect(result).to.eql({ 0: 'foo', 1: 'foo', 2: 1, length: 3 });
+ });
});
describe('#find()', function () {
@@ -951,6 +979,12 @@ var runArrayTests = function (it) {
expect(reduced).to.equal(accumulator);
});
});
+
+ describe('#indexOf()', function () {
+ it('converts second argument from -0 to +0', function () {
+ expect(isNegativeZero([true].indexOf(true, -0))).to.equal(false);
+ });
+ });
});
};
diff --git a/test/json.js b/test/json.js
index 0e4dba5..462e22a 100644
--- a/test/json.js
+++ b/test/json.js
@@ -69,6 +69,10 @@ describe('JSON', function () {
expect(JSON.stringify(obj, ['a', enumSym])).to.equal('{"a":1}');
expect(JSON.stringify(obj, ['a', enumSym], '|')).to.equal('{\n|"a": 1\n}');
});
+
+ it('ignores a non-array non-callable replacer object', function () {
+ expect(JSON.stringify('z', { test: null })).to.equal('"z"');
+ });
});
});
});
diff --git a/test/math.js b/test/math.js
index 494d7c5..f81218f 100644
--- a/test/math.js
+++ b/test/math.js
@@ -605,7 +605,10 @@ describe('Math', function () {
expect(isNegativeZero(Math.tanh(-0))).to.equal(true);
expect(Math.tanh(Infinity)).to.equal(1);
expect(Math.tanh(-Infinity)).to.equal(-1);
- expect(Math.tanh(90)).to.almostEqual(1);
+ expect(Math.tanh(19)).to.almostEqual(1);
+ expect(Math.tanh(-19)).to.almostEqual(-1);
+ expect(Math.tanh(20)).to.equal(1); // JS loses precision for true value at this integer
+ expect(Math.tanh(-20)).to.equal(-1); // JS loses precision for true value at this integer
expect(Math.tanh(10)).to.almostEqual(0.9999999958776927);
expect(Math.tanh(-2e-17)).to.equal(-2e-17);
});
diff --git a/test/number.js b/test/number.js
index 548bf56..508b3e3 100644
--- a/test/number.js
+++ b/test/number.js
@@ -64,6 +64,36 @@ describe('Number', function () {
expect(Number.propertyIsEnumerable('EPSILON')).to.equal(false);
expect(Number.EPSILON).to.equal(2.2204460492503130808472633361816e-16);
});
+
+ it('should have NaN', function () {
+ expect(Number).to.have.property('NaN');
+ expect(Number.propertyIsEnumerable('NaN')).to.equal(false);
+ expect(isNaN(Number.NaN)).to.equal(true);
+ });
+
+ it('should have MAX_VALUE', function () {
+ expect(Number).to.have.property('MAX_VALUE');
+ expect(Number.propertyIsEnumerable('MAX_VALUE')).to.equal(false);
+ expect(Number.MAX_VALUE).to.equal(1.7976931348623157e+308);
+ });
+
+ it('should have MIN_VALUE', function () {
+ expect(Number).to.have.property('MIN_VALUE');
+ expect(Number.propertyIsEnumerable('MIN_VALUE')).to.equal(false);
+ expect(Number.MIN_VALUE).to.equal(5e-324);
+ });
+
+ it('should have NEGATIVE_INFINITY', function () {
+ expect(Number).to.have.property('NEGATIVE_INFINITY');
+ expect(Number.propertyIsEnumerable('NEGATIVE_INFINITY')).to.equal(false);
+ expect(Number.NEGATIVE_INFINITY).to.equal(-Infinity);
+ });
+
+ it('should have POSITIVE_INFINITY', function () {
+ expect(Number).to.have.property('POSITIVE_INFINITY');
+ expect(Number.propertyIsEnumerable('POSITIVE_INFINITY')).to.equal(false);
+ expect(Number.POSITIVE_INFINITY).to.equal(Infinity);
+ });
});
describe('.parseInt()', function () {
diff --git a/test/promise/reject.js b/test/promise/reject.js
index 8d8fd63..bd3ad46 100644
--- a/test/promise/reject.js
+++ b/test/promise/reject.js
@@ -29,5 +29,6 @@ describe('Promise.reject', function () {
expect(function () { Promise.reject.call(42, promise); }).to['throw']();
expect(function () { Promise.reject.call(false, promise); }).to['throw']();
expect(function () { Promise.reject.call(true, promise); }).to['throw']();
+ promise.then(null, function () {}); // silence unhandled rejection errors in Chrome
});
});
diff --git a/test/reflect.js b/test/reflect.js
index 7dee6b0..0a745d4 100644
--- a/test/reflect.js
+++ b/test/reflect.js
@@ -280,111 +280,6 @@ describe('Reflect', function () {
});
});
- describe('.enumerate()', function () {
- if (typeof Reflect.enumerate === 'undefined') {
- return it('exists', function () {
- expect(Reflect).to.have.property('enumerate');
- });
- }
-
- it('is a function', function () {
- expect(typeof Reflect.enumerate).to.equal('function');
- });
-
- ifFunctionsHaveNamesIt('has the right name', function () {
- expect(Reflect.enumerate.name).to.equal('enumerate');
- });
-
- ifES5It('only includes enumerable properties', function () {
- var a = Object.create(null, {
- // Non-enumerable per default.
- a: { value: 1 }
- });
-
- a.b = 2;
-
- var iter = Reflect.enumerate(a);
-
- if (hasSymbols && typeof Symbol.iterator === 'symbol') {
- expect(Symbol.iterator in iter).to.equal(true);
- }
-
- expect(Array.from(iter)).to.deep.equal(['b']);
- });
-
- it('includes all enumerable properties of prototypes', function () {
- var Parent = function () {};
- Parent.prototype.prop = true;
-
- var Child = function () {};
- Child.prototype = new Parent();
- Child.prototype.childProp = true;
- var child = new Child();
-
- expect(Array.from(Reflect.enumerate(child)).sort()).to.deep.equal(['prop', 'childProp'].sort());
- });
-
- describe('keys determined at first next() call', function () {
- it('likely does not yield a key added after next()', function () {
- var obj = { a: 1, b: 2 },
- iter = Reflect.enumerate(obj);
-
- expect(iter.next()).to.deep.equal({ value: 'a', done: false });
-
- obj.c = 3;
- expect(iter.next()).to.deep.equal({ value: 'b', done: false });
- expect(iter.next()).to.deep.equal({ value: undefined, done: true });
- });
-
- it('may not yield a key added after enumerate(), before next()', function () {
- var obj = { a: 1, b: 2 };
- var iter = Reflect.enumerate(obj);
-
- obj.c = 3;
- expect(iter.next()).to.deep.equal({ value: 'a', done: false });
- expect(iter.next()).to.deep.equal({ value: 'b', done: false });
- var thirdResult = iter.next();
- // Webkit's implementation of Reflect.enumerate locks the keys at iterator creation
- if (thirdResult.done) {
- expect(iter.next()).to.deep.equal({ value: undefined, done: true });
- } else {
- expect(iter.next()).to.deep.equal({ value: 'c', done: false });
- expect(iter.next()).to.deep.equal({ value: undefined, done: true });
- }
- });
-
- it('does not yield an unyielded key deleted after first next()', function () {
- var obj = { a: 1, b: 2 };
- var iter = Reflect.enumerate(obj);
-
- expect(iter.next()).to.deep.equal({ value: 'a', done: false });
- delete obj.b;
- expect(iter.next()).to.deep.equal({ value: undefined, done: true });
- });
- });
-
- describe('enumeration order', function () {
- it('enumerates own keys before prototype keys', function () {
- var Foo = function Foo(arg) {
- this.b = arg;
- this[2] = arg;
- };
- Foo.prototype.a = 'bar';
- Foo.prototype.c = 'bar';
- Foo.prototype[1] = 'bar';
- var foo = new Foo(42);
-
- var iter = Reflect.enumerate(foo);
- expect(iter.next()).to.deep.equal({ value: '2', done: false });
- expect(iter.next()).to.deep.equal({ value: 'b', done: false });
- expect(iter.next()).to.deep.equal({ value: '1', done: false });
- expect(iter.next()).to.deep.equal({ value: 'a', done: false });
- expect(iter.next()).to.deep.equal({ value: 'c', done: false });
- expect(iter.next()).to.deep.equal({ value: undefined, done: true });
- });
- });
- });
-
describeIfES5('.get()', function () {
if (typeof Reflect.get === 'undefined') {
return it('exists', function () {
diff --git a/test/regexp.js b/test/regexp.js
index b79985c..b7521e1 100644
--- a/test/regexp.js
+++ b/test/regexp.js
@@ -269,6 +269,35 @@ describe('RegExp', function () {
});
});
+ describe('#toString()', function () {
+ it('throws on null/undefined', function () {
+ expect(function () { RegExp.prototype.toString.call(null); }).to['throw'](TypeError);
+ expect(function () { RegExp.prototype.toString.call(undefined); }).to['throw'](TypeError);
+ });
+
+ it('works on regexes', function () {
+ expect(RegExp.prototype.toString.call(/a/g)).to.equal('/a/g');
+ expect(RegExp.prototype.toString.call(new RegExp('a', 'g'))).to.equal('/a/g');
+ });
+
+ it('works on non-regexes', function () {
+ expect(RegExp.prototype.toString.call({ source: 'abc', flags: '' })).to.equal('/abc/');
+ expect(RegExp.prototype.toString.call({ source: 'abc', flags: 'xyz' })).to.equal('/abc/xyz');
+ });
+
+ ifSymbolsDescribe('Symbol.match', function () {
+ if (!hasSymbols || typeof Symbol.match === 'undefined') {
+ return;
+ }
+
+ it('accepts a non-regex with Symbol.match', function () {
+ var obj = { source: 'abc', flags: 'def' };
+ obj[Symbol.match] = RegExp.prototype[Symbol.match];
+ expect(RegExp.prototype.toString.call(obj)).to.equal('/abc/def');
+ });
+ });
+ });
+
describe('Object properties', function () {
it('does not have the nonstandard $input property', function () {
expect(RegExp).not.to.have.property('$input'); // Chrome < 39, Opera < 26 have this
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-es6-shim.git
More information about the Pkg-javascript-commits
mailing list