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

Side by Side Diff: src/api.cc

Issue 1474353002: Remove easy to remove calls to Isolate::Current() from api.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update Created 5 years 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
« include/v8.h ('K') | « src/api.h ('k') | src/d8.cc » ('j') | 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 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); 1062 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
1063 } 1063 }
1064 1064
1065 1065
1066 Local<AccessorSignature> AccessorSignature::New( 1066 Local<AccessorSignature> AccessorSignature::New(
1067 Isolate* isolate, Local<FunctionTemplate> receiver) { 1067 Isolate* isolate, Local<FunctionTemplate> receiver) {
1068 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); 1068 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
1069 } 1069 }
1070 1070
1071 1071
1072 Local<TypeSwitch> TypeSwitch::New(Local<FunctionTemplate> type) {
1073 Local<FunctionTemplate> types[1] = {type};
1074 return TypeSwitch::New(1, types);
1075 }
1076
1077
1078 Local<TypeSwitch> TypeSwitch::New(int argc, Local<FunctionTemplate> types[]) {
1079 i::Isolate* isolate = i::Isolate::Current();
1080 LOG_API(isolate, "TypeSwitch::New");
1081 ENTER_V8(isolate);
1082 i::Handle<i::FixedArray> vector = isolate->factory()->NewFixedArray(argc);
1083 for (int i = 0; i < argc; i++)
1084 vector->set(i, *Utils::OpenHandle(*types[i]));
1085 i::Handle<i::Struct> struct_obj =
1086 isolate->factory()->NewStruct(i::TYPE_SWITCH_INFO_TYPE);
1087 i::Handle<i::TypeSwitchInfo> obj =
1088 i::Handle<i::TypeSwitchInfo>::cast(struct_obj);
1089 obj->set_types(*vector);
1090 return Utils::ToLocal(obj);
1091 }
1092
1093
1094 int TypeSwitch::match(v8::Local<Value> value) {
1095 i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this);
1096 LOG_API(info->GetIsolate(), "TypeSwitch::match");
1097 i::Handle<i::Object> obj = Utils::OpenHandle(*value);
1098 i::FixedArray* types = i::FixedArray::cast(info->types());
1099 for (int i = 0; i < types->length(); i++) {
1100 if (i::FunctionTemplateInfo::cast(types->get(i))->IsTemplateFor(*obj))
1101 return i + 1;
1102 }
1103 return 0;
1104 }
1105
1106
1107 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ 1072 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
1108 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ 1073 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \
1109 (obj)->setter(*foreign); \ 1074 (obj)->setter(*foreign); \
1110 } while (false) 1075 } while (false)
1111 1076
1112 1077
1113 void FunctionTemplate::SetCallHandler(FunctionCallback callback, 1078 void FunctionTemplate::SetCallHandler(FunctionCallback callback,
1114 v8::Local<Value> data, 1079 v8::Local<Value> data,
1115 v8::Local<Value> fast_handler) { 1080 v8::Local<Value> fast_handler) {
1116 auto info = Utils::OpenHandle(this); 1081 auto info = Utils::OpenHandle(this);
(...skipping 4903 matching lines...) Expand 10 before | Expand all | Expand 10 after
6020 5985
6021 double v8::NumberObject::ValueOf() const { 5986 double v8::NumberObject::ValueOf() const {
6022 i::Handle<i::Object> obj = Utils::OpenHandle(this); 5987 i::Handle<i::Object> obj = Utils::OpenHandle(this);
6023 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); 5988 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
6024 i::Isolate* isolate = jsvalue->GetIsolate(); 5989 i::Isolate* isolate = jsvalue->GetIsolate();
6025 LOG_API(isolate, "NumberObject::NumberValue"); 5990 LOG_API(isolate, "NumberObject::NumberValue");
6026 return jsvalue->value()->Number(); 5991 return jsvalue->value()->Number();
6027 } 5992 }
6028 5993
6029 5994
5995 Local<v8::Value> v8::BooleanObject::New(Isolate* isolate, bool value) {
5996 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5997 LOG_API(i_isolate, "BooleanObject::New");
5998 ENTER_V8(i_isolate);
5999 i::Handle<i::Object> boolean(value ? i_isolate->heap()->true_value()
6000 : i_isolate->heap()->false_value(),
6001 i_isolate);
6002 i::Handle<i::Object> obj =
6003 i::Object::ToObject(i_isolate, boolean).ToHandleChecked();
6004 return Utils::ToLocal(obj);
6005 }
6006
6007
6030 Local<v8::Value> v8::BooleanObject::New(bool value) { 6008 Local<v8::Value> v8::BooleanObject::New(bool value) {
6031 i::Isolate* isolate = i::Isolate::Current(); 6009 return New(Isolate::GetCurrent(), value);
6032 LOG_API(isolate, "BooleanObject::New");
6033 ENTER_V8(isolate);
6034 i::Handle<i::Object> boolean(value
6035 ? isolate->heap()->true_value()
6036 : isolate->heap()->false_value(),
6037 isolate);
6038 i::Handle<i::Object> obj =
6039 i::Object::ToObject(isolate, boolean).ToHandleChecked();
6040 return Utils::ToLocal(obj);
6041 } 6010 }
6042 6011
6043 6012
6044 bool v8::BooleanObject::ValueOf() const { 6013 bool v8::BooleanObject::ValueOf() const {
6045 i::Handle<i::Object> obj = Utils::OpenHandle(this); 6014 i::Handle<i::Object> obj = Utils::OpenHandle(this);
6046 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); 6015 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
6047 i::Isolate* isolate = jsvalue->GetIsolate(); 6016 i::Isolate* isolate = jsvalue->GetIsolate();
6048 LOG_API(isolate, "BooleanObject::BooleanValue"); 6017 LOG_API(isolate, "BooleanObject::BooleanValue");
6049 return jsvalue->value()->IsTrue(); 6018 return jsvalue->value()->IsTrue();
6050 } 6019 }
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after
7880 ENTER_V8(isolate); 7849 ENTER_V8(isolate);
7881 i::Handle<i::Object> val = Utils::OpenHandle(*value); 7850 i::Handle<i::Object> val = Utils::OpenHandle(*value);
7882 i::Handle<i::JSArray> result; 7851 i::Handle<i::JSArray> result;
7883 if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result)) 7852 if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result))
7884 return MaybeLocal<Array>(); 7853 return MaybeLocal<Array>();
7885 return Utils::ToLocal(result); 7854 return Utils::ToLocal(result);
7886 } 7855 }
7887 7856
7888 7857
7889 Local<String> CpuProfileNode::GetFunctionName() const { 7858 Local<String> CpuProfileNode::GetFunctionName() const {
7890 i::Isolate* isolate = i::Isolate::Current();
7891 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); 7859 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7860 i::Isolate* isolate = node->isolate();
7892 const i::CodeEntry* entry = node->entry(); 7861 const i::CodeEntry* entry = node->entry();
7893 i::Handle<i::String> name = 7862 i::Handle<i::String> name =
7894 isolate->factory()->InternalizeUtf8String(entry->name()); 7863 isolate->factory()->InternalizeUtf8String(entry->name());
7895 if (!entry->has_name_prefix()) { 7864 if (!entry->has_name_prefix()) {
7896 return ToApiHandle<String>(name); 7865 return ToApiHandle<String>(name);
7897 } else { 7866 } else {
7898 // We do not expect this to fail. Change this if it does. 7867 // We do not expect this to fail. Change this if it does.
7899 i::Handle<i::String> cons = isolate->factory()->NewConsString( 7868 i::Handle<i::String> cons = isolate->factory()->NewConsString(
7900 isolate->factory()->InternalizeUtf8String(entry->name_prefix()), 7869 isolate->factory()->InternalizeUtf8String(entry->name_prefix()),
7901 name).ToHandleChecked(); 7870 name).ToHandleChecked();
7902 return ToApiHandle<String>(cons); 7871 return ToApiHandle<String>(cons);
7903 } 7872 }
7904 } 7873 }
7905 7874
7906 7875
7907 int CpuProfileNode::GetScriptId() const { 7876 int CpuProfileNode::GetScriptId() const {
7908 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); 7877 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7909 const i::CodeEntry* entry = node->entry(); 7878 const i::CodeEntry* entry = node->entry();
7910 return entry->script_id(); 7879 return entry->script_id();
7911 } 7880 }
7912 7881
7913 7882
7914 Local<String> CpuProfileNode::GetScriptResourceName() const { 7883 Local<String> CpuProfileNode::GetScriptResourceName() const {
7915 i::Isolate* isolate = i::Isolate::Current();
7916 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); 7884 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7885 i::Isolate* isolate = node->isolate();
7917 return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String( 7886 return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
7918 node->entry()->resource_name())); 7887 node->entry()->resource_name()));
7919 } 7888 }
7920 7889
7921 7890
7922 int CpuProfileNode::GetLineNumber() const { 7891 int CpuProfileNode::GetLineNumber() const {
7923 return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number(); 7892 return reinterpret_cast<const i::ProfileNode*>(this)->entry()->line_number();
7924 } 7893 }
7925 7894
7926 7895
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
7976 } 7945 }
7977 7946
7978 7947
7979 const std::vector<CpuProfileDeoptInfo>& CpuProfileNode::GetDeoptInfos() const { 7948 const std::vector<CpuProfileDeoptInfo>& CpuProfileNode::GetDeoptInfos() const {
7980 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); 7949 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
7981 return node->deopt_infos(); 7950 return node->deopt_infos();
7982 } 7951 }
7983 7952
7984 7953
7985 void CpuProfile::Delete() { 7954 void CpuProfile::Delete() {
7986 i::Isolate* isolate = i::Isolate::Current(); 7955 i::CpuProfile* profile = reinterpret_cast<i::CpuProfile*>(this);
7956 i::Isolate* isolate = profile->top_down()->isolate();
7987 i::CpuProfiler* profiler = isolate->cpu_profiler(); 7957 i::CpuProfiler* profiler = isolate->cpu_profiler();
7988 DCHECK(profiler != NULL); 7958 DCHECK(profiler != NULL);
7989 profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this)); 7959 profiler->DeleteProfile(profile);
7990 } 7960 }
7991 7961
7992 7962
7993 Local<String> CpuProfile::GetTitle() const { 7963 Local<String> CpuProfile::GetTitle() const {
7994 i::Isolate* isolate = i::Isolate::Current();
7995 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 7964 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7965 i::Isolate* isolate = profile->top_down()->isolate();
7996 return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String( 7966 return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
7997 profile->title())); 7967 profile->title()));
7998 } 7968 }
7999 7969
8000 7970
8001 const CpuProfileNode* CpuProfile::GetTopDownRoot() const { 7971 const CpuProfileNode* CpuProfile::GetTopDownRoot() const {
8002 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 7972 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
8003 return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root()); 7973 return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
8004 } 7974 }
8005 7975
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
8072 reinterpret_cast<const i::HeapGraphEdge*>(edge)); 8042 reinterpret_cast<const i::HeapGraphEdge*>(edge));
8073 } 8043 }
8074 8044
8075 8045
8076 HeapGraphEdge::Type HeapGraphEdge::GetType() const { 8046 HeapGraphEdge::Type HeapGraphEdge::GetType() const {
8077 return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type()); 8047 return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
8078 } 8048 }
8079 8049
8080 8050
8081 Local<Value> HeapGraphEdge::GetName() const { 8051 Local<Value> HeapGraphEdge::GetName() const {
8082 i::Isolate* isolate = i::Isolate::Current();
8083 i::HeapGraphEdge* edge = ToInternal(this); 8052 i::HeapGraphEdge* edge = ToInternal(this);
8053 i::Isolate* isolate = edge->isolate();
8084 switch (edge->type()) { 8054 switch (edge->type()) {
8085 case i::HeapGraphEdge::kContextVariable: 8055 case i::HeapGraphEdge::kContextVariable:
8086 case i::HeapGraphEdge::kInternal: 8056 case i::HeapGraphEdge::kInternal:
8087 case i::HeapGraphEdge::kProperty: 8057 case i::HeapGraphEdge::kProperty:
8088 case i::HeapGraphEdge::kShortcut: 8058 case i::HeapGraphEdge::kShortcut:
8089 case i::HeapGraphEdge::kWeak: 8059 case i::HeapGraphEdge::kWeak:
8090 return ToApiHandle<String>( 8060 return ToApiHandle<String>(
8091 isolate->factory()->InternalizeUtf8String(edge->name())); 8061 isolate->factory()->InternalizeUtf8String(edge->name()));
8092 case i::HeapGraphEdge::kElement: 8062 case i::HeapGraphEdge::kElement:
8093 case i::HeapGraphEdge::kHidden: 8063 case i::HeapGraphEdge::kHidden:
(...skipping 22 matching lines...) Expand all
8116 reinterpret_cast<const i::HeapEntry*>(entry)); 8086 reinterpret_cast<const i::HeapEntry*>(entry));
8117 } 8087 }
8118 8088
8119 8089
8120 HeapGraphNode::Type HeapGraphNode::GetType() const { 8090 HeapGraphNode::Type HeapGraphNode::GetType() const {
8121 return static_cast<HeapGraphNode::Type>(ToInternal(this)->type()); 8091 return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
8122 } 8092 }
8123 8093
8124 8094
8125 Local<String> HeapGraphNode::GetName() const { 8095 Local<String> HeapGraphNode::GetName() const {
8126 i::Isolate* isolate = i::Isolate::Current(); 8096 i::Isolate* isolate = ToInternal(this)->isolate();
8127 return ToApiHandle<String>( 8097 return ToApiHandle<String>(
8128 isolate->factory()->InternalizeUtf8String(ToInternal(this)->name())); 8098 isolate->factory()->InternalizeUtf8String(ToInternal(this)->name()));
8129 } 8099 }
8130 8100
8131 8101
8132 SnapshotObjectId HeapGraphNode::GetId() const { 8102 SnapshotObjectId HeapGraphNode::GetId() const {
8133 return ToInternal(this)->id(); 8103 return ToInternal(this)->id();
8134 } 8104 }
8135 8105
8136 8106
(...skipping 13 matching lines...) Expand all
8150 } 8120 }
8151 8121
8152 8122
8153 static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) { 8123 static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
8154 return const_cast<i::HeapSnapshot*>( 8124 return const_cast<i::HeapSnapshot*>(
8155 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); 8125 reinterpret_cast<const i::HeapSnapshot*>(snapshot));
8156 } 8126 }
8157 8127
8158 8128
8159 void HeapSnapshot::Delete() { 8129 void HeapSnapshot::Delete() {
8160 i::Isolate* isolate = i::Isolate::Current(); 8130 i::Isolate* isolate = ToInternal(this)->profiler()->isolate();
8161 if (isolate->heap_profiler()->GetSnapshotsCount() > 1) { 8131 if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
8162 ToInternal(this)->Delete(); 8132 ToInternal(this)->Delete();
8163 } else { 8133 } else {
8164 // If this is the last snapshot, clean up all accessory data as well. 8134 // If this is the last snapshot, clean up all accessory data as well.
8165 isolate->heap_profiler()->DeleteAllSnapshots(); 8135 isolate->heap_profiler()->DeleteAllSnapshots();
8166 } 8136 }
8167 } 8137 }
8168 8138
8169 8139
8170 const HeapGraphNode* HeapSnapshot::GetRoot() const { 8140 const HeapGraphNode* HeapSnapshot::GetRoot() const {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
8346 #else 8316 #else
8347 if (run == GetStressRuns() - 1) { 8317 if (run == GetStressRuns() - 1) {
8348 SetFlagsFromString(kForcedOptimizations); 8318 SetFlagsFromString(kForcedOptimizations);
8349 } else if (run != GetStressRuns() - 2) { 8319 } else if (run != GetStressRuns() - 2) {
8350 SetFlagsFromString(kLazyOptimizations); 8320 SetFlagsFromString(kLazyOptimizations);
8351 } 8321 }
8352 #endif 8322 #endif
8353 } 8323 }
8354 8324
8355 8325
8356 // TODO(svenpanne) Deprecate this. 8326 void Testing::DeoptimizeAll(Isolate* isolate) {
8357 void Testing::DeoptimizeAll() { 8327 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
8358 i::Isolate* isolate = i::Isolate::Current(); 8328 i::HandleScope scope(i_isolate);
8359 i::HandleScope scope(isolate); 8329 internal::Deoptimizer::DeoptimizeAll(i_isolate);
8360 internal::Deoptimizer::DeoptimizeAll(isolate);
8361 } 8330 }
8362 8331
8363 8332
8364 namespace internal { 8333 namespace internal {
8365 8334
8366 8335
8367 void HandleScopeImplementer::FreeThreadResources() { 8336 void HandleScopeImplementer::FreeThreadResources() {
8368 Free(); 8337 Free();
8369 } 8338 }
8370 8339
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
8525 Address callback_address = 8494 Address callback_address =
8526 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8495 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8527 VMState<EXTERNAL> state(isolate); 8496 VMState<EXTERNAL> state(isolate);
8528 ExternalCallbackScope call_scope(isolate, callback_address); 8497 ExternalCallbackScope call_scope(isolate, callback_address);
8529 callback(info); 8498 callback(info);
8530 } 8499 }
8531 8500
8532 8501
8533 } // namespace internal 8502 } // namespace internal
8534 } // namespace v8 8503 } // namespace v8
OLDNEW
« include/v8.h ('K') | « src/api.h ('k') | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698