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

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

Issue 580823002: Implement generator mirror (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« src/mirror-debugger.js ('K') | « src/runtime.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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Flags: --expose-debug-as debug
6 // Test the mirror object for functions.
7
8 function *generator(f) {
9 "use strict";
10 yield;
11 f();
12 yield;
13 }
14
15 function MirrorRefCache(json_refs) {
16 var tmp = eval('(' + json_refs + ')');
17 this.refs_ = [];
18 for (var i = 0; i < tmp.length; i++) {
19 this.refs_[tmp[i].handle] = tmp[i];
20 }
21 }
22
23 MirrorRefCache.prototype.lookup = function(handle) {
24 return this.refs_[handle];
25 }
26
27 function TestGeneratorMirror(g, test) {
28 // Create mirror and JSON representation.
29 var mirror = debug.MakeMirror(g);
30 var serializer = debug.MakeMirrorSerializer();
31 var json = JSON.stringify(serializer.serializeValue(mirror));
32 var refs = new MirrorRefCache(
33 JSON.stringify(serializer.serializeReferencedObjects()));
34
35 // Check the mirror hierachy.
36 assertTrue(mirror instanceof debug.Mirror);
37 assertTrue(mirror instanceof debug.ValueMirror);
38 assertTrue(mirror instanceof debug.ObjectMirror);
39 assertTrue(mirror instanceof debug.GeneratorMirror);
40
41 // Check the mirror properties.
42 assertTrue(mirror.isGenerator());
43 assertEquals('generator', mirror.type());
44 assertFalse(mirror.isPrimitive());
45 assertEquals("Generator", mirror.className());
46
47 assertTrue(mirror.receiver().isUndefined());
48 assertEquals(mirror.func().value(), generator);
aandrey 2014/09/17 13:21:30 will mirror.func().scope() return valid scopes for
wingo 2014/09/17 13:54:30 Yes, because func().scope() is the scope captured
49 assertTrue(mirror.context().isContext());
50
51 test(mirror);
52 }
53
54 var iter = generator(function () {})
55
56 // Note that line numbers are 0-based, not 1-based.
57 function assertSourceLocation(loc, line, column) {
58 assertEquals(line, loc.line);
59 assertEquals(column, loc.column);
60 }
61
62 TestGeneratorMirror(iter, function (mirror) {
63 assertEquals(mirror.status(), "suspended")
64 assertSourceLocation(mirror.sourceLocation(), 7, 19);
65 });
66
67 iter.next();
68 TestGeneratorMirror(iter, function (mirror) {
69 assertEquals(mirror.status(), "suspended")
70 assertSourceLocation(mirror.sourceLocation(), 9, 2);
71 });
72
73 iter.next();
74 TestGeneratorMirror(iter, function (mirror) {
75 assertEquals(mirror.status(), "suspended")
76 assertSourceLocation(mirror.sourceLocation(), 11, 2);
77 });
78
79 iter.next();
80 TestGeneratorMirror(iter, function (mirror) {
81 assertEquals(mirror.status(), "closed")
82 assertEquals(mirror.sourceLocation(), undefined);
83 });
OLDNEW
« src/mirror-debugger.js ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698