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

Side by Side Diff: test/mjsunit/es6/generators-mirror.js

Issue 1968263002: Remove unused 'receiver' field from generators (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: weaken dcheck 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
« no previous file with comments | « test/cctest/test-ast-expression-visitor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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: --expose-debug-as debug 5 // Flags: --expose-debug-as debug
6 // Test the mirror object for functions. 6 // Test the mirror object for functions.
7 7
8 function *generator(f) { 8 function *generator(f) {
9 "use strict"; 9 "use strict";
10 yield; 10 yield;
11 f(); 11 f();
12 yield; 12 yield;
13 } 13 }
14 14
15 function MirrorRefCache(json_refs) { 15 function MirrorRefCache(json_refs) {
16 var tmp = eval('(' + json_refs + ')'); 16 var tmp = eval('(' + json_refs + ')');
17 this.refs_ = []; 17 this.refs_ = [];
18 for (var i = 0; i < tmp.length; i++) { 18 for (var i = 0; i < tmp.length; i++) {
19 this.refs_[tmp[i].handle] = tmp[i]; 19 this.refs_[tmp[i].handle] = tmp[i];
20 } 20 }
21 } 21 }
22 22
23 MirrorRefCache.prototype.lookup = function(handle) { 23 MirrorRefCache.prototype.lookup = function(handle) {
24 return this.refs_[handle]; 24 return this.refs_[handle];
25 } 25 }
26 26
27 function TestGeneratorMirror(g, status, line, column, receiver) { 27 function TestGeneratorMirror(g, status, line, column) {
28 // Create mirror and JSON representation. 28 // Create mirror and JSON representation.
29 var mirror = debug.MakeMirror(g); 29 var mirror = debug.MakeMirror(g);
30 var serializer = debug.MakeMirrorSerializer(); 30 var serializer = debug.MakeMirrorSerializer();
31 var json = JSON.stringify(serializer.serializeValue(mirror)); 31 var json = JSON.stringify(serializer.serializeValue(mirror));
32 var refs = new MirrorRefCache( 32 var refs = new MirrorRefCache(
33 JSON.stringify(serializer.serializeReferencedObjects())); 33 JSON.stringify(serializer.serializeReferencedObjects()));
34 34
35 // Check the mirror hierachy. 35 // Check the mirror hierachy.
36 assertTrue(mirror instanceof debug.Mirror); 36 assertTrue(mirror instanceof debug.Mirror);
37 assertTrue(mirror instanceof debug.ValueMirror); 37 assertTrue(mirror instanceof debug.ValueMirror);
38 assertTrue(mirror instanceof debug.ObjectMirror); 38 assertTrue(mirror instanceof debug.ObjectMirror);
39 assertTrue(mirror instanceof debug.GeneratorMirror); 39 assertTrue(mirror instanceof debug.GeneratorMirror);
40 40
41 // Check the mirror properties. 41 // Check the mirror properties.
42 assertTrue(mirror.isGenerator()); 42 assertTrue(mirror.isGenerator());
43 assertEquals('generator', mirror.type()); 43 assertEquals('generator', mirror.type());
44 assertFalse(mirror.isPrimitive()); 44 assertFalse(mirror.isPrimitive());
45 assertEquals('Generator', mirror.className()); 45 assertEquals('Generator', mirror.className());
46 46
47 assertEquals(receiver, mirror.receiver().value());
48 assertEquals(generator, mirror.func().value()); 47 assertEquals(generator, mirror.func().value());
49 48
50 assertEquals(status, mirror.status()); 49 assertEquals(status, mirror.status());
51 50
52 // Note that line numbers are 0-based, not 1-based. 51 // Note that line numbers are 0-based, not 1-based.
53 var loc = mirror.sourceLocation(); 52 var loc = mirror.sourceLocation();
54 if (status === 'suspended') { 53 if (status === 'suspended') {
55 assertTrue(!!loc); 54 assertTrue(!!loc);
56 assertEquals(line, loc.line); 55 assertEquals(line, loc.line);
57 assertEquals(column, loc.column); 56 assertEquals(column, loc.column);
58 } else { 57 } else {
59 assertEquals(undefined, loc); 58 assertEquals(undefined, loc);
60 } 59 }
61 60
62 TestInternalProperties(mirror, status, receiver); 61 TestInternalProperties(mirror, status);
63 } 62 }
64 63
65 function TestInternalProperties(mirror, status, receiver) { 64 function TestInternalProperties(mirror, status) {
66 var properties = mirror.internalProperties(); 65 var properties = mirror.internalProperties();
67 assertEquals(3, properties.length); 66 assertEquals(3, properties.length);
68 assertEquals("[[GeneratorStatus]]", properties[0].name()); 67 assertEquals("[[GeneratorStatus]]", properties[0].name());
69 assertEquals(status, properties[0].value().value()); 68 assertEquals(status, properties[0].value().value());
70 assertEquals("[[GeneratorFunction]]", properties[1].name()); 69 assertEquals("[[GeneratorFunction]]", properties[1].name());
71 assertEquals(generator, properties[1].value().value()); 70 assertEquals(generator, properties[1].value().value());
72 assertEquals("[[GeneratorReceiver]]", properties[2].name());
73 assertEquals(receiver, properties[2].value().value());
74 } 71 }
75 72
76 var iter = generator(function() { 73 var iter = generator(function() {
77 var mirror = debug.MakeMirror(iter); 74 var mirror = debug.MakeMirror(iter);
78 assertEquals('running', mirror.status()); 75 assertEquals('running', mirror.status());
79 assertEquals(undefined, mirror.sourceLocation()); 76 assertEquals(undefined, mirror.sourceLocation());
80 TestInternalProperties(mirror, 'running'); 77 TestInternalProperties(mirror, 'running');
81 }); 78 });
82 79
83 TestGeneratorMirror(iter, 'suspended', 7, 19); 80 TestGeneratorMirror(iter, 'suspended', 7, 19);
84 81
85 iter.next(); 82 iter.next();
86 TestGeneratorMirror(iter, 'suspended', 9, 2); 83 TestGeneratorMirror(iter, 'suspended', 9, 2);
87 84
88 iter.next(); 85 iter.next();
89 TestGeneratorMirror(iter, 'suspended', 11, 2); 86 TestGeneratorMirror(iter, 'suspended', 11, 2);
90 87
91 iter.next(); 88 iter.next();
92 TestGeneratorMirror(iter, 'closed'); 89 TestGeneratorMirror(iter, 'closed');
93 90
94 // Test generator with receiver. 91 // Test generator with receiver.
95 var obj = {foo: 42}; 92 var obj = {foo: 42};
96 var iter2 = generator.call(obj, function() { 93 var iter2 = generator.call(obj, function() {
97 var mirror = debug.MakeMirror(iter2); 94 var mirror = debug.MakeMirror(iter2);
98 assertEquals('running', mirror.status()); 95 assertEquals('running', mirror.status());
99 assertEquals(undefined, mirror.sourceLocation()); 96 assertEquals(undefined, mirror.sourceLocation());
100 TestInternalProperties(mirror, 'running', obj); 97 TestInternalProperties(mirror, 'running');
101 }); 98 });
102 99
103 TestGeneratorMirror(iter2, 'suspended', 7, 19, obj); 100 TestGeneratorMirror(iter2, 'suspended', 7, 19);
104 101
105 iter2.next(); 102 iter2.next();
106 TestGeneratorMirror(iter2, 'suspended', 9, 2, obj); 103 TestGeneratorMirror(iter2, 'suspended', 9, 2);
107 104
108 iter2.next(); 105 iter2.next();
109 TestGeneratorMirror(iter2, 'suspended', 11, 2, obj); 106 TestGeneratorMirror(iter2, 'suspended', 11, 2);
110 107
111 iter2.next(); 108 iter2.next();
112 TestGeneratorMirror(iter2, 'closed', 0, 0, obj); 109 TestGeneratorMirror(iter2, 'closed', 0, 0);
OLDNEW
« no previous file with comments | « test/cctest/test-ast-expression-visitor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698