symbol-hasinstance-to-boolean.js (1455B)
1 // Copyright (C) 2015 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 es6id: 12.9.4 6 description: > 7 Type coercion of value returned by constructor's @@hasInstance property 8 info: | 9 1. If Type(C) is not Object, throw a TypeError exception. 10 2. Let instOfHandler be GetMethod(C,@@hasInstance). 11 3. ReturnIfAbrupt(instOfHandler). 12 4. If instOfHandler is not undefined, then 13 a. Return ToBoolean(Call(instOfHandler, C, «O»)). 14 features: [Symbol, Symbol.hasInstance] 15 ---*/ 16 17 var F = {}; 18 19 F[Symbol.hasInstance] = function() { return undefined; }; 20 assert.sameValue(0 instanceof F, false); 21 22 F[Symbol.hasInstance] = function() { return null; }; 23 assert.sameValue(0 instanceof F, false); 24 25 F[Symbol.hasInstance] = function() { return true; }; 26 assert.sameValue(0 instanceof F, true); 27 28 F[Symbol.hasInstance] = function() { return NaN; }; 29 assert.sameValue(0 instanceof F, false); 30 31 F[Symbol.hasInstance] = function() { return 1; }; 32 assert.sameValue(0 instanceof F, true); 33 34 F[Symbol.hasInstance] = function() { return ''; }; 35 assert.sameValue(0 instanceof F, false); 36 37 F[Symbol.hasInstance] = function() { return 'string'; }; 38 assert.sameValue(0 instanceof F, true); 39 40 F[Symbol.hasInstance] = function() { return Symbol(); }; 41 assert.sameValue(0 instanceof F, true); 42 43 F[Symbol.hasInstance] = function() { return {}; }; 44 assert.sameValue(0 instanceof F, true); 45 46 reportCompare(0, 0);