From 01cc9f54eb739dfdd307bf80df4b29d484cf3734 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 22 Oct 2015 23:47:23 -0700 Subject: [PATCH] Number: Fixed `wrapConstructor` to not require true ES5. See #365. --- README.md | 2 +- es6-shim.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec49b413..9e1b5416 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ In both browser and node you may also want to include `unorm`; see the [`String. * `RegExp.prototype`: * `flags` (requires ES5) ([a standalone shim is also available](https://github.com/es-shims/RegExp.prototype.flags)) * `Number`: - * binary and octal literals: `Number('0b1')` and `Number('0o7')` (requires ES5 property descriptor support) + * binary and octal literals: `Number('0b1')` and `Number('0o7')` * `EPSILON` * `MAX_SAFE_INTEGER` * `MIN_SAFE_INTEGER` diff --git a/es6-shim.js b/es6-shim.js index b3b42880..8e159628 100644 --- a/es6-shim.js +++ b/es6-shim.js @@ -228,10 +228,17 @@ // sets up proper prototype chain where possible Object.setPrototypeOf(original, replacement); } - _forEach(Object.getOwnPropertyNames(original), function (key) { - if (key in noop || keysToSkip[key]) { return; } - Value.proxy(original, key, replacement); - }); + if (supportsDescriptors) { + _forEach(Object.getOwnPropertyNames(original), function (key) { + if (key in noop || keysToSkip[key]) { return; } + Value.proxy(original, key, replacement); + }); + } else { + _forEach(Object.keys(original), function (key) { + if (key in noop || keysToSkip[key]) { return; } + replacement[key] = original[key]; + }); + } replacement.prototype = original.prototype; Value.redefine(original.prototype, 'constructor', replacement); }; @@ -1132,7 +1139,7 @@ }, true); } - if (supportsDescriptors && (Number('0o10') !== 8 || Number('0b10') !== 2)) { + if (Number('0o10') !== 8 || Number('0b10') !== 2) { var OrigNumber = Number; var binaryRegex = /^0b/i; var octalRegex = /^0o/i;