Chromium Code Reviews| Index: test/mjsunit/es6/generator-mirror.js |
| diff --git a/test/mjsunit/es6/generator-mirror.js b/test/mjsunit/es6/generator-mirror.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f80546e97f7c9eaa9659d1423a327e6a4d6dd2a6 |
| --- /dev/null |
| +++ b/test/mjsunit/es6/generator-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(mirror.func().value(), generator); |
| + |
| + test(mirror); |
| +} |
| + |
| +var iter = generator(function () { |
| + assertEquals(debug.MakeMirror(iter).status(), 'running'); |
|
aandrey
2014/09/18 08:45:21
nit: expected value is the first argument, actual
|
| +}) |
| + |
| +// 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(mirror.status(), "suspended") |
| + assertSourceLocation(mirror.sourceLocation(), 7, 19); |
| +}); |
| + |
| +iter.next(); |
| +TestGeneratorMirror(iter, function (mirror) { |
| + assertEquals(mirror.status(), "suspended") |
| + assertSourceLocation(mirror.sourceLocation(), 9, 2); |
| +}); |
| + |
| +iter.next(); |
| +TestGeneratorMirror(iter, function (mirror) { |
| + assertEquals(mirror.status(), "suspended") |
| + assertSourceLocation(mirror.sourceLocation(), 11, 2); |
| +}); |
| + |
| +iter.next(); |
| +TestGeneratorMirror(iter, function (mirror) { |
| + assertEquals(mirror.status(), "closed") |
| + assertEquals(mirror.sourceLocation(), undefined); |
| +}); |