Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: elevate v8 namespaces of repeated references #24460

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,28 @@
namespace node {

using v8::Context;
using v8::EmbedderGraph;
using v8::External;
using v8::Function;
using v8::FunctionTemplate;
using v8::HandleScope;
using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Message;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::Private;
using v8::Promise;
using v8::PromiseHookType;
using v8::StackFrame;
using v8::StackTrace;
using v8::String;
using v8::Symbol;
using v8::TracingController;
using v8::TryCatch;
using v8::Undefined;
using v8::Value;
using worker::Worker;

Expand Down Expand Up @@ -89,7 +97,7 @@ IsolateData::IsolateData(Isolate* isolate,
String::NewFromOneByte( \
isolate, \
reinterpret_cast<const uint8_t*>(StringValue), \
v8::NewStringType::kInternalized, \
NewStringType::kInternalized, \
sizeof(StringValue) - 1).ToLocalChecked()));
PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
#undef V
Expand All @@ -101,7 +109,7 @@ IsolateData::IsolateData(Isolate* isolate,
String::NewFromOneByte( \
isolate, \
reinterpret_cast<const uint8_t*>(StringValue), \
v8::NewStringType::kInternalized, \
NewStringType::kInternalized, \
sizeof(StringValue) - 1).ToLocalChecked()));
PER_ISOLATE_SYMBOL_PROPERTIES(V)
#undef V
Expand All @@ -111,7 +119,7 @@ IsolateData::IsolateData(Isolate* isolate,
String::NewFromOneByte( \
isolate, \
reinterpret_cast<const uint8_t*>(StringValue), \
v8::NewStringType::kInternalized, \
NewStringType::kInternalized, \
sizeof(StringValue) - 1).ToLocalChecked());
PER_ISOLATE_STRING_PROPERTIES(V)
#undef V
Expand Down Expand Up @@ -149,7 +157,7 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() {
return;
TryCatch try_catch(isolate);
try_catch.SetVerbose(true);
cb->Call(env_->context(), v8::Undefined(isolate),
cb->Call(env_->context(), Undefined(isolate),
0, nullptr).ToLocalChecked();
}

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

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

if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) {
trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this);
v8::TracingController* tracing_controller = writer->GetTracingController();
TracingController* tracing_controller = writer->GetTracingController();
if (tracing_controller != nullptr)
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
}
Expand Down Expand Up @@ -232,7 +240,7 @@ Environment::~Environment() {
// CleanupHandles() should have removed all of them.
CHECK(file_handle_read_wrap_freelist_.empty());

v8::HandleScope handle_scope(isolate());
HandleScope handle_scope(isolate());

#if HAVE_INSPECTOR
// Destroy inspector agent before erasing the context. The inspector
Expand All @@ -246,7 +254,7 @@ Environment::~Environment() {
if (trace_state_observer_) {
tracing::AgentWriterHandle* writer = GetTracingAgentWriter();
CHECK_NOT_NULL(writer);
v8::TracingController* tracing_controller = writer->GetTracingController();
TracingController* tracing_controller = writer->GetTracingController();
if (tracing_controller != nullptr)
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
}
Expand Down Expand Up @@ -410,7 +418,7 @@ void Environment::PrintSyncTrace() const {
return;

HandleScope handle_scope(isolate());
Local<v8::StackTrace> stack =
Local<StackTrace> stack =
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);

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

void Environment::EnvPromiseHook(v8::PromiseHookType type,
v8::Local<v8::Promise> promise,
v8::Local<v8::Value> parent) {
Local<v8::Context> context = promise->CreationContext();
void Environment::EnvPromiseHook(PromiseHookType type,
Local<Promise> promise,
Local<Value> parent) {
Local<Context> context = promise->CreationContext();

Environment* env = Environment::GetCurrent(context);
if (env == nullptr) return;
Expand All @@ -568,7 +576,7 @@ void Environment::RunAndClearNativeImmediates() {
std::vector<NativeImmediateCallback> list;
native_immediate_callbacks_.swap(list);
auto drain_list = [&]() {
v8::TryCatch try_catch(isolate());
TryCatch try_catch(isolate());
for (auto it = list.begin(); it != list.end(); ++it) {
#ifdef DEBUG
v8::SealHandleScope seal_handle_scope(isolate());
Expand Down Expand Up @@ -748,7 +756,7 @@ void Environment::set_debug_categories(const std::string& cats, bool enabled) {
}

void CollectExceptionInfo(Environment* env,
v8::Local<v8::Object> obj,
Local<Object> obj,
int errorno,
const char* err_string,
const char* syscall,
Expand All @@ -757,7 +765,7 @@ void CollectExceptionInfo(Environment* env,
const char* dest) {
obj->Set(env->context(),
env->errno_string(),
v8::Integer::New(env->isolate(), errorno)).FromJust();
Integer::New(env->isolate(), errorno)).FromJust();

obj->Set(env->context(), env->code_string(),
OneByteString(env->isolate(), err_string)).FromJust();
Expand All @@ -767,14 +775,14 @@ void CollectExceptionInfo(Environment* env,
OneByteString(env->isolate(), message)).FromJust();
}

v8::Local<v8::Value> path_buffer;
Local<Value> path_buffer;
if (path != nullptr) {
path_buffer =
Buffer::Copy(env->isolate(), path, strlen(path)).ToLocalChecked();
obj->Set(env->context(), env->path_string(), path_buffer).FromJust();
}

v8::Local<v8::Value> dest_buffer;
Local<Value> dest_buffer;
if (dest != nullptr) {
dest_buffer =
Buffer::Copy(env->isolate(), dest, strlen(dest)).ToLocalChecked();
Expand All @@ -787,15 +795,15 @@ void CollectExceptionInfo(Environment* env,
}
}

void Environment::CollectExceptionInfo(v8::Local<v8::Value> object,
void Environment::CollectExceptionInfo(Local<Value> object,
int errorno,
const char* syscall,
const char* message,
const char* path) {
if (!object->IsObject() || errorno == 0)
return;

v8::Local<v8::Object> obj = object.As<v8::Object>();
Local<Object> obj = object.As<Object>();
const char* err_string = node::errno_string(errorno);

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

void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object,
void Environment::CollectUVExceptionInfo(Local<Value> object,
int errorno,
const char* syscall,
const char* message,
Expand All @@ -815,7 +823,7 @@ void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object,
if (!object->IsObject() || errorno == 0)
return;

v8::Local<v8::Object> obj = object.As<v8::Object>();
Local<Object> obj = object.As<Object>();
const char* err_string = uv_err_name(errorno);

if (message == nullptr || message[0] == '\0') {
Expand Down Expand Up @@ -854,8 +862,8 @@ void Environment::stop_sub_worker_contexts() {
}
}

void Environment::BuildEmbedderGraph(v8::Isolate* isolate,
v8::EmbedderGraph* graph,
void Environment::BuildEmbedderGraph(Isolate* isolate,
EmbedderGraph* graph,
void* data) {
MemoryTracker tracker(isolate, graph);
static_cast<Environment*>(data)->ForEachBaseObject([&](BaseObject* obj) {
Expand Down
13 changes: 7 additions & 6 deletions src/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using v8::Integer;
using v8::Isolate;
using v8::Local;
using v8::Message;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
Expand All @@ -39,7 +40,7 @@ Local<Value> ErrnoException(Isolate* isolate,
Local<String> path_string;
if (path != nullptr) {
// FIXME(bnoordhuis) It's questionable to interpret the file path as UTF-8.
path_string = String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
path_string = String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked();
}

Expand Down Expand Up @@ -75,15 +76,15 @@ static Local<String> StringFromPath(Isolate* isolate, const char* path) {
return String::Concat(
isolate,
FIXED_ONE_BYTE_STRING(isolate, "\\\\"),
String::NewFromUtf8(isolate, path + 8, v8::NewStringType::kNormal)
String::NewFromUtf8(isolate, path + 8, NewStringType::kNormal)
.ToLocalChecked());
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
return String::NewFromUtf8(isolate, path + 4, v8::NewStringType::kNormal)
return String::NewFromUtf8(isolate, path + 4, NewStringType::kNormal)
.ToLocalChecked();
}
#endif

return String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
return String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked();
}

Expand Down Expand Up @@ -196,7 +197,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
Local<String> cons2 = String::Concat(
isolate,
cons1,
String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked());
Local<String> cons3 =
String::Concat(isolate, cons2, FIXED_ONE_BYTE_STRING(isolate, "'"));
Expand All @@ -210,7 +211,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,

if (path != nullptr) {
obj->Set(env->path_string(),
String::NewFromUtf8(isolate, path, v8::NewStringType::kNormal)
String::NewFromUtf8(isolate, path, NewStringType::kNormal)
.ToLocalChecked());
}

Expand Down