1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var $ObjectCreate = GetIntrinsic('%Object.create%', true);
|
6 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
7 |
|
|
var $SyntaxError = GetIntrinsic('%SyntaxError%');
|
8 |
|
|
|
9 |
|
|
var Type = require('./Type');
|
10 |
|
|
|
11 |
|
|
var hasProto = !({ __proto__: null } instanceof Object);
|
12 |
|
|
|
13 |
|
|
// https://www.ecma-international.org/ecma-262/6.0/#sec-objectcreate
|
14 |
|
|
|
15 |
|
|
module.exports = function ObjectCreate(proto, internalSlotsList) {
|
16 |
|
|
if (proto !== null && Type(proto) !== 'Object') {
|
17 |
|
|
throw new $TypeError('Assertion failed: `proto` must be null or an object');
|
18 |
|
|
}
|
19 |
|
|
var slots = arguments.length < 2 ? [] : internalSlotsList;
|
20 |
|
|
if (slots.length > 0) {
|
21 |
|
|
throw new $SyntaxError('es-abstract does not yet support internal slots');
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
if ($ObjectCreate) {
|
25 |
|
|
return $ObjectCreate(proto);
|
26 |
|
|
}
|
27 |
|
|
if (hasProto) {
|
28 |
|
|
return { __proto__: proto };
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
if (proto === null) {
|
32 |
|
|
throw new $SyntaxError('native Object.create support is required to create null objects');
|
33 |
|
|
}
|
34 |
|
|
var T = function T() {};
|
35 |
|
|
T.prototype = proto;
|
36 |
|
|
return new T();
|
37 |
|
|
};
|