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 2826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2837 | 2837 |
2838 | 2838 |
2839 // --- S t a c k T r a c e --- | 2839 // --- S t a c k T r a c e --- |
2840 | 2840 |
2841 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { | 2841 Local<StackFrame> StackTrace::GetFrame(uint32_t index) const { |
2842 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2842 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2843 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 2843 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
2844 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2844 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2845 auto self = Utils::OpenHandle(this); | 2845 auto self = Utils::OpenHandle(this); |
2846 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); | 2846 auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked(); |
2847 auto jsobj = i::Handle<i::JSObject>::cast(obj); | 2847 auto info = i::Handle<i::StackFrameInfo>::cast(obj); |
2848 return scope.Escape(Utils::StackFrameToLocal(jsobj)); | 2848 return scope.Escape(Utils::StackFrameToLocal(info)); |
2849 } | 2849 } |
2850 | 2850 |
2851 | 2851 |
2852 int StackTrace::GetFrameCount() const { | 2852 int StackTrace::GetFrameCount() const { |
2853 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); | 2853 return i::Smi::cast(Utils::OpenHandle(this)->length())->value(); |
2854 } | 2854 } |
2855 | 2855 |
2856 | 2856 |
2857 Local<Array> StackTrace::AsArray() { | 2857 Local<Array> StackTrace::AsArray() { |
2858 return Utils::ToLocal(Utils::OpenHandle(this)); | 2858 return Utils::ToLocal(Utils::OpenHandle(this)); |
2859 } | 2859 } |
2860 | 2860 |
2861 | 2861 |
2862 Local<StackTrace> StackTrace::CurrentStackTrace( | 2862 Local<StackTrace> StackTrace::CurrentStackTrace( |
2863 Isolate* isolate, | 2863 Isolate* isolate, |
2864 int frame_limit, | 2864 int frame_limit, |
2865 StackTraceOptions options) { | 2865 StackTraceOptions options) { |
2866 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2866 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
2867 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); | 2867 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); |
2868 i::Handle<i::JSArray> stackTrace = | 2868 i::Handle<i::JSArray> stackTrace = |
2869 i_isolate->CaptureCurrentStackTrace(frame_limit, options); | 2869 i_isolate->CaptureCurrentStackTrace(frame_limit, options); |
2870 return Utils::StackTraceToLocal(stackTrace); | 2870 return Utils::StackTraceToLocal(stackTrace); |
2871 } | 2871 } |
2872 | 2872 |
2873 | 2873 |
2874 // --- S t a c k F r a m e --- | 2874 // --- S t a c k F r a m e --- |
2875 | 2875 |
2876 static int getIntProperty(const StackFrame* f, const char* propertyName, | |
2877 int defaultValue) { | |
2878 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
2879 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | |
2880 i::HandleScope scope(isolate); | |
2881 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
2882 i::Handle<i::Object> obj = | |
2883 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
2884 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; | |
2885 } | |
2886 | |
2887 | |
2888 int StackFrame::GetLineNumber() const { | 2876 int StackFrame::GetLineNumber() const { |
2889 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); | 2877 int v = Utils::OpenHandle(this)->line_number(); |
| 2878 return v ? v : Message::kNoLineNumberInfo; |
2890 } | 2879 } |
2891 | 2880 |
2892 | 2881 |
2893 int StackFrame::GetColumn() const { | 2882 int StackFrame::GetColumn() const { |
2894 return getIntProperty(this, "column", Message::kNoColumnInfo); | 2883 int v = Utils::OpenHandle(this)->column_number(); |
| 2884 return v ? v : Message::kNoLineNumberInfo; |
2895 } | 2885 } |
2896 | 2886 |
2897 | 2887 |
2898 int StackFrame::GetScriptId() const { | 2888 int StackFrame::GetScriptId() const { |
2899 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); | 2889 int v = Utils::OpenHandle(this)->script_id(); |
| 2890 return v ? v : Message::kNoScriptIdInfo; |
2900 } | 2891 } |
2901 | 2892 |
2902 | 2893 Local<String> StackFrame::GetScriptName() const { |
2903 static Local<String> getStringProperty(const StackFrame* f, | 2894 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2904 const char* propertyName) { | |
2905 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
2906 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | |
2907 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2895 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2908 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | 2896 i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this); |
2909 i::Handle<i::Object> obj = | 2897 i::Handle<i::Object> obj(self->script_name(), isolate); |
2910 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
2911 return obj->IsString() | 2898 return obj->IsString() |
2912 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) | 2899 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) |
2913 : Local<String>(); | 2900 : Local<String>(); |
2914 } | 2901 } |
2915 | 2902 |
2916 | 2903 |
2917 Local<String> StackFrame::GetScriptName() const { | |
2918 return getStringProperty(this, "scriptName"); | |
2919 } | |
2920 | |
2921 | |
2922 Local<String> StackFrame::GetScriptNameOrSourceURL() const { | 2904 Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
2923 return getStringProperty(this, "scriptNameOrSourceURL"); | 2905 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2906 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2907 i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this); |
| 2908 i::Handle<i::Object> obj(self->script_name_or_source_url(), isolate); |
| 2909 return obj->IsString() |
| 2910 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) |
| 2911 : Local<String>(); |
2924 } | 2912 } |
2925 | 2913 |
2926 | 2914 |
2927 Local<String> StackFrame::GetFunctionName() const { | 2915 Local<String> StackFrame::GetFunctionName() const { |
2928 return getStringProperty(this, "functionName"); | 2916 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 2917 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
| 2918 i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this); |
| 2919 i::Handle<i::Object> obj(self->function_name(), isolate); |
| 2920 return obj->IsString() |
| 2921 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) |
| 2922 : Local<String>(); |
| 2923 } |
| 2924 |
| 2925 bool StackFrame::IsEval() const { return Utils::OpenHandle(this)->is_eval(); } |
| 2926 |
| 2927 bool StackFrame::IsConstructor() const { |
| 2928 return Utils::OpenHandle(this)->is_constructor(); |
2929 } | 2929 } |
2930 | 2930 |
2931 | 2931 |
2932 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { | |
2933 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
2934 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | |
2935 i::HandleScope scope(isolate); | |
2936 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
2937 i::Handle<i::Object> obj = | |
2938 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
2939 return obj->IsTrue(isolate); | |
2940 } | |
2941 | |
2942 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } | |
2943 | |
2944 | |
2945 bool StackFrame::IsConstructor() const { | |
2946 return getBoolProperty(this, "isConstructor"); | |
2947 } | |
2948 | |
2949 | |
2950 // --- N a t i v e W e a k M a p --- | 2932 // --- N a t i v e W e a k M a p --- |
2951 | 2933 |
2952 Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) { | 2934 Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) { |
2953 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 2935 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
2954 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); | 2936 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
2955 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); | 2937 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); |
2956 i::JSWeakCollection::Initialize(weakmap, isolate); | 2938 i::JSWeakCollection::Initialize(weakmap, isolate); |
2957 return Utils::NativeWeakMapToLocal(weakmap); | 2939 return Utils::NativeWeakMapToLocal(weakmap); |
2958 } | 2940 } |
2959 | 2941 |
(...skipping 7380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10340 Address callback_address = | 10322 Address callback_address = |
10341 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10323 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10342 VMState<EXTERNAL> state(isolate); | 10324 VMState<EXTERNAL> state(isolate); |
10343 ExternalCallbackScope call_scope(isolate, callback_address); | 10325 ExternalCallbackScope call_scope(isolate, callback_address); |
10344 callback(info); | 10326 callback(info); |
10345 } | 10327 } |
10346 | 10328 |
10347 | 10329 |
10348 } // namespace internal | 10330 } // namespace internal |
10349 } // namespace v8 | 10331 } // namespace v8 |
OLD | NEW |