1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-instanceof
// Make sure it's an error if @@hasInstance isn't a function.
(function() {
var F = {};
F[Symbol.hasInstance] = null;
assertThrows(function() { 0 instanceof F; }, TypeError);
})();
// Make sure the result is coerced to boolean.
(function() {
var F = {};
F[Symbol.hasInstance] = function() { return undefined; };
assertEquals(0 instanceof F, false);
F[Symbol.hasInstance] = function() { return null; };
assertEquals(0 instanceof F, false);
F[Symbol.hasInstance] = function() { return true; };
assertEquals(0 instanceof F, true);
})();
// Make sure if @@hasInstance throws, we catch it.
(function() {
var F = {};
F[Symbol.hasInstance] = function() { throw new Error("always throws"); }
try {
0 instanceof F;
} catch (e) {
assertEquals(e.message, "always throws");
}
})();
// @@hasInstance works for bound functions.
(function() {
var BC = function() {};
var bc = new BC();
var bound = BC.bind();
assertEquals(bound[Symbol.hasInstance](bc), true);
assertEquals(bound[Symbol.hasInstance]([]), false);
})();
// if OrdinaryHasInstance is passed a non-callable receiver, return false.
assertEquals(Function.prototype[Symbol.hasInstance].call(Array, []), true);
assertEquals(Function.prototype[Symbol.hasInstance].call({}, {}), false);
// OrdinaryHasInstance passed a non-object argument returns false.
assertEquals(Function.prototype[Symbol.hasInstance].call(Array, 0), false);
|