main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
923 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 |
|
---|
15 | var isObject = require('../helpers/isObject');
|
---|
16 |
|
---|
17 | // https://262.ecma-international.org/6.0/#sec-instanceofoperator
|
---|
18 |
|
---|
19 | module.exports = function InstanceofOperator(O, C) {
|
---|
20 | if (!isObject(O)) {
|
---|
21 | throw new $TypeError('Assertion failed: Type(O) is not Object');
|
---|
22 | }
|
---|
23 | var instOfHandler = $hasInstance ? GetMethod(C, $hasInstance) : void 0;
|
---|
24 | if (typeof instOfHandler !== 'undefined') {
|
---|
25 | return ToBoolean(Call(instOfHandler, C, [O]));
|
---|
26 | }
|
---|
27 | if (!IsCallable(C)) {
|
---|
28 | throw new $TypeError('`C` is not Callable');
|
---|
29 | }
|
---|
30 | return OrdinaryHasInstance(C, O);
|
---|
31 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.