| 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 2733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2744 return GetScriptOrigin().ResourceName(); | 2744 return GetScriptOrigin().ResourceName(); |
| 2745 } | 2745 } |
| 2746 | 2746 |
| 2747 | 2747 |
| 2748 v8::Local<v8::StackTrace> Message::GetStackTrace() const { | 2748 v8::Local<v8::StackTrace> Message::GetStackTrace() const { |
| 2749 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2749 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2750 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 2750 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2751 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2751 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2752 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2752 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
| 2753 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); | 2753 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
| 2754 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); | 2754 if (!stackFramesObj->IsFixedArray()) return v8::Local<v8::StackTrace>(); |
| 2755 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); | 2755 auto stackTrace = i::Handle<i::FixedArray>::cast(stackFramesObj); |
| 2756 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); | 2756 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); |
| 2757 } | 2757 } |
| 2758 | 2758 |
| 2759 | 2759 |
| 2760 Maybe<int> Message::GetLineNumber(Local<Context> context) const { | 2760 Maybe<int> Message::GetLineNumber(Local<Context> context) const { |
| 2761 auto self = Utils::OpenHandle(this); | 2761 auto self = Utils::OpenHandle(this); |
| 2762 i::Isolate* isolate = self->GetIsolate(); | 2762 i::Isolate* isolate = self->GetIsolate(); |
| 2763 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 2763 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2764 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate)); | 2764 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate)); |
| 2765 auto msg = i::Handle<i::JSMessageObject>::cast(self); | 2765 auto msg = i::Handle<i::JSMessageObject>::cast(self); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2870 i_isolate->PrintCurrentStackTrace(out); | 2870 i_isolate->PrintCurrentStackTrace(out); |
| 2871 } | 2871 } |
| 2872 | 2872 |
| 2873 | 2873 |
| 2874 // --- S t a c k T r a c e --- | 2874 // --- S t a c k T r a c e --- |
| 2875 | 2875 |
| 2876 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { | 2876 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
| 2877 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2877 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2878 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 2878 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2879 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2879 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2880 auto self = Utils::OpenHandle(this); | 2880 auto obj = handle(Utils::OpenHandle(this)->get(index), isolate); |
| 2881 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); | |
| 2882 auto info = i::Handle<i::StackFrameInfo>::cast(obj); | 2881 auto info = i::Handle<i::StackFrameInfo>::cast(obj); |
| 2883 return scope.Escape(Utils::StackFrameToLocal(info)); | 2882 return scope.Escape(Utils::StackFrameToLocal(info)); |
| 2884 } | 2883 } |
| 2885 | 2884 |
| 2886 | 2885 |
| 2887 int StackTrace::GetFrameCount() const { | 2886 int StackTrace::GetFrameCount() const { |
| 2888 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); | 2887 return Utils::OpenHandle(this)->length(); |
| 2889 } | 2888 } |
| 2890 | 2889 |
| 2891 namespace { | 2890 namespace { |
| 2892 i::Handle<i::JSObject> NewFrameObject(i::Isolate* isolate, | 2891 i::Handle<i::JSObject> NewFrameObject(i::Isolate* isolate, |
| 2893 i::Handle<i::StackFrameInfo> frame) { | 2892 i::Handle<i::StackFrameInfo> frame) { |
| 2894 i::Handle<i::JSObject> frame_obj = | 2893 i::Handle<i::JSObject> frame_obj = |
| 2895 isolate->factory()->NewJSObject(isolate->object_function()); | 2894 isolate->factory()->NewJSObject(isolate->object_function()); |
| 2896 i::JSObject::AddProperty( | 2895 i::JSObject::AddProperty( |
| 2897 frame_obj, handle(isolate->heap()->line_string()), | 2896 frame_obj, handle(isolate->heap()->line_string()), |
| 2898 handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE); | 2897 handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2926 frame_obj, | 2925 frame_obj, |
| 2927 isolate->factory()->InternalizeOneByteString( | 2926 isolate->factory()->InternalizeOneByteString( |
| 2928 STATIC_CHAR_VECTOR("isConstructor")), | 2927 STATIC_CHAR_VECTOR("isConstructor")), |
| 2929 isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE); | 2928 isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE); |
| 2930 return frame_obj; | 2929 return frame_obj; |
| 2931 } | 2930 } |
| 2932 } // namespace | 2931 } // namespace |
| 2933 | 2932 |
| 2934 Local<Array> StackTrace::AsArray() { | 2933 Local<Array> StackTrace::AsArray() { |
| 2935 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2934 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2936 i::Handle<i::JSArray> self = Utils::OpenHandle(this); | 2935 i::Handle<i::FixedArray> self = Utils::OpenHandle(this); |
| 2937 int frame_count = GetFrameCount(); | 2936 int frame_count = self->length(); |
| 2938 i::Handle<i::FixedArray> frames = | 2937 i::Handle<i::FixedArray> frames = |
| 2939 isolate->factory()->NewFixedArray(frame_count); | 2938 isolate->factory()->NewFixedArray(frame_count); |
| 2940 for (int i = 0; i < frame_count; ++i) { | 2939 for (int i = 0; i < frame_count; ++i) { |
| 2941 auto obj = i::JSReceiver::GetElement(isolate, self, i).ToHandleChecked(); | 2940 auto obj = handle(self->get(i), isolate); |
| 2942 auto frame = i::Handle<i::StackFrameInfo>::cast(obj); | 2941 auto frame = i::Handle<i::StackFrameInfo>::cast(obj); |
| 2943 i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame); | 2942 i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame); |
| 2944 frames->set(i, *frame_obj); | 2943 frames->set(i, *frame_obj); |
| 2945 } | 2944 } |
| 2946 return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements( | 2945 return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements( |
| 2947 frames, i::FAST_ELEMENTS, frame_count)); | 2946 frames, i::FAST_ELEMENTS, frame_count)); |
| 2948 } | 2947 } |
| 2949 | 2948 |
| 2950 | 2949 |
| 2951 Local<StackTrace> StackTrace::CurrentStackTrace( | 2950 Local<StackTrace> StackTrace::CurrentStackTrace( |
| 2952 Isolate* isolate, | 2951 Isolate* isolate, |
| 2953 int frame_limit, | 2952 int frame_limit, |
| 2954 StackTraceOptions options) { | 2953 StackTraceOptions options) { |
| 2955 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2954 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2956 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 2955 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
| 2957 i::Handle<i::JSArray> stackTrace = | 2956 i::Handle<i::FixedArray> stackTrace = |
| 2958 i_isolate->CaptureCurrentStackTrace(frame_limit, options); | 2957 i_isolate->CaptureCurrentStackTrace(frame_limit, options); |
| 2959 return Utils::StackTraceToLocal(stackTrace); | 2958 return Utils::StackTraceToLocal(stackTrace); |
| 2960 } | 2959 } |
| 2961 | 2960 |
| 2962 | 2961 |
| 2963 // --- S t a c k F r a m e --- | 2962 // --- S t a c k F r a m e --- |
| 2964 | 2963 |
| 2965 int StackFrame::GetLineNumber() const { | 2964 int StackFrame::GetLineNumber() const { |
| 2966 int v = Utils::OpenHandle(this)->line_number(); | 2965 int v = Utils::OpenHandle(this)->line_number(); |
| 2967 return v ? v : Message::kNoLineNumberInfo; | 2966 return v ? v : Message::kNoLineNumberInfo; |
| (...skipping 7464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10432 Address callback_address = | 10431 Address callback_address = |
| 10433 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10432 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10434 VMState<EXTERNAL> state(isolate); | 10433 VMState<EXTERNAL> state(isolate); |
| 10435 ExternalCallbackScope call_scope(isolate, callback_address); | 10434 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10436 callback(info); | 10435 callback(info); |
| 10437 } | 10436 } |
| 10438 | 10437 |
| 10439 | 10438 |
| 10440 } // namespace internal | 10439 } // namespace internal |
| 10441 } // namespace v8 | 10440 } // namespace v8 |
| OLD | NEW |