Commit 8bea9aba authored by Théotime Grohens's avatar Théotime Grohens Committed by Commit Bot

Add a nicer print for generator objects in %DebugPrint().

Change-Id: I971fe8a5aaadd6360f589451433848ed67e49813
Reviewed-on: https://chromium-review.googlesource.com/1054232Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Théotime Grohens <theotime@google.com>
Cr-Commit-Position: refs/heads/master@{#53160}
parent d25840c3
......@@ -145,7 +145,6 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
case JS_API_OBJECT_TYPE:
case JS_SPECIAL_API_OBJECT_TYPE:
case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
case JS_GENERATOR_OBJECT_TYPE:
case JS_ASYNC_GENERATOR_OBJECT_TYPE:
case JS_ARGUMENTS_TYPE:
case JS_ERROR_TYPE:
......@@ -156,6 +155,9 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
case WASM_TABLE_TYPE:
JSObject::cast(this)->JSObjectPrint(os);
break;
case JS_GENERATOR_OBJECT_TYPE:
JSGeneratorObject::cast(this)->JSGeneratorObjectPrint(os);
break;
case JS_PROMISE_TYPE:
JSPromise::cast(this)->JSPromisePrint(os);
break;
......@@ -600,6 +602,56 @@ void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT
JSObjectPrintBody(os, this);
}
void JSGeneratorObject::JSGeneratorObjectPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, this, "JSGeneratorObject");
os << "\n - function: " << Brief(function());
os << "\n - context: " << Brief(context());
os << "\n - receiver: " << Brief(receiver());
if (is_executing() || is_closed()) {
os << "\n - input: " << Brief(input_or_debug_pos());
} else {
DCHECK(is_suspended());
os << "\n - debug pos: " << Brief(input_or_debug_pos());
}
const char* mode = "(invalid)";
switch (resume_mode()) {
case kNext:
mode = ".next()";
break;
case kReturn:
mode = ".return()";
break;
case kThrow:
mode = ".throw()";
break;
}
os << "\n - resume mode: " << mode;
os << "\n - continuation: " << continuation();
if (is_closed()) os << " (closed)";
if (is_executing()) os << " (executing)";
if (is_suspended()) os << " (suspended)";
if (is_suspended()) {
DisallowHeapAllocation no_gc;
SharedFunctionInfo* fun_info = function()->shared();
if (fun_info->HasSourceCode()) {
Script* script = Script::cast(fun_info->script());
int lin = script->GetLineNumber(source_position()) + 1;
int col = script->GetColumnNumber(source_position()) + 1;
String* script_name = script->name()->IsString()
? String::cast(script->name())
: GetIsolate()->heap()->empty_string();
os << "\n - source position: " << source_position();
os << " (";
script_name->PrintUC16(os);
os << ", lin " << lin;
os << ", col " << col;
os << ")";
}
}
os << "\n - register file: " << Brief(register_file());
os << "\n";
}
void JSArray::JSArrayPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, this, "JSArray");
os << "\n - length: " << Brief(this->length());
......
......@@ -3232,6 +3232,7 @@ class JSGeneratorObject: public JSObject {
DECL_CAST(JSGeneratorObject)
// Dispatched behavior.
DECL_PRINTER(JSGeneratorObject)
DECL_VERIFIER(JSGeneratorObject)
// Magic sentinel values for the continuation.
......
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