LCOV - code coverage report
Current view: top level - src - api.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 3547 4068 87.2 %
Date: 2019-03-21 Functions: 901 1087 82.9 %

          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             : Local<Context> ContextFromNeverReadOnlySpaceObject(
     244             :     i::Handle<i::JSReceiver> obj) {
     245           0 :   return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
     246             : }
     247             : 
     248     7331088 : class InternalEscapableScope : public v8::EscapableHandleScope {
     249             :  public:
     250             :   explicit inline InternalEscapableScope(i::Isolate* isolate)
     251     7331083 :       : 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    12412834 :   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             :                           isolate_->only_terminate_in_safe_scope()
     275             :                               ? (safe_for_termination_
     276             :                                      ? i::InterruptsScope::kRunInterrupts
     277             :                                      : i::InterruptsScope::kPostponeInterrupts)
     278    12412834 :                               : i::InterruptsScope::kNoop) {
     279    12412844 :     isolate_->handle_scope_implementer()->IncrementCallDepth();
     280    12412844 :     isolate_->set_next_v8_call_is_safe_for_termination(false);
     281    12412844 :     if (!context.IsEmpty()) {
     282             :       i::Handle<i::Context> env = Utils::OpenHandle(*context);
     283             :       i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
     284    37209466 :       if (!isolate->context().is_null() &&
     285    37209020 :           isolate->context()->native_context() == env->native_context()) {
     286    12402641 :         context_ = Local<Context>();
     287             :       } else {
     288             :         impl->SaveContext(isolate->context());
     289             :         isolate->set_context(*env);
     290             :       }
     291             :     }
     292     5425378 :     if (do_callback) isolate_->FireBeforeCallEnteredCallback();
     293    12412836 :   }
     294    12412828 :   ~CallDepthScope() {
     295    12412828 :     i::MicrotaskQueue* microtask_queue = isolate_->default_microtask_queue();
     296    12412828 :     if (!context_.IsEmpty()) {
     297             :       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    12412828 :     if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth();
     304     5425370 :     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    12412831 :     isolate_->set_next_v8_call_is_safe_for_termination(safe_for_termination_);
     310    12412834 :   }
     311             : 
     312       12478 :   void Escape() {
     313             :     DCHECK(!escaped_);
     314       12478 :     escaped_ = true;
     315       12478 :     auto handle_scope_implementer = isolate_->handle_scope_implementer();
     316             :     handle_scope_implementer->DecrementCallDepth();
     317             :     bool clear_exception =
     318             :         handle_scope_implementer->CallDepthIsZero() &&
     319       12478 :         isolate_->thread_local_top()->try_catch_handler_ == nullptr;
     320       12478 :     isolate_->OptionalRescheduleException(clear_exception);
     321       12478 :   }
     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       15985 : static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
     336             :                                              i::Handle<i::Script> script) {
     337       31970 :   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             :                                                 isolate);
     341             :   v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
     342             :   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       47955 :       Utils::ToLocal(host_defined_options));
     354       15985 :   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             :   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          15 : 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           0 :       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          15 :       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             : static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
     502    12414382 :   if (isolate->has_scheduled_exception()) {
     503             :     return isolate->scheduled_exception() ==
     504             :            i::ReadOnlyRoots(isolate).termination_exception();
     505             :   }
     506             :   return false;
     507             : }
     508             : 
     509             : 
     510       60107 : void V8::SetNativesDataBlob(StartupData* natives_blob) {
     511       60107 :   i::V8::SetNativesBlob(natives_blob);
     512       60107 : }
     513             : 
     514             : 
     515       60107 : void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
     516       60107 :   i::V8::SetSnapshotBlob(snapshot_blob);
     517       60107 : }
     518             : 
     519             : namespace {
     520             : 
     521      301014 : class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
     522             :  public:
     523      318256 :   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      318256 :     void* data = calloc(length, 1);
     530             : #endif
     531      318256 :     return data;
     532             :   }
     533             : 
     534       18304 :   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       18304 :     void* data = malloc(length);
     541             : #endif
     542       18304 :     return data;
     543             :   }
     544             : 
     545      336490 :   void Free(void* data, size_t) override { free(data); }
     546             : };
     547             : 
     548         588 : struct SnapshotCreatorData {
     549             :   explicit SnapshotCreatorData(Isolate* isolate)
     550             :       : isolate_(isolate),
     551             :         default_context_(),
     552             :         contexts_(isolate),
     553         392 :         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         196 : SnapshotCreator::SnapshotCreator(Isolate* isolate,
     571             :                                  const intptr_t* external_references,
     572             :                                  StartupData* existing_snapshot) {
     573         196 :   SnapshotCreatorData* data = new SnapshotCreatorData(isolate);
     574             :   data->isolate_ = isolate;
     575             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
     576         196 :   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         196 :                                 : i::Snapshot::DefaultSnapshotBlob();
     583         196 :   if (blob && blob->raw_size > 0) {
     584             :     internal_isolate->set_snapshot_blob(blob);
     585         195 :     i::Snapshot::Initialize(internal_isolate);
     586             :   } else {
     587           1 :     internal_isolate->InitWithoutSnapshot();
     588             :   }
     589         196 :   data_ = data;
     590         196 : }
     591             : 
     592         195 : SnapshotCreator::SnapshotCreator(const intptr_t* external_references,
     593             :                                  StartupData* existing_snapshot)
     594             :     : SnapshotCreator(Isolate::Allocate(), external_references,
     595         195 :                       existing_snapshot) {}
     596             : 
     597         392 : SnapshotCreator::~SnapshotCreator() {
     598         196 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     599             :   DCHECK(data->created_);
     600         196 :   Isolate* isolate = data->isolate_;
     601             :   isolate->Exit();
     602         196 :   isolate->Dispose();
     603         196 :   delete data;
     604         196 : }
     605             : 
     606         196 : Isolate* SnapshotCreator::GetIsolate() {
     607         196 :   return SnapshotCreatorData::cast(data_)->isolate_;
     608             : }
     609             : 
     610         196 : void SnapshotCreator::SetDefaultContext(
     611             :     Local<Context> context, SerializeInternalFieldsCallback callback) {
     612             :   DCHECK(!context.IsEmpty());
     613         196 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     614             :   DCHECK(!data->created_);
     615             :   DCHECK(data->default_context_.IsEmpty());
     616         196 :   Isolate* isolate = data->isolate_;
     617         196 :   CHECK_EQ(isolate, context->GetIsolate());
     618             :   data->default_context_.Reset(isolate, context);
     619         196 :   data->default_embedder_fields_serializer_ = callback;
     620         196 : }
     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             :         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         231 : void ConvertSerializedObjectsToFixedArray(Local<Context> context) {
     681             :   i::Handle<i::Context> ctx = Utils::OpenHandle(*context);
     682             :   i::Isolate* isolate = ctx->GetIsolate();
     683         462 :   if (!ctx->serialized_objects()->IsArrayList()) {
     684           5 :     ctx->set_serialized_objects(i::ReadOnlyRoots(isolate).empty_fixed_array());
     685             :   } else {
     686         452 :     i::Handle<i::ArrayList> list(i::ArrayList::cast(ctx->serialized_objects()),
     687             :                                  isolate);
     688         226 :     i::Handle<i::FixedArray> elements = i::ArrayList::Elements(isolate, list);
     689         226 :     ctx->set_serialized_objects(*elements);
     690             :   }
     691         231 : }
     692             : 
     693         196 : void ConvertSerializedObjectsToFixedArray(i::Isolate* isolate) {
     694         392 :   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             :         i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate);
     700         196 :     i::Handle<i::FixedArray> elements = i::ArrayList::Elements(isolate, list);
     701         196 :     isolate->heap()->SetSerializedObjects(*elements);
     702             :   }
     703         196 : }
     704             : }  // anonymous namespace
     705             : 
     706         196 : StartupData SnapshotCreator::CreateBlob(
     707             :     SnapshotCreator::FunctionCodeHandling function_code_handling) {
     708         196 :   SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
     709         196 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
     710             :   DCHECK(!data->created_);
     711             :   DCHECK(!data->default_context_.IsEmpty());
     712             : 
     713         196 :   int num_additional_contexts = static_cast<int>(data->contexts_.Size());
     714             : 
     715             :   {
     716             :     i::HandleScope scope(isolate);
     717             :     // Convert list of context-independent data to FixedArray.
     718         196 :     ConvertSerializedObjectsToFixedArray(isolate);
     719             : 
     720             :     // Convert lists of context-dependent data to FixedArray.
     721         196 :     ConvertSerializedObjectsToFixedArray(
     722         196 :         data->default_context_.Get(data->isolate_));
     723         266 :     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             :         isolate->factory()->NewFixedArray(num_additional_contexts,
     731         196 :                                           i::AllocationType::kOld);
     732         266 :     for (int i = 0; i < num_additional_contexts; i++) {
     733             :       i::Handle<i::Context> context =
     734          70 :           v8::Utils::OpenHandle(*data->contexts_.Get(i));
     735          35 :       global_proxy_sizes->set(i,
     736          70 :                               i::Smi::FromInt(context->global_proxy()->Size()));
     737             :     }
     738         392 :     isolate->heap()->SetSerializedGlobalProxySizes(*global_proxy_sizes);
     739             :   }
     740             : 
     741             :   // We might rehash strings and re-sort descriptors. Clear the lookup cache.
     742         196 :   isolate->descriptor_lookup_cache()->Clear();
     743             : 
     744             :   // If we don't do this then we end up with a stray root pointing at the
     745             :   // context even after we have disposed of the context.
     746         196 :   isolate->heap()->CollectAllAvailableGarbage(
     747         196 :       i::GarbageCollectionReason::kSnapshotCreator);
     748             :   {
     749         196 :     i::HandleScope scope(isolate);
     750         196 :     isolate->heap()->CompactWeakArrayLists(internal::AllocationType::kOld);
     751             :   }
     752             : 
     753         196 :   isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded();
     754             : 
     755         196 :   if (function_code_handling == FunctionCodeHandling::kClear) {
     756             :     // Clear out re-compilable data from all shared function infos. Any
     757             :     // JSFunctions using these SFIs will have their code pointers reset by the
     758             :     // partial serializer.
     759             :     //
     760             :     // We have to iterate the heap and collect handles to each clearable SFI,
     761             :     // before we disable allocation, since we have to allocate UncompiledDatas
     762             :     // to be able to recompile them.
     763             :     //
     764             :     // Compiled irregexp code is also flushed by collecting and clearing any
     765             :     // seen JSRegExp objects.
     766         166 :     i::HandleScope scope(isolate);
     767             :     std::vector<i::Handle<i::SharedFunctionInfo>> sfis_to_clear;
     768             : 
     769             :     {  // Heap allocation is disallowed within this scope.
     770         332 :       i::HeapIterator heap_iterator(isolate->heap());
     771     1418234 :       for (i::HeapObject current_obj = heap_iterator.next();
     772             :            !current_obj.is_null(); current_obj = heap_iterator.next()) {
     773     1418068 :         if (current_obj->IsSharedFunctionInfo()) {
     774             :           i::SharedFunctionInfo shared =
     775      153626 :               i::SharedFunctionInfo::cast(current_obj);
     776      153626 :           if (shared->CanDiscardCompiled()) {
     777          37 :             sfis_to_clear.emplace_back(shared, isolate);
     778             :           }
     779     1264442 :         } else if (current_obj->IsJSRegExp()) {
     780          10 :           i::JSRegExp regexp = i::JSRegExp::cast(current_obj);
     781          10 :           if (regexp->HasCompiledCode()) {
     782           5 :             regexp->DiscardCompiledCodeForSerialization();
     783             :           }
     784             :         }
     785             :       }
     786             :     }
     787             : 
     788             :     // Must happen after heap iteration since SFI::DiscardCompiled may allocate.
     789         203 :     for (i::Handle<i::SharedFunctionInfo> shared : sfis_to_clear) {
     790          37 :       i::SharedFunctionInfo::DiscardCompiled(isolate, shared);
     791             :     }
     792             :   }
     793             : 
     794             :   i::DisallowHeapAllocation no_gc_from_here_on;
     795             : 
     796         196 :   int num_contexts = num_additional_contexts + 1;
     797             :   std::vector<i::Context> contexts;
     798         196 :   contexts.reserve(num_contexts);
     799             :   {
     800         196 :     i::HandleScope scope(isolate);
     801         392 :     contexts.push_back(
     802         196 :         *v8::Utils::OpenHandle(*data->default_context_.Get(data->isolate_)));
     803             :     data->default_context_.Reset();
     804         266 :     for (int i = 0; i < num_additional_contexts; i++) {
     805             :       i::Handle<i::Context> context =
     806          70 :           v8::Utils::OpenHandle(*data->contexts_.Get(i));
     807          70 :       contexts.push_back(*context);
     808             :     }
     809         196 :     data->contexts_.Clear();
     810             :   }
     811             : 
     812             :   // Check that values referenced by global/eternal handles are accounted for.
     813         196 :   i::SerializedHandleChecker handle_checker(isolate, &contexts);
     814         196 :   CHECK(handle_checker.CheckGlobalAndEternalHandles());
     815             : 
     816         588 :   i::HeapIterator heap_iterator(isolate->heap());
     817     1611051 :   for (i::HeapObject current_obj = heap_iterator.next(); !current_obj.is_null();
     818             :        current_obj = heap_iterator.next()) {
     819     1610855 :     if (current_obj->IsJSFunction()) {
     820      189533 :       i::JSFunction fun = i::JSFunction::cast(current_obj);
     821             : 
     822             :       // Complete in-object slack tracking for all functions.
     823      189533 :       fun->CompleteInobjectSlackTrackingIfActive();
     824             : 
     825             :       // Also, clear out feedback vectors, or any optimized code.
     826      189533 :       if (!fun->raw_feedback_cell()->value()->IsUndefined()) {
     827         120 :         fun->raw_feedback_cell()->set_value(
     828         240 :             i::ReadOnlyRoots(isolate).undefined_value());
     829         120 :         fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy));
     830             :       }
     831             :       if (function_code_handling == FunctionCodeHandling::kClear) {
     832             :         DCHECK(fun->shared()->HasWasmExportedFunctionData() ||
     833             :                fun->shared()->HasBuiltinId() ||
     834             :                fun->shared()->IsApiFunction() ||
     835             :                fun->shared()->HasUncompiledDataWithoutPreparseData());
     836             :       }
     837             :     }
     838             :   }
     839             : 
     840         392 :   i::ReadOnlySerializer read_only_serializer(isolate);
     841         196 :   read_only_serializer.SerializeReadOnlyRoots();
     842             : 
     843         392 :   i::StartupSerializer startup_serializer(isolate, &read_only_serializer);
     844         196 :   startup_serializer.SerializeStrongReferences();
     845             : 
     846             :   // Serialize each context with a new partial serializer.
     847             :   std::vector<i::SnapshotData*> context_snapshots;
     848         196 :   context_snapshots.reserve(num_contexts);
     849             : 
     850             :   // TODO(6593): generalize rehashing, and remove this flag.
     851             :   bool can_be_rehashed = true;
     852             : 
     853         658 :   for (int i = 0; i < num_contexts; i++) {
     854             :     bool is_default_context = i == 0;
     855             :     i::PartialSerializer partial_serializer(
     856             :         isolate, &startup_serializer,
     857             :         is_default_context ? data->default_embedder_fields_serializer_
     858         693 :                            : data->embedder_fields_serializers_[i - 1]);
     859         462 :     partial_serializer.Serialize(&contexts[i], !is_default_context);
     860         231 :     can_be_rehashed = can_be_rehashed && partial_serializer.can_be_rehashed();
     861         462 :     context_snapshots.push_back(new i::SnapshotData(&partial_serializer));
     862             :   }
     863             : 
     864         196 :   startup_serializer.SerializeWeakReferencesAndDeferred();
     865         196 :   can_be_rehashed = can_be_rehashed && startup_serializer.can_be_rehashed();
     866             : 
     867         196 :   read_only_serializer.FinalizeSerialization();
     868         196 :   can_be_rehashed = can_be_rehashed && read_only_serializer.can_be_rehashed();
     869             : 
     870         196 :   i::SnapshotData read_only_snapshot(&read_only_serializer);
     871         196 :   i::SnapshotData startup_snapshot(&startup_serializer);
     872             :   StartupData result =
     873             :       i::Snapshot::CreateSnapshotBlob(&startup_snapshot, &read_only_snapshot,
     874         196 :                                       context_snapshots, can_be_rehashed);
     875             : 
     876             :   // Delete heap-allocated context snapshot instances.
     877         427 :   for (const auto context_snapshot : context_snapshots) {
     878         231 :     delete context_snapshot;
     879             :   }
     880         196 :   data->created_ = true;
     881             : 
     882             :   DCHECK(i::Snapshot::VerifyChecksum(&result));
     883         392 :   return result;
     884             : }
     885             : 
     886           5 : void V8::SetDcheckErrorHandler(DcheckErrorCallback that) {
     887           5 :   v8::base::SetDcheckFunction(that);
     888           5 : }
     889             : 
     890       89401 : void V8::SetFlagsFromString(const char* str, int length) {
     891      111061 :   i::FlagList::SetFlagsFromString(str, length);
     892      111061 :   i::FlagList::EnforceFlagImplications();
     893       89401 : }
     894             : 
     895             : 
     896       34043 : void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
     897       34043 :   i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
     898       34043 : }
     899             : 
     900             : RegisteredExtension* RegisteredExtension::first_extension_ = nullptr;
     901             : 
     902           0 : RegisteredExtension::RegisteredExtension(std::unique_ptr<Extension> extension)
     903      438969 :     : extension_(std::move(extension)) {}
     904             : 
     905             : // static
     906           0 : void RegisteredExtension::Register(std::unique_ptr<Extension> extension) {
     907             :   RegisteredExtension* new_extension =
     908      438969 :       new RegisteredExtension(std::move(extension));
     909      438969 :   new_extension->next_ = first_extension_;
     910      438969 :   first_extension_ = new_extension;
     911           0 : }
     912             : 
     913             : // static
     914       58997 : void RegisteredExtension::UnregisterAll() {
     915       58997 :   RegisteredExtension* re = first_extension_;
     916      491000 :   while (re != nullptr) {
     917             :     RegisteredExtension* next = re->next();
     918      864006 :     delete re;
     919             :     re = next;
     920             :   }
     921       58997 :   first_extension_ = nullptr;
     922       58997 : }
     923             : 
     924             : namespace {
     925      864006 : class ExtensionResource : public String::ExternalOneByteStringResource {
     926             :  public:
     927             :   ExtensionResource() : data_(nullptr), length_(0) {}
     928             :   ExtensionResource(const char* data, size_t length)
     929      438969 :       : data_(data), length_(length) {}
     930       12943 :   const char* data() const override { return data_; }
     931        9133 :   size_t length() const override { return length_; }
     932        4568 :   void Dispose() override {}
     933             : 
     934             :  private:
     935             :   const char* data_;
     936             :   size_t length_;
     937             : };
     938             : }  // anonymous namespace
     939             : 
     940      438969 : void RegisterExtension(std::unique_ptr<Extension> extension) {
     941             :   RegisteredExtension::Register(std::move(extension));
     942      438969 : }
     943             : 
     944      438969 : Extension::Extension(const char* name,
     945             :                      const char* source,
     946             :                      int dep_count,
     947             :                      const char** deps,
     948             :                      int source_length)
     949             :     : name_(name),
     950             :       source_length_(source_length >= 0 ?
     951             :                      source_length :
     952      438949 :                      (source ? static_cast<int>(strlen(source)) : 0)),
     953             :       dep_count_(dep_count),
     954             :       deps_(deps),
     955      877918 :       auto_enable_(false) {
     956      877938 :   source_ = new ExtensionResource(source, source_length_);
     957      438969 :   CHECK(source != nullptr || source_length_ == 0);
     958      438969 : }
     959             : 
     960       60900 : ResourceConstraints::ResourceConstraints()
     961             :     : max_semi_space_size_in_kb_(0),
     962             :       max_old_space_size_(0),
     963             :       stack_limit_(nullptr),
     964             :       code_range_size_(0),
     965       60900 :       max_zone_pool_size_(0) {}
     966             : 
     967       29802 : void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
     968             :                                             uint64_t virtual_memory_limit) {
     969             :   set_max_semi_space_size_in_kb(
     970             :       i::Heap::ComputeMaxSemiSpaceSize(physical_memory));
     971       29802 :   set_max_old_space_size(i::Heap::ComputeMaxOldGenerationSize(physical_memory));
     972             : 
     973       29802 :   if (virtual_memory_limit > 0 && i::kRequiresCodeRange) {
     974             :     // Reserve no more than 1/8 of the memory for the code range, but at most
     975             :     // kMaximalCodeRangeSize.
     976           0 :     set_code_range_size(
     977             :         i::Min(i::kMaximalCodeRangeSize / i::MB,
     978           0 :                static_cast<size_t>((virtual_memory_limit >> 3) / i::MB)));
     979             :   }
     980       29802 : }
     981             : 
     982       61228 : void SetResourceConstraints(i::Isolate* isolate,
     983             :                             const ResourceConstraints& constraints) {
     984             :   size_t semi_space_size = constraints.max_semi_space_size_in_kb();
     985             :   size_t old_space_size = constraints.max_old_space_size();
     986             :   size_t code_range_size = constraints.code_range_size();
     987       61228 :   if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) {
     988             :     isolate->heap()->ConfigureHeap(semi_space_size, old_space_size,
     989       29818 :                                    code_range_size);
     990             :   }
     991             : 
     992       61228 :   if (constraints.stack_limit() != nullptr) {
     993           0 :     uintptr_t limit = reinterpret_cast<uintptr_t>(constraints.stack_limit());
     994           0 :     isolate->stack_guard()->SetStackLimit(limit);
     995             :   }
     996       61228 : }
     997             : 
     998     3027270 : i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) {
     999     3027270 :   LOG_API(isolate, Persistent, New);
    1000     3027270 :   i::Handle<i::Object> result = isolate->global_handles()->Create(*obj);
    1001             : #ifdef VERIFY_HEAP
    1002             :   if (i::FLAG_verify_heap) {
    1003             :     i::Object(*obj)->ObjectVerify(isolate);
    1004             :   }
    1005             : #endif  // VERIFY_HEAP
    1006     3027270 :   return result.location();
    1007             : }
    1008             : 
    1009          70 : i::Address* V8::GlobalizeTracedReference(i::Isolate* isolate, i::Address* obj,
    1010             :                                          internal::Address* slot) {
    1011          70 :   LOG_API(isolate, TracedGlobal, New);
    1012             :   i::Handle<i::Object> result =
    1013          70 :       isolate->global_handles()->CreateTraced(*obj, slot);
    1014             : #ifdef VERIFY_HEAP
    1015             :   if (i::FLAG_verify_heap) {
    1016             :     i::Object(*obj)->ObjectVerify(isolate);
    1017             :   }
    1018             : #endif  // VERIFY_HEAP
    1019          70 :   return result.location();
    1020             : }
    1021             : 
    1022          10 : i::Address* V8::CopyGlobalReference(i::Address* from) {
    1023          10 :   i::Handle<i::Object> result = i::GlobalHandles::CopyGlobal(from);
    1024          10 :   return result.location();
    1025             : }
    1026             : 
    1027        5836 : void V8::MoveGlobalReference(internal::Address** from, internal::Address** to) {
    1028        5836 :   i::GlobalHandles::MoveGlobal(from, to);
    1029        5836 : }
    1030             : 
    1031          55 : void V8::MoveTracedGlobalReference(internal::Address** from,
    1032             :                                    internal::Address** to) {
    1033          55 :   i::GlobalHandles::MoveTracedGlobal(from, to);
    1034          55 : }
    1035             : 
    1036           0 : void V8::RegisterExternallyReferencedObject(i::Address* location,
    1037             :                                             i::Isolate* isolate) {
    1038           0 :   isolate->heap()->RegisterExternallyReferencedObject(location);
    1039           0 : }
    1040             : 
    1041      145053 : void V8::MakeWeak(i::Address* location, void* parameter,
    1042             :                   WeakCallbackInfo<void>::Callback weak_callback,
    1043             :                   WeakCallbackType type) {
    1044      145053 :   i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
    1045      145053 : }
    1046             : 
    1047          36 : void V8::MakeWeak(i::Address** location_addr) {
    1048          36 :   i::GlobalHandles::MakeWeak(location_addr);
    1049          36 : }
    1050             : 
    1051       20885 : void* V8::ClearWeak(i::Address* location) {
    1052       20885 :   return i::GlobalHandles::ClearWeakness(location);
    1053             : }
    1054             : 
    1055     2813294 : void V8::AnnotateStrongRetainer(i::Address* location, const char* label) {
    1056     2813294 :   i::GlobalHandles::AnnotateStrongRetainer(location, label);
    1057     2813294 : }
    1058             : 
    1059     3024552 : void V8::DisposeGlobal(i::Address* location) {
    1060     3024783 :   i::GlobalHandles::Destroy(location);
    1061     3024552 : }
    1062             : 
    1063          50 : void V8::DisposeTracedGlobal(internal::Address* location) {
    1064          50 :   i::GlobalHandles::DestroyTraced(location);
    1065          50 : }
    1066             : 
    1067          10 : void V8::SetFinalizationCallbackTraced(
    1068             :     internal::Address* location, void* parameter,
    1069             :     WeakCallbackInfo<void>::Callback callback) {
    1070             :   i::GlobalHandles::SetFinalizationCallbackForTraced(location, parameter,
    1071          10 :                                                      callback);
    1072          10 : }
    1073             : 
    1074       10245 : Value* V8::Eternalize(Isolate* v8_isolate, Value* value) {
    1075             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    1076       10245 :   i::Object object = *Utils::OpenHandle(value);
    1077       10245 :   int index = -1;
    1078       10245 :   isolate->eternal_handles()->Create(isolate, object, &index);
    1079             :   return reinterpret_cast<Value*>(
    1080       20490 :       isolate->eternal_handles()->Get(index).location());
    1081             : }
    1082             : 
    1083             : 
    1084           0 : void V8::FromJustIsNothing() {
    1085             :   Utils::ApiCheck(false, "v8::FromJust", "Maybe value is Nothing.");
    1086           0 : }
    1087             : 
    1088             : 
    1089           0 : void V8::ToLocalEmpty() {
    1090             :   Utils::ApiCheck(false, "v8::ToLocalChecked", "Empty MaybeLocal.");
    1091           0 : }
    1092             : 
    1093           0 : void V8::InternalFieldOutOfBounds(int index) {
    1094           0 :   Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback,
    1095             :                   "WeakCallbackInfo::GetInternalField",
    1096             :                   "Internal field out of bounds.");
    1097           0 : }
    1098             : 
    1099             : 
    1100             : // --- H a n d l e s ---
    1101             : 
    1102             : 
    1103   469013101 : HandleScope::HandleScope(Isolate* isolate) {
    1104   469013222 :   Initialize(isolate);
    1105   469013090 : }
    1106             : 
    1107             : 
    1108   476735714 : void HandleScope::Initialize(Isolate* isolate) {
    1109             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1110             :   // We do not want to check the correct usage of the Locker class all over the
    1111             :   // place, so we do it only here: Without a HandleScope, an embedder can do
    1112             :   // almost nothing, so it is enough to check in this central place.
    1113             :   // We make an exception if the serializer is enabled, which means that the
    1114             :   // Isolate is exclusively used to create a snapshot.
    1115             :   Utils::ApiCheck(
    1116   476794912 :       !v8::Locker::IsActive() ||
    1117   476735700 :           internal_isolate->thread_manager()->IsLockedByCurrentThread() ||
    1118             :           internal_isolate->serializer_enabled(),
    1119             :       "HandleScope::HandleScope",
    1120             :       "Entering the V8 API without proper locking in place");
    1121             :   i::HandleScopeData* current = internal_isolate->handle_scope_data();
    1122   476735685 :   isolate_ = internal_isolate;
    1123   476735685 :   prev_next_ = current->next;
    1124   476735685 :   prev_limit_ = current->limit;
    1125   476735685 :   current->level++;
    1126   476735685 : }
    1127             : 
    1128             : 
    1129   953132724 : HandleScope::~HandleScope() {
    1130   476735736 :   i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
    1131   476396988 : }
    1132             : 
    1133           0 : void* HandleScope::operator new(size_t) { base::OS::Abort(); }
    1134           0 : void* HandleScope::operator new[](size_t) { base::OS::Abort(); }
    1135           0 : void HandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
    1136           0 : void HandleScope::operator delete[](void*, size_t) { base::OS::Abort(); }
    1137             : 
    1138        6036 : int HandleScope::NumberOfHandles(Isolate* isolate) {
    1139             :   return i::HandleScope::NumberOfHandles(
    1140        6036 :       reinterpret_cast<i::Isolate*>(isolate));
    1141             : }
    1142             : 
    1143     5254526 : i::Address* HandleScope::CreateHandle(i::Isolate* isolate, i::Address value) {
    1144     5254520 :   return i::HandleScope::CreateHandle(isolate, value);
    1145             : }
    1146             : 
    1147     7722556 : EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
    1148             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    1149             :   escape_slot_ =
    1150     7722556 :       CreateHandle(isolate, i::ReadOnlyRoots(isolate).the_hole_value()->ptr());
    1151     7722556 :   Initialize(v8_isolate);
    1152     7722544 : }
    1153             : 
    1154     6848952 : i::Address* EscapableHandleScope::Escape(i::Address* escape_value) {
    1155             :   i::Heap* heap = reinterpret_cast<i::Isolate*>(GetIsolate())->heap();
    1156     6848952 :   Utils::ApiCheck(i::Object(*escape_slot_)->IsTheHole(heap->isolate()),
    1157             :                   "EscapableHandleScope::Escape", "Escape value set twice");
    1158     6848954 :   if (escape_value == nullptr) {
    1159          10 :     *escape_slot_ = i::ReadOnlyRoots(heap).undefined_value()->ptr();
    1160           5 :     return nullptr;
    1161             :   }
    1162     6848949 :   *escape_slot_ = *escape_value;
    1163     6848949 :   return escape_slot_;
    1164             : }
    1165             : 
    1166           0 : void* EscapableHandleScope::operator new(size_t) { base::OS::Abort(); }
    1167           0 : void* EscapableHandleScope::operator new[](size_t) { base::OS::Abort(); }
    1168           0 : void EscapableHandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
    1169           0 : void EscapableHandleScope::operator delete[](void*, size_t) {
    1170           0 :   base::OS::Abort();
    1171             : }
    1172             : 
    1173      339133 : SealHandleScope::SealHandleScope(Isolate* isolate)
    1174      339133 :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
    1175             :   i::HandleScopeData* current = isolate_->handle_scope_data();
    1176      339133 :   prev_limit_ = current->limit;
    1177      339133 :   current->limit = current->next;
    1178      339133 :   prev_sealed_level_ = current->sealed_level;
    1179      339133 :   current->sealed_level = current->level;
    1180      339133 : }
    1181             : 
    1182             : 
    1183      678266 : SealHandleScope::~SealHandleScope() {
    1184      339133 :   i::HandleScopeData* current = isolate_->handle_scope_data();
    1185             :   DCHECK_EQ(current->next, current->limit);
    1186      339133 :   current->limit = prev_limit_;
    1187             :   DCHECK_EQ(current->level, current->sealed_level);
    1188      339133 :   current->sealed_level = prev_sealed_level_;
    1189      339133 : }
    1190             : 
    1191           0 : void* SealHandleScope::operator new(size_t) { base::OS::Abort(); }
    1192           0 : void* SealHandleScope::operator new[](size_t) { base::OS::Abort(); }
    1193           0 : void SealHandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
    1194           0 : void SealHandleScope::operator delete[](void*, size_t) { base::OS::Abort(); }
    1195             : 
    1196     4370590 : void Context::Enter() {
    1197             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    1198             :   i::Isolate* isolate = env->GetIsolate();
    1199             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1200             :   i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
    1201             :   impl->EnterContext(*env);
    1202             :   impl->SaveContext(isolate->context());
    1203             :   isolate->set_context(*env);
    1204     4370578 : }
    1205             : 
    1206     4353910 : void Context::Exit() {
    1207             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    1208             :   i::Isolate* isolate = env->GetIsolate();
    1209             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1210             :   i::HandleScopeImplementer* impl = isolate->handle_scope_implementer();
    1211     4353911 :   if (!Utils::ApiCheck(impl->LastEnteredContextWas(*env), "v8::Context::Exit()",
    1212             :                        "Cannot exit non-entered context")) {
    1213             :     return;
    1214             :   }
    1215             :   impl->LeaveContext();
    1216             :   isolate->set_context(impl->RestoreContext());
    1217             : }
    1218             : 
    1219           2 : Context::BackupIncumbentScope::BackupIncumbentScope(
    1220             :     Local<Context> backup_incumbent_context)
    1221           2 :     : backup_incumbent_context_(backup_incumbent_context) {
    1222             :   DCHECK(!backup_incumbent_context_.IsEmpty());
    1223             : 
    1224             :   i::Handle<i::Context> env = Utils::OpenHandle(*backup_incumbent_context_);
    1225             :   i::Isolate* isolate = env->GetIsolate();
    1226             : 
    1227             :   js_stack_comparable_address_ =
    1228           2 :       i::SimulatorStack::RegisterJSStackComparableAddress(isolate);
    1229             : 
    1230           2 :   prev_ = isolate->top_backup_incumbent_scope();
    1231             :   isolate->set_top_backup_incumbent_scope(this);
    1232           2 : }
    1233             : 
    1234           4 : Context::BackupIncumbentScope::~BackupIncumbentScope() {
    1235             :   i::Handle<i::Context> env = Utils::OpenHandle(*backup_incumbent_context_);
    1236             :   i::Isolate* isolate = env->GetIsolate();
    1237             : 
    1238             :   i::SimulatorStack::UnregisterJSStackComparableAddress(isolate);
    1239             : 
    1240           2 :   isolate->set_top_backup_incumbent_scope(prev_);
    1241           2 : }
    1242             : 
    1243             : STATIC_ASSERT(i::Internals::kEmbedderDataSlotSize == i::kEmbedderDataSlotSize);
    1244             : 
    1245      113295 : static i::Handle<i::EmbedderDataArray> EmbedderDataFor(Context* context,
    1246             :                                                        int index, bool can_grow,
    1247             :                                                        const char* location) {
    1248             :   i::Handle<i::Context> env = Utils::OpenHandle(context);
    1249             :   i::Isolate* isolate = env->GetIsolate();
    1250             :   bool ok =
    1251      226590 :       Utils::ApiCheck(env->IsNativeContext(),
    1252             :                       location,
    1253      226590 :                       "Not a native context") &&
    1254             :       Utils::ApiCheck(index >= 0, location, "Negative index");
    1255      113295 :   if (!ok) return i::Handle<i::EmbedderDataArray>();
    1256             :   // TODO(ishell): remove cast once embedder_data slot has a proper type.
    1257             :   i::Handle<i::EmbedderDataArray> data(
    1258      226590 :       i::EmbedderDataArray::cast(env->embedder_data()), isolate);
    1259      113295 :   if (index < data->length()) return data;
    1260      121130 :   if (!Utils::ApiCheck(can_grow && index < i::EmbedderDataArray::kMaxLength,
    1261             :                        location, "Index too large")) {
    1262           0 :     return i::Handle<i::EmbedderDataArray>();
    1263             :   }
    1264       60565 :   data = i::EmbedderDataArray::EnsureCapacity(isolate, data, index);
    1265      121130 :   env->set_embedder_data(*data);
    1266       60565 :   return data;
    1267             : }
    1268             : 
    1269          75 : uint32_t Context::GetNumberOfEmbedderDataFields() {
    1270             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    1271         150 :   CHECK(context->IsNativeContext());
    1272             :   // TODO(ishell): remove cast once embedder_data slot has a proper type.
    1273             :   return static_cast<uint32_t>(
    1274         150 :       i::EmbedderDataArray::cast(context->embedder_data())->length());
    1275             : }
    1276             : 
    1277           0 : v8::Local<v8::Value> Context::SlowGetEmbedderData(int index) {
    1278             :   const char* location = "v8::Context::GetEmbedderData()";
    1279             :   i::Handle<i::EmbedderDataArray> data =
    1280           0 :       EmbedderDataFor(this, index, false, location);
    1281           0 :   if (data.is_null()) return Local<Value>();
    1282             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1283             :   i::Handle<i::Object> result(i::EmbedderDataSlot(*data, index).load_tagged(),
    1284             :                               isolate);
    1285             :   return Utils::ToLocal(result);
    1286             : }
    1287             : 
    1288             : 
    1289          60 : void Context::SetEmbedderData(int index, v8::Local<Value> value) {
    1290             :   const char* location = "v8::Context::SetEmbedderData()";
    1291             :   i::Handle<i::EmbedderDataArray> data =
    1292          60 :       EmbedderDataFor(this, index, true, location);
    1293          60 :   if (data.is_null()) return;
    1294             :   i::Handle<i::Object> val = Utils::OpenHandle(*value);
    1295             :   i::EmbedderDataSlot::store_tagged(*data, index, *val);
    1296             :   DCHECK_EQ(*Utils::OpenHandle(*value),
    1297             :             *Utils::OpenHandle(*GetEmbedderData(index)));
    1298             : }
    1299             : 
    1300             : 
    1301           0 : void* Context::SlowGetAlignedPointerFromEmbedderData(int index) {
    1302             :   const char* location = "v8::Context::GetAlignedPointerFromEmbedderData()";
    1303             :   i::Handle<i::EmbedderDataArray> data =
    1304           0 :       EmbedderDataFor(this, index, false, location);
    1305           0 :   if (data.is_null()) return nullptr;
    1306             :   void* result;
    1307             :   Utils::ApiCheck(i::EmbedderDataSlot(*data, index).ToAlignedPointer(&result),
    1308             :                   location, "Pointer is not aligned");
    1309           0 :   return result;
    1310             : }
    1311             : 
    1312             : 
    1313      113235 : void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
    1314             :   const char* location = "v8::Context::SetAlignedPointerInEmbedderData()";
    1315             :   i::Handle<i::EmbedderDataArray> data =
    1316      113235 :       EmbedderDataFor(this, index, true, location);
    1317             :   bool ok = i::EmbedderDataSlot(*data, index).store_aligned_pointer(value);
    1318             :   Utils::ApiCheck(ok, location, "Pointer is not aligned");
    1319             :   DCHECK_EQ(value, GetAlignedPointerFromEmbedderData(index));
    1320      113235 : }
    1321             : 
    1322             : 
    1323             : // --- T e m p l a t e ---
    1324             : 
    1325             : 
    1326     4435217 : static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
    1327             :   that->set_number_of_properties(0);
    1328     8870434 :   that->set_tag(i::Smi::FromInt(type));
    1329     4435222 : }
    1330             : 
    1331             : 
    1332     2061985 : void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
    1333             :                    v8::PropertyAttribute attribute) {
    1334             :   auto templ = Utils::OpenHandle(this);
    1335             :   i::Isolate* isolate = templ->GetIsolate();
    1336             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1337             :   i::HandleScope scope(isolate);
    1338             :   auto value_obj = Utils::OpenHandle(*value);
    1339     2061985 :   CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo());
    1340     2061985 :   if (value_obj->IsObjectTemplateInfo()) {
    1341      213208 :     templ->set_serial_number(i::Smi::kZero);
    1342      213208 :     if (templ->IsFunctionTemplateInfo()) {
    1343           0 :       i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
    1344             :     }
    1345             :   }
    1346             :   i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
    1347             :                                  value_obj,
    1348     2061985 :                                  static_cast<i::PropertyAttributes>(attribute));
    1349     2061985 : }
    1350             : 
    1351           0 : void Template::SetPrivate(v8::Local<Private> name, v8::Local<Data> value,
    1352             :                           v8::PropertyAttribute attribute) {
    1353             :   Set(Utils::ToLocal(Utils::OpenHandle(reinterpret_cast<Name*>(*name))), value,
    1354           0 :       attribute);
    1355           0 : }
    1356             : 
    1357         109 : void Template::SetAccessorProperty(
    1358             :     v8::Local<v8::Name> name,
    1359             :     v8::Local<FunctionTemplate> getter,
    1360             :     v8::Local<FunctionTemplate> setter,
    1361             :     v8::PropertyAttribute attribute,
    1362             :     v8::AccessControl access_control) {
    1363             :   // TODO(verwaest): Remove |access_control|.
    1364             :   DCHECK_EQ(v8::DEFAULT, access_control);
    1365             :   auto templ = Utils::OpenHandle(this);
    1366             :   auto isolate = templ->GetIsolate();
    1367             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1368             :   DCHECK(!name.IsEmpty());
    1369             :   DCHECK(!getter.IsEmpty() || !setter.IsEmpty());
    1370             :   i::HandleScope scope(isolate);
    1371             :   i::ApiNatives::AddAccessorProperty(
    1372             :       isolate, templ, Utils::OpenHandle(*name),
    1373             :       Utils::OpenHandle(*getter, true), Utils::OpenHandle(*setter, true),
    1374         109 :       static_cast<i::PropertyAttributes>(attribute));
    1375         109 : }
    1376             : 
    1377             : 
    1378             : // --- F u n c t i o n   T e m p l a t e ---
    1379     3599030 : static void InitializeFunctionTemplate(
    1380             :     i::Handle<i::FunctionTemplateInfo> info) {
    1381     3599030 :   InitializeTemplate(info, Consts::FUNCTION_TEMPLATE);
    1382             :   info->set_flag(0);
    1383     3599032 : }
    1384             : 
    1385             : static Local<ObjectTemplate> ObjectTemplateNew(
    1386             :     i::Isolate* isolate, v8::Local<FunctionTemplate> constructor,
    1387             :     bool do_not_cache);
    1388             : 
    1389      158332 : Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
    1390             :   i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
    1391             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1392             :   i::Handle<i::Object> result(Utils::OpenHandle(this)->GetPrototypeTemplate(),
    1393      316664 :                               i_isolate);
    1394      158332 :   if (result->IsUndefined(i_isolate)) {
    1395             :     // Do not cache prototype objects.
    1396             :     result = Utils::OpenHandle(
    1397      105900 :         *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true));
    1398             :     i::FunctionTemplateInfo::SetPrototypeTemplate(
    1399       52950 :         i_isolate, Utils::OpenHandle(this), result);
    1400             :   }
    1401      158332 :   return ToApiHandle<ObjectTemplate>(result);
    1402             : }
    1403             : 
    1404           5 : void FunctionTemplate::SetPrototypeProviderTemplate(
    1405             :     Local<FunctionTemplate> prototype_provider) {
    1406             :   i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
    1407             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1408             :   i::Handle<i::Object> result = Utils::OpenHandle(*prototype_provider);
    1409             :   auto info = Utils::OpenHandle(this);
    1410          10 :   CHECK(info->GetPrototypeTemplate()->IsUndefined(i_isolate));
    1411          10 :   CHECK(info->GetParentTemplate()->IsUndefined(i_isolate));
    1412             :   i::FunctionTemplateInfo::SetPrototypeProviderTemplate(i_isolate, info,
    1413           5 :                                                         result);
    1414           5 : }
    1415             : 
    1416     5289179 : static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info,
    1417             :                                   const char* func) {
    1418    10578364 :   Utils::ApiCheck(!info->instantiated(), func,
    1419             :                   "FunctionTemplate already instantiated");
    1420     5289185 : }
    1421             : 
    1422             : 
    1423         239 : void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
    1424             :   auto info = Utils::OpenHandle(this);
    1425         239 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit");
    1426             :   i::Isolate* i_isolate = info->GetIsolate();
    1427             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1428         478 :   CHECK(info->GetPrototypeProviderTemplate()->IsUndefined(i_isolate));
    1429         239 :   i::FunctionTemplateInfo::SetParentTemplate(i_isolate, info,
    1430         239 :                                              Utils::OpenHandle(*value));
    1431         239 : }
    1432             : 
    1433     3599034 : static Local<FunctionTemplate> FunctionTemplateNew(
    1434             :     i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
    1435             :     v8::Local<Signature> signature, int length, bool do_not_cache,
    1436             :     v8::Local<Private> cached_property_name = v8::Local<Private>(),
    1437             :     SideEffectType side_effect_type = SideEffectType::kHasSideEffect) {
    1438             :   i::Handle<i::Struct> struct_obj = isolate->factory()->NewStruct(
    1439     3599034 :       i::FUNCTION_TEMPLATE_INFO_TYPE, i::AllocationType::kOld);
    1440             :   i::Handle<i::FunctionTemplateInfo> obj =
    1441             :       i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
    1442     3599037 :   InitializeFunctionTemplate(obj);
    1443     7198064 :   obj->set_do_not_cache(do_not_cache);
    1444             :   int next_serial_number = i::FunctionTemplateInfo::kInvalidSerialNumber;
    1445     3599034 :   if (!do_not_cache) {
    1446             :     next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
    1447             :   }
    1448     7198068 :   obj->set_serial_number(i::Smi::FromInt(next_serial_number));
    1449     3599036 :   if (callback != nullptr) {
    1450     3485353 :     Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type);
    1451             :   }
    1452             :   obj->set_length(length);
    1453     3599032 :   obj->set_undetectable(false);
    1454     3599030 :   obj->set_needs_access_check(false);
    1455     3599031 :   obj->set_accept_any_receiver(true);
    1456     3599034 :   if (!signature.IsEmpty()) {
    1457      316254 :     obj->set_signature(*Utils::OpenHandle(*signature));
    1458             :   }
    1459    14396105 :   obj->set_cached_property_name(
    1460             :       cached_property_name.IsEmpty()
    1461             :           ? i::ReadOnlyRoots(isolate).the_hole_value()
    1462     3599034 :           : *Utils::OpenHandle(*cached_property_name));
    1463     3599033 :   return Utils::ToLocal(obj);
    1464             : }
    1465             : 
    1466     3593786 : Local<FunctionTemplate> FunctionTemplate::New(
    1467             :     Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
    1468             :     v8::Local<Signature> signature, int length, ConstructorBehavior behavior,
    1469             :     SideEffectType side_effect_type) {
    1470             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1471             :   // Changes to the environment cannot be captured in the snapshot. Expect no
    1472             :   // function templates when the isolate is created for serialization.
    1473     3593786 :   LOG_API(i_isolate, FunctionTemplate, New);
    1474             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1475             :   auto templ = FunctionTemplateNew(i_isolate, callback, data, signature, length,
    1476     3593786 :                                    false, Local<Private>(), side_effect_type);
    1477     3593793 :   if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
    1478     7187588 :   return templ;
    1479             : }
    1480             : 
    1481          10 : MaybeLocal<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate,
    1482             :                                                             size_t index) {
    1483             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1484             :   i::FixedArray serialized_objects = i_isolate->heap()->serialized_objects();
    1485          10 :   int int_index = static_cast<int>(index);
    1486          10 :   if (int_index < serialized_objects->length()) {
    1487             :     i::Object info = serialized_objects->get(int_index);
    1488           5 :     if (info->IsFunctionTemplateInfo()) {
    1489             :       return Utils::ToLocal(i::Handle<i::FunctionTemplateInfo>(
    1490           5 :           i::FunctionTemplateInfo::cast(info), i_isolate));
    1491             :     }
    1492             :   }
    1493           5 :   return Local<FunctionTemplate>();
    1494             : }
    1495             : 
    1496          30 : Local<FunctionTemplate> FunctionTemplate::NewWithCache(
    1497             :     Isolate* isolate, FunctionCallback callback, Local<Private> cache_property,
    1498             :     Local<Value> data, Local<Signature> signature, int length,
    1499             :     SideEffectType side_effect_type) {
    1500             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1501          30 :   LOG_API(i_isolate, FunctionTemplate, NewWithCache);
    1502             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    1503             :   return FunctionTemplateNew(i_isolate, callback, data, signature, length,
    1504          60 :                              false, cache_property, side_effect_type);
    1505             : }
    1506             : 
    1507       52756 : Local<Signature> Signature::New(Isolate* isolate,
    1508             :                                 Local<FunctionTemplate> receiver) {
    1509       52756 :   return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
    1510             : }
    1511             : 
    1512             : 
    1513          23 : Local<AccessorSignature> AccessorSignature::New(
    1514             :     Isolate* isolate, Local<FunctionTemplate> receiver) {
    1515          23 :   return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
    1516             : }
    1517             : 
    1518             : #define SET_FIELD_WRAPPED(isolate, obj, setter, cdata)        \
    1519             :   do {                                                        \
    1520             :     i::Handle<i::Object> foreign = FromCData(isolate, cdata); \
    1521             :     (obj)->setter(*foreign);                                  \
    1522             :   } while (false)
    1523             : 
    1524     3485382 : void FunctionTemplate::SetCallHandler(FunctionCallback callback,
    1525             :                                       v8::Local<Value> data,
    1526             :                                       SideEffectType side_effect_type) {
    1527             :   auto info = Utils::OpenHandle(this);
    1528     3485382 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
    1529             :   i::Isolate* isolate = info->GetIsolate();
    1530             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1531             :   i::HandleScope scope(isolate);
    1532             :   i::Handle<i::CallHandlerInfo> obj = isolate->factory()->NewCallHandlerInfo(
    1533     3485381 :       side_effect_type == SideEffectType::kHasNoSideEffect);
    1534     6970764 :   SET_FIELD_WRAPPED(isolate, obj, set_callback, callback);
    1535     6970750 :   SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback());
    1536     3485384 :   if (data.IsEmpty()) {
    1537             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1538             :   }
    1539     3485384 :   obj->set_data(*Utils::OpenHandle(*data));
    1540     6970786 :   info->set_call_code(*obj);
    1541     3485381 : }
    1542             : 
    1543             : 
    1544             : namespace {
    1545             : 
    1546             : template <typename Getter, typename Setter>
    1547       61519 : i::Handle<i::AccessorInfo> MakeAccessorInfo(
    1548             :     i::Isolate* isolate, v8::Local<Name> name, Getter getter, Setter setter,
    1549             :     v8::Local<Value> data, v8::AccessControl settings,
    1550             :     v8::Local<AccessorSignature> signature, bool is_special_data_property,
    1551             :     bool replace_on_access) {
    1552       61519 :   i::Handle<i::AccessorInfo> obj = isolate->factory()->NewAccessorInfo();
    1553      123038 :   SET_FIELD_WRAPPED(isolate, obj, set_getter, getter);
    1554             :   DCHECK_IMPLIES(replace_on_access,
    1555             :                  is_special_data_property && setter == nullptr);
    1556       61519 :   if (is_special_data_property && setter == nullptr) {
    1557             :     setter = reinterpret_cast<Setter>(&i::Accessors::ReconfigureToDataProperty);
    1558             :   }
    1559      123038 :   SET_FIELD_WRAPPED(isolate, obj, set_setter, setter);
    1560       61519 :   i::Address redirected = obj->redirected_getter();
    1561       61519 :   if (redirected != i::kNullAddress) {
    1562      122994 :     SET_FIELD_WRAPPED(isolate, obj, set_js_getter, redirected);
    1563             :   }
    1564       61519 :   if (data.IsEmpty()) {
    1565             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1566             :   }
    1567       61519 :   obj->set_data(*Utils::OpenHandle(*data));
    1568      123038 :   obj->set_is_special_data_property(is_special_data_property);
    1569      123038 :   obj->set_replace_on_access(replace_on_access);
    1570             :   i::Handle<i::Name> accessor_name = Utils::OpenHandle(*name);
    1571       61519 :   if (!accessor_name->IsUniqueName()) {
    1572       53434 :     accessor_name = isolate->factory()->InternalizeString(
    1573             :         i::Handle<i::String>::cast(accessor_name));
    1574             :   }
    1575       61519 :   obj->set_name(*accessor_name);
    1576       61556 :   if (settings & ALL_CAN_READ) obj->set_all_can_read(true);
    1577       61535 :   if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true);
    1578       61519 :   obj->set_initial_property_attributes(i::NONE);
    1579       61519 :   if (!signature.IsEmpty()) {
    1580          36 :     obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
    1581             :   }
    1582       61519 :   return obj;
    1583             : }
    1584             : 
    1585             : }  // namespace
    1586             : 
    1587       60226 : Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
    1588             :   i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true);
    1589       60226 :   if (!Utils::ApiCheck(!handle.is_null(),
    1590             :                        "v8::FunctionTemplate::InstanceTemplate()",
    1591             :                        "Reading from empty handle")) {
    1592           0 :     return Local<ObjectTemplate>();
    1593             :   }
    1594             :   i::Isolate* isolate = handle->GetIsolate();
    1595             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1596      120452 :   if (handle->GetInstanceTemplate()->IsUndefined(isolate)) {
    1597             :     Local<ObjectTemplate> templ =
    1598             :         ObjectTemplate::New(isolate, ToApiHandle<FunctionTemplate>(handle));
    1599       53834 :     i::FunctionTemplateInfo::SetInstanceTemplate(isolate, handle,
    1600       53834 :                                                  Utils::OpenHandle(*templ));
    1601             :   }
    1602             :   i::Handle<i::ObjectTemplateInfo> result(
    1603      120452 :       i::ObjectTemplateInfo::cast(handle->GetInstanceTemplate()), isolate);
    1604             :   return Utils::ToLocal(result);
    1605             : }
    1606             : 
    1607             : 
    1608          12 : void FunctionTemplate::SetLength(int length) {
    1609             :   auto info = Utils::OpenHandle(this);
    1610          12 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetLength");
    1611             :   auto isolate = info->GetIsolate();
    1612             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1613             :   info->set_length(length);
    1614          12 : }
    1615             : 
    1616             : 
    1617       52933 : void FunctionTemplate::SetClassName(Local<String> name) {
    1618             :   auto info = Utils::OpenHandle(this);
    1619       52933 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetClassName");
    1620             :   auto isolate = info->GetIsolate();
    1621             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1622      105866 :   info->set_class_name(*Utils::OpenHandle(*name));
    1623       52933 : }
    1624             : 
    1625             : 
    1626           7 : void FunctionTemplate::SetAcceptAnyReceiver(bool value) {
    1627             :   auto info = Utils::OpenHandle(this);
    1628           7 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetAcceptAnyReceiver");
    1629             :   auto isolate = info->GetIsolate();
    1630             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1631          14 :   info->set_accept_any_receiver(value);
    1632           7 : }
    1633             : 
    1634             : 
    1635           0 : void FunctionTemplate::SetHiddenPrototype(bool value) {
    1636             :   auto info = Utils::OpenHandle(this);
    1637           0 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::SetHiddenPrototype");
    1638             :   auto isolate = info->GetIsolate();
    1639             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1640           0 :   info->set_hidden_prototype(value);
    1641           0 : }
    1642             : 
    1643             : 
    1644     1744061 : void FunctionTemplate::ReadOnlyPrototype() {
    1645             :   auto info = Utils::OpenHandle(this);
    1646     1744061 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::ReadOnlyPrototype");
    1647             :   auto isolate = info->GetIsolate();
    1648             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1649     1744066 :   info->set_read_only_prototype(true);
    1650     1744067 : }
    1651             : 
    1652             : 
    1653        4884 : void FunctionTemplate::RemovePrototype() {
    1654             :   auto info = Utils::OpenHandle(this);
    1655        4884 :   EnsureNotInstantiated(info, "v8::FunctionTemplate::RemovePrototype");
    1656             :   auto isolate = info->GetIsolate();
    1657             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1658        4884 :   info->set_remove_prototype(true);
    1659        4884 : }
    1660             : 
    1661             : 
    1662             : // --- O b j e c t T e m p l a t e ---
    1663             : 
    1664             : 
    1665      673623 : Local<ObjectTemplate> ObjectTemplate::New(
    1666             :     Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
    1667      673627 :   return New(reinterpret_cast<i::Isolate*>(isolate), constructor);
    1668             : }
    1669             : 
    1670             : 
    1671      836190 : static Local<ObjectTemplate> ObjectTemplateNew(
    1672             :     i::Isolate* isolate, v8::Local<FunctionTemplate> constructor,
    1673             :     bool do_not_cache) {
    1674      836190 :   LOG_API(isolate, ObjectTemplate, New);
    1675             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1676             :   i::Handle<i::Struct> struct_obj = isolate->factory()->NewStruct(
    1677      836191 :       i::OBJECT_TEMPLATE_INFO_TYPE, i::AllocationType::kOld);
    1678             :   i::Handle<i::ObjectTemplateInfo> obj =
    1679             :       i::Handle<i::ObjectTemplateInfo>::cast(struct_obj);
    1680      836192 :   InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
    1681             :   int next_serial_number = 0;
    1682      836193 :   if (!do_not_cache) {
    1683             :     next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
    1684             :   }
    1685     1672386 :   obj->set_serial_number(i::Smi::FromInt(next_serial_number));
    1686      836194 :   if (!constructor.IsEmpty())
    1687      108382 :     obj->set_constructor(*Utils::OpenHandle(*constructor));
    1688      836194 :   obj->set_data(i::Smi::kZero);
    1689      836193 :   return Utils::ToLocal(obj);
    1690             : }
    1691             : 
    1692           0 : Local<ObjectTemplate> ObjectTemplate::New(
    1693             :     i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) {
    1694      783239 :   return ObjectTemplateNew(isolate, constructor, false);
    1695             : }
    1696             : 
    1697          10 : MaybeLocal<ObjectTemplate> ObjectTemplate::FromSnapshot(Isolate* isolate,
    1698             :                                                         size_t index) {
    1699             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    1700             :   i::FixedArray serialized_objects = i_isolate->heap()->serialized_objects();
    1701          10 :   int int_index = static_cast<int>(index);
    1702          10 :   if (int_index < serialized_objects->length()) {
    1703             :     i::Object info = serialized_objects->get(int_index);
    1704           5 :     if (info->IsObjectTemplateInfo()) {
    1705             :       return Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>(
    1706           5 :           i::ObjectTemplateInfo::cast(info), i_isolate));
    1707             :     }
    1708             :   }
    1709           5 :   return Local<ObjectTemplate>();
    1710             : }
    1711             : 
    1712             : // Ensure that the object template has a constructor.  If no
    1713             : // constructor is available we create one.
    1714      166332 : static i::Handle<i::FunctionTemplateInfo> EnsureConstructor(
    1715             :     i::Isolate* isolate,
    1716             :     ObjectTemplate* object_template) {
    1717             :   i::Object obj = Utils::OpenHandle(object_template)->constructor();
    1718      166332 :   if (!obj->IsUndefined(isolate)) {
    1719             :     i::FunctionTemplateInfo info = i::FunctionTemplateInfo::cast(obj);
    1720       54148 :     return i::Handle<i::FunctionTemplateInfo>(info, isolate);
    1721             :   }
    1722             :   Local<FunctionTemplate> templ =
    1723      112184 :       FunctionTemplate::New(reinterpret_cast<Isolate*>(isolate));
    1724             :   i::Handle<i::FunctionTemplateInfo> constructor = Utils::OpenHandle(*templ);
    1725      112184 :   i::FunctionTemplateInfo::SetInstanceTemplate(
    1726      112184 :       isolate, constructor, Utils::OpenHandle(object_template));
    1727      224368 :   Utils::OpenHandle(object_template)->set_constructor(*constructor);
    1728      112184 :   return constructor;
    1729             : }
    1730             : 
    1731             : template <typename Getter, typename Setter, typename Data, typename Template>
    1732       53609 : static void TemplateSetAccessor(
    1733             :     Template* template_obj, v8::Local<Name> name, Getter getter, Setter setter,
    1734             :     Data data, AccessControl settings, PropertyAttribute attribute,
    1735             :     v8::Local<AccessorSignature> signature, bool is_special_data_property,
    1736             :     bool replace_on_access, SideEffectType getter_side_effect_type,
    1737             :     SideEffectType setter_side_effect_type) {
    1738             :   auto info = Utils::OpenHandle(template_obj);
    1739             :   auto isolate = info->GetIsolate();
    1740             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1741             :   i::HandleScope scope(isolate);
    1742             :   i::Handle<i::AccessorInfo> accessor_info =
    1743       53609 :       MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature,
    1744       53609 :                        is_special_data_property, replace_on_access);
    1745       53609 :   accessor_info->set_initial_property_attributes(
    1746             :       static_cast<i::PropertyAttributes>(attribute));
    1747       53609 :   accessor_info->set_getter_side_effect_type(getter_side_effect_type);
    1748       53609 :   accessor_info->set_setter_side_effect_type(setter_side_effect_type);
    1749       53609 :   i::ApiNatives::AddNativeDataProperty(isolate, info, accessor_info);
    1750       53609 : }
    1751             : 
    1752         179 : void Template::SetNativeDataProperty(
    1753             :     v8::Local<String> name, AccessorGetterCallback getter,
    1754             :     AccessorSetterCallback setter, v8::Local<Value> data,
    1755             :     PropertyAttribute attribute, v8::Local<AccessorSignature> signature,
    1756             :     AccessControl settings, SideEffectType getter_side_effect_type,
    1757             :     SideEffectType setter_side_effect_type) {
    1758         179 :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1759             :                       signature, true, false, getter_side_effect_type,
    1760         179 :                       setter_side_effect_type);
    1761         179 : }
    1762             : 
    1763          10 : void Template::SetNativeDataProperty(
    1764             :     v8::Local<Name> name, AccessorNameGetterCallback getter,
    1765             :     AccessorNameSetterCallback setter, v8::Local<Value> data,
    1766             :     PropertyAttribute attribute, v8::Local<AccessorSignature> signature,
    1767             :     AccessControl settings, SideEffectType getter_side_effect_type,
    1768             :     SideEffectType setter_side_effect_type) {
    1769             :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1770             :                       signature, true, false, getter_side_effect_type,
    1771          10 :                       setter_side_effect_type);
    1772          10 : }
    1773             : 
    1774          10 : void Template::SetLazyDataProperty(v8::Local<Name> name,
    1775             :                                    AccessorNameGetterCallback getter,
    1776             :                                    v8::Local<Value> data,
    1777             :                                    PropertyAttribute attribute,
    1778             :                                    SideEffectType getter_side_effect_type,
    1779             :                                    SideEffectType setter_side_effect_type) {
    1780          10 :   TemplateSetAccessor(this, name, getter,
    1781             :                       static_cast<AccessorNameSetterCallback>(nullptr), data,
    1782             :                       DEFAULT, attribute, Local<AccessorSignature>(), true,
    1783          10 :                       true, getter_side_effect_type, setter_side_effect_type);
    1784          10 : }
    1785             : 
    1786          55 : void Template::SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
    1787             :                                         PropertyAttribute attribute) {
    1788             :   auto templ = Utils::OpenHandle(this);
    1789             :   i::Isolate* isolate = templ->GetIsolate();
    1790             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1791             :   i::HandleScope scope(isolate);
    1792             :   i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
    1793             :                                  intrinsic,
    1794          55 :                                  static_cast<i::PropertyAttributes>(attribute));
    1795          55 : }
    1796             : 
    1797       53316 : void ObjectTemplate::SetAccessor(v8::Local<String> name,
    1798             :                                  AccessorGetterCallback getter,
    1799             :                                  AccessorSetterCallback setter,
    1800             :                                  v8::Local<Value> data, AccessControl settings,
    1801             :                                  PropertyAttribute attribute,
    1802             :                                  v8::Local<AccessorSignature> signature,
    1803             :                                  SideEffectType getter_side_effect_type,
    1804             :                                  SideEffectType setter_side_effect_type) {
    1805      106632 :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1806             :                       signature, i::FLAG_disable_old_api_accessors, false,
    1807       53316 :                       getter_side_effect_type, setter_side_effect_type);
    1808       53316 : }
    1809             : 
    1810          94 : void ObjectTemplate::SetAccessor(v8::Local<Name> name,
    1811             :                                  AccessorNameGetterCallback getter,
    1812             :                                  AccessorNameSetterCallback setter,
    1813             :                                  v8::Local<Value> data, AccessControl settings,
    1814             :                                  PropertyAttribute attribute,
    1815             :                                  v8::Local<AccessorSignature> signature,
    1816             :                                  SideEffectType getter_side_effect_type,
    1817             :                                  SideEffectType setter_side_effect_type) {
    1818          94 :   TemplateSetAccessor(this, name, getter, setter, data, settings, attribute,
    1819             :                       signature, i::FLAG_disable_old_api_accessors, false,
    1820          94 :                       getter_side_effect_type, setter_side_effect_type);
    1821          94 : }
    1822             : 
    1823             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1824             :           typename Deleter, typename Enumerator, typename Definer>
    1825        1225 : static i::Handle<i::InterceptorInfo> CreateInterceptorInfo(
    1826             :     i::Isolate* isolate, Getter getter, Setter setter, Query query,
    1827             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1828             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1829        1225 :   auto obj = i::Handle<i::InterceptorInfo>::cast(isolate->factory()->NewStruct(
    1830             :       i::INTERCEPTOR_INFO_TYPE, i::AllocationType::kOld));
    1831             :   obj->set_flags(0);
    1832             : 
    1833        2226 :   if (getter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_getter, getter);
    1834        1652 :   if (setter != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_setter, setter);
    1835        1485 :   if (query != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_query, query);
    1836        1225 :   if (descriptor != nullptr)
    1837          60 :     SET_FIELD_WRAPPED(isolate, obj, set_descriptor, descriptor);
    1838        1309 :   if (remover != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_deleter, remover);
    1839        1225 :   if (enumerator != nullptr)
    1840         322 :     SET_FIELD_WRAPPED(isolate, obj, set_enumerator, enumerator);
    1841        1315 :   if (definer != nullptr) SET_FIELD_WRAPPED(isolate, obj, set_definer, definer);
    1842        2450 :   obj->set_can_intercept_symbols(
    1843             :       !(static_cast<int>(flags) &
    1844             :         static_cast<int>(PropertyHandlerFlags::kOnlyInterceptStrings)));
    1845        2450 :   obj->set_all_can_read(static_cast<int>(flags) &
    1846             :                         static_cast<int>(PropertyHandlerFlags::kAllCanRead));
    1847        2450 :   obj->set_non_masking(static_cast<int>(flags) &
    1848             :                        static_cast<int>(PropertyHandlerFlags::kNonMasking));
    1849        2450 :   obj->set_has_no_side_effect(
    1850             :       static_cast<int>(flags) &
    1851             :       static_cast<int>(PropertyHandlerFlags::kHasNoSideEffect));
    1852             : 
    1853        1225 :   if (data.IsEmpty()) {
    1854             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1855             :   }
    1856        1225 :   obj->set_data(*Utils::OpenHandle(*data));
    1857        1225 :   return obj;
    1858             : }
    1859             : 
    1860             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1861             :           typename Deleter, typename Enumerator, typename Definer>
    1862         977 : static i::Handle<i::InterceptorInfo> CreateNamedInterceptorInfo(
    1863             :     i::Isolate* isolate, Getter getter, Setter setter, Query query,
    1864             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1865             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1866             :   auto interceptor =
    1867             :       CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover,
    1868         977 :                             enumerator, definer, data, flags);
    1869         977 :   interceptor->set_is_named(true);
    1870         977 :   return interceptor;
    1871             : }
    1872             : 
    1873             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1874             :           typename Deleter, typename Enumerator, typename Definer>
    1875         248 : static i::Handle<i::InterceptorInfo> CreateIndexedInterceptorInfo(
    1876             :     i::Isolate* isolate, Getter getter, Setter setter, Query query,
    1877             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1878             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1879             :   auto interceptor =
    1880             :       CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover,
    1881         248 :                             enumerator, definer, data, flags);
    1882         248 :   interceptor->set_is_named(false);
    1883         248 :   return interceptor;
    1884             : }
    1885             : 
    1886             : template <typename Getter, typename Setter, typename Query, typename Descriptor,
    1887             :           typename Deleter, typename Enumerator, typename Definer>
    1888         946 : static void ObjectTemplateSetNamedPropertyHandler(
    1889             :     ObjectTemplate* templ, Getter getter, Setter setter, Query query,
    1890             :     Descriptor descriptor, Deleter remover, Enumerator enumerator,
    1891             :     Definer definer, Local<Value> data, PropertyHandlerFlags flags) {
    1892             :   i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate();
    1893             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1894             :   i::HandleScope scope(isolate);
    1895         946 :   auto cons = EnsureConstructor(isolate, templ);
    1896         946 :   EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler");
    1897             :   auto obj =
    1898             :       CreateNamedInterceptorInfo(isolate, getter, setter, query, descriptor,
    1899         946 :                                  remover, enumerator, definer, data, flags);
    1900         946 :   i::FunctionTemplateInfo::SetNamedPropertyHandler(isolate, cons, obj);
    1901         946 : }
    1902             : 
    1903         946 : void ObjectTemplate::SetHandler(
    1904             :     const NamedPropertyHandlerConfiguration& config) {
    1905             :   ObjectTemplateSetNamedPropertyHandler(
    1906         946 :       this, config.getter, config.setter, config.query, config.descriptor,
    1907         946 :       config.deleter, config.enumerator, config.definer, config.data,
    1908        1892 :       config.flags);
    1909         946 : }
    1910             : 
    1911             : 
    1912         149 : void ObjectTemplate::MarkAsUndetectable() {
    1913             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1914             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1915             :   i::HandleScope scope(isolate);
    1916         149 :   auto cons = EnsureConstructor(isolate, this);
    1917         149 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::MarkAsUndetectable");
    1918         149 :   cons->set_undetectable(true);
    1919         149 : }
    1920             : 
    1921             : 
    1922         134 : void ObjectTemplate::SetAccessCheckCallback(AccessCheckCallback callback,
    1923             :                                             Local<Value> data) {
    1924             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1925             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1926             :   i::HandleScope scope(isolate);
    1927         134 :   auto cons = EnsureConstructor(isolate, this);
    1928         134 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetAccessCheckCallback");
    1929             : 
    1930             :   i::Handle<i::Struct> struct_info = isolate->factory()->NewStruct(
    1931         134 :       i::ACCESS_CHECK_INFO_TYPE, i::AllocationType::kOld);
    1932             :   i::Handle<i::AccessCheckInfo> info =
    1933             :       i::Handle<i::AccessCheckInfo>::cast(struct_info);
    1934             : 
    1935         268 :   SET_FIELD_WRAPPED(isolate, info, set_callback, callback);
    1936         134 :   info->set_named_interceptor(i::Object());
    1937         134 :   info->set_indexed_interceptor(i::Object());
    1938             : 
    1939         134 :   if (data.IsEmpty()) {
    1940             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1941             :   }
    1942         134 :   info->set_data(*Utils::OpenHandle(*data));
    1943             : 
    1944         134 :   i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info);
    1945         134 :   cons->set_needs_access_check(true);
    1946         134 : }
    1947             : 
    1948          31 : void ObjectTemplate::SetAccessCheckCallbackAndHandler(
    1949             :     AccessCheckCallback callback,
    1950             :     const NamedPropertyHandlerConfiguration& named_handler,
    1951             :     const IndexedPropertyHandlerConfiguration& indexed_handler,
    1952             :     Local<Value> data) {
    1953             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1954             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1955             :   i::HandleScope scope(isolate);
    1956          31 :   auto cons = EnsureConstructor(isolate, this);
    1957             :   EnsureNotInstantiated(
    1958          31 :       cons, "v8::ObjectTemplate::SetAccessCheckCallbackWithHandler");
    1959             : 
    1960             :   i::Handle<i::Struct> struct_info = isolate->factory()->NewStruct(
    1961          31 :       i::ACCESS_CHECK_INFO_TYPE, i::AllocationType::kOld);
    1962             :   i::Handle<i::AccessCheckInfo> info =
    1963             :       i::Handle<i::AccessCheckInfo>::cast(struct_info);
    1964             : 
    1965          62 :   SET_FIELD_WRAPPED(isolate, info, set_callback, callback);
    1966             :   auto named_interceptor = CreateNamedInterceptorInfo(
    1967          31 :       isolate, named_handler.getter, named_handler.setter, named_handler.query,
    1968          31 :       named_handler.descriptor, named_handler.deleter, named_handler.enumerator,
    1969          62 :       named_handler.definer, named_handler.data, named_handler.flags);
    1970          62 :   info->set_named_interceptor(*named_interceptor);
    1971             :   auto indexed_interceptor = CreateIndexedInterceptorInfo(
    1972          31 :       isolate, indexed_handler.getter, indexed_handler.setter,
    1973          31 :       indexed_handler.query, indexed_handler.descriptor,
    1974          31 :       indexed_handler.deleter, indexed_handler.enumerator,
    1975          62 :       indexed_handler.definer, indexed_handler.data, indexed_handler.flags);
    1976          62 :   info->set_indexed_interceptor(*indexed_interceptor);
    1977             : 
    1978          31 :   if (data.IsEmpty()) {
    1979             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    1980             :   }
    1981          31 :   info->set_data(*Utils::OpenHandle(*data));
    1982             : 
    1983          31 :   i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info);
    1984          31 :   cons->set_needs_access_check(true);
    1985          31 : }
    1986             : 
    1987         217 : void ObjectTemplate::SetHandler(
    1988             :     const IndexedPropertyHandlerConfiguration& config) {
    1989             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    1990             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    1991             :   i::HandleScope scope(isolate);
    1992         217 :   auto cons = EnsureConstructor(isolate, this);
    1993         217 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler");
    1994             :   auto obj = CreateIndexedInterceptorInfo(
    1995         217 :       isolate, config.getter, config.setter, config.query, config.descriptor,
    1996         217 :       config.deleter, config.enumerator, config.definer, config.data,
    1997         434 :       config.flags);
    1998         217 :   i::FunctionTemplateInfo::SetIndexedPropertyHandler(isolate, cons, obj);
    1999         217 : }
    2000             : 
    2001         197 : void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback,
    2002             :                                               Local<Value> data) {
    2003             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2004             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2005             :   i::HandleScope scope(isolate);
    2006         197 :   auto cons = EnsureConstructor(isolate, this);
    2007         197 :   EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetCallAsFunctionHandler");
    2008         197 :   i::Handle<i::CallHandlerInfo> obj = isolate->factory()->NewCallHandlerInfo();
    2009         394 :   SET_FIELD_WRAPPED(isolate, obj, set_callback, callback);
    2010         394 :   SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback());
    2011         197 :   if (data.IsEmpty()) {
    2012             :     data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    2013             :   }
    2014         197 :   obj->set_data(*Utils::OpenHandle(*data));
    2015         197 :   i::FunctionTemplateInfo::SetInstanceCallHandler(isolate, cons, obj);
    2016         197 : }
    2017             : 
    2018       55755 : int ObjectTemplate::InternalFieldCount() {
    2019       55755 :   return Utils::OpenHandle(this)->embedder_field_count();
    2020             : }
    2021             : 
    2022      108829 : void ObjectTemplate::SetInternalFieldCount(int value) {
    2023             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2024      108829 :   if (!Utils::ApiCheck(i::Smi::IsValid(value),
    2025             :                        "v8::ObjectTemplate::SetInternalFieldCount()",
    2026             :                        "Invalid embedder field count")) {
    2027             :     return;
    2028             :   }
    2029             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2030      108829 :   if (value > 0) {
    2031             :     // The embedder field count is set by the constructor function's
    2032             :     // construct code, so we ensure that there is a constructor
    2033             :     // function to do the setting.
    2034       53068 :     EnsureConstructor(isolate, this);
    2035             :   }
    2036      108829 :   Utils::OpenHandle(this)->set_embedder_field_count(value);
    2037             : }
    2038             : 
    2039           0 : bool ObjectTemplate::IsImmutableProto() {
    2040           0 :   return Utils::OpenHandle(this)->immutable_proto();
    2041             : }
    2042             : 
    2043          18 : void ObjectTemplate::SetImmutableProto() {
    2044             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2045             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2046          18 :   Utils::OpenHandle(this)->set_immutable_proto(true);
    2047          18 : }
    2048             : 
    2049             : // --- S c r i p t s ---
    2050             : 
    2051             : 
    2052             : // Internally, UnboundScript is a SharedFunctionInfo, and Script is a
    2053             : // JSFunction.
    2054             : 
    2055         712 : ScriptCompiler::CachedData::CachedData(const uint8_t* data_, int length_,
    2056             :                                        BufferPolicy buffer_policy_)
    2057             :     : data(data_),
    2058             :       length(length_),
    2059             :       rejected(false),
    2060         712 :       buffer_policy(buffer_policy_) {}
    2061             : 
    2062             : 
    2063        1424 : ScriptCompiler::CachedData::~CachedData() {
    2064         712 :   if (buffer_policy == BufferOwned) {
    2065         702 :     delete[] data;
    2066             :   }
    2067         712 : }
    2068             : 
    2069           0 : bool ScriptCompiler::ExternalSourceStream::SetBookmark() { return false; }
    2070             : 
    2071           0 : void ScriptCompiler::ExternalSourceStream::ResetToBookmark() { UNREACHABLE(); }
    2072             : 
    2073           0 : ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream,
    2074             :                                                Encoding encoding)
    2075           0 :     : StreamedSource(std::unique_ptr<ExternalSourceStream>(stream), encoding) {}
    2076             : 
    2077       13231 : ScriptCompiler::StreamedSource::StreamedSource(
    2078             :     std::unique_ptr<ExternalSourceStream> stream, Encoding encoding)
    2079       26462 :     : impl_(new i::ScriptStreamingData(std::move(stream), encoding)) {}
    2080             : 
    2081             : ScriptCompiler::StreamedSource::~StreamedSource() = default;
    2082             : 
    2083      269835 : Local<Script> UnboundScript::BindToCurrentContext() {
    2084             :   auto function_info =
    2085             :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2086             :   i::Isolate* isolate = function_info->GetIsolate();
    2087             :   i::Handle<i::JSFunction> function =
    2088             :       isolate->factory()->NewFunctionFromSharedFunctionInfo(
    2089      539670 :           function_info, isolate->native_context());
    2090      269835 :   return ToApiHandle<Script>(function);
    2091             : }
    2092             : 
    2093         261 : int UnboundScript::GetId() {
    2094             :   auto function_info =
    2095             :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2096             :   i::Isolate* isolate = function_info->GetIsolate();
    2097         261 :   LOG_API(isolate, UnboundScript, GetId);
    2098             :   i::HandleScope scope(isolate);
    2099             :   i::Handle<i::Script> script(i::Script::cast(function_info->script()),
    2100         522 :                               isolate);
    2101         261 :   return script->id();
    2102             : }
    2103             : 
    2104             : 
    2105           5 : int UnboundScript::GetLineNumber(int code_pos) {
    2106             :   i::Handle<i::SharedFunctionInfo> obj =
    2107             :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2108             :   i::Isolate* isolate = obj->GetIsolate();
    2109           5 :   LOG_API(isolate, UnboundScript, GetLineNumber);
    2110          10 :   if (obj->script()->IsScript()) {
    2111          10 :     i::Handle<i::Script> script(i::Script::cast(obj->script()), isolate);
    2112           5 :     return i::Script::GetLineNumber(script, code_pos);
    2113             :   } else {
    2114             :     return -1;
    2115             :   }
    2116             : }
    2117             : 
    2118             : 
    2119           5 : Local<Value> UnboundScript::GetScriptName() {
    2120             :   i::Handle<i::SharedFunctionInfo> obj =
    2121             :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2122             :   i::Isolate* isolate = obj->GetIsolate();
    2123           5 :   LOG_API(isolate, UnboundScript, GetName);
    2124          10 :   if (obj->script()->IsScript()) {
    2125          10 :     i::Object name = i::Script::cast(obj->script())->name();
    2126             :     return Utils::ToLocal(i::Handle<i::Object>(name, isolate));
    2127             :   } else {
    2128           0 :     return Local<String>();
    2129             :   }
    2130             : }
    2131             : 
    2132             : 
    2133         155 : Local<Value> UnboundScript::GetSourceURL() {
    2134             :   i::Handle<i::SharedFunctionInfo> obj =
    2135             :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2136             :   i::Isolate* isolate = obj->GetIsolate();
    2137         155 :   LOG_API(isolate, UnboundScript, GetSourceURL);
    2138         310 :   if (obj->script()->IsScript()) {
    2139         310 :     i::Object url = i::Script::cast(obj->script())->source_url();
    2140             :     return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
    2141             :   } else {
    2142           0 :     return Local<String>();
    2143             :   }
    2144             : }
    2145             : 
    2146             : 
    2147         155 : Local<Value> UnboundScript::GetSourceMappingURL() {
    2148             :   i::Handle<i::SharedFunctionInfo> obj =
    2149             :       i::Handle<i::SharedFunctionInfo>::cast(Utils::OpenHandle(this));
    2150             :   i::Isolate* isolate = obj->GetIsolate();
    2151         155 :   LOG_API(isolate, UnboundScript, GetSourceMappingURL);
    2152         310 :   if (obj->script()->IsScript()) {
    2153         310 :     i::Object url = i::Script::cast(obj->script())->source_mapping_url();
    2154             :     return Utils::ToLocal(i::Handle<i::Object>(url, isolate));
    2155             :   } else {
    2156           0 :     return Local<String>();
    2157             :   }
    2158             : }
    2159             : 
    2160             : 
    2161      267982 : MaybeLocal<Value> Script::Run(Local<Context> context) {
    2162             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    2163      535964 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    2164      803946 :   ENTER_V8(isolate, context, Script, Run, MaybeLocal<Value>(),
    2165             :            InternalEscapableScope);
    2166             :   i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true);
    2167             :   i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
    2168             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    2169             :   auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this));
    2170             : 
    2171      267982 :   i::Handle<i::Object> receiver = isolate->global_proxy();
    2172             :   Local<Value> result;
    2173      535964 :   has_pending_exception = !ToLocal<Value>(
    2174             :       i::Execution::Call(isolate, fun, receiver, 0, nullptr), &result);
    2175             : 
    2176      267982 :   RETURN_ON_FAILED_EXECUTION(Value);
    2177      259348 :   RETURN_ESCAPED(result);
    2178             : }
    2179             : 
    2180             : 
    2181         410 : Local<Value> ScriptOrModule::GetResourceName() {
    2182             :   i::Handle<i::Script> obj = Utils::OpenHandle(this);
    2183             :   i::Isolate* isolate = obj->GetIsolate();
    2184             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2185             :   i::Handle<i::Object> val(obj->name(), isolate);
    2186         410 :   return ToApiHandle<Value>(val);
    2187             : }
    2188             : 
    2189           5 : Local<PrimitiveArray> ScriptOrModule::GetHostDefinedOptions() {
    2190             :   i::Handle<i::Script> obj = Utils::OpenHandle(this);
    2191             :   i::Isolate* isolate = obj->GetIsolate();
    2192             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2193             :   i::Handle<i::FixedArray> val(obj->host_defined_options(), isolate);
    2194           5 :   return ToApiHandle<PrimitiveArray>(val);
    2195             : }
    2196             : 
    2197         838 : Local<UnboundScript> Script::GetUnboundScript() {
    2198             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    2199             :   i::SharedFunctionInfo sfi = i::JSFunction::cast(*obj)->shared();
    2200             :   i::Isolate* isolate = sfi->GetIsolate();
    2201         838 :   return ToApiHandle<UnboundScript>(i::handle(sfi, isolate));
    2202             : }
    2203             : 
    2204             : // static
    2205          11 : Local<PrimitiveArray> PrimitiveArray::New(Isolate* v8_isolate, int length) {
    2206             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2207             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2208             :   Utils::ApiCheck(length >= 0, "v8::PrimitiveArray::New",
    2209             :                   "length must be equal or greater than zero");
    2210          11 :   i::Handle<i::FixedArray> array = isolate->factory()->NewFixedArray(length);
    2211          11 :   return ToApiHandle<PrimitiveArray>(array);
    2212             : }
    2213             : 
    2214           5 : int PrimitiveArray::Length() const {
    2215             :   i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
    2216           5 :   return array->length();
    2217             : }
    2218             : 
    2219          31 : void PrimitiveArray::Set(Isolate* v8_isolate, int index,
    2220             :                          Local<Primitive> item) {
    2221             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2222             :   i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
    2223             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2224          62 :   Utils::ApiCheck(index >= 0 && index < array->length(),
    2225             :                   "v8::PrimitiveArray::Set",
    2226             :                   "index must be greater than or equal to 0 and less than the "
    2227             :                   "array length");
    2228             :   i::Handle<i::Object> i_item = Utils::OpenHandle(*item);
    2229          31 :   array->set(index, *i_item);
    2230          31 : }
    2231             : 
    2232         117 : Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
    2233             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2234             :   i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
    2235             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2236         234 :   Utils::ApiCheck(index >= 0 && index < array->length(),
    2237             :                   "v8::PrimitiveArray::Get",
    2238             :                   "index must be greater than or equal to 0 and less than the "
    2239             :                   "array length");
    2240             :   i::Handle<i::Object> i_item(array->get(index), isolate);
    2241         117 :   return ToApiHandle<Primitive>(i_item);
    2242             : }
    2243             : 
    2244        1036 : Module::Status Module::GetStatus() const {
    2245             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2246        1036 :   switch (self->status()) {
    2247             :     case i::Module::kUninstantiated:
    2248             :     case i::Module::kPreInstantiating:
    2249             :       return kUninstantiated;
    2250             :     case i::Module::kInstantiating:
    2251           0 :       return kInstantiating;
    2252             :     case i::Module::kInstantiated:
    2253         220 :       return kInstantiated;
    2254             :     case i::Module::kEvaluating:
    2255           0 :       return kEvaluating;
    2256             :     case i::Module::kEvaluated:
    2257         561 :       return kEvaluated;
    2258             :     case i::Module::kErrored:
    2259          20 :       return kErrored;
    2260             :   }
    2261           0 :   UNREACHABLE();
    2262             : }
    2263             : 
    2264          10 : Local<Value> Module::GetException() const {
    2265          10 :   Utils::ApiCheck(GetStatus() == kErrored, "v8::Module::GetException",
    2266             :                   "Module status must be kErrored");
    2267             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2268             :   i::Isolate* isolate = self->GetIsolate();
    2269          20 :   return ToApiHandle<Value>(i::handle(self->GetException(), isolate));
    2270             : }
    2271             : 
    2272        1387 : int Module::GetModuleRequestsLength() const {
    2273             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2274        2774 :   return self->info()->module_requests()->length();
    2275             : }
    2276             : 
    2277        1003 : Local<String> Module::GetModuleRequest(int i) const {
    2278        1003 :   CHECK_GE(i, 0);
    2279             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2280             :   i::Isolate* isolate = self->GetIsolate();
    2281        2006 :   i::Handle<i::FixedArray> module_requests(self->info()->module_requests(),
    2282             :                                            isolate);
    2283        1003 :   CHECK_LT(i, module_requests->length());
    2284        1003 :   return ToApiHandle<String>(i::handle(module_requests->get(i), isolate));
    2285             : }
    2286             : 
    2287          10 : Location Module::GetModuleRequestLocation(int i) const {
    2288          10 :   CHECK_GE(i, 0);
    2289             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2290             :   i::HandleScope scope(isolate);
    2291             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2292             :   i::Handle<i::FixedArray> module_request_positions(
    2293          20 :       self->info()->module_request_positions(), isolate);
    2294          10 :   CHECK_LT(i, module_request_positions->length());
    2295             :   int position = i::Smi::ToInt(module_request_positions->get(i));
    2296             :   i::Handle<i::Script> script(self->script(), isolate);
    2297             :   i::Script::PositionInfo info;
    2298          10 :   i::Script::GetPositionInfo(script, position, &info, i::Script::WITH_OFFSET);
    2299          20 :   return v8::Location(info.line, info.column);
    2300             : }
    2301             : 
    2302         226 : Local<Value> Module::GetModuleNamespace() {
    2303         226 :   Utils::ApiCheck(
    2304         226 :       GetStatus() >= kInstantiated, "v8::Module::GetModuleNamespace",
    2305             :       "v8::Module::GetModuleNamespace must be used on an instantiated module");
    2306             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2307             :   i::Handle<i::JSModuleNamespace> module_namespace =
    2308         226 :       i::Module::GetModuleNamespace(self->GetIsolate(), self);
    2309         226 :   return ToApiHandle<Value>(module_namespace);
    2310             : }
    2311             : 
    2312          20 : Local<UnboundModuleScript> Module::GetUnboundModuleScript() {
    2313          20 :   Utils::ApiCheck(
    2314          20 :       GetStatus() < kEvaluating, "v8::Module::GetUnboundScript",
    2315             :       "v8::Module::GetUnboundScript must be used on an unevaluated module");
    2316             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2317             :   return ToApiHandle<UnboundModuleScript>(i::Handle<i::SharedFunctionInfo>(
    2318          40 :       self->GetSharedFunctionInfo(), self->GetIsolate()));
    2319             : }
    2320             : 
    2321        4804 : int Module::GetIdentityHash() const { return Utils::OpenHandle(this)->hash(); }
    2322             : 
    2323        1187 : Maybe<bool> Module::InstantiateModule(Local<Context> context,
    2324             :                                       Module::ResolveCallback callback) {
    2325             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    2326        3561 :   ENTER_V8(isolate, context, Module, InstantiateModule, Nothing<bool>(),
    2327             :            i::HandleScope);
    2328        1187 :   has_pending_exception = !i::Module::Instantiate(
    2329             :       isolate, Utils::OpenHandle(this), context, callback);
    2330        1187 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    2331             :   return Just(true);
    2332             : }
    2333             : 
    2334        1225 : MaybeLocal<Value> Module::Evaluate(Local<Context> context) {
    2335             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    2336        2450 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    2337        3675 :   ENTER_V8(isolate, context, Module, Evaluate, MaybeLocal<Value>(),
    2338             :            InternalEscapableScope);
    2339             :   i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true);
    2340             :   i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy());
    2341             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    2342             : 
    2343             :   i::Handle<i::Module> self = Utils::OpenHandle(this);
    2344             :   // It's an API error to call Evaluate before Instantiate.
    2345        1225 :   CHECK_GE(self->status(), i::Module::kInstantiated);
    2346             : 
    2347             :   Local<Value> result;
    2348        1225 :   has_pending_exception = !ToLocal(i::Module::Evaluate(isolate, self), &result);
    2349        1225 :   RETURN_ON_FAILED_EXECUTION(Value);
    2350        1179 :   RETURN_ESCAPED(result);
    2351             : }
    2352             : 
    2353             : namespace {
    2354             : 
    2355      273670 : i::Compiler::ScriptDetails GetScriptDetails(
    2356             :     i::Isolate* isolate, Local<Value> resource_name,
    2357             :     Local<Integer> resource_line_offset, Local<Integer> resource_column_offset,
    2358             :     Local<Value> source_map_url, Local<PrimitiveArray> host_defined_options) {
    2359             :   i::Compiler::ScriptDetails script_details;
    2360      273670 :   if (!resource_name.IsEmpty()) {
    2361      140472 :     script_details.name_obj = Utils::OpenHandle(*(resource_name));
    2362             :   }
    2363      273670 :   if (!resource_line_offset.IsEmpty()) {
    2364             :     script_details.line_offset =
    2365        4749 :         static_cast<int>(resource_line_offset->Value());
    2366             :   }
    2367      273670 :   if (!resource_column_offset.IsEmpty()) {
    2368             :     script_details.column_offset =
    2369        4728 :         static_cast<int>(resource_column_offset->Value());
    2370             :   }
    2371      273670 :   script_details.host_defined_options = isolate->factory()->empty_fixed_array();
    2372      273670 :   if (!host_defined_options.IsEmpty()) {
    2373             :     script_details.host_defined_options =
    2374           6 :         Utils::OpenHandle(*(host_defined_options));
    2375             :   }
    2376      273670 :   if (!source_map_url.IsEmpty()) {
    2377         954 :     script_details.source_map_url = Utils::OpenHandle(*(source_map_url));
    2378             :   }
    2379      273670 :   return script_details;
    2380             : }
    2381             : 
    2382             : }  // namespace
    2383             : 
    2384      260370 : MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
    2385             :     Isolate* v8_isolate, Source* source, CompileOptions options,
    2386             :     NoCacheReason no_cache_reason) {
    2387             :   auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2388      520740 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
    2389      781090 :   ENTER_V8_NO_SCRIPT(isolate, v8_isolate->GetCurrentContext(), ScriptCompiler,
    2390             :                      CompileUnbound, MaybeLocal<UnboundScript>(),
    2391             :                      InternalEscapableScope);
    2392             : 
    2393             :   i::ScriptData* script_data = nullptr;
    2394      260360 :   if (options == kConsumeCodeCache) {
    2395             :     DCHECK(source->cached_data);
    2396             :     // ScriptData takes care of pointer-aligning the data.
    2397             :     script_data = new i::ScriptData(source->cached_data->data,
    2398         164 :                                     source->cached_data->length);
    2399             :   }
    2400             : 
    2401      260360 :   i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string));
    2402             :   i::Handle<i::SharedFunctionInfo> result;
    2403      781080 :   TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileScript");
    2404             :   i::Compiler::ScriptDetails script_details = GetScriptDetails(
    2405             :       isolate, source->resource_name, source->resource_line_offset,
    2406             :       source->resource_column_offset, source->source_map_url,
    2407      260360 :       source->host_defined_options);
    2408             :   i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
    2409             :       i::Compiler::GetSharedFunctionInfoForScript(
    2410             :           isolate, str, script_details, source->resource_options, nullptr,
    2411      260360 :           script_data, options, no_cache_reason, i::NOT_NATIVES_CODE);
    2412      260360 :   if (options == kConsumeCodeCache) {
    2413         328 :     source->cached_data->rejected = script_data->rejected();
    2414             :   }
    2415      260524 :   delete script_data;
    2416             :   has_pending_exception = !maybe_function_info.ToHandle(&result);
    2417      260360 :   RETURN_ON_FAILED_EXECUTION(UnboundScript);
    2418      258246 :   RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
    2419             : }
    2420             : 
    2421        9222 : MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript(
    2422             :     Isolate* v8_isolate, Source* source, CompileOptions options,
    2423             :     NoCacheReason no_cache_reason) {
    2424             :   Utils::ApiCheck(
    2425             :       !source->GetResourceOptions().IsModule(),
    2426             :       "v8::ScriptCompiler::CompileUnboundScript",
    2427             :       "v8::ScriptCompiler::CompileModule must be used to compile modules");
    2428        9222 :   return CompileUnboundInternal(v8_isolate, source, options, no_cache_reason);
    2429             : }
    2430             : 
    2431      249138 : MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
    2432             :                                            Source* source,
    2433             :                                            CompileOptions options,
    2434             :                                            NoCacheReason no_cache_reason) {
    2435             :   Utils::ApiCheck(
    2436             :       !source->GetResourceOptions().IsModule(), "v8::ScriptCompiler::Compile",
    2437             :       "v8::ScriptCompiler::CompileModule must be used to compile modules");
    2438             :   auto isolate = context->GetIsolate();
    2439             :   auto maybe =
    2440      249138 :       CompileUnboundInternal(isolate, source, options, no_cache_reason);
    2441             :   Local<UnboundScript> result;
    2442      249138 :   if (!maybe.ToLocal(&result)) return MaybeLocal<Script>();
    2443             :   v8::Context::Scope scope(context);
    2444      247211 :   return result->BindToCurrentContext();
    2445             : }
    2446             : 
    2447        2010 : MaybeLocal<Module> ScriptCompiler::CompileModule(
    2448             :     Isolate* isolate, Source* source, CompileOptions options,
    2449             :     NoCacheReason no_cache_reason) {
    2450        2010 :   CHECK(options == kNoCompileOptions || options == kConsumeCodeCache);
    2451             : 
    2452             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    2453             : 
    2454             :   Utils::ApiCheck(source->GetResourceOptions().IsModule(),
    2455             :                   "v8::ScriptCompiler::CompileModule",
    2456             :                   "Invalid ScriptOrigin: is_module must be true");
    2457             :   auto maybe =
    2458        2010 :       CompileUnboundInternal(isolate, source, options, no_cache_reason);
    2459             :   Local<UnboundScript> unbound;
    2460        2010 :   if (!maybe.ToLocal(&unbound)) return MaybeLocal<Module>();
    2461             : 
    2462        1822 :   i::Handle<i::SharedFunctionInfo> shared = Utils::OpenHandle(*unbound);
    2463        1822 :   return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared));
    2464             : }
    2465             : 
    2466             : namespace {
    2467          30 : bool IsIdentifier(i::Isolate* isolate, i::Handle<i::String> string) {
    2468          30 :   string = i::String::Flatten(isolate, string);
    2469             :   const int length = string->length();
    2470          30 :   if (length == 0) return false;
    2471          60 :   if (!i::IsIdentifierStart(string->Get(0))) return false;
    2472             :   i::DisallowHeapAllocation no_gc;
    2473          30 :   i::String::FlatContent flat = string->GetFlatContent(no_gc);
    2474          30 :   if (flat.IsOneByte()) {
    2475             :     auto vector = flat.ToOneByteVector();
    2476          85 :     for (int i = 1; i < length; i++) {
    2477         105 :       if (!i::IsIdentifierPart(vector[i])) return false;
    2478             :     }
    2479             :   } else {
    2480             :     auto vector = flat.ToUC16Vector();
    2481          15 :     for (int i = 1; i < length; i++) {
    2482          15 :       if (!i::IsIdentifierPart(vector[i])) return false;
    2483             :     }
    2484             :   }
    2485             :   return true;
    2486             : }
    2487             : }  // anonymous namespace
    2488             : 
    2489          84 : MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
    2490             :     Local<Context> v8_context, Source* source, size_t arguments_count,
    2491             :     Local<String> arguments[], size_t context_extension_count,
    2492             :     Local<Object> context_extensions[], CompileOptions options,
    2493             :     NoCacheReason no_cache_reason) {
    2494         336 :   PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext,
    2495             :                         Function);
    2496         168 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
    2497             : 
    2498             :   DCHECK(options == CompileOptions::kConsumeCodeCache ||
    2499             :          options == CompileOptions::kEagerCompile ||
    2500             :          options == CompileOptions::kNoCompileOptions);
    2501             : 
    2502             :   i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
    2503             : 
    2504             :   DCHECK(context->IsNativeContext());
    2505             :   i::Handle<i::SharedFunctionInfo> outer_info(
    2506         168 :       context->empty_function()->shared(), isolate);
    2507             : 
    2508             :   i::Handle<i::JSFunction> fun;
    2509             :   i::Handle<i::FixedArray> arguments_list =
    2510          84 :       isolate->factory()->NewFixedArray(static_cast<int>(arguments_count));
    2511         134 :   for (int i = 0; i < static_cast<int>(arguments_count); i++) {
    2512          30 :     i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]);
    2513          30 :     if (!IsIdentifier(isolate, argument)) return Local<Function>();
    2514          50 :     arguments_list->set(i, *argument);
    2515             :   }
    2516             : 
    2517         127 :   for (size_t i = 0; i < context_extension_count; ++i) {
    2518             :     i::Handle<i::JSReceiver> extension =
    2519          24 :         Utils::OpenHandle(*context_extensions[i]);
    2520          24 :     if (!extension->IsJSObject()) return Local<Function>();
    2521             :     context = isolate->factory()->NewWithContext(
    2522             :         context,
    2523             :         i::ScopeInfo::CreateForWithScope(
    2524             :             isolate,
    2525             :             context->IsNativeContext()
    2526             :                 ? i::Handle<i::ScopeInfo>::null()
    2527             :                 : i::Handle<i::ScopeInfo>(context->scope_info(), isolate)),
    2528          53 :         extension);
    2529             :   }
    2530             : 
    2531             :   i::Compiler::ScriptDetails script_details = GetScriptDetails(
    2532             :       isolate, source->resource_name, source->resource_line_offset,
    2533             :       source->resource_column_offset, source->source_map_url,
    2534          79 :       source->host_defined_options);
    2535             : 
    2536             :   i::ScriptData* script_data = nullptr;
    2537          79 :   if (options == kConsumeCodeCache) {
    2538             :     DCHECK(source->cached_data);
    2539             :     // ScriptData takes care of pointer-aligning the data.
    2540             :     script_data = new i::ScriptData(source->cached_data->data,
    2541           5 :                                     source->cached_data->length);
    2542             :   }
    2543             : 
    2544             :   i::Handle<i::JSFunction> result;
    2545             :   has_pending_exception =
    2546         158 :       !i::Compiler::GetWrappedFunction(
    2547             :            Utils::OpenHandle(*source->source_string), arguments_list, context,
    2548             :            script_details, source->resource_options, script_data, options,
    2549             :            no_cache_reason)
    2550             :            .ToHandle(&result);
    2551          79 :   if (options == kConsumeCodeCache) {
    2552          10 :     source->cached_data->rejected = script_data->rejected();
    2553             :   }
    2554          84 :   delete script_data;
    2555          79 :   RETURN_ON_FAILED_EXECUTION(Function);
    2556          69 :   RETURN_ESCAPED(Utils::CallableToLocal(result));
    2557             : }
    2558             : 
    2559       26462 : void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); }
    2560             : 
    2561       13231 : ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript(
    2562             :     Isolate* v8_isolate, StreamedSource* source, CompileOptions options) {
    2563       13231 :   if (!i::FLAG_script_streaming) {
    2564             :     return nullptr;
    2565             :   }
    2566             :   // We don't support other compile options on streaming background compiles.
    2567             :   // TODO(rmcilroy): remove CompileOptions from the API.
    2568       13231 :   CHECK(options == ScriptCompiler::kNoCompileOptions);
    2569       13231 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2570       13231 :   i::ScriptStreamingData* data = source->impl();
    2571             :   std::unique_ptr<i::BackgroundCompileTask> task =
    2572       26462 :       base::make_unique<i::BackgroundCompileTask>(data, isolate);
    2573       13231 :   data->task = std::move(task);
    2574       13231 :   return new ScriptCompiler::ScriptStreamingTask(data);
    2575             : }
    2576             : 
    2577       13231 : MaybeLocal<Script> ScriptCompiler::Compile(Local<Context> context,
    2578             :                                            StreamedSource* v8_source,
    2579             :                                            Local<String> full_source_string,
    2580             :                                            const ScriptOrigin& origin) {
    2581       52924 :   PREPARE_FOR_EXECUTION(context, ScriptCompiler, Compile, Script);
    2582       26462 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.ScriptCompiler");
    2583       39693 :   TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
    2584             :                "V8.CompileStreamedScript");
    2585             : 
    2586       13231 :   i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string));
    2587             :   i::Compiler::ScriptDetails script_details = GetScriptDetails(
    2588             :       isolate, origin.ResourceName(), origin.ResourceLineOffset(),
    2589             :       origin.ResourceColumnOffset(), origin.SourceMapUrl(),
    2590       13231 :       origin.HostDefinedOptions());
    2591             :   i::ScriptStreamingData* data = v8_source->impl();
    2592             : 
    2593             :   i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
    2594             :       i::Compiler::GetSharedFunctionInfoForStreamedScript(
    2595       13231 :           isolate, str, script_details, origin.Options(), data);
    2596             : 
    2597             :   i::Handle<i::SharedFunctionInfo> result;
    2598       13231 :   has_pending_exception = !maybe_function_info.ToHandle(&result);
    2599       13231 :   if (has_pending_exception) isolate->ReportPendingMessages();
    2600             : 
    2601       13231 :   RETURN_ON_FAILED_EXECUTION(Script);
    2602             : 
    2603             :   Local<UnboundScript> generic = ToApiHandle<UnboundScript>(result);
    2604       13124 :   if (generic.IsEmpty()) return Local<Script>();
    2605       13124 :   Local<Script> bound = generic->BindToCurrentContext();
    2606       13124 :   if (bound.IsEmpty()) return Local<Script>();
    2607       13124 :   RETURN_ESCAPED(bound);
    2608             : }
    2609             : 
    2610           0 : uint32_t ScriptCompiler::CachedDataVersionTag() {
    2611             :   return static_cast<uint32_t>(base::hash_combine(
    2612           0 :       internal::Version::Hash(), internal::FlagList::Hash(),
    2613           0 :       static_cast<uint32_t>(internal::CpuFeatures::SupportedFeatures())));
    2614             : }
    2615             : 
    2616         362 : ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
    2617             :     Local<UnboundScript> unbound_script) {
    2618             :   i::Handle<i::SharedFunctionInfo> shared =
    2619             :       i::Handle<i::SharedFunctionInfo>::cast(
    2620         362 :           Utils::OpenHandle(*unbound_script));
    2621             :   DCHECK(shared->is_toplevel());
    2622         362 :   return i::CodeSerializer::Serialize(shared);
    2623             : }
    2624             : 
    2625             : // static
    2626          10 : ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
    2627             :     Local<UnboundModuleScript> unbound_module_script) {
    2628             :   i::Handle<i::SharedFunctionInfo> shared =
    2629             :       i::Handle<i::SharedFunctionInfo>::cast(
    2630          10 :           Utils::OpenHandle(*unbound_module_script));
    2631             :   DCHECK(shared->is_toplevel());
    2632          10 :   return i::CodeSerializer::Serialize(shared);
    2633             : }
    2634             : 
    2635           5 : ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
    2636             :     Local<Function> function) {
    2637             :   auto js_function =
    2638             :       i::Handle<i::JSFunction>::cast(Utils::OpenHandle(*function));
    2639             :   i::Handle<i::SharedFunctionInfo> shared(js_function->shared(),
    2640             :                                           js_function->GetIsolate());
    2641           5 :   CHECK(shared->is_wrapped());
    2642           5 :   return i::CodeSerializer::Serialize(shared);
    2643             : }
    2644             : 
    2645      129028 : MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
    2646             :                                    ScriptOrigin* origin) {
    2647      129028 :   if (origin) {
    2648             :     ScriptCompiler::Source script_source(source, *origin);
    2649        5090 :     return ScriptCompiler::Compile(context, &script_source);
    2650             :   }
    2651             :   ScriptCompiler::Source script_source(source);
    2652      123938 :   return ScriptCompiler::Compile(context, &script_source);
    2653             : }
    2654             : 
    2655             : 
    2656             : // --- E x c e p t i o n s ---
    2657             : 
    2658    20992766 : v8::TryCatch::TryCatch(v8::Isolate* isolate)
    2659             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    2660             :       next_(isolate_->try_catch_handler()),
    2661             :       is_verbose_(false),
    2662             :       can_continue_(true),
    2663             :       capture_message_(true),
    2664             :       rethrow_(false),
    2665    41985532 :       has_terminated_(false) {
    2666             :   ResetInternal();
    2667             :   // Special handling for simulators which have a separate JS stack.
    2668             :   js_stack_comparable_address_ = reinterpret_cast<void*>(
    2669    20992761 :       i::SimulatorStack::RegisterJSStackComparableAddress(isolate_));
    2670    20992761 :   isolate_->RegisterTryCatchHandler(this);
    2671    20992755 : }
    2672             : 
    2673             : 
    2674    41985524 : v8::TryCatch::~TryCatch() {
    2675    20992763 :   if (rethrow_) {
    2676         121 :     v8::Isolate* isolate = reinterpret_cast<Isolate*>(isolate_);
    2677             :     v8::HandleScope scope(isolate);
    2678         242 :     v8::Local<v8::Value> exc = v8::Local<v8::Value>::New(isolate, Exception());
    2679         121 :     if (HasCaught() && capture_message_) {
    2680             :       // If an exception was caught and rethrow_ is indicated, the saved
    2681             :       // message, script, and location need to be restored to Isolate TLS
    2682             :       // for reuse.  capture_message_ needs to be disabled so that Throw()
    2683             :       // does not create a new message.
    2684         121 :       isolate_->thread_local_top()->rethrowing_message_ = true;
    2685         121 :       isolate_->RestorePendingMessageFromTryCatch(this);
    2686             :     }
    2687         121 :     isolate_->UnregisterTryCatchHandler(this);
    2688             :     i::SimulatorStack::UnregisterJSStackComparableAddress(isolate_);
    2689         121 :     reinterpret_cast<Isolate*>(isolate_)->ThrowException(exc);
    2690             :     DCHECK(!isolate_->thread_local_top()->rethrowing_message_);
    2691             :   } else {
    2692    21005386 :     if (HasCaught() && isolate_->has_scheduled_exception()) {
    2693             :       // If an exception was caught but is still scheduled because no API call
    2694             :       // promoted it, then it is canceled to prevent it from being propagated.
    2695             :       // Note that this will not cancel termination exceptions.
    2696         268 :       isolate_->CancelScheduledExceptionFromTryCatch(this);
    2697             :     }
    2698    20992642 :     isolate_->UnregisterTryCatchHandler(this);
    2699             :     i::SimulatorStack::UnregisterJSStackComparableAddress(isolate_);
    2700             :   }
    2701    20992761 : }
    2702             : 
    2703           0 : void* v8::TryCatch::operator new(size_t) { base::OS::Abort(); }
    2704           0 : void* v8::TryCatch::operator new[](size_t) { base::OS::Abort(); }
    2705           0 : void v8::TryCatch::operator delete(void*, size_t) { base::OS::Abort(); }
    2706           0 : void v8::TryCatch::operator delete[](void*, size_t) { base::OS::Abort(); }
    2707             : 
    2708      127926 : bool v8::TryCatch::HasCaught() const {
    2709    21146910 :   return !i::Object(reinterpret_cast<i::Address>(exception_))
    2710    42421746 :               ->IsTheHole(isolate_);
    2711             : }
    2712             : 
    2713             : 
    2714        1679 : bool v8::TryCatch::CanContinue() const {
    2715        1679 :   return can_continue_;
    2716             : }
    2717             : 
    2718             : 
    2719       22114 : bool v8::TryCatch::HasTerminated() const {
    2720       22114 :   return has_terminated_;
    2721             : }
    2722             : 
    2723             : 
    2724         121 : v8::Local<v8::Value> v8::TryCatch::ReThrow() {
    2725         121 :   if (!HasCaught()) return v8::Local<v8::Value>();
    2726         121 :   rethrow_ = true;
    2727         121 :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_));
    2728             : }
    2729             : 
    2730             : 
    2731       10561 : v8::Local<Value> v8::TryCatch::Exception() const {
    2732       10561 :   if (HasCaught()) {
    2733             :     // Check for out of memory exception.
    2734             :     i::Object exception(reinterpret_cast<i::Address>(exception_));
    2735             :     return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_));
    2736             :   } else {
    2737           0 :     return v8::Local<Value>();
    2738             :   }
    2739             : }
    2740             : 
    2741             : 
    2742        6335 : MaybeLocal<Value> v8::TryCatch::StackTrace(Local<Context> context) const {
    2743        6335 :   if (!HasCaught()) return v8::Local<Value>();
    2744             :   i::Object raw_obj(reinterpret_cast<i::Address>(exception_));
    2745        6335 :   if (!raw_obj->IsJSObject()) return v8::Local<Value>();
    2746       10276 :   PREPARE_FOR_EXECUTION(context, TryCatch, StackTrace, Value);
    2747        2569 :   i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_);
    2748             :   i::Handle<i::String> name = isolate->factory()->stack_string();
    2749        2569 :   Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
    2750             :   has_pending_exception = maybe.IsNothing();
    2751        2569 :   RETURN_ON_FAILED_EXECUTION(Value);
    2752        2569 :   if (!maybe.FromJust()) return v8::Local<Value>();
    2753             :   Local<Value> result;
    2754             :   has_pending_exception =
    2755        5138 :       !ToLocal<Value>(i::JSReceiver::GetProperty(isolate, obj, name), &result);
    2756        2569 :   RETURN_ON_FAILED_EXECUTION(Value);
    2757        2569 :   RETURN_ESCAPED(result);
    2758             : }
    2759             : 
    2760             : 
    2761        8490 : v8::Local<v8::Message> v8::TryCatch::Message() const {
    2762        8490 :   i::Object message(reinterpret_cast<i::Address>(message_obj_));
    2763             :   DCHECK(message->IsJSMessageObject() || message->IsTheHole(isolate_));
    2764        8490 :   if (HasCaught() && !message->IsTheHole(isolate_)) {
    2765             :     return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_));
    2766             :   } else {
    2767          60 :     return v8::Local<v8::Message>();
    2768             :   }
    2769             : }
    2770             : 
    2771             : 
    2772         714 : void v8::TryCatch::Reset() {
    2773        1896 :   if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
    2774             :     // If an exception was caught but is still scheduled because no API call
    2775             :     // promoted it, then it is canceled to prevent it from being propagated.
    2776             :     // Note that this will not cancel termination exceptions.
    2777           5 :     isolate_->CancelScheduledExceptionFromTryCatch(this);
    2778             :   }
    2779             :   ResetInternal();
    2780         714 : }
    2781             : 
    2782             : 
    2783           0 : void v8::TryCatch::ResetInternal() {
    2784         714 :   i::Object the_hole = i::ReadOnlyRoots(isolate_).the_hole_value();
    2785    20993480 :   exception_ = reinterpret_cast<void*>(the_hole->ptr());
    2786    20993480 :   message_obj_ = reinterpret_cast<void*>(the_hole->ptr());
    2787           0 : }
    2788             : 
    2789             : 
    2790      174341 : void v8::TryCatch::SetVerbose(bool value) {
    2791      174341 :   is_verbose_ = value;
    2792      174341 : }
    2793             : 
    2794           0 : bool v8::TryCatch::IsVerbose() const { return is_verbose_; }
    2795             : 
    2796       52182 : void v8::TryCatch::SetCaptureMessage(bool value) {
    2797       52182 :   capture_message_ = value;
    2798       52182 : }
    2799             : 
    2800             : 
    2801             : // --- M e s s a g e ---
    2802             : 
    2803             : 
    2804        2893 : Local<String> Message::Get() const {
    2805             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2806             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2807        2893 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2808             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    2809        2893 :   i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj);
    2810             :   Local<String> result = Utils::ToLocal(raw_result);
    2811        2893 :   return scope.Escape(result);
    2812             : }
    2813             : 
    2814          50 : v8::Isolate* Message::GetIsolate() const {
    2815             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2816          50 :   return reinterpret_cast<Isolate*>(isolate);
    2817             : }
    2818             : 
    2819       15973 : ScriptOrigin Message::GetScriptOrigin() const {
    2820             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2821             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2822             :   auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
    2823             :   i::Handle<i::Script> script(message->script(), isolate);
    2824       31946 :   return GetScriptOriginForScript(isolate, script);
    2825             : }
    2826             : 
    2827             : 
    2828           0 : v8::Local<Value> Message::GetScriptResourceName() const {
    2829           0 :   return GetScriptOrigin().ResourceName();
    2830             : }
    2831             : 
    2832             : 
    2833        2099 : v8::Local<v8::StackTrace> Message::GetStackTrace() const {
    2834             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2835             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2836        2099 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2837             :   auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
    2838             :   i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate);
    2839        2099 :   if (!stackFramesObj->IsFixedArray()) return v8::Local<v8::StackTrace>();
    2840             :   auto stackTrace = i::Handle<i::FixedArray>::cast(stackFramesObj);
    2841             :   return scope.Escape(Utils::StackTraceToLocal(stackTrace));
    2842             : }
    2843             : 
    2844             : 
    2845        9074 : Maybe<int> Message::GetLineNumber(Local<Context> context) const {
    2846             :   auto self = Utils::OpenHandle(this);
    2847             :   i::Isolate* isolate = self->GetIsolate();
    2848             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2849        9074 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2850             :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2851       18148 :   return Just(msg->GetLineNumber());
    2852             : }
    2853             : 
    2854             : 
    2855          30 : int Message::GetStartPosition() const {
    2856             :   auto self = Utils::OpenHandle(this);
    2857          30 :   return self->start_position();
    2858             : }
    2859             : 
    2860             : 
    2861          18 : int Message::GetEndPosition() const {
    2862             :   auto self = Utils::OpenHandle(this);
    2863          18 :   return self->end_position();
    2864             : }
    2865             : 
    2866       24272 : int Message::ErrorLevel() const {
    2867             :   auto self = Utils::OpenHandle(this);
    2868       24272 :   return self->error_level();
    2869             : }
    2870             : 
    2871        8791 : int Message::GetStartColumn() const {
    2872             :   auto self = Utils::OpenHandle(this);
    2873             :   i::Isolate* isolate = self->GetIsolate();
    2874             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2875        8791 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2876             :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2877       17582 :   return msg->GetColumnNumber();
    2878             : }
    2879             : 
    2880        8791 : Maybe<int> Message::GetStartColumn(Local<Context> context) const {
    2881        8791 :   return Just(GetStartColumn());
    2882             : }
    2883             : 
    2884        6314 : int Message::GetEndColumn() const {
    2885             :   auto self = Utils::OpenHandle(this);
    2886             :   i::Isolate* isolate = self->GetIsolate();
    2887             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2888        6314 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2889             :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2890        6314 :   const int column_number = msg->GetColumnNumber();
    2891        6314 :   if (column_number == -1) return -1;
    2892             :   const int start = self->start_position();
    2893             :   const int end = self->end_position();
    2894        6314 :   return column_number + (end - start);
    2895             : }
    2896             : 
    2897        6314 : Maybe<int> Message::GetEndColumn(Local<Context> context) const {
    2898        6314 :   return Just(GetEndColumn());
    2899             : }
    2900             : 
    2901             : 
    2902         131 : bool Message::IsSharedCrossOrigin() const {
    2903             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2904             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2905             :   return Utils::OpenHandle(this)
    2906             :       ->script()
    2907             :       ->origin_options()
    2908         131 :       .IsSharedCrossOrigin();
    2909             : }
    2910             : 
    2911           0 : bool Message::IsOpaque() const {
    2912             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2913             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2914           0 :   return Utils::OpenHandle(this)->script()->origin_options().IsOpaque();
    2915             : }
    2916             : 
    2917             : 
    2918        6325 : MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
    2919             :   auto self = Utils::OpenHandle(this);
    2920             :   i::Isolate* isolate = self->GetIsolate();
    2921             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2922        6325 :   EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
    2923             :   auto msg = i::Handle<i::JSMessageObject>::cast(self);
    2924       18975 :   RETURN_ESCAPED(Utils::ToLocal(msg->GetSourceLine()));
    2925             : }
    2926             : 
    2927             : 
    2928           0 : void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
    2929             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    2930             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    2931           0 :   i_isolate->PrintCurrentStackTrace(out);
    2932           0 : }
    2933             : 
    2934             : 
    2935             : // --- S t a c k T r a c e ---
    2936             : 
    2937       62087 : Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
    2938             :                                        uint32_t index) const {
    2939             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    2940             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    2941       62087 :   EscapableHandleScope scope(v8_isolate);
    2942       62087 :   auto obj = handle(Utils::OpenHandle(this)->get(index), isolate);
    2943             :   auto frame = i::Handle<i::StackTraceFrame>::cast(obj);
    2944       62087 :   return scope.Escape(Utils::StackFrameToLocal(frame));
    2945             : }
    2946             : 
    2947      120664 : int StackTrace::GetFrameCount() const {
    2948      120664 :   return Utils::OpenHandle(this)->length();
    2949             : }
    2950             : 
    2951             : 
    2952       64392 : Local<StackTrace> StackTrace::CurrentStackTrace(
    2953             :     Isolate* isolate,
    2954             :     int frame_limit,
    2955             :     StackTraceOptions options) {
    2956             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    2957             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    2958             :   i::Handle<i::FixedArray> stackTrace =
    2959       64392 :       i_isolate->CaptureCurrentStackTrace(frame_limit, options);
    2960       64392 :   return Utils::StackTraceToLocal(stackTrace);
    2961             : }
    2962             : 
    2963             : 
    2964             : // --- S t a c k F r a m e ---
    2965             : 
    2966       60552 : int StackFrame::GetLineNumber() const {
    2967       60552 :   return i::StackTraceFrame::GetLineNumber(Utils::OpenHandle(this));
    2968             : }
    2969             : 
    2970             : 
    2971       60517 : int StackFrame::GetColumn() const {
    2972       60517 :   return i::StackTraceFrame::GetColumnNumber(Utils::OpenHandle(this));
    2973             : }
    2974             : 
    2975             : 
    2976       60133 : int StackFrame::GetScriptId() const {
    2977       60133 :   return i::StackTraceFrame::GetScriptId(Utils::OpenHandle(this));
    2978             : }
    2979             : 
    2980       60320 : Local<String> StackFrame::GetScriptName() const {
    2981             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2982       60320 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2983             :   i::Handle<i::Object> name =
    2984       60320 :       i::StackTraceFrame::GetFileName(Utils::OpenHandle(this));
    2985             :   return name->IsString()
    2986             :              ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
    2987      180113 :              : Local<String>();
    2988             : }
    2989             : 
    2990             : 
    2991      120206 : Local<String> StackFrame::GetScriptNameOrSourceURL() const {
    2992             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    2993      120206 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    2994             :   i::Handle<i::Object> name =
    2995      120206 :       i::StackTraceFrame::GetScriptNameOrSourceUrl(Utils::OpenHandle(this));
    2996             :   return name->IsString()
    2997             :              ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
    2998      359428 :              : Local<String>();
    2999             : }
    3000             : 
    3001             : 
    3002       60482 : Local<String> StackFrame::GetFunctionName() const {
    3003             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    3004       60482 :   EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
    3005             :   i::Handle<i::Object> name =
    3006       60482 :       i::StackTraceFrame::GetFunctionName(Utils::OpenHandle(this));
    3007             :   return name->IsString()
    3008             :              ? scope.Escape(Local<String>::Cast(Utils::ToLocal(name)))
    3009      181446 :              : Local<String>();
    3010             : }
    3011             : 
    3012         100 : bool StackFrame::IsEval() const {
    3013         100 :   return i::StackTraceFrame::IsEval(Utils::OpenHandle(this));
    3014             : }
    3015             : 
    3016         100 : bool StackFrame::IsConstructor() const {
    3017         100 :   return i::StackTraceFrame::IsConstructor(Utils::OpenHandle(this));
    3018             : }
    3019             : 
    3020       60058 : bool StackFrame::IsWasm() const {
    3021       60058 :   return i::StackTraceFrame::IsWasm(Utils::OpenHandle(this));
    3022             : }
    3023             : 
    3024             : // --- J S O N ---
    3025             : 
    3026         135 : MaybeLocal<Value> JSON::Parse(Local<Context> context,
    3027             :                               Local<String> json_string) {
    3028         540 :   PREPARE_FOR_EXECUTION(context, JSON, Parse, Value);
    3029         135 :   i::Handle<i::String> string = Utils::OpenHandle(*json_string);
    3030         135 :   i::Handle<i::String> source = i::String::Flatten(isolate, string);
    3031             :   i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
    3032             :   auto maybe = source->IsSeqOneByteString()
    3033             :                    ? i::JsonParser<true>::Parse(isolate, source, undefined)
    3034         135 :                    : i::JsonParser<false>::Parse(isolate, source, undefined);
    3035             :   Local<Value> result;
    3036             :   has_pending_exception = !ToLocal<Value>(maybe, &result);
    3037         135 :   RETURN_ON_FAILED_EXECUTION(Value);
    3038         134 :   RETURN_ESCAPED(result);
    3039             : }
    3040             : 
    3041         109 : MaybeLocal<String> JSON::Stringify(Local<Context> context,
    3042             :                                    Local<Value> json_object,
    3043             :                                    Local<String> gap) {
    3044         436 :   PREPARE_FOR_EXECUTION(context, JSON, Stringify, String);
    3045         109 :   i::Handle<i::Object> object = Utils::OpenHandle(*json_object);
    3046             :   i::Handle<i::Object> replacer = isolate->factory()->undefined_value();
    3047             :   i::Handle<i::String> gap_string = gap.IsEmpty()
    3048             :                                         ? isolate->factory()->empty_string()
    3049         109 :                                         : Utils::OpenHandle(*gap);
    3050             :   i::Handle<i::Object> maybe;
    3051             :   has_pending_exception =
    3052         218 :       !i::JsonStringify(isolate, object, replacer, gap_string).ToHandle(&maybe);
    3053         109 :   RETURN_ON_FAILED_EXECUTION(String);
    3054             :   Local<String> result;
    3055             :   has_pending_exception =
    3056         109 :       !ToLocal<String>(i::Object::ToString(isolate, maybe), &result);
    3057         109 :   RETURN_ON_FAILED_EXECUTION(String);
    3058         109 :   RETURN_ESCAPED(result);
    3059             : }
    3060             : 
    3061             : // --- V a l u e   S e r i a l i z a t i o n ---
    3062             : 
    3063           0 : Maybe<bool> ValueSerializer::Delegate::WriteHostObject(Isolate* v8_isolate,
    3064             :                                                        Local<Object> object) {
    3065             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3066           0 :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3067             :       isolate->error_function(), i::MessageTemplate::kDataCloneError,
    3068           0 :       Utils::OpenHandle(*object)));
    3069           0 :   return Nothing<bool>();
    3070             : }
    3071             : 
    3072           0 : Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId(
    3073             :     Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) {
    3074             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3075           0 :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3076             :       isolate->error_function(), i::MessageTemplate::kDataCloneError,
    3077           0 :       Utils::OpenHandle(*shared_array_buffer)));
    3078           0 :   return Nothing<uint32_t>();
    3079             : }
    3080             : 
    3081           0 : Maybe<uint32_t> ValueSerializer::Delegate::GetWasmModuleTransferId(
    3082             :     Isolate* v8_isolate, Local<WasmModuleObject> module) {
    3083           0 :   return Nothing<uint32_t>();
    3084             : }
    3085             : 
    3086          20 : void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer,
    3087             :                                                         size_t size,
    3088             :                                                         size_t* actual_size) {
    3089          20 :   *actual_size = size;
    3090          20 :   return realloc(old_buffer, size);
    3091             : }
    3092             : 
    3093          20 : void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) {
    3094          20 :   return free(buffer);
    3095             : }
    3096             : 
    3097        2027 : struct ValueSerializer::PrivateData {
    3098             :   explicit PrivateData(i::Isolate* i, ValueSerializer::Delegate* delegate)
    3099        2029 :       : isolate(i), serializer(i, delegate) {}
    3100             :   i::Isolate* isolate;
    3101             :   i::ValueSerializer serializer;
    3102             : };
    3103             : 
    3104           0 : ValueSerializer::ValueSerializer(Isolate* isolate)
    3105           0 :     : ValueSerializer(isolate, nullptr) {}
    3106             : 
    3107        2019 : ValueSerializer::ValueSerializer(Isolate* isolate, Delegate* delegate)
    3108             :     : private_(
    3109        4042 :           new PrivateData(reinterpret_cast<i::Isolate*>(isolate), delegate)) {}
    3110             : 
    3111        4055 : ValueSerializer::~ValueSerializer() { delete private_; }
    3112             : 
    3113        1859 : void ValueSerializer::WriteHeader() { private_->serializer.WriteHeader(); }
    3114             : 
    3115           1 : void ValueSerializer::SetTreatArrayBufferViewsAsHostObjects(bool mode) {
    3116           1 :   private_->serializer.SetTreatArrayBufferViewsAsHostObjects(mode);
    3117           1 : }
    3118             : 
    3119        1862 : Maybe<bool> ValueSerializer::WriteValue(Local<Context> context,
    3120             :                                         Local<Value> value) {
    3121             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3122        5570 :   ENTER_V8(isolate, context, ValueSerializer, WriteValue, Nothing<bool>(),
    3123             :            i::HandleScope);
    3124        1852 :   i::Handle<i::Object> object = Utils::OpenHandle(*value);
    3125        1852 :   Maybe<bool> result = private_->serializer.WriteObject(object);
    3126             :   has_pending_exception = result.IsNothing();
    3127        1846 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3128        1819 :   return result;
    3129             : }
    3130             : 
    3131        1811 : std::pair<uint8_t*, size_t> ValueSerializer::Release() {
    3132        1811 :   return private_->serializer.Release();
    3133             : }
    3134             : 
    3135          47 : void ValueSerializer::TransferArrayBuffer(uint32_t transfer_id,
    3136             :                                           Local<ArrayBuffer> array_buffer) {
    3137          47 :   private_->serializer.TransferArrayBuffer(transfer_id,
    3138          47 :                                            Utils::OpenHandle(*array_buffer));
    3139          47 : }
    3140             : 
    3141           2 : void ValueSerializer::WriteUint32(uint32_t value) {
    3142           2 :   private_->serializer.WriteUint32(value);
    3143           2 : }
    3144             : 
    3145           2 : void ValueSerializer::WriteUint64(uint64_t value) {
    3146           2 :   private_->serializer.WriteUint64(value);
    3147           2 : }
    3148             : 
    3149           4 : void ValueSerializer::WriteDouble(double value) {
    3150           4 :   private_->serializer.WriteDouble(value);
    3151           4 : }
    3152             : 
    3153          15 : void ValueSerializer::WriteRawBytes(const void* source, size_t length) {
    3154          15 :   private_->serializer.WriteRawBytes(source, length);
    3155          15 : }
    3156             : 
    3157           0 : MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
    3158             :     Isolate* v8_isolate) {
    3159             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3160           0 :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3161             :       isolate->error_function(),
    3162           0 :       i::MessageTemplate::kDataCloneDeserializationError));
    3163           0 :   return MaybeLocal<Object>();
    3164             : }
    3165             : 
    3166           1 : MaybeLocal<WasmModuleObject> ValueDeserializer::Delegate::GetWasmModuleFromId(
    3167             :     Isolate* v8_isolate, uint32_t id) {
    3168             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3169           2 :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3170             :       isolate->error_function(),
    3171           3 :       i::MessageTemplate::kDataCloneDeserializationError));
    3172           1 :   return MaybeLocal<WasmModuleObject>();
    3173             : }
    3174             : 
    3175             : MaybeLocal<SharedArrayBuffer>
    3176           0 : ValueDeserializer::Delegate::GetSharedArrayBufferFromId(Isolate* v8_isolate,
    3177             :                                                         uint32_t id) {
    3178             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3179           0 :   isolate->ScheduleThrow(*isolate->factory()->NewError(
    3180             :       isolate->error_function(),
    3181           0 :       i::MessageTemplate::kDataCloneDeserializationError));
    3182           0 :   return MaybeLocal<SharedArrayBuffer>();
    3183             : }
    3184             : 
    3185        1917 : struct ValueDeserializer::PrivateData {
    3186             :   PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
    3187        1917 :       : isolate(i), deserializer(i, data, delegate) {}
    3188             :   i::Isolate* isolate;
    3189             :   i::ValueDeserializer deserializer;
    3190             :   bool has_aborted = false;
    3191             :   bool supports_legacy_wire_format = false;
    3192             : };
    3193             : 
    3194           0 : ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
    3195             :                                      size_t size)
    3196           0 :     : ValueDeserializer(isolate, data, size, nullptr) {}
    3197             : 
    3198        1917 : ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
    3199             :                                      size_t size, Delegate* delegate) {
    3200        1917 :   if (base::IsValueInRangeForNumericType<int>(size)) {
    3201             :     private_ = new PrivateData(
    3202             :         reinterpret_cast<i::Isolate*>(isolate),
    3203        3834 :         i::Vector<const uint8_t>(data, static_cast<int>(size)), delegate);
    3204             :   } else {
    3205             :     private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate),
    3206           0 :                                i::Vector<const uint8_t>(nullptr, 0), nullptr);
    3207           0 :     private_->has_aborted = true;
    3208             :   }
    3209        1917 : }
    3210             : 
    3211        3834 : ValueDeserializer::~ValueDeserializer() { delete private_; }
    3212             : 
    3213        1917 : Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) {
    3214             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3215        5751 :   ENTER_V8_NO_SCRIPT(isolate, context, ValueDeserializer, ReadHeader,
    3216             :                      Nothing<bool>(), i::HandleScope);
    3217             : 
    3218             :   // We could have aborted during the constructor.
    3219             :   // If so, ReadHeader is where we report it.
    3220        1917 :   if (private_->has_aborted) {
    3221           0 :     isolate->Throw(*isolate->factory()->NewError(
    3222           0 :         i::MessageTemplate::kDataCloneDeserializationError));
    3223             :     has_pending_exception = true;
    3224           0 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3225             :   }
    3226             : 
    3227             :   bool read_header = false;
    3228        3834 :   has_pending_exception = !private_->deserializer.ReadHeader().To(&read_header);
    3229        1917 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3230             :   DCHECK(read_header);
    3231             : 
    3232             :   static const uint32_t kMinimumNonLegacyVersion = 13;
    3233        2035 :   if (GetWireFormatVersion() < kMinimumNonLegacyVersion &&
    3234         120 :       !private_->supports_legacy_wire_format) {
    3235           0 :     isolate->Throw(*isolate->factory()->NewError(
    3236           0 :         i::MessageTemplate::kDataCloneDeserializationVersionError));
    3237             :     has_pending_exception = true;
    3238           0 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    3239             :   }
    3240             : 
    3241             :   return Just(true);
    3242             : }
    3243             : 
    3244        1917 : void ValueDeserializer::SetSupportsLegacyWireFormat(
    3245             :     bool supports_legacy_wire_format) {
    3246        1917 :   private_->supports_legacy_wire_format = supports_legacy_wire_format;
    3247        1917 : }
    3248             : 
    3249         262 : void ValueDeserializer::SetExpectInlineWasm(bool expect_inline_wasm) {
    3250         262 :   private_->deserializer.set_expect_inline_wasm(expect_inline_wasm);
    3251         262 : }
    3252             : 
    3253           8 : uint32_t ValueDeserializer::GetWireFormatVersion() const {
    3254        3838 :   CHECK(!private_->has_aborted);
    3255           8 :   return private_->deserializer.GetWireFormatVersion();
    3256             : }
    3257             : 
    3258        1915 : MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {
    3259        1915 :   CHECK(!private_->has_aborted);
    3260        7660 :   PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value);
    3261             :   i::MaybeHandle<i::Object> result;
    3262        1915 :   if (GetWireFormatVersion() > 0) {
    3263        1903 :     result = private_->deserializer.ReadObject();
    3264             :   } else {
    3265             :     result =
    3266          12 :         private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat();
    3267             :   }
    3268             :   Local<Value> value;
    3269             :   has_pending_exception = !ToLocal(result, &value);
    3270        1915 :   RETURN_ON_FAILED_EXECUTION(Value);
    3271        1886 :   RETURN_ESCAPED(value);
    3272             : }
    3273             : 
    3274          29 : void ValueDeserializer::TransferArrayBuffer(uint32_t transfer_id,
    3275             :                                             Local<ArrayBuffer> array_buffer) {
    3276          29 :   CHECK(!private_->has_aborted);
    3277          29 :   private_->deserializer.TransferArrayBuffer(transfer_id,
    3278          29 :                                              Utils::OpenHandle(*array_buffer));
    3279          29 : }
    3280             : 
    3281           0 : void ValueDeserializer::TransferSharedArrayBuffer(
    3282             :     uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) {
    3283           0 :   CHECK(!private_->has_aborted);
    3284           0 :   private_->deserializer.TransferArrayBuffer(
    3285           0 :       transfer_id, Utils::OpenHandle(*shared_array_buffer));
    3286           0 : }
    3287             : 
    3288           2 : bool ValueDeserializer::ReadUint32(uint32_t* value) {
    3289           2 :   return private_->deserializer.ReadUint32(value);
    3290             : }
    3291             : 
    3292           2 : bool ValueDeserializer::ReadUint64(uint64_t* value) {
    3293           2 :   return private_->deserializer.ReadUint64(value);
    3294             : }
    3295             : 
    3296           4 : bool ValueDeserializer::ReadDouble(double* value) {
    3297           4 :   return private_->deserializer.ReadDouble(value);
    3298             : }
    3299             : 
    3300          13 : bool ValueDeserializer::ReadRawBytes(size_t length, const void** data) {
    3301          13 :   return private_->deserializer.ReadRawBytes(length, data);
    3302             : }
    3303             : 
    3304             : // --- D a t a ---
    3305             : 
    3306           0 : bool Value::FullIsUndefined() const {
    3307             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3308             :   bool result = object->IsUndefined();
    3309             :   DCHECK_EQ(result, QuickIsUndefined());
    3310           0 :   return result;
    3311             : }
    3312             : 
    3313             : 
    3314           0 : bool Value::FullIsNull() const {
    3315             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3316             :   bool result = object->IsNull();
    3317             :   DCHECK_EQ(result, QuickIsNull());
    3318           0 :   return result;
    3319             : }
    3320             : 
    3321             : 
    3322        7766 : bool Value::IsTrue() const {
    3323             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3324       71706 :   if (object->IsSmi()) return false;
    3325             :   return object->IsTrue();
    3326             : }
    3327             : 
    3328             : 
    3329         118 : bool Value::IsFalse() const {
    3330             :   i::Handle<i::Object> object = Utils::OpenHandle(this);
    3331         118 :   if (object->IsSmi()) return false;
    3332             :   return object->IsFalse();
    3333             : }
    3334             : 
    3335             : 
    3336     7490280 : bool Value::IsFunction() const { return Utils::OpenHandle(this)->IsCallable(); }
    3337             : 
    3338             : 
    3339       16635 : bool Value::IsName() const {
    3340       16635 :   return Utils::OpenHandle(this)->IsName();
    3341             : }
    3342             : 
    3343             : 
    3344           0 : bool Value::FullIsString() const {
    3345             :   bool result = Utils::OpenHandle(this)->IsString();
    3346             :   DCHECK_EQ(result, QuickIsString());
    3347           0 :   return result;
    3348             : }
    3349             : 
    3350             : 
    3351     9311668 : bool Value::IsSymbol() const {
    3352     9311668 :   return Utils::OpenHandle(this)->IsSymbol();
    3353             : }
    3354             : 
    3355             : 
    3356     1884164 : bool Value::IsArray() const {
    3357     1884164 :   return Utils::OpenHandle(this)->IsJSArray();
    3358             : }
    3359             : 
    3360             : 
    3361     1267951 : bool Value::IsArrayBuffer() const {
    3362             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3363     1522588 :   return obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared();
    3364             : }
    3365             : 
    3366             : 
    3367          99 : bool Value::IsArrayBufferView() const {
    3368          99 :   return Utils::OpenHandle(this)->IsJSArrayBufferView();
    3369             : }
    3370             : 
    3371             : 
    3372      923548 : bool Value::IsTypedArray() const {
    3373      923547 :   return Utils::OpenHandle(this)->IsJSTypedArray();
    3374             : }
    3375             : 
    3376             : #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype)                    \
    3377             :   bool Value::Is##Type##Array() const {                                      \
    3378             :     i::Handle<i::Object> obj = Utils::OpenHandle(this);                      \
    3379             :     return obj->IsJSTypedArray() &&                                          \
    3380             :            i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \
    3381             :   }
    3382             : 
    3383         222 : TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
    3384             : 
    3385             : #undef VALUE_IS_TYPED_ARRAY
    3386             : 
    3387             : 
    3388      895287 : bool Value::IsDataView() const {
    3389      895287 :   return Utils::OpenHandle(this)->IsJSDataView();
    3390             : }
    3391             : 
    3392             : 
    3393     1267058 : bool Value::IsSharedArrayBuffer() const {
    3394             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3395     1548753 :   return obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared();
    3396             : }
    3397             : 
    3398             : 
    3399    16677297 : bool Value::IsObject() const { return Utils::OpenHandle(this)->IsJSReceiver(); }
    3400             : 
    3401             : 
    3402     3710229 : bool Value::IsNumber() const {
    3403     3710229 :   return Utils::OpenHandle(this)->IsNumber();
    3404             : }
    3405             : 
    3406     6721272 : bool Value::IsBigInt() const { return Utils::OpenHandle(this)->IsBigInt(); }
    3407             : 
    3408     1981598 : bool Value::IsProxy() const { return Utils::OpenHandle(this)->IsJSProxy(); }
    3409             : 
    3410             : #define VALUE_IS_SPECIFIC_TYPE(Type, Check)             \
    3411             :   bool Value::Is##Type() const {                        \
    3412             :     i::Handle<i::Object> obj = Utils::OpenHandle(this); \
    3413             :     return obj->Is##Check();                            \
    3414             :   }
    3415             : 
    3416     1680870 : VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, JSArgumentsObject)
    3417       43690 : VALUE_IS_SPECIFIC_TYPE(BigIntObject, BigIntWrapper)
    3418       43806 : VALUE_IS_SPECIFIC_TYPE(BooleanObject, BooleanWrapper)
    3419       43722 : VALUE_IS_SPECIFIC_TYPE(NumberObject, NumberWrapper)
    3420       66924 : VALUE_IS_SPECIFIC_TYPE(StringObject, StringWrapper)
    3421       43676 : VALUE_IS_SPECIFIC_TYPE(SymbolObject, SymbolWrapper)
    3422     1801084 : VALUE_IS_SPECIFIC_TYPE(Date, JSDate)
    3423     1972994 : VALUE_IS_SPECIFIC_TYPE(Map, JSMap)
    3424     1972472 : VALUE_IS_SPECIFIC_TYPE(Set, JSSet)
    3425     1792008 : VALUE_IS_SPECIFIC_TYPE(WeakMap, JSWeakMap)
    3426     1791910 : VALUE_IS_SPECIFIC_TYPE(WeakSet, JSWeakSet)
    3427          92 : VALUE_IS_SPECIFIC_TYPE(WebAssemblyCompiledModule, WasmModuleObject)
    3428             : 
    3429             : #undef VALUE_IS_SPECIFIC_TYPE
    3430             : 
    3431             : 
    3432     3754090 : bool Value::IsBoolean() const {
    3433     3754090 :   return Utils::OpenHandle(this)->IsBoolean();
    3434             : }
    3435             : 
    3436          97 : bool Value::IsExternal() const {
    3437             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3438          97 :   if (!obj->IsHeapObject()) return false;
    3439             :   i::Handle<i::HeapObject> heap_obj = i::Handle<i::HeapObject>::cast(obj);
    3440             :   // Check the instance type is JS_OBJECT (instance type of Externals) before
    3441             :   // attempting to get the Isolate since that guarantees the object is writable
    3442             :   // and GetIsolate will work.
    3443          97 :   if (heap_obj->map()->instance_type() != i::JS_OBJECT_TYPE) return false;
    3444             :   i::Isolate* isolate = i::JSObject::cast(*heap_obj)->GetIsolate();
    3445          52 :   return heap_obj->IsExternal(isolate);
    3446             : }
    3447             : 
    3448             : 
    3449      534595 : bool Value::IsInt32() const {
    3450             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3451      534595 :   if (obj->IsSmi()) return true;
    3452          59 :   if (obj->IsNumber()) {
    3453             :     return i::IsInt32Double(obj->Number());
    3454             :   }
    3455             :   return false;
    3456             : }
    3457             : 
    3458             : 
    3459        9904 : bool Value::IsUint32() const {
    3460             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3461       17533 :   if (obj->IsSmi()) return i::Smi::ToInt(*obj) >= 0;
    3462        2275 :   if (obj->IsNumber()) {
    3463             :     double value = obj->Number();
    3464         118 :     return !i::IsMinusZero(value) &&
    3465         106 :         value >= 0 &&
    3466         224 :         value <= i::kMaxUInt32 &&
    3467             :         value == i::FastUI2D(i::FastD2UI(value));
    3468             :   }
    3469             :   return false;
    3470             : }
    3471             : 
    3472             : 
    3473      903229 : bool Value::IsNativeError() const {
    3474      903229 :   return Utils::OpenHandle(this)->IsJSError();
    3475             : }
    3476             : 
    3477             : 
    3478     3242772 : bool Value::IsRegExp() const {
    3479             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3480     3242772 :   return obj->IsJSRegExp();
    3481             : }
    3482             : 
    3483          12 : bool Value::IsAsyncFunction() const {
    3484             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3485          12 :   if (!obj->IsJSFunction()) return false;
    3486             :   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
    3487             :   return i::IsAsyncFunction(func->shared()->kind());
    3488             : }
    3489             : 
    3490          95 : bool Value::IsGeneratorFunction() const {
    3491             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3492          95 :   if (!obj->IsJSFunction()) return false;
    3493             :   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(obj);
    3494             :   return i::IsGeneratorFunction(func->shared()->kind());
    3495             : }
    3496             : 
    3497             : 
    3498     1065143 : bool Value::IsGeneratorObject() const {
    3499     1065143 :   return Utils::OpenHandle(this)->IsJSGeneratorObject();
    3500             : }
    3501             : 
    3502             : 
    3503      895876 : bool Value::IsMapIterator() const {
    3504      895876 :   return Utils::OpenHandle(this)->IsJSMapIterator();
    3505             : }
    3506             : 
    3507             : 
    3508      895764 : bool Value::IsSetIterator() const {
    3509      895764 :   return Utils::OpenHandle(this)->IsJSSetIterator();
    3510             : }
    3511             : 
    3512     1823112 : bool Value::IsPromise() const { return Utils::OpenHandle(this)->IsJSPromise(); }
    3513             : 
    3514           5 : bool Value::IsModuleNamespaceObject() const {
    3515           5 :   return Utils::OpenHandle(this)->IsJSModuleNamespace();
    3516             : }
    3517             : 
    3518    13339732 : MaybeLocal<String> Value::ToString(Local<Context> context) const {
    3519             :   auto obj = Utils::OpenHandle(this);
    3520    13339732 :   if (obj->IsString()) return ToApiHandle<String>(obj);
    3521     7516244 :   PREPARE_FOR_EXECUTION(context, Object, ToString, String);
    3522             :   Local<String> result;
    3523             :   has_pending_exception =
    3524     1879061 :       !ToLocal<String>(i::Object::ToString(isolate, obj), &result);
    3525     1879061 :   RETURN_ON_FAILED_EXECUTION(String);
    3526     1878958 :   RETURN_ESCAPED(result);
    3527             : }
    3528             : 
    3529             : 
    3530           0 : Local<String> Value::ToString(Isolate* isolate) const {
    3531           0 :   RETURN_TO_LOCAL_UNCHECKED(ToString(isolate->GetCurrentContext()), String);
    3532             : }
    3533             : 
    3534             : 
    3535          15 : MaybeLocal<String> Value::ToDetailString(Local<Context> context) const {
    3536             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3537          15 :   if (obj->IsString()) return ToApiHandle<String>(obj);
    3538          60 :   PREPARE_FOR_EXECUTION(context, Object, ToDetailString, String);
    3539             :   Local<String> result =
    3540          15 :       Utils::ToLocal(i::Object::NoSideEffectsToString(isolate, obj));
    3541             :   RETURN_ON_FAILED_EXECUTION(String);
    3542          15 :   RETURN_ESCAPED(result);
    3543             : }
    3544             : 
    3545             : 
    3546         424 : MaybeLocal<Object> Value::ToObject(Local<Context> context) const {
    3547             :   auto obj = Utils::OpenHandle(this);
    3548         424 :   if (obj->IsJSReceiver()) return ToApiHandle<Object>(obj);
    3549         164 :   PREPARE_FOR_EXECUTION(context, Object, ToObject, Object);
    3550             :   Local<Object> result;
    3551             :   has_pending_exception =
    3552          41 :       !ToLocal<Object>(i::Object::ToObject(isolate, obj), &result);
    3553          41 :   RETURN_ON_FAILED_EXECUTION(Object);
    3554          35 :   RETURN_ESCAPED(result);
    3555             : }
    3556             : 
    3557             : 
    3558           0 : Local<v8::Object> Value::ToObject(Isolate* isolate) const {
    3559           0 :   RETURN_TO_LOCAL_UNCHECKED(ToObject(isolate->GetCurrentContext()), Object);
    3560             : }
    3561             : 
    3562          56 : MaybeLocal<BigInt> Value::ToBigInt(Local<Context> context) const {
    3563             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    3564          56 :   if (obj->IsBigInt()) return ToApiHandle<BigInt>(obj);
    3565         128 :   PREPARE_FOR_EXECUTION(context, Object, ToBigInt, BigInt);
    3566             :   Local<BigInt> result;
    3567             :   has_pending_exception =
    3568          32 :       !ToLocal<BigInt>(i::BigInt::FromObject(isolate, obj), &result);
    3569          32 :   RETURN_ON_FAILED_EXECUTION(BigInt);
    3570          16 :   RETURN_ESCAPED(result);
    3571             : }
    3572             : 
    3573       31248 : bool Value::BooleanValue(Isolate* v8_isolate) const {
    3574       62616 :   return Utils::OpenHandle(this)->BooleanValue(
    3575       62556 :       reinterpret_cast<i::Isolate*>(v8_isolate));
    3576             : }
    3577             : 
    3578           0 : MaybeLocal<Boolean> Value::ToBoolean(Local<Context> context) const {
    3579           0 :   return ToBoolean(context->GetIsolate());
    3580             : }
    3581             : 
    3582             : 
    3583          60 : Local<Boolean> Value::ToBoolean(Isolate* v8_isolate) const {
    3584             :   auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    3585             :   return ToApiHandle<Boolean>(
    3586          60 :       isolate->factory()->ToBoolean(BooleanValue(v8_isolate)));
    3587             : }
    3588             : 
    3589             : 
    3590        4167 : MaybeLocal<Number> Value::ToNumber(Local<Context> context) const {
    3591             :   auto obj = Utils::OpenHandle(this);
    3592        4167 :   if (obj->IsNumber()) return ToApiHandle<Number>(obj);
    3593         536 :   PREPARE_FOR_EXECUTION(context, Object, ToNumber, Number);
    3594             :   Local<Number> result;
    3595             :   has_pending_exception =
    3596         134 :       !ToLocal<Number>(i::Object::ToNumber(isolate, obj), &result);
    3597         134 :   RETURN_ON_FAILED_EXECUTION(Number);
    3598         128 :   RETURN_ESCAPED(result);
    3599             : }
    3600             : 
    3601             : 
    3602           0 : Local<Number> Value::ToNumber(Isolate* isolate) const {
    3603           0 :   RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number);
    3604             : }
    3605             : 
    3606             : 
    3607           6 : MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const {
    3608             :   auto obj = Utils::OpenHandle(this);
    3609           6 :   if (obj->IsSmi()) return ToApiHandle<Integer>(obj);
    3610          24 :   PREPARE_FOR_EXECUTION(context, Object, ToInteger, Integer);
    3611             :   Local<Integer> result;
    3612             :   has_pending_exception =
    3613             :       !ToLocal<Integer>(i::Object::ToInteger(isolate, obj), &result);
    3614           6 :   RETURN_ON_FAILED_EXECUTION(Integer);
    3615           0 :   RETURN_ESCAPED(result);
    3616             : }
    3617             : 
    3618             : 
    3619           0 : Local<Integer> Value::ToInteger(Isolate* isolate) const {
    3620           0 :   RETURN_TO_LOCAL_UNCHECKED(ToInteger(isolate->GetCurrentContext()), Integer);
    3621             : }
    3622             : 
    3623             : 
    3624        2634 : MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const {
    3625             :   auto obj = Utils::OpenHandle(this);
    3626        2634 :   if (obj->IsSmi()) return ToApiHandle<Int32>(obj);
    3627             :   Local<Int32> result;
    3628        4964 :   PREPARE_FOR_EXECUTION(context, Object, ToInt32, Int32);
    3629             :   has_pending_exception =
    3630             :       !ToLocal<Int32>(i::Object::ToInt32(isolate, obj), &result);
    3631        1241 :   RETURN_ON_FAILED_EXECUTION(Int32);
    3632        1235 :   RETURN_ESCAPED(result);
    3633             : }
    3634             : 
    3635             : 
    3636           0 : Local<Int32> Value::ToInt32(Isolate* isolate) const {
    3637           0 :   RETURN_TO_LOCAL_UNCHECKED(ToInt32(isolate->GetCurrentContext()), Int32);
    3638             : }
    3639             : 
    3640             : 
    3641          48 : MaybeLocal<Uint32> Value::ToUint32(Local<Context> context) const {
    3642             :   auto obj = Utils::OpenHandle(this);
    3643          48 :   if (obj->IsSmi()) return ToApiHandle<Uint32>(obj);
    3644             :   Local<Uint32> result;
    3645         144 :   PREPARE_FOR_EXECUTION(context, Object, ToUint32, Uint32);
    3646             :   has_pending_exception =
    3647          36 :       !ToLocal<Uint32>(i::Object::ToUint32(isolate, obj), &result);
    3648          36 :   RETURN_ON_FAILED_EXECUTION(Uint32);
    3649          30 :   RETURN_ESCAPED(result);
    3650             : }
    3651             : 
    3652        1209 : i::Isolate* i::IsolateFromNeverReadOnlySpaceObject(i::Address obj) {
    3653             :   return i::NeverReadOnlySpaceObject::GetIsolate(
    3654        1209 :       i::HeapObject::cast(i::Object(obj)));
    3655             : }
    3656             : 
    3657          96 : bool i::ShouldThrowOnError(i::Isolate* isolate) {
    3658          96 :   return i::GetShouldThrow(isolate, Nothing<i::ShouldThrow>()) ==
    3659          96 :          i::ShouldThrow::kThrowOnError;
    3660             : }
    3661             : 
    3662           0 : void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
    3663             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    3664           0 :   Utils::ApiCheck(isolate != nullptr && !isolate->IsDead(),
    3665             :                   "v8::internal::Internals::CheckInitialized",
    3666             :                   "Isolate is not initialized or V8 has died");
    3667           0 : }
    3668             : 
    3669             : 
    3670           0 : void External::CheckCast(v8::Value* that) {
    3671           0 :   Utils::ApiCheck(that->IsExternal(), "v8::External::Cast",
    3672             :                   "Could not convert to external");
    3673           0 : }
    3674             : 
    3675             : 
    3676           0 : void v8::Object::CheckCast(Value* that) {
    3677             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3678             :   Utils::ApiCheck(obj->IsJSReceiver(), "v8::Object::Cast",
    3679             :                   "Could not convert to object");
    3680           0 : }
    3681             : 
    3682             : 
    3683           0 : void v8::Function::CheckCast(Value* that) {
    3684             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3685             :   Utils::ApiCheck(obj->IsCallable(), "v8::Function::Cast",
    3686             :                   "Could not convert to function");
    3687           0 : }
    3688             : 
    3689             : 
    3690           0 : void v8::Boolean::CheckCast(v8::Value* that) {
    3691             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3692             :   Utils::ApiCheck(obj->IsBoolean(), "v8::Boolean::Cast",
    3693             :                   "Could not convert to boolean");
    3694           0 : }
    3695             : 
    3696             : 
    3697           0 : void v8::Name::CheckCast(v8::Value* that) {
    3698             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3699             :   Utils::ApiCheck(obj->IsName(), "v8::Name::Cast", "Could not convert to name");
    3700           0 : }
    3701             : 
    3702             : 
    3703           0 : void v8::String::CheckCast(v8::Value* that) {
    3704             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3705             :   Utils::ApiCheck(obj->IsString(), "v8::String::Cast",
    3706             :                   "Could not convert to string");
    3707           0 : }
    3708             : 
    3709             : 
    3710           0 : void v8::Symbol::CheckCast(v8::Value* that) {
    3711             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3712             :   Utils::ApiCheck(obj->IsSymbol(), "v8::Symbol::Cast",
    3713             :                   "Could not convert to symbol");
    3714           0 : }
    3715             : 
    3716             : 
    3717           0 : void v8::Private::CheckCast(v8::Data* that) {
    3718             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3719           0 :   Utils::ApiCheck(obj->IsSymbol() &&
    3720             :                   i::Handle<i::Symbol>::cast(obj)->is_private(),
    3721             :                   "v8::Private::Cast",
    3722             :                   "Could not convert to private");
    3723           0 : }
    3724             : 
    3725             : 
    3726           0 : void v8::Number::CheckCast(v8::Value* that) {
    3727             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3728             :   Utils::ApiCheck(obj->IsNumber(),
    3729             :                   "v8::Number::Cast()",
    3730             :                   "Could not convert to number");
    3731           0 : }
    3732             : 
    3733             : 
    3734           0 : void v8::Integer::CheckCast(v8::Value* that) {
    3735             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3736             :   Utils::ApiCheck(obj->IsNumber(), "v8::Integer::Cast",
    3737             :                   "Could not convert to number");
    3738           0 : }
    3739             : 
    3740             : 
    3741           0 : void v8::Int32::CheckCast(v8::Value* that) {
    3742           0 :   Utils::ApiCheck(that->IsInt32(), "v8::Int32::Cast",
    3743             :                   "Could not convert to 32-bit signed integer");
    3744           0 : }
    3745             : 
    3746             : 
    3747           0 : void v8::Uint32::CheckCast(v8::Value* that) {
    3748           0 :   Utils::ApiCheck(that->IsUint32(), "v8::Uint32::Cast",
    3749             :                   "Could not convert to 32-bit unsigned integer");
    3750           0 : }
    3751             : 
    3752           0 : void v8::BigInt::CheckCast(v8::Value* that) {
    3753           0 :   Utils::ApiCheck(that->IsBigInt(), "v8::BigInt::Cast",
    3754             :                   "Could not convert to BigInt");
    3755           0 : }
    3756             : 
    3757           0 : void v8::Array::CheckCast(Value* that) {
    3758             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3759             :   Utils::ApiCheck(obj->IsJSArray(), "v8::Array::Cast",
    3760             :                   "Could not convert to array");
    3761           0 : }
    3762             : 
    3763             : 
    3764           0 : void v8::Map::CheckCast(Value* that) {
    3765             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3766             :   Utils::ApiCheck(obj->IsJSMap(), "v8::Map::Cast", "Could not convert to Map");
    3767           0 : }
    3768             : 
    3769             : 
    3770           0 : void v8::Set::CheckCast(Value* that) {
    3771             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3772             :   Utils::ApiCheck(obj->IsJSSet(), "v8_Set_Cast", "Could not convert to Set");
    3773           0 : }
    3774             : 
    3775             : 
    3776           0 : void v8::Promise::CheckCast(Value* that) {
    3777           0 :   Utils::ApiCheck(that->IsPromise(), "v8::Promise::Cast",
    3778             :                   "Could not convert to promise");
    3779           0 : }
    3780             : 
    3781             : 
    3782           0 : void v8::Promise::Resolver::CheckCast(Value* that) {
    3783           0 :   Utils::ApiCheck(that->IsPromise(), "v8::Promise::Resolver::Cast",
    3784             :                   "Could not convert to promise resolver");
    3785           0 : }
    3786             : 
    3787             : 
    3788           0 : void v8::Proxy::CheckCast(Value* that) {
    3789           0 :   Utils::ApiCheck(that->IsProxy(), "v8::Proxy::Cast",
    3790             :                   "Could not convert to proxy");
    3791           0 : }
    3792             : 
    3793           0 : void v8::WasmModuleObject::CheckCast(Value* that) {
    3794           0 :   Utils::ApiCheck(that->IsWebAssemblyCompiledModule(),
    3795             :                   "v8::WasmModuleObject::Cast",
    3796             :                   "Could not convert to wasm module object");
    3797           0 : }
    3798             : 
    3799           0 : void v8::ArrayBuffer::CheckCast(Value* that) {
    3800             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3801             :   Utils::ApiCheck(
    3802           0 :       obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(),
    3803             :       "v8::ArrayBuffer::Cast()", "Could not convert to ArrayBuffer");
    3804           0 : }
    3805             : 
    3806             : 
    3807           0 : void v8::ArrayBufferView::CheckCast(Value* that) {
    3808             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3809             :   Utils::ApiCheck(obj->IsJSArrayBufferView(),
    3810             :                   "v8::ArrayBufferView::Cast()",
    3811             :                   "Could not convert to ArrayBufferView");
    3812           0 : }
    3813             : 
    3814             : 
    3815           0 : void v8::TypedArray::CheckCast(Value* that) {
    3816             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3817             :   Utils::ApiCheck(obj->IsJSTypedArray(),
    3818             :                   "v8::TypedArray::Cast()",
    3819             :                   "Could not convert to TypedArray");
    3820           0 : }
    3821             : 
    3822             : #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype)                   \
    3823             :   void v8::Type##Array::CheckCast(Value* that) {                              \
    3824             :     i::Handle<i::Object> obj = Utils::OpenHandle(that);                       \
    3825             :     Utils::ApiCheck(                                                          \
    3826             :         obj->IsJSTypedArray() &&                                              \
    3827             :             i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array, \
    3828             :         "v8::" #Type "Array::Cast()", "Could not convert to " #Type "Array"); \
    3829             :   }
    3830             : 
    3831           0 : TYPED_ARRAYS(CHECK_TYPED_ARRAY_CAST)
    3832             : 
    3833             : #undef CHECK_TYPED_ARRAY_CAST
    3834             : 
    3835             : 
    3836           0 : void v8::DataView::CheckCast(Value* that) {
    3837             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3838             :   Utils::ApiCheck(obj->IsJSDataView(),
    3839             :                   "v8::DataView::Cast()",
    3840             :                   "Could not convert to DataView");
    3841           0 : }
    3842             : 
    3843             : 
    3844           0 : void v8::SharedArrayBuffer::CheckCast(Value* that) {
    3845             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3846             :   Utils::ApiCheck(
    3847           0 :       obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(),
    3848             :       "v8::SharedArrayBuffer::Cast()",
    3849             :       "Could not convert to SharedArrayBuffer");
    3850           0 : }
    3851             : 
    3852             : 
    3853           0 : void v8::Date::CheckCast(v8::Value* that) {
    3854             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3855             :   Utils::ApiCheck(obj->IsJSDate(), "v8::Date::Cast()",
    3856             :                   "Could not convert to date");
    3857           0 : }
    3858             : 
    3859             : 
    3860           0 : void v8::StringObject::CheckCast(v8::Value* that) {
    3861             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3862             :   Utils::ApiCheck(obj->IsStringWrapper(), "v8::StringObject::Cast()",
    3863             :                   "Could not convert to StringObject");
    3864           0 : }
    3865             : 
    3866             : 
    3867           0 : void v8::SymbolObject::CheckCast(v8::Value* that) {
    3868             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3869             :   Utils::ApiCheck(obj->IsSymbolWrapper(), "v8::SymbolObject::Cast()",
    3870             :                   "Could not convert to SymbolObject");
    3871           0 : }
    3872             : 
    3873             : 
    3874           0 : void v8::NumberObject::CheckCast(v8::Value* that) {
    3875             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3876             :   Utils::ApiCheck(obj->IsNumberWrapper(), "v8::NumberObject::Cast()",
    3877             :                   "Could not convert to NumberObject");
    3878           0 : }
    3879             : 
    3880           0 : void v8::BigIntObject::CheckCast(v8::Value* that) {
    3881             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3882             :   Utils::ApiCheck(obj->IsBigIntWrapper(), "v8::BigIntObject::Cast()",
    3883             :                   "Could not convert to BigIntObject");
    3884           0 : }
    3885             : 
    3886           0 : void v8::BooleanObject::CheckCast(v8::Value* that) {
    3887             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3888             :   Utils::ApiCheck(obj->IsBooleanWrapper(), "v8::BooleanObject::Cast()",
    3889             :                   "Could not convert to BooleanObject");
    3890           0 : }
    3891             : 
    3892             : 
    3893           0 : void v8::RegExp::CheckCast(v8::Value* that) {
    3894             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    3895             :   Utils::ApiCheck(obj->IsJSRegExp(),
    3896             :                   "v8::RegExp::Cast()",
    3897             :                   "Could not convert to regular expression");
    3898           0 : }
    3899             : 
    3900             : 
    3901           0 : Maybe<bool> Value::BooleanValue(Local<Context> context) const {
    3902             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3903           0 :   return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
    3904             : }
    3905             : 
    3906             : 
    3907       38802 : Maybe<double> Value::NumberValue(Local<Context> context) const {
    3908             :   auto obj = Utils::OpenHandle(this);
    3909       38802 :   if (obj->IsNumber()) return Just(obj->Number());
    3910             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3911        3129 :   ENTER_V8(isolate, context, Value, NumberValue, Nothing<double>(),
    3912             :            i::HandleScope);
    3913             :   i::Handle<i::Object> num;
    3914        2086 :   has_pending_exception = !i::Object::ToNumber(isolate, obj).ToHandle(&num);
    3915        1043 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(double);
    3916             :   return Just(num->Number());
    3917             : }
    3918             : 
    3919             : 
    3920        2154 : Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
    3921             :   auto obj = Utils::OpenHandle(this);
    3922        2154 :   if (obj->IsNumber()) {
    3923             :     return Just(NumberToInt64(*obj));
    3924             :   }
    3925             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3926          54 :   ENTER_V8(isolate, context, Value, IntegerValue, Nothing<int64_t>(),
    3927             :            i::HandleScope);
    3928             :   i::Handle<i::Object> num;
    3929             :   has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num);
    3930          18 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t);
    3931             :   return Just(NumberToInt64(*num));
    3932             : }
    3933             : 
    3934             : 
    3935      539023 : Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
    3936             :   auto obj = Utils::OpenHandle(this);
    3937     1077956 :   if (obj->IsNumber()) return Just(NumberToInt32(*obj));
    3938             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3939         270 :   ENTER_V8(isolate, context, Value, Int32Value, Nothing<int32_t>(),
    3940             :            i::HandleScope);
    3941             :   i::Handle<i::Object> num;
    3942             :   has_pending_exception = !i::Object::ToInt32(isolate, obj).ToHandle(&num);
    3943          90 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int32_t);
    3944             :   return Just(num->IsSmi() ? i::Smi::ToInt(*num)
    3945          84 :                            : static_cast<int32_t>(num->Number()));
    3946             : }
    3947             : 
    3948             : 
    3949         206 : Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
    3950             :   auto obj = Utils::OpenHandle(this);
    3951         406 :   if (obj->IsNumber()) return Just(NumberToUint32(*obj));
    3952             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    3953          18 :   ENTER_V8(isolate, context, Value, Uint32Value, Nothing<uint32_t>(),
    3954             :            i::HandleScope);
    3955             :   i::Handle<i::Object> num;
    3956          12 :   has_pending_exception = !i::Object::ToUint32(isolate, obj).ToHandle(&num);
    3957           6 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(uint32_t);
    3958             :   return Just(num->IsSmi() ? static_cast<uint32_t>(i::Smi::ToInt(*num))
    3959           0 :                            : static_cast<uint32_t>(num->Number()));
    3960             : }
    3961             : 
    3962             : 
    3963          42 : MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
    3964             :   auto self = Utils::OpenHandle(this);
    3965          42 :   if (self->IsSmi()) {
    3966          12 :     if (i::Smi::ToInt(*self) >= 0) return Utils::Uint32ToLocal(self);
    3967           6 :     return Local<Uint32>();
    3968             :   }
    3969         120 :   PREPARE_FOR_EXECUTION(context, Object, ToArrayIndex, Uint32);
    3970             :   i::Handle<i::Object> string_obj;
    3971             :   has_pending_exception =
    3972          60 :       !i::Object::ToString(isolate, self).ToHandle(&string_obj);
    3973          30 :   RETURN_ON_FAILED_EXECUTION(Uint32);
    3974             :   i::Handle<i::String> str = i::Handle<i::String>::cast(string_obj);
    3975             :   uint32_t index;
    3976          30 :   if (str->AsArrayIndex(&index)) {
    3977             :     i::Handle<i::Object> value;
    3978          12 :     if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
    3979           6 :       value = i::Handle<i::Object>(i::Smi::FromInt(index), isolate);
    3980             :     } else {
    3981           6 :       value = isolate->factory()->NewNumber(index);
    3982             :     }
    3983          12 :     RETURN_ESCAPED(Utils::Uint32ToLocal(value));
    3984             :   }
    3985          18 :   return Local<Uint32>();
    3986             : }
    3987             : 
    3988             : 
    3989      168374 : Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
    3990             :   i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
    3991      168374 :   auto self = Utils::OpenHandle(this);
    3992      168374 :   auto other = Utils::OpenHandle(*that);
    3993      168374 :   return i::Object::Equals(isolate, self, other);
    3994             : }
    3995             : 
    3996             : 
    3997        1562 : bool Value::StrictEquals(Local<Value> that) const {
    3998             :   auto self = Utils::OpenHandle(this);
    3999             :   auto other = Utils::OpenHandle(*that);
    4000        1562 :   return self->StrictEquals(*other);
    4001             : }
    4002             : 
    4003             : 
    4004      123304 : bool Value::SameValue(Local<Value> that) const {
    4005             :   auto self = Utils::OpenHandle(this);
    4006             :   auto other = Utils::OpenHandle(*that);
    4007      123304 :   return self->SameValue(*other);
    4008             : }
    4009             : 
    4010          50 : Local<String> Value::TypeOf(v8::Isolate* external_isolate) {
    4011             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    4012             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4013          50 :   LOG_API(isolate, Value, TypeOf);
    4014         100 :   return Utils::ToLocal(i::Object::TypeOf(isolate, Utils::OpenHandle(this)));
    4015             : }
    4016             : 
    4017          82 : Maybe<bool> Value::InstanceOf(v8::Local<v8::Context> context,
    4018             :                               v8::Local<v8::Object> object) {
    4019             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4020         246 :   ENTER_V8(isolate, context, Value, InstanceOf, Nothing<bool>(),
    4021             :            i::HandleScope);
    4022          82 :   auto left = Utils::OpenHandle(this);
    4023             :   auto right = Utils::OpenHandle(*object);
    4024             :   i::Handle<i::Object> result;
    4025             :   has_pending_exception =
    4026         164 :       !i::Object::InstanceOf(isolate, left, right).ToHandle(&result);
    4027          82 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4028             :   return Just(result->IsTrue(isolate));
    4029             : }
    4030             : 
    4031      187984 : Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
    4032             :                             v8::Local<Value> key, v8::Local<Value> value) {
    4033             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4034      563952 :   ENTER_V8(isolate, context, Object, Set, Nothing<bool>(), i::HandleScope);
    4035             :   auto self = Utils::OpenHandle(this);
    4036      187984 :   auto key_obj = Utils::OpenHandle(*key);
    4037      187984 :   auto value_obj = Utils::OpenHandle(*value);
    4038             :   has_pending_exception =
    4039      375968 :       i::Runtime::SetObjectProperty(isolate, self, key_obj, value_obj,
    4040             :                                     i::StoreOrigin::kMaybeKeyed,
    4041      187984 :                                     Just(i::ShouldThrow::kDontThrow))
    4042             :           .is_null();
    4043      187984 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4044             :   return Just(true);
    4045             : }
    4046             : 
    4047             : 
    4048           0 : bool v8::Object::Set(v8::Local<Value> key, v8::Local<Value> value) {
    4049           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4050           0 :   return Set(context, key, value).FromMaybe(false);
    4051             : }
    4052             : 
    4053             : 
    4054       10988 : Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
    4055             :                             v8::Local<Value> value) {
    4056             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4057       32964 :   ENTER_V8(isolate, context, Object, Set, Nothing<bool>(), i::HandleScope);
    4058             :   auto self = Utils::OpenHandle(this);
    4059       10988 :   auto value_obj = Utils::OpenHandle(*value);
    4060       21976 :   has_pending_exception = i::Object::SetElement(isolate, self, index, value_obj,
    4061       10988 :                                                 i::ShouldThrow::kDontThrow)
    4062             :                               .is_null();
    4063       10988 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4064             :   return Just(true);
    4065             : }
    4066             : 
    4067             : 
    4068           0 : bool v8::Object::Set(uint32_t index, v8::Local<Value> value) {
    4069           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4070           0 :   return Set(context, index, value).FromMaybe(false);
    4071             : }
    4072             : 
    4073             : 
    4074       18319 : Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
    4075             :                                            v8::Local<Name> key,
    4076             :                                            v8::Local<Value> value) {
    4077             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4078       54957 :   ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(),
    4079             :            i::HandleScope);
    4080       18319 :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4081       18319 :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4082       18319 :   i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
    4083             : 
    4084             :   Maybe<bool> result = i::JSReceiver::CreateDataProperty(
    4085       18319 :       isolate, self, key_obj, value_obj, Just(i::kDontThrow));
    4086             :   has_pending_exception = result.IsNothing();
    4087       18319 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4088       18314 :   return result;
    4089             : }
    4090             : 
    4091             : 
    4092       11755 : Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
    4093             :                                            uint32_t index,
    4094             :                                            v8::Local<Value> value) {
    4095             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4096       35265 :   ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(),
    4097             :            i::HandleScope);
    4098             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4099       11755 :   i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
    4100             : 
    4101             :   i::LookupIterator it(isolate, self, index, self, i::LookupIterator::OWN);
    4102             :   Maybe<bool> result =
    4103       11755 :       i::JSReceiver::CreateDataProperty(&it, value_obj, Just(i::kDontThrow));
    4104             :   has_pending_exception = result.IsNothing();
    4105       11755 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4106       11755 :   return result;
    4107             : }
    4108             : 
    4109             : struct v8::PropertyDescriptor::PrivateData {
    4110             :   PrivateData() : desc() {}
    4111             :   i::PropertyDescriptor desc;
    4112             : };
    4113             : 
    4114         216 : v8::PropertyDescriptor::PropertyDescriptor() : private_(new PrivateData()) {}
    4115             : 
    4116             : // DataDescriptor
    4117          83 : v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> value)
    4118         166 :     : private_(new PrivateData()) {
    4119             :   private_->desc.set_value(Utils::OpenHandle(*value, true));
    4120          83 : }
    4121             : 
    4122             : // DataDescriptor with writable field
    4123          26 : v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> value,
    4124             :                                            bool writable)
    4125          52 :     : private_(new PrivateData()) {
    4126             :   private_->desc.set_value(Utils::OpenHandle(*value, true));
    4127             :   private_->desc.set_writable(writable);
    4128          26 : }
    4129             : 
    4130             : // AccessorDescriptor
    4131          68 : v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> get,
    4132             :                                            v8::Local<v8::Value> set)
    4133         136 :     : private_(new PrivateData()) {
    4134             :   DCHECK(get.IsEmpty() || get->IsUndefined() || get->IsFunction());
    4135             :   DCHECK(set.IsEmpty() || set->IsUndefined() || set->IsFunction());
    4136             :   private_->desc.set_get(Utils::OpenHandle(*get, true));
    4137             :   private_->desc.set_set(Utils::OpenHandle(*set, true));
    4138          68 : }
    4139             : 
    4140         285 : v8::PropertyDescriptor::~PropertyDescriptor() { delete private_; }
    4141             : 
    4142          32 : v8::Local<Value> v8::PropertyDescriptor::value() const {
    4143             :   DCHECK(private_->desc.has_value());
    4144          32 :   return Utils::ToLocal(private_->desc.value());
    4145             : }
    4146             : 
    4147          22 : v8::Local<Value> v8::PropertyDescriptor::get() const {
    4148             :   DCHECK(private_->desc.has_get());
    4149          22 :   return Utils::ToLocal(private_->desc.get());
    4150             : }
    4151             : 
    4152          22 : v8::Local<Value> v8::PropertyDescriptor::set() const {
    4153             :   DCHECK(private_->desc.has_set());
    4154          22 :   return Utils::ToLocal(private_->desc.set());
    4155             : }
    4156             : 
    4157          69 : bool v8::PropertyDescriptor::has_value() const {
    4158         138 :   return private_->desc.has_value();
    4159             : }
    4160          69 : bool v8::PropertyDescriptor::has_get() const {
    4161         138 :   return private_->desc.has_get();
    4162             : }
    4163          69 : bool v8::PropertyDescriptor::has_set() const {
    4164         138 :   return private_->desc.has_set();
    4165             : }
    4166             : 
    4167          16 : bool v8::PropertyDescriptor::writable() const {
    4168             :   DCHECK(private_->desc.has_writable());
    4169          32 :   return private_->desc.writable();
    4170             : }
    4171             : 
    4172          69 : bool v8::PropertyDescriptor::has_writable() const {
    4173         138 :   return private_->desc.has_writable();
    4174             : }
    4175             : 
    4176          37 : void v8::PropertyDescriptor::set_enumerable(bool enumerable) {
    4177          37 :   private_->desc.set_enumerable(enumerable);
    4178          37 : }
    4179             : 
    4180          17 : bool v8::PropertyDescriptor::enumerable() const {
    4181             :   DCHECK(private_->desc.has_enumerable());
    4182          34 :   return private_->desc.enumerable();
    4183             : }
    4184             : 
    4185          63 : bool v8::PropertyDescriptor::has_enumerable() const {
    4186         126 :   return private_->desc.has_enumerable();
    4187             : }
    4188             : 
    4189          38 : void v8::PropertyDescriptor::set_configurable(bool configurable) {
    4190          38 :   private_->desc.set_configurable(configurable);
    4191          38 : }
    4192             : 
    4193          32 : bool v8::PropertyDescriptor::configurable() const {
    4194             :   DCHECK(private_->desc.has_configurable());
    4195          64 :   return private_->desc.configurable();
    4196             : }
    4197             : 
    4198          63 : bool v8::PropertyDescriptor::has_configurable() const {
    4199         126 :   return private_->desc.has_configurable();
    4200             : }
    4201             : 
    4202        3336 : Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
    4203             :                                           v8::Local<Name> key,
    4204             :                                           v8::Local<Value> value,
    4205             :                                           v8::PropertyAttribute attributes) {
    4206             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4207             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4208             :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4209             :   i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
    4210             : 
    4211             :   i::PropertyDescriptor desc;
    4212        3336 :   desc.set_writable(!(attributes & v8::ReadOnly));
    4213        3336 :   desc.set_enumerable(!(attributes & v8::DontEnum));
    4214        3336 :   desc.set_configurable(!(attributes & v8::DontDelete));
    4215             :   desc.set_value(value_obj);
    4216             : 
    4217        3336 :   if (self->IsJSProxy()) {
    4218           0 :     ENTER_V8(isolate, context, Object, DefineOwnProperty, Nothing<bool>(),
    4219             :              i::HandleScope);
    4220             :     Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
    4221           0 :         isolate, self, key_obj, &desc, Just(i::kDontThrow));
    4222             :     // Even though we said kDontThrow, there might be accessors that do throw.
    4223             :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4224           0 :     return success;
    4225             :   } else {
    4226             :     // If it's not a JSProxy, i::JSReceiver::DefineOwnProperty should never run
    4227             :     // a script.
    4228       10008 :     ENTER_V8_NO_SCRIPT(isolate, context, Object, DefineOwnProperty,
    4229             :                        Nothing<bool>(), i::HandleScope);
    4230             :     Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
    4231        3336 :         isolate, self, key_obj, &desc, Just(i::kDontThrow));
    4232             :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4233        3336 :     return success;
    4234             :   }
    4235             : }
    4236             : 
    4237         126 : Maybe<bool> v8::Object::DefineProperty(v8::Local<v8::Context> context,
    4238             :                                        v8::Local<Name> key,
    4239             :                                        PropertyDescriptor& descriptor) {
    4240             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4241         378 :   ENTER_V8(isolate, context, Object, DefineOwnProperty, Nothing<bool>(),
    4242             :            i::HandleScope);
    4243         126 :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4244             :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4245             : 
    4246             :   Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
    4247             :       isolate, self, key_obj, &descriptor.get_private()->desc,
    4248         252 :       Just(i::kDontThrow));
    4249             :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4250         126 :   return success;
    4251             : }
    4252             : 
    4253      241048 : Maybe<bool> v8::Object::SetPrivate(Local<Context> context, Local<Private> key,
    4254             :                                    Local<Value> value) {
    4255             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4256      723144 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, SetPrivate, Nothing<bool>(),
    4257             :                      i::HandleScope);
    4258             :   auto self = Utils::OpenHandle(this);
    4259             :   auto key_obj = Utils::OpenHandle(reinterpret_cast<Name*>(*key));
    4260             :   auto value_obj = Utils::OpenHandle(*value);
    4261      241048 :   if (self->IsJSProxy()) {
    4262             :     i::PropertyDescriptor desc;
    4263             :     desc.set_writable(true);
    4264             :     desc.set_enumerable(false);
    4265             :     desc.set_configurable(true);
    4266             :     desc.set_value(value_obj);
    4267             :     return i::JSProxy::SetPrivateSymbol(
    4268             :         isolate, i::Handle<i::JSProxy>::cast(self),
    4269          18 :         i::Handle<i::Symbol>::cast(key_obj), &desc, Just(i::kDontThrow));
    4270             :   }
    4271             :   auto js_object = i::Handle<i::JSObject>::cast(self);
    4272             :   i::LookupIterator it(js_object, key_obj, js_object);
    4273      482060 :   has_pending_exception = i::JSObject::DefineOwnPropertyIgnoreAttributes(
    4274             :                               &it, value_obj, i::DONT_ENUM)
    4275             :                               .is_null();
    4276      241030 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4277             :   return Just(true);
    4278             : }
    4279             : 
    4280             : 
    4281      424267 : MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
    4282             :                                   Local<Value> key) {
    4283     1697068 :   PREPARE_FOR_EXECUTION(context, Object, Get, Value);
    4284             :   auto self = Utils::OpenHandle(this);
    4285      424267 :   auto key_obj = Utils::OpenHandle(*key);
    4286             :   i::Handle<i::Object> result;
    4287             :   has_pending_exception =
    4288      848534 :       !i::Runtime::GetObjectProperty(isolate, self, key_obj).ToHandle(&result);
    4289      424267 :   RETURN_ON_FAILED_EXECUTION(Value);
    4290      424201 :   RETURN_ESCAPED(Utils::ToLocal(result));
    4291             : }
    4292             : 
    4293             : 
    4294           0 : Local<Value> v8::Object::Get(v8::Local<Value> key) {
    4295           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4296           0 :   RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
    4297             : }
    4298             : 
    4299             : 
    4300      158126 : MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
    4301      632504 :   PREPARE_FOR_EXECUTION(context, Object, Get, Value);
    4302      158126 :   auto self = Utils::OpenHandle(this);
    4303             :   i::Handle<i::Object> result;
    4304             :   has_pending_exception =
    4305      316252 :       !i::JSReceiver::GetElement(isolate, self, index).ToHandle(&result);
    4306      158126 :   RETURN_ON_FAILED_EXECUTION(Value);
    4307      158107 :   RETURN_ESCAPED(Utils::ToLocal(result));
    4308             : }
    4309             : 
    4310             : 
    4311           0 : Local<Value> v8::Object::Get(uint32_t index) {
    4312           0 :   auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
    4313           0 :   RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
    4314             : }
    4315             : 
    4316             : 
    4317        2462 : MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
    4318             :                                          Local<Private> key) {
    4319        2462 :   return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
    4320             : }
    4321             : 
    4322             : 
    4323          58 : Maybe<PropertyAttribute> v8::Object::GetPropertyAttributes(
    4324             :     Local<Context> context, Local<Value> key) {
    4325             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4326         174 :   ENTER_V8(isolate, context, Object, GetPropertyAttributes,
    4327             :            Nothing<PropertyAttribute>(), i::HandleScope);
    4328          58 :   auto self = Utils::OpenHandle(this);
    4329             :   auto key_obj = Utils::OpenHandle(*key);
    4330          58 :   if (!key_obj->IsName()) {
    4331             :     has_pending_exception =
    4332          24 :         !i::Object::ToString(isolate, key_obj).ToHandle(&key_obj);
    4333          12 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4334             :   }
    4335          52 :   auto key_name = i::Handle<i::Name>::cast(key_obj);
    4336          52 :   auto result = i::JSReceiver::GetPropertyAttributes(self, key_name);
    4337             :   has_pending_exception = result.IsNothing();
    4338          52 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4339          52 :   if (result.FromJust() == i::ABSENT) {
    4340             :     return Just(static_cast<PropertyAttribute>(i::NONE));
    4341             :   }
    4342             :   return Just(static_cast<PropertyAttribute>(result.FromJust()));
    4343             : }
    4344             : 
    4345             : 
    4346        7730 : MaybeLocal<Value> v8::Object::GetOwnPropertyDescriptor(Local<Context> context,
    4347             :                                                        Local<Name> key) {
    4348       30920 :   PREPARE_FOR_EXECUTION(context, Object, GetOwnPropertyDescriptor, Value);
    4349        7730 :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    4350             :   i::Handle<i::Name> key_name = Utils::OpenHandle(*key);
    4351             : 
    4352             :   i::PropertyDescriptor desc;
    4353             :   Maybe<bool> found =
    4354        7730 :       i::JSReceiver::GetOwnPropertyDescriptor(isolate, obj, key_name, &desc);
    4355             :   has_pending_exception = found.IsNothing();
    4356        7730 :   RETURN_ON_FAILED_EXECUTION(Value);
    4357        7730 :   if (!found.FromJust()) {
    4358           5 :     return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    4359             :   }
    4360       15450 :   RETURN_ESCAPED(Utils::ToLocal(desc.ToObject(isolate)));
    4361             : }
    4362             : 
    4363             : 
    4364      263875 : Local<Value> v8::Object::GetPrototype() {
    4365             :   auto isolate = Utils::OpenHandle(this)->GetIsolate();
    4366      263875 :   auto self = Utils::OpenHandle(this);
    4367      263875 :   i::PrototypeIterator iter(isolate, self);
    4368      263875 :   return Utils::ToLocal(i::PrototypeIterator::GetCurrent(iter));
    4369             : }
    4370             : 
    4371             : 
    4372       11193 : Maybe<bool> v8::Object::SetPrototype(Local<Context> context,
    4373             :                                      Local<Value> value) {
    4374             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4375       33579 :   ENTER_V8(isolate, context, Object, SetPrototype, Nothing<bool>(),
    4376             :            i::HandleScope);
    4377       11193 :   auto self = Utils::OpenHandle(this);
    4378       11193 :   auto value_obj = Utils::OpenHandle(*value);
    4379             :   // We do not allow exceptions thrown while setting the prototype
    4380             :   // to propagate outside.
    4381       22386 :   TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
    4382             :   auto result =
    4383       11193 :       i::JSReceiver::SetPrototype(self, value_obj, false, i::kThrowOnError);
    4384             :   has_pending_exception = result.IsNothing();
    4385       11193 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4386             :   return Just(true);
    4387             : }
    4388             : 
    4389             : 
    4390          54 : Local<Object> v8::Object::FindInstanceInPrototypeChain(
    4391             :     v8::Local<FunctionTemplate> tmpl) {
    4392             :   auto self = Utils::OpenHandle(this);
    4393             :   auto isolate = self->GetIsolate();
    4394             :   i::PrototypeIterator iter(isolate, *self, i::kStartAtReceiver);
    4395          54 :   auto tmpl_info = *Utils::OpenHandle(*tmpl);
    4396         108 :   while (!tmpl_info->IsTemplateFor(iter.GetCurrent<i::JSObject>())) {
    4397          72 :     iter.Advance();
    4398          72 :     if (iter.IsAtEnd()) return Local<Object>();
    4399          54 :     if (!iter.GetCurrent()->IsJSObject()) return Local<Object>();
    4400             :   }
    4401             :   // IsTemplateFor() ensures that iter.GetCurrent() can't be a Proxy here.
    4402             :   return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate));
    4403             : }
    4404             : 
    4405        5907 : MaybeLocal<Array> v8::Object::GetPropertyNames(Local<Context> context) {
    4406             :   return GetPropertyNames(
    4407             :       context, v8::KeyCollectionMode::kIncludePrototypes,
    4408             :       static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS),
    4409        5907 :       v8::IndexFilter::kIncludeIndices);
    4410             : }
    4411             : 
    4412        6618 : MaybeLocal<Array> v8::Object::GetPropertyNames(
    4413             :     Local<Context> context, KeyCollectionMode mode,
    4414             :     PropertyFilter property_filter, IndexFilter index_filter,
    4415             :     KeyConversionMode key_conversion) {
    4416       26472 :   PREPARE_FOR_EXECUTION(context, Object, GetPropertyNames, Array);
    4417        6618 :   auto self = Utils::OpenHandle(this);
    4418             :   i::Handle<i::FixedArray> value;
    4419             :   i::KeyAccumulator accumulator(
    4420             :       isolate, static_cast<i::KeyCollectionMode>(mode),
    4421             :       static_cast<i::PropertyFilter>(property_filter));
    4422        6618 :   accumulator.set_skip_indices(index_filter == IndexFilter::kSkipIndices);
    4423       13236 :   has_pending_exception = accumulator.CollectKeys(self, self).IsNothing();
    4424        6618 :   RETURN_ON_FAILED_EXECUTION(Array);
    4425             :   value =
    4426        6618 :       accumulator.GetKeys(static_cast<i::GetKeysConversion>(key_conversion));
    4427             :   DCHECK(self->map()->EnumLength() == i::kInvalidEnumCacheSentinel ||
    4428             :          self->map()->EnumLength() == 0 ||
    4429             :          self->map()->instance_descriptors()->enum_cache()->keys() != *value);
    4430        6618 :   auto result = isolate->factory()->NewJSArrayWithElements(value);
    4431        6618 :   RETURN_ESCAPED(Utils::ToLocal(result));
    4432             : }
    4433             : 
    4434         591 : MaybeLocal<Array> v8::Object::GetOwnPropertyNames(Local<Context> context) {
    4435             :   return GetOwnPropertyNames(
    4436         591 :       context, static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS));
    4437             : }
    4438             : 
    4439          24 : MaybeLocal<Array> v8::Object::GetOwnPropertyNames(
    4440             :     Local<Context> context, PropertyFilter filter,
    4441             :     KeyConversionMode key_conversion) {
    4442             :   return GetPropertyNames(context, KeyCollectionMode::kOwnOnly, filter,
    4443         615 :                           v8::IndexFilter::kIncludeIndices, key_conversion);
    4444             : }
    4445             : 
    4446         483 : MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) {
    4447        1932 :   PREPARE_FOR_EXECUTION(context, Object, ObjectProtoToString, String);
    4448             :   auto self = Utils::OpenHandle(this);
    4449             :   Local<Value> result;
    4450             :   has_pending_exception =
    4451        1449 :       !ToLocal<Value>(i::Execution::Call(isolate, isolate->object_to_string(),
    4452             :                                          self, 0, nullptr),
    4453             :                       &result);
    4454         483 :   RETURN_ON_FAILED_EXECUTION(String);
    4455         468 :   RETURN_ESCAPED(Local<String>::Cast(result));
    4456             : }
    4457             : 
    4458             : 
    4459     3632112 : Local<String> v8::Object::GetConstructorName() {
    4460     3632112 :   auto self = Utils::OpenHandle(this);
    4461     3632112 :   i::Handle<i::String> name = i::JSReceiver::GetConstructorName(self);
    4462     3632112 :   return Utils::ToLocal(name);
    4463             : }
    4464             : 
    4465           6 : Maybe<bool> v8::Object::SetIntegrityLevel(Local<Context> context,
    4466             :                                           IntegrityLevel level) {
    4467             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4468          18 :   ENTER_V8(isolate, context, Object, SetIntegrityLevel, Nothing<bool>(),
    4469             :            i::HandleScope);
    4470           6 :   auto self = Utils::OpenHandle(this);
    4471             :   i::JSReceiver::IntegrityLevel i_level =
    4472           6 :       level == IntegrityLevel::kFrozen ? i::FROZEN : i::SEALED;
    4473             :   Maybe<bool> result =
    4474           6 :       i::JSReceiver::SetIntegrityLevel(self, i_level, i::kThrowOnError);
    4475             :   has_pending_exception = result.IsNothing();
    4476           6 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4477           5 :   return result;
    4478             : }
    4479             : 
    4480        7991 : Maybe<bool> v8::Object::Delete(Local<Context> context, Local<Value> key) {
    4481             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4482             :   auto self = Utils::OpenHandle(this);
    4483        7991 :   auto key_obj = Utils::OpenHandle(*key);
    4484        7991 :   if (self->IsJSProxy()) {
    4485           0 :     ENTER_V8(isolate, context, Object, Delete, Nothing<bool>(), i::HandleScope);
    4486             :     Maybe<bool> result = i::Runtime::DeleteObjectProperty(
    4487           0 :         isolate, self, key_obj, i::LanguageMode::kSloppy);
    4488             :     has_pending_exception = result.IsNothing();
    4489           0 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4490           0 :     return result;
    4491             :   } else {
    4492             :     // If it's not a JSProxy, i::Runtime::DeleteObjectProperty should never run
    4493             :     // a script.
    4494       23973 :     ENTER_V8_NO_SCRIPT(isolate, context, Object, Delete, Nothing<bool>(),
    4495             :                        i::HandleScope);
    4496             :     Maybe<bool> result = i::Runtime::DeleteObjectProperty(
    4497        7991 :         isolate, self, key_obj, i::LanguageMode::kSloppy);
    4498             :     has_pending_exception = result.IsNothing();
    4499        7991 :     RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4500        7991 :     return result;
    4501             :   }
    4502             : }
    4503             : 
    4504          42 : Maybe<bool> v8::Object::DeletePrivate(Local<Context> context,
    4505             :                                       Local<Private> key) {
    4506             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4507             :   // In case of private symbols, i::Runtime::DeleteObjectProperty does not run
    4508             :   // any author script.
    4509         126 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, Delete, Nothing<bool>(),
    4510             :                      i::HandleScope);
    4511          42 :   auto self = Utils::OpenHandle(this);
    4512          42 :   auto key_obj = Utils::OpenHandle(*key);
    4513             :   Maybe<bool> result = i::Runtime::DeleteObjectProperty(
    4514          42 :       isolate, self, key_obj, i::LanguageMode::kSloppy);
    4515             :   has_pending_exception = result.IsNothing();
    4516          42 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4517          42 :   return result;
    4518             : }
    4519             : 
    4520        9130 : Maybe<bool> v8::Object::Has(Local<Context> context, Local<Value> key) {
    4521             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4522       27390 :   ENTER_V8(isolate, context, Object, Has, Nothing<bool>(), i::HandleScope);
    4523        9130 :   auto self = Utils::OpenHandle(this);
    4524             :   auto key_obj = Utils::OpenHandle(*key);
    4525             :   Maybe<bool> maybe = Nothing<bool>();
    4526             :   // Check if the given key is an array index.
    4527        9130 :   uint32_t index = 0;
    4528       18260 :   if (key_obj->ToArrayIndex(&index)) {
    4529           0 :     maybe = i::JSReceiver::HasElement(self, index);
    4530             :   } else {
    4531             :     // Convert the key to a name - possibly by calling back into JavaScript.
    4532             :     i::Handle<i::Name> name;
    4533       18260 :     if (i::Object::ToName(isolate, key_obj).ToHandle(&name)) {
    4534        9130 :       maybe = i::JSReceiver::HasProperty(self, name);
    4535             :     }
    4536             :   }
    4537             :   has_pending_exception = maybe.IsNothing();
    4538        9130 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4539        9130 :   return maybe;
    4540             : }
    4541             : 
    4542             : 
    4543       79707 : Maybe<bool> v8::Object::HasPrivate(Local<Context> context, Local<Private> key) {
    4544       79707 :   return HasOwnProperty(context, Local<Name>(reinterpret_cast<Name*>(*key)));
    4545             : }
    4546             : 
    4547             : 
    4548          10 : Maybe<bool> v8::Object::Delete(Local<Context> context, uint32_t index) {
    4549             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4550          30 :   ENTER_V8(isolate, context, Object, Delete, Nothing<bool>(), i::HandleScope);
    4551          10 :   auto self = Utils::OpenHandle(this);
    4552          10 :   Maybe<bool> result = i::JSReceiver::DeleteElement(self, index);
    4553             :   has_pending_exception = result.IsNothing();
    4554          10 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4555           5 :   return result;
    4556             : }
    4557             : 
    4558             : 
    4559          30 : Maybe<bool> v8::Object::Has(Local<Context> context, uint32_t index) {
    4560             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4561          90 :   ENTER_V8(isolate, context, Object, Has, Nothing<bool>(), i::HandleScope);
    4562          30 :   auto self = Utils::OpenHandle(this);
    4563          30 :   auto maybe = i::JSReceiver::HasElement(self, index);
    4564             :   has_pending_exception = maybe.IsNothing();
    4565          30 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4566          30 :   return maybe;
    4567             : }
    4568             : 
    4569             : template <typename Getter, typename Setter, typename Data>
    4570        7910 : static Maybe<bool> ObjectSetAccessor(
    4571             :     Local<Context> context, Object* self, Local<Name> name, Getter getter,
    4572             :     Setter setter, Data data, AccessControl settings,
    4573             :     PropertyAttribute attributes, bool is_special_data_property,
    4574             :     bool replace_on_access, SideEffectType getter_side_effect_type,
    4575             :     SideEffectType setter_side_effect_type) {
    4576             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4577       23730 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, SetAccessor, Nothing<bool>(),
    4578             :                      i::HandleScope);
    4579        7910 :   if (!Utils::OpenHandle(self)->IsJSObject()) return Just(false);
    4580             :   i::Handle<i::JSObject> obj =
    4581             :       i::Handle<i::JSObject>::cast(Utils::OpenHandle(self));
    4582             :   v8::Local<AccessorSignature> signature;
    4583             :   i::Handle<i::AccessorInfo> info =
    4584        7910 :       MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature,
    4585        7910 :                        is_special_data_property, replace_on_access);
    4586        7910 :   info->set_getter_side_effect_type(getter_side_effect_type);
    4587        7910 :   info->set_setter_side_effect_type(setter_side_effect_type);
    4588        7910 :   if (info.is_null()) return Nothing<bool>();
    4589        7910 :   bool fast = obj->HasFastProperties();
    4590             :   i::Handle<i::Object> result;
    4591             : 
    4592             :   i::Handle<i::Name> accessor_name(info->name(), isolate);
    4593             :   i::PropertyAttributes attrs = static_cast<i::PropertyAttributes>(attributes);
    4594             :   has_pending_exception =
    4595             :       !i::JSObject::SetAccessor(obj, accessor_name, info, attrs)
    4596       15820 :            .ToHandle(&result);
    4597        7910 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4598        7905 :   if (result->IsUndefined(isolate)) return Just(false);
    4599        7880 :   if (fast) {
    4600        7868 :     i::JSObject::MigrateSlowToFast(obj, 0, "APISetAccessor");
    4601             :   }
    4602             :   return Just(true);
    4603             : }
    4604             : 
    4605        7874 : Maybe<bool> Object::SetAccessor(Local<Context> context, Local<Name> name,
    4606             :                                 AccessorNameGetterCallback getter,
    4607             :                                 AccessorNameSetterCallback setter,
    4608             :                                 MaybeLocal<Value> data, AccessControl settings,
    4609             :                                 PropertyAttribute attribute,
    4610             :                                 SideEffectType getter_side_effect_type,
    4611             :                                 SideEffectType setter_side_effect_type) {
    4612             :   return ObjectSetAccessor(context, this, name, getter, setter,
    4613             :                            data.FromMaybe(Local<Value>()), settings, attribute,
    4614             :                            i::FLAG_disable_old_api_accessors, false,
    4615       15748 :                            getter_side_effect_type, setter_side_effect_type);
    4616             : }
    4617             : 
    4618             : 
    4619      323395 : void Object::SetAccessorProperty(Local<Name> name, Local<Function> getter,
    4620             :                                  Local<Function> setter,
    4621             :                                  PropertyAttribute attribute,
    4622             :                                  AccessControl settings) {
    4623             :   // TODO(verwaest): Remove |settings|.
    4624             :   DCHECK_EQ(v8::DEFAULT, settings);
    4625             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    4626             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4627             :   i::HandleScope scope(isolate);
    4628             :   auto self = Utils::OpenHandle(this);
    4629      323395 :   if (!self->IsJSObject()) return;
    4630             :   i::Handle<i::Object> getter_i = v8::Utils::OpenHandle(*getter);
    4631             :   i::Handle<i::Object> setter_i = v8::Utils::OpenHandle(*setter, true);
    4632      323395 :   if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
    4633             :   i::JSObject::DefineAccessor(i::Handle<i::JSObject>::cast(self),
    4634             :                               v8::Utils::OpenHandle(*name), getter_i, setter_i,
    4635      323395 :                               static_cast<i::PropertyAttributes>(attribute));
    4636             : }
    4637             : 
    4638          16 : Maybe<bool> Object::SetNativeDataProperty(
    4639             :     v8::Local<v8::Context> context, v8::Local<Name> name,
    4640             :     AccessorNameGetterCallback getter, AccessorNameSetterCallback setter,
    4641             :     v8::Local<Value> data, PropertyAttribute attributes,
    4642             :     SideEffectType getter_side_effect_type,
    4643             :     SideEffectType setter_side_effect_type) {
    4644             :   return ObjectSetAccessor(context, this, name, getter, setter, data, DEFAULT,
    4645             :                            attributes, true, false, getter_side_effect_type,
    4646          16 :                            setter_side_effect_type);
    4647             : }
    4648             : 
    4649          20 : Maybe<bool> Object::SetLazyDataProperty(
    4650             :     v8::Local<v8::Context> context, v8::Local<Name> name,
    4651             :     AccessorNameGetterCallback getter, v8::Local<Value> data,
    4652             :     PropertyAttribute attributes, SideEffectType getter_side_effect_type,
    4653             :     SideEffectType setter_side_effect_type) {
    4654             :   return ObjectSetAccessor(context, this, name, getter,
    4655             :                            static_cast<AccessorNameSetterCallback>(nullptr),
    4656             :                            data, DEFAULT, attributes, true, true,
    4657          20 :                            getter_side_effect_type, setter_side_effect_type);
    4658             : }
    4659             : 
    4660       87066 : Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context,
    4661             :                                        Local<Name> key) {
    4662             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4663      261198 :   ENTER_V8(isolate, context, Object, HasOwnProperty, Nothing<bool>(),
    4664             :            i::HandleScope);
    4665       87066 :   auto self = Utils::OpenHandle(this);
    4666       87066 :   auto key_val = Utils::OpenHandle(*key);
    4667       87066 :   auto result = i::JSReceiver::HasOwnProperty(self, key_val);
    4668             :   has_pending_exception = result.IsNothing();
    4669       87066 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4670       87061 :   return result;
    4671             : }
    4672             : 
    4673          25 : Maybe<bool> v8::Object::HasOwnProperty(Local<Context> context, uint32_t index) {
    4674             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4675          75 :   ENTER_V8(isolate, context, Object, HasOwnProperty, Nothing<bool>(),
    4676             :            i::HandleScope);
    4677          25 :   auto self = Utils::OpenHandle(this);
    4678          25 :   auto result = i::JSReceiver::HasOwnProperty(self, index);
    4679             :   has_pending_exception = result.IsNothing();
    4680          25 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4681          25 :   return result;
    4682             : }
    4683             : 
    4684        5847 : Maybe<bool> v8::Object::HasRealNamedProperty(Local<Context> context,
    4685             :                                              Local<Name> key) {
    4686             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4687       17541 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealNamedProperty,
    4688             :                      Nothing<bool>(), i::HandleScope);
    4689             :   auto self = Utils::OpenHandle(this);
    4690        5847 :   if (!self->IsJSObject()) return Just(false);
    4691        5842 :   auto key_val = Utils::OpenHandle(*key);
    4692             :   auto result = i::JSObject::HasRealNamedProperty(
    4693        5842 :       i::Handle<i::JSObject>::cast(self), key_val);
    4694             :   has_pending_exception = result.IsNothing();
    4695        5842 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4696        5837 :   return result;
    4697             : }
    4698             : 
    4699             : 
    4700          17 : Maybe<bool> v8::Object::HasRealIndexedProperty(Local<Context> context,
    4701             :                                                uint32_t index) {
    4702             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4703          51 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealIndexedProperty,
    4704             :                      Nothing<bool>(), i::HandleScope);
    4705             :   auto self = Utils::OpenHandle(this);
    4706          17 :   if (!self->IsJSObject()) return Just(false);
    4707             :   auto result = i::JSObject::HasRealElementProperty(
    4708          17 :       i::Handle<i::JSObject>::cast(self), index);
    4709             :   has_pending_exception = result.IsNothing();
    4710          17 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4711          12 :   return result;
    4712             : }
    4713             : 
    4714           5 : Maybe<bool> v8::Object::HasRealNamedCallbackProperty(Local<Context> context,
    4715             :                                                      Local<Name> key) {
    4716             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4717          15 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealNamedCallbackProperty,
    4718             :                      Nothing<bool>(), i::HandleScope);
    4719             :   auto self = Utils::OpenHandle(this);
    4720           5 :   if (!self->IsJSObject()) return Just(false);
    4721           5 :   auto key_val = Utils::OpenHandle(*key);
    4722             :   auto result = i::JSObject::HasRealNamedCallbackProperty(
    4723           5 :       i::Handle<i::JSObject>::cast(self), key_val);
    4724             :   has_pending_exception = result.IsNothing();
    4725           5 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    4726           0 :   return result;
    4727             : }
    4728             : 
    4729           0 : bool v8::Object::HasNamedLookupInterceptor() {
    4730             :   auto self = Utils::OpenHandle(this);
    4731           0 :   return self->IsJSObject() &&
    4732           0 :          i::Handle<i::JSObject>::cast(self)->HasNamedInterceptor();
    4733             : }
    4734             : 
    4735             : 
    4736           0 : bool v8::Object::HasIndexedLookupInterceptor() {
    4737             :   auto self = Utils::OpenHandle(this);
    4738           0 :   return self->IsJSObject() &&
    4739           0 :          i::Handle<i::JSObject>::cast(self)->HasIndexedInterceptor();
    4740             : }
    4741             : 
    4742             : 
    4743           6 : MaybeLocal<Value> v8::Object::GetRealNamedPropertyInPrototypeChain(
    4744             :     Local<Context> context, Local<Name> key) {
    4745          24 :   PREPARE_FOR_EXECUTION(context, Object, GetRealNamedPropertyInPrototypeChain,
    4746             :                         Value);
    4747             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4748           6 :   if (!self->IsJSObject()) return MaybeLocal<Value>();
    4749           6 :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4750           6 :   i::PrototypeIterator iter(isolate, self);
    4751           6 :   if (iter.IsAtEnd()) return MaybeLocal<Value>();
    4752             :   i::Handle<i::JSReceiver> proto =
    4753           6 :       i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter);
    4754             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4755             :       isolate, self, key_obj, proto,
    4756           6 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4757             :   Local<Value> result;
    4758           6 :   has_pending_exception = !ToLocal<Value>(i::Object::GetProperty(&it), &result);
    4759           6 :   RETURN_ON_FAILED_EXECUTION(Value);
    4760           0 :   if (!it.IsFound()) return MaybeLocal<Value>();
    4761           0 :   RETURN_ESCAPED(result);
    4762             : }
    4763             : 
    4764             : 
    4765             : Maybe<PropertyAttribute>
    4766           6 : v8::Object::GetRealNamedPropertyAttributesInPrototypeChain(
    4767             :     Local<Context> context, Local<Name> key) {
    4768             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4769          18 :   ENTER_V8_NO_SCRIPT(isolate, context, Object,
    4770             :                      GetRealNamedPropertyAttributesInPrototypeChain,
    4771             :                      Nothing<PropertyAttribute>(), i::HandleScope);
    4772             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    4773           6 :   if (!self->IsJSObject()) return Nothing<PropertyAttribute>();
    4774           6 :   i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
    4775           6 :   i::PrototypeIterator iter(isolate, self);
    4776           6 :   if (iter.IsAtEnd()) return Nothing<PropertyAttribute>();
    4777             :   i::Handle<i::JSReceiver> proto =
    4778           6 :       i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter);
    4779             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4780             :       isolate, self, key_obj, proto,
    4781           6 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4782             :   Maybe<i::PropertyAttributes> result =
    4783           6 :       i::JSReceiver::GetPropertyAttributes(&it);
    4784             :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4785           6 :   if (!it.IsFound()) return Nothing<PropertyAttribute>();
    4786           6 :   if (result.FromJust() == i::ABSENT) return Just(None);
    4787             :   return Just(static_cast<PropertyAttribute>(result.FromJust()));
    4788             : }
    4789             : 
    4790             : 
    4791      833486 : MaybeLocal<Value> v8::Object::GetRealNamedProperty(Local<Context> context,
    4792             :                                                    Local<Name> key) {
    4793     3333944 :   PREPARE_FOR_EXECUTION(context, Object, GetRealNamedProperty, Value);
    4794             :   auto self = Utils::OpenHandle(this);
    4795      833486 :   auto key_obj = Utils::OpenHandle(*key);
    4796             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4797             :       isolate, self, key_obj, self,
    4798      833486 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4799             :   Local<Value> result;
    4800      833486 :   has_pending_exception = !ToLocal<Value>(i::Object::GetProperty(&it), &result);
    4801      833486 :   RETURN_ON_FAILED_EXECUTION(Value);
    4802      833468 :   if (!it.IsFound()) return MaybeLocal<Value>();
    4803         258 :   RETURN_ESCAPED(result);
    4804             : }
    4805             : 
    4806             : 
    4807          18 : Maybe<PropertyAttribute> v8::Object::GetRealNamedPropertyAttributes(
    4808             :     Local<Context> context, Local<Name> key) {
    4809             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4810          54 :   ENTER_V8_NO_SCRIPT(isolate, context, Object, GetRealNamedPropertyAttributes,
    4811             :                      Nothing<PropertyAttribute>(), i::HandleScope);
    4812             :   auto self = Utils::OpenHandle(this);
    4813          18 :   auto key_obj = Utils::OpenHandle(*key);
    4814             :   i::LookupIterator it = i::LookupIterator::PropertyOrElement(
    4815             :       isolate, self, key_obj, self,
    4816          18 :       i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
    4817          18 :   auto result = i::JSReceiver::GetPropertyAttributes(&it);
    4818             :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
    4819          18 :   if (!it.IsFound()) return Nothing<PropertyAttribute>();
    4820          18 :   if (result.FromJust() == i::ABSENT) {
    4821             :     return Just(static_cast<PropertyAttribute>(i::NONE));
    4822             :   }
    4823             :   return Just<PropertyAttribute>(
    4824             :       static_cast<PropertyAttribute>(result.FromJust()));
    4825             : }
    4826             : 
    4827             : 
    4828          16 : Local<v8::Object> v8::Object::Clone() {
    4829             :   auto self = i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
    4830             :   auto isolate = self->GetIsolate();
    4831             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4832          16 :   auto result = isolate->factory()->CopyJSObject(self);
    4833          16 :   CHECK(!result.is_null());
    4834          16 :   return Utils::ToLocal(result);
    4835             : }
    4836             : 
    4837             : 
    4838      304925 : Local<v8::Context> v8::Object::CreationContext() {
    4839             :   auto self = Utils::OpenHandle(this);
    4840      304925 :   i::Handle<i::Context> context = self->GetCreationContext();
    4841      304925 :   return Utils::ToLocal(context);
    4842             : }
    4843             : 
    4844             : 
    4845          94 : int v8::Object::GetIdentityHash() {
    4846             :   i::DisallowHeapAllocation no_gc;
    4847             :   auto isolate = Utils::OpenHandle(this)->GetIsolate();
    4848             :   i::HandleScope scope(isolate);
    4849             :   auto self = Utils::OpenHandle(this);
    4850         282 :   return self->GetOrCreateIdentityHash(isolate)->value();
    4851             : }
    4852             : 
    4853             : 
    4854          24 : bool v8::Object::IsCallable() {
    4855             :   auto self = Utils::OpenHandle(this);
    4856          48 :   return self->IsCallable();
    4857             : }
    4858             : 
    4859           6 : bool v8::Object::IsConstructor() {
    4860             :   auto self = Utils::OpenHandle(this);
    4861          12 :   return self->IsConstructor();
    4862             : }
    4863             : 
    4864         114 : MaybeLocal<Value> Object::CallAsFunction(Local<Context> context,
    4865             :                                          Local<Value> recv, int argc,
    4866             :                                          Local<Value> argv[]) {
    4867             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4868         228 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4869         342 :   ENTER_V8(isolate, context, Object, CallAsFunction, MaybeLocal<Value>(),
    4870             :            InternalEscapableScope);
    4871             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4872             :   auto self = Utils::OpenHandle(this);
    4873         114 :   auto recv_obj = Utils::OpenHandle(*recv);
    4874             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4875             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4876             :   Local<Value> result;
    4877         228 :   has_pending_exception = !ToLocal<Value>(
    4878             :       i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
    4879         114 :   RETURN_ON_FAILED_EXECUTION(Value);
    4880         102 :   RETURN_ESCAPED(result);
    4881             : }
    4882             : 
    4883             : 
    4884           0 : MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc,
    4885             :                                             Local<Value> argv[]) {
    4886             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4887           0 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4888           0 :   ENTER_V8(isolate, context, Object, CallAsConstructor, MaybeLocal<Value>(),
    4889             :            InternalEscapableScope);
    4890             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4891             :   auto self = Utils::OpenHandle(this);
    4892             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4893             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4894             :   Local<Value> result;
    4895           0 :   has_pending_exception = !ToLocal<Value>(
    4896             :       i::Execution::New(isolate, self, self, argc, args), &result);
    4897           0 :   RETURN_ON_FAILED_EXECUTION(Value);
    4898           0 :   RETURN_ESCAPED(result);
    4899             : }
    4900             : 
    4901        5211 : MaybeLocal<Function> Function::New(Local<Context> context,
    4902             :                                    FunctionCallback callback, Local<Value> data,
    4903             :                                    int length, ConstructorBehavior behavior,
    4904             :                                    SideEffectType side_effect_type) {
    4905             :   i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
    4906        5211 :   LOG_API(isolate, Function, New);
    4907             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    4908             :   auto templ =
    4909             :       FunctionTemplateNew(isolate, callback, data, Local<Signature>(), length,
    4910        5211 :                           true, Local<Private>(), side_effect_type);
    4911        5211 :   if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
    4912       10422 :   return templ->GetFunction(context);
    4913             : }
    4914             : 
    4915         794 : MaybeLocal<Object> Function::NewInstance(Local<Context> context, int argc,
    4916             :                                          v8::Local<v8::Value> argv[]) const {
    4917             :   return NewInstanceWithSideEffectType(context, argc, argv,
    4918         794 :                                        SideEffectType::kHasSideEffect);
    4919             : }
    4920             : 
    4921         809 : MaybeLocal<Object> Function::NewInstanceWithSideEffectType(
    4922             :     Local<Context> context, int argc, v8::Local<v8::Value> argv[],
    4923             :     SideEffectType side_effect_type) const {
    4924             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4925        1618 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4926        2427 :   ENTER_V8(isolate, context, Function, NewInstance, MaybeLocal<Object>(),
    4927             :            InternalEscapableScope);
    4928             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4929             :   auto self = Utils::OpenHandle(this);
    4930             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4931             :   bool should_set_has_no_side_effect =
    4932         809 :       side_effect_type == SideEffectType::kHasNoSideEffect &&
    4933             :       isolate->debug_execution_mode() == i::DebugInfo::kSideEffects;
    4934         809 :   if (should_set_has_no_side_effect) {
    4935          20 :     CHECK(self->IsJSFunction() &&
    4936             :           i::JSFunction::cast(*self)->shared()->IsApiFunction());
    4937             :     i::Object obj =
    4938             :         i::JSFunction::cast(*self)->shared()->get_api_func_data()->call_code();
    4939          10 :     if (obj->IsCallHandlerInfo()) {
    4940          10 :       i::CallHandlerInfo handler_info = i::CallHandlerInfo::cast(obj);
    4941          10 :       if (!handler_info->IsSideEffectFreeCallHandlerInfo()) {
    4942          10 :         handler_info->SetNextCallHasNoSideEffect();
    4943             :       }
    4944             :     }
    4945             :   }
    4946             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4947             :   Local<Object> result;
    4948        1618 :   has_pending_exception = !ToLocal<Object>(
    4949         809 :       i::Execution::New(isolate, self, self, argc, args), &result);
    4950         809 :   if (should_set_has_no_side_effect) {
    4951             :     i::Object obj =
    4952             :         i::JSFunction::cast(*self)->shared()->get_api_func_data()->call_code();
    4953          10 :     if (obj->IsCallHandlerInfo()) {
    4954          10 :       i::CallHandlerInfo handler_info = i::CallHandlerInfo::cast(obj);
    4955          10 :       if (has_pending_exception) {
    4956             :         // Restore the map if an exception prevented restoration.
    4957           0 :         handler_info->NextCallHasNoSideEffect();
    4958             :       } else {
    4959             :         DCHECK(handler_info->IsSideEffectCallHandlerInfo() ||
    4960             :                handler_info->IsSideEffectFreeCallHandlerInfo());
    4961             :       }
    4962             :     }
    4963             :   }
    4964         809 :   RETURN_ON_FAILED_EXECUTION(Object);
    4965         793 :   RETURN_ESCAPED(result);
    4966             : }
    4967             : 
    4968             : 
    4969      341630 : MaybeLocal<v8::Value> Function::Call(Local<Context> context,
    4970             :                                      v8::Local<v8::Value> recv, int argc,
    4971             :                                      v8::Local<v8::Value> argv[]) {
    4972             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    4973      683260 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute");
    4974     1024899 :   ENTER_V8(isolate, context, Function, Call, MaybeLocal<Value>(),
    4975             :            InternalEscapableScope);
    4976             :   i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate);
    4977             :   auto self = Utils::OpenHandle(this);
    4978             :   Utils::ApiCheck(!self.is_null(), "v8::Function::Call",
    4979             :                   "Function to be called is a null pointer");
    4980      341630 :   i::Handle<i::Object> recv_obj = Utils::OpenHandle(*recv);
    4981             :   STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>));
    4982             :   i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv);
    4983             :   Local<Value> result;
    4984      683264 :   has_pending_exception = !ToLocal<Value>(
    4985             :       i::Execution::Call(isolate, self, recv_obj, argc, args), &result);
    4986      341634 :   RETURN_ON_FAILED_EXECUTION(Value);
    4987      341310 :   RETURN_ESCAPED(result);
    4988             : }
    4989             : 
    4990         640 : void Function::SetName(v8::Local<v8::String> name) {
    4991             :   auto self = Utils::OpenHandle(this);
    4992         640 :   if (!self->IsJSFunction()) return;
    4993             :   auto func = i::Handle<i::JSFunction>::cast(self);
    4994         640 :   func->shared()->SetName(*Utils::OpenHandle(*name));
    4995             : }
    4996             : 
    4997             : 
    4998          42 : Local<Value> Function::GetName() const {
    4999             :   auto self = Utils::OpenHandle(this);
    5000             :   i::Isolate* isolate = self->GetIsolate();
    5001          42 :   if (self->IsJSBoundFunction()) {
    5002           0 :     auto func = i::Handle<i::JSBoundFunction>::cast(self);
    5003             :     i::Handle<i::Object> name;
    5004           0 :     ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, name,
    5005             :                                      i::JSBoundFunction::GetName(isolate, func),
    5006             :                                      Local<Value>());
    5007             :     return Utils::ToLocal(name);
    5008             :   }
    5009          42 :   if (self->IsJSFunction()) {
    5010             :     auto func = i::Handle<i::JSFunction>::cast(self);
    5011          84 :     return Utils::ToLocal(handle(func->shared()->Name(), isolate));
    5012             :   }
    5013           0 :   return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
    5014             : }
    5015             : 
    5016             : 
    5017           6 : Local<Value> Function::GetInferredName() const {
    5018             :   auto self = Utils::OpenHandle(this);
    5019           6 :   if (!self->IsJSFunction()) {
    5020             :     return ToApiHandle<Primitive>(
    5021           0 :         self->GetIsolate()->factory()->undefined_value());
    5022             :   }
    5023             :   auto func = i::Handle<i::JSFunction>::cast(self);
    5024          12 :   return Utils::ToLocal(i::Handle<i::Object>(func->shared()->inferred_name(),
    5025             :                                              func->GetIsolate()));
    5026             : }
    5027             : 
    5028             : 
    5029          72 : Local<Value> Function::GetDebugName() const {
    5030             :   auto self = Utils::OpenHandle(this);
    5031          72 :   if (!self->IsJSFunction()) {
    5032             :     return ToApiHandle<Primitive>(
    5033           0 :         self->GetIsolate()->factory()->undefined_value());
    5034             :   }
    5035          72 :   auto func = i::Handle<i::JSFunction>::cast(self);
    5036          72 :   i::Handle<i::String> name = i::JSFunction::GetDebugName(func);
    5037             :   return Utils::ToLocal(i::Handle<i::Object>(*name, self->GetIsolate()));
    5038             : }
    5039             : 
    5040             : 
    5041          42 : Local<Value> Function::GetDisplayName() const {
    5042             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    5043             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    5044             :   auto self = Utils::OpenHandle(this);
    5045          42 :   if (!self->IsJSFunction()) {
    5046           0 :     return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
    5047             :   }
    5048             :   auto func = i::Handle<i::JSFunction>::cast(self);
    5049             :   i::Handle<i::String> property_name =
    5050          42 :       isolate->factory()->NewStringFromStaticChars("displayName");
    5051             :   i::Handle<i::Object> value =
    5052          42 :       i::JSReceiver::GetDataProperty(func, property_name);
    5053          42 :   if (value->IsString()) {
    5054             :     i::Handle<i::String> name = i::Handle<i::String>::cast(value);
    5055          18 :     if (name->length() > 0) return Utils::ToLocal(name);
    5056             :   }
    5057          24 :   return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
    5058             : }
    5059             : 
    5060             : 
    5061          12 : ScriptOrigin Function::GetScriptOrigin() const {
    5062             :   auto self = Utils::OpenHandle(this);
    5063          12 :   if (!self->IsJSFunction()) {
    5064             :     return v8::ScriptOrigin(Local<Value>());
    5065             :   }
    5066             :   auto func = i::Handle<i::JSFunction>::cast(self);
    5067          24 :   if (func->shared()->script()->IsScript()) {
    5068          24 :     i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5069          12 :                                 func->GetIsolate());
    5070          12 :     return GetScriptOriginForScript(func->GetIsolate(), script);
    5071             :   }
    5072             :   return v8::ScriptOrigin(Local<Value>());
    5073             : }
    5074             : 
    5075             : 
    5076             : const int Function::kLineOffsetNotFound = -1;
    5077             : 
    5078             : 
    5079      151676 : int Function::GetScriptLineNumber() const {
    5080             :   auto self = Utils::OpenHandle(this);
    5081      151676 :   if (!self->IsJSFunction()) {
    5082             :     return kLineOffsetNotFound;
    5083             :   }
    5084             :   auto func = i::Handle<i::JSFunction>::cast(self);
    5085      303332 :   if (func->shared()->script()->IsScript()) {
    5086      303332 :     i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5087      151666 :                                 func->GetIsolate());
    5088      151666 :     return i::Script::GetLineNumber(script, func->shared()->StartPosition());
    5089             :   }
    5090             :   return kLineOffsetNotFound;
    5091             : }
    5092             : 
    5093             : 
    5094      146676 : int Function::GetScriptColumnNumber() const {
    5095             :   auto self = Utils::OpenHandle(this);
    5096      146676 :   if (!self->IsJSFunction()) {
    5097             :     return kLineOffsetNotFound;
    5098             :   }
    5099             :   auto func = i::Handle<i::JSFunction>::cast(self);
    5100      293332 :   if (func->shared()->script()->IsScript()) {
    5101      293332 :     i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5102      146666 :                                 func->GetIsolate());
    5103      146666 :     return i::Script::GetColumnNumber(script, func->shared()->StartPosition());
    5104             :   }
    5105             :   return kLineOffsetNotFound;
    5106             : }
    5107             : 
    5108             : 
    5109      178364 : int Function::ScriptId() const {
    5110             :   auto self = Utils::OpenHandle(this);
    5111      178364 :   if (!self->IsJSFunction()) {
    5112             :     return v8::UnboundScript::kNoScriptId;
    5113             :   }
    5114             :   auto func = i::Handle<i::JSFunction>::cast(self);
    5115      356708 :   if (!func->shared()->script()->IsScript()) {
    5116             :     return v8::UnboundScript::kNoScriptId;
    5117             :   }
    5118      333888 :   i::Handle<i::Script> script(i::Script::cast(func->shared()->script()),
    5119      166944 :                               func->GetIsolate());
    5120             :   return script->id();
    5121             : }
    5122             : 
    5123             : 
    5124         252 : Local<v8::Value> Function::GetBoundFunction() const {
    5125             :   auto self = Utils::OpenHandle(this);
    5126         252 :   if (self->IsJSBoundFunction()) {
    5127             :     auto bound_function = i::Handle<i::JSBoundFunction>::cast(self);
    5128             :     auto bound_target_function = i::handle(
    5129             :         bound_function->bound_target_function(), bound_function->GetIsolate());
    5130         102 :     return Utils::CallableToLocal(bound_target_function);
    5131             :   }
    5132         150 :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(self->GetIsolate()));
    5133             : }
    5134             : 
    5135          50 : int Name::GetIdentityHash() {
    5136             :   auto self = Utils::OpenHandle(this);
    5137          50 :   return static_cast<int>(self->Hash());
    5138             : }
    5139             : 
    5140             : 
    5141    27578280 : int String::Length() const {
    5142             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5143    27578280 :   return str->length();
    5144             : }
    5145             : 
    5146             : 
    5147          67 : bool String::IsOneByte() const {
    5148             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5149          67 :   return str->IsOneByteRepresentation();
    5150             : }
    5151             : 
    5152             : 
    5153             : // Helpers for ContainsOnlyOneByteHelper
    5154             : template<size_t size> struct OneByteMask;
    5155             : template<> struct OneByteMask<4> {
    5156             :   static const uint32_t value = 0xFF00FF00;
    5157             : };
    5158             : template<> struct OneByteMask<8> {
    5159             :   static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00);
    5160             : };
    5161             : static const uintptr_t kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value;
    5162             : static const uintptr_t kAlignmentMask = sizeof(uintptr_t) - 1;
    5163             : static inline bool Unaligned(const uint16_t* chars) {
    5164       45915 :   return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask;
    5165             : }
    5166             : 
    5167             : 
    5168             : static inline const uint16_t* Align(const uint16_t* chars) {
    5169             :   return reinterpret_cast<uint16_t*>(
    5170       17885 :       reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask);
    5171             : }
    5172             : 
    5173             : class ContainsOnlyOneByteHelper {
    5174             :  public:
    5175       17885 :   ContainsOnlyOneByteHelper() : is_one_byte_(true) {}
    5176       17885 :   bool Check(i::String string) {
    5177       17885 :     i::ConsString cons_string = i::String::VisitFlat(this, string, 0);
    5178       17885 :     if (cons_string.is_null()) return is_one_byte_;
    5179          30 :     return CheckCons(cons_string);
    5180             :   }
    5181             :   void VisitOneByteString(const uint8_t* chars, int length) {
    5182             :     // Nothing to do.
    5183             :   }
    5184       17885 :   void VisitTwoByteString(const uint16_t* chars, int length) {
    5185             :     // Accumulated bits.
    5186             :     uintptr_t acc = 0;
    5187             :     // Align to uintptr_t.
    5188       17885 :     const uint16_t* end = chars + length;
    5189       73945 :     while (Unaligned(chars) && chars != end) {
    5190       28030 :       acc |= *chars++;
    5191             :     }
    5192             :     // Read word aligned in blocks,
    5193             :     // checking the return value at the end of each block.
    5194             :     const uint16_t* aligned_end = Align(end);
    5195             :     const int increment = sizeof(uintptr_t)/sizeof(uint16_t);
    5196             :     const int inner_loops = 16;
    5197       33590 :     while (chars + inner_loops*increment < aligned_end) {
    5198      817575 :       for (int i = 0; i < inner_loops; i++) {
    5199      396400 :         acc |= *reinterpret_cast<const uintptr_t*>(chars);
    5200      396400 :         chars += increment;
    5201             :       }
    5202             :       // Check for early return.
    5203       24775 :       if ((acc & kOneByteMask) != 0) {
    5204        9070 :         is_one_byte_ = false;
    5205        9070 :         return;
    5206             :       }
    5207             :     }
    5208             :     // Read the rest.
    5209      927425 :     while (chars != end) {
    5210      459305 :       acc |= *chars++;
    5211             :     }
    5212             :     // Check result.
    5213        8815 :     if ((acc & kOneByteMask) != 0) is_one_byte_ = false;
    5214             :   }
    5215             : 
    5216             :  private:
    5217          40 :   bool CheckCons(i::ConsString cons_string) {
    5218             :     while (true) {
    5219             :       // Check left side if flat.
    5220             :       i::String left = cons_string->first();
    5221       39610 :       i::ConsString left_as_cons = i::String::VisitFlat(this, left, 0);
    5222       39610 :       if (!is_one_byte_) return false;
    5223             :       // Check right side if flat.
    5224             :       i::String right = cons_string->second();
    5225       39610 :       i::ConsString right_as_cons = i::String::VisitFlat(this, right, 0);
    5226       39610 :       if (!is_one_byte_) return false;
    5227             :       // Standard recurse/iterate trick.
    5228       39610 :       if (!left_as_cons.is_null() && !right_as_cons.is_null()) {
    5229          10 :         if (left->length() < right->length()) {
    5230           0 :           CheckCons(left_as_cons);
    5231             :           cons_string = right_as_cons;
    5232             :         } else {
    5233          10 :           CheckCons(right_as_cons);
    5234             :           cons_string = left_as_cons;
    5235             :         }
    5236             :         // Check fast return.
    5237          10 :         if (!is_one_byte_) return false;
    5238             :         continue;
    5239             :       }
    5240             :       // Descend left in place.
    5241       39600 :       if (!left_as_cons.is_null()) {
    5242             :         cons_string = left_as_cons;
    5243             :         continue;
    5244             :       }
    5245             :       // Descend right in place.
    5246       19815 :       if (!right_as_cons.is_null()) {
    5247             :         cons_string = right_as_cons;
    5248             :         continue;
    5249             :       }
    5250             :       // Terminate.
    5251             :       break;
    5252             :     }
    5253             :     return is_one_byte_;
    5254             :   }
    5255             :   bool is_one_byte_;
    5256             :   DISALLOW_COPY_AND_ASSIGN(ContainsOnlyOneByteHelper);
    5257             : };
    5258             : 
    5259             : 
    5260       17905 : bool String::ContainsOnlyOneByte() const {
    5261             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5262       17905 :   if (str->IsOneByteRepresentation()) return true;
    5263             :   ContainsOnlyOneByteHelper helper;
    5264       17885 :   return helper.Check(*str);
    5265             : }
    5266             : 
    5267     9067715 : int String::Utf8Length(Isolate* isolate) const {
    5268             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5269     9067715 :   str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
    5270             :   int length = str->length();
    5271     9067715 :   if (length == 0) return 0;
    5272             :   i::DisallowHeapAllocation no_gc;
    5273     9061584 :   i::String::FlatContent flat = str->GetFlatContent(no_gc);
    5274             :   DCHECK(flat.IsFlat());
    5275             :   int utf8_length = 0;
    5276     9061584 :   if (flat.IsOneByte()) {
    5277   567410124 :     for (uint8_t c : flat.ToOneByteVector()) {
    5278   279176611 :       utf8_length += c >> 7;
    5279             :     }
    5280     9056902 :     utf8_length += length;
    5281             :   } else {
    5282             :     int last_character = unibrow::Utf16::kNoPreviousCharacter;
    5283     2408794 :     for (uint16_t c : flat.ToUC16Vector()) {
    5284     2404112 :       utf8_length += unibrow::Utf8::Length(c, last_character);
    5285     1202056 :       last_character = c;
    5286             :     }
    5287             :   }
    5288             :   return utf8_length;
    5289             : }
    5290             : 
    5291             : namespace {
    5292             : // Writes the flat content of a string to a buffer. This is done in two phases.
    5293             : // The first phase calculates a pessimistic estimate (writable_length) on how
    5294             : // many code units can be safely written without exceeding the buffer capacity
    5295             : // and without leaving at a lone surrogate. The estimated number of code units
    5296             : // is then written out in one go, and the reported byte usage is used to
    5297             : // correct the estimate. This is repeated until the estimate becomes <= 0 or
    5298             : // all code units have been written out. The second phase writes out code
    5299             : // units until the buffer capacity is reached, would be exceeded by the next
    5300             : // unit, or all code units have been written out.
    5301             : template <typename Char>
    5302     9067286 : static int WriteUtf8Impl(i::Vector<const Char> string, char* write_start,
    5303             :                          int write_capacity, int options,
    5304             :                          int* utf16_chars_read_out) {
    5305     9067286 :   bool write_null = !(options & v8::String::NO_NULL_TERMINATION);
    5306     9067286 :   bool replace_invalid_utf8 = (options & v8::String::REPLACE_INVALID_UTF8);
    5307             :   char* current_write = write_start;
    5308             :   const Char* read_start = string.start();
    5309             :   int read_index = 0;
    5310             :   int read_length = string.length();
    5311             :   int prev_char = unibrow::Utf16::kNoPreviousCharacter;
    5312             :   // Do a fast loop where there is no exit capacity check.
    5313             :   // Need enough space to write everything but one character.
    5314             :   STATIC_ASSERT(unibrow::Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit == 3);
    5315             :   static const int kMaxSizePerChar = sizeof(Char) == 1 ? 2 : 3;
    5316    27494806 :   while (read_index < read_length) {
    5317     9227063 :     int up_to = read_length;
    5318     9227063 :     if (write_capacity != -1) {
    5319             :       int remaining_capacity =
    5320      179259 :           write_capacity - static_cast<int>(current_write - write_start);
    5321             :       int writable_length =
    5322      179259 :           (remaining_capacity - kMaxSizePerChar) / kMaxSizePerChar;
    5323             :       // Need to drop into slow loop.
    5324      179259 :       if (writable_length <= 0) break;
    5325      331912 :       up_to = std::min(up_to, read_index + writable_length);
    5326             :     }
    5327             :     // Write the characters to the stream.
    5328             :     if (sizeof(Char) == 1) {
    5329             :       // Simply memcpy if we only have ASCII characters.
    5330             :       uint8_t char_mask = 0;
    5331   333343639 :       for (int i = read_index; i < up_to; i++) char_mask |= read_start[i];
    5332     9208003 :       if ((char_mask & 0x80) == 0) {
    5333     9207804 :         int copy_length = up_to - read_index;
    5334     9207804 :         memcpy(current_write, read_start + read_index, copy_length);
    5335     9207804 :         current_write += copy_length;
    5336             :         read_index = up_to;
    5337             :       } else {
    5338       12955 :         for (; read_index < up_to; read_index++) {
    5339        6378 :           current_write += unibrow::Utf8::EncodeOneByte(
    5340        6378 :               current_write, static_cast<uint8_t>(read_start[read_index]));
    5341             :           DCHECK(write_capacity == -1 ||
    5342             :                  (current_write - write_start) <= write_capacity);
    5343             :         }
    5344             :       }
    5345             :     } else {
    5346   272380869 :       for (; read_index < up_to; read_index++) {
    5347   136187556 :         uint16_t character = read_start[read_index];
    5348   136187556 :         current_write += unibrow::Utf8::Encode(current_write, character,
    5349             :                                                prev_char, replace_invalid_utf8);
    5350   136187556 :         prev_char = character;
    5351             :         DCHECK(write_capacity == -1 ||
    5352             :                (current_write - write_start) <= write_capacity);
    5353             :       }
    5354             :     }
    5355             :   }
    5356     9067286 :   if (read_index < read_length) {
    5357             :     DCHECK_NE(-1, write_capacity);
    5358             :     // Aborted due to limited capacity. Check capacity on each iteration.
    5359             :     int remaining_capacity =
    5360       13303 :         write_capacity - static_cast<int>(current_write - write_start);
    5361             :     DCHECK_GE(remaining_capacity, 0);
    5362       93069 :     for (; read_index < read_length && remaining_capacity > 0; read_index++) {
    5363       39932 :       uint32_t character = read_start[read_index];
    5364             :       int written = 0;
    5365             :       // We can't use a local buffer here because Encode needs to modify
    5366             :       // previous characters in the stream.  We know, however, that
    5367             :       // exactly one character will be advanced.
    5368       79145 :       if (unibrow::Utf16::IsSurrogatePair(prev_char, character)) {
    5369           0 :         written = unibrow::Utf8::Encode(current_write, character, prev_char,
    5370             :                                         replace_invalid_utf8);
    5371             :         DCHECK_EQ(written, 1);
    5372             :       } else {
    5373             :         // Use a scratch buffer to check the required characters.
    5374             :         char temp_buffer[unibrow::Utf8::kMaxEncodedSize];
    5375             :         // Encoding a surrogate pair to Utf8 always takes 4 bytes.
    5376             :         static const int kSurrogatePairEncodedSize =
    5377             :             static_cast<int>(unibrow::Utf8::kMaxEncodedSize);
    5378             :         // For REPLACE_INVALID_UTF8, catch the case where we cut off in the
    5379             :         // middle of a surrogate pair. Abort before encoding the pair instead.
    5380       39938 :         if (replace_invalid_utf8 &&
    5381             :             remaining_capacity < kSurrogatePairEncodedSize &&
    5382             :             unibrow::Utf16::IsLeadSurrogate(character) &&
    5383             :             read_index + 1 < read_length &&
    5384           6 :             unibrow::Utf16::IsTrailSurrogate(read_start[read_index + 1])) {
    5385             :           write_null = false;
    5386          49 :           break;
    5387             :         }
    5388             :         // Can't encode using prev_char as gcc has array bounds issues.
    5389       39926 :         written = unibrow::Utf8::Encode(temp_buffer, character,
    5390             :                                         unibrow::Utf16::kNoPreviousCharacter,
    5391             :                                         replace_invalid_utf8);
    5392       39926 :         if (written > remaining_capacity) {
    5393             :           // Won't fit. Abort and do not null-terminate the result.
    5394             :           write_null = false;
    5395             :           break;
    5396             :         }
    5397             :         // Copy over the character from temp_buffer.
    5398       79904 :         for (int i = 0; i < written; i++) current_write[i] = temp_buffer[i];
    5399             :       }
    5400             : 
    5401       39883 :       current_write += written;
    5402       39883 :       remaining_capacity -= written;
    5403         670 :       prev_char = character;
    5404             :     }
    5405             :   }
    5406             : 
    5407             :   // Write out number of utf16 characters written to the stream.
    5408     9067286 :   if (utf16_chars_read_out != nullptr) *utf16_chars_read_out = read_index;
    5409             : 
    5410             :   // Only null-terminate if there's space.
    5411     9067286 :   if (write_null && (write_capacity == -1 ||
    5412             :                      (current_write - write_start) < write_capacity)) {
    5413     9054017 :     *current_write++ = '\0';
    5414             :   }
    5415     9067286 :   return static_cast<int>(current_write - write_start);
    5416             : }
    5417             : }  // anonymous namespace
    5418             : 
    5419     9067286 : int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
    5420             :                       int* nchars_ref, int options) const {
    5421             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5422             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    5423     9067286 :   LOG_API(isolate, String, WriteUtf8);
    5424             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    5425     9067286 :   str = i::String::Flatten(isolate, str);
    5426             :   i::DisallowHeapAllocation no_gc;
    5427     9067286 :   i::String::FlatContent content = str->GetFlatContent(no_gc);
    5428     9067286 :   if (content.IsOneByte()) {
    5429             :     return WriteUtf8Impl<uint8_t>(content.ToOneByteVector(), buffer, capacity,
    5430     9062938 :                                   options, nchars_ref);
    5431             :   } else {
    5432             :     return WriteUtf8Impl<uint16_t>(content.ToUC16Vector(), buffer, capacity,
    5433        4348 :                                    options, nchars_ref);
    5434             :   }
    5435             : }
    5436             : 
    5437             : template <typename CharType>
    5438     9267469 : static inline int WriteHelper(i::Isolate* isolate, const String* string,
    5439             :                               CharType* buffer, int start, int length,
    5440             :                               int options) {
    5441     9267469 :   LOG_API(isolate, String, Write);
    5442             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    5443             :   DCHECK(start >= 0 && length >= -1);
    5444             :   i::Handle<i::String> str = Utils::OpenHandle(string);
    5445     9267468 :   str = i::String::Flatten(isolate, str);
    5446     9267469 :   int end = start + length;
    5447    18534836 :   if ((length == -1) || (length > str->length() - start) )
    5448             :     end = str->length();
    5449     9267469 :   if (end < 0) return 0;
    5450     9267469 :   i::String::WriteToFlat(*str, buffer, start, end);
    5451     9267468 :   if (!(options & String::NO_NULL_TERMINATION) &&
    5452             :       (length == -1 || end - start < length)) {
    5453          66 :     buffer[end - start] = '\0';
    5454             :   }
    5455     9267468 :   return end - start;
    5456             : }
    5457             : 
    5458             : 
    5459          67 : int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
    5460             :                          int length, int options) const {
    5461             :   return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
    5462          67 :                      start, length, options);
    5463             : }
    5464             : 
    5465             : 
    5466     9267396 : int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
    5467             :                   int options) const {
    5468             :   return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
    5469     9267402 :                      start, length, options);
    5470             : }
    5471             : 
    5472             : 
    5473          67 : bool v8::String::IsExternal() const {
    5474             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5475         134 :   return i::StringShape(*str).IsExternalTwoByte();
    5476             : }
    5477             : 
    5478             : 
    5479          27 : bool v8::String::IsExternalOneByte() const {
    5480             :   i::Handle<i::String> str = Utils::OpenHandle(this);
    5481          54 :   return i::StringShape(*str).IsExternalOneByte();
    5482             : }
    5483             : 
    5484             : 
    5485           0 : void v8::String::VerifyExternalStringResource(
    5486             :     v8::String::ExternalStringResource* value) const {
    5487             :   i::DisallowHeapAllocation no_allocation;
    5488             :   i::String str = *Utils::OpenHandle(this);
    5489             :   const v8::String::ExternalStringResource* expected;
    5490             : 
    5491           0 :   if (str->IsThinString()) {
    5492             :     str = i::ThinString::cast(str)->actual();
    5493             :   }
    5494             : 
    5495           0 :   if (i::StringShape(str).IsExternalTwoByte()) {
    5496             :     const void* resource = i::ExternalTwoByteString::cast(str)->resource();
    5497             :     expected = reinterpret_cast<const ExternalStringResource*>(resource);
    5498             :   } else {
    5499             :     expected = nullptr;
    5500             :   }
    5501           0 :   CHECK_EQ(expected, value);
    5502           0 : }
    5503             : 
    5504           0 : void v8::String::VerifyExternalStringResourceBase(
    5505             :     v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
    5506             :   i::DisallowHeapAllocation no_allocation;
    5507           0 :   i::String str = *Utils::OpenHandle(this);
    5508             :   const v8::String::ExternalStringResourceBase* expected;
    5509             :   Encoding expectedEncoding;
    5510             : 
    5511           0 :   if (str->IsThinString()) {
    5512           0 :     str = i::ThinString::cast(str)->actual();
    5513             :   }
    5514             : 
    5515           0 :   if (i::StringShape(str).IsExternalOneByte()) {
    5516             :     const void* resource = i::ExternalOneByteString::cast(str)->resource();
    5517             :     expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
    5518             :     expectedEncoding = ONE_BYTE_ENCODING;
    5519           0 :   } else if (i::StringShape(str).IsExternalTwoByte()) {
    5520             :     const void* resource = i::ExternalTwoByteString::cast(str)->resource();
    5521             :     expected = reinterpret_cast<const ExternalStringResourceBase*>(resource);
    5522             :     expectedEncoding = TWO_BYTE_ENCODING;
    5523             :   } else {
    5524             :     expected = nullptr;
    5525             :     expectedEncoding =
    5526           0 :         str->IsOneByteRepresentation() ? ONE_BYTE_ENCODING : TWO_BYTE_ENCODING;
    5527             :   }
    5528           0 :   CHECK_EQ(expected, value);
    5529           0 :   CHECK_EQ(expectedEncoding, encoding);
    5530           0 : }
    5531             : 
    5532           0 : String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
    5533             :   i::DisallowHeapAllocation no_allocation;
    5534             :   typedef internal::Internals I;
    5535             :   i::String str = *Utils::OpenHandle(this);
    5536             : 
    5537           0 :   if (str->IsThinString()) {
    5538             :     str = i::ThinString::cast(str)->actual();
    5539             :   }
    5540             : 
    5541           0 :   if (i::StringShape(str).IsExternalTwoByte()) {
    5542             :     void* value = I::ReadRawField<void*>(str.ptr(), I::kStringResourceOffset);
    5543           0 :     return reinterpret_cast<String::ExternalStringResource*>(value);
    5544             :   }
    5545             :   return nullptr;
    5546             : }
    5547             : 
    5548           6 : String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
    5549             :     String::Encoding* encoding_out) const {
    5550             :   i::DisallowHeapAllocation no_allocation;
    5551             :   typedef internal::Internals I;
    5552             :   ExternalStringResourceBase* resource = nullptr;
    5553             :   i::String str = *Utils::OpenHandle(this);
    5554             : 
    5555           6 :   if (str->IsThinString()) {
    5556             :     str = i::ThinString::cast(str)->actual();
    5557             :   }
    5558             : 
    5559             :   internal::Address string = str.ptr();
    5560             :   int type = I::GetInstanceType(string) & I::kFullStringRepresentationMask;
    5561           6 :   *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
    5562          24 :   if (i::StringShape(str).IsExternalOneByte() ||
    5563          12 :       i::StringShape(str).IsExternalTwoByte()) {
    5564             :     void* value = I::ReadRawField<void*>(string, I::kStringResourceOffset);
    5565             :     resource = static_cast<ExternalStringResourceBase*>(value);
    5566             :   }
    5567           6 :   return resource;
    5568             : }
    5569             : 
    5570             : const v8::String::ExternalOneByteStringResource*
    5571          11 : v8::String::GetExternalOneByteStringResource() const {
    5572             :   i::DisallowHeapAllocation no_allocation;
    5573             :   i::String str = *Utils::OpenHandle(this);
    5574          22 :   if (i::StringShape(str).IsExternalOneByte()) {
    5575             :     return i::ExternalOneByteString::cast(str)->resource();
    5576           0 :   } else if (str->IsThinString()) {
    5577             :     str = i::ThinString::cast(str)->actual();
    5578           0 :     if (i::StringShape(str).IsExternalOneByte()) {
    5579             :       return i::ExternalOneByteString::cast(str)->resource();
    5580             :     }
    5581             :   }
    5582             :   return nullptr;
    5583             : }
    5584             : 
    5585             : 
    5586       57891 : Local<Value> Symbol::Name() const {
    5587             :   i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
    5588             : 
    5589             :   i::Isolate* isolate;
    5590       57891 :   if (!i::GetIsolateFromWritableObject(*sym, &isolate)) {
    5591             :     // If the Symbol is in RO_SPACE, then its name must be too. Since RO_SPACE
    5592             :     // objects are immovable we can use the Handle(Address*) constructor with
    5593             :     // the address of the name field in the Symbol object without needing an
    5594             :     // isolate.
    5595             : #ifdef V8_COMPRESS_POINTERS
    5596             :     // Compressed fields can't serve as handle locations.
    5597             :     // TODO(ishell): get Isolate as a parameter.
    5598             :     isolate = i::Isolate::Current();
    5599             : #else
    5600             :     i::Handle<i::HeapObject> ro_name(reinterpret_cast<i::Address*>(
    5601             :         sym->GetFieldAddress(i::Symbol::kNameOffset)));
    5602             :     return Utils::ToLocal(ro_name);
    5603             : #endif
    5604             :   }
    5605             : 
    5606             :   i::Handle<i::Object> name(sym->name(), isolate);
    5607             : 
    5608       57891 :   return Utils::ToLocal(name);
    5609             : }
    5610             : 
    5611             : 
    5612          72 : Local<Value> Private::Name() const {
    5613          72 :   return reinterpret_cast<const Symbol*>(this)->Name();
    5614             : }
    5615             : 
    5616             : 
    5617      330007 : double Number::Value() const {
    5618             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5619      330007 :   return obj->Number();
    5620             : }
    5621             : 
    5622             : 
    5623       21822 : bool Boolean::Value() const {
    5624             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5625       21822 :   return obj->IsTrue();
    5626             : }
    5627             : 
    5628             : 
    5629        2326 : int64_t Integer::Value() const {
    5630             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5631       11803 :   if (obj->IsSmi()) {
    5632       11761 :     return i::Smi::ToInt(*obj);
    5633             :   } else {
    5634          42 :     return static_cast<int64_t>(obj->Number());
    5635             :   }
    5636             : }
    5637             : 
    5638             : 
    5639       33601 : int32_t Int32::Value() const {
    5640             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5641       33601 :   if (obj->IsSmi()) {
    5642       33582 :     return i::Smi::ToInt(*obj);
    5643             :   } else {
    5644          19 :     return static_cast<int32_t>(obj->Number());
    5645             :   }
    5646             : }
    5647             : 
    5648             : 
    5649        7291 : uint32_t Uint32::Value() const {
    5650             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    5651        7291 :   if (obj->IsSmi()) {
    5652        7273 :     return i::Smi::ToInt(*obj);
    5653             :   } else {
    5654          18 :     return static_cast<uint32_t>(obj->Number());
    5655             :   }
    5656             : }
    5657             : 
    5658        4705 : int v8::Object::InternalFieldCount() {
    5659             :   i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
    5660        4705 :   if (!self->IsJSObject()) return 0;
    5661        4705 :   return i::Handle<i::JSObject>::cast(self)->GetEmbedderFieldCount();
    5662             : }
    5663             : 
    5664        2878 : static bool InternalFieldOK(i::Handle<i::JSReceiver> obj, int index,
    5665             :                             const char* location) {
    5666             :   return Utils::ApiCheck(
    5667        5756 :       obj->IsJSObject() &&
    5668        2878 :           (index < i::Handle<i::JSObject>::cast(obj)->GetEmbedderFieldCount()),
    5669        2878 :       location, "Internal field out of bounds");
    5670             : }
    5671             : 
    5672         576 : Local<Value> v8::Object::SlowGetInternalField(int index) {
    5673             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5674             :   const char* location = "v8::Object::GetInternalField()";
    5675         576 :   if (!InternalFieldOK(obj, index, location)) return Local<Value>();
    5676        1152 :   i::Handle<i::Object> value(i::JSObject::cast(*obj)->GetEmbedderField(index),
    5677         576 :                              obj->GetIsolate());
    5678             :   return Utils::ToLocal(value);
    5679             : }
    5680             : 
    5681         649 : void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
    5682             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5683             :   const char* location = "v8::Object::SetInternalField()";
    5684         649 :   if (!InternalFieldOK(obj, index, location)) return;
    5685             :   i::Handle<i::Object> val = Utils::OpenHandle(*value);
    5686         649 :   i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
    5687             : }
    5688             : 
    5689         135 : void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
    5690             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5691             :   const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
    5692         135 :   if (!InternalFieldOK(obj, index, location)) return nullptr;
    5693             :   void* result;
    5694             :   Utils::ApiCheck(i::EmbedderDataSlot(i::JSObject::cast(*obj), index)
    5695             :                       .ToAlignedPointer(&result),
    5696             :                   location, "Unaligned pointer");
    5697         135 :   return result;
    5698             : }
    5699             : 
    5700        1518 : void v8::Object::SetAlignedPointerInInternalField(int index, void* value) {
    5701             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5702             :   const char* location = "v8::Object::SetAlignedPointerInInternalField()";
    5703        1518 :   if (!InternalFieldOK(obj, index, location)) return;
    5704             :   Utils::ApiCheck(i::EmbedderDataSlot(i::JSObject::cast(*obj), index)
    5705             :                       .store_aligned_pointer(value),
    5706             :                   location, "Unaligned pointer");
    5707             :   DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
    5708             : }
    5709             : 
    5710          12 : void v8::Object::SetAlignedPointerInInternalFields(int argc, int indices[],
    5711             :                                                    void* values[]) {
    5712             :   i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
    5713             :   const char* location = "v8::Object::SetAlignedPointerInInternalFields()";
    5714             :   i::DisallowHeapAllocation no_gc;
    5715          12 :   i::JSObject js_obj = i::JSObject::cast(*obj);
    5716          12 :   int nof_embedder_fields = js_obj->GetEmbedderFieldCount();
    5717          60 :   for (int i = 0; i < argc; i++) {
    5718          24 :     int index = indices[i];
    5719          24 :     if (!Utils::ApiCheck(index < nof_embedder_fields, location,
    5720             :                          "Internal field out of bounds")) {
    5721           0 :       return;
    5722             :     }
    5723          24 :     void* value = values[i];
    5724             :     Utils::ApiCheck(
    5725             :         i::EmbedderDataSlot(js_obj, index).store_aligned_pointer(value),
    5726             :         location, "Unaligned pointer");
    5727             :     DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
    5728             :   }
    5729             : }
    5730             : 
    5731     1031961 : static void* ExternalValue(i::Object obj) {
    5732             :   // Obscure semantics for undefined, but somehow checked in our unit tests...
    5733     1031961 :   if (obj->IsUndefined()) {
    5734             :     return nullptr;
    5735             :   }
    5736     1031972 :   i::Object foreign = i::JSObject::cast(obj)->GetEmbedderField(0);
    5737     1031969 :   return reinterpret_cast<void*>(i::Foreign::cast(foreign)->foreign_address());
    5738             : }
    5739             : 
    5740             : // --- E n v i r o n m e n t ---
    5741             : 
    5742             : 
    5743       60098 : void v8::V8::InitializePlatform(Platform* platform) {
    5744       60098 :   i::V8::InitializePlatform(platform);
    5745       60098 : }
    5746             : 
    5747             : 
    5748       58953 : void v8::V8::ShutdownPlatform() {
    5749       58953 :   i::V8::ShutdownPlatform();
    5750       58953 : }
    5751             : 
    5752             : 
    5753       60422 : bool v8::V8::Initialize() {
    5754       60422 :   i::V8::Initialize();
    5755             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
    5756       60422 :   i::ReadNatives();
    5757             : #endif
    5758       60422 :   return true;
    5759             : }
    5760             : 
    5761             : #if V8_OS_LINUX || V8_OS_MACOSX
    5762           7 : bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info,
    5763             :                                    void* context) {
    5764             : #if V8_TARGET_ARCH_X64 && !V8_OS_ANDROID
    5765           7 :   return i::trap_handler::TryHandleSignal(sig_code, info, context);
    5766             : #else
    5767             :   return false;
    5768             : #endif
    5769             : }
    5770             : 
    5771           0 : bool V8::TryHandleSignal(int signum, void* info, void* context) {
    5772             :   return TryHandleWebAssemblyTrapPosix(
    5773           0 :       signum, reinterpret_cast<siginfo_t*>(info), context);
    5774             : }
    5775             : #endif
    5776             : 
    5777             : #if V8_OS_WIN
    5778             : bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) {
    5779             : #if V8_TARGET_ARCH_X64
    5780             :   return i::trap_handler::TryHandleWasmTrap(exception);
    5781             : #endif
    5782             :   return false;
    5783             : }
    5784             : #endif
    5785             : 
    5786       55870 : bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) {
    5787       55870 :   return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler);
    5788             : }
    5789             : 
    5790           0 : void v8::V8::SetEntropySource(EntropySource entropy_source) {
    5791           0 :   base::RandomNumberGenerator::SetEntropySource(entropy_source);
    5792           0 : }
    5793             : 
    5794             : 
    5795           0 : void v8::V8::SetReturnAddressLocationResolver(
    5796             :     ReturnAddressLocationResolver return_address_resolver) {
    5797           0 :   i::StackFrame::SetReturnAddressLocationResolver(return_address_resolver);
    5798           0 : }
    5799             : 
    5800       58997 : bool v8::V8::Dispose() {
    5801       58997 :   i::V8::TearDown();
    5802             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
    5803       58997 :   i::DisposeNatives();
    5804             : #endif
    5805       58997 :   return true;
    5806             : }
    5807             : 
    5808          31 : HeapStatistics::HeapStatistics()
    5809             :     : total_heap_size_(0),
    5810             :       total_heap_size_executable_(0),
    5811             :       total_physical_size_(0),
    5812             :       total_available_size_(0),
    5813             :       used_heap_size_(0),
    5814             :       heap_size_limit_(0),
    5815             :       malloced_memory_(0),
    5816             :       external_memory_(0),
    5817             :       peak_malloced_memory_(0),
    5818             :       does_zap_garbage_(false),
    5819             :       number_of_native_contexts_(0),
    5820          31 :       number_of_detached_contexts_(0) {}
    5821             : 
    5822          40 : HeapSpaceStatistics::HeapSpaceStatistics()
    5823             :     : space_name_(nullptr),
    5824             :       space_size_(0),
    5825             :       space_used_size_(0),
    5826             :       space_available_size_(0),
    5827          40 :       physical_space_size_(0) {}
    5828             : 
    5829           0 : HeapObjectStatistics::HeapObjectStatistics()
    5830             :     : object_type_(nullptr),
    5831             :       object_sub_type_(nullptr),
    5832             :       object_count_(0),
    5833           0 :       object_size_(0) {}
    5834             : 
    5835           0 : HeapCodeStatistics::HeapCodeStatistics()
    5836             :     : code_and_metadata_size_(0),
    5837             :       bytecode_and_metadata_size_(0),
    5838           0 :       external_script_source_size_(0) {}
    5839             : 
    5840           0 : bool v8::V8::InitializeICU(const char* icu_data_file) {
    5841           0 :   return i::InitializeICU(icu_data_file);
    5842             : }
    5843             : 
    5844       57033 : bool v8::V8::InitializeICUDefaultLocation(const char* exec_path,
    5845             :                                           const char* icu_data_file) {
    5846       57033 :   return i::InitializeICUDefaultLocation(exec_path, icu_data_file);
    5847             : }
    5848             : 
    5849       60107 : void v8::V8::InitializeExternalStartupData(const char* directory_path) {
    5850       60107 :   i::InitializeExternalStartupData(directory_path);
    5851       60107 : }
    5852             : 
    5853             : 
    5854           0 : void v8::V8::InitializeExternalStartupData(const char* natives_blob,
    5855             :                                            const char* snapshot_blob) {
    5856           0 :   i::InitializeExternalStartupData(natives_blob, snapshot_blob);
    5857           0 : }
    5858             : 
    5859             : 
    5860          33 : const char* v8::V8::GetVersion() {
    5861          33 :   return i::Version::GetVersion();
    5862             : }
    5863             : 
    5864             : template <typename ObjectType>
    5865             : struct InvokeBootstrapper;
    5866             : 
    5867             : template <>
    5868             : struct InvokeBootstrapper<i::Context> {
    5869             :   i::Handle<i::Context> Invoke(
    5870             :       i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
    5871             :       v8::Local<v8::ObjectTemplate> global_proxy_template,
    5872             :       v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
    5873             :       v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
    5874             :       v8::MicrotaskQueue* microtask_queue) {
    5875             :     return isolate->bootstrapper()->CreateEnvironment(
    5876             :         maybe_global_proxy, global_proxy_template, extensions,
    5877       90479 :         context_snapshot_index, embedder_fields_deserializer, microtask_queue);
    5878             :   }
    5879             : };
    5880             : 
    5881             : template <>
    5882             : struct InvokeBootstrapper<i::JSGlobalProxy> {
    5883             :   i::Handle<i::JSGlobalProxy> Invoke(
    5884             :       i::Isolate* isolate, i::MaybeHandle<i::JSGlobalProxy> maybe_global_proxy,
    5885             :       v8::Local<v8::ObjectTemplate> global_proxy_template,
    5886             :       v8::ExtensionConfiguration* extensions, size_t context_snapshot_index,
    5887             :       v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
    5888             :       v8::MicrotaskQueue* microtask_queue) {
    5889             :     USE(extensions);
    5890             :     USE(context_snapshot_index);
    5891             :     return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy,
    5892          18 :                                                      global_proxy_template);
    5893             :   }
    5894             : };
    5895             : 
    5896             : template <typename ObjectType>
    5897       90497 : static i::Handle<ObjectType> CreateEnvironment(
    5898             :     i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
    5899             :     v8::MaybeLocal<ObjectTemplate> maybe_global_template,
    5900             :     v8::MaybeLocal<Value> maybe_global_proxy, size_t context_snapshot_index,
    5901             :     v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
    5902             :     v8::MicrotaskQueue* microtask_queue) {
    5903             :   i::Handle<ObjectType> result;
    5904             : 
    5905             :   {
    5906             :     ENTER_V8_FOR_NEW_CONTEXT(isolate);
    5907             :     v8::Local<ObjectTemplate> proxy_template;
    5908             :     i::Handle<i::FunctionTemplateInfo> proxy_constructor;
    5909             :     i::Handle<i::FunctionTemplateInfo> global_constructor;
    5910             :     i::Handle<i::Object> named_interceptor(
    5911             :         isolate->factory()->undefined_value());
    5912             :     i::Handle<i::Object> indexed_interceptor(
    5913             :         isolate->factory()->undefined_value());
    5914             : 
    5915       90497 :     if (!maybe_global_template.IsEmpty()) {
    5916             :       v8::Local<v8::ObjectTemplate> global_template =
    5917             :           maybe_global_template.ToLocalChecked();
    5918             :       // Make sure that the global_template has a constructor.
    5919       55782 :       global_constructor = EnsureConstructor(isolate, *global_template);
    5920             : 
    5921             :       // Create a fresh template for the global proxy object.
    5922             :       proxy_template = ObjectTemplate::New(
    5923             :           reinterpret_cast<v8::Isolate*>(isolate));
    5924       55782 :       proxy_constructor = EnsureConstructor(isolate, *proxy_template);
    5925             : 
    5926             :       // Set the global template to be the prototype template of
    5927             :       // global proxy template.
    5928       55782 :       i::FunctionTemplateInfo::SetPrototypeTemplate(
    5929             :           isolate, proxy_constructor, Utils::OpenHandle(*global_template));
    5930             : 
    5931       55782 :       proxy_template->SetInternalFieldCount(
    5932             :           global_template->InternalFieldCount());
    5933             : 
    5934             :       // Migrate security handlers from global_template to
    5935             :       // proxy_template.  Temporarily removing access check
    5936             :       // information from the global template.
    5937      111564 :       if (!global_constructor->GetAccessCheckInfo()->IsUndefined(isolate)) {
    5938         282 :         i::FunctionTemplateInfo::SetAccessCheckInfo(
    5939             :             isolate, proxy_constructor,
    5940             :             i::handle(global_constructor->GetAccessCheckInfo(), isolate));
    5941         282 :         proxy_constructor->set_needs_access_check(
    5942             :             global_constructor->needs_access_check());
    5943         141 :         global_constructor->set_needs_access_check(false);
    5944         141 :         i::FunctionTemplateInfo::SetAccessCheckInfo(
    5945             :             isolate, global_constructor,
    5946             :             i::ReadOnlyRoots(isolate).undefined_value_handle());
    5947             :       }
    5948             : 
    5949             :       // Same for other interceptors. If the global constructor has
    5950             :       // interceptors, we need to replace them temporarily with noop
    5951             :       // interceptors, so the map is correctly marked as having interceptors,
    5952             :       // but we don't invoke any.
    5953      111564 :       if (!global_constructor->GetNamedPropertyHandler()->IsUndefined(
    5954             :               isolate)) {
    5955         144 :         named_interceptor =
    5956         288 :             handle(global_constructor->GetNamedPropertyHandler(), isolate);
    5957         144 :         i::FunctionTemplateInfo::SetNamedPropertyHandler(
    5958             :             isolate, global_constructor,
    5959             :             i::ReadOnlyRoots(isolate).noop_interceptor_info_handle());
    5960             :       }
    5961      111564 :       if (!global_constructor->GetIndexedPropertyHandler()->IsUndefined(
    5962             :               isolate)) {
    5963           0 :         indexed_interceptor =
    5964           0 :             handle(global_constructor->GetIndexedPropertyHandler(), isolate);
    5965           0 :         i::FunctionTemplateInfo::SetIndexedPropertyHandler(
    5966             :             isolate, global_constructor,
    5967             :             i::ReadOnlyRoots(isolate).noop_interceptor_info_handle());
    5968             :       }
    5969             :     }
    5970             : 
    5971             :     i::MaybeHandle<i::JSGlobalProxy> maybe_proxy;
    5972       90497 :     if (!maybe_global_proxy.IsEmpty()) {
    5973             :       maybe_proxy = i::Handle<i::JSGlobalProxy>::cast(
    5974             :           Utils::OpenHandle(*maybe_global_proxy.ToLocalChecked()));
    5975             :     }
    5976             :     // Create the environment.
    5977             :     InvokeBootstrapper<ObjectType> invoke;
    5978             :     result = invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
    5979             :                            context_snapshot_index, embedder_fields_deserializer,
    5980             :                            microtask_queue);
    5981             : 
    5982             :     // Restore the access check info and interceptors on the global template.
    5983       90497 :     if (!maybe_global_template.IsEmpty()) {
    5984             :       DCHECK(!global_constructor.is_null());
    5985             :       DCHECK(!proxy_constructor.is_null());
    5986      111564 :       i::FunctionTemplateInfo::SetAccessCheckInfo(
    5987             :           isolate, global_constructor,
    5988             :           i::handle(proxy_constructor->GetAccessCheckInfo(), isolate));
    5989      111564 :       global_constructor->set_needs_access_check(
    5990             :           proxy_constructor->needs_access_check());
    5991       55782 :       i::FunctionTemplateInfo::SetNamedPropertyHandler(
    5992             :           isolate, global_constructor, named_interceptor);
    5993       55782 :       i::FunctionTemplateInfo::SetIndexedPropertyHandler(
    5994             :           isolate, global_constructor, indexed_interceptor);
    5995             :     }
    5996             :   }
    5997             :   // Leave V8.
    5998             : 
    5999       90497 :   return result;
    6000             : }
    6001             : 
    6002       90479 : Local<Context> NewContext(
    6003             :     v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
    6004             :     v8::MaybeLocal<ObjectTemplate> global_template,
    6005             :     v8::MaybeLocal<Value> global_object, size_t context_snapshot_index,
    6006             :     v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
    6007             :     v8::MicrotaskQueue* microtask_queue) {
    6008             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    6009             :   // TODO(jkummerow): This is for crbug.com/713699. Remove it if it doesn't
    6010             :   // fail.
    6011             :   // Sanity-check that the isolate is initialized and usable.
    6012      180959 :   CHECK(isolate->builtins()->builtin(i::Builtins::kIllegal)->IsCode());
    6013             : 
    6014      180960 :   TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext");
    6015       90480 :   LOG_API(isolate, Context, New);
    6016             :   i::HandleScope scope(isolate);
    6017             :   ExtensionConfiguration no_extensions;
    6018       90480 :   if (extensions == nullptr) extensions = &no_extensions;
    6019             :   i::Handle<i::Context> env = CreateEnvironment<i::Context>(
    6020             :       isolate, extensions, global_template, global_object,
    6021       90480 :       context_snapshot_index, embedder_fields_deserializer, microtask_queue);
    6022       90479 :   if (env.is_null()) {
    6023          40 :     if (isolate->has_pending_exception()) isolate->clear_pending_exception();
    6024          40 :     return Local<Context>();
    6025             :   }
    6026       90439 :   return Utils::ToLocal(scope.CloseAndEscape(env));
    6027             : }
    6028             : 
    6029       90439 : Local<Context> v8::Context::New(
    6030             :     v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
    6031             :     v8::MaybeLocal<ObjectTemplate> global_template,
    6032             :     v8::MaybeLocal<Value> global_object,
    6033             :     DeserializeInternalFieldsCallback internal_fields_deserializer,
    6034             :     v8::MicrotaskQueue* microtask_queue) {
    6035             :   return NewContext(external_isolate, extensions, global_template,
    6036             :                     global_object, 0, internal_fields_deserializer,
    6037       90439 :                     microtask_queue);
    6038             : }
    6039             : 
    6040          45 : MaybeLocal<Context> v8::Context::FromSnapshot(
    6041             :     v8::Isolate* external_isolate, size_t context_snapshot_index,
    6042             :     v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
    6043             :     v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object,
    6044             :     v8::MicrotaskQueue* microtask_queue) {
    6045          45 :   size_t index_including_default_context = context_snapshot_index + 1;
    6046          45 :   if (!i::Snapshot::HasContextSnapshot(
    6047             :           reinterpret_cast<i::Isolate*>(external_isolate),
    6048             :           index_including_default_context)) {
    6049           5 :     return MaybeLocal<Context>();
    6050             :   }
    6051             :   return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(),
    6052             :                     global_object, index_including_default_context,
    6053          40 :                     embedder_fields_deserializer, microtask_queue);
    6054             : }
    6055             : 
    6056          18 : MaybeLocal<Object> v8::Context::NewRemoteContext(
    6057             :     v8::Isolate* external_isolate, v8::Local<ObjectTemplate> global_template,
    6058             :     v8::MaybeLocal<v8::Value> global_object) {
    6059             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
    6060          18 :   LOG_API(isolate, Context, NewRemoteContext);
    6061             :   i::HandleScope scope(isolate);
    6062             :   i::Handle<i::FunctionTemplateInfo> global_constructor =
    6063          18 :       EnsureConstructor(isolate, *global_template);
    6064             :   Utils::ApiCheck(global_constructor->needs_access_check(),
    6065             :                   "v8::Context::NewRemoteContext",
    6066             :                   "Global template needs to have access checks enabled.");
    6067             :   i::Handle<i::AccessCheckInfo> access_check_info = i::handle(
    6068             :       i::AccessCheckInfo::cast(global_constructor->GetAccessCheckInfo()),
    6069          36 :       isolate);
    6070             :   Utils::ApiCheck(access_check_info->named_interceptor() != i::Object(),
    6071             :                   "v8::Context::NewRemoteContext",
    6072             :                   "Global template needs to have access check handlers.");
    6073             :   i::Handle<i::JSObject> global_proxy = CreateEnvironment<i::JSGlobalProxy>(
    6074             :       isolate, nullptr, global_template, global_object, 0,
    6075          18 :       DeserializeInternalFieldsCallback(), nullptr);
    6076          18 :   if (global_proxy.is_null()) {
    6077           0 :     if (isolate->has_pending_exception()) isolate->clear_pending_exception();
    6078           0 :     return MaybeLocal<Object>();
    6079             :   }
    6080          18 :   return Utils::ToLocal(scope.CloseAndEscape(global_proxy));
    6081             : }
    6082             : 
    6083         263 : void v8::Context::SetSecurityToken(Local<Value> token) {
    6084             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6085             :   i::Handle<i::Object> token_handle = Utils::OpenHandle(*token);
    6086         263 :   env->set_security_token(*token_handle);
    6087         263 : }
    6088             : 
    6089             : 
    6090           0 : void v8::Context::UseDefaultSecurityToken() {
    6091             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6092           0 :   env->set_security_token(env->global_object());
    6093           0 : }
    6094             : 
    6095             : 
    6096          17 : Local<Value> v8::Context::GetSecurityToken() {
    6097             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6098             :   i::Isolate* isolate = env->GetIsolate();
    6099          17 :   i::Object security_token = env->security_token();
    6100             :   i::Handle<i::Object> token_handle(security_token, isolate);
    6101          17 :   return Utils::ToLocal(token_handle);
    6102             : }
    6103             : 
    6104             : 
    6105    16686066 : v8::Isolate* Context::GetIsolate() {
    6106             :   i::Handle<i::Context> env = Utils::OpenHandle(this);
    6107    16686066 :   return reinterpret_cast<Isolate*>(env->GetIsolate());
    6108             : }
    6109             : 
    6110      420731 : v8::Local<v8::Object> Context::Global() {
    6111             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6112             :   i::Isolate* isolate = context->GetIsolate();
    6113      841460 :   i::Handle<i::Object> global(context->global_proxy(), isolate);
    6114             :   // TODO(dcarney): This should always return the global proxy
    6115             :   // but can't presently as calls to GetProtoype will return the wrong result.
    6116      841454 :   if (i::Handle<i::JSGlobalProxy>::cast(
    6117     1262183 :           global)->IsDetachedFrom(context->global_object())) {
    6118         130 :     global = i::Handle<i::Object>(context->global_object(), isolate);
    6119             :   }
    6120      420726 :   return Utils::ToLocal(i::Handle<i::JSObject>::cast(global));
    6121             : }
    6122             : 
    6123             : 
    6124         121 : void Context::DetachGlobal() {
    6125             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6126             :   i::Isolate* isolate = context->GetIsolate();
    6127             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6128         121 :   isolate->bootstrapper()->DetachGlobal(context);
    6129         121 : }
    6130             : 
    6131             : 
    6132          45 : Local<v8::Object> Context::GetExtrasBindingObject() {
    6133             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6134             :   i::Isolate* isolate = context->GetIsolate();
    6135          90 :   i::Handle<i::JSObject> binding(context->extras_binding_object(), isolate);
    6136          45 :   return Utils::ToLocal(binding);
    6137             : }
    6138             : 
    6139             : 
    6140         158 : void Context::AllowCodeGenerationFromStrings(bool allow) {
    6141             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6142             :   i::Isolate* isolate = context->GetIsolate();
    6143             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6144         632 :   context->set_allow_code_gen_from_strings(
    6145             :       allow ? i::ReadOnlyRoots(isolate).true_value()
    6146         158 :             : i::ReadOnlyRoots(isolate).false_value());
    6147         158 : }
    6148             : 
    6149             : 
    6150        9653 : bool Context::IsCodeGenerationFromStringsAllowed() {
    6151             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6152       19306 :   return !context->allow_code_gen_from_strings()->IsFalse(
    6153       19306 :       context->GetIsolate());
    6154             : }
    6155             : 
    6156             : 
    6157           5 : void Context::SetErrorMessageForCodeGenerationFromStrings(Local<String> error) {
    6158             :   i::Handle<i::Context> context = Utils::OpenHandle(this);
    6159             :   i::Handle<i::String> error_handle = Utils::OpenHandle(*error);
    6160          10 :   context->set_error_message_for_code_gen_from_strings(*error_handle);
    6161           5 : }
    6162             : 
    6163             : namespace {
    6164         175 : i::Address* GetSerializedDataFromFixedArray(i::Isolate* isolate,
    6165             :                                             i::FixedArray list, size_t index) {
    6166         175 :   if (index < static_cast<size_t>(list->length())) {
    6167         150 :     int int_index = static_cast<int>(index);
    6168             :     i::Object object = list->get(int_index);
    6169         150 :     if (!object->IsTheHole(isolate)) {
    6170             :       list->set_the_hole(isolate, int_index);
    6171             :       // Shrink the list so that the last element is not the hole (unless it's
    6172             :       // the first element, because we don't want to end up with a non-canonical
    6173             :       // empty FixedArray).
    6174          80 :       int last = list->length() - 1;
    6175         280 :       while (last >= 0 && list->is_the_hole(isolate, last)) last--;
    6176          80 :       if (last != -1) list->Shrink(isolate, last + 1);
    6177             :       return i::Handle<i::Object>(object, isolate).location();
    6178             :     }
    6179             :   }
    6180             :   return nullptr;
    6181             : }
    6182             : }  // anonymous namespace
    6183             : 
    6184          90 : i::Address* Context::GetDataFromSnapshotOnce(size_t index) {
    6185             :   auto context = Utils::OpenHandle(this);
    6186             :   i::Isolate* i_isolate = context->GetIsolate();
    6187          90 :   i::FixedArray list = context->serialized_objects();
    6188          90 :   return GetSerializedDataFromFixedArray(i_isolate, list, index);
    6189             : }
    6190             : 
    6191        2569 : MaybeLocal<v8::Object> ObjectTemplate::NewInstance(Local<Context> context) {
    6192       10276 :   PREPARE_FOR_EXECUTION(context, ObjectTemplate, NewInstance, Object);
    6193        2569 :   auto self = Utils::OpenHandle(this);
    6194             :   Local<Object> result;
    6195        5138 :   has_pending_exception = !ToLocal<Object>(
    6196             :       i::ApiNatives::InstantiateObject(isolate, self), &result);
    6197        2569 :   RETURN_ON_FAILED_EXECUTION(Object);
    6198        2569 :   RETURN_ESCAPED(result);
    6199             : }
    6200             : 
    6201           0 : void v8::ObjectTemplate::CheckCast(Data* that) {
    6202             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6203             :   Utils::ApiCheck(obj->IsObjectTemplateInfo(), "v8::ObjectTemplate::Cast",
    6204             :                   "Could not convert to object template");
    6205           0 : }
    6206             : 
    6207           0 : void v8::FunctionTemplate::CheckCast(Data* that) {
    6208             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6209             :   Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::FunctionTemplate::Cast",
    6210             :                   "Could not convert to function template");
    6211           0 : }
    6212             : 
    6213           0 : void v8::Signature::CheckCast(Data* that) {
    6214             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6215             :   Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::Signature::Cast",
    6216             :                   "Could not convert to signature");
    6217           0 : }
    6218             : 
    6219           0 : void v8::AccessorSignature::CheckCast(Data* that) {
    6220             :   i::Handle<i::Object> obj = Utils::OpenHandle(that);
    6221             :   Utils::ApiCheck(obj->IsFunctionTemplateInfo(), "v8::AccessorSignature::Cast",
    6222             :                   "Could not convert to accessor signature");
    6223           0 : }
    6224             : 
    6225       10753 : MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) {
    6226       43012 :   PREPARE_FOR_EXECUTION(context, FunctionTemplate, GetFunction, Function);
    6227       10753 :   auto self = Utils::OpenHandle(this);
    6228             :   Local<Function> result;
    6229             :   has_pending_exception =
    6230       21506 :       !ToLocal<Function>(i::ApiNatives::InstantiateFunction(self), &result);
    6231       10753 :   RETURN_ON_FAILED_EXECUTION(Function);
    6232       10753 :   RETURN_ESCAPED(result);
    6233             : }
    6234             : 
    6235           8 : MaybeLocal<v8::Object> FunctionTemplate::NewRemoteInstance() {
    6236             :   auto self = Utils::OpenHandle(this);
    6237             :   i::Isolate* isolate = self->GetIsolate();
    6238           8 :   LOG_API(isolate, FunctionTemplate, NewRemoteInstance);
    6239             :   i::HandleScope scope(isolate);
    6240             :   i::Handle<i::FunctionTemplateInfo> constructor =
    6241          16 :       EnsureConstructor(isolate, *InstanceTemplate());
    6242             :   Utils::ApiCheck(constructor->needs_access_check(),
    6243             :                   "v8::FunctionTemplate::NewRemoteInstance",
    6244             :                   "InstanceTemplate needs to have access checks enabled.");
    6245             :   i::Handle<i::AccessCheckInfo> access_check_info = i::handle(
    6246          16 :       i::AccessCheckInfo::cast(constructor->GetAccessCheckInfo()), isolate);
    6247             :   Utils::ApiCheck(access_check_info->named_interceptor() != i::Object(),
    6248             :                   "v8::FunctionTemplate::NewRemoteInstance",
    6249             :                   "InstanceTemplate needs to have access check handlers.");
    6250             :   i::Handle<i::JSObject> object;
    6251          24 :   if (!i::ApiNatives::InstantiateRemoteObject(
    6252          16 :            Utils::OpenHandle(*InstanceTemplate()))
    6253             :            .ToHandle(&object)) {
    6254           0 :     if (isolate->has_pending_exception()) {
    6255           0 :       isolate->OptionalRescheduleException(true);
    6256             :     }
    6257           0 :     return MaybeLocal<Object>();
    6258             :   }
    6259           8 :   return Utils::ToLocal(scope.CloseAndEscape(object));
    6260             : }
    6261             : 
    6262         152 : bool FunctionTemplate::HasInstance(v8::Local<v8::Value> value) {
    6263             :   auto self = Utils::OpenHandle(this);
    6264             :   auto obj = Utils::OpenHandle(*value);
    6265         304 :   if (obj->IsJSObject() && self->IsTemplateFor(i::JSObject::cast(*obj))) {
    6266             :     return true;
    6267             :   }
    6268          38 :   if (obj->IsJSGlobalProxy()) {
    6269             :     // If it's a global proxy, then test with the global object. Note that the
    6270             :     // inner global object may not necessarily be a JSGlobalObject.
    6271             :     i::PrototypeIterator iter(self->GetIsolate(),
    6272           2 :                               i::JSObject::cast(*obj)->map());
    6273             :     // The global proxy should always have a prototype, as it is a bug to call
    6274             :     // this on a detached JSGlobalProxy.
    6275             :     DCHECK(!iter.IsAtEnd());
    6276           2 :     return self->IsTemplateFor(iter.GetCurrent<i::JSObject>());
    6277             :   }
    6278             :   return false;
    6279             : }
    6280             : 
    6281             : 
    6282        3910 : Local<External> v8::External::New(Isolate* isolate, void* value) {
    6283             :   STATIC_ASSERT(sizeof(value) == sizeof(i::Address));
    6284             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6285        3910 :   LOG_API(i_isolate, External, New);
    6286             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6287        3910 :   i::Handle<i::JSObject> external = i_isolate->factory()->NewExternal(value);
    6288        3910 :   return Utils::ExternalToLocal(external);
    6289             : }
    6290             : 
    6291             : 
    6292     1031963 : void* External::Value() const {
    6293     1031963 :   return ExternalValue(*Utils::OpenHandle(this));
    6294             : }
    6295             : 
    6296             : 
    6297             : // anonymous namespace for string creation helper functions
    6298             : namespace {
    6299             : 
    6300             : inline int StringLength(const char* string) {
    6301             :   return i::StrLength(string);
    6302             : }
    6303             : 
    6304             : 
    6305             : inline int StringLength(const uint8_t* string) {
    6306             :   return i::StrLength(reinterpret_cast<const char*>(string));
    6307             : }
    6308             : 
    6309             : 
    6310             : inline int StringLength(const uint16_t* string) {
    6311             :   int length = 0;
    6312        4083 :   while (string[length] != '\0')
    6313        4025 :     length++;
    6314             :   return length;
    6315             : }
    6316             : 
    6317             : V8_WARN_UNUSED_RESULT
    6318     9449831 : inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
    6319             :                                            v8::NewStringType type,
    6320             :                                            i::Vector<const char> string) {
    6321     9449831 :   if (type == v8::NewStringType::kInternalized) {
    6322       72384 :     return factory->InternalizeUtf8String(string);
    6323             :   }
    6324     9377447 :   return factory->NewStringFromUtf8(string);
    6325             : }
    6326             : 
    6327             : V8_WARN_UNUSED_RESULT
    6328          24 : inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
    6329             :                                            v8::NewStringType type,
    6330             :                                            i::Vector<const uint8_t> string) {
    6331          24 :   if (type == v8::NewStringType::kInternalized) {
    6332           0 :     return factory->InternalizeOneByteString(string);
    6333             :   }
    6334          24 :   return factory->NewStringFromOneByte(string);
    6335             : }
    6336             : 
    6337             : V8_WARN_UNUSED_RESULT
    6338     1209704 : inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
    6339             :                                            v8::NewStringType type,
    6340             :                                            i::Vector<const uint16_t> string) {
    6341     1209704 :   if (type == v8::NewStringType::kInternalized) {
    6342           0 :     return factory->InternalizeTwoByteString(string);
    6343             :   }
    6344     1209704 :   return factory->NewStringFromTwoByte(string);
    6345             : }
    6346             : 
    6347             : 
    6348             : STATIC_ASSERT(v8::String::kMaxLength == i::String::kMaxLength);
    6349             : 
    6350             : }  // anonymous namespace
    6351             : 
    6352             : // TODO(dcarney): throw a context free exception.
    6353             : #define NEW_STRING(isolate, class_name, function_name, Char, data, type,   \
    6354             :                    length)                                                 \
    6355             :   MaybeLocal<String> result;                                               \
    6356             :   if (length == 0) {                                                       \
    6357             :     result = String::Empty(isolate);                                       \
    6358             :   } else if (length > i::String::kMaxLength) {                             \
    6359             :     result = MaybeLocal<String>();                                         \
    6360             :   } else {                                                                 \
    6361             :     i::Isolate* i_isolate = reinterpret_cast<internal::Isolate*>(isolate); \
    6362             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);                            \
    6363             :     LOG_API(i_isolate, class_name, function_name);                         \
    6364             :     if (length < 0) length = StringLength(data);                           \
    6365             :     i::Handle<i::String> handle_result =                                   \
    6366             :         NewString(i_isolate->factory(), type,                              \
    6367             :                   i::Vector<const Char>(data, length))                     \
    6368             :             .ToHandleChecked();                                            \
    6369             :     result = Utils::ToLocal(handle_result);                                \
    6370             :   }
    6371             : 
    6372           0 : Local<String> String::NewFromUtf8(Isolate* isolate,
    6373             :                                   const char* data,
    6374             :                                   NewStringType type,
    6375             :                                   int length) {
    6376           0 :   NEW_STRING(isolate, String, NewFromUtf8, char, data,
    6377             :              static_cast<v8::NewStringType>(type), length);
    6378           0 :   RETURN_TO_LOCAL_UNCHECKED(result, String);
    6379             : }
    6380             : 
    6381             : 
    6382     9449852 : MaybeLocal<String> String::NewFromUtf8(Isolate* isolate, const char* data,
    6383             :                                        v8::NewStringType type, int length) {
    6384    56699020 :   NEW_STRING(isolate, String, NewFromUtf8, char, data, type, length);
    6385     9449852 :   return result;
    6386             : }
    6387             : 
    6388             : 
    6389          39 : MaybeLocal<String> String::NewFromOneByte(Isolate* isolate, const uint8_t* data,
    6390             :                                           v8::NewStringType type, int length) {
    6391         164 :   NEW_STRING(isolate, String, NewFromOneByte, uint8_t, data, type, length);
    6392          39 :   return result;
    6393             : }
    6394             : 
    6395             : 
    6396           0 : Local<String> String::NewFromTwoByte(Isolate* isolate,
    6397             :                                      const uint16_t* data,
    6398             :                                      NewStringType type,
    6399             :                                      int length) {
    6400           0 :   NEW_STRING(isolate, String, NewFromTwoByte, uint16_t, data,
    6401             :              static_cast<v8::NewStringType>(type), length);
    6402           0 :   RETURN_TO_LOCAL_UNCHECKED(result, String);
    6403             : }
    6404             : 
    6405             : 
    6406     1213147 : MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
    6407             :                                           const uint16_t* data,
    6408             :                                           v8::NewStringType type, int length) {
    6409     7261670 :   NEW_STRING(isolate, String, NewFromTwoByte, uint16_t, data, type, length);
    6410     1213147 :   return result;
    6411             : }
    6412             : 
    6413      140624 : Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
    6414             :                                  Local<String> right) {
    6415             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    6416             :   i::Handle<i::String> left_string = Utils::OpenHandle(*left);
    6417             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6418      140624 :   LOG_API(isolate, String, Concat);
    6419             :   i::Handle<i::String> right_string = Utils::OpenHandle(*right);
    6420             :   // If we are steering towards a range error, do not wait for the error to be
    6421             :   // thrown, and return the null handle instead.
    6422      140624 :   if (left_string->length() + right_string->length() > i::String::kMaxLength) {
    6423          10 :     return Local<String>();
    6424             :   }
    6425      281228 :   i::Handle<i::String> result = isolate->factory()->NewConsString(
    6426             :       left_string, right_string).ToHandleChecked();
    6427             :   return Utils::ToLocal(result);
    6428             : }
    6429             : 
    6430       18910 : MaybeLocal<String> v8::String::NewExternalTwoByte(
    6431             :     Isolate* isolate, v8::String::ExternalStringResource* resource) {
    6432       18910 :   CHECK(resource && resource->data());
    6433             :   // TODO(dcarney): throw a context free exception.
    6434       18910 :   if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) {
    6435           6 :     return MaybeLocal<String>();
    6436             :   }
    6437             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6438             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6439       18904 :   LOG_API(i_isolate, String, NewExternalTwoByte);
    6440       18904 :   if (resource->length() > 0) {
    6441             :     i::Handle<i::String> string = i_isolate->factory()
    6442       37788 :                                       ->NewExternalStringFromTwoByte(resource)
    6443             :                                       .ToHandleChecked();
    6444       18894 :     return Utils::ToLocal(string);
    6445             :   } else {
    6446             :     // The resource isn't going to be used, free it immediately.
    6447          10 :     resource->Dispose();
    6448          10 :     return Utils::ToLocal(i_isolate->factory()->empty_string());
    6449             :   }
    6450             : }
    6451             : 
    6452             : 
    6453        1292 : MaybeLocal<String> v8::String::NewExternalOneByte(
    6454             :     Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
    6455        1292 :   CHECK(resource && resource->data());
    6456             :   // TODO(dcarney): throw a context free exception.
    6457        1292 :   if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) {
    6458           6 :     return MaybeLocal<String>();
    6459             :   }
    6460             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6461             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6462        1286 :   LOG_API(i_isolate, String, NewExternalOneByte);
    6463        1286 :   if (resource->length() > 0) {
    6464             :     i::Handle<i::String> string = i_isolate->factory()
    6465        2562 :                                       ->NewExternalStringFromOneByte(resource)
    6466             :                                       .ToHandleChecked();
    6467        1281 :     return Utils::ToLocal(string);
    6468             :   } else {
    6469             :     // The resource isn't going to be used, free it immediately.
    6470           5 :     resource->Dispose();
    6471           5 :     return Utils::ToLocal(i_isolate->factory()->empty_string());
    6472             :   }
    6473             : }
    6474             : 
    6475             : 
    6476           0 : Local<String> v8::String::NewExternal(
    6477             :     Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
    6478           0 :   RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String);
    6479             : }
    6480             : 
    6481             : 
    6482         290 : bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
    6483             :   i::DisallowHeapAllocation no_allocation;
    6484             : 
    6485         290 :   i::String obj = *Utils::OpenHandle(this);
    6486             : 
    6487         290 :   if (obj->IsThinString()) {
    6488           0 :     obj = i::ThinString::cast(obj)->actual();
    6489             :   }
    6490             : 
    6491         290 :   if (!obj->SupportsExternalization()) {
    6492             :     return false;
    6493             :   }
    6494             : 
    6495             :   // It is safe to call GetIsolateFromWritableHeapObject because
    6496             :   // SupportsExternalization already checked that the object is writable.
    6497             :   i::Isolate* isolate;
    6498             :   i::GetIsolateFromWritableObject(obj, &isolate);
    6499             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6500             : 
    6501         290 :   CHECK(resource && resource->data());
    6502             : 
    6503         290 :   bool result = obj->MakeExternal(resource);
    6504             :   DCHECK(result);
    6505             :   DCHECK(obj->IsExternalString());
    6506             :   return result;
    6507             : }
    6508             : 
    6509             : 
    6510         290 : bool v8::String::MakeExternal(
    6511             :     v8::String::ExternalOneByteStringResource* resource) {
    6512             :   i::DisallowHeapAllocation no_allocation;
    6513             : 
    6514         290 :   i::String obj = *Utils::OpenHandle(this);
    6515             : 
    6516         290 :   if (obj->IsThinString()) {
    6517           0 :     obj = i::ThinString::cast(obj)->actual();
    6518             :   }
    6519             : 
    6520         290 :   if (!obj->SupportsExternalization()) {
    6521             :     return false;
    6522             :   }
    6523             : 
    6524             :   // It is safe to call GetIsolateFromWritableHeapObject because
    6525             :   // SupportsExternalization already checked that the object is writable.
    6526             :   i::Isolate* isolate;
    6527             :   i::GetIsolateFromWritableObject(obj, &isolate);
    6528             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6529             : 
    6530         290 :   CHECK(resource && resource->data());
    6531             : 
    6532         290 :   bool result = obj->MakeExternal(resource);
    6533             :   DCHECK_IMPLIES(result, obj->IsExternalString());
    6534             :   return result;
    6535             : }
    6536             : 
    6537             : 
    6538          40 : bool v8::String::CanMakeExternal() {
    6539             :   i::DisallowHeapAllocation no_allocation;
    6540          40 :   i::String obj = *Utils::OpenHandle(this);
    6541             : 
    6542          40 :   if (obj->IsThinString()) {
    6543           0 :     obj = i::ThinString::cast(obj)->actual();
    6544             :   }
    6545             : 
    6546          40 :   if (!obj->SupportsExternalization()) {
    6547             :     return false;
    6548             :   }
    6549             : 
    6550             :   // Only old space strings should be externalized.
    6551          30 :   return !i::Heap::InYoungGeneration(obj);
    6552             : }
    6553             : 
    6554       17732 : bool v8::String::StringEquals(Local<String> that) {
    6555             :   auto self = Utils::OpenHandle(this);
    6556             :   auto other = Utils::OpenHandle(*that);
    6557       17732 :   return self->Equals(*other);
    6558             : }
    6559             : 
    6560       80060 : Isolate* v8::Object::GetIsolate() {
    6561             :   i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
    6562       80060 :   return reinterpret_cast<Isolate*>(i_isolate);
    6563             : }
    6564             : 
    6565             : 
    6566      107886 : Local<v8::Object> v8::Object::New(Isolate* isolate) {
    6567             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6568      107886 :   LOG_API(i_isolate, Object, New);
    6569             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6570             :   i::Handle<i::JSObject> obj =
    6571      107886 :       i_isolate->factory()->NewJSObject(i_isolate->object_function());
    6572      107886 :   return Utils::ToLocal(obj);
    6573             : }
    6574             : 
    6575          48 : Local<v8::Object> v8::Object::New(Isolate* isolate,
    6576             :                                   Local<Value> prototype_or_null,
    6577             :                                   Local<Name>* names, Local<Value>* values,
    6578             :                                   size_t length) {
    6579             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6580             :   i::Handle<i::Object> proto = Utils::OpenHandle(*prototype_or_null);
    6581         108 :   if (!Utils::ApiCheck(proto->IsNull() || proto->IsJSReceiver(),
    6582             :                        "v8::Object::New", "prototype must be null or object")) {
    6583           0 :     return Local<v8::Object>();
    6584             :   }
    6585          48 :   LOG_API(i_isolate, Object, New);
    6586             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6587             : 
    6588             :   // We assume that this API is mostly used to create objects with named
    6589             :   // properties, and so we default to creating a properties backing store
    6590             :   // large enough to hold all of them, while we start with no elements
    6591             :   // (see http://bit.ly/v8-fast-object-create-cpp for the motivation).
    6592             :   i::Handle<i::NameDictionary> properties =
    6593          48 :       i::NameDictionary::New(i_isolate, static_cast<int>(length));
    6594             :   i::Handle<i::FixedArrayBase> elements =
    6595             :       i_isolate->factory()->empty_fixed_array();
    6596      123084 :   for (size_t i = 0; i < length; ++i) {
    6597       61518 :     i::Handle<i::Name> name = Utils::OpenHandle(*names[i]);
    6598       61518 :     i::Handle<i::Object> value = Utils::OpenHandle(*values[i]);
    6599             : 
    6600             :     // See if the {name} is a valid array index, in which case we need to
    6601             :     // add the {name}/{value} pair to the {elements}, otherwise they end
    6602             :     // up in the {properties} backing store.
    6603             :     uint32_t index;
    6604       61518 :     if (name->AsArrayIndex(&index)) {
    6605             :       // If this is the first element, allocate a proper
    6606             :       // dictionary elements backing store for {elements}.
    6607          18 :       if (!elements->IsNumberDictionary()) {
    6608             :         elements =
    6609          12 :             i::NumberDictionary::New(i_isolate, static_cast<int>(length));
    6610             :       }
    6611             :       elements = i::NumberDictionary::Set(
    6612             :           i_isolate, i::Handle<i::NumberDictionary>::cast(elements), index,
    6613          18 :           value);
    6614             :     } else {
    6615             :       // Internalize the {name} first.
    6616       61500 :       name = i_isolate->factory()->InternalizeName(name);
    6617       61500 :       int const entry = properties->FindEntry(i_isolate, name);
    6618       61500 :       if (entry == i::NameDictionary::kNotFound) {
    6619             :         // Add the {name}/{value} pair as a new entry.
    6620             :         properties = i::NameDictionary::Add(i_isolate, properties, name, value,
    6621       61488 :                                             i::PropertyDetails::Empty());
    6622             :       } else {
    6623             :         // Overwrite the {entry} with the {value}.
    6624          24 :         properties->ValueAtPut(entry, *value);
    6625             :       }
    6626             :     }
    6627             :   }
    6628             :   i::Handle<i::JSObject> obj =
    6629             :       i_isolate->factory()->NewSlowJSObjectWithPropertiesAndElements(
    6630          48 :           proto, properties, elements);
    6631             :   return Utils::ToLocal(obj);
    6632             : }
    6633             : 
    6634           6 : Local<v8::Value> v8::NumberObject::New(Isolate* isolate, double value) {
    6635             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6636           6 :   LOG_API(i_isolate, NumberObject, New);
    6637             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6638           6 :   i::Handle<i::Object> number = i_isolate->factory()->NewNumber(value);
    6639             :   i::Handle<i::Object> obj =
    6640          12 :       i::Object::ToObject(i_isolate, number).ToHandleChecked();
    6641           6 :   return Utils::ToLocal(obj);
    6642             : }
    6643             : 
    6644             : 
    6645          29 : double v8::NumberObject::ValueOf() const {
    6646             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6647             :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6648             :   i::Isolate* isolate = jsvalue->GetIsolate();
    6649          29 :   LOG_API(isolate, NumberObject, NumberValue);
    6650          29 :   return jsvalue->value()->Number();
    6651             : }
    6652             : 
    6653           7 : Local<v8::Value> v8::BigIntObject::New(Isolate* isolate, int64_t value) {
    6654             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6655           7 :   LOG_API(i_isolate, BigIntObject, New);
    6656             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6657           7 :   i::Handle<i::Object> bigint = i::BigInt::FromInt64(i_isolate, value);
    6658             :   i::Handle<i::Object> obj =
    6659          14 :       i::Object::ToObject(i_isolate, bigint).ToHandleChecked();
    6660           7 :   return Utils::ToLocal(obj);
    6661             : }
    6662             : 
    6663          11 : Local<v8::BigInt> v8::BigIntObject::ValueOf() const {
    6664             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6665             :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6666             :   i::Isolate* isolate = jsvalue->GetIsolate();
    6667          11 :   LOG_API(isolate, BigIntObject, BigIntValue);
    6668             :   return Utils::ToLocal(
    6669          11 :       i::Handle<i::BigInt>(i::BigInt::cast(jsvalue->value()), isolate));
    6670             : }
    6671             : 
    6672          24 : Local<v8::Value> v8::BooleanObject::New(Isolate* isolate, bool value) {
    6673             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6674          24 :   LOG_API(i_isolate, BooleanObject, New);
    6675             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6676             :   i::Handle<i::Object> boolean(value
    6677             :                                    ? i::ReadOnlyRoots(i_isolate).true_value()
    6678             :                                    : i::ReadOnlyRoots(i_isolate).false_value(),
    6679          24 :                                i_isolate);
    6680             :   i::Handle<i::Object> obj =
    6681          48 :       i::Object::ToObject(i_isolate, boolean).ToHandleChecked();
    6682          24 :   return Utils::ToLocal(obj);
    6683             : }
    6684             : 
    6685             : 
    6686          47 : bool v8::BooleanObject::ValueOf() const {
    6687             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6688             :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6689             :   i::Isolate* isolate = jsvalue->GetIsolate();
    6690          47 :   LOG_API(isolate, BooleanObject, BooleanValue);
    6691          47 :   return jsvalue->value()->IsTrue(isolate);
    6692             : }
    6693             : 
    6694             : 
    6695          12 : Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
    6696             :                                        Local<String> value) {
    6697             :   i::Handle<i::String> string = Utils::OpenHandle(*value);
    6698             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    6699          12 :   LOG_API(isolate, StringObject, New);
    6700             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6701             :   i::Handle<i::Object> obj =
    6702          24 :       i::Object::ToObject(isolate, string).ToHandleChecked();
    6703          12 :   return Utils::ToLocal(obj);
    6704             : }
    6705             : 
    6706             : 
    6707          34 : Local<v8::String> v8::StringObject::ValueOf() const {
    6708             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6709             :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6710             :   i::Isolate* isolate = jsvalue->GetIsolate();
    6711          34 :   LOG_API(isolate, StringObject, StringValue);
    6712             :   return Utils::ToLocal(
    6713          34 :       i::Handle<i::String>(i::String::cast(jsvalue->value()), isolate));
    6714             : }
    6715             : 
    6716             : 
    6717           6 : Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Local<Symbol> value) {
    6718             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6719           6 :   LOG_API(i_isolate, SymbolObject, New);
    6720             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6721          12 :   i::Handle<i::Object> obj = i::Object::ToObject(
    6722           6 :       i_isolate, Utils::OpenHandle(*value)).ToHandleChecked();
    6723           6 :   return Utils::ToLocal(obj);
    6724             : }
    6725             : 
    6726             : 
    6727          11 : Local<v8::Symbol> v8::SymbolObject::ValueOf() const {
    6728             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6729             :   i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj);
    6730             :   i::Isolate* isolate = jsvalue->GetIsolate();
    6731          11 :   LOG_API(isolate, SymbolObject, SymbolValue);
    6732             :   return Utils::ToLocal(
    6733          11 :       i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()), isolate));
    6734             : }
    6735             : 
    6736             : 
    6737         132 : MaybeLocal<v8::Value> v8::Date::New(Local<Context> context, double time) {
    6738         132 :   if (std::isnan(time)) {
    6739             :     // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
    6740             :     time = std::numeric_limits<double>::quiet_NaN();
    6741             :   }
    6742         528 :   PREPARE_FOR_EXECUTION(context, Date, New, Value);
    6743             :   Local<Value> result;
    6744         396 :   has_pending_exception = !ToLocal<Value>(
    6745             :       i::JSDate::New(isolate->date_function(), isolate->date_function(), time),
    6746             :       &result);
    6747         132 :   RETURN_ON_FAILED_EXECUTION(Value);
    6748         132 :   RETURN_ESCAPED(result);
    6749             : }
    6750             : 
    6751             : 
    6752          10 : double v8::Date::ValueOf() const {
    6753             :   i::Handle<i::Object> obj = Utils::OpenHandle(this);
    6754             :   i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj);
    6755             :   i::Isolate* isolate = jsdate->GetIsolate();
    6756          10 :   LOG_API(isolate, Date, NumberValue);
    6757          10 :   return jsdate->value()->Number();
    6758             : }
    6759             : 
    6760             : // Assert that the static TimeZoneDetection cast in
    6761             : // DateTimeConfigurationChangeNotification is valid.
    6762             : #define TIME_ZONE_DETECTION_ASSERT_EQ(value)                               \
    6763             :   STATIC_ASSERT(                                                           \
    6764             :       static_cast<int>(v8::Isolate::TimeZoneDetection::value) ==           \
    6765             :       static_cast<int>(base::TimezoneCache::TimeZoneDetection::value));    \
    6766             :   STATIC_ASSERT(static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
    6767             :                 static_cast<int>(v8::Date::TimeZoneDetection::value));
    6768             : TIME_ZONE_DETECTION_ASSERT_EQ(kSkip)
    6769             : TIME_ZONE_DETECTION_ASSERT_EQ(kRedetect)
    6770             : #undef TIME_ZONE_DETECTION_ASSERT_EQ
    6771             : 
    6772             : // static
    6773           0 : void v8::Date::DateTimeConfigurationChangeNotification(
    6774             :     Isolate* isolate, TimeZoneDetection time_zone_detection) {
    6775             :   isolate->DateTimeConfigurationChangeNotification(
    6776           0 :       static_cast<v8::Isolate::TimeZoneDetection>(time_zone_detection));
    6777           0 : }
    6778             : 
    6779         210 : MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
    6780             :                                        Local<String> pattern, Flags flags) {
    6781         840 :   PREPARE_FOR_EXECUTION(context, RegExp, New, RegExp);
    6782             :   Local<v8::RegExp> result;
    6783             :   has_pending_exception =
    6784         630 :       !ToLocal<RegExp>(i::JSRegExp::New(isolate, Utils::OpenHandle(*pattern),
    6785             :                                         static_cast<i::JSRegExp::Flags>(flags)),
    6786             :                        &result);
    6787         210 :   RETURN_ON_FAILED_EXECUTION(RegExp);
    6788         200 :   RETURN_ESCAPED(result);
    6789             : }
    6790             : 
    6791             : 
    6792         120 : Local<v8::String> v8::RegExp::GetSource() const {
    6793             :   i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
    6794             :   return Utils::ToLocal(
    6795         240 :       i::Handle<i::String>(obj->Pattern(), obj->GetIsolate()));
    6796             : }
    6797             : 
    6798             : 
    6799             : // Assert that the static flags cast in GetFlags is valid.
    6800             : #define REGEXP_FLAG_ASSERT_EQ(flag)                   \
    6801             :   STATIC_ASSERT(static_cast<int>(v8::RegExp::flag) == \
    6802             :                 static_cast<int>(i::JSRegExp::flag))
    6803             : REGEXP_FLAG_ASSERT_EQ(kNone);
    6804             : REGEXP_FLAG_ASSERT_EQ(kGlobal);
    6805             : REGEXP_FLAG_ASSERT_EQ(kIgnoreCase);
    6806             : REGEXP_FLAG_ASSERT_EQ(kMultiline);
    6807             : REGEXP_FLAG_ASSERT_EQ(kSticky);
    6808             : REGEXP_FLAG_ASSERT_EQ(kUnicode);
    6809             : #undef REGEXP_FLAG_ASSERT_EQ
    6810             : 
    6811         120 : v8::RegExp::Flags v8::RegExp::GetFlags() const {
    6812             :   i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
    6813         240 :   return RegExp::Flags(static_cast<int>(obj->GetFlags()));
    6814             : }
    6815             : 
    6816             : 
    6817       69166 : Local<v8::Array> v8::Array::New(Isolate* isolate, int length) {
    6818             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6819       69166 :   LOG_API(i_isolate, Array, New);
    6820             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6821       69166 :   int real_length = length > 0 ? length : 0;
    6822             :   i::Handle<i::JSArray> obj = i_isolate->factory()->NewJSArray(real_length);
    6823             :   i::Handle<i::Object> length_obj =
    6824       69166 :       i_isolate->factory()->NewNumberFromInt(real_length);
    6825       69166 :   obj->set_length(*length_obj);
    6826       69166 :   return Utils::ToLocal(obj);
    6827             : }
    6828             : 
    6829           6 : Local<v8::Array> v8::Array::New(Isolate* isolate, Local<Value>* elements,
    6830             :                                 size_t length) {
    6831             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6832             :   i::Factory* factory = i_isolate->factory();
    6833           6 :   LOG_API(i_isolate, Array, New);
    6834             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6835           6 :   int len = static_cast<int>(length);
    6836             : 
    6837           6 :   i::Handle<i::FixedArray> result = factory->NewFixedArray(len);
    6838          42 :   for (int i = 0; i < len; i++) {
    6839          18 :     i::Handle<i::Object> element = Utils::OpenHandle(*elements[i]);
    6840          18 :     result->set(i, *element);
    6841             :   }
    6842             : 
    6843             :   return Utils::ToLocal(
    6844          12 :       factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, len));
    6845             : }
    6846             : 
    6847      274736 : uint32_t v8::Array::Length() const {
    6848             :   i::Handle<i::JSArray> obj = Utils::OpenHandle(this);
    6849             :   i::Object length = obj->length();
    6850      274736 :   if (length->IsSmi()) {
    6851      274736 :     return i::Smi::ToInt(length);
    6852             :   } else {
    6853           0 :     return static_cast<uint32_t>(length->Number());
    6854             :   }
    6855             : }
    6856             : 
    6857             : 
    6858           5 : Local<v8::Map> v8::Map::New(Isolate* isolate) {
    6859             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6860           5 :   LOG_API(i_isolate, Map, New);
    6861             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6862           5 :   i::Handle<i::JSMap> obj = i_isolate->factory()->NewJSMap();
    6863           5 :   return Utils::ToLocal(obj);
    6864             : }
    6865             : 
    6866             : 
    6867         188 : size_t v8::Map::Size() const {
    6868             :   i::Handle<i::JSMap> obj = Utils::OpenHandle(this);
    6869         188 :   return i::OrderedHashMap::cast(obj->table())->NumberOfElements();
    6870             : }
    6871             : 
    6872             : 
    6873           5 : void Map::Clear() {
    6874             :   auto self = Utils::OpenHandle(this);
    6875             :   i::Isolate* isolate = self->GetIsolate();
    6876           5 :   LOG_API(isolate, Map, Clear);
    6877             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6878           5 :   i::JSMap::Clear(isolate, self);
    6879           5 : }
    6880             : 
    6881             : 
    6882          15 : MaybeLocal<Value> Map::Get(Local<Context> context, Local<Value> key) {
    6883          60 :   PREPARE_FOR_EXECUTION(context, Map, Get, Value);
    6884             :   auto self = Utils::OpenHandle(this);
    6885             :   Local<Value> result;
    6886          15 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    6887             :   has_pending_exception =
    6888          45 :       !ToLocal<Value>(i::Execution::Call(isolate, isolate->map_get(), self,
    6889             :                                          arraysize(argv), argv),
    6890             :                       &result);
    6891          15 :   RETURN_ON_FAILED_EXECUTION(Value);
    6892          15 :   RETURN_ESCAPED(result);
    6893             : }
    6894             : 
    6895             : 
    6896           5 : MaybeLocal<Map> Map::Set(Local<Context> context, Local<Value> key,
    6897             :                          Local<Value> value) {
    6898          20 :   PREPARE_FOR_EXECUTION(context, Map, Set, Map);
    6899             :   auto self = Utils::OpenHandle(this);
    6900             :   i::Handle<i::Object> result;
    6901             :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
    6902          10 :                                  Utils::OpenHandle(*value)};
    6903          10 :   has_pending_exception = !i::Execution::Call(isolate, isolate->map_set(), self,
    6904          10 :                                               arraysize(argv), argv)
    6905             :                                .ToHandle(&result);
    6906           5 :   RETURN_ON_FAILED_EXECUTION(Map);
    6907           5 :   RETURN_ESCAPED(Local<Map>::Cast(Utils::ToLocal(result)));
    6908             : }
    6909             : 
    6910             : 
    6911          30 : Maybe<bool> Map::Has(Local<Context> context, Local<Value> key) {
    6912             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    6913          90 :   ENTER_V8(isolate, context, Map, Has, Nothing<bool>(), i::HandleScope);
    6914             :   auto self = Utils::OpenHandle(this);
    6915             :   i::Handle<i::Object> result;
    6916          30 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    6917          60 :   has_pending_exception = !i::Execution::Call(isolate, isolate->map_has(), self,
    6918          60 :                                               arraysize(argv), argv)
    6919             :                                .ToHandle(&result);
    6920          30 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    6921             :   return Just(result->IsTrue(isolate));
    6922             : }
    6923             : 
    6924             : 
    6925          15 : Maybe<bool> Map::Delete(Local<Context> context, Local<Value> key) {
    6926             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    6927          45 :   ENTER_V8(isolate, context, Map, Delete, Nothing<bool>(), i::HandleScope);
    6928             :   auto self = Utils::OpenHandle(this);
    6929             :   i::Handle<i::Object> result;
    6930          15 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    6931          30 :   has_pending_exception = !i::Execution::Call(isolate, isolate->map_delete(),
    6932          30 :                                               self, arraysize(argv), argv)
    6933             :                                .ToHandle(&result);
    6934          15 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    6935             :   return Just(result->IsTrue(isolate));
    6936             : }
    6937             : 
    6938             : namespace {
    6939             : 
    6940             : enum class MapAsArrayKind {
    6941             :   kEntries = i::JS_MAP_KEY_VALUE_ITERATOR_TYPE,
    6942             :   kKeys = i::JS_MAP_KEY_ITERATOR_TYPE,
    6943             :   kValues = i::JS_MAP_VALUE_ITERATOR_TYPE
    6944             : };
    6945             : 
    6946             : enum class SetAsArrayKind {
    6947             :   kEntries = i::JS_SET_KEY_VALUE_ITERATOR_TYPE,
    6948             :   kValues = i::JS_SET_VALUE_ITERATOR_TYPE
    6949             : };
    6950             : 
    6951         245 : i::Handle<i::JSArray> MapAsArray(i::Isolate* isolate, i::Object table_obj,
    6952             :                                  int offset, MapAsArrayKind kind) {
    6953             :   i::Factory* factory = isolate->factory();
    6954             :   i::Handle<i::OrderedHashMap> table(i::OrderedHashMap::cast(table_obj),
    6955             :                                      isolate);
    6956             :   const bool collect_keys =
    6957         245 :       kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys;
    6958             :   const bool collect_values =
    6959         245 :       kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues;
    6960         245 :   int capacity = table->UsedCapacity();
    6961             :   int max_length =
    6962         245 :       (capacity - offset) * ((collect_keys && collect_values) ? 2 : 1);
    6963         245 :   i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length);
    6964             :   int result_index = 0;
    6965             :   {
    6966             :     i::DisallowHeapAllocation no_gc;
    6967             :     i::Oddball the_hole = i::ReadOnlyRoots(isolate).the_hole_value();
    6968       11121 :     for (int i = offset; i < capacity; ++i) {
    6969        5438 :       i::Object key = table->KeyAt(i);
    6970        5443 :       if (key == the_hole) continue;
    6971       10723 :       if (collect_keys) result->set(result_index++, key);
    6972       16203 :       if (collect_values) result->set(result_index++, table->ValueAt(i));
    6973             :     }
    6974             :   }
    6975             :   DCHECK_GE(max_length, result_index);
    6976         245 :   if (result_index == 0) return factory->NewJSArray(0);
    6977         221 :   result->Shrink(isolate, result_index);
    6978             :   return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
    6979         221 :                                          result_index);
    6980             : }
    6981             : 
    6982             : }  // namespace
    6983             : 
    6984         123 : Local<Array> Map::AsArray() const {
    6985             :   i::Handle<i::JSMap> obj = Utils::OpenHandle(this);
    6986             :   i::Isolate* isolate = obj->GetIsolate();
    6987         123 :   LOG_API(isolate, Map, AsArray);
    6988             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    6989             :   return Utils::ToLocal(
    6990         246 :       MapAsArray(isolate, obj->table(), 0, MapAsArrayKind::kEntries));
    6991             : }
    6992             : 
    6993             : 
    6994       79698 : Local<v8::Set> v8::Set::New(Isolate* isolate) {
    6995             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    6996       79698 :   LOG_API(i_isolate, Set, New);
    6997             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    6998       79698 :   i::Handle<i::JSSet> obj = i_isolate->factory()->NewJSSet();
    6999       79698 :   return Utils::ToLocal(obj);
    7000             : }
    7001             : 
    7002             : 
    7003         124 : size_t v8::Set::Size() const {
    7004             :   i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
    7005         124 :   return i::OrderedHashSet::cast(obj->table())->NumberOfElements();
    7006             : }
    7007             : 
    7008             : 
    7009           5 : void Set::Clear() {
    7010             :   auto self = Utils::OpenHandle(this);
    7011             :   i::Isolate* isolate = self->GetIsolate();
    7012           5 :   LOG_API(isolate, Set, Clear);
    7013             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7014           5 :   i::JSSet::Clear(isolate, self);
    7015           5 : }
    7016             : 
    7017             : 
    7018     3003088 : MaybeLocal<Set> Set::Add(Local<Context> context, Local<Value> key) {
    7019    12012352 :   PREPARE_FOR_EXECUTION(context, Set, Add, Set);
    7020             :   auto self = Utils::OpenHandle(this);
    7021             :   i::Handle<i::Object> result;
    7022     3003088 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    7023     6006176 :   has_pending_exception = !i::Execution::Call(isolate, isolate->set_add(), self,
    7024     6006176 :                                               arraysize(argv), argv)
    7025             :                                .ToHandle(&result);
    7026     3003088 :   RETURN_ON_FAILED_EXECUTION(Set);
    7027     3003088 :   RETURN_ESCAPED(Local<Set>::Cast(Utils::ToLocal(result)));
    7028             : }
    7029             : 
    7030             : 
    7031     4471308 : Maybe<bool> Set::Has(Local<Context> context, Local<Value> key) {
    7032             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7033    13413924 :   ENTER_V8(isolate, context, Set, Has, Nothing<bool>(), i::HandleScope);
    7034             :   auto self = Utils::OpenHandle(this);
    7035             :   i::Handle<i::Object> result;
    7036     4471308 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    7037     8942616 :   has_pending_exception = !i::Execution::Call(isolate, isolate->set_has(), self,
    7038     8942616 :                                               arraysize(argv), argv)
    7039             :                                .ToHandle(&result);
    7040     4471308 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7041             :   return Just(result->IsTrue(isolate));
    7042             : }
    7043             : 
    7044             : 
    7045          70 : Maybe<bool> Set::Delete(Local<Context> context, Local<Value> key) {
    7046             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7047         210 :   ENTER_V8(isolate, context, Set, Delete, Nothing<bool>(), i::HandleScope);
    7048             :   auto self = Utils::OpenHandle(this);
    7049             :   i::Handle<i::Object> result;
    7050          70 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    7051         140 :   has_pending_exception = !i::Execution::Call(isolate, isolate->set_delete(),
    7052         140 :                                               self, arraysize(argv), argv)
    7053             :                                .ToHandle(&result);
    7054          70 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7055             :   return Just(result->IsTrue(isolate));
    7056             : }
    7057             : 
    7058             : namespace {
    7059         656 : i::Handle<i::JSArray> SetAsArray(i::Isolate* isolate, i::Object table_obj,
    7060             :                                  int offset, SetAsArrayKind kind) {
    7061             :   i::Factory* factory = isolate->factory();
    7062             :   i::Handle<i::OrderedHashSet> table(i::OrderedHashSet::cast(table_obj),
    7063             :                                      isolate);
    7064             :   // Elements skipped by |offset| may already be deleted.
    7065         656 :   int capacity = table->UsedCapacity();
    7066             :   const bool collect_key_values = kind == SetAsArrayKind::kEntries;
    7067         656 :   int max_length = (capacity - offset) * (collect_key_values ? 2 : 1);
    7068         656 :   if (max_length == 0) return factory->NewJSArray(0);
    7069         642 :   i::Handle<i::FixedArray> result = factory->NewFixedArray(max_length);
    7070             :   int result_index = 0;
    7071             :   {
    7072             :     i::DisallowHeapAllocation no_gc;
    7073             :     i::Oddball the_hole = i::ReadOnlyRoots(isolate).the_hole_value();
    7074       27790 :     for (int i = offset; i < capacity; ++i) {
    7075       13574 :       i::Object key = table->KeyAt(i);
    7076       13639 :       if (key == the_hole) continue;
    7077       27018 :       result->set(result_index++, key);
    7078       13567 :       if (collect_key_values) result->set(result_index++, key);
    7079             :     }
    7080             :   }
    7081             :   DCHECK_GE(max_length, result_index);
    7082         642 :   if (result_index == 0) return factory->NewJSArray(0);
    7083         642 :   result->Shrink(isolate, result_index);
    7084             :   return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
    7085         642 :                                          result_index);
    7086             : }
    7087             : }  // namespace
    7088             : 
    7089         529 : Local<Array> Set::AsArray() const {
    7090             :   i::Handle<i::JSSet> obj = Utils::OpenHandle(this);
    7091             :   i::Isolate* isolate = obj->GetIsolate();
    7092         529 :   LOG_API(isolate, Set, AsArray);
    7093             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7094             :   return Utils::ToLocal(
    7095        1058 :       SetAsArray(isolate, obj->table(), 0, SetAsArrayKind::kValues));
    7096             : }
    7097             : 
    7098             : 
    7099        9328 : MaybeLocal<Promise::Resolver> Promise::Resolver::New(Local<Context> context) {
    7100       37312 :   PREPARE_FOR_EXECUTION(context, Promise_Resolver, New, Resolver);
    7101             :   Local<Promise::Resolver> result;
    7102             :   has_pending_exception =
    7103        9328 :       !ToLocal<Promise::Resolver>(isolate->factory()->NewJSPromise(), &result);
    7104        9328 :   RETURN_ON_FAILED_EXECUTION(Promise::Resolver);
    7105        9328 :   RETURN_ESCAPED(result);
    7106             : }
    7107             : 
    7108             : 
    7109        9323 : Local<Promise> Promise::Resolver::GetPromise() {
    7110             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7111        9323 :   return Local<Promise>::Cast(Utils::ToLocal(promise));
    7112             : }
    7113             : 
    7114             : 
    7115         940 : Maybe<bool> Promise::Resolver::Resolve(Local<Context> context,
    7116             :                                        Local<Value> value) {
    7117             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7118        2820 :   ENTER_V8(isolate, context, Promise_Resolver, Resolve, Nothing<bool>(),
    7119             :            i::HandleScope);
    7120             :   auto self = Utils::OpenHandle(this);
    7121             :   auto promise = i::Handle<i::JSPromise>::cast(self);
    7122             : 
    7123         940 :   if (promise->status() != Promise::kPending) {
    7124             :     return Just(true);
    7125             :   }
    7126             : 
    7127             :   has_pending_exception =
    7128        1860 :       i::JSPromise::Resolve(promise, Utils::OpenHandle(*value)).is_null();
    7129         930 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7130             :   return Just(true);
    7131             : }
    7132             : 
    7133             : 
    7134         281 : Maybe<bool> Promise::Resolver::Reject(Local<Context> context,
    7135             :                                       Local<Value> value) {
    7136             :   auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7137         843 :   ENTER_V8(isolate, context, Promise_Resolver, Reject, Nothing<bool>(),
    7138             :            i::HandleScope);
    7139             :   auto self = Utils::OpenHandle(this);
    7140             :   auto promise = i::Handle<i::JSPromise>::cast(self);
    7141             : 
    7142         281 :   if (promise->status() != Promise::kPending) {
    7143             :     return Just(true);
    7144             :   }
    7145             : 
    7146             :   has_pending_exception =
    7147         542 :       i::JSPromise::Reject(promise, Utils::OpenHandle(*value)).is_null();
    7148         271 :   RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
    7149             :   return Just(true);
    7150             : }
    7151             : 
    7152             : 
    7153         655 : MaybeLocal<Promise> Promise::Catch(Local<Context> context,
    7154             :                                    Local<Function> handler) {
    7155        2620 :   PREPARE_FOR_EXECUTION(context, Promise, Catch, Promise);
    7156             :   auto self = Utils::OpenHandle(this);
    7157             :   i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
    7158             :   i::Handle<i::Object> result;
    7159        1310 :   has_pending_exception = !i::Execution::Call(isolate, isolate->promise_catch(),
    7160        1310 :                                               self, arraysize(argv), argv)
    7161             :                                .ToHandle(&result);
    7162         655 :   RETURN_ON_FAILED_EXECUTION(Promise);
    7163         655 :   RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
    7164             : }
    7165             : 
    7166             : 
    7167         699 : MaybeLocal<Promise> Promise::Then(Local<Context> context,
    7168             :                                   Local<Function> handler) {
    7169        2796 :   PREPARE_FOR_EXECUTION(context, Promise, Then, Promise);
    7170             :   auto self = Utils::OpenHandle(this);
    7171             :   i::Handle<i::Object> argv[] = { Utils::OpenHandle(*handler) };
    7172             :   i::Handle<i::Object> result;
    7173        1398 :   has_pending_exception = !i::Execution::Call(isolate, isolate->promise_then(),
    7174        1398 :                                               self, arraysize(argv), argv)
    7175             :                                .ToHandle(&result);
    7176         699 :   RETURN_ON_FAILED_EXECUTION(Promise);
    7177         699 :   RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
    7178             : }
    7179             : 
    7180          35 : MaybeLocal<Promise> Promise::Then(Local<Context> context,
    7181             :                                   Local<Function> on_fulfilled,
    7182             :                                   Local<Function> on_rejected) {
    7183         140 :   PREPARE_FOR_EXECUTION(context, Promise, Then, Promise);
    7184             :   auto self = Utils::OpenHandle(this);
    7185             :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*on_fulfilled),
    7186             :                                  Utils::OpenHandle(*on_rejected)};
    7187             :   i::Handle<i::Object> result;
    7188          70 :   has_pending_exception = !i::Execution::Call(isolate, isolate->promise_then(),
    7189          70 :                                               self, arraysize(argv), argv)
    7190             :                                .ToHandle(&result);
    7191          35 :   RETURN_ON_FAILED_EXECUTION(Promise);
    7192          35 :   RETURN_ESCAPED(Local<Promise>::Cast(Utils::ToLocal(result)));
    7193             : }
    7194             : 
    7195         345 : bool Promise::HasHandler() {
    7196             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7197             :   i::Isolate* isolate = promise->GetIsolate();
    7198         345 :   LOG_API(isolate, Promise, HasRejectHandler);
    7199             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7200         345 :   if (promise->IsJSPromise()) {
    7201             :     i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
    7202             :     return js_promise->has_handler();
    7203             :   }
    7204             :   return false;
    7205             : }
    7206             : 
    7207          50 : Local<Value> Promise::Result() {
    7208             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7209             :   i::Isolate* isolate = promise->GetIsolate();
    7210          50 :   LOG_API(isolate, Promise, Result);
    7211             :   i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
    7212         100 :   Utils::ApiCheck(js_promise->status() != kPending, "v8_Promise_Result",
    7213             :                   "Promise is still pending");
    7214             :   i::Handle<i::Object> result(js_promise->result(), isolate);
    7215          50 :   return Utils::ToLocal(result);
    7216             : }
    7217             : 
    7218         289 : Promise::PromiseState Promise::State() {
    7219             :   i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
    7220             :   i::Isolate* isolate = promise->GetIsolate();
    7221         289 :   LOG_API(isolate, Promise, Status);
    7222             :   i::Handle<i::JSPromise> js_promise = i::Handle<i::JSPromise>::cast(promise);
    7223         578 :   return static_cast<PromiseState>(js_promise->status());
    7224             : }
    7225             : 
    7226           5 : void Promise::MarkAsHandled() {
    7227             :   i::Handle<i::JSPromise> js_promise = Utils::OpenHandle(this);
    7228           5 :   js_promise->set_has_handler(true);
    7229           5 : }
    7230             : 
    7231          35 : Local<Value> Proxy::GetTarget() {
    7232             :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7233             :   i::Handle<i::Object> target(self->target(), self->GetIsolate());
    7234          35 :   return Utils::ToLocal(target);
    7235             : }
    7236             : 
    7237             : 
    7238          10 : Local<Value> Proxy::GetHandler() {
    7239             :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7240             :   i::Handle<i::Object> handler(self->handler(), self->GetIsolate());
    7241          10 :   return Utils::ToLocal(handler);
    7242             : }
    7243             : 
    7244             : 
    7245          10 : bool Proxy::IsRevoked() {
    7246             :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7247          10 :   return self->IsRevoked();
    7248             : }
    7249             : 
    7250             : 
    7251           5 : void Proxy::Revoke() {
    7252           5 :   i::Handle<i::JSProxy> self = Utils::OpenHandle(this);
    7253           5 :   i::JSProxy::Revoke(self);
    7254           5 : }
    7255             : 
    7256             : 
    7257          17 : MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target,
    7258             :                              Local<Object> local_handler) {
    7259          68 :   PREPARE_FOR_EXECUTION(context, Proxy, New, Proxy);
    7260             :   i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target);
    7261             :   i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler);
    7262             :   Local<Proxy> result;
    7263             :   has_pending_exception =
    7264          34 :       !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
    7265          17 :   RETURN_ON_FAILED_EXECUTION(Proxy);
    7266          17 :   RETURN_ESCAPED(result);
    7267             : }
    7268             : 
    7269          48 : CompiledWasmModule::CompiledWasmModule(
    7270             :     std::shared_ptr<internal::wasm::NativeModule> native_module)
    7271             :     : native_module_(std::move(native_module)) {
    7272          48 :   CHECK_NOT_NULL(native_module_);
    7273          48 : }
    7274             : 
    7275          28 : OwnedBuffer CompiledWasmModule::Serialize() {
    7276          28 :   i::wasm::WasmSerializer wasm_serializer(native_module_.get());
    7277          28 :   size_t buffer_size = wasm_serializer.GetSerializedNativeModuleSize();
    7278          28 :   std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
    7279          28 :   if (!wasm_serializer.SerializeNativeModule({buffer.get(), buffer_size}))
    7280           0 :     return {};
    7281             :   return {std::move(buffer), buffer_size};
    7282             : }
    7283             : 
    7284          44 : MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() {
    7285             :   i::Vector<const uint8_t> bytes_vec = native_module_->wire_bytes();
    7286          44 :   return {bytes_vec.start(), bytes_vec.size()};
    7287             : }
    7288             : 
    7289             : WasmModuleObject::TransferrableModule
    7290         126 : WasmModuleObject::GetTransferrableModule() {
    7291         126 :   if (i::FLAG_wasm_shared_code) {
    7292             :     i::Handle<i::WasmModuleObject> obj =
    7293             :         i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
    7294         244 :     return TransferrableModule(obj->shared_native_module());
    7295             :   } else {
    7296           4 :     CompiledWasmModule compiled_module = GetCompiledModule();
    7297           4 :     OwnedBuffer serialized_module = compiled_module.Serialize();
    7298             :     MemorySpan<const uint8_t> wire_bytes_ref =
    7299             :         compiled_module.GetWireBytesRef();
    7300             :     size_t wire_size = wire_bytes_ref.size();
    7301           4 :     std::unique_ptr<uint8_t[]> wire_bytes_copy(new uint8_t[wire_size]);
    7302             :     memcpy(wire_bytes_copy.get(), wire_bytes_ref.data(), wire_size);
    7303             :     return TransferrableModule(std::move(serialized_module),
    7304             :                                {std::move(wire_bytes_copy), wire_size});
    7305             :   }
    7306             : }
    7307             : 
    7308          48 : CompiledWasmModule WasmModuleObject::GetCompiledModule() {
    7309             :   i::Handle<i::WasmModuleObject> obj =
    7310             :       i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
    7311          96 :   return Utils::Convert(obj->shared_native_module());
    7312             : }
    7313             : 
    7314         124 : MaybeLocal<WasmModuleObject> WasmModuleObject::FromTransferrableModule(
    7315             :     Isolate* isolate,
    7316             :     const WasmModuleObject::TransferrableModule& transferrable_module) {
    7317         124 :   if (i::FLAG_wasm_shared_code) {
    7318             :     i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7319             :     i::Handle<i::WasmModuleObject> module_object =
    7320             :         i_isolate->wasm_engine()->ImportNativeModule(
    7321         240 :             i_isolate, transferrable_module.shared_module_);
    7322             :     return Local<WasmModuleObject>::Cast(
    7323         120 :         Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
    7324             :   } else {
    7325             :     return Deserialize(isolate, AsReference(transferrable_module.serialized_),
    7326           4 :                        AsReference(transferrable_module.wire_bytes_));
    7327             :   }
    7328             : }
    7329             : 
    7330          81 : MaybeLocal<WasmModuleObject> WasmModuleObject::Deserialize(
    7331             :     Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
    7332             :     MemorySpan<const uint8_t> wire_bytes) {
    7333             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7334             :   i::MaybeHandle<i::WasmModuleObject> maybe_module_object =
    7335             :       i::wasm::DeserializeNativeModule(
    7336             :           i_isolate, {serialized_module.data(), serialized_module.size()},
    7337          81 :           {wire_bytes.data(), wire_bytes.size()});
    7338             :   i::Handle<i::WasmModuleObject> module_object;
    7339          81 :   if (!maybe_module_object.ToHandle(&module_object)) {
    7340          69 :     return MaybeLocal<WasmModuleObject>();
    7341             :   }
    7342             :   return Local<WasmModuleObject>::Cast(
    7343          12 :       Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
    7344             : }
    7345             : 
    7346          77 : MaybeLocal<WasmModuleObject> WasmModuleObject::DeserializeOrCompile(
    7347             :     Isolate* isolate, MemorySpan<const uint8_t> serialized_module,
    7348             :     MemorySpan<const uint8_t> wire_bytes) {
    7349             :   MaybeLocal<WasmModuleObject> ret =
    7350          77 :       Deserialize(isolate, serialized_module, wire_bytes);
    7351          77 :   if (!ret.IsEmpty()) {
    7352           8 :     return ret;
    7353             :   }
    7354          69 :   return Compile(isolate, wire_bytes.data(), wire_bytes.size());
    7355             : }
    7356             : 
    7357          69 : MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(Isolate* isolate,
    7358             :                                                        const uint8_t* start,
    7359             :                                                        size_t length) {
    7360             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7361         138 :   if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
    7362          20 :     return MaybeLocal<WasmModuleObject>();
    7363             :   }
    7364             :   i::MaybeHandle<i::JSObject> maybe_compiled;
    7365             :   {
    7366          49 :     i::wasm::ErrorThrower thrower(i_isolate, "WasmModuleObject::Compile()");
    7367          49 :     auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
    7368             :     maybe_compiled = i_isolate->wasm_engine()->SyncCompile(
    7369             :         i_isolate, enabled_features, &thrower,
    7370          49 :         i::wasm::ModuleWireBytes(start, start + length));
    7371             :   }
    7372          49 :   CHECK_EQ(maybe_compiled.is_null(), i_isolate->has_pending_exception());
    7373          49 :   if (maybe_compiled.is_null()) {
    7374           9 :     i_isolate->OptionalRescheduleException(false);
    7375           9 :     return MaybeLocal<WasmModuleObject>();
    7376             :   }
    7377             :   return Local<WasmModuleObject>::Cast(
    7378          40 :       Utils::ToLocal(maybe_compiled.ToHandleChecked()));
    7379             : }
    7380             : 
    7381             : // Resolves the result of streaming compilation.
    7382             : // TODO(ahaas): Refactor the streaming compilation API so that this class can
    7383             : // move to wasm-js.cc.
    7384             : class AsyncCompilationResolver : public i::wasm::CompilationResultResolver {
    7385             :  public:
    7386             :   AsyncCompilationResolver(Isolate* isolate, Local<Promise> promise)
    7387             :       : promise_(
    7388             :             reinterpret_cast<i::Isolate*>(isolate)->global_handles()->Create(
    7389             :                 *Utils::OpenHandle(*promise))) {}
    7390             : 
    7391             :   ~AsyncCompilationResolver() override {
    7392             :     i::GlobalHandles::Destroy(promise_.location());
    7393             :   }
    7394             : 
    7395             :   void OnCompilationSucceeded(i::Handle<i::WasmModuleObject> result) override {
    7396             :     i::MaybeHandle<i::Object> promise_result =
    7397             :         i::JSPromise::Resolve(promise_, result);
    7398             :     CHECK_EQ(promise_result.is_null(),
    7399             :              promise_->GetIsolate()->has_pending_exception());
    7400             :   }
    7401             : 
    7402             :   void OnCompilationFailed(i::Handle<i::Object> error_reason) override {
    7403             :     i::MaybeHandle<i::Object> promise_result =
    7404             :         i::JSPromise::Reject(promise_, error_reason);
    7405             :     CHECK_EQ(promise_result.is_null(),
    7406             :              promise_->GetIsolate()->has_pending_exception());
    7407             :   }
    7408             : 
    7409             :  private:
    7410             :   i::Handle<i::JSPromise> promise_;
    7411             : };
    7412             : 
    7413           0 : WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming(
    7414           0 :     Isolate* isolate) {
    7415             :   USE(isolate_);
    7416           0 : }
    7417             : 
    7418           0 : Local<Promise> WasmModuleObjectBuilderStreaming::GetPromise() { return {}; }
    7419             : 
    7420           0 : void WasmModuleObjectBuilderStreaming::OnBytesReceived(const uint8_t* bytes,
    7421             :                                                        size_t size) {
    7422           0 : }
    7423             : 
    7424           0 : void WasmModuleObjectBuilderStreaming::Finish() {
    7425           0 : }
    7426             : 
    7427           0 : void WasmModuleObjectBuilderStreaming::Abort(MaybeLocal<Value> exception) {
    7428           0 : }
    7429             : 
    7430             : // static
    7431      119024 : v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() {
    7432      238048 :   return new ArrayBufferAllocator();
    7433             : }
    7434             : 
    7435          89 : bool v8::ArrayBuffer::IsExternal() const {
    7436          89 :   return Utils::OpenHandle(this)->is_external();
    7437             : }
    7438             : 
    7439          56 : bool v8::ArrayBuffer::IsDetachable() const {
    7440          56 :   return Utils::OpenHandle(this)->is_detachable();
    7441             : }
    7442             : 
    7443          89 : v8::ArrayBuffer::Contents v8::ArrayBuffer::Externalize() {
    7444             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7445             :   i::Isolate* isolate = self->GetIsolate();
    7446             :   Utils::ApiCheck(!self->is_external(), "v8_ArrayBuffer_Externalize",
    7447             :                   "ArrayBuffer already externalized");
    7448             :   self->set_is_external(true);
    7449             : 
    7450          89 :   const v8::ArrayBuffer::Contents contents = GetContents();
    7451          89 :   isolate->heap()->UnregisterArrayBuffer(*self);
    7452             : 
    7453             :   // A regular copy is good enough. No move semantics needed.
    7454          89 :   return contents;
    7455             : }
    7456             : 
    7457           0 : v8::ArrayBuffer::Contents::Contents(void* data, size_t byte_length,
    7458             :                                     void* allocation_base,
    7459             :                                     size_t allocation_length,
    7460             :                                     Allocator::AllocationMode allocation_mode,
    7461             :                                     DeleterCallback deleter, void* deleter_data)
    7462             :     : data_(data),
    7463             :       byte_length_(byte_length),
    7464             :       allocation_base_(allocation_base),
    7465             :       allocation_length_(allocation_length),
    7466             :       allocation_mode_(allocation_mode),
    7467             :       deleter_(deleter),
    7468      282353 :       deleter_data_(deleter_data) {
    7469             :   DCHECK_LE(allocation_base_, data_);
    7470             :   DCHECK_LE(byte_length_, allocation_length_);
    7471           0 : }
    7472             : 
    7473          89 : void WasmMemoryDeleter(void* buffer, size_t lenght, void* info) {
    7474             :   internal::wasm::WasmEngine* engine =
    7475             :       reinterpret_cast<internal::wasm::WasmEngine*>(info);
    7476          89 :   CHECK(engine->memory_tracker()->FreeMemoryIfIsWasmMemory(nullptr, buffer));
    7477          89 : }
    7478             : 
    7479          99 : void ArrayBufferDeleter(void* buffer, size_t length, void* info) {
    7480             :   v8::ArrayBuffer::Allocator* allocator =
    7481             :       reinterpret_cast<v8::ArrayBuffer::Allocator*>(info);
    7482          99 :   allocator->Free(buffer, length);
    7483          99 : }
    7484             : 
    7485      282350 : v8::ArrayBuffer::Contents v8::ArrayBuffer::GetContents() {
    7486             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7487             :   Contents contents(
    7488             :       self->backing_store(), self->byte_length(), self->allocation_base(),
    7489             :       self->allocation_length(),
    7490             :       self->is_wasm_memory() ? Allocator::AllocationMode::kReservation
    7491             :                              : Allocator::AllocationMode::kNormal,
    7492             :       self->is_wasm_memory() ? WasmMemoryDeleter : ArrayBufferDeleter,
    7493             :       self->is_wasm_memory()
    7494             :           ? static_cast<void*>(self->GetIsolate()->wasm_engine())
    7495     1129406 :           : static_cast<void*>(self->GetIsolate()->array_buffer_allocator()));
    7496      282353 :   return contents;
    7497             : }
    7498             : 
    7499          43 : void v8::ArrayBuffer::Detach() {
    7500             :   i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
    7501             :   i::Isolate* isolate = obj->GetIsolate();
    7502             :   Utils::ApiCheck(obj->is_external(), "v8::ArrayBuffer::Detach",
    7503             :                   "Only externalized ArrayBuffers can be detached");
    7504             :   Utils::ApiCheck(obj->is_detachable(), "v8::ArrayBuffer::Detach",
    7505             :                   "Only detachable ArrayBuffers can be detached");
    7506          43 :   LOG_API(isolate, ArrayBuffer, Detach);
    7507             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7508          43 :   obj->Detach();
    7509          43 : }
    7510             : 
    7511         243 : size_t v8::ArrayBuffer::ByteLength() const {
    7512             :   i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
    7513         243 :   return obj->byte_length();
    7514             : }
    7515             : 
    7516             : 
    7517         200 : Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, size_t byte_length) {
    7518             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7519         200 :   LOG_API(i_isolate, ArrayBuffer, New);
    7520             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7521             :   i::Handle<i::JSArrayBuffer> obj =
    7522         200 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
    7523             :   // TODO(jbroman): It may be useful in the future to provide a MaybeLocal
    7524             :   // version that throws an exception or otherwise does not crash.
    7525         200 :   if (!i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length)) {
    7526           0 :     i::FatalProcessOutOfMemory(i_isolate, "v8::ArrayBuffer::New");
    7527             :   }
    7528         200 :   return Utils::ToLocal(obj);
    7529             : }
    7530             : 
    7531             : 
    7532         140 : Local<ArrayBuffer> v8::ArrayBuffer::New(Isolate* isolate, void* data,
    7533             :                                         size_t byte_length,
    7534             :                                         ArrayBufferCreationMode mode) {
    7535             :   // Embedders must guarantee that the external backing store is valid.
    7536         140 :   CHECK(byte_length == 0 || data != nullptr);
    7537         140 :   CHECK_LE(byte_length, i::JSArrayBuffer::kMaxByteLength);
    7538             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7539         140 :   LOG_API(i_isolate, ArrayBuffer, New);
    7540             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7541             :   i::Handle<i::JSArrayBuffer> obj =
    7542         140 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
    7543         140 :   i::JSArrayBuffer::Setup(obj, i_isolate,
    7544             :                           mode == ArrayBufferCreationMode::kExternalized, data,
    7545         140 :                           byte_length);
    7546         140 :   return Utils::ToLocal(obj);
    7547             : }
    7548             : 
    7549             : 
    7550       27556 : Local<ArrayBuffer> v8::ArrayBufferView::Buffer() {
    7551             :   i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
    7552             :   i::Handle<i::JSArrayBuffer> buffer;
    7553       27556 :   if (obj->IsJSDataView()) {
    7554             :     i::Handle<i::JSDataView> data_view(i::JSDataView::cast(*obj),
    7555             :                                        obj->GetIsolate());
    7556             :     DCHECK(data_view->buffer()->IsJSArrayBuffer());
    7557             :     buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer()),
    7558             :                        data_view->GetIsolate());
    7559             :   } else {
    7560             :     DCHECK(obj->IsJSTypedArray());
    7561       27542 :     buffer = i::JSTypedArray::cast(*obj)->GetBuffer();
    7562             :   }
    7563       27561 :   return Utils::ToLocal(buffer);
    7564             : }
    7565             : 
    7566             : 
    7567          15 : size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) {
    7568             :   i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this);
    7569             :   size_t byte_offset = self->byte_offset();
    7570             :   size_t bytes_to_copy = i::Min(byte_length, self->byte_length());
    7571          15 :   if (bytes_to_copy) {
    7572             :     i::DisallowHeapAllocation no_gc;
    7573             :     i::Isolate* isolate = self->GetIsolate();
    7574             :     i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(self->buffer()),
    7575             :                                        isolate);
    7576             :     const char* source = reinterpret_cast<char*>(buffer->backing_store());
    7577          15 :     if (source == nullptr) {
    7578             :       DCHECK(self->IsJSTypedArray());
    7579             :       i::Handle<i::JSTypedArray> typed_array(i::JSTypedArray::cast(*self),
    7580             :                                              isolate);
    7581             :       i::Handle<i::FixedTypedArrayBase> fixed_array(
    7582             :           i::FixedTypedArrayBase::cast(typed_array->elements()), isolate);
    7583             :       source = reinterpret_cast<char*>(fixed_array->DataPtr());
    7584             :     }
    7585          15 :     memcpy(dest, source + byte_offset, bytes_to_copy);
    7586             :   }
    7587          15 :   return bytes_to_copy;
    7588             : }
    7589             : 
    7590             : 
    7591          30 : bool v8::ArrayBufferView::HasBuffer() const {
    7592             :   i::Handle<i::JSArrayBufferView> self = Utils::OpenHandle(this);
    7593             :   i::Handle<i::JSArrayBuffer> buffer(i::JSArrayBuffer::cast(self->buffer()),
    7594             :                                      self->GetIsolate());
    7595          30 :   return buffer->backing_store() != nullptr;
    7596             : }
    7597             : 
    7598             : 
    7599       27735 : size_t v8::ArrayBufferView::ByteOffset() {
    7600             :   i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
    7601       55470 :   return obj->WasDetached() ? 0 : obj->byte_offset();
    7602             : }
    7603             : 
    7604             : 
    7605       27819 : size_t v8::ArrayBufferView::ByteLength() {
    7606             :   i::Handle<i::JSArrayBufferView> obj = Utils::OpenHandle(this);
    7607       55638 :   return obj->WasDetached() ? 0 : obj->byte_length();
    7608             : }
    7609             : 
    7610             : 
    7611         528 : size_t v8::TypedArray::Length() {
    7612             :   i::Handle<i::JSTypedArray> obj = Utils::OpenHandle(this);
    7613        1056 :   return obj->WasDetached() ? 0 : obj->length_value();
    7614             : }
    7615             : 
    7616             : static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue,
    7617             :               "v8::TypedArray::kMaxLength must match i::Smi::kMaxValue");
    7618             : 
    7619             : #define TYPED_ARRAY_NEW(Type, type, TYPE, ctype)                           \
    7620             :   Local<Type##Array> Type##Array::New(Local<ArrayBuffer> array_buffer,     \
    7621             :                                       size_t byte_offset, size_t length) { \
    7622             :     i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate();  \
    7623             :     LOG_API(isolate, Type##Array, New);                                    \
    7624             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);                              \
    7625             :     if (!Utils::ApiCheck(length <= kMaxLength,                             \
    7626             :                          "v8::" #Type                                      \
    7627             :                          "Array::New(Local<ArrayBuffer>, size_t, size_t)", \
    7628             :                          "length exceeds max allowed value")) {            \
    7629             :       return Local<Type##Array>();                                         \
    7630             :     }                                                                      \
    7631             :     i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \
    7632             :     i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray(  \
    7633             :         i::kExternal##Type##Array, buffer, byte_offset, length);           \
    7634             :     return Utils::ToLocal##Type##Array(obj);                               \
    7635             :   }                                                                        \
    7636             :   Local<Type##Array> Type##Array::New(                                     \
    7637             :       Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,    \
    7638             :       size_t length) {                                                     \
    7639             :     CHECK(i::FLAG_harmony_sharedarraybuffer);                              \
    7640             :     i::Isolate* isolate =                                                  \
    7641             :         Utils::OpenHandle(*shared_array_buffer)->GetIsolate();             \
    7642             :     LOG_API(isolate, Type##Array, New);                                    \
    7643             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);                              \
    7644             :     if (!Utils::ApiCheck(                                                  \
    7645             :             length <= kMaxLength,                                          \
    7646             :             "v8::" #Type                                                   \
    7647             :             "Array::New(Local<SharedArrayBuffer>, size_t, size_t)",        \
    7648             :             "length exceeds max allowed value")) {                         \
    7649             :       return Local<Type##Array>();                                         \
    7650             :     }                                                                      \
    7651             :     i::Handle<i::JSArrayBuffer> buffer =                                   \
    7652             :         Utils::OpenHandle(*shared_array_buffer);                           \
    7653             :     i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray(  \
    7654             :         i::kExternal##Type##Array, buffer, byte_offset, length);           \
    7655             :     return Utils::ToLocal##Type##Array(obj);                               \
    7656             :   }
    7657             : 
    7658         930 : TYPED_ARRAYS(TYPED_ARRAY_NEW)
    7659             : #undef TYPED_ARRAY_NEW
    7660             : 
    7661          17 : Local<DataView> DataView::New(Local<ArrayBuffer> array_buffer,
    7662             :                               size_t byte_offset, size_t byte_length) {
    7663             :   i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
    7664             :   i::Isolate* isolate = buffer->GetIsolate();
    7665          17 :   LOG_API(isolate, DataView, New);
    7666             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7667             :   i::Handle<i::JSDataView> obj =
    7668          17 :       isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
    7669          17 :   return Utils::ToLocal(obj);
    7670             : }
    7671             : 
    7672             : 
    7673           6 : Local<DataView> DataView::New(Local<SharedArrayBuffer> shared_array_buffer,
    7674             :                               size_t byte_offset, size_t byte_length) {
    7675           6 :   CHECK(i::FLAG_harmony_sharedarraybuffer);
    7676             :   i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*shared_array_buffer);
    7677             :   i::Isolate* isolate = buffer->GetIsolate();
    7678           6 :   LOG_API(isolate, DataView, New);
    7679             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    7680             :   i::Handle<i::JSDataView> obj =
    7681           6 :       isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
    7682           6 :   return Utils::ToLocal(obj);
    7683             : }
    7684             : 
    7685             : namespace {
    7686         483 : i::Handle<i::JSArrayBuffer> SetupSharedArrayBuffer(
    7687             :     Isolate* isolate, void* data, size_t byte_length,
    7688             :     ArrayBufferCreationMode mode) {
    7689         483 :   CHECK(i::FLAG_harmony_sharedarraybuffer);
    7690             :   // Embedders must guarantee that the external backing store is valid.
    7691         483 :   CHECK(byte_length == 0 || data != nullptr);
    7692             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7693         483 :   LOG_API(i_isolate, SharedArrayBuffer, New);
    7694             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7695             :   i::Handle<i::JSArrayBuffer> obj =
    7696         483 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
    7697             :   bool is_wasm_memory =
    7698         483 :       i_isolate->wasm_engine()->memory_tracker()->IsWasmMemory(data);
    7699         483 :   i::JSArrayBuffer::Setup(obj, i_isolate,
    7700             :                           mode == ArrayBufferCreationMode::kExternalized, data,
    7701         483 :                           byte_length, i::SharedFlag::kShared, is_wasm_memory);
    7702         966 :   return obj;
    7703             : }
    7704             : 
    7705             : }  // namespace
    7706             : 
    7707         443 : bool v8::SharedArrayBuffer::IsExternal() const {
    7708         443 :   return Utils::OpenHandle(this)->is_external();
    7709             : }
    7710             : 
    7711         197 : v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::Externalize() {
    7712             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7713             :   i::Isolate* isolate = self->GetIsolate();
    7714             :   Utils::ApiCheck(!self->is_external(), "v8_SharedArrayBuffer_Externalize",
    7715             :                   "SharedArrayBuffer already externalized");
    7716             :   self->set_is_external(true);
    7717             : 
    7718         197 :   const v8::SharedArrayBuffer::Contents contents = GetContents();
    7719         197 :   isolate->heap()->UnregisterArrayBuffer(*self);
    7720             : 
    7721             :   // A regular copy is good enough. No move semantics needed.
    7722         197 :   return contents;
    7723             : }
    7724             : 
    7725           0 : v8::SharedArrayBuffer::Contents::Contents(
    7726             :     void* data, size_t byte_length, void* allocation_base,
    7727             :     size_t allocation_length, Allocator::AllocationMode allocation_mode,
    7728             :     DeleterCallback deleter, void* deleter_data, bool is_growable)
    7729             :     : data_(data),
    7730             :       byte_length_(byte_length),
    7731             :       allocation_base_(allocation_base),
    7732             :       allocation_length_(allocation_length),
    7733             :       allocation_mode_(allocation_mode),
    7734             :       deleter_(deleter),
    7735             :       deleter_data_(deleter_data),
    7736         431 :       is_growable_(is_growable) {
    7737             :   DCHECK_LE(allocation_base_, data_);
    7738             :   DCHECK_LE(byte_length_, allocation_length_);
    7739           0 : }
    7740             : 
    7741         431 : v8::SharedArrayBuffer::Contents v8::SharedArrayBuffer::GetContents() {
    7742             :   i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle(this);
    7743             :   Contents contents(
    7744             :       self->backing_store(), self->byte_length(), self->allocation_base(),
    7745             :       self->allocation_length(),
    7746             :       self->is_wasm_memory()
    7747             :           ? ArrayBuffer::Allocator::AllocationMode::kReservation
    7748             :           : ArrayBuffer::Allocator::AllocationMode::kNormal,
    7749             :       self->is_wasm_memory()
    7750             :           ? reinterpret_cast<Contents::DeleterCallback>(WasmMemoryDeleter)
    7751             :           : reinterpret_cast<Contents::DeleterCallback>(ArrayBufferDeleter),
    7752             :       self->is_wasm_memory()
    7753             :           ? static_cast<void*>(self->GetIsolate()->wasm_engine())
    7754             :           : static_cast<void*>(self->GetIsolate()->array_buffer_allocator()),
    7755        1724 :       self->is_growable());
    7756         431 :   return contents;
    7757             : }
    7758             : 
    7759          38 : size_t v8::SharedArrayBuffer::ByteLength() const {
    7760             :   i::Handle<i::JSArrayBuffer> obj = Utils::OpenHandle(this);
    7761          38 :   return obj->byte_length();
    7762             : }
    7763             : 
    7764          12 : Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate,
    7765             :                                                     size_t byte_length) {
    7766          12 :   CHECK(i::FLAG_harmony_sharedarraybuffer);
    7767             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7768          12 :   LOG_API(i_isolate, SharedArrayBuffer, New);
    7769             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7770             :   i::Handle<i::JSArrayBuffer> obj =
    7771          12 :       i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
    7772             :   // TODO(jbroman): It may be useful in the future to provide a MaybeLocal
    7773             :   // version that throws an exception or otherwise does not crash.
    7774          12 :   if (!i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length, true,
    7775             :                                              i::SharedFlag::kShared)) {
    7776           0 :     i::FatalProcessOutOfMemory(i_isolate, "v8::SharedArrayBuffer::New");
    7777             :   }
    7778          12 :   return Utils::ToLocalShared(obj);
    7779             : }
    7780             : 
    7781             : 
    7782          70 : Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
    7783             :     Isolate* isolate, void* data, size_t byte_length,
    7784             :     ArrayBufferCreationMode mode) {
    7785             :   i::Handle<i::JSArrayBuffer> buffer =
    7786          70 :       SetupSharedArrayBuffer(isolate, data, byte_length, mode);
    7787          70 :   return Utils::ToLocalShared(buffer);
    7788             : }
    7789             : 
    7790         413 : Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
    7791             :     Isolate* isolate, const SharedArrayBuffer::Contents& contents,
    7792             :     ArrayBufferCreationMode mode) {
    7793             :   i::Handle<i::JSArrayBuffer> buffer = SetupSharedArrayBuffer(
    7794         413 :       isolate, contents.Data(), contents.ByteLength(), mode);
    7795             :   buffer->set_is_growable(contents.IsGrowable());
    7796         413 :   return Utils::ToLocalShared(buffer);
    7797             : }
    7798             : 
    7799         125 : Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
    7800             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7801         125 :   LOG_API(i_isolate, Symbol, New);
    7802             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7803         125 :   i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
    7804         207 :   if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
    7805         125 :   return Utils::ToLocal(result);
    7806             : }
    7807             : 
    7808             : 
    7809          24 : Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) {
    7810             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7811          24 :   i::Handle<i::String> i_name = Utils::OpenHandle(*name);
    7812             :   return Utils::ToLocal(
    7813          24 :       i_isolate->SymbolFor(i::RootIndex::kPublicSymbolTable, i_name, false));
    7814             : }
    7815             : 
    7816             : 
    7817          24 : Local<Symbol> v8::Symbol::ForApi(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::kApiSymbolTable, i_name, false));
    7822             : }
    7823             : 
    7824             : #define WELL_KNOWN_SYMBOLS(V)                 \
    7825             :   V(AsyncIterator, async_iterator)            \
    7826             :   V(HasInstance, has_instance)                \
    7827             :   V(IsConcatSpreadable, is_concat_spreadable) \
    7828             :   V(Iterator, iterator)                       \
    7829             :   V(Match, match)                             \
    7830             :   V(Replace, replace)                         \
    7831             :   V(Search, search)                           \
    7832             :   V(Split, split)                             \
    7833             :   V(ToPrimitive, to_primitive)                \
    7834             :   V(ToStringTag, to_string_tag)               \
    7835             :   V(Unscopables, unscopables)
    7836             : 
    7837             : #define SYMBOL_GETTER(Name, name)                                   \
    7838             :   Local<Symbol> v8::Symbol::Get##Name(Isolate* isolate) {           \
    7839             :     i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); \
    7840             :     return Utils::ToLocal(i_isolate->factory()->name##_symbol());   \
    7841             :   }
    7842             : 
    7843      105584 : WELL_KNOWN_SYMBOLS(SYMBOL_GETTER)
    7844             : 
    7845             : #undef SYMBOL_GETTER
    7846             : #undef WELL_KNOWN_SYMBOLS
    7847             : 
    7848         153 : Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
    7849             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7850         153 :   LOG_API(i_isolate, Private, New);
    7851             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    7852         153 :   i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
    7853         235 :   if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
    7854             :   Local<Symbol> result = Utils::ToLocal(symbol);
    7855         306 :   return v8::Local<Private>(reinterpret_cast<Private*>(*result));
    7856             : }
    7857             : 
    7858             : 
    7859      254819 : Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) {
    7860             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7861      254819 :   i::Handle<i::String> i_name = Utils::OpenHandle(*name);
    7862             :   Local<Symbol> result = Utils::ToLocal(
    7863      254819 :       i_isolate->SymbolFor(i::RootIndex::kApiPrivateSymbolTable, i_name, true));
    7864      254819 :   return v8::Local<Private>(reinterpret_cast<Private*>(*result));
    7865             : }
    7866             : 
    7867             : 
    7868      100658 : Local<Number> v8::Number::New(Isolate* isolate, double value) {
    7869             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7870      100658 :   if (std::isnan(value)) {
    7871             :     // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
    7872             :     value = std::numeric_limits<double>::quiet_NaN();
    7873             :   }
    7874             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7875      100658 :   i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
    7876      100658 :   return Utils::NumberToLocal(result);
    7877             : }
    7878             : 
    7879             : 
    7880      786984 : Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
    7881             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7882      786984 :   if (i::Smi::IsValid(value)) {
    7883             :     return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
    7884             :                                                       internal_isolate));
    7885             :   }
    7886             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7887         718 :   i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
    7888             :   return Utils::IntegerToLocal(result);
    7889             : }
    7890             : 
    7891             : 
    7892         285 : Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
    7893             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7894         285 :   bool fits_into_int32_t = (value & (1 << 31)) == 0;
    7895         285 :   if (fits_into_int32_t) {
    7896         200 :     return Integer::New(isolate, static_cast<int32_t>(value));
    7897             :   }
    7898             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7899          85 :   i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
    7900             :   return Utils::IntegerToLocal(result);
    7901             : }
    7902             : 
    7903          81 : Local<BigInt> v8::BigInt::New(Isolate* isolate, int64_t value) {
    7904             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7905             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7906          81 :   i::Handle<i::BigInt> result = i::BigInt::FromInt64(internal_isolate, value);
    7907          81 :   return Utils::ToLocal(result);
    7908             : }
    7909             : 
    7910           0 : Local<BigInt> v8::BigInt::NewFromUnsigned(Isolate* isolate, uint64_t value) {
    7911             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    7912             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
    7913           0 :   i::Handle<i::BigInt> result = i::BigInt::FromUint64(internal_isolate, value);
    7914           0 :   return Utils::ToLocal(result);
    7915             : }
    7916             : 
    7917          30 : MaybeLocal<BigInt> v8::BigInt::NewFromWords(Local<Context> context,
    7918             :                                             int sign_bit, int word_count,
    7919             :                                             const uint64_t* words) {
    7920             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
    7921          90 :   ENTER_V8_NO_SCRIPT(isolate, context, BigInt, NewFromWords,
    7922             :                      MaybeLocal<BigInt>(), InternalEscapableScope);
    7923             :   i::MaybeHandle<i::BigInt> result =
    7924          30 :       i::BigInt::FromWords64(isolate, sign_bit, word_count, words);
    7925             :   has_pending_exception = result.is_null();
    7926          30 :   RETURN_ON_FAILED_EXECUTION(BigInt);
    7927          15 :   RETURN_ESCAPED(Utils::ToLocal(result.ToHandleChecked()));
    7928             : }
    7929             : 
    7930          55 : uint64_t v8::BigInt::Uint64Value(bool* lossless) const {
    7931             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7932          55 :   return handle->AsUint64(lossless);
    7933             : }
    7934             : 
    7935          90 : int64_t v8::BigInt::Int64Value(bool* lossless) const {
    7936             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7937          90 :   return handle->AsInt64(lossless);
    7938             : }
    7939             : 
    7940          15 : int BigInt::WordCount() const {
    7941             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7942          15 :   return handle->Words64Count();
    7943             : }
    7944             : 
    7945          10 : void BigInt::ToWordsArray(int* sign_bit, int* word_count,
    7946             :                           uint64_t* words) const {
    7947             :   i::Handle<i::BigInt> handle = Utils::OpenHandle(this);
    7948          10 :   return handle->ToWordsArray64(sign_bit, word_count, words);
    7949             : }
    7950             : 
    7951      979796 : void Isolate::ReportExternalAllocationLimitReached() {
    7952             :   i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
    7953      979796 :   if (heap->gc_state() != i::Heap::NOT_IN_GC) return;
    7954      979796 :   heap->ReportExternalMemoryPressure();
    7955             : }
    7956             : 
    7957     1607920 : void Isolate::CheckMemoryPressure() {
    7958             :   i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
    7959     1607920 :   if (heap->gc_state() != i::Heap::NOT_IN_GC) return;
    7960     1607920 :   heap->CheckMemoryPressure();
    7961             : }
    7962             : 
    7963        8186 : HeapProfiler* Isolate::GetHeapProfiler() {
    7964             :   i::HeapProfiler* heap_profiler =
    7965             :       reinterpret_cast<i::Isolate*>(this)->heap_profiler();
    7966        8186 :   return reinterpret_cast<HeapProfiler*>(heap_profiler);
    7967             : }
    7968             : 
    7969           0 : void Isolate::SetIdle(bool is_idle) {
    7970             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7971           0 :   isolate->SetIdle(is_idle);
    7972           0 : }
    7973             : 
    7974           5 : ArrayBuffer::Allocator* Isolate::GetArrayBufferAllocator() {
    7975             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7976           5 :   return isolate->array_buffer_allocator();
    7977             : }
    7978             : 
    7979       84314 : bool Isolate::InContext() {
    7980             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7981       84314 :   return !isolate->context().is_null();
    7982             : }
    7983             : 
    7984             : 
    7985    13099411 : v8::Local<v8::Context> Isolate::GetCurrentContext() {
    7986             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7987    13099411 :   i::Context context = isolate->context();
    7988    13099411 :   if (context.is_null()) return Local<Context>();
    7989    13099373 :   i::Context native_context = context->native_context();
    7990    13099378 :   if (native_context.is_null()) return Local<Context>();
    7991             :   return Utils::ToLocal(i::Handle<i::Context>(native_context, isolate));
    7992             : }
    7993             : 
    7994             : 
    7995           0 : v8::Local<v8::Context> Isolate::GetEnteredContext() {
    7996             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    7997             :   i::Handle<i::Object> last =
    7998           0 :       isolate->handle_scope_implementer()->LastEnteredContext();
    7999           0 :   if (last.is_null()) return Local<Context>();
    8000             :   return Utils::ToLocal(i::Handle<i::Context>::cast(last));
    8001             : }
    8002             : 
    8003       53049 : v8::Local<v8::Context> Isolate::GetEnteredOrMicrotaskContext() {
    8004             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8005             :   i::Handle<i::Object> last =
    8006       53049 :       isolate->handle_scope_implementer()->LastEnteredOrMicrotaskContext();
    8007       53049 :   if (last.is_null()) return Local<Context>();
    8008             :   DCHECK(last->IsNativeContext());
    8009             :   return Utils::ToLocal(i::Handle<i::Context>::cast(last));
    8010             : }
    8011             : 
    8012           4 : v8::Local<v8::Context> Isolate::GetIncumbentContext() {
    8013             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8014           4 :   i::Handle<i::Context> context = isolate->GetIncumbentContext();
    8015           4 :   return Utils::ToLocal(context);
    8016             : }
    8017             : 
    8018        5198 : v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) {
    8019             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8020             :   ENTER_V8_DO_NOT_USE(isolate);
    8021             :   // If we're passed an empty handle, we throw an undefined exception
    8022             :   // to deal more gracefully with out of memory situations.
    8023        5198 :   if (value.IsEmpty()) {
    8024          24 :     isolate->ScheduleThrow(i::ReadOnlyRoots(isolate).undefined_value());
    8025             :   } else {
    8026        5174 :     isolate->ScheduleThrow(*Utils::OpenHandle(*value));
    8027             :   }
    8028       10396 :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
    8029             : }
    8030             : 
    8031          10 : void Isolate::AddGCPrologueCallback(GCCallbackWithData callback, void* data,
    8032             :                                     GCType gc_type) {
    8033             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8034          35 :   isolate->heap()->AddGCPrologueCallback(callback, gc_type, data);
    8035          10 : }
    8036             : 
    8037          10 : void Isolate::RemoveGCPrologueCallback(GCCallbackWithData callback,
    8038             :                                        void* data) {
    8039             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8040          35 :   isolate->heap()->RemoveGCPrologueCallback(callback, data);
    8041          10 : }
    8042             : 
    8043          10 : void Isolate::AddGCEpilogueCallback(GCCallbackWithData callback, void* data,
    8044             :                                     GCType gc_type) {
    8045             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8046          35 :   isolate->heap()->AddGCEpilogueCallback(callback, gc_type, data);
    8047          10 : }
    8048             : 
    8049          10 : void Isolate::RemoveGCEpilogueCallback(GCCallbackWithData callback,
    8050             :                                        void* data) {
    8051             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8052          35 :   isolate->heap()->RemoveGCEpilogueCallback(callback, data);
    8053          10 : }
    8054             : 
    8055          90 : static void CallGCCallbackWithoutData(Isolate* isolate, GCType type,
    8056             :                                       GCCallbackFlags flags, void* data) {
    8057          90 :   reinterpret_cast<Isolate::GCCallback>(data)(isolate, type, flags);
    8058          90 : }
    8059             : 
    8060          25 : void Isolate::AddGCPrologueCallback(GCCallback callback, GCType gc_type) {
    8061             :   void* data = reinterpret_cast<void*>(callback);
    8062             :   AddGCPrologueCallback(CallGCCallbackWithoutData, data, gc_type);
    8063          25 : }
    8064             : 
    8065          25 : void Isolate::RemoveGCPrologueCallback(GCCallback callback) {
    8066             :   void* data = reinterpret_cast<void*>(callback);
    8067             :   RemoveGCPrologueCallback(CallGCCallbackWithoutData, data);
    8068          25 : }
    8069             : 
    8070          25 : void Isolate::AddGCEpilogueCallback(GCCallback callback, GCType gc_type) {
    8071             :   void* data = reinterpret_cast<void*>(callback);
    8072             :   AddGCEpilogueCallback(CallGCCallbackWithoutData, data, gc_type);
    8073          25 : }
    8074             : 
    8075          25 : void Isolate::RemoveGCEpilogueCallback(GCCallback callback) {
    8076             :   void* data = reinterpret_cast<void*>(callback);
    8077             :   RemoveGCEpilogueCallback(CallGCCallbackWithoutData, data);
    8078          25 : }
    8079             : 
    8080         150 : void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
    8081             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8082         150 :   isolate->heap()->SetEmbedderHeapTracer(tracer);
    8083         150 : }
    8084             : 
    8085           0 : EmbedderHeapTracer* Isolate::GetEmbedderHeapTracer() {
    8086             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8087           0 :   return isolate->heap()->GetEmbedderHeapTracer();
    8088             : }
    8089             : 
    8090           0 : void Isolate::SetGetExternallyAllocatedMemoryInBytesCallback(
    8091             :     GetExternallyAllocatedMemoryInBytesCallback callback) {
    8092             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8093             :   isolate->heap()->SetGetExternallyAllocatedMemoryInBytesCallback(callback);
    8094           0 : }
    8095             : 
    8096        1291 : void Isolate::TerminateExecution() {
    8097             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8098             :   isolate->stack_guard()->RequestTerminateExecution();
    8099        1291 : }
    8100             : 
    8101             : 
    8102        1530 : bool Isolate::IsExecutionTerminating() {
    8103             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8104        1530 :   return IsExecutionTerminatingCheck(isolate);
    8105             : }
    8106             : 
    8107             : 
    8108          85 : void Isolate::CancelTerminateExecution() {
    8109             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8110             :   isolate->stack_guard()->ClearTerminateExecution();
    8111          85 :   isolate->CancelTerminateExecution();
    8112          85 : }
    8113             : 
    8114             : 
    8115       60065 : void Isolate::RequestInterrupt(InterruptCallback callback, void* data) {
    8116             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8117       60065 :   isolate->RequestInterrupt(callback, data);
    8118       60065 : }
    8119             : 
    8120             : 
    8121       19794 : void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
    8122       19794 :   CHECK(i::FLAG_expose_gc);
    8123       19794 :   if (type == kMinorGarbageCollection) {
    8124             :     reinterpret_cast<i::Isolate*>(this)->heap()->CollectGarbage(
    8125             :         i::NEW_SPACE, i::GarbageCollectionReason::kTesting,
    8126         108 :         kGCCallbackFlagForced);
    8127             :   } else {
    8128             :     DCHECK_EQ(kFullGarbageCollection, type);
    8129             :     reinterpret_cast<i::Isolate*>(this)->heap()->PreciseCollectAllGarbage(
    8130             :         i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting,
    8131       19686 :         kGCCallbackFlagForced);
    8132             :   }
    8133       19794 : }
    8134             : 
    8135             : 
    8136      919999 : Isolate* Isolate::GetCurrent() {
    8137             :   i::Isolate* isolate = i::Isolate::Current();
    8138      919999 :   return reinterpret_cast<Isolate*>(isolate);
    8139             : }
    8140             : 
    8141             : // static
    8142          85 : Isolate* Isolate::Allocate() {
    8143       61263 :   return reinterpret_cast<Isolate*>(i::Isolate::New());
    8144             : }
    8145             : 
    8146             : // static
    8147             : // This is separate so that tests can provide a different |isolate|.
    8148       61228 : void Isolate::Initialize(Isolate* isolate,
    8149             :                          const v8::Isolate::CreateParams& params) {
    8150             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8151       61228 :   CHECK_NOT_NULL(params.array_buffer_allocator);
    8152             :   i_isolate->set_array_buffer_allocator(params.array_buffer_allocator);
    8153       61228 :   if (params.snapshot_blob != nullptr) {
    8154             :     i_isolate->set_snapshot_blob(params.snapshot_blob);
    8155             :   } else {
    8156       61053 :     i_isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob());
    8157             :   }
    8158       61228 :   auto code_event_handler = params.code_event_handler;
    8159             : #ifdef ENABLE_GDB_JIT_INTERFACE
    8160       61228 :   if (code_event_handler == nullptr && i::FLAG_gdbjit) {
    8161             :     code_event_handler = i::GDBJITInterface::EventHandler;
    8162             :   }
    8163             : #endif  // ENABLE_GDB_JIT_INTERFACE
    8164       61228 :   if (code_event_handler) {
    8165           0 :     i_isolate->InitializeLoggingAndCounters();
    8166             :     i_isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault,
    8167           0 :                                              code_event_handler);
    8168             :   }
    8169       61228 :   if (params.counter_lookup_callback) {
    8170             :     isolate->SetCounterFunction(params.counter_lookup_callback);
    8171             :   }
    8172             : 
    8173       61228 :   if (params.create_histogram_callback) {
    8174             :     isolate->SetCreateHistogramFunction(params.create_histogram_callback);
    8175             :   }
    8176             : 
    8177       61228 :   if (params.add_histogram_sample_callback) {
    8178             :     isolate->SetAddHistogramSampleFunction(
    8179             :         params.add_histogram_sample_callback);
    8180             :   }
    8181             : 
    8182       61228 :   i_isolate->set_api_external_references(params.external_references);
    8183       61228 :   i_isolate->set_allow_atomics_wait(params.allow_atomics_wait);
    8184             : 
    8185       61228 :   SetResourceConstraints(i_isolate, params.constraints);
    8186             :   // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
    8187             :   Isolate::Scope isolate_scope(isolate);
    8188       61227 :   if (!i::Snapshot::Initialize(i_isolate)) {
    8189             :     // If snapshot data was provided and we failed to deserialize it must
    8190             :     // have been corrupted.
    8191           0 :     if (i_isolate->snapshot_blob() != nullptr) {
    8192             :       FATAL(
    8193             :           "Failed to deserialize the V8 snapshot blob. This can mean that the "
    8194           0 :           "snapshot blob file is corrupted or missing.");
    8195             :     }
    8196             :     base::ElapsedTimer timer;
    8197           0 :     if (i::FLAG_profile_deserialization) timer.Start();
    8198           0 :     i_isolate->InitWithoutSnapshot();
    8199           0 :     if (i::FLAG_profile_deserialization) {
    8200           0 :       double ms = timer.Elapsed().InMillisecondsF();
    8201           0 :       i::PrintF("[Initializing isolate from scratch took %0.3f ms]\n", ms);
    8202             :     }
    8203             :   }
    8204             :   i_isolate->set_only_terminate_in_safe_scope(
    8205       61228 :       params.only_terminate_in_safe_scope);
    8206       61228 : }
    8207             : 
    8208       60983 : Isolate* Isolate::New(const Isolate::CreateParams& params) {
    8209             :   Isolate* isolate = Allocate();
    8210       60988 :   Initialize(isolate, params);
    8211       60988 :   return isolate;
    8212             : }
    8213             : 
    8214       61522 : void Isolate::Dispose() {
    8215             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8216       61523 :   if (!Utils::ApiCheck(!isolate->IsInUse(),
    8217             :                        "v8::Isolate::Dispose()",
    8218             :                        "Disposing the isolate that is entered by a thread.")) {
    8219             :     return;
    8220             :   }
    8221       61518 :   i::Isolate::Delete(isolate);
    8222             : }
    8223             : 
    8224           0 : void Isolate::DumpAndResetStats() {
    8225             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8226           0 :   isolate->DumpAndResetStats();
    8227           0 : }
    8228             : 
    8229        1500 : void Isolate::DiscardThreadSpecificMetadata() {
    8230             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8231        1500 :   isolate->DiscardPerThreadDataForThisThread();
    8232        1500 : }
    8233             : 
    8234             : 
    8235      160706 : void Isolate::Enter() {
    8236             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8237      222130 :   isolate->Enter();
    8238      160680 : }
    8239             : 
    8240             : 
    8241      160688 : void Isolate::Exit() {
    8242             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8243      222112 :   isolate->Exit();
    8244      160690 : }
    8245             : 
    8246             : 
    8247           5 : void Isolate::SetAbortOnUncaughtExceptionCallback(
    8248             :     AbortOnUncaughtExceptionCallback callback) {
    8249             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8250           5 :   isolate->SetAbortOnUncaughtExceptionCallback(callback);
    8251           5 : }
    8252             : 
    8253       30493 : void Isolate::SetHostImportModuleDynamicallyCallback(
    8254             :     HostImportModuleDynamicallyCallback callback) {
    8255             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8256       30493 :   isolate->SetHostImportModuleDynamicallyCallback(callback);
    8257       30493 : }
    8258             : 
    8259       30493 : void Isolate::SetHostInitializeImportMetaObjectCallback(
    8260             :     HostInitializeImportMetaObjectCallback callback) {
    8261             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8262       30493 :   isolate->SetHostInitializeImportMetaObjectCallback(callback);
    8263       30493 : }
    8264             : 
    8265          12 : void Isolate::SetPrepareStackTraceCallback(PrepareStackTraceCallback callback) {
    8266             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8267          12 :   isolate->SetPrepareStackTraceCallback(callback);
    8268          12 : }
    8269             : 
    8270       28952 : Isolate::DisallowJavascriptExecutionScope::DisallowJavascriptExecutionScope(
    8271             :     Isolate* isolate,
    8272             :     Isolate::DisallowJavascriptExecutionScope::OnFailure on_failure)
    8273       28952 :     : on_failure_(on_failure) {
    8274             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8275       28952 :   switch (on_failure_) {
    8276             :     case CRASH_ON_FAILURE:
    8277             :       internal_ = reinterpret_cast<void*>(
    8278           5 :           new i::DisallowJavascriptExecution(i_isolate));
    8279           5 :       break;
    8280             :     case THROW_ON_FAILURE:
    8281             :       DCHECK_EQ(THROW_ON_FAILURE, on_failure);
    8282             :       internal_ =
    8283       28942 :           reinterpret_cast<void*>(new i::ThrowOnJavascriptExecution(i_isolate));
    8284       28942 :       break;
    8285             :     case DUMP_ON_FAILURE:
    8286             :       internal_ =
    8287           5 :           reinterpret_cast<void*>(new i::DumpOnJavascriptExecution(i_isolate));
    8288           5 :       break;
    8289             :     default:
    8290           0 :       UNREACHABLE();
    8291             :       break;
    8292             :   }
    8293       28952 : }
    8294             : 
    8295             : 
    8296       57904 : Isolate::DisallowJavascriptExecutionScope::~DisallowJavascriptExecutionScope() {
    8297       28952 :   switch (on_failure_) {
    8298             :     case CRASH_ON_FAILURE:
    8299           5 :       delete reinterpret_cast<i::DisallowJavascriptExecution*>(internal_);
    8300             :       break;
    8301             :     case THROW_ON_FAILURE:
    8302       28942 :       delete reinterpret_cast<i::ThrowOnJavascriptExecution*>(internal_);
    8303             :       break;
    8304             :     case DUMP_ON_FAILURE:
    8305           5 :       delete reinterpret_cast<i::DumpOnJavascriptExecution*>(internal_);
    8306             :       break;
    8307             :     default:
    8308           0 :       UNREACHABLE();
    8309             :       break;
    8310             :   }
    8311       28952 : }
    8312             : 
    8313             : 
    8314      271647 : Isolate::AllowJavascriptExecutionScope::AllowJavascriptExecutionScope(
    8315             :     Isolate* isolate) {
    8316             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8317             :   internal_assert_ = reinterpret_cast<void*>(
    8318      271647 :       new i::AllowJavascriptExecution(i_isolate));
    8319             :   internal_throws_ = reinterpret_cast<void*>(
    8320      271647 :       new i::NoThrowOnJavascriptExecution(i_isolate));
    8321             :   internal_dump_ =
    8322      271647 :       reinterpret_cast<void*>(new i::NoDumpOnJavascriptExecution(i_isolate));
    8323      271647 : }
    8324             : 
    8325             : 
    8326      543294 : Isolate::AllowJavascriptExecutionScope::~AllowJavascriptExecutionScope() {
    8327      271647 :   delete reinterpret_cast<i::AllowJavascriptExecution*>(internal_assert_);
    8328      271647 :   delete reinterpret_cast<i::NoThrowOnJavascriptExecution*>(internal_throws_);
    8329      271647 :   delete reinterpret_cast<i::NoDumpOnJavascriptExecution*>(internal_dump_);
    8330      271647 : }
    8331             : 
    8332       37830 : Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope(
    8333             :     Isolate* isolate)
    8334             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    8335       37830 :       microtask_queue_(isolate_->default_microtask_queue()) {
    8336             :   isolate_->handle_scope_implementer()->IncrementCallDepth();
    8337       37830 :   microtask_queue_->IncrementMicrotasksSuppressions();
    8338       37830 : }
    8339             : 
    8340       75660 : Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
    8341       37830 :   microtask_queue_->DecrementMicrotasksSuppressions();
    8342       37830 :   isolate_->handle_scope_implementer()->DecrementCallDepth();
    8343       37830 : }
    8344             : 
    8345       24230 : Isolate::SafeForTerminationScope::SafeForTerminationScope(v8::Isolate* isolate)
    8346             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    8347       24230 :       prev_value_(isolate_->next_v8_call_is_safe_for_termination()) {
    8348             :   isolate_->set_next_v8_call_is_safe_for_termination(true);
    8349       24230 : }
    8350             : 
    8351       48460 : Isolate::SafeForTerminationScope::~SafeForTerminationScope() {
    8352       24230 :   isolate_->set_next_v8_call_is_safe_for_termination(prev_value_);
    8353       24230 : }
    8354             : 
    8355          85 : i::Address* Isolate::GetDataFromSnapshotOnce(size_t index) {
    8356             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
    8357          85 :   i::FixedArray list = i_isolate->heap()->serialized_objects();
    8358          85 :   return GetSerializedDataFromFixedArray(i_isolate, list, index);
    8359             : }
    8360             : 
    8361         246 : void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
    8362             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8363             :   i::Heap* heap = isolate->heap();
    8364         246 :   heap_statistics->total_heap_size_ = heap->CommittedMemory();
    8365             :   heap_statistics->total_heap_size_executable_ =
    8366         246 :       heap->CommittedMemoryExecutable();
    8367         246 :   heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
    8368         246 :   heap_statistics->total_available_size_ = heap->Available();
    8369         246 :   heap_statistics->used_heap_size_ = heap->SizeOfObjects();
    8370         246 :   heap_statistics->heap_size_limit_ = heap->MaxReserved();
    8371             :   // TODO(7424): There is no public API for the {WasmEngine} yet. Once such an
    8372             :   // API becomes available we should report the malloced memory separately. For
    8373             :   // now we just add the values, thereby over-approximating the peak slightly.
    8374             :   heap_statistics->malloced_memory_ =
    8375         246 :       isolate->allocator()->GetCurrentMemoryUsage() +
    8376         246 :       isolate->wasm_engine()->allocator()->GetCurrentMemoryUsage();
    8377         246 :   heap_statistics->external_memory_ = isolate->heap()->backing_store_bytes();
    8378             :   heap_statistics->peak_malloced_memory_ =
    8379         246 :       isolate->allocator()->GetMaxMemoryUsage() +
    8380         246 :       isolate->wasm_engine()->allocator()->GetMaxMemoryUsage();
    8381         246 :   heap_statistics->number_of_native_contexts_ = heap->NumberOfNativeContexts();
    8382             :   heap_statistics->number_of_detached_contexts_ =
    8383         246 :       heap->NumberOfDetachedContexts();
    8384         246 :   heap_statistics->does_zap_garbage_ = heap->ShouldZapGarbage();
    8385         246 : }
    8386             : 
    8387             : 
    8388          45 : size_t Isolate::NumberOfHeapSpaces() {
    8389          45 :   return i::LAST_SPACE - i::FIRST_SPACE + 1;
    8390             : }
    8391             : 
    8392             : 
    8393          40 : bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
    8394             :                                      size_t index) {
    8395          40 :   if (!space_statistics) return false;
    8396          40 :   if (!i::Heap::IsValidAllocationSpace(static_cast<i::AllocationSpace>(index)))
    8397             :     return false;
    8398             : 
    8399             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8400             :   i::Heap* heap = isolate->heap();
    8401          40 :   i::Space* space = heap->space(static_cast<int>(index));
    8402             : 
    8403          40 :   space_statistics->space_name_ = heap->GetSpaceName(static_cast<int>(index));
    8404          40 :   space_statistics->space_size_ = space->CommittedMemory();
    8405          40 :   space_statistics->space_used_size_ = space->SizeOfObjects();
    8406          40 :   space_statistics->space_available_size_ = space->Available();
    8407          40 :   space_statistics->physical_space_size_ = space->CommittedPhysicalMemory();
    8408          40 :   return true;
    8409             : }
    8410             : 
    8411             : 
    8412           0 : size_t Isolate::NumberOfTrackedHeapObjectTypes() {
    8413             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8414             :   i::Heap* heap = isolate->heap();
    8415           0 :   return heap->NumberOfTrackedHeapObjectTypes();
    8416             : }
    8417             : 
    8418             : 
    8419           0 : bool Isolate::GetHeapObjectStatisticsAtLastGC(
    8420             :     HeapObjectStatistics* object_statistics, size_t type_index) {
    8421           0 :   if (!object_statistics) return false;
    8422           0 :   if (V8_LIKELY(!i::TracingFlags::is_gc_stats_enabled())) return false;
    8423             : 
    8424             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8425             :   i::Heap* heap = isolate->heap();
    8426           0 :   if (type_index >= heap->NumberOfTrackedHeapObjectTypes()) return false;
    8427             : 
    8428             :   const char* object_type;
    8429             :   const char* object_sub_type;
    8430           0 :   size_t object_count = heap->ObjectCountAtLastGC(type_index);
    8431           0 :   size_t object_size = heap->ObjectSizeAtLastGC(type_index);
    8432           0 :   if (!heap->GetObjectTypeName(type_index, &object_type, &object_sub_type)) {
    8433             :     // There should be no objects counted when the type is unknown.
    8434             :     DCHECK_EQ(object_count, 0U);
    8435             :     DCHECK_EQ(object_size, 0U);
    8436             :     return false;
    8437             :   }
    8438             : 
    8439           0 :   object_statistics->object_type_ = object_type;
    8440           0 :   object_statistics->object_sub_type_ = object_sub_type;
    8441           0 :   object_statistics->object_count_ = object_count;
    8442           0 :   object_statistics->object_size_ = object_size;
    8443           0 :   return true;
    8444             : }
    8445             : 
    8446           0 : bool Isolate::GetHeapCodeAndMetadataStatistics(
    8447             :     HeapCodeStatistics* code_statistics) {
    8448           0 :   if (!code_statistics) return false;
    8449             : 
    8450             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8451           0 :   isolate->heap()->CollectCodeStatistics();
    8452             : 
    8453           0 :   code_statistics->code_and_metadata_size_ = isolate->code_and_metadata_size();
    8454             :   code_statistics->bytecode_and_metadata_size_ =
    8455           0 :       isolate->bytecode_and_metadata_size();
    8456             :   code_statistics->external_script_source_size_ =
    8457           0 :       isolate->external_script_source_size();
    8458           0 :   return true;
    8459             : }
    8460             : 
    8461          15 : void Isolate::GetStackSample(const RegisterState& state, void** frames,
    8462             :                              size_t frames_limit, SampleInfo* sample_info) {
    8463          15 :   RegisterState regs = state;
    8464          15 :   if (TickSample::GetStackSample(this, &regs, TickSample::kSkipCEntryFrame,
    8465             :                                  frames, frames_limit, sample_info)) {
    8466          15 :     return;
    8467             :   }
    8468           0 :   sample_info->frames_count = 0;
    8469           0 :   sample_info->vm_state = OTHER;
    8470           0 :   sample_info->external_callback_entry = nullptr;
    8471             : }
    8472             : 
    8473          15 : size_t Isolate::NumberOfPhantomHandleResetsSinceLastCall() {
    8474             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8475          15 :   return isolate->global_handles()->GetAndResetGlobalHandleResetCount();
    8476             : }
    8477             : 
    8478           5 : void Isolate::SetEventLogger(LogEventCallback that) {
    8479             :   // Do not overwrite the event logger if we want to log explicitly.
    8480           5 :   if (i::FLAG_log_internal_timer_events) return;
    8481             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8482             :   isolate->set_event_logger(that);
    8483             : }
    8484             : 
    8485             : 
    8486          15 : void Isolate::AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback) {
    8487          15 :   if (callback == nullptr) return;
    8488             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8489          15 :   isolate->AddBeforeCallEnteredCallback(callback);
    8490             : }
    8491             : 
    8492             : 
    8493           5 : void Isolate::RemoveBeforeCallEnteredCallback(
    8494             :     BeforeCallEnteredCallback callback) {
    8495             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8496           5 :   isolate->RemoveBeforeCallEnteredCallback(callback);
    8497           5 : }
    8498             : 
    8499             : 
    8500          65 : void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
    8501          65 :   if (callback == nullptr) return;
    8502             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8503          65 :   isolate->AddCallCompletedCallback(callback);
    8504             : }
    8505             : 
    8506             : 
    8507        3717 : void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
    8508             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8509        3717 :   isolate->RemoveCallCompletedCallback(callback);
    8510        3717 : }
    8511             : 
    8512          52 : void Isolate::AtomicsWaitWakeHandle::Wake() {
    8513          52 :   reinterpret_cast<i::AtomicsWaitWakeHandle*>(this)->Wake();
    8514          52 : }
    8515             : 
    8516          13 : void Isolate::SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data) {
    8517             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8518          13 :   isolate->SetAtomicsWaitCallback(callback, data);
    8519          13 : }
    8520             : 
    8521         111 : void Isolate::SetPromiseHook(PromiseHook hook) {
    8522             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8523         111 :   isolate->SetPromiseHook(hook);
    8524         111 : }
    8525             : 
    8526        1150 : void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) {
    8527        1150 :   if (callback == nullptr) return;
    8528             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8529        1150 :   isolate->SetPromiseRejectCallback(callback);
    8530             : }
    8531             : 
    8532             : 
    8533         127 : void Isolate::RunMicrotasks() {
    8534             :   DCHECK_NE(MicrotasksPolicy::kScoped, GetMicrotasksPolicy());
    8535             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8536         127 :   isolate->default_microtask_queue()->RunMicrotasks(isolate);
    8537         127 : }
    8538             : 
    8539         120 : void Isolate::EnqueueMicrotask(Local<Function> v8_function) {
    8540             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8541         120 :   i::Handle<i::JSReceiver> function = Utils::OpenHandle(*v8_function);
    8542             :   i::Handle<i::NativeContext> handler_context;
    8543         240 :   if (!i::JSReceiver::GetContextForMicrotask(function).ToHandle(
    8544             :           &handler_context))
    8545           0 :     handler_context = isolate->native_context();
    8546         120 :   handler_context->microtask_queue()->EnqueueMicrotask(this, v8_function);
    8547         120 : }
    8548             : 
    8549         441 : void Isolate::EnqueueMicrotask(MicrotaskCallback callback, void* data) {
    8550             :   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         441 :   isolate->default_microtask_queue()->EnqueueMicrotask(*microtask);
    8556         441 : }
    8557             : 
    8558             : 
    8559        2320 : void Isolate::SetMicrotasksPolicy(MicrotasksPolicy policy) {
    8560             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8561             :   isolate->default_microtask_queue()->set_microtasks_policy(policy);
    8562        2320 : }
    8563             : 
    8564             : 
    8565           0 : MicrotasksPolicy Isolate::GetMicrotasksPolicy() const {
    8566             :   i::Isolate* isolate =
    8567             :       reinterpret_cast<i::Isolate*>(const_cast<Isolate*>(this));
    8568           0 :   return isolate->default_microtask_queue()->microtasks_policy();
    8569             : }
    8570             : 
    8571             : namespace {
    8572             : 
    8573           0 : void MicrotasksCompletedCallbackAdapter(v8::Isolate* isolate, void* data) {
    8574           0 :   auto callback = reinterpret_cast<void (*)(v8::Isolate*)>(data);
    8575           0 :   callback(isolate);
    8576           0 : }
    8577             : 
    8578             : }  // namespace
    8579             : 
    8580           0 : void Isolate::AddMicrotasksCompletedCallback(
    8581             :     MicrotasksCompletedCallback callback) {
    8582             :   DCHECK(callback);
    8583             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8584             :   isolate->default_microtask_queue()->AddMicrotasksCompletedCallback(
    8585           0 :       &MicrotasksCompletedCallbackAdapter, reinterpret_cast<void*>(callback));
    8586           0 : }
    8587             : 
    8588          45 : void Isolate::AddMicrotasksCompletedCallback(
    8589             :     MicrotasksCompletedCallbackWithData callback, void* data) {
    8590             :   DCHECK(callback);
    8591             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8592             :   isolate->default_microtask_queue()->AddMicrotasksCompletedCallback(callback,
    8593          45 :                                                                      data);
    8594          45 : }
    8595             : 
    8596           0 : void Isolate::RemoveMicrotasksCompletedCallback(
    8597             :     MicrotasksCompletedCallback callback) {
    8598             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8599             :   isolate->default_microtask_queue()->RemoveMicrotasksCompletedCallback(
    8600           0 :       &MicrotasksCompletedCallbackAdapter, reinterpret_cast<void*>(callback));
    8601           0 : }
    8602             : 
    8603        3717 : void Isolate::RemoveMicrotasksCompletedCallback(
    8604             :     MicrotasksCompletedCallbackWithData callback, void* data) {
    8605             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8606             :   isolate->default_microtask_queue()->RemoveMicrotasksCompletedCallback(
    8607        3717 :       callback, data);
    8608        3717 : }
    8609             : 
    8610          55 : void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
    8611          55 :   reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
    8612          55 : }
    8613             : 
    8614             : 
    8615           5 : void Isolate::SetCounterFunction(CounterLookupCallback callback) {
    8616             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8617           5 :   isolate->counters()->ResetCounterFunction(callback);
    8618           5 : }
    8619             : 
    8620             : 
    8621           8 : void Isolate::SetCreateHistogramFunction(CreateHistogramCallback callback) {
    8622             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8623           8 :   isolate->counters()->ResetCreateHistogramFunction(callback);
    8624           8 : }
    8625             : 
    8626             : 
    8627           8 : void Isolate::SetAddHistogramSampleFunction(
    8628             :     AddHistogramSampleCallback callback) {
    8629             :   reinterpret_cast<i::Isolate*>(this)
    8630             :       ->counters()
    8631             :       ->SetAddHistogramSampleFunction(callback);
    8632           8 : }
    8633             : 
    8634             : 
    8635         469 : bool Isolate::IdleNotificationDeadline(double deadline_in_seconds) {
    8636             :   // Returning true tells the caller that it need not
    8637             :   // continue to call IdleNotification.
    8638             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8639         469 :   if (!i::FLAG_use_idle_notification) return true;
    8640         469 :   return isolate->heap()->IdleNotification(deadline_in_seconds);
    8641             : }
    8642             : 
    8643         510 : void Isolate::LowMemoryNotification() {
    8644             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8645             :   {
    8646             :     i::HistogramTimerScope idle_notification_scope(
    8647             :         isolate->counters()->gc_low_memory_notification());
    8648        1530 :     TRACE_EVENT0("v8", "V8.GCLowMemoryNotification");
    8649             :     isolate->heap()->CollectAllAvailableGarbage(
    8650         510 :         i::GarbageCollectionReason::kLowMemoryNotification);
    8651             :   }
    8652             :   {
    8653        1020 :     i::HeapIterator iterator(isolate->heap());
    8654     6553676 :     for (i::HeapObject obj = iterator.next(); !obj.is_null();
    8655             :          obj = iterator.next()) {
    8656     3276379 :       if (obj->IsAbstractCode()) {
    8657      774758 :         i::AbstractCode::cast(obj)->DropStackFrameCache();
    8658             :       }
    8659             :     }
    8660             :   }
    8661         510 : }
    8662             : 
    8663             : 
    8664         593 : int Isolate::ContextDisposedNotification(bool dependant_context) {
    8665             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8666         593 :   if (!dependant_context) {
    8667             :     // We left the current context, we can abort all WebAssembly compilations on
    8668             :     // that isolate.
    8669          10 :     isolate->wasm_engine()->DeleteCompileJobsOnIsolate(isolate);
    8670             :   }
    8671             :   // TODO(ahaas): move other non-heap activity out of the heap call.
    8672        1186 :   return isolate->heap()->NotifyContextDisposed(dependant_context);
    8673             : }
    8674             : 
    8675             : 
    8676           0 : void Isolate::IsolateInForegroundNotification() {
    8677             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8678           0 :   return isolate->IsolateInForegroundNotification();
    8679             : }
    8680             : 
    8681             : 
    8682           0 : void Isolate::IsolateInBackgroundNotification() {
    8683             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8684           0 :   return isolate->IsolateInBackgroundNotification();
    8685             : }
    8686             : 
    8687          82 : void Isolate::MemoryPressureNotification(MemoryPressureLevel level) {
    8688             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8689             :   bool on_isolate_thread =
    8690          82 :       v8::Locker::IsActive()
    8691             :           ? isolate->thread_manager()->IsLockedByCurrentThread()
    8692          82 :           : i::ThreadId::Current() == isolate->thread_id();
    8693         164 :   isolate->heap()->MemoryPressureNotification(level, on_isolate_thread);
    8694          82 : }
    8695             : 
    8696           5 : void Isolate::EnableMemorySavingsMode() {
    8697             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8698             :   isolate->EnableMemorySavingsMode();
    8699           5 : }
    8700             : 
    8701           5 : void Isolate::DisableMemorySavingsMode() {
    8702             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8703             :   isolate->DisableMemorySavingsMode();
    8704           5 : }
    8705             : 
    8706           0 : void Isolate::SetRAILMode(RAILMode rail_mode) {
    8707             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8708           0 :   return isolate->SetRAILMode(rail_mode);
    8709             : }
    8710             : 
    8711           0 : void Isolate::IncreaseHeapLimitForDebugging() {
    8712             :   // No-op.
    8713           0 : }
    8714             : 
    8715           5 : void Isolate::RestoreOriginalHeapLimit() {
    8716             :   // No-op.
    8717           5 : }
    8718             : 
    8719           0 : bool Isolate::IsHeapLimitIncreasedForDebugging() { return false; }
    8720             : 
    8721          60 : void Isolate::SetJitCodeEventHandler(JitCodeEventOptions options,
    8722             :                                      JitCodeEventHandler event_handler) {
    8723             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8724             :   // Ensure that logging is initialized for our isolate.
    8725          60 :   isolate->InitializeLoggingAndCounters();
    8726          60 :   isolate->logger()->SetCodeEventHandler(options, event_handler);
    8727          60 : }
    8728             : 
    8729             : 
    8730          10 : void Isolate::SetStackLimit(uintptr_t stack_limit) {
    8731             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8732          10 :   CHECK(stack_limit);
    8733          10 :   isolate->stack_guard()->SetStackLimit(stack_limit);
    8734          10 : }
    8735             : 
    8736           0 : void Isolate::GetCodeRange(void** start, size_t* length_in_bytes) {
    8737             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8738             :   const base::AddressRegion& code_range =
    8739             :       isolate->heap()->memory_allocator()->code_range();
    8740          70 :   *start = reinterpret_cast<void*>(code_range.begin());
    8741          70 :   *length_in_bytes = code_range.size();
    8742           0 : }
    8743             : 
    8744          70 : UnwindState Isolate::GetUnwindState() {
    8745          70 :   UnwindState unwind_state;
    8746             :   void* code_range_start;
    8747             :   GetCodeRange(&code_range_start, &unwind_state.code_range.length_in_bytes);
    8748          70 :   unwind_state.code_range.start = code_range_start;
    8749             : 
    8750             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8751             :   unwind_state.embedded_code_range.start =
    8752          70 :       reinterpret_cast<const void*>(isolate->embedded_blob());
    8753             :   unwind_state.embedded_code_range.length_in_bytes =
    8754          70 :       isolate->embedded_blob_size();
    8755             : 
    8756          70 :   i::Code js_entry = isolate->heap()->builtin(i::Builtins::kJSEntry);
    8757             :   unwind_state.js_entry_stub.code.start =
    8758          70 :       reinterpret_cast<const void*>(js_entry->InstructionStart());
    8759          70 :   unwind_state.js_entry_stub.code.length_in_bytes = js_entry->InstructionSize();
    8760             : 
    8761          70 :   return unwind_state;
    8762             : }
    8763             : 
    8764             : #define CALLBACK_SETTER(ExternalName, Type, InternalName)      \
    8765             :   void Isolate::Set##ExternalName(Type callback) {             \
    8766             :     i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); \
    8767             :     isolate->set_##InternalName(callback);                     \
    8768             :   }
    8769             : 
    8770          80 : CALLBACK_SETTER(FatalErrorHandler, FatalErrorCallback, exception_behavior)
    8771           0 : CALLBACK_SETTER(OOMErrorHandler, OOMErrorCallback, oom_behavior)
    8772         340 : CALLBACK_SETTER(AllowCodeGenerationFromStringsCallback,
    8773             :                 AllowCodeGenerationFromStringsCallback, allow_code_gen_callback)
    8774         272 : CALLBACK_SETTER(AllowWasmCodeGenerationCallback,
    8775             :                 AllowWasmCodeGenerationCallback, allow_wasm_code_gen_callback)
    8776             : 
    8777          96 : CALLBACK_SETTER(WasmModuleCallback, ExtensionCallback, wasm_module_callback)
    8778          16 : CALLBACK_SETTER(WasmInstanceCallback, ExtensionCallback, wasm_instance_callback)
    8779             : 
    8780          48 : CALLBACK_SETTER(WasmStreamingCallback, WasmStreamingCallback,
    8781             :                 wasm_streaming_callback)
    8782             : 
    8783          58 : CALLBACK_SETTER(WasmThreadsEnabledCallback, WasmThreadsEnabledCallback,
    8784             :                 wasm_threads_enabled_callback)
    8785             : 
    8786        3418 : void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
    8787             :                                        void* data) {
    8788             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8789        3418 :   isolate->heap()->AddNearHeapLimitCallback(callback, data);
    8790        3418 : }
    8791             : 
    8792        3418 : void Isolate::RemoveNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
    8793             :                                           size_t heap_limit) {
    8794             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8795        3418 :   isolate->heap()->RemoveNearHeapLimitCallback(callback, heap_limit);
    8796        3418 : }
    8797             : 
    8798           0 : void Isolate::AutomaticallyRestoreInitialHeapLimit(double threshold_percent) {
    8799             :   DCHECK_GT(threshold_percent, 0.0);
    8800             :   DCHECK_LT(threshold_percent, 1.0);
    8801             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8802           0 :   isolate->heap()->AutomaticallyRestoreInitialHeapLimit(threshold_percent);
    8803           0 : }
    8804             : 
    8805           0 : bool Isolate::IsDead() {
    8806             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8807           0 :   return isolate->IsDead();
    8808             : }
    8809             : 
    8810        1271 : bool Isolate::AddMessageListener(MessageCallback that, Local<Value> data) {
    8811        1271 :   return AddMessageListenerWithErrorLevel(that, kMessageError, data);
    8812             : }
    8813             : 
    8814       31128 : bool Isolate::AddMessageListenerWithErrorLevel(MessageCallback that,
    8815             :                                                int message_levels,
    8816             :                                                Local<Value> data) {
    8817             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8818             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    8819             :   i::HandleScope scope(isolate);
    8820             :   i::Handle<i::TemplateList> list = isolate->factory()->message_listeners();
    8821       31128 :   i::Handle<i::FixedArray> listener = isolate->factory()->NewFixedArray(3);
    8822             :   i::Handle<i::Foreign> foreign =
    8823       31128 :       isolate->factory()->NewForeign(FUNCTION_ADDR(that));
    8824       62256 :   listener->set(0, *foreign);
    8825      124496 :   listener->set(1, data.IsEmpty() ? i::ReadOnlyRoots(isolate).undefined_value()
    8826       31128 :                                   : *Utils::OpenHandle(*data));
    8827             :   listener->set(2, i::Smi::FromInt(message_levels));
    8828       31128 :   list = i::TemplateList::Add(isolate, list, listener);
    8829             :   isolate->heap()->SetMessageListeners(*list);
    8830       31128 :   return true;
    8831             : }
    8832             : 
    8833             : 
    8834         151 : void Isolate::RemoveMessageListeners(MessageCallback that) {
    8835             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8836             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    8837             :   i::HandleScope scope(isolate);
    8838             :   i::DisallowHeapAllocation no_gc;
    8839             :   i::TemplateList listeners = isolate->heap()->message_listeners();
    8840         344 :   for (int i = 0; i < listeners->length(); i++) {
    8841         193 :     if (listeners->get(i)->IsUndefined(isolate)) continue;  // skip deleted ones
    8842             :     i::FixedArray listener = i::FixedArray::cast(listeners->get(i));
    8843             :     i::Foreign callback_obj = i::Foreign::cast(listener->get(0));
    8844         151 :     if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
    8845             :       listeners->set(i, i::ReadOnlyRoots(isolate).undefined_value());
    8846             :     }
    8847             :   }
    8848         151 : }
    8849             : 
    8850             : 
    8851          26 : void Isolate::SetFailedAccessCheckCallbackFunction(
    8852             :     FailedAccessCheckCallback callback) {
    8853             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8854          26 :   isolate->SetFailedAccessCheckCallback(callback);
    8855          26 : }
    8856             : 
    8857             : 
    8858        1311 : void Isolate::SetCaptureStackTraceForUncaughtExceptions(
    8859             :     bool capture, int frame_limit, StackTrace::StackTraceOptions options) {
    8860             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8861        1311 :   isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit,
    8862        1311 :                                                      options);
    8863        1311 : }
    8864             : 
    8865             : 
    8866           5 : void Isolate::VisitExternalResources(ExternalResourceVisitor* visitor) {
    8867             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8868           5 :   isolate->heap()->VisitExternalResources(visitor);
    8869           5 : }
    8870             : 
    8871             : 
    8872       66148 : bool Isolate::IsInUse() {
    8873             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8874       66148 :   return isolate->IsInUse();
    8875             : }
    8876             : 
    8877             : 
    8878          10 : void Isolate::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
    8879             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8880             :   i::DisallowHeapAllocation no_allocation;
    8881          10 :   isolate->global_handles()->IterateAllRootsWithClassIds(visitor);
    8882          10 : }
    8883             : 
    8884           0 : void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) {
    8885             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8886             :   i::DisallowHeapAllocation no_allocation;
    8887           0 :   isolate->global_handles()->IterateYoungWeakRootsWithClassIds(visitor);
    8888           0 : }
    8889             : 
    8890           5 : void Isolate::SetAllowAtomicsWait(bool allow) {
    8891             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
    8892             :   isolate->set_allow_atomics_wait(allow);
    8893           5 : }
    8894             : 
    8895           0 : void v8::Isolate::DateTimeConfigurationChangeNotification(
    8896             :     TimeZoneDetection time_zone_detection) {
    8897             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
    8898           0 :   LOG_API(i_isolate, Isolate, DateTimeConfigurationChangeNotification);
    8899             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    8900             :   i_isolate->date_cache()->ResetDateCache(
    8901           0 :       static_cast<base::TimezoneCache::TimeZoneDetection>(time_zone_detection));
    8902             : #ifdef V8_INTL_SUPPORT
    8903             :   i_isolate->clear_cached_icu_object(
    8904           0 :       i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat);
    8905             :   i_isolate->clear_cached_icu_object(
    8906           0 :       i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime);
    8907             :   i_isolate->clear_cached_icu_object(
    8908           0 :       i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate);
    8909             : #endif  // V8_INTL_SUPPORT
    8910           0 : }
    8911             : 
    8912           0 : void v8::Isolate::LocaleConfigurationChangeNotification() {
    8913             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
    8914           0 :   LOG_API(i_isolate, Isolate, LocaleConfigurationChangeNotification);
    8915             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    8916             : 
    8917             : #ifdef V8_INTL_SUPPORT
    8918             :   i_isolate->ResetDefaultLocale();
    8919             : #endif  // V8_INTL_SUPPORT
    8920           0 : }
    8921             : 
    8922             : // static
    8923           0 : std::unique_ptr<MicrotaskQueue> MicrotaskQueue::New(Isolate* isolate) {
    8924           0 :   return i::MicrotaskQueue::New(reinterpret_cast<i::Isolate*>(isolate));
    8925             : }
    8926             : 
    8927     1291115 : MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type)
    8928             :     : MicrotasksScope(
    8929             :           isolate,
    8930             :           reinterpret_cast<i::Isolate*>(isolate)->default_microtask_queue(),
    8931     1291115 :           type) {}
    8932             : 
    8933           0 : MicrotasksScope::MicrotasksScope(Isolate* isolate,
    8934             :                                  MicrotaskQueue* microtask_queue,
    8935             :                                  MicrotasksScope::Type type)
    8936             :     : isolate_(reinterpret_cast<i::Isolate*>(isolate)),
    8937             :       microtask_queue_(static_cast<i::MicrotaskQueue*>(microtask_queue)),
    8938     1291115 :       run_(type == MicrotasksScope::kRunMicrotasks) {
    8939     1291115 :   if (run_) microtask_queue_->IncrementMicrotasksScopeDepth();
    8940             : #ifdef DEBUG
    8941             :   if (!run_) microtask_queue_->IncrementDebugMicrotasksScopeDepth();
    8942             : #endif
    8943           0 : }
    8944             : 
    8945     2582219 : MicrotasksScope::~MicrotasksScope() {
    8946     1291108 :   if (run_) {
    8947      143000 :     microtask_queue_->DecrementMicrotasksScopeDepth();
    8948      143000 :     if (MicrotasksPolicy::kScoped == microtask_queue_->microtasks_policy()) {
    8949       75119 :       PerformCheckpoint(reinterpret_cast<Isolate*>(isolate_));
    8950             :     }
    8951             :   }
    8952             : #ifdef DEBUG
    8953             :   if (!run_) microtask_queue_->DecrementDebugMicrotasksScopeDepth();
    8954             : #endif
    8955     1291111 : }
    8956             : 
    8957       48955 : void MicrotasksScope::PerformCheckpoint(Isolate* v8_isolate) {
    8958             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    8959             :   auto* microtask_queue = isolate->default_microtask_queue();
    8960      124074 :   microtask_queue->PerformCheckpoint(v8_isolate);
    8961       48955 : }
    8962             : 
    8963           0 : int MicrotasksScope::GetCurrentDepth(Isolate* v8_isolate) {
    8964             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    8965             :   auto* microtask_queue = isolate->default_microtask_queue();
    8966           0 :   return microtask_queue->GetMicrotasksScopeDepth();
    8967             : }
    8968             : 
    8969         100 : bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8_isolate) {
    8970             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    8971             :   auto* microtask_queue = isolate->default_microtask_queue();
    8972         100 :   return microtask_queue->IsRunningMicrotasks();
    8973             : }
    8974             : 
    8975     9053821 : String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
    8976     9053821 :     : str_(nullptr), length_(0) {
    8977     9053864 :   if (obj.IsEmpty()) return;
    8978             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8979             :   ENTER_V8_DO_NOT_USE(i_isolate);
    8980             :   i::HandleScope scope(i_isolate);
    8981     9053786 :   Local<Context> context = isolate->GetCurrentContext();
    8982    18107564 :   TryCatch try_catch(isolate);
    8983             :   Local<String> str;
    8984    18107580 :   if (!obj->ToString(context).ToLocal(&str)) return;
    8985     9053778 :   length_ = str->Utf8Length(isolate);
    8986     9053778 :   str_ = i::NewArray<char>(length_ + 1);
    8987     9053778 :   str->WriteUtf8(isolate, str_);
    8988             : }
    8989             : 
    8990    18107642 : String::Utf8Value::~Utf8Value() {
    8991     9053821 :   i::DeleteArray(str_);
    8992     9053821 : }
    8993             : 
    8994           6 : String::Value::Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
    8995           6 :     : str_(nullptr), length_(0) {
    8996           6 :   if (obj.IsEmpty()) return;
    8997             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    8998             :   ENTER_V8_DO_NOT_USE(i_isolate);
    8999             :   i::HandleScope scope(i_isolate);
    9000           6 :   Local<Context> context = isolate->GetCurrentContext();
    9001          12 :   TryCatch try_catch(isolate);
    9002             :   Local<String> str;
    9003          12 :   if (!obj->ToString(context).ToLocal(&str)) return;
    9004           6 :   length_ = str->Length();
    9005           6 :   str_ = i::NewArray<uint16_t>(length_ + 1);
    9006             :   str->Write(isolate, str_);
    9007             : }
    9008             : 
    9009          12 : String::Value::~Value() {
    9010           6 :   i::DeleteArray(str_);
    9011           6 : }
    9012             : 
    9013             : #define DEFINE_ERROR(NAME, name)                                         \
    9014             :   Local<Value> Exception::NAME(v8::Local<v8::String> raw_message) {      \
    9015             :     i::Isolate* isolate = i::Isolate::Current();                         \
    9016             :     LOG_API(isolate, NAME, New);                                         \
    9017             :     ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);                            \
    9018             :     i::Object error;                                                     \
    9019             :     {                                                                    \
    9020             :       i::HandleScope scope(isolate);                                     \
    9021             :       i::Handle<i::String> message = Utils::OpenHandle(*raw_message);    \
    9022             :       i::Handle<i::JSFunction> constructor = isolate->name##_function(); \
    9023             :       error = *isolate->factory()->NewError(constructor, message);       \
    9024             :     }                                                                    \
    9025             :     i::Handle<i::Object> result(error, isolate);                         \
    9026             :     return Utils::ToLocal(result);                                       \
    9027             :   }
    9028             : 
    9029         110 : DEFINE_ERROR(RangeError, range_error)
    9030          30 : DEFINE_ERROR(ReferenceError, reference_error)
    9031          30 : DEFINE_ERROR(SyntaxError, syntax_error)
    9032          30 : DEFINE_ERROR(TypeError, type_error)
    9033        1215 : DEFINE_ERROR(Error, error)
    9034             : 
    9035             : #undef DEFINE_ERROR
    9036             : 
    9037             : 
    9038         328 : Local<Message> Exception::CreateMessage(Isolate* isolate,
    9039             :                                         Local<Value> exception) {
    9040         328 :   i::Handle<i::Object> obj = Utils::OpenHandle(*exception);
    9041             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9042             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    9043             :   i::HandleScope scope(i_isolate);
    9044             :   return Utils::MessageToLocal(
    9045         656 :       scope.CloseAndEscape(i_isolate->CreateMessage(obj, nullptr)));
    9046             : }
    9047             : 
    9048             : 
    9049          77 : Local<StackTrace> Exception::GetStackTrace(Local<Value> exception) {
    9050             :   i::Handle<i::Object> obj = Utils::OpenHandle(*exception);
    9051          77 :   if (!obj->IsJSObject()) return Local<StackTrace>();
    9052             :   i::Handle<i::JSObject> js_obj = i::Handle<i::JSObject>::cast(obj);
    9053             :   i::Isolate* isolate = js_obj->GetIsolate();
    9054             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9055          77 :   return Utils::StackTraceToLocal(isolate->GetDetailedStackTrace(js_obj));
    9056             : }
    9057             : 
    9058             : 
    9059             : // --- D e b u g   S u p p o r t ---
    9060             : 
    9061        3771 : void debug::SetContextId(Local<Context> context, int id) {
    9062        7542 :   Utils::OpenHandle(*context)->set_debug_context_id(i::Smi::FromInt(id));
    9063        3771 : }
    9064             : 
    9065     3881862 : int debug::GetContextId(Local<Context> context) {
    9066     3881862 :   i::Object value = Utils::OpenHandle(*context)->debug_context_id();
    9067     7763724 :   return (value->IsSmi()) ? i::Smi::ToInt(value) : 0;
    9068             : }
    9069             : 
    9070        7344 : void debug::SetInspector(Isolate* isolate,
    9071             :                          v8_inspector::V8Inspector* inspector) {
    9072             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9073             :   i_isolate->set_inspector(inspector);
    9074        7344 : }
    9075             : 
    9076     7194420 : v8_inspector::V8Inspector* debug::GetInspector(Isolate* isolate) {
    9077     7194420 :   return reinterpret_cast<i::Isolate*>(isolate)->inspector();
    9078             : }
    9079             : 
    9080        6615 : void debug::SetBreakOnNextFunctionCall(Isolate* isolate) {
    9081        6615 :   reinterpret_cast<i::Isolate*>(isolate)->debug()->SetBreakOnNextFunctionCall();
    9082        6615 : }
    9083             : 
    9084          30 : void debug::ClearBreakOnNextFunctionCall(Isolate* isolate) {
    9085             :   reinterpret_cast<i::Isolate*>(isolate)
    9086             :       ->debug()
    9087          30 :       ->ClearBreakOnNextFunctionCall();
    9088          30 : }
    9089             : 
    9090       79258 : MaybeLocal<Array> debug::GetInternalProperties(Isolate* v8_isolate,
    9091             :                                                Local<Value> value) {
    9092             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9093             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9094       79258 :   i::Handle<i::Object> val = Utils::OpenHandle(*value);
    9095             :   i::Handle<i::JSArray> result;
    9096      158516 :   if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result))
    9097           0 :     return MaybeLocal<Array>();
    9098       79258 :   return Utils::ToLocal(result);
    9099             : }
    9100             : 
    9101       79273 : MaybeLocal<Array> debug::GetPrivateFields(Local<Context> context,
    9102             :                                           Local<Object> value) {
    9103      317092 :   PREPARE_FOR_EXECUTION(context, debug, GetPrivateFields, Array);
    9104       79273 :   i::Handle<i::JSReceiver> val = Utils::OpenHandle(*value);
    9105             :   i::Handle<i::JSArray> result;
    9106             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9107             :   has_pending_exception =
    9108      158546 :       !(internal_isolate->debug()->GetPrivateFields(val).ToHandle(&result));
    9109       79273 :   RETURN_ON_FAILED_EXECUTION(Array);
    9110       79273 :   RETURN_ESCAPED(Utils::ToLocal(result));
    9111             : }
    9112             : 
    9113        7493 : void debug::ChangeBreakOnException(Isolate* isolate, ExceptionBreakState type) {
    9114             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9115        7493 :   internal_isolate->debug()->ChangeBreakOnException(
    9116        7493 :       i::BreakException, type == BreakOnAnyException);
    9117        7493 :   internal_isolate->debug()->ChangeBreakOnException(i::BreakUncaughtException,
    9118        7493 :                                                     type != NoBreakOnException);
    9119        7493 : }
    9120             : 
    9121        7076 : void debug::SetBreakPointsActive(Isolate* v8_isolate, bool is_active) {
    9122             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9123             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9124             :   isolate->debug()->set_break_points_active(is_active);
    9125        7076 : }
    9126             : 
    9127       44423 : void debug::PrepareStep(Isolate* v8_isolate, StepAction action) {
    9128             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9129             :   ENTER_V8_DO_NOT_USE(isolate);
    9130       44423 :   CHECK(isolate->debug()->CheckExecutionState());
    9131             :   // Clear all current stepping setup.
    9132       44423 :   isolate->debug()->ClearStepping();
    9133             :   // Prepare step.
    9134       44423 :   isolate->debug()->PrepareStep(static_cast<i::StepAction>(action));
    9135       44423 : }
    9136             : 
    9137           0 : void debug::ClearStepping(Isolate* v8_isolate) {
    9138             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9139             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9140             :   // Clear all current stepping setup.
    9141           0 :   isolate->debug()->ClearStepping();
    9142           0 : }
    9143             : 
    9144       60221 : void debug::BreakRightNow(Isolate* v8_isolate) {
    9145             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9146             :   ENTER_V8_DO_NOT_USE(isolate);
    9147       60221 :   isolate->debug()->HandleDebugBreak(i::kIgnoreIfAllFramesBlackboxed);
    9148       60221 : }
    9149             : 
    9150         370 : bool debug::AllFramesOnStackAreBlackboxed(Isolate* v8_isolate) {
    9151             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9152             :   ENTER_V8_DO_NOT_USE(isolate);
    9153         740 :   return isolate->debug()->AllFramesOnStackAreBlackboxed();
    9154             : }
    9155             : 
    9156           0 : v8::Isolate* debug::Script::GetIsolate() const {
    9157           0 :   return reinterpret_cast<v8::Isolate*>(Utils::OpenHandle(this)->GetIsolate());
    9158             : }
    9159             : 
    9160           0 : ScriptOriginOptions debug::Script::OriginOptions() const {
    9161           0 :   return Utils::OpenHandle(this)->origin_options();
    9162             : }
    9163             : 
    9164       33830 : bool debug::Script::WasCompiled() const {
    9165             :   return Utils::OpenHandle(this)->compilation_state() ==
    9166       33830 :          i::Script::COMPILATION_STATE_COMPILED;
    9167             : }
    9168             : 
    9169       33727 : bool debug::Script::IsEmbedded() const {
    9170             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9171             :   return script->context_data() ==
    9172       33727 :          script->GetReadOnlyRoots().uninitialized_symbol();
    9173             : }
    9174             : 
    9175      723528 : int debug::Script::Id() const { return Utils::OpenHandle(this)->id(); }
    9176             : 
    9177       55927 : int debug::Script::LineOffset() const {
    9178       55927 :   return Utils::OpenHandle(this)->line_offset();
    9179             : }
    9180             : 
    9181       55927 : int debug::Script::ColumnOffset() const {
    9182       55927 :   return Utils::OpenHandle(this)->column_offset();
    9183             : }
    9184             : 
    9185       55927 : std::vector<int> debug::Script::LineEnds() const {
    9186             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9187       55931 :   if (script->type() == i::Script::TYPE_WASM &&
    9188           4 :       this->SourceMappingURL().IsEmpty()) {
    9189             :     return std::vector<int>();
    9190             :   }
    9191             :   i::Isolate* isolate = script->GetIsolate();
    9192             :   i::HandleScope scope(isolate);
    9193       55927 :   i::Script::InitLineEnds(script);
    9194       55927 :   CHECK(script->line_ends()->IsFixedArray());
    9195             :   i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends()),
    9196             :                                      isolate);
    9197       55927 :   std::vector<int> result(line_ends->length());
    9198    17694059 :   for (int i = 0; i < line_ends->length(); ++i) {
    9199             :     i::Smi line_end = i::Smi::cast(line_ends->get(i));
    9200    17638132 :     result[i] = line_end->value();
    9201             :   }
    9202             :   return result;
    9203             : }
    9204             : 
    9205       53968 : MaybeLocal<String> debug::Script::Name() const {
    9206             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9207             :   i::HandleScope handle_scope(isolate);
    9208             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9209             :   i::Handle<i::Object> value(script->name(), isolate);
    9210       53968 :   if (!value->IsString()) return MaybeLocal<String>();
    9211             :   return Utils::ToLocal(
    9212       22897 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9213             : }
    9214             : 
    9215      112021 : MaybeLocal<String> debug::Script::SourceURL() const {
    9216             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9217             :   i::HandleScope handle_scope(isolate);
    9218             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9219             :   i::Handle<i::Object> value(script->source_url(), isolate);
    9220      112021 :   if (!value->IsString()) return MaybeLocal<String>();
    9221             :   return Utils::ToLocal(
    9222        4400 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9223             : }
    9224             : 
    9225       56091 : MaybeLocal<String> debug::Script::SourceMappingURL() const {
    9226             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9227             :   i::HandleScope handle_scope(isolate);
    9228             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9229             :   i::Handle<i::Object> value(script->source_mapping_url(), isolate);
    9230       56091 :   if (!value->IsString()) return MaybeLocal<String>();
    9231             :   return Utils::ToLocal(
    9232         538 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9233             : }
    9234             : 
    9235      123151 : Maybe<int> debug::Script::ContextId() const {
    9236             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9237             :   i::HandleScope handle_scope(isolate);
    9238             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9239             :   i::Object value = script->context_data();
    9240      123151 :   if (value->IsSmi()) return Just(i::Smi::ToInt(value));
    9241             :   return Nothing<int>();
    9242             : }
    9243             : 
    9244      134297 : MaybeLocal<String> debug::Script::Source() const {
    9245             :   i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
    9246             :   i::HandleScope handle_scope(isolate);
    9247             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9248             :   i::Handle<i::Object> value(script->source(), isolate);
    9249      134297 :   if (!value->IsString()) return MaybeLocal<String>();
    9250             :   return Utils::ToLocal(
    9251      134297 :       handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value)));
    9252             : }
    9253             : 
    9254       22322 : bool debug::Script::IsWasm() const {
    9255       22322 :   return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM;
    9256             : }
    9257             : 
    9258       55927 : bool debug::Script::IsModule() const {
    9259       55927 :   return Utils::OpenHandle(this)->origin_options().IsModule();
    9260             : }
    9261             : 
    9262             : namespace {
    9263             : int GetSmiValue(i::Handle<i::FixedArray> array, int index) {
    9264             :   return i::Smi::ToInt(array->get(index));
    9265             : }
    9266             : 
    9267       42030 : bool CompareBreakLocation(const i::BreakLocation& loc1,
    9268             :                           const i::BreakLocation& loc2) {
    9269       42030 :   return loc1.position() < loc2.position();
    9270             : }
    9271             : }  // namespace
    9272             : 
    9273         264 : bool debug::Script::GetPossibleBreakpoints(
    9274             :     const debug::Location& start, const debug::Location& end,
    9275             :     bool restrict_to_function,
    9276             :     std::vector<debug::BreakLocation>* locations) const {
    9277         264 :   CHECK(!start.IsEmpty());
    9278             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9279         288 :   if (script->type() == i::Script::TYPE_WASM &&
    9280          24 :       this->SourceMappingURL().IsEmpty()) {
    9281             :     i::WasmModuleObject module_object =
    9282          24 :         i::WasmModuleObject::cast(script->wasm_module_object());
    9283          24 :     return module_object->GetPossibleBreakpoints(start, end, locations);
    9284             :   }
    9285             : 
    9286         240 :   i::Script::InitLineEnds(script);
    9287         240 :   CHECK(script->line_ends()->IsFixedArray());
    9288             :   i::Isolate* isolate = script->GetIsolate();
    9289             :   i::Handle<i::FixedArray> line_ends =
    9290             :       i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
    9291         240 :   CHECK(line_ends->length());
    9292             : 
    9293         240 :   int start_offset = GetSourceOffset(start);
    9294             :   int end_offset = end.IsEmpty()
    9295         155 :                        ? GetSmiValue(line_ends, line_ends->length() - 1) + 1
    9296         395 :                        : GetSourceOffset(end);
    9297         240 :   if (start_offset >= end_offset) return true;
    9298             : 
    9299             :   std::vector<i::BreakLocation> v8_locations;
    9300         215 :   if (!isolate->debug()->GetPossibleBreakpoints(
    9301             :           script, start_offset, end_offset, restrict_to_function,
    9302             :           &v8_locations)) {
    9303             :     return false;
    9304             :   }
    9305             : 
    9306             :   std::sort(v8_locations.begin(), v8_locations.end(), CompareBreakLocation);
    9307             :   int current_line_end_index = 0;
    9308        5210 :   for (const auto& v8_location : v8_locations) {
    9309             :     int offset = v8_location.position();
    9310        8165 :     while (offset > GetSmiValue(line_ends, current_line_end_index)) {
    9311        3165 :       ++current_line_end_index;
    9312        3165 :       CHECK(current_line_end_index < line_ends->length());
    9313             :     }
    9314             :     int line_offset = 0;
    9315             : 
    9316        5000 :     if (current_line_end_index > 0) {
    9317        9100 :       line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1;
    9318             :     }
    9319       20000 :     locations->emplace_back(
    9320        5000 :         current_line_end_index + script->line_offset(),
    9321       10000 :         offset - line_offset +
    9322             :             (current_line_end_index == 0 ? script->column_offset() : 0),
    9323       10000 :         v8_location.type());
    9324             :   }
    9325             :   return true;
    9326             : }
    9327             : 
    9328        2928 : int debug::Script::GetSourceOffset(const debug::Location& location) const {
    9329             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9330        2928 :   if (script->type() == i::Script::TYPE_WASM) {
    9331         160 :     if (this->SourceMappingURL().IsEmpty()) {
    9332         152 :       return i::WasmModuleObject::cast(script->wasm_module_object())
    9333         152 :                  ->GetFunctionOffset(location.GetLineNumber()) +
    9334          76 :              location.GetColumnNumber();
    9335             :     }
    9336             :     DCHECK_EQ(0, location.GetLineNumber());
    9337           4 :     return location.GetColumnNumber();
    9338             :   }
    9339             : 
    9340        8544 :   int line = std::max(location.GetLineNumber() - script->line_offset(), 0);
    9341        2848 :   int column = location.GetColumnNumber();
    9342        2848 :   if (line == 0) {
    9343         788 :     column = std::max(0, column - script->column_offset());
    9344             :   }
    9345             : 
    9346        2848 :   i::Script::InitLineEnds(script);
    9347        2848 :   CHECK(script->line_ends()->IsFixedArray());
    9348             :   i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast(
    9349             :       i::handle(script->line_ends(), script->GetIsolate()));
    9350        2848 :   CHECK(line_ends->length());
    9351        2848 :   if (line >= line_ends->length())
    9352          15 :     return GetSmiValue(line_ends, line_ends->length() - 1);
    9353        2833 :   int line_offset = GetSmiValue(line_ends, line);
    9354        3227 :   if (line == 0) return std::min(column, line_offset);
    9355        2439 :   int prev_line_offset = GetSmiValue(line_ends, line - 1);
    9356        4878 :   return std::min(prev_line_offset + column + 1, line_offset);
    9357             : }
    9358             : 
    9359      461348 : v8::debug::Location debug::Script::GetSourceLocation(int offset) const {
    9360      461348 :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9361             :   i::Script::PositionInfo info;
    9362      461348 :   i::Script::GetPositionInfo(script, offset, &info, i::Script::WITH_OFFSET);
    9363      461348 :   return debug::Location(info.line, info.column);
    9364             : }
    9365             : 
    9366          50 : bool debug::Script::SetScriptSource(v8::Local<v8::String> newSource,
    9367             :                                     bool preview,
    9368             :                                     debug::LiveEditResult* result) const {
    9369             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9370             :   i::Isolate* isolate = script->GetIsolate();
    9371          50 :   return isolate->debug()->SetScriptSource(
    9372          50 :       script, Utils::OpenHandle(*newSource), preview, result);
    9373             : }
    9374             : 
    9375        2143 : bool debug::Script::SetBreakpoint(v8::Local<v8::String> condition,
    9376             :                                   debug::Location* location,
    9377             :                                   debug::BreakpointId* id) const {
    9378             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9379             :   i::Isolate* isolate = script->GetIsolate();
    9380        2143 :   int offset = GetSourceOffset(*location);
    9381        2143 :   if (!isolate->debug()->SetBreakPointForScript(
    9382             :           script, Utils::OpenHandle(*condition), &offset, id)) {
    9383             :     return false;
    9384             :   }
    9385        2113 :   *location = GetSourceLocation(offset);
    9386        2113 :   return true;
    9387             : }
    9388             : 
    9389        2203 : void debug::RemoveBreakpoint(Isolate* v8_isolate, BreakpointId id) {
    9390             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9391             :   i::HandleScope handle_scope(isolate);
    9392        2203 :   isolate->debug()->RemoveBreakpoint(id);
    9393        2203 : }
    9394             : 
    9395          30 : v8::Platform* debug::GetCurrentPlatform() {
    9396          30 :   return i::V8::GetCurrentPlatform();
    9397             : }
    9398             : 
    9399          52 : debug::WasmScript* debug::WasmScript::Cast(debug::Script* script) {
    9400          52 :   CHECK(script->IsWasm());
    9401          52 :   return static_cast<WasmScript*>(script);
    9402             : }
    9403             : 
    9404         136 : int debug::WasmScript::NumFunctions() const {
    9405             :   i::DisallowHeapAllocation no_gc;
    9406             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9407             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9408             :   i::WasmModuleObject module_object =
    9409         136 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9410             :   const i::wasm::WasmModule* module = module_object->module();
    9411             :   DCHECK_GE(i::kMaxInt, module->functions.size());
    9412         136 :   return static_cast<int>(module->functions.size());
    9413             : }
    9414             : 
    9415         136 : int debug::WasmScript::NumImportedFunctions() const {
    9416             :   i::DisallowHeapAllocation no_gc;
    9417             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9418             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9419             :   i::WasmModuleObject module_object =
    9420         136 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9421             :   const i::wasm::WasmModule* module = module_object->module();
    9422             :   DCHECK_GE(i::kMaxInt, module->num_imported_functions);
    9423         136 :   return static_cast<int>(module->num_imported_functions);
    9424             : }
    9425             : 
    9426           4 : std::pair<int, int> debug::WasmScript::GetFunctionRange(
    9427             :     int function_index) const {
    9428             :   i::DisallowHeapAllocation no_gc;
    9429             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9430             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9431             :   i::WasmModuleObject module_object =
    9432           4 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9433             :   const i::wasm::WasmModule* module = module_object->module();
    9434             :   DCHECK_LE(0, function_index);
    9435             :   DCHECK_GT(module->functions.size(), function_index);
    9436           4 :   const i::wasm::WasmFunction& func = module->functions[function_index];
    9437             :   DCHECK_GE(i::kMaxInt, func.code.offset());
    9438             :   DCHECK_GE(i::kMaxInt, func.code.end_offset());
    9439             :   return std::make_pair(static_cast<int>(func.code.offset()),
    9440           4 :                         static_cast<int>(func.code.end_offset()));
    9441             : }
    9442             : 
    9443          84 : uint32_t debug::WasmScript::GetFunctionHash(int function_index) {
    9444             :   i::DisallowHeapAllocation no_gc;
    9445             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9446             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9447             :   i::WasmModuleObject module_object =
    9448          84 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9449             :   const i::wasm::WasmModule* module = module_object->module();
    9450             :   DCHECK_LE(0, function_index);
    9451             :   DCHECK_GT(module->functions.size(), function_index);
    9452          84 :   const i::wasm::WasmFunction& func = module->functions[function_index];
    9453             :   i::wasm::ModuleWireBytes wire_bytes(
    9454          84 :       module_object->native_module()->wire_bytes());
    9455             :   i::Vector<const i::byte> function_bytes = wire_bytes.GetFunctionBytes(&func);
    9456             :   // TODO(herhut): Maybe also take module, name and signature into account.
    9457             :   return i::StringHasher::HashSequentialString(function_bytes.start(),
    9458          84 :                                                function_bytes.length(), 0);
    9459             : }
    9460             : 
    9461          76 : debug::WasmDisassembly debug::WasmScript::DisassembleFunction(
    9462             :     int function_index) const {
    9463             :   i::DisallowHeapAllocation no_gc;
    9464             :   i::Handle<i::Script> script = Utils::OpenHandle(this);
    9465             :   DCHECK_EQ(i::Script::TYPE_WASM, script->type());
    9466             :   i::WasmModuleObject module_object =
    9467          76 :       i::WasmModuleObject::cast(script->wasm_module_object());
    9468          76 :   return module_object->DisassembleFunction(function_index);
    9469             : }
    9470             : 
    9471       28352 : debug::Location::Location(int line_number, int column_number)
    9472             :     : line_number_(line_number),
    9473             :       column_number_(column_number),
    9474       33352 :       is_empty_(false) {}
    9475             : 
    9476         274 : debug::Location::Location()
    9477             :     : line_number_(v8::Function::kLineOffsetNotFound),
    9478             :       column_number_(v8::Function::kLineOffsetNotFound),
    9479         274 :       is_empty_(true) {}
    9480             : 
    9481      476629 : int debug::Location::GetLineNumber() const {
    9482             :   DCHECK(!IsEmpty());
    9483      479553 :   return line_number_;
    9484             : }
    9485             : 
    9486      472728 : int debug::Location::GetColumnNumber() const {
    9487             :   DCHECK(!IsEmpty());
    9488      475656 :   return column_number_;
    9489             : }
    9490             : 
    9491         932 : bool debug::Location::IsEmpty() const { return is_empty_; }
    9492             : 
    9493        3492 : void debug::GetLoadedScripts(v8::Isolate* v8_isolate,
    9494             :                              PersistentValueVector<debug::Script>& scripts) {
    9495             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9496             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9497             :   {
    9498             :     i::DisallowHeapAllocation no_gc;
    9499        3492 :     i::Script::Iterator iterator(isolate);
    9500       95818 :     for (i::Script script = iterator.Next(); !script.is_null();
    9501             :          script = iterator.Next()) {
    9502       44417 :       if (!script->IsUserJavaScript()) continue;
    9503       33835 :       if (script->HasValidSource()) {
    9504             :         i::HandleScope handle_scope(isolate);
    9505             :         i::Handle<i::Script> script_handle(script, isolate);
    9506       33835 :         scripts.Append(ToApiHandle<Script>(script_handle));
    9507             :       }
    9508             :     }
    9509             :   }
    9510        3492 : }
    9511             : 
    9512         306 : MaybeLocal<UnboundScript> debug::CompileInspectorScript(Isolate* v8_isolate,
    9513             :                                                         Local<String> source) {
    9514             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9515         918 :   PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript);
    9516         306 :   i::Handle<i::String> str = Utils::OpenHandle(*source);
    9517             :   i::Handle<i::SharedFunctionInfo> result;
    9518             :   {
    9519             :     ScriptOriginOptions origin_options;
    9520             :     i::ScriptData* script_data = nullptr;
    9521             :     i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
    9522             :         i::Compiler::GetSharedFunctionInfoForScript(
    9523             :             isolate, str, i::Compiler::ScriptDetails(), origin_options, nullptr,
    9524             :             script_data, ScriptCompiler::kNoCompileOptions,
    9525             :             ScriptCompiler::kNoCacheBecauseInspector,
    9526             :             i::FLAG_expose_inspector_scripts ? i::NOT_NATIVES_CODE
    9527         612 :                                              : i::INSPECTOR_CODE);
    9528             :     has_pending_exception = !maybe_function_info.ToHandle(&result);
    9529         306 :     RETURN_ON_FAILED_EXECUTION(UnboundScript);
    9530             :   }
    9531         301 :   RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
    9532             : }
    9533             : 
    9534        7873 : void debug::SetDebugDelegate(Isolate* v8_isolate,
    9535             :                              debug::DebugDelegate* delegate) {
    9536             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9537        7873 :   isolate->debug()->SetDebugDelegate(delegate);
    9538        7873 : }
    9539             : 
    9540         460 : void debug::SetAsyncEventDelegate(Isolate* v8_isolate,
    9541             :                                   debug::AsyncEventDelegate* delegate) {
    9542             :   reinterpret_cast<i::Isolate*>(v8_isolate)->set_async_event_delegate(delegate);
    9543         460 : }
    9544             : 
    9545      112020 : void debug::ResetBlackboxedStateCache(Isolate* v8_isolate,
    9546             :                                       v8::Local<debug::Script> script) {
    9547             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9548             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9549             :   i::DisallowHeapAllocation no_gc;
    9550             :   i::SharedFunctionInfo::ScriptIterator iter(isolate,
    9551      112020 :                                              *Utils::OpenHandle(*script));
    9552     2541184 :   for (i::SharedFunctionInfo info = iter.Next(); !info.is_null();
    9553             :        info = iter.Next()) {
    9554     1158572 :     if (info->HasDebugInfo()) {
    9555       18375 :       info->GetDebugInfo()->set_computed_debug_is_blackboxed(false);
    9556             :     }
    9557             :   }
    9558      112020 : }
    9559             : 
    9560        7050 : int debug::EstimatedValueSize(Isolate* v8_isolate, v8::Local<v8::Value> value) {
    9561             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9562             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9563             :   i::Handle<i::Object> object = Utils::OpenHandle(*value);
    9564        7050 :   if (object->IsSmi()) return i::kTaggedSize;
    9565        6305 :   CHECK(object->IsHeapObject());
    9566        6305 :   return i::Handle<i::HeapObject>::cast(object)->Size();
    9567             : }
    9568             : 
    9569       90233 : v8::MaybeLocal<v8::Array> v8::Object::PreviewEntries(bool* is_key_value) {
    9570       90233 :   if (IsMap()) {
    9571         108 :     *is_key_value = true;
    9572         108 :     return Map::Cast(this)->AsArray();
    9573             :   }
    9574       90125 :   if (IsSet()) {
    9575          89 :     *is_key_value = false;
    9576          89 :     return Set::Cast(this)->AsArray();
    9577             :   }
    9578             : 
    9579             :   i::Handle<i::JSReceiver> object = Utils::OpenHandle(this);
    9580             :   i::Isolate* isolate = object->GetIsolate();
    9581             :   Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
    9582             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9583       90036 :   if (object->IsJSWeakCollection()) {
    9584          98 :     *is_key_value = object->IsJSWeakMap();
    9585             :     return Utils::ToLocal(i::JSWeakCollection::GetEntries(
    9586          98 :         i::Handle<i::JSWeakCollection>::cast(object), 0));
    9587             :   }
    9588       89938 :   if (object->IsJSMapIterator()) {
    9589             :     i::Handle<i::JSMapIterator> it = i::Handle<i::JSMapIterator>::cast(object);
    9590             :     MapAsArrayKind const kind =
    9591         157 :         static_cast<MapAsArrayKind>(it->map()->instance_type());
    9592         157 :     *is_key_value = kind == MapAsArrayKind::kEntries;
    9593         157 :     if (!it->HasMore()) return v8::Array::New(v8_isolate);
    9594             :     return Utils::ToLocal(
    9595         122 :         MapAsArray(isolate, it->table(), i::Smi::ToInt(it->index()), kind));
    9596             :   }
    9597       89781 :   if (object->IsJSSetIterator()) {
    9598             :     i::Handle<i::JSSetIterator> it = i::Handle<i::JSSetIterator>::cast(object);
    9599             :     SetAsArrayKind const kind =
    9600         142 :         static_cast<SetAsArrayKind>(it->map()->instance_type());
    9601         142 :     *is_key_value = kind == SetAsArrayKind::kEntries;
    9602         142 :     if (!it->HasMore()) return v8::Array::New(v8_isolate);
    9603             :     return Utils::ToLocal(
    9604         127 :         SetAsArray(isolate, it->table(), i::Smi::ToInt(it->index()), kind));
    9605             :   }
    9606       89639 :   return v8::MaybeLocal<v8::Array>();
    9607             : }
    9608             : 
    9609           0 : Local<Function> debug::GetBuiltin(Isolate* v8_isolate, Builtin builtin) {
    9610             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9611             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9612             :   i::HandleScope handle_scope(isolate);
    9613             :   i::Builtins::Name builtin_id;
    9614           0 :   switch (builtin) {
    9615             :     case kStringToLowerCase:
    9616             :       builtin_id = i::Builtins::kStringPrototypeToLocaleLowerCase;
    9617             :       break;
    9618             :     default:
    9619           0 :       UNREACHABLE();
    9620             :   }
    9621             : 
    9622           0 :   i::Handle<i::String> name = isolate->factory()->empty_string();
    9623             :   i::NewFunctionArgs args = i::NewFunctionArgs::ForBuiltinWithoutPrototype(
    9624           0 :       name, builtin_id, i::LanguageMode::kStrict);
    9625           0 :   i::Handle<i::JSFunction> fun = isolate->factory()->NewFunction(args);
    9626             : 
    9627             :   fun->shared()->set_internal_formal_parameter_count(0);
    9628             :   fun->shared()->set_length(0);
    9629           0 :   return Utils::ToLocal(handle_scope.CloseAndEscape(fun));
    9630             : }
    9631             : 
    9632       37837 : void debug::SetConsoleDelegate(Isolate* v8_isolate, ConsoleDelegate* delegate) {
    9633             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9634             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9635             :   isolate->set_console_delegate(delegate);
    9636       37837 : }
    9637             : 
    9638         425 : debug::ConsoleCallArguments::ConsoleCallArguments(
    9639             :     const v8::FunctionCallbackInfo<v8::Value>& info)
    9640         425 :     : v8::FunctionCallbackInfo<v8::Value>(nullptr, info.values_, info.length_) {
    9641         425 : }
    9642             : 
    9643       12737 : debug::ConsoleCallArguments::ConsoleCallArguments(
    9644             :     internal::BuiltinArguments& args)
    9645             :     : v8::FunctionCallbackInfo<v8::Value>(
    9646             :           nullptr,
    9647             :           // Drop the first argument (receiver, i.e. the "console" object).
    9648             :           args.address_of_arg_at(args.length() > 1 ? 1 : 0),
    9649       25474 :           args.length() - 1) {}
    9650             : 
    9651        5755 : int debug::GetStackFrameId(v8::Local<v8::StackFrame> frame) {
    9652        5755 :   return Utils::OpenHandle(*frame)->id();
    9653             : }
    9654             : 
    9655          15 : v8::Local<v8::StackTrace> debug::GetDetailedStackTrace(
    9656             :     Isolate* v8_isolate, v8::Local<v8::Object> v8_error) {
    9657             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9658             :   i::Handle<i::JSReceiver> error = Utils::OpenHandle(*v8_error);
    9659          15 :   if (!error->IsJSObject()) {
    9660           0 :     return v8::Local<v8::StackTrace>();
    9661             :   }
    9662             :   i::Handle<i::FixedArray> stack_trace =
    9663          15 :       isolate->GetDetailedStackTrace(i::Handle<i::JSObject>::cast(error));
    9664             :   return Utils::StackTraceToLocal(stack_trace);
    9665             : }
    9666             : 
    9667          40 : MaybeLocal<debug::Script> debug::GeneratorObject::Script() {
    9668             :   i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
    9669          40 :   i::Object maybe_script = obj->function()->shared()->script();
    9670          40 :   if (!maybe_script->IsScript()) return MaybeLocal<debug::Script>();
    9671             :   i::Handle<i::Script> script(i::Script::cast(maybe_script), obj->GetIsolate());
    9672          40 :   return ToApiHandle<debug::Script>(script);
    9673             : }
    9674             : 
    9675          10 : Local<Function> debug::GeneratorObject::Function() {
    9676             :   i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
    9677          10 :   return Utils::ToLocal(handle(obj->function(), obj->GetIsolate()));
    9678             : }
    9679             : 
    9680          40 : debug::Location debug::GeneratorObject::SuspendedLocation() {
    9681             :   i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
    9682          40 :   CHECK(obj->is_suspended());
    9683          40 :   i::Object maybe_script = obj->function()->shared()->script();
    9684          40 :   if (!maybe_script->IsScript()) return debug::Location();
    9685             :   i::Isolate* isolate = obj->GetIsolate();
    9686             :   i::Handle<i::Script> script(i::Script::cast(maybe_script), isolate);
    9687             :   i::Script::PositionInfo info;
    9688             :   i::SharedFunctionInfo::EnsureSourcePositionsAvailable(
    9689          40 :       isolate, i::handle(obj->function()->shared(), isolate));
    9690          80 :   i::Script::GetPositionInfo(script, obj->source_position(), &info,
    9691          40 :                              i::Script::WITH_OFFSET);
    9692          40 :   return debug::Location(info.line, info.column);
    9693             : }
    9694             : 
    9695         100 : bool debug::GeneratorObject::IsSuspended() {
    9696         100 :   return Utils::OpenHandle(this)->is_suspended();
    9697             : }
    9698             : 
    9699         100 : v8::Local<debug::GeneratorObject> debug::GeneratorObject::Cast(
    9700             :     v8::Local<v8::Value> value) {
    9701         100 :   CHECK(value->IsGeneratorObject());
    9702         100 :   return ToApiHandle<debug::GeneratorObject>(Utils::OpenHandle(*value));
    9703             : }
    9704             : 
    9705        9228 : MaybeLocal<v8::Value> debug::EvaluateGlobal(v8::Isolate* isolate,
    9706             :                                             v8::Local<v8::String> source,
    9707             :                                             bool throw_on_side_effect) {
    9708             :   i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9709       27684 :   PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(internal_isolate, Value);
    9710             :   Local<Value> result;
    9711       18456 :   has_pending_exception = !ToLocal<Value>(
    9712             :       i::DebugEvaluate::Global(internal_isolate, Utils::OpenHandle(*source),
    9713             :                                throw_on_side_effect),
    9714             :       &result);
    9715        9228 :   RETURN_ON_FAILED_EXECUTION(Value);
    9716        8693 :   RETURN_ESCAPED(result);
    9717             : }
    9718             : 
    9719          85 : void debug::QueryObjects(v8::Local<v8::Context> v8_context,
    9720             :                          QueryObjectPredicate* predicate,
    9721             :                          PersistentValueVector<v8::Object>* objects) {
    9722             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_context->GetIsolate());
    9723             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
    9724             :   isolate->heap_profiler()->QueryObjects(Utils::OpenHandle(*v8_context),
    9725          85 :                                          predicate, objects);
    9726          85 : }
    9727             : 
    9728          35 : void debug::GlobalLexicalScopeNames(
    9729             :     v8::Local<v8::Context> v8_context,
    9730             :     v8::PersistentValueVector<v8::String>* names) {
    9731             :   i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
    9732             :   i::Isolate* isolate = context->GetIsolate();
    9733             :   i::Handle<i::ScriptContextTable> table(
    9734         105 :       context->global_object()->native_context()->script_context_table(),
    9735          35 :       isolate);
    9736         305 :   for (int i = 0; i < table->used(); i++) {
    9737             :     i::Handle<i::Context> context =
    9738         135 :         i::ScriptContextTable::GetContext(isolate, table, i);
    9739             :     DCHECK(context->IsScriptContext());
    9740         270 :     i::Handle<i::ScopeInfo> scope_info(context->scope_info(), isolate);
    9741         135 :     int local_count = scope_info->ContextLocalCount();
    9742         435 :     for (int j = 0; j < local_count; ++j) {
    9743         150 :       i::String name = scope_info->ContextLocalName(j);
    9744         185 :       if (i::ScopeInfo::VariableIsSynthetic(name)) continue;
    9745         115 :       names->Append(Utils::ToLocal(handle(name, isolate)));
    9746             :     }
    9747             :   }
    9748          35 : }
    9749             : 
    9750          10 : void debug::SetReturnValue(v8::Isolate* v8_isolate,
    9751             :                            v8::Local<v8::Value> value) {
    9752             :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
    9753             :   isolate->debug()->set_return_value(*Utils::OpenHandle(*value));
    9754          10 : }
    9755             : 
    9756       10272 : int64_t debug::GetNextRandomInt64(v8::Isolate* v8_isolate) {
    9757             :   return reinterpret_cast<i::Isolate*>(v8_isolate)
    9758             :       ->random_number_generator()
    9759       10272 :       ->NextInt64();
    9760             : }
    9761             : 
    9762         170 : int debug::GetDebuggingId(v8::Local<v8::Function> function) {
    9763             :   i::Handle<i::JSReceiver> callable = v8::Utils::OpenHandle(*function);
    9764         170 :   if (!callable->IsJSFunction()) return i::DebugInfo::kNoDebuggingId;
    9765             :   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(callable);
    9766         170 :   int id = func->GetIsolate()->debug()->GetFunctionDebuggingId(func);
    9767             :   DCHECK_NE(i::DebugInfo::kNoDebuggingId, id);
    9768         170 :   return id;
    9769             : }
    9770             : 
    9771          95 : bool debug::SetFunctionBreakpoint(v8::Local<v8::Function> function,
    9772             :                                   v8::Local<v8::String> condition,
    9773             :                                   BreakpointId* id) {
    9774             :   i::Handle<i::JSReceiver> callable = Utils::OpenHandle(*function);
    9775          95 :   if (!callable->IsJSFunction()) return false;
    9776             :   i::Handle<i::JSFunction> jsfunction =
    9777             :       i::Handle<i::JSFunction>::cast(callable);
    9778             :   i::Isolate* isolate = jsfunction->GetIsolate();
    9779             :   i::Handle<i::String> condition_string =
    9780             :       condition.IsEmpty() ? isolate->factory()->empty_string()
    9781         140 :                           : Utils::OpenHandle(*condition);
    9782             :   return isolate->debug()->SetBreakpointForFunction(jsfunction,
    9783          95 :                                                     condition_string, id);
    9784             : }
    9785             : 
    9786           0 : debug::PostponeInterruptsScope::PostponeInterruptsScope(v8::Isolate* isolate)
    9787             :     : scope_(
    9788             :           new i::PostponeInterruptsScope(reinterpret_cast<i::Isolate*>(isolate),
    9789           0 :                                          i::StackGuard::API_INTERRUPT)) {}
    9790             : 
    9791             : debug::PostponeInterruptsScope::~PostponeInterruptsScope() = default;
    9792             : 
    9793        1947 : Local<String> CpuProfileNode::GetFunctionName() const {
    9794             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9795             :   i::Isolate* isolate = node->isolate();
    9796             :   const i::CodeEntry* entry = node->entry();
    9797             :   i::Handle<i::String> name =
    9798        1947 :       isolate->factory()->InternalizeUtf8String(entry->name());
    9799        1947 :   return ToApiHandle<String>(name);
    9800             : }
    9801             : 
    9802          32 : int debug::Coverage::BlockData::StartOffset() const { return block_->start; }
    9803          32 : int debug::Coverage::BlockData::EndOffset() const { return block_->end; }
    9804          32 : uint32_t debug::Coverage::BlockData::Count() const { return block_->count; }
    9805             : 
    9806         420 : int debug::Coverage::FunctionData::StartOffset() const {
    9807         420 :   return function_->start;
    9808             : }
    9809         420 : int debug::Coverage::FunctionData::EndOffset() const { return function_->end; }
    9810         410 : uint32_t debug::Coverage::FunctionData::Count() const {
    9811         410 :   return function_->count;
    9812             : }
    9813             : 
    9814         380 : MaybeLocal<String> debug::Coverage::FunctionData::Name() const {
    9815         380 :   return ToApiHandle<String>(function_->name);
    9816             : }
    9817             : 
    9818         412 : size_t debug::Coverage::FunctionData::BlockCount() const {
    9819         824 :   return function_->blocks.size();
    9820             : }
    9821             : 
    9822         380 : bool debug::Coverage::FunctionData::HasBlockCoverage() const {
    9823         380 :   return function_->has_block_coverage;
    9824             : }
    9825             : 
    9826          32 : debug::Coverage::BlockData debug::Coverage::FunctionData::GetBlockData(
    9827             :     size_t i) const {
    9828          64 :   return BlockData(&function_->blocks.at(i), coverage_);
    9829             : }
    9830             : 
    9831         170 : Local<debug::Script> debug::Coverage::ScriptData::GetScript() const {
    9832         170 :   return ToApiHandle<debug::Script>(script_->script);
    9833             : }
    9834             : 
    9835         555 : size_t debug::Coverage::ScriptData::FunctionCount() const {
    9836        1110 :   return script_->functions.size();
    9837             : }
    9838             : 
    9839         405 : debug::Coverage::FunctionData debug::Coverage::ScriptData::GetFunctionData(
    9840             :     size_t i) const {
    9841         810 :   return FunctionData(&script_->functions.at(i), coverage_);
    9842             : }
    9843             : 
    9844         175 : debug::Coverage::ScriptData::ScriptData(size_t index,
    9845             :                                         std::shared_ptr<i::Coverage> coverage)
    9846         350 :     : script_(&coverage->at(index)), coverage_(std::move(coverage)) {}
    9847             : 
    9848         622 : size_t debug::Coverage::ScriptCount() const { return coverage_->size(); }
    9849             : 
    9850         175 : debug::Coverage::ScriptData debug::Coverage::GetScriptData(size_t i) const {
    9851         350 :   return ScriptData(i, coverage_);
    9852             : }
    9853             : 
    9854         103 : debug::Coverage debug::Coverage::CollectPrecise(Isolate* isolate) {
    9855             :   return Coverage(
    9856         206 :       i::Coverage::CollectPrecise(reinterpret_cast<i::Isolate*>(isolate)));
    9857             : }
    9858             : 
    9859          48 : debug::Coverage debug::Coverage::CollectBestEffort(Isolate* isolate) {
    9860             :   return Coverage(
    9861          96 :       i::Coverage::CollectBestEffort(reinterpret_cast<i::Isolate*>(isolate)));
    9862             : }
    9863             : 
    9864         309 : void debug::Coverage::SelectMode(Isolate* isolate, debug::CoverageMode mode) {
    9865         309 :   i::Coverage::SelectMode(reinterpret_cast<i::Isolate*>(isolate), mode);
    9866         309 : }
    9867             : 
    9868         148 : int debug::TypeProfile::Entry::SourcePosition() const {
    9869         148 :   return entry_->position;
    9870             : }
    9871             : 
    9872         148 : std::vector<MaybeLocal<String>> debug::TypeProfile::Entry::Types() const {
    9873             :   std::vector<MaybeLocal<String>> result;
    9874         148 :   for (const internal::Handle<internal::String>& type : entry_->types) {
    9875         196 :     result.emplace_back(ToApiHandle<String>(type));
    9876             :   }
    9877         148 :   return result;
    9878             : }
    9879             : 
    9880          32 : debug::TypeProfile::ScriptData::ScriptData(
    9881             :     size_t index, std::shared_ptr<i::TypeProfile> type_profile)
    9882             :     : script_(&type_profile->at(index)),
    9883          64 :       type_profile_(std::move(type_profile)) {}
    9884             : 
    9885          32 : Local<debug::Script> debug::TypeProfile::ScriptData::GetScript() const {
    9886          32 :   return ToApiHandle<debug::Script>(script_->script);
    9887             : }
    9888             : 
    9889          32 : std::vector<debug::TypeProfile::Entry> debug::TypeProfile::ScriptData::Entries()
    9890             :     const {
    9891             :   std::vector<debug::TypeProfile::Entry> result;
    9892         212 :   for (const internal::TypeProfileEntry& entry : script_->entries) {
    9893         296 :     result.push_back(debug::TypeProfile::Entry(&entry, type_profile_));
    9894             :   }
    9895          32 :   return result;
    9896             : }
    9897             : 
    9898          40 : debug::TypeProfile debug::TypeProfile::Collect(Isolate* isolate) {
    9899             :   return TypeProfile(
    9900          80 :       i::TypeProfile::Collect(reinterpret_cast<i::Isolate*>(isolate)));
    9901             : }
    9902             : 
    9903         100 : void debug::TypeProfile::SelectMode(Isolate* isolate,
    9904             :                                     debug::TypeProfileMode mode) {
    9905         100 :   i::TypeProfile::SelectMode(reinterpret_cast<i::Isolate*>(isolate), mode);
    9906         100 : }
    9907             : 
    9908         144 : size_t debug::TypeProfile::ScriptCount() const { return type_profile_->size(); }
    9909             : 
    9910          32 : debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData(
    9911             :     size_t i) const {
    9912          64 :   return ScriptData(i, type_profile_);
    9913             : }
    9914             : 
    9915        2431 : v8::MaybeLocal<v8::Value> debug::WeakMap::Get(v8::Local<v8::Context> context,
    9916             :                                               v8::Local<v8::Value> key) {
    9917        9724 :   PREPARE_FOR_EXECUTION(context, WeakMap, Get, Value);
    9918             :   auto self = Utils::OpenHandle(this);
    9919             :   Local<Value> result;
    9920        2431 :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
    9921             :   has_pending_exception =
    9922        7293 :       !ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(), self,
    9923             :                                          arraysize(argv), argv),
    9924             :                       &result);
    9925        2431 :   RETURN_ON_FAILED_EXECUTION(Value);
    9926        2431 :   RETURN_ESCAPED(result);
    9927             : }
    9928             : 
    9929       10832 : v8::MaybeLocal<debug::WeakMap> debug::WeakMap::Set(
    9930             :     v8::Local<v8::Context> context, v8::Local<v8::Value> key,
    9931             :     v8::Local<v8::Value> value) {
    9932       43328 :   PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap);
    9933             :   auto self = Utils::OpenHandle(this);
    9934             :   i::Handle<i::Object> result;
    9935             :   i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
    9936       21664 :                                  Utils::OpenHandle(*value)};
    9937       21664 :   has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(),
    9938       21664 :                                               self, arraysize(argv), argv)
    9939             :                                .ToHandle(&result);
    9940       10832 :   RETURN_ON_FAILED_EXECUTION(WeakMap);
    9941       10832 :   RETURN_ESCAPED(Local<WeakMap>::Cast(Utils::ToLocal(result)));
    9942             : }
    9943             : 
    9944          64 : Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) {
    9945             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
    9946          64 :   LOG_API(i_isolate, WeakMap, New);
    9947             :   ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
    9948          64 :   i::Handle<i::JSWeakMap> obj = i_isolate->factory()->NewJSWeakMap();
    9949          64 :   return ToApiHandle<debug::WeakMap>(obj);
    9950             : }
    9951             : 
    9952             : debug::WeakMap* debug::WeakMap::Cast(v8::Value* value) {
    9953             :   return static_cast<debug::WeakMap*>(value);
    9954             : }
    9955             : 
    9956         261 : const char* CpuProfileNode::GetFunctionNameStr() const {
    9957             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9958         261 :   return node->entry()->name();
    9959             : }
    9960             : 
    9961         382 : int CpuProfileNode::GetScriptId() const {
    9962             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9963             :   const i::CodeEntry* entry = node->entry();
    9964         382 :   return entry->script_id();
    9965             : }
    9966             : 
    9967         372 : Local<String> CpuProfileNode::GetScriptResourceName() const {
    9968             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9969             :   i::Isolate* isolate = node->isolate();
    9970             :   return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
    9971         372 :       node->entry()->resource_name()));
    9972             : }
    9973             : 
    9974          25 : const char* CpuProfileNode::GetScriptResourceNameStr() const {
    9975             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9976          25 :   return node->entry()->resource_name();
    9977             : }
    9978             : 
    9979           0 : bool CpuProfileNode::IsScriptSharedCrossOrigin() const {
    9980             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9981           0 :   return node->entry()->is_shared_cross_origin();
    9982             : }
    9983             : 
    9984         567 : int CpuProfileNode::GetLineNumber() const {
    9985         567 :   return reinterpret_cast<const i::ProfileNode*>(this)->line_number();
    9986             : }
    9987             : 
    9988             : 
    9989         372 : int CpuProfileNode::GetColumnNumber() const {
    9990             :   return reinterpret_cast<const i::ProfileNode*>(this)->
    9991         372 :       entry()->column_number();
    9992             : }
    9993             : 
    9994             : 
    9995         347 : unsigned int CpuProfileNode::GetHitLineCount() const {
    9996             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
    9997         347 :   return node->GetHitLineCount();
    9998             : }
    9999             : 
   10000             : 
   10001          22 : bool CpuProfileNode::GetLineTicks(LineTick* entries,
   10002             :                                   unsigned int length) const {
   10003             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
   10004          22 :   return node->GetLineTicks(entries, length);
   10005             : }
   10006             : 
   10007             : 
   10008         352 : const char* CpuProfileNode::GetBailoutReason() const {
   10009             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
   10010         352 :   return node->entry()->bailout_reason();
   10011             : }
   10012             : 
   10013             : 
   10014         357 : unsigned CpuProfileNode::GetHitCount() const {
   10015         357 :   return reinterpret_cast<const i::ProfileNode*>(this)->self_ticks();
   10016             : }
   10017             : 
   10018             : 
   10019           0 : unsigned CpuProfileNode::GetCallUid() const {
   10020           0 :   return reinterpret_cast<const i::ProfileNode*>(this)->function_id();
   10021             : }
   10022             : 
   10023             : 
   10024         744 : unsigned CpuProfileNode::GetNodeId() const {
   10025         744 :   return reinterpret_cast<const i::ProfileNode*>(this)->id();
   10026             : }
   10027             : 
   10028             : 
   10029        2364 : int CpuProfileNode::GetChildrenCount() const {
   10030             :   return static_cast<int>(
   10031        2364 :       reinterpret_cast<const i::ProfileNode*>(this)->children()->size());
   10032             : }
   10033             : 
   10034             : 
   10035        2225 : const CpuProfileNode* CpuProfileNode::GetChild(int index) const {
   10036             :   const i::ProfileNode* child =
   10037        4450 :       reinterpret_cast<const i::ProfileNode*>(this)->children()->at(index);
   10038        2225 :   return reinterpret_cast<const CpuProfileNode*>(child);
   10039             : }
   10040             : 
   10041          33 : const CpuProfileNode* CpuProfileNode::GetParent() const {
   10042             :   const i::ProfileNode* parent =
   10043             :       reinterpret_cast<const i::ProfileNode*>(this)->parent();
   10044          33 :   return reinterpret_cast<const CpuProfileNode*>(parent);
   10045             : }
   10046             : 
   10047           0 : const std::vector<CpuProfileDeoptInfo>& CpuProfileNode::GetDeoptInfos() const {
   10048             :   const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
   10049           0 :   return node->deopt_infos();
   10050             : }
   10051             : 
   10052             : 
   10053         754 : void CpuProfile::Delete() {
   10054             :   i::CpuProfile* profile = reinterpret_cast<i::CpuProfile*>(this);
   10055             :   i::CpuProfiler* profiler = profile->cpu_profiler();
   10056             :   DCHECK_NOT_NULL(profiler);
   10057         754 :   profiler->DeleteProfile(profile);
   10058         754 : }
   10059             : 
   10060             : 
   10061           0 : Local<String> CpuProfile::GetTitle() const {
   10062             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10063             :   i::Isolate* isolate = profile->top_down()->isolate();
   10064             :   return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
   10065           0 :       profile->title()));
   10066             : }
   10067             : 
   10068             : 
   10069         240 : const CpuProfileNode* CpuProfile::GetTopDownRoot() const {
   10070             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10071         240 :   return reinterpret_cast<const CpuProfileNode*>(profile->top_down()->root());
   10072             : }
   10073             : 
   10074             : 
   10075        6428 : const CpuProfileNode* CpuProfile::GetSample(int index) const {
   10076             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10077        6428 :   return reinterpret_cast<const CpuProfileNode*>(profile->sample(index).node);
   10078             : }
   10079             : 
   10080             : 
   10081        6428 : int64_t CpuProfile::GetSampleTimestamp(int index) const {
   10082             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10083       12856 :   return (profile->sample(index).timestamp - base::TimeTicks())
   10084       12856 :       .InMicroseconds();
   10085             : }
   10086             : 
   10087             : 
   10088         290 : int64_t CpuProfile::GetStartTime() const {
   10089             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10090         290 :   return (profile->start_time() - base::TimeTicks()).InMicroseconds();
   10091             : }
   10092             : 
   10093             : 
   10094         150 : int64_t CpuProfile::GetEndTime() const {
   10095             :   const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
   10096         150 :   return (profile->end_time() - base::TimeTicks()).InMicroseconds();
   10097             : }
   10098             : 
   10099             : 
   10100        6533 : int CpuProfile::GetSamplesCount() const {
   10101        6533 :   return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
   10102             : }
   10103             : 
   10104         196 : CpuProfiler* CpuProfiler::New(Isolate* isolate) {
   10105             :   return reinterpret_cast<CpuProfiler*>(
   10106         196 :       new i::CpuProfiler(reinterpret_cast<i::Isolate*>(isolate)));
   10107             : }
   10108             : 
   10109         196 : void CpuProfiler::Dispose() { delete reinterpret_cast<i::CpuProfiler*>(this); }
   10110             : 
   10111             : // static
   10112          10 : void CpuProfiler::CollectSample(Isolate* isolate) {
   10113          10 :   i::CpuProfiler::CollectSample(reinterpret_cast<i::Isolate*>(isolate));
   10114          10 : }
   10115             : 
   10116         560 : void CpuProfiler::SetSamplingInterval(int us) {
   10117             :   DCHECK_GE(us, 0);
   10118         560 :   return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
   10119         560 :       base::TimeDelta::FromMicroseconds(us));
   10120             : }
   10121             : 
   10122           0 : void CpuProfiler::CollectSample() {
   10123           0 :   reinterpret_cast<i::CpuProfiler*>(this)->CollectSample();
   10124           0 : }
   10125             : 
   10126         276 : void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
   10127         276 :   reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
   10128         276 :       *Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers);
   10129         276 : }
   10130             : 
   10131         565 : void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
   10132             :                                  bool record_samples) {
   10133         565 :   reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
   10134         565 :       *Utils::OpenHandle(*title), record_samples, mode);
   10135         565 : }
   10136             : 
   10137         806 : CpuProfile* CpuProfiler::StopProfiling(Local<String> title) {
   10138             :   return reinterpret_cast<CpuProfile*>(
   10139             :       reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
   10140         806 :           *Utils::OpenHandle(*title)));
   10141             : }
   10142             : 
   10143             : 
   10144           0 : void CpuProfiler::SetIdle(bool is_idle) {
   10145             :   i::CpuProfiler* profiler = reinterpret_cast<i::CpuProfiler*>(this);
   10146             :   i::Isolate* isolate = profiler->isolate();
   10147           0 :   isolate->SetIdle(is_idle);
   10148           0 : }
   10149             : 
   10150          10 : void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) {
   10151             :   reinterpret_cast<i::Isolate*>(isolate)
   10152             :       ->set_detailed_source_positions_for_profiling(true);
   10153          10 : }
   10154             : 
   10155           0 : uintptr_t CodeEvent::GetCodeStartAddress() {
   10156           0 :   return reinterpret_cast<i::CodeEvent*>(this)->code_start_address;
   10157             : }
   10158             : 
   10159           0 : size_t CodeEvent::GetCodeSize() {
   10160           0 :   return reinterpret_cast<i::CodeEvent*>(this)->code_size;
   10161             : }
   10162             : 
   10163         111 : Local<String> CodeEvent::GetFunctionName() {
   10164             :   return ToApiHandle<String>(
   10165         111 :       reinterpret_cast<i::CodeEvent*>(this)->function_name);
   10166             : }
   10167             : 
   10168           0 : Local<String> CodeEvent::GetScriptName() {
   10169             :   return ToApiHandle<String>(
   10170           0 :       reinterpret_cast<i::CodeEvent*>(this)->script_name);
   10171             : }
   10172             : 
   10173           0 : int CodeEvent::GetScriptLine() {
   10174           0 :   return reinterpret_cast<i::CodeEvent*>(this)->script_line;
   10175             : }
   10176             : 
   10177           0 : int CodeEvent::GetScriptColumn() {
   10178           0 :   return reinterpret_cast<i::CodeEvent*>(this)->script_column;
   10179             : }
   10180             : 
   10181       19896 : CodeEventType CodeEvent::GetCodeType() {
   10182       19896 :   return reinterpret_cast<i::CodeEvent*>(this)->code_type;
   10183             : }
   10184             : 
   10185       19896 : const char* CodeEvent::GetComment() {
   10186       19896 :   return reinterpret_cast<i::CodeEvent*>(this)->comment;
   10187             : }
   10188             : 
   10189       19896 : const char* CodeEvent::GetCodeEventTypeName(CodeEventType code_event_type) {
   10190       19896 :   switch (code_event_type) {
   10191             :     case kUnknownType:
   10192             :       return "Unknown";
   10193             : #define V(Name)       \
   10194             :   case k##Name##Type: \
   10195             :     return #Name;
   10196       19779 :       CODE_EVENTS_LIST(V)
   10197             : #undef V
   10198             :   }
   10199             :   // The execution should never pass here
   10200           0 :   UNREACHABLE();
   10201             :   // NOTE(mmarchini): Workaround to fix a compiler failure on GCC 4.9
   10202             :   return "Unknown";
   10203             : }
   10204             : 
   10205          19 : CodeEventHandler::CodeEventHandler(Isolate* isolate) {
   10206             :   internal_listener_ =
   10207          19 :       new i::ExternalCodeEventListener(reinterpret_cast<i::Isolate*>(isolate));
   10208          19 : }
   10209             : 
   10210          38 : CodeEventHandler::~CodeEventHandler() {
   10211          19 :   delete reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_);
   10212          19 : }
   10213             : 
   10214          19 : void CodeEventHandler::Enable() {
   10215          19 :   reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_)
   10216          19 :       ->StartListening(this);
   10217          19 : }
   10218             : 
   10219           0 : void CodeEventHandler::Disable() {
   10220           0 :   reinterpret_cast<i::ExternalCodeEventListener*>(internal_listener_)
   10221           0 :       ->StopListening();
   10222           0 : }
   10223             : 
   10224             : static i::HeapGraphEdge* ToInternal(const HeapGraphEdge* edge) {
   10225             :   return const_cast<i::HeapGraphEdge*>(
   10226             :       reinterpret_cast<const i::HeapGraphEdge*>(edge));
   10227             : }
   10228             : 
   10229             : 
   10230     6054677 : HeapGraphEdge::Type HeapGraphEdge::GetType() const {
   10231     6054677 :   return static_cast<HeapGraphEdge::Type>(ToInternal(this)->type());
   10232             : }
   10233             : 
   10234             : 
   10235     6005642 : Local<Value> HeapGraphEdge::GetName() const {
   10236             :   i::HeapGraphEdge* edge = ToInternal(this);
   10237             :   i::Isolate* isolate = edge->isolate();
   10238             :   switch (edge->type()) {
   10239             :     case i::HeapGraphEdge::kContextVariable:
   10240             :     case i::HeapGraphEdge::kInternal:
   10241             :     case i::HeapGraphEdge::kProperty:
   10242             :     case i::HeapGraphEdge::kShortcut:
   10243             :     case i::HeapGraphEdge::kWeak:
   10244             :       return ToApiHandle<String>(
   10245     6005393 :           isolate->factory()->InternalizeUtf8String(edge->name()));
   10246             :     case i::HeapGraphEdge::kElement:
   10247             :     case i::HeapGraphEdge::kHidden:
   10248             :       return ToApiHandle<Number>(
   10249         249 :           isolate->factory()->NewNumberFromInt(edge->index()));
   10250           0 :     default: UNREACHABLE();
   10251             :   }
   10252             :   return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
   10253             : }
   10254             : 
   10255             : 
   10256         339 : const HeapGraphNode* HeapGraphEdge::GetFromNode() const {
   10257             :   const i::HeapEntry* from = ToInternal(this)->from();
   10258         339 :   return reinterpret_cast<const HeapGraphNode*>(from);
   10259             : }
   10260             : 
   10261             : 
   10262      657263 : const HeapGraphNode* HeapGraphEdge::GetToNode() const {
   10263             :   const i::HeapEntry* to = ToInternal(this)->to();
   10264      657263 :   return reinterpret_cast<const HeapGraphNode*>(to);
   10265             : }
   10266             : 
   10267             : 
   10268             : static i::HeapEntry* ToInternal(const HeapGraphNode* entry) {
   10269             :   return const_cast<i::HeapEntry*>(
   10270             :       reinterpret_cast<const i::HeapEntry*>(entry));
   10271             : }
   10272             : 
   10273             : 
   10274         370 : HeapGraphNode::Type HeapGraphNode::GetType() const {
   10275         370 :   return static_cast<HeapGraphNode::Type>(ToInternal(this)->type());
   10276             : }
   10277             : 
   10278             : 
   10279        1115 : Local<String> HeapGraphNode::GetName() const {
   10280             :   i::Isolate* isolate = ToInternal(this)->isolate();
   10281             :   return ToApiHandle<String>(
   10282        1115 :       isolate->factory()->InternalizeUtf8String(ToInternal(this)->name()));
   10283             : }
   10284             : 
   10285             : 
   10286      552821 : SnapshotObjectId HeapGraphNode::GetId() const {
   10287      552821 :   return ToInternal(this)->id();
   10288             : }
   10289             : 
   10290             : 
   10291          20 : size_t HeapGraphNode::GetShallowSize() const {
   10292          20 :   return ToInternal(this)->self_size();
   10293             : }
   10294             : 
   10295             : 
   10296       60829 : int HeapGraphNode::GetChildrenCount() const {
   10297       60829 :   return ToInternal(this)->children_count();
   10298             : }
   10299             : 
   10300             : 
   10301     6340104 : const HeapGraphEdge* HeapGraphNode::GetChild(int index) const {
   10302     6340104 :   return reinterpret_cast<const HeapGraphEdge*>(ToInternal(this)->child(index));
   10303             : }
   10304             : 
   10305             : 
   10306             : static i::HeapSnapshot* ToInternal(const HeapSnapshot* snapshot) {
   10307             :   return const_cast<i::HeapSnapshot*>(
   10308             :       reinterpret_cast<const i::HeapSnapshot*>(snapshot));
   10309             : }
   10310             : 
   10311             : 
   10312          40 : void HeapSnapshot::Delete() {
   10313          40 :   i::Isolate* isolate = ToInternal(this)->profiler()->isolate();
   10314          40 :   if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
   10315           5 :     ToInternal(this)->Delete();
   10316             :   } else {
   10317             :     // If this is the last snapshot, clean up all accessory data as well.
   10318          35 :     isolate->heap_profiler()->DeleteAllSnapshots();
   10319             :   }
   10320          40 : }
   10321             : 
   10322             : 
   10323         299 : const HeapGraphNode* HeapSnapshot::GetRoot() const {
   10324         299 :   return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
   10325             : }
   10326             : 
   10327             : 
   10328      183059 : const HeapGraphNode* HeapSnapshot::GetNodeById(SnapshotObjectId id) const {
   10329             :   return reinterpret_cast<const HeapGraphNode*>(
   10330      183059 :       ToInternal(this)->GetEntryById(id));
   10331             : }
   10332             : 
   10333             : 
   10334          10 : int HeapSnapshot::GetNodesCount() const {
   10335          10 :   return static_cast<int>(ToInternal(this)->entries().size());
   10336             : }
   10337             : 
   10338             : 
   10339       67262 : const HeapGraphNode* HeapSnapshot::GetNode(int index) const {
   10340             :   return reinterpret_cast<const HeapGraphNode*>(
   10341      134524 :       &ToInternal(this)->entries().at(index));
   10342             : }
   10343             : 
   10344             : 
   10345          20 : SnapshotObjectId HeapSnapshot::GetMaxSnapshotJSObjectId() const {
   10346          20 :   return ToInternal(this)->max_snapshot_js_object_id();
   10347             : }
   10348             : 
   10349             : 
   10350          35 : void HeapSnapshot::Serialize(OutputStream* stream,
   10351             :                              HeapSnapshot::SerializationFormat format) const {
   10352             :   Utils::ApiCheck(format == kJSON,
   10353             :                   "v8::HeapSnapshot::Serialize",
   10354             :                   "Unknown serialization format");
   10355          35 :   Utils::ApiCheck(stream->GetChunkSize() > 0,
   10356             :                   "v8::HeapSnapshot::Serialize",
   10357             :                   "Invalid stream chunk size");
   10358             :   i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
   10359          35 :   serializer.Serialize(stream);
   10360          35 : }
   10361             : 
   10362             : 
   10363             : // static
   10364             : STATIC_CONST_MEMBER_DEFINITION const SnapshotObjectId
   10365             :     HeapProfiler::kUnknownObjectId;
   10366             : 
   10367             : 
   10368         115 : int HeapProfiler::GetSnapshotCount() {
   10369         115 :   return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
   10370             : }
   10371             : 
   10372             : 
   10373          30 : const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) {
   10374             :   return reinterpret_cast<const HeapSnapshot*>(
   10375          30 :       reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
   10376             : }
   10377             : 
   10378             : 
   10379         155 : SnapshotObjectId HeapProfiler::GetObjectId(Local<Value> value) {
   10380         155 :   i::Handle<i::Object> obj = Utils::OpenHandle(*value);
   10381         155 :   return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
   10382             : }
   10383             : 
   10384             : 
   10385         140 : Local<Value> HeapProfiler::FindObjectById(SnapshotObjectId id) {
   10386             :   i::Handle<i::Object> obj =
   10387         140 :       reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id);
   10388         140 :   if (obj.is_null()) return Local<Value>();
   10389             :   return Utils::ToLocal(obj);
   10390             : }
   10391             : 
   10392             : 
   10393        3871 : void HeapProfiler::ClearObjectIds() {
   10394        3871 :   reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap();
   10395        3871 : }
   10396             : 
   10397             : 
   10398         398 : const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
   10399             :     ActivityControl* control, ObjectNameResolver* resolver) {
   10400             :   return reinterpret_cast<const HeapSnapshot*>(
   10401             :       reinterpret_cast<i::HeapProfiler*>(this)
   10402         398 :           ->TakeSnapshot(control, resolver));
   10403             : }
   10404             : 
   10405             : 
   10406          45 : void HeapProfiler::StartTrackingHeapObjects(bool track_allocations) {
   10407          45 :   reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
   10408          45 :       track_allocations);
   10409          45 : }
   10410             : 
   10411             : 
   10412        3911 : void HeapProfiler::StopTrackingHeapObjects() {
   10413        3911 :   reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
   10414        3911 : }
   10415             : 
   10416             : 
   10417          55 : SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream,
   10418             :                                             int64_t* timestamp_us) {
   10419             :   i::HeapProfiler* heap_profiler = reinterpret_cast<i::HeapProfiler*>(this);
   10420          55 :   return heap_profiler->PushHeapObjectsStats(stream, timestamp_us);
   10421             : }
   10422             : 
   10423          59 : bool HeapProfiler::StartSamplingHeapProfiler(uint64_t sample_interval,
   10424             :                                              int stack_depth,
   10425             :                                              SamplingFlags flags) {
   10426             :   return reinterpret_cast<i::HeapProfiler*>(this)->StartSamplingHeapProfiler(
   10427          59 :       sample_interval, stack_depth, flags);
   10428             : }
   10429             : 
   10430             : 
   10431          59 : void HeapProfiler::StopSamplingHeapProfiler() {
   10432          59 :   reinterpret_cast<i::HeapProfiler*>(this)->StopSamplingHeapProfiler();
   10433          59 : }
   10434             : 
   10435             : 
   10436          77 : AllocationProfile* HeapProfiler::GetAllocationProfile() {
   10437          77 :   return reinterpret_cast<i::HeapProfiler*>(this)->GetAllocationProfile();
   10438             : }
   10439             : 
   10440          35 : void HeapProfiler::DeleteAllHeapSnapshots() {
   10441          35 :   reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
   10442          35 : }
   10443             : 
   10444          35 : void HeapProfiler::AddBuildEmbedderGraphCallback(
   10445             :     BuildEmbedderGraphCallback callback, void* data) {
   10446             :   reinterpret_cast<i::HeapProfiler*>(this)->AddBuildEmbedderGraphCallback(
   10447          35 :       callback, data);
   10448          35 : }
   10449             : 
   10450           5 : void HeapProfiler::RemoveBuildEmbedderGraphCallback(
   10451             :     BuildEmbedderGraphCallback callback, void* data) {
   10452             :   reinterpret_cast<i::HeapProfiler*>(this)->RemoveBuildEmbedderGraphCallback(
   10453           5 :       callback, data);
   10454           5 : }
   10455             : 
   10456             : v8::Testing::StressType internal::Testing::stress_type_ =
   10457             :     v8::Testing::kStressTypeOpt;
   10458             : 
   10459             : 
   10460        5592 : void Testing::SetStressRunType(Testing::StressType type) {
   10461             :   internal::Testing::set_stress_type(type);
   10462        5592 : }
   10463             : 
   10464             : 
   10465        5592 : int Testing::GetStressRuns() {
   10466       54267 :   if (internal::FLAG_stress_runs != 0) return internal::FLAG_stress_runs;
   10467             : #ifdef DEBUG
   10468             :   // In debug mode the code runs much slower so stressing will only make two
   10469             :   // runs.
   10470             :   return 2;
   10471             : #else
   10472             :   return 5;
   10473             : #endif
   10474             : }
   10475             : 
   10476             : 
   10477       21660 : static void SetFlagsFromString(const char* flags) {
   10478             :   V8::SetFlagsFromString(flags, i::StrLength(flags));
   10479       21660 : }
   10480             : 
   10481             : 
   10482       27016 : void Testing::PrepareStressRun(int run) {
   10483             :   static const char* kLazyOptimizations =
   10484             :       "--prepare-always-opt "
   10485             :       "--max-inlined-bytecode-size=999999 "
   10486             :       "--max-inlined-bytecode-size-cumulative=999999 "
   10487             :       "--noalways-opt";
   10488             :   static const char* kForcedOptimizations = "--always-opt";
   10489             : 
   10490             :   // If deoptimization stressed turn on frequent deoptimization. If no value
   10491             :   // is spefified through --deopt-every-n-times use a default default value.
   10492             :   static const char* kDeoptEvery13Times = "--deopt-every-n-times=13";
   10493       27016 :   if (internal::Testing::stress_type() == Testing::kStressTypeDeopt &&
   10494           0 :       internal::FLAG_deopt_every_n_times == 0) {
   10495           0 :     SetFlagsFromString(kDeoptEvery13Times);
   10496             :   }
   10497             : 
   10498             : #ifdef DEBUG
   10499             :   // As stressing in debug mode only make two runs skip the deopt stressing
   10500             :   // here.
   10501             :   if (run == GetStressRuns() - 1) {
   10502             :     SetFlagsFromString(kForcedOptimizations);
   10503             :   } else {
   10504             :     SetFlagsFromString(kLazyOptimizations);
   10505             :   }
   10506             : #else
   10507       27016 :   if (run == GetStressRuns() - 1) {
   10508        5357 :     SetFlagsFromString(kForcedOptimizations);
   10509       21659 :   } else if (run != GetStressRuns() - 2) {
   10510       16303 :     SetFlagsFromString(kLazyOptimizations);
   10511             :   }
   10512             : #endif
   10513       27016 : }
   10514             : 
   10515             : 
   10516        5592 : void Testing::DeoptimizeAll(Isolate* isolate) {
   10517             :   i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
   10518             :   i::HandleScope scope(i_isolate);
   10519        5592 :   i::Deoptimizer::DeoptimizeAll(i_isolate);
   10520        5592 : }
   10521             : 
   10522          10 : void EmbedderHeapTracer::FinalizeTracing() {
   10523          10 :   if (isolate_) {
   10524             :     i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
   10525          10 :     if (isolate->heap()->incremental_marking()->IsMarking()) {
   10526             :       isolate->heap()->FinalizeIncrementalMarkingAtomically(
   10527           5 :           i::GarbageCollectionReason::kExternalFinalize);
   10528             :     }
   10529             :   }
   10530          10 : }
   10531             : 
   10532           5 : void EmbedderHeapTracer::GarbageCollectionForTesting(
   10533             :     EmbedderStackState stack_state) {
   10534           5 :   CHECK(isolate_);
   10535           5 :   CHECK(i::FLAG_expose_gc);
   10536             :   i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap();
   10537           5 :   heap->SetEmbedderStackStateForNextFinalizaton(stack_state);
   10538             :   heap->PreciseCollectAllGarbage(i::Heap::kNoGCFlags,
   10539             :                                  i::GarbageCollectionReason::kTesting,
   10540           5 :                                  kGCCallbackFlagForced);
   10541           5 : }
   10542             : 
   10543           5 : void EmbedderHeapTracer::RegisterEmbedderReference(
   10544             :     const TracedGlobal<v8::Value>& ref) {
   10545           5 :   if (ref.IsEmpty()) return;
   10546             : 
   10547           5 :   i::Heap* const heap = reinterpret_cast<i::Isolate*>(isolate_)->heap();
   10548             :   heap->RegisterExternallyReferencedObject(
   10549           5 :       reinterpret_cast<i::Address*>(ref.val_));
   10550             : }
   10551             : 
   10552           5 : void EmbedderHeapTracer::IterateTracedGlobalHandles(
   10553             :     TracedGlobalHandleVisitor* visitor) {
   10554           5 :   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(isolate_);
   10555             :   i::DisallowHeapAllocation no_allocation;
   10556           5 :   isolate->global_handles()->IterateTracedNodes(visitor);
   10557           5 : }
   10558             : 
   10559             : namespace internal {
   10560             : 
   10561             : const size_t HandleScopeImplementer::kEnteredContextsOffset =
   10562             :     offsetof(HandleScopeImplementer, entered_contexts_);
   10563             : const size_t HandleScopeImplementer::kIsMicrotaskContextOffset =
   10564             :     offsetof(HandleScopeImplementer, is_microtask_context_);
   10565             : 
   10566        5918 : void HandleScopeImplementer::FreeThreadResources() {
   10567        5918 :   Free();
   10568        5918 : }
   10569             : 
   10570             : 
   10571       32437 : char* HandleScopeImplementer::ArchiveThread(char* storage) {
   10572       32437 :   HandleScopeData* current = isolate_->handle_scope_data();
   10573       32437 :   handle_scope_data_ = *current;
   10574             :   MemCopy(storage, this, sizeof(*this));
   10575             : 
   10576             :   ResetAfterArchive();
   10577             :   current->Initialize();
   10578             : 
   10579       32437 :   return storage + ArchiveSpacePerThread();
   10580             : }
   10581             : 
   10582             : 
   10583       85216 : int HandleScopeImplementer::ArchiveSpacePerThread() {
   10584       85216 :   return sizeof(HandleScopeImplementer);
   10585             : }
   10586             : 
   10587             : 
   10588       32437 : char* HandleScopeImplementer::RestoreThread(char* storage) {
   10589             :   MemCopy(this, storage, sizeof(*this));
   10590       32437 :   *isolate_->handle_scope_data() = handle_scope_data_;
   10591       32437 :   return storage + ArchiveSpacePerThread();
   10592             : }
   10593             : 
   10594      559327 : void HandleScopeImplementer::IterateThis(RootVisitor* v) {
   10595             : #ifdef DEBUG
   10596             :   bool found_block_before_deferred = false;
   10597             : #endif
   10598             :   // Iterate over all handles in the blocks except for the last.
   10599      689076 :   for (int i = static_cast<int>(blocks()->size()) - 2; i >= 0; --i) {
   10600      259498 :     Address* block = blocks()->at(i);
   10601             :     // Cast possibly-unrelated pointers to plain Address before comparing them
   10602             :     // to avoid undefined behavior.
   10603      129762 :     if (last_handle_before_deferred_block_ != nullptr &&
   10604          26 :         (reinterpret_cast<Address>(last_handle_before_deferred_block_) <=
   10605          26 :          reinterpret_cast<Address>(&block[kHandleBlockSize])) &&
   10606          13 :         (reinterpret_cast<Address>(last_handle_before_deferred_block_) >=
   10607             :          reinterpret_cast<Address>(block))) {
   10608          13 :       v->VisitRootPointers(Root::kHandleScope, nullptr, FullObjectSlot(block),
   10609          26 :                            FullObjectSlot(last_handle_before_deferred_block_));
   10610          13 :       DCHECK(!found_block_before_deferred);
   10611             : #ifdef DEBUG
   10612             :       found_block_before_deferred = true;
   10613             : #endif
   10614             :     } else {
   10615      259472 :       v->VisitRootPointers(Root::kHandleScope, nullptr, FullObjectSlot(block),
   10616      259472 :                            FullObjectSlot(&block[kHandleBlockSize]));
   10617             :     }
   10618             :   }
   10619             : 
   10620             :   DCHECK(last_handle_before_deferred_block_ == nullptr ||
   10621             :          found_block_before_deferred);
   10622             : 
   10623             :   // Iterate over live handles in the last block (if any).
   10624      559327 :   if (!blocks()->empty()) {
   10625      747042 :     v->VisitRootPointers(Root::kHandleScope, nullptr,
   10626             :                          FullObjectSlot(blocks()->back()),
   10627      747042 :                          FullObjectSlot(handle_scope_data_.next));
   10628             :   }
   10629             : 
   10630             :   DetachableVector<Context>* context_lists[2] = {&saved_contexts_,
   10631      559327 :                                                  &entered_contexts_};
   10632     2796635 :   for (unsigned i = 0; i < arraysize(context_lists); i++) {
   10633     1118654 :     context_lists[i]->shrink_to_fit();
   10634     1118654 :     if (context_lists[i]->empty()) continue;
   10635             :     FullObjectSlot start(&context_lists[i]->front());
   10636      787022 :     v->VisitRootPointers(Root::kHandleScope, nullptr, start,
   10637     1574044 :                          start + static_cast<int>(context_lists[i]->size()));
   10638             :   }
   10639      559327 : }
   10640             : 
   10641      553781 : void HandleScopeImplementer::Iterate(RootVisitor* v) {
   10642      553781 :   HandleScopeData* current = isolate_->handle_scope_data();
   10643      553781 :   handle_scope_data_ = *current;
   10644      553781 :   IterateThis(v);
   10645      553781 : }
   10646             : 
   10647        5546 : char* HandleScopeImplementer::Iterate(RootVisitor* v, char* storage) {
   10648             :   HandleScopeImplementer* scope_implementer =
   10649             :       reinterpret_cast<HandleScopeImplementer*>(storage);
   10650        5546 :   scope_implementer->IterateThis(v);
   10651        5546 :   return storage + ArchiveSpacePerThread();
   10652             : }
   10653             : 
   10654        7162 : DeferredHandles* HandleScopeImplementer::Detach(Address* prev_limit) {
   10655             :   DeferredHandles* deferred =
   10656        7162 :       new DeferredHandles(isolate()->handle_scope_data()->next, isolate());
   10657             : 
   10658       14324 :   while (!blocks_.empty()) {
   10659       14324 :     Address* block_start = blocks_.back();
   10660       14324 :     Address* block_limit = &block_start[kHandleBlockSize];
   10661             :     // We should not need to check for SealHandleScope here. Assert this.
   10662             :     DCHECK(prev_limit == block_limit ||
   10663             :            !(block_start <= prev_limit && prev_limit <= block_limit));
   10664       14324 :     if (prev_limit == block_limit) break;
   10665        7162 :     deferred->blocks_.push_back(blocks_.back());
   10666             :     blocks_.pop_back();
   10667             :   }
   10668             : 
   10669             :   // deferred->blocks_ now contains the blocks installed on the
   10670             :   // HandleScope stack since BeginDeferredScope was called, but in
   10671             :   // reverse order.
   10672             : 
   10673             :   DCHECK(prev_limit == nullptr || !blocks_.empty());
   10674             : 
   10675             :   DCHECK(!blocks_.empty() && prev_limit != nullptr);
   10676             :   DCHECK_NOT_NULL(last_handle_before_deferred_block_);
   10677        7162 :   last_handle_before_deferred_block_ = nullptr;
   10678        7162 :   return deferred;
   10679             : }
   10680             : 
   10681             : 
   10682        7162 : void HandleScopeImplementer::BeginDeferredScope() {
   10683             :   DCHECK_NULL(last_handle_before_deferred_block_);
   10684        7162 :   last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
   10685        7162 : }
   10686             : 
   10687             : 
   10688       14324 : DeferredHandles::~DeferredHandles() {
   10689        7162 :   isolate_->UnlinkDeferredHandles(this);
   10690             : 
   10691       21486 :   for (size_t i = 0; i < blocks_.size(); i++) {
   10692             : #ifdef ENABLE_HANDLE_ZAPPING
   10693        7162 :     HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]);
   10694             : #endif
   10695        7162 :     isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]);
   10696             :   }
   10697        7162 : }
   10698             : 
   10699        3113 : void DeferredHandles::Iterate(RootVisitor* v) {
   10700             :   DCHECK(!blocks_.empty());
   10701             : 
   10702             :   // Comparing pointers that do not point into the same array is undefined
   10703             :   // behavior, which means if we didn't cast everything to plain Address
   10704             :   // before comparing, the compiler would be allowed to assume that all
   10705             :   // comparisons evaluate to true and drop the entire check.
   10706             :   DCHECK((reinterpret_cast<Address>(first_block_limit_) >=
   10707             :           reinterpret_cast<Address>(blocks_.front())) &&
   10708             :          (reinterpret_cast<Address>(first_block_limit_) <=
   10709             :           reinterpret_cast<Address>(&(blocks_.front())[kHandleBlockSize])));
   10710             : 
   10711        6226 :   v->VisitRootPointers(Root::kHandleScope, nullptr,
   10712             :                        FullObjectSlot(blocks_.front()),
   10713        6226 :                        FullObjectSlot(first_block_limit_));
   10714             : 
   10715        3113 :   for (size_t i = 1; i < blocks_.size(); i++) {
   10716           0 :     v->VisitRootPointers(Root::kHandleScope, nullptr,
   10717             :                          FullObjectSlot(blocks_[i]),
   10718           0 :                          FullObjectSlot(&blocks_[i][kHandleBlockSize]));
   10719             :   }
   10720        3113 : }
   10721             : 
   10722             : 
   10723         645 : void InvokeAccessorGetterCallback(
   10724             :     v8::Local<v8::Name> property,
   10725             :     const v8::PropertyCallbackInfo<v8::Value>& info,
   10726             :     v8::AccessorNameGetterCallback getter) {
   10727             :   // Leaving JavaScript.
   10728             :   Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
   10729             :   RuntimeCallTimerScope timer(isolate,
   10730         645 :                               RuntimeCallCounterId::kAccessorGetterCallback);
   10731         645 :   Address getter_address = reinterpret_cast<Address>(getter);
   10732        1290 :   VMState<EXTERNAL> state(isolate);
   10733        1290 :   ExternalCallbackScope call_scope(isolate, getter_address);
   10734         645 :   getter(property, info);
   10735         645 : }
   10736             : 
   10737             : 
   10738           0 : void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info,
   10739             :                             v8::FunctionCallback callback) {
   10740             :   Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
   10741             :   RuntimeCallTimerScope timer(isolate,
   10742           0 :                               RuntimeCallCounterId::kInvokeFunctionCallback);
   10743           0 :   Address callback_address = reinterpret_cast<Address>(callback);
   10744           0 :   VMState<EXTERNAL> state(isolate);
   10745           0 :   ExternalCallbackScope call_scope(isolate, callback_address);
   10746           0 :   callback(info);
   10747           0 : }
   10748             : 
   10749             : // Undefine macros for jumbo build.
   10750             : #undef LOG_API
   10751             : #undef ENTER_V8_DO_NOT_USE
   10752             : #undef ENTER_V8_HELPER_DO_NOT_USE
   10753             : #undef PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE
   10754             : #undef PREPARE_FOR_EXECUTION_WITH_CONTEXT
   10755             : #undef PREPARE_FOR_EXECUTION
   10756             : #undef ENTER_V8
   10757             : #undef ENTER_V8_NO_SCRIPT
   10758             : #undef ENTER_V8_NO_SCRIPT_NO_EXCEPTION
   10759             : #undef ENTER_V8_FOR_NEW_CONTEXT
   10760             : #undef EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE
   10761             : #undef RETURN_ON_FAILED_EXECUTION
   10762             : #undef RETURN_ON_FAILED_EXECUTION_PRIMITIVE
   10763             : #undef RETURN_TO_LOCAL_UNCHECKED
   10764             : #undef RETURN_ESCAPED
   10765             : #undef SET_FIELD_WRAPPED
   10766             : #undef NEW_STRING
   10767             : #undef CALLBACK_SETTER
   10768             : 
   10769             : }  // namespace internal
   10770      120216 : }  // namespace v8

Generated by: LCOV version 1.10