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

Unified Diff: test/mjsunit/es6/generators-mirror.js

Issue 580823002: Implement generator mirror (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits; rename generator-mirror.js to generators-mirror.js 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/generators-mirror.js
diff --git a/test/mjsunit/es6/generators-mirror.js b/test/mjsunit/es6/generators-mirror.js
new file mode 100644
index 0000000000000000000000000000000000000000..69252858825bfd7fe7c96d2a7850814ce5a94418
--- /dev/null
+++ b/test/mjsunit/es6/generators-mirror.js
@@ -0,0 +1,84 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug
+// Test the mirror object for functions.
+
+function *generator(f) {
+ "use strict";
+ yield;
+ f();
+ yield;
+}
+
+function MirrorRefCache(json_refs) {
+ var tmp = eval('(' + json_refs + ')');
+ this.refs_ = [];
+ for (var i = 0; i < tmp.length; i++) {
+ this.refs_[tmp[i].handle] = tmp[i];
+ }
+}
+
+MirrorRefCache.prototype.lookup = function(handle) {
+ return this.refs_[handle];
+}
+
+function TestGeneratorMirror(g, test) {
+ // Create mirror and JSON representation.
+ var mirror = debug.MakeMirror(g);
+ var serializer = debug.MakeMirrorSerializer();
+ var json = JSON.stringify(serializer.serializeValue(mirror));
+ var refs = new MirrorRefCache(
+ JSON.stringify(serializer.serializeReferencedObjects()));
+
+ // Check the mirror hierachy.
+ assertTrue(mirror instanceof debug.Mirror);
+ assertTrue(mirror instanceof debug.ValueMirror);
+ assertTrue(mirror instanceof debug.ObjectMirror);
+ assertTrue(mirror instanceof debug.GeneratorMirror);
+
+ // Check the mirror properties.
+ assertTrue(mirror.isGenerator());
+ assertEquals('generator', mirror.type());
+ assertFalse(mirror.isPrimitive());
+ assertEquals('Generator', mirror.className());
+
+ assertTrue(mirror.receiver().isUndefined());
+ assertEquals(generator, mirror.func().value());
+
+ test(mirror);
+}
+
+var iter = generator(function () {
+ assertEquals('running', debug.MakeMirror(iter).status());
+})
+
+// Note that line numbers are 0-based, not 1-based.
+function assertSourceLocation(loc, line, column) {
+ assertEquals(line, loc.line);
+ assertEquals(column, loc.column);
+}
+
+TestGeneratorMirror(iter, function (mirror) {
+ assertEquals('suspended', mirror.status())
+ assertSourceLocation(mirror.sourceLocation(), 7, 19);
+});
+
+iter.next();
+TestGeneratorMirror(iter, function (mirror) {
+ assertEquals('suspended', mirror.status())
+ assertSourceLocation(mirror.sourceLocation(), 9, 2);
+});
+
+iter.next();
+TestGeneratorMirror(iter, function (mirror) {
+ assertEquals('suspended', mirror.status())
+ assertSourceLocation(mirror.sourceLocation(), 11, 2);
+});
+
+iter.next();
+TestGeneratorMirror(iter, function (mirror) {
+ assertEquals('closed', mirror.status())
+ assertEquals(undefined, mirror.sourceLocation());
+});
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698