Skip to content

Commit

Permalink
src: cleanup v8 namespace uses in c++ files
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jan 12, 2025
1 parent 3720d03 commit 6d72c96
Show file tree
Hide file tree
Showing 77 changed files with 746 additions and 664 deletions.
7 changes: 4 additions & 3 deletions src/api/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::MaybeLocal;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Undefined;
Expand Down Expand Up @@ -51,7 +52,7 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
Local<Object> object,
const async_context& asyncContext,
int flags,
v8::Local<v8::Value> context_frame)
Local<Value> context_frame)
: env_(env),
async_context_(asyncContext),
object_(object),
Expand Down Expand Up @@ -216,7 +217,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
Local<Context> context = env->context();
if (use_async_hooks_trampoline) {
MaybeStackBuffer<Local<Value>, 16> args(3 + argc);
args[0] = v8::Number::New(env->isolate(), asyncContext.async_id);
args[0] = Number::New(env->isolate(), asyncContext.async_id);
args[1] = resource;
args[2] = callback;
for (int i = 0; i < argc; i++) {
Expand Down Expand Up @@ -345,7 +346,7 @@ MaybeLocal<Value> MakeSyncCallback(Isolate* isolate,
argc,
argv,
async_context{0, 0},
v8::Undefined(isolate));
Undefined(isolate));
return ret;
}

Expand Down
7 changes: 4 additions & 3 deletions src/api/embed_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using v8::Maybe;
using v8::Nothing;
using v8::SealHandleScope;
using v8::SnapshotCreator;
using v8::StackTrace;
using v8::TryCatch;

namespace node {
Expand Down Expand Up @@ -133,7 +134,7 @@ CommonEnvironmentSetup::CommonEnvironmentSetup(
platform->RegisterIsolate(isolate, loop);
impl_->snapshot_creator.emplace(isolate, external_references.data());
isolate->SetCaptureStackTraceForUncaughtExceptions(
true, 10, v8::StackTrace::StackTraceOptions::kDetailed);
true, 10, StackTrace::StackTraceOptions::kDetailed);
SetIsolateMiscHandlers(isolate, {});
} else {
impl_->allocator = ArrayBufferAllocator::Create();
Expand Down Expand Up @@ -290,11 +291,11 @@ Environment* CommonEnvironmentSetup::env() const {
return impl_->env.get();
}

v8::Local<v8::Context> CommonEnvironmentSetup::context() const {
Local<Context> CommonEnvironmentSetup::context() const {
return impl_->main_context.Get(impl_->isolate);
}

v8::SnapshotCreator* CommonEnvironmentSetup::snapshot_creator() {
SnapshotCreator* CommonEnvironmentSetup::snapshot_creator() {
return impl_->snapshot_creator ? &impl_->snapshot_creator.value() : nullptr;
}

Expand Down
3 changes: 2 additions & 1 deletion src/api/encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace node {
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::Uint32;
using v8::Value;

enum encoding ParseEncoding(const char* encoding,
Expand Down Expand Up @@ -114,7 +115,7 @@ enum encoding ParseEncoding(Isolate* isolate,
Local<Value> encoding_id,
enum encoding default_encoding) {
if (encoding_id->IsUint32()) {
return static_cast<enum encoding>(encoding_id.As<v8::Uint32>()->Value());
return static_cast<enum encoding>(encoding_id.As<Uint32>()->Value());
}

return ParseEncoding(isolate, encoding_v, default_encoding);
Expand Down
34 changes: 18 additions & 16 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ using errors::TryCatchScope;
using v8::Array;
using v8::Boolean;
using v8::Context;
using v8::CpuProfiler;
using v8::DeserializeContextDataCallback;
using v8::DeserializeInternalFieldsCallback;
using v8::EscapableHandleScope;
using v8::Function;
using v8::FunctionCallbackInfo;
Expand All @@ -39,10 +42,12 @@ using v8::Nothing;
using v8::Null;
using v8::Object;
using v8::ObjectTemplate;
using v8::PageAllocator;
using v8::Private;
using v8::PropertyDescriptor;
using v8::SealHandleScope;
using v8::String;
using v8::TracingController;
using v8::Value;

bool AllowWasmCodeGenerationCallback(Local<Context> context,
Expand Down Expand Up @@ -218,7 +223,7 @@ void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) {
#endif
}

void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
void SetIsolateErrorHandlers(Isolate* isolate, const IsolateSettings& s) {
if (s.flags & MESSAGE_LISTENER_WITH_ERROR_LEVEL)
isolate->AddMessageListenerWithErrorLevel(
errors::PerIsolateMessageListener,
Expand All @@ -242,7 +247,7 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
}
}

void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
void SetIsolateMiscHandlers(Isolate* isolate, const IsolateSettings& s) {
isolate->SetMicrotasksPolicy(s.policy);

auto* allow_wasm_codegen_cb = s.allow_wasm_code_generation_callback ?
Expand Down Expand Up @@ -278,18 +283,17 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
}

if (s.flags & DETAILED_SOURCE_POSITIONS_FOR_PROFILING)
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
}

void SetIsolateUpForNode(v8::Isolate* isolate,
const IsolateSettings& settings) {
void SetIsolateUpForNode(Isolate* isolate, const IsolateSettings& settings) {
Isolate::Scope isolate_scope(isolate);

SetIsolateErrorHandlers(isolate, settings);
SetIsolateMiscHandlers(isolate, settings);
}

void SetIsolateUpForNode(v8::Isolate* isolate) {
void SetIsolateUpForNode(Isolate* isolate) {
IsolateSettings settings;
SetIsolateUpForNode(isolate, settings);
}
Expand Down Expand Up @@ -427,12 +431,12 @@ Environment* CreateEnvironment(
if (use_snapshot) {
context = Context::FromSnapshot(isolate,
SnapshotData::kNodeMainContextIndex,
v8::DeserializeInternalFieldsCallback(
DeserializeInternalFieldsCallback(
DeserializeNodeInternalFields, env),
nullptr,
MaybeLocal<Value>(),
nullptr,
v8::DeserializeContextDataCallback(
DeserializeContextDataCallback(
DeserializeNodeContextData, env))
.ToLocalChecked();

Expand Down Expand Up @@ -570,14 +574,12 @@ MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env) {
MultiIsolatePlatform* CreatePlatform(
int thread_pool_size,
node::tracing::TracingController* tracing_controller) {
return CreatePlatform(
thread_pool_size,
static_cast<v8::TracingController*>(tracing_controller));
return CreatePlatform(thread_pool_size,
static_cast<TracingController*>(tracing_controller));
}

MultiIsolatePlatform* CreatePlatform(
int thread_pool_size,
v8::TracingController* tracing_controller) {
MultiIsolatePlatform* CreatePlatform(int thread_pool_size,
TracingController* tracing_controller) {
return MultiIsolatePlatform::Create(thread_pool_size,
tracing_controller)
.release();
Expand All @@ -589,8 +591,8 @@ void FreePlatform(MultiIsolatePlatform* platform) {

std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create(
int thread_pool_size,
v8::TracingController* tracing_controller,
v8::PageAllocator* page_allocator) {
TracingController* tracing_controller,
PageAllocator* page_allocator) {
return std::make_unique<NodePlatform>(thread_pool_size,
tracing_controller,
page_allocator);
Expand Down
3 changes: 2 additions & 1 deletion src/api/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::TryCatch;
using v8::Value;

Local<Value> ErrnoException(Isolate* isolate,
Expand Down Expand Up @@ -243,7 +244,7 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
// fatal any more, as the user can handle the exception in the
// TryCatch by listening to `uncaughtException`.
// TODO(joyeecheung): deprecate it in favor of a more accurate name.
void FatalException(Isolate* isolate, const v8::TryCatch& try_catch) {
void FatalException(Isolate* isolate, const TryCatch& try_catch) {
errors::TriggerUncaughtException(isolate, try_catch);
}

Expand Down
48 changes: 26 additions & 22 deletions src/compile_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#endif

namespace node {

using v8::Function;
using v8::Local;
using v8::Module;
using v8::ScriptCompiler;
using v8::String;

std::string Uint32ToHex(uint32_t crc) {
std::string str;
str.reserve(8);
Expand All @@ -40,8 +47,7 @@ std::string GetCacheVersionTag() {
// This should be fine on Windows, as there local directories tend to be
// user-specific.
std::string tag = std::string(NODE_VERSION) + '-' + std::string(NODE_ARCH) +
'-' +
Uint32ToHex(v8::ScriptCompiler::CachedDataVersionTag());
'-' + Uint32ToHex(ScriptCompiler::CachedDataVersionTag());
#ifdef NODE_IMPLEMENTS_POSIX_CREDENTIALS
tag += '-' + std::to_string(getuid());
#endif
Expand All @@ -64,13 +70,13 @@ inline void CompileCacheHandler::Debug(const char* format,
}
}

v8::ScriptCompiler::CachedData* CompileCacheEntry::CopyCache() const {
ScriptCompiler::CachedData* CompileCacheEntry::CopyCache() const {
DCHECK_NOT_NULL(cache);
int cache_size = cache->length;
uint8_t* data = new uint8_t[cache_size];
memcpy(data, cache->data, cache_size);
return new v8::ScriptCompiler::CachedData(
data, cache_size, v8::ScriptCompiler::CachedData::BufferOwned);
return new ScriptCompiler::CachedData(
data, cache_size, ScriptCompiler::CachedData::BufferOwned);
}

// Used for identifying and verifying a file is a compile cache file.
Expand Down Expand Up @@ -193,15 +199,14 @@ void CompileCacheHandler::ReadCacheFile(CompileCacheEntry* entry) {
return;
}

entry->cache.reset(new v8::ScriptCompiler::CachedData(
buffer, total_read, v8::ScriptCompiler::CachedData::BufferOwned));
entry->cache.reset(new ScriptCompiler::CachedData(
buffer, total_read, ScriptCompiler::CachedData::BufferOwned));
Debug(" success, size=%d\n", total_read);
}

CompileCacheEntry* CompileCacheHandler::GetOrInsert(
v8::Local<v8::String> code,
v8::Local<v8::String> filename,
CachedCodeType type) {
CompileCacheEntry* CompileCacheHandler::GetOrInsert(Local<String> code,
Local<String> filename,
CachedCodeType type) {
DCHECK(!compile_cache_dir_.empty());

Utf8Value filename_utf8(isolate_, filename);
Expand Down Expand Up @@ -242,18 +247,17 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert(
return result;
}

v8::ScriptCompiler::CachedData* SerializeCodeCache(
v8::Local<v8::Function> func) {
return v8::ScriptCompiler::CreateCodeCacheForFunction(func);
ScriptCompiler::CachedData* SerializeCodeCache(Local<Function> func) {
return ScriptCompiler::CreateCodeCacheForFunction(func);
}

v8::ScriptCompiler::CachedData* SerializeCodeCache(v8::Local<v8::Module> mod) {
return v8::ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript());
ScriptCompiler::CachedData* SerializeCodeCache(Local<Module> mod) {
return ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript());
}

template <typename T>
void CompileCacheHandler::MaybeSaveImpl(CompileCacheEntry* entry,
v8::Local<T> func_or_mod,
Local<T> func_or_mod,
bool rejected) {
DCHECK_NOT_NULL(entry);
Debug("[compile cache] cache for %s was %s, ",
Expand All @@ -268,21 +272,21 @@ void CompileCacheHandler::MaybeSaveImpl(CompileCacheEntry* entry,
Debug("%s the in-memory entry\n",
entry->cache == nullptr ? "initializing" : "refreshing");

v8::ScriptCompiler::CachedData* data = SerializeCodeCache(func_or_mod);
DCHECK_EQ(data->buffer_policy, v8::ScriptCompiler::CachedData::BufferOwned);
ScriptCompiler::CachedData* data = SerializeCodeCache(func_or_mod);
DCHECK_EQ(data->buffer_policy, ScriptCompiler::CachedData::BufferOwned);
entry->refreshed = true;
entry->cache.reset(data);
}

void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry,
v8::Local<v8::Module> mod,
Local<Module> mod,
bool rejected) {
DCHECK(mod->IsSourceTextModule());
MaybeSaveImpl(entry, mod, rejected);
}

void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry,
v8::Local<v8::Function> func,
Local<Function> func,
bool rejected) {
MaybeSaveImpl(entry, func, rejected);
}
Expand Down Expand Up @@ -333,7 +337,7 @@ void CompileCacheHandler::Persist() {
}

DCHECK_EQ(entry->cache->buffer_policy,
v8::ScriptCompiler::CachedData::BufferOwned);
ScriptCompiler::CachedData::BufferOwned);
char* cache_ptr =
reinterpret_cast<char*>(const_cast<uint8_t*>(entry->cache->data));
uint32_t cache_size = static_cast<uint32_t>(entry->cache->length);
Expand Down
9 changes: 5 additions & 4 deletions src/crypto/crypto_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using v8::Maybe;
using v8::MaybeLocal;
using v8::Name;
using v8::Nothing;
using v8::Null;
using v8::Object;
using v8::Uint32;
using v8::Value;
Expand Down Expand Up @@ -153,12 +154,12 @@ void Hash::GetCachedAliases(const FunctionCallbackInfo<Value>& args) {
values.reserve(size);
for (auto& [alias, id] : env->alias_to_md_id_map) {
names.push_back(OneByteString(isolate, alias));
values.push_back(v8::Uint32::New(isolate, id));
values.push_back(Uint32::New(isolate, id));
}
#else
CHECK(env->alias_to_md_id_map.empty());
#endif
Local<Value> prototype = v8::Null(isolate);
Local<Value> prototype = Null(isolate);
Local<Object> result =
Object::New(isolate, prototype, names.data(), values.data(), size);
args.GetReturnValue().Set(result);
Expand Down Expand Up @@ -191,7 +192,7 @@ const EVP_MD* GetDigestImplementation(Environment* env,
if (algorithm_cache.As<Object>()
->Set(isolate->GetCurrentContext(),
algorithm,
v8::Int32::New(isolate, result.cache_id))
Int32::New(isolate, result.cache_id))
.IsNothing()) {
return nullptr;
}
Expand Down Expand Up @@ -532,7 +533,7 @@ bool HashTraits::DeriveBits(
return true;
}

void InternalVerifyIntegrity(const v8::FunctionCallbackInfo<v8::Value>& args) {
void InternalVerifyIntegrity(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK_EQ(args.Length(), 3);
Expand Down
7 changes: 3 additions & 4 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ KeyObjectData::GetPublicKeyEncodingFromJs(
}

KeyObjectData KeyObjectData::GetPrivateKeyFromJs(
const v8::FunctionCallbackInfo<v8::Value>& args,
const FunctionCallbackInfo<Value>& args,
unsigned int* offset,
bool allow_key_object) {
if (args[*offset]->IsString() || IsAnyBufferSource(args[*offset])) {
Expand Down Expand Up @@ -592,7 +592,7 @@ bool KeyObjectHandle::HasInstance(Environment* env, Local<Value> value) {
return !t.IsEmpty() && t->HasInstance(value);
}

v8::Local<v8::Function> KeyObjectHandle::Initialize(Environment* env) {
Local<Function> KeyObjectHandle::Initialize(Environment* env) {
Local<FunctionTemplate> templ = env->crypto_key_object_handle_constructor();
if (templ.IsEmpty()) {
Isolate* isolate = env->isolate();
Expand Down Expand Up @@ -1031,8 +1031,7 @@ MaybeLocal<Value> KeyObjectHandle::ExportPrivateKey(
return WritePrivateKey(env(), data_.GetAsymmetricKey(), config);
}

void KeyObjectHandle::ExportJWK(
const v8::FunctionCallbackInfo<v8::Value>& args) {
void KeyObjectHandle::ExportJWK(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
KeyObjectHandle* key;
ASSIGN_OR_RETURN_UNWRAP(&key, args.This());
Expand Down
Loading

0 comments on commit 6d72c96

Please sign in to comment.