Skip to content

src: make minor cleanups in multiple files #57448

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

Closed
wants to merge 2 commits 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
54 changes: 30 additions & 24 deletions src/compile_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
#endif

namespace node {

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

namespace {
std::string Uint32ToHex(uint32_t crc) {
std::string str;
str.reserve(8);
Expand All @@ -40,8 +48,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 @@ -55,6 +62,7 @@ uint32_t GetCacheKey(std::string_view filename, CachedCodeType type) {
crc, reinterpret_cast<const Bytef*>(filename.data()), filename.length());
return crc;
}
} // namespace

template <typename... Args>
inline void CompileCacheHandler::Debug(const char* format,
Expand All @@ -64,13 +72,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 @@ -210,15 +218,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 @@ -259,18 +266,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] V8 code cache for %s %s was %s, ",
Expand All @@ -286,21 +292,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 All @@ -319,8 +325,8 @@ void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry,
int cache_size = static_cast<int>(transpiled.size());
uint8_t* data = new uint8_t[cache_size];
memcpy(data, transpiled.data(), cache_size);
entry->cache.reset(new v8::ScriptCompiler::CachedData(
data, cache_size, v8::ScriptCompiler::CachedData::BufferOwned));
entry->cache.reset(new ScriptCompiler::CachedData(
data, cache_size, ScriptCompiler::CachedData::BufferOwned));
entry->refreshed = true;
}

Expand Down Expand Up @@ -377,7 +383,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
12 changes: 7 additions & 5 deletions src/encoding_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::ObjectTemplate;
using v8::SnapshotCreator;
using v8::String;
using v8::Uint8Array;
using v8::Value;
Expand All @@ -32,7 +34,7 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const {
}

BindingData::BindingData(Realm* realm,
v8::Local<v8::Object> object,
Local<Object> object,
InternalFieldInfo* info)
: SnapshotableObject(realm, object, type_int),
encode_into_results_buffer_(
Expand All @@ -52,7 +54,7 @@ BindingData::BindingData(Realm* realm,
}

bool BindingData::PrepareForSerialization(Local<Context> context,
v8::SnapshotCreator* creator) {
SnapshotCreator* creator) {
DCHECK_NULL(internal_field_info_);
internal_field_info_ = InternalFieldInfoBase::New<InternalFieldInfo>(type());
internal_field_info_->encode_into_results_buffer =
Expand All @@ -74,7 +76,7 @@ void BindingData::Deserialize(Local<Context> context,
int index,
InternalFieldInfoBase* info) {
DCHECK_IS_SNAPSHOT_SLOT(index);
v8::HandleScope scope(context->GetIsolate());
HandleScope scope(context->GetIsolate());
Realm* realm = Realm::GetCurrent(context);
// Recreate the buffer in the constructor.
InternalFieldInfo* casted_info = static_cast<InternalFieldInfo*>(info);
Expand Down Expand Up @@ -194,7 +196,7 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret);
}

void BindingData::ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args) {
void BindingData::ToASCII(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1);
CHECK(args[0]->IsString());
Expand All @@ -207,7 +209,7 @@ void BindingData::ToASCII(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}

void BindingData::ToUnicode(const v8::FunctionCallbackInfo<v8::Value>& args) {
void BindingData::ToUnicode(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1);
CHECK(args[0]->IsString());
Expand Down
Loading