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) {
case 2: kind = "values"; break;
case 3: kind = "entries"; break;
}
var result = [];
result.push(new InternalPropertyMirror("[[IteratorHasMore]]", details[0]));
result.push(new InternalPropertyMirror("[[IteratorIndex]]", details[1]));
var result = [
new InternalPropertyMirror("[[IteratorHasMore]]", details[0]),
new InternalPropertyMirror("[[IteratorIndex]]", details[1])
];
if (kind) {
result.push(new InternalPropertyMirror("[[IteratorKind]]", kind));
}
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)) {
var result = [];
result.push(new InternalPropertyMirror("[[PromiseStatus]]",
PromiseGetStatus_(value)));
result.push(new InternalPropertyMirror("[[PromiseValue]]",
PromiseGetValue_(value)));
return result;
return [
new InternalPropertyMirror("[[PromiseStatus]]", PromiseGetStatus_(value)),
new InternalPropertyMirror("[[PromiseValue]]", PromiseGetValue_(value))
];
}
return [];
}
......@@ -1443,11 +1451,16 @@ function GeneratorMirror(value) {
inherits(GeneratorMirror, ObjectMirror);
GeneratorMirror.prototype.status = function() {
var continuation = %GeneratorGetContinuation(this.value_);
function GeneratorGetStatus_(value) {
var continuation = %GeneratorGetContinuation(value);
if (continuation < 0) return "running";
if (continuation == 0) return "closed";
return "suspended";
}
GeneratorMirror.prototype.status = function() {
return GeneratorGetStatus_(this.value_);
};
......
......@@ -24,7 +24,7 @@ MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function TestGeneratorMirror(g, test) {
function TestGeneratorMirror(g, status, line, column, receiver) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(g);
var serializer = debug.MakeMirrorSerializer();
......@@ -44,41 +44,69 @@ function TestGeneratorMirror(g, test) {
assertFalse(mirror.isPrimitive());
assertEquals('Generator', mirror.className());
assertTrue(mirror.receiver().isUndefined());
assertEquals(receiver, mirror.receiver().value());
assertEquals(generator, mirror.func().value());
test(mirror);
}
assertEquals(status, mirror.status());
// Note that line numbers are 0-based, not 1-based.
var loc = mirror.sourceLocation();
if (status === 'suspended') {
assertTrue(!!loc);
assertEquals(line, loc.line);
assertEquals(column, loc.column);
} else {
assertEquals(undefined, loc);
}
var iter = generator(function () {
assertEquals('running', debug.MakeMirror(iter).status());
})
TestInternalProperties(mirror, status, receiver);
}
// Note that line numbers are 0-based, not 1-based.
function assertSourceLocation(loc, line, column) {
assertEquals(line, loc.line);
assertEquals(column, loc.column);
function TestInternalProperties(mirror, status, receiver) {
var properties = mirror.internalProperties();
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());
}
TestGeneratorMirror(iter, function (mirror) {
assertEquals('suspended', mirror.status())
assertSourceLocation(mirror.sourceLocation(), 7, 19);
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();
TestGeneratorMirror(iter, function (mirror) {
assertEquals('suspended', mirror.status())
assertSourceLocation(mirror.sourceLocation(), 9, 2);
});
TestGeneratorMirror(iter, 'suspended', 9, 2);
iter.next();
TestGeneratorMirror(iter, function (mirror) {
assertEquals('suspended', mirror.status())
assertSourceLocation(mirror.sourceLocation(), 11, 2);
});
TestGeneratorMirror(iter, 'suspended', 11, 2);
iter.next();
TestGeneratorMirror(iter, function (mirror) {
assertEquals('closed', mirror.status())
TestGeneratorMirror(iter, 'closed');
// 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());
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