blob: 3d52cc53caf56c9c93b545c7d52147670e29d28f [file] [log] [blame]
Tim van der Lippefdbd42e2020-04-07 14:14:361'use strict';
2
Tim van der Lippe2c891972021-07-29 15:22:503var GetIntrinsic = require('get-intrinsic');
Tim van der Lippefdbd42e2020-04-07 14:14:364
Nikolay Vitkovd76576c2024-12-02 14:10:155var $TypeError = require('es-errors/type');
Tim van der Lippefdbd42e2020-04-07 14:14:366
7var $hasInstance = GetIntrinsic('Symbol.hasInstance', true);
8
9var Call = require('./Call');
10var GetMethod = require('./GetMethod');
11var IsCallable = require('./IsCallable');
12var OrdinaryHasInstance = require('./OrdinaryHasInstance');
13var ToBoolean = require('./ToBoolean');
14var Type = require('./Type');
15
Nikolay Vitkovd76576c2024-12-02 14:10:1516// https://262.ecma-international.org/6.0/#sec-instanceofoperator
Tim van der Lippefdbd42e2020-04-07 14:14:3617
18module.exports = function InstanceofOperator(O, C) {
19 if (Type(O) !== 'Object') {
20 throw new $TypeError('Assertion failed: Type(O) is not Object');
21 }
22 var instOfHandler = $hasInstance ? GetMethod(C, $hasInstance) : void 0;
23 if (typeof instOfHandler !== 'undefined') {
24 return ToBoolean(Call(instOfHandler, C, [O]));
25 }
26 if (!IsCallable(C)) {
27 throw new $TypeError('`C` is not Callable');
28 }
29 return OrdinaryHasInstance(C, O);
30};