From 759e841a05a5def99a631d57144daec44a80e188 Mon Sep 17 00:00:00 2001 From: Camillo Bruni Date: Wed, 27 Apr 2022 20:52:38 +0200 Subject: [PATCH] [api] Rename isolate variables * Prefix all isolate variables with i_ for i::Isolate and v8_ for v8::Isolate * Change _DO_NOT_USE macro suffix to _INTERNAL Change-Id: I005efbe0192cf202741448c63a4263e6a4b1fa1b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610429 Commit-Queue: Camillo Bruni Reviewed-by: Anton Bikineev Reviewed-by: Jakob Linke Cr-Commit-Position: refs/heads/main@{#80252} --- include/v8-embedder-heap.h | 4 +- include/v8-exception.h | 2 +- include/v8-isolate.h | 18 +- include/v8-local-handle.h | 8 +- include/v8-message.h | 4 +- include/v8-microtask-queue.h | 2 +- include/v8-wasm.h | 2 +- src/api/api-inl.h | 8 - src/api/api-macros-undef.h | 4 +- src/api/api-macros.h | 119 +- src/api/api.cc | 3269 +++++++++++++++++---------------- src/debug/debug-interface.cc | 40 +- src/execution/isolate-inl.h | 5 + src/execution/isolate.h | 1 + src/execution/v8threads.cc | 4 +- src/heap/embedder-tracing.cc | 4 +- src/heap/embedder-tracing.h | 2 +- test/cctest/test-serialize.cc | 15 +- 18 files changed, 1783 insertions(+), 1728 deletions(-) diff --git a/include/v8-embedder-heap.h b/include/v8-embedder-heap.h index 09dbae1fd8..01b74dbebc 100644 --- a/include/v8-embedder-heap.h +++ b/include/v8-embedder-heap.h @@ -205,10 +205,10 @@ class V8_EXPORT EmbedderHeapTracer { * Returns the v8::Isolate this tracer is attached too and |nullptr| if it * is not attached to any v8::Isolate. */ - v8::Isolate* isolate() const { return isolate_; } + v8::Isolate* isolate() const { return v8_isolate_; } protected: - v8::Isolate* isolate_ = nullptr; + v8::Isolate* v8_isolate_ = nullptr; friend class internal::LocalEmbedderHeapTracer; }; diff --git a/include/v8-exception.h b/include/v8-exception.h index 64126c420a..bc058e3fc7 100644 --- a/include/v8-exception.h +++ b/include/v8-exception.h @@ -197,7 +197,7 @@ class V8_EXPORT TryCatch { void ResetInternal(); - internal::Isolate* isolate_; + internal::Isolate* i_isolate_; TryCatch* next_; void* exception_; void* message_obj_; diff --git a/include/v8-isolate.h b/include/v8-isolate.h index fb0491688b..f116e580f4 100644 --- a/include/v8-isolate.h +++ b/include/v8-isolate.h @@ -301,16 +301,18 @@ class V8_EXPORT Isolate { */ class V8_EXPORT V8_NODISCARD Scope { public: - explicit Scope(Isolate* isolate) : isolate_(isolate) { isolate->Enter(); } + explicit Scope(Isolate* isolate) : v8_isolate_(isolate) { + v8_isolate_->Enter(); + } - ~Scope() { isolate_->Exit(); } + ~Scope() { v8_isolate_->Exit(); } // Prevent copying of Scope objects. Scope(const Scope&) = delete; Scope& operator=(const Scope&) = delete; private: - Isolate* const isolate_; + Isolate* const v8_isolate_; }; /** @@ -331,7 +333,7 @@ class V8_EXPORT Isolate { private: OnFailure on_failure_; - Isolate* isolate_; + v8::Isolate* v8_isolate_; bool was_execution_allowed_assert_; bool was_execution_allowed_throws_; @@ -353,7 +355,7 @@ class V8_EXPORT Isolate { const AllowJavascriptExecutionScope&) = delete; private: - Isolate* isolate_; + Isolate* v8_isolate_; bool was_execution_allowed_assert_; bool was_execution_allowed_throws_; bool was_execution_allowed_dump_; @@ -376,7 +378,7 @@ class V8_EXPORT Isolate { const SuppressMicrotaskExecutionScope&) = delete; private: - internal::Isolate* const isolate_; + internal::Isolate* const i_isolate_; internal::MicrotaskQueue* const microtask_queue_; internal::Address previous_stack_height_; @@ -389,7 +391,7 @@ class V8_EXPORT Isolate { */ class V8_EXPORT V8_NODISCARD SafeForTerminationScope { public: - explicit SafeForTerminationScope(v8::Isolate* isolate); + explicit SafeForTerminationScope(v8::Isolate* v8_isolate); ~SafeForTerminationScope(); // Prevent copying of Scope objects. @@ -397,7 +399,7 @@ class V8_EXPORT Isolate { SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete; private: - internal::Isolate* isolate_; + internal::Isolate* i_isolate_; bool prev_value_; }; diff --git a/include/v8-local-handle.h b/include/v8-local-handle.h index 5ae974081f..fbb8b05863 100644 --- a/include/v8-local-handle.h +++ b/include/v8-local-handle.h @@ -86,7 +86,7 @@ class V8_EXPORT V8_NODISCARD HandleScope { static int NumberOfHandles(Isolate* isolate); V8_INLINE Isolate* GetIsolate() const { - return reinterpret_cast(isolate_); + return reinterpret_cast(i_isolate_); } HandleScope(const HandleScope&) = delete; @@ -97,7 +97,7 @@ class V8_EXPORT V8_NODISCARD HandleScope { void Initialize(Isolate* isolate); - static internal::Address* CreateHandle(internal::Isolate* isolate, + static internal::Address* CreateHandle(internal::Isolate* i_isolate, internal::Address value); private: @@ -108,7 +108,7 @@ class V8_EXPORT V8_NODISCARD HandleScope { void operator delete(void*, size_t); void operator delete[](void*, size_t); - internal::Isolate* isolate_; + internal::Isolate* i_isolate_; internal::Address* prev_next_; internal::Address* prev_limit_; @@ -445,7 +445,7 @@ class V8_EXPORT V8_NODISCARD SealHandleScope { void operator delete(void*, size_t); void operator delete[](void*, size_t); - internal::Isolate* const isolate_; + internal::Isolate* const i_isolate_; internal::Address* prev_limit_; int prev_sealed_level_; }; diff --git a/include/v8-message.h b/include/v8-message.h index a13276412a..86eb9d9aaa 100644 --- a/include/v8-message.h +++ b/include/v8-message.h @@ -70,7 +70,7 @@ class V8_EXPORT ScriptOrigin { bool resource_is_opaque = false, bool is_wasm = false, bool is_module = false, Local host_defined_options = Local()) - : isolate_(isolate), + : v8_isolate_(isolate), resource_name_(resource_name), resource_line_offset_(resource_line_offset), resource_column_offset_(resource_column_offset), @@ -94,7 +94,7 @@ class V8_EXPORT ScriptOrigin { private: void VerifyHostDefinedOptions() const; - Isolate* isolate_; + Isolate* v8_isolate_; Local resource_name_; int resource_line_offset_; int resource_column_offset_; diff --git a/include/v8-microtask-queue.h b/include/v8-microtask-queue.h index af9caa54a8..f1624b903b 100644 --- a/include/v8-microtask-queue.h +++ b/include/v8-microtask-queue.h @@ -142,7 +142,7 @@ class V8_EXPORT V8_NODISCARD MicrotasksScope { MicrotasksScope& operator=(const MicrotasksScope&) = delete; private: - internal::Isolate* const isolate_; + internal::Isolate* const i_isolate_; internal::MicrotaskQueue* const microtask_queue_; bool run_; }; diff --git a/include/v8-wasm.h b/include/v8-wasm.h index 59b2a69b12..fc074d17e0 100644 --- a/include/v8-wasm.h +++ b/include/v8-wasm.h @@ -235,7 +235,7 @@ class V8_EXPORT WasmModuleObjectBuilderStreaming final { const WasmModuleObjectBuilderStreaming&) = delete; WasmModuleObjectBuilderStreaming& operator=( WasmModuleObjectBuilderStreaming&&) = default; - Isolate* isolate_ = nullptr; + Isolate* v8_isolate_ = nullptr; #if V8_CC_MSVC /** diff --git a/src/api/api-inl.h b/src/api/api-inl.h index 975976ae09..9a507fc135 100644 --- a/src/api/api-inl.h +++ b/src/api/api-inl.h @@ -233,14 +233,6 @@ class V8_NODISCARD InternalEscapableScope : public EscapableHandleScope { : EscapableHandleScope(reinterpret_cast(isolate)) {} }; -inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { - if (isolate->has_scheduled_exception()) { - return isolate->scheduled_exception() == - i::ReadOnlyRoots(isolate).termination_exception(); - } - return false; -} - template void CopySmiElementsToTypedBuffer(T* dst, uint32_t length, i::FixedArray elements) { diff --git a/src/api/api-macros-undef.h b/src/api/api-macros-undef.h index d3eea83a5f..ab1116d9ce 100644 --- a/src/api/api-macros-undef.h +++ b/src/api/api-macros-undef.h @@ -5,8 +5,8 @@ // PRESUBMIT_INTENTIONALLY_MISSING_INCLUDE_GUARD #undef LOG_API -#undef ENTER_V8_DO_NOT_USE -#undef ENTER_V8_HELPER_DO_NOT_USE +#undef ENTER_V8_BASIC +#undef ENTER_V8_HELPER_INTERNAL #undef PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE #undef PREPARE_FOR_EXECUTION_WITH_CONTEXT #undef PREPARE_FOR_EXECUTION diff --git a/src/api/api-macros.h b/src/api/api-macros.h index 9fbe9a9739..c241754065 100644 --- a/src/api/api-macros.h +++ b/src/api/api-macros.h @@ -35,98 +35,99 @@ * TODO(verwaest): Remove calls form API methods to DO_NOT_USE macros. */ -#define API_RCS_SCOPE(isolate, class_name, function_name) \ - RCS_SCOPE(isolate, \ +#define API_RCS_SCOPE(i_isolate, class_name, function_name) \ + RCS_SCOPE(i_isolate, \ i::RuntimeCallCounterId::kAPI_##class_name##_##function_name); -#define ENTER_V8_DO_NOT_USE(isolate) i::VMState __state__((isolate)) +#define ENTER_V8_BASIC(i_isolate) i::VMState __state__((i_isolate)) -#define ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, \ - function_name, bailout_value, \ - HandleScopeClass, do_callback) \ - if (IsExecutionTerminatingCheck(isolate)) { \ - return bailout_value; \ - } \ - HandleScopeClass handle_scope(isolate); \ - CallDepthScope call_depth_scope(isolate, context); \ - API_RCS_SCOPE(isolate, class_name, function_name); \ - i::VMState __state__((isolate)); \ +#define ENTER_V8_HELPER_INTERNAL(i_isolate, context, class_name, \ + function_name, bailout_value, \ + HandleScopeClass, do_callback) \ + if (i_isolate->is_execution_terminating()) { \ + return bailout_value; \ + } \ + HandleScopeClass handle_scope(i_isolate); \ + CallDepthScope call_depth_scope(i_isolate, context); \ + API_RCS_SCOPE(i_isolate, class_name, function_name); \ + i::VMState __state__((i_isolate)); \ bool has_pending_exception = false -#define PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, T) \ - if (IsExecutionTerminatingCheck(isolate)) { \ - return MaybeLocal(); \ - } \ - InternalEscapableScope handle_scope(isolate); \ - CallDepthScope call_depth_scope(isolate, v8::Local()); \ - i::VMState __state__((isolate)); \ +#define PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(i_isolate, T) \ + if (i_isolate->is_execution_terminating()) { \ + return MaybeLocal(); \ + } \ + InternalEscapableScope handle_scope(i_isolate); \ + CallDepthScope call_depth_scope(i_isolate, v8::Local()); \ + i::VMState __state__((i_isolate)); \ bool has_pending_exception = false #define PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ bailout_value, HandleScopeClass, \ do_callback) \ - auto isolate = context.IsEmpty() \ - ? i::Isolate::Current() \ - : reinterpret_cast(context->GetIsolate()); \ - ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ - bailout_value, HandleScopeClass, do_callback); + auto i_isolate = context.IsEmpty() \ + ? i::Isolate::Current() \ + : reinterpret_cast(context->GetIsolate()); \ + ENTER_V8_HELPER_INTERNAL(i_isolate, context, class_name, function_name, \ + bailout_value, HandleScopeClass, do_callback); #define PREPARE_FOR_EXECUTION(context, class_name, function_name, T) \ PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ MaybeLocal(), InternalEscapableScope, \ false) -#define ENTER_V8(isolate, context, class_name, function_name, bailout_value, \ - HandleScopeClass) \ - ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ - bailout_value, HandleScopeClass, true) +#define ENTER_V8(i_isolate, context, class_name, function_name, bailout_value, \ + HandleScopeClass) \ + ENTER_V8_HELPER_INTERNAL(i_isolate, context, class_name, function_name, \ + bailout_value, HandleScopeClass, true) #ifdef DEBUG -#define ENTER_V8_NO_SCRIPT(isolate, context, class_name, function_name, \ +#define ENTER_V8_NO_SCRIPT(i_isolate, context, class_name, function_name, \ bailout_value, HandleScopeClass) \ - ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ - bailout_value, HandleScopeClass, false); \ - i::DisallowJavascriptExecutionDebugOnly __no_script__((isolate)) + ENTER_V8_HELPER_INTERNAL(i_isolate, context, class_name, function_name, \ + bailout_value, HandleScopeClass, false); \ + i::DisallowJavascriptExecutionDebugOnly __no_script__((i_isolate)) // Lightweight version for APIs that don't require an active context. -#define ASSERT_NO_SCRIPT_NO_EXCEPTION(isolate) \ - i::DisallowJavascriptExecutionDebugOnly __no_script__((isolate)); \ - i::DisallowExceptions __no_exceptions__((isolate)) +#define DCHECK_NO_SCRIPT_NO_EXCEPTION(i_isolate) \ + i::DisallowJavascriptExecutionDebugOnly __no_script__((i_isolate)); \ + i::DisallowExceptions __no_exceptions__((i_isolate)) -#define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate) \ - i::VMState __state__((isolate)); \ - ASSERT_NO_SCRIPT_NO_EXCEPTION(isolate) +#define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate) \ + i::VMState __state__((i_isolate)); \ + DCHECK_NO_SCRIPT_NO_EXCEPTION(i_isolate) -#define ENTER_V8_FOR_NEW_CONTEXT(isolate) \ - i::VMState __state__((isolate)); \ - i::DisallowExceptions __no_exceptions__((isolate)) -#else -#define ENTER_V8_NO_SCRIPT(isolate, context, class_name, function_name, \ +#define ENTER_V8_FOR_NEW_CONTEXT(i_isolate) \ + DCHECK(!(i_isolate)->is_execution_terminating()); \ + i::VMState __state__((i_isolate)); \ + i::DisallowExceptions __no_exceptions__((i_isolate)) +#else // DEBUG +#define ENTER_V8_NO_SCRIPT(i_isolate, context, class_name, function_name, \ bailout_value, HandleScopeClass) \ - ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ - bailout_value, HandleScopeClass, false) + ENTER_V8_HELPER_INTERNAL(i_isolate, context, class_name, function_name, \ + bailout_value, HandleScopeClass, false) -#define ASSERT_NO_SCRIPT_NO_EXCEPTION(isolate) +#define DCHECK_NO_SCRIPT_NO_EXCEPTION(i_isolate) -#define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate) \ - i::VMState __state__((isolate)); +#define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate) \ + i::VMState __state__((i_isolate)); -#define ENTER_V8_FOR_NEW_CONTEXT(isolate) \ - i::VMState __state__((isolate)); +#define ENTER_V8_FOR_NEW_CONTEXT(i_isolate) \ + i::VMState __state__((i_isolate)); #endif // DEBUG -#define EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, value) \ - do { \ - if (has_pending_exception) { \ - call_depth_scope.Escape(); \ - return value; \ - } \ +#define EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(i_isolate, value) \ + do { \ + if (has_pending_exception) { \ + call_depth_scope.Escape(); \ + return value; \ + } \ } while (false) #define RETURN_ON_FAILED_EXECUTION(T) \ - EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, MaybeLocal()) + EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(i_isolate, MaybeLocal()) #define RETURN_ON_FAILED_EXECUTION_PRIMITIVE(T) \ - EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, Nothing()) + EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(i_isolate, Nothing()) #define RETURN_ESCAPED(value) return handle_scope.Escape(value); diff --git a/src/api/api.cc b/src/api/api.cc index 38c1861782..bde3fe4cc0 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -174,19 +174,19 @@ namespace v8 { static OOMErrorCallback g_oom_error_callback = nullptr; -static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, +static ScriptOrigin GetScriptOriginForScript(i::Isolate* i_isolate, i::Handle script) { - i::Handle scriptName(script->GetNameOrSourceURL(), isolate); - i::Handle source_map_url(script->source_mapping_url(), isolate); + i::Handle scriptName(script->GetNameOrSourceURL(), i_isolate); + i::Handle source_map_url(script->source_mapping_url(), i_isolate); i::Handle host_defined_options(script->host_defined_options(), - isolate); + i_isolate); ScriptOriginOptions options(script->origin_options()); bool is_wasm = false; #if V8_ENABLE_WEBASSEMBLY is_wasm = script->type() == i::Script::TYPE_WASM; #endif // V8_ENABLE_WEBASSEMBLY v8::ScriptOrigin origin( - reinterpret_cast(isolate), Utils::ToLocal(scriptName), + reinterpret_cast(i_isolate), Utils::ToLocal(scriptName), script->line_offset(), script->column_offset(), options.IsSharedCrossOrigin(), script->id(), Utils::ToLocal(source_map_url), options.IsOpaque(), is_wasm, @@ -207,23 +207,23 @@ Local ScriptOrigin::HostDefinedOptions() const { // --- E x c e p t i o n B e h a v i o r --- -void i::FatalProcessOutOfMemory(i::Isolate* isolate, const char* location) { - i::V8::FatalProcessOutOfMemory(isolate, location, false); +void i::FatalProcessOutOfMemory(i::Isolate* i_isolate, const char* location) { + i::V8::FatalProcessOutOfMemory(i_isolate, location, false); } // When V8 cannot allocate memory FatalProcessOutOfMemory is called. The default // OOM error handler is called and execution is stopped. -void i::V8::FatalProcessOutOfMemory(i::Isolate* isolate, const char* location, +void i::V8::FatalProcessOutOfMemory(i::Isolate* i_isolate, const char* location, bool is_heap_oom) { char last_few_messages[Heap::kTraceRingBufferSize + 1]; char js_stacktrace[Heap::kStacktraceBufferSize + 1]; i::HeapStats heap_stats; - if (isolate == nullptr) { - isolate = Isolate::TryGetCurrent(); + if (i_isolate == nullptr) { + i_isolate = Isolate::TryGetCurrent(); } - if (isolate == nullptr) { + if (i_isolate == nullptr) { // If the Isolate is not available for the current thread we cannot retrieve // memory information from the Isolate. Write easy-to-recognize values on // the stack. @@ -294,10 +294,10 @@ void i::V8::FatalProcessOutOfMemory(i::Isolate* isolate, const char* location, heap_stats.js_stacktrace = js_stacktrace; intptr_t end_marker; heap_stats.end_marker = &end_marker; - if (isolate->heap()->HasBeenSetUp()) { + if (i_isolate->heap()->HasBeenSetUp()) { // BUG(1718): Don't use the take_snapshot since we don't support // HeapObjectIterator here without doing a special GC. - isolate->heap()->RecordStats(&heap_stats, false); + i_isolate->heap()->RecordStats(&heap_stats, false); if (!FLAG_correctness_fuzzer_suppressions) { char* first_newline = strchr(last_few_messages, '\n'); if (first_newline == nullptr || first_newline[1] == '\0') @@ -306,17 +306,17 @@ void i::V8::FatalProcessOutOfMemory(i::Isolate* isolate, const char* location, base::OS::PrintError("\n<--- JS stacktrace --->\n%s\n", js_stacktrace); } } - Utils::ReportOOMFailure(isolate, location, is_heap_oom); + Utils::ReportOOMFailure(i_isolate, location, is_heap_oom); if (g_oom_error_callback) g_oom_error_callback(location, is_heap_oom); // If the fatal error handler returns, we stop execution. FATAL("API fatal error handler returned after process out of memory"); } void Utils::ReportApiFailure(const char* location, const char* message) { - i::Isolate* isolate = i::Isolate::TryGetCurrent(); + i::Isolate* i_isolate = i::Isolate::TryGetCurrent(); FatalErrorCallback callback = nullptr; - if (isolate != nullptr) { - callback = isolate->exception_behavior(); + if (i_isolate != nullptr) { + callback = i_isolate->exception_behavior(); } if (callback == nullptr) { base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location, @@ -325,16 +325,16 @@ void Utils::ReportApiFailure(const char* location, const char* message) { } else { callback(location, message); } - isolate->SignalFatalError(); + i_isolate->SignalFatalError(); } -void Utils::ReportOOMFailure(i::Isolate* isolate, const char* location, +void Utils::ReportOOMFailure(i::Isolate* i_isolate, const char* location, bool is_heap_oom) { - OOMErrorCallback oom_callback = isolate->oom_behavior(); + OOMErrorCallback oom_callback = i_isolate->oom_behavior(); if (oom_callback == nullptr) { // TODO(wfh): Remove this fallback once Blink is setting OOM handler. See // crbug.com/614440. - FatalErrorCallback fatal_callback = isolate->exception_behavior(); + FatalErrorCallback fatal_callback = i_isolate->exception_behavior(); if (fatal_callback == nullptr) { base::OS::PrintError("\n#\n# Fatal %s OOM in %s\n#\n\n", is_heap_oom ? "javascript" : "process", location); @@ -352,7 +352,7 @@ void Utils::ReportOOMFailure(i::Isolate* isolate, const char* location, } else { oom_callback(location, is_heap_oom); } - isolate->SignalFatalError(); + i_isolate->SignalFatalError(); } void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) { @@ -436,10 +436,10 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { #endif // V8_SANDBOXED_POINTERS struct SnapshotCreatorData { - explicit SnapshotCreatorData(Isolate* isolate) - : isolate_(isolate), + explicit SnapshotCreatorData(Isolate* v8_isolate) + : isolate_(v8_isolate), default_context_(), - contexts_(isolate), + contexts_(v8_isolate), created_(false) {} static SnapshotCreatorData* cast(void* data) { @@ -457,27 +457,27 @@ struct SnapshotCreatorData { } // namespace -SnapshotCreator::SnapshotCreator(Isolate* isolate, +SnapshotCreator::SnapshotCreator(Isolate* v8_isolate, const intptr_t* external_references, StartupData* existing_snapshot) { - SnapshotCreatorData* data = new SnapshotCreatorData(isolate); - i::Isolate* internal_isolate = reinterpret_cast(isolate); - internal_isolate->set_array_buffer_allocator(&data->allocator_); - internal_isolate->set_api_external_references(external_references); - internal_isolate->enable_serializer(); - isolate->Enter(); + SnapshotCreatorData* data = new SnapshotCreatorData(v8_isolate); + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); + i_isolate->set_array_buffer_allocator(&data->allocator_); + i_isolate->set_api_external_references(external_references); + i_isolate->enable_serializer(); + v8_isolate->Enter(); const StartupData* blob = existing_snapshot ? existing_snapshot : i::Snapshot::DefaultSnapshotBlob(); if (blob && blob->raw_size > 0) { - internal_isolate->set_snapshot_blob(blob); - i::Snapshot::Initialize(internal_isolate); + i_isolate->set_snapshot_blob(blob); + i::Snapshot::Initialize(i_isolate); } else { - internal_isolate->InitWithoutSnapshot(); + i_isolate->InitWithoutSnapshot(); } data_ = data; // Disable batch compilation during snapshot creation. - internal_isolate->baseline_batch_compiler()->set_enabled(false); + i_isolate->baseline_batch_compiler()->set_enabled(false); } SnapshotCreator::SnapshotCreator(const intptr_t* external_references, @@ -488,9 +488,9 @@ SnapshotCreator::SnapshotCreator(const intptr_t* external_references, SnapshotCreator::~SnapshotCreator() { SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); DCHECK(data->created_); - Isolate* isolate = data->isolate_; - isolate->Exit(); - isolate->Dispose(); + Isolate* v8_isolate = data->isolate_; + v8_isolate->Exit(); + v8_isolate->Dispose(); delete data; } @@ -504,9 +504,9 @@ void SnapshotCreator::SetDefaultContext( SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); DCHECK(!data->created_); DCHECK(data->default_context_.IsEmpty()); - Isolate* isolate = data->isolate_; - CHECK_EQ(isolate, context->GetIsolate()); - data->default_context_.Reset(isolate, context); + Isolate* v8_isolate = data->isolate_; + CHECK_EQ(v8_isolate, context->GetIsolate()); + data->default_context_.Reset(v8_isolate, context); data->default_embedder_fields_serializer_ = callback; } @@ -515,8 +515,8 @@ size_t SnapshotCreator::AddContext(Local context, DCHECK(!context.IsEmpty()); SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); DCHECK(!data->created_); - Isolate* isolate = data->isolate_; - CHECK_EQ(isolate, context->GetIsolate()); + Isolate* v8_isolate = data->isolate_; + CHECK_EQ(v8_isolate, context->GetIsolate()); size_t index = data->contexts_.Size(); data->contexts_.Append(context); data->embedder_fields_serializers_.push_back(callback); @@ -527,19 +527,19 @@ size_t SnapshotCreator::AddData(i::Address object) { DCHECK_NE(object, i::kNullAddress); SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); DCHECK(!data->created_); - i::Isolate* isolate = reinterpret_cast(data->isolate_); - i::HandleScope scope(isolate); - i::Handle obj(i::Object(object), isolate); + i::Isolate* i_isolate = reinterpret_cast(data->isolate_); + i::HandleScope scope(i_isolate); + i::Handle obj(i::Object(object), i_isolate); i::Handle list; - if (!isolate->heap()->serialized_objects().IsArrayList()) { - list = i::ArrayList::New(isolate, 1); + if (!i_isolate->heap()->serialized_objects().IsArrayList()) { + list = i::ArrayList::New(i_isolate, 1); } else { list = i::Handle( - i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate); + i::ArrayList::cast(i_isolate->heap()->serialized_objects()), i_isolate); } size_t index = static_cast(list->Length()); - list = i::ArrayList::Add(isolate, list, obj); - isolate->heap()->SetSerializedObjects(*list); + list = i::ArrayList::Add(i_isolate, list, obj); + i_isolate->heap()->SetSerializedObjects(*list); return index; } @@ -547,18 +547,18 @@ size_t SnapshotCreator::AddData(Local context, i::Address object) { DCHECK_NE(object, i::kNullAddress); DCHECK(!SnapshotCreatorData::cast(data_)->created_); i::Handle ctx = Utils::OpenHandle(*context); - i::Isolate* isolate = ctx->GetIsolate(); - i::HandleScope scope(isolate); - i::Handle obj(i::Object(object), isolate); + i::Isolate* i_isolate = ctx->GetIsolate(); + i::HandleScope scope(i_isolate); + i::Handle obj(i::Object(object), i_isolate); i::Handle list; if (!ctx->serialized_objects().IsArrayList()) { - list = i::ArrayList::New(isolate, 1); + list = i::ArrayList::New(i_isolate, 1); } else { list = i::Handle( - i::ArrayList::cast(ctx->serialized_objects()), isolate); + i::ArrayList::cast(ctx->serialized_objects()), i_isolate); } size_t index = static_cast(list->Length()); - list = i::ArrayList::Add(isolate, list, obj); + list = i::ArrayList::Add(i_isolate, list, obj); ctx->set_serialized_objects(*list); return index; } @@ -566,26 +566,27 @@ size_t SnapshotCreator::AddData(Local context, i::Address object) { namespace { void ConvertSerializedObjectsToFixedArray(Local context) { i::Handle ctx = Utils::OpenHandle(*context); - i::Isolate* isolate = ctx->GetIsolate(); + i::Isolate* i_isolate = ctx->GetIsolate(); if (!ctx->serialized_objects().IsArrayList()) { - ctx->set_serialized_objects(i::ReadOnlyRoots(isolate).empty_fixed_array()); + ctx->set_serialized_objects( + i::ReadOnlyRoots(i_isolate).empty_fixed_array()); } else { i::Handle list(i::ArrayList::cast(ctx->serialized_objects()), - isolate); - i::Handle elements = i::ArrayList::Elements(isolate, list); + i_isolate); + i::Handle elements = i::ArrayList::Elements(i_isolate, list); ctx->set_serialized_objects(*elements); } } -void ConvertSerializedObjectsToFixedArray(i::Isolate* isolate) { - if (!isolate->heap()->serialized_objects().IsArrayList()) { - isolate->heap()->SetSerializedObjects( - i::ReadOnlyRoots(isolate).empty_fixed_array()); +void ConvertSerializedObjectsToFixedArray(i::Isolate* i_isolate) { + if (!i_isolate->heap()->serialized_objects().IsArrayList()) { + i_isolate->heap()->SetSerializedObjects( + i::ReadOnlyRoots(i_isolate).empty_fixed_array()); } else { i::Handle list( - i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate); - i::Handle elements = i::ArrayList::Elements(isolate, list); - isolate->heap()->SetSerializedObjects(*elements); + i::ArrayList::cast(i_isolate->heap()->serialized_objects()), i_isolate); + i::Handle elements = i::ArrayList::Elements(i_isolate, list); + i_isolate->heap()->SetSerializedObjects(*elements); } } } // anonymous namespace @@ -593,7 +594,7 @@ void ConvertSerializedObjectsToFixedArray(i::Isolate* isolate) { StartupData SnapshotCreator::CreateBlob( SnapshotCreator::FunctionCodeHandling function_code_handling) { SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); - i::Isolate* isolate = reinterpret_cast(data->isolate_); + i::Isolate* i_isolate = reinterpret_cast(data->isolate_); DCHECK(!data->created_); DCHECK(!data->default_context_.IsEmpty()); @@ -603,9 +604,9 @@ StartupData SnapshotCreator::CreateBlob( // Create and store lists of embedder-provided data needed during // serialization. { - i::HandleScope scope(isolate); + i::HandleScope scope(i_isolate); // Convert list of context-independent data to FixedArray. - ConvertSerializedObjectsToFixedArray(isolate); + ConvertSerializedObjectsToFixedArray(i_isolate); // Convert lists of context-dependent data to FixedArray. ConvertSerializedObjectsToFixedArray( @@ -617,33 +618,33 @@ StartupData SnapshotCreator::CreateBlob( // We need to store the global proxy size upfront in case we need the // bootstrapper to create a global proxy before we deserialize the context. i::Handle global_proxy_sizes = - isolate->factory()->NewFixedArray(num_additional_contexts, - i::AllocationType::kOld); + i_isolate->factory()->NewFixedArray(num_additional_contexts, + i::AllocationType::kOld); for (int i = 0; i < num_additional_contexts; i++) { i::Handle context = v8::Utils::OpenHandle(*data->contexts_.Get(i)); global_proxy_sizes->set(i, i::Smi::FromInt(context->global_proxy().Size())); } - isolate->heap()->SetSerializedGlobalProxySizes(*global_proxy_sizes); + i_isolate->heap()->SetSerializedGlobalProxySizes(*global_proxy_sizes); } // We might rehash strings and re-sort descriptors. Clear the lookup cache. - isolate->descriptor_lookup_cache()->Clear(); + i_isolate->descriptor_lookup_cache()->Clear(); // If we don't do this then we end up with a stray root pointing at the // context even after we have disposed of the context. - isolate->heap()->CollectAllAvailableGarbage( + i_isolate->heap()->CollectAllAvailableGarbage( i::GarbageCollectionReason::kSnapshotCreator); { - i::HandleScope scope(isolate); - isolate->heap()->CompactWeakArrayLists(); + i::HandleScope scope(i_isolate); + i_isolate->heap()->CompactWeakArrayLists(); } i::Snapshot::ClearReconstructableDataForSerialization( - isolate, function_code_handling == FunctionCodeHandling::kClear); + i_isolate, function_code_handling == FunctionCodeHandling::kClear); - i::GlobalSafepointScope global_safepoint(isolate); + i::GlobalSafepointScope global_safepoint(i_isolate); i::DisallowGarbageCollection no_gc_from_here_on; // Create a vector with all contexts and clear associated Persistent fields. @@ -653,7 +654,7 @@ StartupData SnapshotCreator::CreateBlob( std::vector contexts; contexts.reserve(num_contexts); { - i::HandleScope scope(isolate); + i::HandleScope scope(i_isolate); contexts.push_back( *v8::Utils::OpenHandle(*data->default_context_.Get(data->isolate_))); data->default_context_.Reset(); @@ -666,7 +667,7 @@ StartupData SnapshotCreator::CreateBlob( } // Check that values referenced by global/eternal handles are accounted for. - i::SerializedHandleChecker handle_checker(isolate, &contexts); + i::SerializedHandleChecker handle_checker(i_isolate, &contexts); CHECK(handle_checker.CheckGlobalAndEternalHandles()); // Create a vector with all embedder fields serializers. @@ -680,7 +681,7 @@ StartupData SnapshotCreator::CreateBlob( } data->created_ = true; - return i::Snapshot::Create(isolate, &contexts, embedder_fields_serializers, + return i::Snapshot::Create(i_isolate, &contexts, embedder_fields_serializers, global_safepoint, no_gc_from_here_on); } @@ -811,19 +812,19 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, namespace internal { -i::Address* GlobalizeTracedReference(i::Isolate* isolate, i::Address* obj, +i::Address* GlobalizeTracedReference(i::Isolate* i_isolate, i::Address* obj, internal::Address* slot, GlobalHandleStoreMode store_mode) { - API_RCS_SCOPE(isolate, TracedGlobal, New); + API_RCS_SCOPE(i_isolate, TracedGlobal, New); #ifdef DEBUG Utils::ApiCheck((slot != nullptr), "v8::GlobalizeTracedReference", "the address slot must be not null"); #endif i::Handle result = - isolate->global_handles()->CreateTraced(*obj, slot, store_mode); + i_isolate->global_handles()->CreateTraced(*obj, slot, store_mode); #ifdef VERIFY_HEAP if (i::FLAG_verify_heap) { - i::Object(*obj).ObjectVerify(isolate); + i::Object(*obj).ObjectVerify(i_isolate); } #endif // VERIFY_HEAP return result.location(); @@ -846,12 +847,12 @@ void DisposeTracedReference(internal::Address* location) { namespace api_internal { -i::Address* GlobalizeReference(i::Isolate* isolate, i::Address* obj) { - API_RCS_SCOPE(isolate, Persistent, New); - i::Handle result = isolate->global_handles()->Create(*obj); +i::Address* GlobalizeReference(i::Isolate* i_isolate, i::Address* obj) { + API_RCS_SCOPE(i_isolate, Persistent, New); + i::Handle result = i_isolate->global_handles()->Create(*obj); #ifdef VERIFY_HEAP if (i::FLAG_verify_heap) { - i::Object(*obj).ObjectVerify(isolate); + i::Object(*obj).ObjectVerify(i_isolate); } #endif // VERIFY_HEAP return result.location(); @@ -889,12 +890,12 @@ void DisposeGlobal(i::Address* location) { } Value* Eternalize(Isolate* v8_isolate, Value* value) { - i::Isolate* isolate = reinterpret_cast(v8_isolate); + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); i::Object object = *Utils::OpenHandle(value); int index = -1; - isolate->eternal_handles()->Create(isolate, object, &index); + i_isolate->eternal_handles()->Create(i_isolate, object, &index); return reinterpret_cast( - isolate->eternal_handles()->Get(index).location()); + i_isolate->eternal_handles()->Get(index).location()); } void FromJustIsNothing() { @@ -915,30 +916,29 @@ void InternalFieldOutOfBounds(int index) { // --- H a n d l e s --- -HandleScope::HandleScope(Isolate* isolate) { Initialize(isolate); } +HandleScope::HandleScope(Isolate* v8_isolate) { Initialize(v8_isolate); } -void HandleScope::Initialize(Isolate* isolate) { - i::Isolate* internal_isolate = reinterpret_cast(isolate); +void HandleScope::Initialize(Isolate* v8_isolate) { + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); // We do not want to check the correct usage of the Locker class all over the // place, so we do it only here: Without a HandleScope, an embedder can do // almost nothing, so it is enough to check in this central place. // We make an exception if the serializer is enabled, which means that the // Isolate is exclusively used to create a snapshot. - Utils::ApiCheck( - !internal_isolate->was_locker_ever_used() || - internal_isolate->thread_manager()->IsLockedByCurrentThread() || - internal_isolate->serializer_enabled(), - "HandleScope::HandleScope", - "Entering the V8 API without proper locking in place"); - i::HandleScopeData* current = internal_isolate->handle_scope_data(); - isolate_ = internal_isolate; + Utils::ApiCheck(!i_isolate->was_locker_ever_used() || + i_isolate->thread_manager()->IsLockedByCurrentThread() || + i_isolate->serializer_enabled(), + "HandleScope::HandleScope", + "Entering the V8 API without proper locking in place"); + i::HandleScopeData* current = i_isolate->handle_scope_data(); + i_isolate_ = i_isolate; prev_next_ = current->next; prev_limit_ = current->limit; current->level++; } HandleScope::~HandleScope() { - i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_); + i::HandleScope::CloseScope(i_isolate_, prev_next_, prev_limit_); } void* HandleScope::operator new(size_t) { base::OS::Abort(); } @@ -946,19 +946,19 @@ void* HandleScope::operator new[](size_t) { base::OS::Abort(); } void HandleScope::operator delete(void*, size_t) { base::OS::Abort(); } void HandleScope::operator delete[](void*, size_t) { base::OS::Abort(); } -int HandleScope::NumberOfHandles(Isolate* isolate) { +int HandleScope::NumberOfHandles(Isolate* v8_isolate) { return i::HandleScope::NumberOfHandles( - reinterpret_cast(isolate)); + reinterpret_cast(v8_isolate)); } -i::Address* HandleScope::CreateHandle(i::Isolate* isolate, i::Address value) { - return i::HandleScope::CreateHandle(isolate, value); +i::Address* HandleScope::CreateHandle(i::Isolate* i_isolate, i::Address value) { + return i::HandleScope::CreateHandle(i_isolate, value); } EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) { - i::Isolate* isolate = reinterpret_cast(v8_isolate); - escape_slot_ = - CreateHandle(isolate, i::ReadOnlyRoots(isolate).the_hole_value().ptr()); + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); + escape_slot_ = CreateHandle( + i_isolate, i::ReadOnlyRoots(i_isolate).the_hole_value().ptr()); Initialize(v8_isolate); } @@ -981,9 +981,9 @@ void EscapableHandleScope::operator delete[](void*, size_t) { base::OS::Abort(); } -SealHandleScope::SealHandleScope(Isolate* isolate) - : isolate_(reinterpret_cast(isolate)) { - i::HandleScopeData* current = isolate_->handle_scope_data(); +SealHandleScope::SealHandleScope(Isolate* v8_isolate) + : i_isolate_(reinterpret_cast(v8_isolate)) { + i::HandleScopeData* current = i_isolate_->handle_scope_data(); prev_limit_ = current->limit; current->limit = current->next; prev_sealed_level_ = current->sealed_level; @@ -991,7 +991,7 @@ SealHandleScope::SealHandleScope(Isolate* isolate) } SealHandleScope::~SealHandleScope() { - i::HandleScopeData* current = isolate_->handle_scope_data(); + i::HandleScopeData* current = i_isolate_->handle_scope_data(); DCHECK_EQ(current->next, current->limit); current->limit = prev_limit_; DCHECK_EQ(current->level, current->sealed_level); @@ -1036,25 +1036,25 @@ bool Data::IsContext() const { return Utils::OpenHandle(this)->IsContext(); } void Context::Enter() { i::Handle env = Utils::OpenHandle(this); - i::Isolate* isolate = env->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); + i::Isolate* i_isolate = env->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScopeImplementer* impl = i_isolate->handle_scope_implementer(); impl->EnterContext(*env); - impl->SaveContext(isolate->context()); - isolate->set_context(*env); + impl->SaveContext(i_isolate->context()); + i_isolate->set_context(*env); } void Context::Exit() { i::Handle env = Utils::OpenHandle(this); - i::Isolate* isolate = env->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScopeImplementer* impl = isolate->handle_scope_implementer(); + i::Isolate* i_isolate = env->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScopeImplementer* impl = i_isolate->handle_scope_implementer(); if (!Utils::ApiCheck(impl->LastEnteredContextWas(*env), "v8::Context::Exit()", "Cannot exit non-entered context")) { return; } impl->LeaveContext(); - isolate->set_context(impl->RestoreContext()); + i_isolate->set_context(impl->RestoreContext()); } Context::BackupIncumbentScope::BackupIncumbentScope( @@ -1063,22 +1063,22 @@ Context::BackupIncumbentScope::BackupIncumbentScope( DCHECK(!backup_incumbent_context_.IsEmpty()); i::Handle env = Utils::OpenHandle(*backup_incumbent_context_); - i::Isolate* isolate = env->GetIsolate(); + i::Isolate* i_isolate = env->GetIsolate(); js_stack_comparable_address_ = - i::SimulatorStack::RegisterJSStackComparableAddress(isolate); + i::SimulatorStack::RegisterJSStackComparableAddress(i_isolate); - prev_ = isolate->top_backup_incumbent_scope(); - isolate->set_top_backup_incumbent_scope(this); + prev_ = i_isolate->top_backup_incumbent_scope(); + i_isolate->set_top_backup_incumbent_scope(this); } Context::BackupIncumbentScope::~BackupIncumbentScope() { i::Handle env = Utils::OpenHandle(*backup_incumbent_context_); - i::Isolate* isolate = env->GetIsolate(); + i::Isolate* i_isolate = env->GetIsolate(); - i::SimulatorStack::UnregisterJSStackComparableAddress(isolate); + i::SimulatorStack::UnregisterJSStackComparableAddress(i_isolate); - isolate->set_top_backup_incumbent_scope(prev_); + i_isolate->set_top_backup_incumbent_scope(prev_); } STATIC_ASSERT(i::Internals::kEmbedderDataSlotSize == i::kEmbedderDataSlotSize); @@ -1087,28 +1087,28 @@ static i::Handle EmbedderDataFor(Context* context, int index, bool can_grow, const char* location) { i::Handle env = Utils::OpenHandle(context); - i::Isolate* isolate = env->GetIsolate(); - ASSERT_NO_SCRIPT_NO_EXCEPTION(isolate); + i::Isolate* i_isolate = env->GetIsolate(); + DCHECK_NO_SCRIPT_NO_EXCEPTION(i_isolate); bool ok = Utils::ApiCheck(env->IsNativeContext(), location, "Not a native context") && Utils::ApiCheck(index >= 0, location, "Negative index"); if (!ok) return i::Handle(); // TODO(ishell): remove cast once embedder_data slot has a proper type. i::Handle data( - i::EmbedderDataArray::cast(env->embedder_data()), isolate); + i::EmbedderDataArray::cast(env->embedder_data()), i_isolate); if (index < data->length()) return data; if (!Utils::ApiCheck(can_grow && index < i::EmbedderDataArray::kMaxLength, location, "Index too large")) { return i::Handle(); } - data = i::EmbedderDataArray::EnsureCapacity(isolate, data, index); + data = i::EmbedderDataArray::EnsureCapacity(i_isolate, data, index); env->set_embedder_data(*data); return data; } uint32_t Context::GetNumberOfEmbedderDataFields() { i::Handle context = Utils::OpenHandle(this); - ASSERT_NO_SCRIPT_NO_EXCEPTION(context->GetIsolate()); + DCHECK_NO_SCRIPT_NO_EXCEPTION(context->GetIsolate()); Utils::ApiCheck(context->IsNativeContext(), "Context::GetNumberOfEmbedderDataFields", "Not a native context"); @@ -1122,9 +1122,9 @@ v8::Local Context::SlowGetEmbedderData(int index) { i::Handle data = EmbedderDataFor(this, index, false, location); if (data.is_null()) return Local(); - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); i::Handle result(i::EmbedderDataSlot(*data, index).load_tagged(), - isolate); + i_isolate); return Utils::ToLocal(result); } @@ -1141,25 +1141,25 @@ void Context::SetEmbedderData(int index, v8::Local value) { void* Context::SlowGetAlignedPointerFromEmbedderData(int index) { const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()"; - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - i::HandleScope handle_scope(isolate); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); + i::HandleScope handle_scope(i_isolate); i::Handle data = EmbedderDataFor(this, index, false, location); if (data.is_null()) return nullptr; void* result; Utils::ApiCheck( - i::EmbedderDataSlot(*data, index).ToAlignedPointer(isolate, &result), + i::EmbedderDataSlot(*data, index).ToAlignedPointer(i_isolate, &result), location, "Pointer is not aligned"); return result; } void Context::SetAlignedPointerInEmbedderData(int index, void* value) { const char* location = "v8::Context::SetAlignedPointerInEmbedderData()"; - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); i::Handle data = EmbedderDataFor(this, index, true, location); bool ok = - i::EmbedderDataSlot(*data, index).store_aligned_pointer(isolate, value); + i::EmbedderDataSlot(*data, index).store_aligned_pointer(i_isolate, value); Utils::ApiCheck(ok, location, "Pointer is not aligned"); DCHECK_EQ(value, GetAlignedPointerFromEmbedderData(index)); } @@ -1178,9 +1178,9 @@ static void InitializeTemplate(i::TemplateInfo that, int type, void Template::Set(v8::Local name, v8::Local value, v8::PropertyAttribute attribute) { auto templ = Utils::OpenHandle(this); - i::Isolate* isolate = templ->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); + i::Isolate* i_isolate = templ->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); auto value_obj = Utils::OpenHandle(*value); Utils::ApiCheck(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo(), @@ -1194,7 +1194,7 @@ void Template::Set(v8::Local name, v8::Local value, templ->set_serial_number(i::TemplateInfo::kDoNotCache); } - i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), + i::ApiNatives::AddDataProperty(i_isolate, templ, Utils::OpenHandle(*name), value_obj, static_cast(attribute)); } @@ -1213,13 +1213,13 @@ void Template::SetAccessorProperty(v8::Local name, // TODO(verwaest): Remove |access_control|. DCHECK_EQ(v8::DEFAULT, access_control); auto templ = Utils::OpenHandle(this); - auto isolate = templ->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + auto i_isolate = templ->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); DCHECK(!name.IsEmpty()); DCHECK(!getter.IsEmpty() || !setter.IsEmpty()); - i::HandleScope scope(isolate); + i::HandleScope scope(i_isolate); i::ApiNatives::AddAccessorProperty( - isolate, templ, Utils::OpenHandle(*name), + i_isolate, templ, Utils::OpenHandle(*name), Utils::OpenHandle(*getter, true), Utils::OpenHandle(*setter, true), static_cast(attribute)); } @@ -1231,9 +1231,29 @@ static void InitializeFunctionTemplate(i::FunctionTemplateInfo info, info.set_flag(0); } -static Local ObjectTemplateNew( - i::Isolate* isolate, v8::Local constructor, - bool do_not_cache); +namespace { +Local ObjectTemplateNew(i::Isolate* i_isolate, + v8::Local constructor, + bool do_not_cache) { + API_RCS_SCOPE(i_isolate, ObjectTemplate, New); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::Handle struct_obj = i_isolate->factory()->NewStruct( + i::OBJECT_TEMPLATE_INFO_TYPE, i::AllocationType::kOld); + i::Handle obj = + i::Handle::cast(struct_obj); + { + // Disallow GC until all fields of obj have acceptable types. + i::DisallowGarbageCollection no_gc; + i::ObjectTemplateInfo raw = *obj; + InitializeTemplate(raw, Consts::OBJECT_TEMPLATE, do_not_cache); + raw.set_data(0); + if (!constructor.IsEmpty()) { + raw.set_constructor(*Utils::OpenHandle(*constructor)); + } + } + return Utils::ToLocal(obj); +} +} // namespace Local FunctionTemplate::PrototypeTemplate() { auto self = Utils::OpenHandle(this); @@ -1266,6 +1286,7 @@ void FunctionTemplate::SetPrototypeProviderTemplate( result); } +namespace { static void EnsureNotPublished(i::Handle info, const char* func) { DCHECK_IMPLIES(info->instantiated(), info->published()); @@ -1273,20 +1294,8 @@ static void EnsureNotPublished(i::Handle info, "FunctionTemplate already instantiated"); } -void FunctionTemplate::Inherit(v8::Local value) { - auto info = Utils::OpenHandle(this); - EnsureNotPublished(info, "v8::FunctionTemplate::Inherit"); - i::Isolate* i_isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); - Utils::ApiCheck(info->GetPrototypeProviderTemplate().IsUndefined(i_isolate), - "v8::FunctionTemplate::Inherit", - "Protoype provider must be empty"); - i::FunctionTemplateInfo::SetParentTemplate(i_isolate, info, - Utils::OpenHandle(*value)); -} - -static Local FunctionTemplateNew( - i::Isolate* isolate, FunctionCallback callback, v8::Local data, +Local FunctionTemplateNew( + i::Isolate* i_isolate, FunctionCallback callback, v8::Local data, v8::Local signature, int length, ConstructorBehavior behavior, bool do_not_cache, v8::Local cached_property_name = v8::Local(), @@ -1295,7 +1304,7 @@ static Local FunctionTemplateNew( uint8_t instance_type = 0, uint8_t allowed_receiver_instance_type_range_start = 0, uint8_t allowed_receiver_instance_type_range_end = 0) { - i::Handle struct_obj = isolate->factory()->NewStruct( + i::Handle struct_obj = i_isolate->factory()->NewStruct( i::FUNCTION_TEMPLATE_INFO_TYPE, i::AllocationType::kOld); i::Handle obj = i::Handle::cast(struct_obj); @@ -1313,7 +1322,7 @@ static Local FunctionTemplateNew( } raw.set_cached_property_name( cached_property_name.IsEmpty() - ? i::ReadOnlyRoots(isolate).the_hole_value() + ? i::ReadOnlyRoots(i_isolate).the_hole_value() : *Utils::OpenHandle(*cached_property_name)); if (behavior == ConstructorBehavior::kThrow) raw.set_remove_prototype(true); raw.SetInstanceType(instance_type); @@ -1328,14 +1337,27 @@ static Local FunctionTemplateNew( } return Utils::ToLocal(obj); } +} // namespace + +void FunctionTemplate::Inherit(v8::Local value) { + auto info = Utils::OpenHandle(this); + EnsureNotPublished(info, "v8::FunctionTemplate::Inherit"); + i::Isolate* i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + Utils::ApiCheck(info->GetPrototypeProviderTemplate().IsUndefined(i_isolate), + "v8::FunctionTemplate::Inherit", + "Protoype provider must be empty"); + i::FunctionTemplateInfo::SetParentTemplate(i_isolate, info, + Utils::OpenHandle(*value)); +} Local FunctionTemplate::New( - Isolate* isolate, FunctionCallback callback, v8::Local data, + Isolate* v8_isolate, FunctionCallback callback, v8::Local data, v8::Local signature, int length, ConstructorBehavior behavior, SideEffectType side_effect_type, const CFunction* c_function, uint16_t instance_type, uint16_t allowed_receiver_instance_type_range_start, uint16_t allowed_receiver_instance_type_range_end) { - i::Isolate* i_isolate = reinterpret_cast(isolate); + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); // Changes to the environment cannot be captured in the snapshot. Expect no // function templates when the isolate is created for serialization. API_RCS_SCOPE(i_isolate, FunctionTemplate, New); @@ -1358,11 +1380,11 @@ Local FunctionTemplate::New( } Local FunctionTemplate::NewWithCFunctionOverloads( - Isolate* isolate, FunctionCallback callback, v8::Local data, + Isolate* v8_isolate, FunctionCallback callback, v8::Local data, v8::Local signature, int length, ConstructorBehavior behavior, SideEffectType side_effect_type, const MemorySpan& c_function_overloads) { - i::Isolate* i_isolate = reinterpret_cast(isolate); + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); API_RCS_SCOPE(i_isolate, FunctionTemplate, New); if (!Utils::ApiCheck( @@ -1380,10 +1402,10 @@ Local FunctionTemplate::NewWithCFunctionOverloads( } Local FunctionTemplate::NewWithCache( - Isolate* isolate, FunctionCallback callback, Local cache_property, - Local data, Local signature, int length, - SideEffectType side_effect_type) { - i::Isolate* i_isolate = reinterpret_cast(isolate); + Isolate* v8_isolate, FunctionCallback callback, + Local cache_property, Local data, + Local signature, int length, SideEffectType side_effect_type) { + i::Isolate* i_isolate = reinterpret_cast(v8_isolate); API_RCS_SCOPE(i_isolate, FunctionTemplate, NewWithCache); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); return FunctionTemplateNew(i_isolate, callback, data, signature, length, @@ -1391,20 +1413,20 @@ Local FunctionTemplate::NewWithCache( side_effect_type); } -Local Signature::New(Isolate* isolate, +Local Signature::New(Isolate* v8_isolate, Local receiver) { return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); } Local AccessorSignature::New( - Isolate* isolate, Local receiver) { + Isolate* v8_isolate, Local receiver) { return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); } -#define SET_FIELD_WRAPPED(isolate, obj, setter, cdata) \ - do { \ - i::Handle foreign = FromCData(isolate, cdata); \ - (obj)->setter(*foreign); \ +#define SET_FIELD_WRAPPED(i_isolate, obj, setter, cdata) \ + do { \ + i::Handle foreign = FromCData(i_isolate, cdata); \ + (obj)->setter(*foreign); \ } while (false) void FunctionTemplate::SetCallHandler( @@ -1413,38 +1435,39 @@ void FunctionTemplate::SetCallHandler( const MemorySpan& c_function_overloads) { auto info = Utils::OpenHandle(this); EnsureNotPublished(info, "v8::FunctionTemplate::SetCallHandler"); - i::Isolate* isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - i::Handle obj = isolate->factory()->NewCallHandlerInfo( + i::Isolate* i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + i::Handle obj = i_isolate->factory()->NewCallHandlerInfo( side_effect_type == SideEffectType::kHasNoSideEffect); - SET_FIELD_WRAPPED(isolate, obj, set_callback, callback); - SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback()); + SET_FIELD_WRAPPED(i_isolate, obj, set_callback, callback); + SET_FIELD_WRAPPED(i_isolate, obj, set_js_callback, + obj->redirected_callback()); if (data.IsEmpty()) { - data = v8::Undefined(reinterpret_cast(isolate)); + data = v8::Undefined(reinterpret_cast(i_isolate)); } obj->set_data(*Utils::OpenHandle(*data)); if (c_function_overloads.size() > 0) { // Stores the data for a sequence of CFunction overloads into a single // FixedArray, as [address_0, signature_0, ... address_n-1, signature_n-1]. i::Handle function_overloads = - isolate->factory()->NewFixedArray(static_cast( + i_isolate->factory()->NewFixedArray(static_cast( c_function_overloads.size() * i::FunctionTemplateInfo::kFunctionOverloadEntrySize)); int function_count = static_cast(c_function_overloads.size()); for (int i = 0; i < function_count; i++) { const CFunction& c_function = c_function_overloads.data()[i]; i::Handle address = - FromCData(isolate, c_function.GetAddress()); + FromCData(i_isolate, c_function.GetAddress()); function_overloads->set( i::FunctionTemplateInfo::kFunctionOverloadEntrySize * i, *address); i::Handle signature = - FromCData(isolate, c_function.GetTypeInfo()); + FromCData(i_isolate, c_function.GetTypeInfo()); function_overloads->set( i::FunctionTemplateInfo::kFunctionOverloadEntrySize * i + 1, *signature); } - i::FunctionTemplateInfo::SetCFunctionOverloads(isolate, info, + i::FunctionTemplateInfo::SetCFunctionOverloads(i_isolate, info, function_overloads); } info->set_call_code(*obj, kReleaseStore); @@ -1454,32 +1477,32 @@ namespace { template i::Handle MakeAccessorInfo( - i::Isolate* isolate, v8::Local name, Getter getter, Setter setter, + i::Isolate* i_isolate, v8::Local name, Getter getter, Setter setter, v8::Local data, v8::AccessControl settings, v8::Local signature, bool is_special_data_property, bool replace_on_access) { - i::Handle obj = isolate->factory()->NewAccessorInfo(); - SET_FIELD_WRAPPED(isolate, obj, set_getter, getter); + i::Handle obj = i_isolate->factory()->NewAccessorInfo(); + SET_FIELD_WRAPPED(i_isolate, obj, set_getter, getter); DCHECK_IMPLIES(replace_on_access, is_special_data_property && setter == nullptr); if (is_special_data_property && setter == nullptr) { setter = reinterpret_cast(&i::Accessors::ReconfigureToDataProperty); } - SET_FIELD_WRAPPED(isolate, obj, set_setter, setter); + SET_FIELD_WRAPPED(i_isolate, obj, set_setter, setter); i::Address redirected = obj->redirected_getter(); if (redirected != i::kNullAddress) { - SET_FIELD_WRAPPED(isolate, obj, set_js_getter, redirected); + SET_FIELD_WRAPPED(i_isolate, obj, set_js_getter, redirected); } i::Handle accessor_name = Utils::OpenHandle(*name); if (!accessor_name->IsUniqueName()) { - accessor_name = isolate->factory()->InternalizeString( + accessor_name = i_isolate->factory()->InternalizeString( i::Handle::cast(accessor_name)); } i::DisallowGarbageCollection no_gc; i::AccessorInfo raw_obj = *obj; if (data.IsEmpty()) { - raw_obj.set_data(i::ReadOnlyRoots(isolate).undefined_value()); + raw_obj.set_data(i::ReadOnlyRoots(i_isolate).undefined_value()); } else { raw_obj.set_data(*Utils::OpenHandle(*data)); } @@ -1504,125 +1527,105 @@ Local FunctionTemplate::InstanceTemplate() { "Reading from empty handle")) { return Local(); } - i::Isolate* isolate = handle->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - if (handle->GetInstanceTemplate().IsUndefined(isolate)) { + i::Isolate* i_isolate = handle->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + if (handle->GetInstanceTemplate().IsUndefined(i_isolate)) { Local templ = - ObjectTemplate::New(isolate, ToApiHandle(handle)); - i::FunctionTemplateInfo::SetInstanceTemplate(isolate, handle, + ObjectTemplate::New(i_isolate, ToApiHandle(handle)); + i::FunctionTemplateInfo::SetInstanceTemplate(i_isolate, handle, Utils::OpenHandle(*templ)); } i::Handle result( - i::ObjectTemplateInfo::cast(handle->GetInstanceTemplate()), isolate); + i::ObjectTemplateInfo::cast(handle->GetInstanceTemplate()), i_isolate); return Utils::ToLocal(result); } void FunctionTemplate::SetLength(int length) { auto info = Utils::OpenHandle(this); EnsureNotPublished(info, "v8::FunctionTemplate::SetLength"); - auto isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + auto i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); info->set_length(length); } void FunctionTemplate::SetClassName(Local name) { auto info = Utils::OpenHandle(this); EnsureNotPublished(info, "v8::FunctionTemplate::SetClassName"); - auto isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + auto i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); info->set_class_name(*Utils::OpenHandle(*name)); } void FunctionTemplate::SetAcceptAnyReceiver(bool value) { auto info = Utils::OpenHandle(this); EnsureNotPublished(info, "v8::FunctionTemplate::SetAcceptAnyReceiver"); - auto isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + auto i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); info->set_accept_any_receiver(value); } void FunctionTemplate::ReadOnlyPrototype() { auto info = Utils::OpenHandle(this); EnsureNotPublished(info, "v8::FunctionTemplate::ReadOnlyPrototype"); - auto isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + auto i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); info->set_read_only_prototype(true); } void FunctionTemplate::RemovePrototype() { auto info = Utils::OpenHandle(this); EnsureNotPublished(info, "v8::FunctionTemplate::RemovePrototype"); - auto isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + auto i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); info->set_remove_prototype(true); } // --- O b j e c t T e m p l a t e --- Local ObjectTemplate::New( - Isolate* isolate, v8::Local constructor) { - return New(reinterpret_cast(isolate), constructor); -} - -static Local ObjectTemplateNew( - i::Isolate* isolate, v8::Local constructor, - bool do_not_cache) { - API_RCS_SCOPE(isolate, ObjectTemplate, New); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::Handle struct_obj = isolate->factory()->NewStruct( - i::OBJECT_TEMPLATE_INFO_TYPE, i::AllocationType::kOld); - i::Handle obj = - i::Handle::cast(struct_obj); - { - // Disallow GC until all fields of obj have acceptable types. - i::DisallowGarbageCollection no_gc; - i::ObjectTemplateInfo raw = *obj; - InitializeTemplate(raw, Consts::OBJECT_TEMPLATE, do_not_cache); - raw.set_data(0); - if (!constructor.IsEmpty()) { - raw.set_constructor(*Utils::OpenHandle(*constructor)); - } - } - return Utils::ToLocal(obj); + Isolate* v8_isolate, v8::Local constructor) { + return New(reinterpret_cast(v8_isolate), constructor); } Local ObjectTemplate::New( - i::Isolate* isolate, v8::Local constructor) { - return ObjectTemplateNew(isolate, constructor, false); + i::Isolate* i_isolate, v8::Local constructor) { + return ObjectTemplateNew(i_isolate, constructor, false); } +namespace { // Ensure that the object template has a constructor. If no // constructor is available we create one. -static i::Handle EnsureConstructor( - i::Isolate* isolate, ObjectTemplate* object_template) { +i::Handle EnsureConstructor( + i::Isolate* i_isolate, ObjectTemplate* object_template) { i::Object obj = Utils::OpenHandle(object_template)->constructor(); - if (!obj.IsUndefined(isolate)) { + if (!obj.IsUndefined(i_isolate)) { i::FunctionTemplateInfo info = i::FunctionTemplateInfo::cast(obj); - return i::Handle(info, isolate); + return i::Handle(info, i_isolate); } Local templ = - FunctionTemplate::New(reinterpret_cast(isolate)); + FunctionTemplate::New(reinterpret_cast(i_isolate)); i::Handle constructor = Utils::OpenHandle(*templ); i::FunctionTemplateInfo::SetInstanceTemplate( - isolate, constructor, Utils::OpenHandle(object_template)); + i_isolate, constructor, Utils::OpenHandle(object_template)); Utils::OpenHandle(object_template)->set_constructor(*constructor); return constructor; } template -static void TemplateSetAccessor( - Template* template_obj, v8::Local name, Getter getter, Setter setter, - Data data, AccessControl settings, PropertyAttribute attribute, - v8::Local signature, bool is_special_data_property, - bool replace_on_access, SideEffectType getter_side_effect_type, - SideEffectType setter_side_effect_type) { +void TemplateSetAccessor(Template* template_obj, v8::Local name, + Getter getter, Setter setter, Data data, + AccessControl settings, PropertyAttribute attribute, + v8::Local signature, + bool is_special_data_property, bool replace_on_access, + SideEffectType getter_side_effect_type, + SideEffectType setter_side_effect_type) { auto info = Utils::OpenHandle(template_obj); - auto isolate = info->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); + auto i_isolate = info->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); i::Handle accessor_info = - MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature, - is_special_data_property, replace_on_access); + MakeAccessorInfo(i_isolate, name, getter, setter, data, settings, + signature, is_special_data_property, replace_on_access); { i::DisallowGarbageCollection no_gc; i::AccessorInfo raw = *accessor_info; @@ -1631,8 +1634,9 @@ static void TemplateSetAccessor( raw.set_getter_side_effect_type(getter_side_effect_type); raw.set_setter_side_effect_type(setter_side_effect_type); } - i::ApiNatives::AddNativeDataProperty(isolate, info, accessor_info); + i::ApiNatives::AddNativeDataProperty(i_isolate, info, accessor_info); } +} // namespace void Template::SetNativeDataProperty(v8::Local name, AccessorGetterCallback getter, @@ -1697,10 +1701,10 @@ void Template::SetLazyDataProperty(v8::Local name, void Template::SetIntrinsicDataProperty(Local name, Intrinsic intrinsic, PropertyAttribute attribute) { auto templ = Utils::OpenHandle(this); - i::Isolate* isolate = templ->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), + i::Isolate* i_isolate = templ->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + i::ApiNatives::AddDataProperty(i_isolate, templ, Utils::OpenHandle(*name), intrinsic, static_cast(attribute)); } @@ -1757,25 +1761,29 @@ void ObjectTemplate::SetAccessor(v8::Local name, getter_side_effect_type, setter_side_effect_type); } +namespace { template -static i::Handle CreateInterceptorInfo( - i::Isolate* isolate, Getter getter, Setter setter, Query query, +i::Handle CreateInterceptorInfo( + i::Isolate* i_isolate, Getter getter, Setter setter, Query query, Descriptor descriptor, Deleter remover, Enumerator enumerator, Definer definer, Local data, PropertyHandlerFlags flags) { - auto obj = i::Handle::cast(isolate->factory()->NewStruct( - i::INTERCEPTOR_INFO_TYPE, i::AllocationType::kOld)); + auto obj = + i::Handle::cast(i_isolate->factory()->NewStruct( + i::INTERCEPTOR_INFO_TYPE, i::AllocationType::kOld)); obj->set_flags(0); - if (getter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_getter, getter); - if (setter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_setter, setter); - if (query != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_query, query); + if (getter != nullptr) SET_FIELD_WRAPPED(i_isolate, obj, set_getter, getter); + if (setter != nullptr) SET_FIELD_WRAPPED(i_isolate, obj, set_setter, setter); + if (query != nullptr) SET_FIELD_WRAPPED(i_isolate, obj, set_query, query); if (descriptor != nullptr) - SET_FIELD_WRAPPED(isolate, obj, set_descriptor, descriptor); - if (remover != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_deleter, remover); + SET_FIELD_WRAPPED(i_isolate, obj, set_descriptor, descriptor); + if (remover != nullptr) + SET_FIELD_WRAPPED(i_isolate, obj, set_deleter, remover); if (enumerator != nullptr) - SET_FIELD_WRAPPED(isolate, obj, set_enumerator, enumerator); - if (definer != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_definer, definer); + SET_FIELD_WRAPPED(i_isolate, obj, set_enumerator, enumerator); + if (definer != nullptr) + SET_FIELD_WRAPPED(i_isolate, obj, set_definer, definer); obj->set_can_intercept_symbols( !(static_cast(flags) & static_cast(PropertyHandlerFlags::kOnlyInterceptStrings))); @@ -1788,7 +1796,7 @@ static i::Handle CreateInterceptorInfo( static_cast(PropertyHandlerFlags::kHasNoSideEffect)); if (data.IsEmpty()) { - data = v8::Undefined(reinterpret_cast(isolate)); + data = v8::Undefined(reinterpret_cast(i_isolate)); } obj->set_data(*Utils::OpenHandle(*data)); return obj; @@ -1796,46 +1804,47 @@ static i::Handle CreateInterceptorInfo( template -static i::Handle CreateNamedInterceptorInfo( - i::Isolate* isolate, Getter getter, Setter setter, Query query, +i::Handle CreateNamedInterceptorInfo( + i::Isolate* i_isolate, Getter getter, Setter setter, Query query, Descriptor descriptor, Deleter remover, Enumerator enumerator, Definer definer, Local data, PropertyHandlerFlags flags) { auto interceptor = - CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover, - enumerator, definer, data, flags); + CreateInterceptorInfo(i_isolate, getter, setter, query, descriptor, + remover, enumerator, definer, data, flags); interceptor->set_is_named(true); return interceptor; } template -static i::Handle CreateIndexedInterceptorInfo( - i::Isolate* isolate, Getter getter, Setter setter, Query query, +i::Handle CreateIndexedInterceptorInfo( + i::Isolate* i_isolate, Getter getter, Setter setter, Query query, Descriptor descriptor, Deleter remover, Enumerator enumerator, Definer definer, Local data, PropertyHandlerFlags flags) { auto interceptor = - CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover, - enumerator, definer, data, flags); + CreateInterceptorInfo(i_isolate, getter, setter, query, descriptor, + remover, enumerator, definer, data, flags); interceptor->set_is_named(false); return interceptor; } template -static void ObjectTemplateSetNamedPropertyHandler( +void ObjectTemplateSetNamedPropertyHandler( ObjectTemplate* templ, Getter getter, Setter setter, Query query, Descriptor descriptor, Deleter remover, Enumerator enumerator, Definer definer, Local data, PropertyHandlerFlags flags) { - i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - auto cons = EnsureConstructor(isolate, templ); + i::Isolate* i_isolate = Utils::OpenHandle(templ)->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + auto cons = EnsureConstructor(i_isolate, templ); EnsureNotPublished(cons, "ObjectTemplateSetNamedPropertyHandler"); auto obj = - CreateNamedInterceptorInfo(isolate, getter, setter, query, descriptor, + CreateNamedInterceptorInfo(i_isolate, getter, setter, query, descriptor, remover, enumerator, definer, data, flags); - i::FunctionTemplateInfo::SetNamedPropertyHandler(isolate, cons, obj); + i::FunctionTemplateInfo::SetNamedPropertyHandler(i_isolate, cons, obj); } +} // namespace void ObjectTemplate::SetHandler( const NamedPropertyHandlerConfiguration& config) { @@ -1846,37 +1855,37 @@ void ObjectTemplate::SetHandler( } void ObjectTemplate::MarkAsUndetectable() { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - auto cons = EnsureConstructor(isolate, this); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + auto cons = EnsureConstructor(i_isolate, this); EnsureNotPublished(cons, "v8::ObjectTemplate::MarkAsUndetectable"); cons->set_undetectable(true); } void ObjectTemplate::SetAccessCheckCallback(AccessCheckCallback callback, Local data) { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - auto cons = EnsureConstructor(isolate, this); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + auto cons = EnsureConstructor(i_isolate, this); EnsureNotPublished(cons, "v8::ObjectTemplate::SetAccessCheckCallback"); - i::Handle struct_info = isolate->factory()->NewStruct( + i::Handle struct_info = i_isolate->factory()->NewStruct( i::ACCESS_CHECK_INFO_TYPE, i::AllocationType::kOld); i::Handle info = i::Handle::cast(struct_info); - SET_FIELD_WRAPPED(isolate, info, set_callback, callback); + SET_FIELD_WRAPPED(i_isolate, info, set_callback, callback); info->set_named_interceptor(i::Object()); info->set_indexed_interceptor(i::Object()); if (data.IsEmpty()) { - data = v8::Undefined(reinterpret_cast(isolate)); + data = v8::Undefined(reinterpret_cast(i_isolate)); } info->set_data(*Utils::OpenHandle(*data)); - i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info); + i::FunctionTemplateInfo::SetAccessCheckInfo(i_isolate, cons, info); cons->set_needs_access_check(true); } @@ -1885,69 +1894,72 @@ void ObjectTemplate::SetAccessCheckCallbackAndHandler( const NamedPropertyHandlerConfiguration& named_handler, const IndexedPropertyHandlerConfiguration& indexed_handler, Local data) { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - auto cons = EnsureConstructor(isolate, this); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + auto cons = EnsureConstructor(i_isolate, this); EnsureNotPublished(cons, "v8::ObjectTemplate::SetAccessCheckCallbackWithHandler"); - i::Handle struct_info = isolate->factory()->NewStruct( + i::Handle struct_info = i_isolate->factory()->NewStruct( i::ACCESS_CHECK_INFO_TYPE, i::AllocationType::kOld); i::Handle info = i::Handle::cast(struct_info); - SET_FIELD_WRAPPED(isolate, info, set_callback, callback); + SET_FIELD_WRAPPED(i_isolate, info, set_callback, callback); auto named_interceptor = CreateNamedInterceptorInfo( - isolate, named_handler.getter, named_handler.setter, named_handler.query, - named_handler.descriptor, named_handler.deleter, named_handler.enumerator, - named_handler.definer, named_handler.data, named_handler.flags); + i_isolate, named_handler.getter, named_handler.setter, + named_handler.query, named_handler.descriptor, named_handler.deleter, + named_handler.enumerator, named_handler.definer, named_handler.data, + named_handler.flags); info->set_named_interceptor(*named_interceptor); auto indexed_interceptor = CreateIndexedInterceptorInfo( - isolate, indexed_handler.getter, indexed_handler.setter, + i_isolate, indexed_handler.getter, indexed_handler.setter, indexed_handler.query, indexed_handler.descriptor, indexed_handler.deleter, indexed_handler.enumerator, indexed_handler.definer, indexed_handler.data, indexed_handler.flags); info->set_indexed_interceptor(*indexed_interceptor); if (data.IsEmpty()) { - data = v8::Undefined(reinterpret_cast(isolate)); + data = v8::Undefined(reinterpret_cast(i_isolate)); } info->set_data(*Utils::OpenHandle(*data)); - i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info); + i::FunctionTemplateInfo::SetAccessCheckInfo(i_isolate, cons, info); cons->set_needs_access_check(true); } void ObjectTemplate::SetHandler( const IndexedPropertyHandlerConfiguration& config) { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - auto cons = EnsureConstructor(isolate, this); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + auto cons = EnsureConstructor(i_isolate, this); EnsureNotPublished(cons, "v8::ObjectTemplate::SetHandler"); auto obj = CreateIndexedInterceptorInfo( - isolate, config.getter, config.setter, config.query, config.descriptor, + i_isolate, config.getter, config.setter, config.query, config.descriptor, config.deleter, config.enumerator, config.definer, config.data, config.flags); - i::FunctionTemplateInfo::SetIndexedPropertyHandler(isolate, cons, obj); + i::FunctionTemplateInfo::SetIndexedPropertyHandler(i_isolate, cons, obj); } void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, Local data) { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); - i::HandleScope scope(isolate); - auto cons = EnsureConstructor(isolate, this); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); + i::HandleScope scope(i_isolate); + auto cons = EnsureConstructor(i_isolate, this); EnsureNotPublished(cons, "v8::ObjectTemplate::SetCallAsFunctionHandler"); - i::Handle obj = isolate->factory()->NewCallHandlerInfo(); - SET_FIELD_WRAPPED(isolate, obj, set_callback, callback); - SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback()); + i::Handle obj = + i_isolate->factory()->NewCallHandlerInfo(); + SET_FIELD_WRAPPED(i_isolate, obj, set_callback, callback); + SET_FIELD_WRAPPED(i_isolate, obj, set_js_callback, + obj->redirected_callback()); if (data.IsEmpty()) { - data = v8::Undefined(reinterpret_cast(isolate)); + data = v8::Undefined(reinterpret_cast(i_isolate)); } obj->set_data(*Utils::OpenHandle(*data)); - i::FunctionTemplateInfo::SetInstanceCallHandler(isolate, cons, obj); + i::FunctionTemplateInfo::SetInstanceCallHandler(i_isolate, cons, obj); } int ObjectTemplate::InternalFieldCount() const { @@ -1955,18 +1967,18 @@ int ObjectTemplate::InternalFieldCount() const { } void ObjectTemplate::SetInternalFieldCount(int value) { - i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); + i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); if (!Utils::ApiCheck(i::Smi::IsValid(value), "v8::ObjectTemplate::SetInternalFieldCount()", "Invalid embedder field count")) { return; } - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); if (value > 0) { // The embedder field count is set by the constructor function's // construct code, so we ensure that there is a constructor // function to do the setting. - EnsureConstructor(isolate, this); + EnsureConstructor(i_isolate, this); } Utils::OpenHandle(this)->set_embedder_field_count(value); } @@ -1977,8 +1989,8 @@ bool ObjectTemplate::IsImmutableProto() const { void ObjectTemplate::SetImmutableProto() { auto self = Utils::OpenHandle(this); - i::Isolate* isolate = self->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + i::Isolate* i_isolate = self->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); self->set_immutable_proto(true); } @@ -1988,8 +2000,8 @@ bool ObjectTemplate::IsCodeLike() const { void ObjectTemplate::SetCodeLike() { auto self = Utils::OpenHandle(this); - i::Isolate* isolate = self->GetIsolate(); - ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); + i::Isolate* i_isolate = self->GetIsolate(); + ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); self->set_code_like(true); } @@ -2020,11 +2032,11 @@ ScriptCompiler::StreamedSource::~StreamedSource() = default; Local