diff --git a/src/compile_cache.cc b/src/compile_cache.cc index f13797e5f50288..d2efbd9655bee6 100644 --- a/src/compile_cache.cc +++ b/src/compile_cache.cc @@ -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); @@ -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 @@ -55,6 +62,7 @@ uint32_t GetCacheKey(std::string_view filename, CachedCodeType type) { crc, reinterpret_cast(filename.data()), filename.length()); return crc; } +} // namespace template inline void CompileCacheHandler::Debug(const char* format, @@ -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. @@ -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 code, - v8::Local filename, - CachedCodeType type) { +CompileCacheEntry* CompileCacheHandler::GetOrInsert(Local code, + Local filename, + CachedCodeType type) { DCHECK(!compile_cache_dir_.empty()); Utf8Value filename_utf8(isolate_, filename); @@ -259,18 +266,17 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert( return result; } -v8::ScriptCompiler::CachedData* SerializeCodeCache( - v8::Local func) { - return v8::ScriptCompiler::CreateCodeCacheForFunction(func); +ScriptCompiler::CachedData* SerializeCodeCache(Local func) { + return ScriptCompiler::CreateCodeCacheForFunction(func); } -v8::ScriptCompiler::CachedData* SerializeCodeCache(v8::Local mod) { - return v8::ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript()); +ScriptCompiler::CachedData* SerializeCodeCache(Local mod) { + return ScriptCompiler::CreateCodeCache(mod->GetUnboundModuleScript()); } template void CompileCacheHandler::MaybeSaveImpl(CompileCacheEntry* entry, - v8::Local func_or_mod, + Local func_or_mod, bool rejected) { DCHECK_NOT_NULL(entry); Debug("[compile cache] V8 code cache for %s %s was %s, ", @@ -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 mod, + Local mod, bool rejected) { DCHECK(mod->IsSourceTextModule()); MaybeSaveImpl(entry, mod, rejected); } void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry, - v8::Local func, + Local func, bool rejected) { MaybeSaveImpl(entry, func, rejected); } @@ -319,8 +325,8 @@ void CompileCacheHandler::MaybeSave(CompileCacheEntry* entry, int cache_size = static_cast(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; } @@ -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(const_cast(entry->cache->data)); uint32_t cache_size = static_cast(entry->cache->length); diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc index 9bdb2a660364c6..61d692dfe5ffa0 100644 --- a/src/encoding_binding.cc +++ b/src/encoding_binding.cc @@ -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; @@ -32,7 +34,7 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const { } BindingData::BindingData(Realm* realm, - v8::Local object, + Local object, InternalFieldInfo* info) : SnapshotableObject(realm, object, type_int), encode_into_results_buffer_( @@ -52,7 +54,7 @@ BindingData::BindingData(Realm* realm, } bool BindingData::PrepareForSerialization(Local context, - v8::SnapshotCreator* creator) { + SnapshotCreator* creator) { DCHECK_NULL(internal_field_info_); internal_field_info_ = InternalFieldInfoBase::New(type()); internal_field_info_->encode_into_results_buffer = @@ -74,7 +76,7 @@ void BindingData::Deserialize(Local 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(info); @@ -194,7 +196,7 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(ret); } -void BindingData::ToASCII(const v8::FunctionCallbackInfo& args) { +void BindingData::ToASCII(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString()); @@ -207,7 +209,7 @@ void BindingData::ToASCII(const v8::FunctionCallbackInfo& args) { } } -void BindingData::ToUnicode(const v8::FunctionCallbackInfo& args) { +void BindingData::ToUnicode(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK_GE(args.Length(), 1); CHECK(args[0]->IsString());