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

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

Issue 1692713005: ES6: Desugaring of instanceof to support @@hasInstance (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@blah
Patch Set: REBASE plus comment response. Created 4 years, 10 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
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | test/mjsunit/messages.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --harmony-instanceof
6
7 // Make sure it's an error if @@hasInstance isn't a function.
8 (function() {
9 var F = {};
10 F[Symbol.hasInstance] = null;
11 assertThrows(function() { 0 instanceof F; }, TypeError);
12 })();
13
14 // Make sure the result is coerced to boolean.
15 (function() {
16 var F = {};
17 F[Symbol.hasInstance] = function() { return undefined; };
18 assertEquals(0 instanceof F, false);
19 F[Symbol.hasInstance] = function() { return null; };
20 assertEquals(0 instanceof F, false);
21 F[Symbol.hasInstance] = function() { return true; };
22 assertEquals(0 instanceof F, true);
23 })();
24
25 // Make sure if @@hasInstance throws, we catch it.
26 (function() {
27 var F = {};
28 F[Symbol.hasInstance] = function() { throw new Error("always throws"); }
29 try {
30 0 instanceof F;
31 } catch (e) {
32 assertEquals(e.message, "always throws");
33 }
34 })();
35
36 // @@hasInstance works for bound functions.
37 (function() {
38 var BC = function() {};
39 var bc = new BC();
40 var bound = BC.bind();
41 assertEquals(bound[Symbol.hasInstance](bc), true);
42 assertEquals(bound[Symbol.hasInstance]([]), false);
43 })();
44
45 // if OrdinaryHasInstance is passed a non-callable receiver, return false.
46 assertEquals(Function.prototype[Symbol.hasInstance].call(Array, []), true);
47 assertEquals(Function.prototype[Symbol.hasInstance].call({}, {}), false);
48
49 // OrdinaryHasInstance passed a non-object argument returns false.
50 assertEquals(Function.prototype[Symbol.hasInstance].call(Array, 0), false);
OLDNEW
« no previous file with comments | « src/runtime/runtime-function.cc ('k') | test/mjsunit/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698