Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: src/api.cc

Issue 2761293002: Correctly annotate v8::StackTrace and v8::StackFrame API methods (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
mmoroz 2017/03/21 13:12:58 Looks like dcarney@ is not at Google anymore. Shou
jochen (gone - plz use gerrit) 2017/03/22 09:59:06 yeah, eventually we should do that... however, we'
mmoroz 2017/03/22 11:55:43 Yeah, I didn't mean to simply delete others. Sorry
jochen (gone - plz use gerrit) 2017/03/22 12:45:33 great! I'd do that in separate CLs, however. in t
mmoroz 2017/03/22 13:34:17 Done.
2870 options = static_cast<StackTraceOptions>( 2869 options = static_cast<StackTraceOptions>(
2871 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins); 2870 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins);
mmoroz 2017/03/21 13:12:58 Why do we need to expose frames across security or
jochen (gone - plz use gerrit) 2017/03/22 09:59:06 when we expose a stack to javascript, e.g. via new
mmoroz 2017/03/22 11:55:43 Acknowledged.
2872 i::Handle<i::JSArray> stackTrace = 2871 i::Handle<i::JSArray> stackTrace =
2873 i_isolate->CaptureCurrentStackTrace(frame_limit, options); 2872 i_isolate->CaptureCurrentStackTrace(frame_limit, options);
2874 return Utils::StackTraceToLocal(stackTrace); 2873 return Utils::StackTraceToLocal(stackTrace);
2875 } 2874 }
2876 2875
2877 2876
2878 // --- S t a c k F r a m e --- 2877 // --- S t a c k F r a m e ---
2879 2878
2880 static int getIntProperty(const StackFrame* f, const char* propertyName, 2879 static int getIntProperty(const StackFrame* f, const char* propertyName,
2881 int defaultValue) { 2880 int defaultValue) {
2882 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); 2881 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2883 ENTER_V8(isolate); 2882 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2884 i::HandleScope scope(isolate); 2883 i::HandleScope scope(isolate);
2885 i::Handle<i::JSObject> self = Utils::OpenHandle(f); 2884 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2886 i::Handle<i::Object> obj = 2885 i::Handle<i::Object> obj =
2887 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); 2886 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
mmoroz 2017/03/21 13:12:58 None of the tests failed, but I cannot understand
2888 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; 2887 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
2889 } 2888 }
2890 2889
2891 2890
2892 int StackFrame::GetLineNumber() const { 2891 int StackFrame::GetLineNumber() const {
2893 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); 2892 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
2894 } 2893 }
2895 2894
2896 2895
2897 int StackFrame::GetColumn() const { 2896 int StackFrame::GetColumn() const {
2898 return getIntProperty(this, "column", Message::kNoColumnInfo); 2897 return getIntProperty(this, "column", Message::kNoColumnInfo);
2899 } 2898 }
2900 2899
2901 2900
2902 int StackFrame::GetScriptId() const { 2901 int StackFrame::GetScriptId() const {
2903 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); 2902 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
2904 } 2903 }
2905 2904
2906 2905
2907 static Local<String> getStringProperty(const StackFrame* f, 2906 static Local<String> getStringProperty(const StackFrame* f,
2908 const char* propertyName) { 2907 const char* propertyName) {
2909 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); 2908 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2910 ENTER_V8(isolate); 2909 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2911 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 2910 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2912 i::Handle<i::JSObject> self = Utils::OpenHandle(f); 2911 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2913 i::Handle<i::Object> obj = 2912 i::Handle<i::Object> obj =
2914 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); 2913 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2915 return obj->IsString() 2914 return obj->IsString()
2916 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) 2915 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
2917 : Local<String>(); 2916 : Local<String>();
2918 } 2917 }
2919 2918
2920 2919
2921 Local<String> StackFrame::GetScriptName() const { 2920 Local<String> StackFrame::GetScriptName() const {
2922 return getStringProperty(this, "scriptName"); 2921 return getStringProperty(this, "scriptName");
2923 } 2922 }
2924 2923
2925 2924
2926 Local<String> StackFrame::GetScriptNameOrSourceURL() const { 2925 Local<String> StackFrame::GetScriptNameOrSourceURL() const {
2927 return getStringProperty(this, "scriptNameOrSourceURL"); 2926 return getStringProperty(this, "scriptNameOrSourceURL");
2928 } 2927 }
2929 2928
2930 2929
2931 Local<String> StackFrame::GetFunctionName() const { 2930 Local<String> StackFrame::GetFunctionName() const {
2932 return getStringProperty(this, "functionName"); 2931 return getStringProperty(this, "functionName");
2933 } 2932 }
2934 2933
2935 2934
2936 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { 2935 static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
2937 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); 2936 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2938 ENTER_V8(isolate); 2937 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2939 i::HandleScope scope(isolate); 2938 i::HandleScope scope(isolate);
2940 i::Handle<i::JSObject> self = Utils::OpenHandle(f); 2939 i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2941 i::Handle<i::Object> obj = 2940 i::Handle<i::Object> obj =
2942 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); 2941 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2943 return obj->IsTrue(isolate); 2942 return obj->IsTrue(isolate);
mmoroz 2017/03/21 13:12:58 This concerns me a bit. Can "IsTrue" evaluate the
2944 } 2943 }
2945 2944
2946 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } 2945 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
2947 2946
2948 2947
2949 bool StackFrame::IsConstructor() const { 2948 bool StackFrame::IsConstructor() const {
2950 return getBoolProperty(this, "isConstructor"); 2949 return getBoolProperty(this, "isConstructor");
2951 } 2950 }
2952 2951
2953 2952
(...skipping 7336 matching lines...) Expand 10 before | Expand all | Expand 10 after
10290 Address callback_address = 10289 Address callback_address =
10291 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10290 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10292 VMState<EXTERNAL> state(isolate); 10291 VMState<EXTERNAL> state(isolate);
10293 ExternalCallbackScope call_scope(isolate, callback_address); 10292 ExternalCallbackScope call_scope(isolate, callback_address);
10294 callback(info); 10293 callback(info);
10295 } 10294 }
10296 10295
10297 10296
10298 } // namespace internal 10297 } // namespace internal
10299 } // namespace v8 10298 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698