| 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 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2834 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2834 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2835 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 2835 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
| 2836 i_isolate->PrintCurrentStackTrace(out); | 2836 i_isolate->PrintCurrentStackTrace(out); |
| 2837 } | 2837 } |
| 2838 | 2838 |
| 2839 | 2839 |
| 2840 // --- S t a c k T r a c e --- | 2840 // --- S t a c k T r a c e --- |
| 2841 | 2841 |
| 2842 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { | 2842 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
| 2843 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2843 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2844 ENTER_V8(isolate); | 2844 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2845 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2845 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2846 auto self = Utils::OpenHandle(this); | 2846 auto self = Utils::OpenHandle(this); |
| 2847 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); | 2847 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); |
| 2848 auto jsobj = i::Handle<i::JSObject>::cast(obj); | 2848 auto jsobj = i::Handle<i::JSObject>::cast(obj); |
| 2849 return scope.Escape(Utils::StackFrameToLocal(jsobj)); | 2849 return scope.Escape(Utils::StackFrameToLocal(jsobj)); |
| 2850 } | 2850 } |
| 2851 | 2851 |
| 2852 | 2852 |
| 2853 int StackTrace::GetFrameCount() const { | 2853 int StackTrace::GetFrameCount() const { |
| 2854 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); | 2854 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
| 2855 } | 2855 } |
| 2856 | 2856 |
| 2857 | 2857 |
| 2858 Local<Array> StackTrace::AsArray() { | 2858 Local<Array> StackTrace::AsArray() { |
| 2859 return Utils::ToLocal(Utils::OpenHandle(this)); | 2859 return Utils::ToLocal(Utils::OpenHandle(this)); |
| 2860 } | 2860 } |
| 2861 | 2861 |
| 2862 | 2862 |
| 2863 Local<StackTrace> StackTrace::CurrentStackTrace( | 2863 Local<StackTrace> StackTrace::CurrentStackTrace( |
| 2864 Isolate* isolate, | 2864 Isolate* isolate, |
| 2865 int frame_limit, | 2865 int frame_limit, |
| 2866 StackTraceOptions options) { | 2866 StackTraceOptions options) { |
| 2867 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2867 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2868 ENTER_V8(i_isolate); | 2868 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
| 2869 // TODO(dcarney): remove when ScriptDebugServer is fixed. | |
| 2870 options = static_cast<StackTraceOptions>( | |
| 2871 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins); | |
| 2872 i::Handle<i::JSArray> stackTrace = | 2869 i::Handle<i::JSArray> stackTrace = |
| 2873 i_isolate->CaptureCurrentStackTrace(frame_limit, options); | 2870 i_isolate->CaptureCurrentStackTrace(frame_limit, options); |
| 2874 return Utils::StackTraceToLocal(stackTrace); | 2871 return Utils::StackTraceToLocal(stackTrace); |
| 2875 } | 2872 } |
| 2876 | 2873 |
| 2877 | 2874 |
| 2878 // --- S t a c k F r a m e --- | 2875 // --- S t a c k F r a m e --- |
| 2879 | 2876 |
| 2880 static int getIntProperty(const StackFrame* f, const char* propertyName, | 2877 static int getIntProperty(const StackFrame* f, const char* propertyName, |
| 2881 int defaultValue) { | 2878 int defaultValue) { |
| 2882 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | 2879 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); |
| 2883 ENTER_V8(isolate); | 2880 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2884 i::HandleScope scope(isolate); | 2881 i::HandleScope scope(isolate); |
| 2885 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | 2882 i::Handle<i::JSObject> self = Utils::OpenHandle(f); |
| 2886 i::Handle<i::Object> obj = | 2883 i::Handle<i::Object> obj = |
| 2887 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | 2884 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); |
| 2888 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; | 2885 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; |
| 2889 } | 2886 } |
| 2890 | 2887 |
| 2891 | 2888 |
| 2892 int StackFrame::GetLineNumber() const { | 2889 int StackFrame::GetLineNumber() const { |
| 2893 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); | 2890 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); |
| 2894 } | 2891 } |
| 2895 | 2892 |
| 2896 | 2893 |
| 2897 int StackFrame::GetColumn() const { | 2894 int StackFrame::GetColumn() const { |
| 2898 return getIntProperty(this, "column", Message::kNoColumnInfo); | 2895 return getIntProperty(this, "column", Message::kNoColumnInfo); |
| 2899 } | 2896 } |
| 2900 | 2897 |
| 2901 | 2898 |
| 2902 int StackFrame::GetScriptId() const { | 2899 int StackFrame::GetScriptId() const { |
| 2903 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); | 2900 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); |
| 2904 } | 2901 } |
| 2905 | 2902 |
| 2906 | 2903 |
| 2907 static Local<String> getStringProperty(const StackFrame* f, | 2904 static Local<String> getStringProperty(const StackFrame* f, |
| 2908 const char* propertyName) { | 2905 const char* propertyName) { |
| 2909 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | 2906 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); |
| 2910 ENTER_V8(isolate); | 2907 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2911 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2908 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2912 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | 2909 i::Handle<i::JSObject> self = Utils::OpenHandle(f); |
| 2913 i::Handle<i::Object> obj = | 2910 i::Handle<i::Object> obj = |
| 2914 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | 2911 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); |
| 2915 return obj->IsString() | 2912 return obj->IsString() |
| 2916 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) | 2913 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) |
| 2917 : Local<String>(); | 2914 : Local<String>(); |
| 2918 } | 2915 } |
| 2919 | 2916 |
| 2920 | 2917 |
| 2921 Local<String> StackFrame::GetScriptName() const { | 2918 Local<String> StackFrame::GetScriptName() const { |
| 2922 return getStringProperty(this, "scriptName"); | 2919 return getStringProperty(this, "scriptName"); |
| 2923 } | 2920 } |
| 2924 | 2921 |
| 2925 | 2922 |
| 2926 Local<String> StackFrame::GetScriptNameOrSourceURL() const { | 2923 Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
| 2927 return getStringProperty(this, "scriptNameOrSourceURL"); | 2924 return getStringProperty(this, "scriptNameOrSourceURL"); |
| 2928 } | 2925 } |
| 2929 | 2926 |
| 2930 | 2927 |
| 2931 Local<String> StackFrame::GetFunctionName() const { | 2928 Local<String> StackFrame::GetFunctionName() const { |
| 2932 return getStringProperty(this, "functionName"); | 2929 return getStringProperty(this, "functionName"); |
| 2933 } | 2930 } |
| 2934 | 2931 |
| 2935 | 2932 |
| 2936 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { | 2933 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { |
| 2937 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | 2934 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); |
| 2938 ENTER_V8(isolate); | 2935 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 2939 i::HandleScope scope(isolate); | 2936 i::HandleScope scope(isolate); |
| 2940 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | 2937 i::Handle<i::JSObject> self = Utils::OpenHandle(f); |
| 2941 i::Handle<i::Object> obj = | 2938 i::Handle<i::Object> obj = |
| 2942 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | 2939 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); |
| 2943 return obj->IsTrue(isolate); | 2940 return obj->IsTrue(isolate); |
| 2944 } | 2941 } |
| 2945 | 2942 |
| 2946 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } | 2943 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } |
| 2947 | 2944 |
| 2948 | 2945 |
| (...skipping 7341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10290 Address callback_address = | 10287 Address callback_address = |
| 10291 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10288 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10292 VMState<EXTERNAL> state(isolate); | 10289 VMState<EXTERNAL> state(isolate); |
| 10293 ExternalCallbackScope call_scope(isolate, callback_address); | 10290 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10294 callback(info); | 10291 callback(info); |
| 10295 } | 10292 } |
| 10296 | 10293 |
| 10297 | 10294 |
| 10298 } // namespace internal | 10295 } // namespace internal |
| 10299 } // namespace v8 | 10296 } // namespace v8 |
| OLD | NEW |