12 #include "src/api-inl.h" 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/code-stubs.h" 30 #include "src/compiler-dispatcher/compiler-dispatcher.h" 31 #include "src/compiler.h" 32 #include "src/contexts.h" 33 #include "src/conversions-inl.h" 34 #include "src/counters.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/icu_util.h" 49 #include "src/isolate-inl.h" 50 #include "src/json-parser.h" 51 #include "src/json-stringifier.h" 52 #include "src/messages.h" 53 #include "src/objects-inl.h" 54 #include "src/objects/api-callbacks.h" 55 #include "src/objects/embedder-data-array-inl.h" 56 #include "src/objects/embedder-data-slot-inl.h" 57 #include "src/objects/hash-table-inl.h" 58 #include "src/objects/heap-object.h" 59 #include "src/objects/js-array-inl.h" 60 #include "src/objects/js-collection-inl.h" 61 #include "src/objects/js-generator-inl.h" 62 #include "src/objects/js-promise-inl.h" 63 #include "src/objects/js-regexp-inl.h" 64 #include "src/objects/module-inl.h" 65 #include "src/objects/ordered-hash-table-inl.h" 66 #include "src/objects/slots.h" 67 #include "src/objects/smi.h" 68 #include "src/objects/stack-frame-info-inl.h" 69 #include "src/objects/templates.h" 70 #include "src/parsing/parse-info.h" 71 #include "src/parsing/parser.h" 72 #include "src/parsing/scanner-character-streams.h" 73 #include "src/pending-compilation-error-handler.h" 74 #include "src/profiler/cpu-profiler.h" 75 #include "src/profiler/heap-profiler.h" 76 #include "src/profiler/heap-snapshot-generator-inl.h" 77 #include "src/profiler/profile-generator-inl.h" 78 #include "src/profiler/tick-sample.h" 79 #include "src/property-descriptor.h" 80 #include "src/property-details.h" 81 #include "src/property.h" 82 #include "src/prototype.h" 83 #include "src/runtime-profiler.h" 84 #include "src/runtime/runtime.h" 85 #include "src/simulator.h" 86 #include "src/snapshot/code-serializer.h" 87 #include "src/snapshot/natives.h" 88 #include "src/snapshot/partial-serializer.h" 89 #include "src/snapshot/read-only-serializer.h" 90 #include "src/snapshot/snapshot.h" 91 #include "src/snapshot/startup-serializer.h" 92 #include "src/startup-data-util.h" 93 #include "src/string-hasher.h" 94 #include "src/tracing/trace-event.h" 95 #include "src/trap-handler/trap-handler.h" 96 #include "src/unicode-inl.h" 98 #include "src/v8threads.h" 99 #include "src/value-serializer.h" 100 #include "src/version.h" 101 #include "src/vm-state-inl.h" 102 #include "src/wasm/streaming-decoder.h" 103 #include "src/wasm/wasm-engine.h" 104 #include "src/wasm/wasm-objects-inl.h" 105 #include "src/wasm/wasm-result.h" 106 #include "src/wasm/wasm-serialization.h" 108 #if V8_OS_LINUX || V8_OS_MACOSX 110 #include "src/trap-handler/handler-inside-posix.h" 115 #include "src/trap-handler/handler-inside-win.h" 140 #define LOG_API(isolate, class_name, function_name) \ 141 i::RuntimeCallTimerScope _runtime_timer( \ 142 isolate, i::RuntimeCallCounterId::kAPI_##class_name##_##function_name); \ 143 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) 145 #define ENTER_V8_DO_NOT_USE(isolate) i::VMState<v8::OTHER> __state__((isolate)) 147 #define ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, \ 148 function_name, bailout_value, \ 149 HandleScopeClass, do_callback) \ 150 if (IsExecutionTerminatingCheck(isolate)) { \ 151 return bailout_value; \ 153 HandleScopeClass handle_scope(isolate); \ 154 CallDepthScope<do_callback> call_depth_scope(isolate, context); \ 155 LOG_API(isolate, class_name, function_name); \ 156 i::VMState<v8::OTHER> __state__((isolate)); \ 157 bool has_pending_exception = false 159 #define PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, T) \ 160 if (IsExecutionTerminatingCheck(isolate)) { \ 161 return MaybeLocal<T>(); \ 163 InternalEscapableScope handle_scope(isolate); \ 164 CallDepthScope<false> call_depth_scope(isolate, v8::Local<v8::Context>()); \ 165 i::VMState<v8::OTHER> __state__((isolate)); \ 166 bool has_pending_exception = false 168 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ 169 bailout_value, HandleScopeClass, \ 171 auto isolate = context.IsEmpty() \ 172 ? i::Isolate::Current() \ 173 : reinterpret_cast<i::Isolate*>(context->GetIsolate()); \ 174 ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ 175 bailout_value, HandleScopeClass, do_callback); 177 #define PREPARE_FOR_EXECUTION(context, class_name, function_name, T) \ 178 PREPARE_FOR_EXECUTION_WITH_CONTEXT(context, class_name, function_name, \ 179 MaybeLocal<T>(), InternalEscapableScope, \ 182 #define ENTER_V8(isolate, context, class_name, function_name, bailout_value, \ 184 ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ 185 bailout_value, HandleScopeClass, true) 188 #define ENTER_V8_NO_SCRIPT(isolate, context, class_name, function_name, \ 189 bailout_value, HandleScopeClass) \ 190 ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ 191 bailout_value, HandleScopeClass, false); \ 192 i::DisallowJavascriptExecutionDebugOnly __no_script__((isolate)) 194 #define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate) \ 195 i::VMState<v8::OTHER> __state__((isolate)); \ 196 i::DisallowJavascriptExecutionDebugOnly __no_script__((isolate)); \ 197 i::DisallowExceptions __no_exceptions__((isolate)) 199 #define ENTER_V8_FOR_NEW_CONTEXT(isolate) \ 200 i::VMState<v8::OTHER> __state__((isolate)); \ 201 i::DisallowExceptions __no_exceptions__((isolate)) 203 #define ENTER_V8_NO_SCRIPT(isolate, context, class_name, function_name, \ 204 bailout_value, HandleScopeClass) \ 205 ENTER_V8_HELPER_DO_NOT_USE(isolate, context, class_name, function_name, \ 206 bailout_value, HandleScopeClass, false) 208 #define ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate) \ 209 i::VMState<v8::OTHER> __state__((isolate)); 211 #define ENTER_V8_FOR_NEW_CONTEXT(isolate) \ 212 i::VMState<v8::OTHER> __state__((isolate)); 215 #define EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, value) \ 217 if (has_pending_exception) { \ 218 call_depth_scope.Escape(); \ 223 #define RETURN_ON_FAILED_EXECUTION(T) \ 224 EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, MaybeLocal<T>()) 226 #define RETURN_ON_FAILED_EXECUTION_PRIMITIVE(T) \ 227 EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, Nothing<T>()) 229 #define RETURN_TO_LOCAL_UNCHECKED(maybe_local, T) \ 230 return maybe_local.FromMaybe(Local<T>()); 233 #define RETURN_ESCAPED(value) return handle_scope.Escape(value); 237 Local<Context> ContextFromNeverReadOnlySpaceObject(
239 return reinterpret_cast<v8::Isolate*
>(obj->GetIsolate())->GetCurrentContext();
244 explicit inline InternalEscapableScope(
i::Isolate* isolate)
245 :
v8::EscapableHandleScope(reinterpret_cast<
v8::Isolate*>(isolate)) {}
249 #ifdef V8_CHECK_MICROTASKS_SCOPES_CONSISTENCY 250 void CheckMicrotasksScopesConsistency(
i::Isolate* isolate) {
251 auto handle_scope_implementer = isolate->handle_scope_implementer();
252 if (handle_scope_implementer->microtasks_policy() ==
253 v8::MicrotasksPolicy::kScoped) {
254 DCHECK(handle_scope_implementer->GetMicrotasksScopeDepth() ||
255 !handle_scope_implementer->DebugMicrotasksScopeDepthIsZero());
260 template <
bool do_callback>
261 class CallDepthScope {
263 explicit CallDepthScope(
i::Isolate* isolate, Local<Context> context)
267 safe_for_termination_(isolate->next_v8_call_is_safe_for_termination()),
268 interrupts_scope_(isolate_,
i::StackGuard::TERMINATE_EXECUTION,
269 isolate_->only_terminate_in_safe_scope()
270 ? (safe_for_termination_
271 ?
i::InterruptsScope::kRunInterrupts
272 :
i::InterruptsScope::kPostponeInterrupts)
273 :
i::InterruptsScope::kNoop) {
275 DCHECK(!isolate_->external_caught_exception());
276 isolate_->handle_scope_implementer()->IncrementCallDepth();
277 isolate_->set_next_v8_call_is_safe_for_termination(
false);
278 if (!context.IsEmpty()) {
281 if (!isolate->context().is_null() &&
282 isolate->context()->native_context() == env->native_context()) {
283 context_ = Local<Context>();
285 impl->SaveContext(isolate->context());
286 isolate->set_context(*env);
289 if (do_callback) isolate_->FireBeforeCallEnteredCallback();
292 if (!context_.IsEmpty()) {
294 isolate_->set_context(impl->RestoreContext());
296 if (!escaped_) isolate_->handle_scope_implementer()->DecrementCallDepth();
297 if (do_callback) isolate_->FireCallCompletedCallback();
299 #ifdef V8_CHECK_MICROTASKS_SCOPES_CONSISTENCY 300 if (do_callback) CheckMicrotasksScopesConsistency(isolate_);
302 isolate_->set_next_v8_call_is_safe_for_termination(safe_for_termination_);
308 auto handle_scope_implementer = isolate_->handle_scope_implementer();
309 handle_scope_implementer->DecrementCallDepth();
310 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero();
311 isolate_->OptionalRescheduleException(call_depth_is_zero);
316 Local<Context> context_;
319 bool safe_for_termination_;
326 static ScriptOrigin GetScriptOriginForScript(
i::Isolate* isolate,
332 v8::Isolate* v8_isolate =
reinterpret_cast<v8::Isolate*
>(isolate);
333 ScriptOriginOptions options(script->origin_options());
335 Utils::ToLocal(scriptName),
336 v8::Integer::New(v8_isolate, script->line_offset()),
337 v8::Integer::New(v8_isolate, script->column_offset()),
338 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()),
339 v8::Integer::New(v8_isolate, script->id()),
340 Utils::ToLocal(source_map_url),
341 v8::Boolean::New(v8_isolate, options.IsOpaque()),
342 v8::Boolean::New(v8_isolate, script->type() == i::Script::TYPE_WASM),
343 v8::Boolean::New(v8_isolate, options.IsModule()),
344 Utils::ToLocal(host_defined_options));
351 void i::FatalProcessOutOfMemory(
i::Isolate* isolate,
const char* location) {
352 i::V8::FatalProcessOutOfMemory(isolate, location,
false);
357 void i::V8::FatalProcessOutOfMemory(
i::Isolate* isolate,
const char* location,
359 char last_few_messages[Heap::kTraceRingBufferSize + 1];
360 char js_stacktrace[Heap::kStacktraceBufferSize + 1];
363 if (isolate ==
nullptr) {
364 isolate = Isolate::TryGetCurrent();
367 if (isolate ==
nullptr) {
371 memset(last_few_messages, 0x0BADC0DE, Heap::kTraceRingBufferSize + 1);
372 memset(js_stacktrace, 0x0BADC0DE, Heap::kStacktraceBufferSize + 1);
373 memset(&heap_stats, 0xBADC0DE,
sizeof(heap_stats));
376 FATAL(
"Fatal process out of memory: %s", location);
380 memset(last_few_messages, 0, Heap::kTraceRingBufferSize + 1);
381 memset(js_stacktrace, 0, Heap::kStacktraceBufferSize + 1);
383 intptr_t start_marker;
384 heap_stats.start_marker = &start_marker;
385 size_t ro_space_size;
386 heap_stats.ro_space_size = &ro_space_size;
387 size_t ro_space_capacity;
388 heap_stats.ro_space_capacity = &ro_space_capacity;
389 size_t new_space_size;
390 heap_stats.new_space_size = &new_space_size;
391 size_t new_space_capacity;
392 heap_stats.new_space_capacity = &new_space_capacity;
393 size_t old_space_size;
394 heap_stats.old_space_size = &old_space_size;
395 size_t old_space_capacity;
396 heap_stats.old_space_capacity = &old_space_capacity;
397 size_t code_space_size;
398 heap_stats.code_space_size = &code_space_size;
399 size_t code_space_capacity;
400 heap_stats.code_space_capacity = &code_space_capacity;
401 size_t map_space_size;
402 heap_stats.map_space_size = &map_space_size;
403 size_t map_space_capacity;
404 heap_stats.map_space_capacity = &map_space_capacity;
405 size_t lo_space_size;
406 heap_stats.lo_space_size = &lo_space_size;
407 size_t code_lo_space_size;
408 heap_stats.code_lo_space_size = &code_lo_space_size;
409 size_t global_handle_count;
410 heap_stats.global_handle_count = &global_handle_count;
411 size_t weak_global_handle_count;
412 heap_stats.weak_global_handle_count = &weak_global_handle_count;
413 size_t pending_global_handle_count;
414 heap_stats.pending_global_handle_count = &pending_global_handle_count;
415 size_t near_death_global_handle_count;
416 heap_stats.near_death_global_handle_count = &near_death_global_handle_count;
417 size_t free_global_handle_count;
418 heap_stats.free_global_handle_count = &free_global_handle_count;
419 size_t memory_allocator_size;
420 heap_stats.memory_allocator_size = &memory_allocator_size;
421 size_t memory_allocator_capacity;
422 heap_stats.memory_allocator_capacity = &memory_allocator_capacity;
423 size_t malloced_memory;
424 heap_stats.malloced_memory = &malloced_memory;
425 size_t malloced_peak_memory;
426 heap_stats.malloced_peak_memory = &malloced_peak_memory;
427 size_t objects_per_type[LAST_TYPE + 1] = {0};
428 heap_stats.objects_per_type = objects_per_type;
429 size_t size_per_type[LAST_TYPE + 1] = {0};
430 heap_stats.size_per_type = size_per_type;
432 heap_stats.os_error = &os_error;
433 heap_stats.last_few_messages = last_few_messages;
434 heap_stats.js_stacktrace = js_stacktrace;
436 heap_stats.end_marker = &end_marker;
437 if (isolate->heap()->HasBeenSetUp()) {
440 isolate->heap()->RecordStats(&heap_stats,
false);
441 char* first_newline = strchr(last_few_messages,
'\n');
442 if (first_newline ==
nullptr || first_newline[1] ==
'\0')
443 first_newline = last_few_messages;
444 PrintF(
"\n<--- Last few GCs --->\n%s\n", first_newline);
445 PrintF(
"\n<--- JS stacktrace --->\n%s\n", js_stacktrace);
447 Utils::ReportOOMFailure(isolate, location, is_heap_oom);
449 FATAL(
"API fatal error handler returned after process out of memory");
453 void Utils::ReportApiFailure(
const char* location,
const char* message) {
455 FatalErrorCallback callback =
nullptr;
456 if (isolate !=
nullptr) {
457 callback = isolate->exception_behavior();
459 if (callback ==
nullptr) {
460 base::OS::PrintError(
"\n#\n# Fatal error in %s\n# %s\n#\n\n", location,
464 callback(location, message);
466 isolate->SignalFatalError();
469 void Utils::ReportOOMFailure(
i::Isolate* isolate,
const char* location,
471 OOMErrorCallback oom_callback = isolate->oom_behavior();
472 if (oom_callback ==
nullptr) {
475 FatalErrorCallback fatal_callback = isolate->exception_behavior();
476 if (fatal_callback ==
nullptr) {
477 base::OS::PrintError(
"\n#\n# Fatal %s OOM in %s\n#\n\n",
478 is_heap_oom ?
"javascript" :
"process", location);
481 fatal_callback(location,
483 ?
"Allocation failed - JavaScript heap out of memory" 484 :
"Allocation failed - process out of memory");
487 oom_callback(location, is_heap_oom);
489 isolate->SignalFatalError();
492 static inline bool IsExecutionTerminatingCheck(
i::Isolate* isolate) {
493 if (isolate->has_scheduled_exception()) {
494 return isolate->scheduled_exception() ==
501 void V8::SetNativesDataBlob(StartupData* natives_blob) {
502 i::V8::SetNativesBlob(natives_blob);
506 void V8::SetSnapshotDataBlob(StartupData* snapshot_blob) {
507 i::V8::SetSnapshotBlob(snapshot_blob);
514 void* Allocate(
size_t length)
override {
515 #if V8_OS_AIX && _LINUX_SOURCE_COMPAT 518 void* data = __linux_calloc(length, 1);
520 void* data = calloc(length, 1);
525 void* AllocateUninitialized(
size_t length)
override {
526 #if V8_OS_AIX && _LINUX_SOURCE_COMPAT 529 void* data = __linux_malloc(length);
531 void* data = malloc(length);
536 void Free(
void* data,
size_t)
override { free(data); }
539 struct SnapshotCreatorData {
540 explicit SnapshotCreatorData(Isolate* isolate)
546 static SnapshotCreatorData* cast(
void* data) {
547 return reinterpret_cast<SnapshotCreatorData*
>(data);
550 ArrayBufferAllocator allocator_;
552 Persistent<Context> default_context_;
553 SerializeInternalFieldsCallback default_embedder_fields_serializer_;
554 PersistentValueVector<Context> contexts_;
555 std::vector<SerializeInternalFieldsCallback> embedder_fields_serializers_;
561 SnapshotCreator::SnapshotCreator(Isolate* isolate,
562 const intptr_t* external_references,
563 StartupData* existing_snapshot) {
564 SnapshotCreatorData* data =
new SnapshotCreatorData(isolate);
565 data->isolate_ = isolate;
567 internal_isolate->set_array_buffer_allocator(&data->allocator_);
568 internal_isolate->set_api_external_references(external_references);
569 internal_isolate->enable_serializer();
571 const StartupData* blob = existing_snapshot
573 : i::Snapshot::DefaultSnapshotBlob();
574 if (blob && blob->raw_size > 0) {
575 internal_isolate->set_snapshot_blob(blob);
576 i::Snapshot::Initialize(internal_isolate);
578 internal_isolate->Init(
nullptr);
583 SnapshotCreator::SnapshotCreator(
const intptr_t* external_references,
584 StartupData* existing_snapshot)
585 : SnapshotCreator(Isolate::Allocate(), external_references,
586 existing_snapshot) {}
588 SnapshotCreator::~SnapshotCreator() {
589 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
590 DCHECK(data->created_);
591 Isolate* isolate = data->isolate_;
597 Isolate* SnapshotCreator::GetIsolate() {
598 return SnapshotCreatorData::cast(data_)->isolate_;
601 void SnapshotCreator::SetDefaultContext(
602 Local<Context> context, SerializeInternalFieldsCallback callback) {
603 DCHECK(!context.IsEmpty());
604 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
605 DCHECK(!data->created_);
606 DCHECK(data->default_context_.IsEmpty());
607 Isolate* isolate = data->isolate_;
608 CHECK_EQ(isolate, context->GetIsolate());
609 data->default_context_.Reset(isolate, context);
610 data->default_embedder_fields_serializer_ = callback;
613 size_t SnapshotCreator::AddContext(Local<Context> context,
614 SerializeInternalFieldsCallback callback) {
615 DCHECK(!context.IsEmpty());
616 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
617 DCHECK(!data->created_);
618 Isolate* isolate = data->isolate_;
619 CHECK_EQ(isolate, context->GetIsolate());
620 size_t index = data->contexts_.Size();
621 data->contexts_.Append(context);
622 data->embedder_fields_serializers_.push_back(callback);
626 size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
627 return AddData(template_obj);
630 size_t SnapshotCreator::AddData(
i::Address object) {
631 DCHECK_NE(
object, i::kNullAddress);
632 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
633 DCHECK(!data->created_);
638 if (!isolate->heap()->serialized_objects()->IsArrayList()) {
639 list = i::ArrayList::New(isolate, 1);
642 i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate);
644 size_t index =
static_cast<size_t>(list->Length());
645 list = i::ArrayList::Add(isolate, list, obj);
646 isolate->heap()->SetSerializedObjects(*list);
650 size_t SnapshotCreator::AddData(Local<Context> context,
i::Address object) {
651 DCHECK_NE(
object, i::kNullAddress);
652 DCHECK(!SnapshotCreatorData::cast(data_)->created_);
658 if (!ctx->serialized_objects()->IsArrayList()) {
659 list = i::ArrayList::New(isolate, 1);
662 i::ArrayList::cast(ctx->serialized_objects()), isolate);
664 size_t index =
static_cast<size_t>(list->Length());
665 list = i::ArrayList::Add(isolate, list, obj);
666 ctx->set_serialized_objects(*list);
671 void ConvertSerializedObjectsToFixedArray(Local<Context> context) {
674 if (!ctx->serialized_objects()->IsArrayList()) {
680 ctx->set_serialized_objects(*elements);
684 void ConvertSerializedObjectsToFixedArray(
i::Isolate* isolate) {
685 if (!isolate->heap()->serialized_objects()->IsArrayList()) {
686 isolate->heap()->SetSerializedObjects(
690 i::ArrayList::cast(isolate->heap()->serialized_objects()), isolate);
692 isolate->heap()->SetSerializedObjects(*elements);
697 StartupData SnapshotCreator::CreateBlob(
698 SnapshotCreator::FunctionCodeHandling function_code_handling) {
699 SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
701 DCHECK(!data->created_);
702 DCHECK(!data->default_context_.IsEmpty());
704 int num_additional_contexts =
static_cast<int>(data->contexts_.Size());
709 ConvertSerializedObjectsToFixedArray(isolate);
712 ConvertSerializedObjectsToFixedArray(
713 data->default_context_.Get(data->isolate_));
714 for (
int i = 0;
i < num_additional_contexts;
i++) {
715 ConvertSerializedObjectsToFixedArray(data->contexts_.Get(
i));
721 isolate->factory()->NewFixedArray(num_additional_contexts, i::TENURED);
722 for (
int i = 0;
i < num_additional_contexts;
i++) {
724 v8::Utils::OpenHandle(*data->contexts_.Get(
i));
725 global_proxy_sizes->set(
i,
726 i::Smi::FromInt(context->global_proxy()->Size()));
728 isolate->heap()->SetSerializedGlobalProxySizes(*global_proxy_sizes);
732 isolate->descriptor_lookup_cache()->Clear();
736 isolate->heap()->CollectAllAvailableGarbage(
737 i::GarbageCollectionReason::kSnapshotCreator);
740 isolate->heap()->CompactWeakArrayLists(internal::TENURED);
743 isolate->heap()->read_only_space()->ClearStringPaddingIfNeeded();
745 if (function_code_handling == FunctionCodeHandling::kClear) {
754 std::vector<i::Handle<i::SharedFunctionInfo>> sfis_to_clear;
758 if (current_obj->IsSharedFunctionInfo()) {
760 i::SharedFunctionInfo::cast(current_obj);
761 if (shared->CanDiscardCompiled()) {
762 sfis_to_clear.emplace_back(shared, isolate);
768 i::SharedFunctionInfo::DiscardCompiled(isolate, shared);
774 int num_contexts = num_additional_contexts + 1;
775 std::vector<i::Context> contexts;
776 contexts.reserve(num_contexts);
780 *v8::Utils::OpenHandle(*data->default_context_.Get(data->isolate_)));
781 data->default_context_.Reset();
782 for (
int i = 0;
i < num_additional_contexts;
i++) {
784 v8::Utils::OpenHandle(*data->contexts_.Get(
i));
785 contexts.push_back(*context);
787 data->contexts_.Clear();
792 CHECK(handle_checker.CheckGlobalAndEternalHandles());
796 if (current_obj->IsJSFunction()) {
800 fun->CompleteInobjectSlackTrackingIfActive();
803 if (fun->has_feedback_vector()) {
804 fun->feedback_cell()->set_value(
806 fun->set_code(isolate->builtins()->builtin(i::Builtins::kCompileLazy));
808 if (function_code_handling == FunctionCodeHandling::kClear) {
809 DCHECK(fun->shared()->HasWasmExportedFunctionData() ||
810 fun->shared()->HasBuiltinId() ||
811 fun->shared()->IsApiFunction() ||
812 fun->shared()->HasUncompiledDataWithoutPreParsedScope());
818 read_only_serializer.SerializeReadOnlyRoots();
821 startup_serializer.SerializeStrongReferences();
824 std::vector<i::SnapshotData*> context_snapshots;
825 context_snapshots.reserve(num_contexts);
828 bool can_be_rehashed =
true;
830 for (
int i = 0;
i < num_contexts;
i++) {
831 bool is_default_context =
i == 0;
833 isolate, &startup_serializer,
834 is_default_context ? data->default_embedder_fields_serializer_
835 : data->embedder_fields_serializers_[
i - 1]);
836 partial_serializer.Serialize(&contexts[
i], !is_default_context);
837 can_be_rehashed = can_be_rehashed && partial_serializer.can_be_rehashed();
841 startup_serializer.SerializeWeakReferencesAndDeferred();
842 can_be_rehashed = can_be_rehashed && startup_serializer.can_be_rehashed();
844 read_only_serializer.FinalizeSerialization();
845 can_be_rehashed = can_be_rehashed && read_only_serializer.can_be_rehashed();
850 i::Snapshot::CreateSnapshotBlob(&startup_snapshot, &read_only_snapshot,
851 context_snapshots, can_be_rehashed);
854 for (
const auto context_snapshot : context_snapshots) {
855 delete context_snapshot;
857 data->created_ =
true;
859 DCHECK(i::Snapshot::VerifyChecksum(&result));
863 void V8::SetDcheckErrorHandler(DcheckErrorCallback that) {
864 v8::base::SetDcheckFunction(that);
867 void V8::SetFlagsFromString(
const char* str,
int length) {
868 i::FlagList::SetFlagsFromString(str, length);
869 i::FlagList::EnforceFlagImplications();
873 void V8::SetFlagsFromCommandLine(
int* argc,
char** argv,
bool remove_flags) {
874 i::FlagList::SetFlagsFromCommandLine(argc, argv, remove_flags);
877 RegisteredExtension* RegisteredExtension::first_extension_ =
nullptr;
879 RegisteredExtension::RegisteredExtension(Extension* extension)
880 : extension_(extension) { }
883 void RegisteredExtension::Register(RegisteredExtension* that) {
884 that->next_ = first_extension_;
885 first_extension_ = that;
889 void RegisteredExtension::UnregisterAll() {
890 RegisteredExtension* re = first_extension_;
891 while (re !=
nullptr) {
892 RegisteredExtension* next = re->next();
896 first_extension_ =
nullptr;
900 class ExtensionResource :
public String::ExternalOneByteStringResource {
902 ExtensionResource() : data_(nullptr), length_(0) {}
903 ExtensionResource(
const char* data,
size_t length)
904 : data_(data), length_(length) {}
905 const char* data()
const override {
return data_; }
906 size_t length()
const override {
return length_; }
907 void Dispose()
override {}
915 void RegisterExtension(Extension* that) {
916 RegisteredExtension* extension =
new RegisteredExtension(that);
917 RegisteredExtension::Register(extension);
921 Extension::Extension(
const char* name,
927 source_length_(source_length >= 0 ?
929 (source ? static_cast<
int>(strlen(source)) : 0)),
930 dep_count_(dep_count),
932 auto_enable_(false) {
933 source_ =
new ExtensionResource(source, source_length_);
934 CHECK(source !=
nullptr || source_length_ == 0);
937 ResourceConstraints::ResourceConstraints()
938 : max_semi_space_size_in_kb_(0),
939 max_old_space_size_(0),
940 stack_limit_(nullptr),
942 max_zone_pool_size_(0) {}
944 void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
945 uint64_t virtual_memory_limit) {
946 set_max_semi_space_size_in_kb(
947 i::Heap::ComputeMaxSemiSpaceSize(physical_memory));
948 set_max_old_space_size(i::Heap::ComputeMaxOldGenerationSize(physical_memory));
949 set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize);
951 if (virtual_memory_limit > 0 && i::kRequiresCodeRange) {
955 i::Min(i::kMaximalCodeRangeSize / i::MB,
956 static_cast<size_t>((virtual_memory_limit >> 3) / i::MB)));
960 void SetResourceConstraints(
i::Isolate* isolate,
961 const ResourceConstraints& constraints) {
962 size_t semi_space_size = constraints.max_semi_space_size_in_kb();
963 size_t old_space_size = constraints.max_old_space_size();
964 size_t code_range_size = constraints.code_range_size();
965 size_t max_pool_size = constraints.max_zone_pool_size();
966 if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) {
967 isolate->heap()->ConfigureHeap(semi_space_size, old_space_size,
970 isolate->allocator()->ConfigureSegmentPool(max_pool_size);
972 if (constraints.stack_limit() !=
nullptr) {
974 isolate->stack_guard()->SetStackLimit(limit);
979 LOG_API(isolate, Persistent, New);
982 if (i::FLAG_verify_heap) {
985 #endif // VERIFY_HEAP 986 return result.location();
991 return result.location();
994 void V8::RegisterExternallyReferencedObject(
i::Address* location,
996 isolate->heap()->RegisterExternallyReferencedObject(location);
999 void V8::MakeWeak(
i::Address* location,
void* parameter,
1000 WeakCallbackInfo<void>::Callback weak_callback,
1001 WeakCallbackType type) {
1002 i::GlobalHandles::MakeWeak(location, parameter, weak_callback, type);
1005 void V8::MakeWeak(
i::Address** location_addr) {
1006 i::GlobalHandles::MakeWeak(location_addr);
1010 return i::GlobalHandles::ClearWeakness(location);
1013 void V8::AnnotateStrongRetainer(
i::Address* location,
const char* label) {
1014 i::GlobalHandles::AnnotateStrongRetainer(location, label);
1017 void V8::DisposeGlobal(
i::Address* location) {
1018 i::GlobalHandles::Destroy(location);
1021 Value* V8::Eternalize(Isolate* v8_isolate,
Value* value) {
1023 i::Object*
object = *Utils::OpenHandle(value);
1025 isolate->eternal_handles()->Create(isolate,
object, &index);
1026 return reinterpret_cast<Value*
>(
1027 isolate->eternal_handles()->Get(index).location());
1031 void V8::FromJustIsNothing() {
1032 Utils::ApiCheck(
false,
"v8::FromJust",
"Maybe value is Nothing.");
1036 void V8::ToLocalEmpty() {
1037 Utils::ApiCheck(
false,
"v8::ToLocalChecked",
"Empty MaybeLocal.");
1040 void V8::InternalFieldOutOfBounds(
int index) {
1041 Utils::ApiCheck(0 <= index && index < kInternalFieldsInWeakCallback,
1042 "WeakCallbackInfo::GetInternalField",
1043 "Internal field out of bounds.");
1050 HandleScope::HandleScope(Isolate* isolate) {
1051 Initialize(isolate);
1055 void HandleScope::Initialize(Isolate* isolate) {
1063 !v8::Locker::IsActive() ||
1064 internal_isolate->thread_manager()->IsLockedByCurrentThread() ||
1065 internal_isolate->serializer_enabled(),
1066 "HandleScope::HandleScope",
1067 "Entering the V8 API without proper locking in place");
1069 isolate_ = internal_isolate;
1070 prev_next_ = current->next;
1071 prev_limit_ = current->limit;
1076 HandleScope::~HandleScope() {
1077 i::HandleScope::CloseScope(isolate_, prev_next_, prev_limit_);
1080 void* HandleScope::operator
new(
size_t) { base::OS::Abort(); }
1081 void* HandleScope::operator
new[](
size_t) { base::OS::Abort(); }
1082 void HandleScope::operator
delete(
void*,
size_t) { base::OS::Abort(); }
1083 void HandleScope::operator
delete[](
void*,
size_t) { base::OS::Abort(); }
1085 int HandleScope::NumberOfHandles(Isolate* isolate) {
1086 return i::HandleScope::NumberOfHandles(
1087 reinterpret_cast<i::Isolate*>(isolate));
1090 i::Address* HandleScope::CreateHandle(
i::Isolate* isolate, i::Address value) {
1091 return i::HandleScope::CreateHandle(isolate, value);
1096 DCHECK(reinterpret_cast<i::HeapObject*>(writable_object)->IsHeapObject());
1097 return i::HandleScope::CreateHandle(writable_object->GetIsolate(), value);
1101 EscapableHandleScope::EscapableHandleScope(Isolate* v8_isolate) {
1103 escape_slot_ = CreateHandle(
1106 Initialize(v8_isolate);
1112 reinterpret_cast<i::Object*>(*escape_slot_)->IsTheHole(heap->isolate()),
1113 "EscapableHandleScope::Escape",
"Escape value set twice");
1114 if (escape_value ==
nullptr) {
1119 *escape_slot_ = *escape_value;
1120 return escape_slot_;
1123 void* EscapableHandleScope::operator
new(
size_t) { base::OS::Abort(); }
1124 void* EscapableHandleScope::operator
new[](
size_t) { base::OS::Abort(); }
1125 void EscapableHandleScope::operator
delete(
void*,
size_t) { base::OS::Abort(); }
1126 void EscapableHandleScope::operator
delete[](
void*,
size_t) {
1130 SealHandleScope::SealHandleScope(Isolate* isolate)
1131 : isolate_(reinterpret_cast<
i::Isolate*>(isolate)) {
1133 prev_limit_ = current->limit;
1134 current->limit = current->next;
1135 prev_sealed_level_ = current->sealed_level;
1136 current->sealed_level = current->level;
1140 SealHandleScope::~SealHandleScope() {
1142 DCHECK_EQ(current->next, current->limit);
1143 current->limit = prev_limit_;
1144 DCHECK_EQ(current->level, current->sealed_level);
1145 current->sealed_level = prev_sealed_level_;
1148 void* SealHandleScope::operator
new(
size_t) { base::OS::Abort(); }
1149 void* SealHandleScope::operator
new[](
size_t) { base::OS::Abort(); }
1150 void SealHandleScope::operator
delete(
void*,
size_t) { base::OS::Abort(); }
1151 void SealHandleScope::operator
delete[](
void*,
size_t) { base::OS::Abort(); }
1153 void Context::Enter() {
1156 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1158 impl->EnterContext(env);
1159 impl->SaveContext(isolate->context());
1160 isolate->set_context(*env);
1163 void Context::Exit() {
1166 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1168 if (!Utils::ApiCheck(impl->LastEnteredContextWas(env),
1169 "v8::Context::Exit()",
1170 "Cannot exit non-entered context")) {
1173 impl->LeaveContext();
1174 isolate->set_context(impl->RestoreContext());
1179 : backup_incumbent_context_(backup_incumbent_context) {
1180 DCHECK(!backup_incumbent_context_.
IsEmpty());
1184 prev_ = isolate->top_backup_incumbent_scope();
1185 isolate->set_top_backup_incumbent_scope(
this);
1188 Context::BackupIncumbentScope::~BackupIncumbentScope() {
1191 isolate->set_top_backup_incumbent_scope(prev_);
1194 STATIC_ASSERT(i::Internals::kEmbedderDataSlotSize == i::kEmbedderDataSlotSize);
1197 int index,
bool can_grow,
1198 const char* location) {
1202 Utils::ApiCheck(env->IsNativeContext(),
1204 "Not a native context") &&
1205 Utils::ApiCheck(index >= 0, location,
"Negative index");
1209 i::EmbedderDataArray::cast(env->embedder_data()), isolate);
1210 if (index < data->length())
return data;
1211 if (!Utils::ApiCheck(can_grow && index < i::EmbedderDataArray::kMaxLength,
1212 location,
"Index too large")) {
1215 data = i::EmbedderDataArray::EnsureCapacity(isolate, data, index);
1216 env->set_embedder_data(*data);
1220 uint32_t Context::GetNumberOfEmbedderDataFields() {
1222 CHECK(context->IsNativeContext());
1225 i::EmbedderDataArray::cast(context->embedder_data())->length());
1229 const char* location =
"v8::Context::GetEmbedderData()";
1231 EmbedderDataFor(
this, index,
false, location);
1232 if (data.is_null())
return Local<Value>();
1233 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1236 return Utils::ToLocal(result);
1241 const char* location =
"v8::Context::SetEmbedderData()";
1243 EmbedderDataFor(
this, index,
true, location);
1244 if (data.is_null())
return;
1246 i::EmbedderDataSlot::store_tagged(*data, index, *val);
1247 DCHECK_EQ(*Utils::OpenHandle(*value),
1248 *Utils::OpenHandle(*GetEmbedderData(index)));
1252 void* Context::SlowGetAlignedPointerFromEmbedderData(
int index) {
1253 const char* location =
"v8::Context::GetAlignedPointerFromEmbedderData()";
1255 EmbedderDataFor(
this, index,
false, location);
1256 if (data.is_null())
return nullptr;
1259 location,
"Pointer is not aligned");
1264 void Context::SetAlignedPointerInEmbedderData(
int index,
void* value) {
1265 const char* location =
"v8::Context::SetAlignedPointerInEmbedderData()";
1267 EmbedderDataFor(
this, index,
true, location);
1269 Utils::ApiCheck(ok, location,
"Pointer is not aligned");
1270 DCHECK_EQ(value, GetAlignedPointerFromEmbedderData(index));
1278 that->set_number_of_properties(0);
1279 that->set_tag(i::Smi::FromInt(type));
1285 auto templ = Utils::OpenHandle(
this);
1287 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1289 auto value_obj = Utils::OpenHandle(*value);
1290 CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo());
1291 if (value_obj->IsObjectTemplateInfo()) {
1292 templ->set_serial_number(i::Smi::kZero);
1293 if (templ->IsFunctionTemplateInfo()) {
1297 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
1299 static_cast<i::PropertyAttributes>(attribute));
1304 Set(Utils::ToLocal(Utils::OpenHandle(reinterpret_cast<Name*>(*name))), value,
1308 void Template::SetAccessorProperty(
1315 DCHECK_EQ(v8::DEFAULT, access_control);
1316 auto templ = Utils::OpenHandle(
this);
1317 auto isolate = templ->GetIsolate();
1318 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1319 DCHECK(!name.IsEmpty());
1320 DCHECK(!getter.IsEmpty() || !setter.IsEmpty());
1322 i::ApiNatives::AddAccessorProperty(
1323 isolate, templ, Utils::OpenHandle(*name),
1324 Utils::OpenHandle(*getter,
true), Utils::OpenHandle(*setter,
true),
1325 static_cast<i::PropertyAttributes>(attribute));
1330 static void InitializeFunctionTemplate(
1332 InitializeTemplate(info, Consts::FUNCTION_TEMPLATE);
1336 static Local<ObjectTemplate> ObjectTemplateNew(
1341 i::Isolate* i_isolate = Utils::OpenHandle(
this)->GetIsolate();
1342 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
1345 if (result->IsUndefined(i_isolate)) {
1347 result = Utils::OpenHandle(
1349 i::FunctionTemplateInfo::SetPrototypeTemplate(
1350 i_isolate, Utils::OpenHandle(
this), result);
1352 return ToApiHandle<ObjectTemplate>(result);
1357 i::Isolate* i_isolate = Utils::OpenHandle(
this)->GetIsolate();
1358 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
1360 auto info = Utils::OpenHandle(
this);
1361 CHECK(info->GetPrototypeTemplate()->IsUndefined(i_isolate));
1362 CHECK(info->GetParentTemplate()->IsUndefined(i_isolate));
1363 i::FunctionTemplateInfo::SetPrototypeProviderTemplate(i_isolate, info,
1369 Utils::ApiCheck(!info->instantiated(), func,
1370 "FunctionTemplate already instantiated");
1375 auto info = Utils::OpenHandle(
this);
1376 EnsureNotInstantiated(info,
"v8::FunctionTemplate::Inherit");
1378 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
1379 CHECK(info->GetPrototypeProviderTemplate()->IsUndefined(i_isolate));
1380 i::FunctionTemplateInfo::SetParentTemplate(i_isolate, info,
1381 Utils::OpenHandle(*value));
1388 SideEffectType side_effect_type = SideEffectType::kHasSideEffect) {
1390 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE, i::TENURED);
1393 InitializeFunctionTemplate(obj);
1394 obj->set_do_not_cache(do_not_cache);
1395 int next_serial_number = i::FunctionTemplateInfo::kInvalidSerialNumber;
1396 if (!do_not_cache) {
1397 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
1399 obj->set_serial_number(i::Smi::FromInt(next_serial_number));
1400 if (callback !=
nullptr) {
1401 Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type);
1403 obj->set_length(length);
1404 obj->set_undetectable(
false);
1405 obj->set_needs_access_check(
false);
1406 obj->set_accept_any_receiver(
true);
1408 obj->set_signature(*Utils::OpenHandle(*signature));
1410 obj->set_cached_property_name(
1411 cached_property_name.IsEmpty()
1413 : *Utils::OpenHandle(*cached_property_name));
1414 return Utils::ToLocal(obj);
1425 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
1426 auto templ = FunctionTemplateNew(i_isolate, callback, data, signature, length,
1428 if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
1435 i::FixedArray serialized_objects = i_isolate->heap()->serialized_objects();
1436 int int_index =
static_cast<int>(index);
1437 if (int_index < serialized_objects->length()) {
1438 i::Object* info = serialized_objects->get(int_index);
1439 if (info->IsFunctionTemplateInfo()) {
1441 i::FunctionTemplateInfo::cast(info), i_isolate));
1448 Isolate* isolate, FunctionCallback callback,
Local<Private> cache_property,
1453 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
1454 return FunctionTemplateNew(i_isolate, callback, data, signature, length,
1455 false, cache_property, side_effect_type);
1460 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
1464 Local<AccessorSignature> AccessorSignature::New(
1465 Isolate* isolate, Local<FunctionTemplate> receiver) {
1466 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
1469 #define SET_FIELD_WRAPPED(isolate, obj, setter, cdata) \ 1471 i::Handle<i::Object> foreign = FromCData(isolate, cdata); \ 1472 (obj)->setter(*foreign); \ 1478 auto info = Utils::OpenHandle(
this);
1479 EnsureNotInstantiated(info,
"v8::FunctionTemplate::SetCallHandler");
1481 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1484 side_effect_type == SideEffectType::kHasNoSideEffect);
1485 SET_FIELD_WRAPPED(isolate, obj, set_callback, callback);
1486 SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback());
1487 if (data.IsEmpty()) {
1488 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1490 obj->set_data(*Utils::OpenHandle(*data));
1491 info->set_call_code(*obj);
1497 template <
typename Getter,
typename Setter>
1502 bool replace_on_access) {
1504 SET_FIELD_WRAPPED(isolate, obj, set_getter, getter);
1505 DCHECK_IMPLIES(replace_on_access,
1506 is_special_data_property && setter ==
nullptr);
1507 if (is_special_data_property && setter ==
nullptr) {
1508 setter =
reinterpret_cast<Setter
>(&i::Accessors::ReconfigureToDataProperty);
1510 SET_FIELD_WRAPPED(isolate, obj, set_setter, setter);
1511 i::Address redirected = obj->redirected_getter();
1512 if (redirected != i::kNullAddress) {
1513 SET_FIELD_WRAPPED(isolate, obj, set_js_getter, redirected);
1515 if (data.IsEmpty()) {
1516 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1518 obj->set_data(*Utils::OpenHandle(*data));
1519 obj->set_is_special_data_property(is_special_data_property);
1520 obj->set_replace_on_access(replace_on_access);
1522 if (!accessor_name->IsUniqueName()) {
1523 accessor_name = isolate->factory()->InternalizeString(
1526 obj->set_name(*accessor_name);
1527 if (settings & ALL_CAN_READ) obj->set_all_can_read(
true);
1528 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(
true);
1529 obj->set_initial_property_attributes(i::NONE);
1531 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature));
1540 if (!Utils::ApiCheck(!handle.is_null(),
1541 "v8::FunctionTemplate::InstanceTemplate()",
1542 "Reading from empty handle")) {
1546 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1547 if (handle->GetInstanceTemplate()->IsUndefined(isolate)) {
1550 i::FunctionTemplateInfo::SetInstanceTemplate(isolate, handle,
1551 Utils::OpenHandle(*templ));
1554 i::ObjectTemplateInfo::cast(handle->GetInstanceTemplate()), isolate);
1555 return Utils::ToLocal(result);
1560 auto info = Utils::OpenHandle(
this);
1561 EnsureNotInstantiated(info,
"v8::FunctionTemplate::SetLength");
1562 auto isolate = info->GetIsolate();
1563 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1564 info->set_length(length);
1569 auto info = Utils::OpenHandle(
this);
1570 EnsureNotInstantiated(info,
"v8::FunctionTemplate::SetClassName");
1571 auto isolate = info->GetIsolate();
1572 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1573 info->set_class_name(*Utils::OpenHandle(*name));
1578 auto info = Utils::OpenHandle(
this);
1579 EnsureNotInstantiated(info,
"v8::FunctionTemplate::SetAcceptAnyReceiver");
1580 auto isolate = info->GetIsolate();
1581 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1582 info->set_accept_any_receiver(value);
1587 auto info = Utils::OpenHandle(
this);
1588 EnsureNotInstantiated(info,
"v8::FunctionTemplate::SetHiddenPrototype");
1589 auto isolate = info->GetIsolate();
1590 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1591 info->set_hidden_prototype(value);
1596 auto info = Utils::OpenHandle(
this);
1597 EnsureNotInstantiated(info,
"v8::FunctionTemplate::ReadOnlyPrototype");
1598 auto isolate = info->GetIsolate();
1599 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1600 info->set_read_only_prototype(
true);
1605 auto info = Utils::OpenHandle(
this);
1606 EnsureNotInstantiated(info,
"v8::FunctionTemplate::RemovePrototype");
1607 auto isolate = info->GetIsolate();
1608 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1609 info->set_remove_prototype(
true);
1618 return New(reinterpret_cast<i::Isolate*>(isolate), constructor);
1624 bool do_not_cache) {
1626 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1628 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE, i::TENURED);
1631 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
1632 int next_serial_number = 0;
1633 if (!do_not_cache) {
1634 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
1636 obj->set_serial_number(i::Smi::FromInt(next_serial_number));
1638 obj->set_constructor(*Utils::OpenHandle(*constructor));
1639 obj->set_data(i::Smi::kZero);
1640 return Utils::ToLocal(obj);
1645 return ObjectTemplateNew(isolate, constructor,
false);
1651 i::FixedArray serialized_objects = i_isolate->heap()->serialized_objects();
1652 int int_index =
static_cast<int>(index);
1653 if (int_index < serialized_objects->length()) {
1654 i::Object* info = serialized_objects->get(int_index);
1655 if (info->IsObjectTemplateInfo()) {
1657 i::ObjectTemplateInfo::cast(info), i_isolate));
1668 i::Object* obj = Utils::OpenHandle(object_template)->constructor();
1669 if (!obj->IsUndefined(isolate)) {
1673 Local<FunctionTemplate> templ =
1676 i::FunctionTemplateInfo::SetInstanceTemplate(
1677 isolate, constructor, Utils::OpenHandle(object_template));
1678 Utils::OpenHandle(object_template)->set_constructor(*constructor);
1682 template <
typename Getter,
typename Setter,
typename Data,
typename Template>
1683 static void TemplateSetAccessor(
1684 Template* template_obj,
v8::Local<Name> name, Getter getter, Setter setter,
1689 auto info = Utils::OpenHandle(template_obj);
1690 auto isolate = info->GetIsolate();
1691 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1694 MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature,
1695 is_special_data_property, replace_on_access);
1696 accessor_info->set_initial_property_attributes(
1697 static_cast<i::PropertyAttributes>(attribute));
1698 accessor_info->set_getter_side_effect_type(getter_side_effect_type);
1699 accessor_info->set_setter_side_effect_type(setter_side_effect_type);
1700 i::ApiNatives::AddNativeDataProperty(isolate, info, accessor_info);
1709 TemplateSetAccessor(
this, name, getter, setter, data, settings, attribute,
1710 signature,
true,
false, getter_side_effect_type,
1711 setter_side_effect_type);
1720 TemplateSetAccessor(
this, name, getter, setter, data, settings, attribute,
1721 signature,
true,
false, getter_side_effect_type,
1722 setter_side_effect_type);
1726 AccessorNameGetterCallback getter,
1731 TemplateSetAccessor(
this, name, getter,
1732 static_cast<AccessorNameSetterCallback>(
nullptr), data,
1734 true, getter_side_effect_type, setter_side_effect_type);
1739 auto templ = Utils::OpenHandle(
this);
1741 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1743 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
1745 static_cast<i::PropertyAttributes>(attribute));
1750 AccessorSetterCallback setter,
1756 TemplateSetAccessor(
this, name, getter, setter, data, settings, attribute,
1757 signature, i::FLAG_disable_old_api_accessors,
false,
1758 getter_side_effect_type, setter_side_effect_type);
1762 AccessorNameGetterCallback getter,
1763 AccessorNameSetterCallback setter,
1769 TemplateSetAccessor(
this, name, getter, setter, data, settings, attribute,
1770 signature, i::FLAG_disable_old_api_accessors,
false,
1771 getter_side_effect_type, setter_side_effect_type);
1774 template <
typename Getter,
typename Setter,
typename Query,
typename Descriptor,
1775 typename Deleter,
typename Enumerator,
typename Definer>
1777 i::Isolate* isolate, Getter getter, Setter setter, Query query,
1778 Descriptor descriptor, Deleter remover, Enumerator enumerator,
1781 isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE, i::TENURED));
1784 if (getter !=
nullptr) SET_FIELD_WRAPPED(isolate, obj, set_getter, getter);
1785 if (setter !=
nullptr) SET_FIELD_WRAPPED(isolate, obj, set_setter, setter);
1786 if (query !=
nullptr) SET_FIELD_WRAPPED(isolate, obj, set_query, query);
1787 if (descriptor !=
nullptr)
1788 SET_FIELD_WRAPPED(isolate, obj, set_descriptor, descriptor);
1789 if (remover !=
nullptr) SET_FIELD_WRAPPED(isolate, obj, set_deleter, remover);
1790 if (enumerator !=
nullptr)
1791 SET_FIELD_WRAPPED(isolate, obj, set_enumerator, enumerator);
1792 if (definer !=
nullptr) SET_FIELD_WRAPPED(isolate, obj, set_definer, definer);
1793 obj->set_can_intercept_symbols(
1794 !(static_cast<int>(flags) &
1796 obj->set_all_can_read(static_cast<int>(flags) &
1798 obj->set_non_masking(static_cast<int>(flags) &
1800 obj->set_has_no_side_effect(
1801 static_cast<int>(flags) &
1804 if (data.IsEmpty()) {
1805 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1807 obj->set_data(*Utils::OpenHandle(*data));
1811 template <
typename Getter,
typename Setter,
typename Query,
typename Descriptor,
1812 typename Deleter,
typename Enumerator,
typename Definer>
1814 i::Isolate* isolate, Getter getter, Setter setter, Query query,
1815 Descriptor descriptor, Deleter remover, Enumerator enumerator,
1818 CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover,
1819 enumerator, definer, data, flags);
1820 interceptor->set_is_named(
true);
1824 template <
typename Getter,
typename Setter,
typename Query,
typename Descriptor,
1825 typename Deleter,
typename Enumerator,
typename Definer>
1827 i::Isolate* isolate, Getter getter, Setter setter, Query query,
1828 Descriptor descriptor, Deleter remover, Enumerator enumerator,
1831 CreateInterceptorInfo(isolate, getter, setter, query, descriptor, remover,
1832 enumerator, definer, data, flags);
1833 interceptor->set_is_named(
false);
1837 template <
typename Getter,
typename Setter,
typename Query,
typename Descriptor,
1838 typename Deleter,
typename Enumerator,
typename Definer>
1839 static void ObjectTemplateSetNamedPropertyHandler(
1840 ObjectTemplate* templ, Getter getter, Setter setter, Query query,
1841 Descriptor descriptor, Deleter remover, Enumerator enumerator,
1843 i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate();
1844 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1846 auto cons = EnsureConstructor(isolate, templ);
1847 EnsureNotInstantiated(cons,
"ObjectTemplateSetNamedPropertyHandler");
1849 CreateNamedInterceptorInfo(isolate, getter, setter, query, descriptor,
1850 remover, enumerator, definer, data, flags);
1851 i::FunctionTemplateInfo::SetNamedPropertyHandler(isolate, cons, obj);
1856 ObjectTemplateSetNamedPropertyHandler(
1857 this, config.getter, config.setter, config.query, config.descriptor,
1858 config.deleter, config.enumerator, config.definer, config.data,
1864 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1865 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1867 auto cons = EnsureConstructor(isolate,
this);
1868 EnsureNotInstantiated(cons,
"v8::ObjectTemplate::MarkAsUndetectable");
1869 cons->set_undetectable(
true);
1875 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1876 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1878 auto cons = EnsureConstructor(isolate,
this);
1879 EnsureNotInstantiated(cons,
"v8::ObjectTemplate::SetAccessCheckCallback");
1882 isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE, i::TENURED);
1886 SET_FIELD_WRAPPED(isolate, info, set_callback, callback);
1887 info->set_named_interceptor(
nullptr);
1888 info->set_indexed_interceptor(
nullptr);
1890 if (data.IsEmpty()) {
1891 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1893 info->set_data(*Utils::OpenHandle(*data));
1895 i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info);
1896 cons->set_needs_access_check(
true);
1904 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1905 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1907 auto cons = EnsureConstructor(isolate,
this);
1908 EnsureNotInstantiated(
1909 cons,
"v8::ObjectTemplate::SetAccessCheckCallbackWithHandler");
1912 isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE, i::TENURED);
1916 SET_FIELD_WRAPPED(isolate, info, set_callback, callback);
1917 auto named_interceptor = CreateNamedInterceptorInfo(
1918 isolate, named_handler.getter, named_handler.setter, named_handler.query,
1919 named_handler.descriptor, named_handler.deleter, named_handler.enumerator,
1920 named_handler.definer, named_handler.data, named_handler.flags);
1921 info->set_named_interceptor(*named_interceptor);
1922 auto indexed_interceptor = CreateIndexedInterceptorInfo(
1923 isolate, indexed_handler.getter, indexed_handler.setter,
1924 indexed_handler.query, indexed_handler.descriptor,
1925 indexed_handler.deleter, indexed_handler.enumerator,
1926 indexed_handler.definer, indexed_handler.data, indexed_handler.flags);
1927 info->set_indexed_interceptor(*indexed_interceptor);
1929 if (data.IsEmpty()) {
1930 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1932 info->set_data(*Utils::OpenHandle(*data));
1934 i::FunctionTemplateInfo::SetAccessCheckInfo(isolate, cons, info);
1935 cons->set_needs_access_check(
true);
1940 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1941 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1943 auto cons = EnsureConstructor(isolate,
this);
1944 EnsureNotInstantiated(cons,
"v8::ObjectTemplate::SetHandler");
1945 auto obj = CreateIndexedInterceptorInfo(
1946 isolate, config.getter, config.setter, config.query, config.descriptor,
1947 config.deleter, config.enumerator, config.definer, config.data,
1949 i::FunctionTemplateInfo::SetIndexedPropertyHandler(isolate, cons, obj);
1954 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1955 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1957 auto cons = EnsureConstructor(isolate,
this);
1958 EnsureNotInstantiated(cons,
"v8::ObjectTemplate::SetCallAsFunctionHandler");
1960 SET_FIELD_WRAPPED(isolate, obj, set_callback, callback);
1961 SET_FIELD_WRAPPED(isolate, obj, set_js_callback, obj->redirected_callback());
1962 if (data.IsEmpty()) {
1963 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1965 obj->set_data(*Utils::OpenHandle(*data));
1966 i::FunctionTemplateInfo::SetInstanceCallHandler(isolate, cons, obj);
1970 return Utils::OpenHandle(
this)->embedder_field_count();
1974 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1975 if (!Utils::ApiCheck(i::Smi::IsValid(value),
1976 "v8::ObjectTemplate::SetInternalFieldCount()",
1977 "Invalid embedder field count")) {
1980 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1985 EnsureConstructor(isolate,
this);
1987 Utils::OpenHandle(
this)->set_embedder_field_count(value);
1991 return Utils::OpenHandle(
this)->immutable_proto();
1995 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
1996 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
1997 Utils::OpenHandle(
this)->set_immutable_proto(
true);
2006 ScriptCompiler::CachedData::CachedData(
const uint8_t* data_,
int length_,
2007 BufferPolicy buffer_policy_)
2011 buffer_policy(buffer_policy_) {}
2014 ScriptCompiler::CachedData::~CachedData() {
2015 if (buffer_policy == BufferOwned) {
2026 : impl_(new
i::ScriptStreamingData(stream, encoding)) {}
2028 ScriptCompiler::StreamedSource::~StreamedSource() =
default;
2031 auto function_info =
2033 i::Isolate* isolate = function_info->GetIsolate();
2035 isolate->factory()->NewFunctionFromSharedFunctionInfo(
2036 function_info, isolate->native_context());
2037 return ToApiHandle<Script>(
function);
2040 int UnboundScript::GetId() {
2041 auto function_info =
2043 i::Isolate* isolate = function_info->GetIsolate();
2048 return script->id();
2057 if (obj->script()->IsScript()) {
2059 return i::Script::GetLineNumber(script, code_pos);
2071 if (obj->script()->IsScript()) {
2072 i::Object* name = i::Script::cast(obj->script())->name();
2075 return Local<String>();
2085 if (obj->script()->IsScript()) {
2086 i::Object* url = i::Script::cast(obj->script())->source_url();
2099 if (obj->script()->IsScript()) {
2100 i::Object* url = i::Script::cast(obj->script())->source_mapping_url();
2109 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
2110 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.Execute");
2112 InternalEscapableScope);
2120 has_pending_exception = !ToLocal<Value>(
2121 i::Execution::Call(isolate, fun, receiver, 0,
nullptr), &result);
2123 RETURN_ON_FAILED_EXECUTION(
Value);
2124 RETURN_ESCAPED(result);
2131 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2133 return ToApiHandle<Value>(val);
2139 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2141 return ToApiHandle<PrimitiveArray>(val);
2148 return ToApiHandle<UnboundScript>(i::handle(sfi, isolate));
2154 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2155 Utils::ApiCheck(length >= 0,
"v8::PrimitiveArray::New",
2156 "length must be equal or greater than zero");
2158 return ToApiHandle<PrimitiveArray>(array);
2161 int PrimitiveArray::Length()
const {
2163 return array->length();
2166 void PrimitiveArray::Set(Isolate* v8_isolate,
int index,
2167 Local<Primitive> item) {
2170 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2171 Utils::ApiCheck(index >= 0 && index < array->length(),
2172 "v8::PrimitiveArray::Set",
2173 "index must be greater than or equal to 0 and less than the " 2176 array->set(index, *i_item);
2179 Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate,
int index) {
2182 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2183 Utils::ApiCheck(index >= 0 && index < array->length(),
2184 "v8::PrimitiveArray::Get",
2185 "index must be greater than or equal to 0 and less than the " 2188 return ToApiHandle<Primitive>(i_item);
2193 switch (self->status()) {
2194 case i::Module::kUninstantiated:
2195 case i::Module::kPreInstantiating:
2196 return kUninstantiated;
2197 case i::Module::kInstantiating:
2198 return kInstantiating;
2199 case i::Module::kInstantiated:
2200 return kInstantiated;
2201 case i::Module::kEvaluating:
2203 case i::Module::kEvaluated:
2205 case i::Module::kErrored:
2212 Utils::ApiCheck(GetStatus() == kErrored,
"v8::Module::GetException",
2213 "Module status must be kErrored");
2216 return ToApiHandle<Value>(i::handle(self->GetException(), isolate));
2221 return self->info()->module_requests()->length();
2230 CHECK_LT(
i, module_requests->length());
2231 return ToApiHandle<String>(i::handle(module_requests->get(
i), isolate));
2236 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2240 self->info()->module_request_positions(), isolate);
2241 CHECK_LT(
i, module_request_positions->length());
2242 int position = i::Smi::ToInt(module_request_positions->get(
i));
2244 i::Script::PositionInfo info;
2245 i::Script::GetPositionInfo(script, position, &info, i::Script::WITH_OFFSET);
2251 GetStatus() >= kInstantiated,
"v8::Module::GetModuleNamespace",
2252 "v8::Module::GetModuleNamespace must be used on an instantiated module");
2255 i::Module::GetModuleNamespace(self->GetIsolate(),
self);
2256 return ToApiHandle<Value>(module_namespace);
2261 GetStatus() < kEvaluating,
"v8::Module::GetUnboundScript",
2262 "v8::Module::GetUnboundScript must be used on an unevaluated module");
2265 self->GetSharedFunctionInfo(),
self->GetIsolate()));
2271 Module::ResolveCallback callback) {
2272 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
2273 ENTER_V8(isolate, context,
Module, InstantiateModule, Nothing<bool>(),
2275 has_pending_exception = !i::Module::Instantiate(
2276 isolate, Utils::OpenHandle(
this), context, callback);
2277 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
2282 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
2283 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.Execute");
2285 InternalEscapableScope);
2292 CHECK_GE(self->status(), i::Module::kInstantiated);
2295 has_pending_exception = !ToLocal(i::Module::Evaluate(isolate,
self), &result);
2296 RETURN_ON_FAILED_EXECUTION(
Value);
2297 RETURN_ESCAPED(result);
2302 i::Compiler::ScriptDetails GetScriptDetails(
2306 i::Compiler::ScriptDetails script_details;
2307 if (!resource_name.
IsEmpty()) {
2308 script_details.name_obj = Utils::OpenHandle(*(resource_name));
2310 if (!resource_line_offset.
IsEmpty()) {
2311 script_details.line_offset =
2312 static_cast<int>(resource_line_offset->Value());
2314 if (!resource_column_offset.
IsEmpty()) {
2315 script_details.column_offset =
2316 static_cast<int>(resource_column_offset->Value());
2318 script_details.host_defined_options = isolate->factory()->empty_fixed_array();
2319 if (!host_defined_options.
IsEmpty()) {
2320 script_details.host_defined_options =
2321 Utils::OpenHandle(*(host_defined_options));
2323 if (!source_map_url.
IsEmpty()) {
2324 script_details.source_map_url = Utils::OpenHandle(*(source_map_url));
2326 return script_details;
2331 MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
2332 Isolate* v8_isolate, Source* source, CompileOptions options,
2334 auto isolate =
reinterpret_cast<i::Isolate*
>(v8_isolate);
2335 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.ScriptCompiler");
2336 ENTER_V8_NO_SCRIPT(isolate, v8_isolate->GetCurrentContext(), ScriptCompiler,
2337 CompileUnbound, MaybeLocal<UnboundScript>(),
2338 InternalEscapableScope);
2341 if (options == kConsumeCodeCache) {
2342 DCHECK(source->cached_data);
2345 source->cached_data->length);
2350 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT(
"v8.compile"),
"V8.CompileScript");
2351 i::Compiler::ScriptDetails script_details = GetScriptDetails(
2352 isolate, source->resource_name, source->resource_line_offset,
2353 source->resource_column_offset, source->source_map_url,
2354 source->host_defined_options);
2356 i::Compiler::GetSharedFunctionInfoForScript(
2357 isolate, str, script_details, source->resource_options,
nullptr,
2358 script_data, options, no_cache_reason, i::NOT_NATIVES_CODE);
2359 if (options == kConsumeCodeCache) {
2360 source->cached_data->rejected = script_data->rejected();
2363 has_pending_exception = !maybe_function_info.ToHandle(&result);
2364 RETURN_ON_FAILED_EXECUTION(UnboundScript);
2365 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
2369 Isolate* v8_isolate,
Source* source, CompileOptions options,
2372 !source->GetResourceOptions().IsModule(),
2373 "v8::ScriptCompiler::CompileUnboundScript",
2374 "v8::ScriptCompiler::CompileModule must be used to compile modules");
2375 return CompileUnboundInternal(v8_isolate, source, options, no_cache_reason);
2380 CompileOptions options,
2383 !source->GetResourceOptions().IsModule(),
"v8::ScriptCompiler::Compile",
2384 "v8::ScriptCompiler::CompileModule must be used to compile modules");
2385 auto isolate = context->GetIsolate();
2387 CompileUnboundInternal(isolate, source, options, no_cache_reason);
2391 return result->BindToCurrentContext();
2395 Isolate* isolate,
Source* source, CompileOptions options,
2397 CHECK(options == kNoCompileOptions || options == kConsumeCodeCache);
2401 Utils::ApiCheck(source->GetResourceOptions().IsModule(),
2402 "v8::ScriptCompiler::CompileModule",
2403 "Invalid ScriptOrigin: is_module must be true");
2405 CompileUnboundInternal(isolate, source, options, no_cache_reason);
2410 return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared));
2419 i::ConsString cons_string = i::String::VisitFlat(
this,
string, 0);
2420 if (cons_string.is_null())
return is_identifier_;
2424 void VisitOneByteString(
const uint8_t* chars,
int length) {
2425 for (
int i = 0;
i < length; ++
i) {
2427 first_char_ =
false;
2428 is_identifier_ = i::IsIdentifierStart(chars[0]);
2430 is_identifier_ &= i::IsIdentifierPart(chars[
i]);
2434 void VisitTwoByteString(
const uint16_t* chars,
int length) {
2435 for (
int i = 0;
i < length; ++
i) {
2437 first_char_ =
false;
2438 is_identifier_ = i::IsIdentifierStart(chars[0]);
2440 is_identifier_ &= i::IsIdentifierPart(chars[
i]);
2446 bool is_identifier_;
2458 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.ScriptCompiler");
2460 DCHECK(options == CompileOptions::kConsumeCodeCache ||
2461 options == CompileOptions::kEagerCompile ||
2462 options == CompileOptions::kNoCompileOptions);
2466 DCHECK(context->IsNativeContext());
2468 context->empty_function()->shared(), isolate);
2472 isolate->factory()->NewFixedArray(static_cast<int>(arguments_count));
2473 for (
int i = 0; i < static_cast<int>(arguments_count);
i++) {
2477 arguments_list->set(
i, *argument);
2480 for (
size_t i = 0;
i < context_extension_count; ++
i) {
2482 Utils::OpenHandle(*context_extensions[
i]);
2484 context = isolate->factory()->NewWithContext(
2486 i::ScopeInfo::CreateForWithScope(
2488 context->IsNativeContext()
2494 i::Compiler::ScriptDetails script_details = GetScriptDetails(
2495 isolate, source->resource_name, source->resource_line_offset,
2496 source->resource_column_offset, source->source_map_url,
2497 source->host_defined_options);
2500 if (options == kConsumeCodeCache) {
2501 DCHECK(source->cached_data);
2504 source->cached_data->length);
2508 has_pending_exception =
2509 !i::Compiler::GetWrappedFunction(
2510 Utils::OpenHandle(*source->source_string), arguments_list, context,
2511 script_details, source->resource_options, script_data, options,
2514 if (options == kConsumeCodeCache) {
2515 source->cached_data->rejected = script_data->rejected();
2518 RETURN_ON_FAILED_EXECUTION(
Function);
2519 RETURN_ESCAPED(Utils::CallableToLocal(result));
2522 void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); }
2525 Isolate* v8_isolate,
StreamedSource* source, CompileOptions options) {
2526 if (!i::FLAG_script_streaming) {
2531 CHECK(options == ScriptCompiler::kNoCompileOptions);
2534 std::unique_ptr<i::BackgroundCompileTask> task =
2535 base::make_unique<i::BackgroundCompileTask>(data, isolate);
2536 data->task = std::move(task);
2545 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.ScriptCompiler");
2546 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT(
"v8.compile"),
2547 "V8.CompileStreamedScript");
2550 i::Compiler::ScriptDetails script_details = GetScriptDetails(
2551 isolate, origin.ResourceName(), origin.ResourceLineOffset(),
2552 origin.ResourceColumnOffset(), origin.SourceMapUrl(),
2553 origin.HostDefinedOptions());
2557 i::Compiler::GetSharedFunctionInfoForStreamedScript(
2558 isolate, str, script_details, origin.Options(), data);
2561 has_pending_exception = !maybe_function_info.ToHandle(&result);
2562 if (has_pending_exception) isolate->ReportPendingMessages();
2564 RETURN_ON_FAILED_EXECUTION(
Script);
2570 RETURN_ESCAPED(bound);
2574 return static_cast<uint32_t>(base::hash_combine(
2575 internal::Version::Hash(), internal::FlagList::Hash(),
2576 static_cast<uint32_t>(internal::CpuFeatures::SupportedFeatures())));
2583 Utils::OpenHandle(*unbound_script));
2584 DCHECK(shared->is_toplevel());
2585 return i::CodeSerializer::Serialize(shared);
2593 Utils::OpenHandle(*unbound_module_script));
2594 DCHECK(shared->is_toplevel());
2595 return i::CodeSerializer::Serialize(shared);
2603 js_function->GetIsolate());
2604 CHECK(shared->is_wrapped());
2605 return i::CodeSerializer::Serialize(shared);
2621 v8::TryCatch::TryCatch(v8::Isolate* isolate)
2622 : isolate_(reinterpret_cast<
i::Isolate*>(isolate)),
2623 next_(isolate_->try_catch_handler()),
2625 can_continue_(true),
2626 capture_message_(true),
2628 has_terminated_(false) {
2631 js_stack_comparable_address_ =
2632 reinterpret_cast<void*
>(i::SimulatorStack::RegisterCTryCatch(
2633 isolate_, i::GetCurrentStackPosition()));
2634 isolate_->RegisterTryCatchHandler(
this);
2638 v8::TryCatch::~TryCatch() {
2640 v8::Isolate* isolate =
reinterpret_cast<Isolate*
>(isolate_);
2643 if (HasCaught() && capture_message_) {
2648 isolate_->thread_local_top()->rethrowing_message_ =
true;
2649 isolate_->RestorePendingMessageFromTryCatch(
this);
2651 isolate_->UnregisterTryCatchHandler(
this);
2652 i::SimulatorStack::UnregisterCTryCatch(isolate_);
2653 reinterpret_cast<Isolate*
>(isolate_)->ThrowException(exc);
2654 DCHECK(!isolate_->thread_local_top()->rethrowing_message_);
2656 if (HasCaught() && isolate_->has_scheduled_exception()) {
2660 isolate_->CancelScheduledExceptionFromTryCatch(
this);
2662 isolate_->UnregisterTryCatchHandler(
this);
2663 i::SimulatorStack::UnregisterCTryCatch(isolate_);
2667 void* v8::TryCatch::operator
new(
size_t) { base::OS::Abort(); }
2668 void* v8::TryCatch::operator
new[](
size_t) { base::OS::Abort(); }
2669 void v8::TryCatch::operator
delete(
void*,
size_t) { base::OS::Abort(); }
2670 void v8::TryCatch::operator
delete[](
void*,
size_t) { base::OS::Abort(); }
2672 bool v8::TryCatch::HasCaught()
const {
2673 return !
reinterpret_cast<i::Object*
>(exception_)->IsTheHole(isolate_);
2677 bool v8::TryCatch::CanContinue()
const {
2678 return can_continue_;
2682 bool v8::TryCatch::HasTerminated()
const {
2683 return has_terminated_;
2690 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate_));
2705 MaybeLocal<Value> v8::TryCatch::StackTrace(Local<Context> context)
const {
2709 PREPARE_FOR_EXECUTION(context, TryCatch, StackTrace,
Value);
2712 Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name);
2713 has_pending_exception = maybe.IsNothing();
2714 RETURN_ON_FAILED_EXECUTION(
Value);
2716 Local<Value> result;
2717 has_pending_exception =
2718 !ToLocal<Value>(i::JSReceiver::GetProperty(isolate, obj, name), &result);
2719 RETURN_ON_FAILED_EXECUTION(
Value);
2720 RETURN_ESCAPED(result);
2726 DCHECK(message->IsJSMessageObject() || message->IsTheHole(isolate_));
2727 if (HasCaught() && !message->IsTheHole(isolate_)) {
2735 void v8::TryCatch::Reset() {
2736 if (!rethrow_ && HasCaught() && isolate_->has_scheduled_exception()) {
2740 isolate_->CancelScheduledExceptionFromTryCatch(
this);
2746 void v8::TryCatch::ResetInternal() {
2748 exception_ = the_hole;
2749 message_obj_ = the_hole;
2753 void v8::TryCatch::SetVerbose(
bool value) {
2754 is_verbose_ = value;
2757 bool v8::TryCatch::IsVerbose()
const {
return is_verbose_; }
2759 void v8::TryCatch::SetCaptureMessage(
bool value) {
2760 capture_message_ = value;
2767 Local<String> Message::Get()
const {
2768 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2769 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2770 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2773 Local<String> result = Utils::ToLocal(raw_result);
2774 return scope.Escape(result);
2778 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2779 return reinterpret_cast<Isolate*
>(isolate);
2783 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2784 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2787 return GetScriptOriginForScript(isolate, script);
2797 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2798 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2804 return scope.
Escape(Utils::StackTraceToLocal(stackTrace));
2809 auto self = Utils::OpenHandle(
this);
2811 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2814 return Just(msg->GetLineNumber());
2819 auto self = Utils::OpenHandle(
this);
2820 return self->start_position();
2825 auto self = Utils::OpenHandle(
this);
2826 return self->end_position();
2830 auto self = Utils::OpenHandle(
this);
2831 return self->error_level();
2835 auto self = Utils::OpenHandle(
this);
2837 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2840 return msg->GetColumnNumber();
2848 auto self = Utils::OpenHandle(
this);
2850 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2853 const int column_number = msg->GetColumnNumber();
2854 if (column_number == -1)
return -1;
2855 const int start =
self->start_position();
2856 const int end =
self->end_position();
2857 return column_number + (end - start);
2866 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2867 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2868 return Utils::OpenHandle(
this)
2871 .IsSharedCrossOrigin();
2874 bool Message::IsOpaque()
const {
2875 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2876 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2877 return Utils::OpenHandle(
this)->script()->origin_options().IsOpaque();
2881 MaybeLocal<String> Message::GetSourceLine(Local<Context> context)
const {
2882 auto self = Utils::OpenHandle(
this);
2884 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2885 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate));
2887 RETURN_ESCAPED(Utils::ToLocal(msg->GetSourceLine()));
2891 void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
2893 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
2894 i_isolate->PrintCurrentStackTrace(out);
2903 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2905 auto obj = handle(Utils::OpenHandle(
this)->
get(index), isolate);
2907 return scope.
Escape(Utils::StackFrameToLocal(info));
2911 return Utils::OpenHandle(
this)->length();
2920 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
2922 i_isolate->CaptureCurrentStackTrace(frame_limit, options);
2923 return Utils::StackTraceToLocal(stackTrace);
2930 int v = Utils::OpenHandle(
this)->line_number();
2931 return v ? v : Message::kNoLineNumberInfo;
2936 int v = Utils::OpenHandle(
this)->column_number();
2937 return v ? v : Message::kNoLineNumberInfo;
2942 int v = Utils::OpenHandle(
this)->script_id();
2943 return v ? v : Message::kNoScriptIdInfo;
2947 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2951 return obj->IsString()
2958 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2962 return obj->IsString()
2969 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
2973 return obj->IsString()
2981 return Utils::OpenHandle(
this)->is_constructor();
2990 PREPARE_FOR_EXECUTION(v8_isolate->GetCurrentContext(),
JSON, Parse,
Value);
2994 auto maybe = source->IsSeqOneByteString()
2996 :
i::JsonParser<false>::Parse(isolate, source, undefined);
2998 has_pending_exception = !ToLocal<Value>(maybe, &result);
2999 RETURN_ON_FAILED_EXECUTION(
Value);
3000 RETURN_ESCAPED(result);
3003 MaybeLocal<Value> JSON::Parse(Local<Context> context,
3004 Local<String> json_string) {
3005 PREPARE_FOR_EXECUTION(context, JSON, Parse,
Value);
3009 auto maybe = source->IsSeqOneByteString()
3011 :
i::JsonParser<false>::Parse(isolate, source, undefined);
3012 Local<Value> result;
3013 has_pending_exception = !ToLocal<Value>(maybe, &result);
3014 RETURN_ON_FAILED_EXECUTION(
Value);
3015 RETURN_ESCAPED(result);
3025 ? isolate->factory()->empty_string()
3026 : Utils::OpenHandle(*gap);
3028 has_pending_exception =
3029 !i::JsonStringify(isolate,
object, replacer, gap_string).ToHandle(&maybe);
3030 RETURN_ON_FAILED_EXECUTION(
String);
3032 has_pending_exception =
3033 !ToLocal<String>(i::Object::ToString(isolate, maybe), &result);
3034 RETURN_ON_FAILED_EXECUTION(
String);
3035 RETURN_ESCAPED(result);
3043 isolate->ScheduleThrow(*isolate->factory()->NewError(
3044 isolate->error_function(), i::MessageTemplate::kDataCloneError,
3045 Utils::OpenHandle(*
object)));
3046 return Nothing<bool>();
3052 isolate->ScheduleThrow(*isolate->factory()->NewError(
3053 isolate->error_function(), i::MessageTemplate::kDataCloneError,
3054 Utils::OpenHandle(*shared_array_buffer)));
3055 return Nothing<uint32_t>();
3060 return Nothing<uint32_t>();
3065 size_t* actual_size) {
3066 *actual_size = size;
3067 return realloc(old_buffer, size);
3071 return free(buffer);
3076 : isolate(
i), serializer(
i, delegate) {}
3081 ValueSerializer::ValueSerializer(Isolate* isolate)
3084 ValueSerializer::ValueSerializer(Isolate* isolate, Delegate* delegate)
3086 new PrivateData(reinterpret_cast<
i::Isolate*>(isolate), delegate)) {}
3088 ValueSerializer::~ValueSerializer() {
delete private_; }
3093 private_->serializer.SetTreatArrayBufferViewsAsHostObjects(mode);
3098 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3102 Maybe<bool> result = private_->serializer.WriteObject(
object);
3103 has_pending_exception = result.IsNothing();
3104 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
3108 std::vector<uint8_t> ValueSerializer::ReleaseBuffer() {
3109 return private_->serializer.ReleaseBuffer();
3113 return private_->serializer.Release();
3118 private_->serializer.TransferArrayBuffer(transfer_id,
3119 Utils::OpenHandle(*array_buffer));
3122 void ValueSerializer::TransferSharedArrayBuffer(
3124 private_->serializer.TransferArrayBuffer(
3125 transfer_id, Utils::OpenHandle(*shared_array_buffer));
3129 private_->serializer.WriteUint32(value);
3132 void ValueSerializer::WriteUint64(uint64_t value) {
3133 private_->serializer.WriteUint64(value);
3136 void ValueSerializer::WriteDouble(
double value) {
3137 private_->serializer.WriteDouble(value);
3140 void ValueSerializer::WriteRawBytes(
const void* source,
size_t length) {
3141 private_->serializer.WriteRawBytes(source, length);
3145 Isolate* v8_isolate) {
3147 isolate->ScheduleThrow(*isolate->factory()->NewError(
3148 isolate->error_function(),
3149 i::MessageTemplate::kDataCloneDeserializationError));
3154 Isolate* v8_isolate,
uint32_t id) {
3156 isolate->ScheduleThrow(*isolate->factory()->NewError(
3157 isolate->error_function(),
3158 i::MessageTemplate::kDataCloneDeserializationError));
3166 isolate->ScheduleThrow(*isolate->factory()->NewError(
3167 isolate->error_function(),
3168 i::MessageTemplate::kDataCloneDeserializationError));
3174 : isolate(
i), deserializer(
i, data, delegate) {}
3177 bool has_aborted =
false;
3178 bool supports_legacy_wire_format =
false;
3181 ValueDeserializer::ValueDeserializer(Isolate* isolate,
const uint8_t* data,
3185 ValueDeserializer::ValueDeserializer(Isolate* isolate,
const uint8_t* data,
3186 size_t size, Delegate* delegate) {
3187 if (base::IsValueInRangeForNumericType<int>(size)) {
3188 private_ =
new PrivateData(
3189 reinterpret_cast<i::Isolate*>(isolate),
3192 private_ =
new PrivateData(reinterpret_cast<i::Isolate*>(isolate),
3194 private_->has_aborted =
true;
3198 ValueDeserializer::~ValueDeserializer() {
delete private_; }
3201 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3207 if (private_->has_aborted) {
3208 isolate->Throw(*isolate->factory()->NewError(
3209 i::MessageTemplate::kDataCloneDeserializationError));
3210 has_pending_exception =
true;
3211 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
3214 bool read_header =
false;
3215 has_pending_exception = !private_->deserializer.ReadHeader().To(&read_header);
3216 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
3217 DCHECK(read_header);
3219 static const uint32_t kMinimumNonLegacyVersion = 13;
3221 !private_->supports_legacy_wire_format) {
3222 isolate->Throw(*isolate->factory()->NewError(
3223 i::MessageTemplate::kDataCloneDeserializationVersionError));
3224 has_pending_exception =
true;
3225 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
3232 bool supports_legacy_wire_format) {
3233 private_->supports_legacy_wire_format = supports_legacy_wire_format;
3237 private_->deserializer.set_expect_inline_wasm(expect_inline_wasm);
3241 CHECK(!private_->has_aborted);
3242 return private_->deserializer.GetWireFormatVersion();
3246 CHECK(!private_->has_aborted);
3250 result = private_->deserializer.ReadObject();
3253 private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat();
3256 has_pending_exception = !ToLocal(result, &value);
3257 RETURN_ON_FAILED_EXECUTION(
Value);
3258 RETURN_ESCAPED(value);
3263 CHECK(!private_->has_aborted);
3264 private_->deserializer.TransferArrayBuffer(transfer_id,
3265 Utils::OpenHandle(*array_buffer));
3270 CHECK(!private_->has_aborted);
3271 private_->deserializer.TransferArrayBuffer(
3272 transfer_id, Utils::OpenHandle(*shared_array_buffer));
3276 return private_->deserializer.ReadUint32(value);
3279 bool ValueDeserializer::ReadUint64(uint64_t* value) {
3280 return private_->deserializer.ReadUint64(value);
3283 bool ValueDeserializer::ReadDouble(
double* value) {
3284 return private_->deserializer.ReadDouble(value);
3287 bool ValueDeserializer::ReadRawBytes(
size_t length,
const void** data) {
3288 return private_->deserializer.ReadRawBytes(length, data);
3293 bool Value::FullIsUndefined()
const {
3295 bool result =
object->IsUndefined();
3296 DCHECK_EQ(result, QuickIsUndefined());
3301 bool Value::FullIsNull()
const {
3303 bool result =
object->IsNull();
3304 DCHECK_EQ(result, QuickIsNull());
3311 if (object->IsSmi())
return false;
3312 return object->IsTrue();
3318 if (object->IsSmi())
return false;
3319 return object->IsFalse();
3327 return Utils::OpenHandle(
this)->IsName();
3331 bool Value::FullIsString()
const {
3332 bool result = Utils::OpenHandle(
this)->IsString();
3333 DCHECK_EQ(result, QuickIsString());
3339 return Utils::OpenHandle(
this)->IsSymbol();
3344 return Utils::OpenHandle(
this)->IsJSArray();
3350 return obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared();
3355 return Utils::OpenHandle(
this)->IsJSArrayBufferView();
3360 return Utils::OpenHandle(
this)->IsJSTypedArray();
3363 #define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype) \ 3364 bool Value::Is##Type##Array() const { \ 3365 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ 3366 return obj->IsJSTypedArray() && \ 3367 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array; \ 3370 TYPED_ARRAYS(VALUE_IS_TYPED_ARRAY)
3372 #undef VALUE_IS_TYPED_ARRAY 3376 return Utils::OpenHandle(
this)->IsJSDataView();
3382 return obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared();
3390 return Utils::OpenHandle(
this)->IsNumber();
3397 #define VALUE_IS_SPECIFIC_TYPE(Type, Check) \ 3398 bool Value::Is##Type() const { \ 3399 i::Handle<i::Object> obj = Utils::OpenHandle(this); \ 3400 return obj->Is##Check(); \ 3403 VALUE_IS_SPECIFIC_TYPE(ArgumentsObject, JSArgumentsObject)
3409 VALUE_IS_SPECIFIC_TYPE(
Date, JSDate)
3410 VALUE_IS_SPECIFIC_TYPE(
Map, JSMap)
3411 VALUE_IS_SPECIFIC_TYPE(
Set, JSSet)
3412 VALUE_IS_SPECIFIC_TYPE(WeakMap, JSWeakMap)
3413 VALUE_IS_SPECIFIC_TYPE(WeakSet, JSWeakSet)
3414 VALUE_IS_SPECIFIC_TYPE(WebAssemblyCompiledModule, WasmModuleObject)
3416 #undef VALUE_IS_SPECIFIC_TYPE 3420 return Utils::OpenHandle(
this)->IsBoolean();
3425 if (!obj->IsHeapObject())
return false;
3430 if (heap_obj->map()->instance_type() != i::JS_OBJECT_TYPE)
return false;
3431 i::Isolate* isolate = i::JSObject::cast(*heap_obj)->GetIsolate();
3432 return heap_obj->IsExternal(isolate);
3438 if (obj->IsSmi())
return true;
3439 if (obj->IsNumber()) {
3440 return i::IsInt32Double(obj->Number());
3448 if (obj->IsSmi())
return i::Smi::ToInt(*obj) >= 0;
3449 if (obj->IsNumber()) {
3450 double value = obj->Number();
3451 return !i::IsMinusZero(value) &&
3453 value <= i::kMaxUInt32 &&
3454 value == i::FastUI2D(i::FastD2UI(value));
3461 return Utils::OpenHandle(
this)->IsJSError();
3467 return obj->IsJSRegExp();
3472 if (!obj->IsJSFunction())
return false;
3474 return i::IsAsyncFunction(func->shared()->kind());
3479 if (!obj->IsJSFunction())
return false;
3481 return i::IsGeneratorFunction(func->shared()->kind());
3486 return Utils::OpenHandle(
this)->IsJSGeneratorObject();
3491 return Utils::OpenHandle(
this)->IsJSMapIterator();
3496 return Utils::OpenHandle(
this)->IsJSSetIterator();
3502 return Utils::OpenHandle(
this)->IsJSModuleNamespace();
3506 auto obj = Utils::OpenHandle(
this);
3507 if (obj->IsString())
return ToApiHandle<String>(obj);
3508 PREPARE_FOR_EXECUTION(context,
Object, ToString,
String);
3510 has_pending_exception =
3511 !ToLocal<String>(i::Object::ToString(isolate, obj), &result);
3512 RETURN_ON_FAILED_EXECUTION(
String);
3513 RETURN_ESCAPED(result);
3517 Local<String> Value::ToString(Isolate* isolate)
const {
3518 RETURN_TO_LOCAL_UNCHECKED(ToString(isolate->GetCurrentContext()), String);
3522 MaybeLocal<String> Value::ToDetailString(Local<Context> context)
const {
3524 if (obj->IsString())
return ToApiHandle<String>(obj);
3525 PREPARE_FOR_EXECUTION(context, Object, ToDetailString, String);
3526 Local<String> result =
3527 Utils::ToLocal(i::Object::NoSideEffectsToString(isolate, obj));
3528 RETURN_ON_FAILED_EXECUTION(String);
3529 RETURN_ESCAPED(result);
3533 MaybeLocal<Object> Value::ToObject(Local<Context> context)
const {
3534 auto obj = Utils::OpenHandle(
this);
3535 if (obj->IsJSReceiver())
return ToApiHandle<Object>(obj);
3536 PREPARE_FOR_EXECUTION(context, Object, ToObject, Object);
3537 Local<Object> result;
3538 has_pending_exception =
3539 !ToLocal<Object>(i::Object::ToObject(isolate, obj), &result);
3540 RETURN_ON_FAILED_EXECUTION(Object);
3541 RETURN_ESCAPED(result);
3545 Local<v8::Object> Value::ToObject(Isolate* isolate)
const {
3546 RETURN_TO_LOCAL_UNCHECKED(ToObject(isolate->GetCurrentContext()), Object);
3549 MaybeLocal<BigInt> Value::ToBigInt(Local<Context> context)
const {
3551 if (obj->IsBigInt())
return ToApiHandle<BigInt>(obj);
3552 PREPARE_FOR_EXECUTION(context, Object, ToBigInt, BigInt);
3553 Local<BigInt> result;
3554 has_pending_exception =
3555 !ToLocal<BigInt>(i::BigInt::FromObject(isolate, obj), &result);
3556 RETURN_ON_FAILED_EXECUTION(BigInt);
3557 RETURN_ESCAPED(result);
3560 bool Value::BooleanValue(Isolate* v8_isolate)
const {
3561 return Utils::OpenHandle(
this)->BooleanValue(
3562 reinterpret_cast<i::Isolate*>(v8_isolate));
3565 MaybeLocal<Boolean> Value::ToBoolean(Local<Context> context)
const {
3566 return ToBoolean(context->GetIsolate());
3570 Local<Boolean> Value::ToBoolean(Isolate* v8_isolate)
const {
3571 auto isolate =
reinterpret_cast<i::Isolate*
>(v8_isolate);
3572 return ToApiHandle<Boolean>(
3573 isolate->factory()->ToBoolean(BooleanValue(v8_isolate)));
3577 MaybeLocal<Number> Value::ToNumber(Local<Context> context)
const {
3578 auto obj = Utils::OpenHandle(
this);
3579 if (obj->IsNumber())
return ToApiHandle<Number>(obj);
3580 PREPARE_FOR_EXECUTION(context, Object, ToNumber, Number);
3581 Local<Number> result;
3582 has_pending_exception =
3583 !ToLocal<Number>(i::Object::ToNumber(isolate, obj), &result);
3584 RETURN_ON_FAILED_EXECUTION(Number);
3585 RETURN_ESCAPED(result);
3589 Local<Number> Value::ToNumber(Isolate* isolate)
const {
3590 RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number);
3594 MaybeLocal<Integer> Value::ToInteger(Local<Context> context)
const {
3595 auto obj = Utils::OpenHandle(
this);
3596 if (obj->IsSmi())
return ToApiHandle<Integer>(obj);
3597 PREPARE_FOR_EXECUTION(context, Object, ToInteger, Integer);
3598 Local<Integer> result;
3599 has_pending_exception =
3600 !ToLocal<Integer>(i::Object::ToInteger(isolate, obj), &result);
3601 RETURN_ON_FAILED_EXECUTION(Integer);
3602 RETURN_ESCAPED(result);
3606 Local<Integer> Value::ToInteger(Isolate* isolate)
const {
3607 RETURN_TO_LOCAL_UNCHECKED(ToInteger(isolate->GetCurrentContext()), Integer);
3611 MaybeLocal<Int32> Value::ToInt32(Local<Context> context)
const {
3612 auto obj = Utils::OpenHandle(
this);
3613 if (obj->IsSmi())
return ToApiHandle<Int32>(obj);
3614 Local<Int32> result;
3615 PREPARE_FOR_EXECUTION(context, Object, ToInt32, Int32);
3616 has_pending_exception =
3617 !ToLocal<Int32>(i::Object::ToInt32(isolate, obj), &result);
3618 RETURN_ON_FAILED_EXECUTION(Int32);
3619 RETURN_ESCAPED(result);
3623 Local<Int32> Value::ToInt32(Isolate* isolate)
const {
3624 RETURN_TO_LOCAL_UNCHECKED(ToInt32(isolate->GetCurrentContext()), Int32);
3628 MaybeLocal<Uint32> Value::ToUint32(Local<Context> context)
const {
3629 auto obj = Utils::OpenHandle(
this);
3630 if (obj->IsSmi())
return ToApiHandle<Uint32>(obj);
3631 Local<Uint32> result;
3632 PREPARE_FOR_EXECUTION(context, Object, ToUint32, Uint32);
3633 has_pending_exception =
3634 !ToLocal<Uint32>(i::Object::ToUint32(isolate, obj), &result);
3635 RETURN_ON_FAILED_EXECUTION(Uint32);
3636 RETURN_ESCAPED(result);
3640 void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
3642 Utils::ApiCheck(isolate !=
nullptr && !isolate->IsDead(),
3643 "v8::internal::Internals::CheckInitialized",
3644 "Isolate is not initialized or V8 has died");
3648 void External::CheckCast(
v8::Value* that) {
3649 Utils::ApiCheck(that->
IsExternal(),
"v8::External::Cast",
3650 "Could not convert to external");
3654 void v8::Object::CheckCast(
Value* that) {
3656 Utils::ApiCheck(obj->IsJSReceiver(),
"v8::Object::Cast",
3657 "Could not convert to object");
3661 void v8::Function::CheckCast(
Value* that) {
3663 Utils::ApiCheck(obj->IsCallable(),
"v8::Function::Cast",
3664 "Could not convert to function");
3668 void v8::Boolean::CheckCast(
v8::Value* that) {
3670 Utils::ApiCheck(obj->IsBoolean(),
"v8::Boolean::Cast",
3671 "Could not convert to boolean");
3675 void v8::Name::CheckCast(
v8::Value* that) {
3677 Utils::ApiCheck(obj->IsName(),
"v8::Name::Cast",
"Could not convert to name");
3681 void v8::String::CheckCast(
v8::Value* that) {
3683 Utils::ApiCheck(obj->IsString(),
"v8::String::Cast",
3684 "Could not convert to string");
3688 void v8::Symbol::CheckCast(
v8::Value* that) {
3690 Utils::ApiCheck(obj->IsSymbol(),
"v8::Symbol::Cast",
3691 "Could not convert to symbol");
3695 void v8::Private::CheckCast(
v8::Data* that) {
3697 Utils::ApiCheck(obj->IsSymbol() &&
3699 "v8::Private::Cast",
3700 "Could not convert to private");
3704 void v8::Number::CheckCast(
v8::Value* that) {
3706 Utils::ApiCheck(obj->IsNumber(),
3707 "v8::Number::Cast()",
3708 "Could not convert to number");
3712 void v8::Integer::CheckCast(
v8::Value* that) {
3714 Utils::ApiCheck(obj->IsNumber(),
"v8::Integer::Cast",
3715 "Could not convert to number");
3719 void v8::Int32::CheckCast(
v8::Value* that) {
3720 Utils::ApiCheck(that->
IsInt32(),
"v8::Int32::Cast",
3721 "Could not convert to 32-bit signed integer");
3725 void v8::Uint32::CheckCast(
v8::Value* that) {
3726 Utils::ApiCheck(that->
IsUint32(),
"v8::Uint32::Cast",
3727 "Could not convert to 32-bit unsigned integer");
3730 void v8::BigInt::CheckCast(
v8::Value* that) {
3731 Utils::ApiCheck(that->
IsBigInt(),
"v8::BigInt::Cast",
3732 "Could not convert to BigInt");
3735 void v8::Array::CheckCast(
Value* that) {
3737 Utils::ApiCheck(obj->IsJSArray(),
"v8::Array::Cast",
3738 "Could not convert to array");
3742 void v8::Map::CheckCast(
Value* that) {
3744 Utils::ApiCheck(obj->IsJSMap(),
"v8::Map::Cast",
"Could not convert to Map");
3748 void v8::Set::CheckCast(
Value* that) {
3750 Utils::ApiCheck(obj->IsJSSet(),
"v8_Set_Cast",
"Could not convert to Set");
3754 void v8::Promise::CheckCast(
Value* that) {
3755 Utils::ApiCheck(that->IsPromise(),
"v8::Promise::Cast",
3756 "Could not convert to promise");
3760 void v8::Promise::Resolver::CheckCast(
Value* that) {
3761 Utils::ApiCheck(that->IsPromise(),
"v8::Promise::Resolver::Cast",
3762 "Could not convert to promise resolver");
3766 void v8::Proxy::CheckCast(
Value* that) {
3767 Utils::ApiCheck(that->IsProxy(),
"v8::Proxy::Cast",
3768 "Could not convert to proxy");
3771 void v8::WasmCompiledModule::CheckCast(
Value* that) {
3772 Utils::ApiCheck(that->IsWebAssemblyCompiledModule(),
3773 "v8::WasmCompiledModule::Cast",
3774 "Could not convert to wasm compiled module");
3777 void v8::ArrayBuffer::CheckCast(
Value* that) {
3780 obj->IsJSArrayBuffer() && !i::JSArrayBuffer::cast(*obj)->is_shared(),
3781 "v8::ArrayBuffer::Cast()",
"Could not convert to ArrayBuffer");
3785 void v8::ArrayBufferView::CheckCast(
Value* that) {
3787 Utils::ApiCheck(obj->IsJSArrayBufferView(),
3788 "v8::ArrayBufferView::Cast()",
3789 "Could not convert to ArrayBufferView");
3793 void v8::TypedArray::CheckCast(
Value* that) {
3795 Utils::ApiCheck(obj->IsJSTypedArray(),
3796 "v8::TypedArray::Cast()",
3797 "Could not convert to TypedArray");
3800 #define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype) \ 3801 void v8::Type##Array::CheckCast(Value* that) { \ 3802 i::Handle<i::Object> obj = Utils::OpenHandle(that); \ 3804 obj->IsJSTypedArray() && \ 3805 i::JSTypedArray::cast(*obj)->type() == i::kExternal##Type##Array, \ 3806 "v8::" #Type "Array::Cast()", "Could not convert to " #Type "Array"); \ 3809 TYPED_ARRAYS(CHECK_TYPED_ARRAY_CAST)
3811 #undef CHECK_TYPED_ARRAY_CAST 3814 void v8::DataView::CheckCast(
Value* that) {
3816 Utils::ApiCheck(obj->IsJSDataView(),
3817 "v8::DataView::Cast()",
3818 "Could not convert to DataView");
3822 void v8::SharedArrayBuffer::CheckCast(
Value* that) {
3825 obj->IsJSArrayBuffer() && i::JSArrayBuffer::cast(*obj)->is_shared(),
3826 "v8::SharedArrayBuffer::Cast()",
3827 "Could not convert to SharedArrayBuffer");
3831 void v8::Date::CheckCast(
v8::Value* that) {
3833 Utils::ApiCheck(obj->IsJSDate(),
"v8::Date::Cast()",
3834 "Could not convert to date");
3838 void v8::StringObject::CheckCast(
v8::Value* that) {
3840 Utils::ApiCheck(obj->IsStringWrapper(),
"v8::StringObject::Cast()",
3841 "Could not convert to StringObject");
3845 void v8::SymbolObject::CheckCast(
v8::Value* that) {
3847 Utils::ApiCheck(obj->IsSymbolWrapper(),
"v8::SymbolObject::Cast()",
3848 "Could not convert to SymbolObject");
3852 void v8::NumberObject::CheckCast(
v8::Value* that) {
3854 Utils::ApiCheck(obj->IsNumberWrapper(),
"v8::NumberObject::Cast()",
3855 "Could not convert to NumberObject");
3858 void v8::BigIntObject::CheckCast(
v8::Value* that) {
3860 Utils::ApiCheck(obj->IsBigIntWrapper(),
"v8::BigIntObject::Cast()",
3861 "Could not convert to BigIntObject");
3864 void v8::BooleanObject::CheckCast(
v8::Value* that) {
3866 Utils::ApiCheck(obj->IsBooleanWrapper(),
"v8::BooleanObject::Cast()",
3867 "Could not convert to BooleanObject");
3871 void v8::RegExp::CheckCast(
v8::Value* that) {
3873 Utils::ApiCheck(obj->IsJSRegExp(),
3874 "v8::RegExp::Cast()",
3875 "Could not convert to regular expression");
3879 Maybe<bool> Value::BooleanValue(Local<Context> context)
const {
3881 return Just(Utils::OpenHandle(
this)->BooleanValue(isolate));
3885 Maybe<double> Value::NumberValue(Local<Context> context)
const {
3886 auto obj = Utils::OpenHandle(
this);
3887 if (obj->IsNumber())
return Just(obj->Number());
3888 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3889 ENTER_V8(isolate, context,
Value, NumberValue, Nothing<double>(),
3892 has_pending_exception = !i::Object::ToNumber(isolate, obj).ToHandle(&num);
3893 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
double);
3894 return Just(num->Number());
3898 Maybe<int64_t> Value::IntegerValue(Local<Context> context)
const {
3899 auto obj = Utils::OpenHandle(
this);
3900 if (obj->IsNumber()) {
3901 return Just(NumberToInt64(*obj));
3903 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3904 ENTER_V8(isolate, context,
Value, IntegerValue, Nothing<int64_t>(),
3907 has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num);
3908 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
int64_t);
3909 return Just(NumberToInt64(*num));
3913 Maybe<int32_t> Value::Int32Value(Local<Context> context)
const {
3914 auto obj = Utils::OpenHandle(
this);
3915 if (obj->IsNumber())
return Just(NumberToInt32(*obj));
3916 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3917 ENTER_V8(isolate, context,
Value, Int32Value, Nothing<int32_t>(),
3920 has_pending_exception = !i::Object::ToInt32(isolate, obj).ToHandle(&num);
3921 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int32_t);
3922 return Just(num->IsSmi() ? i::Smi::ToInt(*num)
3923 : static_cast<int32_t>(num->Number()));
3927 Maybe<uint32_t> Value::Uint32Value(Local<Context> context)
const {
3928 auto obj = Utils::OpenHandle(
this);
3929 if (obj->IsNumber())
return Just(NumberToUint32(*obj));
3930 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3931 ENTER_V8(isolate, context,
Value, Uint32Value, Nothing<uint32_t>(),
3934 has_pending_exception = !i::Object::ToUint32(isolate, obj).ToHandle(&num);
3935 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
uint32_t);
3936 return Just(num->IsSmi() ?
static_cast<uint32_t>(i::Smi::ToInt(*num))
3937 : static_cast<uint32_t>(num->Number()));
3942 auto self = Utils::OpenHandle(
this);
3943 if (self->IsSmi()) {
3944 if (i::Smi::ToInt(*
self) >= 0)
return Utils::Uint32ToLocal(
self);
3947 PREPARE_FOR_EXECUTION(context,
Object, ToArrayIndex,
Uint32);
3949 has_pending_exception =
3950 !i::Object::ToString(isolate,
self).ToHandle(&string_obj);
3951 RETURN_ON_FAILED_EXECUTION(
Uint32);
3954 if (str->AsArrayIndex(&index)) {
3956 if (index <= static_cast<uint32_t>(i::Smi::kMaxValue)) {
3959 value = isolate->factory()->NewNumber(index);
3961 RETURN_ESCAPED(Utils::Uint32ToLocal(value));
3968 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
3969 auto self = Utils::OpenHandle(
this);
3970 auto other = Utils::OpenHandle(*that);
3971 return i::Object::Equals(isolate,
self, other);
3976 auto self = Utils::OpenHandle(
this);
3977 auto other = Utils::OpenHandle(*that);
3978 return self->StrictEquals(*other);
3982 bool Value::SameValue(Local<Value> that)
const {
3983 auto self = Utils::OpenHandle(
this);
3984 auto other = Utils::OpenHandle(*that);
3985 return self->SameValue(*other);
3988 Local<String> Value::TypeOf(v8::Isolate* external_isolate) {
3990 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
3991 LOG_API(isolate,
Value, TypeOf);
3992 return Utils::ToLocal(i::Object::TypeOf(isolate, Utils::OpenHandle(
this)));
3997 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
3998 ENTER_V8(isolate, context,
Value, InstanceOf, Nothing<bool>(),
4000 auto left = Utils::OpenHandle(
this);
4001 auto right = Utils::OpenHandle(*
object);
4003 has_pending_exception =
4004 !i::Object::InstanceOf(isolate, left, right).ToHandle(&result);
4005 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4006 return Just(result->IsTrue(isolate));
4011 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4012 ENTER_V8(isolate, context, Object, Set, Nothing<bool>(),
i::HandleScope);
4013 auto self = Utils::OpenHandle(
this);
4014 auto key_obj = Utils::OpenHandle(*key);
4015 auto value_obj = Utils::OpenHandle(*value);
4016 has_pending_exception =
4017 i::Runtime::SetObjectProperty(isolate,
self, key_obj, value_obj,
4018 i::LanguageMode::kSloppy,
4019 i::StoreOrigin::kMaybeKeyed)
4021 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4027 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4028 return Set(context, key, value).FromMaybe(
false);
4034 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4035 ENTER_V8(isolate, context, Object, Set, Nothing<bool>(),
i::HandleScope);
4036 auto self = Utils::OpenHandle(
this);
4037 auto value_obj = Utils::OpenHandle(*value);
4038 has_pending_exception = i::Object::SetElement(isolate,
self, index, value_obj,
4039 i::LanguageMode::kSloppy)
4041 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4047 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4048 return Set(context, index, value).FromMaybe(
false);
4055 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4056 ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(),
4062 Maybe<bool> result = i::JSReceiver::CreateDataProperty(
4063 isolate,
self, key_obj, value_obj, i::kDontThrow);
4064 has_pending_exception = result.IsNothing();
4065 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4073 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4074 ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(),
4080 Maybe<bool> result =
4081 i::JSReceiver::CreateDataProperty(&it, value_obj, i::kDontThrow);
4082 has_pending_exception = result.IsNothing();
4083 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4092 v8::PropertyDescriptor::PropertyDescriptor() : private_(new
PrivateData()) {}
4096 : private_(new PrivateData()) {
4097 private_->desc.set_value(Utils::OpenHandle(*value,
true));
4103 : private_(new PrivateData()) {
4104 private_->desc.set_value(Utils::OpenHandle(*value,
true));
4105 private_->desc.set_writable(writable);
4111 : private_(new PrivateData()) {
4112 DCHECK(
get.IsEmpty() || get->IsUndefined() ||
get->IsFunction());
4113 DCHECK(
set.IsEmpty() || set->IsUndefined() ||
set->IsFunction());
4114 private_->desc.set_get(Utils::OpenHandle(*
get,
true));
4115 private_->desc.set_set(Utils::OpenHandle(*
set,
true));
4118 v8::PropertyDescriptor::~PropertyDescriptor() {
delete private_; }
4121 DCHECK(private_->desc.has_value());
4122 return Utils::ToLocal(private_->desc.value());
4126 DCHECK(private_->desc.has_get());
4127 return Utils::ToLocal(private_->desc.get());
4131 DCHECK(private_->desc.has_set());
4132 return Utils::ToLocal(private_->desc.set());
4135 bool v8::PropertyDescriptor::has_value()
const {
4136 return private_->desc.has_value();
4138 bool v8::PropertyDescriptor::has_get()
const {
4139 return private_->desc.has_get();
4141 bool v8::PropertyDescriptor::has_set()
const {
4142 return private_->desc.has_set();
4145 bool v8::PropertyDescriptor::writable()
const {
4146 DCHECK(private_->desc.has_writable());
4147 return private_->desc.writable();
4150 bool v8::PropertyDescriptor::has_writable()
const {
4151 return private_->desc.has_writable();
4154 void v8::PropertyDescriptor::set_enumerable(
bool enumerable) {
4155 private_->desc.set_enumerable(enumerable);
4158 bool v8::PropertyDescriptor::enumerable()
const {
4159 DCHECK(private_->desc.has_enumerable());
4160 return private_->desc.enumerable();
4163 bool v8::PropertyDescriptor::has_enumerable()
const {
4164 return private_->desc.has_enumerable();
4167 void v8::PropertyDescriptor::set_configurable(
bool configurable) {
4168 private_->desc.set_configurable(configurable);
4171 bool v8::PropertyDescriptor::configurable()
const {
4172 DCHECK(private_->desc.has_configurable());
4173 return private_->desc.configurable();
4176 bool v8::PropertyDescriptor::has_configurable()
const {
4177 return private_->desc.has_configurable();
4184 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4193 desc.set_value(value_obj);
4195 if (self->IsJSProxy()) {
4196 ENTER_V8(isolate, context, Object, DefineOwnProperty, Nothing<bool>(),
4198 Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
4199 isolate,
self, key_obj, &desc, i::kDontThrow);
4201 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4206 ENTER_V8_NO_SCRIPT(isolate, context, Object, DefineOwnProperty,
4208 Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
4209 isolate,
self, key_obj, &desc, i::kDontThrow);
4210 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4217 PropertyDescriptor& descriptor) {
4218 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4219 ENTER_V8(isolate, context, Object, DefineOwnProperty, Nothing<bool>(),
4224 Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
4225 isolate,
self, key_obj, &descriptor.get_private()->desc, i::kDontThrow);
4226 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4230 Maybe<bool> v8::Object::SetPrivate(Local<Context> context, Local<Private> key,
4231 Local<Value> value) {
4232 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4233 ENTER_V8_NO_SCRIPT(isolate, context, Object, SetPrivate, Nothing<bool>(),
4235 auto self = Utils::OpenHandle(
this);
4236 auto key_obj = Utils::OpenHandle(reinterpret_cast<Name*>(*key));
4237 auto value_obj = Utils::OpenHandle(*value);
4238 if (self->IsJSProxy()) {
4240 desc.set_writable(
true);
4241 desc.set_enumerable(
false);
4242 desc.set_configurable(
true);
4243 desc.set_value(value_obj);
4244 return i::JSProxy::SetPrivateSymbol(
4250 has_pending_exception = i::JSObject::DefineOwnPropertyIgnoreAttributes(
4251 &it, value_obj, i::DONT_ENUM)
4253 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4258 MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
4260 PREPARE_FOR_EXECUTION(context, Object, Get,
Value);
4261 auto self = Utils::OpenHandle(
this);
4262 auto key_obj = Utils::OpenHandle(*key);
4264 has_pending_exception =
4265 !i::Runtime::GetObjectProperty(isolate,
self, key_obj).ToHandle(&result);
4266 RETURN_ON_FAILED_EXECUTION(
Value);
4267 RETURN_ESCAPED(Utils::ToLocal(result));
4272 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4273 RETURN_TO_LOCAL_UNCHECKED(Get(context, key),
Value);
4277 MaybeLocal<Value> v8::Object::Get(Local<Context> context,
uint32_t index) {
4278 PREPARE_FOR_EXECUTION(context, Object, Get,
Value);
4279 auto self = Utils::OpenHandle(
this);
4281 has_pending_exception =
4282 !i::JSReceiver::GetElement(isolate,
self, index).ToHandle(&result);
4283 RETURN_ON_FAILED_EXECUTION(
Value);
4284 RETURN_ESCAPED(Utils::ToLocal(result));
4288 Local<Value> v8::Object::Get(
uint32_t index) {
4289 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4290 RETURN_TO_LOCAL_UNCHECKED(Get(context, index),
Value);
4294 MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
4295 Local<Private> key) {
4296 return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
4302 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4303 ENTER_V8(isolate, context,
Object, GetPropertyAttributes,
4305 auto self = Utils::OpenHandle(
this);
4306 auto key_obj = Utils::OpenHandle(*key);
4307 if (!key_obj->IsName()) {
4308 has_pending_exception =
4309 !i::Object::ToString(isolate, key_obj).ToHandle(&key_obj);
4313 auto result = i::JSReceiver::GetPropertyAttributes(
self, key_name);
4314 has_pending_exception = result.IsNothing();
4316 if (result.FromJust() == i::ABSENT) {
4317 return Just(static_cast<PropertyAttribute>(i::NONE));
4319 return Just(static_cast<PropertyAttribute>(result.FromJust()));
4325 PREPARE_FOR_EXECUTION(context,
Object, GetOwnPropertyDescriptor,
Value);
4331 i::JSReceiver::GetOwnPropertyDescriptor(isolate, obj, key_name, &desc);
4332 has_pending_exception = found.IsNothing();
4333 RETURN_ON_FAILED_EXECUTION(
Value);
4335 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
4337 RETURN_ESCAPED(Utils::ToLocal(desc.ToObject(isolate)));
4342 auto isolate = Utils::OpenHandle(
this)->GetIsolate();
4343 auto self = Utils::OpenHandle(
this);
4345 return Utils::ToLocal(i::PrototypeIterator::GetCurrent(iter));
4351 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4352 ENTER_V8(isolate, context,
Object, SetPrototype, Nothing<bool>(),
4354 auto self = Utils::OpenHandle(
this);
4355 auto value_obj = Utils::OpenHandle(*value);
4358 TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
4360 i::JSReceiver::SetPrototype(
self, value_obj,
false, i::kThrowOnError);
4361 has_pending_exception = result.IsNothing();
4362 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4369 auto self = Utils::OpenHandle(
this);
4370 auto isolate =
self->GetIsolate();
4372 auto tmpl_info = *Utils::OpenHandle(*tmpl);
4373 while (!tmpl_info->IsTemplateFor(iter.GetCurrent<
i::JSObject>())) {
4376 if (!iter.GetCurrent()->IsJSObject())
return Local<Object>();
4379 return Utils::ToLocal(i::handle(iter.GetCurrent<
i::JSObject>(), isolate));
4383 return GetPropertyNames(
4384 context, v8::KeyCollectionMode::kIncludePrototypes,
4385 static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS),
4386 v8::IndexFilter::kIncludeIndices);
4389 MaybeLocal<Array> v8::Object::GetPropertyNames(
4393 PREPARE_FOR_EXECUTION(context, Object, GetPropertyNames, Array);
4394 auto self = Utils::OpenHandle(
this);
4397 isolate, static_cast<i::KeyCollectionMode>(mode),
4398 static_cast<i::PropertyFilter>(property_filter));
4399 accumulator.set_skip_indices(index_filter == IndexFilter::kSkipIndices);
4400 has_pending_exception = accumulator.CollectKeys(
self,
self).IsNothing();
4401 RETURN_ON_FAILED_EXECUTION(Array);
4403 accumulator.GetKeys(static_cast<i::GetKeysConversion>(key_conversion));
4404 DCHECK(self->map()->EnumLength() == i::kInvalidEnumCacheSentinel ||
4405 self->map()->EnumLength() == 0 ||
4406 self->map()->instance_descriptors()->enum_cache()->keys() != *value);
4407 auto result = isolate->factory()->NewJSArrayWithElements(value);
4408 RETURN_ESCAPED(Utils::ToLocal(result));
4412 Local<Array> v8::Object::GetPropertyNames() {
4413 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4414 RETURN_TO_LOCAL_UNCHECKED(GetPropertyNames(context), Array);
4417 MaybeLocal<Array> v8::Object::GetOwnPropertyNames(Local<Context> context) {
4418 return GetOwnPropertyNames(
4419 context, static_cast<v8::PropertyFilter>(ONLY_ENUMERABLE | SKIP_SYMBOLS));
4422 Local<Array> v8::Object::GetOwnPropertyNames() {
4423 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4424 RETURN_TO_LOCAL_UNCHECKED(GetOwnPropertyNames(context), Array);
4430 return GetPropertyNames(context, KeyCollectionMode::kOwnOnly, filter,
4431 v8::IndexFilter::kIncludeIndices, key_conversion);
4435 PREPARE_FOR_EXECUTION(context,
Object, ObjectProtoToString,
String);
4436 auto self = Utils::OpenHandle(
this);
4438 has_pending_exception =
4439 !ToLocal<Value>(i::Execution::Call(isolate, isolate->object_to_string(),
4442 RETURN_ON_FAILED_EXECUTION(
String);
4448 auto self = Utils::OpenHandle(
this);
4450 return Utils::ToLocal(name);
4455 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4456 ENTER_V8(isolate, context,
Object, SetIntegrityLevel, Nothing<bool>(),
4458 auto self = Utils::OpenHandle(
this);
4459 i::JSReceiver::IntegrityLevel i_level =
4460 level == IntegrityLevel::kFrozen ? i::FROZEN : i::SEALED;
4462 i::JSReceiver::SetIntegrityLevel(
self, i_level, i::kThrowOnError);
4463 has_pending_exception = result.IsNothing();
4464 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4469 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4470 auto self = Utils::OpenHandle(
this);
4471 auto key_obj = Utils::OpenHandle(*key);
4472 if (self->IsJSProxy()) {
4474 Maybe<bool> result = i::Runtime::DeleteObjectProperty(
4475 isolate,
self, key_obj, i::LanguageMode::kSloppy);
4476 has_pending_exception = result.IsNothing();
4477 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4482 ENTER_V8_NO_SCRIPT(isolate, context, Object, Delete, Nothing<bool>(),
4484 Maybe<bool> result = i::Runtime::DeleteObjectProperty(
4485 isolate,
self, key_obj, i::LanguageMode::kSloppy);
4486 has_pending_exception = result.IsNothing();
4487 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4493 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4494 return Delete(context, key).FromMaybe(
false);
4497 Maybe<bool> v8::Object::DeletePrivate(Local<Context> context,
4498 Local<Private> key) {
4499 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4502 ENTER_V8_NO_SCRIPT(isolate, context, Object, Delete, Nothing<bool>(),
4504 auto self = Utils::OpenHandle(
this);
4505 auto key_obj = Utils::OpenHandle(*key);
4506 Maybe<bool> result = i::Runtime::DeleteObjectProperty(
4507 isolate,
self, key_obj, i::LanguageMode::kSloppy);
4508 has_pending_exception = result.IsNothing();
4509 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4514 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4516 auto self = Utils::OpenHandle(
this);
4517 auto key_obj = Utils::OpenHandle(*key);
4521 if (key_obj->ToArrayIndex(&index)) {
4522 maybe = i::JSReceiver::HasElement(
self, index);
4526 if (i::Object::ToName(isolate, key_obj).ToHandle(&name)) {
4527 maybe = i::JSReceiver::HasProperty(
self, name);
4530 has_pending_exception = maybe.IsNothing();
4531 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4537 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4538 return Has(context, key).FromMaybe(
false);
4543 return HasOwnProperty(context,
Local<Name>(reinterpret_cast<Name*>(*key)));
4548 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4550 auto self = Utils::OpenHandle(
this);
4551 Maybe<bool> result = i::JSReceiver::DeleteElement(
self, index);
4552 has_pending_exception = result.IsNothing();
4553 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4559 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4560 ENTER_V8(isolate, context, Object, Has, Nothing<bool>(),
i::HandleScope);
4561 auto self = Utils::OpenHandle(
this);
4562 auto maybe = i::JSReceiver::HasElement(
self, index);
4563 has_pending_exception = maybe.IsNothing();
4564 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4568 template <
typename Getter,
typename Setter,
typename Data>
4569 static Maybe<bool> ObjectSetAccessor(
4570 Local<Context> context, Object*
self, Local<Name> name, Getter getter,
4575 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4576 ENTER_V8_NO_SCRIPT(isolate, context, Object, SetAccessor, Nothing<bool>(),
4578 if (!Utils::OpenHandle(
self)->IsJSObject())
return Just(
false);
4583 MakeAccessorInfo(isolate, name, getter, setter, data, settings, signature,
4584 is_special_data_property, replace_on_access);
4585 info->set_getter_side_effect_type(getter_side_effect_type);
4586 info->set_setter_side_effect_type(setter_side_effect_type);
4587 if (info.is_null())
return Nothing<bool>();
4588 bool fast = obj->HasFastProperties();
4592 i::PropertyAttributes attrs =
static_cast<i::PropertyAttributes
>(attributes);
4593 has_pending_exception =
4594 !i::JSObject::SetAccessor(obj, accessor_name, info, attrs)
4596 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4597 if (result->IsUndefined(isolate))
return Just(
false);
4599 i::JSObject::MigrateSlowToFast(obj, 0,
"APISetAccessor");
4605 AccessorNameGetterCallback getter,
4606 AccessorNameSetterCallback setter,
4611 return ObjectSetAccessor(context,
this, name, getter, setter,
4613 i::FLAG_disable_old_api_accessors,
false,
4614 getter_side_effect_type, setter_side_effect_type);
4623 DCHECK_EQ(v8::DEFAULT, settings);
4624 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
4625 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
4627 auto self = Utils::OpenHandle(
this);
4628 if (!self->IsJSObject())
return;
4631 if (setter_i.is_null()) setter_i = isolate->factory()->null_value();
4633 v8::Utils::OpenHandle(*name), getter_i, setter_i,
4634 static_cast<i::PropertyAttributes>(attribute));
4639 AccessorNameGetterCallback getter, AccessorNameSetterCallback setter,
4643 return ObjectSetAccessor(context,
this, name, getter, setter, data, DEFAULT,
4644 attributes,
true,
false, getter_side_effect_type,
4645 setter_side_effect_type);
4653 return ObjectSetAccessor(context,
this, name, getter,
4654 static_cast<AccessorNameSetterCallback>(
nullptr),
4655 data, DEFAULT, attributes,
true,
true,
4656 getter_side_effect_type, setter_side_effect_type);
4661 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4662 ENTER_V8(isolate, context,
Object, HasOwnProperty, Nothing<bool>(),
4664 auto self = Utils::OpenHandle(
this);
4665 auto key_val = Utils::OpenHandle(*key);
4666 auto result = i::JSReceiver::HasOwnProperty(
self, key_val);
4667 has_pending_exception = result.IsNothing();
4668 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4673 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4674 ENTER_V8(isolate, context,
Object, HasOwnProperty, Nothing<bool>(),
4676 auto self = Utils::OpenHandle(
this);
4677 auto result = i::JSReceiver::HasOwnProperty(
self, index);
4678 has_pending_exception = result.IsNothing();
4679 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4685 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4686 ENTER_V8_NO_SCRIPT(isolate, context,
Object, HasRealNamedProperty,
4688 auto self = Utils::OpenHandle(
this);
4689 if (!self->IsJSObject())
return Just(
false);
4690 auto key_val = Utils::OpenHandle(*key);
4691 auto result = i::JSObject::HasRealNamedProperty(
4693 has_pending_exception = result.IsNothing();
4694 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4700 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4701 return HasRealNamedProperty(context, key).FromMaybe(
false);
4705 Maybe<bool> v8::Object::HasRealIndexedProperty(Local<Context> context,
4707 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4708 ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealIndexedProperty,
4710 auto self = Utils::OpenHandle(
this);
4711 if (!self->IsJSObject())
return Just(
false);
4712 auto result = i::JSObject::HasRealElementProperty(
4714 has_pending_exception = result.IsNothing();
4715 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4720 bool v8::Object::HasRealIndexedProperty(
uint32_t index) {
4721 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4722 return HasRealIndexedProperty(context, index).FromMaybe(
false);
4726 Maybe<bool> v8::Object::HasRealNamedCallbackProperty(Local<Context> context,
4728 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4729 ENTER_V8_NO_SCRIPT(isolate, context, Object, HasRealNamedCallbackProperty,
4731 auto self = Utils::OpenHandle(
this);
4732 if (!self->IsJSObject())
return Just(
false);
4733 auto key_val = Utils::OpenHandle(*key);
4734 auto result = i::JSObject::HasRealNamedCallbackProperty(
4736 has_pending_exception = result.IsNothing();
4737 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
4742 bool v8::Object::HasRealNamedCallbackProperty(Local<String> key) {
4743 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
4744 return HasRealNamedCallbackProperty(context, key).FromMaybe(
false);
4749 auto self = Utils::OpenHandle(
this);
4750 return self->IsJSObject() &&
4756 auto self = Utils::OpenHandle(
this);
4757 return self->IsJSObject() &&
4764 PREPARE_FOR_EXECUTION(context,
Object, GetRealNamedPropertyInPrototypeChain,
4772 i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter);
4774 isolate,
self, key_obj, proto,
4775 i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
4777 has_pending_exception = !ToLocal<Value>(i::Object::GetProperty(&it), &result);
4778 RETURN_ON_FAILED_EXECUTION(
Value);
4780 RETURN_ESCAPED(result);
4787 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4788 ENTER_V8_NO_SCRIPT(isolate, context,
Object,
4789 GetRealNamedPropertyAttributesInPrototypeChain,
4792 if (!self->IsJSObject())
return Nothing<PropertyAttribute>();
4795 if (iter.IsAtEnd())
return Nothing<PropertyAttribute>();
4797 i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter);
4799 isolate,
self, key_obj, proto,
4800 i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
4802 i::JSReceiver::GetPropertyAttributes(&it);
4804 if (!it.IsFound())
return Nothing<PropertyAttribute>();
4805 if (result.FromJust() == i::ABSENT)
return Just(
None);
4806 return Just(static_cast<PropertyAttribute>(result.FromJust()));
4812 PREPARE_FOR_EXECUTION(context,
Object, GetRealNamedProperty,
Value);
4813 auto self = Utils::OpenHandle(
this);
4814 auto key_obj = Utils::OpenHandle(*key);
4816 isolate,
self, key_obj,
self,
4817 i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
4819 has_pending_exception = !ToLocal<Value>(i::Object::GetProperty(&it), &result);
4820 RETURN_ON_FAILED_EXECUTION(
Value);
4822 RETURN_ESCAPED(result);
4828 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4829 ENTER_V8_NO_SCRIPT(isolate, context,
Object, GetRealNamedPropertyAttributes,
4831 auto self = Utils::OpenHandle(
this);
4832 auto key_obj = Utils::OpenHandle(*key);
4834 isolate,
self, key_obj,
self,
4835 i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
4836 auto result = i::JSReceiver::GetPropertyAttributes(&it);
4838 if (!it.IsFound())
return Nothing<PropertyAttribute>();
4839 if (result.FromJust() == i::ABSENT) {
4840 return Just(static_cast<PropertyAttribute>(i::NONE));
4842 return Just<PropertyAttribute>(
4849 auto isolate =
self->GetIsolate();
4850 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
4851 auto result = isolate->factory()->CopyJSObject(
self);
4852 CHECK(!result.is_null());
4853 return Utils::ToLocal(result);
4858 auto self = Utils::OpenHandle(
this);
4859 return Utils::ToLocal(self->GetCreationContext());
4865 auto isolate = Utils::OpenHandle(
this)->GetIsolate();
4867 auto self = Utils::OpenHandle(
this);
4868 return self->GetOrCreateIdentityHash(isolate)->value();
4873 auto self = Utils::OpenHandle(
this);
4874 return self->IsCallable();
4878 auto self = Utils::OpenHandle(
this);
4879 return self->IsConstructor();
4885 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4886 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.Execute");
4888 InternalEscapableScope);
4890 auto self = Utils::OpenHandle(
this);
4891 auto recv_obj = Utils::OpenHandle(*recv);
4895 has_pending_exception = !ToLocal<Value>(
4896 i::Execution::Call(isolate,
self, recv_obj, argc, args), &result);
4897 RETURN_ON_FAILED_EXECUTION(
Value);
4898 RETURN_ESCAPED(result);
4904 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4905 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.Execute");
4907 InternalEscapableScope);
4909 auto self = Utils::OpenHandle(
this);
4913 has_pending_exception = !ToLocal<Value>(
4914 i::Execution::New(isolate,
self,
self, argc, args), &result);
4915 RETURN_ON_FAILED_EXECUTION(
Value);
4916 RETURN_ESCAPED(result);
4921 int length, ConstructorBehavior behavior,
4923 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
4925 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
4929 if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
4930 return templ->GetFunction(context);
4936 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length,
4937 ConstructorBehavior::kAllow)
4941 MaybeLocal<Object> Function::NewInstance(Local<Context> context,
int argc,
4943 return NewInstanceWithSideEffectType(context, argc, argv,
4944 SideEffectType::kHasSideEffect);
4950 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4951 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.Execute");
4953 InternalEscapableScope);
4955 auto self = Utils::OpenHandle(
this);
4957 bool should_set_has_no_side_effect =
4958 side_effect_type == SideEffectType::kHasNoSideEffect &&
4959 isolate->debug_execution_mode() == i::DebugInfo::kSideEffects;
4960 if (should_set_has_no_side_effect) {
4961 CHECK(self->IsJSFunction() &&
4962 i::JSFunction::cast(*self)->shared()->IsApiFunction());
4964 i::JSFunction::cast(*self)->shared()->get_api_func_data()->call_code();
4965 if (obj->IsCallHandlerInfo()) {
4967 if (!handler_info->IsSideEffectFreeCallHandlerInfo()) {
4968 handler_info->SetNextCallHasNoSideEffect();
4974 has_pending_exception = !ToLocal<Object>(
4975 i::Execution::New(isolate,
self,
self, argc, args), &result);
4976 if (should_set_has_no_side_effect) {
4978 i::JSFunction::cast(*self)->shared()->get_api_func_data()->call_code();
4979 if (obj->IsCallHandlerInfo()) {
4981 if (has_pending_exception) {
4983 handler_info->NextCallHasNoSideEffect();
4985 DCHECK(handler_info->IsSideEffectCallHandlerInfo() ||
4986 handler_info->IsSideEffectFreeCallHandlerInfo());
4990 RETURN_ON_FAILED_EXECUTION(
Object);
4991 RETURN_ESCAPED(result);
4998 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
4999 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.Execute");
5001 InternalEscapableScope);
5003 auto self = Utils::OpenHandle(
this);
5004 Utils::ApiCheck(!
self.is_null(),
"v8::Function::Call",
5005 "Function to be called is a null pointer");
5010 has_pending_exception = !ToLocal<Value>(
5011 i::Execution::Call(isolate,
self, recv_obj, argc, args), &result);
5012 RETURN_ON_FAILED_EXECUTION(
Value);
5013 RETURN_ESCAPED(result);
5019 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
5020 RETURN_TO_LOCAL_UNCHECKED(Call(context, recv, argc, argv),
Value);
5025 auto self = Utils::OpenHandle(
this);
5026 if (!self->IsJSFunction())
return;
5028 func->shared()->SetName(*Utils::OpenHandle(*name));
5032 Local<Value> Function::GetName()
const {
5033 auto self = Utils::OpenHandle(
this);
5035 if (self->IsJSBoundFunction()) {
5038 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, name,
5039 i::JSBoundFunction::GetName(isolate, func),
5041 return Utils::ToLocal(name);
5043 if (self->IsJSFunction()) {
5045 return Utils::ToLocal(handle(func->shared()->Name(), isolate));
5047 return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
5052 auto self = Utils::OpenHandle(
this);
5053 if (!self->IsJSFunction()) {
5054 return ToApiHandle<Primitive>(
5055 self->GetIsolate()->factory()->undefined_value());
5059 func->GetIsolate()));
5064 auto self = Utils::OpenHandle(
this);
5065 if (!self->IsJSFunction()) {
5066 return ToApiHandle<Primitive>(
5067 self->GetIsolate()->factory()->undefined_value());
5076 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
5077 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
5078 auto self = Utils::OpenHandle(
this);
5079 if (!self->IsJSFunction()) {
5080 return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
5084 isolate->factory()->NewStringFromStaticChars(
"displayName");
5086 i::JSReceiver::GetDataProperty(func, property_name);
5087 if (value->IsString()) {
5089 if (name->length() > 0)
return Utils::ToLocal(name);
5091 return ToApiHandle<Primitive>(isolate->factory()->undefined_value());
5096 auto self = Utils::OpenHandle(
this);
5097 if (!self->IsJSFunction()) {
5101 if (func->shared()->script()->IsScript()) {
5103 func->GetIsolate());
5104 return GetScriptOriginForScript(func->GetIsolate(), script);
5110 const int Function::kLineOffsetNotFound = -1;
5114 auto self = Utils::OpenHandle(
this);
5115 if (!self->IsJSFunction()) {
5116 return kLineOffsetNotFound;
5119 if (func->shared()->script()->IsScript()) {
5121 func->GetIsolate());
5122 return i::Script::GetLineNumber(script, func->shared()->StartPosition());
5124 return kLineOffsetNotFound;
5129 auto self = Utils::OpenHandle(
this);
5130 if (!self->IsJSFunction()) {
5131 return kLineOffsetNotFound;
5134 if (func->shared()->script()->IsScript()) {
5136 func->GetIsolate());
5137 return i::Script::GetColumnNumber(script, func->shared()->StartPosition());
5139 return kLineOffsetNotFound;
5144 auto self = Utils::OpenHandle(
this);
5145 if (!self->IsJSFunction()) {
5146 return v8::UnboundScript::kNoScriptId;
5149 if (!func->shared()->script()->IsScript()) {
5150 return v8::UnboundScript::kNoScriptId;
5153 func->GetIsolate());
5154 return script->id();
5159 auto self = Utils::OpenHandle(
this);
5160 if (self->IsJSBoundFunction()) {
5162 auto bound_target_function = i::handle(
5163 bound_function->bound_target_function(), bound_function->GetIsolate());
5164 return Utils::CallableToLocal(bound_target_function);
5166 return v8::Undefined(reinterpret_cast<v8::Isolate*>(self->GetIsolate()));
5170 auto self = Utils::OpenHandle(
this);
5171 return static_cast<int>(
self->Hash());
5177 return str->length();
5183 return str->HasOnlyOneByteChars();
5190 static const uint32_t value = 0xFF00FF00;
5193 static const uint64_t value = V8_2PART_UINT64_C(0xFF00FF00, FF00FF00);
5197 static inline bool Unaligned(
const uint16_t* chars) {
5198 return reinterpret_cast<const uintptr_t>(chars) & kAlignmentMask;
5202 static inline const uint16_t* Align(
const uint16_t* chars) {
5203 return reinterpret_cast<uint16_t*
>(
5204 reinterpret_cast<uintptr_t>(chars) & ~kAlignmentMask);
5211 i::ConsString cons_string = i::String::VisitFlat(
this,
string, 0);
5212 if (cons_string.is_null())
return is_one_byte_;
5213 return CheckCons(cons_string);
5215 void VisitOneByteString(
const uint8_t* chars,
int length) {
5218 void VisitTwoByteString(
const uint16_t* chars,
int length) {
5222 const uint16_t* end = chars + length;
5223 while (Unaligned(chars) && chars != end) {
5228 const uint16_t* aligned_end = Align(end);
5229 const int increment =
sizeof(
uintptr_t)/
sizeof(uint16_t);
5230 const int inner_loops = 16;
5231 while (chars + inner_loops*increment < aligned_end) {
5232 for (
int i = 0;
i < inner_loops;
i++) {
5233 acc |= *
reinterpret_cast<const uintptr_t*
>(chars);
5237 if ((acc & kOneByteMask) != 0) {
5238 is_one_byte_ =
false;
5243 while (chars != end) {
5247 if ((acc & kOneByteMask) != 0) is_one_byte_ =
false;
5255 i::ConsString left_as_cons = i::String::VisitFlat(
this, left, 0);
5256 if (!is_one_byte_)
return false;
5258 i::String right = cons_string->second();
5259 i::ConsString right_as_cons = i::String::VisitFlat(
this, right, 0);
5260 if (!is_one_byte_)
return false;
5262 if (!left_as_cons.is_null() && !right_as_cons.is_null()) {
5263 if (left->length() < right->length()) {
5264 CheckCons(left_as_cons);
5265 cons_string = right_as_cons;
5267 CheckCons(right_as_cons);
5268 cons_string = left_as_cons;
5271 if (!is_one_byte_)
return false;
5275 if (!left_as_cons.is_null()) {
5276 cons_string = left_as_cons;
5280 if (!right_as_cons.is_null()) {
5281 cons_string = right_as_cons;
5287 return is_one_byte_;
5296 if (str->HasOnlyOneByteChars())
return true;
5298 return helper.Check(*str);
5303 str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
5304 int length = str->length();
5305 if (length == 0)
return 0;
5307 i::String::FlatContent flat = str->GetFlatContent();
5308 DCHECK(flat.IsFlat());
5309 int utf8_length = 0;
5310 if (flat.IsOneByte()) {
5311 for (uint8_t c : flat.ToOneByteVector()) {
5312 utf8_length += c >> 7;
5314 utf8_length += length;
5316 int last_character = unibrow::Utf16::kNoPreviousCharacter;
5317 for (uint16_t c : flat.ToUC16Vector()) {
5318 utf8_length += unibrow::Utf8::Length(c, last_character);
5330 bool skip_capacity_check,
5331 bool replace_invalid_utf8)
5332 : early_termination_(
false),
5333 last_character_(unibrow::Utf16::kNoPreviousCharacter),
5336 capacity_(capacity),
5337 skip_capacity_check_(capacity == -1 || skip_capacity_check),
5338 replace_invalid_utf8_(replace_invalid_utf8),
5339 utf16_chars_read_(0) {
5342 static int WriteEndCharacter(uint16_t character,
5346 bool replace_invalid_utf8) {
5347 DCHECK_GT(remaining, 0);
5351 if (unibrow::Utf16::IsSurrogatePair(last_character, character)) {
5352 int written = unibrow::Utf8::Encode(buffer, character, last_character,
5353 replace_invalid_utf8);
5354 DCHECK_EQ(written, 1);
5358 char temp_buffer[unibrow::Utf8::kMaxEncodedSize];
5360 int written = unibrow::Utf8::Encode(temp_buffer, character,
5361 unibrow::Utf16::kNoPreviousCharacter,
5362 replace_invalid_utf8);
5364 if (written > remaining)
return 0;
5366 for (
int j = 0; j < written; j++) {
5367 buffer[j] = temp_buffer[j];
5382 template<
typename Char>
5383 void Visit(
const Char* chars,
const int length) {
5384 DCHECK(!early_termination_);
5385 if (length == 0)
return;
5387 char* buffer = buffer_;
5388 int last_character =
sizeof(Char) == 1
5389 ? unibrow::Utf16::kNoPreviousCharacter
5395 if (skip_capacity_check_) {
5396 fast_length = length;
5398 int remaining_capacity = capacity_ -
static_cast<int>(buffer - start_);
5400 STATIC_ASSERT(unibrow::Utf16::kMaxExtraUtf8BytesForOneUtf16CodeUnit ==
5402 int max_size_per_char =
sizeof(Char) == 1 ? 2 : 3;
5403 int writable_length =
5404 (remaining_capacity - max_size_per_char)/max_size_per_char;
5406 if (writable_length <= 0)
break;
5407 fast_length =
i + writable_length;
5408 if (fast_length > length) fast_length = length;
5411 if (
sizeof(Char) == 1) {
5412 for (;
i < fast_length;
i++) {
5413 buffer += unibrow::Utf8::EncodeOneByte(
5414 buffer, static_cast<uint8_t>(*chars++));
5415 DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
5418 for (;
i < fast_length;
i++) {
5419 uint16_t character = *chars++;
5420 buffer += unibrow::Utf8::Encode(buffer, character, last_character,
5421 replace_invalid_utf8_);
5422 last_character = character;
5423 DCHECK(capacity_ == -1 || (buffer - start_) <= capacity_);
5427 if (fast_length == length) {
5429 last_character_ = last_character;
5431 utf16_chars_read_ += length;
5435 DCHECK(!skip_capacity_check_);
5437 int remaining_capacity = capacity_ -
static_cast<int>(buffer - start_);
5438 DCHECK_GE(remaining_capacity, 0);
5439 for (; i < length && remaining_capacity > 0;
i++) {
5440 uint16_t character = *chars++;
5443 if (replace_invalid_utf8_ && unibrow::Utf16::IsLeadSurrogate(character)) {
5444 early_termination_ =
true;
5447 int written = WriteEndCharacter(character,
5451 replace_invalid_utf8_);
5453 early_termination_ =
true;
5457 remaining_capacity -= written;
5458 last_character = character;
5461 last_character_ = last_character;
5463 utf16_chars_read_ +=
i;
5466 inline bool IsDone() {
5467 return early_termination_;
5470 inline void VisitOneByteString(
const uint8_t* chars,
int length) {
5471 Visit(chars, length);
5474 inline void VisitTwoByteString(
const uint16_t* chars,
int length) {
5475 Visit(chars, length);
5478 int CompleteWrite(
bool write_null,
int* utf16_chars_read_out) {
5480 if (utf16_chars_read_out !=
nullptr) {
5481 *utf16_chars_read_out = utf16_chars_read_;
5485 !early_termination_ &&
5486 (capacity_ == -1 || (buffer_ - start_) < capacity_)) {
5489 return static_cast<int>(buffer_ - start_);
5493 bool early_termination_;
5494 int last_character_;
5498 bool const skip_capacity_check_;
5499 bool const replace_invalid_utf8_;
5500 int utf16_chars_read_;
5505 static bool RecursivelySerializeToUtf8(
i::String current,
5507 int recursion_budget) {
5508 while (!writer->IsDone()) {
5509 i::ConsString cons_string = i::String::VisitFlat(writer, current);
5510 if (cons_string.is_null())
return true;
5511 if (recursion_budget <= 0)
return false;
5514 bool success = RecursivelySerializeToUtf8(first,
5516 recursion_budget - 1);
5517 if (!success)
return false;
5519 current = cons_string->second();
5524 int String::WriteUtf8(Isolate* v8_isolate,
char* buffer,
int capacity,
5525 int* nchars_ref,
int options)
const {
5528 LOG_API(isolate, String, WriteUtf8);
5529 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
5530 str = i::String::Flatten(isolate, str);
5531 const int string_length = str->length();
5532 bool write_null = !(options & NO_NULL_TERMINATION);
5533 bool replace_invalid_utf8 = (options & REPLACE_INVALID_UTF8);
5534 int max16BitCodeUnitSize = unibrow::Utf8::kMax16BitCodeUnitSize;
5536 if (capacity == -1 || capacity / max16BitCodeUnitSize >= string_length) {
5537 Utf8WriterVisitor writer(buffer, capacity,
true, replace_invalid_utf8);
5538 const int kMaxRecursion = 100;
5539 bool success = RecursivelySerializeToUtf8(*str, &writer, kMaxRecursion);
5540 if (success)
return writer.CompleteWrite(write_null, nchars_ref);
5541 }
else if (capacity >= string_length) {
5543 int utf8_bytes = Utf8Length(v8_isolate);
5544 if (utf8_bytes <= capacity) {
5546 if (utf8_bytes == string_length) {
5547 WriteOneByte(v8_isolate, reinterpret_cast<uint8_t*>(buffer), 0,
5549 if (nchars_ref !=
nullptr) *nchars_ref = string_length;
5550 if (write_null && (utf8_bytes+1 <= capacity)) {
5551 return string_length + 1;
5553 return string_length;
5555 if (write_null && (utf8_bytes+1 > capacity)) {
5556 options |= NO_NULL_TERMINATION;
5561 return WriteUtf8(v8_isolate, buffer, -1, nchars_ref, options);
5564 Utf8WriterVisitor writer(buffer, capacity,
false, replace_invalid_utf8);
5565 i::String::VisitFlat(&writer, *str);
5566 return writer.CompleteWrite(write_null, nchars_ref);
5569 template <
typename CharType>
5570 static inline int WriteHelper(
i::Isolate* isolate,
const String*
string,
5571 CharType* buffer,
int start,
int length,
5573 LOG_API(isolate, String, Write);
5574 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
5575 DCHECK(start >= 0 && length >= -1);
5577 str = i::String::Flatten(isolate, str);
5578 int end = start + length;
5579 if ((length == -1) || (length > str->length() - start) )
5580 end = str->length();
5581 if (end < 0)
return 0;
5582 i::String::WriteToFlat(*str, buffer, start, end);
5583 if (!(options & String::NO_NULL_TERMINATION) &&
5584 (length == -1 || end - start < length)) {
5585 buffer[end - start] =
'\0';
5591 int String::WriteOneByte(Isolate* isolate, uint8_t* buffer,
int start,
5592 int length,
int options)
const {
5593 return WriteHelper(reinterpret_cast<i::Isolate*>(isolate),
this, buffer,
5594 start, length, options);
5598 int String::Write(Isolate* isolate, uint16_t* buffer,
int start,
int length,
5599 int options)
const {
5600 return WriteHelper(reinterpret_cast<i::Isolate*>(isolate),
this, buffer,
5601 start, length, options);
5617 void v8::String::VerifyExternalStringResource(
5620 i::String str = *Utils::OpenHandle(
this);
5623 if (str->IsThinString()) {
5624 str = i::ThinString::cast(str)->actual();
5628 const void* resource = i::ExternalTwoByteString::cast(str)->resource();
5629 expected =
reinterpret_cast<const ExternalStringResource*
>(resource);
5633 CHECK_EQ(expected, value);
5636 void v8::String::VerifyExternalStringResourceBase(
5639 i::String str = *Utils::OpenHandle(
this);
5641 Encoding expectedEncoding;
5643 if (str->IsThinString()) {
5644 str = i::ThinString::cast(str)->actual();
5648 const void* resource = i::ExternalOneByteString::cast(str)->resource();
5649 expected =
reinterpret_cast<const ExternalStringResourceBase*
>(resource);
5650 expectedEncoding = ONE_BYTE_ENCODING;
5652 const void* resource = i::ExternalTwoByteString::cast(str)->resource();
5653 expected =
reinterpret_cast<const ExternalStringResourceBase*
>(resource);
5654 expectedEncoding = TWO_BYTE_ENCODING;
5658 str->IsOneByteRepresentation() ? ONE_BYTE_ENCODING : TWO_BYTE_ENCODING;
5660 CHECK_EQ(expected, value);
5661 CHECK_EQ(expectedEncoding, encoding);
5664 String::ExternalStringResource* String::GetExternalStringResourceSlow()
const {
5666 typedef internal::Internals I;
5667 i::String str = *Utils::OpenHandle(
this);
5669 if (str->IsThinString()) {
5670 str = i::ThinString::cast(str)->actual();
5674 void* value = I::ReadField<void*>(str.ptr(), I::kStringResourceOffset);
5675 return reinterpret_cast<String::ExternalStringResource*
>(value);
5680 String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
5681 String::Encoding* encoding_out)
const {
5683 typedef internal::Internals I;
5684 ExternalStringResourceBase* resource =
nullptr;
5685 i::String str = *Utils::OpenHandle(
this);
5687 if (str->IsThinString()) {
5688 str = i::ThinString::cast(str)->actual();
5691 internal::Address
string = str.ptr();
5692 int type = I::GetInstanceType(
string) & I::kFullStringRepresentationMask;
5693 *encoding_out =
static_cast<Encoding
>(type & I::kStringEncodingMask);
5696 void* value = I::ReadField<void*>(string, I::kStringResourceOffset);
5697 resource =
static_cast<ExternalStringResourceBase*
>(value);
5705 i::String str = *Utils::OpenHandle(
this);
5707 return i::ExternalOneByteString::cast(str)->resource();
5708 }
else if (str->IsThinString()) {
5709 str = i::ThinString::cast(str)->actual();
5711 return i::ExternalOneByteString::cast(str)->resource();
5722 if (!i::Isolate::FromWritableHeapObject(*sym, &isolate)) {
5728 sym->GetFieldAddress(i::Symbol::kNameOffset)));
5729 return Utils::ToLocal(ro_name);
5734 return Utils::ToLocal(name);
5739 return reinterpret_cast<const Symbol*
>(
this)->
Name();
5743 double Number::Value()
const {
5745 return obj->Number();
5749 bool Boolean::Value()
const {
5751 return obj->IsTrue();
5755 int64_t Integer::Value()
const {
5758 return i::Smi::ToInt(*obj);
5760 return static_cast<int64_t>(obj->Number());
5765 int32_t Int32::Value()
const {
5768 return i::Smi::ToInt(*obj);
5770 return static_cast<int32_t
>(obj->Number());
5778 return i::Smi::ToInt(*obj);
5780 return static_cast<uint32_t>(obj->Number());
5786 if (!self->IsJSObject())
return 0;
5791 const char* location) {
5792 return Utils::ApiCheck(
5793 obj->IsJSObject() &&
5794 (index < i::Handle<i::JSObject>::cast(obj)->GetEmbedderFieldCount()),
5795 location,
"Internal field out of bounds");
5798 Local<Value> v8::Object::SlowGetInternalField(
int index) {
5800 const char* location =
"v8::Object::GetInternalField()";
5801 if (!InternalFieldOK(obj, index, location))
return Local<Value>();
5804 return Utils::ToLocal(value);
5809 const char* location =
"v8::Object::SetInternalField()";
5810 if (!InternalFieldOK(obj, index, location))
return;
5815 void* v8::Object::SlowGetAlignedPointerFromInternalField(
int index) {
5817 const char* location =
"v8::Object::GetAlignedPointerFromInternalField()";
5818 if (!InternalFieldOK(obj, index, location))
return nullptr;
5821 .ToAlignedPointer(&result),
5822 location,
"Unaligned pointer");
5828 const char* location =
"v8::Object::SetAlignedPointerInInternalField()";
5829 if (!InternalFieldOK(obj, index, location))
return;
5831 .store_aligned_pointer(value),
5832 location,
"Unaligned pointer");
5833 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
5836 void v8::Object::SetAlignedPointerInInternalFields(
int argc,
int indices[],
5839 const char* location =
"v8::Object::SetAlignedPointerInInternalFields()";
5842 int nof_embedder_fields = js_obj->GetEmbedderFieldCount();
5843 for (
int i = 0;
i < argc;
i++) {
5844 int index = indices[
i];
5845 if (!Utils::ApiCheck(index < nof_embedder_fields, location,
5846 "Internal field out of bounds")) {
5849 void* value = values[
i];
5852 location,
"Unaligned pointer");
5853 DCHECK_EQ(value, GetAlignedPointerFromInternalField(index));
5857 static void* ExternalValue(
i::Object* obj) {
5859 if (obj->IsUndefined()) {
5862 i::Object* foreign = i::JSObject::cast(obj)->GetEmbedderField(0);
5863 return reinterpret_cast<void*
>(i::Foreign::cast(foreign)->foreign_address());
5870 void v8::V8::InitializePlatform(Platform* platform) {
5871 i::V8::InitializePlatform(platform);
5875 void v8::V8::ShutdownPlatform() {
5876 i::V8::ShutdownPlatform();
5880 bool v8::V8::Initialize() {
5881 i::V8::Initialize();
5882 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 5888 #if V8_OS_LINUX || V8_OS_MACOSX 5891 #if V8_TARGET_ARCH_X64 && !V8_OS_ANDROID 5892 return i::trap_handler::TryHandleSignal(sig_code, info, context);
5898 bool V8::TryHandleSignal(
int signum,
void* info,
void* context) {
5900 signum, reinterpret_cast<siginfo_t*>(info), context);
5906 #if V8_TARGET_ARCH_X64 5907 return i::trap_handler::TryHandleWasmTrap(exception);
5913 bool V8::RegisterDefaultSignalHandler() {
5914 return v8::internal::trap_handler::RegisterDefaultTrapHandler();
5917 bool V8::EnableWebAssemblyTrapHandler(
bool use_v8_signal_handler) {
5918 return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler);
5921 void v8::V8::SetEntropySource(EntropySource entropy_source) {
5922 base::RandomNumberGenerator::SetEntropySource(entropy_source);
5926 void v8::V8::SetReturnAddressLocationResolver(
5927 ReturnAddressLocationResolver return_address_resolver) {
5928 i::StackFrame::SetReturnAddressLocationResolver(return_address_resolver);
5932 bool v8::V8::Dispose() {
5934 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 5935 i::DisposeNatives();
5940 HeapStatistics::HeapStatistics()
5941 : total_heap_size_(0),
5942 total_heap_size_executable_(0),
5943 total_physical_size_(0),
5944 total_available_size_(0),
5946 heap_size_limit_(0),
5947 malloced_memory_(0),
5948 external_memory_(0),
5949 peak_malloced_memory_(0),
5950 does_zap_garbage_(false),
5951 number_of_native_contexts_(0),
5952 number_of_detached_contexts_(0) {}
5954 HeapSpaceStatistics::HeapSpaceStatistics()
5955 : space_name_(nullptr),
5957 space_used_size_(0),
5958 space_available_size_(0),
5959 physical_space_size_(0) {}
5961 HeapObjectStatistics::HeapObjectStatistics()
5962 : object_type_(nullptr),
5963 object_sub_type_(nullptr),
5967 HeapCodeStatistics::HeapCodeStatistics()
5968 : code_and_metadata_size_(0),
5969 bytecode_and_metadata_size_(0),
5970 external_script_source_size_(0) {}
5972 bool v8::V8::InitializeICU(
const char* icu_data_file) {
5973 return i::InitializeICU(icu_data_file);
5976 bool v8::V8::InitializeICUDefaultLocation(
const char* exec_path,
5977 const char* icu_data_file) {
5978 return i::InitializeICUDefaultLocation(exec_path, icu_data_file);
5981 void v8::V8::InitializeExternalStartupData(
const char* directory_path) {
5982 i::InitializeExternalStartupData(directory_path);
5986 void v8::V8::InitializeExternalStartupData(
const char* natives_blob,
5987 const char* snapshot_blob) {
5988 i::InitializeExternalStartupData(natives_blob, snapshot_blob);
5992 const char* v8::V8::GetVersion() {
5993 return i::Version::GetVersion();
5996 template <
typename ObjectType>
6004 v8::ExtensionConfiguration* extensions,
size_t context_snapshot_index,
6005 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6006 return isolate->bootstrapper()->CreateEnvironment(
6007 maybe_global_proxy, global_proxy_template, extensions,
6008 context_snapshot_index, embedder_fields_deserializer);
6017 v8::ExtensionConfiguration* extensions,
size_t context_snapshot_index,
6018 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6020 USE(context_snapshot_index);
6021 return isolate->bootstrapper()->NewRemoteContext(maybe_global_proxy,
6022 global_proxy_template);
6026 template <
typename ObjectType>
6028 i::Isolate* isolate, v8::ExtensionConfiguration* extensions,
6031 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6035 ENTER_V8_FOR_NEW_CONTEXT(isolate);
6040 isolate->factory()->undefined_value());
6042 isolate->factory()->undefined_value());
6044 if (!maybe_global_template.IsEmpty()) {
6048 global_constructor = EnsureConstructor(isolate, *global_template);
6052 reinterpret_cast<v8::Isolate*>(isolate));
6053 proxy_constructor = EnsureConstructor(isolate, *proxy_template);
6057 i::FunctionTemplateInfo::SetPrototypeTemplate(
6058 isolate, proxy_constructor, Utils::OpenHandle(*global_template));
6066 if (!global_constructor->GetAccessCheckInfo()->IsUndefined(isolate)) {
6067 i::FunctionTemplateInfo::SetAccessCheckInfo(
6068 isolate, proxy_constructor,
6069 i::handle(global_constructor->GetAccessCheckInfo(), isolate));
6070 proxy_constructor->set_needs_access_check(
6071 global_constructor->needs_access_check());
6072 global_constructor->set_needs_access_check(
false);
6073 i::FunctionTemplateInfo::SetAccessCheckInfo(
6074 isolate, global_constructor,
6082 if (!global_constructor->GetNamedPropertyHandler()->IsUndefined(
6085 handle(global_constructor->GetNamedPropertyHandler(), isolate);
6086 i::FunctionTemplateInfo::SetNamedPropertyHandler(
6087 isolate, global_constructor,
6090 if (!global_constructor->GetIndexedPropertyHandler()->IsUndefined(
6092 indexed_interceptor =
6093 handle(global_constructor->GetIndexedPropertyHandler(), isolate);
6094 i::FunctionTemplateInfo::SetIndexedPropertyHandler(
6095 isolate, global_constructor,
6101 if (!maybe_global_proxy.IsEmpty()) {
6106 InvokeBootstrapper<ObjectType> invoke;
6108 invoke.Invoke(isolate, maybe_proxy, proxy_template, extensions,
6109 context_snapshot_index, embedder_fields_deserializer);
6112 if (!maybe_global_template.IsEmpty()) {
6113 DCHECK(!global_constructor.is_null());
6114 DCHECK(!proxy_constructor.is_null());
6115 i::FunctionTemplateInfo::SetAccessCheckInfo(
6116 isolate, global_constructor,
6117 i::handle(proxy_constructor->GetAccessCheckInfo(), isolate));
6118 global_constructor->set_needs_access_check(
6119 proxy_constructor->needs_access_check());
6120 i::FunctionTemplateInfo::SetNamedPropertyHandler(
6121 isolate, global_constructor, named_interceptor);
6122 i::FunctionTemplateInfo::SetIndexedPropertyHandler(
6123 isolate, global_constructor, indexed_interceptor);
6131 Local<Context> NewContext(
6132 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
6135 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer) {
6140 CHECK(isolate->builtins()->builtin(i::Builtins::kIllegal)->IsCode());
6142 TRACE_EVENT_CALL_STATS_SCOPED(isolate,
"v8",
"V8.NewContext");
6143 LOG_API(isolate, Context, New);
6145 ExtensionConfiguration no_extensions;
6146 if (extensions ==
nullptr) extensions = &no_extensions;
6148 isolate, extensions, global_template, global_object,
6149 context_snapshot_index, embedder_fields_deserializer);
6150 if (env.is_null()) {
6151 if (isolate->has_pending_exception()) isolate->clear_pending_exception();
6152 return Local<Context>();
6154 return Utils::ToLocal(scope.CloseAndEscape(env));
6157 Local<Context> v8::Context::New(
6158 v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions,
6161 DeserializeInternalFieldsCallback internal_fields_deserializer) {
6162 return NewContext(external_isolate, extensions, global_template,
6163 global_object, 0, internal_fields_deserializer);
6166 MaybeLocal<Context> v8::Context::FromSnapshot(
6167 v8::Isolate* external_isolate,
size_t context_snapshot_index,
6168 v8::DeserializeInternalFieldsCallback embedder_fields_deserializer,
6169 v8::ExtensionConfiguration* extensions, MaybeLocal<Value> global_object) {
6170 size_t index_including_default_context = context_snapshot_index + 1;
6171 if (!i::Snapshot::HasContextSnapshot(
6172 reinterpret_cast<i::Isolate*>(external_isolate),
6173 index_including_default_context)) {
6174 return MaybeLocal<Context>();
6176 return NewContext(external_isolate, extensions, MaybeLocal<ObjectTemplate>(),
6177 global_object, index_including_default_context,
6178 embedder_fields_deserializer);
6181 MaybeLocal<Object> v8::Context::NewRemoteContext(
6185 LOG_API(isolate, Context, NewRemoteContext);
6188 EnsureConstructor(isolate, *global_template);
6189 Utils::ApiCheck(global_constructor->needs_access_check(),
6190 "v8::Context::NewRemoteContext",
6191 "Global template needs to have access checks enabled.");
6193 i::AccessCheckInfo::cast(global_constructor->GetAccessCheckInfo()),
6195 Utils::ApiCheck(access_check_info->named_interceptor() !=
nullptr,
6196 "v8::Context::NewRemoteContext",
6197 "Global template needs to have access check handlers.");
6199 CreateEnvironment<i::JSGlobalProxy>(isolate,
nullptr, global_template,
6201 DeserializeInternalFieldsCallback());
6202 if (global_proxy.is_null()) {
6203 if (isolate->has_pending_exception()) isolate->clear_pending_exception();
6204 return MaybeLocal<Object>();
6206 return Utils::ToLocal(
6210 void v8::Context::SetSecurityToken(Local<Value> token) {
6213 env->set_security_token(*token_handle);
6217 void v8::Context::UseDefaultSecurityToken() {
6219 env->set_security_token(env->global_object());
6223 Local<Value> v8::Context::GetSecurityToken() {
6226 i::Object* security_token = env->security_token();
6228 return Utils::ToLocal(token_handle);
6232 v8::Isolate* Context::GetIsolate() {
6234 return reinterpret_cast<Isolate*
>(env->GetIsolate());
6244 global)->IsDetachedFrom(context->global_object())) {
6251 void Context::DetachGlobal() {
6254 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
6255 isolate->bootstrapper()->DetachGlobal(context);
6259 Local<v8::Object> Context::GetExtrasBindingObject() {
6263 return Utils::ToLocal(binding);
6267 void Context::AllowCodeGenerationFromStrings(
bool allow) {
6270 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
6271 context->set_allow_code_gen_from_strings(
6277 bool Context::IsCodeGenerationFromStringsAllowed() {
6279 return !context->allow_code_gen_from_strings()->IsFalse(
6280 context->GetIsolate());
6284 void Context::SetErrorMessageForCodeGenerationFromStrings(Local<String> error) {
6287 context->set_error_message_for_code_gen_from_strings(*error_handle);
6293 if (index < static_cast<size_t>(list->length())) {
6294 int int_index =
static_cast<int>(index);
6295 i::Object*
object = list->get(int_index);
6296 if (!object->IsTheHole(isolate)) {
6297 list->set_the_hole(isolate, int_index);
6301 int last = list->length() - 1;
6302 while (last >= 0 && list->is_the_hole(isolate, last)) last--;
6303 if (last != -1) list->Shrink(isolate, last + 1);
6311 i::Address* Context::GetDataFromSnapshotOnce(
size_t index) {
6312 auto context = Utils::OpenHandle(
this);
6313 i::Isolate* i_isolate = context->GetIsolate();
6315 return GetSerializedDataFromFixedArray(i_isolate, list, index);
6318 MaybeLocal<v8::Object> ObjectTemplate::NewInstance(Local<Context> context) {
6319 PREPARE_FOR_EXECUTION(context, ObjectTemplate, NewInstance, Object);
6320 auto self = Utils::OpenHandle(
this);
6321 Local<Object> result;
6322 has_pending_exception = !ToLocal<Object>(
6323 i::ApiNatives::InstantiateObject(isolate,
self), &result);
6324 RETURN_ON_FAILED_EXECUTION(Object);
6325 RETURN_ESCAPED(result);
6329 Local<v8::Object> ObjectTemplate::NewInstance() {
6330 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
6331 RETURN_TO_LOCAL_UNCHECKED(NewInstance(context), Object);
6334 void v8::ObjectTemplate::CheckCast(Data* that) {
6336 Utils::ApiCheck(obj->IsObjectTemplateInfo(),
"v8::ObjectTemplate::Cast",
6337 "Could not convert to object template");
6340 void v8::FunctionTemplate::CheckCast(Data* that) {
6342 Utils::ApiCheck(obj->IsFunctionTemplateInfo(),
"v8::FunctionTemplate::Cast",
6343 "Could not convert to function template");
6346 void v8::Signature::CheckCast(Data* that) {
6348 Utils::ApiCheck(obj->IsFunctionTemplateInfo(),
"v8::Signature::Cast",
6349 "Could not convert to signature");
6352 void v8::AccessorSignature::CheckCast(Data* that) {
6354 Utils::ApiCheck(obj->IsFunctionTemplateInfo(),
"v8::AccessorSignature::Cast",
6355 "Could not convert to accessor signature");
6358 MaybeLocal<v8::Function> FunctionTemplate::GetFunction(Local<Context> context) {
6359 PREPARE_FOR_EXECUTION(context, FunctionTemplate, GetFunction, Function);
6360 auto self = Utils::OpenHandle(
this);
6361 Local<Function> result;
6362 has_pending_exception =
6363 !ToLocal<Function>(i::ApiNatives::InstantiateFunction(
self), &result);
6364 RETURN_ON_FAILED_EXECUTION(Function);
6365 RETURN_ESCAPED(result);
6369 Local<v8::Function> FunctionTemplate::GetFunction() {
6370 auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(
this));
6371 RETURN_TO_LOCAL_UNCHECKED(GetFunction(context), Function);
6375 auto self = Utils::OpenHandle(
this);
6381 Utils::ApiCheck(constructor->needs_access_check(),
6382 "v8::FunctionTemplate::NewRemoteInstance",
6383 "InstanceTemplate needs to have access checks enabled.");
6385 i::AccessCheckInfo::cast(constructor->GetAccessCheckInfo()), isolate);
6386 Utils::ApiCheck(access_check_info->named_interceptor() !=
nullptr,
6387 "v8::FunctionTemplate::NewRemoteInstance",
6388 "InstanceTemplate needs to have access check handlers.");
6390 if (!i::ApiNatives::InstantiateRemoteObject(
6392 .ToHandle(&
object)) {
6393 if (isolate->has_pending_exception()) {
6394 isolate->OptionalRescheduleException(
true);
6398 return Utils::ToLocal(scope.CloseAndEscape(
object));
6402 auto self = Utils::OpenHandle(
this);
6403 auto obj = Utils::OpenHandle(*value);
6404 if (obj->IsJSObject() &&
self->IsTemplateFor(i::JSObject::cast(*obj))) {
6407 if (obj->IsJSGlobalProxy()) {
6411 i::JSObject::cast(*obj)->map());
6414 DCHECK(!iter.IsAtEnd());
6415 return self->IsTemplateFor(iter.GetCurrent<
i::JSObject>());
6422 STATIC_ASSERT(
sizeof(value) ==
sizeof(i::Address));
6425 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6427 return Utils::ExternalToLocal(external);
6431 void* External::Value()
const {
6432 return ExternalValue(*Utils::OpenHandle(
this));
6439 inline int StringLength(
const char*
string) {
6440 return i::StrLength(
string);
6444 inline int StringLength(
const uint8_t*
string) {
6445 return i::StrLength(reinterpret_cast<const char*>(
string));
6449 inline int StringLength(
const uint16_t*
string) {
6451 while (
string[length] !=
'\0')
6456 V8_WARN_UNUSED_RESULT
6461 return factory->InternalizeUtf8String(
string);
6463 return factory->NewStringFromUtf8(
string);
6466 V8_WARN_UNUSED_RESULT
6471 return factory->InternalizeOneByteString(
string);
6473 return factory->NewStringFromOneByte(
string);
6476 V8_WARN_UNUSED_RESULT
6481 return factory->InternalizeTwoByteString(
string);
6483 return factory->NewStringFromTwoByte(
string);
6487 STATIC_ASSERT(v8::String::kMaxLength == i::String::kMaxLength);
6492 #define NEW_STRING(isolate, class_name, function_name, Char, data, type, \ 6494 MaybeLocal<String> result; \ 6495 if (length == 0) { \ 6496 result = String::Empty(isolate); \ 6497 } else if (length > i::String::kMaxLength) { \ 6498 result = MaybeLocal<String>(); \ 6500 i::Isolate* i_isolate = reinterpret_cast<internal::Isolate*>(isolate); \ 6501 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); \ 6502 LOG_API(i_isolate, class_name, function_name); \ 6503 if (length < 0) length = StringLength(data); \ 6504 i::Handle<i::String> handle_result = \ 6505 NewString(i_isolate->factory(), type, \ 6506 i::Vector<const Char>(data, length)) \ 6507 .ToHandleChecked(); \ 6508 result = Utils::ToLocal(handle_result); \ 6516 static_cast<v8::NewStringType>(
type), length);
6517 RETURN_TO_LOCAL_UNCHECKED(result,
String);
6536 const uint16_t* data,
6540 static_cast<v8::NewStringType>(
type), length);
6541 RETURN_TO_LOCAL_UNCHECKED(result,
String);
6546 const uint16_t* data,
6556 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
6557 LOG_API(isolate,
String, Concat);
6561 if (left_string->length() + right_string->length() > i::String::kMaxLength) {
6565 left_string, right_string).ToHandleChecked();
6566 return Utils::ToLocal(result);
6571 CHECK(resource && resource->
data());
6573 if (resource->
length() >
static_cast<size_t>(i::String::kMaxLength)) {
6577 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6578 LOG_API(i_isolate,
String, NewExternalTwoByte);
6579 if (resource->
length() > 0) {
6581 ->NewExternalStringFromTwoByte(resource)
6583 return Utils::ToLocal(
string);
6587 return Utils::ToLocal(i_isolate->factory()->empty_string());
6594 CHECK(resource && resource->
data());
6596 if (resource->
length() >
static_cast<size_t>(i::String::kMaxLength)) {
6600 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6601 LOG_API(i_isolate, String, NewExternalOneByte);
6602 if (resource->
length() > 0) {
6604 ->NewExternalStringFromOneByte(resource)
6606 return Utils::ToLocal(
string);
6610 return Utils::ToLocal(i_isolate->factory()->empty_string());
6615 Local<String> v8::String::NewExternal(
6617 RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String);
6624 i::String obj = *Utils::OpenHandle(
this);
6626 if (obj->IsThinString()) {
6627 obj = i::ThinString::cast(obj)->actual();
6630 if (!obj->SupportsExternalization()) {
6637 i::Isolate::FromWritableHeapObject(obj, &isolate);
6638 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
6640 CHECK(resource && resource->
data());
6642 bool result = obj->MakeExternal(resource);
6644 DCHECK(obj->IsExternalString());
6653 i::String obj = *Utils::OpenHandle(
this);
6655 if (obj->IsThinString()) {
6656 obj = i::ThinString::cast(obj)->actual();
6659 if (!obj->SupportsExternalization()) {
6666 i::Isolate::FromWritableHeapObject(obj, &isolate);
6667 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
6669 CHECK(resource && resource->
data());
6671 bool result = obj->MakeExternal(resource);
6673 DCHECK(obj->IsExternalString());
6680 i::String obj = *Utils::OpenHandle(
this);
6682 if (obj->IsThinString()) {
6683 obj = i::ThinString::cast(obj)->actual();
6686 if (!obj->SupportsExternalization()) {
6691 return !i::Heap::InNewSpace(obj);
6695 auto self = Utils::OpenHandle(
this);
6696 auto other = Utils::OpenHandle(*that);
6697 return self->Equals(*other);
6701 i::Isolate* i_isolate = Utils::OpenHandle(
this)->GetIsolate();
6702 return reinterpret_cast<Isolate*
>(i_isolate);
6708 LOG_API(i_isolate,
Object, New);
6709 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6711 i_isolate->factory()->NewJSObject(i_isolate->object_function());
6712 return Utils::ToLocal(obj);
6721 if (!Utils::ApiCheck(proto->IsNull() || proto->IsJSReceiver(),
6722 "v8::Object::New",
"prototype must be null or object")) {
6725 LOG_API(i_isolate,
Object, New);
6726 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6733 i::NameDictionary::New(i_isolate, static_cast<int>(length));
6735 i_isolate->factory()->empty_fixed_array();
6736 for (
size_t i = 0;
i < length; ++
i) {
6744 if (name->AsArrayIndex(&index)) {
6747 if (!elements->IsNumberDictionary()) {
6750 i::NumberDictionary::New(i_isolate, static_cast<int>(length))
6755 i::NumberDictionary::Set(
6761 name = i_isolate->factory()->InternalizeName(name);
6762 int const entry = properties->FindEntry(i_isolate, name);
6763 if (entry == i::NameDictionary::kNotFound) {
6765 properties = i::NameDictionary::Add(i_isolate, properties, name, value,
6766 i::PropertyDetails::Empty());
6769 properties->ValueAtPut(entry, *value);
6774 i_isolate->factory()->NewSlowJSObjectWithPropertiesAndElements(
6775 proto, properties, elements);
6776 return Utils::ToLocal(obj);
6782 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6785 i::Object::ToObject(i_isolate, number).ToHandleChecked();
6786 return Utils::ToLocal(obj);
6790 double v8::NumberObject::ValueOf()
const {
6794 LOG_API(isolate, NumberObject, NumberValue);
6795 return jsvalue->value()->Number();
6798 Local<v8::Value> v8::BigIntObject::New(Isolate* isolate,
int64_t value) {
6800 LOG_API(i_isolate, BigIntObject, New);
6801 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6804 i::Object::ToObject(i_isolate, bigint).ToHandleChecked();
6805 return Utils::ToLocal(obj);
6808 Local<v8::BigInt> v8::BigIntObject::ValueOf()
const {
6812 LOG_API(isolate, BigIntObject, BigIntValue);
6813 return Utils::ToLocal(
6817 Local<v8::Value> v8::BooleanObject::New(Isolate* isolate,
bool value) {
6819 LOG_API(i_isolate, BooleanObject, New);
6820 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6826 i::Object::ToObject(i_isolate,
boolean).ToHandleChecked();
6827 return Utils::ToLocal(obj);
6831 bool v8::BooleanObject::ValueOf()
const {
6835 LOG_API(isolate, BooleanObject, BooleanValue);
6836 return jsvalue->value()->IsTrue(isolate);
6840 Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
6841 Local<String> value) {
6844 LOG_API(isolate, StringObject, New);
6845 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
6847 i::Object::ToObject(isolate,
string).ToHandleChecked();
6848 return Utils::ToLocal(obj);
6852 Local<v8::String> v8::StringObject::ValueOf()
const {
6856 LOG_API(isolate, StringObject, StringValue);
6857 return Utils::ToLocal(
6862 Local<v8::Value> v8::SymbolObject::New(Isolate* isolate, Local<Symbol> value) {
6864 LOG_API(i_isolate, SymbolObject, New);
6865 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6867 i_isolate, Utils::OpenHandle(*value)).ToHandleChecked();
6868 return Utils::ToLocal(obj);
6872 Local<v8::Symbol> v8::SymbolObject::ValueOf()
const {
6876 LOG_API(isolate, SymbolObject, SymbolValue);
6877 return Utils::ToLocal(
6882 MaybeLocal<v8::Value> v8::Date::New(Local<Context> context,
double time) {
6883 if (std::isnan(time)) {
6885 time = std::numeric_limits<double>::quiet_NaN();
6887 PREPARE_FOR_EXECUTION(context, Date, New,
Value);
6888 Local<Value> result;
6889 has_pending_exception = !ToLocal<Value>(
6890 i::JSDate::New(isolate->date_function(), isolate->date_function(), time),
6892 RETURN_ON_FAILED_EXECUTION(
Value);
6893 RETURN_ESCAPED(result);
6897 Local<v8::Value> v8::Date::New(Isolate* isolate,
double time) {
6898 auto context = isolate->GetCurrentContext();
6899 RETURN_TO_LOCAL_UNCHECKED(New(context, time),
Value);
6907 LOG_API(isolate,
Date, NumberValue);
6908 return jsdate->value()->Number();
6914 LOG_API(i_isolate,
Date, DateTimeConfigurationChangeNotification);
6915 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6916 i_isolate->date_cache()->ResetDateCache();
6917 #ifdef V8_INTL_SUPPORT 6918 i_isolate->clear_cached_icu_object(
6919 i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormat);
6920 i_isolate->clear_cached_icu_object(
6921 i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForTime);
6922 i_isolate->clear_cached_icu_object(
6923 i::Isolate::ICUObjectCacheType::kDefaultSimpleDateFormatForDate);
6924 #endif // V8_INTL_SUPPORT 6932 has_pending_exception =
6933 !ToLocal<RegExp>(i::JSRegExp::New(isolate, Utils::OpenHandle(*pattern),
6934 static_cast<i::JSRegExp::Flags>(flags)),
6936 RETURN_ON_FAILED_EXECUTION(
RegExp);
6937 RETURN_ESCAPED(result);
6943 return Utils::ToLocal(
6949 #define REGEXP_FLAG_ASSERT_EQ(flag) \ 6950 STATIC_ASSERT(static_cast<int>(v8::RegExp::flag) == \ 6951 static_cast<int>(i::JSRegExp::flag)) 6952 REGEXP_FLAG_ASSERT_EQ(kNone);
6953 REGEXP_FLAG_ASSERT_EQ(kGlobal);
6954 REGEXP_FLAG_ASSERT_EQ(kIgnoreCase);
6955 REGEXP_FLAG_ASSERT_EQ(kMultiline);
6956 REGEXP_FLAG_ASSERT_EQ(kSticky);
6957 REGEXP_FLAG_ASSERT_EQ(kUnicode);
6958 #undef REGEXP_FLAG_ASSERT_EQ 6968 LOG_API(i_isolate,
Array, New);
6969 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6970 int real_length = length > 0 ? length : 0;
6973 i_isolate->factory()->NewNumberFromInt(real_length);
6974 obj->set_length(*length_obj);
6975 return Utils::ToLocal(obj);
6982 LOG_API(i_isolate,
Array, New);
6983 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
6984 int len =
static_cast<int>(length);
6987 for (
int i = 0;
i < len;
i++) {
6989 result->set(
i, *element);
6992 return Utils::ToLocal(
6993 factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS, len));
6996 uint32_t v8::Array::Length()
const {
6999 if (length->IsSmi()) {
7000 return i::Smi::ToInt(length);
7002 return static_cast<uint32_t>(length->Number());
7009 LOG_API(i_isolate,
Map, New);
7010 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7012 return Utils::ToLocal(obj);
7016 size_t v8::Map::Size()
const {
7018 return i::OrderedHashMap::cast(obj->table())->NumberOfElements();
7023 auto self = Utils::OpenHandle(
this);
7025 LOG_API(isolate, Map, Clear);
7026 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7027 i::JSMap::Clear(isolate,
self);
7031 MaybeLocal<Value> Map::Get(Local<Context> context, Local<Value> key) {
7032 PREPARE_FOR_EXECUTION(context, Map, Get,
Value);
7033 auto self = Utils::OpenHandle(
this);
7034 Local<Value> result;
7036 has_pending_exception =
7037 !ToLocal<Value>(i::Execution::Call(isolate, isolate->map_get(),
self,
7038 arraysize(argv), argv),
7040 RETURN_ON_FAILED_EXECUTION(
Value);
7041 RETURN_ESCAPED(result);
7045 MaybeLocal<Map> Map::Set(Local<Context> context, Local<Value> key,
7046 Local<Value> value) {
7047 PREPARE_FOR_EXECUTION(context, Map, Set, Map);
7048 auto self = Utils::OpenHandle(
this);
7051 Utils::OpenHandle(*value)};
7052 has_pending_exception = !i::Execution::Call(isolate, isolate->map_set(),
self,
7053 arraysize(argv), argv)
7055 RETURN_ON_FAILED_EXECUTION(Map);
7060 Maybe<bool> Map::Has(Local<Context> context, Local<Value> key) {
7061 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
7062 ENTER_V8(isolate, context, Map, Has, Nothing<bool>(),
i::HandleScope);
7063 auto self = Utils::OpenHandle(
this);
7066 has_pending_exception = !i::Execution::Call(isolate, isolate->map_has(),
self,
7067 arraysize(argv), argv)
7069 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
7070 return Just(result->IsTrue(isolate));
7074 Maybe<bool> Map::Delete(Local<Context> context, Local<Value> key) {
7075 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
7076 ENTER_V8(isolate, context, Map, Delete, Nothing<bool>(),
i::HandleScope);
7077 auto self = Utils::OpenHandle(
this);
7080 has_pending_exception = !i::Execution::Call(isolate, isolate->map_delete(),
7081 self, arraysize(argv), argv)
7083 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
7084 return Just(result->IsTrue(isolate));
7089 enum class MapAsArrayKind {
7090 kEntries = i::JS_MAP_KEY_VALUE_ITERATOR_TYPE,
7091 kKeys = i::JS_MAP_KEY_ITERATOR_TYPE,
7092 kValues = i::JS_MAP_VALUE_ITERATOR_TYPE
7096 int offset, MapAsArrayKind kind) {
7100 const bool collect_keys =
7101 kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kKeys;
7102 const bool collect_values =
7103 kind == MapAsArrayKind::kEntries || kind == MapAsArrayKind::kValues;
7104 int capacity = table->UsedCapacity();
7106 (capacity - offset) * ((collect_keys && collect_values) ? 2 : 1);
7108 int result_index = 0;
7112 for (
int i = offset;
i < capacity; ++
i) {
7114 if (key == the_hole)
continue;
7115 if (collect_keys) result->set(result_index++, key);
7116 if (collect_values) result->set(result_index++, table->ValueAt(
i));
7119 DCHECK_GE(max_length, result_index);
7120 if (result_index == 0)
return factory->NewJSArray(0);
7121 result->Shrink(isolate, result_index);
7122 return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
7132 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7133 return Utils::ToLocal(
7134 MapAsArray(isolate, obj->table(), 0, MapAsArrayKind::kEntries));
7140 LOG_API(i_isolate,
Set, New);
7141 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7143 return Utils::ToLocal(obj);
7147 size_t v8::Set::Size()
const {
7149 return i::OrderedHashSet::cast(obj->table())->NumberOfElements();
7154 auto self = Utils::OpenHandle(
this);
7156 LOG_API(isolate, Set, Clear);
7157 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7158 i::JSSet::Clear(isolate,
self);
7162 MaybeLocal<Set> Set::Add(Local<Context> context, Local<Value> key) {
7163 PREPARE_FOR_EXECUTION(context, Set, Add, Set);
7164 auto self = Utils::OpenHandle(
this);
7167 has_pending_exception = !i::Execution::Call(isolate, isolate->set_add(),
self,
7168 arraysize(argv), argv)
7170 RETURN_ON_FAILED_EXECUTION(Set);
7175 Maybe<bool> Set::Has(Local<Context> context, Local<Value> key) {
7176 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
7177 ENTER_V8(isolate, context, Set, Has, Nothing<bool>(),
i::HandleScope);
7178 auto self = Utils::OpenHandle(
this);
7181 has_pending_exception = !i::Execution::Call(isolate, isolate->set_has(),
self,
7182 arraysize(argv), argv)
7184 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
7185 return Just(result->IsTrue(isolate));
7189 Maybe<bool> Set::Delete(Local<Context> context, Local<Value> key) {
7190 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
7191 ENTER_V8(isolate, context, Set, Delete, Nothing<bool>(),
i::HandleScope);
7192 auto self = Utils::OpenHandle(
this);
7195 has_pending_exception = !i::Execution::Call(isolate, isolate->set_delete(),
7196 self, arraysize(argv), argv)
7198 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
7199 return Just(result->IsTrue(isolate));
7209 int capacity = table->UsedCapacity();
7210 int max_length = capacity - offset;
7211 if (max_length == 0)
return factory->NewJSArray(0);
7213 int result_index = 0;
7217 for (
int i = offset;
i < capacity; ++
i) {
7219 if (key == the_hole)
continue;
7220 result->set(result_index++, key);
7223 DCHECK_GE(max_length, result_index);
7224 if (result_index == 0)
return factory->NewJSArray(0);
7225 result->Shrink(isolate, result_index);
7226 return factory->NewJSArrayWithElements(result, i::PACKED_ELEMENTS,
7235 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7236 return Utils::ToLocal(SetAsArray(isolate, obj->table(), 0));
7241 PREPARE_FOR_EXECUTION(context, Promise_Resolver,
New,
Resolver);
7243 has_pending_exception =
7244 !ToLocal<Promise::Resolver>(isolate->factory()->NewJSPromise(), &result);
7246 RETURN_ESCAPED(result);
7258 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
7259 ENTER_V8(isolate, context, Promise_Resolver, Resolve, Nothing<bool>(),
7261 auto self = Utils::OpenHandle(
this);
7264 if (promise->status() != Promise::kPending) {
7268 has_pending_exception =
7269 i::JSPromise::Resolve(promise, Utils::OpenHandle(*value)).is_null();
7270 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
7277 auto isolate =
reinterpret_cast<i::Isolate*
>(context->GetIsolate());
7278 ENTER_V8(isolate, context, Promise_Resolver, Reject, Nothing<bool>(),
7280 auto self = Utils::OpenHandle(
this);
7283 if (promise->status() != Promise::kPending) {
7287 has_pending_exception =
7288 i::JSPromise::Reject(promise, Utils::OpenHandle(*value)).is_null();
7289 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(
bool);
7297 auto self = Utils::OpenHandle(
this);
7300 has_pending_exception = !i::Execution::Call(isolate, isolate->promise_catch(),
7301 self, arraysize(argv), argv)
7303 RETURN_ON_FAILED_EXECUTION(
Promise);
7311 auto self = Utils::OpenHandle(
this);
7314 has_pending_exception = !i::Execution::Call(isolate, isolate->promise_then(),
7315 self, arraysize(argv), argv)
7317 RETURN_ON_FAILED_EXECUTION(Promise);
7325 LOG_API(isolate,
Promise, HasRejectHandler);
7326 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7327 if (promise->IsJSPromise()) {
7329 return js_promise->has_handler();
7339 Utils::ApiCheck(js_promise->status() != kPending,
"v8_Promise_Result",
7340 "Promise is still pending");
7342 return Utils::ToLocal(result);
7348 LOG_API(isolate,
Promise, Status);
7350 return static_cast<PromiseState>(js_promise->status());
7355 js_promise->set_has_handler(
true);
7361 return Utils::ToLocal(target);
7365 Local<Value> Proxy::GetHandler() {
7368 return Utils::ToLocal(handler);
7372 bool Proxy::IsRevoked() {
7374 return self->IsRevoked();
7378 void Proxy::Revoke() {
7380 i::JSProxy::Revoke(
self);
7386 PREPARE_FOR_EXECUTION(context,
Proxy, New,
Proxy);
7390 has_pending_exception =
7391 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result);
7392 RETURN_ON_FAILED_EXECUTION(
Proxy);
7393 RETURN_ESCAPED(result);
7400 return {bytes_vec.start(), bytes_vec.size()};
7405 if (i::FLAG_wasm_shared_code) {
7410 WasmCompiledModule::SerializedModule serialized_module = Serialize();
7412 size_t wire_size = wire_bytes_ref.size;
7413 std::unique_ptr<uint8_t[]> wire_bytes_copy(
new uint8_t[wire_size]);
7414 memcpy(wire_bytes_copy.get(), wire_bytes_ref.start, wire_size);
7416 {std::move(wire_bytes_copy), wire_size});
7423 if (i::FLAG_wasm_shared_code) {
7426 i_isolate->wasm_engine()->ImportNativeModule(
7427 i_isolate, transferrable_module.shared_module_);
7431 return Deserialize(isolate, AsReference(transferrable_module.serialized_),
7432 AsReference(transferrable_module.wire_bytes_));
7439 i::wasm::NativeModule* native_module = obj->native_module();
7440 i::wasm::WasmSerializer wasm_serializer(obj->GetIsolate(), native_module);
7441 size_t buffer_size = wasm_serializer.GetSerializedNativeModuleSize();
7442 std::unique_ptr<uint8_t[]> buffer(
new uint8_t[buffer_size]);
7443 if (wasm_serializer.SerializeNativeModule({buffer.get(), buffer_size}))
7444 return {std::move(buffer), buffer_size};
7453 i::wasm::DeserializeNativeModule(
7454 i_isolate, {serialized_module.start, serialized_module.size},
7455 {wire_bytes.start, wire_bytes.size});
7457 if (!maybe_module_object.ToHandle(&module_object)) {
7458 return MaybeLocal<WasmCompiledModule>();
7468 Deserialize(isolate, serialized_module, wire_bytes);
7469 if (!ret.IsEmpty()) {
7472 return Compile(isolate, wire_bytes.start, wire_bytes.size);
7476 const uint8_t* start,
7479 i::wasm::ErrorThrower thrower(i_isolate,
"WasmCompiledModule::Compile()");
7480 if (!i::wasm::IsWasmCodegenAllowed(i_isolate, i_isolate->native_context())) {
7483 auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
7485 i_isolate->wasm_engine()->SyncCompile(
7486 i_isolate, enabled_features, &thrower,
7487 i::wasm::ModuleWireBytes(start, start + length));
7488 if (maybe_compiled.is_null())
return MaybeLocal<WasmCompiledModule>();
7490 Utils::ToLocal(maybe_compiled.ToHandleChecked()));
7500 reinterpret_cast<i::Isolate*>(isolate)->global_handles()->Create(
7501 *Utils::OpenHandle(*promise))) {}
7504 i::GlobalHandles::Destroy(promise_.location());
7509 i::JSPromise::Resolve(promise_, result);
7510 CHECK_EQ(promise_result.is_null(),
7511 promise_->GetIsolate()->has_pending_exception());
7516 i::JSPromise::Reject(promise_, error_reason);
7517 CHECK_EQ(promise_result.is_null(),
7518 promise_->GetIsolate()->has_pending_exception());
7525 WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming(
7530 Local<Promise> WasmModuleObjectBuilderStreaming::GetPromise() {
return {}; }
7536 void WasmModuleObjectBuilderStreaming::Finish() {
7544 return new ArrayBufferAllocator();
7548 return Utils::OpenHandle(
this)->is_external();
7553 return Utils::OpenHandle(
this)->is_neuterable();
7560 Utils::ApiCheck(!self->is_external(),
"v8_ArrayBuffer_Externalize",
7561 "ArrayBuffer already externalized");
7562 self->set_is_external(
true);
7565 isolate->heap()->UnregisterArrayBuffer(*
self);
7571 v8::ArrayBuffer::Contents::Contents(
void* data,
size_t byte_length,
7572 void* allocation_base,
7573 size_t allocation_length,
7574 Allocator::AllocationMode allocation_mode,
7575 DeleterCallback deleter,
void* deleter_data)
7577 byte_length_(byte_length),
7578 allocation_base_(allocation_base),
7579 allocation_length_(allocation_length),
7580 allocation_mode_(allocation_mode),
7582 deleter_data_(deleter_data) {
7583 DCHECK_LE(allocation_base_, data_);
7584 DCHECK_LE(byte_length_, allocation_length_);
7587 void WasmMemoryDeleter(
void* buffer,
size_t lenght,
void* info) {
7588 internal::wasm::WasmEngine* engine =
7589 reinterpret_cast<internal::wasm::WasmEngine*
>(info);
7590 CHECK(engine->memory_tracker()->FreeMemoryIfIsWasmMemory(
nullptr, buffer));
7593 void ArrayBufferDeleter(
void* buffer,
size_t length,
void* info) {
7596 allocator->
Free(buffer, length);
7602 self->backing_store(),
self->byte_length(),
self->allocation_base(),
7603 self->allocation_length(),
7604 self->is_wasm_memory() ? Allocator::AllocationMode::kReservation
7605 : Allocator::AllocationMode::kNormal,
7606 self->is_wasm_memory() ? WasmMemoryDeleter : ArrayBufferDeleter,
7607 self->is_wasm_memory()
7608 ?
static_cast<void*
>(
self->GetIsolate()->wasm_engine())
7609 : static_cast<void*>(self->GetIsolate()->array_buffer_allocator()));
7617 Utils::ApiCheck(obj->is_external(),
7618 "v8::ArrayBuffer::Neuter",
7619 "Only externalized ArrayBuffers can be neutered");
7620 Utils::ApiCheck(obj->is_neuterable(),
"v8::ArrayBuffer::Neuter",
7621 "Only neuterable ArrayBuffers can be neutered");
7623 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7630 return obj->byte_length();
7637 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7639 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
7642 if (!i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length)) {
7643 i::FatalProcessOutOfMemory(i_isolate,
"v8::ArrayBuffer::New");
7645 return Utils::ToLocal(obj);
7651 ArrayBufferCreationMode mode) {
7653 CHECK(byte_length == 0 || data !=
nullptr);
7654 CHECK_LE(byte_length, i::JSArrayBuffer::kMaxByteLength);
7657 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7659 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kNotShared);
7660 i::JSArrayBuffer::Setup(obj, i_isolate,
7661 mode == ArrayBufferCreationMode::kExternalized, data,
7663 return Utils::ToLocal(obj);
7670 if (obj->IsJSDataView()) {
7673 DCHECK(data_view->buffer()->IsJSArrayBuffer());
7674 buffer = i::handle(i::JSArrayBuffer::cast(data_view->buffer()),
7675 data_view->GetIsolate());
7677 DCHECK(obj->IsJSTypedArray());
7678 buffer = i::JSTypedArray::cast(*obj)->GetBuffer();
7680 return Utils::ToLocal(buffer);
7686 size_t byte_offset =
self->byte_offset();
7687 size_t bytes_to_copy = i::Min(byte_length, self->byte_length());
7688 if (bytes_to_copy) {
7693 const char* source =
reinterpret_cast<char*
>(buffer->backing_store());
7694 if (source ==
nullptr) {
7695 DCHECK(self->IsJSTypedArray());
7699 i::FixedTypedArrayBase::cast(typed_array->elements()), isolate);
7700 source =
reinterpret_cast<char*
>(fixed_array->DataPtr());
7702 memcpy(dest, source + byte_offset, bytes_to_copy);
7704 return bytes_to_copy;
7711 self->GetIsolate());
7712 return buffer->backing_store() !=
nullptr;
7718 return obj->WasNeutered() ? 0 : obj->byte_offset();
7724 return obj->WasNeutered() ? 0 : obj->byte_length();
7730 return obj->WasNeutered() ? 0 : obj->length_value();
7733 static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue,
7734 "v8::TypedArray::kMaxLength must match i::Smi::kMaxValue");
7736 #define TYPED_ARRAY_NEW(Type, type, TYPE, ctype) \ 7737 Local<Type##Array> Type##Array::New(Local<ArrayBuffer> array_buffer, \ 7738 size_t byte_offset, size_t length) { \ 7739 i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \ 7740 LOG_API(isolate, Type##Array, New); \ 7741 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \ 7742 if (!Utils::ApiCheck(length <= kMaxLength, \ 7744 "Array::New(Local<ArrayBuffer>, size_t, size_t)", \ 7745 "length exceeds max allowed value")) { \ 7746 return Local<Type##Array>(); \ 7748 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); \ 7749 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \ 7750 i::kExternal##Type##Array, buffer, byte_offset, length); \ 7751 return Utils::ToLocal##Type##Array(obj); \ 7753 Local<Type##Array> Type##Array::New( \ 7754 Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, \ 7756 CHECK(i::FLAG_harmony_sharedarraybuffer); \ 7757 i::Isolate* isolate = \ 7758 Utils::OpenHandle(*shared_array_buffer)->GetIsolate(); \ 7759 LOG_API(isolate, Type##Array, New); \ 7760 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \ 7761 if (!Utils::ApiCheck( \ 7762 length <= kMaxLength, \ 7764 "Array::New(Local<SharedArrayBuffer>, size_t, size_t)", \ 7765 "length exceeds max allowed value")) { \ 7766 return Local<Type##Array>(); \ 7768 i::Handle<i::JSArrayBuffer> buffer = \ 7769 Utils::OpenHandle(*shared_array_buffer); \ 7770 i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \ 7771 i::kExternal##Type##Array, buffer, byte_offset, length); \ 7772 return Utils::ToLocal##Type##Array(obj); \ 7775 TYPED_ARRAYS(TYPED_ARRAY_NEW)
7776 #undef TYPED_ARRAY_NEW 7779 size_t byte_offset,
size_t byte_length) {
7783 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7785 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
7786 return Utils::ToLocal(obj);
7790 Local<DataView> DataView::New(Local<SharedArrayBuffer> shared_array_buffer,
7791 size_t byte_offset,
size_t byte_length) {
7792 CHECK(i::FLAG_harmony_sharedarraybuffer);
7795 LOG_API(isolate, DataView, New);
7796 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
7798 isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
7799 return Utils::ToLocal(obj);
7804 return Utils::OpenHandle(
this)->is_external();
7810 Utils::ApiCheck(!self->is_external(),
"v8_SharedArrayBuffer_Externalize",
7811 "SharedArrayBuffer already externalized");
7812 self->set_is_external(
true);
7815 isolate->heap()->UnregisterArrayBuffer(*
self);
7821 v8::SharedArrayBuffer::Contents::Contents(
7822 void* data,
size_t byte_length,
void* allocation_base,
7823 size_t allocation_length, Allocator::AllocationMode allocation_mode,
7824 DeleterCallback deleter,
void* deleter_data)
7826 byte_length_(byte_length),
7827 allocation_base_(allocation_base),
7828 allocation_length_(allocation_length),
7829 allocation_mode_(allocation_mode),
7831 deleter_data_(deleter_data) {
7832 DCHECK_LE(allocation_base_, data_);
7833 DCHECK_LE(byte_length_, allocation_length_);
7839 self->backing_store(),
self->byte_length(),
self->allocation_base(),
7840 self->allocation_length(),
7841 self->is_wasm_memory()
7842 ? ArrayBuffer::Allocator::AllocationMode::kReservation
7843 : ArrayBuffer::Allocator::AllocationMode::kNormal,
7844 self->is_wasm_memory()
7845 ?
reinterpret_cast<Contents::DeleterCallback
>(WasmMemoryDeleter)
7846 : reinterpret_cast<Contents::DeleterCallback>(ArrayBufferDeleter),
7847 self->is_wasm_memory()
7848 ?
static_cast<void*
>(
self->GetIsolate()->wasm_engine())
7849 : static_cast<void*>(self->GetIsolate()->array_buffer_allocator()));
7855 return obj->byte_length();
7859 size_t byte_length) {
7860 CHECK(i::FLAG_harmony_sharedarraybuffer);
7863 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7865 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
7868 if (!i::JSArrayBuffer::SetupAllocatingData(obj, i_isolate, byte_length,
true,
7869 i::SharedFlag::kShared)) {
7870 i::FatalProcessOutOfMemory(i_isolate,
"v8::SharedArrayBuffer::New");
7872 return Utils::ToLocalShared(obj);
7877 Isolate* isolate,
void* data,
size_t byte_length,
7878 ArrayBufferCreationMode mode) {
7879 CHECK(i::FLAG_harmony_sharedarraybuffer);
7881 CHECK(byte_length == 0 || data !=
nullptr);
7884 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7886 i_isolate->factory()->NewJSArrayBuffer(i::SharedFlag::kShared);
7887 bool is_wasm_memory =
7888 i_isolate->wasm_engine()->memory_tracker()->IsWasmMemory(data);
7889 i::JSArrayBuffer::Setup(obj, i_isolate,
7890 mode == ArrayBufferCreationMode::kExternalized, data,
7891 byte_length, i::SharedFlag::kShared, is_wasm_memory);
7892 return Utils::ToLocalShared(obj);
7898 LOG_API(i_isolate,
Symbol, New);
7899 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7901 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
7902 return Utils::ToLocal(result);
7909 return Utils::ToLocal(
7910 i_isolate->SymbolFor(i::RootIndex::kPublicSymbolTable, i_name,
false));
7917 return Utils::ToLocal(
7918 i_isolate->SymbolFor(i::RootIndex::kApiSymbolTable, i_name,
false));
7921 #define WELL_KNOWN_SYMBOLS(V) \ 7922 V(AsyncIterator, async_iterator) \ 7923 V(HasInstance, has_instance) \ 7924 V(IsConcatSpreadable, is_concat_spreadable) \ 7925 V(Iterator, iterator) \ 7927 V(Replace, replace) \ 7930 V(ToPrimitive, to_primitive) \ 7931 V(ToStringTag, to_string_tag) \ 7932 V(Unscopables, unscopables) 7934 #define SYMBOL_GETTER(Name, name) \ 7935 Local<Symbol> v8::Symbol::Get##Name(Isolate* isolate) { \ 7936 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); \ 7937 return Utils::ToLocal(i_isolate->factory()->name##_symbol()); \ 7940 WELL_KNOWN_SYMBOLS(SYMBOL_GETTER)
7942 #undef SYMBOL_GETTER 7943 #undef WELL_KNOWN_SYMBOLS 7947 LOG_API(i_isolate,
Private, New);
7948 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
7950 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
7960 i_isolate->SymbolFor(i::RootIndex::kApiPrivateSymbolTable, i_name,
true));
7965 Local<Number> v8::Number::New(Isolate* isolate,
double value) {
7967 if (std::isnan(value)) {
7969 value = std::numeric_limits<double>::quiet_NaN();
7971 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
7973 return Utils::NumberToLocal(result);
7977 Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
7979 if (i::Smi::IsValid(value)) {
7983 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
7985 return Utils::IntegerToLocal(result);
7989 Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate,
uint32_t value) {
7991 bool fits_into_int32_t = (value & (1 << 31)) == 0;
7992 if (fits_into_int32_t) {
7993 return Integer::New(isolate, static_cast<int32_t>(value));
7995 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
7997 return Utils::IntegerToLocal(result);
8000 Local<BigInt> v8::BigInt::New(Isolate* isolate,
int64_t value) {
8002 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
8004 return Utils::ToLocal(result);
8007 Local<BigInt> v8::BigInt::NewFromUnsigned(Isolate* isolate, uint64_t value) {
8009 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(internal_isolate);
8011 return Utils::ToLocal(result);
8015 int sign_bit,
int word_count,
8016 const uint64_t* words) {
8018 ENTER_V8_NO_SCRIPT(isolate, context,
BigInt, NewFromWords,
8021 i::BigInt::FromWords64(isolate, sign_bit, word_count, words);
8022 has_pending_exception = result.is_null();
8023 RETURN_ON_FAILED_EXECUTION(
BigInt);
8024 RETURN_ESCAPED(Utils::ToLocal(result.ToHandleChecked()));
8029 return handle->AsUint64(lossless);
8034 return handle->AsInt64(lossless);
8039 return handle->Words64Count();
8043 uint64_t* words)
const {
8045 return handle->ToWordsArray64(sign_bit, word_count, words);
8048 void Isolate::ReportExternalAllocationLimitReached() {
8050 if (heap->gc_state() != i::Heap::NOT_IN_GC)
return;
8051 heap->ReportExternalMemoryPressure();
8054 void Isolate::CheckMemoryPressure() {
8056 if (heap->gc_state() != i::Heap::NOT_IN_GC)
return;
8057 heap->CheckMemoryPressure();
8060 HeapProfiler* Isolate::GetHeapProfiler() {
8062 reinterpret_cast<i::Isolate*
>(
this)->heap_profiler();
8063 return reinterpret_cast<HeapProfiler*
>(heap_profiler);
8066 void Isolate::SetIdle(
bool is_idle) {
8068 isolate->SetIdle(is_idle);
8071 bool Isolate::InContext() {
8073 return !isolate->context().is_null();
8080 if (context.is_null())
return Local<Context>();
8081 i::Context native_context = context->native_context();
8082 if (native_context.is_null())
return Local<Context>();
8090 isolate->handle_scope_implementer()->LastEnteredContext();
8091 if (last.is_null())
return Local<Context>();
8098 isolate->handle_scope_implementer()->LastEnteredOrMicrotaskContext();
8099 if (last.is_null())
return Local<Context>();
8100 DCHECK(last->IsNativeContext());
8107 return Utils::ToLocal(context);
8112 ENTER_V8_DO_NOT_USE(isolate);
8115 if (value.IsEmpty()) {
8118 isolate->ScheduleThrow(*Utils::OpenHandle(*value));
8120 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
8123 void Isolate::AddGCPrologueCallback(GCCallbackWithData callback,
void* data,
8126 isolate->heap()->AddGCPrologueCallback(callback, gc_type, data);
8129 void Isolate::RemoveGCPrologueCallback(GCCallbackWithData callback,
8132 isolate->heap()->RemoveGCPrologueCallback(callback, data);
8135 void Isolate::AddGCEpilogueCallback(GCCallbackWithData callback,
void* data,
8138 isolate->heap()->AddGCEpilogueCallback(callback, gc_type, data);
8141 void Isolate::RemoveGCEpilogueCallback(GCCallbackWithData callback,
8144 isolate->heap()->RemoveGCEpilogueCallback(callback, data);
8147 static void CallGCCallbackWithoutData(Isolate* isolate, GCType type,
8148 GCCallbackFlags flags,
void* data) {
8149 reinterpret_cast<Isolate::GCCallback
>(data)(isolate, type, flags);
8152 void Isolate::AddGCPrologueCallback(GCCallback callback, GCType gc_type) {
8153 void* data =
reinterpret_cast<void*
>(callback);
8154 AddGCPrologueCallback(CallGCCallbackWithoutData, data, gc_type);
8157 void Isolate::RemoveGCPrologueCallback(GCCallback callback) {
8158 void* data =
reinterpret_cast<void*
>(callback);
8159 RemoveGCPrologueCallback(CallGCCallbackWithoutData, data);
8162 void Isolate::AddGCEpilogueCallback(GCCallback callback, GCType gc_type) {
8163 void* data =
reinterpret_cast<void*
>(callback);
8164 AddGCEpilogueCallback(CallGCCallbackWithoutData, data, gc_type);
8167 void Isolate::RemoveGCEpilogueCallback(GCCallback callback) {
8168 void* data =
reinterpret_cast<void*
>(callback);
8169 RemoveGCEpilogueCallback(CallGCCallbackWithoutData, data);
8172 void Isolate::SetEmbedderHeapTracer(EmbedderHeapTracer* tracer) {
8174 isolate->heap()->SetEmbedderHeapTracer(tracer);
8177 EmbedderHeapTracer* Isolate::GetEmbedderHeapTracer() {
8179 return isolate->heap()->GetEmbedderHeapTracer();
8182 void Isolate::SetGetExternallyAllocatedMemoryInBytesCallback(
8183 GetExternallyAllocatedMemoryInBytesCallback callback) {
8185 isolate->heap()->SetGetExternallyAllocatedMemoryInBytesCallback(callback);
8188 void Isolate::TerminateExecution() {
8190 isolate->stack_guard()->RequestTerminateExecution();
8194 bool Isolate::IsExecutionTerminating() {
8196 return IsExecutionTerminatingCheck(isolate);
8200 void Isolate::CancelTerminateExecution() {
8202 isolate->stack_guard()->ClearTerminateExecution();
8203 isolate->CancelTerminateExecution();
8207 void Isolate::RequestInterrupt(InterruptCallback callback,
void* data) {
8209 isolate->RequestInterrupt(callback, data);
8213 void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
8214 CHECK(i::FLAG_expose_gc);
8215 if (type == kMinorGarbageCollection) {
8216 reinterpret_cast<i::Isolate*
>(
this)->heap()->CollectGarbage(
8217 i::NEW_SPACE, i::GarbageCollectionReason::kTesting,
8218 kGCCallbackFlagForced);
8220 DCHECK_EQ(kFullGarbageCollection, type);
8221 reinterpret_cast<i::Isolate*
>(
this)->heap()->PreciseCollectAllGarbage(
8222 i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting,
8223 kGCCallbackFlagForced);
8228 Isolate* Isolate::GetCurrent() {
8230 return reinterpret_cast<Isolate*
>(isolate);
8234 Isolate* Isolate::Allocate() {
8235 return reinterpret_cast<Isolate*
>(i::Isolate::New());
8240 void Isolate::Initialize(Isolate* isolate,
8248 i_isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob());
8251 #ifdef ENABLE_GDB_JIT_INTERFACE 8252 if (code_event_handler ==
nullptr && i::FLAG_gdbjit) {
8253 code_event_handler = i::GDBJITInterface::EventHandler;
8255 #endif // ENABLE_GDB_JIT_INTERFACE 8256 if (code_event_handler) {
8257 i_isolate->InitializeLoggingAndCounters();
8258 i_isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault,
8259 code_event_handler);
8269 if (params.add_histogram_sample_callback) {
8270 isolate->SetAddHistogramSampleFunction(
8271 params.add_histogram_sample_callback);
8277 SetResourceConstraints(i_isolate, params.
constraints);
8279 Isolate::Scope isolate_scope(isolate);
8280 if (!i::Snapshot::Initialize(i_isolate)) {
8283 if (i_isolate->snapshot_blob() !=
nullptr) {
8285 "Failed to deserialize the V8 snapshot blob. This can mean that the " 8286 "snapshot blob file is corrupted or missing.");
8288 base::ElapsedTimer timer;
8289 if (i::FLAG_profile_deserialization) timer.Start();
8290 i_isolate->Init(
nullptr);
8291 if (i::FLAG_profile_deserialization) {
8292 double ms = timer.Elapsed().InMillisecondsF();
8293 i::PrintF(
"[Initializing isolate from scratch took %0.3f ms]\n", ms);
8296 i_isolate->set_only_terminate_in_safe_scope(
8300 Isolate* Isolate::New(
const Isolate::CreateParams& params) {
8301 Isolate* isolate = Allocate();
8302 Initialize(isolate, params);
8306 void Isolate::Dispose() {
8308 if (!Utils::ApiCheck(!isolate->IsInUse(),
8309 "v8::Isolate::Dispose()",
8310 "Disposing the isolate that is entered by a thread.")) {
8313 i::Isolate::Delete(isolate);
8316 void Isolate::DumpAndResetStats() {
8318 isolate->DumpAndResetStats();
8321 void Isolate::DiscardThreadSpecificMetadata() {
8323 isolate->DiscardPerThreadDataForThisThread();
8327 void Isolate::Enter() {
8333 void Isolate::Exit() {
8339 void Isolate::SetAbortOnUncaughtExceptionCallback(
8340 AbortOnUncaughtExceptionCallback callback) {
8342 isolate->SetAbortOnUncaughtExceptionCallback(callback);
8345 void Isolate::SetHostImportModuleDynamicallyCallback(
8346 HostImportModuleDynamicallyCallback callback) {
8348 isolate->SetHostImportModuleDynamicallyCallback(callback);
8351 void Isolate::SetHostInitializeImportMetaObjectCallback(
8352 HostInitializeImportMetaObjectCallback callback) {
8354 isolate->SetHostInitializeImportMetaObjectCallback(callback);
8357 void Isolate::SetPrepareStackTraceCallback(PrepareStackTraceCallback callback) {
8359 isolate->SetPrepareStackTraceCallback(callback);
8362 Isolate::DisallowJavascriptExecutionScope::DisallowJavascriptExecutionScope(
8364 Isolate::DisallowJavascriptExecutionScope::OnFailure on_failure)
8365 : on_failure_(on_failure) {
8367 switch (on_failure_) {
8368 case CRASH_ON_FAILURE:
8369 internal_ =
reinterpret_cast<void*
>(
8372 case THROW_ON_FAILURE:
8373 DCHECK_EQ(THROW_ON_FAILURE, on_failure);
8377 case DUMP_ON_FAILURE:
8388 Isolate::DisallowJavascriptExecutionScope::~DisallowJavascriptExecutionScope() {
8389 switch (on_failure_) {
8390 case CRASH_ON_FAILURE:
8393 case THROW_ON_FAILURE:
8396 case DUMP_ON_FAILURE:
8406 Isolate::AllowJavascriptExecutionScope::AllowJavascriptExecutionScope(
8409 internal_assert_ =
reinterpret_cast<void*
>(
8411 internal_throws_ =
reinterpret_cast<void*
>(
8418 Isolate::AllowJavascriptExecutionScope::~AllowJavascriptExecutionScope() {
8425 Isolate::SuppressMicrotaskExecutionScope::SuppressMicrotaskExecutionScope(
8427 : isolate_(reinterpret_cast<
i::Isolate*>(isolate)) {
8428 isolate_->handle_scope_implementer()->IncrementCallDepth();
8429 isolate_->handle_scope_implementer()->IncrementMicrotasksSuppressions();
8433 Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
8434 isolate_->handle_scope_implementer()->DecrementMicrotasksSuppressions();
8435 isolate_->handle_scope_implementer()->DecrementCallDepth();
8438 Isolate::SafeForTerminationScope::SafeForTerminationScope(v8::Isolate* isolate)
8439 : isolate_(reinterpret_cast<
i::Isolate*>(isolate)),
8440 prev_value_(isolate_->next_v8_call_is_safe_for_termination()) {
8441 isolate_->set_next_v8_call_is_safe_for_termination(
true);
8444 Isolate::SafeForTerminationScope::~SafeForTerminationScope() {
8445 isolate_->set_next_v8_call_is_safe_for_termination(prev_value_);
8448 i::Address* Isolate::GetDataFromSnapshotOnce(
size_t index) {
8450 i::FixedArray list = i_isolate->heap()->serialized_objects();
8451 return GetSerializedDataFromFixedArray(i_isolate, list, index);
8454 void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
8456 i::Heap* heap = isolate->heap();
8457 heap_statistics->total_heap_size_ = heap->CommittedMemory();
8458 heap_statistics->total_heap_size_executable_ =
8459 heap->CommittedMemoryExecutable();
8460 heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
8461 heap_statistics->total_available_size_ = heap->Available();
8462 heap_statistics->used_heap_size_ = heap->SizeOfObjects();
8463 heap_statistics->heap_size_limit_ = heap->MaxReserved();
8467 heap_statistics->malloced_memory_ =
8468 isolate->allocator()->GetCurrentMemoryUsage() +
8469 isolate->wasm_engine()->allocator()->GetCurrentMemoryUsage();
8470 heap_statistics->external_memory_ = isolate->heap()->external_memory();
8471 heap_statistics->peak_malloced_memory_ =
8472 isolate->allocator()->GetMaxMemoryUsage() +
8473 isolate->wasm_engine()->allocator()->GetMaxMemoryUsage();
8474 heap_statistics->number_of_native_contexts_ = heap->NumberOfNativeContexts();
8475 heap_statistics->number_of_detached_contexts_ =
8476 heap->NumberOfDetachedContexts();
8477 heap_statistics->does_zap_garbage_ = heap->ShouldZapGarbage();
8481 size_t Isolate::NumberOfHeapSpaces() {
8482 return i::LAST_SPACE - i::FIRST_SPACE + 1;
8486 bool Isolate::GetHeapSpaceStatistics(HeapSpaceStatistics* space_statistics,
8488 if (!space_statistics)
return false;
8489 if (!i::Heap::IsValidAllocationSpace(static_cast<i::AllocationSpace>(index)))
8493 i::Heap* heap = isolate->heap();
8494 i::Space* space = heap->space(static_cast<int>(index));
8496 space_statistics->space_name_ = heap->GetSpaceName(static_cast<int>(index));
8497 space_statistics->space_size_ = space->CommittedMemory();
8498 space_statistics->space_used_size_ = space->SizeOfObjects();
8499 space_statistics->space_available_size_ = space->Available();
8500 space_statistics->physical_space_size_ = space->CommittedPhysicalMemory();
8505 size_t Isolate::NumberOfTrackedHeapObjectTypes() {
8507 i::Heap* heap = isolate->heap();
8508 return heap->NumberOfTrackedHeapObjectTypes();
8512 bool Isolate::GetHeapObjectStatisticsAtLastGC(
8513 HeapObjectStatistics* object_statistics,
size_t type_index) {
8514 if (!object_statistics)
return false;
8515 if (V8_LIKELY(!i::FLAG_gc_stats))
return false;
8518 i::Heap* heap = isolate->heap();
8519 if (type_index >= heap->NumberOfTrackedHeapObjectTypes())
return false;
8521 const char* object_type;
8522 const char* object_sub_type;
8523 size_t object_count = heap->ObjectCountAtLastGC(type_index);
8524 size_t object_size = heap->ObjectSizeAtLastGC(type_index);
8525 if (!heap->GetObjectTypeName(type_index, &object_type, &object_sub_type)) {
8527 DCHECK_EQ(object_count, 0U);
8528 DCHECK_EQ(object_size, 0U);
8532 object_statistics->object_type_ = object_type;
8533 object_statistics->object_sub_type_ = object_sub_type;
8534 object_statistics->object_count_ = object_count;
8535 object_statistics->object_size_ = object_size;
8539 bool Isolate::GetHeapCodeAndMetadataStatistics(
8540 HeapCodeStatistics* code_statistics) {
8541 if (!code_statistics)
return false;
8544 isolate->heap()->CollectCodeStatistics();
8546 code_statistics->code_and_metadata_size_ = isolate->code_and_metadata_size();
8547 code_statistics->bytecode_and_metadata_size_ =
8548 isolate->bytecode_and_metadata_size();
8549 code_statistics->external_script_source_size_ =
8550 isolate->external_script_source_size();
8554 void Isolate::GetStackSample(
const RegisterState& state,
void** frames,
8555 size_t frames_limit, SampleInfo* sample_info) {
8556 RegisterState regs = state;
8558 frames, frames_limit, sample_info)) {
8561 sample_info->frames_count = 0;
8562 sample_info->vm_state = OTHER;
8563 sample_info->external_callback_entry =
nullptr;
8566 size_t Isolate::NumberOfPhantomHandleResetsSinceLastCall() {
8568 size_t result = isolate->global_handles()->NumberOfPhantomHandleResets();
8569 isolate->global_handles()->ResetNumberOfPhantomHandleResets();
8573 void Isolate::SetEventLogger(LogEventCallback that) {
8575 if (i::FLAG_log_internal_timer_events)
return;
8577 isolate->set_event_logger(that);
8581 void Isolate::AddBeforeCallEnteredCallback(BeforeCallEnteredCallback callback) {
8582 if (callback ==
nullptr)
return;
8584 isolate->AddBeforeCallEnteredCallback(callback);
8588 void Isolate::RemoveBeforeCallEnteredCallback(
8589 BeforeCallEnteredCallback callback) {
8591 isolate->RemoveBeforeCallEnteredCallback(callback);
8595 void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
8596 if (callback ==
nullptr)
return;
8598 isolate->AddCallCompletedCallback(callback);
8602 void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
8604 isolate->RemoveCallCompletedCallback(callback);
8611 void Isolate::SetAtomicsWaitCallback(AtomicsWaitCallback callback,
void* data) {
8613 isolate->SetAtomicsWaitCallback(callback, data);
8616 void Isolate::SetPromiseHook(PromiseHook hook) {
8618 isolate->SetPromiseHook(hook);
8621 void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) {
8622 if (callback ==
nullptr)
return;
8624 isolate->SetPromiseRejectCallback(callback);
8628 void Isolate::RunMicrotasks() {
8629 DCHECK_NE(MicrotasksPolicy::kScoped, GetMicrotasksPolicy());
8630 reinterpret_cast<i::Isolate*
>(
this)->RunMicrotasks();
8633 void Isolate::EnqueueMicrotask(Local<Function>
function) {
8636 Utils::OpenHandle(*
function), isolate->native_context());
8637 isolate->EnqueueMicrotask(microtask);
8640 void Isolate::EnqueueMicrotask(MicrotaskCallback callback,
void* data) {
8644 isolate->factory()->NewForeign(reinterpret_cast<i::Address>(callback)),
8645 isolate->factory()->NewForeign(reinterpret_cast<i::Address>(data)));
8646 isolate->EnqueueMicrotask(microtask);
8650 void Isolate::SetMicrotasksPolicy(MicrotasksPolicy policy) {
8652 isolate->handle_scope_implementer()->set_microtasks_policy(policy);
8656 MicrotasksPolicy Isolate::GetMicrotasksPolicy()
const {
8658 reinterpret_cast<i::Isolate*
>(
const_cast<Isolate*
>(
this));
8659 return isolate->handle_scope_implementer()->microtasks_policy();
8663 void Isolate::AddMicrotasksCompletedCallback(
8664 MicrotasksCompletedCallback callback) {
8667 isolate->AddMicrotasksCompletedCallback(callback);
8671 void Isolate::RemoveMicrotasksCompletedCallback(
8672 MicrotasksCompletedCallback callback) {
8674 isolate->RemoveMicrotasksCompletedCallback(callback);
8678 void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
8679 reinterpret_cast<i::Isolate*
>(
this)->SetUseCounterCallback(callback);
8683 void Isolate::SetCounterFunction(CounterLookupCallback callback) {
8685 isolate->counters()->ResetCounterFunction(callback);
8689 void Isolate::SetCreateHistogramFunction(CreateHistogramCallback callback) {
8691 isolate->counters()->ResetCreateHistogramFunction(callback);
8695 void Isolate::SetAddHistogramSampleFunction(
8696 AddHistogramSampleCallback callback) {
8699 ->SetAddHistogramSampleFunction(callback);
8703 bool Isolate::IdleNotificationDeadline(
double deadline_in_seconds) {
8707 if (!i::FLAG_use_idle_notification)
return true;
8708 return isolate->heap()->IdleNotification(deadline_in_seconds);
8711 void Isolate::LowMemoryNotification() {
8715 isolate->counters()->gc_low_memory_notification());
8716 TRACE_EVENT0(
"v8",
"V8.GCLowMemoryNotification");
8717 isolate->heap()->CollectAllAvailableGarbage(
8718 i::GarbageCollectionReason::kLowMemoryNotification);
8723 while ((obj = iterator.next()) !=
nullptr) {
8724 if (obj->IsAbstractCode()) {
8725 i::AbstractCode::cast(obj)->DropStackFrameCache();
8732 int Isolate::ContextDisposedNotification(
bool dependant_context) {
8734 if (!dependant_context) {
8737 isolate->wasm_engine()->DeleteCompileJobsOnIsolate(isolate);
8740 return isolate->heap()->NotifyContextDisposed(dependant_context);
8744 void Isolate::IsolateInForegroundNotification() {
8746 return isolate->IsolateInForegroundNotification();
8750 void Isolate::IsolateInBackgroundNotification() {
8752 return isolate->IsolateInBackgroundNotification();
8755 void Isolate::MemoryPressureNotification(MemoryPressureLevel level) {
8757 bool on_isolate_thread =
8758 v8::Locker::IsActive()
8759 ? isolate->thread_manager()->IsLockedByCurrentThread()
8760 : i::ThreadId::Current().Equals(isolate->thread_id());
8761 isolate->heap()->MemoryPressureNotification(level, on_isolate_thread);
8762 isolate->allocator()->MemoryPressureNotification(level);
8765 void Isolate::EnableMemorySavingsMode() {
8767 isolate->EnableMemorySavingsMode();
8770 void Isolate::DisableMemorySavingsMode() {
8772 isolate->DisableMemorySavingsMode();
8775 void Isolate::SetRAILMode(RAILMode rail_mode) {
8777 return isolate->SetRAILMode(rail_mode);
8780 void Isolate::IncreaseHeapLimitForDebugging() {
8784 void Isolate::RestoreOriginalHeapLimit() {
8788 bool Isolate::IsHeapLimitIncreasedForDebugging() {
return false; }
8790 void Isolate::SetJitCodeEventHandler(JitCodeEventOptions options,
8791 JitCodeEventHandler event_handler) {
8794 isolate->InitializeLoggingAndCounters();
8795 isolate->logger()->SetCodeEventHandler(options, event_handler);
8799 void Isolate::SetStackLimit(
uintptr_t stack_limit) {
8802 isolate->stack_guard()->SetStackLimit(stack_limit);
8805 void Isolate::GetCodeRange(
void** start,
size_t* length_in_bytes) {
8807 const base::AddressRegion& code_range =
8808 isolate->heap()->memory_allocator()->code_range();
8809 *start =
reinterpret_cast<void*
>(code_range.begin());
8810 *length_in_bytes = code_range.size();
8813 UnwindState Isolate::GetUnwindState() {
8814 UnwindState unwind_state;
8815 void* code_range_start;
8816 GetCodeRange(&code_range_start, &unwind_state.code_range.length_in_bytes);
8817 unwind_state.code_range.start = code_range_start;
8820 unwind_state.embedded_code_range.start =
8821 reinterpret_cast<const void*
>(isolate->embedded_blob());
8822 unwind_state.embedded_code_range.length_in_bytes =
8823 isolate->embedded_blob_size();
8825 i::Code js_entry = isolate->heap()->js_entry_code();
8826 unwind_state.js_entry_stub.code.start =
8827 reinterpret_cast<const void*
>(js_entry->InstructionStart());
8828 unwind_state.js_entry_stub.code.length_in_bytes = js_entry->InstructionSize();
8830 return unwind_state;
8833 #define CALLBACK_SETTER(ExternalName, Type, InternalName) \ 8834 void Isolate::Set##ExternalName(Type callback) { \ 8835 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); \ 8836 isolate->set_##InternalName(callback); \ 8839 CALLBACK_SETTER(FatalErrorHandler, FatalErrorCallback, exception_behavior)
8840 CALLBACK_SETTER(OOMErrorHandler, OOMErrorCallback, oom_behavior)
8841 CALLBACK_SETTER(AllowCodeGenerationFromStringsCallback,
8842 AllowCodeGenerationFromStringsCallback, allow_code_gen_callback)
8843 CALLBACK_SETTER(AllowWasmCodeGenerationCallback,
8844 AllowWasmCodeGenerationCallback, allow_wasm_code_gen_callback)
8846 CALLBACK_SETTER(WasmModuleCallback, ExtensionCallback, wasm_module_callback)
8847 CALLBACK_SETTER(WasmInstanceCallback, ExtensionCallback, wasm_instance_callback)
8849 CALLBACK_SETTER(WasmCompileStreamingCallback, ApiImplementationCallback,
8850 wasm_compile_streaming_callback)
8852 CALLBACK_SETTER(WasmStreamingCallback, WasmStreamingCallback,
8853 wasm_streaming_callback)
8855 CALLBACK_SETTER(WasmThreadsEnabledCallback, WasmThreadsEnabledCallback,
8856 wasm_threads_enabled_callback)
8858 void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
8861 isolate->heap()->AddNearHeapLimitCallback(callback, data);
8864 void Isolate::RemoveNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
8865 size_t heap_limit) {
8867 isolate->heap()->RemoveNearHeapLimitCallback(callback, heap_limit);
8870 bool Isolate::IsDead() {
8872 return isolate->IsDead();
8875 bool Isolate::AddMessageListener(MessageCallback that, Local<Value> data) {
8876 return AddMessageListenerWithErrorLevel(that, kMessageError, data);
8879 bool Isolate::AddMessageListenerWithErrorLevel(MessageCallback that,
8881 Local<Value> data) {
8883 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
8888 isolate->factory()->NewForeign(FUNCTION_ADDR(that));
8889 listener->set(0, *foreign);
8890 listener->set(1, data.IsEmpty() ?
i::ReadOnlyRoots(isolate).undefined_value()
8891 : *Utils::OpenHandle(*data));
8892 listener->set(2, i::Smi::FromInt(message_levels));
8893 list = i::TemplateList::Add(isolate, list, listener);
8894 isolate->heap()->SetMessageListeners(*list);
8899 void Isolate::RemoveMessageListeners(MessageCallback that) {
8901 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
8905 for (
int i = 0;
i < listeners->length();
i++) {
8906 if (listeners->get(
i)->IsUndefined(isolate))
continue;
8908 i::Foreign* callback_obj = i::Foreign::cast(listener->get(0));
8909 if (callback_obj->foreign_address() == FUNCTION_ADDR(that)) {
8916 void Isolate::SetFailedAccessCheckCallbackFunction(
8917 FailedAccessCheckCallback callback) {
8919 isolate->SetFailedAccessCheckCallback(callback);
8923 void Isolate::SetCaptureStackTraceForUncaughtExceptions(
8926 isolate->SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit,
8931 void Isolate::VisitExternalResources(ExternalResourceVisitor* visitor) {
8933 isolate->heap()->VisitExternalResources(visitor);
8937 bool Isolate::IsInUse() {
8939 return isolate->IsInUse();
8943 void Isolate::VisitHandlesWithClassIds(PersistentHandleVisitor* visitor) {
8946 isolate->global_handles()->IterateAllRootsWithClassIds(visitor);
8950 void Isolate::VisitHandlesForPartialDependence(
8951 PersistentHandleVisitor* visitor) {
8954 isolate->global_handles()->IterateAllRootsInNewSpaceWithClassIds(visitor);
8958 void Isolate::VisitWeakHandles(PersistentHandleVisitor* visitor) {
8961 isolate->global_handles()->IterateWeakRootsInNewSpaceWithClassIds(visitor);
8964 void Isolate::SetAllowAtomicsWait(
bool allow) {
8966 isolate->set_allow_atomics_wait(allow);
8969 MicrotasksScope::MicrotasksScope(Isolate* isolate, MicrotasksScope::Type type)
8970 : isolate_(reinterpret_cast<
i::Isolate*>(isolate)),
8971 run_(type == MicrotasksScope::kRunMicrotasks) {
8972 auto handle_scope_implementer = isolate_->handle_scope_implementer();
8973 if (run_) handle_scope_implementer->IncrementMicrotasksScopeDepth();
8975 if (!run_) handle_scope_implementer->IncrementDebugMicrotasksScopeDepth();
8980 MicrotasksScope::~MicrotasksScope() {
8981 auto handle_scope_implementer = isolate_->handle_scope_implementer();
8983 handle_scope_implementer->DecrementMicrotasksScopeDepth();
8984 if (MicrotasksPolicy::kScoped ==
8985 handle_scope_implementer->microtasks_policy()) {
8986 PerformCheckpoint(reinterpret_cast<Isolate*>(isolate_));
8990 if (!run_) handle_scope_implementer->DecrementDebugMicrotasksScopeDepth();
8995 void MicrotasksScope::PerformCheckpoint(Isolate* v8Isolate) {
8997 if (IsExecutionTerminatingCheck(isolate))
return;
8998 auto handle_scope_implementer = isolate->handle_scope_implementer();
8999 if (!handle_scope_implementer->GetMicrotasksScopeDepth() &&
9000 !handle_scope_implementer->HasMicrotasksSuppressions()) {
9001 isolate->RunMicrotasks();
9006 int MicrotasksScope::GetCurrentDepth(Isolate* v8Isolate) {
9008 return isolate->handle_scope_implementer()->GetMicrotasksScopeDepth();
9011 bool MicrotasksScope::IsRunningMicrotasks(Isolate* v8Isolate) {
9013 return isolate->IsRunningMicrotasks();
9017 : str_(nullptr), length_(0) {
9018 if (obj.IsEmpty())
return;
9020 ENTER_V8_DO_NOT_USE(i_isolate);
9022 Local<Context> context = isolate->GetCurrentContext();
9023 TryCatch try_catch(isolate);
9025 if (!obj->ToString(context).ToLocal(&str))
return;
9026 length_ = str->Utf8Length(isolate);
9027 str_ = i::NewArray<char>(length_ + 1);
9028 str->WriteUtf8(isolate, str_);
9031 String::Utf8Value::~Utf8Value() {
9032 i::DeleteArray(str_);
9036 : str_(nullptr), length_(0) {
9037 if (obj.IsEmpty())
return;
9039 ENTER_V8_DO_NOT_USE(i_isolate);
9041 Local<Context> context = isolate->GetCurrentContext();
9042 TryCatch try_catch(isolate);
9044 if (!obj->ToString(context).ToLocal(&str))
return;
9045 length_ = str->Length();
9046 str_ = i::NewArray<uint16_t>(length_ + 1);
9047 str->Write(isolate, str_);
9050 String::Value::~Value() {
9051 i::DeleteArray(str_);
9054 #define DEFINE_ERROR(NAME, name) \ 9055 Local<Value> Exception::NAME(v8::Local<v8::String> raw_message) { \ 9056 i::Isolate* isolate = i::Isolate::Current(); \ 9057 LOG_API(isolate, NAME, New); \ 9058 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \ 9061 i::HandleScope scope(isolate); \ 9062 i::Handle<i::String> message = Utils::OpenHandle(*raw_message); \ 9063 i::Handle<i::JSFunction> constructor = isolate->name##_function(); \ 9064 error = *isolate->factory()->NewError(constructor, message); \ 9066 i::Handle<i::Object> result(error, isolate); \ 9067 return Utils::ToLocal(result); \ 9070 DEFINE_ERROR(RangeError, range_error)
9071 DEFINE_ERROR(ReferenceError, reference_error)
9072 DEFINE_ERROR(SyntaxError, syntax_error)
9073 DEFINE_ERROR(TypeError, type_error)
9074 DEFINE_ERROR(Error, error)
9079 Local<Message> Exception::CreateMessage(Isolate* isolate,
9080 Local<Value> exception) {
9083 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
9085 return Utils::MessageToLocal(
9086 scope.CloseAndEscape(i_isolate->CreateMessage(obj,
nullptr)));
9090 Local<StackTrace> Exception::GetStackTrace(Local<Value> exception) {
9092 if (!obj->IsJSObject())
return Local<StackTrace>();
9095 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9096 return Utils::StackTraceToLocal(isolate->GetDetailedStackTrace(js_obj));
9102 void debug::SetContextId(Local<Context> context,
int id) {
9103 Utils::OpenHandle(*context)->set_debug_context_id(i::Smi::FromInt(
id));
9106 int debug::GetContextId(Local<Context> context) {
9107 i::Object* value = Utils::OpenHandle(*context)->debug_context_id();
9108 return (value->IsSmi()) ? i::Smi::ToInt(value) : 0;
9111 void debug::SetInspector(Isolate* isolate,
9114 i_isolate->set_inspector(inspector);
9118 return reinterpret_cast<i::Isolate*
>(isolate)->inspector();
9121 void debug::SetBreakOnNextFunctionCall(Isolate* isolate) {
9122 reinterpret_cast<i::Isolate*
>(isolate)->debug()->SetBreakOnNextFunctionCall();
9125 void debug::ClearBreakOnNextFunctionCall(Isolate* isolate) {
9128 ->ClearBreakOnNextFunctionCall();
9131 MaybeLocal<Array> debug::GetInternalProperties(Isolate* v8_isolate,
9132 Local<Value> value) {
9134 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9137 if (!i::Runtime::GetInternalProperties(isolate, val).ToHandle(&result))
9138 return MaybeLocal<Array>();
9139 return Utils::ToLocal(result);
9142 void debug::ChangeBreakOnException(Isolate* isolate, ExceptionBreakState type) {
9144 internal_isolate->debug()->ChangeBreakOnException(
9145 i::BreakException, type == BreakOnAnyException);
9146 internal_isolate->debug()->ChangeBreakOnException(i::BreakUncaughtException,
9147 type != NoBreakOnException);
9150 void debug::SetBreakPointsActive(Isolate* v8_isolate,
bool is_active) {
9152 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9153 isolate->debug()->set_break_points_active(is_active);
9156 void debug::PrepareStep(Isolate* v8_isolate, StepAction action) {
9158 ENTER_V8_DO_NOT_USE(isolate);
9159 CHECK(isolate->debug()->CheckExecutionState());
9161 isolate->debug()->ClearStepping();
9163 isolate->debug()->PrepareStep(static_cast<i::StepAction>(action));
9166 void debug::ClearStepping(Isolate* v8_isolate) {
9168 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9170 isolate->debug()->ClearStepping();
9173 void debug::BreakRightNow(Isolate* v8_isolate) {
9175 ENTER_V8_DO_NOT_USE(isolate);
9176 isolate->debug()->HandleDebugBreak(i::kIgnoreIfAllFramesBlackboxed);
9179 bool debug::AllFramesOnStackAreBlackboxed(Isolate* v8_isolate) {
9181 ENTER_V8_DO_NOT_USE(isolate);
9182 return isolate->debug()->AllFramesOnStackAreBlackboxed();
9185 v8::Isolate* debug::Script::GetIsolate()
const {
9186 return reinterpret_cast<v8::Isolate*
>(Utils::OpenHandle(
this)->GetIsolate());
9189 ScriptOriginOptions debug::Script::OriginOptions()
const {
9190 return Utils::OpenHandle(
this)->origin_options();
9193 bool debug::Script::WasCompiled()
const {
9194 return Utils::OpenHandle(
this)->compilation_state() ==
9195 i::Script::COMPILATION_STATE_COMPILED;
9198 bool debug::Script::IsEmbedded()
const {
9200 return script->context_data() ==
9201 script->GetReadOnlyRoots().uninitialized_symbol();
9204 int debug::Script::Id()
const {
return Utils::OpenHandle(
this)->id(); }
9206 int debug::Script::LineOffset()
const {
9207 return Utils::OpenHandle(
this)->line_offset();
9210 int debug::Script::ColumnOffset()
const {
9211 return Utils::OpenHandle(
this)->column_offset();
9214 std::vector<int> debug::Script::LineEnds()
const {
9216 if (script->type() == i::Script::TYPE_WASM &&
9217 this->SourceMappingURL().IsEmpty()) {
9218 return std::vector<int>();
9222 i::Script::InitLineEnds(script);
9223 CHECK(script->line_ends()->IsFixedArray());
9226 std::vector<int> result(line_ends->length());
9227 for (
int i = 0;
i < line_ends->length(); ++
i) {
9228 i::Smi line_end = i::Smi::cast(line_ends->get(
i));
9229 result[
i] = line_end->value();
9234 MaybeLocal<String> debug::Script::Name()
const {
9235 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
9239 if (!value->IsString())
return MaybeLocal<String>();
9240 return Utils::ToLocal(
9244 MaybeLocal<String> debug::Script::SourceURL()
const {
9245 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
9249 if (!value->IsString())
return MaybeLocal<String>();
9250 return Utils::ToLocal(
9254 MaybeLocal<String> debug::Script::SourceMappingURL()
const {
9255 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
9259 if (!value->IsString())
return MaybeLocal<String>();
9260 return Utils::ToLocal(
9264 Maybe<int> debug::Script::ContextId()
const {
9265 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
9268 i::Object* value = script->context_data();
9269 if (value->IsSmi())
return Just(i::Smi::ToInt(value));
9270 return Nothing<int>();
9273 MaybeLocal<String> debug::Script::Source()
const {
9274 i::Isolate* isolate = Utils::OpenHandle(
this)->GetIsolate();
9278 if (!value->IsString())
return MaybeLocal<String>();
9279 return Utils::ToLocal(
9283 bool debug::Script::IsWasm()
const {
9284 return Utils::OpenHandle(
this)->type() == i::Script::TYPE_WASM;
9287 bool debug::Script::IsModule()
const {
9288 return Utils::OpenHandle(
this)->origin_options().IsModule();
9293 return i::Smi::ToInt(array->get(index));
9298 return loc1.position() < loc2.position();
9302 bool debug::Script::GetPossibleBreakpoints(
9303 const debug::Location& start,
const debug::Location& end,
9304 bool restrict_to_function,
9305 std::vector<debug::BreakLocation>* locations)
const {
9306 CHECK(!start.IsEmpty());
9308 if (script->type() == i::Script::TYPE_WASM &&
9309 this->SourceMappingURL().IsEmpty()) {
9311 i::WasmModuleObject::cast(script->wasm_module_object());
9312 return module_object->GetPossibleBreakpoints(start, end, locations);
9315 i::Script::InitLineEnds(script);
9316 CHECK(script->line_ends()->IsFixedArray());
9320 CHECK(line_ends->length());
9322 int start_offset = GetSourceOffset(start);
9323 int end_offset = end.IsEmpty()
9324 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1
9325 : GetSourceOffset(end);
9326 if (start_offset >= end_offset)
return true;
9328 std::vector<i::BreakLocation> v8_locations;
9329 if (!isolate->debug()->GetPossibleBreakpoints(
9330 script, start_offset, end_offset, restrict_to_function,
9335 std::sort(v8_locations.begin(), v8_locations.end(), CompareBreakLocation);
9336 int current_line_end_index = 0;
9337 for (
const auto& v8_location : v8_locations) {
9338 int offset = v8_location.position();
9339 while (offset > GetSmiValue(line_ends, current_line_end_index)) {
9340 ++current_line_end_index;
9341 CHECK(current_line_end_index < line_ends->length());
9343 int line_offset = 0;
9345 if (current_line_end_index > 0) {
9346 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1;
9348 locations->emplace_back(
9349 current_line_end_index + script->line_offset(),
9350 offset - line_offset +
9351 (current_line_end_index == 0 ? script->column_offset() : 0),
9352 v8_location.type());
9357 int debug::Script::GetSourceOffset(
const debug::Location& location)
const {
9359 if (script->type() == i::Script::TYPE_WASM) {
9360 if (this->SourceMappingURL().IsEmpty()) {
9361 return i::WasmModuleObject::cast(script->wasm_module_object())
9362 ->GetFunctionOffset(location.GetLineNumber()) +
9363 location.GetColumnNumber();
9365 DCHECK_EQ(0, location.GetLineNumber());
9366 return location.GetColumnNumber();
9369 int line = std::max(location.GetLineNumber() - script->line_offset(), 0);
9370 int column = location.GetColumnNumber();
9372 column = std::max(0, column - script->column_offset());
9375 i::Script::InitLineEnds(script);
9376 CHECK(script->line_ends()->IsFixedArray());
9378 i::handle(script->line_ends(), script->GetIsolate()));
9379 CHECK(line_ends->length());
9380 if (line >= line_ends->length())
9381 return GetSmiValue(line_ends, line_ends->length() - 1);
9382 int line_offset = GetSmiValue(line_ends, line);
9383 if (line == 0)
return std::min(column, line_offset);
9384 int prev_line_offset = GetSmiValue(line_ends, line - 1);
9385 return std::min(prev_line_offset + column + 1, line_offset);
9390 i::Script::PositionInfo info;
9391 i::Script::GetPositionInfo(script, offset, &info, i::Script::WITH_OFFSET);
9392 return debug::Location(info.line, info.column);
9397 debug::LiveEditResult* result)
const {
9400 return isolate->debug()->SetScriptSource(
9401 script, Utils::OpenHandle(*newSource), preview, result);
9405 debug::Location* location,
9406 debug::BreakpointId*
id)
const {
9409 int offset = GetSourceOffset(*location);
9410 if (!isolate->debug()->SetBreakPointForScript(
9411 script, Utils::OpenHandle(*condition), &offset,
id)) {
9414 *location = GetSourceLocation(offset);
9418 void debug::RemoveBreakpoint(Isolate* v8_isolate, BreakpointId
id) {
9421 isolate->debug()->RemoveBreakpoint(
id);
9425 return i::V8::GetCurrentPlatform();
9428 debug::WasmScript* debug::WasmScript::Cast(debug::Script* script) {
9429 CHECK(script->IsWasm());
9430 return static_cast<WasmScript*
>(script);
9433 int debug::WasmScript::NumFunctions()
const {
9436 DCHECK_EQ(i::Script::TYPE_WASM, script->type());
9438 i::WasmModuleObject::cast(script->wasm_module_object());
9439 const i::wasm::WasmModule* module = module_object->module();
9440 DCHECK_GE(i::kMaxInt, module->functions.size());
9441 return static_cast<int>(module->functions.size());
9444 int debug::WasmScript::NumImportedFunctions()
const {
9447 DCHECK_EQ(i::Script::TYPE_WASM, script->type());
9449 i::WasmModuleObject::cast(script->wasm_module_object());
9450 const i::wasm::WasmModule* module = module_object->module();
9451 DCHECK_GE(i::kMaxInt, module->num_imported_functions);
9452 return static_cast<int>(module->num_imported_functions);
9455 std::pair<int, int> debug::WasmScript::GetFunctionRange(
9456 int function_index)
const {
9459 DCHECK_EQ(i::Script::TYPE_WASM, script->type());
9461 i::WasmModuleObject::cast(script->wasm_module_object());
9462 const i::wasm::WasmModule* module = module_object->module();
9463 DCHECK_LE(0, function_index);
9464 DCHECK_GT(module->functions.size(), function_index);
9465 const i::wasm::WasmFunction& func = module->functions[function_index];
9466 DCHECK_GE(i::kMaxInt, func.code.offset());
9467 DCHECK_GE(i::kMaxInt, func.code.end_offset());
9468 return std::make_pair(static_cast<int>(func.code.offset()),
9469 static_cast<int>(func.code.end_offset()));
9472 uint32_t debug::WasmScript::GetFunctionHash(
int function_index) {
9475 DCHECK_EQ(i::Script::TYPE_WASM, script->type());
9477 i::WasmModuleObject::cast(script->wasm_module_object());
9478 const i::wasm::WasmModule* module = module_object->module();
9479 DCHECK_LE(0, function_index);
9480 DCHECK_GT(module->functions.size(), function_index);
9481 const i::wasm::WasmFunction& func = module->functions[function_index];
9482 i::wasm::ModuleWireBytes wire_bytes(
9483 module_object->native_module()->wire_bytes());
9486 return i::StringHasher::HashSequentialString(function_bytes.start(),
9487 function_bytes.length(), 0);
9490 debug::WasmDisassembly debug::WasmScript::DisassembleFunction(
9491 int function_index)
const {
9494 DCHECK_EQ(i::Script::TYPE_WASM, script->type());
9496 i::WasmModuleObject::cast(script->wasm_module_object());
9497 return module_object->DisassembleFunction(function_index);
9501 : line_number_(line_number),
9502 column_number_(column_number),
9506 : line_number_(
v8::
Function::kLineOffsetNotFound),
9507 column_number_(
v8::
Function::kLineOffsetNotFound),
9510 int debug::Location::GetLineNumber()
const {
9512 return line_number_;
9515 int debug::Location::GetColumnNumber()
const {
9517 return column_number_;
9520 bool debug::Location::IsEmpty()
const {
return is_empty_; }
9522 void debug::GetLoadedScripts(v8::Isolate* v8_isolate,
9523 PersistentValueVector<debug::Script>& scripts) {
9525 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9528 i::Script::Iterator iterator(isolate);
9530 while ((script = iterator.Next()) !=
nullptr) {
9531 if (!script->IsUserJavaScript())
continue;
9532 if (script->HasValidSource()) {
9535 scripts.Append(ToApiHandle<Script>(script_handle));
9541 MaybeLocal<UnboundScript> debug::CompileInspectorScript(Isolate* v8_isolate,
9542 Local<String> source) {
9544 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript);
9548 ScriptOriginOptions origin_options;
9551 i::Compiler::GetSharedFunctionInfoForScript(
9552 isolate, str, i::Compiler::ScriptDetails(), origin_options,
nullptr,
9553 script_data, ScriptCompiler::kNoCompileOptions,
9554 ScriptCompiler::kNoCacheBecauseInspector,
9555 i::FLAG_expose_inspector_scripts ? i::NOT_NATIVES_CODE
9556 : i::INSPECTOR_CODE);
9557 has_pending_exception = !maybe_function_info.ToHandle(&result);
9558 RETURN_ON_FAILED_EXECUTION(UnboundScript);
9560 RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
9563 void debug::SetDebugDelegate(Isolate* v8_isolate,
9564 debug::DebugDelegate* delegate) {
9566 isolate->debug()->SetDebugDelegate(delegate);
9569 void debug::SetAsyncEventDelegate(Isolate* v8_isolate,
9570 debug::AsyncEventDelegate* delegate) {
9571 reinterpret_cast<i::Isolate*
>(v8_isolate)->set_async_event_delegate(delegate);
9574 void debug::ResetBlackboxedStateCache(Isolate* v8_isolate,
9577 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9579 i::SharedFunctionInfo::ScriptIterator iter(isolate,
9580 *Utils::OpenHandle(*script));
9582 if (info->HasDebugInfo()) {
9583 info->GetDebugInfo()->set_computed_debug_is_blackboxed(
false);
9590 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9592 if (object->IsSmi())
return i::kPointerSize;
9593 CHECK(object->IsHeapObject());
9599 *is_key_value =
true;
9600 return Map::Cast(
this)->AsArray();
9603 *is_key_value =
false;
9604 return Set::Cast(
this)->AsArray();
9609 Isolate* v8_isolate =
reinterpret_cast<Isolate*
>(isolate);
9610 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9611 if (object->IsJSWeakCollection()) {
9612 *is_key_value =
object->IsJSWeakMap();
9613 return Utils::ToLocal(i::JSWeakCollection::GetEntries(
9616 if (object->IsJSMapIterator()) {
9619 MapAsArrayKind
const kind =
9620 static_cast<MapAsArrayKind
>(iterator->map()->instance_type());
9621 *is_key_value = kind == MapAsArrayKind::kEntries;
9623 return Utils::ToLocal(MapAsArray(isolate, iterator->table(),
9624 i::Smi::ToInt(iterator->index()), kind));
9626 if (object->IsJSSetIterator()) {
9628 *is_key_value =
false;
9630 return Utils::ToLocal(
9631 SetAsArray(isolate, it->table(), i::Smi::ToInt(it->index())));
9636 Local<Function> debug::GetBuiltin(Isolate* v8_isolate, Builtin builtin) {
9638 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9640 i::Builtins::Name builtin_id;
9642 case kStringToLowerCase:
9643 builtin_id = i::Builtins::kStringPrototypeToLocaleLowerCase;
9651 name, builtin_id, i::LanguageMode::kStrict);
9654 fun->shared()->set_internal_formal_parameter_count(0);
9655 fun->shared()->set_length(0);
9656 return Utils::ToLocal(handle_scope.CloseAndEscape(fun));
9659 void debug::SetConsoleDelegate(Isolate* v8_isolate, ConsoleDelegate* delegate) {
9661 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9662 isolate->set_console_delegate(delegate);
9665 debug::ConsoleCallArguments::ConsoleCallArguments(
9667 :
v8::FunctionCallbackInfo<
v8::
Value>(nullptr, info.values_, info.length_) {
9670 debug::ConsoleCallArguments::ConsoleCallArguments(
9671 internal::BuiltinArguments& args)
9675 args.address_of_arg_at(args.length() > 1 ? 1 : 0),
9676 args.length() - 1) {}
9679 return Utils::OpenHandle(*frame)->id();
9686 if (!error->IsJSObject()) {
9691 return Utils::StackTraceToLocal(stack_trace);
9694 MaybeLocal<debug::Script> debug::GeneratorObject::Script() {
9696 i::Object* maybe_script = obj->function()->shared()->script();
9697 if (!maybe_script->IsScript())
return MaybeLocal<debug::Script>();
9699 return ToApiHandle<debug::Script>(script);
9702 Local<Function> debug::GeneratorObject::Function() {
9704 return Utils::ToLocal(handle(obj->function(), obj->GetIsolate()));
9707 debug::Location debug::GeneratorObject::SuspendedLocation() {
9709 CHECK(obj->is_suspended());
9710 i::Object* maybe_script = obj->function()->shared()->script();
9711 if (!maybe_script->IsScript())
return debug::Location();
9713 i::Script::PositionInfo info;
9714 i::Script::GetPositionInfo(script, obj->source_position(), &info,
9715 i::Script::WITH_OFFSET);
9716 return debug::Location(info.line, info.column);
9719 bool debug::GeneratorObject::IsSuspended() {
9720 return Utils::OpenHandle(
this)->is_suspended();
9725 CHECK(value->IsGeneratorObject());
9726 return ToApiHandle<debug::GeneratorObject>(Utils::OpenHandle(*value));
9729 MaybeLocal<v8::Value> debug::EvaluateGlobal(v8::Isolate* isolate,
9731 bool throw_on_side_effect) {
9733 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(internal_isolate,
Value);
9734 Local<Value> result;
9735 has_pending_exception = !ToLocal<Value>(
9736 i::DebugEvaluate::Global(internal_isolate, Utils::OpenHandle(*source),
9737 throw_on_side_effect),
9739 RETURN_ON_FAILED_EXECUTION(
Value);
9740 RETURN_ESCAPED(result);
9744 QueryObjectPredicate* predicate,
9745 PersistentValueVector<v8::Object>* objects) {
9747 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
9748 isolate->heap_profiler()->QueryObjects(Utils::OpenHandle(*v8_context),
9749 predicate, objects);
9752 void debug::GlobalLexicalScopeNames(
9758 context->global_object()->native_context()->script_context_table(),
9760 for (
int i = 0;
i < table->used();
i++) {
9762 i::ScriptContextTable::GetContext(isolate, table,
i);
9763 DCHECK(context->IsScriptContext());
9765 int local_count = scope_info->ContextLocalCount();
9766 for (
int j = 0; j < local_count; ++j) {
9767 i::String name = scope_info->ContextLocalName(j);
9768 if (i::ScopeInfo::VariableIsSynthetic(name))
continue;
9769 names->
Append(Utils::ToLocal(handle(name, isolate)));
9774 void debug::SetReturnValue(v8::Isolate* v8_isolate,
9777 isolate->debug()->set_return_value(*Utils::OpenHandle(*value));
9780 int64_t debug::GetNextRandomInt64(v8::Isolate* v8_isolate) {
9781 return reinterpret_cast<i::Isolate*
>(v8_isolate)
9782 ->random_number_generator()
9788 if (!callable->IsJSFunction())
return i::DebugInfo::kNoDebuggingId;
9790 int id = func->GetIsolate()->debug()->GetFunctionDebuggingId(func);
9791 DCHECK_NE(i::DebugInfo::kNoDebuggingId,
id);
9799 if (!callable->IsJSFunction())
return false;
9802 i::Isolate* isolate = jsfunction->GetIsolate();
9804 condition.
IsEmpty() ? isolate->factory()->empty_string()
9805 : Utils::OpenHandle(*condition);
9806 return isolate->debug()->SetBreakpointForFunction(jsfunction,
9807 condition_string,
id);
9810 debug::PostponeInterruptsScope::PostponeInterruptsScope(v8::Isolate* isolate)
9812 new
i::PostponeInterruptsScope(reinterpret_cast<
i::Isolate*>(isolate),
9813 i::StackGuard::API_INTERRUPT)) {}
9815 debug::PostponeInterruptsScope::~PostponeInterruptsScope() =
default;
9822 isolate->factory()->InternalizeUtf8String(entry->name());
9823 return ToApiHandle<String>(name);
9826 int debug::Coverage::BlockData::StartOffset()
const {
return block_->start; }
9827 int debug::Coverage::BlockData::EndOffset()
const {
return block_->end; }
9828 uint32_t debug::Coverage::BlockData::Count()
const {
return block_->count; }
9830 int debug::Coverage::FunctionData::StartOffset()
const {
9831 return function_->start;
9833 int debug::Coverage::FunctionData::EndOffset()
const {
return function_->end; }
9834 uint32_t debug::Coverage::FunctionData::Count()
const {
9835 return function_->count;
9838 MaybeLocal<String> debug::Coverage::FunctionData::Name()
const {
9839 return ToApiHandle<String>(function_->name);
9842 size_t debug::Coverage::FunctionData::BlockCount()
const {
9843 return function_->blocks.size();
9846 bool debug::Coverage::FunctionData::HasBlockCoverage()
const {
9847 return function_->has_block_coverage;
9850 debug::Coverage::BlockData debug::Coverage::FunctionData::GetBlockData(
9852 return BlockData(&function_->blocks.at(
i), coverage_);
9855 Local<debug::Script> debug::Coverage::ScriptData::GetScript()
const {
9856 return ToApiHandle<debug::Script>(script_->script);
9859 size_t debug::Coverage::ScriptData::FunctionCount()
const {
9860 return script_->functions.size();
9863 debug::Coverage::FunctionData debug::Coverage::ScriptData::GetFunctionData(
9865 return FunctionData(&script_->functions.at(
i), coverage_);
9868 debug::Coverage::ScriptData::ScriptData(
size_t index,
9869 std::shared_ptr<i::Coverage> coverage)
9870 : script_(&coverage->at(index)), coverage_(
std::move(coverage)) {}
9872 size_t debug::Coverage::ScriptCount()
const {
return coverage_->size(); }
9874 debug::Coverage::ScriptData debug::Coverage::GetScriptData(
size_t i)
const {
9875 return ScriptData(
i, coverage_);
9878 debug::Coverage debug::Coverage::CollectPrecise(Isolate* isolate) {
9880 i::Coverage::CollectPrecise(reinterpret_cast<i::Isolate*>(isolate)));
9883 debug::Coverage debug::Coverage::CollectBestEffort(Isolate* isolate) {
9885 i::Coverage::CollectBestEffort(reinterpret_cast<i::Isolate*>(isolate)));
9888 void debug::Coverage::SelectMode(Isolate* isolate, debug::Coverage::Mode mode) {
9889 i::Coverage::SelectMode(reinterpret_cast<i::Isolate*>(isolate), mode);
9892 int debug::TypeProfile::Entry::SourcePosition()
const {
9893 return entry_->position;
9896 std::vector<MaybeLocal<String>> debug::TypeProfile::Entry::Types()
const {
9897 std::vector<MaybeLocal<String>> result;
9898 for (
const internal::Handle<internal::String>& type : entry_->types) {
9899 result.emplace_back(ToApiHandle<String>(type));
9904 debug::TypeProfile::ScriptData::ScriptData(
9905 size_t index, std::shared_ptr<i::TypeProfile> type_profile)
9906 : script_(&type_profile->at(index)),
9907 type_profile_(
std::move(type_profile)) {}
9909 Local<debug::Script> debug::TypeProfile::ScriptData::GetScript()
const {
9910 return ToApiHandle<debug::Script>(script_->script);
9913 std::vector<debug::TypeProfile::Entry> debug::TypeProfile::ScriptData::Entries()
9915 std::vector<debug::TypeProfile::Entry> result;
9916 for (
const internal::TypeProfileEntry& entry : script_->entries) {
9917 result.push_back(debug::TypeProfile::Entry(&entry, type_profile_));
9922 debug::TypeProfile debug::TypeProfile::Collect(Isolate* isolate) {
9924 i::TypeProfile::Collect(reinterpret_cast<i::Isolate*>(isolate)));
9927 void debug::TypeProfile::SelectMode(Isolate* isolate,
9928 debug::TypeProfile::Mode mode) {
9929 i::TypeProfile::SelectMode(reinterpret_cast<i::Isolate*>(isolate), mode);
9932 size_t debug::TypeProfile::ScriptCount()
const {
return type_profile_->size(); }
9934 debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData(
9936 return ScriptData(
i, type_profile_);
9941 PREPARE_FOR_EXECUTION(context, WeakMap, Get,
Value);
9942 auto self = Utils::OpenHandle(
this);
9943 Local<Value> result;
9945 has_pending_exception =
9946 !ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(),
self,
9947 arraysize(argv), argv),
9949 RETURN_ON_FAILED_EXECUTION(
Value);
9950 RETURN_ESCAPED(result);
9956 PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap);
9957 auto self = Utils::OpenHandle(
this);
9960 Utils::OpenHandle(*value)};
9961 has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(),
9962 self, arraysize(argv), argv)
9964 RETURN_ON_FAILED_EXECUTION(WeakMap);
9968 Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) {
9970 LOG_API(i_isolate, WeakMap, New);
9971 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
9973 return ToApiHandle<debug::WeakMap>(obj);
9976 debug::WeakMap* debug::WeakMap::Cast(
v8::Value* value) {
9977 return static_cast<debug::WeakMap*
>(value);
9982 return node->entry()->name();
9988 return entry->script_id();
9994 return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
9995 node->entry()->resource_name()));
10000 return node->entry()->resource_name();
10004 return reinterpret_cast<const i::ProfileNode*
>(
this)->line_number();
10010 entry()->column_number();
10016 return node->GetHitLineCount();
10021 unsigned int length)
const {
10023 return node->GetLineTicks(entries, length);
10029 return node->entry()->bailout_reason();
10034 return reinterpret_cast<const i::ProfileNode*
>(
this)->self_ticks();
10038 unsigned CpuProfileNode::GetCallUid()
const {
10039 return reinterpret_cast<const i::ProfileNode*
>(
this)->function_id();
10049 return static_cast<int>(
10050 reinterpret_cast<const i::ProfileNode*
>(
this)->children()->size());
10056 reinterpret_cast<const i::ProfileNode*
>(
this)->children()->at(index);
10063 return node->deopt_infos();
10070 DCHECK_NOT_NULL(profiler);
10071 profiler->DeleteProfile(profile);
10077 i::Isolate* isolate = profile->top_down()->isolate();
10078 return ToApiHandle<String>(isolate->factory()->InternalizeUtf8String(
10079 profile->title()));
10085 return reinterpret_cast<const CpuProfileNode*
>(profile->top_down()->root());
10091 return reinterpret_cast<const CpuProfileNode*
>(profile->sample(index));
10115 return reinterpret_cast<const i::CpuProfile*
>(
this)->samples_count();
10127 i::CpuProfiler::CollectSample(reinterpret_cast<i::Isolate*>(isolate));
10132 return reinterpret_cast<i::CpuProfiler*
>(
this)->set_sampling_interval(
10133 base::TimeDelta::FromMicroseconds(us));
10142 *Utils::OpenHandle(*title), record_samples, kLeafNodeLineNumbers);
10146 bool record_samples) {
10148 *Utils::OpenHandle(*title), record_samples, mode);
10154 *Utils::OpenHandle(*title)));
10158 void CpuProfiler::SetIdle(
bool is_idle) {
10161 isolate->SetIdle(is_idle);
10166 ->set_detailed_source_positions_for_profiling(
true);
10169 uintptr_t CodeEvent::GetCodeStartAddress() {
10170 return reinterpret_cast<i::CodeEvent*
>(
this)->code_start_address;
10173 size_t CodeEvent::GetCodeSize() {
10174 return reinterpret_cast<i::CodeEvent*
>(
this)->code_size;
10177 Local<String> CodeEvent::GetFunctionName() {
10178 return ToApiHandle<String>(
10179 reinterpret_cast<i::CodeEvent*
>(
this)->function_name);
10182 Local<String> CodeEvent::GetScriptName() {
10183 return ToApiHandle<String>(
10187 int CodeEvent::GetScriptLine() {
10188 return reinterpret_cast<i::CodeEvent*
>(
this)->script_line;
10191 int CodeEvent::GetScriptColumn() {
10192 return reinterpret_cast<i::CodeEvent*
>(
this)->script_column;
10196 return reinterpret_cast<i::CodeEvent*
>(
this)->code_type;
10199 const char* CodeEvent::GetComment() {
10200 return reinterpret_cast<i::CodeEvent*
>(
this)->comment;
10203 const char* CodeEvent::GetCodeEventTypeName(
CodeEventType code_event_type) {
10204 switch (code_event_type) {
10208 case k##Name##Type: \ 10210 CODE_EVENTS_LIST(
V)
10219 CodeEventHandler::CodeEventHandler(Isolate* isolate) {
10220 internal_listener_ =
10224 CodeEventHandler::~CodeEventHandler() {
10228 void CodeEventHandler::Enable() {
10230 ->StartListening(
this);
10233 void CodeEventHandler::Disable() {
10245 return static_cast<HeapGraphEdge::Type
>(ToInternal(
this)->type());
10252 switch (edge->type()) {
10253 case i::HeapGraphEdge::kContextVariable:
10254 case i::HeapGraphEdge::kInternal:
10255 case i::HeapGraphEdge::kProperty:
10256 case i::HeapGraphEdge::kShortcut:
10257 case i::HeapGraphEdge::kWeak:
10258 return ToApiHandle<String>(
10259 isolate->factory()->InternalizeUtf8String(edge->name()));
10260 case i::HeapGraphEdge::kElement:
10261 case i::HeapGraphEdge::kHidden:
10262 return ToApiHandle<Number>(
10263 isolate->factory()->NewNumberFromInt(edge->index()));
10264 default: UNREACHABLE();
10266 return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
10289 return static_cast<HeapGraphNode::Type
>(ToInternal(
this)->type());
10294 i::Isolate* isolate = ToInternal(
this)->isolate();
10295 return ToApiHandle<String>(
10296 isolate->factory()->InternalizeUtf8String(ToInternal(
this)->name()));
10301 return ToInternal(
this)->id();
10306 return ToInternal(
this)->self_size();
10311 return ToInternal(
this)->children_count();
10316 return reinterpret_cast<const HeapGraphEdge*
>(ToInternal(
this)->child(index));
10327 i::Isolate* isolate = ToInternal(
this)->profiler()->isolate();
10328 if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
10329 ToInternal(
this)->Delete();
10332 isolate->heap_profiler()->DeleteAllSnapshots();
10338 return reinterpret_cast<const HeapGraphNode*
>(ToInternal(
this)->root());
10344 ToInternal(
this)->GetEntryById(
id));
10349 return static_cast<int>(ToInternal(
this)->entries().size());
10355 &ToInternal(
this)->entries().at(index));
10360 return ToInternal(
this)->max_snapshot_js_object_id();
10365 HeapSnapshot::SerializationFormat format)
const {
10366 Utils::ApiCheck(format == kJSON,
10367 "v8::HeapSnapshot::Serialize",
10368 "Unknown serialization format");
10370 "v8::HeapSnapshot::Serialize",
10371 "Invalid stream chunk size");
10373 serializer.Serialize(stream);
10378 STATIC_CONST_MEMBER_DEFINITION
const SnapshotObjectId
10383 return reinterpret_cast<i::HeapProfiler*
>(
this)->GetSnapshotsCount();
10395 return reinterpret_cast<i::HeapProfiler*
>(
this)->GetSnapshotObjectId(obj);
10403 return Utils::ToLocal(obj);
10416 ->TakeSnapshot(control, resolver));
10422 track_allocations);
10434 return heap_profiler->PushHeapObjectsStats(stream, timestamp_us);
10439 SamplingFlags flags) {
10440 return reinterpret_cast<i::HeapProfiler*
>(
this)->StartSamplingHeapProfiler(
10441 sample_interval, stack_depth, flags);
10446 reinterpret_cast<i::HeapProfiler*
>(
this)->StopSamplingHeapProfiler();
10451 return reinterpret_cast<i::HeapProfiler*
>(
this)->GetAllocationProfile();
10459 void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id,
10460 WrapperInfoCallback callback) {
10461 reinterpret_cast<i::HeapProfiler*
>(
this)->DefineWrapperClass(class_id,
10465 void HeapProfiler::SetGetRetainerInfosCallback(
10466 GetRetainerInfosCallback callback) {
10467 reinterpret_cast<i::HeapProfiler*
>(
this)->SetGetRetainerInfosCallback(
10471 void HeapProfiler::SetBuildEmbedderGraphCallback(
10472 LegacyBuildEmbedderGraphCallback callback) {
10473 reinterpret_cast<i::HeapProfiler*
>(
this)->AddBuildEmbedderGraphCallback(
10475 reinterpret_cast<LegacyBuildEmbedderGraphCallback
>(data)(isolate,
10478 reinterpret_cast<void*
>(callback));
10481 void HeapProfiler::AddBuildEmbedderGraphCallback(
10482 BuildEmbedderGraphCallback callback,
void* data) {
10483 reinterpret_cast<i::HeapProfiler*
>(
this)->AddBuildEmbedderGraphCallback(
10487 void HeapProfiler::RemoveBuildEmbedderGraphCallback(
10488 BuildEmbedderGraphCallback callback,
void* data) {
10489 reinterpret_cast<i::HeapProfiler*
>(
this)->RemoveBuildEmbedderGraphCallback(
10493 v8::Testing::StressType internal::Testing::stress_type_ =
10494 v8::Testing::kStressTypeOpt;
10498 internal::Testing::set_stress_type(
type);
10503 if (internal::FLAG_stress_runs != 0)
return internal::FLAG_stress_runs;
10514 static void SetFlagsFromString(
const char* flags) {
10515 V8::SetFlagsFromString(flags, i::StrLength(flags));
10520 static const char* kLazyOptimizations =
10521 "--prepare-always-opt " 10522 "--max-inlined-bytecode-size=999999 " 10523 "--max-inlined-bytecode-size-cumulative=999999 " 10525 static const char* kForcedOptimizations =
"--always-opt";
10529 static const char* kDeoptEvery13Times =
"--deopt-every-n-times=13";
10530 if (internal::Testing::stress_type() == Testing::kStressTypeDeopt &&
10531 internal::FLAG_deopt_every_n_times == 0) {
10532 SetFlagsFromString(kDeoptEvery13Times);
10538 if (run == GetStressRuns() - 1) {
10539 SetFlagsFromString(kForcedOptimizations);
10541 SetFlagsFromString(kLazyOptimizations);
10544 if (run == GetStressRuns() - 1) {
10545 SetFlagsFromString(kForcedOptimizations);
10546 }
else if (run != GetStressRuns() - 2) {
10547 SetFlagsFromString(kLazyOptimizations);
10556 i::Deoptimizer::DeoptimizeAll(i_isolate);
10559 void EmbedderHeapTracer::FinalizeTracing() {
10562 if (isolate->heap()->incremental_marking()->IsMarking()) {
10563 isolate->heap()->FinalizeIncrementalMarkingAtomically(
10564 i::GarbageCollectionReason::kExternalFinalize);
10569 void EmbedderHeapTracer::GarbageCollectionForTesting(
10570 EmbedderStackState stack_state) {
10572 CHECK(i::FLAG_expose_gc);
10574 heap->SetEmbedderStackStateForNextFinalizaton(stack_state);
10575 heap->PreciseCollectAllGarbage(i::Heap::kNoGCFlags,
10576 i::GarbageCollectionReason::kTesting,
10577 kGCCallbackFlagForced);
10580 namespace internal {
10582 void HandleScopeImplementer::FreeThreadResources() {
10587 char* HandleScopeImplementer::ArchiveThread(
char* storage) {
10588 HandleScopeData* current = isolate_->handle_scope_data();
10589 handle_scope_data_ = *current;
10590 MemCopy(storage,
this,
sizeof(*
this));
10592 ResetAfterArchive();
10593 current->Initialize();
10595 return storage + ArchiveSpacePerThread();
10599 int HandleScopeImplementer::ArchiveSpacePerThread() {
10600 return sizeof(HandleScopeImplementer);
10604 char* HandleScopeImplementer::RestoreThread(
char* storage) {
10605 MemCopy(
this, storage,
sizeof(*
this));
10606 *isolate_->handle_scope_data() = handle_scope_data_;
10607 return storage + ArchiveSpacePerThread();
10610 void HandleScopeImplementer::IterateThis(RootVisitor* v) {
10612 bool found_block_before_deferred =
false;
10615 for (
int i = static_cast<int>(blocks()->size()) - 2;
i >= 0; --
i) {
10616 Address* block = blocks()->at(
i);
10619 if (last_handle_before_deferred_block_ !=
nullptr &&
10620 (reinterpret_cast<Address>(last_handle_before_deferred_block_) <=
10621 reinterpret_cast<Address>(&block[kHandleBlockSize])) &&
10622 (reinterpret_cast<Address>(last_handle_before_deferred_block_) >=
10623 reinterpret_cast<Address>(block))) {
10624 v->VisitRootPointers(Root::kHandleScope,
nullptr, ObjectSlot(block),
10625 ObjectSlot(last_handle_before_deferred_block_));
10626 DCHECK(!found_block_before_deferred);
10628 found_block_before_deferred =
true;
10631 v->VisitRootPointers(Root::kHandleScope,
nullptr, ObjectSlot(block),
10632 ObjectSlot(&block[kHandleBlockSize]));
10636 DCHECK(last_handle_before_deferred_block_ ==
nullptr ||
10637 found_block_before_deferred);
10640 if (!blocks()->empty()) {
10641 v->VisitRootPointers(Root::kHandleScope,
nullptr,
10642 ObjectSlot(blocks()->back()),
10643 ObjectSlot(handle_scope_data_.next));
10646 DetachableVector<Context>* context_lists[2] = {&saved_contexts_,
10647 &entered_contexts_};
10648 for (
unsigned i = 0;
i < arraysize(context_lists);
i++) {
10649 context_lists[
i]->shrink_to_fit();
10650 if (context_lists[
i]->empty())
continue;
10651 ObjectSlot start(&context_lists[
i]->front());
10652 v->VisitRootPointers(Root::kHandleScope,
nullptr, start,
10653 start + static_cast<int>(context_lists[
i]->size()));
10655 if (!microtask_context_.is_null()) {
10656 v->VisitRootPointer(Root::kHandleScope,
nullptr,
10657 ObjectSlot(µtask_context_));
10661 void HandleScopeImplementer::Iterate(RootVisitor* v) {
10662 HandleScopeData* current = isolate_->handle_scope_data();
10663 handle_scope_data_ = *current;
10667 char* HandleScopeImplementer::Iterate(RootVisitor* v,
char* storage) {
10668 HandleScopeImplementer* scope_implementer =
10669 reinterpret_cast<HandleScopeImplementer*
>(storage);
10670 scope_implementer->IterateThis(v);
10671 return storage + ArchiveSpacePerThread();
10674 DeferredHandles* HandleScopeImplementer::Detach(Address* prev_limit) {
10675 DeferredHandles* deferred =
10676 new DeferredHandles(isolate()->handle_scope_data()->next, isolate());
10678 while (!blocks_.empty()) {
10679 Address* block_start = blocks_.back();
10680 Address* block_limit = &block_start[kHandleBlockSize];
10682 DCHECK(prev_limit == block_limit ||
10683 !(block_start <= prev_limit && prev_limit <= block_limit));
10684 if (prev_limit == block_limit)
break;
10685 deferred->blocks_.push_back(blocks_.back());
10686 blocks_.pop_back();
10693 DCHECK(prev_limit ==
nullptr || !blocks_.empty());
10695 DCHECK(!blocks_.empty() && prev_limit !=
nullptr);
10696 DCHECK_NOT_NULL(last_handle_before_deferred_block_);
10697 last_handle_before_deferred_block_ =
nullptr;
10702 void HandleScopeImplementer::BeginDeferredScope() {
10703 DCHECK_NULL(last_handle_before_deferred_block_);
10704 last_handle_before_deferred_block_ = isolate()->handle_scope_data()->next;
10708 DeferredHandles::~DeferredHandles() {
10709 isolate_->UnlinkDeferredHandles(
this);
10711 for (
size_t i = 0;
i < blocks_.size();
i++) {
10712 #ifdef ENABLE_HANDLE_ZAPPING 10713 HandleScope::ZapRange(blocks_[
i], &blocks_[
i][kHandleBlockSize]);
10715 isolate_->handle_scope_implementer()->ReturnBlock(blocks_[
i]);
10719 void DeferredHandles::Iterate(RootVisitor* v) {
10720 DCHECK(!blocks_.empty());
10726 DCHECK((reinterpret_cast<Address>(first_block_limit_) >=
10727 reinterpret_cast<Address>(blocks_.front())) &&
10728 (
reinterpret_cast<Address
>(first_block_limit_) <=
10729 reinterpret_cast<Address>(&(blocks_.front())[kHandleBlockSize])));
10731 v->VisitRootPointers(Root::kHandleScope,
nullptr, ObjectSlot(blocks_.front()),
10732 ObjectSlot(first_block_limit_));
10734 for (
size_t i = 1;
i < blocks_.size();
i++) {
10735 v->VisitRootPointers(Root::kHandleScope,
nullptr, ObjectSlot(blocks_[
i]),
10736 ObjectSlot(&blocks_[
i][kHandleBlockSize]));
10741 void InvokeAccessorGetterCallback(
10744 v8::AccessorNameGetterCallback getter) {
10746 Isolate* isolate =
reinterpret_cast<Isolate*
>(info.
GetIsolate());
10747 RuntimeCallTimerScope timer(isolate,
10748 RuntimeCallCounterId::kAccessorGetterCallback);
10749 Address getter_address =
reinterpret_cast<Address
>(getter);
10750 VMState<EXTERNAL> state(isolate);
10751 ExternalCallbackScope call_scope(isolate, getter_address);
10752 getter(property, info);
10757 v8::FunctionCallback callback) {
10758 Isolate* isolate =
reinterpret_cast<Isolate*
>(info.
GetIsolate());
10759 RuntimeCallTimerScope timer(isolate,
10760 RuntimeCallCounterId::kInvokeFunctionCallback);
10761 Address callback_address =
reinterpret_cast<Address
>(callback);
10762 VMState<EXTERNAL> state(isolate);
10763 ExternalCallbackScope call_scope(isolate, callback_address);
10769 #undef ENTER_V8_DO_NOT_USE 10770 #undef ENTER_V8_HELPER_DO_NOT_USE 10771 #undef PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE 10772 #undef PREPARE_FOR_EXECUTION_WITH_CONTEXT 10773 #undef PREPARE_FOR_EXECUTION 10775 #undef ENTER_V8_NO_SCRIPT 10776 #undef ENTER_V8_NO_SCRIPT_NO_EXCEPTION 10777 #undef ENTER_V8_FOR_NEW_CONTEXT 10778 #undef EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE 10779 #undef RETURN_ON_FAILED_EXECUTION 10780 #undef RETURN_ON_FAILED_EXECUTION_PRIMITIVE 10781 #undef RETURN_TO_LOCAL_UNCHECKED 10782 #undef RETURN_ESCAPED 10783 #undef SET_FIELD_WRAPPED 10785 #undef CALLBACK_SETTER void TransferSharedArrayBuffer(uint32_t id, Local< SharedArrayBuffer > shared_array_buffer)
const HeapGraphNode * GetNodeById(SnapshotObjectId id) const
int GetSamplesCount() const
bool IsSetIterator() const
V8_WARN_UNUSED_RESULT Maybe< bool > HasOwnProperty(Local< Context > context, Local< Name > key)
static V8_WARN_UNUSED_RESULT MaybeLocal< Module > CompileModule(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
static V8_WARN_UNUSED_RESULT MaybeLocal< Resolver > New(Local< Context > context)
int64_t GetStartTime() const
static CachedData * CreateCodeCache(Local< UnboundScript > unbound_script)
bool StringEquals(Local< String > str)
V8_WARN_UNUSED_RESULT Maybe< bool > Resolve(Local< Context > context, Local< Value > value)
const HeapSnapshot * TakeHeapSnapshot(ActivityControl *control=nullptr, ObjectNameResolver *global_object_name_resolver=nullptr)
static V8_WARN_UNUSED_RESULT MaybeLocal< String > Stringify(Local< Context > context, Local< Value > json_object, Local< String > gap=Local< String >())
static Local< Set > New(Isolate *isolate)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > CallAsFunction(Local< Context > context, Local< Value > recv, int argc, Local< Value > argv[])
void SetTreatArrayBufferViewsAsHostObjects(bool mode)
static MaybeLocal< FunctionTemplate > FromSnapshot(Isolate *isolate, size_t index)
static Local< Symbol > New(Isolate *isolate, Local< String > name=Local< String >())
Local< Value > GetSourceURL()
bool IsMapIterator() const
void SetAlignedPointerInInternalField(int index, void *value)
bool only_terminate_in_safe_scope
const ExternalOneByteStringResource * GetExternalOneByteStringResource() const
bool IsNativeError() const
virtual bool SetBookmark()
virtual Maybe< uint32_t > GetSharedArrayBufferId(Isolate *isolate, Local< SharedArrayBuffer > shared_array_buffer)
int64_t GetEndTime() const
V8_WARN_UNUSED_RESULT Maybe< int > GetLineNumber(Local< Context > context) const
Local< String > GetScriptResourceName() const
Local< Value > GetPrototype()
virtual const uint16_t * data() const =0
Local< String > GetFunctionName() const
Local< String > GetName() const
Local< ArrayBuffer > Buffer()
void SetLazyDataProperty(Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
void SetInternalField(int index, Local< Value > value)
Local< Value > GetSourceMappingURL()
SnapshotObjectId GetId() const
int GetModuleRequestsLength() const
Local< Value > FindObjectById(SnapshotObjectId id)
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromOneByte(Isolate *isolate, const uint8_t *data, v8::NewStringType type, int length=-1)
static Local< Symbol > ForApi(Isolate *isolate, Local< String > name)
static Local< FunctionTemplate > NewWithCache(Isolate *isolate, FunctionCallback callback, Local< Private > cache_property, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewInstanceWithSideEffectType(Local< Context > context, int argc, Local< Value > argv[], SideEffectType side_effect_type=SideEffectType::kHasSideEffect) const
int GetScriptLineNumber() const
unsigned GetNodeId() const
V8_INLINE Local< T > Escape(Local< T > value)
static V8_WARN_UNUSED_RESULT MaybeLocal< Script > Compile(Local< Context > context, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
const CpuProfileNode * GetSample(int index) const
bool IsGeneratorFunction() const
BufferReference GetWasmWireBytesRef()
bool IsSharedCrossOrigin() const
const std::vector< CpuProfileDeoptInfo > & GetDeoptInfos() const
virtual MaybeLocal< SharedArrayBuffer > GetSharedArrayBufferFromId(Isolate *isolate, uint32_t clone_id)
static V8_INLINE Local< T > Cast(Local< S > that)
static int GetStressRuns()
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Run(Local< Context > context)
Local< String > GetScriptName() const
const HeapGraphNode * GetRoot() const
Local< StackTrace > GetStackTrace() const
SerializedModule Serialize()
void SetPrototypeProviderTemplate(Local< FunctionTemplate > prototype_provider)
static Local< SharedArrayBuffer > New(Isolate *isolate, size_t byte_length)
void SetSamplingInterval(int us)
void Inherit(Local< FunctionTemplate > parent)
Local< Array > AsArray() const
CodeEventType GetCodeType()
virtual void Free(void *data, size_t length)=0
uint64_t Uint64Value(bool *lossless=nullptr) const
Local< Script > BindToCurrentContext()
V8_WARN_UNUSED_RESULT MaybeLocal< Promise > Catch(Local< Context > context, Local< Function > handler)
Local< Value > GetName() const
void SetHiddenPrototype(bool value)
Local< StackFrame > GetFrame(Isolate *isolate, uint32_t index) const
const HeapGraphNode * GetFromNode() const
Maybe< bool > SetIntegrityLevel(Local< Context > context, IntegrityLevel level)
static CachedData * CreateCodeCacheForFunction(Local< Function > function)
void(* AccessorGetterCallback)(Local< String > property, const PropertyCallbackInfo< Value > &info)
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewExternalTwoByte(Isolate *isolate, ExternalStringResource *resource)
virtual void * ReallocateBufferMemory(void *old_buffer, size_t size, size_t *actual_size)
void SetClassName(Local< String > name)
V8_INLINE bool IsEmpty() const
Local< Context > CreationContext()
int GetChildrenCount() const
size_t ByteLength() const
bool IsModuleNamespaceObject() const
MaybeLocal< Array > PreviewEntries(bool *is_key_value)
V8_WARN_UNUSED_RESULT Maybe< bool > SetAccessor(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, MaybeLocal< Value > data=MaybeLocal< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
static Local< Array > New(Isolate *isolate, int length=0)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Evaluate(Local< Context > context)
void SetAccessCheckCallbackAndHandler(AccessCheckCallback callback, const NamedPropertyHandlerConfiguration &named_handler, const IndexedPropertyHandlerConfiguration &indexed_handler, Local< Value > data=Local< Value >())
void SetInternalFieldCount(int value)
V8_WARN_UNUSED_RESULT Maybe< bool > HasRealNamedProperty(Local< Context > context, Local< Name > key)
Local< String > GetTitle() const
V8_WARN_UNUSED_RESULT Maybe< bool > InstantiateModule(Local< Context > context, ResolveCallback callback)
Local< PrimitiveArray > GetHostDefinedOptions()
void SetCallHandler(FunctionCallback callback, Local< Value > data=Local< Value >(), SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
Local< String > GetModuleRequest(int i) const
void StartTrackingHeapObjects(bool track_allocations=false)
static MaybeLocal< WasmCompiledModule > DeserializeOrCompile(Isolate *isolate, BufferReference serialized_module, BufferReference wire_bytes)
V8_INLINE Isolate * GetIsolate() const
static MaybeLocal< Function > New(Local< Context > context, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
CpuProfile * StopProfiling(Local< String > title)
void StopTrackingHeapObjects()
V8_INLINE T FromJust() const
void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format)
Local< String > GetSource() const
const char * GetScriptResourceNameStr() const
Local< Value > GetDebugName() const
Local< ObjectTemplate > InstanceTemplate()
void SetExpectInlineWasm(bool allow_inline_wasm)
Isolate * GetIsolate() const
Local< Value > GetResourceName()
size_t ByteLength() const
V8_WARN_UNUSED_RESULT MaybeLocal< Uint32 > ToArrayIndex(Local< Context > context) const
bool(* AccessCheckCallback)(Local< Context > accessing_context, Local< Object > accessed_object, Local< Value > data)
virtual int GetChunkSize()
CreateHistogramCallback create_histogram_callback
static void DateTimeConfigurationChangeNotification(Isolate *isolate)
int GetFrameCount() const
static CpuProfiler * New(Isolate *isolate)
int GetLineNumber(int code_pos)
virtual const char * data() const =0
int GetStartColumn() const
void TransferArrayBuffer(uint32_t transfer_id, Local< ArrayBuffer > array_buffer)
bool HasIndexedLookupInterceptor()
StartupData * snapshot_blob
V8_WARN_UNUSED_RESULT Maybe< bool > SetPrototype(Local< Context > context, Local< Value > prototype)
virtual void FreeBufferMemory(void *buffer)
void SetAccessor(Local< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
static MaybeLocal< ObjectTemplate > FromSnapshot(Isolate *isolate, size_t index)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > CallAsConstructor(Local< Context > context, int argc, Local< Value > argv[])
Location GetModuleRequestLocation(int i) const
void SetHandler(const NamedPropertyHandlerConfiguration &configuration)
void StartProfiling(Local< String > title, CpuProfilingMode mode, bool record_samples=false)
virtual size_t length() const =0
V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t *value)
bool IsAsyncFunction() const
virtual MaybeLocal< Object > ReadHostObject(Isolate *isolate)
bool IsExternalOneByte() const
static V8_WARN_UNUSED_RESULT MaybeLocal< Script > Compile(Local< Context > context, Local< String > source, ScriptOrigin *origin=nullptr)
void SetLength(int length)
static uint32_t CachedDataVersionTag()
SnapshotObjectId GetObjectId(Local< Value > value)
CounterLookupCallback counter_lookup_callback
const HeapGraphNode * GetToNode() const
Local< Value > Name() const
bool MakeExternal(ExternalStringResource *resource)
void SetAcceptAnyReceiver(bool value)
static Local< ObjectTemplate > New(Isolate *isolate, Local< FunctionTemplate > constructor=Local< FunctionTemplate >())
int GetIdentityHash() const
V8_WARN_UNUSED_RESULT MaybeLocal< String > ObjectProtoToString(Local< Context > context)
static void CollectSample(Isolate *isolate)
uint32_t GetWireFormatVersion() const
int GetLineNumber() const
static Local< ArrayBuffer > New(Isolate *isolate, size_t byte_length)
unsigned GetHitCount() const
V8_INLINE Local< T > ToLocalChecked()
V8_WARN_UNUSED_RESULT Maybe< bool > ReadHeader(Local< Context > context)
const CpuProfileNode * GetTopDownRoot() const
virtual MaybeLocal< WasmCompiledModule > GetWasmModuleFromId(Isolate *isolate, uint32_t transfer_id)
const HeapGraphNode * GetNode(int index) const
Local< Array > AsArray() const
Local< Value > GetInferredName() const
static Local< Private > ForApi(Isolate *isolate, Local< String > name)
Local< UnboundModuleScript > GetUnboundModuleScript()
static Local< StackTrace > CurrentStackTrace(Isolate *isolate, int frame_limit, StackTraceOptions options=kDetailed)
int GetScriptColumnNumber() const
V8_WARN_UNUSED_RESULT MaybeLocal< Object > NewRemoteInstance()
static Local< Symbol > For(Isolate *isolate, Local< String > name)
Local< Value > GetBoundFunction() const
void SetNativeDataProperty(Local< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
Local< String > GetScriptNameOrSourceURL() const
static V8_WARN_UNUSED_RESULT MaybeLocal< RegExp > New(Local< Context > context, Local< String > pattern, Flags flags)
V8_WARN_UNUSED_RESULT Maybe< PropertyAttribute > GetPropertyAttributes(Local< Context > context, Local< Value > key)
Local< Value > GetModuleNamespace()
bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS *exception)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetRealNamedPropertyInPrototypeChain(Local< Context > context, Local< Name > key)
bool IsNeuterable() const
void MarkAsUndetectable()
virtual void ResetToBookmark()
AllocationProfile * GetAllocationProfile()
static Local< Private > New(Isolate *isolate, Local< String > name=Local< String >())
int GetLineNumber() const
static MaybeLocal< BigInt > NewFromWords(Local< Context > context, int sign_bit, int word_count, const uint64_t *words)
const intptr_t * external_references
V8_WARN_UNUSED_RESULT Maybe< bool > WriteValue(Local< Context > context, Local< Value > value)
int64_t GetSampleTimestamp(int index) const
const char * GetFunctionNameStr() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > ReadValue(Local< Context > context)
void Set(Local< Name > name, Local< Data > value, PropertyAttribute attributes=None)
int GetNodesCount() const
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromTwoByte(Isolate *isolate, const uint16_t *data, v8::NewStringType type, int length=-1)
int GetChildrenCount() const
bool HasNamedLookupInterceptor()
SnapshotObjectId GetMaxSnapshotJSObjectId() const
void Abort(MaybeLocal< Value > exception)
static V8_WARN_UNUSED_RESULT MaybeLocal< UnboundScript > CompileUnboundScript(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
void SetAccessCheckCallback(AccessCheckCallback callback, Local< Value > data=Local< Value >())
Maybe< bool > HasPrivate(Local< Context > context, Local< Private > key)
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
static void UseDetailedSourcePositionsForProfiling(Isolate *isolate)
Local< Object > FindInstanceInPrototypeChain(Local< FunctionTemplate > tmpl)
Local< Promise > GetPromise()
Local< Value > GetException() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetOwnPropertyDescriptor(Local< Context > context, Local< Name > key)
static MaybeLocal< Proxy > New(Local< Context > context, Local< Object > local_target, Local< Object > local_handler)
JitCodeEventHandler code_event_handler
const HeapSnapshot * GetHeapSnapshot(int index)
int64_t Int64Value(bool *lossless=nullptr) const
const char * GetBailoutReason() const
static void SetStressRunType(StressType type)
void DeleteAllHeapSnapshots()
bool IsSharedArrayBuffer() const
const CpuProfileNode * GetChild(int index) const
static MaybeLocal< WasmCompiledModule > FromTransferrableModule(Isolate *isolate, const TransferrableModule &)
void Append(Local< V > value)
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, v8::NewStringType type, int length=-1)
Local< Value > GetDisplayName() const
void Serialize(OutputStream *stream, SerializationFormat format=kJSON) const
size_t GetShallowSize() const
ArrayBuffer::Allocator * array_buffer_allocator
Local< UnboundScript > GetUnboundScript()
int GetColumnNumber() const
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
V8_WARN_UNUSED_RESULT Maybe< bool > Equals(Local< Context > context, Local< Value > that) const
Local< String > GetFunctionName() const
int GetStartPosition() const
bool IsArrayBufferView() const
int Utf8Length(Isolate *isolate) const
BackupIncumbentScope(Local< Context > backup_incumbent_context)
ScriptOrigin GetScriptOrigin() const
void StopSamplingHeapProfiler()
bool HasInstance(Local< Value > object)
bool GetLineTicks(LineTick *entries, unsigned int length) const
Local< String > GetConstructorName()
V8_WARN_UNUSED_RESULT Maybe< PropertyAttribute > GetRealNamedPropertyAttributes(Local< Context > context, Local< Name > key)
bool StartSamplingHeapProfiler(uint64_t sample_interval=512 *1024, int stack_depth=16, SamplingFlags flags=kSamplingNoFlags)
Local< Value > Name() const
static Local< Map > New(Isolate *isolate)
TransferrableModule GetTransferrableModule()
const HeapGraphEdge * GetChild(int index) const
V8_WARN_UNUSED_RESULT std::pair< uint8_t *, size_t > Release()
void SetIntrinsicDataProperty(Local< Name > name, Intrinsic intrinsic, PropertyAttribute attribute=None)
static bool GetStackSample(Isolate *isolate, v8::RegisterState *state, RecordCEntryFrame record_c_entry_frame, void **frames, size_t frames_limit, v8::SampleInfo *sample_info, bool use_simulator_reg_state=true)
V8_WARN_UNUSED_RESULT Maybe< bool > Has(Local< Context > context, Local< Value > key)
void WriteUint32(uint32_t value)
virtual Maybe< bool > WriteHostObject(Isolate *isolate, Local< Object > object)
unsigned int GetHitLineCount() const
bool IsArrayBuffer() const
static Allocator * NewDefaultAllocator()
Local< ObjectTemplate > PrototypeTemplate()
bool IsTypedArray() const
Local< Value > GetScriptResourceName() const
void ToWordsArray(int *sign_bit, int *word_count, uint64_t *words) const
void SetCallAsFunctionHandler(FunctionCallback callback, Local< Value > data=Local< Value >())
size_t CopyContents(void *dest, size_t byte_length)
bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t *info, void *context)
bool ContainsOnlyOneByte() const
void OnBytesReceived(const uint8_t *, size_t size)
V8_WARN_UNUSED_RESULT Maybe< PropertyAttribute > GetRealNamedPropertyAttributesInPrototypeChain(Local< Context > context, Local< Name > key)
static const SnapshotObjectId kUnknownObjectId
V8_INLINE Isolate * GetIsolate() const
static V8_WARN_UNUSED_RESULT MaybeLocal< Function > CompileFunctionInContext(Local< Context > context, Source *source, size_t arguments_count, Local< String > arguments[], size_t context_extension_count, Local< Object > context_extensions[], CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
ResourceConstraints constraints
bool IsConstructor() const
V8_WARN_UNUSED_RESULT Maybe< bool > SetLazyDataProperty(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
static Local< String > Concat(Isolate *isolate, Local< String > left, Local< String > right)
int GetEndPosition() const
static void DeoptimizeAll(Isolate *isolate)
V8_WARN_UNUSED_RESULT Maybe< bool > SetNativeDataProperty(Local< Context > context, Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attributes=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect)
static void PrepareStressRun(int run)
virtual size_t length() const =0
bool IsGeneratorObject() const
static ScriptStreamingTask * StartStreamingScript(Isolate *isolate, StreamedSource *source, CompileOptions options=kNoCompileOptions)
SnapshotObjectId GetHeapStats(OutputStream *stream, int64_t *timestamp_us=nullptr)
void TransferArrayBuffer(uint32_t transfer_id, Local< ArrayBuffer > array_buffer)
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetRealNamedProperty(Local< Context > context, Local< Name > key)