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

Unified Diff: src/api.cc

Issue 2806373005: [v8] v8::StackTrace::AsArray returns correct array (Closed)
Patch Set: addressed comments Created 3 years, 8 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 | « include/v8.h ('k') | src/isolate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index be65add4b2515be163dfbef4c6442204c120681a..69fd81a758d7fb32c1e0c1296d71c3693b0ebbc9 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2855,9 +2855,63 @@ int StackTrace::GetFrameCount() const {
return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
}
+namespace {
+i::Handle<i::JSObject> NewFrameObject(i::Isolate* isolate,
+ i::Handle<i::StackFrameInfo> frame) {
+ i::Handle<i::JSObject> frame_obj =
+ isolate->factory()->NewJSObject(isolate->object_function());
+ i::JSObject::AddProperty(
+ frame_obj, handle(isolate->heap()->line_string()),
+ handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE);
+ i::JSObject::AddProperty(
+ frame_obj, handle(isolate->heap()->column_string()),
+ handle(i::Smi::FromInt(frame->column_number() + 1), isolate), i::NONE);
+ i::JSObject::AddProperty(frame_obj,
+ isolate->factory()->InternalizeOneByteString(
+ STATIC_CHAR_VECTOR("scriptId")),
+ handle(i::Smi::FromInt(frame->script_id()), isolate),
+ i::NONE);
+ i::JSObject::AddProperty(frame_obj,
+ isolate->factory()->InternalizeOneByteString(
+ STATIC_CHAR_VECTOR("scriptName")),
+ handle(frame->script_name(), isolate), i::NONE);
+ i::JSObject::AddProperty(frame_obj,
+ isolate->factory()->InternalizeOneByteString(
+ STATIC_CHAR_VECTOR("scriptNameOrSourceURL")),
+ handle(frame->script_name_or_source_url(), isolate),
+ i::NONE);
+ i::JSObject::AddProperty(frame_obj,
+ isolate->factory()->InternalizeOneByteString(
+ STATIC_CHAR_VECTOR("functionName")),
+ handle(frame->function_name(), isolate), i::NONE);
+ i::JSObject::AddProperty(frame_obj,
+ isolate->factory()->InternalizeOneByteString(
+ STATIC_CHAR_VECTOR("isEval")),
+ isolate->factory()->ToBoolean(frame->is_eval()),
+ i::NONE);
+ i::JSObject::AddProperty(
+ frame_obj,
+ isolate->factory()->InternalizeOneByteString(
+ STATIC_CHAR_VECTOR("isConstructor")),
+ isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE);
+ return frame_obj;
+}
+} // namespace
Local<Array> StackTrace::AsArray() {
- return Utils::ToLocal(Utils::OpenHandle(this));
+ i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
+ i::Handle<i::JSArray> self = Utils::OpenHandle(this);
+ int frame_count = GetFrameCount();
+ i::Handle<i::FixedArray> frames =
+ isolate->factory()->NewFixedArray(frame_count);
+ for (int i = 0; i < frame_count; ++i) {
+ auto obj = i::JSReceiver::GetElement(isolate, self, i).ToHandleChecked();
+ auto frame = i::Handle<i::StackFrameInfo>::cast(obj);
+ i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame);
+ frames->set(i, *frame_obj);
+ }
+ return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements(
+ frames, i::FAST_ELEMENTS, frame_count));
}
« no previous file with comments | « include/v8.h ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698