Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: test/mjsunit/harmony/instanceof-es6.js

Issue 1980483003: [es6] Reintroduce the instanceof operator in the backends. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-instanceof 5 // Flags: --harmony-instanceof
6 6
7 // Make sure it's an error if @@hasInstance isn't a function. 7 // Make sure it's an error if @@hasInstance isn't a function.
8 (function() { 8 (function() {
9 var F = {}; 9 var F = {};
10 F[Symbol.hasInstance] = null; 10 F[Symbol.hasInstance] = null;
(...skipping 30 matching lines...) Expand all
41 assertEquals(bound[Symbol.hasInstance](bc), true); 41 assertEquals(bound[Symbol.hasInstance](bc), true);
42 assertEquals(bound[Symbol.hasInstance]([]), false); 42 assertEquals(bound[Symbol.hasInstance]([]), false);
43 })(); 43 })();
44 44
45 // if OrdinaryHasInstance is passed a non-callable receiver, return false. 45 // if OrdinaryHasInstance is passed a non-callable receiver, return false.
46 assertEquals(Function.prototype[Symbol.hasInstance].call(Array, []), true); 46 assertEquals(Function.prototype[Symbol.hasInstance].call(Array, []), true);
47 assertEquals(Function.prototype[Symbol.hasInstance].call({}, {}), false); 47 assertEquals(Function.prototype[Symbol.hasInstance].call({}, {}), false);
48 48
49 // OrdinaryHasInstance passed a non-object argument returns false. 49 // OrdinaryHasInstance passed a non-object argument returns false.
50 assertEquals(Function.prototype[Symbol.hasInstance].call(Array, 0), false); 50 assertEquals(Function.prototype[Symbol.hasInstance].call(Array, 0), false);
51
52 // Cannot assign to @@hasInstance with %FunctionPrototype%.
53 (function() {
54 "use strict";
55 function F() {}
56 assertThrows(function() { F[Symbol.hasInstance] = (v) => v }, TypeError);
57 })();
58
59 // Check correct invocation of @@hasInstance handler on function instance.
60 (function() {
61 function F() {}
62 var proto = Object.getPrototypeOf(F);
63 Object.setPrototypeOf(F, null);
64 F[Symbol.hasInstance] = function(v) { return true };
Igor Sheludko 2016/05/17 08:40:32 How about increasing hasInstance invocation counte
Benedikt Meurer 2016/05/17 10:23:21 Done.
65 Object.setPrototypeOf(F, proto);
66 assertTrue(1 instanceof F);
67 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698