source: imaps-frontend/node_modules/es-abstract/2015/ObjectCreate.js

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 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/6.0/#sec-objectcreate
19
20module.exports = function ObjectCreate(proto, internalSlotsList) {
21 if (proto !== null && Type(proto) !== 'Object') {
22 throw new $TypeError('Assertion failed: `proto` must be null or an object');
23 }
24 var slots = arguments.length < 2 ? [] : internalSlotsList; // step 1
25 if (arguments.length >= 2 && !IsArray(slots)) {
26 throw new $TypeError('Assertion failed: `internalSlotsList` must be an Array');
27 }
28
29 var O;
30 if ($ObjectCreate) {
31 O = $ObjectCreate(proto);
32 } else if (hasProto) {
33 O = { __proto__: proto };
34 } else {
35 if (proto === null) {
36 throw new $SyntaxError('native Object.create support is required to create null objects');
37 }
38 var T = function T() {};
39 T.prototype = proto;
40 O = new T();
41 }
42
43 if (slots.length > 0) {
44 forEach(slots, function (slot) {
45 SLOT.set(O, slot, void undefined);
46 });
47 }
48
49 return O; // step 6
50};
Note: See TracBrowser for help on using the repository browser.