aboutsummaryrefslogtreecommitdiff
path: root/node_modules/core-js/library/modules/es6.reflect.construct.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/core-js/library/modules/es6.reflect.construct.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/core-js/library/modules/es6.reflect.construct.js')
-rw-r--r--node_modules/core-js/library/modules/es6.reflect.construct.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/node_modules/core-js/library/modules/es6.reflect.construct.js b/node_modules/core-js/library/modules/es6.reflect.construct.js
new file mode 100644
index 00000000..380addb5
--- /dev/null
+++ b/node_modules/core-js/library/modules/es6.reflect.construct.js
@@ -0,0 +1,47 @@
+// 26.1.2 Reflect.construct(target, argumentsList [, newTarget])
+var $export = require('./_export');
+var create = require('./_object-create');
+var aFunction = require('./_a-function');
+var anObject = require('./_an-object');
+var isObject = require('./_is-object');
+var fails = require('./_fails');
+var bind = require('./_bind');
+var rConstruct = (require('./_global').Reflect || {}).construct;
+
+// MS Edge supports only 2 arguments and argumentsList argument is optional
+// FF Nightly sets third argument as `new.target`, but does not create `this` from it
+var NEW_TARGET_BUG = fails(function () {
+ function F() { /* empty */ }
+ return !(rConstruct(function () { /* empty */ }, [], F) instanceof F);
+});
+var ARGS_BUG = !fails(function () {
+ rConstruct(function () { /* empty */ });
+});
+
+$export($export.S + $export.F * (NEW_TARGET_BUG || ARGS_BUG), 'Reflect', {
+ construct: function construct(Target, args /* , newTarget */) {
+ aFunction(Target);
+ anObject(args);
+ var newTarget = arguments.length < 3 ? Target : aFunction(arguments[2]);
+ if (ARGS_BUG && !NEW_TARGET_BUG) return rConstruct(Target, args, newTarget);
+ if (Target == newTarget) {
+ // w/o altered newTarget, optimization for 0-4 arguments
+ switch (args.length) {
+ case 0: return new Target();
+ case 1: return new Target(args[0]);
+ case 2: return new Target(args[0], args[1]);
+ case 3: return new Target(args[0], args[1], args[2]);
+ case 4: return new Target(args[0], args[1], args[2], args[3]);
+ }
+ // w/o altered newTarget, lot of arguments case
+ var $args = [null];
+ $args.push.apply($args, args);
+ return new (bind.apply(Target, $args))();
+ }
+ // with altered newTarget, not support built-in constructors
+ var proto = newTarget.prototype;
+ var instance = create(isObject(proto) ? proto : Object.prototype);
+ var result = Function.apply.call(Target, instance, args);
+ return isObject(result) ? result : instance;
+ }
+});