LCOV - code coverage report
Current view: top level - src - api.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 3874 4445 87.2 %
Date: 2019-02-19 Functions: 904 1089 83.0 %

          Line data    Source code
       1             : // Copyright 2012 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/api.h"
       6             : 
       7             : #include <string.h>  // For memcpy, strlen.
       8             : #include <cmath>     // For isnan.
       9             : #include <limits>
      10             : #include <vector>
      11             : 
      12             : #include "src/api-inl.h"
      13             : 
      14             : #include "include/v8-profiler.h"
      15             : #include "include/v8-testing.h"
      16             : #include "include/v8-util.h"
      17             : #include "src/accessors.h"
      18             : #include "src/api-natives.h"
      19             : #include "src/assert-scope.h"
      20             : #include "src/base/functional.h"
      21             : #include "src/base/logging.h"
      22             : #include "src/base/platform/platform.h"
      23             : #include "src/base/platform/time.h"
      24             : #include "src/base/safe_conversions.h"
      25             : #include "src/base/utils/random-number-generator.h"
      26             : #include "src/bootstrapper.h"
      27             : #include "src/builtins/builtins-utils.h"
      28             : #include "src/char-predicates-inl.h"
      29             : #include "src/compiler-dispatcher/compiler-dispatcher.h"
      30             : #include "src/compiler.h"
      31             : #include "src/contexts.h"
      32             : #include "src/conversions-inl.h"
      33             : #include "src/counters.h"
      34             : #include "src/cpu-features.h"
      35             : #include "src/date.h"
      36             : #include "src/debug/debug-coverage.h"
      37             : #include "src/debug/debug-evaluate.h"
      38             : #include "src/debug/debug-type-profile.h"
      39             : #include "src/debug/debug.h"
      40             : #include "src/debug/liveedit.h"
      41             : #include "src/deoptimizer.h"
      42             : #include "src/detachable-vector.h"
      43             : #include "src/execution.h"
      44             : #include "src/frames-inl.h"
      45             : #include "src/gdb-jit.h"
      46             : #include "src/global-handles.h"
      47             : #include "src/globals.h"
      48             : #include "src/heap/heap-inl.h"
      49             : #include "src/icu_util.h"
      50             : #include "src/isolate-inl.h"
      51             : #include "src/json-parser.h"
      52             : #include "src/json-stringifier.h"
      53             : #include "src/messages.h"
      54             : #include "src/microtask-queue.h"
      55             : #include "src/objects-inl.h"
      56             : #include "src/objects/api-callbacks.h"
      57             : #include "src/objects/embedder-data-array-inl.h"
      58             : #include "src/objects/embedder-data-slot-inl.h"
      59             : #include "src/objects/frame-array-inl.h"
      60             : #include "src/objects/hash-table-inl.h"
      61             : #include "src/objects/heap-object.h"
      62             : #include "src/objects/js-array-inl.h"
      63             : #include "src/objects/js-collection-inl.h"
      64             : #include "src/objects/js-generator-inl.h"
      65             : #include "src/objects/js-promise-inl.h"
      66             : #include "src/objects/js-regexp-inl.h"
      67             : #include "src/objects/module-inl.h"
      68             : #include "src/objects/oddball.h"
      69             : #include "src/objects/ordered-hash-table-inl.h"
      70             : #include "src/objects/slots.h"
      71             : #include "src/objects/smi.h"
      72             : #include "src/objects/stack-frame-info-inl.h"
      73             : #include "src/objects/templates.h"
      74             : #include "src/parsing/parse-info.h"
      75             : #include "src/parsing/parser.h"
      76             : #include "src/parsing/scanner-character-streams.h"
      77             : #include "src/pending-compilation-error-handler.h"
      78             : #include "src/profiler/cpu-profiler.h"
      79             : #include "src/profiler/heap-profiler.h"
      80             : #include "src/profiler/heap-snapshot-generator-inl.h"
      81             : #include "src/profiler/profile-generator-inl.h"
      82             : #include "src/profiler/tick-sample.h"
      83             : #include "src/property-descriptor.h"
      84             : #include "src/property-details.h"
      85             : #include "src/property.h"
      86             : #include "src/prototype.h"
      87             : #include "src/runtime-profiler.h"
      88             : #include "src/runtime/runtime.h"
      89             : #include "src/simulator.h"
      90             : #include "src/snapshot/code-serializer.h"
      91             : #include "src/snapshot/natives.h"
      92             : #include "src/snapshot/partial-serializer.h"
      93             : #include "src/snapshot/read-only-serializer.h"
      94             : #include "src/snapshot/snapshot.h"
      95             : #include "src/snapshot/startup-serializer.h"
      96             : #include "src/startup-data-util.h"
      97             : #include "src/string-hasher.h"
      98             : #include "src/tracing/trace-event.h"
      99             : #include "src/trap-handler/trap-handler.h"
     100             : #include "src/unicode-inl.h"
     101             : #include "src/v8.h"
     102             : #include "src/v8threads.h"
     103             : #include "src/value-serializer.h"
     104             : #include "src/version.h"
     105             : #include "src/vm-state-inl.h"
     106             : #include "src/wasm/streaming-decoder.h"
     107             : #include "src/wasm/wasm-engine.h"
     108             : #include "src/wasm/wasm-objects-inl.h"
     109             : #include "src/wasm/wasm-result.h"
     110             : #include "src/wasm/wasm-serialization.h"
     111             : 
     112             : #if V8_OS_LINUX || V8_OS_MACOSX
     113             : #include <signal.h>
     114             : #include "include/v8-wasm-trap-handler-posix.h"
     115             : #include "src/trap-handler/handler-inside-posix.h"
     116             : #endif
     117             : 
     118             : #if V8_OS_WIN
     119             : #include <windows.h>
     120             : #include "include/v8-wasm-trap-handler-win.h"
     121             : #include "src/trap-handler/handler-inside-win.h"
     122             : #endif
     123             : 
     124             : namespace v8 {
     125             : 
     126             : /*
     127             :  * Most API methods should use one of the three macros:
     128             :  *
     129             :  * ENTER_V8, ENTER_V8_NO_SCRIPT, ENTER_V8_NO_SCRIPT_NO_EXCEPTION.
     130             :  *
     131             :  * The latter two assume that no script is executed, and no exceptions are
     132             :  * scheduled in addition (respectively). Creating a pending exception and
     133             :  * removing it before returning is ok.
     134             :  *
     135             :  * Exceptions should be handled either by invoking one of the
     136             :  * RETURN_ON_FAILED_EXECUTION* macros.
     137             :  *
     138             :  * Don't use macros with DO_NOT_USE in their name.
     139             :  *
     140             :  * TODO(jochen): Document debugger specific macros.
     141             :  * TODO(jochen): Document LOG_API and other RuntimeCallStats macros.
     142             :  * TODO(jochen): All API methods should invoke one of the ENTER_V8* macros.
     143             :  * TODO(jochen): Remove calls form API methods to DO_NOT_USE macros.
     144             :  */
     145             : 
     146             : #define LOG_API(isolate, class_name, function_name)                           \
     147             :   i::RuntimeCallTimerScope _runtime_timer(                                    \
     148             :       isolate, i::RuntimeCallCounterId::kAPI_##class_name##_##function_name); \
     149             :   LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name))
     150             : 
     151             : #define ENTER_V8_DO_NOT_USE(isolate) i::VMState<v8::OTHER> __state__((isolate))
     152             : 
     153             : #define ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name,  \
     154             :                                    function_name, bailout_value,  \
     155             :                                    HandleScopeClass, do_callback) \
     156             :   if (IsExecutionTerminatingCheck(isolate)) {                     \
     157             :     return bailout_value;                                         \
     158             :   }                                                               \
     159             :   HandleScopeClass handle_scope(isolate);                         \
     160             :   CallDepthScope<do_callback> call_depth_scope(isolate, context); \
     161             :   LOG_API(isolate, class_name, function_name);                    \
     162             :   i::VMState<v8::OTHER> __state__((isolate));                     \
     163             :   bool has_pending_exception = false
     164             : 
     165             : #define PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, T)       \
     166             :   if (IsExecutionTerminatingCheck(isolate)) {                                \
     167             :     return MaybeLocal<T>();                                                  \
     168             :   }                                                                          \
     169             :   InternalEscapableScope handle_scope(isolate);                              \
     170             :   CallDepthScope<false> call_depth_scope(isolate, v8::Local<v8::Context>()); \
     171             :   i::VMState<v8::OTHER> __state__((isolate));                                \
     172             :   bool has_pending_exception = false
     173             : 
     174             : #define PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \
     175             :                                            bailout_value, HandleScopeClass,    \
     176             :                                            do_callback)                        \
     177             :   auto isolate = context.IsEmpty()                                             \
     178             :                      ? i::Isolate::Current()                                   \
     179             :                      : reinterpret_cast<i::Isolate*>(context->GetIsolate());   \
     180             :   ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name,      \
     181             :                              bailout_value, HandleScopeClass, do_callback);
     182             : 
     183             : #define PREPARE_FOR_EXECUTION(context, class_name, function_name, T)          \
     184             :   PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name,      \
     185             :                                      MaybeLocal<T>(), InternalEscapableScope, \
     186             :                                      false)
     187             : 
     188             : #define ENTER_V8(isolate, context, class_name, function_name, bailout_value, \
     189             :                  HandleScopeClass)                                           \
     190             :   ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name,    \
     191             :                              bailout_value, HandleScopeClass, true)
     192             : 
     193             : #ifdef DEBUG
     194             : #define ENTER_V8_NO_SCRIPT(isolate, context, class_name, function_name,   \
     195             :                            bailout_value, HandleScopeClass)               \
     196             :   ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \
     197             :                              bailout_value, HandleScopeClass, false);     \
     198             :   i::DisallowJavascriptExecutionDebugOnly __no_script__((isolate))
     199             : 
     200             : #define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate)                    \
     201             :   i::VMState<v8::OTHER> __state__((isolate));                       \
     202             :   i::DisallowJavascriptExecutionDebugOnly __no_script__((isolate)); \
     203             :   i::DisallowExceptions __no_exceptions__((isolate))
     204             : 
     205             : #define ENTER_V8_FOR_NEW_CONTEXT(isolate)     \
     206             :   i::VMState<v8::OTHER> __state__((isolate)); \
     207             :   i::DisallowExceptions __no_exceptions__((isolate))
     208             : #else
     209             : #define ENTER_V8_NO_SCRIPT(isolate, context, class_name, function_name,   \
     210             :                            bailout_value, HandleScopeClass)               \
     211             :   ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \
     212             :                              bailout_value, HandleScopeClass, false)
     213             : 
     214             : #define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate) \
     215             :   i::VMState<v8::OTHER> __state__((isolate));
     216             : 
     217             : #define ENTER_V8_FOR_NEW_CONTEXT(isolate) \
     218             :   i::VMState<v8::OTHER> __state__((isolate));
     219             : #endif  // DEBUG
     220             : 
     221             : #define EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, value) \
     222             :   do {                                                            \
     223             :     if (has_pending_exception) {                                  \
     224             :       call_depth_scope.Escape();                                  \
     225             :       return value;                                               \
     226             :     }                                                             \
     227             :   } while (false)
     228             : 
     229             : #define RETURN_ON_FAILED_EXECUTION(T) \
     230             :   EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, MaybeLocal<T>())
     231             : 
     232             : #define RETURN_ON_FAILED_EXECUTION_PRIMITIVE(T) \
     233             :   EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, Nothing<T>())
     234             : 
     235             : #define RETURN_TO_LOCAL_UNCHECKED(maybe_local, T) \
     236             :   return maybe_local.FromMaybe(Local<T>());
     237             : 
     238             : 
     239             : #define RETURN_ESCAPED(value) return handle_scope.Escape(value);
     240             : 
     241             : namespace {
     242             : 
     243           0 : Local<Context> ContextFromNeverReadOnlySpaceObject(
     244             :     i::Handle<i::JSReceiver> obj) {
     245           0 :   return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
     246             : }
     247             : 
     248             : class InternalEscapableScope : public v8::EscapableHandleScope {
     249             :  public:
     250             :   explicit inline InternalEscapableScope(i::Isolate* isolate)
     251     7258870 :       : v8::EscapableHandleScope(reinterpret_cast<v8::Isolate*>(isolate)) {}
     252             : };
     253             : 
     254             : // TODO(jochen): This should be #ifdef DEBUG
     255             : #ifdef V8_CHECK_MICROTASKS_SCOPES_CONSISTENCY
     256             : void CheckMicrotasksScopesConsistency(i::MicrotaskQueue* microtask_queue) {
     257             :   if (microtask_queue &&
     258             :       microtask_queue->microtasks_policy() == v8::MicrotasksPolicy::kScoped) {
     259             :     DCHECK(microtask_queue->GetMicrotasksScopeDepth() ||
     260             :            !microtask_queue->DebugMicrotasksScopeDepthIsZero());
     261             :   }
     262             : }
     263             : #endif
     264             : 
     265             : template <bool do_callback>
     266             : class CallDepthScope {
     267             :  public:
     268    36999938 :   explicit CallDepthScope(i::Isolate* isolate, Local<Context> context)
     269             :       : isolate_(isolate),
     270             :         context_(context),
     271             :         escaped_(false),
     272             :         safe_for_termination_(isolate->next_v8_call_is_safe_for_termination()),
     273             :         interrupts_scope_(isolate_, i::StackGuard::TERMINATE_EXECUTION,
     274    24672674 :                           isolate_->only_terminate_in_safe_scope()
     275             :                               ? (safe_for_termination_
     276             :                                      ? i::InterruptsScope::kRunInterrupts
     277             :                                      : i::InterruptsScope::kPostponeInterrupts)
     278    37008999 :                               : i::InterruptsScope::kNoop) {
     279    12336341 :     isolate_->handle_scope_implementer()->IncrementCallDepth();
     280    12336341 :     isolate_->set_next_v8_call_is_safe_for_termination(false);
     281    12336341 :     if (!context.IsEmpty()) {
     282             :       i::Handle<i::Context> env = Utils::OpenHandle(*context);
     283             :       i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
     284    36981367 :       if (!isolate->context().is_null() &&
     285    36980915 :           isolate->context()->native_context() == env->native_context()) {
     286    12326611 :         context_ = Local<Context>();
     287             :       } else {
     288             :         impl->SaveContext(isolate->context());
     289             :         isolate->set_context(*env);
     290             :       }
     291             :     }
     292     5437047 :     if (do_callback) isolate_->FireBeforeCallEnteredCallback();
     293    12336342 :   }
     294    12336331 :   ~CallDepthScope() {
     295    17761617 :     i::MicrotaskQueue* microtask_queue = isolate_->default_microtask_queue();
     296    12336331 :     if (!context_.IsEmpty()) {
     297         253 :       i::HandleScopeImplementer* impl = isolate_->handle_scope_implementer();
     298         662 :       isolate_->set_context(impl->RestoreContext());
     299             : 
     300             :       i::Handle<i::Context> env = Utils::OpenHandle(*context_);
     301        1071 :       microtask_queue = env->native_context()->microtask_queue();
     302             :     }
     303    12336331 :     if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth();
     304     5437037 :     if (do_callback) isolate_->FireCallCompletedCallback(microtask_queue);
     305             : // TODO(jochen): This should be #ifdef DEBUG
     306             : #ifdef V8_CHECK_MICROTASKS_SCOPES_CONSISTENCY
     307             :     if (do_callback) CheckMicrotasksScopesConsistency(microtask_queue);
     308             : #endif
     309    12336330 :     isolate_->set_next_v8_call_is_safe_for_termination(safe_for_termination_);
     310    12336331 :   }
     311             : 
     312       12415 :   void Escape() {
     313             :     DCHECK(!escaped_);
     314       12415 :     escaped_ = true;
     315       12415 :     auto handle_scope_implementer = isolate_->handle_scope_implementer();
     316             :     handle_scope_implementer->DecrementCallDepth();
     317             :     bool clear_exception =
     318             :         handle_scope_implementer->CallDepthIsZero() &&
     319       12415 :         isolate_->thread_local_top()->try_catch_handler_ == nullptr;
     320       12415 :     isolate_->OptionalRescheduleException(clear_exception);
     321       12415 :   }
     322             : 
     323             :  private:
     324             :   i::Isolate* const isolate_;
     325             :   Local<Context> context_;
     326             :   bool escaped_;
     327             :   bool do_callback_;
     328             :   bool safe_for_termination_;
     329             :   i::InterruptsScope interrupts_scope_;
     330             : };
     331             : 
     332             : }  // namespace
     333             : 
     334             : 
     335       15864 : static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
     336             :                                              i::Handle<i::Script> script) {
     337       31728 :   i::Handle<i::Object> scriptName(script->GetNameOrSourceURL(), isolate);
     338             :   i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate);
     339             :   i::Handle<i::FixedArray> host_defined_options(script->host_defined_options(),
     340       31728 :                                                 isolate);
     341             :   v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
     342       15864 :   ScriptOriginOptions options(script->origin_options());
     343             :   v8::ScriptOrigin origin(
     344             :       Utils::ToLocal(scriptName),
     345             :       v8::Integer::New(v8_isolate, script->line_offset()),
     346             :       v8::Integer::New(v8_isolate, script->column_offset()),
     347             :       v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()),
     348             :       v8::Integer::New(v8_isolate, script->id()),
     349             :       Utils::ToLocal(source_map_url),
     350             :       v8::Boolean::New(v8_isolate, options.IsOpaque()),
     351             :       v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM),
     352             :       v8::Boolean::New(v8_isolate, options.IsModule()),
     353       47592 :       Utils::ToLocal(host_defined_options));
     354       15864 :   return origin;
     355             : }
     356             : 
     357             : 
     358             : // --- E x c e p t i o n   B e h a v i o r ---
     359             : 
     360           5 : void i::FatalProcessOutOfMemory(i::Isolate* isolate, const char* location) {
     361           5 :   i::V8::FatalProcessOutOfMemory(isolate, location, false);
     362             : }
     363             : 
     364             : // When V8 cannot allocate memory FatalProcessOutOfMemory is called. The default
     365             : // OOM error handler is called and execution is stopped.
     366          15 : void i::V8::FatalProcessOutOfMemory(i::Isolate* isolate, const char* location,
     367             :                                     bool is_heap_oom) {
     368             :   char last_few_messages[Heap::kTraceRingBufferSize + 1];
     369             :   char js_stacktrace[Heap::kStacktraceBufferSize + 1];
     370             :   i::HeapStats heap_stats;
     371             : 
     372          15 :   if (isolate == nullptr) {
     373             :     isolate = Isolate::TryGetCurrent();
     374             :   }
     375             : 
     376          15 :   if (isolate == nullptr) {
     377             :     // If the Isolate is not available for the current thread we cannot retrieve
     378             :     // memory information from the Isolate. Write easy-to-recognize values on
     379             :     // the stack.
     380             :     memset(last_few_messages, 0x0BADC0DE, Heap::kTraceRingBufferSize + 1);
     381             :     memset(js_stacktrace, 0x0BADC0DE, Heap::kStacktraceBufferSize + 1);
     382             :     memset(&heap_stats, 0xBADC0DE, sizeof(heap_stats));
     383             :     // Note that the embedder's oom handler is also not available and therefore
     384             :     // won't be called in this case. We just crash.
     385           0 :     FATAL("Fatal process out of memory: %s", location);
     386             :     UNREACHABLE();
     387             :   }
     388             : 
     389             :   memset(last_few_messages, 0, Heap::kTraceRingBufferSize + 1);
     390             :   memset(js_stacktrace, 0, Heap::kStacktraceBufferSize + 1);
     391             : 
     392             :   intptr_t start_marker;
     393          15 :   heap_stats.start_marker = &start_marker;
     394             :   size_t ro_space_size;
     395          15 :   heap_stats.ro_space_size = &ro_space_size;
     396             :   size_t ro_space_capacity;
     397          15 :   heap_stats.ro_space_capacity = &ro_space_capacity;
     398             :   size_t new_space_size;
     399          15 :   heap_stats.new_space_size = &new_space_size;
     400             :   size_t new_space_capacity;
     401          15 :   heap_stats.new_space_capacity = &new_space_capacity;
     402             :   size_t old_space_size;
     403          15 :   heap_stats.old_space_size = &old_space_size;
     404             :   size_t old_space_capacity;
     405          15 :   heap_stats.old_space_capacity = &old_space_capacity;
     406             :   size_t code_space_size;
     407          15 :   heap_stats.code_space_size = &code_space_size;
     408             :   size_t code_space_capacity;
     409          15 :   heap_stats.code_space_capacity = &code_space_capacity;
     410             :   size_t map_space_size;
     411          15 :   heap_stats.map_space_size = &map_space_size;
     412             :   size_t map_space_capacity;
     413          15 :   heap_stats.map_space_capacity = &map_space_capacity;
     414             :   size_t lo_space_size;
     415          15 :   heap_stats.lo_space_size = &lo_space_size;
     416             :   size_t code_lo_space_size;
     417          15 :   heap_stats.code_lo_space_size = &code_lo_space_size;
     418             :   size_t global_handle_count;
     419          15 :   heap_stats.global_handle_count = &global_handle_count;
     420             :   size_t weak_global_handle_count;
     421          15 :   heap_stats.weak_global_handle_count = &weak_global_handle_count;
     422             :   size_t pending_global_handle_count;
     423          15 :   heap_stats.pending_global_handle_count = &pending_global_handle_count;
     424             :   size_t near_death_global_handle_count;
     425          15 :   heap_stats.near_death_global_handle_count = &near_death_global_handle_count;
     426             :   size_t free_global_handle_count;
     427          15 :   heap_stats.free_global_handle_count = &free_global_handle_count;
     428             :   size_t memory_allocator_size;
     429          15 :   heap_stats.memory_allocator_size = &memory_allocator_size;
     430             :   size_t memory_allocator_capacity;
     431          15 :   heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
     432             :   size_t malloced_memory;
     433          15 :   heap_stats.malloced_memory = &malloced_memory;
     434             :   size_t malloced_peak_memory;
     435          15 :   heap_stats.malloced_peak_memory = &malloced_peak_memory;
     436          15 :   size_t objects_per_type[LAST_TYPE + 1] = {0};
     437          15 :   heap_stats.objects_per_type = objects_per_type;
     438          15 :   size_t size_per_type[LAST_TYPE + 1] = {0};
     439          15 :   heap_stats.size_per_type = size_per_type;
     440             :   int os_error;
     441          15 :   heap_stats.os_error = &os_error;
     442          15 :   heap_stats.last_few_messages = last_few_messages;
     443          15 :   heap_stats.js_stacktrace = js_stacktrace;
     444             :   intptr_t end_marker;
     445          15 :   heap_stats.end_marker = &end_marker;
     446          15 :   if (isolate->heap()->HasBeenSetUp()) {
     447             :     // BUG(1718): Don't use the take_snapshot since we don't support
     448             :     // HeapIterator here without doing a special GC.
     449          15 :     isolate->heap()->RecordStats(&heap_stats, false);
     450             :     char* first_newline = strchr(last_few_messages, '\n');
     451          15 :     if (first_newline == nullptr || first_newline[1] == '\0')
     452             :       first_newline = last_few_messages;
     453          15 :     PrintF("\n<--- Last few GCs --->\n%s\n", first_newline);
     454          15 :     PrintF("\n<--- JS stacktrace --->\n%s\n", js_stacktrace);
     455             :   }
     456          15 :   Utils::ReportOOMFailure(isolate, location, is_heap_oom);
     457             :   // If the fatal error handler returns, we stop execution.
     458           0 :   FATAL("API fatal error handler returned after process out of memory");
     459             : }
     460             : 
     461             : 
     462          10 : void Utils::ReportApiFailure(const char* location, const char* message) {
     463          10 :   i::Isolate* isolate = i::Isolate::Current();
     464             :   FatalErrorCallback callback = nullptr;
     465          10 :   if (isolate != nullptr) {
     466             :     callback = isolate->exception_behavior();
     467             :   }
     468          10 :   if (callback == nullptr) {
     469             :     base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location,
     470           0 :                          message);
     471           0 :     base::OS::Abort();
     472             :   } else {
     473          10 :     callback(location, message);
     474             :   }
     475             :   isolate->SignalFatalError();
     476          10 : }
     477             : 
     478          30 : void Utils::ReportOOMFailure(i::Isolate* isolate, const char* location,
     479             :                              bool is_heap_oom) {
     480             :   OOMErrorCallback oom_callback = isolate->oom_behavior();
     481          15 :   if (oom_callback == nullptr) {
     482             :     // TODO(wfh): Remove this fallback once Blink is setting OOM handler. See
     483             :     // crbug.com/614440.
     484             :     FatalErrorCallback fatal_callback = isolate->exception_behavior();
     485          15 :     if (fatal_callback == nullptr) {
     486             :       base::OS::PrintError("\n#\n# Fatal %s OOM in %s\n#\n\n",
     487           0 :                            is_heap_oom ? "javascript" : "process", location);
     488           0 :       base::OS::Abort();
     489             :     } else {
     490             :       fatal_callback(location,
     491             :                      is_heap_oom
     492             :                          ? "Allocation failed - JavaScript heap out of memory"
     493          15 :                          : "Allocation failed - process out of memory");
     494             :     }
     495             :   } else {
     496           0 :     oom_callback(location, is_heap_oom);
     497             :   }
     498             :   isolate->SignalFatalError();
     499           0 : }
     500             : 
     501    12337869 : static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
     502    12337869 :   if (isolate->has_scheduled_exception()) {
     503             :     return isolate->scheduled_exception() ==
     504             :            i::ReadOnlyRoots(isolate).termination_exception();
     505             :   }
     506             :   return false;
     507             : }
     508             : 
     509             : 
     510       59592 : void V8::SetNativesDataBlob(StartupData* natives_blob) {
     511       59592 :   i::V8::SetNativesBlob(natives_blob);
     512       59592 : }
     513             : 
     514             : 
     515       59592 : void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
     516       59592 :   i::V8::SetSnapshotBlob(snapshot_blob);
     517       59592 : }
     518             : 
     519             : namespace {
     520             : 
     521      298024 : class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
     522             :  public:
     523      214494 :   void* Allocate(size_t length) override {
     524             : #if V8_OS_AIX && _LINUX_SOURCE_COMPAT
     525             :     // Work around for GCC bug on AIX
     526             :     // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79839
     527             :     void* data = __linux_calloc(length, 1);
     528             : #else
     529      214494 :     void* data = calloc(length, 1);
     530             : #endif
     531      214494 :     return data;
     532             :   }
     533             : 
     534       11998 :   void* AllocateUninitialized(size_t length) override {
     535             : #if V8_OS_AIX && _LINUX_SOURCE_COMPAT
     536             :     // Work around for GCC bug on AIX
     537             :     // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79839
     538             :     void* data = __linux_malloc(length);
     539             : #else
     540       11998 :     void* data = malloc(length);
     541             : #endif
     542       11998 :     return data;
     543             :   }
     544             : 
     545      226438 :   void Free(void* data, size_t) override { free(data); }
     546             : };
     547             : 
     548         573 : struct SnapshotCreatorData {
     549             :   explicit SnapshotCreatorData(Isolate* isolate)
     550             :       : isolate_(isolate),
     551             :         default_context_(),
     552             :         contexts_(isolate),
     553         382 :         created_(false) {}
     554             : 
     555             :   static SnapshotCreatorData* cast(void* data) {
     556             :     return reinterpret_cast<SnapshotCreatorData*>(data);
     557             :   }
     558             : 
     559             :   ArrayBufferAllocator allocator_;
     560             :   Isolate* isolate_;
     561             :   Persistent<Context> default_context_;
     562             :   SerializeInternalFieldsCallback default_embedder_fields_serializer_;
     563             :   PersistentValueVector<Context> contexts_;
     564             :   std::vector<SerializeInternalFieldsCallback> embedder_fields_serializers_;
     565             :   bool created_;
     566             : };
     567             : 
     568             : }  // namespace
     569             : 
     570         191 : SnapshotCreator::SnapshotCreator(Isolate* isolate,
     571             :                                  const intptr_t* external_references,
     572             :                                  StartupData* existing_snapshot) {
     573         191 :   SnapshotCreatorData* data = new SnapshotCreatorData(isolate);
     574             :   data->isolate_ = isolate;
     575             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
     576         191 :   internal_isolate->set_array_buffer_allocator(&data->allocator_);
     577             :   internal_isolate->set_api_external_references(external_references);
     578             :   internal_isolate->enable_serializer();
     579             :   isolate->Enter();
     580             :   const StartupData* blob = existing_snapshot
     581             :                                 ? existing_snapshot
     582         191 :                                 : i::Snapshot::DefaultSnapshotBlob();
     583         191 :   if (blob && blob->raw_size > 0) {
     584             :     internal_isolate->set_snapshot_blob(blob);
     585         190 :     i::Snapshot::Initialize(internal_isolate);
     586             :   } else {
     587           1 :     internal_isolate->Init(nullptr);
     588             :   }
     589         191 :   data_ = data;
     590         191 : }
     591             : 
     592         190 : SnapshotCreator::SnapshotCreator(const intptr_t* external_references,
     593             :                                  StartupData* existing_snapshot)
     594             :     : SnapshotCreator(Isolate::Allocate(), external_references,
     595         190 :                       existing_snapshot) {}
     596             : 
     597         191 : SnapshotCreator::~SnapshotCreator() {
     598         191 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     599             :   DCHECK(data->created_);
     600         191 :   Isolate* isolate = data->isolate_;
     601             :   isolate->Exit();
     602         191 :   isolate->Dispose();
     603         191 :   delete data;
     604         191 : }
     605             : 
     606         191 : Isolate* SnapshotCreator::GetIsolate() {
     607         191 :   return SnapshotCreatorData::cast(data_)->isolate_;
     608             : }
     609             : 
     610         191 : void SnapshotCreator::SetDefaultContext(
     611             :     Local<Context> context, SerializeInternalFieldsCallback callback) {
     612             :   DCHECK(!context.IsEmpty());
     613         191 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     614             :   DCHECK(!data->created_);
     615             :   DCHECK(data->default_context_.IsEmpty());
     616         191 :   Isolate* isolate = data->isolate_;
     617         191 :   CHECK_EQ(isolate, context->GetIsolate());
     618             :   data->default_context_.Reset(isolate, context);
     619         191 :   data->default_embedder_fields_serializer_ = callback;
     620         191 : }
     621             : 
     622          35 : size_t SnapshotCreator::AddContext(Local<Context> context,
     623             :                                    SerializeInternalFieldsCallback callback) {
     624             :   DCHECK(!context.IsEmpty());
     625          35 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     626             :   DCHECK(!data->created_);
     627          35 :   Isolate* isolate = data->isolate_;
     628          35 :   CHECK_EQ(isolate, context->GetIsolate());
     629             :   size_t index = data->contexts_.Size();
     630          35 :   data->contexts_.Append(context);
     631          35 :   data->embedder_fields_serializers_.push_back(callback);
     632          35 :   return index;
     633             : }
     634             : 
     635          10 : size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
     636          10 :   return AddData(template_obj);
     637             : }
     638             : 
     639          50 : size_t SnapshotCreator::AddData(i::Address object) {
     640             :   DCHECK_NE(object, i::kNullAddress);
     641          50 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     642             :   DCHECK(!data->created_);
     643          50 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
     644             :   i::HandleScope scope(isolate);
     645             :   i::Handle<i::Object> obj(i::Object(object), isolate);
     646             :   i::Handle<i::ArrayList> list;
     647         100 :   if (!isolate->heap()->serialized_objects()->IsArrayList()) {
     648           5 :     list = i::ArrayList::New(isolate, 1);
     649             :   } else {
     650             :     list = i::Handle<i::ArrayList>(
     651          90 :         i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate);
     652             :   }
     653          50 :   size_t index = static_cast<size_t>(list->Length());
     654          50 :   list = i::ArrayList::Add(isolate, list, obj);
     655          50 :   isolate->heap()->SetSerializedObjects(*list);
     656          50 :   return index;
     657             : }
     658             : 
     659          35 : size_t SnapshotCreator::AddData(Local<Context> context, i::Address object) {
     660             :   DCHECK_NE(object, i::kNullAddress);
     661             :   DCHECK(!SnapshotCreatorData::cast(data_)->created_);
     662             :   i::Handle<i::Context> ctx = Utils::OpenHandle(*context);
     663             :   i::Isolate* isolate = ctx->GetIsolate();
     664             :   i::HandleScope scope(isolate);
     665             :   i::Handle<i::Object> obj(i::Object(object), isolate);
     666             :   i::Handle<i::ArrayList> list;
     667          70 :   if (!ctx->serialized_objects()->IsArrayList()) {
     668           5 :     list = i::ArrayList::New(isolate, 1);
     669             :   } else {
     670             :     list = i::Handle<i::ArrayList>(
     671          60 :         i::ArrayList::cast(ctx->serialized_objects()), isolate);
     672             :   }
     673          35 :   size_t index = static_cast<size_t>(list->Length());
     674          35 :   list = i::ArrayList::Add(isolate, list, obj);
     675          70 :   ctx->set_serialized_objects(*list);
     676          35 :   return index;
     677             : }
     678             : 
     679             : namespace {
     680         226 : void ConvertSerializedObjectsToFixedArray(Local<Context> context) {
     681             :   i::Handle<i::Context> ctx = Utils::OpenHandle(*context);
     682             :   i::Isolate* isolate = ctx->GetIsolate();
     683         452 :   if (!ctx->serialized_objects()->IsArrayList()) {
     684           5 :     ctx->set_serialized_objects(i::ReadOnlyRoots(isolate).empty_fixed_array());
     685             :   } else {
     686         442 :     i::Handle<i::ArrayList> list(i::ArrayList::cast(ctx->serialized_objects()),
     687         442 :                                  isolate);
     688         221 :     i::Handle<i::FixedArray> elements = i::ArrayList::Elements(isolate, list);
     689         221 :     ctx->set_serialized_objects(*elements);
     690             :   }
     691         226 : }
     692             : 
     693         191 : void ConvertSerializedObjectsToFixedArray(i::Isolate* isolate) {
     694         382 :   if (!isolate->heap()->serialized_objects()->IsArrayList()) {
     695             :     isolate->heap()->SetSerializedObjects(
     696           0 :         i::ReadOnlyRoots(isolate).empty_fixed_array());
     697             :   } else {
     698             :     i::Handle<i::ArrayList> list(
     699         382 :         i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate);
     700         191 :     i::Handle<i::FixedArray> elements = i::ArrayList::Elements(isolate, list);
     701         191 :     isolate->heap()->SetSerializedObjects(*elements);
     702             :   }
     703         191 : }
     704             : }  // anonymous namespace
     705             : 
     706         191 : StartupData SnapshotCreator::CreateBlob(
     707             :     SnapshotCreator::FunctionCodeHandling function_code_handling) {
     708         191 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     709         191 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
     710             :   DCHECK(!data->created_);
     711             :   DCHECK(!data->default_context_.IsEmpty());
     712             : 
     713         191 :   int num_additional_contexts = static_cast<int>(data->contexts_.Size());
     714             : 
     715             :   {
     716         191 :     i::HandleScope scope(isolate);
     717             :     // Convert list of context-independent data to FixedArray.
     718         191 :     ConvertSerializedObjectsToFixedArray(isolate);
     719             : 
     720             :     // Convert lists of context-dependent data to FixedArray.
     721             :     ConvertSerializedObjectsToFixedArray(
     722         382 :         data->default_context_.Get(data->isolate_));
     723         226 :     for (int i = 0; i < num_additional_contexts; i++) {
     724          35 :       ConvertSerializedObjectsToFixedArray(data->contexts_.Get(i));
     725             :     }
     726             : 
     727             :     // We need to store the global proxy size upfront in case we need the
     728             :     // bootstrapper to create a global proxy before we deserialize the context.
     729             :     i::Handle<i::FixedArray> global_proxy_sizes =
     730         191 :         isolate->factory()->NewFixedArray(num_additional_contexts, i::TENURED);
     731         226 :     for (int i = 0; i < num_additional_contexts; i++) {
     732             :       i::Handle<i::Context> context =
     733          70 :           v8::Utils::OpenHandle(*data->contexts_.Get(i));
     734             :       global_proxy_sizes->set(i,
     735          70 :                               i::Smi::FromInt(context->global_proxy()->Size()));
     736             :     }
     737         191 :     isolate->heap()->SetSerializedGlobalProxySizes(*global_proxy_sizes);
     738             :   }
     739             : 
     740             :   // We might rehash strings and re-sort descriptors. Clear the lookup cache.
     741         382 :   isolate->descriptor_lookup_cache()->Clear();
     742             : 
     743             :   // If we don't do this then we end up with a stray root pointing at the
     744             :   // context even after we have disposed of the context.
     745             :   isolate->heap()->CollectAllAvailableGarbage(
     746         191 :       i::GarbageCollectionReason::kSnapshotCreator);
     747             :   {
     748         191 :     i::HandleScope scope(isolate);
     749         191 :     isolate->heap()->CompactWeakArrayLists(internal::TENURED);
     750             :   }
     751             : 
     752         191 :   isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded();
     753             : 
     754         191 :   if (function_code_handling == FunctionCodeHandling::kClear) {
     755             :     // Clear out re-compilable data from all shared function infos. Any
     756             :     // JSFunctions using these SFIs will have their code pointers reset by the
     757             :     // partial serializer.
     758             :     //
     759             :     // We have to iterate the heap and collect handles to each clearable SFI,
     760             :     // before we disable allocation, since we have to allocate UncompiledDatas
     761             :     // to be able to recompile them.
     762             :     //
     763             :     // Compiled irregexp code is also flushed by collecting and clearing any
     764             :     // seen JSRegExp objects.
     765         161 :     i::HandleScope scope(isolate);
     766             :     std::vector<i::Handle<i::SharedFunctionInfo>> sfis_to_clear;
     767             : 
     768             :     {  // Heap allocation is disallowed within this scope.
     769         161 :       i::HeapIterator heap_iterator(isolate->heap());
     770     2770998 :       for (i::HeapObject current_obj = heap_iterator.next();
     771             :            !current_obj.is_null(); current_obj = heap_iterator.next()) {
     772     1385338 :         if (current_obj->IsSharedFunctionInfo()) {
     773             :           i::SharedFunctionInfo shared =
     774      150511 :               i::SharedFunctionInfo::cast(current_obj);
     775      150511 :           if (shared->CanDiscardCompiled()) {
     776          37 :             sfis_to_clear.emplace_back(shared, isolate);
     777             :           }
     778     1234827 :         } else if (current_obj->IsJSRegExp()) {
     779          10 :           i::JSRegExp regexp = i::JSRegExp::cast(current_obj);
     780          10 :           if (regexp->HasCompiledCode()) {
     781           5 :             regexp->DiscardCompiledCodeForSerialization();
     782             :           }
     783             :         }
     784         161 :       }
     785             :     }
     786             : 
     787             :     // Must happen after heap iteration since SFI::DiscardCompiled may allocate.
     788         359 :     for (i::Handle<i::SharedFunctionInfo> shared : sfis_to_clear) {
     789          37 :       i::SharedFunctionInfo::DiscardCompiled(isolate, shared);
     790             :     }
     791             :   }
     792             : 
     793             :   i::DisallowHeapAllocation no_gc_from_here_on;
     794             : 
     795         191 :   int num_contexts = num_additional_contexts + 1;
     796             :   std::vector<i::Context> contexts;
     797         191 :   contexts.reserve(num_contexts);
     798             :   {
     799         191 :     i::HandleScope scope(isolate);
     800             :     contexts.push_back(
     801         573 :         *v8::Utils::OpenHandle(*data->default_context_.Get(data->isolate_)));
     802             :     data->default_context_.Reset();
     803          35 :     for (int i = 0; i < num_additional_contexts; i++) {
     804             :       i::Handle<i::Context> context =
     805          70 :           v8::Utils::OpenHandle(*data->contexts_.Get(i));
     806          70 :       contexts.push_back(*context);
     807             :     }
     808         191 :     data->contexts_.Clear();
     809             :   }
     810             : 
     811             :   // Check that values referenced by global/eternal handles are accounted for.
     812         382 :   i::SerializedHandleChecker handle_checker(isolate, &contexts);
     813         191 :   CHECK(handle_checker.CheckGlobalAndEternalHandles());
     814             : 
     815         382 :   i::HeapIterator heap_iterator(isolate->heap());
     816     3156352 :   for (i::HeapObject current_obj = heap_iterator.next(); !current_obj.is_null();
     817             :        current_obj = heap_iterator.next()) {
     818     1577985 :     if (current_obj->IsJSFunction()) {
     819      186518 :       i::JSFunction fun = i::JSFunction::cast(current_obj);
     820             : 
     821             :       // Complete in-object slack tracking for all functions.
     822      186518 :       fun->CompleteInobjectSlackTrackingIfActive();
     823             : 
     824             :       // Also, clear out feedback vectors, or any optimized code.
     825      373036 :       if (!fun->raw_feedback_cell()->value()->IsUndefined()) {
     826             :         fun->raw_feedback_cell()->set_value(
     827         120 :             i::ReadOnlyRoots(isolate).undefined_value());
     828          60 :         fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy));
     829             :       }
     830             :       if (function_code_handling == FunctionCodeHandling::kClear) {
     831             :         DCHECK(fun->shared()->HasWasmExportedFunctionData() ||
     832             :                fun->shared()->HasBuiltinId() ||
     833             :                fun->shared()->IsApiFunction() ||
     834             :                fun->shared()->HasUncompiledDataWithoutPreparseData());
     835             :       }
     836             :     }
     837             :   }
     838             : 
     839         382 :   i::ReadOnlySerializer read_only_serializer(isolate);
     840         191 :   read_only_serializer.SerializeReadOnlyRoots();
     841             : 
     842         382 :   i::StartupSerializer startup_serializer(isolate, &read_only_serializer);
     843         191 :   startup_serializer.SerializeStrongReferences();
     844             : 
     845             :   // Serialize each context with a new partial serializer.
     846             :   std::vector<i::SnapshotData*> context_snapshots;
     847         191 :   context_snapshots.reserve(num_contexts);
     848             : 
     849             :   // TODO(6593): generalize rehashing, and remove this flag.
     850             :   bool can_be_rehashed = true;
     851             : 
     852         417 :   for (int i = 0; i < num_contexts; i++) {
     853         226 :     bool is_default_context = i == 0;
     854             :     i::PartialSerializer partial_serializer(
     855             :         isolate, &startup_serializer,
     856             :         is_default_context ? data->default_embedder_fields_serializer_
     857         452 :                            : data->embedder_fields_serializers_[i - 1]);
     858         452 :     partial_serializer.Serialize(&contexts[i], !is_default_context);
     859         226 :     can_be_rehashed = can_be_rehashed && partial_serializer.can_be_rehashed();
     860         452 :     context_snapshots.push_back(new i::SnapshotData(&partial_serializer));
     861         226 :   }
     862             : 
     863         191 :   startup_serializer.SerializeWeakReferencesAndDeferred();
     864         191 :   can_be_rehashed = can_be_rehashed && startup_serializer.can_be_rehashed();
     865             : 
     866         191 :   read_only_serializer.FinalizeSerialization();
     867         191 :   can_be_rehashed = can_be_rehashed && read_only_serializer.can_be_rehashed();
     868             : 
     869         191 :   i::SnapshotData read_only_snapshot(&read_only_serializer);
     870         191 :   i::SnapshotData startup_snapshot(&startup_serializer);
     871             :   StartupData result =
     872             :       i::Snapshot::CreateSnapshotBlob(&startup_snapshot, &read_only_snapshot,
     873         191 :                                       context_snapshots, can_be_rehashed);
     874             : 
     875             :   // Delete heap-allocated context snapshot instances.
     876         608 :   for (const auto context_snapshot : context_snapshots) {
     877         226 :     delete context_snapshot;
     878             :   }
     879         191 :   data->created_ = true;
     880             : 
     881             :   DCHECK(i::Snapshot::VerifyChecksum(&result));
     882         382 :   return result;
     883             : }
     884             : 
     885           5 : void V8::SetDcheckErrorHandler(DcheckErrorCallback that) {
     886           5 :   v8::base::SetDcheckFunction(that);
     887           5 : }
     888             : 
     889       88637 : void V8::SetFlagsFromString(const char* str, int length) {
     890      110087 :   i::FlagList::SetFlagsFromString(str, length);
     891      110087 :   i::FlagList::EnforceFlagImplications();
     892       88637 : }
     893             : 
     894             : 
     895       33716 : void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
     896       33716 :   i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
     897       33716 : }
     898             : 
     899             : RegisteredExtension* RegisteredExtension::first_extension_ = nullptr;
     900             : 
     901           0 : RegisteredExtension::RegisteredExtension(Extension* extension)
     902           0 :     : legacy_unowned_extension_(extension) {}
     903             : 
     904           0 : RegisteredExtension::RegisteredExtension(std::unique_ptr<Extension> extension)
     905      870630 :     : extension_(std::move(extension)) {}
     906             : 
     907             : // static
     908           0 : void RegisteredExtension::Register(Extension* extension) {
     909           0 :   RegisteredExtension* new_extension = new RegisteredExtension(extension);
     910           0 :   new_extension->next_ = first_extension_;
     911           0 :   first_extension_ = new_extension;
     912           0 : }
     913             : 
     914             : // static
     915      435315 : void RegisteredExtension::Register(std::unique_ptr<Extension> extension) {
     916             :   RegisteredExtension* new_extension =
     917      435315 :       new RegisteredExtension(std::move(extension));
     918      435315 :   new_extension->next_ = first_extension_;
     919      435315 :   first_extension_ = new_extension;
     920      435315 : }
     921             : 
     922             : // static
     923       58516 : void RegisteredExtension::UnregisterAll() {
     924      487069 :   RegisteredExtension* re = first_extension_;
     925      545585 :   while (re != nullptr) {
     926             :     RegisteredExtension* next = re->next();
     927      857106 :     delete re;
     928             :     re = next;
     929             :   }
     930       58516 :   first_extension_ = nullptr;
     931       58516 : }
     932             : 
     933             : namespace {
     934      857106 : class ExtensionResource : public String::ExternalOneByteStringResource {
     935             :  public:
     936             :   ExtensionResource() : data_(nullptr), length_(0) {}
     937             :   ExtensionResource(const char* data, size_t length)
     938      435315 :       : data_(data), length_(length) {}
     939       12633 :   const char* data() const override { return data_; }
     940        8891 :   size_t length() const override { return length_; }
     941        4446 :   void Dispose() override {}
     942             : 
     943             :  private:
     944             :   const char* data_;
     945             :   size_t length_;
     946             : };
     947             : }  // anonymous namespace
     948             : 
     949           0 : void RegisterExtension(Extension* that) { RegisteredExtension::Register(that); }
     950             : 
     951      435315 : void RegisterExtension(std::unique_ptr<Extension> extension) {
     952      870630 :   RegisteredExtension::Register(std::move(extension));
     953      435315 : }
     954             : 
     955      435315 : Extension::Extension(const char* name,
     956             :                      const char* source,
     957             :                      int dep_count,
     958             :                      const char** deps,
     959             :                      int source_length)
     960             :     : name_(name),
     961             :       source_length_(source_length >= 0 ?
     962             :                      source_length :
     963      435295 :                      (source ? static_cast<int>(strlen(source)) : 0)),
     964             :       dep_count_(dep_count),
     965             :       deps_(deps),
     966      870610 :       auto_enable_(false) {
     967      870630 :   source_ = new ExtensionResource(source, source_length_);
     968      435315 :   CHECK(source != nullptr || source_length_ == 0);
     969      435315 : }
     970             : 
     971       60425 : ResourceConstraints::ResourceConstraints()
     972             :     : max_semi_space_size_in_kb_(0),
     973             :       max_old_space_size_(0),
     974             :       stack_limit_(nullptr),
     975             :       code_range_size_(0),
     976       60425 :       max_zone_pool_size_(0) {}
     977             : 
     978       29546 : void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
     979             :                                             uint64_t virtual_memory_limit) {
     980             :   set_max_semi_space_size_in_kb(
     981             :       i::Heap::ComputeMaxSemiSpaceSize(physical_memory));
     982       29546 :   set_max_old_space_size(i::Heap::ComputeMaxOldGenerationSize(physical_memory));
     983             :   set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize);
     984             : 
     985       29546 :   if (virtual_memory_limit > 0 && i::kRequiresCodeRange) {
     986             :     // Reserve no more than 1/8 of the memory for the code range, but at most
     987             :     // kMaximalCodeRangeSize.
     988             :     set_code_range_size(
     989             :         i::Min(i::kMaximalCodeRangeSize / i::MB,
     990           0 :                static_cast<size_t>((virtual_memory_limit >> 3) / i::MB)));
     991             :   }
     992       29546 : }
     993             : 
     994      121496 : void SetResourceConstraints(i::Isolate* isolate,
     995      121496 :                             const ResourceConstraints& constraints) {
     996             :   size_t semi_space_size = constraints.max_semi_space_size_in_kb();
     997             :   size_t old_space_size = constraints.max_old_space_size();
     998             :   size_t code_range_size = constraints.code_range_size();
     999             :   size_t max_pool_size = constraints.max_zone_pool_size();
    1000       60748 :   if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) {
    1001             :     isolate->heap()->ConfigureHeap(semi_space_size, old_space_size,
    1002       29562 :                                    code_range_size);
    1003             :   }
    1004       60748 :   isolate->allocator()->ConfigureSegmentPool(max_pool_size);
    1005             : 
    1006       60748 :   if (constraints.stack_limit() != nullptr) {
    1007           0 :     uintptr_t limit = reinterpret_cast<uintptr_t>(constraints.stack_limit());
    1008           0 :     isolate->stack_guard()->SetStackLimit(limit);
    1009             :   }
    1010       60748 : }
    1011             : 
    1012     9147390 : i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) {
    1013     6098260 :   LOG_API(isolate, Persistent, New);
    1014     6098260 :   i::Handle<i::Object> result = isolate->global_handles()->Create(*obj);
    1015             : #ifdef VERIFY_HEAP
    1016             :   if (i::FLAG_verify_heap) {
    1017             :     i::Object(*obj)->ObjectVerify(isolate);
    1018             :   }
    1019             : #endif  // VERIFY_HEAP
    1020     3049130 :   return result.location();
    1021             : }
    1022             : 
    1023         210 : i::Address* V8::GlobalizeTracedReference(i::Isolate* isolate, i::Address* obj,
    1024             :                                          internal::Address* slot) {
    1025         140 :   LOG_API(isolate, TracedGlobal, New);
    1026             :   i::Handle<i::Object> result =
    1027         140 :       isolate->global_handles()->CreateTraced(*obj, slot);
    1028             : #ifdef VERIFY_HEAP
    1029             :   if (i::FLAG_verify_heap) {
    1030             :     i::Object(*obj)->ObjectVerify(isolate);
    1031             :   }
    1032             : #endif  // VERIFY_HEAP
    1033          70 :   return result.location();
    1034             : }
    1035             : 
    1036          10 : i::Address* V8::CopyGlobalReference(i::Address* from) {
    1037          10 :   i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(from);
    1038          10 :   return result.location();
    1039             : }
    1040             : 
    1041        5706 : void V8::MoveGlobalReference(internal::Address** from, internal::Address** to) {
    1042        5706 :   i::GlobalHandles::MoveGlobal(from, to);
    1043        5706 : }
    1044             : 
    1045          55 : void V8::MoveTracedGlobalReference(internal::Address** from,
    1046             :                                    internal::Address** to) {
    1047          55 :   i::GlobalHandles::MoveTracedGlobal(from, to);
    1048          55 : }
    1049             : 
    1050           0 : void V8::RegisterExternallyReferencedObject(i::Address* location,
    1051             :                                             i::Isolate* isolate) {
    1052           0 :   isolate->heap()->RegisterExternallyReferencedObject(location);
    1053           0 : }
    1054             : 
    1055      109905 : void V8::MakeWeak(i::Address* location, void* parameter,
    1056             :                   WeakCallbackInfo<void>::Callback weak_callback,
    1057             :                   WeakCallbackType type) {
    1058      109905 :   i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
    1059      109905 : }
    1060             : 
    1061          36 : void V8::MakeWeak(i::Address** location_addr) {
    1062          36 :   i::GlobalHandles::MakeWeak(location_addr);
    1063          36 : }
    1064             : 
    1065          35 : void* V8::ClearWeak(i::Address* location) {
    1066          35 :   return i::GlobalHandles::ClearWeakness(location);
    1067             : }
    1068             : 
    1069     2815434 : void V8::AnnotateStrongRetainer(i::Address* location, const char* label) {
    1070     2815434 :   i::GlobalHandles::AnnotateStrongRetainer(location, label);
    1071     2815434 : }
    1072             : 
    1073     3046658 : void V8::DisposeGlobal(i::Address* location) {
    1074     3046658 :   i::GlobalHandles::Destroy(location);
    1075     3046658 : }
    1076             : 
    1077          50 : void V8::DisposeTracedGlobal(internal::Address* location) {
    1078          50 :   i::GlobalHandles::DestroyTraced(location);
    1079          50 : }
    1080             : 
    1081          10 : void V8::SetFinalizationCallbackTraced(
    1082             :     internal::Address* location, void* parameter,
    1083             :     WeakCallbackInfo<void>::Callback callback) {
    1084             :   i::GlobalHandles::SetFinalizationCallbackForTraced(location, parameter,
    1085          10 :                                                      callback);
    1086          10 : }
    1087             : 
    1088       10245 : Value* V8::Eternalize(Isolate* v8_isolate, Value* value) {
    1089       20490 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    1090       10245 :   i::Object object = *Utils::OpenHandle(value);
    1091       10245 :   int index = -1;
    1092       10245 :   isolate->eternal_handles()->Create(isolate, object, &index);
    1093             :   return reinterpret_cast<Value*>(
    1094       20490 :       isolate->eternal_handles()->Get(index).location());
    1095             : }
    1096             : 
    1097             : 
    1098           0 : void V8::FromJustIsNothing() {
    1099             :   Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing.");
    1100           0 : }
    1101             : 
    1102             : 
    1103           0 : void V8::ToLocalEmpty() {
    1104             :   Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal.");
    1105           0 : }
    1106             : 
    1107           0 : void V8::InternalFieldOutOfBounds(int index) {
    1108             :   Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback,
    1109             :                   "WeakCallbackInfo::GetInternalField",
    1110           0 :                   "Internal field out of bounds.");
    1111           0 : }
    1112             : 
    1113             : 
    1114             : // --- H a n d l e s ---
    1115             : 
    1116             : 
    1117   436518007 : HandleScope::HandleScope(Isolate* isolate) {
    1118   436518128 :   Initialize(isolate);
    1119   436518015 : }
    1120             : 
    1121             : 
    1122   444189816 : void HandleScope::Initialize(Isolate* isolate) {
    1123       59137 :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1124             :   // We do not want to check the correct usage of the Locker class all over the
    1125             :   // place, so we do it only here: Without a HandleScope, an embedder can do
    1126             :   // almost nothing, so it is enough to check in this central place.
    1127             :   // We make an exception if the serializer is enabled, which means that the
    1128             :   // Isolate is exclusively used to create a snapshot.
    1129             :   Utils::ApiCheck(
    1130   444248938 :       !v8::Locker::IsActive() ||
    1131   444248963 :           internal_isolate->thread_manager()->IsLockedByCurrentThread() ||
    1132             :           internal_isolate->serializer_enabled(),
    1133             :       "HandleScope::HandleScope",
    1134             :       "Entering the V8 API without proper locking in place");
    1135             :   i::HandleScopeData* current = internal_isolate->handle_scope_data();
    1136   444189826 :   isolate_ = internal_isolate;
    1137   444189826 :   prev_next_ = current->next;
    1138   444189826 :   prev_limit_ = current->limit;
    1139   444189826 :   current->level++;
    1140   444189826 : }
    1141             : 
    1142             : 
    1143   444189649 : HandleScope::~HandleScope() {
    1144   444189770 :   i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
    1145   444189646 : }
    1146             : 
    1147           0 : void* HandleScope::operator new(size_t) { base::OS::Abort(); }
    1148           0 : void* HandleScope::operator new[](size_t) { base::OS::Abort(); }
    1149           0 : void HandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
    1150           0 : void HandleScope::operator delete[](void*, size_t) { base::OS::Abort(); }
    1151             : 
    1152        6036 : int HandleScope::NumberOfHandles(Isolate* isolate) {
    1153             :   return i::HandleScope::NumberOfHandles(
    1154        6036 :       reinterpret_cast<i::Isolate*>(isolate));
    1155             : }
    1156             : 
    1157    12898717 : i::Address* HandleScope::CreateHandle(i::Isolate* isolate, i::Address value) {
    1158    12898712 :   return i::HandleScope::CreateHandle(isolate, value);
    1159             : }
    1160             : 
    1161     7671704 : EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
    1162             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    1163             :   escape_slot_ =
    1164     7671704 :       CreateHandle(isolate, i::ReadOnlyRoots(isolate).the_hole_value()->ptr());
    1165     7671703 :   Initialize(v8_isolate);
    1166     7671704 : }
    1167             : 
    1168     6800587 : i::Address* EscapableHandleScope::Escape(i::Address* escape_value) {
    1169     6800587 :   i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
    1170    13601179 :   Utils::ApiCheck(i::Object(*escape_slot_)->IsTheHole(heap->isolate()),
    1171             :                   "EscapableHandleScope::Escape", "Escape value set twice");
    1172     6800592 :   if (escape_value == nullptr) {
    1173          10 :     *escape_slot_ = i::ReadOnlyRoots(heap).undefined_value()->ptr();
    1174           5 :     return nullptr;
    1175             :   }
    1176     6800587 :   *escape_slot_ = *escape_value;
    1177     6800587 :   return escape_slot_;
    1178             : }
    1179             : 
    1180           0 : void* EscapableHandleScope::operator new(size_t) { base::OS::Abort(); }
    1181           0 : void* EscapableHandleScope::operator new[](size_t) { base::OS::Abort(); }
    1182           0 : void EscapableHandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
    1183           0 : void EscapableHandleScope::operator delete[](void*, size_t) {
    1184           0 :   base::OS::Abort();
    1185             : }
    1186             : 
    1187      159245 : SealHandleScope::SealHandleScope(Isolate* isolate)
    1188      159245 :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
    1189             :   i::HandleScopeData* current = isolate_->handle_scope_data();
    1190      159245 :   prev_limit_ = current->limit;
    1191      159245 :   current->limit = current->next;
    1192      159245 :   prev_sealed_level_ = current->sealed_level;
    1193      159245 :   current->sealed_level = current->level;
    1194      159245 : }
    1195             : 
    1196             : 
    1197      159245 : SealHandleScope::~SealHandleScope() {
    1198      159245 :   i::HandleScopeData* current = isolate_->handle_scope_data();
    1199             :   DCHECK_EQ(current->next, current->limit);
    1200      159245 :   current->limit = prev_limit_;
    1201             :   DCHECK_EQ(current->level, current->sealed_level);
    1202      159245 :   current->sealed_level = prev_sealed_level_;
    1203      159245 : }
    1204             : 
    1205           0 : void* SealHandleScope::operator new(size_t) { base::OS::Abort(); }
    1206           0 : void* SealHandleScope::operator new[](size_t) { base::OS::Abort(); }
    1207           0 : void SealHandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
    1208           0 : void SealHandleScope::operator delete[](void*, size_t) { base::OS::Abort(); }
    1209             : 
    1210     4377334 : void Context::Enter() {
    1211             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    1212     4377333 :   i::Isolate* isolate = env->GetIsolate();
    1213             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1214             :   i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
    1215     4377335 :   impl->EnterContext(*env);
    1216             :   impl->SaveContext(isolate->context());
    1217             :   isolate->set_context(*env);
    1218     4377301 : }
    1219             : 
    1220     4360733 : void Context::Exit() {
    1221             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    1222     4360733 :   i::Isolate* isolate = env->GetIsolate();
    1223             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1224             :   i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
    1225     4360729 :   if (!Utils::ApiCheck(impl->LastEnteredContextWas(*env), "v8::Context::Exit()",
    1226             :                        "Cannot exit non-entered context")) {
    1227     4360729 :     return;
    1228             :   }
    1229             :   impl->LeaveContext();
    1230             :   isolate->set_context(impl->RestoreContext());
    1231             : }
    1232             : 
    1233           2 : Context::BackupIncumbentScope::BackupIncumbentScope(
    1234             :     Local<Context> backup_incumbent_context)
    1235           2 :     : backup_incumbent_context_(backup_incumbent_context) {
    1236             :   DCHECK(!backup_incumbent_context_.IsEmpty());
    1237             : 
    1238             :   i::Handle<i::Context> env = Utils::OpenHandle(*backup_incumbent_context_);
    1239           2 :   i::Isolate* isolate = env->GetIsolate();
    1240             : 
    1241             :   js_stack_comparable_address_ =
    1242           2 :       i::SimulatorStack::RegisterJSStackComparableAddress(isolate);
    1243             : 
    1244           2 :   prev_ = isolate->top_backup_incumbent_scope();
    1245             :   isolate->set_top_backup_incumbent_scope(this);
    1246           2 : }
    1247             : 
    1248           2 : Context::BackupIncumbentScope::~BackupIncumbentScope() {
    1249             :   i::Handle<i::Context> env = Utils::OpenHandle(*backup_incumbent_context_);
    1250             :   i::Isolate* isolate = env->GetIsolate();
    1251             : 
    1252             :   i::SimulatorStack::UnregisterJSStackComparableAddress(isolate);
    1253             : 
    1254           2 :   isolate->set_top_backup_incumbent_scope(prev_);
    1255           2 : }
    1256             : 
    1257             : STATIC_ASSERT(i::Internals::kEmbedderDataSlotSize == i::kEmbedderDataSlotSize);
    1258             : 
    1259      112159 : static i::Handle<i::EmbedderDataArray> EmbedderDataFor(Context* context,
    1260             :                                                        int index, bool can_grow,
    1261             :                                                        const char* location) {
    1262             :   i::Handle<i::Context> env = Utils::OpenHandle(context);
    1263             :   i::Isolate* isolate = env->GetIsolate();
    1264             :   bool ok =
    1265      224318 :       Utils::ApiCheck(env->IsNativeContext(),
    1266             :                       location,
    1267      224318 :                       "Not a native context") &&
    1268      112159 :       Utils::ApiCheck(index >= 0, location, "Negative index");
    1269      112159 :   if (!ok) return i::Handle<i::EmbedderDataArray>();
    1270             :   // TODO(ishell): remove cast once embedder_data slot has a proper type.
    1271             :   i::Handle<i::EmbedderDataArray> data(
    1272      224318 :       i::EmbedderDataArray::cast(env->embedder_data()), isolate);
    1273      224318 :   if (index < data->length()) return data;
    1274      119858 :   if (!Utils::ApiCheck(can_grow && index < i::EmbedderDataArray::kMaxLength,
    1275             :                        location, "Index too large")) {
    1276           0 :     return i::Handle<i::EmbedderDataArray>();
    1277             :   }
    1278       59929 :   data = i::EmbedderDataArray::EnsureCapacity(isolate, data, index);
    1279      119858 :   env->set_embedder_data(*data);
    1280       59929 :   return data;
    1281             : }
    1282             : 
    1283          75 : uint32_t Context::GetNumberOfEmbedderDataFields() {
    1284             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    1285         150 :   CHECK(context->IsNativeContext());
    1286             :   // TODO(ishell): remove cast once embedder_data slot has a proper type.
    1287             :   return static_cast<uint32_t>(
    1288         225 :       i::EmbedderDataArray::cast(context->embedder_data())->length());
    1289             : }
    1290             : 
    1291           0 : v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) {
    1292             :   const char* location = "v8::Context::GetEmbedderData()";
    1293             :   i::Handle<i::EmbedderDataArray> data =
    1294           0 :       EmbedderDataFor(this, index, false, location);
    1295           0 :   if (data.is_null()) return Local<Value>();
    1296             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1297             :   i::Handle<i::Object> result(i::EmbedderDataSlot(*data, index).load_tagged(),
    1298           0 :                               isolate);
    1299             :   return Utils::ToLocal(result);
    1300             : }
    1301             : 
    1302             : 
    1303          60 : void Context::SetEmbedderData(int index, v8::Local<Value> value) {
    1304             :   const char* location = "v8::Context::SetEmbedderData()";
    1305             :   i::Handle<i::EmbedderDataArray> data =
    1306          60 :       EmbedderDataFor(this, index, true, location);
    1307         120 :   if (data.is_null()) return;
    1308             :   i::Handle<i::Object> val = Utils::OpenHandle(*value);
    1309             :   i::EmbedderDataSlot::store_tagged(*data, index, *val);
    1310             :   DCHECK_EQ(*Utils::OpenHandle(*value),
    1311             :             *Utils::OpenHandle(*GetEmbedderData(index)));
    1312             : }
    1313             : 
    1314             : 
    1315           0 : void* Context::SlowGetAlignedPointerFromEmbedderData(int index) {
    1316             :   const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()";
    1317             :   i::Handle<i::EmbedderDataArray> data =
    1318           0 :       EmbedderDataFor(this, index, false, location);
    1319           0 :   if (data.is_null()) return nullptr;
    1320             :   void* result;
    1321           0 :   Utils::ApiCheck(i::EmbedderDataSlot(*data, index).ToAlignedPointer(&result),
    1322             :                   location, "Pointer is not aligned");
    1323           0 :   return result;
    1324             : }
    1325             : 
    1326             : 
    1327      112099 : void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
    1328             :   const char* location = "v8::Context::SetAlignedPointerInEmbedderData()";
    1329             :   i::Handle<i::EmbedderDataArray> data =
    1330      112099 :       EmbedderDataFor(this, index, true, location);
    1331      112099 :   bool ok = i::EmbedderDataSlot(*data, index).store_aligned_pointer(value);
    1332             :   Utils::ApiCheck(ok, location, "Pointer is not aligned");
    1333             :   DCHECK_EQ(value, GetAlignedPointerFromEmbedderData(index));
    1334      112099 : }
    1335             : 
    1336             : 
    1337             : // --- T e m p l a t e ---
    1338             : 
    1339             : 
    1340     4342009 : static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
    1341             :   that->set_number_of_properties(0);
    1342     8684018 :   that->set_tag(i::Smi::FromInt(type));
    1343     4342009 : }
    1344             : 
    1345             : 
    1346     1989506 : void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
    1347             :                    v8::PropertyAttribute attribute) {
    1348             :   auto templ = Utils::OpenHandle(this);
    1349             :   i::Isolate* isolate = templ->GetIsolate();
    1350             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1351             :   i::HandleScope scope(isolate);
    1352             :   auto value_obj = Utils::OpenHandle(*value);
    1353     3979012 :   CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo());
    1354     3979012 :   if (value_obj->IsObjectTemplateInfo()) {
    1355      211140 :     templ->set_serial_number(i::Smi::kZero);
    1356      422280 :     if (templ->IsFunctionTemplateInfo()) {
    1357           0 :       i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
    1358             :     }
    1359             :   }
    1360             :   i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
    1361             :                                  value_obj,
    1362     1989506 :                                  static_cast<i::PropertyAttributes>(attribute));
    1363     1989506 : }
    1364             : 
    1365           0 : void Template::SetPrivate(v8::Local<Private> name, v8::Local<Data> value,
    1366             :                           v8::PropertyAttribute attribute) {
    1367             :   Set(Utils::ToLocal(Utils::OpenHandle(reinterpret_cast<Name*>(*name))), value,
    1368           0 :       attribute);
    1369           0 : }
    1370             : 
    1371         109 : void Template::SetAccessorProperty(
    1372             :     v8::Local<v8::Name> name,
    1373             :     v8::Local<FunctionTemplate> getter,
    1374             :     v8::Local<FunctionTemplate> setter,
    1375             :     v8::PropertyAttribute attribute,
    1376             :     v8::AccessControl access_control) {
    1377             :   // TODO(verwaest): Remove |access_control|.
    1378             :   DCHECK_EQ(v8::DEFAULT, access_control);
    1379             :   auto templ = Utils::OpenHandle(this);
    1380             :   auto isolate = templ->GetIsolate();
    1381             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1382             :   DCHECK(!name.IsEmpty());
    1383             :   DCHECK(!getter.IsEmpty() || !setter.IsEmpty());
    1384             :   i::HandleScope scope(isolate);
    1385             :   i::ApiNatives::AddAccessorProperty(
    1386             :       isolate, templ, Utils::OpenHandle(*name),
    1387             :       Utils::OpenHandle(*getter, true), Utils::OpenHandle(*setter, true),
    1388         109 :       static_cast<i::PropertyAttributes>(attribute));
    1389         109 : }
    1390             : 
    1391             : 
    1392             : // --- F u n c t i o n   T e m p l a t e ---
    1393     3513496 : static void InitializeFunctionTemplate(
    1394             :     i::Handle<i::FunctionTemplateInfo> info) {
    1395     3513496 :   InitializeTemplate(info, Consts::FUNCTION_TEMPLATE);
    1396             :   info->set_flag(0);
    1397     3513496 : }
    1398             : 
    1399             : static Local<ObjectTemplate> ObjectTemplateNew(
    1400             :     i::Isolate* isolate, v8::Local<FunctionTemplate> constructor,
    1401             :     bool do_not_cache);
    1402             : 
    1403      156832 : Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
    1404             :   i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
    1405             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1406             :   i::Handle<i::Object> result(Utils::OpenHandle(this)->GetPrototypeTemplate(),
    1407      313664 :                               i_isolate);
    1408      313664 :   if (result->IsUndefined(i_isolate)) {
    1409             :     // Do not cache prototype objects.
    1410             :     result = Utils::OpenHandle(
    1411      104900 :         *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true));
    1412             :     i::FunctionTemplateInfo::SetPrototypeTemplate(
    1413       52450 :         i_isolate, Utils::OpenHandle(this), result);
    1414             :   }
    1415      156832 :   return ToApiHandle<ObjectTemplate>(result);
    1416             : }
    1417             : 
    1418           5 : void FunctionTemplate::SetPrototypeProviderTemplate(
    1419             :     Local<FunctionTemplate> prototype_provider) {
    1420             :   i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
    1421             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1422             :   i::Handle<i::Object> result = Utils::OpenHandle(*prototype_provider);
    1423             :   auto info = Utils::OpenHandle(this);
    1424          10 :   CHECK(info->GetPrototypeTemplate()->IsUndefined(i_isolate));
    1425          10 :   CHECK(info->GetParentTemplate()->IsUndefined(i_isolate));
    1426             :   i::FunctionTemplateInfo::SetPrototypeProviderTemplate(i_isolate, info,
    1427           5 :                                                         result);
    1428           5 : }
    1429             : 
    1430     5189512 : static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info,
    1431             :                                   const char* func) {
    1432    10379023 :   Utils::ApiCheck(!info->instantiated(), func,
    1433             :                   "FunctionTemplate already instantiated");
    1434     5189511 : }
    1435             : 
    1436             : 
    1437         239 : void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
    1438             :   auto info = Utils::OpenHandle(this);
    1439         239 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit");
    1440             :   i::Isolate* i_isolate = info->GetIsolate();
    1441             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1442         478 :   CHECK(info->GetPrototypeProviderTemplate()->IsUndefined(i_isolate));
    1443             :   i::FunctionTemplateInfo::SetParentTemplate(i_isolate, info,
    1444         239 :                                              Utils::OpenHandle(*value));
    1445         239 : }
    1446             : 
    1447     3513494 : static Local<FunctionTemplate> FunctionTemplateNew(
    1448             :     i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
    1449             :     v8::Local<Signature> signature, int length, bool do_not_cache,
    1450             :     v8::Local<Private> cached_property_name = v8::Local<Private>(),
    1451             :     SideEffectType side_effect_type = SideEffectType::kHasSideEffect) {
    1452             :   i::Handle<i::Struct> struct_obj =
    1453     3513494 :       isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE, i::TENURED);
    1454             :   i::Handle<i::FunctionTemplateInfo> obj =
    1455     3513496 :       i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
    1456     3513496 :   InitializeFunctionTemplate(obj);
    1457     7026992 :   obj->set_do_not_cache(do_not_cache);
    1458             :   int next_serial_number = i::FunctionTemplateInfo::kInvalidSerialNumber;
    1459     3513496 :   if (!do_not_cache) {
    1460     3508353 :     next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
    1461             :   }
    1462     7026992 :   obj->set_serial_number(i::Smi::FromInt(next_serial_number));
    1463     3513496 :   if (callback != nullptr) {
    1464     3401028 :     Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type);
    1465             :   }
    1466             :   obj->set_length(length);
    1467     3513496 :   obj->set_undetectable(false);
    1468     3513496 :   obj->set_needs_access_check(false);
    1469     3513496 :   obj->set_accept_any_receiver(true);
    1470     3513496 :   if (!signature.IsEmpty()) {
    1471      313254 :     obj->set_signature(*Utils::OpenHandle(*signature));
    1472             :   }
    1473             :   obj->set_cached_property_name(
    1474             :       cached_property_name.IsEmpty()
    1475             :           ? i::ReadOnlyRoots(isolate).the_hole_value()
    1476    10540458 :           : *Utils::OpenHandle(*cached_property_name));
    1477     3513496 :   return Utils::ToLocal(obj);
    1478             : }
    1479             : 
    1480     3508321 : Local<FunctionTemplate> FunctionTemplate::New(
    1481             :     Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
    1482             :     v8::Local<Signature> signature, int length, ConstructorBehavior behavior,
    1483             :     SideEffectType side_effect_type) {
    1484     3508321 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1485             :   // Changes to the environment cannot be captured in the snapshot. Expect no
    1486             :   // function templates when the isolate is created for serialization.
    1487     7016642 :   LOG_API(i_isolate, FunctionTemplate, New);
    1488             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1489             :   auto templ = FunctionTemplateNew(i_isolate, callback, data, signature, length,
    1490     3508321 :                                    false, Local<Private>(), side_effect_type);
    1491     3508323 :   if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
    1492     7016646 :   return templ;
    1493             : }
    1494             : 
    1495          10 : MaybeLocal<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate,
    1496             :                                                             size_t index) {
    1497             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1498          10 :   i::FixedArray serialized_objects = i_isolate->heap()->serialized_objects();
    1499          10 :   int int_index = static_cast<int>(index);
    1500          10 :   if (int_index < serialized_objects->length()) {
    1501           5 :     i::Object info = serialized_objects->get(int_index);
    1502           5 :     if (info->IsFunctionTemplateInfo()) {
    1503             :       return Utils::ToLocal(i::Handle<i::FunctionTemplateInfo>(
    1504           5 :           i::FunctionTemplateInfo::cast(info), i_isolate));
    1505             :     }
    1506             :   }
    1507           5 :   return Local<FunctionTemplate>();
    1508             : }
    1509             : 
    1510          30 : Local<FunctionTemplate> FunctionTemplate::NewWithCache(
    1511             :     Isolate* isolate, FunctionCallback callback, Local<Private> cache_property,
    1512             :     Local<Value> data, Local<Signature> signature, int length,
    1513             :     SideEffectType side_effect_type) {
    1514          30 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1515          60 :   LOG_API(i_isolate, FunctionTemplate, NewWithCache);
    1516             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1517             :   return FunctionTemplateNew(i_isolate, callback, data, signature, length,
    1518          60 :                              false, cache_property, side_effect_type);
    1519             : }
    1520             : 
    1521       52256 : Local<Signature> Signature::New(Isolate* isolate,
    1522             :                                 Local<FunctionTemplate> receiver) {
    1523       52256 :   return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
    1524             : }
    1525             : 
    1526             : 
    1527          23 : Local<AccessorSignature> AccessorSignature::New(
    1528             :     Isolate* isolate, Local<FunctionTemplate> receiver) {
    1529          23 :   return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
    1530             : }
    1531             : 
    1532             : #define SET_FIELD_WRAPPED(isolate, obj, setter, cdata)        \
    1533             :   do {                                                        \
    1534             :     i::Handle<i::Object> foreign = FromCData(isolate, cdata); \
    1535             :     (obj)->setter(*foreign);                                  \
    1536             :   } while (false)
    1537             : 
    1538     3401061 : void FunctionTemplate::SetCallHandler(FunctionCallback callback,
    1539             :                                       v8::Local<Value> data,
    1540             :                                       SideEffectType side_effect_type) {
    1541             :   auto info = Utils::OpenHandle(this);
    1542     3401061 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
    1543             :   i::Isolate* isolate = info->GetIsolate();
    1544             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1545             :   i::HandleScope scope(isolate);
    1546             :   i::Handle<i::CallHandlerInfo> obj = isolate->factory()->NewCallHandlerInfo(
    1547     3401061 :       side_effect_type == SideEffectType::kHasNoSideEffect);
    1548     6802119 :   SET_FIELD_WRAPPED(isolate, obj, set_callback, callback);
    1549     6802119 :   SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback());
    1550     3401062 :   if (data.IsEmpty()) {
    1551             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1552             :   }
    1553     3401062 :   obj->set_data(*Utils::OpenHandle(*data));
    1554     6802123 :   info->set_call_code(*obj);
    1555     3401062 : }
    1556             : 
    1557             : 
    1558             : namespace {
    1559             : 
    1560             : template <typename Getter, typename Setter>
    1561       61014 : i::Handle<i::AccessorInfo> MakeAccessorInfo(
    1562             :     i::Isolate* isolate, v8::Local<Name> name, Getter getter, Setter setter,
    1563             :     v8::Local<Value> data, v8::AccessControl settings,
    1564             :     v8::Local<AccessorSignature> signature, bool is_special_data_property,
    1565             :     bool replace_on_access) {
    1566       61014 :   i::Handle<i::AccessorInfo> obj = isolate->factory()->NewAccessorInfo();
    1567      122028 :   SET_FIELD_WRAPPED(isolate, obj, set_getter, getter);
    1568             :   DCHECK_IMPLIES(replace_on_access,
    1569             :                  is_special_data_property && setter == nullptr);
    1570       61014 :   if (is_special_data_property && setter == nullptr) {
    1571             :     setter = reinterpret_cast<Setter>(&i::Accessors::ReconfigureToDataProperty);
    1572             :   }
    1573      122028 :   SET_FIELD_WRAPPED(isolate, obj, set_setter, setter);
    1574       61014 :   i::Address redirected = obj->redirected_getter();
    1575       61014 :   if (redirected != i::kNullAddress) {
    1576      121984 :     SET_FIELD_WRAPPED(isolate, obj, set_js_getter, redirected);
    1577             :   }
    1578       61014 :   if (data.IsEmpty()) {
    1579             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1580             :   }
    1581       61014 :   obj->set_data(*Utils::OpenHandle(*data));
    1582      122028 :   obj->set_is_special_data_property(is_special_data_property);
    1583      122028 :   obj->set_replace_on_access(replace_on_access);
    1584             :   i::Handle<i::Name> accessor_name = Utils::OpenHandle(*name);
    1585       61014 :   if (!accessor_name->IsUniqueName()) {
    1586       52929 :     accessor_name = isolate->factory()->InternalizeString(
    1587             :         i::Handle<i::String>::cast(accessor_name));
    1588             :   }
    1589       61014 :   obj->set_name(*accessor_name);
    1590       61051 :   if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
    1591       61030 :   if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
    1592       61014 :   obj->set_initial_property_attributes(i::NONE);
    1593       61014 :   if (!signature.IsEmpty()) {
    1594          36 :     obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
    1595             :   }
    1596       61014 :   return obj;
    1597             : }
    1598             : 
    1599             : }  // namespace
    1600             : 
    1601       59711 : Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
    1602             :   i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true);
    1603      119422 :   if (!Utils::ApiCheck(!handle.is_null(),
    1604             :                        "v8::FunctionTemplate::InstanceTemplate()",
    1605             :                        "Reading from empty handle")) {
    1606           0 :     return Local<ObjectTemplate>();
    1607             :   }
    1608             :   i::Isolate* isolate = handle->GetIsolate();
    1609             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1610      119422 :   if (handle->GetInstanceTemplate()->IsUndefined(isolate)) {
    1611             :     Local<ObjectTemplate> templ =
    1612             :         ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle));
    1613             :     i::FunctionTemplateInfo::SetInstanceTemplate(isolate, handle,
    1614       53319 :                                                  Utils::OpenHandle(*templ));
    1615             :   }
    1616             :   i::Handle<i::ObjectTemplateInfo> result(
    1617      119422 :       i::ObjectTemplateInfo::cast(handle->GetInstanceTemplate()), isolate);
    1618             :   return Utils::ToLocal(result);
    1619             : }
    1620             : 
    1621             : 
    1622          12 : void FunctionTemplate::SetLength(int length) {
    1623             :   auto info = Utils::OpenHandle(this);
    1624          12 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetLength");
    1625             :   auto isolate = info->GetIsolate();
    1626             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1627             :   info->set_length(length);
    1628          12 : }
    1629             : 
    1630             : 
    1631       52433 : void FunctionTemplate::SetClassName(Local<String> name) {
    1632             :   auto info = Utils::OpenHandle(this);
    1633       52433 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetClassName");
    1634             :   auto isolate = info->GetIsolate();
    1635             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1636      104866 :   info->set_class_name(*Utils::OpenHandle(*name));
    1637       52433 : }
    1638             : 
    1639             : 
    1640           7 : void FunctionTemplate::SetAcceptAnyReceiver(bool value) {
    1641             :   auto info = Utils::OpenHandle(this);
    1642           7 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetAcceptAnyReceiver");
    1643             :   auto isolate = info->GetIsolate();
    1644             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1645          14 :   info->set_accept_any_receiver(value);
    1646           7 : }
    1647             : 
    1648             : 
    1649           0 : void FunctionTemplate::SetHiddenPrototype(bool value) {
    1650             :   auto info = Utils::OpenHandle(this);
    1651           0 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetHiddenPrototype");
    1652             :   auto isolate = info->GetIsolate();
    1653             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1654           0 :   info->set_hidden_prototype(value);
    1655           0 : }
    1656             : 
    1657             : 
    1658     1729342 : void FunctionTemplate::ReadOnlyPrototype() {
    1659             :   auto info = Utils::OpenHandle(this);
    1660     1729342 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::ReadOnlyPrototype");
    1661             :   auto isolate = info->GetIsolate();
    1662             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1663     1729342 :   info->set_read_only_prototype(true);
    1664     1729342 : }
    1665             : 
    1666             : 
    1667        4816 : void FunctionTemplate::RemovePrototype() {
    1668             :   auto info = Utils::OpenHandle(this);
    1669        4816 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::RemovePrototype");
    1670             :   auto isolate = info->GetIsolate();
    1671             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1672        4816 :   info->set_remove_prototype(true);
    1673        4816 : }
    1674             : 
    1675             : 
    1676             : // --- O b j e c t T e m p l a t e ---
    1677             : 
    1678             : 
    1679      667526 : Local<ObjectTemplate> ObjectTemplate::New(
    1680             :     Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
    1681      667526 :   return New(reinterpret_cast<i::Isolate*>(isolate), constructor);
    1682             : }
    1683             : 
    1684             : 
    1685      828513 : static Local<ObjectTemplate> ObjectTemplateNew(
    1686      828513 :     i::Isolate* isolate, v8::Local<FunctionTemplate> constructor,
    1687             :     bool do_not_cache) {
    1688     1657026 :   LOG_API(isolate, ObjectTemplate, New);
    1689             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1690             :   i::Handle<i::Struct> struct_obj =
    1691      828513 :       isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE, i::TENURED);
    1692             :   i::Handle<i::ObjectTemplateInfo> obj =
    1693      828513 :       i::Handle<i::ObjectTemplateInfo>::cast(struct_obj);
    1694      828513 :   InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
    1695             :   int next_serial_number = 0;
    1696      828513 :   if (!do_not_cache) {
    1697      776063 :     next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
    1698             :   }
    1699     1657026 :   obj->set_serial_number(i::Smi::FromInt(next_serial_number));
    1700      828513 :   if (!constructor.IsEmpty())
    1701      107352 :     obj->set_constructor(*Utils::OpenHandle(*constructor));
    1702      828513 :   obj->set_data(i::Smi::kZero);
    1703      828513 :   return Utils::ToLocal(obj);
    1704             : }
    1705             : 
    1706           0 : Local<ObjectTemplate> ObjectTemplate::New(
    1707             :     i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
    1708      776063 :   return ObjectTemplateNew(isolate, constructor, false);
    1709             : }
    1710             : 
    1711          10 : MaybeLocal<ObjectTemplate> ObjectTemplate::FromSnapshot(Isolate* isolate,
    1712             :                                                         size_t index) {
    1713             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1714          10 :   i::FixedArray serialized_objects = i_isolate->heap()->serialized_objects();
    1715          10 :   int int_index = static_cast<int>(index);
    1716          10 :   if (int_index < serialized_objects->length()) {
    1717           5 :     i::Object info = serialized_objects->get(int_index);
    1718           5 :     if (info->IsObjectTemplateInfo()) {
    1719             :       return Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>(
    1720           5 :           i::ObjectTemplateInfo::cast(info), i_isolate));
    1721             :     }
    1722             :   }
    1723           5 :   return Local<ObjectTemplate>();
    1724             : }
    1725             : 
    1726             : // Ensure that the object template has a constructor.  If no
    1727             : // constructor is available we create one.
    1728      164622 : static i::Handle<i::FunctionTemplateInfo> EnsureConstructor(
    1729             :     i::Isolate* isolate,
    1730             :     ObjectTemplate* object_template) {
    1731      164622 :   i::Object obj = Utils::OpenHandle(object_template)->constructor();
    1732      164622 :   if (!obj->IsUndefined(isolate)) {
    1733             :     i::FunctionTemplateInfo info = i::FunctionTemplateInfo::cast(obj);
    1734       53638 :     return i::Handle<i::FunctionTemplateInfo>(info, isolate);
    1735             :   }
    1736             :   Local<FunctionTemplate> templ =
    1737      110984 :       FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
    1738             :   i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
    1739             :   i::FunctionTemplateInfo::SetInstanceTemplate(
    1740      110984 :       isolate, constructor, Utils::OpenHandle(object_template));
    1741      221968 :   Utils::OpenHandle(object_template)->set_constructor(*constructor);
    1742      110984 :   return constructor;
    1743             : }
    1744             : 
    1745             : template <typename Getter, typename Setter, typename Data, typename Template>
    1746       53104 : static void TemplateSetAccessor(
    1747             :     Template* template_obj, v8::Local<Name> name, Getter getter, Setter setter,
    1748             :     Data data, AccessControl settings, PropertyAttribute attribute,
    1749             :     v8::Local<AccessorSignature> signature, bool is_special_data_property,
    1750             :     bool replace_on_access, SideEffectType getter_side_effect_type,
    1751             :     SideEffectType setter_side_effect_type) {
    1752             :   auto info = Utils::OpenHandle(template_obj);
    1753             :   auto isolate = info->GetIsolate();
    1754             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1755             :   i::HandleScope scope(isolate);
    1756             :   i::Handle<i::AccessorInfo> accessor_info =
    1757             :       MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature,
    1758       53104 :                        is_special_data_property, replace_on_access);
    1759       53104 :   accessor_info->set_initial_property_attributes(
    1760      106208 :       static_cast<i::PropertyAttributes>(attribute));
    1761       53104 :   accessor_info->set_getter_side_effect_type(getter_side_effect_type);
    1762       53104 :   accessor_info->set_setter_side_effect_type(setter_side_effect_type);
    1763       53104 :   i::ApiNatives::AddNativeDataProperty(isolate, info, accessor_info);
    1764       53104 : }
    1765             : 
    1766         179 : void Template::SetNativeDataProperty(
    1767             :     v8::Local<String> name, AccessorGetterCallback getter,
    1768             :     AccessorSetterCallback setter, v8::Local<Value> data,
    1769             :     PropertyAttribute attribute, v8::Local<AccessorSignature> signature,
    1770             :     AccessControl settings, SideEffectType getter_side_effect_type,
    1771             :     SideEffectType setter_side_effect_type) {
    1772             :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1773             :                       signature, true, false, getter_side_effect_type,
    1774         179 :                       setter_side_effect_type);
    1775         179 : }
    1776             : 
    1777          10 : void Template::SetNativeDataProperty(
    1778             :     v8::Local<Name> name, AccessorNameGetterCallback getter,
    1779             :     AccessorNameSetterCallback setter, v8::Local<Value> data,
    1780             :     PropertyAttribute attribute, v8::Local<AccessorSignature> signature,
    1781             :     AccessControl settings, SideEffectType getter_side_effect_type,
    1782             :     SideEffectType setter_side_effect_type) {
    1783             :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1784             :                       signature, true, false, getter_side_effect_type,
    1785          10 :                       setter_side_effect_type);
    1786          10 : }
    1787             : 
    1788          10 : void Template::SetLazyDataProperty(v8::Local<Name> name,
    1789             :                                    AccessorNameGetterCallback getter,
    1790             :                                    v8::Local<Value> data,
    1791             :                                    PropertyAttribute attribute,
    1792             :                                    SideEffectType getter_side_effect_type,
    1793             :                                    SideEffectType setter_side_effect_type) {
    1794             :   TemplateSetAccessor(this, name, getter,
    1795             :                       static_cast<AccessorNameSetterCallback>(nullptr), data,
    1796             :                       DEFAULT, attribute, Local<AccessorSignature>(), true,
    1797          10 :                       true, getter_side_effect_type, setter_side_effect_type);
    1798          10 : }
    1799             : 
    1800          55 : void Template::SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
    1801             :                                         PropertyAttribute attribute) {
    1802             :   auto templ = Utils::OpenHandle(this);
    1803             :   i::Isolate* isolate = templ->GetIsolate();
    1804             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1805             :   i::HandleScope scope(isolate);
    1806             :   i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
    1807             :                                  intrinsic,
    1808          55 :                                  static_cast<i::PropertyAttributes>(attribute));
    1809          55 : }
    1810             : 
    1811       52811 : void ObjectTemplate::SetAccessor(v8::Local<String> name,
    1812             :                                  AccessorGetterCallback getter,
    1813             :                                  AccessorSetterCallback setter,
    1814             :                                  v8::Local<Value> data, AccessControl settings,
    1815             :                                  PropertyAttribute attribute,
    1816             :                                  v8::Local<AccessorSignature> signature,
    1817             :                                  SideEffectType getter_side_effect_type,
    1818             :                                  SideEffectType setter_side_effect_type) {
    1819             :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1820             :                       signature, i::FLAG_disable_old_api_accessors, false,
    1821      105622 :                       getter_side_effect_type, setter_side_effect_type);
    1822       52811 : }
    1823             : 
    1824          94 : void ObjectTemplate::SetAccessor(v8::Local<Name> name,
    1825             :                                  AccessorNameGetterCallback getter,
    1826             :                                  AccessorNameSetterCallback setter,
    1827             :                                  v8::Local<Value> data, AccessControl settings,
    1828             :                                  PropertyAttribute attribute,
    1829             :                                  v8::Local<AccessorSignature> signature,
    1830             :                                  SideEffectType getter_side_effect_type,
    1831             :                                  SideEffectType setter_side_effect_type) {
    1832             :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1833             :                       signature, i::FLAG_disable_old_api_accessors, false,
    1834          94 :                       getter_side_effect_type, setter_side_effect_type);
    1835          94 : }
    1836             : 
    1837             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1838             :           typename Deleter, typename Enumerator, typename Definer>
    1839        1153 : static i::Handle<i::InterceptorInfo> CreateInterceptorInfo(
    1840             :     i::Isolate* isolate, Getter getter, Setter setter, Query query,
    1841             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1842             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1843             :   auto obj = i::Handle<i::InterceptorInfo>::cast(
    1844        1153 :       isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE, i::TENURED));
    1845             :   obj->set_flags(0);
    1846             : 
    1847        2118 :   if (getter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_getter, getter);
    1848        1580 :   if (setter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_setter, setter);
    1849        1353 :   if (query != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_query, query);
    1850        1153 :   if (descriptor != nullptr)
    1851          60 :     SET_FIELD_WRAPPED(isolate, obj, set_descriptor, descriptor);
    1852        1237 :   if (remover != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_deleter, remover);
    1853        1153 :   if (enumerator != nullptr)
    1854         322 :     SET_FIELD_WRAPPED(isolate, obj, set_enumerator, enumerator);
    1855        1243 :   if (definer != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_definer, definer);
    1856        1153 :   obj->set_can_intercept_symbols(
    1857             :       !(static_cast<int>(flags) &
    1858        3459 :         static_cast<int>(PropertyHandlerFlags::kOnlyInterceptStrings)));
    1859        1153 :   obj->set_all_can_read(static_cast<int>(flags) &
    1860        3459 :                         static_cast<int>(PropertyHandlerFlags::kAllCanRead));
    1861        1153 :   obj->set_non_masking(static_cast<int>(flags) &
    1862        3459 :                        static_cast<int>(PropertyHandlerFlags::kNonMasking));
    1863        1153 :   obj->set_has_no_side_effect(
    1864             :       static_cast<int>(flags) &
    1865        3459 :       static_cast<int>(PropertyHandlerFlags::kHasNoSideEffect));
    1866             : 
    1867        1153 :   if (data.IsEmpty()) {
    1868             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1869             :   }
    1870        1153 :   obj->set_data(*Utils::OpenHandle(*data));
    1871        1153 :   return obj;
    1872             : }
    1873             : 
    1874             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1875             :           typename Deleter, typename Enumerator, typename Definer>
    1876         941 : static i::Handle<i::InterceptorInfo> CreateNamedInterceptorInfo(
    1877             :     i::Isolate* isolate, Getter getter, Setter setter, Query query,
    1878             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1879             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1880             :   auto interceptor =
    1881             :       CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover,
    1882         941 :                             enumerator, definer, data, flags);
    1883         941 :   interceptor->set_is_named(true);
    1884         941 :   return interceptor;
    1885             : }
    1886             : 
    1887             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1888             :           typename Deleter, typename Enumerator, typename Definer>
    1889         212 : static i::Handle<i::InterceptorInfo> CreateIndexedInterceptorInfo(
    1890             :     i::Isolate* isolate, Getter getter, Setter setter, Query query,
    1891             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1892             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1893             :   auto interceptor =
    1894             :       CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover,
    1895         212 :                             enumerator, definer, data, flags);
    1896         212 :   interceptor->set_is_named(false);
    1897         212 :   return interceptor;
    1898             : }
    1899             : 
    1900             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1901             :           typename Deleter, typename Enumerator, typename Definer>
    1902         910 : static void ObjectTemplateSetNamedPropertyHandler(
    1903             :     ObjectTemplate* templ, Getter getter, Setter setter, Query query,
    1904             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1905             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1906             :   i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate();
    1907             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1908             :   i::HandleScope scope(isolate);
    1909         910 :   auto cons = EnsureConstructor(isolate, templ);
    1910         910 :   EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler");
    1911             :   auto obj =
    1912             :       CreateNamedInterceptorInfo(isolate, getter, setter, query, descriptor,
    1913         910 :                                  remover, enumerator, definer, data, flags);
    1914         910 :   i::FunctionTemplateInfo::SetNamedPropertyHandler(isolate, cons, obj);
    1915         910 : }
    1916             : 
    1917         910 : void ObjectTemplate::SetHandler(
    1918             :     const NamedPropertyHandlerConfiguration& config) {
    1919             :   ObjectTemplateSetNamedPropertyHandler(
    1920             :       this, config.getter, config.setter, config.query, config.descriptor,
    1921             :       config.deleter, config.enumerator, config.definer, config.data,
    1922         910 :       config.flags);
    1923         910 : }
    1924             : 
    1925             : 
    1926         149 : void ObjectTemplate::MarkAsUndetectable() {
    1927             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1928             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1929             :   i::HandleScope scope(isolate);
    1930         149 :   auto cons = EnsureConstructor(isolate, this);
    1931         149 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::MarkAsUndetectable");
    1932         149 :   cons->set_undetectable(true);
    1933         149 : }
    1934             : 
    1935             : 
    1936         134 : void ObjectTemplate::SetAccessCheckCallback(AccessCheckCallback callback,
    1937             :                                             Local<Value> data) {
    1938             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1939             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1940             :   i::HandleScope scope(isolate);
    1941         134 :   auto cons = EnsureConstructor(isolate, this);
    1942         134 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetAccessCheckCallback");
    1943             : 
    1944             :   i::Handle<i::Struct> struct_info =
    1945         134 :       isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE, i::TENURED);
    1946             :   i::Handle<i::AccessCheckInfo> info =
    1947         134 :       i::Handle<i::AccessCheckInfo>::cast(struct_info);
    1948             : 
    1949         268 :   SET_FIELD_WRAPPED(isolate, info, set_callback, callback);
    1950         134 :   info->set_named_interceptor(i::Object());
    1951         134 :   info->set_indexed_interceptor(i::Object());
    1952             : 
    1953         134 :   if (data.IsEmpty()) {
    1954             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1955             :   }
    1956         134 :   info->set_data(*Utils::OpenHandle(*data));
    1957             : 
    1958         134 :   i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info);
    1959         134 :   cons->set_needs_access_check(true);
    1960         134 : }
    1961             : 
    1962          31 : void ObjectTemplate::SetAccessCheckCallbackAndHandler(
    1963             :     AccessCheckCallback callback,
    1964             :     const NamedPropertyHandlerConfiguration& named_handler,
    1965             :     const IndexedPropertyHandlerConfiguration& indexed_handler,
    1966             :     Local<Value> data) {
    1967             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1968             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1969             :   i::HandleScope scope(isolate);
    1970          31 :   auto cons = EnsureConstructor(isolate, this);
    1971             :   EnsureNotInstantiated(
    1972          31 :       cons, "v8::ObjectTemplate::SetAccessCheckCallbackWithHandler");
    1973             : 
    1974             :   i::Handle<i::Struct> struct_info =
    1975          31 :       isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE, i::TENURED);
    1976             :   i::Handle<i::AccessCheckInfo> info =
    1977          31 :       i::Handle<i::AccessCheckInfo>::cast(struct_info);
    1978             : 
    1979          62 :   SET_FIELD_WRAPPED(isolate, info, set_callback, callback);
    1980             :   auto named_interceptor = CreateNamedInterceptorInfo(
    1981             :       isolate, named_handler.getter, named_handler.setter, named_handler.query,
    1982             :       named_handler.descriptor, named_handler.deleter, named_handler.enumerator,
    1983          31 :       named_handler.definer, named_handler.data, named_handler.flags);
    1984          62 :   info->set_named_interceptor(*named_interceptor);
    1985             :   auto indexed_interceptor = CreateIndexedInterceptorInfo(
    1986             :       isolate, indexed_handler.getter, indexed_handler.setter,
    1987             :       indexed_handler.query, indexed_handler.descriptor,
    1988             :       indexed_handler.deleter, indexed_handler.enumerator,
    1989          31 :       indexed_handler.definer, indexed_handler.data, indexed_handler.flags);
    1990          62 :   info->set_indexed_interceptor(*indexed_interceptor);
    1991             : 
    1992          31 :   if (data.IsEmpty()) {
    1993             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1994             :   }
    1995          31 :   info->set_data(*Utils::OpenHandle(*data));
    1996             : 
    1997          31 :   i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info);
    1998          31 :   cons->set_needs_access_check(true);
    1999          31 : }
    2000             : 
    2001         181 : void ObjectTemplate::SetHandler(
    2002             :     const IndexedPropertyHandlerConfiguration& config) {
    2003             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2004             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2005             :   i::HandleScope scope(isolate);
    2006         181 :   auto cons = EnsureConstructor(isolate, this);
    2007         181 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler");
    2008             :   auto obj = CreateIndexedInterceptorInfo(
    2009             :       isolate, config.getter, config.setter, config.query, config.descriptor,
    2010             :       config.deleter, config.enumerator, config.definer, config.data,
    2011         181 :       config.flags);
    2012         181 :   i::FunctionTemplateInfo::SetIndexedPropertyHandler(isolate, cons, obj);
    2013         181 : }
    2014             : 
    2015         197 : void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback,
    2016             :                                               Local<Value> data) {
    2017             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2018             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2019             :   i::HandleScope scope(isolate);
    2020         197 :   auto cons = EnsureConstructor(isolate, this);
    2021         197 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetCallAsFunctionHandler");
    2022         197 :   i::Handle<i::CallHandlerInfo> obj = isolate->factory()->NewCallHandlerInfo();
    2023         394 :   SET_FIELD_WRAPPED(isolate, obj, set_callback, callback);
    2024         394 :   SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback());
    2025         197 :   if (data.IsEmpty()) {
    2026             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    2027             :   }
    2028         197 :   obj->set_data(*Utils::OpenHandle(*data));
    2029         197 :   i::FunctionTemplateInfo::SetInstanceCallHandler(isolate, cons, obj);
    2030         197 : }
    2031             : 
    2032      110409 : int ObjectTemplate::InternalFieldCount() {
    2033      110409 :   return Utils::OpenHandle(this)->embedder_field_count();
    2034             : }
    2035             : 
    2036      107755 : void ObjectTemplate::SetInternalFieldCount(int value) {
    2037             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2038             :   if (!Utils::ApiCheck(i::Smi::IsValid(value),
    2039             :                        "v8::ObjectTemplate::SetInternalFieldCount()",
    2040             :                        "Invalid embedder field count")) {
    2041      107755 :     return;
    2042             :   }
    2043             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2044      107755 :   if (value > 0) {
    2045             :     // The embedder field count is set by the constructor function's
    2046             :     // construct code, so we ensure that there is a constructor
    2047             :     // function to do the setting.
    2048       52558 :     EnsureConstructor(isolate, this);
    2049             :   }
    2050      107755 :   Utils::OpenHandle(this)->set_embedder_field_count(value);
    2051             : }
    2052             : 
    2053           0 : bool ObjectTemplate::IsImmutableProto() {
    2054           0 :   return Utils::OpenHandle(this)->immutable_proto();
    2055             : }
    2056             : 
    2057          18 : void ObjectTemplate::SetImmutableProto() {
    2058             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2059             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2060          18 :   Utils::OpenHandle(this)->set_immutable_proto(true);
    2061          18 : }
    2062             : 
    2063             : // --- S c r i p t s ---
    2064             : 
    2065             : 
    2066             : // Internally, UnboundScript is a SharedFunctionInfo, and Script is a
    2067             : // JSFunction.
    2068             : 
    2069         712 : ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
    2070             :                                        BufferPolicy buffer_policy_)
    2071             :     : data(data_),
    2072             :       length(length_),
    2073             :       rejected(false),
    2074         712 :       buffer_policy(buffer_policy_) {}
    2075             : 
    2076             : 
    2077         712 : ScriptCompiler::CachedData::~CachedData() {
    2078         712 :   if (buffer_policy == BufferOwned) {
    2079         702 :     delete[] data;
    2080             :   }
    2081         712 : }
    2082             : 
    2083           0 : bool ScriptCompiler::ExternalSourceStream::SetBookmark() { return false; }
    2084             : 
    2085           0 : void ScriptCompiler::ExternalSourceStream::ResetToBookmark() { UNREACHABLE(); }
    2086             : 
    2087       13104 : ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream,
    2088             :                                                Encoding encoding)
    2089       26208 :     : impl_(new i::ScriptStreamingData(stream, encoding)) {}
    2090             : 
    2091             : ScriptCompiler::StreamedSource::~StreamedSource() = default;
    2092             : 
    2093      268225 : Local<Script> UnboundScript::BindToCurrentContext() {
    2094             :   auto function_info =
    2095      268225 :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2096             :   i::Isolate* isolate = function_info->GetIsolate();
    2097             :   i::Handle<i::JSFunction> function =
    2098             :       isolate->factory()->NewFunctionFromSharedFunctionInfo(
    2099      536452 :           function_info, isolate->native_context());
    2100      268225 :   return ToApiHandle<Script>(function);
    2101             : }
    2102             : 
    2103         253 : int UnboundScript::GetId() {
    2104             :   auto function_info =
    2105         253 :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2106         253 :   i::Isolate* isolate = function_info->GetIsolate();
    2107         506 :   LOG_API(isolate, UnboundScript, GetId);
    2108             :   i::HandleScope scope(isolate);
    2109             :   i::Handle<i::Script> script(i::Script::cast(function_info->script()),
    2110         506 :                               isolate);
    2111         253 :   return script->id();
    2112             : }
    2113             : 
    2114             : 
    2115           5 : int UnboundScript::GetLineNumber(int code_pos) {
    2116             :   i::Handle<i::SharedFunctionInfo> obj =
    2117           5 :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2118           5 :   i::Isolate* isolate = obj->GetIsolate();
    2119          10 :   LOG_API(isolate, UnboundScript, GetLineNumber);
    2120          10 :   if (obj->script()->IsScript()) {
    2121          10 :     i::Handle<i::Script> script(i::Script::cast(obj->script()), isolate);
    2122           5 :     return i::Script::GetLineNumber(script, code_pos);
    2123             :   } else {
    2124             :     return -1;
    2125             :   }
    2126             : }
    2127             : 
    2128             : 
    2129           5 : Local<Value> UnboundScript::GetScriptName() {
    2130             :   i::Handle<i::SharedFunctionInfo> obj =
    2131           5 :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2132           5 :   i::Isolate* isolate = obj->GetIsolate();
    2133          10 :   LOG_API(isolate, UnboundScript, GetName);
    2134          10 :   if (obj->script()->IsScript()) {
    2135          10 :     i::Object name = i::Script::cast(obj->script())->name();
    2136             :     return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
    2137             :   } else {
    2138           0 :     return Local<String>();
    2139             :   }
    2140             : }
    2141             : 
    2142             : 
    2143         155 : Local<Value> UnboundScript::GetSourceURL() {
    2144             :   i::Handle<i::SharedFunctionInfo> obj =
    2145         155 :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2146         155 :   i::Isolate* isolate = obj->GetIsolate();
    2147         310 :   LOG_API(isolate, UnboundScript, GetSourceURL);
    2148         310 :   if (obj->script()->IsScript()) {
    2149         310 :     i::Object url = i::Script::cast(obj->script())->source_url();
    2150             :     return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
    2151             :   } else {
    2152           0 :     return Local<String>();
    2153             :   }
    2154             : }
    2155             : 
    2156             : 
    2157         155 : Local<Value> UnboundScript::GetSourceMappingURL() {
    2158             :   i::Handle<i::SharedFunctionInfo> obj =
    2159         155 :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2160         155 :   i::Isolate* isolate = obj->GetIsolate();
    2161         310 :   LOG_API(isolate, UnboundScript, GetSourceMappingURL);
    2162         310 :   if (obj->script()->IsScript()) {
    2163         310 :     i::Object url = i::Script::cast(obj->script())->source_mapping_url();
    2164             :     return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
    2165             :   } else {
    2166           0 :     return Local<String>();
    2167             :   }
    2168             : }
    2169             : 
    2170             : 
    2171      266498 : MaybeLocal<Value> Script::Run(Local<Context> context) {
    2172      532996 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    2173      532996 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    2174     1065994 :   ENTER_V8(isolate, context, Script, Run, MaybeLocal<Value>(),
    2175             :            InternalEscapableScope);
    2176      266498 :   i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true);
    2177      266499 :   i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
    2178             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    2179      266498 :   auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this));
    2180             : 
    2181      266498 :   i::Handle<i::Object> receiver = isolate->global_proxy();
    2182             :   Local<Value> result;
    2183             :   has_pending_exception = !ToLocal<Value>(
    2184      532998 :       i::Execution::Call(isolate, fun, receiver, 0, nullptr), &result);
    2185             : 
    2186      266499 :   RETURN_ON_FAILED_EXECUTION(Value);
    2187      524450 :   RETURN_ESCAPED(result);
    2188             : }
    2189             : 
    2190             : 
    2191         410 : Local<Value> ScriptOrModule::GetResourceName() {
    2192             :   i::Handle<i::Script> obj = Utils::OpenHandle(this);
    2193             :   i::Isolate* isolate = obj->GetIsolate();
    2194             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2195             :   i::Handle<i::Object> val(obj->name(), isolate);
    2196         410 :   return ToApiHandle<Value>(val);
    2197             : }
    2198             : 
    2199           5 : Local<PrimitiveArray> ScriptOrModule::GetHostDefinedOptions() {
    2200             :   i::Handle<i::Script> obj = Utils::OpenHandle(this);
    2201             :   i::Isolate* isolate = obj->GetIsolate();
    2202             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2203          10 :   i::Handle<i::FixedArray> val(obj->host_defined_options(), isolate);
    2204           5 :   return ToApiHandle<PrimitiveArray>(val);
    2205             : }
    2206             : 
    2207         830 : Local<UnboundScript> Script::GetUnboundScript() {
    2208             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    2209         830 :   i::SharedFunctionInfo sfi = i::JSFunction::cast(*obj)->shared();
    2210             :   i::Isolate* isolate = sfi->GetIsolate();
    2211         830 :   return ToApiHandle<UnboundScript>(i::handle(sfi, isolate));
    2212             : }
    2213             : 
    2214             : // static
    2215          11 : Local<PrimitiveArray> PrimitiveArray::New(Isolate* v8_isolate, int length) {
    2216             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2217             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2218             :   Utils::ApiCheck(length >= 0, "v8::PrimitiveArray::New",
    2219             :                   "length must be equal or greater than zero");
    2220          11 :   i::Handle<i::FixedArray> array = isolate->factory()->NewFixedArray(length);
    2221          11 :   return ToApiHandle<PrimitiveArray>(array);
    2222             : }
    2223             : 
    2224           5 : int PrimitiveArray::Length() const {
    2225             :   i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
    2226           5 :   return array->length();
    2227             : }
    2228             : 
    2229          31 : void PrimitiveArray::Set(Isolate* v8_isolate, int index,
    2230             :                          Local<Primitive> item) {
    2231             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2232             :   i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
    2233             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2234          62 :   Utils::ApiCheck(index >= 0 && index < array->length(),
    2235             :                   "v8::PrimitiveArray::Set",
    2236             :                   "index must be greater than or equal to 0 and less than the "
    2237             :                   "array length");
    2238             :   i::Handle<i::Object> i_item = Utils::OpenHandle(*item);
    2239          31 :   array->set(index, *i_item);
    2240          31 : }
    2241             : 
    2242         117 : Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
    2243             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2244             :   i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
    2245             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2246         234 :   Utils::ApiCheck(index >= 0 && index < array->length(),
    2247             :                   "v8::PrimitiveArray::Get",
    2248             :                   "index must be greater than or equal to 0 and less than the "
    2249             :                   "array length");
    2250             :   i::Handle<i::Object> i_item(array->get(index), isolate);
    2251         117 :   return ToApiHandle<Primitive>(i_item);
    2252             : }
    2253             : 
    2254        1036 : Module::Status Module::GetStatus() const {
    2255             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2256        1036 :   switch (self->status()) {
    2257             :     case i::Module::kUninstantiated:
    2258             :     case i::Module::kPreInstantiating:
    2259             :       return kUninstantiated;
    2260             :     case i::Module::kInstantiating:
    2261           0 :       return kInstantiating;
    2262             :     case i::Module::kInstantiated:
    2263         220 :       return kInstantiated;
    2264             :     case i::Module::kEvaluating:
    2265           0 :       return kEvaluating;
    2266             :     case i::Module::kEvaluated:
    2267         561 :       return kEvaluated;
    2268             :     case i::Module::kErrored:
    2269          20 :       return kErrored;
    2270             :   }
    2271           0 :   UNREACHABLE();
    2272             : }
    2273             : 
    2274          10 : Local<Value> Module::GetException() const {
    2275          10 :   Utils::ApiCheck(GetStatus() == kErrored, "v8::Module::GetException",
    2276             :                   "Module status must be kErrored");
    2277             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2278             :   i::Isolate* isolate = self->GetIsolate();
    2279          20 :   return ToApiHandle<Value>(i::handle(self->GetException(), isolate));
    2280             : }
    2281             : 
    2282        1360 : int Module::GetModuleRequestsLength() const {
    2283             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2284        2720 :   return self->info()->module_requests()->length();
    2285             : }
    2286             : 
    2287         994 : Local<String> Module::GetModuleRequest(int i) const {
    2288         994 :   CHECK_GE(i, 0);
    2289             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2290             :   i::Isolate* isolate = self->GetIsolate();
    2291        1988 :   i::Handle<i::FixedArray> module_requests(self->info()->module_requests(),
    2292        1988 :                                            isolate);
    2293         994 :   CHECK_LT(i, module_requests->length());
    2294         994 :   return ToApiHandle<String>(i::handle(module_requests->get(i), isolate));
    2295             : }
    2296             : 
    2297          10 : Location Module::GetModuleRequestLocation(int i) const {
    2298          10 :   CHECK_GE(i, 0);
    2299             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2300             :   i::HandleScope scope(isolate);
    2301             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2302             :   i::Handle<i::FixedArray> module_request_positions(
    2303          20 :       self->info()->module_request_positions(), isolate);
    2304          10 :   CHECK_LT(i, module_request_positions->length());
    2305          10 :   int position = i::Smi::ToInt(module_request_positions->get(i));
    2306          20 :   i::Handle<i::Script> script(self->script(), isolate);
    2307             :   i::Script::PositionInfo info;
    2308          10 :   i::Script::GetPositionInfo(script, position, &info, i::Script::WITH_OFFSET);
    2309          20 :   return v8::Location(info.line, info.column);
    2310             : }
    2311             : 
    2312         226 : Local<Value> Module::GetModuleNamespace() {
    2313             :   Utils::ApiCheck(
    2314         226 :       GetStatus() >= kInstantiated, "v8::Module::GetModuleNamespace",
    2315         226 :       "v8::Module::GetModuleNamespace must be used on an instantiated module");
    2316             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2317             :   i::Handle<i::JSModuleNamespace> module_namespace =
    2318         226 :       i::Module::GetModuleNamespace(self->GetIsolate(), self);
    2319         226 :   return ToApiHandle<Value>(module_namespace);
    2320             : }
    2321             : 
    2322          20 : Local<UnboundModuleScript> Module::GetUnboundModuleScript() {
    2323             :   Utils::ApiCheck(
    2324          20 :       GetStatus() < kEvaluating, "v8::Module::GetUnboundScript",
    2325          20 :       "v8::Module::GetUnboundScript must be used on an unevaluated module");
    2326             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2327             :   return ToApiHandle<UnboundModuleScript>(i::Handle<i::SharedFunctionInfo>(
    2328          40 :       self->GetSharedFunctionInfo(), self->GetIsolate()));
    2329             : }
    2330             : 
    2331        4732 : int Module::GetIdentityHash() const { return Utils::OpenHandle(this)->hash(); }
    2332             : 
    2333        1169 : Maybe<bool> Module::InstantiateModule(Local<Context> context,
    2334             :                                       Module::ResolveCallback callback) {
    2335        2338 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    2336        4676 :   ENTER_V8(isolate, context, Module, InstantiateModule, Nothing<bool>(),
    2337             :            i::HandleScope);
    2338             :   has_pending_exception = !i::Module::Instantiate(
    2339        1169 :       isolate, Utils::OpenHandle(this), context, callback);
    2340        1169 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    2341             :   return Just(true);
    2342             : }
    2343             : 
    2344        1207 : MaybeLocal<Value> Module::Evaluate(Local<Context> context) {
    2345        2414 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    2346        2414 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    2347        4828 :   ENTER_V8(isolate, context, Module, Evaluate, MaybeLocal<Value>(),
    2348             :            InternalEscapableScope);
    2349        1207 :   i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true);
    2350        1207 :   i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
    2351             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    2352             : 
    2353             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2354             :   // It's an API error to call Evaluate before Instantiate.
    2355        1207 :   CHECK_GE(self->status(), i::Module::kInstantiated);
    2356             : 
    2357             :   Local<Value> result;
    2358        1207 :   has_pending_exception = !ToLocal(i::Module::Evaluate(isolate, self), &result);
    2359        1207 :   RETURN_ON_FAILED_EXECUTION(Value);
    2360        2368 :   RETURN_ESCAPED(result);
    2361             : }
    2362             : 
    2363             : namespace {
    2364             : 
    2365      272058 : i::Compiler::ScriptDetails GetScriptDetails(
    2366             :     i::Isolate* isolate, Local<Value> resource_name,
    2367             :     Local<Integer> resource_line_offset, Local<Integer> resource_column_offset,
    2368             :     Local<Value> source_map_url, Local<PrimitiveArray> host_defined_options) {
    2369             :   i::Compiler::ScriptDetails script_details;
    2370      272058 :   if (!resource_name.IsEmpty()) {
    2371      139157 :     script_details.name_obj = Utils::OpenHandle(*(resource_name));
    2372             :   }
    2373      272058 :   if (!resource_line_offset.IsEmpty()) {
    2374             :     script_details.line_offset =
    2375        4602 :         static_cast<int>(resource_line_offset->Value());
    2376             :   }
    2377      272058 :   if (!resource_column_offset.IsEmpty()) {
    2378             :     script_details.column_offset =
    2379        4581 :         static_cast<int>(resource_column_offset->Value());
    2380             :   }
    2381      272058 :   script_details.host_defined_options = isolate->factory()->empty_fixed_array();
    2382      272058 :   if (!host_defined_options.IsEmpty()) {
    2383             :     script_details.host_defined_options =
    2384           6 :         Utils::OpenHandle(*(host_defined_options));
    2385             :   }
    2386      272058 :   if (!source_map_url.IsEmpty()) {
    2387         894 :     script_details.source_map_url = Utils::OpenHandle(*(source_map_url));
    2388             :   }
    2389      272058 :   return script_details;
    2390             : }
    2391             : 
    2392             : }  // namespace
    2393             : 
    2394      258885 : MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
    2395             :     Isolate* v8_isolate, Source* source, CompileOptions options,
    2396             :     NoCacheReason no_cache_reason) {
    2397      258875 :   auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2398      517770 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
    2399     1035509 :   ENTER_V8_NO_SCRIPT(isolate, v8_isolate->GetCurrentContext(), ScriptCompiler,
    2400             :                      CompileUnbound, MaybeLocal<UnboundScript>(),
    2401             :                      InternalEscapableScope);
    2402             : 
    2403             :   i::ScriptData* script_data = nullptr;
    2404      258875 :   if (options == kConsumeCodeCache) {
    2405             :     DCHECK(source->cached_data);
    2406             :     // ScriptData takes care of pointer-aligning the data.
    2407             :     script_data = new i::ScriptData(source->cached_data->data,
    2408         164 :                                     source->cached_data->length);
    2409             :   }
    2410             : 
    2411      258875 :   i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string));
    2412             :   i::Handle<i::SharedFunctionInfo> result;
    2413      776624 :   TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileScript");
    2414             :   i::Compiler::ScriptDetails script_details = GetScriptDetails(
    2415             :       isolate, source->resource_name, source->resource_line_offset,
    2416             :       source->resource_column_offset, source->source_map_url,
    2417      258875 :       source->host_defined_options);
    2418             :   i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
    2419             :       i::Compiler::GetSharedFunctionInfoForScript(
    2420             :           isolate, str, script_details, source->resource_options, nullptr,
    2421      258875 :           script_data, options, no_cache_reason, i::NOT_NATIVES_CODE);
    2422      258875 :   if (options == kConsumeCodeCache) {
    2423         328 :     source->cached_data->rejected = script_data->rejected();
    2424             :   }
    2425      259039 :   delete script_data;
    2426             :   has_pending_exception = !maybe_function_info.ToHandle(&result);
    2427      258874 :   RETURN_ON_FAILED_EXECUTION(UnboundScript);
    2428      515654 :   RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
    2429             : }
    2430             : 
    2431        9222 : MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript(
    2432             :     Isolate* v8_isolate, Source* source, CompileOptions options,
    2433             :     NoCacheReason no_cache_reason) {
    2434             :   Utils::ApiCheck(
    2435             :       !source->GetResourceOptions().IsModule(),
    2436             :       "v8::ScriptCompiler::CompileUnboundScript",
    2437             :       "v8::ScriptCompiler::CompileModule must be used to compile modules");
    2438        9222 :   return CompileUnboundInternal(v8_isolate, source, options, no_cache_reason);
    2439             : }
    2440             : 
    2441      247680 : MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
    2442             :                                            Source* source,
    2443             :                                            CompileOptions options,
    2444             :                                            NoCacheReason no_cache_reason) {
    2445             :   Utils::ApiCheck(
    2446             :       !source->GetResourceOptions().IsModule(), "v8::ScriptCompiler::Compile",
    2447             :       "v8::ScriptCompiler::CompileModule must be used to compile modules");
    2448      247680 :   auto isolate = context->GetIsolate();
    2449             :   auto maybe =
    2450      247680 :       CompileUnboundInternal(isolate, source, options, no_cache_reason);
    2451             :   Local<UnboundScript> result;
    2452      247679 :   if (!maybe.ToLocal(&result)) return MaybeLocal<Script>();
    2453             :   v8::Context::Scope scope(context);
    2454      245763 :   return result->BindToCurrentContext();
    2455             : }
    2456             : 
    2457        1983 : MaybeLocal<Module> ScriptCompiler::CompileModule(
    2458             :     Isolate* isolate, Source* source, CompileOptions options,
    2459             :     NoCacheReason no_cache_reason) {
    2460        1983 :   CHECK(options == kNoCompileOptions || options == kConsumeCodeCache);
    2461             : 
    2462             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    2463             : 
    2464             :   Utils::ApiCheck(source->GetResourceOptions().IsModule(),
    2465             :                   "v8::ScriptCompiler::CompileModule",
    2466             :                   "Invalid ScriptOrigin: is_module must be true");
    2467             :   auto maybe =
    2468        1983 :       CompileUnboundInternal(isolate, source, options, no_cache_reason);
    2469             :   Local<UnboundScript> unbound;
    2470        1983 :   if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>();
    2471             : 
    2472        1795 :   i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound);
    2473        1795 :   return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared));
    2474             : }
    2475             : 
    2476             : namespace {
    2477          30 : bool IsIdentifier(i::Isolate* isolate, i::Handle<i::String> string) {
    2478          30 :   string = i::String::Flatten(isolate, string);
    2479             :   const int length = string->length();
    2480          30 :   if (length == 0) return false;
    2481          90 :   if (!i::IsIdentifierStart(string->Get(0))) return false;
    2482             :   i::DisallowHeapAllocation no_gc;
    2483          30 :   i::String::FlatContent flat = string->GetFlatContent(no_gc);
    2484          30 :   if (flat.IsOneByte()) {
    2485             :     auto vector = flat.ToOneByteVector();
    2486          30 :     for (int i = 1; i < length; i++) {
    2487         105 :       if (!i::IsIdentifierPart(vector[i])) return false;
    2488             :     }
    2489             :   } else {
    2490             :     auto vector = flat.ToUC16Vector();
    2491           5 :     for (int i = 1; i < length; i++) {
    2492          15 :       if (!i::IsIdentifierPart(vector[i])) return false;
    2493             :     }
    2494             :   }
    2495             :   return true;
    2496             : }
    2497             : }  // anonymous namespace
    2498             : 
    2499          84 : MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
    2500             :     Local<Context> v8_context, Source* source, size_t arguments_count,
    2501             :     Local<String> arguments[], size_t context_extension_count,
    2502             :     Local<Object> context_extensions[], CompileOptions options,
    2503             :     NoCacheReason no_cache_reason) {
    2504         336 :   PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext,
    2505             :                         Function);
    2506         252 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
    2507             : 
    2508             :   DCHECK(options == CompileOptions::kConsumeCodeCache ||
    2509             :          options == CompileOptions::kEagerCompile ||
    2510             :          options == CompileOptions::kNoCompileOptions);
    2511             : 
    2512             :   i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
    2513             : 
    2514             :   DCHECK(context->IsNativeContext());
    2515             :   i::Handle<i::SharedFunctionInfo> outer_info(
    2516         168 :       context->empty_function()->shared(), isolate);
    2517             : 
    2518             :   i::Handle<i::JSFunction> fun;
    2519             :   i::Handle<i::FixedArray> arguments_list =
    2520          84 :       isolate->factory()->NewFixedArray(static_cast<int>(arguments_count));
    2521         109 :   for (int i = 0; i < static_cast<int>(arguments_count); i++) {
    2522          30 :     i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]);
    2523          30 :     if (!IsIdentifier(isolate, argument)) return Local<Function>();
    2524          50 :     arguments_list->set(i, *argument);
    2525             :   }
    2526             : 
    2527          24 :   for (size_t i = 0; i < context_extension_count; ++i) {
    2528             :     i::Handle<i::JSReceiver> extension =
    2529          24 :         Utils::OpenHandle(*context_extensions[i]);
    2530          48 :     if (!extension->IsJSObject()) return Local<Function>();
    2531             :     context = isolate->factory()->NewWithContext(
    2532             :         context,
    2533             :         i::ScopeInfo::CreateForWithScope(
    2534             :             isolate,
    2535          48 :             context->IsNativeContext()
    2536             :                 ? i::Handle<i::ScopeInfo>::null()
    2537             :                 : i::Handle<i::ScopeInfo>(context->scope_info(), isolate)),
    2538          53 :         extension);
    2539             :   }
    2540             : 
    2541             :   i::Compiler::ScriptDetails script_details = GetScriptDetails(
    2542             :       isolate, source->resource_name, source->resource_line_offset,
    2543             :       source->resource_column_offset, source->source_map_url,
    2544          79 :       source->host_defined_options);
    2545             : 
    2546             :   i::ScriptData* script_data = nullptr;
    2547          79 :   if (options == kConsumeCodeCache) {
    2548             :     DCHECK(source->cached_data);
    2549             :     // ScriptData takes care of pointer-aligning the data.
    2550             :     script_data = new i::ScriptData(source->cached_data->data,
    2551           5 :                                     source->cached_data->length);
    2552             :   }
    2553             : 
    2554             :   i::Handle<i::JSFunction> result;
    2555             :   has_pending_exception =
    2556             :       !i::Compiler::GetWrappedFunction(
    2557             :            Utils::OpenHandle(*source->source_string), arguments_list, context,
    2558             :            script_details, source->resource_options, script_data, options,
    2559             :            no_cache_reason)
    2560         158 :            .ToHandle(&result);
    2561          79 :   if (options == kConsumeCodeCache) {
    2562          10 :     source->cached_data->rejected = script_data->rejected();
    2563             :   }
    2564          84 :   delete script_data;
    2565          79 :   RETURN_ON_FAILED_EXECUTION(Function);
    2566          69 :   RETURN_ESCAPED(Utils::CallableToLocal(result));
    2567             : }
    2568             : 
    2569       26208 : void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); }
    2570             : 
    2571       13104 : ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript(
    2572             :     Isolate* v8_isolate, StreamedSource* source, CompileOptions options) {
    2573       13104 :   if (!i::FLAG_script_streaming) {
    2574             :     return nullptr;
    2575             :   }
    2576             :   // We don't support other compile options on streaming background compiles.
    2577             :   // TODO(rmcilroy): remove CompileOptions from the API.
    2578       13104 :   CHECK(options == ScriptCompiler::kNoCompileOptions);
    2579       13104 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2580       13104 :   i::ScriptStreamingData* data = source->impl();
    2581             :   std::unique_ptr<i::BackgroundCompileTask> task =
    2582       13104 :       base::make_unique<i::BackgroundCompileTask>(data, isolate);
    2583       13104 :   data->task = std::move(task);
    2584       13104 :   return new ScriptCompiler::ScriptStreamingTask(data);
    2585             : }
    2586             : 
    2587       13104 : MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
    2588             :                                            StreamedSource* v8_source,
    2589             :                                            Local<String> full_source_string,
    2590             :                                            const ScriptOrigin& origin) {
    2591       52416 :   PREPARE_FOR_EXECUTION(context, ScriptCompiler, Compile, Script);
    2592       39312 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
    2593       39312 :   TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
    2594             :                "V8.CompileStreamedScript");
    2595             : 
    2596       13104 :   i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
    2597             :   i::Compiler::ScriptDetails script_details = GetScriptDetails(
    2598             :       isolate, origin.ResourceName(), origin.ResourceLineOffset(),
    2599             :       origin.ResourceColumnOffset(), origin.SourceMapUrl(),
    2600       13104 :       origin.HostDefinedOptions());
    2601             :   i::ScriptStreamingData* data = v8_source->impl();
    2602             : 
    2603             :   i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
    2604             :       i::Compiler::GetSharedFunctionInfoForStreamedScript(
    2605       13104 :           isolate, str, script_details, origin.Options(), data);
    2606             : 
    2607             :   i::Handle<i::SharedFunctionInfo> result;
    2608       13104 :   has_pending_exception = !maybe_function_info.ToHandle(&result);
    2609       13104 :   if (has_pending_exception) isolate->ReportPendingMessages();
    2610             : 
    2611       13104 :   RETURN_ON_FAILED_EXECUTION(Script);
    2612             : 
    2613             :   Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
    2614       12998 :   if (generic.IsEmpty()) return Local<Script>();
    2615       12998 :   Local<Script> bound = generic->BindToCurrentContext();
    2616       12998 :   if (bound.IsEmpty()) return Local<Script>();
    2617       12998 :   RETURN_ESCAPED(bound);
    2618             : }
    2619             : 
    2620           0 : uint32_t ScriptCompiler::CachedDataVersionTag() {
    2621             :   return static_cast<uint32_t>(base::hash_combine(
    2622           0 :       internal::Version::Hash(), internal::FlagList::Hash(),
    2623           0 :       static_cast<uint32_t>(internal::CpuFeatures::SupportedFeatures())));
    2624             : }
    2625             : 
    2626         362 : ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
    2627             :     Local<UnboundScript> unbound_script) {
    2628             :   i::Handle<i::SharedFunctionInfo> shared =
    2629             :       i::Handle<i::SharedFunctionInfo>::cast(
    2630         362 :           Utils::OpenHandle(*unbound_script));
    2631             :   DCHECK(shared->is_toplevel());
    2632         362 :   return i::CodeSerializer::Serialize(shared);
    2633             : }
    2634             : 
    2635             : // static
    2636          10 : ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
    2637             :     Local<UnboundModuleScript> unbound_module_script) {
    2638             :   i::Handle<i::SharedFunctionInfo> shared =
    2639             :       i::Handle<i::SharedFunctionInfo>::cast(
    2640          10 :           Utils::OpenHandle(*unbound_module_script));
    2641             :   DCHECK(shared->is_toplevel());
    2642          10 :   return i::CodeSerializer::Serialize(shared);
    2643             : }
    2644             : 
    2645           5 : ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
    2646             :     Local<Function> function) {
    2647             :   auto js_function =
    2648           5 :       i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*function));
    2649             :   i::Handle<i::SharedFunctionInfo> shared(js_function->shared(),
    2650          10 :                                           js_function->GetIsolate());
    2651           5 :   CHECK(shared->is_wrapped());
    2652           5 :   return i::CodeSerializer::Serialize(shared);
    2653             : }
    2654             : 
    2655      128731 : MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
    2656             :                                    ScriptOrigin* origin) {
    2657      128731 :   if (origin) {
    2658             :     ScriptCompiler::Source script_source(source, *origin);
    2659        5090 :     return ScriptCompiler::Compile(context, &script_source);
    2660             :   }
    2661             :   ScriptCompiler::Source script_source(source);
    2662      123641 :   return ScriptCompiler::Compile(context, &script_source);
    2663             : }
    2664             : 
    2665             : 
    2666             : // --- E x c e p t i o n s ---
    2667             : 
    2668    20928036 : v8::TryCatch::TryCatch(v8::Isolate* isolate)
    2669             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    2670             :       next_(isolate_->try_catch_handler()),
    2671             :       is_verbose_(false),
    2672             :       can_continue_(true),
    2673             :       capture_message_(true),
    2674             :       rethrow_(false),
    2675    41856072 :       has_terminated_(false) {
    2676    20928036 :   ResetInternal();
    2677             :   // Special handling for simulators which have a separate JS stack.
    2678             :   js_stack_comparable_address_ = reinterpret_cast<void*>(
    2679    20928035 :       i::SimulatorStack::RegisterJSStackComparableAddress(isolate_));
    2680    20928035 :   isolate_->RegisterTryCatchHandler(this);
    2681    20928033 : }
    2682             : 
    2683             : 
    2684    20928034 : v8::TryCatch::~TryCatch() {
    2685    20928034 :   if (rethrow_) {
    2686         121 :     v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_);
    2687             :     v8::HandleScope scope(isolate);
    2688         242 :     v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(isolate, Exception());
    2689         121 :     if (HasCaught() && capture_message_) {
    2690             :       // If an exception was caught and rethrow_ is indicated, the saved
    2691             :       // message, script, and location need to be restored to Isolate TLS
    2692             :       // for reuse.  capture_message_ needs to be disabled so that Throw()
    2693             :       // does not create a new message.
    2694         121 :       isolate_->thread_local_top()->rethrowing_message_ = true;
    2695         121 :       isolate_->RestorePendingMessageFromTryCatch(this);
    2696             :     }
    2697         121 :     isolate_->UnregisterTryCatchHandler(this);
    2698             :     i::SimulatorStack::UnregisterJSStackComparableAddress(isolate_);
    2699         121 :     reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc);
    2700             :     DCHECK(!isolate_->thread_local_top()->rethrowing_message_);
    2701             :   } else {
    2702    20927913 :     if (HasCaught() && isolate_->has_scheduled_exception()) {
    2703             :       // If an exception was caught but is still scheduled because no API call
    2704             :       // promoted it, then it is canceled to prevent it from being propagated.
    2705             :       // Note that this will not cancel termination exceptions.
    2706         248 :       isolate_->CancelScheduledExceptionFromTryCatch(this);
    2707             :     }
    2708    20927912 :     isolate_->UnregisterTryCatchHandler(this);
    2709             :     i::SimulatorStack::UnregisterJSStackComparableAddress(isolate_);
    2710             :   }
    2711    20928032 : }
    2712             : 
    2713           0 : void* v8::TryCatch::operator new(size_t) { base::OS::Abort(); }
    2714           0 : void* v8::TryCatch::operator new[](size_t) { base::OS::Abort(); }
    2715           0 : void v8::TryCatch::operator delete(void*, size_t) { base::OS::Abort(); }
    2716           0 : void v8::TryCatch::operator delete[](void*, size_t) { base::OS::Abort(); }
    2717             : 
    2718    21098962 : bool v8::TryCatch::HasCaught() const {
    2719             :   return !i::Object(reinterpret_cast<i::Address>(exception_))
    2720    42197929 :               ->IsTheHole(isolate_);
    2721             : }
    2722             : 
    2723             : 
    2724        1658 : bool v8::TryCatch::CanContinue() const {
    2725        1658 :   return can_continue_;
    2726             : }
    2727             : 
    2728             : 
    2729       21452 : bool v8::TryCatch::HasTerminated() const {
    2730       21452 :   return has_terminated_;
    2731             : }
    2732             : 
    2733             : 
    2734         121 : v8::Local<v8::Value> v8::TryCatch::ReThrow() {
    2735         121 :   if (!HasCaught()) return v8::Local<v8::Value>();
    2736         121 :   rethrow_ = true;
    2737         242 :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_));
    2738             : }
    2739             : 
    2740             : 
    2741       10425 : v8::Local<Value> v8::TryCatch::Exception() const {
    2742       10425 :   if (HasCaught()) {
    2743             :     // Check for out of memory exception.
    2744       10425 :     i::Object exception(reinterpret_cast<i::Address>(exception_));
    2745       10425 :     return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_));
    2746             :   } else {
    2747           0 :     return v8::Local<Value>();
    2748             :   }
    2749             : }
    2750             : 
    2751             : 
    2752        6301 : MaybeLocal<Value> v8::TryCatch::StackTrace(Local<Context> context) const {
    2753        6301 :   if (!HasCaught()) return v8::Local<Value>();
    2754        6301 :   i::Object raw_obj(reinterpret_cast<i::Address>(exception_));
    2755        6301 :   if (!raw_obj->IsJSObject()) return v8::Local<Value>();
    2756       10240 :   PREPARE_FOR_EXECUTION(context, TryCatch, StackTrace, Value);
    2757        2560 :   i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
    2758             :   i::Handle<i::String> name = isolate->factory()->stack_string();
    2759        2560 :   Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
    2760        2560 :   has_pending_exception = maybe.IsNothing();
    2761        2560 :   RETURN_ON_FAILED_EXECUTION(Value);
    2762        2560 :   if (!maybe.FromJust()) return v8::Local<Value>();
    2763             :   Local<Value> result;
    2764             :   has_pending_exception =
    2765        5120 :       !ToLocal<Value>(i::JSReceiver::GetProperty(isolate, obj, name), &result);
    2766        2560 :   RETURN_ON_FAILED_EXECUTION(Value);
    2767        2560 :   RETURN_ESCAPED(result);
    2768             : }
    2769             : 
    2770             : 
    2771        8437 : v8::Local<v8::Message> v8::TryCatch::Message() const {
    2772        8437 :   i::Object message(reinterpret_cast<i::Address>(message_obj_));
    2773             :   DCHECK(message->IsJSMessageObject() || message->IsTheHole(isolate_));
    2774       16874 :   if (HasCaught() && !message->IsTheHole(isolate_)) {
    2775        8377 :     return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
    2776             :   } else {
    2777          60 :     return v8::Local<v8::Message>();
    2778             :   }
    2779             : }
    2780             : 
    2781             : 
    2782         714 : void v8::TryCatch::Reset() {
    2783         714 :   if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
    2784             :     // If an exception was caught but is still scheduled because no API call
    2785             :     // promoted it, then it is canceled to prevent it from being propagated.
    2786             :     // Note that this will not cancel termination exceptions.
    2787           5 :     isolate_->CancelScheduledExceptionFromTryCatch(this);
    2788             :   }
    2789         714 :   ResetInternal();
    2790         714 : }
    2791             : 
    2792             : 
    2793    20928748 : void v8::TryCatch::ResetInternal() {
    2794    20928748 :   i::Object the_hole = i::ReadOnlyRoots(isolate_).the_hole_value();
    2795    20928748 :   exception_ = reinterpret_cast<void*>(the_hole->ptr());
    2796    20928748 :   message_obj_ = reinterpret_cast<void*>(the_hole->ptr());
    2797    20928748 : }
    2798             : 
    2799             : 
    2800      180015 : void v8::TryCatch::SetVerbose(bool value) {
    2801      180015 :   is_verbose_ = value;
    2802      180015 : }
    2803             : 
    2804           0 : bool v8::TryCatch::IsVerbose() const { return is_verbose_; }
    2805             : 
    2806       58888 : void v8::TryCatch::SetCaptureMessage(bool value) {
    2807       58888 :   capture_message_ = value;
    2808       58888 : }
    2809             : 
    2810             : 
    2811             : // --- M e s s a g e ---
    2812             : 
    2813             : 
    2814        2860 : Local<String> Message::Get() const {
    2815             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2816             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2817        2860 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2818             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    2819        2860 :   i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj);
    2820             :   Local<String> result = Utils::ToLocal(raw_result);
    2821        2860 :   return scope.Escape(result);
    2822             : }
    2823             : 
    2824          50 : v8::Isolate* Message::GetIsolate() const {
    2825             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2826          50 :   return reinterpret_cast<Isolate*>(isolate);
    2827             : }
    2828             : 
    2829       15852 : ScriptOrigin Message::GetScriptOrigin() const {
    2830             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2831             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2832       15852 :   auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
    2833       31704 :   i::Handle<i::Script> script(message->script(), isolate);
    2834       31704 :   return GetScriptOriginForScript(isolate, script);
    2835             : }
    2836             : 
    2837             : 
    2838           0 : v8::Local<Value> Message::GetScriptResourceName() const {
    2839           0 :   return GetScriptOrigin().ResourceName();
    2840             : }
    2841             : 
    2842             : 
    2843        2070 : v8::Local<v8::StackTrace> Message::GetStackTrace() const {
    2844             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2845             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2846        2070 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2847        2070 :   auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
    2848             :   i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
    2849        4140 :   if (!stackFramesObj->IsFixedArray()) return v8::Local<v8::StackTrace>();
    2850         241 :   auto stackTrace = i::Handle<i::FixedArray>::cast(stackFramesObj);
    2851             :   return scope.Escape(Utils::StackTraceToLocal(stackTrace));
    2852             : }
    2853             : 
    2854             : 
    2855        9007 : Maybe<int> Message::GetLineNumber(Local<Context> context) const {
    2856             :   auto self = Utils::OpenHandle(this);
    2857             :   i::Isolate* isolate = self->GetIsolate();
    2858             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2859        9007 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2860        9007 :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2861       18014 :   return Just(msg->GetLineNumber());
    2862             : }
    2863             : 
    2864             : 
    2865          30 : int Message::GetStartPosition() const {
    2866             :   auto self = Utils::OpenHandle(this);
    2867          30 :   return self->start_position();
    2868             : }
    2869             : 
    2870             : 
    2871          18 : int Message::GetEndPosition() const {
    2872             :   auto self = Utils::OpenHandle(this);
    2873          18 :   return self->end_position();
    2874             : }
    2875             : 
    2876       24140 : int Message::ErrorLevel() const {
    2877             :   auto self = Utils::OpenHandle(this);
    2878       24140 :   return self->error_level();
    2879             : }
    2880             : 
    2881        8718 : int Message::GetStartColumn() const {
    2882             :   auto self = Utils::OpenHandle(this);
    2883             :   i::Isolate* isolate = self->GetIsolate();
    2884             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2885        8718 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2886        8718 :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2887       17436 :   return msg->GetColumnNumber();
    2888             : }
    2889             : 
    2890        8718 : Maybe<int> Message::GetStartColumn(Local<Context> context) const {
    2891        8718 :   return Just(GetStartColumn());
    2892             : }
    2893             : 
    2894        6280 : int Message::GetEndColumn() const {
    2895             :   auto self = Utils::OpenHandle(this);
    2896             :   i::Isolate* isolate = self->GetIsolate();
    2897             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2898        6280 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2899        6280 :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2900        6280 :   const int column_number = msg->GetColumnNumber();
    2901        6280 :   if (column_number == -1) return -1;
    2902             :   const int start = self->start_position();
    2903             :   const int end = self->end_position();
    2904        6280 :   return column_number + (end - start);
    2905             : }
    2906             : 
    2907        6280 : Maybe<int> Message::GetEndColumn(Local<Context> context) const {
    2908        6280 :   return Just(GetEndColumn());
    2909             : }
    2910             : 
    2911             : 
    2912         131 : bool Message::IsSharedCrossOrigin() const {
    2913             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2914             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2915             :   return Utils::OpenHandle(this)
    2916         262 :       ->script()
    2917         262 :       ->origin_options()
    2918         393 :       .IsSharedCrossOrigin();
    2919             : }
    2920             : 
    2921           0 : bool Message::IsOpaque() const {
    2922             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2923             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2924           0 :   return Utils::OpenHandle(this)->script()->origin_options().IsOpaque();
    2925             : }
    2926             : 
    2927             : 
    2928        6291 : MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
    2929             :   auto self = Utils::OpenHandle(this);
    2930             :   i::Isolate* isolate = self->GetIsolate();
    2931             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2932        6291 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2933        6291 :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2934       18873 :   RETURN_ESCAPED(Utils::ToLocal(msg->GetSourceLine()));
    2935             : }
    2936             : 
    2937             : 
    2938           0 : void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
    2939             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    2940             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    2941           0 :   i_isolate->PrintCurrentStackTrace(out);
    2942           0 : }
    2943             : 
    2944             : 
    2945             : // --- S t a c k T r a c e ---
    2946             : 
    2947       66728 : Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
    2948             :                                        uint32_t index) const {
    2949             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2950             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2951       66728 :   EscapableHandleScope scope(v8_isolate);
    2952      133456 :   auto obj = handle(Utils::OpenHandle(this)->get(index), isolate);
    2953       66728 :   auto frame = i::Handle<i::StackTraceFrame>::cast(obj);
    2954       66728 :   return scope.Escape(Utils::StackFrameToLocal(frame));
    2955             : }
    2956             : 
    2957      129491 : int StackTrace::GetFrameCount() const {
    2958      129491 :   return Utils::OpenHandle(this)->length();
    2959             : }
    2960             : 
    2961             : 
    2962       68858 : Local<StackTrace> StackTrace::CurrentStackTrace(
    2963             :     Isolate* isolate,
    2964             :     int frame_limit,
    2965             :     StackTraceOptions options) {
    2966             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    2967             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    2968             :   i::Handle<i::FixedArray> stackTrace =
    2969       68858 :       i_isolate->CaptureCurrentStackTrace(frame_limit, options);
    2970       68858 :   return Utils::StackTraceToLocal(stackTrace);
    2971             : }
    2972             : 
    2973             : 
    2974             : // --- S t a c k F r a m e ---
    2975             : 
    2976       64923 : int StackFrame::GetLineNumber() const {
    2977       64923 :   return i::StackTraceFrame::GetLineNumber(Utils::OpenHandle(this));
    2978             : }
    2979             : 
    2980             : 
    2981       64888 : int StackFrame::GetColumn() const {
    2982       64888 :   return i::StackTraceFrame::GetColumnNumber(Utils::OpenHandle(this));
    2983             : }
    2984             : 
    2985             : 
    2986       64504 : int StackFrame::GetScriptId() const {
    2987       64504 :   return i::StackTraceFrame::GetScriptId(Utils::OpenHandle(this));
    2988             : }
    2989             : 
    2990       64691 : Local<String> StackFrame::GetScriptName() const {
    2991             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2992       64691 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2993             :   i::Handle<i::Object> name =
    2994       64691 :       i::StackTraceFrame::GetFileName(Utils::OpenHandle(this));
    2995      129382 :   return name->IsString()
    2996             :              ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
    2997      193236 :              : Local<String>();
    2998             : }
    2999             : 
    3000             : 
    3001      128948 : Local<String> StackFrame::GetScriptNameOrSourceURL() const {
    3002             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    3003      128948 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    3004             :   i::Handle<i::Object> name =
    3005      128948 :       i::StackTraceFrame::GetScriptNameOrSourceUrl(Utils::OpenHandle(this));
    3006      257896 :   return name->IsString()
    3007             :              ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
    3008      385674 :              : Local<String>();
    3009             : }
    3010             : 
    3011             : 
    3012       64853 : Local<String> StackFrame::GetFunctionName() const {
    3013             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    3014       64853 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    3015             :   i::Handle<i::Object> name =
    3016       64853 :       i::StackTraceFrame::GetFunctionName(Utils::OpenHandle(this));
    3017      129706 :   return name->IsString()
    3018             :              ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
    3019      194559 :              : Local<String>();
    3020             : }
    3021             : 
    3022         100 : bool StackFrame::IsEval() const {
    3023         100 :   return i::StackTraceFrame::IsEval(Utils::OpenHandle(this));
    3024             : }
    3025             : 
    3026         100 : bool StackFrame::IsConstructor() const {
    3027         100 :   return i::StackTraceFrame::IsConstructor(Utils::OpenHandle(this));
    3028             : }
    3029             : 
    3030       64429 : bool StackFrame::IsWasm() const {
    3031       64429 :   return i::StackTraceFrame::IsWasm(Utils::OpenHandle(this));
    3032             : }
    3033             : 
    3034             : // --- J S O N ---
    3035             : 
    3036         135 : MaybeLocal<Value> JSON::Parse(Local<Context> context,
    3037             :                               Local<String> json_string) {
    3038         540 :   PREPARE_FOR_EXECUTION(context, JSON, Parse, Value);
    3039         135 :   i::Handle<i::String> string = Utils::OpenHandle(*json_string);
    3040         135 :   i::Handle<i::String> source = i::String::Flatten(isolate, string);
    3041             :   i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
    3042         270 :   auto maybe = source->IsSeqOneByteString()
    3043             :                    ? i::JsonParser<true>::Parse(isolate, source, undefined)
    3044         135 :                    : i::JsonParser<false>::Parse(isolate, source, undefined);
    3045             :   Local<Value> result;
    3046             :   has_pending_exception = !ToLocal<Value>(maybe, &result);
    3047         135 :   RETURN_ON_FAILED_EXECUTION(Value);
    3048         134 :   RETURN_ESCAPED(result);
    3049             : }
    3050             : 
    3051         109 : MaybeLocal<String> JSON::Stringify(Local<Context> context,
    3052             :                                    Local<Value> json_object,
    3053             :                                    Local<String> gap) {
    3054         436 :   PREPARE_FOR_EXECUTION(context, JSON, Stringify, String);
    3055         109 :   i::Handle<i::Object> object = Utils::OpenHandle(*json_object);
    3056             :   i::Handle<i::Object> replacer = isolate->factory()->undefined_value();
    3057             :   i::Handle<i::String> gap_string = gap.IsEmpty()
    3058             :                                         ? isolate->factory()->empty_string()
    3059         109 :                                         : Utils::OpenHandle(*gap);
    3060             :   i::Handle<i::Object> maybe;
    3061             :   has_pending_exception =
    3062         218 :       !i::JsonStringify(isolate, object, replacer, gap_string).ToHandle(&maybe);
    3063         109 :   RETURN_ON_FAILED_EXECUTION(String);
    3064             :   Local<String> result;
    3065             :   has_pending_exception =
    3066         109 :       !ToLocal<String>(i::Object::ToString(isolate, maybe), &result);
    3067         109 :   RETURN_ON_FAILED_EXECUTION(String);
    3068         109 :   RETURN_ESCAPED(result);
    3069             : }
    3070             : 
    3071             : // --- V a l u e   S e r i a l i z a t i o n ---
    3072             : 
    3073           0 : Maybe<bool> ValueSerializer::Delegate::WriteHostObject(Isolate* v8_isolate,
    3074             :                                                        Local<Object> object) {
    3075             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3076             :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3077             :       isolate->error_function(), i::MessageTemplate::kDataCloneError,
    3078           0 :       Utils::OpenHandle(*object)));
    3079           0 :   return Nothing<bool>();
    3080             : }
    3081             : 
    3082           0 : Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId(
    3083             :     Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) {
    3084             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3085             :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3086             :       isolate->error_function(), i::MessageTemplate::kDataCloneError,
    3087           0 :       Utils::OpenHandle(*shared_array_buffer)));
    3088           0 :   return Nothing<uint32_t>();
    3089             : }
    3090             : 
    3091           0 : Maybe<uint32_t> ValueSerializer::Delegate::GetWasmModuleTransferId(
    3092             :     Isolate* v8_isolate, Local<WasmModuleObject> module) {
    3093           0 :   return Nothing<uint32_t>();
    3094             : }
    3095             : 
    3096          20 : void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer,
    3097             :                                                         size_t size,
    3098             :                                                         size_t* actual_size) {
    3099          20 :   *actual_size = size;
    3100          20 :   return realloc(old_buffer, size);
    3101             : }
    3102             : 
    3103          20 : void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) {
    3104          20 :   return free(buffer);
    3105             : }
    3106             : 
    3107        1957 : struct ValueSerializer::PrivateData {
    3108             :   explicit PrivateData(i::Isolate* i, ValueSerializer::Delegate* delegate)
    3109        1956 :       : isolate(i), serializer(i, delegate) {}
    3110             :   i::Isolate* isolate;
    3111             :   i::ValueSerializer serializer;
    3112             : };
    3113             : 
    3114           0 : ValueSerializer::ValueSerializer(Isolate* isolate)
    3115           0 :     : ValueSerializer(isolate, nullptr) {}
    3116             : 
    3117        1949 : ValueSerializer::ValueSerializer(Isolate* isolate, Delegate* delegate)
    3118             :     : private_(
    3119        3899 :           new PrivateData(reinterpret_cast<i::Isolate*>(isolate), delegate)) {}
    3120             : 
    3121        3914 : ValueSerializer::~ValueSerializer() { delete private_; }
    3122             : 
    3123        1790 : void ValueSerializer::WriteHeader() { private_->serializer.WriteHeader(); }
    3124             : 
    3125           1 : void ValueSerializer::SetTreatArrayBufferViewsAsHostObjects(bool mode) {
    3126           1 :   private_->serializer.SetTreatArrayBufferViewsAsHostObjects(mode);
    3127           1 : }
    3128             : 
    3129        1786 : Maybe<bool> ValueSerializer::WriteValue(Local<Context> context,
    3130             :                                         Local<Value> value) {
    3131        3579 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3132        7163 :   ENTER_V8(isolate, context, ValueSerializer, WriteValue, Nothing<bool>(),
    3133             :            i::HandleScope);
    3134        1793 :   i::Handle<i::Object> object = Utils::OpenHandle(*value);
    3135        1793 :   Maybe<bool> result = private_->serializer.WriteObject(object);
    3136        1789 :   has_pending_exception = result.IsNothing();
    3137        1789 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3138        1762 :   return result;
    3139             : }
    3140             : 
    3141        1749 : std::pair<uint8_t*, size_t> ValueSerializer::Release() {
    3142        1749 :   return private_->serializer.Release();
    3143             : }
    3144             : 
    3145          47 : void ValueSerializer::TransferArrayBuffer(uint32_t transfer_id,
    3146             :                                           Local<ArrayBuffer> array_buffer) {
    3147             :   private_->serializer.TransferArrayBuffer(transfer_id,
    3148          47 :                                            Utils::OpenHandle(*array_buffer));
    3149          47 : }
    3150             : 
    3151           2 : void ValueSerializer::WriteUint32(uint32_t value) {
    3152           2 :   private_->serializer.WriteUint32(value);
    3153           2 : }
    3154             : 
    3155           2 : void ValueSerializer::WriteUint64(uint64_t value) {
    3156           2 :   private_->serializer.WriteUint64(value);
    3157           2 : }
    3158             : 
    3159           4 : void ValueSerializer::WriteDouble(double value) {
    3160           4 :   private_->serializer.WriteDouble(value);
    3161           4 : }
    3162             : 
    3163          15 : void ValueSerializer::WriteRawBytes(const void* source, size_t length) {
    3164          15 :   private_->serializer.WriteRawBytes(source, length);
    3165          15 : }
    3166             : 
    3167           0 : MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
    3168             :     Isolate* v8_isolate) {
    3169             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3170             :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3171             :       isolate->error_function(),
    3172           0 :       i::MessageTemplate::kDataCloneDeserializationError));
    3173           0 :   return MaybeLocal<Object>();
    3174             : }
    3175             : 
    3176           1 : MaybeLocal<WasmModuleObject> ValueDeserializer::Delegate::GetWasmModuleFromId(
    3177             :     Isolate* v8_isolate, uint32_t id) {
    3178             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3179             :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3180             :       isolate->error_function(),
    3181           2 :       i::MessageTemplate::kDataCloneDeserializationError));
    3182           1 :   return MaybeLocal<WasmModuleObject>();
    3183             : }
    3184             : 
    3185             : MaybeLocal<SharedArrayBuffer>
    3186           0 : ValueDeserializer::Delegate::GetSharedArrayBufferFromId(Isolate* v8_isolate,
    3187             :                                                         uint32_t id) {
    3188             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3189             :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3190             :       isolate->error_function(),
    3191           0 :       i::MessageTemplate::kDataCloneDeserializationError));
    3192           0 :   return MaybeLocal<SharedArrayBuffer>();
    3193             : }
    3194             : 
    3195        1845 : struct ValueDeserializer::PrivateData {
    3196             :   PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
    3197        1845 :       : isolate(i), deserializer(i, data, delegate) {}
    3198             :   i::Isolate* isolate;
    3199             :   i::ValueDeserializer deserializer;
    3200             :   bool has_aborted = false;
    3201             :   bool supports_legacy_wire_format = false;
    3202             : };
    3203             : 
    3204           0 : ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
    3205             :                                      size_t size)
    3206           0 :     : ValueDeserializer(isolate, data, size, nullptr) {}
    3207             : 
    3208        1845 : ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
    3209             :                                      size_t size, Delegate* delegate) {
    3210        1845 :   if (base::IsValueInRangeForNumericType<int>(size)) {
    3211             :     private_ = new PrivateData(
    3212             :         reinterpret_cast<i::Isolate*>(isolate),
    3213        3690 :         i::Vector<const uint8_t>(data, static_cast<int>(size)), delegate);
    3214             :   } else {
    3215             :     private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate),
    3216           0 :                                i::Vector<const uint8_t>(nullptr, 0), nullptr);
    3217           0 :     private_->has_aborted = true;
    3218             :   }
    3219        1845 : }
    3220             : 
    3221        3690 : ValueDeserializer::~ValueDeserializer() { delete private_; }
    3222             : 
    3223        1845 : Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) {
    3224        3690 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3225        7380 :   ENTER_V8_NO_SCRIPT(isolate, context, ValueDeserializer, ReadHeader,
    3226             :                      Nothing<bool>(), i::HandleScope);
    3227             : 
    3228             :   // We could have aborted during the constructor.
    3229             :   // If so, ReadHeader is where we report it.
    3230        1845 :   if (private_->has_aborted) {
    3231             :     isolate->Throw(*isolate->factory()->NewError(
    3232           0 :         i::MessageTemplate::kDataCloneDeserializationError));
    3233             :     has_pending_exception = true;
    3234           0 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3235             :   }
    3236             : 
    3237             :   bool read_header = false;
    3238        3690 :   has_pending_exception = !private_->deserializer.ReadHeader().To(&read_header);
    3239        1845 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3240             :   DCHECK(read_header);
    3241             : 
    3242             :   static const uint32_t kMinimumNonLegacyVersion = 13;
    3243        1963 :   if (GetWireFormatVersion() < kMinimumNonLegacyVersion &&
    3244         120 :       !private_->supports_legacy_wire_format) {
    3245             :     isolate->Throw(*isolate->factory()->NewError(
    3246           0 :         i::MessageTemplate::kDataCloneDeserializationVersionError));
    3247             :     has_pending_exception = true;
    3248           0 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3249             :   }
    3250             : 
    3251             :   return Just(true);
    3252             : }
    3253             : 
    3254        1845 : void ValueDeserializer::SetSupportsLegacyWireFormat(
    3255             :     bool supports_legacy_wire_format) {
    3256        1845 :   private_->supports_legacy_wire_format = supports_legacy_wire_format;
    3257        1845 : }
    3258             : 
    3259         262 : void ValueDeserializer::SetExpectInlineWasm(bool expect_inline_wasm) {
    3260         262 :   private_->deserializer.set_expect_inline_wasm(expect_inline_wasm);
    3261         262 : }
    3262             : 
    3263        3694 : uint32_t ValueDeserializer::GetWireFormatVersion() const {
    3264        3694 :   CHECK(!private_->has_aborted);
    3265        3694 :   return private_->deserializer.GetWireFormatVersion();
    3266             : }
    3267             : 
    3268        1843 : MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {
    3269        1843 :   CHECK(!private_->has_aborted);
    3270        7372 :   PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value);
    3271             :   i::MaybeHandle<i::Object> result;
    3272        1843 :   if (GetWireFormatVersion() > 0) {
    3273        1831 :     result = private_->deserializer.ReadObject();
    3274             :   } else {
    3275             :     result =
    3276          12 :         private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat();
    3277             :   }
    3278             :   Local<Value> value;
    3279             :   has_pending_exception = !ToLocal(result, &value);
    3280        1843 :   RETURN_ON_FAILED_EXECUTION(Value);
    3281        1814 :   RETURN_ESCAPED(value);
    3282             : }
    3283             : 
    3284          29 : void ValueDeserializer::TransferArrayBuffer(uint32_t transfer_id,
    3285             :                                             Local<ArrayBuffer> array_buffer) {
    3286          29 :   CHECK(!private_->has_aborted);
    3287             :   private_->deserializer.TransferArrayBuffer(transfer_id,
    3288          29 :                                              Utils::OpenHandle(*array_buffer));
    3289          29 : }
    3290             : 
    3291           0 : void ValueDeserializer::TransferSharedArrayBuffer(
    3292             :     uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) {
    3293           0 :   CHECK(!private_->has_aborted);
    3294             :   private_->deserializer.TransferArrayBuffer(
    3295           0 :       transfer_id, Utils::OpenHandle(*shared_array_buffer));
    3296           0 : }
    3297             : 
    3298           2 : bool ValueDeserializer::ReadUint32(uint32_t* value) {
    3299           2 :   return private_->deserializer.ReadUint32(value);
    3300             : }
    3301             : 
    3302           2 : bool ValueDeserializer::ReadUint64(uint64_t* value) {
    3303           2 :   return private_->deserializer.ReadUint64(value);
    3304             : }
    3305             : 
    3306           4 : bool ValueDeserializer::ReadDouble(double* value) {
    3307           4 :   return private_->deserializer.ReadDouble(value);
    3308             : }
    3309             : 
    3310          13 : bool ValueDeserializer::ReadRawBytes(size_t length, const void** data) {
    3311          13 :   return private_->deserializer.ReadRawBytes(length, data);
    3312             : }
    3313             : 
    3314             : // --- D a t a ---
    3315             : 
    3316           0 : bool Value::FullIsUndefined() const {
    3317             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3318           0 :   bool result = object->IsUndefined();
    3319             :   DCHECK_EQ(result, QuickIsUndefined());
    3320           0 :   return result;
    3321             : }
    3322             : 
    3323             : 
    3324           0 : bool Value::FullIsNull() const {
    3325             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3326           0 :   bool result = object->IsNull();
    3327             :   DCHECK_EQ(result, QuickIsNull());
    3328           0 :   return result;
    3329             : }
    3330             : 
    3331             : 
    3332       70923 : bool Value::IsTrue() const {
    3333             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3334      141846 :   if (object->IsSmi()) return false;
    3335      141846 :   return object->IsTrue();
    3336             : }
    3337             : 
    3338             : 
    3339         118 : bool Value::IsFalse() const {
    3340             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3341         236 :   if (object->IsSmi()) return false;
    3342         236 :   return object->IsFalse();
    3343             : }
    3344             : 
    3345             : 
    3346    11212017 : bool Value::IsFunction() const { return Utils::OpenHandle(this)->IsCallable(); }
    3347             : 
    3348             : 
    3349       16635 : bool Value::IsName() const {
    3350       33270 :   return Utils::OpenHandle(this)->IsName();
    3351             : }
    3352             : 
    3353             : 
    3354           0 : bool Value::FullIsString() const {
    3355           0 :   bool result = Utils::OpenHandle(this)->IsString();
    3356             :   DCHECK_EQ(result, QuickIsString());
    3357           0 :   return result;
    3358             : }
    3359             : 
    3360             : 
    3361     9303187 : bool Value::IsSymbol() const {
    3362    18606374 :   return Utils::OpenHandle(this)->IsSymbol();
    3363             : }
    3364             : 
    3365             : 
    3366     1879571 : bool Value::IsArray() const {
    3367     3759140 :   return Utils::OpenHandle(this)->IsJSArray();
    3368             : }
    3369             : 
    3370             : 
    3371     1263142 : bool Value::IsArrayBuffer() const {
    3372             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3373     2802957 :   return obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared();
    3374             : }
    3375             : 
    3376             : 
    3377          75 : bool Value::IsArrayBufferView() const {
    3378         150 :   return Utils::OpenHandle(this)->IsJSArrayBufferView();
    3379             : }
    3380             : 
    3381             : 
    3382      896806 : bool Value::IsTypedArray() const {
    3383     1793612 :   return Utils::OpenHandle(this)->IsJSTypedArray();
    3384             : }
    3385             : 
    3386             : #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype)                    \
    3387             :   bool Value::Is##Type##Array() const {                                      \
    3388             :     i::Handle<i::Object> obj = Utils::OpenHandle(this);                      \
    3389             :     return obj->IsJSTypedArray() &&                                          \
    3390             :            i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \
    3391             :   }
    3392             : 
    3393         296 : TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
    3394             : 
    3395             : #undef VALUE_IS_TYPED_ARRAY
    3396             : 
    3397             : 
    3398      893064 : bool Value::IsDataView() const {
    3399     1786128 :   return Utils::OpenHandle(this)->IsJSDataView();
    3400             : }
    3401             : 
    3402             : 
    3403     1262241 : bool Value::IsSharedArrayBuffer() const {
    3404             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3405     2803702 :   return obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared();
    3406             : }
    3407             : 
    3408             : 
    3409    24952737 : bool Value::IsObject() const { return Utils::OpenHandle(this)->IsJSReceiver(); }
    3410             : 
    3411             : 
    3412     3704417 : bool Value::IsNumber() const {
    3413     7408834 :   return Utils::OpenHandle(this)->IsNumber();
    3414             : }
    3415             : 
    3416    10066392 : bool Value::IsBigInt() const { return Utils::OpenHandle(this)->IsBigInt(); }
    3417             : 
    3418     2965074 : bool Value::IsProxy() const { return Utils::OpenHandle(this)->IsJSProxy(); }
    3419             : 
    3420             : #define VALUE_IS_SPECIFIC_TYPE(Type, Check)             \
    3421             :   bool Value::Is##Type() const {                        \
    3422             :     i::Handle<i::Object> obj = Utils::OpenHandle(this); \
    3423             :     return obj->Is##Check();                            \
    3424             :   }
    3425             : 
    3426     2514666 : VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, JSArgumentsObject)
    3427       65430 : VALUE_IS_SPECIFIC_TYPE(BigIntObject, BigIntWrapper)
    3428       65604 : VALUE_IS_SPECIFIC_TYPE(BooleanObject, BooleanWrapper)
    3429       65478 : VALUE_IS_SPECIFIC_TYPE(NumberObject, NumberWrapper)
    3430      100191 : VALUE_IS_SPECIFIC_TYPE(StringObject, StringWrapper)
    3431       65409 : VALUE_IS_SPECIFIC_TYPE(SymbolObject, SymbolWrapper)
    3432     2694753 : VALUE_IS_SPECIFIC_TYPE(Date, JSDate)
    3433     2952342 : VALUE_IS_SPECIFIC_TYPE(Map, JSMap)
    3434     2951559 : VALUE_IS_SPECIFIC_TYPE(Set, JSSet)
    3435     2681223 : VALUE_IS_SPECIFIC_TYPE(WeakMap, JSWeakMap)
    3436     2681076 : VALUE_IS_SPECIFIC_TYPE(WeakSet, JSWeakSet)
    3437         138 : VALUE_IS_SPECIFIC_TYPE(WebAssemblyCompiledModule, WasmModuleObject)
    3438             : 
    3439             : #undef VALUE_IS_SPECIFIC_TYPE
    3440             : 
    3441             : 
    3442     3748408 : bool Value::IsBoolean() const {
    3443     7496816 :   return Utils::OpenHandle(this)->IsBoolean();
    3444             : }
    3445             : 
    3446          97 : bool Value::IsExternal() const {
    3447             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3448         194 :   if (!obj->IsHeapObject()) return false;
    3449          97 :   i::Handle<i::HeapObject> heap_obj = i::Handle<i::HeapObject>::cast(obj);
    3450             :   // Check the instance type is JS_OBJECT (instance type of Externals) before
    3451             :   // attempting to get the Isolate since that guarantees the object is writable
    3452             :   // and GetIsolate will work.
    3453          97 :   if (heap_obj->map()->instance_type() != i::JS_OBJECT_TYPE) return false;
    3454             :   i::Isolate* isolate = i::JSObject::cast(*heap_obj)->GetIsolate();
    3455          52 :   return heap_obj->IsExternal(isolate);
    3456             : }
    3457             : 
    3458             : 
    3459      548208 : bool Value::IsInt32() const {
    3460             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3461     1096416 :   if (obj->IsSmi()) return true;
    3462          72 :   if (obj->IsNumber()) {
    3463          72 :     return i::IsInt32Double(obj->Number());
    3464             :   }
    3465             :   return false;
    3466             : }
    3467             : 
    3468             : 
    3469        9869 : bool Value::IsUint32() const {
    3470             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3471       27378 :   if (obj->IsSmi()) return i::Smi::ToInt(*obj) >= 0;
    3472        4458 :   if (obj->IsNumber()) {
    3473         113 :     double value = obj->Number();
    3474         107 :     return !i::IsMinusZero(value) &&
    3475          95 :         value >= 0 &&
    3476         202 :         value <= i::kMaxUInt32 &&
    3477         113 :         value == i::FastUI2D(i::FastD2UI(value));
    3478             :   }
    3479             :   return false;
    3480             : }
    3481             : 
    3482             : 
    3483      900870 : bool Value::IsNativeError() const {
    3484     1801740 :   return Utils::OpenHandle(this)->IsJSError();
    3485             : }
    3486             : 
    3487             : 
    3488     3237951 : bool Value::IsRegExp() const {
    3489             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3490     6475902 :   return obj->IsJSRegExp();
    3491             : }
    3492             : 
    3493          12 : bool Value::IsAsyncFunction() const {
    3494             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3495          24 :   if (!obj->IsJSFunction()) return false;
    3496          12 :   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
    3497          24 :   return i::IsAsyncFunction(func->shared()->kind());
    3498             : }
    3499             : 
    3500          90 : bool Value::IsGeneratorFunction() const {
    3501             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3502         180 :   if (!obj->IsJSFunction()) return false;
    3503          73 :   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
    3504         146 :   return i::IsGeneratorFunction(func->shared()->kind());
    3505             : }
    3506             : 
    3507             : 
    3508     1062655 : bool Value::IsGeneratorObject() const {
    3509     2125310 :   return Utils::OpenHandle(this)->IsJSGeneratorObject();
    3510             : }
    3511             : 
    3512             : 
    3513      893613 : bool Value::IsMapIterator() const {
    3514     1787226 :   return Utils::OpenHandle(this)->IsJSMapIterator();
    3515             : }
    3516             : 
    3517             : 
    3518      893501 : bool Value::IsSetIterator() const {
    3519     1787002 :   return Utils::OpenHandle(this)->IsJSSetIterator();
    3520             : }
    3521             : 
    3522     2727780 : bool Value::IsPromise() const { return Utils::OpenHandle(this)->IsJSPromise(); }
    3523             : 
    3524           5 : bool Value::IsModuleNamespaceObject() const {
    3525          10 :   return Utils::OpenHandle(this)->IsJSModuleNamespace();
    3526             : }
    3527             : 
    3528    13337339 : MaybeLocal<String> Value::ToString(Local<Context> context) const {
    3529             :   auto obj = Utils::OpenHandle(this);
    3530    26674678 :   if (obj->IsString()) return ToApiHandle<String>(obj);
    3531     7515512 :   PREPARE_FOR_EXECUTION(context, Object, ToString, String);
    3532             :   Local<String> result;
    3533             :   has_pending_exception =
    3534     1878878 :       !ToLocal<String>(i::Object::ToString(isolate, obj), &result);
    3535     1878878 :   RETURN_ON_FAILED_EXECUTION(String);
    3536     1878775 :   RETURN_ESCAPED(result);
    3537             : }
    3538             : 
    3539             : 
    3540           0 : Local<String> Value::ToString(Isolate* isolate) const {
    3541           0 :   RETURN_TO_LOCAL_UNCHECKED(ToString(isolate->GetCurrentContext()), String);
    3542             : }
    3543             : 
    3544             : 
    3545          15 : MaybeLocal<String> Value::ToDetailString(Local<Context> context) const {
    3546             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3547          30 :   if (obj->IsString()) return ToApiHandle<String>(obj);
    3548          60 :   PREPARE_FOR_EXECUTION(context, Object, ToDetailString, String);
    3549             :   Local<String> result =
    3550          15 :       Utils::ToLocal(i::Object::NoSideEffectsToString(isolate, obj));
    3551             :   RETURN_ON_FAILED_EXECUTION(String);
    3552          15 :   RETURN_ESCAPED(result);
    3553             : }
    3554             : 
    3555             : 
    3556         389 : MaybeLocal<Object> Value::ToObject(Local<Context> context) const {
    3557             :   auto obj = Utils::OpenHandle(this);
    3558         778 :   if (obj->IsJSReceiver()) return ToApiHandle<Object>(obj);
    3559          24 :   PREPARE_FOR_EXECUTION(context, Object, ToObject, Object);
    3560             :   Local<Object> result;
    3561             :   has_pending_exception =
    3562           6 :       !ToLocal<Object>(i::Object::ToObject(isolate, obj), &result);
    3563           6 :   RETURN_ON_FAILED_EXECUTION(Object);
    3564           0 :   RETURN_ESCAPED(result);
    3565             : }
    3566             : 
    3567             : 
    3568           0 : Local<v8::Object> Value::ToObject(Isolate* isolate) const {
    3569           0 :   RETURN_TO_LOCAL_UNCHECKED(ToObject(isolate->GetCurrentContext()), Object);
    3570             : }
    3571             : 
    3572          56 : MaybeLocal<BigInt> Value::ToBigInt(Local<Context> context) const {
    3573             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3574         112 :   if (obj->IsBigInt()) return ToApiHandle<BigInt>(obj);
    3575         128 :   PREPARE_FOR_EXECUTION(context, Object, ToBigInt, BigInt);
    3576             :   Local<BigInt> result;
    3577             :   has_pending_exception =
    3578          32 :       !ToLocal<BigInt>(i::BigInt::FromObject(isolate, obj), &result);
    3579          32 :   RETURN_ON_FAILED_EXECUTION(BigInt);
    3580          16 :   RETURN_ESCAPED(result);
    3581             : }
    3582             : 
    3583       31239 : bool Value::BooleanValue(Isolate* v8_isolate) const {
    3584             :   return Utils::OpenHandle(this)->BooleanValue(
    3585       31239 :       reinterpret_cast<i::Isolate*>(v8_isolate));
    3586             : }
    3587             : 
    3588           0 : MaybeLocal<Boolean> Value::ToBoolean(Local<Context> context) const {
    3589           0 :   return ToBoolean(context->GetIsolate());
    3590             : }
    3591             : 
    3592             : 
    3593          60 : Local<Boolean> Value::ToBoolean(Isolate* v8_isolate) const {
    3594             :   auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3595             :   return ToApiHandle<Boolean>(
    3596          60 :       isolate->factory()->ToBoolean(BooleanValue(v8_isolate)));
    3597             : }
    3598             : 
    3599             : 
    3600        4167 : MaybeLocal<Number> Value::ToNumber(Local<Context> context) const {
    3601             :   auto obj = Utils::OpenHandle(this);
    3602        8334 :   if (obj->IsNumber()) return ToApiHandle<Number>(obj);
    3603         536 :   PREPARE_FOR_EXECUTION(context, Object, ToNumber, Number);
    3604             :   Local<Number> result;
    3605             :   has_pending_exception =
    3606         134 :       !ToLocal<Number>(i::Object::ToNumber(isolate, obj), &result);
    3607         134 :   RETURN_ON_FAILED_EXECUTION(Number);
    3608         128 :   RETURN_ESCAPED(result);
    3609             : }
    3610             : 
    3611             : 
    3612           0 : Local<Number> Value::ToNumber(Isolate* isolate) const {
    3613           0 :   RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number);
    3614             : }
    3615             : 
    3616             : 
    3617           6 : MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const {
    3618             :   auto obj = Utils::OpenHandle(this);
    3619          12 :   if (obj->IsSmi()) return ToApiHandle<Integer>(obj);
    3620          24 :   PREPARE_FOR_EXECUTION(context, Object, ToInteger, Integer);
    3621             :   Local<Integer> result;
    3622             :   has_pending_exception =
    3623           6 :       !ToLocal<Integer>(i::Object::ToInteger(isolate, obj), &result);
    3624           6 :   RETURN_ON_FAILED_EXECUTION(Integer);
    3625           0 :   RETURN_ESCAPED(result);
    3626             : }
    3627             : 
    3628             : 
    3629           0 : Local<Integer> Value::ToInteger(Isolate* isolate) const {
    3630           0 :   RETURN_TO_LOCAL_UNCHECKED(ToInteger(isolate->GetCurrentContext()), Integer);
    3631             : }
    3632             : 
    3633             : 
    3634        2634 : MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const {
    3635             :   auto obj = Utils::OpenHandle(this);
    3636        5268 :   if (obj->IsSmi()) return ToApiHandle<Int32>(obj);
    3637             :   Local<Int32> result;
    3638        4068 :   PREPARE_FOR_EXECUTION(context, Object, ToInt32, Int32);
    3639             :   has_pending_exception =
    3640        1017 :       !ToLocal<Int32>(i::Object::ToInt32(isolate, obj), &result);
    3641        1017 :   RETURN_ON_FAILED_EXECUTION(Int32);
    3642        1011 :   RETURN_ESCAPED(result);
    3643             : }
    3644             : 
    3645             : 
    3646           0 : Local<Int32> Value::ToInt32(Isolate* isolate) const {
    3647           0 :   RETURN_TO_LOCAL_UNCHECKED(ToInt32(isolate->GetCurrentContext()), Int32);
    3648             : }
    3649             : 
    3650             : 
    3651          48 : MaybeLocal<Uint32> Value::ToUint32(Local<Context> context) const {
    3652             :   auto obj = Utils::OpenHandle(this);
    3653          96 :   if (obj->IsSmi()) return ToApiHandle<Uint32>(obj);
    3654             :   Local<Uint32> result;
    3655         144 :   PREPARE_FOR_EXECUTION(context, Object, ToUint32, Uint32);
    3656             :   has_pending_exception =
    3657          36 :       !ToLocal<Uint32>(i::Object::ToUint32(isolate, obj), &result);
    3658          36 :   RETURN_ON_FAILED_EXECUTION(Uint32);
    3659          30 :   RETURN_ESCAPED(result);
    3660             : }
    3661             : 
    3662         959 : i::Isolate* i::IsolateFromNeverReadOnlySpaceObject(i::Address obj) {
    3663             :   return i::NeverReadOnlySpaceObject::GetIsolate(
    3664         959 :       i::HeapObject::cast(i::Object(obj)));
    3665             : }
    3666             : 
    3667          96 : bool i::ShouldThrowOnError(i::Isolate* isolate) {
    3668          96 :   return i::GetShouldThrow(isolate, Nothing<i::ShouldThrow>()) ==
    3669          96 :          i::ShouldThrow::kThrowOnError;
    3670             : }
    3671             : 
    3672           0 : void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
    3673           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    3674           0 :   Utils::ApiCheck(isolate != nullptr && !isolate->IsDead(),
    3675             :                   "v8::internal::Internals::CheckInitialized",
    3676             :                   "Isolate is not initialized or V8 has died");
    3677           0 : }
    3678             : 
    3679             : 
    3680           0 : void External::CheckCast(v8::Value* that) {
    3681           0 :   Utils::ApiCheck(that->IsExternal(), "v8::External::Cast",
    3682             :                   "Could not convert to external");
    3683           0 : }
    3684             : 
    3685             : 
    3686           0 : void v8::Object::CheckCast(Value* that) {
    3687             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3688           0 :   Utils::ApiCheck(obj->IsJSReceiver(), "v8::Object::Cast",
    3689             :                   "Could not convert to object");
    3690           0 : }
    3691             : 
    3692             : 
    3693           0 : void v8::Function::CheckCast(Value* that) {
    3694             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3695           0 :   Utils::ApiCheck(obj->IsCallable(), "v8::Function::Cast",
    3696             :                   "Could not convert to function");
    3697           0 : }
    3698             : 
    3699             : 
    3700           0 : void v8::Boolean::CheckCast(v8::Value* that) {
    3701             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3702           0 :   Utils::ApiCheck(obj->IsBoolean(), "v8::Boolean::Cast",
    3703             :                   "Could not convert to boolean");
    3704           0 : }
    3705             : 
    3706             : 
    3707           0 : void v8::Name::CheckCast(v8::Value* that) {
    3708             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3709           0 :   Utils::ApiCheck(obj->IsName(), "v8::Name::Cast", "Could not convert to name");
    3710           0 : }
    3711             : 
    3712             : 
    3713           0 : void v8::String::CheckCast(v8::Value* that) {
    3714             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3715           0 :   Utils::ApiCheck(obj->IsString(), "v8::String::Cast",
    3716             :                   "Could not convert to string");
    3717           0 : }
    3718             : 
    3719             : 
    3720           0 : void v8::Symbol::CheckCast(v8::Value* that) {
    3721             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3722           0 :   Utils::ApiCheck(obj->IsSymbol(), "v8::Symbol::Cast",
    3723             :                   "Could not convert to symbol");
    3724           0 : }
    3725             : 
    3726             : 
    3727           0 : void v8::Private::CheckCast(v8::Data* that) {
    3728             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3729           0 :   Utils::ApiCheck(obj->IsSymbol() &&
    3730           0 :                   i::Handle<i::Symbol>::cast(obj)->is_private(),
    3731             :                   "v8::Private::Cast",
    3732             :                   "Could not convert to private");
    3733           0 : }
    3734             : 
    3735             : 
    3736           0 : void v8::Number::CheckCast(v8::Value* that) {
    3737             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3738           0 :   Utils::ApiCheck(obj->IsNumber(),
    3739             :                   "v8::Number::Cast()",
    3740             :                   "Could not convert to number");
    3741           0 : }
    3742             : 
    3743             : 
    3744           0 : void v8::Integer::CheckCast(v8::Value* that) {
    3745             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3746           0 :   Utils::ApiCheck(obj->IsNumber(), "v8::Integer::Cast",
    3747             :                   "Could not convert to number");
    3748           0 : }
    3749             : 
    3750             : 
    3751           0 : void v8::Int32::CheckCast(v8::Value* that) {
    3752           0 :   Utils::ApiCheck(that->IsInt32(), "v8::Int32::Cast",
    3753             :                   "Could not convert to 32-bit signed integer");
    3754           0 : }
    3755             : 
    3756             : 
    3757           0 : void v8::Uint32::CheckCast(v8::Value* that) {
    3758           0 :   Utils::ApiCheck(that->IsUint32(), "v8::Uint32::Cast",
    3759             :                   "Could not convert to 32-bit unsigned integer");
    3760           0 : }
    3761             : 
    3762           0 : void v8::BigInt::CheckCast(v8::Value* that) {
    3763           0 :   Utils::ApiCheck(that->IsBigInt(), "v8::BigInt::Cast",
    3764             :                   "Could not convert to BigInt");
    3765           0 : }
    3766             : 
    3767           0 : void v8::Array::CheckCast(Value* that) {
    3768             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3769           0 :   Utils::ApiCheck(obj->IsJSArray(), "v8::Array::Cast",
    3770             :                   "Could not convert to array");
    3771           0 : }
    3772             : 
    3773             : 
    3774           0 : void v8::Map::CheckCast(Value* that) {
    3775             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3776           0 :   Utils::ApiCheck(obj->IsJSMap(), "v8::Map::Cast", "Could not convert to Map");
    3777           0 : }
    3778             : 
    3779             : 
    3780           0 : void v8::Set::CheckCast(Value* that) {
    3781             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3782           0 :   Utils::ApiCheck(obj->IsJSSet(), "v8_Set_Cast", "Could not convert to Set");
    3783           0 : }
    3784             : 
    3785             : 
    3786           0 : void v8::Promise::CheckCast(Value* that) {
    3787           0 :   Utils::ApiCheck(that->IsPromise(), "v8::Promise::Cast",
    3788             :                   "Could not convert to promise");
    3789           0 : }
    3790             : 
    3791             : 
    3792           0 : void v8::Promise::Resolver::CheckCast(Value* that) {
    3793           0 :   Utils::ApiCheck(that->IsPromise(), "v8::Promise::Resolver::Cast",
    3794             :                   "Could not convert to promise resolver");
    3795           0 : }
    3796             : 
    3797             : 
    3798           0 : void v8::Proxy::CheckCast(Value* that) {
    3799           0 :   Utils::ApiCheck(that->IsProxy(), "v8::Proxy::Cast",
    3800             :                   "Could not convert to proxy");
    3801           0 : }
    3802             : 
    3803           0 : void v8::WasmModuleObject::CheckCast(Value* that) {
    3804           0 :   Utils::ApiCheck(that->IsWebAssemblyCompiledModule(),
    3805             :                   "v8::WasmModuleObject::Cast",
    3806             :                   "Could not convert to wasm module object");
    3807           0 : }
    3808             : 
    3809           0 : void v8::ArrayBuffer::CheckCast(Value* that) {
    3810             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3811             :   Utils::ApiCheck(
    3812           0 :       obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(),
    3813             :       "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer");
    3814           0 : }
    3815             : 
    3816             : 
    3817           0 : void v8::ArrayBufferView::CheckCast(Value* that) {
    3818             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3819           0 :   Utils::ApiCheck(obj->IsJSArrayBufferView(),
    3820             :                   "v8::ArrayBufferView::Cast()",
    3821             :                   "Could not convert to ArrayBufferView");
    3822           0 : }
    3823             : 
    3824             : 
    3825           0 : void v8::TypedArray::CheckCast(Value* that) {
    3826             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3827           0 :   Utils::ApiCheck(obj->IsJSTypedArray(),
    3828             :                   "v8::TypedArray::Cast()",
    3829             :                   "Could not convert to TypedArray");
    3830           0 : }
    3831             : 
    3832             : #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype)                   \
    3833             :   void v8::Type##Array::CheckCast(Value* that) {                              \
    3834             :     i::Handle<i::Object> obj = Utils::OpenHandle(that);                       \
    3835             :     Utils::ApiCheck(                                                          \
    3836             :         obj->IsJSTypedArray() &&                                              \
    3837             :             i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array, \
    3838             :         "v8::" #Type "Array::Cast()", "Could not convert to " #Type "Array"); \
    3839             :   }
    3840             : 
    3841           0 : TYPED_ARRAYS(CHECK_TYPED_ARRAY_CAST)
    3842             : 
    3843             : #undef CHECK_TYPED_ARRAY_CAST
    3844             : 
    3845             : 
    3846           0 : void v8::DataView::CheckCast(Value* that) {
    3847             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3848           0 :   Utils::ApiCheck(obj->IsJSDataView(),
    3849             :                   "v8::DataView::Cast()",
    3850             :                   "Could not convert to DataView");
    3851           0 : }
    3852             : 
    3853             : 
    3854           0 : void v8::SharedArrayBuffer::CheckCast(Value* that) {
    3855             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3856             :   Utils::ApiCheck(
    3857           0 :       obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(),
    3858             :       "v8::SharedArrayBuffer::Cast()",
    3859             :       "Could not convert to SharedArrayBuffer");
    3860           0 : }
    3861             : 
    3862             : 
    3863           0 : void v8::Date::CheckCast(v8::Value* that) {
    3864             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3865           0 :   Utils::ApiCheck(obj->IsJSDate(), "v8::Date::Cast()",
    3866             :                   "Could not convert to date");
    3867           0 : }
    3868             : 
    3869             : 
    3870           0 : void v8::StringObject::CheckCast(v8::Value* that) {
    3871             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3872           0 :   Utils::ApiCheck(obj->IsStringWrapper(), "v8::StringObject::Cast()",
    3873             :                   "Could not convert to StringObject");
    3874           0 : }
    3875             : 
    3876             : 
    3877           0 : void v8::SymbolObject::CheckCast(v8::Value* that) {
    3878             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3879           0 :   Utils::ApiCheck(obj->IsSymbolWrapper(), "v8::SymbolObject::Cast()",
    3880             :                   "Could not convert to SymbolObject");
    3881           0 : }
    3882             : 
    3883             : 
    3884           0 : void v8::NumberObject::CheckCast(v8::Value* that) {
    3885             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3886           0 :   Utils::ApiCheck(obj->IsNumberWrapper(), "v8::NumberObject::Cast()",
    3887             :                   "Could not convert to NumberObject");
    3888           0 : }
    3889             : 
    3890           0 : void v8::BigIntObject::CheckCast(v8::Value* that) {
    3891             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3892           0 :   Utils::ApiCheck(obj->IsBigIntWrapper(), "v8::BigIntObject::Cast()",
    3893             :                   "Could not convert to BigIntObject");
    3894           0 : }
    3895             : 
    3896           0 : void v8::BooleanObject::CheckCast(v8::Value* that) {
    3897             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3898           0 :   Utils::ApiCheck(obj->IsBooleanWrapper(), "v8::BooleanObject::Cast()",
    3899             :                   "Could not convert to BooleanObject");
    3900           0 : }
    3901             : 
    3902             : 
    3903           0 : void v8::RegExp::CheckCast(v8::Value* that) {
    3904             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3905           0 :   Utils::ApiCheck(obj->IsJSRegExp(),
    3906             :                   "v8::RegExp::Cast()",
    3907             :                   "Could not convert to regular expression");
    3908           0 : }
    3909             : 
    3910             : 
    3911           0 : Maybe<bool> Value::BooleanValue(Local<Context> context) const {
    3912           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3913           0 :   return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
    3914             : }
    3915             : 
    3916             : 
    3917       38222 : Maybe<double> Value::NumberValue(Local<Context> context) const {
    3918             :   auto obj = Utils::OpenHandle(this);
    3919      113623 :   if (obj->IsNumber()) return Just(obj->Number());
    3920        2086 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3921        4172 :   ENTER_V8(isolate, context, Value, NumberValue, Nothing<double>(),
    3922             :            i::HandleScope);
    3923             :   i::Handle<i::Object> num;
    3924        2086 :   has_pending_exception = !i::Object::ToNumber(isolate, obj).ToHandle(&num);
    3925        1043 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(double);
    3926         973 :   return Just(num->Number());
    3927             : }
    3928             : 
    3929             : 
    3930        2154 : Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
    3931             :   auto obj = Utils::OpenHandle(this);
    3932        4308 :   if (obj->IsNumber()) {
    3933        2136 :     return Just(NumberToInt64(*obj));
    3934             :   }
    3935          36 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3936          72 :   ENTER_V8(isolate, context, Value, IntegerValue, Nothing<int64_t>(),
    3937             :            i::HandleScope);
    3938             :   i::Handle<i::Object> num;
    3939          36 :   has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num);
    3940          18 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t);
    3941           6 :   return Just(NumberToInt64(*num));
    3942             : }
    3943             : 
    3944             : 
    3945      538826 : Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
    3946             :   auto obj = Utils::OpenHandle(this);
    3947     1616424 :   if (obj->IsNumber()) return Just(NumberToInt32(*obj));
    3948         108 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3949         216 :   ENTER_V8(isolate, context, Value, Int32Value, Nothing<int32_t>(),
    3950             :            i::HandleScope);
    3951             :   i::Handle<i::Object> num;
    3952         108 :   has_pending_exception = !i::Object::ToInt32(isolate, obj).ToHandle(&num);
    3953          54 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int32_t);
    3954          96 :   return Just(num->IsSmi() ? i::Smi::ToInt(*num)
    3955          96 :                            : static_cast<int32_t>(num->Number()));
    3956             : }
    3957             : 
    3958             : 
    3959         211 : Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
    3960             :   auto obj = Utils::OpenHandle(this);
    3961         627 :   if (obj->IsNumber()) return Just(NumberToUint32(*obj));
    3962          12 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3963          24 :   ENTER_V8(isolate, context, Value, Uint32Value, Nothing<uint32_t>(),
    3964             :            i::HandleScope);
    3965             :   i::Handle<i::Object> num;
    3966          12 :   has_pending_exception = !i::Object::ToUint32(isolate, obj).ToHandle(&num);
    3967           6 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(uint32_t);
    3968           0 :   return Just(num->IsSmi() ? static_cast<uint32_t>(i::Smi::ToInt(*num))
    3969           0 :                            : static_cast<uint32_t>(num->Number()));
    3970             : }
    3971             : 
    3972             : 
    3973          42 : MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
    3974             :   auto self = Utils::OpenHandle(this);
    3975          84 :   if (self->IsSmi()) {
    3976          12 :     if (i::Smi::ToInt(*self) >= 0) return Utils::Uint32ToLocal(self);
    3977           6 :     return Local<Uint32>();
    3978             :   }
    3979         120 :   PREPARE_FOR_EXECUTION(context, Object, ToArrayIndex, Uint32);
    3980             :   i::Handle<i::Object> string_obj;
    3981             :   has_pending_exception =
    3982          60 :       !i::Object::ToString(isolate, self).ToHandle(&string_obj);
    3983          30 :   RETURN_ON_FAILED_EXECUTION(Uint32);
    3984          30 :   i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj);
    3985             :   uint32_t index;
    3986          30 :   if (str->AsArrayIndex(&index)) {
    3987             :     i::Handle<i::Object> value;
    3988          12 :     if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
    3989             :       value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate);
    3990             :     } else {
    3991           6 :       value = isolate->factory()->NewNumber(index);
    3992             :     }
    3993          12 :     RETURN_ESCAPED(Utils::Uint32ToLocal(value));
    3994             :   }
    3995          18 :   return Local<Uint32>();
    3996             : }
    3997             : 
    3998             : 
    3999      155036 : Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
    4000             :   i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
    4001      155036 :   auto self = Utils::OpenHandle(this);
    4002      155036 :   auto other = Utils::OpenHandle(*that);
    4003      155036 :   return i::Object::Equals(isolate, self, other);
    4004             : }
    4005             : 
    4006             : 
    4007        1344 : bool Value::StrictEquals(Local<Value> that) const {
    4008             :   auto self = Utils::OpenHandle(this);
    4009             :   auto other = Utils::OpenHandle(*that);
    4010        1344 :   return self->StrictEquals(*other);
    4011             : }
    4012             : 
    4013             : 
    4014      123304 : bool Value::SameValue(Local<Value> that) const {
    4015             :   auto self = Utils::OpenHandle(this);
    4016             :   auto other = Utils::OpenHandle(*that);
    4017      123304 :   return self->SameValue(*other);
    4018             : }
    4019             : 
    4020          50 : Local<String> Value::TypeOf(v8::Isolate* external_isolate) {
    4021          50 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    4022             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4023         100 :   LOG_API(isolate, Value, TypeOf);
    4024         100 :   return Utils::ToLocal(i::Object::TypeOf(isolate, Utils::OpenHandle(this)));
    4025             : }
    4026             : 
    4027          82 : Maybe<bool> Value::InstanceOf(v8::Local<v8::Context> context,
    4028             :                               v8::Local<v8::Object> object) {
    4029         164 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4030         328 :   ENTER_V8(isolate, context, Value, InstanceOf, Nothing<bool>(),
    4031             :            i::HandleScope);
    4032          82 :   auto left = Utils::OpenHandle(this);
    4033             :   auto right = Utils::OpenHandle(*object);
    4034             :   i::Handle<i::Object> result;
    4035             :   has_pending_exception =
    4036         164 :       !i::Object::InstanceOf(isolate, left, right).ToHandle(&result);
    4037          82 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4038         140 :   return Just(result->IsTrue(isolate));
    4039             : }
    4040             : 
    4041      187324 : Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
    4042             :                             v8::Local<Value> key, v8::Local<Value> value) {
    4043      374648 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4044      749296 :   ENTER_V8(isolate, context, Object, Set, Nothing<bool>(), i::HandleScope);
    4045             :   auto self = Utils::OpenHandle(this);
    4046      187324 :   auto key_obj = Utils::OpenHandle(*key);
    4047      187324 :   auto value_obj = Utils::OpenHandle(*value);
    4048             :   has_pending_exception =
    4049             :       i::Runtime::SetObjectProperty(isolate, self, key_obj, value_obj,
    4050             :                                     i::StoreOrigin::kMaybeKeyed,
    4051      187324 :                                     Just(i::ShouldThrow::kDontThrow))
    4052      374648 :           .is_null();
    4053      187324 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4054             :   return Just(true);
    4055             : }
    4056             : 
    4057             : 
    4058           0 : bool v8::Object::Set(v8::Local<Value> key, v8::Local<Value> value) {
    4059           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4060           0 :   return Set(context, key, value).FromMaybe(false);
    4061             : }
    4062             : 
    4063             : 
    4064       10983 : Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
    4065             :                             v8::Local<Value> value) {
    4066       21966 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4067       43932 :   ENTER_V8(isolate, context, Object, Set, Nothing<bool>(), i::HandleScope);
    4068             :   auto self = Utils::OpenHandle(this);
    4069       10983 :   auto value_obj = Utils::OpenHandle(*value);
    4070             :   has_pending_exception = i::Object::SetElement(isolate, self, index, value_obj,
    4071       10983 :                                                 i::ShouldThrow::kDontThrow)
    4072       21966 :                               .is_null();
    4073       10983 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4074             :   return Just(true);
    4075             : }
    4076             : 
    4077             : 
    4078           0 : bool v8::Object::Set(uint32_t index, v8::Local<Value> value) {
    4079           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4080           0 :   return Set(context, index, value).FromMaybe(false);
    4081             : }
    4082             : 
    4083             : 
    4084       17975 : Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
    4085             :                                            v8::Local<Name> key,
    4086             :                                            v8::Local<Value> value) {
    4087       35950 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4088       71900 :   ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(),
    4089             :            i::HandleScope);
    4090       17975 :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4091       17975 :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4092       17975 :   i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
    4093             : 
    4094             :   Maybe<bool> result = i::JSReceiver::CreateDataProperty(
    4095       17975 :       isolate, self, key_obj, value_obj, Just(i::kDontThrow));
    4096       17975 :   has_pending_exception = result.IsNothing();
    4097       17975 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4098       17970 :   return result;
    4099             : }
    4100             : 
    4101             : 
    4102       11755 : Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
    4103             :                                            uint32_t index,
    4104             :                                            v8::Local<Value> value) {
    4105       23510 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4106       47020 :   ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(),
    4107             :            i::HandleScope);
    4108             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4109       11755 :   i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
    4110             : 
    4111             :   i::LookupIterator it(isolate, self, index, self, i::LookupIterator::OWN);
    4112             :   Maybe<bool> result =
    4113       11755 :       i::JSReceiver::CreateDataProperty(&it, value_obj, Just(i::kDontThrow));
    4114       11755 :   has_pending_exception = result.IsNothing();
    4115       11755 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4116       11755 :   return result;
    4117             : }
    4118             : 
    4119             : struct v8::PropertyDescriptor::PrivateData {
    4120             :   PrivateData() : desc() {}
    4121             :   i::PropertyDescriptor desc;
    4122             : };
    4123             : 
    4124         216 : v8::PropertyDescriptor::PropertyDescriptor() : private_(new PrivateData()) {}
    4125             : 
    4126             : // DataDescriptor
    4127          83 : v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> value)
    4128         166 :     : private_(new PrivateData()) {
    4129             :   private_->desc.set_value(Utils::OpenHandle(*value, true));
    4130          83 : }
    4131             : 
    4132             : // DataDescriptor with writable field
    4133          26 : v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> value,
    4134             :                                            bool writable)
    4135          52 :     : private_(new PrivateData()) {
    4136             :   private_->desc.set_value(Utils::OpenHandle(*value, true));
    4137          26 :   private_->desc.set_writable(writable);
    4138          26 : }
    4139             : 
    4140             : // AccessorDescriptor
    4141          68 : v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> get,
    4142             :                                            v8::Local<v8::Value> set)
    4143         136 :     : private_(new PrivateData()) {
    4144             :   DCHECK(get.IsEmpty() || get->IsUndefined() || get->IsFunction());
    4145             :   DCHECK(set.IsEmpty() || set->IsUndefined() || set->IsFunction());
    4146             :   private_->desc.set_get(Utils::OpenHandle(*get, true));
    4147          68 :   private_->desc.set_set(Utils::OpenHandle(*set, true));
    4148          68 : }
    4149             : 
    4150         285 : v8::PropertyDescriptor::~PropertyDescriptor() { delete private_; }
    4151             : 
    4152          32 : v8::Local<Value> v8::PropertyDescriptor::value() const {
    4153             :   DCHECK(private_->desc.has_value());
    4154          32 :   return Utils::ToLocal(private_->desc.value());
    4155             : }
    4156             : 
    4157          22 : v8::Local<Value> v8::PropertyDescriptor::get() const {
    4158             :   DCHECK(private_->desc.has_get());
    4159          22 :   return Utils::ToLocal(private_->desc.get());
    4160             : }
    4161             : 
    4162          22 : v8::Local<Value> v8::PropertyDescriptor::set() const {
    4163             :   DCHECK(private_->desc.has_set());
    4164          22 :   return Utils::ToLocal(private_->desc.set());
    4165             : }
    4166             : 
    4167          69 : bool v8::PropertyDescriptor::has_value() const {
    4168         138 :   return private_->desc.has_value();
    4169             : }
    4170          69 : bool v8::PropertyDescriptor::has_get() const {
    4171         138 :   return private_->desc.has_get();
    4172             : }
    4173          69 : bool v8::PropertyDescriptor::has_set() const {
    4174         138 :   return private_->desc.has_set();
    4175             : }
    4176             : 
    4177          16 : bool v8::PropertyDescriptor::writable() const {
    4178             :   DCHECK(private_->desc.has_writable());
    4179          32 :   return private_->desc.writable();
    4180             : }
    4181             : 
    4182          69 : bool v8::PropertyDescriptor::has_writable() const {
    4183         138 :   return private_->desc.has_writable();
    4184             : }
    4185             : 
    4186          37 : void v8::PropertyDescriptor::set_enumerable(bool enumerable) {
    4187          37 :   private_->desc.set_enumerable(enumerable);
    4188          37 : }
    4189             : 
    4190          17 : bool v8::PropertyDescriptor::enumerable() const {
    4191             :   DCHECK(private_->desc.has_enumerable());
    4192          34 :   return private_->desc.enumerable();
    4193             : }
    4194             : 
    4195          63 : bool v8::PropertyDescriptor::has_enumerable() const {
    4196         126 :   return private_->desc.has_enumerable();
    4197             : }
    4198             : 
    4199          38 : void v8::PropertyDescriptor::set_configurable(bool configurable) {
    4200          38 :   private_->desc.set_configurable(configurable);
    4201          38 : }
    4202             : 
    4203          32 : bool v8::PropertyDescriptor::configurable() const {
    4204             :   DCHECK(private_->desc.has_configurable());
    4205          64 :   return private_->desc.configurable();
    4206             : }
    4207             : 
    4208          63 : bool v8::PropertyDescriptor::has_configurable() const {
    4209         126 :   return private_->desc.has_configurable();
    4210             : }
    4211             : 
    4212        3336 : Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
    4213             :                                           v8::Local<Name> key,
    4214             :                                           v8::Local<Value> value,
    4215             :                                           v8::PropertyAttribute attributes) {
    4216        6672 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4217             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4218             :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4219             :   i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
    4220             : 
    4221             :   i::PropertyDescriptor desc;
    4222        3336 :   desc.set_writable(!(attributes & v8::ReadOnly));
    4223        3336 :   desc.set_enumerable(!(attributes & v8::DontEnum));
    4224        3336 :   desc.set_configurable(!(attributes & v8::DontDelete));
    4225             :   desc.set_value(value_obj);
    4226             : 
    4227        6672 :   if (self->IsJSProxy()) {
    4228           0 :     ENTER_V8(isolate, context, Object, DefineOwnProperty, Nothing<bool>(),
    4229             :              i::HandleScope);
    4230             :     Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
    4231           0 :         isolate, self, key_obj, &desc, Just(i::kDontThrow));
    4232             :     // Even though we said kDontThrow, there might be accessors that do throw.
    4233             :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4234           0 :     return success;
    4235             :   } else {
    4236             :     // If it's not a JSProxy, i::JSReceiver::DefineOwnProperty should never run
    4237             :     // a script.
    4238       13344 :     ENTER_V8_NO_SCRIPT(isolate, context, Object, DefineOwnProperty,
    4239             :                        Nothing<bool>(), i::HandleScope);
    4240             :     Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
    4241        3336 :         isolate, self, key_obj, &desc, Just(i::kDontThrow));
    4242             :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4243        3336 :     return success;
    4244             :   }
    4245             : }
    4246             : 
    4247         126 : Maybe<bool> v8::Object::DefineProperty(v8::Local<v8::Context> context,
    4248             :                                        v8::Local<Name> key,
    4249             :                                        PropertyDescriptor& descriptor) {
    4250         252 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4251         504 :   ENTER_V8(isolate, context, Object, DefineOwnProperty, Nothing<bool>(),
    4252             :            i::HandleScope);
    4253         126 :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4254             :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4255             : 
    4256             :   Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
    4257             :       isolate, self, key_obj, &descriptor.get_private()->desc,
    4258         252 :       Just(i::kDontThrow));
    4259             :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4260         126 :   return success;
    4261             : }
    4262             : 
    4263      241048 : Maybe<bool> v8::Object::SetPrivate(Local<Context> context, Local<Private> key,
    4264             :                                    Local<Value> value) {
    4265      482096 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4266      964192 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, SetPrivate, Nothing<bool>(),
    4267             :                      i::HandleScope);
    4268             :   auto self = Utils::OpenHandle(this);
    4269      241048 :   auto key_obj = Utils::OpenHandle(reinterpret_cast<Name*>(*key));
    4270             :   auto value_obj = Utils::OpenHandle(*value);
    4271      482096 :   if (self->IsJSProxy()) {
    4272             :     i::PropertyDescriptor desc;
    4273             :     desc.set_writable(true);
    4274             :     desc.set_enumerable(false);
    4275             :     desc.set_configurable(true);
    4276             :     desc.set_value(value_obj);
    4277             :     return i::JSProxy::SetPrivateSymbol(
    4278             :         isolate, i::Handle<i::JSProxy>::cast(self),
    4279          18 :         i::Handle<i::Symbol>::cast(key_obj), &desc, Just(i::kDontThrow));
    4280             :   }
    4281      241030 :   auto js_object = i::Handle<i::JSObject>::cast(self);
    4282      241030 :   i::LookupIterator it(js_object, key_obj, js_object);
    4283             :   has_pending_exception = i::JSObject::DefineOwnPropertyIgnoreAttributes(
    4284             :                               &it, value_obj, i::DONT_ENUM)
    4285      482060 :                               .is_null();
    4286      241030 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4287             :   return Just(true);
    4288             : }
    4289             : 
    4290             : 
    4291      423154 : MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
    4292             :                                   Local<Value> key) {
    4293     1692616 :   PREPARE_FOR_EXECUTION(context, Object, Get, Value);
    4294             :   auto self = Utils::OpenHandle(this);
    4295      423154 :   auto key_obj = Utils::OpenHandle(*key);
    4296             :   i::Handle<i::Object> result;
    4297             :   has_pending_exception =
    4298      846308 :       !i::Runtime::GetObjectProperty(isolate, self, key_obj).ToHandle(&result);
    4299      423154 :   RETURN_ON_FAILED_EXECUTION(Value);
    4300      423088 :   RETURN_ESCAPED(Utils::ToLocal(result));
    4301             : }
    4302             : 
    4303             : 
    4304           0 : Local<Value> v8::Object::Get(v8::Local<Value> key) {
    4305           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4306           0 :   RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
    4307             : }
    4308             : 
    4309             : 
    4310      157901 : MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
    4311      631604 :   PREPARE_FOR_EXECUTION(context, Object, Get, Value);
    4312      157901 :   auto self = Utils::OpenHandle(this);
    4313             :   i::Handle<i::Object> result;
    4314             :   has_pending_exception =
    4315      315802 :       !i::JSReceiver::GetElement(isolate, self, index).ToHandle(&result);
    4316      157901 :   RETURN_ON_FAILED_EXECUTION(Value);
    4317      157882 :   RETURN_ESCAPED(Utils::ToLocal(result));
    4318             : }
    4319             : 
    4320             : 
    4321           0 : Local<Value> v8::Object::Get(uint32_t index) {
    4322           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4323           0 :   RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
    4324             : }
    4325             : 
    4326             : 
    4327        2462 : MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
    4328             :                                          Local<Private> key) {
    4329        2462 :   return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
    4330             : }
    4331             : 
    4332             : 
    4333          58 : Maybe<PropertyAttribute> v8::Object::GetPropertyAttributes(
    4334             :     Local<Context> context, Local<Value> key) {
    4335         116 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4336         232 :   ENTER_V8(isolate, context, Object, GetPropertyAttributes,
    4337             :            Nothing<PropertyAttribute>(), i::HandleScope);
    4338          58 :   auto self = Utils::OpenHandle(this);
    4339             :   auto key_obj = Utils::OpenHandle(*key);
    4340         116 :   if (!key_obj->IsName()) {
    4341             :     has_pending_exception =
    4342          24 :         !i::Object::ToString(isolate, key_obj).ToHandle(&key_obj);
    4343          12 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4344             :   }
    4345          52 :   auto key_name = i::Handle<i::Name>::cast(key_obj);
    4346          52 :   auto result = i::JSReceiver::GetPropertyAttributes(self, key_name);
    4347          52 :   has_pending_exception = result.IsNothing();
    4348          52 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4349          52 :   if (result.FromJust() == i::ABSENT) {
    4350             :     return Just(static_cast<PropertyAttribute>(i::NONE));
    4351             :   }
    4352             :   return Just(static_cast<PropertyAttribute>(result.FromJust()));
    4353             : }
    4354             : 
    4355             : 
    4356        7730 : MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context,
    4357             :                                                        Local<Name> key) {
    4358       30920 :   PREPARE_FOR_EXECUTION(context, Object, GetOwnPropertyDescriptor, Value);
    4359        7730 :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    4360             :   i::Handle<i::Name> key_name = Utils::OpenHandle(*key);
    4361             : 
    4362             :   i::PropertyDescriptor desc;
    4363             :   Maybe<bool> found =
    4364        7730 :       i::JSReceiver::GetOwnPropertyDescriptor(isolate, obj, key_name, &desc);
    4365        7730 :   has_pending_exception = found.IsNothing();
    4366        7730 :   RETURN_ON_FAILED_EXECUTION(Value);
    4367        7730 :   if (!found.FromJust()) {
    4368           5 :     return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    4369             :   }
    4370       15450 :   RETURN_ESCAPED(Utils::ToLocal(desc.ToObject(isolate)));
    4371             : }
    4372             : 
    4373             : 
    4374      260225 : Local<Value> v8::Object::GetPrototype() {
    4375             :   auto isolate = Utils::OpenHandle(this)->GetIsolate();
    4376      260225 :   auto self = Utils::OpenHandle(this);
    4377      260225 :   i::PrototypeIterator iter(isolate, self);
    4378      260225 :   return Utils::ToLocal(i::PrototypeIterator::GetCurrent(iter));
    4379             : }
    4380             : 
    4381             : 
    4382       11193 : Maybe<bool> v8::Object::SetPrototype(Local<Context> context,
    4383             :                                      Local<Value> value) {
    4384       22386 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4385       44772 :   ENTER_V8(isolate, context, Object, SetPrototype, Nothing<bool>(),
    4386             :            i::HandleScope);
    4387       11193 :   auto self = Utils::OpenHandle(this);
    4388       11193 :   auto value_obj = Utils::OpenHandle(*value);
    4389             :   // We do not allow exceptions thrown while setting the prototype
    4390             :   // to propagate outside.
    4391       22386 :   TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
    4392             :   auto result =
    4393       11193 :       i::JSReceiver::SetPrototype(self, value_obj, false, i::kThrowOnError);
    4394       11193 :   has_pending_exception = result.IsNothing();
    4395       11193 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4396             :   return Just(true);
    4397             : }
    4398             : 
    4399             : 
    4400          54 : Local<Object> v8::Object::FindInstanceInPrototypeChain(
    4401             :     v8::Local<FunctionTemplate> tmpl) {
    4402             :   auto self = Utils::OpenHandle(this);
    4403             :   auto isolate = self->GetIsolate();
    4404             :   i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver);
    4405          54 :   auto tmpl_info = *Utils::OpenHandle(*tmpl);
    4406         162 :   while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) {
    4407          72 :     iter.Advance();
    4408          72 :     if (iter.IsAtEnd()) return Local<Object>();
    4409         108 :     if (!iter.GetCurrent()->IsJSObject()) return Local<Object>();
    4410             :   }
    4411             :   // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here.
    4412          36 :   return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate));
    4413             : }
    4414             : 
    4415        5902 : MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) {
    4416             :   return GetPropertyNames(
    4417             :       context, v8::KeyCollectionMode::kIncludePrototypes,
    4418             :       static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS),
    4419        5902 :       v8::IndexFilter::kIncludeIndices);
    4420             : }
    4421             : 
    4422        6613 : MaybeLocal<Array> v8::Object::GetPropertyNames(
    4423             :     Local<Context> context, KeyCollectionMode mode,
    4424             :     PropertyFilter property_filter, IndexFilter index_filter,
    4425             :     KeyConversionMode key_conversion) {
    4426       26452 :   PREPARE_FOR_EXECUTION(context, Object, GetPropertyNames, Array);
    4427        6613 :   auto self = Utils::OpenHandle(this);
    4428             :   i::Handle<i::FixedArray> value;
    4429             :   i::KeyAccumulator accumulator(
    4430             :       isolate, static_cast<i::KeyCollectionMode>(mode),
    4431             :       static_cast<i::PropertyFilter>(property_filter));
    4432        6613 :   accumulator.set_skip_indices(index_filter == IndexFilter::kSkipIndices);
    4433        6613 :   has_pending_exception = accumulator.CollectKeys(self, self).IsNothing();
    4434        6613 :   RETURN_ON_FAILED_EXECUTION(Array);
    4435             :   value =
    4436        6613 :       accumulator.GetKeys(static_cast<i::GetKeysConversion>(key_conversion));
    4437             :   DCHECK(self->map()->EnumLength() == i::kInvalidEnumCacheSentinel ||
    4438             :          self->map()->EnumLength() == 0 ||
    4439             :          self->map()->instance_descriptors()->enum_cache()->keys() != *value);
    4440        6613 :   auto result = isolate->factory()->NewJSArrayWithElements(value);
    4441        6613 :   RETURN_ESCAPED(Utils::ToLocal(result));
    4442             : }
    4443             : 
    4444         591 : MaybeLocal<Array> v8::Object::GetOwnPropertyNames(Local<Context> context) {
    4445             :   return GetOwnPropertyNames(
    4446         591 :       context, static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS));
    4447             : }
    4448             : 
    4449          24 : MaybeLocal<Array> v8::Object::GetOwnPropertyNames(
    4450             :     Local<Context> context, PropertyFilter filter,
    4451             :     KeyConversionMode key_conversion) {
    4452             :   return GetPropertyNames(context, KeyCollectionMode::kOwnOnly, filter,
    4453         615 :                           v8::IndexFilter::kIncludeIndices, key_conversion);
    4454             : }
    4455             : 
    4456         473 : MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) {
    4457        1892 :   PREPARE_FOR_EXECUTION(context, Object, ObjectProtoToString, String);
    4458             :   auto self = Utils::OpenHandle(this);
    4459             :   Local<Value> result;
    4460             :   has_pending_exception =
    4461             :       !ToLocal<Value>(i::Execution::Call(isolate, isolate->object_to_string(),
    4462             :                                          self, 0, nullptr),
    4463        1419 :                       &result);
    4464         473 :   RETURN_ON_FAILED_EXECUTION(String);
    4465         458 :   RETURN_ESCAPED(Local<String>::Cast(result));
    4466             : }
    4467             : 
    4468             : 
    4469     3627440 : Local<String> v8::Object::GetConstructorName() {
    4470     3627440 :   auto self = Utils::OpenHandle(this);
    4471     3627440 :   i::Handle<i::String> name = i::JSReceiver::GetConstructorName(self);
    4472     3627440 :   return Utils::ToLocal(name);
    4473             : }
    4474             : 
    4475           6 : Maybe<bool> v8::Object::SetIntegrityLevel(Local<Context> context,
    4476             :                                           IntegrityLevel level) {
    4477          12 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4478          24 :   ENTER_V8(isolate, context, Object, SetIntegrityLevel, Nothing<bool>(),
    4479             :            i::HandleScope);
    4480           6 :   auto self = Utils::OpenHandle(this);
    4481             :   i::JSReceiver::IntegrityLevel i_level =
    4482           6 :       level == IntegrityLevel::kFrozen ? i::FROZEN : i::SEALED;
    4483             :   Maybe<bool> result =
    4484           6 :       i::JSReceiver::SetIntegrityLevel(self, i_level, i::kThrowOnError);
    4485           6 :   has_pending_exception = result.IsNothing();
    4486           6 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4487           5 :   return result;
    4488             : }
    4489             : 
    4490        7991 : Maybe<bool> v8::Object::Delete(Local<Context> context, Local<Value> key) {
    4491       15982 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4492             :   auto self = Utils::OpenHandle(this);
    4493        7991 :   auto key_obj = Utils::OpenHandle(*key);
    4494       15982 :   if (self->IsJSProxy()) {
    4495           0 :     ENTER_V8(isolate, context, Object, Delete, Nothing<bool>(), i::HandleScope);
    4496             :     Maybe<bool> result = i::Runtime::DeleteObjectProperty(
    4497           0 :         isolate, self, key_obj, i::LanguageMode::kSloppy);
    4498           0 :     has_pending_exception = result.IsNothing();
    4499           0 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4500           0 :     return result;
    4501             :   } else {
    4502             :     // If it's not a JSProxy, i::Runtime::DeleteObjectProperty should never run
    4503             :     // a script.
    4504       31964 :     ENTER_V8_NO_SCRIPT(isolate, context, Object, Delete, Nothing<bool>(),
    4505             :                        i::HandleScope);
    4506             :     Maybe<bool> result = i::Runtime::DeleteObjectProperty(
    4507        7991 :         isolate, self, key_obj, i::LanguageMode::kSloppy);
    4508        7991 :     has_pending_exception = result.IsNothing();
    4509        7991 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4510        7991 :     return result;
    4511             :   }
    4512             : }
    4513             : 
    4514          42 : Maybe<bool> v8::Object::DeletePrivate(Local<Context> context,
    4515             :                                       Local<Private> key) {
    4516          84 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4517             :   // In case of private symbols, i::Runtime::DeleteObjectProperty does not run
    4518             :   // any author script.
    4519         168 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, Delete, Nothing<bool>(),
    4520             :                      i::HandleScope);
    4521          42 :   auto self = Utils::OpenHandle(this);
    4522          42 :   auto key_obj = Utils::OpenHandle(*key);
    4523             :   Maybe<bool> result = i::Runtime::DeleteObjectProperty(
    4524          42 :       isolate, self, key_obj, i::LanguageMode::kSloppy);
    4525          42 :   has_pending_exception = result.IsNothing();
    4526          42 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4527          42 :   return result;
    4528             : }
    4529             : 
    4530        9130 : Maybe<bool> v8::Object::Has(Local<Context> context, Local<Value> key) {
    4531       18260 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4532       36520 :   ENTER_V8(isolate, context, Object, Has, Nothing<bool>(), i::HandleScope);
    4533        9130 :   auto self = Utils::OpenHandle(this);
    4534             :   auto key_obj = Utils::OpenHandle(*key);
    4535             :   Maybe<bool> maybe = Nothing<bool>();
    4536             :   // Check if the given key is an array index.
    4537        9130 :   uint32_t index = 0;
    4538       18260 :   if (key_obj->ToArrayIndex(&index)) {
    4539           0 :     maybe = i::JSReceiver::HasElement(self, index);
    4540             :   } else {
    4541             :     // Convert the key to a name - possibly by calling back into JavaScript.
    4542             :     i::Handle<i::Name> name;
    4543       18260 :     if (i::Object::ToName(isolate, key_obj).ToHandle(&name)) {
    4544        9130 :       maybe = i::JSReceiver::HasProperty(self, name);
    4545             :     }
    4546             :   }
    4547        9130 :   has_pending_exception = maybe.IsNothing();
    4548        9130 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4549        9130 :   return maybe;
    4550             : }
    4551             : 
    4552             : 
    4553       78322 : Maybe<bool> v8::Object::HasPrivate(Local<Context> context, Local<Private> key) {
    4554       78322 :   return HasOwnProperty(context, Local<Name>(reinterpret_cast<Name*>(*key)));
    4555             : }
    4556             : 
    4557             : 
    4558          10 : Maybe<bool> v8::Object::Delete(Local<Context> context, uint32_t index) {
    4559          20 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4560          40 :   ENTER_V8(isolate, context, Object, Delete, Nothing<bool>(), i::HandleScope);
    4561          10 :   auto self = Utils::OpenHandle(this);
    4562          10 :   Maybe<bool> result = i::JSReceiver::DeleteElement(self, index);
    4563          10 :   has_pending_exception = result.IsNothing();
    4564          10 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4565           5 :   return result;
    4566             : }
    4567             : 
    4568             : 
    4569          30 : Maybe<bool> v8::Object::Has(Local<Context> context, uint32_t index) {
    4570          60 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4571         120 :   ENTER_V8(isolate, context, Object, Has, Nothing<bool>(), i::HandleScope);
    4572          30 :   auto self = Utils::OpenHandle(this);
    4573          30 :   auto maybe = i::JSReceiver::HasElement(self, index);
    4574          30 :   has_pending_exception = maybe.IsNothing();
    4575          30 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4576          30 :   return maybe;
    4577             : }
    4578             : 
    4579             : template <typename Getter, typename Setter, typename Data>
    4580        7910 : static Maybe<bool> ObjectSetAccessor(
    4581             :     Local<Context> context, Object* self, Local<Name> name, Getter getter,
    4582             :     Setter setter, Data data, AccessControl settings,
    4583             :     PropertyAttribute attributes, bool is_special_data_property,
    4584             :     bool replace_on_access, SideEffectType getter_side_effect_type,
    4585             :     SideEffectType setter_side_effect_type) {
    4586       15820 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4587       31640 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, SetAccessor, Nothing<bool>(),
    4588             :                      i::HandleScope);
    4589       15820 :   if (!Utils::OpenHandle(self)->IsJSObject()) return Just(false);
    4590             :   i::Handle<i::JSObject> obj =
    4591        7910 :       i::Handle<i::JSObject>::cast(Utils::OpenHandle(self));
    4592             :   v8::Local<AccessorSignature> signature;
    4593             :   i::Handle<i::AccessorInfo> info =
    4594             :       MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature,
    4595        7910 :                        is_special_data_property, replace_on_access);
    4596        7910 :   info->set_getter_side_effect_type(getter_side_effect_type);
    4597        7910 :   info->set_setter_side_effect_type(setter_side_effect_type);
    4598        7910 :   if (info.is_null()) return Nothing<bool>();
    4599        7910 :   bool fast = obj->HasFastProperties();
    4600             :   i::Handle<i::Object> result;
    4601             : 
    4602       15820 :   i::Handle<i::Name> accessor_name(info->name(), isolate);
    4603             :   i::PropertyAttributes attrs = static_cast<i::PropertyAttributes>(attributes);
    4604             :   has_pending_exception =
    4605             :       !i::JSObject::SetAccessor(obj, accessor_name, info, attrs)
    4606       15820 :            .ToHandle(&result);
    4607        7910 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4608       15810 :   if (result->IsUndefined(isolate)) return Just(false);
    4609        7880 :   if (fast) {
    4610        7868 :     i::JSObject::MigrateSlowToFast(obj, 0, "APISetAccessor");
    4611             :   }
    4612             :   return Just(true);
    4613             : }
    4614             : 
    4615        7874 : Maybe<bool> Object::SetAccessor(Local<Context> context, Local<Name> name,
    4616             :                                 AccessorNameGetterCallback getter,
    4617             :                                 AccessorNameSetterCallback setter,
    4618             :                                 MaybeLocal<Value> data, AccessControl settings,
    4619             :                                 PropertyAttribute attribute,
    4620             :                                 SideEffectType getter_side_effect_type,
    4621             :                                 SideEffectType setter_side_effect_type) {
    4622             :   return ObjectSetAccessor(context, this, name, getter, setter,
    4623             :                            data.FromMaybe(Local<Value>()), settings, attribute,
    4624             :                            i::FLAG_disable_old_api_accessors, false,
    4625       15748 :                            getter_side_effect_type, setter_side_effect_type);
    4626             : }
    4627             : 
    4628             : 
    4629      320667 : void Object::SetAccessorProperty(Local<Name> name, Local<Function> getter,
    4630             :                                  Local<Function> setter,
    4631             :                                  PropertyAttribute attribute,
    4632             :                                  AccessControl settings) {
    4633             :   // TODO(verwaest): Remove |settings|.
    4634             :   DCHECK_EQ(v8::DEFAULT, settings);
    4635             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    4636             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4637             :   i::HandleScope scope(isolate);
    4638             :   auto self = Utils::OpenHandle(this);
    4639      962001 :   if (!self->IsJSObject()) return;
    4640             :   i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
    4641             :   i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
    4642      320667 :   if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
    4643             :   i::JSObject::DefineAccessor(i::Handle<i::JSObject>::cast(self),
    4644             :                               v8::Utils::OpenHandle(*name), getter_i, setter_i,
    4645      320667 :                               static_cast<i::PropertyAttributes>(attribute));
    4646             : }
    4647             : 
    4648          16 : Maybe<bool> Object::SetNativeDataProperty(
    4649             :     v8::Local<v8::Context> context, v8::Local<Name> name,
    4650             :     AccessorNameGetterCallback getter, AccessorNameSetterCallback setter,
    4651             :     v8::Local<Value> data, PropertyAttribute attributes,
    4652             :     SideEffectType getter_side_effect_type,
    4653             :     SideEffectType setter_side_effect_type) {
    4654             :   return ObjectSetAccessor(context, this, name, getter, setter, data, DEFAULT,
    4655             :                            attributes, true, false, getter_side_effect_type,
    4656          16 :                            setter_side_effect_type);
    4657             : }
    4658             : 
    4659          20 : Maybe<bool> Object::SetLazyDataProperty(
    4660             :     v8::Local<v8::Context> context, v8::Local<Name> name,
    4661             :     AccessorNameGetterCallback getter, v8::Local<Value> data,
    4662             :     PropertyAttribute attributes, SideEffectType getter_side_effect_type,
    4663             :     SideEffectType setter_side_effect_type) {
    4664             :   return ObjectSetAccessor(context, this, name, getter,
    4665             :                            static_cast<AccessorNameSetterCallback>(nullptr),
    4666             :                            data, DEFAULT, attributes, true, true,
    4667          20 :                            getter_side_effect_type, setter_side_effect_type);
    4668             : }
    4669             : 
    4670       85681 : Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context,
    4671             :                                        Local<Name> key) {
    4672      171362 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4673      342724 :   ENTER_V8(isolate, context, Object, HasOwnProperty, Nothing<bool>(),
    4674             :            i::HandleScope);
    4675       85681 :   auto self = Utils::OpenHandle(this);
    4676       85681 :   auto key_val = Utils::OpenHandle(*key);
    4677       85681 :   auto result = i::JSReceiver::HasOwnProperty(self, key_val);
    4678       85681 :   has_pending_exception = result.IsNothing();
    4679       85681 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4680       85676 :   return result;
    4681             : }
    4682             : 
    4683          25 : Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context, uint32_t index) {
    4684          50 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4685         100 :   ENTER_V8(isolate, context, Object, HasOwnProperty, Nothing<bool>(),
    4686             :            i::HandleScope);
    4687          25 :   auto self = Utils::OpenHandle(this);
    4688          25 :   auto result = i::JSReceiver::HasOwnProperty(self, index);
    4689          25 :   has_pending_exception = result.IsNothing();
    4690          25 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4691          25 :   return result;
    4692             : }
    4693             : 
    4694        5847 : Maybe<bool> v8::Object::HasRealNamedProperty(Local<Context> context,
    4695             :                                              Local<Name> key) {
    4696       11694 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4697       23388 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealNamedProperty,
    4698             :                      Nothing<bool>(), i::HandleScope);
    4699             :   auto self = Utils::OpenHandle(this);
    4700       11694 :   if (!self->IsJSObject()) return Just(false);
    4701        5842 :   auto key_val = Utils::OpenHandle(*key);
    4702             :   auto result = i::JSObject::HasRealNamedProperty(
    4703        5842 :       i::Handle<i::JSObject>::cast(self), key_val);
    4704        5842 :   has_pending_exception = result.IsNothing();
    4705        5842 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4706        5837 :   return result;
    4707             : }
    4708             : 
    4709             : 
    4710          17 : Maybe<bool> v8::Object::HasRealIndexedProperty(Local<Context> context,
    4711             :                                                uint32_t index) {
    4712          34 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4713          68 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealIndexedProperty,
    4714             :                      Nothing<bool>(), i::HandleScope);
    4715             :   auto self = Utils::OpenHandle(this);
    4716          34 :   if (!self->IsJSObject()) return Just(false);
    4717             :   auto result = i::JSObject::HasRealElementProperty(
    4718          17 :       i::Handle<i::JSObject>::cast(self), index);
    4719          17 :   has_pending_exception = result.IsNothing();
    4720          17 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4721          12 :   return result;
    4722             : }
    4723             : 
    4724           5 : Maybe<bool> v8::Object::HasRealNamedCallbackProperty(Local<Context> context,
    4725             :                                                      Local<Name> key) {
    4726          10 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4727          20 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealNamedCallbackProperty,
    4728             :                      Nothing<bool>(), i::HandleScope);
    4729             :   auto self = Utils::OpenHandle(this);
    4730          10 :   if (!self->IsJSObject()) return Just(false);
    4731           5 :   auto key_val = Utils::OpenHandle(*key);
    4732             :   auto result = i::JSObject::HasRealNamedCallbackProperty(
    4733           5 :       i::Handle<i::JSObject>::cast(self), key_val);
    4734           5 :   has_pending_exception = result.IsNothing();
    4735           5 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4736           0 :   return result;
    4737             : }
    4738             : 
    4739           0 : bool v8::Object::HasNamedLookupInterceptor() {
    4740             :   auto self = Utils::OpenHandle(this);
    4741           0 :   return self->IsJSObject() &&
    4742           0 :          i::Handle<i::JSObject>::cast(self)->HasNamedInterceptor();
    4743             : }
    4744             : 
    4745             : 
    4746           0 : bool v8::Object::HasIndexedLookupInterceptor() {
    4747             :   auto self = Utils::OpenHandle(this);
    4748           0 :   return self->IsJSObject() &&
    4749           0 :          i::Handle<i::JSObject>::cast(self)->HasIndexedInterceptor();
    4750             : }
    4751             : 
    4752             : 
    4753           6 : MaybeLocal<Value> v8::Object::GetRealNamedPropertyInPrototypeChain(
    4754             :     Local<Context> context, Local<Name> key) {
    4755          24 :   PREPARE_FOR_EXECUTION(context, Object, GetRealNamedPropertyInPrototypeChain,
    4756             :                         Value);
    4757             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4758          12 :   if (!self->IsJSObject()) return MaybeLocal<Value>();
    4759           6 :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4760           6 :   i::PrototypeIterator iter(isolate, self);
    4761           6 :   if (iter.IsAtEnd()) return MaybeLocal<Value>();
    4762             :   i::Handle<i::JSReceiver> proto =
    4763           6 :       i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter);
    4764             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4765             :       isolate, self, key_obj, proto,
    4766           6 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4767             :   Local<Value> result;
    4768           6 :   has_pending_exception = !ToLocal<Value>(i::Object::GetProperty(&it), &result);
    4769           6 :   RETURN_ON_FAILED_EXECUTION(Value);
    4770           0 :   if (!it.IsFound()) return MaybeLocal<Value>();
    4771           0 :   RETURN_ESCAPED(result);
    4772             : }
    4773             : 
    4774             : 
    4775             : Maybe<PropertyAttribute>
    4776           6 : v8::Object::GetRealNamedPropertyAttributesInPrototypeChain(
    4777             :     Local<Context> context, Local<Name> key) {
    4778          12 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4779          24 :   ENTER_V8_NO_SCRIPT(isolate, context, Object,
    4780             :                      GetRealNamedPropertyAttributesInPrototypeChain,
    4781             :                      Nothing<PropertyAttribute>(), i::HandleScope);
    4782             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4783          12 :   if (!self->IsJSObject()) return Nothing<PropertyAttribute>();
    4784           6 :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4785           6 :   i::PrototypeIterator iter(isolate, self);
    4786           6 :   if (iter.IsAtEnd()) return Nothing<PropertyAttribute>();
    4787             :   i::Handle<i::JSReceiver> proto =
    4788           6 :       i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter);
    4789             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4790             :       isolate, self, key_obj, proto,
    4791           6 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4792             :   Maybe<i::PropertyAttributes> result =
    4793           6 :       i::JSReceiver::GetPropertyAttributes(&it);
    4794             :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4795           6 :   if (!it.IsFound()) return Nothing<PropertyAttribute>();
    4796           6 :   if (result.FromJust() == i::ABSENT) return Just(None);
    4797             :   return Just(static_cast<PropertyAttribute>(result.FromJust()));
    4798             : }
    4799             : 
    4800             : 
    4801      831273 : MaybeLocal<Value> v8::Object::GetRealNamedProperty(Local<Context> context,
    4802             :                                                    Local<Name> key) {
    4803     3325092 :   PREPARE_FOR_EXECUTION(context, Object, GetRealNamedProperty, Value);
    4804             :   auto self = Utils::OpenHandle(this);
    4805      831273 :   auto key_obj = Utils::OpenHandle(*key);
    4806             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4807             :       isolate, self, key_obj, self,
    4808      831273 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4809             :   Local<Value> result;
    4810      831273 :   has_pending_exception = !ToLocal<Value>(i::Object::GetProperty(&it), &result);
    4811      831273 :   RETURN_ON_FAILED_EXECUTION(Value);
    4812      831255 :   if (!it.IsFound()) return MaybeLocal<Value>();
    4813         258 :   RETURN_ESCAPED(result);
    4814             : }
    4815             : 
    4816             : 
    4817          18 : Maybe<PropertyAttribute> v8::Object::GetRealNamedPropertyAttributes(
    4818             :     Local<Context> context, Local<Name> key) {
    4819          36 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4820          72 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, GetRealNamedPropertyAttributes,
    4821             :                      Nothing<PropertyAttribute>(), i::HandleScope);
    4822             :   auto self = Utils::OpenHandle(this);
    4823          18 :   auto key_obj = Utils::OpenHandle(*key);
    4824             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4825             :       isolate, self, key_obj, self,
    4826          18 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4827          18 :   auto result = i::JSReceiver::GetPropertyAttributes(&it);
    4828             :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4829          18 :   if (!it.IsFound()) return Nothing<PropertyAttribute>();
    4830          18 :   if (result.FromJust() == i::ABSENT) {
    4831             :     return Just(static_cast<PropertyAttribute>(i::NONE));
    4832             :   }
    4833             :   return Just<PropertyAttribute>(
    4834             :       static_cast<PropertyAttribute>(result.FromJust()));
    4835             : }
    4836             : 
    4837             : 
    4838          16 : Local<v8::Object> v8::Object::Clone() {
    4839          16 :   auto self = i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
    4840             :   auto isolate = self->GetIsolate();
    4841             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4842          16 :   auto result = isolate->factory()->CopyJSObject(self);
    4843          16 :   CHECK(!result.is_null());
    4844          16 :   return Utils::ToLocal(result);
    4845             : }
    4846             : 
    4847             : 
    4848      299145 : Local<v8::Context> v8::Object::CreationContext() {
    4849             :   auto self = Utils::OpenHandle(this);
    4850      299145 :   i::Handle<i::Context> context = self->GetCreationContext();
    4851      299145 :   return Utils::ToLocal(context);
    4852             : }
    4853             : 
    4854             : 
    4855          94 : int v8::Object::GetIdentityHash() {
    4856             :   i::DisallowHeapAllocation no_gc;
    4857             :   auto isolate = Utils::OpenHandle(this)->GetIsolate();
    4858             :   i::HandleScope scope(isolate);
    4859             :   auto self = Utils::OpenHandle(this);
    4860         282 :   return self->GetOrCreateIdentityHash(isolate)->value();
    4861             : }
    4862             : 
    4863             : 
    4864          24 : bool v8::Object::IsCallable() {
    4865             :   auto self = Utils::OpenHandle(this);
    4866          48 :   return self->IsCallable();
    4867             : }
    4868             : 
    4869           6 : bool v8::Object::IsConstructor() {
    4870             :   auto self = Utils::OpenHandle(this);
    4871          12 :   return self->IsConstructor();
    4872             : }
    4873             : 
    4874         114 : MaybeLocal<Value> Object::CallAsFunction(Local<Context> context,
    4875             :                                          Local<Value> recv, int argc,
    4876             :                                          Local<Value> argv[]) {
    4877         228 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4878         228 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4879         456 :   ENTER_V8(isolate, context, Object, CallAsFunction, MaybeLocal<Value>(),
    4880             :            InternalEscapableScope);
    4881             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4882             :   auto self = Utils::OpenHandle(this);
    4883         114 :   auto recv_obj = Utils::OpenHandle(*recv);
    4884             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4885             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4886             :   Local<Value> result;
    4887             :   has_pending_exception = !ToLocal<Value>(
    4888         228 :       i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
    4889         114 :   RETURN_ON_FAILED_EXECUTION(Value);
    4890         216 :   RETURN_ESCAPED(result);
    4891             : }
    4892             : 
    4893             : 
    4894           0 : MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc,
    4895             :                                             Local<Value> argv[]) {
    4896           0 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4897           0 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4898           0 :   ENTER_V8(isolate, context, Object, CallAsConstructor, MaybeLocal<Value>(),
    4899             :            InternalEscapableScope);
    4900             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4901             :   auto self = Utils::OpenHandle(this);
    4902             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4903             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4904             :   Local<Value> result;
    4905             :   has_pending_exception = !ToLocal<Value>(
    4906           0 :       i::Execution::New(isolate, self, self, argc, args), &result);
    4907           0 :   RETURN_ON_FAILED_EXECUTION(Value);
    4908           0 :   RETURN_ESCAPED(result);
    4909             : }
    4910             : 
    4911        5143 : MaybeLocal<Function> Function::New(Local<Context> context,
    4912             :                                    FunctionCallback callback, Local<Value> data,
    4913             :                                    int length, ConstructorBehavior behavior,
    4914             :                                    SideEffectType side_effect_type) {
    4915        5143 :   i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
    4916       10286 :   LOG_API(isolate, Function, New);
    4917             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4918             :   auto templ =
    4919             :       FunctionTemplateNew(isolate, callback, data, Local<Signature>(), length,
    4920        5143 :                           true, Local<Private>(), side_effect_type);
    4921        5143 :   if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
    4922       10286 :   return templ->GetFunction(context);
    4923             : }
    4924             : 
    4925         779 : MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc,
    4926             :                                          v8::Local<v8::Value> argv[]) const {
    4927             :   return NewInstanceWithSideEffectType(context, argc, argv,
    4928         779 :                                        SideEffectType::kHasSideEffect);
    4929             : }
    4930             : 
    4931         794 : MaybeLocal<Object> Function::NewInstanceWithSideEffectType(
    4932             :     Local<Context> context, int argc, v8::Local<v8::Value> argv[],
    4933             :     SideEffectType side_effect_type) const {
    4934        1603 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4935        1588 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4936        3176 :   ENTER_V8(isolate, context, Function, NewInstance, MaybeLocal<Object>(),
    4937             :            InternalEscapableScope);
    4938             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4939             :   auto self = Utils::OpenHandle(this);
    4940             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4941             :   bool should_set_has_no_side_effect =
    4942         809 :       side_effect_type == SideEffectType::kHasNoSideEffect &&
    4943             :       isolate->debug_execution_mode() == i::DebugInfo::kSideEffects;
    4944         794 :   if (should_set_has_no_side_effect) {
    4945          30 :     CHECK(self->IsJSFunction() &&
    4946             :           i::JSFunction::cast(*self)->shared()->IsApiFunction());
    4947             :     i::Object obj =
    4948          20 :         i::JSFunction::cast(*self)->shared()->get_api_func_data()->call_code();
    4949          10 :     if (obj->IsCallHandlerInfo()) {
    4950          10 :       i::CallHandlerInfo handler_info = i::CallHandlerInfo::cast(obj);
    4951          10 :       if (!handler_info->IsSideEffectFreeCallHandlerInfo()) {
    4952          10 :         handler_info->SetNextCallHasNoSideEffect();
    4953             :       }
    4954             :     }
    4955             :   }
    4956             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4957             :   Local<Object> result;
    4958             :   has_pending_exception = !ToLocal<Object>(
    4959        1588 :       i::Execution::New(isolate, self, self, argc, args), &result);
    4960         794 :   if (should_set_has_no_side_effect) {
    4961             :     i::Object obj =
    4962          20 :         i::JSFunction::cast(*self)->shared()->get_api_func_data()->call_code();
    4963          10 :     if (obj->IsCallHandlerInfo()) {
    4964          10 :       i::CallHandlerInfo handler_info = i::CallHandlerInfo::cast(obj);
    4965          10 :       if (has_pending_exception) {
    4966             :         // Restore the map if an exception prevented restoration.
    4967           0 :         handler_info->NextCallHasNoSideEffect();
    4968             :       } else {
    4969             :         DCHECK(handler_info->IsSideEffectCallHandlerInfo() ||
    4970             :                handler_info->IsSideEffectFreeCallHandlerInfo());
    4971             :       }
    4972             :     }
    4973             :   }
    4974         794 :   RETURN_ON_FAILED_EXECUTION(Object);
    4975        1572 :   RETURN_ESCAPED(result);
    4976             : }
    4977             : 
    4978             : 
    4979      359027 : MaybeLocal<v8::Value> Function::Call(Local<Context> context,
    4980             :                                      v8::Local<v8::Value> recv, int argc,
    4981             :                                      v8::Local<v8::Value> argv[]) {
    4982      718053 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4983      718054 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4984     1436106 :   ENTER_V8(isolate, context, Function, Call, MaybeLocal<Value>(),
    4985             :            InternalEscapableScope);
    4986             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4987             :   auto self = Utils::OpenHandle(this);
    4988             :   Utils::ApiCheck(!self.is_null(), "v8::Function::Call",
    4989             :                   "Function to be called is a null pointer");
    4990      359026 :   i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
    4991             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4992             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4993             :   Local<Value> result;
    4994             :   has_pending_exception = !ToLocal<Value>(
    4995      718051 :       i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
    4996      359025 :   RETURN_ON_FAILED_EXECUTION(Value);
    4997      717703 :   RETURN_ESCAPED(result);
    4998             : }
    4999             : 
    5000         640 : void Function::SetName(v8::Local<v8::String> name) {
    5001             :   auto self = Utils::OpenHandle(this);
    5002        1280 :   if (!self->IsJSFunction()) return;
    5003         640 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5004         640 :   func->shared()->SetName(*Utils::OpenHandle(*name));
    5005             : }
    5006             : 
    5007             : 
    5008          42 : Local<Value> Function::GetName() const {
    5009             :   auto self = Utils::OpenHandle(this);
    5010             :   i::Isolate* isolate = self->GetIsolate();
    5011          84 :   if (self->IsJSBoundFunction()) {
    5012           0 :     auto func = i::Handle<i::JSBoundFunction>::cast(self);
    5013             :     i::Handle<i::Object> name;
    5014           0 :     ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, name,
    5015             :                                      i::JSBoundFunction::GetName(isolate, func),
    5016             :                                      Local<Value>());
    5017             :     return Utils::ToLocal(name);
    5018             :   }
    5019          84 :   if (self->IsJSFunction()) {
    5020          42 :     auto func = i::Handle<i::JSFunction>::cast(self);
    5021          84 :     return Utils::ToLocal(handle(func->shared()->Name(), isolate));
    5022             :   }
    5023           0 :   return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
    5024             : }
    5025             : 
    5026             : 
    5027           6 : Local<Value> Function::GetInferredName() const {
    5028             :   auto self = Utils::OpenHandle(this);
    5029          12 :   if (!self->IsJSFunction()) {
    5030             :     return ToApiHandle<Primitive>(
    5031           0 :         self->GetIsolate()->factory()->undefined_value());
    5032             :   }
    5033           6 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5034          12 :   return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(),
    5035          12 :                                              func->GetIsolate()));
    5036             : }
    5037             : 
    5038             : 
    5039          72 : Local<Value> Function::GetDebugName() const {
    5040             :   auto self = Utils::OpenHandle(this);
    5041         144 :   if (!self->IsJSFunction()) {
    5042             :     return ToApiHandle<Primitive>(
    5043           0 :         self->GetIsolate()->factory()->undefined_value());
    5044             :   }
    5045          72 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5046          72 :   i::Handle<i::String> name = i::JSFunction::GetDebugName(func);
    5047             :   return Utils::ToLocal(i::Handle<i::Object>(*name, self->GetIsolate()));
    5048             : }
    5049             : 
    5050             : 
    5051          42 : Local<Value> Function::GetDisplayName() const {
    5052             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    5053             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    5054             :   auto self = Utils::OpenHandle(this);
    5055          84 :   if (!self->IsJSFunction()) {
    5056           0 :     return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
    5057             :   }
    5058          42 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5059             :   i::Handle<i::String> property_name =
    5060          42 :       isolate->factory()->NewStringFromStaticChars("displayName");
    5061             :   i::Handle<i::Object> value =
    5062          42 :       i::JSReceiver::GetDataProperty(func, property_name);
    5063          84 :   if (value->IsString()) {
    5064          18 :     i::Handle<i::String> name = i::Handle<i::String>::cast(value);
    5065          18 :     if (name->length() > 0) return Utils::ToLocal(name);
    5066             :   }
    5067          24 :   return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
    5068             : }
    5069             : 
    5070             : 
    5071          12 : ScriptOrigin Function::GetScriptOrigin() const {
    5072             :   auto self = Utils::OpenHandle(this);
    5073          24 :   if (!self->IsJSFunction()) {
    5074             :     return v8::ScriptOrigin(Local<Value>());
    5075             :   }
    5076          12 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5077          24 :   if (func->shared()->script()->IsScript()) {
    5078          24 :     i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5079          24 :                                 func->GetIsolate());
    5080          12 :     return GetScriptOriginForScript(func->GetIsolate(), script);
    5081             :   }
    5082             :   return v8::ScriptOrigin(Local<Value>());
    5083             : }
    5084             : 
    5085             : 
    5086             : const int Function::kLineOffsetNotFound = -1;
    5087             : 
    5088             : 
    5089      151147 : int Function::GetScriptLineNumber() const {
    5090             :   auto self = Utils::OpenHandle(this);
    5091      302294 :   if (!self->IsJSFunction()) {
    5092             :     return kLineOffsetNotFound;
    5093             :   }
    5094      151142 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5095      302284 :   if (func->shared()->script()->IsScript()) {
    5096      302284 :     i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5097      302284 :                                 func->GetIsolate());
    5098      151142 :     return i::Script::GetLineNumber(script, func->shared()->StartPosition());
    5099             :   }
    5100             :   return kLineOffsetNotFound;
    5101             : }
    5102             : 
    5103             : 
    5104      146147 : int Function::GetScriptColumnNumber() const {
    5105             :   auto self = Utils::OpenHandle(this);
    5106      292294 :   if (!self->IsJSFunction()) {
    5107             :     return kLineOffsetNotFound;
    5108             :   }
    5109      146142 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5110      292284 :   if (func->shared()->script()->IsScript()) {
    5111      292284 :     i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5112      292284 :                                 func->GetIsolate());
    5113      146142 :     return i::Script::GetColumnNumber(script, func->shared()->StartPosition());
    5114             :   }
    5115             :   return kLineOffsetNotFound;
    5116             : }
    5117             : 
    5118             : 
    5119      176685 : int Function::ScriptId() const {
    5120             :   auto self = Utils::OpenHandle(this);
    5121      353370 :   if (!self->IsJSFunction()) {
    5122             :     return v8::UnboundScript::kNoScriptId;
    5123             :   }
    5124      176680 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5125      353360 :   if (!func->shared()->script()->IsScript()) {
    5126             :     return v8::UnboundScript::kNoScriptId;
    5127             :   }
    5128      330580 :   i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5129      330580 :                               func->GetIsolate());
    5130             :   return script->id();
    5131             : }
    5132             : 
    5133             : 
    5134         252 : Local<v8::Value> Function::GetBoundFunction() const {
    5135             :   auto self = Utils::OpenHandle(this);
    5136         504 :   if (self->IsJSBoundFunction()) {
    5137         102 :     auto bound_function = i::Handle<i::JSBoundFunction>::cast(self);
    5138             :     auto bound_target_function = i::handle(
    5139         204 :         bound_function->bound_target_function(), bound_function->GetIsolate());
    5140         102 :     return Utils::CallableToLocal(bound_target_function);
    5141             :   }
    5142         150 :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(self->GetIsolate()));
    5143             : }
    5144             : 
    5145          50 : int Name::GetIdentityHash() {
    5146             :   auto self = Utils::OpenHandle(this);
    5147          50 :   return static_cast<int>(self->Hash());
    5148             : }
    5149             : 
    5150             : 
    5151    27638530 : int String::Length() const {
    5152             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5153    27638530 :   return str->length();
    5154             : }
    5155             : 
    5156             : 
    5157          67 : bool String::IsOneByte() const {
    5158             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5159          67 :   return str->HasOnlyOneByteChars();
    5160             : }
    5161             : 
    5162             : 
    5163             : // Helpers for ContainsOnlyOneByteHelper
    5164             : template<size_t size> struct OneByteMask;
    5165             : template<> struct OneByteMask<4> {
    5166             :   static const uint32_t value = 0xFF00FF00;
    5167             : };
    5168             : template<> struct OneByteMask<8> {
    5169             :   static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00);
    5170             : };
    5171             : static const uintptr_t kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value;
    5172             : static const uintptr_t kAlignmentMask = sizeof(uintptr_t) - 1;
    5173             : static inline bool Unaligned(const uint16_t* chars) {
    5174       45915 :   return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask;
    5175             : }
    5176             : 
    5177             : 
    5178             : static inline const uint16_t* Align(const uint16_t* chars) {
    5179             :   return reinterpret_cast<uint16_t*>(
    5180       17885 :       reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask);
    5181             : }
    5182             : 
    5183             : class ContainsOnlyOneByteHelper {
    5184             :  public:
    5185       17885 :   ContainsOnlyOneByteHelper() : is_one_byte_(true) {}
    5186       17885 :   bool Check(i::String string) {
    5187       17885 :     i::ConsString cons_string = i::String::VisitFlat(this, string, 0);
    5188       17885 :     if (cons_string.is_null()) return is_one_byte_;
    5189          30 :     return CheckCons(cons_string);
    5190             :   }
    5191             :   void VisitOneByteString(const uint8_t* chars, int length) {
    5192             :     // Nothing to do.
    5193             :   }
    5194       17885 :   void VisitTwoByteString(const uint16_t* chars, int length) {
    5195             :     // Accumulated bits.
    5196             :     uintptr_t acc = 0;
    5197             :     // Align to uintptr_t.
    5198       17885 :     const uint16_t* end = chars + length;
    5199       63800 :     while (Unaligned(chars) && chars != end) {
    5200       28030 :       acc |= *chars++;
    5201             :     }
    5202             :     // Read word aligned in blocks,
    5203             :     // checking the return value at the end of each block.
    5204             :     const uint16_t* aligned_end = Align(end);
    5205             :     const int increment = sizeof(uintptr_t)/sizeof(uint16_t);
    5206             :     const int inner_loops = 16;
    5207       51475 :     while (chars + inner_loops*increment < aligned_end) {
    5208      396400 :       for (int i = 0; i < inner_loops; i++) {
    5209      396400 :         acc |= *reinterpret_cast<const uintptr_t*>(chars);
    5210      396400 :         chars += increment;
    5211             :       }
    5212             :       // Check for early return.
    5213       24775 :       if ((acc & kOneByteMask) != 0) {
    5214        9070 :         is_one_byte_ = false;
    5215       26955 :         return;
    5216             :       }
    5217             :     }
    5218             :     // Read the rest.
    5219      468120 :     while (chars != end) {
    5220      459305 :       acc |= *chars++;
    5221             :     }
    5222             :     // Check result.
    5223        8815 :     if ((acc & kOneByteMask) != 0) is_one_byte_ = false;
    5224             :   }
    5225             : 
    5226             :  private:
    5227          40 :   bool CheckCons(i::ConsString cons_string) {
    5228             :     while (true) {
    5229             :       // Check left side if flat.
    5230       39610 :       i::String left = cons_string->first();
    5231       39610 :       i::ConsString left_as_cons = i::String::VisitFlat(this, left, 0);
    5232       39610 :       if (!is_one_byte_) return false;
    5233             :       // Check right side if flat.
    5234       39610 :       i::String right = cons_string->second();
    5235       39610 :       i::ConsString right_as_cons = i::String::VisitFlat(this, right, 0);
    5236       39610 :       if (!is_one_byte_) return false;
    5237             :       // Standard recurse/iterate trick.
    5238       39610 :       if (!left_as_cons.is_null() && !right_as_cons.is_null()) {
    5239          10 :         if (left->length() < right->length()) {
    5240           0 :           CheckCons(left_as_cons);
    5241           0 :           cons_string = right_as_cons;
    5242             :         } else {
    5243          10 :           CheckCons(right_as_cons);
    5244          10 :           cons_string = left_as_cons;
    5245             :         }
    5246             :         // Check fast return.
    5247          10 :         if (!is_one_byte_) return false;
    5248       39570 :         continue;
    5249             :       }
    5250             :       // Descend left in place.
    5251       39600 :       if (!left_as_cons.is_null()) {
    5252       19785 :         cons_string = left_as_cons;
    5253       19785 :         continue;
    5254             :       }
    5255             :       // Descend right in place.
    5256       19815 :       if (!right_as_cons.is_null()) {
    5257       19775 :         cons_string = right_as_cons;
    5258       19775 :         continue;
    5259             :       }
    5260             :       // Terminate.
    5261          40 :       break;
    5262             :     }
    5263       39610 :     return is_one_byte_;
    5264             :   }
    5265             :   bool is_one_byte_;
    5266             :   DISALLOW_COPY_AND_ASSIGN(ContainsOnlyOneByteHelper);
    5267             : };
    5268             : 
    5269             : 
    5270       17905 : bool String::ContainsOnlyOneByte() const {
    5271             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5272       17905 :   if (str->HasOnlyOneByteChars()) return true;
    5273             :   ContainsOnlyOneByteHelper helper;
    5274       17885 :   return helper.Check(*str);
    5275             : }
    5276             : 
    5277     9067585 : int String::Utf8Length(Isolate* isolate) const {
    5278             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5279     9067585 :   str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
    5280             :   int length = str->length();
    5281     9067585 :   if (length == 0) return 0;
    5282             :   i::DisallowHeapAllocation no_gc;
    5283     9061459 :   i::String::FlatContent flat = str->GetFlatContent(no_gc);
    5284             :   DCHECK(flat.IsFlat());
    5285             :   int utf8_length = 0;
    5286     9061459 :   if (flat.IsOneByte()) {
    5287   284652244 :     for (uint8_t c : flat.ToOneByteVector()) {
    5288   275595467 :       utf8_length += c >> 7;
    5289             :     }
    5290     9056777 :     utf8_length += length;
    5291             :   } else {
    5292             :     int last_character = unibrow::Utf16::kNoPreviousCharacter;
    5293     1207357 :     for (uint16_t c : flat.ToUC16Vector()) {
    5294     2405350 :       utf8_length += unibrow::Utf8::Length(c, last_character);
    5295     1202675 :       last_character = c;
    5296             :     }
    5297             :   }
    5298     9061459 :   return utf8_length;
    5299             : }
    5300             : 
    5301             : namespace {
    5302             : // Writes the flat content of a string to a buffer. This is done in two phases.
    5303             : // The first phase calculates a pessimistic estimate (writable_length) on how
    5304             : // many code units can be safely written without exceeding the buffer capacity
    5305             : // and without leaving at a lone surrogate. The estimated number of code units
    5306             : // is then written out in one go, and the reported byte usage is used to
    5307             : // correct the estimate. This is repeated until the estimate becomes <= 0 or
    5308             : // all code units have been written out. The second phase writes out code
    5309             : // units until the buffer capacity is reached, would be exceeded by the next
    5310             : // unit, or all code units have been written out.
    5311             : template <typename Char>
    5312     9067147 : static int WriteUtf8Impl(i::Vector<const Char> string, char* write_start,
    5313             :                          int write_capacity, int options,
    5314             :                          int* utf16_chars_read_out) {
    5315     9067147 :   bool write_null = !(options & v8::String::NO_NULL_TERMINATION);
    5316     9067147 :   bool replace_invalid_utf8 = (options & v8::String::REPLACE_INVALID_UTF8);
    5317             :   char* current_write = write_start;
    5318     9067147 :   const Char* read_start = string.start();
    5319             :   int read_index = 0;
    5320     9067147 :   int read_length = string.length();
    5321             :   int prev_char = unibrow::Utf16::kNoPreviousCharacter;
    5322             :   // Do a fast loop where there is no exit capacity check.
    5323             :   // Need enough space to write everything but one character.
    5324             :   STATIC_ASSERT(unibrow::Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3);
    5325             :   static const int kMaxSizePerChar = sizeof(Char) == 1 ? 2 : 3;
    5326    27346401 :   while (read_index < read_length) {
    5327     9225287 :     int up_to = read_length;
    5328     9225287 :     if (write_capacity != -1) {
    5329             :       int remaining_capacity =
    5330      177489 :           write_capacity - static_cast<int>(current_write - write_start);
    5331             :       int writable_length =
    5332      177489 :           (remaining_capacity - kMaxSizePerChar) / kMaxSizePerChar;
    5333             :       // Need to drop into slow loop.
    5334      177489 :       if (writable_length <= 0) break;
    5335      328618 :       up_to = std::min(up_to, read_index + writable_length);
    5336             :     }
    5337             :     // Write the characters to the stream.
    5338             :     if (sizeof(Char) == 1) {
    5339             :       // Simply memcpy if we only have ASCII characters.
    5340             :       uint8_t char_mask = 0;
    5341     9206350 :       for (int i = read_index; i < up_to; i++) char_mask |= read_start[i];
    5342     9206350 :       if ((char_mask & 0x80) == 0) {
    5343     9206151 :         int copy_length = up_to - read_index;
    5344     9206151 :         memcpy(current_write, read_start + read_index, copy_length);
    5345     9206151 :         current_write += copy_length;
    5346             :         read_index = up_to;
    5347             :       } else {
    5348        6378 :         for (; read_index < up_to; read_index++) {
    5349        6378 :           current_write += unibrow::Utf8::EncodeOneByte(
    5350        6378 :               current_write, static_cast<uint8_t>(read_start[read_index]));
    5351             :           DCHECK(write_capacity == -1 ||
    5352             :                  (current_write - write_start) <= write_capacity);
    5353             :         }
    5354             :       }
    5355             :     } else {
    5356   136188175 :       for (; read_index < up_to; read_index++) {
    5357   136188175 :         uint16_t character = read_start[read_index];
    5358   136188175 :         current_write += unibrow::Utf8::Encode(current_write, character,
    5359   136188175 :                                                prev_char, replace_invalid_utf8);
    5360   136188175 :         prev_char = character;
    5361             :         DCHECK(write_capacity == -1 ||
    5362             :                (current_write - write_start) <= write_capacity);
    5363             :       }
    5364             :     }
    5365             :   }
    5366     9067147 :   if (read_index < read_length) {
    5367             :     DCHECK_NE(-1, write_capacity);
    5368             :     // Aborted due to limited capacity. Check capacity on each iteration.
    5369             :     int remaining_capacity =
    5370       13180 :         write_capacity - static_cast<int>(current_write - write_start);
    5371             :     DCHECK_GE(remaining_capacity, 0);
    5372       52690 :     for (; read_index < read_length && remaining_capacity > 0; read_index++) {
    5373       39559 :       uint32_t character = read_start[read_index];
    5374             :       int written = 0;
    5375             :       // We can't use a local buffer here because Encode needs to modify
    5376             :       // previous characters in the stream.  We know, however, that
    5377             :       // exactly one character will be advanced.
    5378       78399 :       if (unibrow::Utf16::IsSurrogatePair(prev_char, character)) {
    5379           0 :         written = unibrow::Utf8::Encode(current_write, character, prev_char,
    5380           0 :                                         replace_invalid_utf8);
    5381             :         DCHECK_EQ(written, 1);
    5382             :       } else {
    5383             :         // Use a scratch buffer to check the required characters.
    5384             :         char temp_buffer[unibrow::Utf8::kMaxEncodedSize];
    5385             :         // Encoding a surrogate pair to Utf8 always takes 4 bytes.
    5386             :         static const int kSurrogatePairEncodedSize =
    5387             :             static_cast<int>(unibrow::Utf8::kMaxEncodedSize);
    5388             :         // For REPLACE_INVALID_UTF8, catch the case where we cut off in the
    5389             :         // middle of a surrogate pair. Abort before encoding the pair instead.
    5390       39586 :         if (replace_invalid_utf8 &&
    5391             :             remaining_capacity < kSurrogatePairEncodedSize &&
    5392             :             unibrow::Utf16::IsLeadSurrogate(character) &&
    5393             :             read_index + 1 < read_length &&
    5394           6 :             unibrow::Utf16::IsTrailSurrogate(read_start[read_index + 1])) {
    5395             :           write_null = false;
    5396          49 :           break;
    5397             :         }
    5398             :         // Can't encode using prev_char as gcc has array bounds issues.
    5399       39553 :         written = unibrow::Utf8::Encode(temp_buffer, character,
    5400             :                                         unibrow::Utf16::kNoPreviousCharacter,
    5401       39553 :                                         replace_invalid_utf8);
    5402       39553 :         if (written > remaining_capacity) {
    5403             :           // Won't fit. Abort and do not null-terminate the result.
    5404             :           write_null = false;
    5405             :           break;
    5406             :         }
    5407             :         // Copy over the character from temp_buffer.
    5408       39648 :         for (int i = 0; i < written; i++) current_write[i] = temp_buffer[i];
    5409             :       }
    5410             : 
    5411       39510 :       current_write += written;
    5412       39510 :       remaining_capacity -= written;
    5413         670 :       prev_char = character;
    5414             :     }
    5415             :   }
    5416             : 
    5417             :   // Write out number of utf16 characters written to the stream.
    5418     9067147 :   if (utf16_chars_read_out != nullptr) *utf16_chars_read_out = read_index;
    5419             : 
    5420             :   // Only null-terminate if there's space.
    5421     9067147 :   if (write_null && (write_capacity == -1 ||
    5422             :                      (current_write - write_start) < write_capacity)) {
    5423     9054005 :     *current_write++ = '\0';
    5424             :   }
    5425     9067147 :   return static_cast<int>(current_write - write_start);
    5426             : }
    5427             : }  // anonymous namespace
    5428             : 
    5429     9067147 : int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
    5430             :                       int* nchars_ref, int options) const {
    5431             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5432     9067147 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    5433    18134294 :   LOG_API(isolate, String, WriteUtf8);
    5434             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    5435     9067147 :   str = i::String::Flatten(isolate, str);
    5436             :   i::DisallowHeapAllocation no_gc;
    5437     9067147 :   i::String::FlatContent content = str->GetFlatContent(no_gc);
    5438     9067147 :   if (content.IsOneByte()) {
    5439             :     return WriteUtf8Impl<uint8_t>(content.ToOneByteVector(), buffer, capacity,
    5440     9062799 :                                   options, nchars_ref);
    5441             :   } else {
    5442             :     return WriteUtf8Impl<uint16_t>(content.ToUC16Vector(), buffer, capacity,
    5443        4348 :                                    options, nchars_ref);
    5444             :   }
    5445             : }
    5446             : 
    5447             : template <typename CharType>
    5448    18611214 : static inline int WriteHelper(i::Isolate* isolate, const String* string,
    5449             :                               CharType* buffer, int start, int length,
    5450             :                               int options) {
    5451    18611214 :   LOG_API(isolate, String, Write);
    5452             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    5453             :   DCHECK(start >= 0 && length >= -1);
    5454             :   i::Handle<i::String> str = Utils::OpenHandle(string);
    5455     9305607 :   str = i::String::Flatten(isolate, str);
    5456     9305609 :   int end = start + length;
    5457    18611116 :   if ((length == -1) || (length > str->length() - start) )
    5458             :     end = str->length();
    5459     9305609 :   if (end < 0) return 0;
    5460     9305607 :   i::String::WriteToFlat(*str, buffer, start, end);
    5461     9305607 :   if (!(options & String::NO_NULL_TERMINATION) &&
    5462             :       (length == -1 || end - start < length)) {
    5463          66 :     buffer[end - start] = '\0';
    5464             :   }
    5465     9305607 :   return end - start;
    5466             : }
    5467             : 
    5468             : 
    5469          67 : int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
    5470             :                          int length, int options) const {
    5471             :   return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
    5472          67 :                      start, length, options);
    5473             : }
    5474             : 
    5475             : 
    5476     9305534 : int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
    5477             :                   int options) const {
    5478             :   return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
    5479     9305540 :                      start, length, options);
    5480             : }
    5481             : 
    5482             : 
    5483          67 : bool v8::String::IsExternal() const {
    5484             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5485          67 :   return i::StringShape(*str).IsExternalTwoByte();
    5486             : }
    5487             : 
    5488             : 
    5489          27 : bool v8::String::IsExternalOneByte() const {
    5490             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5491          27 :   return i::StringShape(*str).IsExternalOneByte();
    5492             : }
    5493             : 
    5494             : 
    5495           0 : void v8::String::VerifyExternalStringResource(
    5496             :     v8::String::ExternalStringResource* value) const {
    5497             :   i::DisallowHeapAllocation no_allocation;
    5498           0 :   i::String str = *Utils::OpenHandle(this);
    5499             :   const v8::String::ExternalStringResource* expected;
    5500             : 
    5501           0 :   if (str->IsThinString()) {
    5502           0 :     str = i::ThinString::cast(str)->actual();
    5503             :   }
    5504             : 
    5505           0 :   if (i::StringShape(str).IsExternalTwoByte()) {
    5506             :     const void* resource = i::ExternalTwoByteString::cast(str)->resource();
    5507             :     expected = reinterpret_cast<const ExternalStringResource*>(resource);
    5508             :   } else {
    5509             :     expected = nullptr;
    5510             :   }
    5511           0 :   CHECK_EQ(expected, value);
    5512           0 : }
    5513             : 
    5514           0 : void v8::String::VerifyExternalStringResourceBase(
    5515             :     v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
    5516             :   i::DisallowHeapAllocation no_allocation;
    5517           0 :   i::String str = *Utils::OpenHandle(this);
    5518             :   const v8::String::ExternalStringResourceBase* expected;
    5519             :   Encoding expectedEncoding;
    5520             : 
    5521           0 :   if (str->IsThinString()) {
    5522           0 :     str = i::ThinString::cast(str)->actual();
    5523             :   }
    5524             : 
    5525           0 :   if (i::StringShape(str).IsExternalOneByte()) {
    5526             :     const void* resource = i::ExternalOneByteString::cast(str)->resource();
    5527             :     expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
    5528             :     expectedEncoding = ONE_BYTE_ENCODING;
    5529           0 :   } else if (i::StringShape(str).IsExternalTwoByte()) {
    5530             :     const void* resource = i::ExternalTwoByteString::cast(str)->resource();
    5531             :     expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
    5532             :     expectedEncoding = TWO_BYTE_ENCODING;
    5533             :   } else {
    5534             :     expected = nullptr;
    5535             :     expectedEncoding =
    5536           0 :         str->IsOneByteRepresentation() ? ONE_BYTE_ENCODING : TWO_BYTE_ENCODING;
    5537             :   }
    5538           0 :   CHECK_EQ(expected, value);
    5539           0 :   CHECK_EQ(expectedEncoding, encoding);
    5540           0 : }
    5541             : 
    5542           0 : String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
    5543             :   i::DisallowHeapAllocation no_allocation;
    5544             :   typedef internal::Internals I;
    5545           0 :   i::String str = *Utils::OpenHandle(this);
    5546             : 
    5547           0 :   if (str->IsThinString()) {
    5548           0 :     str = i::ThinString::cast(str)->actual();
    5549             :   }
    5550             : 
    5551           0 :   if (i::StringShape(str).IsExternalTwoByte()) {
    5552             :     void* value = I::ReadRawField<void*>(str.ptr(), I::kStringResourceOffset);
    5553           0 :     return reinterpret_cast<String::ExternalStringResource*>(value);
    5554             :   }
    5555             :   return nullptr;
    5556             : }
    5557             : 
    5558           6 : String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
    5559             :     String::Encoding* encoding_out) const {
    5560             :   i::DisallowHeapAllocation no_allocation;
    5561             :   typedef internal::Internals I;
    5562             :   ExternalStringResourceBase* resource = nullptr;
    5563           6 :   i::String str = *Utils::OpenHandle(this);
    5564             : 
    5565           6 :   if (str->IsThinString()) {
    5566           0 :     str = i::ThinString::cast(str)->actual();
    5567             :   }
    5568             : 
    5569             :   internal::Address string = str.ptr();
    5570             :   int type = I::GetInstanceType(string) & I::kFullStringRepresentationMask;
    5571           6 :   *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
    5572          12 :   if (i::StringShape(str).IsExternalOneByte() ||
    5573             :       i::StringShape(str).IsExternalTwoByte()) {
    5574             :     void* value = I::ReadRawField<void*>(string, I::kStringResourceOffset);
    5575             :     resource = static_cast<ExternalStringResourceBase*>(value);
    5576             :   }
    5577           6 :   return resource;
    5578             : }
    5579             : 
    5580             : const v8::String::ExternalOneByteStringResource*
    5581          11 : v8::String::GetExternalOneByteStringResource() const {
    5582             :   i::DisallowHeapAllocation no_allocation;
    5583          11 :   i::String str = *Utils::OpenHandle(this);
    5584          11 :   if (i::StringShape(str).IsExternalOneByte()) {
    5585             :     return i::ExternalOneByteString::cast(str)->resource();
    5586           0 :   } else if (str->IsThinString()) {
    5587           0 :     str = i::ThinString::cast(str)->actual();
    5588           0 :     if (i::StringShape(str).IsExternalOneByte()) {
    5589             :       return i::ExternalOneByteString::cast(str)->resource();
    5590             :     }
    5591             :   }
    5592             :   return nullptr;
    5593             : }
    5594             : 
    5595             : 
    5596       57826 : Local<Value> Symbol::Name() const {
    5597             :   i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
    5598             : 
    5599             :   i::Isolate* isolate;
    5600       57826 :   if (!i::GetIsolateFromWritableObject(*sym, &isolate)) {
    5601             :     // If the Symbol is in RO_SPACE, then its name must be too. Since RO_SPACE
    5602             :     // objects are immovable we can use the Handle(Address*) constructor with
    5603             :     // the address of the name field in the Symbol object without needing an
    5604             :     // isolate.
    5605             : #ifdef V8_COMPRESS_POINTERS
    5606             :     // Compressed fields can't serve as handle locations.
    5607             :     // TODO(ishell): get Isolate as a parameter.
    5608             :     isolate = i::Isolate::Current();
    5609             : #else
    5610             :     i::Handle<i::HeapObject> ro_name(reinterpret_cast<i::Address*>(
    5611       57555 :         sym->GetFieldAddress(i::Symbol::kNameOffset)));
    5612             :     return Utils::ToLocal(ro_name);
    5613             : #endif
    5614             :   }
    5615             : 
    5616         271 :   i::Handle<i::Object> name(sym->name(), isolate);
    5617             : 
    5618             :   return Utils::ToLocal(name);
    5619             : }
    5620             : 
    5621             : 
    5622          12 : Local<Value> Private::Name() const {
    5623          12 :   return reinterpret_cast<const Symbol*>(this)->Name();
    5624             : }
    5625             : 
    5626             : 
    5627      329112 : double Number::Value() const {
    5628             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5629      329112 :   return obj->Number();
    5630             : }
    5631             : 
    5632             : 
    5633       21792 : bool Boolean::Value() const {
    5634             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5635       43584 :   return obj->IsTrue();
    5636             : }
    5637             : 
    5638             : 
    5639       11468 : int64_t Integer::Value() const {
    5640             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5641       22936 :   if (obj->IsSmi()) {
    5642       11432 :     return i::Smi::ToInt(*obj);
    5643             :   } else {
    5644          36 :     return static_cast<int64_t>(obj->Number());
    5645             :   }
    5646             : }
    5647             : 
    5648             : 
    5649       47199 : int32_t Int32::Value() const {
    5650             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5651       94398 :   if (obj->IsSmi()) {
    5652       47199 :     return i::Smi::ToInt(*obj);
    5653             :   } else {
    5654           0 :     return static_cast<int32_t>(obj->Number());
    5655             :   }
    5656             : }
    5657             : 
    5658             : 
    5659        7291 : uint32_t Uint32::Value() const {
    5660             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5661       14582 :   if (obj->IsSmi()) {
    5662        7273 :     return i::Smi::ToInt(*obj);
    5663             :   } else {
    5664          18 :     return static_cast<uint32_t>(obj->Number());
    5665             :   }
    5666             : }
    5667             : 
    5668        4453 : int v8::Object::InternalFieldCount() {
    5669             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    5670        8906 :   if (!self->IsJSObject()) return 0;
    5671        8906 :   return i::Handle<i::JSObject>::cast(self)->GetEmbedderFieldCount();
    5672             : }
    5673             : 
    5674        2681 : static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index,
    5675             :                             const char* location) {
    5676             :   return Utils::ApiCheck(
    5677       10724 :       obj->IsJSObject() &&
    5678        8043 :           (index < i::Handle<i::JSObject>::cast(obj)->GetEmbedderFieldCount()),
    5679        2681 :       location, "Internal field out of bounds");
    5680             : }
    5681             : 
    5682         576 : Local<Value> v8::Object::SlowGetInternalField(int index) {
    5683             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5684             :   const char* location = "v8::Object::GetInternalField()";
    5685         576 :   if (!InternalFieldOK(obj, index, location)) return Local<Value>();
    5686             :   i::Handle<i::Object> value(i::JSObject::cast(*obj)->GetEmbedderField(index),
    5687        1152 :                              obj->GetIsolate());
    5688             :   return Utils::ToLocal(value);
    5689             : }
    5690             : 
    5691         524 : void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
    5692         524 :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5693             :   const char* location = "v8::Object::SetInternalField()";
    5694         524 :   if (!InternalFieldOK(obj, index, location)) return;
    5695             :   i::Handle<i::Object> val = Utils::OpenHandle(*value);
    5696        1048 :   i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
    5697             : }
    5698             : 
    5699         135 : void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
    5700             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5701             :   const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
    5702         135 :   if (!InternalFieldOK(obj, index, location)) return nullptr;
    5703             :   void* result;
    5704             :   Utils::ApiCheck(i::EmbedderDataSlot(i::JSObject::cast(*obj), index)
    5705         135 :                       .ToAlignedPointer(&result),
    5706             :                   location, "Unaligned pointer");
    5707         135 :   return result;
    5708             : }
    5709             : 
    5710        1446 : void v8::Object::SetAlignedPointerInInternalField(int index, void* value) {
    5711             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5712             :   const char* location = "v8::Object::SetAlignedPointerInInternalField()";
    5713        2892 :   if (!InternalFieldOK(obj, index, location)) return;
    5714             :   Utils::ApiCheck(i::EmbedderDataSlot(i::JSObject::cast(*obj), index)
    5715        1446 :                       .store_aligned_pointer(value),
    5716             :                   location, "Unaligned pointer");
    5717             :   DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
    5718             : }
    5719             : 
    5720          12 : void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[],
    5721             :                                                    void* values[]) {
    5722             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5723             :   const char* location = "v8::Object::SetAlignedPointerInInternalFields()";
    5724             :   i::DisallowHeapAllocation no_gc;
    5725          12 :   i::JSObject js_obj = i::JSObject::cast(*obj);
    5726          12 :   int nof_embedder_fields = js_obj->GetEmbedderFieldCount();
    5727          36 :   for (int i = 0; i < argc; i++) {
    5728          24 :     int index = indices[i];
    5729          24 :     if (!Utils::ApiCheck(index < nof_embedder_fields, location,
    5730          24 :                          "Internal field out of bounds")) {
    5731           0 :       return;
    5732             :     }
    5733          24 :     void* value = values[i];
    5734             :     Utils::ApiCheck(
    5735          24 :         i::EmbedderDataSlot(js_obj, index).store_aligned_pointer(value),
    5736             :         location, "Unaligned pointer");
    5737             :     DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
    5738             :   }
    5739             : }
    5740             : 
    5741      936758 : static void* ExternalValue(i::Object obj) {
    5742             :   // Obscure semantics for undefined, but somehow checked in our unit tests...
    5743      936758 :   if (obj->IsUndefined()) {
    5744             :     return nullptr;
    5745             :   }
    5746      936760 :   i::Object foreign = i::JSObject::cast(obj)->GetEmbedderField(0);
    5747      936761 :   return reinterpret_cast<void*>(i::Foreign::cast(foreign)->foreign_address());
    5748             : }
    5749             : 
    5750             : // --- E n v i r o n m e n t ---
    5751             : 
    5752             : 
    5753       59583 : void v8::V8::InitializePlatform(Platform* platform) {
    5754       59583 :   i::V8::InitializePlatform(platform);
    5755       59583 : }
    5756             : 
    5757             : 
    5758       58472 : void v8::V8::ShutdownPlatform() {
    5759       58472 :   i::V8::ShutdownPlatform();
    5760       58472 : }
    5761             : 
    5762             : 
    5763       59907 : bool v8::V8::Initialize() {
    5764       59907 :   i::V8::Initialize();
    5765             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
    5766       59907 :   i::ReadNatives();
    5767             : #endif
    5768       59907 :   return true;
    5769             : }
    5770             : 
    5771             : #if V8_OS_LINUX || V8_OS_MACOSX
    5772           7 : bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info,
    5773             :                                    void* context) {
    5774             : #if V8_TARGET_ARCH_X64 && !V8_OS_ANDROID
    5775           7 :   return i::trap_handler::TryHandleSignal(sig_code, info, context);
    5776             : #else
    5777             :   return false;
    5778             : #endif
    5779             : }
    5780             : 
    5781           0 : bool V8::TryHandleSignal(int signum, void* info, void* context) {
    5782             :   return TryHandleWebAssemblyTrapPosix(
    5783           0 :       signum, reinterpret_cast<siginfo_t*>(info), context);
    5784             : }
    5785             : #endif
    5786             : 
    5787             : #if V8_OS_WIN
    5788             : bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) {
    5789             : #if V8_TARGET_ARCH_X64
    5790             :   return i::trap_handler::TryHandleWasmTrap(exception);
    5791             : #endif
    5792             :   return false;
    5793             : }
    5794             : #endif
    5795             : 
    5796       55426 : bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) {
    5797       55426 :   return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler);
    5798             : }
    5799             : 
    5800           0 : void v8::V8::SetEntropySource(EntropySource entropy_source) {
    5801           0 :   base::RandomNumberGenerator::SetEntropySource(entropy_source);
    5802           0 : }
    5803             : 
    5804             : 
    5805           0 : void v8::V8::SetReturnAddressLocationResolver(
    5806             :     ReturnAddressLocationResolver return_address_resolver) {
    5807           0 :   i::StackFrame::SetReturnAddressLocationResolver(return_address_resolver);
    5808           0 : }
    5809             : 
    5810       58516 : bool v8::V8::Dispose() {
    5811       58516 :   i::V8::TearDown();
    5812             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
    5813       58516 :   i::DisposeNatives();
    5814             : #endif
    5815       58516 :   return true;
    5816             : }
    5817             : 
    5818          31 : HeapStatistics::HeapStatistics()
    5819             :     : total_heap_size_(0),
    5820             :       total_heap_size_executable_(0),
    5821             :       total_physical_size_(0),
    5822             :       total_available_size_(0),
    5823             :       used_heap_size_(0),
    5824             :       heap_size_limit_(0),
    5825             :       malloced_memory_(0),
    5826             :       external_memory_(0),
    5827             :       peak_malloced_memory_(0),
    5828             :       does_zap_garbage_(false),
    5829             :       number_of_native_contexts_(0),
    5830          31 :       number_of_detached_contexts_(0) {}
    5831             : 
    5832          40 : HeapSpaceStatistics::HeapSpaceStatistics()
    5833             :     : space_name_(nullptr),
    5834             :       space_size_(0),
    5835             :       space_used_size_(0),
    5836             :       space_available_size_(0),
    5837          40 :       physical_space_size_(0) {}
    5838             : 
    5839           0 : HeapObjectStatistics::HeapObjectStatistics()
    5840             :     : object_type_(nullptr),
    5841             :       object_sub_type_(nullptr),
    5842             :       object_count_(0),
    5843           0 :       object_size_(0) {}
    5844             : 
    5845           0 : HeapCodeStatistics::HeapCodeStatistics()
    5846             :     : code_and_metadata_size_(0),
    5847             :       bytecode_and_metadata_size_(0),
    5848           0 :       external_script_source_size_(0) {}
    5849             : 
    5850           0 : bool v8::V8::InitializeICU(const char* icu_data_file) {
    5851           0 :   return i::InitializeICU(icu_data_file);
    5852             : }
    5853             : 
    5854       56555 : bool v8::V8::InitializeICUDefaultLocation(const char* exec_path,
    5855             :                                           const char* icu_data_file) {
    5856       56555 :   return i::InitializeICUDefaultLocation(exec_path, icu_data_file);
    5857             : }
    5858             : 
    5859       59592 : void v8::V8::InitializeExternalStartupData(const char* directory_path) {
    5860       59592 :   i::InitializeExternalStartupData(directory_path);
    5861       59592 : }
    5862             : 
    5863             : 
    5864           0 : void v8::V8::InitializeExternalStartupData(const char* natives_blob,
    5865             :                                            const char* snapshot_blob) {
    5866           0 :   i::InitializeExternalStartupData(natives_blob, snapshot_blob);
    5867           0 : }
    5868             : 
    5869             : 
    5870          33 : const char* v8::V8::GetVersion() {
    5871          33 :   return i::Version::GetVersion();
    5872             : }
    5873             : 
    5874             : template <typename ObjectType>
    5875             : struct InvokeBootstrapper;
    5876             : 
    5877             : template <>
    5878             : struct InvokeBootstrapper<i::Context> {
    5879             :   i::Handle<i::Context> Invoke(
    5880       89797 :       i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
    5881             :       v8::Local<v8::ObjectTemplate> global_proxy_template,
    5882             :       v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
    5883             :       v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
    5884             :     return isolate->bootstrapper()->CreateEnvironment(
    5885             :         maybe_global_proxy, global_proxy_template, extensions,
    5886       89797 :         context_snapshot_index, embedder_fields_deserializer);
    5887             :   }
    5888             : };
    5889             : 
    5890             : template <>
    5891             : struct InvokeBootstrapper<i::JSGlobalProxy> {
    5892             :   i::Handle<i::JSGlobalProxy> Invoke(
    5893          18 :       i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
    5894             :       v8::Local<v8::ObjectTemplate> global_proxy_template,
    5895             :       v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
    5896             :       v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
    5897             :     USE(extensions);
    5898             :     USE(context_snapshot_index);
    5899             :     return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy,
    5900          18 :                                                      global_proxy_template);
    5901             :   }
    5902             : };
    5903             : 
    5904             : template <typename ObjectType>
    5905       89815 : static i::Handle<ObjectType> CreateEnvironment(
    5906             :     i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
    5907             :     v8::MaybeLocal<ObjectTemplate> maybe_global_template,
    5908             :     v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index,
    5909             :     v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
    5910             :   i::Handle<ObjectType> result;
    5911             : 
    5912             :   {
    5913             :     ENTER_V8_FOR_NEW_CONTEXT(isolate);
    5914             :     v8::Local<ObjectTemplate> proxy_template;
    5915             :     i::Handle<i::FunctionTemplateInfo> proxy_constructor;
    5916             :     i::Handle<i::FunctionTemplateInfo> global_constructor;
    5917             :     i::Handle<i::Object> named_interceptor(
    5918             :         isolate->factory()->undefined_value());
    5919             :     i::Handle<i::Object> indexed_interceptor(
    5920             :         isolate->factory()->undefined_value());
    5921             : 
    5922       89815 :     if (!maybe_global_template.IsEmpty()) {
    5923             :       v8::Local<v8::ObjectTemplate> global_template =
    5924             :           maybe_global_template.ToLocalChecked();
    5925             :       // Make sure that the global_template has a constructor.
    5926       55218 :       global_constructor = EnsureConstructor(isolate, *global_template);
    5927             : 
    5928             :       // Create a fresh template for the global proxy object.
    5929             :       proxy_template = ObjectTemplate::New(
    5930             :           reinterpret_cast<v8::Isolate*>(isolate));
    5931       55218 :       proxy_constructor = EnsureConstructor(isolate, *proxy_template);
    5932             : 
    5933             :       // Set the global template to be the prototype template of
    5934             :       // global proxy template.
    5935       55218 :       i::FunctionTemplateInfo::SetPrototypeTemplate(
    5936       55218 :           isolate, proxy_constructor, Utils::OpenHandle(*global_template));
    5937             : 
    5938       55218 :       proxy_template->SetInternalFieldCount(
    5939       55218 :           global_template->InternalFieldCount());
    5940             : 
    5941             :       // Migrate security handlers from global_template to
    5942             :       // proxy_template.  Temporarily removing access check
    5943             :       // information from the global template.
    5944      110436 :       if (!global_constructor->GetAccessCheckInfo()->IsUndefined(isolate)) {
    5945         141 :         i::FunctionTemplateInfo::SetAccessCheckInfo(
    5946             :             isolate, proxy_constructor,
    5947         282 :             i::handle(global_constructor->GetAccessCheckInfo(), isolate));
    5948         141 :         proxy_constructor->set_needs_access_check(
    5949         423 :             global_constructor->needs_access_check());
    5950         141 :         global_constructor->set_needs_access_check(false);
    5951         141 :         i::FunctionTemplateInfo::SetAccessCheckInfo(
    5952             :             isolate, global_constructor,
    5953         141 :             i::ReadOnlyRoots(isolate).undefined_value_handle());
    5954             :       }
    5955             : 
    5956             :       // Same for other interceptors. If the global constructor has
    5957             :       // interceptors, we need to replace them temporarily with noop
    5958             :       // interceptors, so the map is correctly marked as having interceptors,
    5959             :       // but we don't invoke any.
    5960      110436 :       if (!global_constructor->GetNamedPropertyHandler()->IsUndefined(
    5961      110436 :               isolate)) {
    5962         144 :         named_interceptor =
    5963         288 :             handle(global_constructor->GetNamedPropertyHandler(), isolate);
    5964         144 :         i::FunctionTemplateInfo::SetNamedPropertyHandler(
    5965             :             isolate, global_constructor,
    5966         144 :             i::ReadOnlyRoots(isolate).noop_interceptor_info_handle());
    5967             :       }
    5968      110436 :       if (!global_constructor->GetIndexedPropertyHandler()->IsUndefined(
    5969      110436 :               isolate)) {
    5970           0 :         indexed_interceptor =
    5971           0 :             handle(global_constructor->GetIndexedPropertyHandler(), isolate);
    5972           0 :         i::FunctionTemplateInfo::SetIndexedPropertyHandler(
    5973             :             isolate, global_constructor,
    5974           0 :             i::ReadOnlyRoots(isolate).noop_interceptor_info_handle());
    5975             :       }
    5976             :     }
    5977             : 
    5978             :     i::MaybeHandle<i::JSGlobalProxy> maybe_proxy;
    5979       89815 :     if (!maybe_global_proxy.IsEmpty()) {
    5980          74 :       maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(
    5981             :           Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked()));
    5982             :     }
    5983             :     // Create the environment.
    5984             :     InvokeBootstrapper<ObjectType> invoke;
    5985             :     result =
    5986             :         invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
    5987             :                       context_snapshot_index, embedder_fields_deserializer);
    5988             : 
    5989             :     // Restore the access check info and interceptors on the global template.
    5990       89815 :     if (!maybe_global_template.IsEmpty()) {
    5991             :       DCHECK(!global_constructor.is_null());
    5992             :       DCHECK(!proxy_constructor.is_null());
    5993       55218 :       i::FunctionTemplateInfo::SetAccessCheckInfo(
    5994             :           isolate, global_constructor,
    5995      110436 :           i::handle(proxy_constructor->GetAccessCheckInfo(), isolate));
    5996       55218 :       global_constructor->set_needs_access_check(
    5997      165654 :           proxy_constructor->needs_access_check());
    5998       55218 :       i::FunctionTemplateInfo::SetNamedPropertyHandler(
    5999             :           isolate, global_constructor, named_interceptor);
    6000       55218 :       i::FunctionTemplateInfo::SetIndexedPropertyHandler(
    6001             :           isolate, global_constructor, indexed_interceptor);
    6002             :     }
    6003             :   }
    6004             :   // Leave V8.
    6005             : 
    6006       89815 :   return result;
    6007             : }
    6008             : 
    6009       89797 : Local<Context> NewContext(
    6010             :     v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
    6011             :     v8::MaybeLocal<ObjectTemplate> global_template,
    6012             :     v8::MaybeLocal<Value> global_object, size_t context_snapshot_index,
    6013             :     v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
    6014       89797 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    6015             :   // TODO(jkummerow): This is for crbug.com/713699. Remove it if it doesn't
    6016             :   // fail.
    6017             :   // Sanity-check that the isolate is initialized and usable.
    6018      179594 :   CHECK(isolate->builtins()->builtin(i::Builtins::kIllegal)->IsCode());
    6019             : 
    6020      179594 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
    6021      179594 :   LOG_API(isolate, Context, New);
    6022             :   i::HandleScope scope(isolate);
    6023             :   ExtensionConfiguration no_extensions;
    6024       89797 :   if (extensions == nullptr) extensions = &no_extensions;
    6025             :   i::Handle<i::Context> env = CreateEnvironment<i::Context>(
    6026             :       isolate, extensions, global_template, global_object,
    6027       89797 :       context_snapshot_index, embedder_fields_deserializer);
    6028       89797 :   if (env.is_null()) {
    6029          40 :     if (isolate->has_pending_exception()) isolate->clear_pending_exception();
    6030          40 :     return Local<Context>();
    6031             :   }
    6032      179554 :   return Utils::ToLocal(scope.CloseAndEscape(env));
    6033             : }
    6034             : 
    6035       89757 : Local<Context> v8::Context::New(
    6036             :     v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
    6037             :     v8::MaybeLocal<ObjectTemplate> global_template,
    6038             :     v8::MaybeLocal<Value> global_object,
    6039             :     DeserializeInternalFieldsCallback internal_fields_deserializer) {
    6040             :   return NewContext(external_isolate, extensions, global_template,
    6041       89757 :                     global_object, 0, internal_fields_deserializer);
    6042             : }
    6043             : 
    6044          45 : MaybeLocal<Context> v8::Context::FromSnapshot(
    6045             :     v8::Isolate* external_isolate, size_t context_snapshot_index,
    6046             :     v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
    6047             :     v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) {
    6048          45 :   size_t index_including_default_context = context_snapshot_index + 1;
    6049          45 :   if (!i::Snapshot::HasContextSnapshot(
    6050             :           reinterpret_cast<i::Isolate*>(external_isolate),
    6051          45 :           index_including_default_context)) {
    6052           5 :     return MaybeLocal<Context>();
    6053             :   }
    6054             :   return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(),
    6055             :                     global_object, index_including_default_context,
    6056          40 :                     embedder_fields_deserializer);
    6057             : }
    6058             : 
    6059          18 : MaybeLocal<Object> v8::Context::NewRemoteContext(
    6060             :     v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template,
    6061             :     v8::MaybeLocal<v8::Value> global_object) {
    6062          18 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    6063          36 :   LOG_API(isolate, Context, NewRemoteContext);
    6064             :   i::HandleScope scope(isolate);
    6065             :   i::Handle<i::FunctionTemplateInfo> global_constructor =
    6066          18 :       EnsureConstructor(isolate, *global_template);
    6067          36 :   Utils::ApiCheck(global_constructor->needs_access_check(),
    6068             :                   "v8::Context::NewRemoteContext",
    6069             :                   "Global template needs to have access checks enabled.");
    6070             :   i::Handle<i::AccessCheckInfo> access_check_info = i::handle(
    6071             :       i::AccessCheckInfo::cast(global_constructor->GetAccessCheckInfo()),
    6072          36 :       isolate);
    6073             :   Utils::ApiCheck(access_check_info->named_interceptor() != i::Object(),
    6074             :                   "v8::Context::NewRemoteContext",
    6075             :                   "Global template needs to have access check handlers.");
    6076             :   i::Handle<i::JSGlobalProxy> global_proxy =
    6077             :       CreateEnvironment<i::JSGlobalProxy>(isolate, nullptr, global_template,
    6078             :                                           global_object, 0,
    6079          18 :                                           DeserializeInternalFieldsCallback());
    6080          18 :   if (global_proxy.is_null()) {
    6081           0 :     if (isolate->has_pending_exception()) isolate->clear_pending_exception();
    6082           0 :     return MaybeLocal<Object>();
    6083             :   }
    6084             :   return Utils::ToLocal(
    6085          18 :       scope.CloseAndEscape(i::Handle<i::JSObject>::cast(global_proxy)));
    6086             : }
    6087             : 
    6088         263 : void v8::Context::SetSecurityToken(Local<Value> token) {
    6089             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6090             :   i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
    6091         263 :   env->set_security_token(*token_handle);
    6092         263 : }
    6093             : 
    6094             : 
    6095           0 : void v8::Context::UseDefaultSecurityToken() {
    6096             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6097           0 :   env->set_security_token(env->global_object());
    6098           0 : }
    6099             : 
    6100             : 
    6101          17 : Local<Value> v8::Context::GetSecurityToken() {
    6102             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6103             :   i::Isolate* isolate = env->GetIsolate();
    6104          17 :   i::Object security_token = env->security_token();
    6105             :   i::Handle<i::Object> token_handle(security_token, isolate);
    6106          17 :   return Utils::ToLocal(token_handle);
    6107             : }
    6108             : 
    6109             : 
    6110    28900356 : v8::Isolate* Context::GetIsolate() {
    6111             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6112    28900360 :   return reinterpret_cast<Isolate*>(env->GetIsolate());
    6113             : }
    6114             : 
    6115      437439 : v8::Local<v8::Object> Context::Global() {
    6116             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6117             :   i::Isolate* isolate = context->GetIsolate();
    6118      874878 :   i::Handle<i::Object> global(context->global_proxy(), isolate);
    6119             :   // TODO(dcarney): This should always return the global proxy
    6120             :   // but can't presently as calls to GetProtoype will return the wrong result.
    6121      874878 :   if (i::Handle<i::JSGlobalProxy>::cast(
    6122     1312317 :           global)->IsDetachedFrom(context->global_object())) {
    6123         130 :     global = i::Handle<i::Object>(context->global_object(), isolate);
    6124             :   }
    6125      437439 :   return Utils::ToLocal(i::Handle<i::JSObject>::cast(global));
    6126             : }
    6127             : 
    6128             : 
    6129         107 : void Context::DetachGlobal() {
    6130             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6131         107 :   i::Isolate* isolate = context->GetIsolate();
    6132             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6133         107 :   isolate->bootstrapper()->DetachGlobal(context);
    6134         107 : }
    6135             : 
    6136             : 
    6137          45 : Local<v8::Object> Context::GetExtrasBindingObject() {
    6138             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6139             :   i::Isolate* isolate = context->GetIsolate();
    6140          90 :   i::Handle<i::JSObject> binding(context->extras_binding_object(), isolate);
    6141          45 :   return Utils::ToLocal(binding);
    6142             : }
    6143             : 
    6144             : 
    6145         158 : void Context::AllowCodeGenerationFromStrings(bool allow) {
    6146             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6147             :   i::Isolate* isolate = context->GetIsolate();
    6148             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6149             :   context->set_allow_code_gen_from_strings(
    6150             :       allow ? i::ReadOnlyRoots(isolate).true_value()
    6151         474 :             : i::ReadOnlyRoots(isolate).false_value());
    6152         158 : }
    6153             : 
    6154             : 
    6155        9169 : bool Context::IsCodeGenerationFromStringsAllowed() {
    6156             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6157       18338 :   return !context->allow_code_gen_from_strings()->IsFalse(
    6158       27507 :       context->GetIsolate());
    6159             : }
    6160             : 
    6161             : 
    6162           5 : void Context::SetErrorMessageForCodeGenerationFromStrings(Local<String> error) {
    6163             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6164             :   i::Handle<i::String> error_handle = Utils::OpenHandle(*error);
    6165          10 :   context->set_error_message_for_code_gen_from_strings(*error_handle);
    6166           5 : }
    6167             : 
    6168             : namespace {
    6169         175 : i::Address* GetSerializedDataFromFixedArray(i::Isolate* isolate,
    6170             :                                             i::FixedArray list, size_t index) {
    6171         175 :   if (index < static_cast<size_t>(list->length())) {
    6172         150 :     int int_index = static_cast<int>(index);
    6173         150 :     i::Object object = list->get(int_index);
    6174         150 :     if (!object->IsTheHole(isolate)) {
    6175          80 :       list->set_the_hole(isolate, int_index);
    6176             :       // Shrink the list so that the last element is not the hole (unless it's
    6177             :       // the first element, because we don't want to end up with a non-canonical
    6178             :       // empty FixedArray).
    6179          80 :       int last = list->length() - 1;
    6180          80 :       while (last >= 0 && list->is_the_hole(isolate, last)) last--;
    6181          80 :       if (last != -1) list->Shrink(isolate, last + 1);
    6182             :       return i::Handle<i::Object>(object, isolate).location();
    6183             :     }
    6184             :   }
    6185             :   return nullptr;
    6186             : }
    6187             : }  // anonymous namespace
    6188             : 
    6189          90 : i::Address* Context::GetDataFromSnapshotOnce(size_t index) {
    6190             :   auto context = Utils::OpenHandle(this);
    6191             :   i::Isolate* i_isolate = context->GetIsolate();
    6192          90 :   i::FixedArray list = context->serialized_objects();
    6193          90 :   return GetSerializedDataFromFixedArray(i_isolate, list, index);
    6194             : }
    6195             : 
    6196        2497 : MaybeLocal<v8::Object> ObjectTemplate::NewInstance(Local<Context> context) {
    6197        9988 :   PREPARE_FOR_EXECUTION(context, ObjectTemplate, NewInstance, Object);
    6198        2497 :   auto self = Utils::OpenHandle(this);
    6199             :   Local<Object> result;
    6200             :   has_pending_exception = !ToLocal<Object>(
    6201        4994 :       i::ApiNatives::InstantiateObject(isolate, self), &result);
    6202        2497 :   RETURN_ON_FAILED_EXECUTION(Object);
    6203        2497 :   RETURN_ESCAPED(result);
    6204             : }
    6205             : 
    6206           0 : void v8::ObjectTemplate::CheckCast(Data* that) {
    6207             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6208           0 :   Utils::ApiCheck(obj->IsObjectTemplateInfo(), "v8::ObjectTemplate::Cast",
    6209             :                   "Could not convert to object template");
    6210           0 : }
    6211             : 
    6212           0 : void v8::FunctionTemplate::CheckCast(Data* that) {
    6213             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6214           0 :   Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::FunctionTemplate::Cast",
    6215             :                   "Could not convert to function template");
    6216           0 : }
    6217             : 
    6218           0 : void v8::Signature::CheckCast(Data* that) {
    6219             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6220           0 :   Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::Signature::Cast",
    6221             :                   "Could not convert to signature");
    6222           0 : }
    6223             : 
    6224           0 : void v8::AccessorSignature::CheckCast(Data* that) {
    6225             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6226           0 :   Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::AccessorSignature::Cast",
    6227             :                   "Could not convert to accessor signature");
    6228           0 : }
    6229             : 
    6230       10634 : MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) {
    6231       42536 :   PREPARE_FOR_EXECUTION(context, FunctionTemplate, GetFunction, Function);
    6232       10634 :   auto self = Utils::OpenHandle(this);
    6233             :   Local<Function> result;
    6234             :   has_pending_exception =
    6235       21268 :       !ToLocal<Function>(i::ApiNatives::InstantiateFunction(self), &result);
    6236       10634 :   RETURN_ON_FAILED_EXECUTION(Function);
    6237       10634 :   RETURN_ESCAPED(result);
    6238             : }
    6239             : 
    6240           8 : MaybeLocal<v8::Object> FunctionTemplate::NewRemoteInstance() {
    6241             :   auto self = Utils::OpenHandle(this);
    6242           8 :   i::Isolate* isolate = self->GetIsolate();
    6243          16 :   LOG_API(isolate, FunctionTemplate, NewRemoteInstance);
    6244             :   i::HandleScope scope(isolate);
    6245             :   i::Handle<i::FunctionTemplateInfo> constructor =
    6246          16 :       EnsureConstructor(isolate, *InstanceTemplate());
    6247          16 :   Utils::ApiCheck(constructor->needs_access_check(),
    6248             :                   "v8::FunctionTemplate::NewRemoteInstance",
    6249             :                   "InstanceTemplate needs to have access checks enabled.");
    6250             :   i::Handle<i::AccessCheckInfo> access_check_info = i::handle(
    6251          16 :       i::AccessCheckInfo::cast(constructor->GetAccessCheckInfo()), isolate);
    6252             :   Utils::ApiCheck(access_check_info->named_interceptor() != i::Object(),
    6253             :                   "v8::FunctionTemplate::NewRemoteInstance",
    6254             :                   "InstanceTemplate needs to have access check handlers.");
    6255             :   i::Handle<i::JSObject> object;
    6256           8 :   if (!i::ApiNatives::InstantiateRemoteObject(
    6257          16 :            Utils::OpenHandle(*InstanceTemplate()))
    6258          16 :            .ToHandle(&object)) {
    6259           0 :     if (isolate->has_pending_exception()) {
    6260           0 :       isolate->OptionalRescheduleException(true);
    6261             :     }
    6262           0 :     return MaybeLocal<Object>();
    6263             :   }
    6264           8 :   return Utils::ToLocal(scope.CloseAndEscape(object));
    6265             : }
    6266             : 
    6267         152 : bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
    6268             :   auto self = Utils::OpenHandle(this);
    6269             :   auto obj = Utils::OpenHandle(*value);
    6270         456 :   if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) {
    6271             :     return true;
    6272             :   }
    6273          76 :   if (obj->IsJSGlobalProxy()) {
    6274             :     // If it's a global proxy, then test with the global object. Note that the
    6275             :     // inner global object may not necessarily be a JSGlobalObject.
    6276             :     i::PrototypeIterator iter(self->GetIsolate(),
    6277           2 :                               i::JSObject::cast(*obj)->map());
    6278             :     // The global proxy should always have a prototype, as it is a bug to call
    6279             :     // this on a detached JSGlobalProxy.
    6280             :     DCHECK(!iter.IsAtEnd());
    6281           4 :     return self->IsTemplateFor(iter.GetCurrent<i::JSObject>());
    6282             :   }
    6283             :   return false;
    6284             : }
    6285             : 
    6286             : 
    6287        3835 : Local<External> v8::External::New(Isolate* isolate, void* value) {
    6288             :   STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
    6289        3835 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6290        7670 :   LOG_API(i_isolate, External, New);
    6291             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6292        3835 :   i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value);
    6293        3835 :   return Utils::ExternalToLocal(external);
    6294             : }
    6295             : 
    6296             : 
    6297      936756 : void* External::Value() const {
    6298      936759 :   return ExternalValue(*Utils::OpenHandle(this));
    6299             : }
    6300             : 
    6301             : 
    6302             : // anonymous namespace for string creation helper functions
    6303             : namespace {
    6304             : 
    6305             : inline int StringLength(const char* string) {
    6306             :   return i::StrLength(string);
    6307             : }
    6308             : 
    6309             : 
    6310             : inline int StringLength(const uint8_t* string) {
    6311             :   return i::StrLength(reinterpret_cast<const char*>(string));
    6312             : }
    6313             : 
    6314             : 
    6315             : inline int StringLength(const uint16_t* string) {
    6316             :   int length = 0;
    6317        4053 :   while (string[length] != '\0')
    6318        4000 :     length++;
    6319             :   return length;
    6320             : }
    6321             : 
    6322             : V8_WARN_UNUSED_RESULT
    6323     9359294 : inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
    6324             :                                            v8::NewStringType type,
    6325             :                                            i::Vector<const char> string) {
    6326     9359294 :   if (type == v8::NewStringType::kInternalized) {
    6327       71820 :     return factory->InternalizeUtf8String(string);
    6328             :   }
    6329     9287474 :   return factory->NewStringFromUtf8(string);
    6330             : }
    6331             : 
    6332             : V8_WARN_UNUSED_RESULT
    6333          24 : inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
    6334             :                                            v8::NewStringType type,
    6335             :                                            i::Vector<const uint8_t> string) {
    6336          24 :   if (type == v8::NewStringType::kInternalized) {
    6337           0 :     return factory->InternalizeOneByteString(string);
    6338             :   }
    6339          24 :   return factory->NewStringFromOneByte(string);
    6340             : }
    6341             : 
    6342             : V8_WARN_UNUSED_RESULT
    6343     1224348 : inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
    6344             :                                            v8::NewStringType type,
    6345             :                                            i::Vector<const uint16_t> string) {
    6346     1224348 :   if (type == v8::NewStringType::kInternalized) {
    6347           0 :     return factory->InternalizeTwoByteString(string);
    6348             :   }
    6349     1224348 :   return factory->NewStringFromTwoByte(string);
    6350             : }
    6351             : 
    6352             : 
    6353             : STATIC_ASSERT(v8::String::kMaxLength == i::String::kMaxLength);
    6354             : 
    6355             : }  // anonymous namespace
    6356             : 
    6357             : // TODO(dcarney): throw a context free exception.
    6358             : #define NEW_STRING(isolate, class_name, function_name, Char, data, type,   \
    6359             :                    length)                                                 \
    6360             :   MaybeLocal<String> result;                                               \
    6361             :   if (length == 0) {                                                       \
    6362             :     result = String::Empty(isolate);                                       \
    6363             :   } else if (length > i::String::kMaxLength) {                             \
    6364             :     result = MaybeLocal<String>();                                         \
    6365             :   } else {                                                                 \
    6366             :     i::Isolate* i_isolate = reinterpret_cast<internal::Isolate*>(isolate); \
    6367             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);                            \
    6368             :     LOG_API(i_isolate, class_name, function_name);                         \
    6369             :     if (length < 0) length = StringLength(data);                           \
    6370             :     i::Handle<i::String> handle_result =                                   \
    6371             :         NewString(i_isolate->factory(), type,                              \
    6372             :                   i::Vector<const Char>(data, length))                     \
    6373             :             .ToHandleChecked();                                            \
    6374             :     result = Utils::ToLocal(handle_result);                                \
    6375             :   }
    6376             : 
    6377           0 : Local<String> String::NewFromUtf8(Isolate* isolate,
    6378             :                                   const char* data,
    6379             :                                   NewStringType type,
    6380             :                                   int length) {
    6381           0 :   NEW_STRING(isolate, String, NewFromUtf8, char, data,
    6382             :              static_cast<v8::NewStringType>(type), length);
    6383           0 :   RETURN_TO_LOCAL_UNCHECKED(result, String);
    6384             : }
    6385             : 
    6386             : 
    6387     9359313 : MaybeLocal<String> String::NewFromUtf8(Isolate* isolate, const char* data,
    6388             :                                        v8::NewStringType type, int length) {
    6389    56155787 :   NEW_STRING(isolate, String, NewFromUtf8, char, data, type, length);
    6390     9359312 :   return result;
    6391             : }
    6392             : 
    6393             : 
    6394          39 : MaybeLocal<String> String::NewFromOneByte(Isolate* isolate, const uint8_t* data,
    6395             :                                           v8::NewStringType type, int length) {
    6396         164 :   NEW_STRING(isolate, String, NewFromOneByte, uint8_t, data, type, length);
    6397          39 :   return result;
    6398             : }
    6399             : 
    6400             : 
    6401           0 : Local<String> String::NewFromTwoByte(Isolate* isolate,
    6402             :                                      const uint16_t* data,
    6403             :                                      NewStringType type,
    6404             :                                      int length) {
    6405           0 :   NEW_STRING(isolate, String, NewFromTwoByte, uint16_t, data,
    6406             :              static_cast<v8::NewStringType>(type), length);
    6407           0 :   RETURN_TO_LOCAL_UNCHECKED(result, String);
    6408             : }
    6409             : 
    6410             : 
    6411     1227708 : MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
    6412             :                                           const uint16_t* data,
    6413             :                                           v8::NewStringType type, int length) {
    6414     7349451 :   NEW_STRING(isolate, String, NewFromTwoByte, uint16_t, data, type, length);
    6415     1227709 :   return result;
    6416             : }
    6417             : 
    6418      140624 : Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
    6419             :                                  Local<String> right) {
    6420      140624 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    6421             :   i::Handle<i::String> left_string = Utils::OpenHandle(*left);
    6422             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6423      281248 :   LOG_API(isolate, String, Concat);
    6424             :   i::Handle<i::String> right_string = Utils::OpenHandle(*right);
    6425             :   // If we are steering towards a range error, do not wait for the error to be
    6426             :   // thrown, and return the null handle instead.
    6427      140624 :   if (left_string->length() + right_string->length() > i::String::kMaxLength) {
    6428          10 :     return Local<String>();
    6429             :   }
    6430             :   i::Handle<i::String> result = isolate->factory()->NewConsString(
    6431      281228 :       left_string, right_string).ToHandleChecked();
    6432             :   return Utils::ToLocal(result);
    6433             : }
    6434             : 
    6435       18910 : MaybeLocal<String> v8::String::NewExternalTwoByte(
    6436             :     Isolate* isolate, v8::String::ExternalStringResource* resource) {
    6437       18910 :   CHECK(resource && resource->data());
    6438             :   // TODO(dcarney): throw a context free exception.
    6439       18910 :   if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) {
    6440           6 :     return MaybeLocal<String>();
    6441             :   }
    6442       18904 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6443             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6444       37808 :   LOG_API(i_isolate, String, NewExternalTwoByte);
    6445       18904 :   if (resource->length() > 0) {
    6446             :     i::Handle<i::String> string = i_isolate->factory()
    6447             :                                       ->NewExternalStringFromTwoByte(resource)
    6448       37788 :                                       .ToHandleChecked();
    6449       18894 :     return Utils::ToLocal(string);
    6450             :   } else {
    6451             :     // The resource isn't going to be used, free it immediately.
    6452          10 :     resource->Dispose();
    6453          10 :     return Utils::ToLocal(i_isolate->factory()->empty_string());
    6454             :   }
    6455             : }
    6456             : 
    6457             : 
    6458        1292 : MaybeLocal<String> v8::String::NewExternalOneByte(
    6459             :     Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
    6460        1292 :   CHECK(resource && resource->data());
    6461             :   // TODO(dcarney): throw a context free exception.
    6462        1292 :   if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) {
    6463           6 :     return MaybeLocal<String>();
    6464             :   }
    6465        1286 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6466             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6467        2572 :   LOG_API(i_isolate, String, NewExternalOneByte);
    6468        1286 :   if (resource->length() > 0) {
    6469             :     i::Handle<i::String> string = i_isolate->factory()
    6470             :                                       ->NewExternalStringFromOneByte(resource)
    6471        2562 :                                       .ToHandleChecked();
    6472        1281 :     return Utils::ToLocal(string);
    6473             :   } else {
    6474             :     // The resource isn't going to be used, free it immediately.
    6475           5 :     resource->Dispose();
    6476           5 :     return Utils::ToLocal(i_isolate->factory()->empty_string());
    6477             :   }
    6478             : }
    6479             : 
    6480             : 
    6481           0 : Local<String> v8::String::NewExternal(
    6482             :     Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
    6483           0 :   RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String);
    6484             : }
    6485             : 
    6486             : 
    6487         295 : bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
    6488             :   i::DisallowHeapAllocation no_allocation;
    6489             : 
    6490         295 :   i::String obj = *Utils::OpenHandle(this);
    6491             : 
    6492         295 :   if (obj->IsThinString()) {
    6493           0 :     obj = i::ThinString::cast(obj)->actual();
    6494             :   }
    6495             : 
    6496         295 :   if (!obj->SupportsExternalization()) {
    6497             :     return false;
    6498             :   }
    6499             : 
    6500             :   // It is safe to call GetIsolateFromWritableHeapObject because
    6501             :   // SupportsExternalization already checked that the object is writable.
    6502             :   i::Isolate* isolate;
    6503         295 :   i::GetIsolateFromWritableObject(obj, &isolate);
    6504         295 :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6505             : 
    6506         295 :   CHECK(resource && resource->data());
    6507             : 
    6508         295 :   bool result = obj->MakeExternal(resource);
    6509             :   DCHECK(result);
    6510             :   DCHECK(obj->IsExternalString());
    6511             :   return result;
    6512             : }
    6513             : 
    6514             : 
    6515         295 : bool v8::String::MakeExternal(
    6516             :     v8::String::ExternalOneByteStringResource* resource) {
    6517             :   i::DisallowHeapAllocation no_allocation;
    6518             : 
    6519         295 :   i::String obj = *Utils::OpenHandle(this);
    6520             : 
    6521         295 :   if (obj->IsThinString()) {
    6522           0 :     obj = i::ThinString::cast(obj)->actual();
    6523             :   }
    6524             : 
    6525         295 :   if (!obj->SupportsExternalization()) {
    6526             :     return false;
    6527             :   }
    6528             : 
    6529             :   // It is safe to call GetIsolateFromWritableHeapObject because
    6530             :   // SupportsExternalization already checked that the object is writable.
    6531             :   i::Isolate* isolate;
    6532         295 :   i::GetIsolateFromWritableObject(obj, &isolate);
    6533         295 :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6534             : 
    6535         295 :   CHECK(resource && resource->data());
    6536             : 
    6537         295 :   bool result = obj->MakeExternal(resource);
    6538             :   DCHECK(result);
    6539             :   DCHECK(obj->IsExternalString());
    6540             :   return result;
    6541             : }
    6542             : 
    6543             : 
    6544          20 : bool v8::String::CanMakeExternal() {
    6545             :   i::DisallowHeapAllocation no_allocation;
    6546          20 :   i::String obj = *Utils::OpenHandle(this);
    6547             : 
    6548          20 :   if (obj->IsThinString()) {
    6549           0 :     obj = i::ThinString::cast(obj)->actual();
    6550             :   }
    6551             : 
    6552          20 :   if (!obj->SupportsExternalization()) {
    6553             :     return false;
    6554             :   }
    6555             : 
    6556             :   // Only old space strings should be externalized.
    6557          20 :   return !i::Heap::InYoungGeneration(obj);
    6558             : }
    6559             : 
    6560       17116 : bool v8::String::StringEquals(Local<String> that) {
    6561             :   auto self = Utils::OpenHandle(this);
    6562             :   auto other = Utils::OpenHandle(*that);
    6563       17116 :   return self->Equals(*other);
    6564             : }
    6565             : 
    6566       79950 : Isolate* v8::Object::GetIsolate() {
    6567             :   i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
    6568       79950 :   return reinterpret_cast<Isolate*>(i_isolate);
    6569             : }
    6570             : 
    6571             : 
    6572      107723 : Local<v8::Object> v8::Object::New(Isolate* isolate) {
    6573      107723 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6574      215446 :   LOG_API(i_isolate, Object, New);
    6575             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6576             :   i::Handle<i::JSObject> obj =
    6577      107723 :       i_isolate->factory()->NewJSObject(i_isolate->object_function());
    6578      107723 :   return Utils::ToLocal(obj);
    6579             : }
    6580             : 
    6581          48 : Local<v8::Object> v8::Object::New(Isolate* isolate,
    6582             :                                   Local<Value> prototype_or_null,
    6583             :                                   Local<Name>* names, Local<Value>* values,
    6584             :                                   size_t length) {
    6585          48 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6586             :   i::Handle<i::Object> proto = Utils::OpenHandle(*prototype_or_null);
    6587         168 :   if (!Utils::ApiCheck(proto->IsNull() || proto->IsJSReceiver(),
    6588             :                        "v8::Object::New", "prototype must be null or object")) {
    6589           0 :     return Local<v8::Object>();
    6590             :   }
    6591          96 :   LOG_API(i_isolate, Object, New);
    6592             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6593             : 
    6594             :   // We assume that this API is mostly used to create objects with named
    6595             :   // properties, and so we default to creating a properties backing store
    6596             :   // large enough to hold all of them, while we start with no elements
    6597             :   // (see http://bit.ly/v8-fast-object-create-cpp for the motivation).
    6598             :   i::Handle<i::NameDictionary> properties =
    6599          48 :       i::NameDictionary::New(i_isolate, static_cast<int>(length));
    6600             :   i::Handle<i::FixedArrayBase> elements =
    6601             :       i_isolate->factory()->empty_fixed_array();
    6602       61566 :   for (size_t i = 0; i < length; ++i) {
    6603       61518 :     i::Handle<i::Name> name = Utils::OpenHandle(*names[i]);
    6604       61518 :     i::Handle<i::Object> value = Utils::OpenHandle(*values[i]);
    6605             : 
    6606             :     // See if the {name} is a valid array index, in which case we need to
    6607             :     // add the {name}/{value} pair to the {elements}, otherwise they end
    6608             :     // up in the {properties} backing store.
    6609             :     uint32_t index;
    6610       61518 :     if (name->AsArrayIndex(&index)) {
    6611             :       // If this is the first element, allocate a proper
    6612             :       // dictionary elements backing store for {elements}.
    6613          36 :       if (!elements->IsNumberDictionary()) {
    6614             :         elements =
    6615          12 :             i::NumberDictionary::New(i_isolate, static_cast<int>(length));
    6616             :       }
    6617             :       elements = i::NumberDictionary::Set(
    6618             :           i_isolate, i::Handle<i::NumberDictionary>::cast(elements), index,
    6619          18 :           value);
    6620             :     } else {
    6621             :       // Internalize the {name} first.
    6622       61500 :       name = i_isolate->factory()->InternalizeName(name);
    6623       61500 :       int const entry = properties->FindEntry(i_isolate, name);
    6624       61500 :       if (entry == i::NameDictionary::kNotFound) {
    6625             :         // Add the {name}/{value} pair as a new entry.
    6626             :         properties = i::NameDictionary::Add(i_isolate, properties, name, value,
    6627       61488 :                                             i::PropertyDetails::Empty());
    6628             :       } else {
    6629             :         // Overwrite the {entry} with the {value}.
    6630          24 :         properties->ValueAtPut(entry, *value);
    6631             :       }
    6632             :     }
    6633             :   }
    6634             :   i::Handle<i::JSObject> obj =
    6635             :       i_isolate->factory()->NewSlowJSObjectWithPropertiesAndElements(
    6636          48 :           proto, properties, elements);
    6637             :   return Utils::ToLocal(obj);
    6638             : }
    6639             : 
    6640           6 : Local<v8::Value> v8::NumberObject::New(Isolate* isolate, double value) {
    6641           6 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6642          12 :   LOG_API(i_isolate, NumberObject, New);
    6643             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6644           6 :   i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value);
    6645             :   i::Handle<i::Object> obj =
    6646          12 :       i::Object::ToObject(i_isolate, number).ToHandleChecked();
    6647           6 :   return Utils::ToLocal(obj);
    6648             : }
    6649             : 
    6650             : 
    6651          29 : double v8::NumberObject::ValueOf() const {
    6652             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6653          29 :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6654          29 :   i::Isolate* isolate = jsvalue->GetIsolate();
    6655          58 :   LOG_API(isolate, NumberObject, NumberValue);
    6656          58 :   return jsvalue->value()->Number();
    6657             : }
    6658             : 
    6659           7 : Local<v8::Value> v8::BigIntObject::New(Isolate* isolate, int64_t value) {
    6660           7 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6661          14 :   LOG_API(i_isolate, BigIntObject, New);
    6662             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6663           7 :   i::Handle<i::Object> bigint = i::BigInt::FromInt64(i_isolate, value);
    6664             :   i::Handle<i::Object> obj =
    6665          14 :       i::Object::ToObject(i_isolate, bigint).ToHandleChecked();
    6666           7 :   return Utils::ToLocal(obj);
    6667             : }
    6668             : 
    6669          11 : Local<v8::BigInt> v8::BigIntObject::ValueOf() const {
    6670             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6671          11 :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6672          11 :   i::Isolate* isolate = jsvalue->GetIsolate();
    6673          22 :   LOG_API(isolate, BigIntObject, BigIntValue);
    6674             :   return Utils::ToLocal(
    6675          11 :       i::Handle<i::BigInt>(i::BigInt::cast(jsvalue->value()), isolate));
    6676             : }
    6677             : 
    6678          24 : Local<v8::Value> v8::BooleanObject::New(Isolate* isolate, bool value) {
    6679          24 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6680          48 :   LOG_API(i_isolate, BooleanObject, New);
    6681             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6682             :   i::Handle<i::Object> boolean(value
    6683             :                                    ? i::ReadOnlyRoots(i_isolate).true_value()
    6684             :                                    : i::ReadOnlyRoots(i_isolate).false_value(),
    6685          24 :                                i_isolate);
    6686             :   i::Handle<i::Object> obj =
    6687          48 :       i::Object::ToObject(i_isolate, boolean).ToHandleChecked();
    6688          24 :   return Utils::ToLocal(obj);
    6689             : }
    6690             : 
    6691             : 
    6692          47 : bool v8::BooleanObject::ValueOf() const {
    6693             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6694          47 :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6695          47 :   i::Isolate* isolate = jsvalue->GetIsolate();
    6696          94 :   LOG_API(isolate, BooleanObject, BooleanValue);
    6697         141 :   return jsvalue->value()->IsTrue(isolate);
    6698             : }
    6699             : 
    6700             : 
    6701          12 : Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
    6702             :                                        Local<String> value) {
    6703             :   i::Handle<i::String> string = Utils::OpenHandle(*value);
    6704          12 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    6705          24 :   LOG_API(isolate, StringObject, New);
    6706             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6707             :   i::Handle<i::Object> obj =
    6708          24 :       i::Object::ToObject(isolate, string).ToHandleChecked();
    6709          12 :   return Utils::ToLocal(obj);
    6710             : }
    6711             : 
    6712             : 
    6713          34 : Local<v8::String> v8::StringObject::ValueOf() const {
    6714             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6715          34 :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6716          34 :   i::Isolate* isolate = jsvalue->GetIsolate();
    6717          68 :   LOG_API(isolate, StringObject, StringValue);
    6718             :   return Utils::ToLocal(
    6719          34 :       i::Handle<i::String>(i::String::cast(jsvalue->value()), isolate));
    6720             : }
    6721             : 
    6722             : 
    6723           6 : Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Local<Symbol> value) {
    6724           6 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6725          12 :   LOG_API(i_isolate, SymbolObject, New);
    6726             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6727             :   i::Handle<i::Object> obj = i::Object::ToObject(
    6728          12 :       i_isolate, Utils::OpenHandle(*value)).ToHandleChecked();
    6729           6 :   return Utils::ToLocal(obj);
    6730             : }
    6731             : 
    6732             : 
    6733          11 : Local<v8::Symbol> v8::SymbolObject::ValueOf() const {
    6734             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6735          11 :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6736          11 :   i::Isolate* isolate = jsvalue->GetIsolate();
    6737          22 :   LOG_API(isolate, SymbolObject, SymbolValue);
    6738             :   return Utils::ToLocal(
    6739          11 :       i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()), isolate));
    6740             : }
    6741             : 
    6742             : 
    6743         132 : MaybeLocal<v8::Value> v8::Date::New(Local<Context> context, double time) {
    6744         132 :   if (std::isnan(time)) {
    6745             :     // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
    6746             :     time = std::numeric_limits<double>::quiet_NaN();
    6747             :   }
    6748         528 :   PREPARE_FOR_EXECUTION(context, Date, New, Value);
    6749             :   Local<Value> result;
    6750             :   has_pending_exception = !ToLocal<Value>(
    6751             :       i::JSDate::New(isolate->date_function(), isolate->date_function(), time),
    6752         396 :       &result);
    6753         132 :   RETURN_ON_FAILED_EXECUTION(Value);
    6754         132 :   RETURN_ESCAPED(result);
    6755             : }
    6756             : 
    6757             : 
    6758          10 : double v8::Date::ValueOf() const {
    6759             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6760          10 :   i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj);
    6761          10 :   i::Isolate* isolate = jsdate->GetIsolate();
    6762          20 :   LOG_API(isolate, Date, NumberValue);
    6763          20 :   return jsdate->value()->Number();
    6764             : }
    6765             : 
    6766             : // Assert that the static TimeZoneDetection cast in
    6767             : // DateTimeConfigurationChangeNotification is valid.
    6768             : #define TIME_ZONE_DETECTION_ASSERT_EQ(value)                  \
    6769             :   STATIC_ASSERT(                                              \
    6770             :       static_cast<int>(v8::Date::TimeZoneDetection::value) == \
    6771             :       static_cast<int>(base::TimezoneCache::TimeZoneDetection::value))
    6772             : TIME_ZONE_DETECTION_ASSERT_EQ(kSkip);
    6773             : TIME_ZONE_DETECTION_ASSERT_EQ(kRedetect);
    6774             : #undef TIME_ZONE_DETECTION_ASSERT_EQ
    6775             : 
    6776           0 : void v8::Date::DateTimeConfigurationChangeNotification(
    6777             :     Isolate* isolate, TimeZoneDetection time_zone_detection) {
    6778           0 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6779           0 :   LOG_API(i_isolate, Date, DateTimeConfigurationChangeNotification);
    6780             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6781             :   i_isolate->date_cache()->ResetDateCache(
    6782           0 :       static_cast<base::TimezoneCache::TimeZoneDetection>(time_zone_detection));
    6783             : #ifdef V8_INTL_SUPPORT
    6784             :   i_isolate->clear_cached_icu_object(
    6785           0 :       i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat);
    6786             :   i_isolate->clear_cached_icu_object(
    6787           0 :       i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime);
    6788             :   i_isolate->clear_cached_icu_object(
    6789           0 :       i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate);
    6790             : #endif  // V8_INTL_SUPPORT
    6791           0 : }
    6792             : 
    6793         165 : MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
    6794             :                                        Local<String> pattern, Flags flags) {
    6795         660 :   PREPARE_FOR_EXECUTION(context, RegExp, New, RegExp);
    6796             :   Local<v8::RegExp> result;
    6797             :   has_pending_exception =
    6798             :       !ToLocal<RegExp>(i::JSRegExp::New(isolate, Utils::OpenHandle(*pattern),
    6799             :                                         static_cast<i::JSRegExp::Flags>(flags)),
    6800         495 :                        &result);
    6801         165 :   RETURN_ON_FAILED_EXECUTION(RegExp);
    6802         155 :   RETURN_ESCAPED(result);
    6803             : }
    6804             : 
    6805             : 
    6806         120 : Local<v8::String> v8::RegExp::GetSource() const {
    6807             :   i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
    6808             :   return Utils::ToLocal(
    6809         240 :       i::Handle<i::String>(obj->Pattern(), obj->GetIsolate()));
    6810             : }
    6811             : 
    6812             : 
    6813             : // Assert that the static flags cast in GetFlags is valid.
    6814             : #define REGEXP_FLAG_ASSERT_EQ(flag)                   \
    6815             :   STATIC_ASSERT(static_cast<int>(v8::RegExp::flag) == \
    6816             :                 static_cast<int>(i::JSRegExp::flag))
    6817             : REGEXP_FLAG_ASSERT_EQ(kNone);
    6818             : REGEXP_FLAG_ASSERT_EQ(kGlobal);
    6819             : REGEXP_FLAG_ASSERT_EQ(kIgnoreCase);
    6820             : REGEXP_FLAG_ASSERT_EQ(kMultiline);
    6821             : REGEXP_FLAG_ASSERT_EQ(kSticky);
    6822             : REGEXP_FLAG_ASSERT_EQ(kUnicode);
    6823             : #undef REGEXP_FLAG_ASSERT_EQ
    6824             : 
    6825         120 : v8::RegExp::Flags v8::RegExp::GetFlags() const {
    6826             :   i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
    6827         240 :   return RegExp::Flags(static_cast<int>(obj->GetFlags()));
    6828             : }
    6829             : 
    6830             : 
    6831       68661 : Local<v8::Array> v8::Array::New(Isolate* isolate, int length) {
    6832       68661 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6833      137322 :   LOG_API(i_isolate, Array, New);
    6834             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6835       68661 :   int real_length = length > 0 ? length : 0;
    6836       68661 :   i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length);
    6837             :   i::Handle<i::Object> length_obj =
    6838       68661 :       i_isolate->factory()->NewNumberFromInt(real_length);
    6839       68661 :   obj->set_length(*length_obj);
    6840       68661 :   return Utils::ToLocal(obj);
    6841             : }
    6842             : 
    6843           6 : Local<v8::Array> v8::Array::New(Isolate* isolate, Local<Value>* elements,
    6844             :                                 size_t length) {
    6845           6 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6846             :   i::Factory* factory = i_isolate->factory();
    6847          12 :   LOG_API(i_isolate, Array, New);
    6848             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6849           6 :   int len = static_cast<int>(length);
    6850             : 
    6851           6 :   i::Handle<i::FixedArray> result = factory->NewFixedArray(len);
    6852          24 :   for (int i = 0; i < len; i++) {
    6853          18 :     i::Handle<i::Object> element = Utils::OpenHandle(*elements[i]);
    6854          18 :     result->set(i, *element);
    6855             :   }
    6856             : 
    6857             :   return Utils::ToLocal(
    6858          12 :       factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, len));
    6859             : }
    6860             : 
    6861      195248 : uint32_t v8::Array::Length() const {
    6862             :   i::Handle<i::JSArray> obj = Utils::OpenHandle(this);
    6863      195248 :   i::Object length = obj->length();
    6864      195248 :   if (length->IsSmi()) {
    6865      195248 :     return i::Smi::ToInt(length);
    6866             :   } else {
    6867           0 :     return static_cast<uint32_t>(length->Number());
    6868             :   }
    6869             : }
    6870             : 
    6871             : 
    6872           5 : Local<v8::Map> v8::Map::New(Isolate* isolate) {
    6873           5 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6874          10 :   LOG_API(i_isolate, Map, New);
    6875             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6876           5 :   i::Handle<i::JSMap> obj = i_isolate->factory()->NewJSMap();
    6877           5 :   return Utils::ToLocal(obj);
    6878             : }
    6879             : 
    6880             : 
    6881         188 : size_t v8::Map::Size() const {
    6882             :   i::Handle<i::JSMap> obj = Utils::OpenHandle(this);
    6883         188 :   return i::OrderedHashMap::cast(obj->table())->NumberOfElements();
    6884             : }
    6885             : 
    6886             : 
    6887           5 : void Map::Clear() {
    6888             :   auto self = Utils::OpenHandle(this);
    6889           5 :   i::Isolate* isolate = self->GetIsolate();
    6890          10 :   LOG_API(isolate, Map, Clear);
    6891             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6892           5 :   i::JSMap::Clear(isolate, self);
    6893           5 : }
    6894             : 
    6895             : 
    6896          15 : MaybeLocal<Value> Map::Get(Local<Context> context, Local<Value> key) {
    6897          60 :   PREPARE_FOR_EXECUTION(context, Map, Get, Value);
    6898             :   auto self = Utils::OpenHandle(this);
    6899             :   Local<Value> result;
    6900          15 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    6901             :   has_pending_exception =
    6902             :       !ToLocal<Value>(i::Execution::Call(isolate, isolate->map_get(), self,
    6903             :                                          arraysize(argv), argv),
    6904          45 :                       &result);
    6905          15 :   RETURN_ON_FAILED_EXECUTION(Value);
    6906          15 :   RETURN_ESCAPED(result);
    6907             : }
    6908             : 
    6909             : 
    6910           5 : MaybeLocal<Map> Map::Set(Local<Context> context, Local<Value> key,
    6911             :                          Local<Value> value) {
    6912          20 :   PREPARE_FOR_EXECUTION(context, Map, Set, Map);
    6913             :   auto self = Utils::OpenHandle(this);
    6914             :   i::Handle<i::Object> result;
    6915             :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
    6916          10 :                                  Utils::OpenHandle(*value)};
    6917             :   has_pending_exception = !i::Execution::Call(isolate, isolate->map_set(), self,
    6918          10 :                                               arraysize(argv), argv)
    6919          10 :                                .ToHandle(&result);
    6920           5 :   RETURN_ON_FAILED_EXECUTION(Map);
    6921           5 :   RETURN_ESCAPED(Local<Map>::Cast(Utils::ToLocal(result)));
    6922             : }
    6923             : 
    6924             : 
    6925          30 : Maybe<bool> Map::Has(Local<Context> context, Local<Value> key) {
    6926          60 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    6927         120 :   ENTER_V8(isolate, context, Map, Has, Nothing<bool>(), i::HandleScope);
    6928             :   auto self = Utils::OpenHandle(this);
    6929             :   i::Handle<i::Object> result;
    6930          30 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    6931             :   has_pending_exception = !i::Execution::Call(isolate, isolate->map_has(), self,
    6932          60 :                                               arraysize(argv), argv)
    6933          60 :                                .ToHandle(&result);
    6934          30 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    6935          60 :   return Just(result->IsTrue(isolate));
    6936             : }
    6937             : 
    6938             : 
    6939          15 : Maybe<bool> Map::Delete(Local<Context> context, Local<Value> key) {
    6940          30 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    6941          60 :   ENTER_V8(isolate, context, Map, Delete, Nothing<bool>(), i::HandleScope);
    6942             :   auto self = Utils::OpenHandle(this);
    6943             :   i::Handle<i::Object> result;
    6944          15 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    6945             :   has_pending_exception = !i::Execution::Call(isolate, isolate->map_delete(),
    6946          30 :                                               self, arraysize(argv), argv)
    6947          30 :                                .ToHandle(&result);
    6948          15 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    6949          30 :   return Just(result->IsTrue(isolate));
    6950             : }
    6951             : 
    6952             : namespace {
    6953             : 
    6954             : enum class MapAsArrayKind {
    6955             :   kEntries = i::JS_MAP_KEY_VALUE_ITERATOR_TYPE,
    6956             :   kKeys = i::JS_MAP_KEY_ITERATOR_TYPE,
    6957             :   kValues = i::JS_MAP_VALUE_ITERATOR_TYPE
    6958             : };
    6959             : 
    6960             : enum class SetAsArrayKind {
    6961             :   kEntries = i::JS_SET_KEY_VALUE_ITERATOR_TYPE,
    6962             :   kValues = i::JS_SET_VALUE_ITERATOR_TYPE
    6963             : };
    6964             : 
    6965         245 : i::Handle<i::JSArray> MapAsArray(i::Isolate* isolate, i::Object table_obj,
    6966             :                                  int offset, MapAsArrayKind kind) {
    6967             :   i::Factory* factory = isolate->factory();
    6968             :   i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(table_obj),
    6969             :                                      isolate);
    6970             :   const bool collect_keys =
    6971         245 :       kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys;
    6972             :   const bool collect_values =
    6973         245 :       kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues;
    6974         245 :   int capacity = table->UsedCapacity();
    6975             :   int max_length =
    6976         245 :       (capacity - offset) * ((collect_keys && collect_values) ? 2 : 1);
    6977         245 :   i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length);
    6978             :   int result_index = 0;
    6979             :   {
    6980             :     i::DisallowHeapAllocation no_gc;
    6981             :     i::Oddball the_hole = i::ReadOnlyRoots(isolate).the_hole_value();
    6982        5683 :     for (int i = offset; i < capacity; ++i) {
    6983        5438 :       i::Object key = table->KeyAt(i);
    6984        5443 :       if (key == the_hole) continue;
    6985       10723 :       if (collect_keys) result->set(result_index++, key);
    6986       16203 :       if (collect_values) result->set(result_index++, table->ValueAt(i));
    6987             :     }
    6988             :   }
    6989             :   DCHECK_GE(max_length, result_index);
    6990         245 :   if (result_index == 0) return factory->NewJSArray(0);
    6991         221 :   result->Shrink(isolate, result_index);
    6992             :   return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
    6993         221 :                                          result_index);
    6994             : }
    6995             : 
    6996             : }  // namespace
    6997             : 
    6998         123 : Local<Array> Map::AsArray() const {
    6999             :   i::Handle<i::JSMap> obj = Utils::OpenHandle(this);
    7000         123 :   i::Isolate* isolate = obj->GetIsolate();
    7001         246 :   LOG_API(isolate, Map, AsArray);
    7002             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7003             :   return Utils::ToLocal(
    7004         246 :       MapAsArray(isolate, obj->table(), 0, MapAsArrayKind::kEntries));
    7005             : }
    7006             : 
    7007             : 
    7008       79588 : Local<v8::Set> v8::Set::New(Isolate* isolate) {
    7009       79588 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7010      159176 :   LOG_API(i_isolate, Set, New);
    7011             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7012       79588 :   i::Handle<i::JSSet> obj = i_isolate->factory()->NewJSSet();
    7013       79588 :   return Utils::ToLocal(obj);
    7014             : }
    7015             : 
    7016             : 
    7017         124 : size_t v8::Set::Size() const {
    7018             :   i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
    7019         124 :   return i::OrderedHashSet::cast(obj->table())->NumberOfElements();
    7020             : }
    7021             : 
    7022             : 
    7023           5 : void Set::Clear() {
    7024             :   auto self = Utils::OpenHandle(this);
    7025           5 :   i::Isolate* isolate = self->GetIsolate();
    7026          10 :   LOG_API(isolate, Set, Clear);
    7027             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7028           5 :   i::JSSet::Clear(isolate, self);
    7029           5 : }
    7030             : 
    7031             : 
    7032     3001518 : MaybeLocal<Set> Set::Add(Local<Context> context, Local<Value> key) {
    7033    12006072 :   PREPARE_FOR_EXECUTION(context, Set, Add, Set);
    7034             :   auto self = Utils::OpenHandle(this);
    7035             :   i::Handle<i::Object> result;
    7036     3001518 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    7037             :   has_pending_exception = !i::Execution::Call(isolate, isolate->set_add(), self,
    7038     6003036 :                                               arraysize(argv), argv)
    7039     6003036 :                                .ToHandle(&result);
    7040     3001518 :   RETURN_ON_FAILED_EXECUTION(Set);
    7041     3001518 :   RETURN_ESCAPED(Local<Set>::Cast(Utils::ToLocal(result)));
    7042             : }
    7043             : 
    7044             : 
    7045     4469608 : Maybe<bool> Set::Has(Local<Context> context, Local<Value> key) {
    7046     8939216 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7047    17878432 :   ENTER_V8(isolate, context, Set, Has, Nothing<bool>(), i::HandleScope);
    7048             :   auto self = Utils::OpenHandle(this);
    7049             :   i::Handle<i::Object> result;
    7050     4469608 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    7051             :   has_pending_exception = !i::Execution::Call(isolate, isolate->set_has(), self,
    7052     8939216 :                                               arraysize(argv), argv)
    7053     8939216 :                                .ToHandle(&result);
    7054     4469608 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7055     8939216 :   return Just(result->IsTrue(isolate));
    7056             : }
    7057             : 
    7058             : 
    7059          70 : Maybe<bool> Set::Delete(Local<Context> context, Local<Value> key) {
    7060         140 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7061         280 :   ENTER_V8(isolate, context, Set, Delete, Nothing<bool>(), i::HandleScope);
    7062             :   auto self = Utils::OpenHandle(this);
    7063             :   i::Handle<i::Object> result;
    7064          70 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    7065             :   has_pending_exception = !i::Execution::Call(isolate, isolate->set_delete(),
    7066         140 :                                               self, arraysize(argv), argv)
    7067         140 :                                .ToHandle(&result);
    7068          70 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7069         140 :   return Just(result->IsTrue(isolate));
    7070             : }
    7071             : 
    7072             : namespace {
    7073         656 : i::Handle<i::JSArray> SetAsArray(i::Isolate* isolate, i::Object table_obj,
    7074             :                                  int offset, SetAsArrayKind kind) {
    7075             :   i::Factory* factory = isolate->factory();
    7076             :   i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(table_obj),
    7077             :                                      isolate);
    7078             :   // Elements skipped by |offset| may already be deleted.
    7079         656 :   int capacity = table->UsedCapacity();
    7080         656 :   const bool collect_key_values = kind == SetAsArrayKind::kEntries;
    7081         656 :   int max_length = (capacity - offset) * (collect_key_values ? 2 : 1);
    7082         656 :   if (max_length == 0) return factory->NewJSArray(0);
    7083         642 :   i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length);
    7084             :   int result_index = 0;
    7085             :   {
    7086             :     i::DisallowHeapAllocation no_gc;
    7087             :     i::Oddball the_hole = i::ReadOnlyRoots(isolate).the_hole_value();
    7088       14216 :     for (int i = offset; i < capacity; ++i) {
    7089       13574 :       i::Object key = table->KeyAt(i);
    7090       13639 :       if (key == the_hole) continue;
    7091       27018 :       result->set(result_index++, key);
    7092       13567 :       if (collect_key_values) result->set(result_index++, key);
    7093             :     }
    7094             :   }
    7095             :   DCHECK_GE(max_length, result_index);
    7096         642 :   if (result_index == 0) return factory->NewJSArray(0);
    7097         642 :   result->Shrink(isolate, result_index);
    7098             :   return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
    7099         642 :                                          result_index);
    7100             : }
    7101             : }  // namespace
    7102             : 
    7103         529 : Local<Array> Set::AsArray() const {
    7104             :   i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
    7105         529 :   i::Isolate* isolate = obj->GetIsolate();
    7106        1058 :   LOG_API(isolate, Set, AsArray);
    7107             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7108             :   return Utils::ToLocal(
    7109        1058 :       SetAsArray(isolate, obj->table(), 0, SetAsArrayKind::kValues));
    7110             : }
    7111             : 
    7112             : 
    7113        8516 : MaybeLocal<Promise::Resolver> Promise::Resolver::New(Local<Context> context) {
    7114       34064 :   PREPARE_FOR_EXECUTION(context, Promise_Resolver, New, Resolver);
    7115             :   Local<Promise::Resolver> result;
    7116             :   has_pending_exception =
    7117        8516 :       !ToLocal<Promise::Resolver>(isolate->factory()->NewJSPromise(), &result);
    7118        8516 :   RETURN_ON_FAILED_EXECUTION(Promise::Resolver);
    7119        8516 :   RETURN_ESCAPED(result);
    7120             : }
    7121             : 
    7122             : 
    7123        8511 : Local<Promise> Promise::Resolver::GetPromise() {
    7124             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7125        8511 :   return Local<Promise>::Cast(Utils::ToLocal(promise));
    7126             : }
    7127             : 
    7128             : 
    7129         940 : Maybe<bool> Promise::Resolver::Resolve(Local<Context> context,
    7130             :                                        Local<Value> value) {
    7131        1880 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7132        3760 :   ENTER_V8(isolate, context, Promise_Resolver, Resolve, Nothing<bool>(),
    7133             :            i::HandleScope);
    7134         940 :   auto self = Utils::OpenHandle(this);
    7135         940 :   auto promise = i::Handle<i::JSPromise>::cast(self);
    7136             : 
    7137         940 :   if (promise->status() != Promise::kPending) {
    7138             :     return Just(true);
    7139             :   }
    7140             : 
    7141             :   has_pending_exception =
    7142        1860 :       i::JSPromise::Resolve(promise, Utils::OpenHandle(*value)).is_null();
    7143         930 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7144             :   return Just(true);
    7145             : }
    7146             : 
    7147             : 
    7148         281 : Maybe<bool> Promise::Resolver::Reject(Local<Context> context,
    7149             :                                       Local<Value> value) {
    7150         562 :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7151        1124 :   ENTER_V8(isolate, context, Promise_Resolver, Reject, Nothing<bool>(),
    7152             :            i::HandleScope);
    7153         281 :   auto self = Utils::OpenHandle(this);
    7154         281 :   auto promise = i::Handle<i::JSPromise>::cast(self);
    7155             : 
    7156         281 :   if (promise->status() != Promise::kPending) {
    7157             :     return Just(true);
    7158             :   }
    7159             : 
    7160             :   has_pending_exception =
    7161         542 :       i::JSPromise::Reject(promise, Utils::OpenHandle(*value)).is_null();
    7162         271 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7163             :   return Just(true);
    7164             : }
    7165             : 
    7166             : 
    7167         655 : MaybeLocal<Promise> Promise::Catch(Local<Context> context,
    7168             :                                    Local<Function> handler) {
    7169        2620 :   PREPARE_FOR_EXECUTION(context, Promise, Catch, Promise);
    7170             :   auto self = Utils::OpenHandle(this);
    7171             :   i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
    7172             :   i::Handle<i::Object> result;
    7173             :   has_pending_exception = !i::Execution::Call(isolate, isolate->promise_catch(),
    7174        1310 :                                               self, arraysize(argv), argv)
    7175        1310 :                                .ToHandle(&result);
    7176         655 :   RETURN_ON_FAILED_EXECUTION(Promise);
    7177         655 :   RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
    7178             : }
    7179             : 
    7180             : 
    7181         699 : MaybeLocal<Promise> Promise::Then(Local<Context> context,
    7182             :                                   Local<Function> handler) {
    7183        2796 :   PREPARE_FOR_EXECUTION(context, Promise, Then, Promise);
    7184             :   auto self = Utils::OpenHandle(this);
    7185             :   i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
    7186             :   i::Handle<i::Object> result;
    7187             :   has_pending_exception = !i::Execution::Call(isolate, isolate->promise_then(),
    7188        1398 :                                               self, arraysize(argv), argv)
    7189        1398 :                                .ToHandle(&result);
    7190         699 :   RETURN_ON_FAILED_EXECUTION(Promise);
    7191         699 :   RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
    7192             : }
    7193             : 
    7194          35 : MaybeLocal<Promise> Promise::Then(Local<Context> context,
    7195             :                                   Local<Function> on_fulfilled,
    7196             :                                   Local<Function> on_rejected) {
    7197         140 :   PREPARE_FOR_EXECUTION(context, Promise, Then, Promise);
    7198             :   auto self = Utils::OpenHandle(this);
    7199             :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*on_fulfilled),
    7200             :                                  Utils::OpenHandle(*on_rejected)};
    7201             :   i::Handle<i::Object> result;
    7202             :   has_pending_exception = !i::Execution::Call(isolate, isolate->promise_then(),
    7203          70 :                                               self, arraysize(argv), argv)
    7204          70 :                                .ToHandle(&result);
    7205          35 :   RETURN_ON_FAILED_EXECUTION(Promise);
    7206          35 :   RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
    7207             : }
    7208             : 
    7209         345 : bool Promise::HasHandler() {
    7210             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7211         345 :   i::Isolate* isolate = promise->GetIsolate();
    7212         690 :   LOG_API(isolate, Promise, HasRejectHandler);
    7213             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7214         690 :   if (promise->IsJSPromise()) {
    7215         345 :     i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
    7216         345 :     return js_promise->has_handler();
    7217             :   }
    7218             :   return false;
    7219             : }
    7220             : 
    7221          50 : Local<Value> Promise::Result() {
    7222             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7223          50 :   i::Isolate* isolate = promise->GetIsolate();
    7224         100 :   LOG_API(isolate, Promise, Result);
    7225          50 :   i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
    7226         100 :   Utils::ApiCheck(js_promise->status() != kPending, "v8_Promise_Result",
    7227             :                   "Promise is still pending");
    7228             :   i::Handle<i::Object> result(js_promise->result(), isolate);
    7229          50 :   return Utils::ToLocal(result);
    7230             : }
    7231             : 
    7232         289 : Promise::PromiseState Promise::State() {
    7233             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7234         289 :   i::Isolate* isolate = promise->GetIsolate();
    7235         578 :   LOG_API(isolate, Promise, Status);
    7236         289 :   i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
    7237         578 :   return static_cast<PromiseState>(js_promise->status());
    7238             : }
    7239             : 
    7240           5 : void Promise::MarkAsHandled() {
    7241             :   i::Handle<i::JSPromise> js_promise = Utils::OpenHandle(this);
    7242           5 :   js_promise->set_has_handler(true);
    7243           5 : }
    7244             : 
    7245          30 : Local<Value> Proxy::GetTarget() {
    7246             :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7247             :   i::Handle<i::Object> target(self->target(), self->GetIsolate());
    7248          30 :   return Utils::ToLocal(target);
    7249             : }
    7250             : 
    7251             : 
    7252          10 : Local<Value> Proxy::GetHandler() {
    7253             :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7254             :   i::Handle<i::Object> handler(self->handler(), self->GetIsolate());
    7255          10 :   return Utils::ToLocal(handler);
    7256             : }
    7257             : 
    7258             : 
    7259          10 : bool Proxy::IsRevoked() {
    7260             :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7261          20 :   return self->IsRevoked();
    7262             : }
    7263             : 
    7264             : 
    7265           5 : void Proxy::Revoke() {
    7266           5 :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7267           5 :   i::JSProxy::Revoke(self);
    7268           5 : }
    7269             : 
    7270             : 
    7271          17 : MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target,
    7272             :                              Local<Object> local_handler) {
    7273          68 :   PREPARE_FOR_EXECUTION(context, Proxy, New, Proxy);
    7274             :   i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target);
    7275             :   i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler);
    7276             :   Local<Proxy> result;
    7277             :   has_pending_exception =
    7278          34 :       !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
    7279          17 :   RETURN_ON_FAILED_EXECUTION(Proxy);
    7280          17 :   RETURN_ESCAPED(result);
    7281             : }
    7282             : 
    7283          48 : CompiledWasmModule::CompiledWasmModule(
    7284             :     std::shared_ptr<internal::wasm::NativeModule> native_module)
    7285             :     : native_module_(std::move(native_module)) {
    7286          48 :   CHECK_NOT_NULL(native_module_);
    7287          48 : }
    7288             : 
    7289          28 : OwnedBuffer CompiledWasmModule::Serialize() {
    7290          28 :   i::wasm::WasmSerializer wasm_serializer(native_module_.get());
    7291          28 :   size_t buffer_size = wasm_serializer.GetSerializedNativeModuleSize();
    7292          28 :   std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
    7293          28 :   if (!wasm_serializer.SerializeNativeModule({buffer.get(), buffer_size}))
    7294           0 :     return {};
    7295             :   return {std::move(buffer), buffer_size};
    7296             : }
    7297             : 
    7298          44 : MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() {
    7299          48 :   i::Vector<const uint8_t> bytes_vec = native_module_->wire_bytes();
    7300          44 :   return {bytes_vec.start(), bytes_vec.size()};
    7301             : }
    7302             : 
    7303             : WasmModuleObject::TransferrableModule
    7304         106 : WasmModuleObject::GetTransferrableModule() {
    7305         106 :   if (i::FLAG_wasm_shared_code) {
    7306             :     i::Handle<i::WasmModuleObject> obj =
    7307         102 :         i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
    7308         204 :     return TransferrableModule(obj->shared_native_module());
    7309             :   } else {
    7310           4 :     CompiledWasmModule compiled_module = GetCompiledModule();
    7311           4 :     OwnedBuffer serialized_module = compiled_module.Serialize();
    7312             :     MemorySpan<const uint8_t> wire_bytes_ref =
    7313             :         compiled_module.GetWireBytesRef();
    7314             :     size_t wire_size = wire_bytes_ref.size();
    7315           4 :     std::unique_ptr<uint8_t[]> wire_bytes_copy(new uint8_t[wire_size]);
    7316             :     memcpy(wire_bytes_copy.get(), wire_bytes_ref.data(), wire_size);
    7317             :     return TransferrableModule(std::move(serialized_module),
    7318             :                                {std::move(wire_bytes_copy), wire_size});
    7319             :   }
    7320             : }
    7321             : 
    7322          48 : CompiledWasmModule WasmModuleObject::GetCompiledModule() {
    7323             :   i::Handle<i::WasmModuleObject> obj =
    7324          48 :       i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
    7325          96 :   return Utils::Convert(obj->shared_native_module());
    7326             : }
    7327             : 
    7328         104 : MaybeLocal<WasmModuleObject> WasmModuleObject::FromTransferrableModule(
    7329             :     Isolate* isolate,
    7330             :     const WasmModuleObject::TransferrableModule& transferrable_module) {
    7331         104 :   if (i::FLAG_wasm_shared_code) {
    7332             :     i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7333             :     i::Handle<i::WasmModuleObject> module_object =
    7334             :         i_isolate->wasm_engine()->ImportNativeModule(
    7335         200 :             i_isolate, transferrable_module.shared_module_);
    7336             :     return Local<WasmModuleObject>::Cast(
    7337         100 :         Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
    7338             :   } else {
    7339             :     return Deserialize(isolate, AsReference(transferrable_module.serialized_),
    7340           4 :                        AsReference(transferrable_module.wire_bytes_));
    7341             :   }
    7342             : }
    7343             : 
    7344          76 : MaybeLocal<WasmModuleObject> WasmModuleObject::Deserialize(
    7345             :     Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
    7346             :     MemorySpan<const uint8_t> wire_bytes) {
    7347             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7348             :   i::MaybeHandle<i::WasmModuleObject> maybe_module_object =
    7349             :       i::wasm::DeserializeNativeModule(
    7350             :           i_isolate, {serialized_module.data(), serialized_module.size()},
    7351         228 :           {wire_bytes.data(), wire_bytes.size()});
    7352             :   i::Handle<i::WasmModuleObject> module_object;
    7353          76 :   if (!maybe_module_object.ToHandle(&module_object)) {
    7354          64 :     return MaybeLocal<WasmModuleObject>();
    7355             :   }
    7356             :   return Local<WasmModuleObject>::Cast(
    7357          12 :       Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
    7358             : }
    7359             : 
    7360          72 : MaybeLocal<WasmModuleObject> WasmModuleObject::DeserializeOrCompile(
    7361             :     Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
    7362             :     MemorySpan<const uint8_t> wire_bytes) {
    7363             :   MaybeLocal<WasmModuleObject> ret =
    7364          72 :       Deserialize(isolate, serialized_module, wire_bytes);
    7365          72 :   if (!ret.IsEmpty()) {
    7366           8 :     return ret;
    7367             :   }
    7368          64 :   return Compile(isolate, wire_bytes.data(), wire_bytes.size());
    7369             : }
    7370             : 
    7371          64 : MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(Isolate* isolate,
    7372             :                                                        const uint8_t* start,
    7373             :                                                        size_t length) {
    7374             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7375             :   i::wasm::ErrorThrower thrower(i_isolate, "WasmModuleObject::Compile()");
    7376         128 :   if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
    7377          20 :     return MaybeLocal<WasmModuleObject>();
    7378             :   }
    7379          44 :   auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
    7380             :   i::MaybeHandle<i::JSObject> maybe_compiled =
    7381             :       i_isolate->wasm_engine()->SyncCompile(
    7382             :           i_isolate, enabled_features, &thrower,
    7383          88 :           i::wasm::ModuleWireBytes(start, start + length));
    7384          44 :   if (maybe_compiled.is_null()) return MaybeLocal<WasmModuleObject>();
    7385             :   return Local<WasmModuleObject>::Cast(
    7386          40 :       Utils::ToLocal(maybe_compiled.ToHandleChecked()));
    7387             : }
    7388             : 
    7389             : // Resolves the result of streaming compilation.
    7390             : // TODO(ahaas): Refactor the streaming compilation API so that this class can
    7391             : // move to wasm-js.cc.
    7392             : class AsyncCompilationResolver : public i::wasm::CompilationResultResolver {
    7393             :  public:
    7394             :   AsyncCompilationResolver(Isolate* isolate, Local<Promise> promise)
    7395             :       : promise_(
    7396             :             reinterpret_cast<i::Isolate*>(isolate)->global_handles()->Create(
    7397             :                 *Utils::OpenHandle(*promise))) {}
    7398             : 
    7399           0 :   ~AsyncCompilationResolver() override {
    7400           0 :     i::GlobalHandles::Destroy(promise_.location());
    7401           0 :   }
    7402             : 
    7403           0 :   void OnCompilationSucceeded(i::Handle<i::WasmModuleObject> result) override {
    7404             :     i::MaybeHandle<i::Object> promise_result =
    7405           0 :         i::JSPromise::Resolve(promise_, result);
    7406           0 :     CHECK_EQ(promise_result.is_null(),
    7407             :              promise_->GetIsolate()->has_pending_exception());
    7408           0 :   }
    7409             : 
    7410           0 :   void OnCompilationFailed(i::Handle<i::Object> error_reason) override {
    7411             :     i::MaybeHandle<i::Object> promise_result =
    7412           0 :         i::JSPromise::Reject(promise_, error_reason);
    7413           0 :     CHECK_EQ(promise_result.is_null(),
    7414             :              promise_->GetIsolate()->has_pending_exception());
    7415           0 :   }
    7416             : 
    7417             :  private:
    7418             :   i::Handle<i::JSPromise> promise_;
    7419             : };
    7420             : 
    7421           0 : WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming(
    7422           0 :     Isolate* isolate) {
    7423             :   USE(isolate_);
    7424           0 : }
    7425             : 
    7426           0 : Local<Promise> WasmModuleObjectBuilderStreaming::GetPromise() { return {}; }
    7427             : 
    7428           0 : void WasmModuleObjectBuilderStreaming::OnBytesReceived(const uint8_t* bytes,
    7429             :                                                        size_t size) {
    7430           0 : }
    7431             : 
    7432           0 : void WasmModuleObjectBuilderStreaming::Finish() {
    7433           0 : }
    7434             : 
    7435           0 : void WasmModuleObjectBuilderStreaming::Abort(MaybeLocal<Value> exception) {
    7436           0 : }
    7437             : 
    7438             : // static
    7439      117989 : v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() {
    7440      235978 :   return new ArrayBufferAllocator();
    7441             : }
    7442             : 
    7443          89 : bool v8::ArrayBuffer::IsExternal() const {
    7444          89 :   return Utils::OpenHandle(this)->is_external();
    7445             : }
    7446             : 
    7447          56 : bool v8::ArrayBuffer::IsDetachable() const {
    7448          56 :   return Utils::OpenHandle(this)->is_detachable();
    7449             : }
    7450             : 
    7451          89 : v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
    7452             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7453             :   i::Isolate* isolate = self->GetIsolate();
    7454             :   Utils::ApiCheck(!self->is_external(), "v8_ArrayBuffer_Externalize",
    7455             :                   "ArrayBuffer already externalized");
    7456             :   self->set_is_external(true);
    7457             : 
    7458          89 :   const v8::ArrayBuffer::Contents contents = GetContents();
    7459          89 :   isolate->heap()->UnregisterArrayBuffer(*self);
    7460             : 
    7461             :   // A regular copy is good enough. No move semantics needed.
    7462          89 :   return contents;
    7463             : }
    7464             : 
    7465           0 : v8::ArrayBuffer::Contents::Contents(void* data, size_t byte_length,
    7466             :                                     void* allocation_base,
    7467             :                                     size_t allocation_length,
    7468             :                                     Allocator::AllocationMode allocation_mode,
    7469             :                                     DeleterCallback deleter, void* deleter_data)
    7470             :     : data_(data),
    7471             :       byte_length_(byte_length),
    7472             :       allocation_base_(allocation_base),
    7473             :       allocation_length_(allocation_length),
    7474             :       allocation_mode_(allocation_mode),
    7475             :       deleter_(deleter),
    7476      279894 :       deleter_data_(deleter_data) {
    7477             :   DCHECK_LE(allocation_base_, data_);
    7478             :   DCHECK_LE(byte_length_, allocation_length_);
    7479           0 : }
    7480             : 
    7481          49 : void WasmMemoryDeleter(void* buffer, size_t lenght, void* info) {
    7482             :   internal::wasm::WasmEngine* engine =
    7483             :       reinterpret_cast<internal::wasm::WasmEngine*>(info);
    7484          49 :   CHECK(engine->memory_tracker()->FreeMemoryIfIsWasmMemory(nullptr, buffer));
    7485          49 : }
    7486             : 
    7487          99 : void ArrayBufferDeleter(void* buffer, size_t length, void* info) {
    7488             :   v8::ArrayBuffer::Allocator* allocator =
    7489             :       reinterpret_cast<v8::ArrayBuffer::Allocator*>(info);
    7490          99 :   allocator->Free(buffer, length);
    7491          99 : }
    7492             : 
    7493      279893 : v8::ArrayBuffer::Contents v8::ArrayBuffer::GetContents() {
    7494             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7495             :   Contents contents(
    7496             :       self->backing_store(), self->byte_length(), self->allocation_base(),
    7497             :       self->allocation_length(),
    7498             :       self->is_wasm_memory() ? Allocator::AllocationMode::kReservation
    7499             :                              : Allocator::AllocationMode::kNormal,
    7500             :       self->is_wasm_memory() ? WasmMemoryDeleter : ArrayBufferDeleter,
    7501             :       self->is_wasm_memory()
    7502             :           ? static_cast<void*>(self->GetIsolate()->wasm_engine())
    7503     1959258 :           : static_cast<void*>(self->GetIsolate()->array_buffer_allocator()));
    7504      279894 :   return contents;
    7505             : }
    7506             : 
    7507          43 : void v8::ArrayBuffer::Detach() {
    7508             :   i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
    7509          43 :   i::Isolate* isolate = obj->GetIsolate();
    7510             :   Utils::ApiCheck(obj->is_external(), "v8::ArrayBuffer::Detach",
    7511             :                   "Only externalized ArrayBuffers can be detached");
    7512             :   Utils::ApiCheck(obj->is_detachable(), "v8::ArrayBuffer::Detach",
    7513             :                   "Only detachable ArrayBuffers can be detached");
    7514          86 :   LOG_API(isolate, ArrayBuffer, Detach);
    7515             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7516          43 :   obj->Detach();
    7517          43 : }
    7518             : 
    7519         227 : size_t v8::ArrayBuffer::ByteLength() const {
    7520             :   i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
    7521         227 :   return obj->byte_length();
    7522             : }
    7523             : 
    7524             : 
    7525         200 : Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
    7526         200 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7527         400 :   LOG_API(i_isolate, ArrayBuffer, New);
    7528             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7529             :   i::Handle<i::JSArrayBuffer> obj =
    7530         200 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
    7531             :   // TODO(jbroman): It may be useful in the future to provide a MaybeLocal
    7532             :   // version that throws an exception or otherwise does not crash.
    7533         200 :   if (!i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length)) {
    7534           0 :     i::FatalProcessOutOfMemory(i_isolate, "v8::ArrayBuffer::New");
    7535             :   }
    7536         200 :   return Utils::ToLocal(obj);
    7537             : }
    7538             : 
    7539             : 
    7540         140 : Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
    7541             :                                         size_t byte_length,
    7542             :                                         ArrayBufferCreationMode mode) {
    7543             :   // Embedders must guarantee that the external backing store is valid.
    7544         140 :   CHECK(byte_length == 0 || data != nullptr);
    7545         140 :   CHECK_LE(byte_length, i::JSArrayBuffer::kMaxByteLength);
    7546         140 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7547         280 :   LOG_API(i_isolate, ArrayBuffer, New);
    7548             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7549             :   i::Handle<i::JSArrayBuffer> obj =
    7550         140 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
    7551             :   i::JSArrayBuffer::Setup(obj, i_isolate,
    7552             :                           mode == ArrayBufferCreationMode::kExternalized, data,
    7553         140 :                           byte_length);
    7554         140 :   return Utils::ToLocal(obj);
    7555             : }
    7556             : 
    7557             : 
    7558        3080 : Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
    7559             :   i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
    7560             :   i::Handle<i::JSArrayBuffer> buffer;
    7561        6160 :   if (obj->IsJSDataView()) {
    7562             :     i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj),
    7563             :                                        obj->GetIsolate());
    7564             :     DCHECK(data_view->buffer()->IsJSArrayBuffer());
    7565             :     buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer()),
    7566             :                        data_view->GetIsolate());
    7567             :   } else {
    7568             :     DCHECK(obj->IsJSTypedArray());
    7569        3066 :     buffer = i::JSTypedArray::cast(*obj)->GetBuffer();
    7570             :   }
    7571        3080 :   return Utils::ToLocal(buffer);
    7572             : }
    7573             : 
    7574             : 
    7575          15 : size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) {
    7576             :   i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this);
    7577             :   size_t byte_offset = self->byte_offset();
    7578             :   size_t bytes_to_copy = i::Min(byte_length, self->byte_length());
    7579          15 :   if (bytes_to_copy) {
    7580             :     i::DisallowHeapAllocation no_gc;
    7581             :     i::Isolate* isolate = self->GetIsolate();
    7582             :     i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(self->buffer()),
    7583             :                                        isolate);
    7584             :     const char* source = reinterpret_cast<char*>(buffer->backing_store());
    7585          15 :     if (source == nullptr) {
    7586             :       DCHECK(self->IsJSTypedArray());
    7587             :       i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*self),
    7588             :                                              isolate);
    7589             :       i::Handle<i::FixedTypedArrayBase> fixed_array(
    7590          20 :           i::FixedTypedArrayBase::cast(typed_array->elements()), isolate);
    7591             :       source = reinterpret_cast<char*>(fixed_array->DataPtr());
    7592             :     }
    7593          15 :     memcpy(dest, source + byte_offset, bytes_to_copy);
    7594             :   }
    7595          15 :   return bytes_to_copy;
    7596             : }
    7597             : 
    7598             : 
    7599          30 : bool v8::ArrayBufferView::HasBuffer() const {
    7600             :   i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this);
    7601             :   i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(self->buffer()),
    7602             :                                      self->GetIsolate());
    7603          30 :   return buffer->backing_store() != nullptr;
    7604             : }
    7605             : 
    7606             : 
    7607        3254 : size_t v8::ArrayBufferView::ByteOffset() {
    7608             :   i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
    7609        6508 :   return obj->WasDetached() ? 0 : obj->byte_offset();
    7610             : }
    7611             : 
    7612             : 
    7613        3312 : size_t v8::ArrayBufferView::ByteLength() {
    7614             :   i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
    7615        6624 :   return obj->WasDetached() ? 0 : obj->byte_length();
    7616             : }
    7617             : 
    7618             : 
    7619         498 : size_t v8::TypedArray::Length() {
    7620             :   i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
    7621         996 :   return obj->WasDetached() ? 0 : obj->length_value();
    7622             : }
    7623             : 
    7624             : static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue,
    7625             :               "v8::TypedArray::kMaxLength must match i::Smi::kMaxValue");
    7626             : 
    7627             : #define TYPED_ARRAY_NEW(Type, type, TYPE, ctype)                           \
    7628             :   Local<Type##Array> Type##Array::New(Local<ArrayBuffer> array_buffer,     \
    7629             :                                       size_t byte_offset, size_t length) { \
    7630             :     i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate();  \
    7631             :     LOG_API(isolate, Type##Array, New);                                    \
    7632             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);                              \
    7633             :     if (!Utils::ApiCheck(length <= kMaxLength,                             \
    7634             :                          "v8::" #Type                                      \
    7635             :                          "Array::New(Local<ArrayBuffer>, size_t, size_t)", \
    7636             :                          "length exceeds max allowed value")) {            \
    7637             :       return Local<Type##Array>();                                         \
    7638             :     }                                                                      \
    7639             :     i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \
    7640             :     i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray(  \
    7641             :         i::kExternal##Type##Array, buffer, byte_offset, length);           \
    7642             :     return Utils::ToLocal##Type##Array(obj);                               \
    7643             :   }                                                                        \
    7644             :   Local<Type##Array> Type##Array::New(                                     \
    7645             :       Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,    \
    7646             :       size_t length) {                                                     \
    7647             :     CHECK(i::FLAG_harmony_sharedarraybuffer);                              \
    7648             :     i::Isolate* isolate =                                                  \
    7649             :         Utils::OpenHandle(*shared_array_buffer)->GetIsolate();             \
    7650             :     LOG_API(isolate, Type##Array, New);                                    \
    7651             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);                              \
    7652             :     if (!Utils::ApiCheck(                                                  \
    7653             :             length <= kMaxLength,                                          \
    7654             :             "v8::" #Type                                                   \
    7655             :             "Array::New(Local<SharedArrayBuffer>, size_t, size_t)",        \
    7656             :             "length exceeds max allowed value")) {                         \
    7657             :       return Local<Type##Array>();                                         \
    7658             :     }                                                                      \
    7659             :     i::Handle<i::JSArrayBuffer> buffer =                                   \
    7660             :         Utils::OpenHandle(*shared_array_buffer);                           \
    7661             :     i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray(  \
    7662             :         i::kExternal##Type##Array, buffer, byte_offset, length);           \
    7663             :     return Utils::ToLocal##Type##Array(obj);                               \
    7664             :   }
    7665             : 
    7666        1120 : TYPED_ARRAYS(TYPED_ARRAY_NEW)
    7667             : #undef TYPED_ARRAY_NEW
    7668             : 
    7669          17 : Local<DataView> DataView::New(Local<ArrayBuffer> array_buffer,
    7670             :                               size_t byte_offset, size_t byte_length) {
    7671             :   i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
    7672          17 :   i::Isolate* isolate = buffer->GetIsolate();
    7673          34 :   LOG_API(isolate, DataView, New);
    7674             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7675             :   i::Handle<i::JSDataView> obj =
    7676          17 :       isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
    7677          17 :   return Utils::ToLocal(obj);
    7678             : }
    7679             : 
    7680             : 
    7681           6 : Local<DataView> DataView::New(Local<SharedArrayBuffer> shared_array_buffer,
    7682             :                               size_t byte_offset, size_t byte_length) {
    7683           6 :   CHECK(i::FLAG_harmony_sharedarraybuffer);
    7684             :   i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*shared_array_buffer);
    7685           6 :   i::Isolate* isolate = buffer->GetIsolate();
    7686          12 :   LOG_API(isolate, DataView, New);
    7687             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7688             :   i::Handle<i::JSDataView> obj =
    7689           6 :       isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
    7690           6 :   return Utils::ToLocal(obj);
    7691             : }
    7692             : 
    7693             : namespace {
    7694         439 : i::Handle<i::JSArrayBuffer> SetupSharedArrayBuffer(
    7695             :     Isolate* isolate, void* data, size_t byte_length,
    7696             :     ArrayBufferCreationMode mode) {
    7697         439 :   CHECK(i::FLAG_harmony_sharedarraybuffer);
    7698             :   // Embedders must guarantee that the external backing store is valid.
    7699         439 :   CHECK(byte_length == 0 || data != nullptr);
    7700         439 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7701         878 :   LOG_API(i_isolate, SharedArrayBuffer, New);
    7702             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7703             :   i::Handle<i::JSArrayBuffer> obj =
    7704         439 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
    7705             :   bool is_wasm_memory =
    7706         439 :       i_isolate->wasm_engine()->memory_tracker()->IsWasmMemory(data);
    7707             :   i::JSArrayBuffer::Setup(obj, i_isolate,
    7708             :                           mode == ArrayBufferCreationMode::kExternalized, data,
    7709         439 :                           byte_length, i::SharedFlag::kShared, is_wasm_memory);
    7710         878 :   return obj;
    7711             : }
    7712             : 
    7713             : }  // namespace
    7714             : 
    7715         399 : bool v8::SharedArrayBuffer::IsExternal() const {
    7716         399 :   return Utils::OpenHandle(this)->is_external();
    7717             : }
    7718             : 
    7719         157 : v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() {
    7720             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7721             :   i::Isolate* isolate = self->GetIsolate();
    7722             :   Utils::ApiCheck(!self->is_external(), "v8_SharedArrayBuffer_Externalize",
    7723             :                   "SharedArrayBuffer already externalized");
    7724             :   self->set_is_external(true);
    7725             : 
    7726         157 :   const v8::SharedArrayBuffer::Contents contents = GetContents();
    7727         157 :   isolate->heap()->UnregisterArrayBuffer(*self);
    7728             : 
    7729             :   // A regular copy is good enough. No move semantics needed.
    7730         157 :   return contents;
    7731             : }
    7732             : 
    7733           0 : v8::SharedArrayBuffer::Contents::Contents(
    7734             :     void* data, size_t byte_length, void* allocation_base,
    7735             :     size_t allocation_length, Allocator::AllocationMode allocation_mode,
    7736             :     DeleterCallback deleter, void* deleter_data, bool is_growable)
    7737             :     : data_(data),
    7738             :       byte_length_(byte_length),
    7739             :       allocation_base_(allocation_base),
    7740             :       allocation_length_(allocation_length),
    7741             :       allocation_mode_(allocation_mode),
    7742             :       deleter_(deleter),
    7743             :       deleter_data_(deleter_data),
    7744         387 :       is_growable_(is_growable) {
    7745             :   DCHECK_LE(allocation_base_, data_);
    7746             :   DCHECK_LE(byte_length_, allocation_length_);
    7747           0 : }
    7748             : 
    7749         387 : v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() {
    7750             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7751             :   Contents contents(
    7752             :       self->backing_store(), self->byte_length(), self->allocation_base(),
    7753             :       self->allocation_length(),
    7754             :       self->is_wasm_memory()
    7755             :           ? ArrayBuffer::Allocator::AllocationMode::kReservation
    7756             :           : ArrayBuffer::Allocator::AllocationMode::kNormal,
    7757             :       self->is_wasm_memory()
    7758             :           ? reinterpret_cast<Contents::DeleterCallback>(WasmMemoryDeleter)
    7759             :           : reinterpret_cast<Contents::DeleterCallback>(ArrayBufferDeleter),
    7760             :       self->is_wasm_memory()
    7761             :           ? static_cast<void*>(self->GetIsolate()->wasm_engine())
    7762         279 :           : static_cast<void*>(self->GetIsolate()->array_buffer_allocator()),
    7763        2322 :       self->is_growable());
    7764         387 :   return contents;
    7765             : }
    7766             : 
    7767          38 : size_t v8::SharedArrayBuffer::ByteLength() const {
    7768             :   i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
    7769          38 :   return obj->byte_length();
    7770             : }
    7771             : 
    7772          12 : Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate,
    7773             :                                                     size_t byte_length) {
    7774          12 :   CHECK(i::FLAG_harmony_sharedarraybuffer);
    7775          12 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7776          24 :   LOG_API(i_isolate, SharedArrayBuffer, New);
    7777             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7778             :   i::Handle<i::JSArrayBuffer> obj =
    7779          12 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
    7780             :   // TODO(jbroman): It may be useful in the future to provide a MaybeLocal
    7781             :   // version that throws an exception or otherwise does not crash.
    7782          12 :   if (!i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length, true,
    7783          12 :                                              i::SharedFlag::kShared)) {
    7784           0 :     i::FatalProcessOutOfMemory(i_isolate, "v8::SharedArrayBuffer::New");
    7785             :   }
    7786          12 :   return Utils::ToLocalShared(obj);
    7787             : }
    7788             : 
    7789             : 
    7790          70 : Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
    7791             :     Isolate* isolate, void* data, size_t byte_length,
    7792             :     ArrayBufferCreationMode mode) {
    7793             :   i::Handle<i::JSArrayBuffer> buffer =
    7794          70 :       SetupSharedArrayBuffer(isolate, data, byte_length, mode);
    7795          70 :   return Utils::ToLocalShared(buffer);
    7796             : }
    7797             : 
    7798         369 : Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
    7799         738 :     Isolate* isolate, const SharedArrayBuffer::Contents& contents,
    7800             :     ArrayBufferCreationMode mode) {
    7801             :   i::Handle<i::JSArrayBuffer> buffer = SetupSharedArrayBuffer(
    7802         369 :       isolate, contents.Data(), contents.ByteLength(), mode);
    7803             :   buffer->set_is_growable(contents.IsGrowable());
    7804         369 :   return Utils::ToLocalShared(buffer);
    7805             : }
    7806             : 
    7807         125 : Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
    7808         125 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7809         250 :   LOG_API(i_isolate, Symbol, New);
    7810             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7811         125 :   i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
    7812         207 :   if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
    7813         125 :   return Utils::ToLocal(result);
    7814             : }
    7815             : 
    7816             : 
    7817          24 : Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) {
    7818             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7819          24 :   i::Handle<i::String> i_name = Utils::OpenHandle(*name);
    7820             :   return Utils::ToLocal(
    7821          24 :       i_isolate->SymbolFor(i::RootIndex::kPublicSymbolTable, i_name, false));
    7822             : }
    7823             : 
    7824             : 
    7825          24 : Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) {
    7826             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7827          24 :   i::Handle<i::String> i_name = Utils::OpenHandle(*name);
    7828             :   return Utils::ToLocal(
    7829          24 :       i_isolate->SymbolFor(i::RootIndex::kApiSymbolTable, i_name, false));
    7830             : }
    7831             : 
    7832             : #define WELL_KNOWN_SYMBOLS(V)                 \
    7833             :   V(AsyncIterator, async_iterator)            \
    7834             :   V(HasInstance, has_instance)                \
    7835             :   V(IsConcatSpreadable, is_concat_spreadable) \
    7836             :   V(Iterator, iterator)                       \
    7837             :   V(Match, match)                             \
    7838             :   V(Replace, replace)                         \
    7839             :   V(Search, search)                           \
    7840             :   V(Split, split)                             \
    7841             :   V(ToPrimitive, to_primitive)                \
    7842             :   V(ToStringTag, to_string_tag)               \
    7843             :   V(Unscopables, unscopables)
    7844             : 
    7845             : #define SYMBOL_GETTER(Name, name)                                   \
    7846             :   Local<Symbol> v8::Symbol::Get##Name(Isolate* isolate) {           \
    7847             :     i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); \
    7848             :     return Utils::ToLocal(i_isolate->factory()->name##_symbol());   \
    7849             :   }
    7850             : 
    7851      104584 : WELL_KNOWN_SYMBOLS(SYMBOL_GETTER)
    7852             : 
    7853             : #undef SYMBOL_GETTER
    7854             : #undef WELL_KNOWN_SYMBOLS
    7855             : 
    7856         153 : Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
    7857         153 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7858         306 :   LOG_API(i_isolate, Private, New);
    7859             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7860         153 :   i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
    7861         235 :   if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
    7862             :   Local<Symbol> result = Utils::ToLocal(symbol);
    7863         306 :   return v8::Local<Private>(reinterpret_cast<Private*>(*result));
    7864             : }
    7865             : 
    7866             : 
    7867      254641 : Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) {
    7868             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7869      254641 :   i::Handle<i::String> i_name = Utils::OpenHandle(*name);
    7870             :   Local<Symbol> result = Utils::ToLocal(
    7871      254641 :       i_isolate->SymbolFor(i::RootIndex::kApiPrivateSymbolTable, i_name, true));
    7872      254641 :   return v8::Local<Private>(reinterpret_cast<Private*>(*result));
    7873             : }
    7874             : 
    7875             : 
    7876      100541 : Local<Number> v8::Number::New(Isolate* isolate, double value) {
    7877             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7878      100541 :   if (std::isnan(value)) {
    7879             :     // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
    7880             :     value = std::numeric_limits<double>::quiet_NaN();
    7881             :   }
    7882             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7883      100541 :   i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
    7884      100541 :   return Utils::NumberToLocal(result);
    7885             : }
    7886             : 
    7887             : 
    7888      731320 : Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
    7889             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7890             :   if (i::Smi::IsValid(value)) {
    7891             :     return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
    7892             :                                                       internal_isolate));
    7893             :   }
    7894             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7895             :   i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
    7896             :   return Utils::IntegerToLocal(result);
    7897             : }
    7898             : 
    7899             : 
    7900         122 : Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
    7901             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7902         122 :   bool fits_into_int32_t = (value & (1 << 31)) == 0;
    7903         122 :   if (fits_into_int32_t) {
    7904          30 :     return Integer::New(isolate, static_cast<int32_t>(value));
    7905             :   }
    7906             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7907          92 :   i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
    7908             :   return Utils::IntegerToLocal(result);
    7909             : }
    7910             : 
    7911          81 : Local<BigInt> v8::BigInt::New(Isolate* isolate, int64_t value) {
    7912             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7913             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7914          81 :   i::Handle<i::BigInt> result = i::BigInt::FromInt64(internal_isolate, value);
    7915          81 :   return Utils::ToLocal(result);
    7916             : }
    7917             : 
    7918           0 : Local<BigInt> v8::BigInt::NewFromUnsigned(Isolate* isolate, uint64_t value) {
    7919             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7920             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7921           0 :   i::Handle<i::BigInt> result = i::BigInt::FromUint64(internal_isolate, value);
    7922           0 :   return Utils::ToLocal(result);
    7923             : }
    7924             : 
    7925          30 : MaybeLocal<BigInt> v8::BigInt::NewFromWords(Local<Context> context,
    7926             :                                             int sign_bit, int word_count,
    7927             :                                             const uint64_t* words) {
    7928          60 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7929         120 :   ENTER_V8_NO_SCRIPT(isolate, context, BigInt, NewFromWords,
    7930             :                      MaybeLocal<BigInt>(), InternalEscapableScope);
    7931             :   i::MaybeHandle<i::BigInt> result =
    7932          30 :       i::BigInt::FromWords64(isolate, sign_bit, word_count, words);
    7933             :   has_pending_exception = result.is_null();
    7934          30 :   RETURN_ON_FAILED_EXECUTION(BigInt);
    7935          15 :   RETURN_ESCAPED(Utils::ToLocal(result.ToHandleChecked()));
    7936             : }
    7937             : 
    7938          55 : uint64_t v8::BigInt::Uint64Value(bool* lossless) const {
    7939             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7940          55 :   return handle->AsUint64(lossless);
    7941             : }
    7942             : 
    7943          90 : int64_t v8::BigInt::Int64Value(bool* lossless) const {
    7944             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7945          90 :   return handle->AsInt64(lossless);
    7946             : }
    7947             : 
    7948          15 : int BigInt::WordCount() const {
    7949             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7950          15 :   return handle->Words64Count();
    7951             : }
    7952             : 
    7953          10 : void BigInt::ToWordsArray(int* sign_bit, int* word_count,
    7954             :                           uint64_t* words) const {
    7955             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7956          10 :   return handle->ToWordsArray64(sign_bit, word_count, words);
    7957             : }
    7958             : 
    7959      970594 : void Isolate::ReportExternalAllocationLimitReached() {
    7960      970594 :   i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
    7961     1941188 :   if (heap->gc_state() != i::Heap::NOT_IN_GC) return;
    7962      970594 :   heap->ReportExternalMemoryPressure();
    7963             : }
    7964             : 
    7965     1723441 : void Isolate::CheckMemoryPressure() {
    7966     1723441 :   i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
    7967     3446882 :   if (heap->gc_state() != i::Heap::NOT_IN_GC) return;
    7968     1723441 :   heap->CheckMemoryPressure();
    7969             : }
    7970             : 
    7971        8118 : HeapProfiler* Isolate::GetHeapProfiler() {
    7972             :   i::HeapProfiler* heap_profiler =
    7973             :       reinterpret_cast<i::Isolate*>(this)->heap_profiler();
    7974        8118 :   return reinterpret_cast<HeapProfiler*>(heap_profiler);
    7975             : }
    7976             : 
    7977           0 : void Isolate::SetIdle(bool is_idle) {
    7978             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7979           0 :   isolate->SetIdle(is_idle);
    7980           0 : }
    7981             : 
    7982       88460 : bool Isolate::InContext() {
    7983             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7984       88460 :   return !isolate->context().is_null();
    7985             : }
    7986             : 
    7987             : 
    7988    13084762 : v8::Local<v8::Context> Isolate::GetCurrentContext() {
    7989             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7990    13084762 :   i::Context context = isolate->context();
    7991    13084762 :   if (context.is_null()) return Local<Context>();
    7992    13084724 :   i::Context native_context = context->native_context();
    7993    13084722 :   if (native_context.is_null()) return Local<Context>();
    7994             :   return Utils::ToLocal(i::Handle<i::Context>(native_context, isolate));
    7995             : }
    7996             : 
    7997             : 
    7998           0 : v8::Local<v8::Context> Isolate::GetEnteredContext() {
    7999           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8000             :   i::Handle<i::Object> last =
    8001           0 :       isolate->handle_scope_implementer()->LastEnteredContext();
    8002           0 :   if (last.is_null()) return Local<Context>();
    8003           0 :   return Utils::ToLocal(i::Handle<i::Context>::cast(last));
    8004             : }
    8005             : 
    8006       52539 : v8::Local<v8::Context> Isolate::GetEnteredOrMicrotaskContext() {
    8007       52539 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8008             :   i::Handle<i::Object> last =
    8009       52539 :       isolate->handle_scope_implementer()->LastEnteredOrMicrotaskContext();
    8010       52539 :   if (last.is_null()) return Local<Context>();
    8011             :   DCHECK(last->IsNativeContext());
    8012       52539 :   return Utils::ToLocal(i::Handle<i::Context>::cast(last));
    8013             : }
    8014             : 
    8015           4 : v8::Local<v8::Context> Isolate::GetIncumbentContext() {
    8016             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8017           4 :   i::Handle<i::Context> context = isolate->GetIncumbentContext();
    8018           4 :   return Utils::ToLocal(context);
    8019             : }
    8020             : 
    8021        5136 : v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) {
    8022             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8023             :   ENTER_V8_DO_NOT_USE(isolate);
    8024             :   // If we're passed an empty handle, we throw an undefined exception
    8025             :   // to deal more gracefully with out of memory situations.
    8026        5136 :   if (value.IsEmpty()) {
    8027          24 :     isolate->ScheduleThrow(i::ReadOnlyRoots(isolate).undefined_value());
    8028             :   } else {
    8029        5112 :     isolate->ScheduleThrow(*Utils::OpenHandle(*value));
    8030             :   }
    8031       10272 :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    8032             : }
    8033             : 
    8034          10 : void Isolate::AddGCPrologueCallback(GCCallbackWithData callback, void* data,
    8035             :                                     GCType gc_type) {
    8036             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8037          39 :   isolate->heap()->AddGCPrologueCallback(callback, gc_type, data);
    8038          10 : }
    8039             : 
    8040          10 : void Isolate::RemoveGCPrologueCallback(GCCallbackWithData callback,
    8041             :                                        void* data) {
    8042             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8043          35 :   isolate->heap()->RemoveGCPrologueCallback(callback, data);
    8044          10 : }
    8045             : 
    8046          10 : void Isolate::AddGCEpilogueCallback(GCCallbackWithData callback, void* data,
    8047             :                                     GCType gc_type) {
    8048             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8049          35 :   isolate->heap()->AddGCEpilogueCallback(callback, gc_type, data);
    8050          10 : }
    8051             : 
    8052          10 : void Isolate::RemoveGCEpilogueCallback(GCCallbackWithData callback,
    8053             :                                        void* data) {
    8054             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8055          35 :   isolate->heap()->RemoveGCEpilogueCallback(callback, data);
    8056          10 : }
    8057             : 
    8058          92 : static void CallGCCallbackWithoutData(Isolate* isolate, GCType type,
    8059             :                                       GCCallbackFlags flags, void* data) {
    8060          92 :   reinterpret_cast<Isolate::GCCallback>(data)(isolate, type, flags);
    8061          92 : }
    8062             : 
    8063          29 : void Isolate::AddGCPrologueCallback(GCCallback callback, GCType gc_type) {
    8064             :   void* data = reinterpret_cast<void*>(callback);
    8065             :   AddGCPrologueCallback(CallGCCallbackWithoutData, data, gc_type);
    8066          29 : }
    8067             : 
    8068          25 : void Isolate::RemoveGCPrologueCallback(GCCallback callback) {
    8069             :   void* data = reinterpret_cast<void*>(callback);
    8070             :   RemoveGCPrologueCallback(CallGCCallbackWithoutData, data);
    8071          25 : }
    8072             : 
    8073          25 : void Isolate::AddGCEpilogueCallback(GCCallback callback, GCType gc_type) {
    8074             :   void* data = reinterpret_cast<void*>(callback);
    8075             :   AddGCEpilogueCallback(CallGCCallbackWithoutData, data, gc_type);
    8076          25 : }
    8077             : 
    8078          25 : void Isolate::RemoveGCEpilogueCallback(GCCallback callback) {
    8079             :   void* data = reinterpret_cast<void*>(callback);
    8080             :   RemoveGCEpilogueCallback(CallGCCallbackWithoutData, data);
    8081          25 : }
    8082             : 
    8083         140 : void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
    8084             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8085         140 :   isolate->heap()->SetEmbedderHeapTracer(tracer);
    8086         140 : }
    8087             : 
    8088           0 : EmbedderHeapTracer* Isolate::GetEmbedderHeapTracer() {
    8089             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8090           0 :   return isolate->heap()->GetEmbedderHeapTracer();
    8091             : }
    8092             : 
    8093           0 : void Isolate::SetGetExternallyAllocatedMemoryInBytesCallback(
    8094             :     GetExternallyAllocatedMemoryInBytesCallback callback) {
    8095             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8096             :   isolate->heap()->SetGetExternallyAllocatedMemoryInBytesCallback(callback);
    8097           0 : }
    8098             : 
    8099        1269 : void Isolate::TerminateExecution() {
    8100             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8101        1269 :   isolate->stack_guard()->RequestTerminateExecution();
    8102        1269 : }
    8103             : 
    8104             : 
    8105        1526 : bool Isolate::IsExecutionTerminating() {
    8106             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8107        1526 :   return IsExecutionTerminatingCheck(isolate);
    8108             : }
    8109             : 
    8110             : 
    8111          85 : void Isolate::CancelTerminateExecution() {
    8112             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8113          85 :   isolate->stack_guard()->ClearTerminateExecution();
    8114          85 :   isolate->CancelTerminateExecution();
    8115          85 : }
    8116             : 
    8117             : 
    8118       60020 : void Isolate::RequestInterrupt(InterruptCallback callback, void* data) {
    8119             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8120       60020 :   isolate->RequestInterrupt(callback, data);
    8121       60020 : }
    8122             : 
    8123             : 
    8124       19894 : void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
    8125       19894 :   CHECK(i::FLAG_expose_gc);
    8126       19894 :   if (type == kMinorGarbageCollection) {
    8127             :     reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage(
    8128             :         i::NEW_SPACE, i::GarbageCollectionReason::kTesting,
    8129         108 :         kGCCallbackFlagForced);
    8130             :   } else {
    8131             :     DCHECK_EQ(kFullGarbageCollection, type);
    8132             :     reinterpret_cast<i::Isolate*>(this)->heap()->PreciseCollectAllGarbage(
    8133             :         i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting,
    8134       19786 :         kGCCallbackFlagForced);
    8135             :   }
    8136       19894 : }
    8137             : 
    8138             : 
    8139      904119 : Isolate* Isolate::GetCurrent() {
    8140             :   i::Isolate* isolate = i::Isolate::Current();
    8141      904119 :   return reinterpret_cast<Isolate*>(isolate);
    8142             : }
    8143             : 
    8144             : // static
    8145          85 : Isolate* Isolate::Allocate() {
    8146       60788 :   return reinterpret_cast<Isolate*>(i::Isolate::New());
    8147             : }
    8148             : 
    8149             : // static
    8150             : // This is separate so that tests can provide a different |isolate|.
    8151       60748 : void Isolate::Initialize(Isolate* isolate,
    8152             :                          const v8::Isolate::CreateParams& params) {
    8153           0 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8154       60748 :   CHECK_NOT_NULL(params.array_buffer_allocator);
    8155             :   i_isolate->set_array_buffer_allocator(params.array_buffer_allocator);
    8156       60748 :   if (params.snapshot_blob != nullptr) {
    8157             :     i_isolate->set_snapshot_blob(params.snapshot_blob);
    8158             :   } else {
    8159       60578 :     i_isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob());
    8160             :   }
    8161       60748 :   auto code_event_handler = params.code_event_handler;
    8162             : #ifdef ENABLE_GDB_JIT_INTERFACE
    8163       60748 :   if (code_event_handler == nullptr && i::FLAG_gdbjit) {
    8164             :     code_event_handler = i::GDBJITInterface::EventHandler;
    8165             :   }
    8166             : #endif  // ENABLE_GDB_JIT_INTERFACE
    8167       60748 :   if (code_event_handler) {
    8168           0 :     i_isolate->InitializeLoggingAndCounters();
    8169             :     i_isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault,
    8170           0 :                                              code_event_handler);
    8171             :   }
    8172       60748 :   if (params.counter_lookup_callback) {
    8173             :     isolate->SetCounterFunction(params.counter_lookup_callback);
    8174             :   }
    8175             : 
    8176       60748 :   if (params.create_histogram_callback) {
    8177             :     isolate->SetCreateHistogramFunction(params.create_histogram_callback);
    8178             :   }
    8179             : 
    8180       60748 :   if (params.add_histogram_sample_callback) {
    8181             :     isolate->SetAddHistogramSampleFunction(
    8182             :         params.add_histogram_sample_callback);
    8183             :   }
    8184             : 
    8185       60748 :   i_isolate->set_api_external_references(params.external_references);
    8186       60748 :   i_isolate->set_allow_atomics_wait(params.allow_atomics_wait);
    8187             : 
    8188       60748 :   SetResourceConstraints(i_isolate, params.constraints);
    8189             :   // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
    8190             :   Isolate::Scope isolate_scope(isolate);
    8191       60748 :   if (!i::Snapshot::Initialize(i_isolate)) {
    8192             :     // If snapshot data was provided and we failed to deserialize it must
    8193             :     // have been corrupted.
    8194           0 :     if (i_isolate->snapshot_blob() != nullptr) {
    8195             :       FATAL(
    8196             :           "Failed to deserialize the V8 snapshot blob. This can mean that the "
    8197           0 :           "snapshot blob file is corrupted or missing.");
    8198             :     }
    8199             :     base::ElapsedTimer timer;
    8200           0 :     if (i::FLAG_profile_deserialization) timer.Start();
    8201           0 :     i_isolate->Init(nullptr);
    8202           0 :     if (i::FLAG_profile_deserialization) {
    8203           0 :       double ms = timer.Elapsed().InMillisecondsF();
    8204           0 :       i::PrintF("[Initializing isolate from scratch took %0.3f ms]\n", ms);
    8205             :     }
    8206             :   }
    8207             :   i_isolate->set_only_terminate_in_safe_scope(
    8208       60748 :       params.only_terminate_in_safe_scope);
    8209       60748 : }
    8210             : 
    8211       60513 : Isolate* Isolate::New(const Isolate::CreateParams& params) {
    8212             :   Isolate* isolate = Allocate();
    8213       60513 :   Initialize(isolate, params);
    8214       60513 :   return isolate;
    8215             : }
    8216             : 
    8217       61039 : void Isolate::Dispose() {
    8218       61039 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8219      122078 :   if (!Utils::ApiCheck(!isolate->IsInUse(),
    8220             :                        "v8::Isolate::Dispose()",
    8221             :                        "Disposing the isolate that is entered by a thread.")) {
    8222       61039 :     return;
    8223             :   }
    8224       61034 :   i::Isolate::Delete(isolate);
    8225             : }
    8226             : 
    8227           0 : void Isolate::DumpAndResetStats() {
    8228             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8229           0 :   isolate->DumpAndResetStats();
    8230           0 : }
    8231             : 
    8232        1498 : void Isolate::DiscardThreadSpecificMetadata() {
    8233             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8234        1498 :   isolate->DiscardPerThreadDataForThisThread();
    8235        1498 : }
    8236             : 
    8237             : 
    8238      191690 : void Isolate::Enter() {
    8239             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8240      252629 :   isolate->Enter();
    8241      191688 : }
    8242             : 
    8243             : 
    8244      191675 : void Isolate::Exit() {
    8245             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8246      252614 :   isolate->Exit();
    8247      191673 : }
    8248             : 
    8249             : 
    8250           5 : void Isolate::SetAbortOnUncaughtExceptionCallback(
    8251             :     AbortOnUncaughtExceptionCallback callback) {
    8252             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8253           5 :   isolate->SetAbortOnUncaughtExceptionCallback(callback);
    8254           5 : }
    8255             : 
    8256       30201 : void Isolate::SetHostImportModuleDynamicallyCallback(
    8257             :     HostImportModuleDynamicallyCallback callback) {
    8258             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8259       30201 :   isolate->SetHostImportModuleDynamicallyCallback(callback);
    8260       30201 : }
    8261             : 
    8262       30201 : void Isolate::SetHostInitializeImportMetaObjectCallback(
    8263             :     HostInitializeImportMetaObjectCallback callback) {
    8264             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8265       30201 :   isolate->SetHostInitializeImportMetaObjectCallback(callback);
    8266       30201 : }
    8267             : 
    8268          12 : void Isolate::SetPrepareStackTraceCallback(PrepareStackTraceCallback callback) {
    8269             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8270          12 :   isolate->SetPrepareStackTraceCallback(callback);
    8271          12 : }
    8272             : 
    8273       28952 : Isolate::DisallowJavascriptExecutionScope::DisallowJavascriptExecutionScope(
    8274             :     Isolate* isolate,
    8275             :     Isolate::DisallowJavascriptExecutionScope::OnFailure on_failure)
    8276       28952 :     : on_failure_(on_failure) {
    8277             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8278       28952 :   switch (on_failure_) {
    8279             :     case CRASH_ON_FAILURE:
    8280             :       internal_ = reinterpret_cast<void*>(
    8281           5 :           new i::DisallowJavascriptExecution(i_isolate));
    8282           5 :       break;
    8283             :     case THROW_ON_FAILURE:
    8284             :       DCHECK_EQ(THROW_ON_FAILURE, on_failure);
    8285             :       internal_ =
    8286       28942 :           reinterpret_cast<void*>(new i::ThrowOnJavascriptExecution(i_isolate));
    8287       28942 :       break;
    8288             :     case DUMP_ON_FAILURE:
    8289             :       internal_ =
    8290           5 :           reinterpret_cast<void*>(new i::DumpOnJavascriptExecution(i_isolate));
    8291           5 :       break;
    8292             :     default:
    8293           0 :       UNREACHABLE();
    8294             :       break;
    8295             :   }
    8296       28952 : }
    8297             : 
    8298             : 
    8299       28952 : Isolate::DisallowJavascriptExecutionScope::~DisallowJavascriptExecutionScope() {
    8300       28952 :   switch (on_failure_) {
    8301             :     case CRASH_ON_FAILURE:
    8302           5 :       delete reinterpret_cast<i::DisallowJavascriptExecution*>(internal_);
    8303             :       break;
    8304             :     case THROW_ON_FAILURE:
    8305       28942 :       delete reinterpret_cast<i::ThrowOnJavascriptExecution*>(internal_);
    8306             :       break;
    8307             :     case DUMP_ON_FAILURE:
    8308           5 :       delete reinterpret_cast<i::DumpOnJavascriptExecution*>(internal_);
    8309             :       break;
    8310             :     default:
    8311           0 :       UNREACHABLE();
    8312             :       break;
    8313             :   }
    8314       28952 : }
    8315             : 
    8316             : 
    8317      271607 : Isolate::AllowJavascriptExecutionScope::AllowJavascriptExecutionScope(
    8318             :     Isolate* isolate) {
    8319             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8320             :   internal_assert_ = reinterpret_cast<void*>(
    8321      271607 :       new i::AllowJavascriptExecution(i_isolate));
    8322             :   internal_throws_ = reinterpret_cast<void*>(
    8323      271607 :       new i::NoThrowOnJavascriptExecution(i_isolate));
    8324             :   internal_dump_ =
    8325      271607 :       reinterpret_cast<void*>(new i::NoDumpOnJavascriptExecution(i_isolate));
    8326      271607 : }
    8327             : 
    8328             : 
    8329      271607 : Isolate::AllowJavascriptExecutionScope::~AllowJavascriptExecutionScope() {
    8330      271607 :   delete reinterpret_cast<i::AllowJavascriptExecution*>(internal_assert_);
    8331      271607 :   delete reinterpret_cast<i::NoThrowOnJavascriptExecution*>(internal_throws_);
    8332      271607 :   delete reinterpret_cast<i::NoDumpOnJavascriptExecution*>(internal_dump_);
    8333      271607 : }
    8334             : 
    8335       51579 : Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope(
    8336             :     Isolate* isolate)
    8337             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    8338       51579 :       microtask_queue_(isolate_->default_microtask_queue()) {
    8339             :   isolate_->handle_scope_implementer()->IncrementCallDepth();
    8340       51579 :   microtask_queue_->IncrementMicrotasksSuppressions();
    8341       51579 : }
    8342             : 
    8343       51579 : Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
    8344       51579 :   microtask_queue_->DecrementMicrotasksSuppressions();
    8345       51579 :   isolate_->handle_scope_implementer()->DecrementCallDepth();
    8346       51579 : }
    8347             : 
    8348       23486 : Isolate::SafeForTerminationScope::SafeForTerminationScope(v8::Isolate* isolate)
    8349             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    8350       23486 :       prev_value_(isolate_->next_v8_call_is_safe_for_termination()) {
    8351             :   isolate_->set_next_v8_call_is_safe_for_termination(true);
    8352       23486 : }
    8353             : 
    8354       23486 : Isolate::SafeForTerminationScope::~SafeForTerminationScope() {
    8355       23486 :   isolate_->set_next_v8_call_is_safe_for_termination(prev_value_);
    8356       23486 : }
    8357             : 
    8358          85 : i::Address* Isolate::GetDataFromSnapshotOnce(size_t index) {
    8359             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
    8360          85 :   i::FixedArray list = i_isolate->heap()->serialized_objects();
    8361          85 :   return GetSerializedDataFromFixedArray(i_isolate, list, index);
    8362             : }
    8363             : 
    8364         246 : void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
    8365         492 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8366         246 :   i::Heap* heap = isolate->heap();
    8367         246 :   heap_statistics->total_heap_size_ = heap->CommittedMemory();
    8368             :   heap_statistics->total_heap_size_executable_ =
    8369         246 :       heap->CommittedMemoryExecutable();
    8370         246 :   heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
    8371         246 :   heap_statistics->total_available_size_ = heap->Available();
    8372         246 :   heap_statistics->used_heap_size_ = heap->SizeOfObjects();
    8373         246 :   heap_statistics->heap_size_limit_ = heap->MaxReserved();
    8374             :   // TODO(7424): There is no public API for the {WasmEngine} yet. Once such an
    8375             :   // API becomes available we should report the malloced memory separately. For
    8376             :   // now we just add the values, thereby over-approximating the peak slightly.
    8377             :   heap_statistics->malloced_memory_ =
    8378         492 :       isolate->allocator()->GetCurrentMemoryUsage() +
    8379         492 :       isolate->wasm_engine()->allocator()->GetCurrentMemoryUsage();
    8380         246 :   heap_statistics->external_memory_ = isolate->heap()->backing_store_bytes();
    8381             :   heap_statistics->peak_malloced_memory_ =
    8382         492 :       isolate->allocator()->GetMaxMemoryUsage() +
    8383         492 :       isolate->wasm_engine()->allocator()->GetMaxMemoryUsage();
    8384         246 :   heap_statistics->number_of_native_contexts_ = heap->NumberOfNativeContexts();
    8385             :   heap_statistics->number_of_detached_contexts_ =
    8386         246 :       heap->NumberOfDetachedContexts();
    8387         246 :   heap_statistics->does_zap_garbage_ = heap->ShouldZapGarbage();
    8388         246 : }
    8389             : 
    8390             : 
    8391          45 : size_t Isolate::NumberOfHeapSpaces() {
    8392          45 :   return i::LAST_SPACE - i::FIRST_SPACE + 1;
    8393             : }
    8394             : 
    8395             : 
    8396          40 : bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
    8397             :                                      size_t index) {
    8398          40 :   if (!space_statistics) return false;
    8399          40 :   if (!i::Heap::IsValidAllocationSpace(static_cast<i::AllocationSpace>(index)))
    8400             :     return false;
    8401             : 
    8402             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8403          40 :   i::Heap* heap = isolate->heap();
    8404          40 :   i::Space* space = heap->space(static_cast<int>(index));
    8405             : 
    8406          40 :   space_statistics->space_name_ = heap->GetSpaceName(static_cast<int>(index));
    8407          40 :   space_statistics->space_size_ = space->CommittedMemory();
    8408          40 :   space_statistics->space_used_size_ = space->SizeOfObjects();
    8409          40 :   space_statistics->space_available_size_ = space->Available();
    8410          40 :   space_statistics->physical_space_size_ = space->CommittedPhysicalMemory();
    8411          40 :   return true;
    8412             : }
    8413             : 
    8414             : 
    8415           0 : size_t Isolate::NumberOfTrackedHeapObjectTypes() {
    8416             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8417           0 :   i::Heap* heap = isolate->heap();
    8418           0 :   return heap->NumberOfTrackedHeapObjectTypes();
    8419             : }
    8420             : 
    8421             : 
    8422           0 : bool Isolate::GetHeapObjectStatisticsAtLastGC(
    8423             :     HeapObjectStatistics* object_statistics, size_t type_index) {
    8424           0 :   if (!object_statistics) return false;
    8425           0 :   if (V8_LIKELY(!i::FLAG_gc_stats)) return false;
    8426             : 
    8427             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8428           0 :   i::Heap* heap = isolate->heap();
    8429           0 :   if (type_index >= heap->NumberOfTrackedHeapObjectTypes()) return false;
    8430             : 
    8431             :   const char* object_type;
    8432             :   const char* object_sub_type;
    8433           0 :   size_t object_count = heap->ObjectCountAtLastGC(type_index);
    8434           0 :   size_t object_size = heap->ObjectSizeAtLastGC(type_index);
    8435           0 :   if (!heap->GetObjectTypeName(type_index, &object_type, &object_sub_type)) {
    8436             :     // There should be no objects counted when the type is unknown.
    8437             :     DCHECK_EQ(object_count, 0U);
    8438             :     DCHECK_EQ(object_size, 0U);
    8439             :     return false;
    8440             :   }
    8441             : 
    8442           0 :   object_statistics->object_type_ = object_type;
    8443           0 :   object_statistics->object_sub_type_ = object_sub_type;
    8444           0 :   object_statistics->object_count_ = object_count;
    8445           0 :   object_statistics->object_size_ = object_size;
    8446           0 :   return true;
    8447             : }
    8448             : 
    8449           0 : bool Isolate::GetHeapCodeAndMetadataStatistics(
    8450             :     HeapCodeStatistics* code_statistics) {
    8451           0 :   if (!code_statistics) return false;
    8452             : 
    8453           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8454           0 :   isolate->heap()->CollectCodeStatistics();
    8455             : 
    8456           0 :   code_statistics->code_and_metadata_size_ = isolate->code_and_metadata_size();
    8457             :   code_statistics->bytecode_and_metadata_size_ =
    8458           0 :       isolate->bytecode_and_metadata_size();
    8459             :   code_statistics->external_script_source_size_ =
    8460           0 :       isolate->external_script_source_size();
    8461           0 :   return true;
    8462             : }
    8463             : 
    8464          15 : void Isolate::GetStackSample(const RegisterState& state, void** frames,
    8465             :                              size_t frames_limit, SampleInfo* sample_info) {
    8466          15 :   RegisterState regs = state;
    8467          15 :   if (TickSample::GetStackSample(this, &regs, TickSample::kSkipCEntryFrame,
    8468             :                                  frames, frames_limit, sample_info)) {
    8469          15 :     return;
    8470             :   }
    8471           0 :   sample_info->frames_count = 0;
    8472           0 :   sample_info->vm_state = OTHER;
    8473           0 :   sample_info->external_callback_entry = nullptr;
    8474             : }
    8475             : 
    8476          15 : size_t Isolate::NumberOfPhantomHandleResetsSinceLastCall() {
    8477          15 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8478          15 :   return isolate->global_handles()->GetAndResetGlobalHandleResetCount();
    8479             : }
    8480             : 
    8481           5 : void Isolate::SetEventLogger(LogEventCallback that) {
    8482             :   // Do not overwrite the event logger if we want to log explicitly.
    8483          10 :   if (i::FLAG_log_internal_timer_events) return;
    8484             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8485             :   isolate->set_event_logger(that);
    8486             : }
    8487             : 
    8488             : 
    8489          15 : void Isolate::AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback) {
    8490          30 :   if (callback == nullptr) return;
    8491             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8492          15 :   isolate->AddBeforeCallEnteredCallback(callback);
    8493             : }
    8494             : 
    8495             : 
    8496           5 : void Isolate::RemoveBeforeCallEnteredCallback(
    8497             :     BeforeCallEnteredCallback callback) {
    8498             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8499           5 :   isolate->RemoveBeforeCallEnteredCallback(callback);
    8500           5 : }
    8501             : 
    8502             : 
    8503          65 : void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
    8504         130 :   if (callback == nullptr) return;
    8505             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8506          65 :   isolate->AddCallCompletedCallback(callback);
    8507             : }
    8508             : 
    8509             : 
    8510        3683 : void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
    8511             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8512        3683 :   isolate->RemoveCallCompletedCallback(callback);
    8513        3683 : }
    8514             : 
    8515          20 : void Isolate::AtomicsWaitWakeHandle::Wake() {
    8516          20 :   reinterpret_cast<i::AtomicsWaitWakeHandle*>(this)->Wake();
    8517          20 : }
    8518             : 
    8519           5 : void Isolate::SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data) {
    8520             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8521           5 :   isolate->SetAtomicsWaitCallback(callback, data);
    8522           5 : }
    8523             : 
    8524         110 : void Isolate::SetPromiseHook(PromiseHook hook) {
    8525             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8526         110 :   isolate->SetPromiseHook(hook);
    8527         110 : }
    8528             : 
    8529        1116 : void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) {
    8530        2232 :   if (callback == nullptr) return;
    8531             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8532        1116 :   isolate->SetPromiseRejectCallback(callback);
    8533             : }
    8534             : 
    8535             : 
    8536         126 : void Isolate::RunMicrotasks() {
    8537             :   DCHECK_NE(MicrotasksPolicy::kScoped, GetMicrotasksPolicy());
    8538         126 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8539         126 :   isolate->default_microtask_queue()->RunMicrotasks(isolate);
    8540         126 : }
    8541             : 
    8542         120 : void Isolate::EnqueueMicrotask(Local<Function> function) {
    8543         120 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8544             :   i::Handle<i::CallableTask> microtask = isolate->factory()->NewCallableTask(
    8545         240 :       Utils::OpenHandle(*function), isolate->native_context());
    8546         240 :   isolate->default_microtask_queue()->EnqueueMicrotask(*microtask);
    8547         120 : }
    8548             : 
    8549         441 : void Isolate::EnqueueMicrotask(MicrotaskCallback callback, void* data) {
    8550         441 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8551             :   i::HandleScope scope(isolate);
    8552             :   i::Handle<i::CallbackTask> microtask = isolate->factory()->NewCallbackTask(
    8553             :       isolate->factory()->NewForeign(reinterpret_cast<i::Address>(callback)),
    8554         441 :       isolate->factory()->NewForeign(reinterpret_cast<i::Address>(data)));
    8555         882 :   isolate->default_microtask_queue()->EnqueueMicrotask(*microtask);
    8556         441 : }
    8557             : 
    8558             : 
    8559        2252 : void Isolate::SetMicrotasksPolicy(MicrotasksPolicy policy) {
    8560        2252 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8561             :   isolate->default_microtask_queue()->set_microtasks_policy(policy);
    8562        2252 : }
    8563             : 
    8564             : 
    8565           0 : MicrotasksPolicy Isolate::GetMicrotasksPolicy() const {
    8566           0 :   i::Isolate* isolate =
    8567             :       reinterpret_cast<i::Isolate*>(const_cast<Isolate*>(this));
    8568           0 :   return isolate->default_microtask_queue()->microtasks_policy();
    8569             : }
    8570             : 
    8571             : 
    8572          45 : void Isolate::AddMicrotasksCompletedCallback(
    8573             :     MicrotasksCompletedCallback callback) {
    8574             :   DCHECK(callback);
    8575          45 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8576          45 :   isolate->default_microtask_queue()->AddMicrotasksCompletedCallback(callback);
    8577          45 : }
    8578             : 
    8579             : 
    8580        3683 : void Isolate::RemoveMicrotasksCompletedCallback(
    8581             :     MicrotasksCompletedCallback callback) {
    8582        3683 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8583             :   isolate->default_microtask_queue()->RemoveMicrotasksCompletedCallback(
    8584        3683 :       callback);
    8585        3683 : }
    8586             : 
    8587             : 
    8588          55 : void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
    8589          55 :   reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
    8590          55 : }
    8591             : 
    8592             : 
    8593           5 : void Isolate::SetCounterFunction(CounterLookupCallback callback) {
    8594             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8595           5 :   isolate->counters()->ResetCounterFunction(callback);
    8596           5 : }
    8597             : 
    8598             : 
    8599           8 : void Isolate::SetCreateHistogramFunction(CreateHistogramCallback callback) {
    8600             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8601           8 :   isolate->counters()->ResetCreateHistogramFunction(callback);
    8602           8 : }
    8603             : 
    8604             : 
    8605           8 : void Isolate::SetAddHistogramSampleFunction(
    8606             :     AddHistogramSampleCallback callback) {
    8607             :   reinterpret_cast<i::Isolate*>(this)
    8608             :       ->counters()
    8609             :       ->SetAddHistogramSampleFunction(callback);
    8610           8 : }
    8611             : 
    8612             : 
    8613         479 : bool Isolate::IdleNotificationDeadline(double deadline_in_seconds) {
    8614             :   // Returning true tells the caller that it need not
    8615             :   // continue to call IdleNotification.
    8616             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8617         479 :   if (!i::FLAG_use_idle_notification) return true;
    8618         479 :   return isolate->heap()->IdleNotification(deadline_in_seconds);
    8619             : }
    8620             : 
    8621         500 : void Isolate::LowMemoryNotification() {
    8622             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8623             :   {
    8624             :     i::HistogramTimerScope idle_notification_scope(
    8625         500 :         isolate->counters()->gc_low_memory_notification());
    8626        1500 :     TRACE_EVENT0("v8", "V8.GCLowMemoryNotification");
    8627             :     isolate->heap()->CollectAllAvailableGarbage(
    8628         500 :         i::GarbageCollectionReason::kLowMemoryNotification);
    8629             :   }
    8630             :   {
    8631         500 :     i::HeapIterator iterator(isolate->heap());
    8632     6362590 :     for (i::HeapObject obj = iterator.next(); !obj.is_null();
    8633             :          obj = iterator.next()) {
    8634     3180795 :       if (obj->IsAbstractCode()) {
    8635      754570 :         i::AbstractCode::cast(obj)->DropStackFrameCache();
    8636             :       }
    8637         500 :     }
    8638             :   }
    8639         500 : }
    8640             : 
    8641             : 
    8642         593 : int Isolate::ContextDisposedNotification(bool dependant_context) {
    8643             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8644         593 :   if (!dependant_context) {
    8645             :     // We left the current context, we can abort all WebAssembly compilations on
    8646             :     // that isolate.
    8647          10 :     isolate->wasm_engine()->DeleteCompileJobsOnIsolate(isolate);
    8648             :   }
    8649             :   // TODO(ahaas): move other non-heap activity out of the heap call.
    8650         593 :   return isolate->heap()->NotifyContextDisposed(dependant_context);
    8651             : }
    8652             : 
    8653             : 
    8654           0 : void Isolate::IsolateInForegroundNotification() {
    8655             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8656           0 :   return isolate->IsolateInForegroundNotification();
    8657             : }
    8658             : 
    8659             : 
    8660           0 : void Isolate::IsolateInBackgroundNotification() {
    8661             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8662           0 :   return isolate->IsolateInBackgroundNotification();
    8663             : }
    8664             : 
    8665          83 : void Isolate::MemoryPressureNotification(MemoryPressureLevel level) {
    8666         103 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8667             :   bool on_isolate_thread =
    8668          83 :       v8::Locker::IsActive()
    8669             :           ? isolate->thread_manager()->IsLockedByCurrentThread()
    8670         249 :           : i::ThreadId::Current().Equals(isolate->thread_id());
    8671          83 :   isolate->heap()->MemoryPressureNotification(level, on_isolate_thread);
    8672          83 :   isolate->allocator()->MemoryPressureNotification(level);
    8673          83 : }
    8674             : 
    8675           5 : void Isolate::EnableMemorySavingsMode() {
    8676             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8677             :   isolate->EnableMemorySavingsMode();
    8678           5 : }
    8679             : 
    8680           5 : void Isolate::DisableMemorySavingsMode() {
    8681             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8682             :   isolate->DisableMemorySavingsMode();
    8683           5 : }
    8684             : 
    8685           0 : void Isolate::SetRAILMode(RAILMode rail_mode) {
    8686             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8687           0 :   return isolate->SetRAILMode(rail_mode);
    8688             : }
    8689             : 
    8690           0 : void Isolate::IncreaseHeapLimitForDebugging() {
    8691             :   // No-op.
    8692           0 : }
    8693             : 
    8694           5 : void Isolate::RestoreOriginalHeapLimit() {
    8695             :   // No-op.
    8696           5 : }
    8697             : 
    8698           0 : bool Isolate::IsHeapLimitIncreasedForDebugging() { return false; }
    8699             : 
    8700          60 : void Isolate::SetJitCodeEventHandler(JitCodeEventOptions options,
    8701             :                                      JitCodeEventHandler event_handler) {
    8702          60 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8703             :   // Ensure that logging is initialized for our isolate.
    8704          60 :   isolate->InitializeLoggingAndCounters();
    8705          60 :   isolate->logger()->SetCodeEventHandler(options, event_handler);
    8706          60 : }
    8707             : 
    8708             : 
    8709          10 : void Isolate::SetStackLimit(uintptr_t stack_limit) {
    8710             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8711          10 :   CHECK(stack_limit);
    8712          10 :   isolate->stack_guard()->SetStackLimit(stack_limit);
    8713          10 : }
    8714             : 
    8715           0 : void Isolate::GetCodeRange(void** start, size_t* length_in_bytes) {
    8716             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8717         140 :   const base::AddressRegion& code_range =
    8718             :       isolate->heap()->memory_allocator()->code_range();
    8719          70 :   *start = reinterpret_cast<void*>(code_range.begin());
    8720          70 :   *length_in_bytes = code_range.size();
    8721           0 : }
    8722             : 
    8723          70 : UnwindState Isolate::GetUnwindState() {
    8724          70 :   UnwindState unwind_state;
    8725             :   void* code_range_start;
    8726             :   GetCodeRange(&code_range_start, &unwind_state.code_range.length_in_bytes);
    8727          70 :   unwind_state.code_range.start = code_range_start;
    8728             : 
    8729             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8730             :   unwind_state.embedded_code_range.start =
    8731          70 :       reinterpret_cast<const void*>(isolate->embedded_blob());
    8732             :   unwind_state.embedded_code_range.length_in_bytes =
    8733          70 :       isolate->embedded_blob_size();
    8734             : 
    8735          70 :   i::Code js_entry = isolate->heap()->builtin(i::Builtins::kJSEntry);
    8736             :   unwind_state.js_entry_stub.code.start =
    8737          70 :       reinterpret_cast<const void*>(js_entry->InstructionStart());
    8738          70 :   unwind_state.js_entry_stub.code.length_in_bytes = js_entry->InstructionSize();
    8739             : 
    8740          70 :   return unwind_state;
    8741             : }
    8742             : 
    8743             : #define CALLBACK_SETTER(ExternalName, Type, InternalName)      \
    8744             :   void Isolate::Set##ExternalName(Type callback) {             \
    8745             :     i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); \
    8746             :     isolate->set_##InternalName(callback);                     \
    8747             :   }
    8748             : 
    8749          80 : CALLBACK_SETTER(FatalErrorHandler, FatalErrorCallback, exception_behavior)
    8750           0 : CALLBACK_SETTER(OOMErrorHandler, OOMErrorCallback, oom_behavior)
    8751         340 : CALLBACK_SETTER(AllowCodeGenerationFromStringsCallback,
    8752             :                 AllowCodeGenerationFromStringsCallback, allow_code_gen_callback)
    8753         272 : CALLBACK_SETTER(AllowWasmCodeGenerationCallback,
    8754             :                 AllowWasmCodeGenerationCallback, allow_wasm_code_gen_callback)
    8755             : 
    8756          96 : CALLBACK_SETTER(WasmModuleCallback, ExtensionCallback, wasm_module_callback)
    8757          16 : CALLBACK_SETTER(WasmInstanceCallback, ExtensionCallback, wasm_instance_callback)
    8758             : 
    8759          48 : CALLBACK_SETTER(WasmStreamingCallback, WasmStreamingCallback,
    8760             :                 wasm_streaming_callback)
    8761             : 
    8762          58 : CALLBACK_SETTER(WasmThreadsEnabledCallback, WasmThreadsEnabledCallback,
    8763             :                 wasm_threads_enabled_callback)
    8764             : 
    8765        3398 : void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
    8766             :                                        void* data) {
    8767             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8768        3398 :   isolate->heap()->AddNearHeapLimitCallback(callback, data);
    8769        3398 : }
    8770             : 
    8771        3398 : void Isolate::RemoveNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
    8772             :                                           size_t heap_limit) {
    8773             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8774        3398 :   isolate->heap()->RemoveNearHeapLimitCallback(callback, heap_limit);
    8775        3398 : }
    8776             : 
    8777           0 : void Isolate::AutomaticallyRestoreInitialHeapLimit(double threshold_percent) {
    8778             :   DCHECK_GT(threshold_percent, 0.0);
    8779             :   DCHECK_LT(threshold_percent, 1.0);
    8780             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8781           0 :   isolate->heap()->AutomaticallyRestoreInitialHeapLimit(threshold_percent);
    8782           0 : }
    8783             : 
    8784           0 : bool Isolate::IsDead() {
    8785           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8786           0 :   return isolate->IsDead();
    8787             : }
    8788             : 
    8789        1237 : bool Isolate::AddMessageListener(MessageCallback that, Local<Value> data) {
    8790        1237 :   return AddMessageListenerWithErrorLevel(that, kMessageError, data);
    8791             : }
    8792             : 
    8793       30838 : bool Isolate::AddMessageListenerWithErrorLevel(MessageCallback that,
    8794             :                                                int message_levels,
    8795             :                                                Local<Value> data) {
    8796             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8797             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    8798             :   i::HandleScope scope(isolate);
    8799             :   i::Handle<i::TemplateList> list = isolate->factory()->message_listeners();
    8800       30838 :   i::Handle<i::FixedArray> listener = isolate->factory()->NewFixedArray(3);
    8801             :   i::Handle<i::Foreign> foreign =
    8802       30838 :       isolate->factory()->NewForeign(FUNCTION_ADDR(that));
    8803       61676 :   listener->set(0, *foreign);
    8804             :   listener->set(1, data.IsEmpty() ? i::ReadOnlyRoots(isolate).undefined_value()
    8805       92498 :                                   : *Utils::OpenHandle(*data));
    8806             :   listener->set(2, i::Smi::FromInt(message_levels));
    8807       30838 :   list = i::TemplateList::Add(isolate, list, listener);
    8808       30838 :   isolate->heap()->SetMessageListeners(*list);
    8809       30838 :   return true;
    8810             : }
    8811             : 
    8812             : 
    8813         151 : void Isolate::RemoveMessageListeners(MessageCallback that) {
    8814             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8815             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    8816             :   i::HandleScope scope(isolate);
    8817             :   i::DisallowHeapAllocation no_gc;
    8818         151 :   i::TemplateList listeners = isolate->heap()->message_listeners();
    8819         344 :   for (int i = 0; i < listeners->length(); i++) {
    8820         386 :     if (listeners->get(i)->IsUndefined(isolate)) continue;  // skip deleted ones
    8821         151 :     i::FixedArray listener = i::FixedArray::cast(listeners->get(i));
    8822             :     i::Foreign callback_obj = i::Foreign::cast(listener->get(0));
    8823         151 :     if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
    8824         151 :       listeners->set(i, i::ReadOnlyRoots(isolate).undefined_value());
    8825             :     }
    8826             :   }
    8827         151 : }
    8828             : 
    8829             : 
    8830          26 : void Isolate::SetFailedAccessCheckCallbackFunction(
    8831             :     FailedAccessCheckCallback callback) {
    8832             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8833          26 :   isolate->SetFailedAccessCheckCallback(callback);
    8834          26 : }
    8835             : 
    8836             : 
    8837        1271 : void Isolate::SetCaptureStackTraceForUncaughtExceptions(
    8838             :     bool capture, int frame_limit, StackTrace::StackTraceOptions options) {
    8839             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8840             :   isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit,
    8841        1271 :                                                      options);
    8842        1271 : }
    8843             : 
    8844             : 
    8845           5 : void Isolate::VisitExternalResources(ExternalResourceVisitor* visitor) {
    8846             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8847           5 :   isolate->heap()->VisitExternalResources(visitor);
    8848           5 : }
    8849             : 
    8850             : 
    8851       27302 : bool Isolate::IsInUse() {
    8852       27302 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8853       27302 :   return isolate->IsInUse();
    8854             : }
    8855             : 
    8856             : 
    8857          10 : void Isolate::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
    8858          10 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8859             :   i::DisallowHeapAllocation no_allocation;
    8860          10 :   isolate->global_handles()->IterateAllRootsWithClassIds(visitor);
    8861          10 : }
    8862             : 
    8863             : 
    8864           5 : void Isolate::VisitHandlesForPartialDependence(
    8865             :     PersistentHandleVisitor* visitor) {
    8866           5 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8867             :   i::DisallowHeapAllocation no_allocation;
    8868           5 :   isolate->global_handles()->IterateAllYoungRootsWithClassIds(visitor);
    8869           5 : }
    8870             : 
    8871             : 
    8872           0 : void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) {
    8873           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8874             :   i::DisallowHeapAllocation no_allocation;
    8875           0 :   isolate->global_handles()->IterateYoungWeakRootsWithClassIds(visitor);
    8876           0 : }
    8877             : 
    8878           5 : void Isolate::SetAllowAtomicsWait(bool allow) {
    8879             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8880             :   isolate->set_allow_atomics_wait(allow);
    8881           5 : }
    8882             : 
    8883     1225245 : MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type)
    8884             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    8885     1225245 :       microtask_queue_(isolate_->default_microtask_queue()),
    8886     2450490 :       run_(type == MicrotasksScope::kRunMicrotasks) {
    8887     1225245 :   if (run_) microtask_queue_->IncrementMicrotasksScopeDepth();
    8888             : #ifdef DEBUG
    8889             :   if (!run_) microtask_queue_->IncrementDebugMicrotasksScopeDepth();
    8890             : #endif
    8891     1225245 : }
    8892             : 
    8893     1225245 : MicrotasksScope::~MicrotasksScope() {
    8894     1225245 :   if (run_) {
    8895      320288 :     microtask_queue_->DecrementMicrotasksScopeDepth();
    8896      320288 :     if (MicrotasksPolicy::kScoped == microtask_queue_->microtasks_policy()) {
    8897       92264 :       PerformCheckpoint(reinterpret_cast<Isolate*>(isolate_));
    8898             :     }
    8899             :   }
    8900             : #ifdef DEBUG
    8901             :   if (!run_) microtask_queue_->DecrementDebugMicrotasksScopeDepth();
    8902             : #endif
    8903     1225241 : }
    8904             : 
    8905             : 
    8906      141211 : void MicrotasksScope::PerformCheckpoint(Isolate* v8Isolate) {
    8907      141211 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8Isolate);
    8908      280909 :   auto* microtask_queue = isolate->default_microtask_queue();
    8909      280909 :   if (!microtask_queue->GetMicrotasksScopeDepth() &&
    8910             :       !microtask_queue->HasMicrotasksSuppressions()) {
    8911      139651 :     microtask_queue->RunMicrotasks(isolate);
    8912             :   }
    8913      141207 : }
    8914             : 
    8915             : 
    8916           0 : int MicrotasksScope::GetCurrentDepth(Isolate* v8Isolate) {
    8917           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8Isolate);
    8918           0 :   return isolate->default_microtask_queue()->GetMicrotasksScopeDepth();
    8919             : }
    8920             : 
    8921         100 : bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) {
    8922         100 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8Isolate);
    8923         100 :   return isolate->default_microtask_queue()->IsRunningMicrotasks();
    8924             : }
    8925             : 
    8926     9053800 : String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
    8927     9053800 :     : str_(nullptr), length_(0) {
    8928     9053843 :   if (obj.IsEmpty()) return;
    8929             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8930             :   ENTER_V8_DO_NOT_USE(i_isolate);
    8931             :   i::HandleScope scope(i_isolate);
    8932     9053765 :   Local<Context> context = isolate->GetCurrentContext();
    8933    18107522 :   TryCatch try_catch(isolate);
    8934             :   Local<String> str;
    8935    18107538 :   if (!obj->ToString(context).ToLocal(&str)) return;
    8936     9053757 :   length_ = str->Utf8Length(isolate);
    8937     9053757 :   str_ = i::NewArray<char>(length_ + 1);
    8938     9053757 :   str->WriteUtf8(isolate, str_);
    8939             : }
    8940             : 
    8941     9053800 : String::Utf8Value::~Utf8Value() {
    8942     9053800 :   i::DeleteArray(str_);
    8943     9053800 : }
    8944             : 
    8945           6 : String::Value::Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
    8946           6 :     : str_(nullptr), length_(0) {
    8947           6 :   if (obj.IsEmpty()) return;
    8948             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8949             :   ENTER_V8_DO_NOT_USE(i_isolate);
    8950             :   i::HandleScope scope(i_isolate);
    8951           6 :   Local<Context> context = isolate->GetCurrentContext();
    8952          12 :   TryCatch try_catch(isolate);
    8953             :   Local<String> str;
    8954          12 :   if (!obj->ToString(context).ToLocal(&str)) return;
    8955           6 :   length_ = str->Length();
    8956           6 :   str_ = i::NewArray<uint16_t>(length_ + 1);
    8957             :   str->Write(isolate, str_);
    8958             : }
    8959             : 
    8960           6 : String::Value::~Value() {
    8961           6 :   i::DeleteArray(str_);
    8962           6 : }
    8963             : 
    8964             : #define DEFINE_ERROR(NAME, name)                                         \
    8965             :   Local<Value> Exception::NAME(v8::Local<v8::String> raw_message) {      \
    8966             :     i::Isolate* isolate = i::Isolate::Current();                         \
    8967             :     LOG_API(isolate, NAME, New);                                         \
    8968             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);                            \
    8969             :     i::Object error;                                                     \
    8970             :     {                                                                    \
    8971             :       i::HandleScope scope(isolate);                                     \
    8972             :       i::Handle<i::String> message = Utils::OpenHandle(*raw_message);    \
    8973             :       i::Handle<i::JSFunction> constructor = isolate->name##_function(); \
    8974             :       error = *isolate->factory()->NewError(constructor, message);       \
    8975             :     }                                                                    \
    8976             :     i::Handle<i::Object> result(error, isolate);                         \
    8977             :     return Utils::ToLocal(result);                                       \
    8978             :   }
    8979             : 
    8980         110 : DEFINE_ERROR(RangeError, range_error)
    8981          30 : DEFINE_ERROR(ReferenceError, reference_error)
    8982          30 : DEFINE_ERROR(SyntaxError, syntax_error)
    8983          30 : DEFINE_ERROR(TypeError, type_error)
    8984        1215 : DEFINE_ERROR(Error, error)
    8985             : 
    8986             : #undef DEFINE_ERROR
    8987             : 
    8988             : 
    8989         328 : Local<Message> Exception::CreateMessage(Isolate* isolate,
    8990             :                                         Local<Value> exception) {
    8991         328 :   i::Handle<i::Object> obj = Utils::OpenHandle(*exception);
    8992             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8993             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    8994             :   i::HandleScope scope(i_isolate);
    8995             :   return Utils::MessageToLocal(
    8996         656 :       scope.CloseAndEscape(i_isolate->CreateMessage(obj, nullptr)));
    8997             : }
    8998             : 
    8999             : 
    9000          77 : Local<StackTrace> Exception::GetStackTrace(Local<Value> exception) {
    9001             :   i::Handle<i::Object> obj = Utils::OpenHandle(*exception);
    9002         154 :   if (!obj->IsJSObject()) return Local<StackTrace>();
    9003          77 :   i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
    9004             :   i::Isolate* isolate = js_obj->GetIsolate();
    9005             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9006          77 :   return Utils::StackTraceToLocal(isolate->GetDetailedStackTrace(js_obj));
    9007             : }
    9008             : 
    9009             : 
    9010             : // --- D e b u g   S u p p o r t ---
    9011             : 
    9012        3737 : void debug::SetContextId(Local<Context> context, int id) {
    9013        7474 :   Utils::OpenHandle(*context)->set_debug_context_id(i::Smi::FromInt(id));
    9014        3737 : }
    9015             : 
    9016     3876281 : int debug::GetContextId(Local<Context> context) {
    9017     3876281 :   i::Object value = Utils::OpenHandle(*context)->debug_context_id();
    9018     3876281 :   return (value->IsSmi()) ? i::Smi::ToInt(value) : 0;
    9019             : }
    9020             : 
    9021        7276 : void debug::SetInspector(Isolate* isolate,
    9022             :                          v8_inspector::V8Inspector* inspector) {
    9023             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9024             :   i_isolate->set_inspector(inspector);
    9025        7276 : }
    9026             : 
    9027     7184319 : v8_inspector::V8Inspector* debug::GetInspector(Isolate* isolate) {
    9028     7184319 :   return reinterpret_cast<i::Isolate*>(isolate)->inspector();
    9029             : }
    9030             : 
    9031        6615 : void debug::SetBreakOnNextFunctionCall(Isolate* isolate) {
    9032        6615 :   reinterpret_cast<i::Isolate*>(isolate)->debug()->SetBreakOnNextFunctionCall();
    9033        6615 : }
    9034             : 
    9035          30 : void debug::ClearBreakOnNextFunctionCall(Isolate* isolate) {
    9036             :   reinterpret_cast<i::Isolate*>(isolate)
    9037             :       ->debug()
    9038          30 :       ->ClearBreakOnNextFunctionCall();
    9039          30 : }
    9040             : 
    9041       79153 : MaybeLocal<Array> debug::GetInternalProperties(Isolate* v8_isolate,
    9042             :                                                Local<Value> value) {
    9043             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9044             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9045       79153 :   i::Handle<i::Object> val = Utils::OpenHandle(*value);
    9046             :   i::Handle<i::JSArray> result;
    9047      158306 :   if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result))
    9048           0 :     return MaybeLocal<Array>();
    9049       79153 :   return Utils::ToLocal(result);
    9050             : }
    9051             : 
    9052        7473 : void debug::ChangeBreakOnException(Isolate* isolate, ExceptionBreakState type) {
    9053       14946 :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9054             :   internal_isolate->debug()->ChangeBreakOnException(
    9055       14946 :       i::BreakException, type == BreakOnAnyException);
    9056             :   internal_isolate->debug()->ChangeBreakOnException(i::BreakUncaughtException,
    9057       14946 :                                                     type != NoBreakOnException);
    9058        7473 : }
    9059             : 
    9060        7036 : void debug::SetBreakPointsActive(Isolate* v8_isolate, bool is_active) {
    9061        7036 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9062             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9063             :   isolate->debug()->set_break_points_active(is_active);
    9064        7036 : }
    9065             : 
    9066       44423 : void debug::PrepareStep(Isolate* v8_isolate, StepAction action) {
    9067       88846 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9068             :   ENTER_V8_DO_NOT_USE(isolate);
    9069       44423 :   CHECK(isolate->debug()->CheckExecutionState());
    9070             :   // Clear all current stepping setup.
    9071       44423 :   isolate->debug()->ClearStepping();
    9072             :   // Prepare step.
    9073       88846 :   isolate->debug()->PrepareStep(static_cast<i::StepAction>(action));
    9074       44423 : }
    9075             : 
    9076           0 : void debug::ClearStepping(Isolate* v8_isolate) {
    9077           0 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9078             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9079             :   // Clear all current stepping setup.
    9080           0 :   isolate->debug()->ClearStepping();
    9081           0 : }
    9082             : 
    9083       60221 : void debug::BreakRightNow(Isolate* v8_isolate) {
    9084       60221 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9085             :   ENTER_V8_DO_NOT_USE(isolate);
    9086       60221 :   isolate->debug()->HandleDebugBreak(i::kIgnoreIfAllFramesBlackboxed);
    9087       60221 : }
    9088             : 
    9089         370 : bool debug::AllFramesOnStackAreBlackboxed(Isolate* v8_isolate) {
    9090         370 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9091             :   ENTER_V8_DO_NOT_USE(isolate);
    9092         740 :   return isolate->debug()->AllFramesOnStackAreBlackboxed();
    9093             : }
    9094             : 
    9095           0 : v8::Isolate* debug::Script::GetIsolate() const {
    9096           0 :   return reinterpret_cast<v8::Isolate*>(Utils::OpenHandle(this)->GetIsolate());
    9097             : }
    9098             : 
    9099           0 : ScriptOriginOptions debug::Script::OriginOptions() const {
    9100           0 :   return Utils::OpenHandle(this)->origin_options();
    9101             : }
    9102             : 
    9103       33830 : bool debug::Script::WasCompiled() const {
    9104       67660 :   return Utils::OpenHandle(this)->compilation_state() ==
    9105       67660 :          i::Script::COMPILATION_STATE_COMPILED;
    9106             : }
    9107             : 
    9108       33727 : bool debug::Script::IsEmbedded() const {
    9109             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9110             :   return script->context_data() ==
    9111       67454 :          script->GetReadOnlyRoots().uninitialized_symbol();
    9112             : }
    9113             : 
    9114      730614 : int debug::Script::Id() const { return Utils::OpenHandle(this)->id(); }
    9115             : 
    9116       60483 : int debug::Script::LineOffset() const {
    9117       60483 :   return Utils::OpenHandle(this)->line_offset();
    9118             : }
    9119             : 
    9120       60483 : int debug::Script::ColumnOffset() const {
    9121       60483 :   return Utils::OpenHandle(this)->column_offset();
    9122             : }
    9123             : 
    9124       60483 : std::vector<int> debug::Script::LineEnds() const {
    9125             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9126      120970 :   if (script->type() == i::Script::TYPE_WASM &&
    9127       60487 :       this->SourceMappingURL().IsEmpty()) {
    9128             :     return std::vector<int>();
    9129             :   }
    9130             :   i::Isolate* isolate = script->GetIsolate();
    9131             :   i::HandleScope scope(isolate);
    9132       60483 :   i::Script::InitLineEnds(script);
    9133      120966 :   CHECK(script->line_ends()->IsFixedArray());
    9134             :   i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends()),
    9135             :                                      isolate);
    9136       60483 :   std::vector<int> result(line_ends->length());
    9137    17761390 :   for (int i = 0; i < line_ends->length(); ++i) {
    9138             :     i::Smi line_end = i::Smi::cast(line_ends->get(i));
    9139    17640424 :     result[i] = line_end->value();
    9140             :   }
    9141             :   return result;
    9142             : }
    9143             : 
    9144       58514 : MaybeLocal<String> debug::Script::Name() const {
    9145             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9146             :   i::HandleScope handle_scope(isolate);
    9147             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9148             :   i::Handle<i::Object> value(script->name(), isolate);
    9149      117028 :   if (!value->IsString()) return MaybeLocal<String>();
    9150             :   return Utils::ToLocal(
    9151       22772 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9152             : }
    9153             : 
    9154      121133 : MaybeLocal<String> debug::Script::SourceURL() const {
    9155             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9156             :   i::HandleScope handle_scope(isolate);
    9157             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9158             :   i::Handle<i::Object> value(script->source_url(), isolate);
    9159      242266 :   if (!value->IsString()) return MaybeLocal<String>();
    9160             :   return Utils::ToLocal(
    9161        4420 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9162             : }
    9163             : 
    9164       60647 : MaybeLocal<String> debug::Script::SourceMappingURL() const {
    9165             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9166             :   i::HandleScope handle_scope(isolate);
    9167             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9168             :   i::Handle<i::Object> value(script->source_mapping_url(), isolate);
    9169      121294 :   if (!value->IsString()) return MaybeLocal<String>();
    9170             :   return Utils::ToLocal(
    9171         508 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9172             : }
    9173             : 
    9174      132298 : Maybe<int> debug::Script::ContextId() const {
    9175             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9176             :   i::HandleScope handle_scope(isolate);
    9177             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9178      132298 :   i::Object value = script->context_data();
    9179      132298 :   if (value->IsSmi()) return Just(i::Smi::ToInt(value));
    9180             :   return Nothing<int>();
    9181             : }
    9182             : 
    9183      141933 : MaybeLocal<String> debug::Script::Source() const {
    9184             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9185             :   i::HandleScope handle_scope(isolate);
    9186             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9187             :   i::Handle<i::Object> value(script->source(), isolate);
    9188      283866 :   if (!value->IsString()) return MaybeLocal<String>();
    9189             :   return Utils::ToLocal(
    9190      141933 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9191             : }
    9192             : 
    9193       26930 : bool debug::Script::IsWasm() const {
    9194       26930 :   return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM;
    9195             : }
    9196             : 
    9197       60483 : bool debug::Script::IsModule() const {
    9198      120966 :   return Utils::OpenHandle(this)->origin_options().IsModule();
    9199             : }
    9200             : 
    9201             : namespace {
    9202       18307 : int GetSmiValue(i::Handle<i::FixedArray> array, int index) {
    9203       18307 :   return i::Smi::ToInt(array->get(index));
    9204             : }
    9205             : 
    9206       42940 : bool CompareBreakLocation(const i::BreakLocation& loc1,
    9207       42940 :                           const i::BreakLocation& loc2) {
    9208       42940 :   return loc1.position() < loc2.position();
    9209             : }
    9210             : }  // namespace
    9211             : 
    9212         264 : bool debug::Script::GetPossibleBreakpoints(
    9213             :     const debug::Location& start, const debug::Location& end,
    9214             :     bool restrict_to_function,
    9215             :     std::vector<debug::BreakLocation>* locations) const {
    9216         264 :   CHECK(!start.IsEmpty());
    9217             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9218         552 :   if (script->type() == i::Script::TYPE_WASM &&
    9219         288 :       this->SourceMappingURL().IsEmpty()) {
    9220             :     i::WasmModuleObject module_object =
    9221          24 :         i::WasmModuleObject::cast(script->wasm_module_object());
    9222          24 :     return module_object->GetPossibleBreakpoints(start, end, locations);
    9223             :   }
    9224             : 
    9225         240 :   i::Script::InitLineEnds(script);
    9226         480 :   CHECK(script->line_ends()->IsFixedArray());
    9227         215 :   i::Isolate* isolate = script->GetIsolate();
    9228             :   i::Handle<i::FixedArray> line_ends =
    9229         240 :       i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
    9230         240 :   CHECK(line_ends->length());
    9231             : 
    9232         240 :   int start_offset = GetSourceOffset(start);
    9233             :   int end_offset = end.IsEmpty()
    9234         155 :                        ? GetSmiValue(line_ends, line_ends->length() - 1) + 1
    9235         395 :                        : GetSourceOffset(end);
    9236         240 :   if (start_offset >= end_offset) return true;
    9237             : 
    9238             :   std::vector<i::BreakLocation> v8_locations;
    9239         215 :   if (!isolate->debug()->GetPossibleBreakpoints(
    9240             :           script, start_offset, end_offset, restrict_to_function,
    9241         430 :           &v8_locations)) {
    9242             :     return false;
    9243             :   }
    9244             : 
    9245         210 :   std::sort(v8_locations.begin(), v8_locations.end(), CompareBreakLocation);
    9246             :   int current_line_end_index = 0;
    9247        5510 :   for (const auto& v8_location : v8_locations) {
    9248             :     int offset = v8_location.position();
    9249       13345 :     while (offset > GetSmiValue(line_ends, current_line_end_index)) {
    9250        3165 :       ++current_line_end_index;
    9251        3165 :       CHECK(current_line_end_index < line_ends->length());
    9252             :     }
    9253             :     int line_offset = 0;
    9254             : 
    9255        5090 :     if (current_line_end_index > 0) {
    9256        4640 :       line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1;
    9257             :     }
    9258             :     locations->emplace_back(
    9259        5090 :         current_line_end_index + script->line_offset(),
    9260       10180 :         offset - line_offset +
    9261             :             (current_line_end_index == 0 ? script->column_offset() : 0),
    9262       15270 :         v8_location.type());
    9263             :   }
    9264             :   return true;
    9265             : }
    9266             : 
    9267        2913 : int debug::Script::GetSourceOffset(const debug::Location& location) const {
    9268             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9269        2913 :   if (script->type() == i::Script::TYPE_WASM) {
    9270         160 :     if (this->SourceMappingURL().IsEmpty()) {
    9271             :       return i::WasmModuleObject::cast(script->wasm_module_object())
    9272         228 :                  ->GetFunctionOffset(location.GetLineNumber()) +
    9273          76 :              location.GetColumnNumber();
    9274             :     }
    9275             :     DCHECK_EQ(0, location.GetLineNumber());
    9276           4 :     return location.GetColumnNumber();
    9277             :   }
    9278             : 
    9279        8499 :   int line = std::max(location.GetLineNumber() - script->line_offset(), 0);
    9280        2833 :   int column = location.GetColumnNumber();
    9281        2833 :   if (line == 0) {
    9282         788 :     column = std::max(0, column - script->column_offset());
    9283             :   }
    9284             : 
    9285        2833 :   i::Script::InitLineEnds(script);
    9286        5666 :   CHECK(script->line_ends()->IsFixedArray());
    9287             :   i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast(
    9288        2833 :       i::handle(script->line_ends(), script->GetIsolate()));
    9289        2833 :   CHECK(line_ends->length());
    9290        2833 :   if (line >= line_ends->length())
    9291          15 :     return GetSmiValue(line_ends, line_ends->length() - 1);
    9292        2818 :   int line_offset = GetSmiValue(line_ends, line);
    9293        3212 :   if (line == 0) return std::min(column, line_offset);
    9294        2424 :   int prev_line_offset = GetSmiValue(line_ends, line - 1);
    9295        4848 :   return std::min(prev_line_offset + column + 1, line_offset);
    9296             : }
    9297             : 
    9298      459851 : v8::debug::Location debug::Script::GetSourceLocation(int offset) const {
    9299      459851 :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9300             :   i::Script::PositionInfo info;
    9301      459851 :   i::Script::GetPositionInfo(script, offset, &info, i::Script::WITH_OFFSET);
    9302      459851 :   return debug::Location(info.line, info.column);
    9303             : }
    9304             : 
    9305          50 : bool debug::Script::SetScriptSource(v8::Local<v8::String> newSource,
    9306             :                                     bool preview,
    9307             :                                     debug::LiveEditResult* result) const {
    9308             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9309          50 :   i::Isolate* isolate = script->GetIsolate();
    9310             :   return isolate->debug()->SetScriptSource(
    9311         100 :       script, Utils::OpenHandle(*newSource), preview, result);
    9312             : }
    9313             : 
    9314        2128 : bool debug::Script::SetBreakpoint(v8::Local<v8::String> condition,
    9315             :                                   debug::Location* location,
    9316             :                                   debug::BreakpointId* id) const {
    9317             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9318        2128 :   i::Isolate* isolate = script->GetIsolate();
    9319        2128 :   int offset = GetSourceOffset(*location);
    9320        2128 :   if (!isolate->debug()->SetBreakPointForScript(
    9321        2128 :           script, Utils::OpenHandle(*condition), &offset, id)) {
    9322             :     return false;
    9323             :   }
    9324        2098 :   *location = GetSourceLocation(offset);
    9325        2098 :   return true;
    9326             : }
    9327             : 
    9328        2188 : void debug::RemoveBreakpoint(Isolate* v8_isolate, BreakpointId id) {
    9329        2188 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9330             :   i::HandleScope handle_scope(isolate);
    9331        2188 :   isolate->debug()->RemoveBreakpoint(id);
    9332        2188 : }
    9333             : 
    9334          30 : v8::Platform* debug::GetCurrentPlatform() {
    9335          30 :   return i::V8::GetCurrentPlatform();
    9336             : }
    9337             : 
    9338          52 : debug::WasmScript* debug::WasmScript::Cast(debug::Script* script) {
    9339          52 :   CHECK(script->IsWasm());
    9340          52 :   return static_cast<WasmScript*>(script);
    9341             : }
    9342             : 
    9343         136 : int debug::WasmScript::NumFunctions() const {
    9344             :   i::DisallowHeapAllocation no_gc;
    9345             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9346             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9347             :   i::WasmModuleObject module_object =
    9348         136 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9349             :   const i::wasm::WasmModule* module = module_object->module();
    9350             :   DCHECK_GE(i::kMaxInt, module->functions.size());
    9351         272 :   return static_cast<int>(module->functions.size());
    9352             : }
    9353             : 
    9354         136 : int debug::WasmScript::NumImportedFunctions() const {
    9355             :   i::DisallowHeapAllocation no_gc;
    9356             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9357             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9358             :   i::WasmModuleObject module_object =
    9359         136 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9360             :   const i::wasm::WasmModule* module = module_object->module();
    9361             :   DCHECK_GE(i::kMaxInt, module->num_imported_functions);
    9362         136 :   return static_cast<int>(module->num_imported_functions);
    9363             : }
    9364             : 
    9365           4 : std::pair<int, int> debug::WasmScript::GetFunctionRange(
    9366             :     int function_index) const {
    9367             :   i::DisallowHeapAllocation no_gc;
    9368             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9369             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9370             :   i::WasmModuleObject module_object =
    9371           4 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9372             :   const i::wasm::WasmModule* module = module_object->module();
    9373             :   DCHECK_LE(0, function_index);
    9374             :   DCHECK_GT(module->functions.size(), function_index);
    9375           4 :   const i::wasm::WasmFunction& func = module->functions[function_index];
    9376             :   DCHECK_GE(i::kMaxInt, func.code.offset());
    9377             :   DCHECK_GE(i::kMaxInt, func.code.end_offset());
    9378             :   return std::make_pair(static_cast<int>(func.code.offset()),
    9379           4 :                         static_cast<int>(func.code.end_offset()));
    9380             : }
    9381             : 
    9382          84 : uint32_t debug::WasmScript::GetFunctionHash(int function_index) {
    9383             :   i::DisallowHeapAllocation no_gc;
    9384             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9385             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9386             :   i::WasmModuleObject module_object =
    9387          84 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9388             :   const i::wasm::WasmModule* module = module_object->module();
    9389             :   DCHECK_LE(0, function_index);
    9390             :   DCHECK_GT(module->functions.size(), function_index);
    9391          84 :   const i::wasm::WasmFunction& func = module->functions[function_index];
    9392             :   i::wasm::ModuleWireBytes wire_bytes(
    9393          84 :       module_object->native_module()->wire_bytes());
    9394             :   i::Vector<const i::byte> function_bytes = wire_bytes.GetFunctionBytes(&func);
    9395             :   // TODO(herhut): Maybe also take module, name and signature into account.
    9396             :   return i::StringHasher::HashSequentialString(function_bytes.start(),
    9397          84 :                                                function_bytes.length(), 0);
    9398             : }
    9399             : 
    9400          76 : debug::WasmDisassembly debug::WasmScript::DisassembleFunction(
    9401             :     int function_index) const {
    9402             :   i::DisallowHeapAllocation no_gc;
    9403             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9404             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9405             :   i::WasmModuleObject module_object =
    9406          76 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9407          76 :   return module_object->DisassembleFunction(function_index);
    9408             : }
    9409             : 
    9410       28407 : debug::Location::Location(int line_number, int column_number)
    9411             :     : line_number_(line_number),
    9412             :       column_number_(column_number),
    9413       33497 :       is_empty_(false) {}
    9414             : 
    9415         274 : debug::Location::Location()
    9416             :     : line_number_(v8::Function::kLineOffsetNotFound),
    9417             :       column_number_(v8::Function::kLineOffsetNotFound),
    9418         274 :       is_empty_(true) {}
    9419             : 
    9420      475312 : int debug::Location::GetLineNumber() const {
    9421             :   DCHECK(!IsEmpty());
    9422      478221 :   return line_number_;
    9423             : }
    9424             : 
    9425      471411 : int debug::Location::GetColumnNumber() const {
    9426             :   DCHECK(!IsEmpty());
    9427      474324 :   return column_number_;
    9428             : }
    9429             : 
    9430         932 : bool debug::Location::IsEmpty() const { return is_empty_; }
    9431             : 
    9432        3472 : void debug::GetLoadedScripts(v8::Isolate* v8_isolate,
    9433             :                              PersistentValueVector<debug::Script>& scripts) {
    9434             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9435             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9436             :   {
    9437             :     i::DisallowHeapAllocation no_gc;
    9438        3472 :     i::Script::Iterator iterator(isolate);
    9439       95658 :     for (i::Script script = iterator.Next(); !script.is_null();
    9440             :          script = iterator.Next()) {
    9441       44357 :       if (!script->IsUserJavaScript()) continue;
    9442       33835 :       if (script->HasValidSource()) {
    9443             :         i::HandleScope handle_scope(isolate);
    9444             :         i::Handle<i::Script> script_handle(script, isolate);
    9445       33835 :         scripts.Append(ToApiHandle<Script>(script_handle));
    9446             :       }
    9447             :     }
    9448             :   }
    9449        3472 : }
    9450             : 
    9451         266 : MaybeLocal<UnboundScript> debug::CompileInspectorScript(Isolate* v8_isolate,
    9452             :                                                         Local<String> source) {
    9453             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9454         798 :   PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript);
    9455         266 :   i::Handle<i::String> str = Utils::OpenHandle(*source);
    9456             :   i::Handle<i::SharedFunctionInfo> result;
    9457             :   {
    9458             :     ScriptOriginOptions origin_options;
    9459             :     i::ScriptData* script_data = nullptr;
    9460             :     i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
    9461             :         i::Compiler::GetSharedFunctionInfoForScript(
    9462             :             isolate, str, i::Compiler::ScriptDetails(), origin_options, nullptr,
    9463             :             script_data, ScriptCompiler::kNoCompileOptions,
    9464             :             ScriptCompiler::kNoCacheBecauseInspector,
    9465             :             i::FLAG_expose_inspector_scripts ? i::NOT_NATIVES_CODE
    9466         532 :                                              : i::INSPECTOR_CODE);
    9467             :     has_pending_exception = !maybe_function_info.ToHandle(&result);
    9468         266 :     RETURN_ON_FAILED_EXECUTION(UnboundScript);
    9469             :   }
    9470         266 :   RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
    9471             : }
    9472             : 
    9473        7833 : void debug::SetDebugDelegate(Isolate* v8_isolate,
    9474             :                              debug::DebugDelegate* delegate) {
    9475        7833 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9476        7833 :   isolate->debug()->SetDebugDelegate(delegate);
    9477        7833 : }
    9478             : 
    9479         460 : void debug::SetAsyncEventDelegate(Isolate* v8_isolate,
    9480             :                                   debug::AsyncEventDelegate* delegate) {
    9481             :   reinterpret_cast<i::Isolate*>(v8_isolate)->set_async_event_delegate(delegate);
    9482         460 : }
    9483             : 
    9484      120761 : void debug::ResetBlackboxedStateCache(Isolate* v8_isolate,
    9485             :                                       v8::Local<debug::Script> script) {
    9486             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9487             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9488             :   i::DisallowHeapAllocation no_gc;
    9489             :   i::SharedFunctionInfo::ScriptIterator iter(isolate,
    9490      120761 :                                              *Utils::OpenHandle(*script));
    9491     2555360 :   for (i::SharedFunctionInfo info = iter.Next(); !info.is_null();
    9492             :        info = iter.Next()) {
    9493     1156919 :     if (info->HasDebugInfo()) {
    9494       18410 :       info->GetDebugInfo()->set_computed_debug_is_blackboxed(false);
    9495             :     }
    9496             :   }
    9497      120761 : }
    9498             : 
    9499        7020 : int debug::EstimatedValueSize(Isolate* v8_isolate, v8::Local<v8::Value> value) {
    9500             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9501             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9502             :   i::Handle<i::Object> object = Utils::OpenHandle(*value);
    9503       14040 :   if (object->IsSmi()) return i::kTaggedSize;
    9504       12560 :   CHECK(object->IsHeapObject());
    9505       12560 :   return i::Handle<i::HeapObject>::cast(object)->Size();
    9506             : }
    9507             : 
    9508       90113 : v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) {
    9509       90113 :   if (IsMap()) {
    9510         108 :     *is_key_value = true;
    9511         108 :     return Map::Cast(this)->AsArray();
    9512             :   }
    9513       90005 :   if (IsSet()) {
    9514          89 :     *is_key_value = false;
    9515          89 :     return Set::Cast(this)->AsArray();
    9516             :   }
    9517             : 
    9518             :   i::Handle<i::JSReceiver> object = Utils::OpenHandle(this);
    9519             :   i::Isolate* isolate = object->GetIsolate();
    9520             :   Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
    9521             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9522      179832 :   if (object->IsJSWeakCollection()) {
    9523         196 :     *is_key_value = object->IsJSWeakMap();
    9524             :     return Utils::ToLocal(i::JSWeakCollection::GetEntries(
    9525          98 :         i::Handle<i::JSWeakCollection>::cast(object), 0));
    9526             :   }
    9527      179636 :   if (object->IsJSMapIterator()) {
    9528         157 :     i::Handle<i::JSMapIterator> it = i::Handle<i::JSMapIterator>::cast(object);
    9529             :     MapAsArrayKind const kind =
    9530         157 :         static_cast<MapAsArrayKind>(it->map()->instance_type());
    9531         157 :     *is_key_value = kind == MapAsArrayKind::kEntries;
    9532         157 :     if (!it->HasMore()) return v8::Array::New(v8_isolate);
    9533             :     return Utils::ToLocal(
    9534         244 :         MapAsArray(isolate, it->table(), i::Smi::ToInt(it->index()), kind));
    9535             :   }
    9536      179322 :   if (object->IsJSSetIterator()) {
    9537         142 :     i::Handle<i::JSSetIterator> it = i::Handle<i::JSSetIterator>::cast(object);
    9538             :     SetAsArrayKind const kind =
    9539         142 :         static_cast<SetAsArrayKind>(it->map()->instance_type());
    9540         142 :     *is_key_value = kind == SetAsArrayKind::kEntries;
    9541         142 :     if (!it->HasMore()) return v8::Array::New(v8_isolate);
    9542             :     return Utils::ToLocal(
    9543         254 :         SetAsArray(isolate, it->table(), i::Smi::ToInt(it->index()), kind));
    9544             :   }
    9545       89519 :   return v8::MaybeLocal<v8::Array>();
    9546             : }
    9547             : 
    9548           0 : Local<Function> debug::GetBuiltin(Isolate* v8_isolate, Builtin builtin) {
    9549             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9550             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9551             :   i::HandleScope handle_scope(isolate);
    9552             :   i::Builtins::Name builtin_id;
    9553           0 :   switch (builtin) {
    9554             :     case kStringToLowerCase:
    9555             :       builtin_id = i::Builtins::kStringPrototypeToLocaleLowerCase;
    9556             :       break;
    9557             :     default:
    9558           0 :       UNREACHABLE();
    9559             :   }
    9560             : 
    9561           0 :   i::Handle<i::String> name = isolate->factory()->empty_string();
    9562             :   i::NewFunctionArgs args = i::NewFunctionArgs::ForBuiltinWithoutPrototype(
    9563           0 :       name, builtin_id, i::LanguageMode::kStrict);
    9564           0 :   i::Handle<i::JSFunction> fun = isolate->factory()->NewFunction(args);
    9565             : 
    9566           0 :   fun->shared()->set_internal_formal_parameter_count(0);
    9567           0 :   fun->shared()->set_length(0);
    9568           0 :   return Utils::ToLocal(handle_scope.CloseAndEscape(fun));
    9569             : }
    9570             : 
    9571       37477 : void debug::SetConsoleDelegate(Isolate* v8_isolate, ConsoleDelegate* delegate) {
    9572             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9573             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9574             :   isolate->set_console_delegate(delegate);
    9575       37477 : }
    9576             : 
    9577         425 : debug::ConsoleCallArguments::ConsoleCallArguments(
    9578             :     const v8::FunctionCallbackInfo<v8::Value>& info)
    9579         425 :     : v8::FunctionCallbackInfo<v8::Value>(nullptr, info.values_, info.length_) {
    9580         425 : }
    9581             : 
    9582       12511 : debug::ConsoleCallArguments::ConsoleCallArguments(
    9583             :     internal::BuiltinArguments& args)
    9584             :     : v8::FunctionCallbackInfo<v8::Value>(
    9585             :           nullptr,
    9586             :           // Drop the first argument (receiver, i.e. the "console" object).
    9587             :           args.address_of_arg_at(args.length() > 1 ? 1 : 0),
    9588       25022 :           args.length() - 1) {}
    9589             : 
    9590        6025 : int debug::GetStackFrameId(v8::Local<v8::StackFrame> frame) {
    9591        6025 :   return Utils::OpenHandle(*frame)->id();
    9592             : }
    9593             : 
    9594          15 : v8::Local<v8::StackTrace> debug::GetDetailedStackTrace(
    9595             :     Isolate* v8_isolate, v8::Local<v8::Object> v8_error) {
    9596             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9597             :   i::Handle<i::JSReceiver> error = Utils::OpenHandle(*v8_error);
    9598          30 :   if (!error->IsJSObject()) {
    9599           0 :     return v8::Local<v8::StackTrace>();
    9600             :   }
    9601             :   i::Handle<i::FixedArray> stack_trace =
    9602          15 :       isolate->GetDetailedStackTrace(i::Handle<i::JSObject>::cast(error));
    9603             :   return Utils::StackTraceToLocal(stack_trace);
    9604             : }
    9605             : 
    9606          40 : MaybeLocal<debug::Script> debug::GeneratorObject::Script() {
    9607             :   i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
    9608          40 :   i::Object maybe_script = obj->function()->shared()->script();
    9609          40 :   if (!maybe_script->IsScript()) return MaybeLocal<debug::Script>();
    9610             :   i::Handle<i::Script> script(i::Script::cast(maybe_script), obj->GetIsolate());
    9611          40 :   return ToApiHandle<debug::Script>(script);
    9612             : }
    9613             : 
    9614          10 : Local<Function> debug::GeneratorObject::Function() {
    9615             :   i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
    9616          20 :   return Utils::ToLocal(handle(obj->function(), obj->GetIsolate()));
    9617             : }
    9618             : 
    9619          40 : debug::Location debug::GeneratorObject::SuspendedLocation() {
    9620             :   i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
    9621          40 :   CHECK(obj->is_suspended());
    9622          40 :   i::Object maybe_script = obj->function()->shared()->script();
    9623          40 :   if (!maybe_script->IsScript()) return debug::Location();
    9624             :   i::Isolate* isolate = obj->GetIsolate();
    9625             :   i::Handle<i::Script> script(i::Script::cast(maybe_script), isolate);
    9626             :   i::Script::PositionInfo info;
    9627             :   i::SharedFunctionInfo::EnsureSourcePositionsAvailable(
    9628          80 :       isolate, i::handle(obj->function()->shared(), isolate));
    9629             :   i::Script::GetPositionInfo(script, obj->source_position(), &info,
    9630          40 :                              i::Script::WITH_OFFSET);
    9631          40 :   return debug::Location(info.line, info.column);
    9632             : }
    9633             : 
    9634         100 : bool debug::GeneratorObject::IsSuspended() {
    9635         100 :   return Utils::OpenHandle(this)->is_suspended();
    9636             : }
    9637             : 
    9638         100 : v8::Local<debug::GeneratorObject> debug::GeneratorObject::Cast(
    9639             :     v8::Local<v8::Value> value) {
    9640         100 :   CHECK(value->IsGeneratorObject());
    9641         100 :   return ToApiHandle<debug::GeneratorObject>(Utils::OpenHandle(*value));
    9642             : }
    9643             : 
    9644        8804 : MaybeLocal<v8::Value> debug::EvaluateGlobal(v8::Isolate* isolate,
    9645             :                                             v8::Local<v8::String> source,
    9646             :                                             bool throw_on_side_effect) {
    9647             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9648       26412 :   PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(internal_isolate, Value);
    9649             :   Local<Value> result;
    9650             :   has_pending_exception = !ToLocal<Value>(
    9651             :       i::DebugEvaluate::Global(internal_isolate, Utils::OpenHandle(*source),
    9652             :                                throw_on_side_effect),
    9653       17608 :       &result);
    9654        8804 :   RETURN_ON_FAILED_EXECUTION(Value);
    9655        8255 :   RETURN_ESCAPED(result);
    9656             : }
    9657             : 
    9658          85 : void debug::QueryObjects(v8::Local<v8::Context> v8_context,
    9659             :                          QueryObjectPredicate* predicate,
    9660             :                          PersistentValueVector<v8::Object>* objects) {
    9661         170 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate());
    9662             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9663             :   isolate->heap_profiler()->QueryObjects(Utils::OpenHandle(*v8_context),
    9664          85 :                                          predicate, objects);
    9665          85 : }
    9666             : 
    9667          35 : void debug::GlobalLexicalScopeNames(
    9668             :     v8::Local<v8::Context> v8_context,
    9669             :     v8::PersistentValueVector<v8::String>* names) {
    9670             :   i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
    9671             :   i::Isolate* isolate = context->GetIsolate();
    9672             :   i::Handle<i::ScriptContextTable> table(
    9673          70 :       context->global_object()->native_context()->script_context_table(),
    9674          35 :       isolate);
    9675         340 :   for (int i = 0; i < table->used(); i++) {
    9676             :     i::Handle<i::Context> context =
    9677         135 :         i::ScriptContextTable::GetContext(isolate, table, i);
    9678             :     DCHECK(context->IsScriptContext());
    9679         270 :     i::Handle<i::ScopeInfo> scope_info(context->scope_info(), isolate);
    9680         135 :     int local_count = scope_info->ContextLocalCount();
    9681         285 :     for (int j = 0; j < local_count; ++j) {
    9682         150 :       i::String name = scope_info->ContextLocalName(j);
    9683         185 :       if (i::ScopeInfo::VariableIsSynthetic(name)) continue;
    9684         115 :       names->Append(Utils::ToLocal(handle(name, isolate)));
    9685             :     }
    9686             :   }
    9687          35 : }
    9688             : 
    9689          10 : void debug::SetReturnValue(v8::Isolate* v8_isolate,
    9690             :                            v8::Local<v8::Value> value) {
    9691          10 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9692             :   isolate->debug()->set_return_value(*Utils::OpenHandle(*value));
    9693          10 : }
    9694             : 
    9695       10198 : int64_t debug::GetNextRandomInt64(v8::Isolate* v8_isolate) {
    9696             :   return reinterpret_cast<i::Isolate*>(v8_isolate)
    9697             :       ->random_number_generator()
    9698       10198 :       ->NextInt64();
    9699             : }
    9700             : 
    9701         170 : int debug::GetDebuggingId(v8::Local<v8::Function> function) {
    9702             :   i::Handle<i::JSReceiver> callable = v8::Utils::OpenHandle(*function);
    9703         340 :   if (!callable->IsJSFunction()) return i::DebugInfo::kNoDebuggingId;
    9704         170 :   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(callable);
    9705         170 :   int id = func->GetIsolate()->debug()->GetFunctionDebuggingId(func);
    9706             :   DCHECK_NE(i::DebugInfo::kNoDebuggingId, id);
    9707         170 :   return id;
    9708             : }
    9709             : 
    9710          95 : bool debug::SetFunctionBreakpoint(v8::Local<v8::Function> function,
    9711             :                                   v8::Local<v8::String> condition,
    9712             :                                   BreakpointId* id) {
    9713             :   i::Handle<i::JSReceiver> callable = Utils::OpenHandle(*function);
    9714         190 :   if (!callable->IsJSFunction()) return false;
    9715             :   i::Handle<i::JSFunction> jsfunction =
    9716          95 :       i::Handle<i::JSFunction>::cast(callable);
    9717          95 :   i::Isolate* isolate = jsfunction->GetIsolate();
    9718             :   i::Handle<i::String> condition_string =
    9719             :       condition.IsEmpty() ? isolate->factory()->empty_string()
    9720         140 :                           : Utils::OpenHandle(*condition);
    9721             :   return isolate->debug()->SetBreakpointForFunction(jsfunction,
    9722          95 :                                                     condition_string, id);
    9723             : }
    9724             : 
    9725           0 : debug::PostponeInterruptsScope::PostponeInterruptsScope(v8::Isolate* isolate)
    9726             :     : scope_(
    9727             :           new i::PostponeInterruptsScope(reinterpret_cast<i::Isolate*>(isolate),
    9728           0 :                                          i::StackGuard::API_INTERRUPT)) {}
    9729             : 
    9730             : debug::PostponeInterruptsScope::~PostponeInterruptsScope() = default;
    9731             : 
    9732         367 : Local<String> CpuProfileNode::GetFunctionName() const {
    9733         734 :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9734             :   i::Isolate* isolate = node->isolate();
    9735         367 :   const i::CodeEntry* entry = node->entry();
    9736             :   i::Handle<i::String> name =
    9737         367 :       isolate->factory()->InternalizeUtf8String(entry->name());
    9738         367 :   return ToApiHandle<String>(name);
    9739             : }
    9740             : 
    9741          32 : int debug::Coverage::BlockData::StartOffset() const { return block_->start; }
    9742          32 : int debug::Coverage::BlockData::EndOffset() const { return block_->end; }
    9743          32 : uint32_t debug::Coverage::BlockData::Count() const { return block_->count; }
    9744             : 
    9745         420 : int debug::Coverage::FunctionData::StartOffset() const {
    9746         420 :   return function_->start;
    9747             : }
    9748         420 : int debug::Coverage::FunctionData::EndOffset() const { return function_->end; }
    9749         410 : uint32_t debug::Coverage::FunctionData::Count() const {
    9750         410 :   return function_->count;
    9751             : }
    9752             : 
    9753         380 : MaybeLocal<String> debug::Coverage::FunctionData::Name() const {
    9754         380 :   return ToApiHandle<String>(function_->name);
    9755             : }
    9756             : 
    9757         412 : size_t debug::Coverage::FunctionData::BlockCount() const {
    9758         824 :   return function_->blocks.size();
    9759             : }
    9760             : 
    9761         380 : bool debug::Coverage::FunctionData::HasBlockCoverage() const {
    9762         380 :   return function_->has_block_coverage;
    9763             : }
    9764             : 
    9765          32 : debug::Coverage::BlockData debug::Coverage::FunctionData::GetBlockData(
    9766             :     size_t i) const {
    9767          64 :   return BlockData(&function_->blocks.at(i), coverage_);
    9768             : }
    9769             : 
    9770         170 : Local<debug::Script> debug::Coverage::ScriptData::GetScript() const {
    9771         170 :   return ToApiHandle<debug::Script>(script_->script);
    9772             : }
    9773             : 
    9774         555 : size_t debug::Coverage::ScriptData::FunctionCount() const {
    9775        1110 :   return script_->functions.size();
    9776             : }
    9777             : 
    9778         405 : debug::Coverage::FunctionData debug::Coverage::ScriptData::GetFunctionData(
    9779             :     size_t i) const {
    9780         810 :   return FunctionData(&script_->functions.at(i), coverage_);
    9781             : }
    9782             : 
    9783         175 : debug::Coverage::ScriptData::ScriptData(size_t index,
    9784             :                                         std::shared_ptr<i::Coverage> coverage)
    9785         525 :     : script_(&coverage->at(index)), coverage_(std::move(coverage)) {}
    9786             : 
    9787         622 : size_t debug::Coverage::ScriptCount() const { return coverage_->size(); }
    9788             : 
    9789         175 : debug::Coverage::ScriptData debug::Coverage::GetScriptData(size_t i) const {
    9790         350 :   return ScriptData(i, coverage_);
    9791             : }
    9792             : 
    9793         103 : debug::Coverage debug::Coverage::CollectPrecise(Isolate* isolate) {
    9794             :   return Coverage(
    9795         309 :       i::Coverage::CollectPrecise(reinterpret_cast<i::Isolate*>(isolate)));
    9796             : }
    9797             : 
    9798          48 : debug::Coverage debug::Coverage::CollectBestEffort(Isolate* isolate) {
    9799             :   return Coverage(
    9800         144 :       i::Coverage::CollectBestEffort(reinterpret_cast<i::Isolate*>(isolate)));
    9801             : }
    9802             : 
    9803         305 : void debug::Coverage::SelectMode(Isolate* isolate, debug::Coverage::Mode mode) {
    9804         305 :   i::Coverage::SelectMode(reinterpret_cast<i::Isolate*>(isolate), mode);
    9805         305 : }
    9806             : 
    9807         148 : int debug::TypeProfile::Entry::SourcePosition() const {
    9808         148 :   return entry_->position;
    9809             : }
    9810             : 
    9811         148 : std::vector<MaybeLocal<String>> debug::TypeProfile::Entry::Types() const {
    9812             :   std::vector<MaybeLocal<String>> result;
    9813         492 :   for (const internal::Handle<internal::String>& type : entry_->types) {
    9814         196 :     result.emplace_back(ToApiHandle<String>(type));
    9815             :   }
    9816         148 :   return result;
    9817             : }
    9818             : 
    9819          32 : debug::TypeProfile::ScriptData::ScriptData(
    9820             :     size_t index, std::shared_ptr<i::TypeProfile> type_profile)
    9821          32 :     : script_(&type_profile->at(index)),
    9822          64 :       type_profile_(std::move(type_profile)) {}
    9823             : 
    9824          32 : Local<debug::Script> debug::TypeProfile::ScriptData::GetScript() const {
    9825          32 :   return ToApiHandle<debug::Script>(script_->script);
    9826             : }
    9827             : 
    9828          32 : std::vector<debug::TypeProfile::Entry> debug::TypeProfile::ScriptData::Entries()
    9829             :     const {
    9830             :   std::vector<debug::TypeProfile::Entry> result;
    9831         244 :   for (const internal::TypeProfileEntry& entry : script_->entries) {
    9832         148 :     result.push_back(debug::TypeProfile::Entry(&entry, type_profile_));
    9833             :   }
    9834          32 :   return result;
    9835             : }
    9836             : 
    9837          40 : debug::TypeProfile debug::TypeProfile::Collect(Isolate* isolate) {
    9838             :   return TypeProfile(
    9839         120 :       i::TypeProfile::Collect(reinterpret_cast<i::Isolate*>(isolate)));
    9840             : }
    9841             : 
    9842         100 : void debug::TypeProfile::SelectMode(Isolate* isolate,
    9843             :                                     debug::TypeProfile::Mode mode) {
    9844         100 :   i::TypeProfile::SelectMode(reinterpret_cast<i::Isolate*>(isolate), mode);
    9845         100 : }
    9846             : 
    9847         144 : size_t debug::TypeProfile::ScriptCount() const { return type_profile_->size(); }
    9848             : 
    9849          32 : debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData(
    9850             :     size_t i) const {
    9851          64 :   return ScriptData(i, type_profile_);
    9852             : }
    9853             : 
    9854        2396 : v8::MaybeLocal<v8::Value> debug::WeakMap::Get(v8::Local<v8::Context> context,
    9855             :                                               v8::Local<v8::Value> key) {
    9856        9584 :   PREPARE_FOR_EXECUTION(context, WeakMap, Get, Value);
    9857             :   auto self = Utils::OpenHandle(this);
    9858             :   Local<Value> result;
    9859        2396 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    9860             :   has_pending_exception =
    9861             :       !ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(), self,
    9862             :                                          arraysize(argv), argv),
    9863        7188 :                       &result);
    9864        2396 :   RETURN_ON_FAILED_EXECUTION(Value);
    9865        2396 :   RETURN_ESCAPED(result);
    9866             : }
    9867             : 
    9868       10832 : v8::MaybeLocal<debug::WeakMap> debug::WeakMap::Set(
    9869             :     v8::Local<v8::Context> context, v8::Local<v8::Value> key,
    9870             :     v8::Local<v8::Value> value) {
    9871       43328 :   PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap);
    9872             :   auto self = Utils::OpenHandle(this);
    9873             :   i::Handle<i::Object> result;
    9874             :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
    9875       21664 :                                  Utils::OpenHandle(*value)};
    9876             :   has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(),
    9877       21664 :                                               self, arraysize(argv), argv)
    9878       21664 :                                .ToHandle(&result);
    9879       10832 :   RETURN_ON_FAILED_EXECUTION(WeakMap);
    9880       10832 :   RETURN_ESCAPED(Local<WeakMap>::Cast(Utils::ToLocal(result)));
    9881             : }
    9882             : 
    9883          64 : Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) {
    9884          64 :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9885         128 :   LOG_API(i_isolate, WeakMap, New);
    9886             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    9887          64 :   i::Handle<i::JSWeakMap> obj = i_isolate->factory()->NewJSWeakMap();
    9888          64 :   return ToApiHandle<debug::WeakMap>(obj);
    9889             : }
    9890             : 
    9891             : debug::WeakMap* debug::WeakMap::Cast(v8::Value* value) {
    9892             :   return static_cast<debug::WeakMap*>(value);
    9893             : }
    9894             : 
    9895         167 : const char* CpuProfileNode::GetFunctionNameStr() const {
    9896         167 :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9897         167 :   return node->entry()->name();
    9898             : }
    9899             : 
    9900         143 : int CpuProfileNode::GetScriptId() const {
    9901         143 :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9902         143 :   const i::CodeEntry* entry = node->entry();
    9903         143 :   return entry->script_id();
    9904             : }
    9905             : 
    9906         133 : Local<String> CpuProfileNode::GetScriptResourceName() const {
    9907         266 :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9908             :   i::Isolate* isolate = node->isolate();
    9909             :   return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
    9910         133 :       node->entry()->resource_name()));
    9911             : }
    9912             : 
    9913          29 : const char* CpuProfileNode::GetScriptResourceNameStr() const {
    9914          29 :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9915          29 :   return node->entry()->resource_name();
    9916             : }
    9917             : 
    9918         263 : int CpuProfileNode::GetLineNumber() const {
    9919         263 :   return reinterpret_cast<const i::ProfileNode*>(this)->line_number();
    9920             : }
    9921             : 
    9922             : 
    9923         133 : int CpuProfileNode::GetColumnNumber() const {
    9924             :   return reinterpret_cast<const i::ProfileNode*>(this)->
    9925         133 :       entry()->column_number();
    9926             : }
    9927             : 
    9928             : 
    9929         104 : unsigned int CpuProfileNode::GetHitLineCount() const {
    9930             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9931         104 :   return node->GetHitLineCount();
    9932             : }
    9933             : 
    9934             : 
    9935           4 : bool CpuProfileNode::GetLineTicks(LineTick* entries,
    9936             :                                   unsigned int length) const {
    9937             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9938           4 :   return node->GetLineTicks(entries, length);
    9939             : }
    9940             : 
    9941             : 
    9942         109 : const char* CpuProfileNode::GetBailoutReason() const {
    9943         109 :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9944         109 :   return node->entry()->bailout_reason();
    9945             : }
    9946             : 
    9947             : 
    9948         114 : unsigned CpuProfileNode::GetHitCount() const {
    9949         114 :   return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
    9950             : }
    9951             : 
    9952             : 
    9953           0 : unsigned CpuProfileNode::GetCallUid() const {
    9954           0 :   return reinterpret_cast<const i::ProfileNode*>(this)->function_id();
    9955             : }
    9956             : 
    9957             : 
    9958         208 : unsigned CpuProfileNode::GetNodeId() const {
    9959         208 :   return reinterpret_cast<const i::ProfileNode*>(this)->id();
    9960             : }
    9961             : 
    9962             : 
    9963         502 : int CpuProfileNode::GetChildrenCount() const {
    9964             :   return static_cast<int>(
    9965        1004 :       reinterpret_cast<const i::ProfileNode*>(this)->children()->size());
    9966             : }
    9967             : 
    9968             : 
    9969         490 : const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
    9970             :   const i::ProfileNode* child =
    9971         980 :       reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index);
    9972         490 :   return reinterpret_cast<const CpuProfileNode*>(child);
    9973             : }
    9974             : 
    9975             : 
    9976           0 : const std::vector<CpuProfileDeoptInfo>& CpuProfileNode::GetDeoptInfos() const {
    9977             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9978           0 :   return node->deopt_infos();
    9979             : }
    9980             : 
    9981             : 
    9982         630 : void CpuProfile::Delete() {
    9983         630 :   i::CpuProfile* profile = reinterpret_cast<i::CpuProfile*>(this);
    9984             :   i::CpuProfiler* profiler = profile->cpu_profiler();
    9985             :   DCHECK_NOT_NULL(profiler);
    9986         630 :   profiler->DeleteProfile(profile);
    9987         630 : }
    9988             : 
    9989             : 
    9990           0 : Local<String> CpuProfile::GetTitle() const {
    9991           0 :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
    9992           0 :   i::Isolate* isolate = profile->top_down()->isolate();
    9993             :   return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
    9994           0 :       profile->title()));
    9995             : }
    9996             : 
    9997             : 
    9998         116 : const CpuProfileNode* CpuProfile::GetTopDownRoot() const {
    9999             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10000         116 :   return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
   10001             : }
   10002             : 
   10003             : 
   10004          45 : const CpuProfileNode* CpuProfile::GetSample(int index) const {
   10005             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10006          45 :   return reinterpret_cast<const CpuProfileNode*>(profile->sample(index).node);
   10007             : }
   10008             : 
   10009             : 
   10010          45 : int64_t CpuProfile::GetSampleTimestamp(int index) const {
   10011             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10012          90 :   return (profile->sample(index).timestamp - base::TimeTicks())
   10013          90 :       .InMicroseconds();
   10014             : }
   10015             : 
   10016             : 
   10017          95 : int64_t CpuProfile::GetStartTime() const {
   10018             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10019          95 :   return (profile->start_time() - base::TimeTicks()).InMicroseconds();
   10020             : }
   10021             : 
   10022             : 
   10023          50 : int64_t CpuProfile::GetEndTime() const {
   10024             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10025          50 :   return (profile->end_time() - base::TimeTicks()).InMicroseconds();
   10026             : }
   10027             : 
   10028             : 
   10029          95 : int CpuProfile::GetSamplesCount() const {
   10030          95 :   return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
   10031             : }
   10032             : 
   10033         158 : CpuProfiler* CpuProfiler::New(Isolate* isolate) {
   10034             :   return reinterpret_cast<CpuProfiler*>(
   10035         158 :       new i::CpuProfiler(reinterpret_cast<i::Isolate*>(isolate)));
   10036             : }
   10037             : 
   10038         158 : void CpuProfiler::Dispose() { delete reinterpret_cast<i::CpuProfiler*>(this); }
   10039             : 
   10040             : // static
   10041           5 : void CpuProfiler::CollectSample(Isolate* isolate) {
   10042           5 :   i::CpuProfiler::CollectSample(reinterpret_cast<i::Isolate*>(isolate));
   10043           5 : }
   10044             : 
   10045         535 : void CpuProfiler::SetSamplingInterval(int us) {
   10046             :   DCHECK_GE(us, 0);
   10047             :   return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
   10048         535 :       base::TimeDelta::FromMicroseconds(us));
   10049             : }
   10050             : 
   10051           0 : void CpuProfiler::CollectSample() {
   10052           0 :   reinterpret_cast<i::CpuProfiler*>(this)->CollectSample();
   10053           0 : }
   10054             : 
   10055         163 : void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
   10056             :   reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
   10057         326 :       *Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers);
   10058         163 : }
   10059             : 
   10060         540 : void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
   10061             :                                  bool record_samples) {
   10062             :   reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
   10063        1080 :       *Utils::OpenHandle(*title), record_samples, mode);
   10064         540 : }
   10065             : 
   10066         668 : CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
   10067             :   return reinterpret_cast<CpuProfile*>(
   10068             :       reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
   10069         668 :           *Utils::OpenHandle(*title)));
   10070             : }
   10071             : 
   10072             : 
   10073           0 : void CpuProfiler::SetIdle(bool is_idle) {
   10074           0 :   i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(this);
   10075             :   i::Isolate* isolate = profiler->isolate();
   10076           0 :   isolate->SetIdle(is_idle);
   10077           0 : }
   10078             : 
   10079          10 : void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
   10080             :   reinterpret_cast<i::Isolate*>(isolate)
   10081             :       ->set_detailed_source_positions_for_profiling(true);
   10082          10 : }
   10083             : 
   10084           0 : uintptr_t CodeEvent::GetCodeStartAddress() {
   10085           0 :   return reinterpret_cast<i::CodeEvent*>(this)->code_start_address;
   10086             : }
   10087             : 
   10088           0 : size_t CodeEvent::GetCodeSize() {
   10089           0 :   return reinterpret_cast<i::CodeEvent*>(this)->code_size;
   10090             : }
   10091             : 
   10092         120 : Local<String> CodeEvent::GetFunctionName() {
   10093             :   return ToApiHandle<String>(
   10094         120 :       reinterpret_cast<i::CodeEvent*>(this)->function_name);
   10095             : }
   10096             : 
   10097           0 : Local<String> CodeEvent::GetScriptName() {
   10098             :   return ToApiHandle<String>(
   10099           0 :       reinterpret_cast<i::CodeEvent*>(this)->script_name);
   10100             : }
   10101             : 
   10102           0 : int CodeEvent::GetScriptLine() {
   10103           0 :   return reinterpret_cast<i::CodeEvent*>(this)->script_line;
   10104             : }
   10105             : 
   10106           0 : int CodeEvent::GetScriptColumn() {
   10107           0 :   return reinterpret_cast<i::CodeEvent*>(this)->script_column;
   10108             : }
   10109             : 
   10110       20746 : CodeEventType CodeEvent::GetCodeType() {
   10111       20746 :   return reinterpret_cast<i::CodeEvent*>(this)->code_type;
   10112             : }
   10113             : 
   10114       20746 : const char* CodeEvent::GetComment() {
   10115       20746 :   return reinterpret_cast<i::CodeEvent*>(this)->comment;
   10116             : }
   10117             : 
   10118       20746 : const char* CodeEvent::GetCodeEventTypeName(CodeEventType code_event_type) {
   10119       20746 :   switch (code_event_type) {
   10120             :     case kUnknownType:
   10121             :       return "Unknown";
   10122             : #define V(Name)       \
   10123             :   case k##Name##Type: \
   10124             :     return #Name;
   10125       20620 :       CODE_EVENTS_LIST(V)
   10126             : #undef V
   10127             :   }
   10128             :   // The execution should never pass here
   10129           0 :   UNREACHABLE();
   10130             :   // NOTE(mmarchini): Workaround to fix a compiler failure on GCC 4.9
   10131             :   return "Unknown";
   10132             : }
   10133             : 
   10134          20 : CodeEventHandler::CodeEventHandler(Isolate* isolate) {
   10135             :   internal_listener_ =
   10136          20 :       new i::ExternalCodeEventListener(reinterpret_cast<i::Isolate*>(isolate));
   10137          20 : }
   10138             : 
   10139          20 : CodeEventHandler::~CodeEventHandler() {
   10140          20 :   delete reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_);
   10141          20 : }
   10142             : 
   10143          20 : void CodeEventHandler::Enable() {
   10144             :   reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_)
   10145          20 :       ->StartListening(this);
   10146          20 : }
   10147             : 
   10148           0 : void CodeEventHandler::Disable() {
   10149             :   reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_)
   10150           0 :       ->StopListening();
   10151           0 : }
   10152             : 
   10153             : static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
   10154             :   return const_cast<i::HeapGraphEdge*>(
   10155             :       reinterpret_cast<const i::HeapGraphEdge*>(edge));
   10156             : }
   10157             : 
   10158             : 
   10159     6056755 : HeapGraphEdge::Type HeapGraphEdge::GetType() const {
   10160    12113510 :   return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
   10161             : }
   10162             : 
   10163             : 
   10164     6007730 : Local<Value> HeapGraphEdge::GetName() const {
   10165    18023190 :   i::HeapGraphEdge* edge = ToInternal(this);
   10166             :   i::Isolate* isolate = edge->isolate();
   10167     6007730 :   switch (edge->type()) {
   10168             :     case i::HeapGraphEdge::kContextVariable:
   10169             :     case i::HeapGraphEdge::kInternal:
   10170             :     case i::HeapGraphEdge::kProperty:
   10171             :     case i::HeapGraphEdge::kShortcut:
   10172             :     case i::HeapGraphEdge::kWeak:
   10173             :       return ToApiHandle<String>(
   10174     6007481 :           isolate->factory()->InternalizeUtf8String(edge->name()));
   10175             :     case i::HeapGraphEdge::kElement:
   10176             :     case i::HeapGraphEdge::kHidden:
   10177             :       return ToApiHandle<Number>(
   10178         249 :           isolate->factory()->NewNumberFromInt(edge->index()));
   10179           0 :     default: UNREACHABLE();
   10180             :   }
   10181             :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
   10182             : }
   10183             : 
   10184             : 
   10185         339 : const HeapGraphNode* HeapGraphEdge::GetFromNode() const {
   10186             :   const i::HeapEntry* from = ToInternal(this)->from();
   10187         339 :   return reinterpret_cast<const HeapGraphNode*>(from);
   10188             : }
   10189             : 
   10190             : 
   10191      654268 : const HeapGraphNode* HeapGraphEdge::GetToNode() const {
   10192      654268 :   const i::HeapEntry* to = ToInternal(this)->to();
   10193      654268 :   return reinterpret_cast<const HeapGraphNode*>(to);
   10194             : }
   10195             : 
   10196             : 
   10197             : static i::HeapEntry* ToInternal(const HeapGraphNode* entry) {
   10198             :   return const_cast<i::HeapEntry*>(
   10199             :       reinterpret_cast<const i::HeapEntry*>(entry));
   10200             : }
   10201             : 
   10202             : 
   10203         370 : HeapGraphNode::Type HeapGraphNode::GetType() const {
   10204         370 :   return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
   10205             : }
   10206             : 
   10207             : 
   10208        1125 : Local<String> HeapGraphNode::GetName() const {
   10209        1125 :   i::Isolate* isolate = ToInternal(this)->isolate();
   10210             :   return ToApiHandle<String>(
   10211        1125 :       isolate->factory()->InternalizeUtf8String(ToInternal(this)->name()));
   10212             : }
   10213             : 
   10214             : 
   10215      551146 : SnapshotObjectId HeapGraphNode::GetId() const {
   10216      551146 :   return ToInternal(this)->id();
   10217             : }
   10218             : 
   10219             : 
   10220          20 : size_t HeapGraphNode::GetShallowSize() const {
   10221          20 :   return ToInternal(this)->self_size();
   10222             : }
   10223             : 
   10224             : 
   10225       60474 : int HeapGraphNode::GetChildrenCount() const {
   10226       60474 :   return ToInternal(this)->children_count();
   10227             : }
   10228             : 
   10229             : 
   10230     6340287 : const HeapGraphEdge* HeapGraphNode::GetChild(int index) const {
   10231     6340287 :   return reinterpret_cast<const HeapGraphEdge*>(ToInternal(this)->child(index));
   10232             : }
   10233             : 
   10234             : 
   10235             : static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
   10236             :   return const_cast<i::HeapSnapshot*>(
   10237             :       reinterpret_cast<const i::HeapSnapshot*>(snapshot));
   10238             : }
   10239             : 
   10240             : 
   10241          40 : void HeapSnapshot::Delete() {
   10242          75 :   i::Isolate* isolate = ToInternal(this)->profiler()->isolate();
   10243          40 :   if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
   10244           5 :     ToInternal(this)->Delete();
   10245             :   } else {
   10246             :     // If this is the last snapshot, clean up all accessory data as well.
   10247          35 :     isolate->heap_profiler()->DeleteAllSnapshots();
   10248             :   }
   10249          40 : }
   10250             : 
   10251             : 
   10252         299 : const HeapGraphNode* HeapSnapshot::GetRoot() const {
   10253         299 :   return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
   10254             : }
   10255             : 
   10256             : 
   10257      182484 : const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const {
   10258             :   return reinterpret_cast<const HeapGraphNode*>(
   10259      182484 :       ToInternal(this)->GetEntryById(id));
   10260             : }
   10261             : 
   10262             : 
   10263          10 : int HeapSnapshot::GetNodesCount() const {
   10264          10 :   return static_cast<int>(ToInternal(this)->entries().size());
   10265             : }
   10266             : 
   10267             : 
   10268       66602 : const HeapGraphNode* HeapSnapshot::GetNode(int index) const {
   10269             :   return reinterpret_cast<const HeapGraphNode*>(
   10270       66602 :       &ToInternal(this)->entries().at(index));
   10271             : }
   10272             : 
   10273             : 
   10274          20 : SnapshotObjectId HeapSnapshot::GetMaxSnapshotJSObjectId() const {
   10275          20 :   return ToInternal(this)->max_snapshot_js_object_id();
   10276             : }
   10277             : 
   10278             : 
   10279          35 : void HeapSnapshot::Serialize(OutputStream* stream,
   10280             :                              HeapSnapshot::SerializationFormat format) const {
   10281             :   Utils::ApiCheck(format == kJSON,
   10282             :                   "v8::HeapSnapshot::Serialize",
   10283             :                   "Unknown serialization format");
   10284          35 :   Utils::ApiCheck(stream->GetChunkSize() > 0,
   10285             :                   "v8::HeapSnapshot::Serialize",
   10286             :                   "Invalid stream chunk size");
   10287             :   i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
   10288          35 :   serializer.Serialize(stream);
   10289          35 : }
   10290             : 
   10291             : 
   10292             : // static
   10293             : STATIC_CONST_MEMBER_DEFINITION const SnapshotObjectId
   10294             :     HeapProfiler::kUnknownObjectId;
   10295             : 
   10296             : 
   10297         115 : int HeapProfiler::GetSnapshotCount() {
   10298         115 :   return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
   10299             : }
   10300             : 
   10301             : 
   10302          30 : const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) {
   10303             :   return reinterpret_cast<const HeapSnapshot*>(
   10304          30 :       reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
   10305             : }
   10306             : 
   10307             : 
   10308         155 : SnapshotObjectId HeapProfiler::GetObjectId(Local<Value> value) {
   10309         155 :   i::Handle<i::Object> obj = Utils::OpenHandle(*value);
   10310         155 :   return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
   10311             : }
   10312             : 
   10313             : 
   10314         140 : Local<Value> HeapProfiler::FindObjectById(SnapshotObjectId id) {
   10315             :   i::Handle<i::Object> obj =
   10316         140 :       reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id);
   10317         140 :   if (obj.is_null()) return Local<Value>();
   10318             :   return Utils::ToLocal(obj);
   10319             : }
   10320             : 
   10321             : 
   10322        3837 : void HeapProfiler::ClearObjectIds() {
   10323        3837 :   reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap();
   10324        3837 : }
   10325             : 
   10326             : 
   10327         398 : const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
   10328             :     ActivityControl* control, ObjectNameResolver* resolver) {
   10329             :   return reinterpret_cast<const HeapSnapshot*>(
   10330             :       reinterpret_cast<i::HeapProfiler*>(this)
   10331         398 :           ->TakeSnapshot(control, resolver));
   10332             : }
   10333             : 
   10334             : 
   10335          45 : void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) {
   10336             :   reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
   10337          45 :       track_allocations);
   10338          45 : }
   10339             : 
   10340             : 
   10341        3877 : void HeapProfiler::StopTrackingHeapObjects() {
   10342        3877 :   reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
   10343        3877 : }
   10344             : 
   10345             : 
   10346          55 : SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream,
   10347             :                                             int64_t* timestamp_us) {
   10348             :   i::HeapProfiler* heap_profiler = reinterpret_cast<i::HeapProfiler*>(this);
   10349          55 :   return heap_profiler->PushHeapObjectsStats(stream, timestamp_us);
   10350             : }
   10351             : 
   10352          59 : bool HeapProfiler::StartSamplingHeapProfiler(uint64_t sample_interval,
   10353             :                                              int stack_depth,
   10354             :                                              SamplingFlags flags) {
   10355             :   return reinterpret_cast<i::HeapProfiler*>(this)->StartSamplingHeapProfiler(
   10356          59 :       sample_interval, stack_depth, flags);
   10357             : }
   10358             : 
   10359             : 
   10360          59 : void HeapProfiler::StopSamplingHeapProfiler() {
   10361          59 :   reinterpret_cast<i::HeapProfiler*>(this)->StopSamplingHeapProfiler();
   10362          59 : }
   10363             : 
   10364             : 
   10365          77 : AllocationProfile* HeapProfiler::GetAllocationProfile() {
   10366          77 :   return reinterpret_cast<i::HeapProfiler*>(this)->GetAllocationProfile();
   10367             : }
   10368             : 
   10369          35 : void HeapProfiler::DeleteAllHeapSnapshots() {
   10370          35 :   reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
   10371          35 : }
   10372             : 
   10373           0 : void HeapProfiler::SetBuildEmbedderGraphCallback(
   10374             :     LegacyBuildEmbedderGraphCallback callback) {
   10375             :   reinterpret_cast<i::HeapProfiler*>(this)->AddBuildEmbedderGraphCallback(
   10376           0 :       [](v8::Isolate* isolate, v8::EmbedderGraph* graph, void* data) {
   10377             :         reinterpret_cast<LegacyBuildEmbedderGraphCallback>(data)(isolate,
   10378           0 :                                                                  graph);
   10379           0 :       },
   10380           0 :       reinterpret_cast<void*>(callback));
   10381           0 : }
   10382             : 
   10383          35 : void HeapProfiler::AddBuildEmbedderGraphCallback(
   10384             :     BuildEmbedderGraphCallback callback, void* data) {
   10385             :   reinterpret_cast<i::HeapProfiler*>(this)->AddBuildEmbedderGraphCallback(
   10386          35 :       callback, data);
   10387          35 : }
   10388             : 
   10389           5 : void HeapProfiler::RemoveBuildEmbedderGraphCallback(
   10390             :     BuildEmbedderGraphCallback callback, void* data) {
   10391             :   reinterpret_cast<i::HeapProfiler*>(this)->RemoveBuildEmbedderGraphCallback(
   10392           5 :       callback, data);
   10393           5 : }
   10394             : 
   10395             : v8::Testing::StressType internal::Testing::stress_type_ =
   10396             :     v8::Testing::kStressTypeOpt;
   10397             : 
   10398             : 
   10399        5538 : void Testing::SetStressRunType(Testing::StressType type) {
   10400             :   internal::Testing::set_stress_type(type);
   10401        5538 : }
   10402             : 
   10403             : 
   10404        5538 : int Testing::GetStressRuns() {
   10405       53741 :   if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs;
   10406             : #ifdef DEBUG
   10407             :   // In debug mode the code runs much slower so stressing will only make two
   10408             :   // runs.
   10409             :   return 2;
   10410             : #else
   10411             :   return 5;
   10412             : #endif
   10413             : }
   10414             : 
   10415             : 
   10416       21450 : static void SetFlagsFromString(const char* flags) {
   10417             :   V8::SetFlagsFromString(flags, i::StrLength(flags));
   10418       21450 : }
   10419             : 
   10420             : 
   10421       26754 : void Testing::PrepareStressRun(int run) {
   10422             :   static const char* kLazyOptimizations =
   10423             :       "--prepare-always-opt "
   10424             :       "--max-inlined-bytecode-size=999999 "
   10425             :       "--max-inlined-bytecode-size-cumulative=999999 "
   10426             :       "--noalways-opt";
   10427             :   static const char* kForcedOptimizations = "--always-opt";
   10428             : 
   10429             :   // If deoptimization stressed turn on frequent deoptimization. If no value
   10430             :   // is spefified through --deopt-every-n-times use a default default value.
   10431             :   static const char* kDeoptEvery13Times = "--deopt-every-n-times=13";
   10432       26754 :   if (internal::Testing::stress_type() == Testing::kStressTypeDeopt &&
   10433           0 :       internal::FLAG_deopt_every_n_times == 0) {
   10434           0 :     SetFlagsFromString(kDeoptEvery13Times);
   10435             :   }
   10436             : 
   10437             : #ifdef DEBUG
   10438             :   // As stressing in debug mode only make two runs skip the deopt stressing
   10439             :   // here.
   10440             :   if (run == GetStressRuns() - 1) {
   10441             :     SetFlagsFromString(kForcedOptimizations);
   10442             :   } else {
   10443             :     SetFlagsFromString(kLazyOptimizations);
   10444             :   }
   10445             : #else
   10446       26754 :   if (run == GetStressRuns() - 1) {
   10447        5305 :     SetFlagsFromString(kForcedOptimizations);
   10448       21449 :   } else if (run != GetStressRuns() - 2) {
   10449       16145 :     SetFlagsFromString(kLazyOptimizations);
   10450             :   }
   10451             : #endif
   10452       26754 : }
   10453             : 
   10454             : 
   10455        5538 : void Testing::DeoptimizeAll(Isolate* isolate) {
   10456             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
   10457             :   i::HandleScope scope(i_isolate);
   10458        5538 :   i::Deoptimizer::DeoptimizeAll(i_isolate);
   10459        5538 : }
   10460             : 
   10461          10 : void EmbedderHeapTracer::FinalizeTracing() {
   10462          10 :   if (isolate_) {
   10463             :     i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
   10464          10 :     if (isolate->heap()->incremental_marking()->IsMarking()) {
   10465             :       isolate->heap()->FinalizeIncrementalMarkingAtomically(
   10466           5 :           i::GarbageCollectionReason::kExternalFinalize);
   10467             :     }
   10468             :   }
   10469          10 : }
   10470             : 
   10471           5 : void EmbedderHeapTracer::GarbageCollectionForTesting(
   10472             :     EmbedderStackState stack_state) {
   10473           5 :   CHECK(isolate_);
   10474           5 :   CHECK(i::FLAG_expose_gc);
   10475           5 :   i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap();
   10476           5 :   heap->SetEmbedderStackStateForNextFinalizaton(stack_state);
   10477             :   heap->PreciseCollectAllGarbage(i::Heap::kNoGCFlags,
   10478             :                                  i::GarbageCollectionReason::kTesting,
   10479           5 :                                  kGCCallbackFlagForced);
   10480           5 : }
   10481             : 
   10482           5 : void EmbedderHeapTracer::RegisterEmbedderReference(
   10483             :     const TracedGlobal<v8::Value>& ref) {
   10484          10 :   if (ref.IsEmpty()) return;
   10485             : 
   10486           5 :   i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap();
   10487             :   heap->RegisterExternallyReferencedObject(
   10488           5 :       reinterpret_cast<i::Address*>(ref.val_));
   10489             : }
   10490             : 
   10491           5 : void EmbedderHeapTracer::IterateTracedGlobalHandles(
   10492             :     TracedGlobalHandleVisitor* visitor) {
   10493           5 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
   10494             :   i::DisallowHeapAllocation no_allocation;
   10495           5 :   isolate->global_handles()->IterateTracedNodes(visitor);
   10496           5 : }
   10497             : 
   10498             : namespace internal {
   10499             : 
   10500             : const size_t HandleScopeImplementer::kEnteredContextsOffset =
   10501             :     offsetof(HandleScopeImplementer, entered_contexts_);
   10502             : const size_t HandleScopeImplementer::kIsMicrotaskContextOffset =
   10503             :     offsetof(HandleScopeImplementer, is_microtask_context_);
   10504             : 
   10505        5906 : void HandleScopeImplementer::FreeThreadResources() {
   10506        5906 :   Free();
   10507        5906 : }
   10508             : 
   10509             : 
   10510       23397 : char* HandleScopeImplementer::ArchiveThread(char* storage) {
   10511       23397 :   HandleScopeData* current = isolate_->handle_scope_data();
   10512       23397 :   handle_scope_data_ = *current;
   10513             :   MemCopy(storage, this, sizeof(*this));
   10514             : 
   10515             :   ResetAfterArchive();
   10516             :   current->Initialize();
   10517             : 
   10518       23397 :   return storage + ArchiveSpacePerThread();
   10519             : }
   10520             : 
   10521             : 
   10522       64335 : int HandleScopeImplementer::ArchiveSpacePerThread() {
   10523       64335 :   return sizeof(HandleScopeImplementer);
   10524             : }
   10525             : 
   10526             : 
   10527       23397 : char* HandleScopeImplementer::RestoreThread(char* storage) {
   10528             :   MemCopy(this, storage, sizeof(*this));
   10529       23397 :   *isolate_->handle_scope_data() = handle_scope_data_;
   10530       23397 :   return storage + ArchiveSpacePerThread();
   10531             : }
   10532             : 
   10533      566859 : void HandleScopeImplementer::IterateThis(RootVisitor* v) {
   10534             : #ifdef DEBUG
   10535             :   bool found_block_before_deferred = false;
   10536             : #endif
   10537             :   // Iterate over all handles in the blocks except for the last.
   10538      686062 :   for (int i = static_cast<int>(blocks()->size()) - 2; i >= 0; --i) {
   10539      238406 :     Address* block = blocks()->at(i);
   10540             :     // Cast possibly-unrelated pointers to plain Address before comparing them
   10541             :     // to avoid undefined behavior.
   10542      119214 :     if (last_handle_before_deferred_block_ != nullptr &&
   10543          22 :         (reinterpret_cast<Address>(last_handle_before_deferred_block_) <=
   10544          22 :          reinterpret_cast<Address>(&block[kHandleBlockSize])) &&
   10545          11 :         (reinterpret_cast<Address>(last_handle_before_deferred_block_) >=
   10546             :          reinterpret_cast<Address>(block))) {
   10547             :       v->VisitRootPointers(Root::kHandleScope, nullptr, FullObjectSlot(block),
   10548          22 :                            FullObjectSlot(last_handle_before_deferred_block_));
   10549          11 :       DCHECK(!found_block_before_deferred);
   10550             : #ifdef DEBUG
   10551             :       found_block_before_deferred = true;
   10552             : #endif
   10553             :     } else {
   10554             :       v->VisitRootPointers(Root::kHandleScope, nullptr, FullObjectSlot(block),
   10555      238384 :                            FullObjectSlot(&block[kHandleBlockSize]));
   10556             :     }
   10557             :   }
   10558             : 
   10559             :   DCHECK(last_handle_before_deferred_block_ == nullptr ||
   10560             :          found_block_before_deferred);
   10561             : 
   10562             :   // Iterate over live handles in the last block (if any).
   10563      566859 :   if (!blocks()->empty()) {
   10564             :     v->VisitRootPointers(Root::kHandleScope, nullptr,
   10565             :                          FullObjectSlot(blocks()->back()),
   10566     1154451 :                          FullObjectSlot(handle_scope_data_.next));
   10567             :   }
   10568             : 
   10569             :   DetachableVector<Context>* context_lists[2] = {&saved_contexts_,
   10570      566859 :                                                  &entered_contexts_};
   10571     1700577 :   for (unsigned i = 0; i < arraysize(context_lists); i++) {
   10572     1133718 :     context_lists[i]->shrink_to_fit();
   10573     1133718 :     if (context_lists[i]->empty()) continue;
   10574             :     FullObjectSlot start(&context_lists[i]->front());
   10575             :     v->VisitRootPointers(Root::kHandleScope, nullptr, start,
   10576     1611376 :                          start + static_cast<int>(context_lists[i]->size()));
   10577             :   }
   10578      566859 : }
   10579             : 
   10580      561679 : void HandleScopeImplementer::Iterate(RootVisitor* v) {
   10581      561679 :   HandleScopeData* current = isolate_->handle_scope_data();
   10582      561679 :   handle_scope_data_ = *current;
   10583      561679 :   IterateThis(v);
   10584      561679 : }
   10585             : 
   10586        5180 : char* HandleScopeImplementer::Iterate(RootVisitor* v, char* storage) {
   10587             :   HandleScopeImplementer* scope_implementer =
   10588             :       reinterpret_cast<HandleScopeImplementer*>(storage);
   10589        5180 :   scope_implementer->IterateThis(v);
   10590        5180 :   return storage + ArchiveSpacePerThread();
   10591             : }
   10592             : 
   10593        7174 : DeferredHandles* HandleScopeImplementer::Detach(Address* prev_limit) {
   10594             :   DeferredHandles* deferred =
   10595        7174 :       new DeferredHandles(isolate()->handle_scope_data()->next, isolate());
   10596             : 
   10597       21522 :   while (!blocks_.empty()) {
   10598       14348 :     Address* block_start = blocks_.back();
   10599       14348 :     Address* block_limit = &block_start[kHandleBlockSize];
   10600             :     // We should not need to check for SealHandleScope here. Assert this.
   10601             :     DCHECK(prev_limit == block_limit ||
   10602             :            !(block_start <= prev_limit && prev_limit <= block_limit));
   10603       14348 :     if (prev_limit == block_limit) break;
   10604        7174 :     deferred->blocks_.push_back(blocks_.back());
   10605       14348 :     blocks_.pop_back();
   10606             :   }
   10607             : 
   10608             :   // deferred->blocks_ now contains the blocks installed on the
   10609             :   // HandleScope stack since BeginDeferredScope was called, but in
   10610             :   // reverse order.
   10611             : 
   10612             :   DCHECK(prev_limit == nullptr || !blocks_.empty());
   10613             : 
   10614             :   DCHECK(!blocks_.empty() && prev_limit != nullptr);
   10615             :   DCHECK_NOT_NULL(last_handle_before_deferred_block_);
   10616        7174 :   last_handle_before_deferred_block_ = nullptr;
   10617        7174 :   return deferred;
   10618             : }
   10619             : 
   10620             : 
   10621        7174 : void HandleScopeImplementer::BeginDeferredScope() {
   10622             :   DCHECK_NULL(last_handle_before_deferred_block_);
   10623        7174 :   last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
   10624        7174 : }
   10625             : 
   10626             : 
   10627        7174 : DeferredHandles::~DeferredHandles() {
   10628       14348 :   isolate_->UnlinkDeferredHandles(this);
   10629             : 
   10630       28696 :   for (size_t i = 0; i < blocks_.size(); i++) {
   10631             : #ifdef ENABLE_HANDLE_ZAPPING
   10632       21522 :     HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]);
   10633             : #endif
   10634        7174 :     isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]);
   10635             :   }
   10636        7174 : }
   10637             : 
   10638        2622 : void DeferredHandles::Iterate(RootVisitor* v) {
   10639             :   DCHECK(!blocks_.empty());
   10640             : 
   10641             :   // Comparing pointers that do not point into the same array is undefined
   10642             :   // behavior, which means if we didn't cast everything to plain Address
   10643             :   // before comparing, the compiler would be allowed to assume that all
   10644             :   // comparisons evaluate to true and drop the entire check.
   10645             :   DCHECK((reinterpret_cast<Address>(first_block_limit_) >=
   10646             :           reinterpret_cast<Address>(blocks_.front())) &&
   10647             :          (reinterpret_cast<Address>(first_block_limit_) <=
   10648             :           reinterpret_cast<Address>(&(blocks_.front())[kHandleBlockSize])));
   10649             : 
   10650             :   v->VisitRootPointers(Root::kHandleScope, nullptr,
   10651        2622 :                        FullObjectSlot(blocks_.front()),
   10652        7866 :                        FullObjectSlot(first_block_limit_));
   10653             : 
   10654        5244 :   for (size_t i = 1; i < blocks_.size(); i++) {
   10655             :     v->VisitRootPointers(Root::kHandleScope, nullptr,
   10656             :                          FullObjectSlot(blocks_[i]),
   10657           0 :                          FullObjectSlot(&blocks_[i][kHandleBlockSize]));
   10658             :   }
   10659        2622 : }
   10660             : 
   10661             : 
   10662         645 : void InvokeAccessorGetterCallback(
   10663             :     v8::Local<v8::Name> property,
   10664             :     const v8::PropertyCallbackInfo<v8::Value>& info,
   10665             :     v8::AccessorNameGetterCallback getter) {
   10666             :   // Leaving JavaScript.
   10667             :   Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
   10668             :   RuntimeCallTimerScope timer(isolate,
   10669         645 :                               RuntimeCallCounterId::kAccessorGetterCallback);
   10670         645 :   Address getter_address = reinterpret_cast<Address>(getter);
   10671        1290 :   VMState<EXTERNAL> state(isolate);
   10672        1290 :   ExternalCallbackScope call_scope(isolate, getter_address);
   10673         645 :   getter(property, info);
   10674         645 : }
   10675             : 
   10676             : 
   10677           0 : void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
   10678             :                             v8::FunctionCallback callback) {
   10679             :   Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
   10680             :   RuntimeCallTimerScope timer(isolate,
   10681           0 :                               RuntimeCallCounterId::kInvokeFunctionCallback);
   10682           0 :   Address callback_address = reinterpret_cast<Address>(callback);
   10683           0 :   VMState<EXTERNAL> state(isolate);
   10684           0 :   ExternalCallbackScope call_scope(isolate, callback_address);
   10685           0 :   callback(info);
   10686           0 : }
   10687             : 
   10688             : // Undefine macros for jumbo build.
   10689             : #undef LOG_API
   10690             : #undef ENTER_V8_DO_NOT_USE
   10691             : #undef ENTER_V8_HELPER_DO_NOT_USE
   10692             : #undef PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE
   10693             : #undef PREPARE_FOR_EXECUTION_WITH_CONTEXT
   10694             : #undef PREPARE_FOR_EXECUTION
   10695             : #undef ENTER_V8
   10696             : #undef ENTER_V8_NO_SCRIPT
   10697             : #undef ENTER_V8_NO_SCRIPT_NO_EXCEPTION
   10698             : #undef ENTER_V8_FOR_NEW_CONTEXT
   10699             : #undef EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE
   10700             : #undef RETURN_ON_FAILED_EXECUTION
   10701             : #undef RETURN_ON_FAILED_EXECUTION_PRIMITIVE
   10702             : #undef RETURN_TO_LOCAL_UNCHECKED
   10703             : #undef RETURN_ESCAPED
   10704             : #undef SET_FIELD_WRAPPED
   10705             : #undef NEW_STRING
   10706             : #undef CALLBACK_SETTER
   10707             : 
   10708             : }  // namespace internal
   10709      178779 : }  // namespace v8

Generated by: LCOV version 1.10