Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index be65add4b2515be163dfbef4c6442204c120681a..2dc5b89d4b4293c10fb910a0ca77d4bda0210d4f 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -2855,9 +2855,83 @@ 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, |
+ StackTrace::StackTraceOptions options) { |
+ i::Handle<i::JSObject> frame_obj = |
+ isolate->factory()->NewJSObject(isolate->object_function()); |
+ if (options & StackTrace::kLineNumber) { |
+ i::JSObject::AddProperty( |
+ frame_obj, handle(isolate->heap()->line_string()), |
+ handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE); |
+ if (options & StackTrace::kColumnOffset) { |
+ i::JSObject::AddProperty( |
+ frame_obj, handle(isolate->heap()->column_string()), |
+ handle(i::Smi::FromInt(frame->column_number() + 1), isolate), |
+ i::NONE); |
+ } |
+ } |
+ if (options & StackTrace::kScriptId) { |
+ i::JSObject::AddProperty( |
+ frame_obj, |
+ isolate->factory()->InternalizeOneByteString( |
+ STATIC_CHAR_VECTOR("scriptId")), |
+ handle(i::Smi::FromInt(frame->script_id()), isolate), i::NONE); |
+ } |
+ if (options & StackTrace::kScriptName) { |
+ i::JSObject::AddProperty(frame_obj, |
+ isolate->factory()->InternalizeOneByteString( |
+ STATIC_CHAR_VECTOR("scriptName")), |
+ handle(frame->script_name(), isolate), i::NONE); |
+ } |
+ if (options & StackTrace::kScriptNameOrSourceURL) { |
+ i::JSObject::AddProperty( |
+ frame_obj, |
+ isolate->factory()->InternalizeOneByteString( |
+ STATIC_CHAR_VECTOR("scriptNameOrSourceURL")), |
+ handle(frame->script_name_or_source_url(), isolate), i::NONE); |
+ } |
+ if (options & StackTrace::kFunctionName) { |
+ i::JSObject::AddProperty(frame_obj, |
+ isolate->factory()->InternalizeOneByteString( |
+ STATIC_CHAR_VECTOR("functionName")), |
+ handle(frame->function_name(), isolate), i::NONE); |
+ } |
+ if (options & StackTrace::kIsEval) { |
+ i::JSObject::AddProperty(frame_obj, |
+ isolate->factory()->InternalizeOneByteString( |
+ STATIC_CHAR_VECTOR("isEval")), |
+ isolate->factory()->ToBoolean(frame->is_eval()), |
+ i::NONE); |
+ } |
+ if (options & StackTrace::kIsConstructor) { |
+ 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() { |
Yang
2017/04/11 13:05:49
AsArray doesnt seem to be used anywhere in Chromiu
kozy
2017/04/11 15:04:06
Done.
|
- 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); |
+ StackTraceOptions options = |
+ static_cast<StackTraceOptions>(frame->options()); |
+ i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame, options); |
+ frames->set(i, *frame_obj); |
+ } |
+ return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements( |
+ frames, i::FAST_ELEMENTS, frame_count)); |
} |