diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/es-abstract/2018/ObjectCreate.js | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/es-abstract/2018/ObjectCreate.js')
-rw-r--r-- | src/node_modules/es-abstract/2018/ObjectCreate.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/node_modules/es-abstract/2018/ObjectCreate.js b/src/node_modules/es-abstract/2018/ObjectCreate.js new file mode 100644 index 0000000..e2445b0 --- /dev/null +++ b/src/node_modules/es-abstract/2018/ObjectCreate.js @@ -0,0 +1,37 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $ObjectCreate = GetIntrinsic('%Object.create%', true); +var $TypeError = GetIntrinsic('%TypeError%'); +var $SyntaxError = GetIntrinsic('%SyntaxError%'); + +var Type = require('./Type'); + +var hasProto = !({ __proto__: null } instanceof Object); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-objectcreate + +module.exports = function ObjectCreate(proto, internalSlotsList) { + if (proto !== null && Type(proto) !== 'Object') { + throw new $TypeError('Assertion failed: `proto` must be null or an object'); + } + var slots = arguments.length < 2 ? [] : internalSlotsList; + if (slots.length > 0) { + throw new $SyntaxError('es-abstract does not yet support internal slots'); + } + + if ($ObjectCreate) { + return $ObjectCreate(proto); + } + if (hasProto) { + return { __proto__: proto }; + } + + if (proto === null) { + throw new $SyntaxError('native Object.create support is required to create null objects'); + } + var T = function T() {}; + T.prototype = proto; + return new T(); +}; |