From cdcedaa853cbb198209ca96588f2601297cc39fa Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 9 May 2017 00:10:37 +0100 Subject: [PATCH 1/2] avoid Array.from and Reflect --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 5e34095..ed10dc4 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const buildHelper = template(` function ExtendableBuiltin(){ // Not passing "newTarget" because core-js would fall back to non-exotic // object creation. - var instance = Reflect.construct(cls, Array.from(arguments)); + var instance = new (Function.prototype.bind.apply(cls, arguments))(); Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); return instance; } From aafe8fe115ff3c0ed491a59c2477d9092db3bab6 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 9 May 2017 00:20:50 +0100 Subject: [PATCH 2/2] consistent use of get/setPrototypeOf polyfill --- src/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index ed10dc4..dc0e016 100644 --- a/src/index.js +++ b/src/index.js @@ -6,11 +6,17 @@ import template from 'babel-template'; */ const buildHelper = template(` function HELPER(cls){ + var setPrototypeOf = Object.setPrototypeOf || (function setPrototypeOf(a, b) { + a.__proto__ = b; + }); + var getPrototypeOf = Object.getPrototypeOf || (function getPrototypeOf(a)) { + return a.__proto__; + }); function ExtendableBuiltin(){ // Not passing "newTarget" because core-js would fall back to non-exotic // object creation. var instance = new (Function.prototype.bind.apply(cls, arguments))(); - Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); + setPrototypeOf(instance, getPrototypeOf(this)); return instance; } ExtendableBuiltin.prototype = Object.create(cls.prototype, { @@ -21,12 +27,8 @@ const buildHelper = template(` configurable: true, }, }); - if (Object.setPrototypeOf){ - Object.setPrototypeOf(ExtendableBuiltin, cls); - } else { - ExtendableBuiltin.__proto__ = cls; - } + setPrototypeOf(ExtendableBuiltin, cls); return ExtendableBuiltin; } `);