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