Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 self = Utils::OpenHandle(this); | 
| 2881 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); | 2881 if (index >= static_cast<uint32_t>(self->length())) { | 
| 
 
Clemens Hammacher
2017/04/14 10:10:42
Since the code did a `ToHandleChecked()` before, t
 
Clemens Hammacher
2017/04/14 10:10:42
Since the code did a `ToHandleChecked()` before, t
 
kozy
2017/04/14 16:15:03
Done.
 
 | |
| 2882 return Local<StackFrame>(); | |
| 2883 } | |
| 2884 auto obj = handle(self->get(index), isolate); | |
| 2882 auto info = i::Handle<i::StackFrameInfo>::cast(obj); | 2885 auto info = i::Handle<i::StackFrameInfo>::cast(obj); | 
| 2883 return scope.Escape(Utils::StackFrameToLocal(info)); | 2886 return scope.Escape(Utils::StackFrameToLocal(info)); | 
| 2884 } | 2887 } | 
| 2885 | 2888 | 
| 2886 | 2889 | 
| 2887 int StackTrace::GetFrameCount() const { | 2890 int StackTrace::GetFrameCount() const { | 
| 2888 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); | 2891 return Utils::OpenHandle(this)->length(); | 
| 2889 } | 2892 } | 
| 2890 | 2893 | 
| 2891 namespace { | 2894 namespace { | 
| 2892 i::Handle<i::JSObject> NewFrameObject(i::Isolate* isolate, | 2895 i::Handle<i::JSObject> NewFrameObject(i::Isolate* isolate, | 
| 2893 i::Handle<i::StackFrameInfo> frame) { | 2896 i::Handle<i::StackFrameInfo> frame) { | 
| 2894 i::Handle<i::JSObject> frame_obj = | 2897 i::Handle<i::JSObject> frame_obj = | 
| 2895 isolate->factory()->NewJSObject(isolate->object_function()); | 2898 isolate->factory()->NewJSObject(isolate->object_function()); | 
| 2896 i::JSObject::AddProperty( | 2899 i::JSObject::AddProperty( | 
| 2897 frame_obj, handle(isolate->heap()->line_string()), | 2900 frame_obj, handle(isolate->heap()->line_string()), | 
| 2898 handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE); | 2901 handle(i::Smi::FromInt(frame->line_number() + 1), isolate), i::NONE); | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 2926 frame_obj, | 2929 frame_obj, | 
| 2927 isolate->factory()->InternalizeOneByteString( | 2930 isolate->factory()->InternalizeOneByteString( | 
| 2928 STATIC_CHAR_VECTOR("isConstructor")), | 2931 STATIC_CHAR_VECTOR("isConstructor")), | 
| 2929 isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE); | 2932 isolate->factory()->ToBoolean(frame->is_constructor()), i::NONE); | 
| 2930 return frame_obj; | 2933 return frame_obj; | 
| 2931 } | 2934 } | 
| 2932 } // namespace | 2935 } // namespace | 
| 2933 | 2936 | 
| 2934 Local<Array> StackTrace::AsArray() { | 2937 Local<Array> StackTrace::AsArray() { | 
| 2935 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2938 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 
| 2936 i::Handle<i::JSArray> self = Utils::OpenHandle(this); | 2939 i::Handle<i::FixedArray> self = Utils::OpenHandle(this); | 
| 2937 int frame_count = GetFrameCount(); | 2940 int frame_count = self->length(); | 
| 2938 i::Handle<i::FixedArray> frames = | 2941 i::Handle<i::FixedArray> frames = | 
| 2939 isolate->factory()->NewFixedArray(frame_count); | 2942 isolate->factory()->NewFixedArray(frame_count); | 
| 2940 for (int i = 0; i < frame_count; ++i) { | 2943 for (int i = 0; i < frame_count; ++i) { | 
| 2941 auto obj = i::JSReceiver::GetElement(isolate, self, i).ToHandleChecked(); | 2944 auto obj = handle(self->get(i), isolate); | 
| 2942 auto frame = i::Handle<i::StackFrameInfo>::cast(obj); | 2945 auto frame = i::Handle<i::StackFrameInfo>::cast(obj); | 
| 2943 i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame); | 2946 i::Handle<i::JSObject> frame_obj = NewFrameObject(isolate, frame); | 
| 2944 frames->set(i, *frame_obj); | 2947 frames->set(i, *frame_obj); | 
| 2945 } | 2948 } | 
| 2946 return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements( | 2949 return Utils::ToLocal(isolate->factory()->NewJSArrayWithElements( | 
| 2947 frames, i::FAST_ELEMENTS, frame_count)); | 2950 frames, i::FAST_ELEMENTS, frame_count)); | 
| 2948 } | 2951 } | 
| 2949 | 2952 | 
| 2950 | 2953 | 
| 2951 Local<StackTrace> StackTrace::CurrentStackTrace( | 2954 Local<StackTrace> StackTrace::CurrentStackTrace( | 
| 2952 Isolate* isolate, | 2955 Isolate* isolate, | 
| 2953 int frame_limit, | 2956 int frame_limit, | 
| 2954 StackTraceOptions options) { | 2957 StackTraceOptions options) { | 
| 2955 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2958 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 
| 2956 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 2959 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 
| 2957 i::Handle<i::JSArray> stackTrace = | 2960 i::Handle<i::FixedArray> stackTrace = | 
| 2958 i_isolate->CaptureCurrentStackTrace(frame_limit, options); | 2961 i_isolate->CaptureCurrentStackTrace(frame_limit, options); | 
| 2959 return Utils::StackTraceToLocal(stackTrace); | 2962 return Utils::StackTraceToLocal(stackTrace); | 
| 2960 } | 2963 } | 
| 2961 | 2964 | 
| 2962 | 2965 | 
| 2963 // --- S t a c k F r a m e --- | 2966 // --- S t a c k F r a m e --- | 
| 2964 | 2967 | 
| 2965 int StackFrame::GetLineNumber() const { | 2968 int StackFrame::GetLineNumber() const { | 
| 2966 int v = Utils::OpenHandle(this)->line_number(); | 2969 int v = Utils::OpenHandle(this)->line_number(); | 
| 2967 return v ? v : Message::kNoLineNumberInfo; | 2970 return v ? v : Message::kNoLineNumberInfo; | 
| (...skipping 7451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10419 Address callback_address = | 10422 Address callback_address = | 
| 10420 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10423 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 
| 10421 VMState<EXTERNAL> state(isolate); | 10424 VMState<EXTERNAL> state(isolate); | 
| 10422 ExternalCallbackScope call_scope(isolate, callback_address); | 10425 ExternalCallbackScope call_scope(isolate, callback_address); | 
| 10423 callback(info); | 10426 callback(info); | 
| 10424 } | 10427 } | 
| 10425 | 10428 | 
| 10426 | 10429 | 
| 10427 } // namespace internal | 10430 } // namespace internal | 
| 10428 } // namespace v8 | 10431 } // namespace v8 | 
| OLD | NEW |