source: imaps-frontend/node_modules/es-abstract/2020/OrdinaryObjectCreate.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.6 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $ObjectCreate = GetIntrinsic('%Object.create%', true);
6var $TypeError = require('es-errors/type');
7var $SyntaxError = require('es-errors/syntax');
8
9var IsArray = require('./IsArray');
10var Type = require('./Type');
11
12var forEach = require('../helpers/forEach');
13
14var SLOT = require('internal-slot');
15
16var hasProto = require('has-proto')();
17
18// https://262.ecma-international.org/11.0/#sec-objectcreate
19
20module.exports = function OrdinaryObjectCreate(proto) {
21 if (proto !== null && Type(proto) !== 'Object') {
22 throw new $TypeError('Assertion failed: `proto` must be null or an object');
23 }
24 var additionalInternalSlotsList = arguments.length < 2 ? [] : arguments[1];
25 if (!IsArray(additionalInternalSlotsList)) {
26 throw new $TypeError('Assertion failed: `additionalInternalSlotsList` must be an Array');
27 }
28
29 // var internalSlotsList = ['[[Prototype]]', '[[Extensible]]']; // step 1
30 // internalSlotsList.push(...additionalInternalSlotsList); // step 2
31 // var O = MakeBasicObject(internalSlotsList); // step 3
32 // setProto(O, proto); // step 4
33 // return O; // step 5
34
35 var O;
36 if ($ObjectCreate) {
37 O = $ObjectCreate(proto);
38 } else if (hasProto) {
39 O = { __proto__: proto };
40 } else {
41 if (proto === null) {
42 throw new $SyntaxError('native Object.create support is required to create null objects');
43 }
44 var T = function T() {};
45 T.prototype = proto;
46 O = new T();
47 }
48
49 if (additionalInternalSlotsList.length > 0) {
50 forEach(additionalInternalSlotsList, function (slot) {
51 SLOT.set(O, slot, void undefined);
52 });
53 }
54
55 return O;
56};
Note: See TracBrowser for help on using the repository browser.