From 46e43f4bde4a35785b4997b81e86cd19f046b69b Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 16:52:28 +0100 Subject: Commit --- .../es-abstract/2015/InstanceofOperator.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/node_modules/es-abstract/2015/InstanceofOperator.js (limited to 'src/node_modules/es-abstract/2015/InstanceofOperator.js') diff --git a/src/node_modules/es-abstract/2015/InstanceofOperator.js b/src/node_modules/es-abstract/2015/InstanceofOperator.js new file mode 100644 index 0000000..ebd308c --- /dev/null +++ b/src/node_modules/es-abstract/2015/InstanceofOperator.js @@ -0,0 +1,30 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); + +var $hasInstance = GetIntrinsic('Symbol.hasInstance', true); + +var Call = require('./Call'); +var GetMethod = require('./GetMethod'); +var IsCallable = require('./IsCallable'); +var OrdinaryHasInstance = require('./OrdinaryHasInstance'); +var ToBoolean = require('./ToBoolean'); +var Type = require('./Type'); + +// https://www.ecma-international.org/ecma-262/6.0/#sec-instanceofoperator + +module.exports = function InstanceofOperator(O, C) { + if (Type(O) !== 'Object') { + throw new $TypeError('Assertion failed: Type(O) is not Object'); + } + var instOfHandler = $hasInstance ? GetMethod(C, $hasInstance) : void 0; + if (typeof instOfHandler !== 'undefined') { + return ToBoolean(Call(instOfHandler, C, [O])); + } + if (!IsCallable(C)) { + throw new $TypeError('`C` is not Callable'); + } + return OrdinaryHasInstance(C, O); +}; -- cgit