OLD | NEW |
---|---|
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 Loading... | |
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 StackTrace::StackTraceOptions options) { | |
2862 i::Handle<i::JSObject> frame_obj = | |
2863 isolate->factory()->NewJSObject(isolate->object_function()); | |
2864 if (options & StackTrace::kLineNumber) { | |
2865 i::JSObject::AddProperty( | |
2866 frame_obj, handle(isolate->heap()->line_string()), | |
2867 handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE); | |
2868 if (options & StackTrace::kColumnOffset) { | |
2869 i::JSObject::AddProperty( | |
2870 frame_obj, handle(isolate->heap()->column_string()), | |
2871 handle(i::Smi::FromInt(frame->column_number() + 1), isolate), | |
2872 i::NONE); | |
2873 } | |
2874 } | |
2875 if (options & StackTrace::kScriptId) { | |
2876 i::JSObject::AddProperty( | |
2877 frame_obj, | |
2878 isolate->factory()->InternalizeOneByteString( | |
2879 STATIC_CHAR_VECTOR("scriptId")), | |
2880 handle(i::Smi::FromInt(frame->script_id()), isolate), i::NONE); | |
2881 } | |
2882 if (options & StackTrace::kScriptName) { | |
2883 i::JSObject::AddProperty(frame_obj, | |
2884 isolate->factory()->InternalizeOneByteString( | |
2885 STATIC_CHAR_VECTOR("scriptName")), | |
2886 handle(frame->script_name(), isolate), i::NONE); | |
2887 } | |
2888 if (options & StackTrace::kScriptNameOrSourceURL) { | |
2889 i::JSObject::AddProperty( | |
2890 frame_obj, | |
2891 isolate->factory()->InternalizeOneByteString( | |
2892 STATIC_CHAR_VECTOR("scriptNameOrSourceURL")), | |
2893 handle(frame->script_name_or_source_url(), isolate), i::NONE); | |
2894 } | |
2895 if (options & StackTrace::kFunctionName) { | |
2896 i::JSObject::AddProperty(frame_obj, | |
2897 isolate->factory()->InternalizeOneByteString( | |
2898 STATIC_CHAR_VECTOR("functionName")), | |
2899 handle(frame->function_name(), isolate), i::NONE); | |
2900 } | |
2901 if (options & StackTrace::kIsEval) { | |
2902 i::JSObject::AddProperty(frame_obj, | |
2903 isolate->factory()->InternalizeOneByteString( | |
2904 STATIC_CHAR_VECTOR("isEval")), | |
2905 isolate->factory()->ToBoolean(frame->is_eval()), | |
2906 i::NONE); | |
2907 } | |
2908 if (options & StackTrace::kIsConstructor) { | |
2909 i::JSObject::AddProperty( | |
2910 frame_obj, | |
2911 isolate->factory()->InternalizeOneByteString( | |
2912 STATIC_CHAR_VECTOR("isConstructor")), | |
2913 isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE); | |
2914 } | |
2915 return frame_obj; | |
2916 } | |
2917 } // namespace | |
2858 | 2918 |
2859 Local<Array> StackTrace::AsArray() { | 2919 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.
| |
2860 return Utils::ToLocal(Utils::OpenHandle(this)); | 2920 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2921 i::Handle<i::JSArray> self = Utils::OpenHandle(this); | |
2922 int frame_count = GetFrameCount(); | |
2923 i::Handle<i::FixedArray> frames = | |
2924 isolate->factory()->NewFixedArray(frame_count); | |
2925 for (int i = 0; i < frame_count; ++i) { | |
2926 auto obj = i::JSReceiver::GetElement(isolate, self, i).ToHandleChecked(); | |
2927 auto frame = i::Handle<i::StackFrameInfo>::cast(obj); | |
2928 StackTraceOptions options = | |
2929 static_cast<StackTraceOptions>(frame->options()); | |
2930 i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame, options); | |
2931 frames->set(i, *frame_obj); | |
2932 } | |
2933 return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements( | |
2934 frames, i::FAST_ELEMENTS, frame_count)); | |
2861 } | 2935 } |
2862 | 2936 |
2863 | 2937 |
2864 Local<StackTrace> StackTrace::CurrentStackTrace( | 2938 Local<StackTrace> StackTrace::CurrentStackTrace( |
2865 Isolate* isolate, | 2939 Isolate* isolate, |
2866 int frame_limit, | 2940 int frame_limit, |
2867 StackTraceOptions options) { | 2941 StackTraceOptions options) { |
2868 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2942 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
2869 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 2943 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
2870 i::Handle<i::JSArray> stackTrace = | 2944 i::Handle<i::JSArray> stackTrace = |
(...skipping 7446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10317 Address callback_address = | 10391 Address callback_address = |
10318 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10392 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10319 VMState<EXTERNAL> state(isolate); | 10393 VMState<EXTERNAL> state(isolate); |
10320 ExternalCallbackScope call_scope(isolate, callback_address); | 10394 ExternalCallbackScope call_scope(isolate, callback_address); |
10321 callback(info); | 10395 callback(info); |
10322 } | 10396 } |
10323 | 10397 |
10324 | 10398 |
10325 } // namespace internal | 10399 } // namespace internal |
10326 } // namespace v8 | 10400 } // namespace v8 |
OLD | NEW |