Comparing version 0.10.1 to 0.11.0
{ | ||
"name": "es6-shim", | ||
"repo": "paulmillr/es6-shim", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -0,1 +1,12 @@ | ||
# es6-shim x.x.x (not yet released) | ||
# es6-shim 0.11.0 (11 May 2014) | ||
* Remove `Object.getOwnPropertyDescriptors`, per spec. (#234, #235) | ||
* IE8 fixes. (#163, #236) | ||
* Improve `Promise` scheduling. (#231) | ||
* Add some more standalone shims | ||
* Use an Object.create fallback, for better ES3 compatibility | ||
* Fix Math.expm1 in more browsers (#84) | ||
* Fix es6-shim in Web Workers (#247, #248) | ||
# es6-shim 0.10.1 (13 Mar 2014) | ||
@@ -2,0 +13,0 @@ * Update bower.json, component.json, and .npmignore (#229, #230, #233) |
{ | ||
"name": "es6-shim", | ||
"repo": "paulmillr/es6-shim", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
112
es6-shim.js
@@ -1,2 +0,2 @@ | ||
// ES6-shim 0.10.1 (c) 2013-2014 Paul Miller (http://paulmillr.com) | ||
// ES6-shim 0.11.0 (c) 2013-2014 Paul Miller (http://paulmillr.com) | ||
// ES6-shim may be freely distributed under the MIT license. | ||
@@ -52,3 +52,3 @@ // For more details and documentation: | ||
var main = function() { | ||
var globals = (typeof global === 'undefined') ? window : global; | ||
var globals = (typeof global === 'undefined') ? self : global; | ||
var global_isFinite = globals.isFinite; | ||
@@ -81,2 +81,13 @@ var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported(); | ||
// Simple shim for Object.create on ES3 browsers | ||
// (unlike real shim, no attepmt to support `prototype===null`) | ||
var create = Object.create || function(prototype, properties) { | ||
function Type() {} | ||
Type.prototype = prototype; | ||
var object = new Type(); | ||
if (typeof properties !== "undefined") | ||
defineProperties(object, properties); | ||
return object; | ||
}; | ||
// This is a private name in the es6 spec, equal to '[Symbol.iterator]' | ||
@@ -226,3 +237,3 @@ // we're going to use an arbitrary _-prefixed name to make our shims | ||
// OrdinaryCreateFromConstructor | ||
obj = Object.create(C.prototype || null); | ||
obj = create(C.prototype || null); | ||
} | ||
@@ -702,3 +713,5 @@ // Mark that we've used the es6 construct path | ||
// any way to identify its iterator. So add our own shimmed field. | ||
addIterator(Object.getPrototypeOf([].values())); | ||
if (Object.getPrototypeOf) { | ||
addIterator(Object.getPrototypeOf([].values())); | ||
} | ||
@@ -746,10 +759,2 @@ var maxSafeInteger = Math.pow(2, 53) - 1; | ||
defineProperties(Object, { | ||
getOwnPropertyDescriptors: function(subject) { | ||
var descs = {}; | ||
Object.getOwnPropertyNames(subject).forEach(function(propName) { | ||
descs[propName] = Object.getOwnPropertyDescriptor(subject, propName); | ||
}); | ||
return descs; | ||
}, | ||
getPropertyDescriptor: function(subject, name) { | ||
@@ -784,6 +789,14 @@ var pd = Object.getOwnPropertyDescriptor(subject, name); | ||
assign: function(target, source) { | ||
return Object.keys(source).reduce(function(target, key) { | ||
target[key] = source[key]; | ||
return target; | ||
}, target); | ||
if (!ES.TypeIsObject(target)) { | ||
throw new TypeError('target must be an object'); | ||
} | ||
return Array.prototype.reduce.call(arguments, function(target, source) { | ||
if (!ES.TypeIsObject(source)) { | ||
throw new TypeError('source must be an object'); | ||
} | ||
return Object.keys(source).reduce(function(target, key) { | ||
target[key] = source[key]; | ||
return target; | ||
}, target); | ||
}); | ||
} | ||
@@ -949,11 +962,3 @@ }); | ||
if (!global_isFinite(value) || value === 0) return value; | ||
var result = 0; | ||
var n = 50; | ||
for (var i = 1; i < n; i++) { | ||
for (var j = 2, factorial = 1; j <= i; j++) { | ||
factorial *= j; | ||
} | ||
result += Math.pow(value, i) / factorial; | ||
} | ||
return result; | ||
return Math.exp(value) - 1; | ||
}, | ||
@@ -1115,20 +1120,33 @@ | ||
var setTimeout = globals.setTimeout; | ||
var makeZeroTimeout = function() { | ||
// from http://dbaron.org/log/20100309-faster-timeouts | ||
var timeouts = []; | ||
var messageName = "zero-timeout-message"; | ||
var setZeroTimeout = function(fn) { | ||
timeouts.push(fn); | ||
window.postMessage(messageName, "*"); | ||
var makeZeroTimeout; | ||
if (typeof window !== 'undefined' && ES.IsCallable(window.postMessage)) { | ||
makeZeroTimeout = function() { | ||
// from http://dbaron.org/log/20100309-faster-timeouts | ||
var timeouts = []; | ||
var messageName = "zero-timeout-message"; | ||
var setZeroTimeout = function(fn) { | ||
timeouts.push(fn); | ||
window.postMessage(messageName, "*"); | ||
}; | ||
var handleMessage = function(event) { | ||
if (event.source == window && event.data == messageName) { | ||
event.stopPropagation(); | ||
if (timeouts.length === 0) { return; } | ||
var fn = timeouts.shift(); | ||
fn(); | ||
} | ||
}; | ||
window.addEventListener("message", handleMessage, true); | ||
return setZeroTimeout; | ||
}; | ||
var handleMessage = function(event) { | ||
if (event.source == window && event.data == messageName) { | ||
event.stopPropagation(); | ||
if (timeouts.length === 0) { return; } | ||
var fn = timeouts.shift(); | ||
fn(); | ||
} | ||
} | ||
var makePromiseAsap = function() { | ||
// An efficient task-scheduler based on a pre-existing Promise | ||
// implementation, which we can use even if we override the | ||
// global Promise below (in order to workaround bugs) | ||
// https://github.com/Raynos/observ-hash/issues/2#issuecomment-35857671 | ||
var P = globals.Promise; | ||
return P && P.resolve && function(task) { | ||
return P.resolve().then(task); | ||
}; | ||
window.addEventListener("message", handleMessage, true); | ||
return setZeroTimeout; | ||
}; | ||
@@ -1138,4 +1156,5 @@ var enqueue = ES.IsCallable(globals.setImmediate) ? | ||
typeof process === 'object' && process.nextTick ? process.nextTick : | ||
ES.IsCallable(window.postMessage) ? makeZeroTimeout() : | ||
function(task) { setTimeout(task, 0); }; // fallback | ||
makePromiseAsap() || | ||
(ES.IsCallable(makeZeroTimeout) ? makeZeroTimeout() : | ||
function(task) { setTimeout(task, 0); }); // fallback | ||
@@ -1251,3 +1270,3 @@ var triggerPromiseReactions = function(reactions, x) { | ||
var prototype = constructor.prototype || Promise$prototype; | ||
obj = obj || Object.create(prototype); | ||
obj = obj || create(prototype); | ||
defineProperties(obj, { | ||
@@ -1524,3 +1543,3 @@ _status: undefined, | ||
var prototype = constructor.prototype || Map$prototype; | ||
obj = obj || Object.create(prototype); | ||
obj = obj || create(prototype); | ||
defineProperties(obj, { _es6map: true }); | ||
@@ -1703,3 +1722,3 @@ return obj; | ||
var prototype = constructor.prototype || Set$prototype; | ||
obj = obj || Object.create(prototype); | ||
obj = obj || create(prototype); | ||
defineProperties(obj, { _es6set: true }); | ||
@@ -1821,2 +1840,3 @@ return obj; | ||
new globals.Map().size !== 0 || | ||
typeof globals.Map.prototype.keys !== 'function' || | ||
typeof globals.Set.prototype.keys !== 'function' || | ||
@@ -1823,0 +1843,0 @@ typeof globals.Map.prototype.forEach !== 'function' || |
{ | ||
"author": "Paul Miller (http://paulmillr.com)", | ||
"name": "es6-shim", | ||
"version": "0.10.1", | ||
"version": "0.11.0", | ||
"description": "ECMAScript 6 (Harmony) compatibility shims for legacy JavaScript engines", | ||
@@ -46,8 +46,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"mocha": "~1.17.1", | ||
"chai": "~1.9.0", | ||
"es5-shim": "~2.3.0", | ||
"jshint": "~2.4.3", | ||
"promises-aplus-tests": "~2.0.3" | ||
"mocha": "~1.18.2", | ||
"chai": "~1.9.1", | ||
"es5-shim": "~3.1.1", | ||
"jshint": "~2.5.0", | ||
"promises-aplus-tests": "~2.0.4" | ||
} | ||
} |
@@ -49,4 +49,4 @@ # ES6 Shim | ||
* `Array`: | ||
* `from()` | ||
* `of()` | ||
* `from()` ([a standalone shim is also available](https://npmjs.org/package/array.from)) | ||
* `of()` ([a standalone shim is also available](https://npmjs.org/package/array.of)) | ||
* `Array.prototype`: | ||
@@ -61,3 +61,2 @@ * `copyWithin()` | ||
* `Object`: | ||
* `getOwnPropertyDescriptors()` (ES5) | ||
* `getPropertyDescriptor()` (ES5) | ||
@@ -68,3 +67,3 @@ * `getPropertyNames()` (ES5) | ||
* `is()` ([a standalone shim is also available](https://github.com/ljharb/object-is)) | ||
* `assign()` | ||
* `assign()` ([a standalone shim is also available](https://github.com/ljharb/object.assign)) | ||
* `setPrototypeOf()` (IE >= 11) | ||
@@ -71,0 +70,0 @@ * `Math`: |
77316
1737
220