Commit cec0acad authored by aandrey's avatar aandrey Committed by Commit bot

Expose generator object internal properties via mirrors.

BUG=v8:3292
R=yangguo@chromium.org, wingo@igalia.com
LOG=N

Review URL: https://codereview.chromium.org/760303002

Cr-Commit-Position: refs/heads/master@{#25571}
parent d6285620
...@@ -931,20 +931,28 @@ ObjectMirror.GetInternalProperties = function(value) { ...@@ -931,20 +931,28 @@ ObjectMirror.GetInternalProperties = function(value) {
case 2: kind = "values"; break; case 2: kind = "values"; break;
case 3: kind = "entries"; break; case 3: kind = "entries"; break;
} }
var result = []; var result = [
result.push(new InternalPropertyMirror("[[IteratorHasMore]]", details[0])); new InternalPropertyMirror("[[IteratorHasMore]]", details[0]),
result.push(new InternalPropertyMirror("[[IteratorIndex]]", details[1])); new InternalPropertyMirror("[[IteratorIndex]]", details[1])
];
if (kind) { if (kind) {
result.push(new InternalPropertyMirror("[[IteratorKind]]", kind)); result.push(new InternalPropertyMirror("[[IteratorKind]]", kind));
} }
return result; return result;
} else if (IS_GENERATOR(value)) {
return [
new InternalPropertyMirror("[[GeneratorStatus]]",
GeneratorGetStatus_(value)),
new InternalPropertyMirror("[[GeneratorFunction]]",
%GeneratorGetFunction(value)),
new InternalPropertyMirror("[[GeneratorReceiver]]",
%GeneratorGetReceiver(value))
];
} else if (ObjectIsPromise(value)) { } else if (ObjectIsPromise(value)) {
var result = []; return [
result.push(new InternalPropertyMirror("[[PromiseStatus]]", new InternalPropertyMirror("[[PromiseStatus]]", PromiseGetStatus_(value)),
PromiseGetStatus_(value))); new InternalPropertyMirror("[[PromiseValue]]", PromiseGetValue_(value))
result.push(new InternalPropertyMirror("[[PromiseValue]]", ];
PromiseGetValue_(value)));
return result;
} }
return []; return [];
} }
...@@ -1443,11 +1451,16 @@ function GeneratorMirror(value) { ...@@ -1443,11 +1451,16 @@ function GeneratorMirror(value) {
inherits(GeneratorMirror, ObjectMirror); inherits(GeneratorMirror, ObjectMirror);
GeneratorMirror.prototype.status = function() { function GeneratorGetStatus_(value) {
var continuation = %GeneratorGetContinuation(this.value_); var continuation = %GeneratorGetContinuation(value);
if (continuation < 0) return "running"; if (continuation < 0) return "running";
if (continuation == 0) return "closed"; if (continuation == 0) return "closed";
return "suspended"; return "suspended";
}
GeneratorMirror.prototype.status = function() {
return GeneratorGetStatus_(this.value_);
}; };
......
...@@ -24,7 +24,7 @@ MirrorRefCache.prototype.lookup = function(handle) { ...@@ -24,7 +24,7 @@ MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle]; return this.refs_[handle];
} }
function TestGeneratorMirror(g, test) { function TestGeneratorMirror(g, status, line, column, receiver) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(g); var mirror = debug.MakeMirror(g);
var serializer = debug.MakeMirrorSerializer(); var serializer = debug.MakeMirrorSerializer();
...@@ -44,41 +44,69 @@ function TestGeneratorMirror(g, test) { ...@@ -44,41 +44,69 @@ function TestGeneratorMirror(g, test) {
assertFalse(mirror.isPrimitive()); assertFalse(mirror.isPrimitive());
assertEquals('Generator', mirror.className()); assertEquals('Generator', mirror.className());
assertTrue(mirror.receiver().isUndefined()); assertEquals(receiver, mirror.receiver().value());
assertEquals(generator, mirror.func().value()); assertEquals(generator, mirror.func().value());
test(mirror); assertEquals(status, mirror.status());
}
var iter = generator(function () {
assertEquals('running', debug.MakeMirror(iter).status());
})
// Note that line numbers are 0-based, not 1-based. // Note that line numbers are 0-based, not 1-based.
function assertSourceLocation(loc, line, column) { var loc = mirror.sourceLocation();
if (status === 'suspended') {
assertTrue(!!loc);
assertEquals(line, loc.line); assertEquals(line, loc.line);
assertEquals(column, loc.column); assertEquals(column, loc.column);
} else {
assertEquals(undefined, loc);
}
TestInternalProperties(mirror, status, receiver);
} }
TestGeneratorMirror(iter, function (mirror) { function TestInternalProperties(mirror, status, receiver) {
assertEquals('suspended', mirror.status()) var properties = mirror.internalProperties();
assertSourceLocation(mirror.sourceLocation(), 7, 19); assertEquals(3, properties.length);
assertEquals("[[GeneratorStatus]]", properties[0].name());
assertEquals(status, properties[0].value().value());
assertEquals("[[GeneratorFunction]]", properties[1].name());
assertEquals(generator, properties[1].value().value());
assertEquals("[[GeneratorReceiver]]", properties[2].name());
assertEquals(receiver, properties[2].value().value());
}
var iter = generator(function() {
var mirror = debug.MakeMirror(iter);
assertEquals('running', mirror.status());
assertEquals(undefined, mirror.sourceLocation());
TestInternalProperties(mirror, 'running');
}); });
TestGeneratorMirror(iter, 'suspended', 7, 19);
iter.next(); iter.next();
TestGeneratorMirror(iter, function (mirror) { TestGeneratorMirror(iter, 'suspended', 9, 2);
assertEquals('suspended', mirror.status())
assertSourceLocation(mirror.sourceLocation(), 9, 2);
});
iter.next(); iter.next();
TestGeneratorMirror(iter, function (mirror) { TestGeneratorMirror(iter, 'suspended', 11, 2);
assertEquals('suspended', mirror.status())
assertSourceLocation(mirror.sourceLocation(), 11, 2);
});
iter.next(); iter.next();
TestGeneratorMirror(iter, function (mirror) { TestGeneratorMirror(iter, 'closed');
assertEquals('closed', mirror.status())
// Test generator with receiver.
var obj = {foo: 42};
var iter2 = generator.call(obj, function() {
var mirror = debug.MakeMirror(iter2);
assertEquals('running', mirror.status());
assertEquals(undefined, mirror.sourceLocation()); assertEquals(undefined, mirror.sourceLocation());
TestInternalProperties(mirror, 'running', obj);
}); });
TestGeneratorMirror(iter2, 'suspended', 7, 19, obj);
iter2.next();
TestGeneratorMirror(iter2, 'suspended', 9, 2, obj);
iter2.next();
TestGeneratorMirror(iter2, 'suspended', 11, 2, obj);
iter2.next();
TestGeneratorMirror(iter2, 'closed', 0, 0, obj);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment