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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); 2848 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked();
2849 auto info = i::Handle<i::StackFrameInfo>::cast(obj); 2849 auto info = i::Handle<i::StackFrameInfo>::cast(obj);
2850 return scope.Escape(Utils::StackFrameToLocal(info)); 2850 return scope.Escape(Utils::StackFrameToLocal(info));
2851 } 2851 }
2852 2852
2853 2853
2854 int StackTrace::GetFrameCount() const { 2854 int StackTrace::GetFrameCount() const {
2855 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); 2855 return i::Smi::cast(Utils::OpenHandle(this)->length())->value();
2856 } 2856 }
2857 2857
2858 namespace {
2859 i::Handle<i::JSObject> NewFrameObject(i::Isolate* isolate,
2860 i::Handle<i::StackFrameInfo> frame) {
2861 i::Handle<i::JSObject> frame_obj =
2862 isolate->factory()->NewJSObject(isolate->object_function());
2863 i::JSObject::AddProperty(
2864 frame_obj, handle(isolate->heap()->line_string()),
2865 handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE);
2866 i::JSObject::AddProperty(
2867 frame_obj, handle(isolate->heap()->column_string()),
2868 handle(i::Smi::FromInt(frame->column_number() + 1), isolate), i::NONE);
2869 i::JSObject::AddProperty(frame_obj,
2870 isolate->factory()->InternalizeOneByteString(
2871 STATIC_CHAR_VECTOR("scriptId")),
2872 handle(i::Smi::FromInt(frame->script_id()), isolate),
2873 i::NONE);
2874 i::JSObject::AddProperty(frame_obj,
2875 isolate->factory()->InternalizeOneByteString(
2876 STATIC_CHAR_VECTOR("scriptName")),
2877 handle(frame->script_name(), isolate), i::NONE);
2878 i::JSObject::AddProperty(frame_obj,
2879 isolate->factory()->InternalizeOneByteString(
2880 STATIC_CHAR_VECTOR("scriptNameOrSourceURL")),
2881 handle(frame->script_name_or_source_url(), isolate),
2882 i::NONE);
2883 i::JSObject::AddProperty(frame_obj,
2884 isolate->factory()->InternalizeOneByteString(
2885 STATIC_CHAR_VECTOR("functionName")),
2886 handle(frame->function_name(), isolate), i::NONE);
2887 i::JSObject::AddProperty(frame_obj,
2888 isolate->factory()->InternalizeOneByteString(
2889 STATIC_CHAR_VECTOR("isEval")),
2890 isolate->factory()->ToBoolean(frame->is_eval()),
2891 i::NONE);
2892 i::JSObject::AddProperty(
2893 frame_obj,
2894 isolate->factory()->InternalizeOneByteString(
2895 STATIC_CHAR_VECTOR("isConstructor")),
2896 isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE);
2897 return frame_obj;
2898 }
2899 } // namespace
2858 2900
2859 Local<Array> StackTrace::AsArray() { 2901 Local<Array> StackTrace::AsArray() {
2860 return Utils::ToLocal(Utils::OpenHandle(this)); 2902 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2903 i::Handle<i::JSArray> self = Utils::OpenHandle(this);
2904 int frame_count = GetFrameCount();
2905 i::Handle<i::FixedArray> frames =
2906 isolate->factory()->NewFixedArray(frame_count);
2907 for (int i = 0; i < frame_count; ++i) {
2908 auto obj = i::JSReceiver::GetElement(isolate, self, i).ToHandleChecked();
2909 auto frame = i::Handle<i::StackFrameInfo>::cast(obj);
2910 i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame);
2911 frames->set(i, *frame_obj);
2912 }
2913 return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements(
2914 frames, i::FAST_ELEMENTS, frame_count));
2861 } 2915 }
2862 2916
2863 2917
2864 Local<StackTrace> StackTrace::CurrentStackTrace( 2918 Local<StackTrace> StackTrace::CurrentStackTrace(
2865 Isolate* isolate, 2919 Isolate* isolate,
2866 int frame_limit, 2920 int frame_limit,
2867 StackTraceOptions options) { 2921 StackTraceOptions options) {
2868 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 2922 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2869 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); 2923 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
2870 i::Handle<i::JSArray> stackTrace = 2924 i::Handle<i::JSArray> stackTrace =
(...skipping 7446 matching lines...) Expand 10 before | Expand all | Expand 10 after
10317 Address callback_address = 10371 Address callback_address =
10318 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10372 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10319 VMState<EXTERNAL> state(isolate); 10373 VMState<EXTERNAL> state(isolate);
10320 ExternalCallbackScope call_scope(isolate, callback_address); 10374 ExternalCallbackScope call_scope(isolate, callback_address);
10321 callback(info); 10375 callback(info);
10322 } 10376 }
10323 10377
10324 10378
10325 } // namespace internal 10379 } // namespace internal
10326 } // namespace v8 10380 } // namespace v8
OLDNEW
« 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