main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
911 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 |
|
---|
7 | var $hasInstance = GetIntrinsic('Symbol.hasInstance', true);
|
---|
8 |
|
---|
9 | var Call = require('./Call');
|
---|
10 | var GetMethod = require('./GetMethod');
|
---|
11 | var IsCallable = require('./IsCallable');
|
---|
12 | var OrdinaryHasInstance = require('./OrdinaryHasInstance');
|
---|
13 | var ToBoolean = require('./ToBoolean');
|
---|
14 | var Type = require('./Type');
|
---|
15 |
|
---|
16 | // https://262.ecma-international.org/6.0/#sec-instanceofoperator
|
---|
17 |
|
---|
18 | module.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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.