source: trip-planner-front/node_modules/core-js/modules/es.reflect.construct.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1var $ = require('../internals/export');
2var getBuiltIn = require('../internals/get-built-in');
3var aFunction = require('../internals/a-function');
4var anObject = require('../internals/an-object');
5var isObject = require('../internals/is-object');
6var create = require('../internals/object-create');
7var bind = require('../internals/function-bind');
8var fails = require('../internals/fails');
9
10var nativeConstruct = getBuiltIn('Reflect', 'construct');
11
12// `Reflect.construct` method
13// https://tc39.es/ecma262/#sec-reflect.construct
14// MS Edge supports only 2 arguments and argumentsList argument is optional
15// FF Nightly sets third argument as `new.target`, but does not create `this` from it
16var NEW_TARGET_BUG = fails(function () {
17 function F() { /* empty */ }
18 return !(nativeConstruct(function () { /* empty */ }, [], F) instanceof F);
19});
20var ARGS_BUG = !fails(function () {
21 nativeConstruct(function () { /* empty */ });
22});
23var FORCED = NEW_TARGET_BUG || ARGS_BUG;
24
25$({ target: 'Reflect', stat: true, forced: FORCED, sham: FORCED }, {
26 construct: function construct(Target, args /* , newTarget */) {
27 aFunction(Target);
28 anObject(args);
29 var newTarget = arguments.length < 3 ? Target : aFunction(arguments[2]);
30 if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget);
31 if (Target == newTarget) {
32 // w/o altered newTarget, optimization for 0-4 arguments
33 switch (args.length) {
34 case 0: return new Target();
35 case 1: return new Target(args[0]);
36 case 2: return new Target(args[0], args[1]);
37 case 3: return new Target(args[0], args[1], args[2]);
38 case 4: return new Target(args[0], args[1], args[2], args[3]);
39 }
40 // w/o altered newTarget, lot of arguments case
41 var $args = [null];
42 $args.push.apply($args, args);
43 return new (bind.apply(Target, $args))();
44 }
45 // with altered newTarget, not support built-in constructors
46 var proto = newTarget.prototype;
47 var instance = create(isObject(proto) ? proto : Object.prototype);
48 var result = Function.apply.call(Target, instance, args);
49 return isObject(result) ? result : instance;
50 }
51});
Note: See TracBrowser for help on using the repository browser.