Skip to content

Commit 873dee9

Browse files
leeightrvagg
authored andcommitted
src: elevate v8 namespaces of repeated references
PR-URL: #24460 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent e16ff52 commit 873dee9

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

src/env.cc

+34-26
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@
1515
namespace node {
1616

1717
using v8::Context;
18+
using v8::EmbedderGraph;
19+
using v8::External;
1820
using v8::Function;
1921
using v8::FunctionTemplate;
2022
using v8::HandleScope;
2123
using v8::Integer;
2224
using v8::Isolate;
2325
using v8::Local;
2426
using v8::Message;
27+
using v8::NewStringType;
2528
using v8::Number;
29+
using v8::Object;
2630
using v8::Private;
31+
using v8::Promise;
32+
using v8::PromiseHookType;
2733
using v8::StackFrame;
2834
using v8::StackTrace;
2935
using v8::String;
3036
using v8::Symbol;
37+
using v8::TracingController;
3138
using v8::TryCatch;
39+
using v8::Undefined;
3240
using v8::Value;
3341
using worker::Worker;
3442

@@ -89,7 +97,7 @@ IsolateData::IsolateData(Isolate* isolate,
8997
String::NewFromOneByte( \
9098
isolate, \
9199
reinterpret_cast<const uint8_t*>(StringValue), \
92-
v8::NewStringType::kInternalized, \
100+
NewStringType::kInternalized, \
93101
sizeof(StringValue) - 1).ToLocalChecked()));
94102
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
95103
#undef V
@@ -101,7 +109,7 @@ IsolateData::IsolateData(Isolate* isolate,
101109
String::NewFromOneByte( \
102110
isolate, \
103111
reinterpret_cast<const uint8_t*>(StringValue), \
104-
v8::NewStringType::kInternalized, \
112+
NewStringType::kInternalized, \
105113
sizeof(StringValue) - 1).ToLocalChecked()));
106114
PER_ISOLATE_SYMBOL_PROPERTIES(V)
107115
#undef V
@@ -111,7 +119,7 @@ IsolateData::IsolateData(Isolate* isolate,
111119
String::NewFromOneByte( \
112120
isolate, \
113121
reinterpret_cast<const uint8_t*>(StringValue), \
114-
v8::NewStringType::kInternalized, \
122+
NewStringType::kInternalized, \
115123
sizeof(StringValue) - 1).ToLocalChecked());
116124
PER_ISOLATE_STRING_PROPERTIES(V)
117125
#undef V
@@ -149,7 +157,7 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() {
149157
return;
150158
TryCatch try_catch(isolate);
151159
try_catch.SetVerbose(true);
152-
cb->Call(env_->context(), v8::Undefined(isolate),
160+
cb->Call(env_->context(), Undefined(isolate),
153161
0, nullptr).ToLocalChecked();
154162
}
155163

@@ -173,9 +181,9 @@ Environment::Environment(IsolateData* isolate_data,
173181
fs_stats_field_bigint_array_(isolate_, kFsStatsBufferLength),
174182
context_(context->GetIsolate(), context) {
175183
// We'll be creating new objects so make sure we've entered the context.
176-
v8::HandleScope handle_scope(isolate());
177-
v8::Context::Scope context_scope(context);
178-
set_as_external(v8::External::New(isolate(), this));
184+
HandleScope handle_scope(isolate());
185+
Context::Scope context_scope(context);
186+
set_as_external(External::New(isolate(), this));
179187

180188
// We create new copies of the per-Environment option sets, so that it is
181189
// easier to modify them after Environment creation. The defaults are
@@ -194,7 +202,7 @@ Environment::Environment(IsolateData* isolate_data,
194202

195203
if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) {
196204
trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this);
197-
v8::TracingController* tracing_controller = writer->GetTracingController();
205+
TracingController* tracing_controller = writer->GetTracingController();
198206
if (tracing_controller != nullptr)
199207
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
200208
}
@@ -232,7 +240,7 @@ Environment::~Environment() {
232240
// CleanupHandles() should have removed all of them.
233241
CHECK(file_handle_read_wrap_freelist_.empty());
234242

235-
v8::HandleScope handle_scope(isolate());
243+
HandleScope handle_scope(isolate());
236244

237245
#if HAVE_INSPECTOR
238246
// Destroy inspector agent before erasing the context. The inspector
@@ -246,7 +254,7 @@ Environment::~Environment() {
246254
if (trace_state_observer_) {
247255
tracing::AgentWriterHandle* writer = GetTracingAgentWriter();
248256
CHECK_NOT_NULL(writer);
249-
v8::TracingController* tracing_controller = writer->GetTracingController();
257+
TracingController* tracing_controller = writer->GetTracingController();
250258
if (tracing_controller != nullptr)
251259
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
252260
}
@@ -410,7 +418,7 @@ void Environment::PrintSyncTrace() const {
410418
return;
411419

412420
HandleScope handle_scope(isolate());
413-
Local<v8::StackTrace> stack =
421+
Local<StackTrace> stack =
414422
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
415423

416424
fprintf(stderr, "(node:%d) WARNING: Detected use of sync API\n",
@@ -545,10 +553,10 @@ bool Environment::RemovePromiseHook(promise_hook_func fn, void* arg) {
545553
return true;
546554
}
547555

548-
void Environment::EnvPromiseHook(v8::PromiseHookType type,
549-
v8::Local<v8::Promise> promise,
550-
v8::Local<v8::Value> parent) {
551-
Local<v8::Context> context = promise->CreationContext();
556+
void Environment::EnvPromiseHook(PromiseHookType type,
557+
Local<Promise> promise,
558+
Local<Value> parent) {
559+
Local<Context> context = promise->CreationContext();
552560

553561
Environment* env = Environment::GetCurrent(context);
554562
if (env == nullptr) return;
@@ -568,7 +576,7 @@ void Environment::RunAndClearNativeImmediates() {
568576
std::vector<NativeImmediateCallback> list;
569577
native_immediate_callbacks_.swap(list);
570578
auto drain_list = [&]() {
571-
v8::TryCatch try_catch(isolate());
579+
TryCatch try_catch(isolate());
572580
for (auto it = list.begin(); it != list.end(); ++it) {
573581
#ifdef DEBUG
574582
v8::SealHandleScope seal_handle_scope(isolate());
@@ -748,7 +756,7 @@ void Environment::set_debug_categories(const std::string& cats, bool enabled) {
748756
}
749757

750758
void CollectExceptionInfo(Environment* env,
751-
v8::Local<v8::Object> obj,
759+
Local<Object> obj,
752760
int errorno,
753761
const char* err_string,
754762
const char* syscall,
@@ -757,7 +765,7 @@ void CollectExceptionInfo(Environment* env,
757765
const char* dest) {
758766
obj->Set(env->context(),
759767
env->errno_string(),
760-
v8::Integer::New(env->isolate(), errorno)).FromJust();
768+
Integer::New(env->isolate(), errorno)).FromJust();
761769

762770
obj->Set(env->context(), env->code_string(),
763771
OneByteString(env->isolate(), err_string)).FromJust();
@@ -767,14 +775,14 @@ void CollectExceptionInfo(Environment* env,
767775
OneByteString(env->isolate(), message)).FromJust();
768776
}
769777

770-
v8::Local<v8::Value> path_buffer;
778+
Local<Value> path_buffer;
771779
if (path != nullptr) {
772780
path_buffer =
773781
Buffer::Copy(env->isolate(), path, strlen(path)).ToLocalChecked();
774782
obj->Set(env->context(), env->path_string(), path_buffer).FromJust();
775783
}
776784

777-
v8::Local<v8::Value> dest_buffer;
785+
Local<Value> dest_buffer;
778786
if (dest != nullptr) {
779787
dest_buffer =
780788
Buffer::Copy(env->isolate(), dest, strlen(dest)).ToLocalChecked();
@@ -787,15 +795,15 @@ void CollectExceptionInfo(Environment* env,
787795
}
788796
}
789797

790-
void Environment::CollectExceptionInfo(v8::Local<v8::Value> object,
798+
void Environment::CollectExceptionInfo(Local<Value> object,
791799
int errorno,
792800
const char* syscall,
793801
const char* message,
794802
const char* path) {
795803
if (!object->IsObject() || errorno == 0)
796804
return;
797805

798-
v8::Local<v8::Object> obj = object.As<v8::Object>();
806+
Local<Object> obj = object.As<Object>();
799807
const char* err_string = node::errno_string(errorno);
800808

801809
if (message == nullptr || message[0] == '\0') {
@@ -806,7 +814,7 @@ void Environment::CollectExceptionInfo(v8::Local<v8::Value> object,
806814
syscall, message, path, nullptr);
807815
}
808816

809-
void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object,
817+
void Environment::CollectUVExceptionInfo(Local<Value> object,
810818
int errorno,
811819
const char* syscall,
812820
const char* message,
@@ -815,7 +823,7 @@ void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object,
815823
if (!object->IsObject() || errorno == 0)
816824
return;
817825

818-
v8::Local<v8::Object> obj = object.As<v8::Object>();
826+
Local<Object> obj = object.As<Object>();
819827
const char* err_string = uv_err_name(errorno);
820828

821829
if (message == nullptr || message[0] == '\0') {
@@ -854,8 +862,8 @@ void Environment::stop_sub_worker_contexts() {
854862
}
855863
}
856864

857-
void Environment::BuildEmbedderGraph(v8::Isolate* isolate,
858-
v8::EmbedderGraph* graph,
865+
void Environment::BuildEmbedderGraph(Isolate* isolate,
866+
EmbedderGraph* graph,
859867
void* data) {
860868
MemoryTracker tracker(isolate, graph);
861869
static_cast<Environment*>(data)->ForEachBaseObject([&](BaseObject* obj) {

src/exceptions.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using v8::Integer;
1414
using v8::Isolate;
1515
using v8::Local;
1616
using v8::Message;
17+
using v8::NewStringType;
1718
using v8::Object;
1819
using v8::String;
1920
using v8::Value;
@@ -39,7 +40,7 @@ Local<Value> ErrnoException(Isolate* isolate,
3940
Local<String> path_string;
4041
if (path != nullptr) {
4142
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
42-
path_string = String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
43+
path_string = String::NewFromUtf8(isolate, path, NewStringType::kNormal)
4344
.ToLocalChecked();
4445
}
4546

@@ -75,15 +76,15 @@ static Local<String> StringFromPath(Isolate* isolate, const char* path) {
7576
return String::Concat(
7677
isolate,
7778
FIXED_ONE_BYTE_STRING(isolate, "\\\\"),
78-
String::NewFromUtf8(isolate, path + 8, v8::NewStringType::kNormal)
79+
String::NewFromUtf8(isolate, path + 8, NewStringType::kNormal)
7980
.ToLocalChecked());
8081
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
81-
return String::NewFromUtf8(isolate, path + 4, v8::NewStringType::kNormal)
82+
return String::NewFromUtf8(isolate, path + 4, NewStringType::kNormal)
8283
.ToLocalChecked();
8384
}
8485
#endif
8586

86-
return String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
87+
return String::NewFromUtf8(isolate, path, NewStringType::kNormal)
8788
.ToLocalChecked();
8889
}
8990

@@ -196,7 +197,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
196197
Local<String> cons2 = String::Concat(
197198
isolate,
198199
cons1,
199-
String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
200+
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
200201
.ToLocalChecked());
201202
Local<String> cons3 =
202203
String::Concat(isolate, cons2, FIXED_ONE_BYTE_STRING(isolate, "'"));
@@ -210,7 +211,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
210211

211212
if (path != nullptr) {
212213
obj->Set(env->path_string(),
213-
String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
214+
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
214215
.ToLocalChecked());
215216
}
216217

0 commit comments

Comments
 (0)