v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
api.cc File Reference
#include "src/api/api.h"
#include <algorithm>
#include <cmath>
#include <limits>
#include <optional>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include "include/v8-array-buffer.h"
#include "include/v8-callbacks.h"
#include "include/v8-cppgc.h"
#include "include/v8-date.h"
#include "include/v8-embedder-state-scope.h"
#include "include/v8-extension.h"
#include "include/v8-external-memory-accounter.h"
#include "include/v8-fast-api-calls.h"
#include "include/v8-function.h"
#include "include/v8-json.h"
#include "include/v8-locker.h"
#include "include/v8-primitive-object.h"
#include "include/v8-profiler.h"
#include "include/v8-source-location.h"
#include "include/v8-template.h"
#include "include/v8-unwinder-state.h"
#include "include/v8-util.h"
#include "include/v8-wasm.h"
#include "src/api/api-arguments.h"
#include "src/api/api-inl.h"
#include "src/api/api-natives.h"
#include "src/base/hashing.h"
#include "src/base/logging.h"
#include "src/base/numerics/safe_conversions.h"
#include "src/base/platform/memory.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
#include "src/base/utils/random-number-generator.h"
#include "src/base/vector.h"
#include "src/builtins/accessors.h"
#include "src/builtins/builtins-utils.h"
#include "src/codegen/compilation-cache.h"
#include "src/codegen/compiler.h"
#include "src/codegen/cpu-features.h"
#include "src/codegen/script-details.h"
#include "src/common/assert-scope.h"
#include "src/common/globals.h"
#include "src/compiler-dispatcher/lazy-compile-dispatcher.h"
#include "src/date/date.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/execution/embedder-state.h"
#include "src/execution/execution.h"
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/messages.h"
#include "src/execution/microtask-queue.h"
#include "src/execution/simulator.h"
#include "src/execution/v8threads.h"
#include "src/execution/vm-state-inl.h"
#include "src/handles/global-handles.h"
#include "src/handles/persistent-handles.h"
#include "src/handles/shared-object-conveyor-handles.h"
#include "src/handles/traced-handles-inl.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap-layout-inl.h"
#include "src/heap/heap-write-barrier.h"
#include "src/heap/safepoint.h"
#include "src/heap/visit-object.h"
#include "src/init/bootstrapper.h"
#include "src/init/icu_util.h"
#include "src/init/startup-data-util.h"
#include "src/init/v8.h"
#include "src/json/json-parser.h"
#include "src/json/json-stringifier.h"
#include "src/logging/counters-scopes.h"
#include "src/logging/metrics.h"
#include "src/logging/runtime-call-stats-scope.h"
#include "src/logging/tracing-flags.h"
#include "src/numbers/conversions-inl.h"
#include "src/objects/api-callbacks.h"
#include "src/objects/backing-store.h"
#include "src/objects/contexts.h"
#include "src/objects/embedder-data-array-inl.h"
#include "src/objects/embedder-data-slot-inl.h"
#include "src/objects/hash-table-inl.h"
#include "src/objects/heap-object.h"
#include "src/objects/instance-type-inl.h"
#include "src/objects/instance-type.h"
#include "src/objects/js-array-buffer-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-collection-inl.h"
#include "src/objects/js-objects.h"
#include "src/objects/js-promise-inl.h"
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-weak-refs-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/oddball.h"
#include "src/objects/ordered-hash-table-inl.h"
#include "src/objects/primitive-heap-object.h"
#include "src/objects/property-descriptor.h"
#include "src/objects/property-details.h"
#include "src/objects/property.h"
#include "src/objects/prototype.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/slots.h"
#include "src/objects/smi.h"
#include "src/objects/string.h"
#include "src/objects/synthetic-module-inl.h"
#include "src/objects/templates.h"
#include "src/objects/value-serializer.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parser.h"
#include "src/parsing/pending-compilation-error-handler.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/profiler/cpu-profiler.h"
#include "src/profiler/heap-profiler.h"
#include "src/profiler/heap-snapshot-generator-inl.h"
#include "src/profiler/profile-generator-inl.h"
#include "src/profiler/tick-sample.h"
#include "src/regexp/regexp-utils.h"
#include "src/roots/static-roots.h"
#include "src/runtime/runtime.h"
#include "src/sandbox/external-pointer.h"
#include "src/sandbox/isolate.h"
#include "src/sandbox/sandbox.h"
#include "src/snapshot/code-serializer.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/snapshot/snapshot.h"
#include "src/strings/char-predicates-inl.h"
#include "src/strings/string-hasher.h"
#include "src/strings/unicode-inl.h"
#include "src/tracing/trace-event.h"
#include "src/utils/detachable-vector.h"
#include "src/utils/identity-map.h"
#include "src/utils/version.h"
#include "src/api/api-macros.h"
#include "src/api/api-macros-undef.h"

Go to the source code of this file.

Classes

struct  v8::ValueSerializer::PrivateData
 
struct  v8::ValueDeserializer::PrivateData
 
struct  v8::PropertyDescriptor::PrivateData
 
struct  v8::OneByteMask< 4 >
 
struct  v8::OneByteMask< 8 >
 
class  v8::ContainsOnlyOneByteHelper
 
struct  v8::InvokeBootstrapper< i::NativeContext >
 
struct  v8::InvokeBootstrapper< i::JSGlobalProxy >
 
class  v8::WasmStreaming::WasmStreamingImpl
 

Namespaces

namespace  v8
 
namespace  v8::internal
 
namespace  v8::api_internal
 

Macros

#define SET_FIELD_WRAPPED(i_isolate, obj, setter, cdata, tag)
 
#define SET_CALLBACK_FIELD(Name, name)
 
#define VALUE_IS_TYPED_ARRAY(Type, typeName, TYPE, ctype)
 
#define VALUE_IS_SPECIFIC_TYPE(Type, Check)
 
#define CHECK_TYPED_ARRAY_CAST(Type, typeName, TYPE, ctype)
 
#define NEW_STRING(v8_isolate, class_name, function_name, Char, data, type, length)
 
#define TIME_ZONE_DETECTION_ASSERT_EQ(value)
 
#define REGEXP_FLAG_ASSERT_EQ(flag)
 
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype)
 
#define TYPED_ARRAY_NEW(Type, type, TYPE, ctype)
 
#define WELL_KNOWN_SYMBOLS(V)
 
#define SYMBOL_GETTER(Name, name)
 
#define CALLBACK_SETTER(ExternalName, Type, InternalName)
 
#define DEFINE_ERROR(NAME, name)
 
#define V(Name)
 

Enumerations

enum class  v8::internal::FastIterateResult { v8::internal::kException = static_cast<int>(v8::Array::CallbackResult::kException) , v8::internal::kBreak = static_cast<int>(v8::Array::CallbackResult::kBreak) , v8::internal::kSlowPath , v8::internal::kFinished }
 

Functions

static ScriptOrigin v8::GetScriptOriginForScript (i::Isolate *i_isolate, i::DirectHandle< i::Script > script)
 
void v8::RegisterExtension (std::unique_ptr< Extension > extension)
 
void v8::internal::VerifyHandleIsNonEmpty (bool is_empty)
 
i::Addressv8::internal::GlobalizeTracedReference (i::Isolate *i_isolate, i::Address value, internal::Address *slot, TracedReferenceStoreMode store_mode, TracedReferenceHandling reference_handling)
 
void v8::internal::MoveTracedReference (internal::Address **from, internal::Address **to)
 
void v8::internal::CopyTracedReference (const internal::Address *const *from, internal::Address **to)
 
void v8::internal::DisposeTracedReference (internal::Address *location)
 
i::Addressv8::api_internal::GlobalizeReference (i::Isolate *i_isolate, i::Address value)
 
i::Addressv8::api_internal::CopyGlobalReference (i::Address *from)
 
void v8::api_internal::MoveGlobalReference (internal::Address **from, internal::Address **to)
 
void v8::api_internal::MakeWeak (i::Address *location, void *parameter, WeakCallbackInfo< void >::Callback weak_callback, WeakCallbackType type)
 
void v8::api_internal::MakeWeak (i::Address **location_addr)
 
void * v8::api_internal::ClearWeak (i::Address *location)
 
void v8::api_internal::AnnotateStrongRetainer (i::Address *location, const char *label)
 
void v8::api_internal::DisposeGlobal (i::Address *location)
 
i::Addressv8::api_internal::Eternalize (Isolate *v8_isolate, Value *value)
 
void v8::api_internal::FromJustIsNothing ()
 
void v8::api_internal::ToLocalEmpty ()
 
void v8::api_internal::InternalFieldOutOfBounds (int index)
 
static i::DirectHandle< i::EmbedderDataArrayv8::EmbedderDataFor (Context *context, int index, bool can_grow, const char *location)
 
i::Address v8::api_internal::ConvertToJSGlobalProxyIfNecessary (i::Address holder_ptr)
 
template<typename Getter , typename Setter , typename Data >
static Maybe< bool > v8::ObjectSetAccessor (Local< Context > context, Object *self, Local< Name > name, Getter getter, Setter setter, Data data, PropertyAttribute attributes, bool replace_on_access, SideEffectType getter_side_effect_type, SideEffectType setter_side_effect_type)
 
static bool v8::Unaligned (const uint16_t *chars)
 
static const uint16_t * v8::Align (const uint16_t *chars)
 
template<typename CharType >
static int v8::WriteHelper (i::Isolate *i_isolate, const String *string, CharType *buffer, int start, int length, int options)
 
template<typename CharType >
static void v8::WriteHelperV2 (i::Isolate *i_isolate, const String *string, CharType *buffer, uint32_t offset, uint32_t length, int flags)
 
static V8_INLINE bool v8::InternalFieldOK (i::DirectHandle< i::JSReceiver > obj, int index, const char *location)
 
template<typename ObjectType >
static i::DirectHandle< ObjectType > v8::CreateEnvironment (i::Isolate *i_isolate, v8::ExtensionConfiguration *extensions, v8::MaybeLocal< ObjectTemplate > maybe_global_template, v8::MaybeLocal< Value > maybe_global_proxy, size_t context_snapshot_index, i::DeserializeEmbedderFieldsCallback embedder_fields_deserializer, v8::MicrotaskQueue *microtask_queue)
 
Local< Contextv8::NewContext (v8::Isolate *external_isolate, v8::ExtensionConfiguration *extensions, v8::MaybeLocal< ObjectTemplate > global_template, v8::MaybeLocal< Value > global_object, size_t context_snapshot_index, i::DeserializeEmbedderFieldsCallback embedder_fields_deserializer, v8::MicrotaskQueue *microtask_queue)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kNone)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kGlobal)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kIgnoreCase)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kMultiline)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kSticky)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kUnicode)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kHasIndices)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kLinear)
 
 v8::REGEXP_FLAG_ASSERT_EQ (kUnicodeSets)
 
uint32_t v8::internal::GetLength (Tagged< JSArray > array)
 
bool v8::internal::CanUseFastIteration (Isolate *isolate, DirectHandle< JSArray > array)
 
FastIterateResult v8::internal::FastIterateArray (DirectHandle< JSArray > array, Isolate *isolate, v8::Array::IterationCallback callback, void *callback_data)
 
static void v8::CallGCCallbackWithoutData (Isolate *v8_isolate, GCType type, GCCallbackFlags flags, void *data)
 
 v8::CALLBACK_SETTER (ModifyCodeGenerationFromStringsCallback, ModifyCodeGenerationFromStringsCallback2, modify_code_gen_callback) CALLBACK_SETTER(AllowWasmCodeGenerationCallback
 
allow_wasm_code_gen_callback v8::CALLBACK_SETTER (WasmStreamingCallback, WasmStreamingCallback, wasm_streaming_callback) CALLBACK_SETTER(WasmAsyncResolvePromiseCallback
 
allow_wasm_code_gen_callback wasm_async_resolve_promise_callback v8::CALLBACK_SETTER (WasmLoadSourceMapCallback, WasmLoadSourceMapCallback, wasm_load_source_map_callback) CALLBACK_SETTER(WasmImportedStringsEnabledCallback
 
allow_wasm_code_gen_callback wasm_async_resolve_promise_callback wasm_imported_strings_enabled_callback v8::CALLBACK_SETTER (WasmJSPIEnabledCallback, WasmJSPIEnabledCallback, wasm_jspi_enabled_callback) CALLBACK_SETTER(SharedArrayBufferConstructorEnabledCallback
 
allow_wasm_code_gen_callback wasm_async_resolve_promise_callback wasm_imported_strings_enabled_callback sharedarraybuffer_constructor_enabled_callback v8::CALLBACK_SETTER (JavaScriptCompileHintsMagicEnabledCallback, JavaScriptCompileHintsMagicEnabledCallback, compile_hints_magic_enabled_callback) CALLBACK_SETTER(IsJSApiWrapperNativeErrorCallback
 
static i::CpuProfilev8::ToInternal (const CpuProfile *profile)
 
static i::HeapGraphEdgev8::ToInternal (const HeapGraphEdge *edge)
 
static i::HeapEntryv8::ToInternal (const HeapGraphNode *entry)
 
static i::HeapSnapshotv8::ToInternal (const HeapSnapshot *snapshot)
 
V8_EXPORT v8::Local< v8::Valuev8::api_internal::GetFunctionTemplateData (v8::Isolate *isolate, v8::Local< v8::Data > raw_target)
 
void v8::internal::InvokeAccessorGetterCallback (v8::Local< v8::Name > property, const v8::PropertyCallbackInfo< v8::Value > &info)
 
void v8::internal::InvokeFunctionCallbackGeneric (const v8::FunctionCallbackInfo< v8::Value > &info)
 
void v8::internal::InvokeFunctionCallbackOptimized (const v8::FunctionCallbackInfo< v8::Value > &info)
 
void v8::internal::InvokeFinalizationRegistryCleanupFromTask (DirectHandle< NativeContext > native_context, DirectHandle< JSFinalizationRegistry > finalization_registry)
 
template<>
int32_t v8::internal::ConvertDouble (double d)
 
template<>
uint32_t v8::internal::ConvertDouble (double d)
 
template<>
float v8::internal::ConvertDouble (double d)
 
template<>
double v8::internal::ConvertDouble (double d)
 
template<>
int64_t v8::internal::ConvertDouble (double d)
 
template<>
uint64_t v8::internal::ConvertDouble (double d)
 
template<>
bool v8::internal::ConvertDouble (double d)
 
template<typename T >
bool v8::internal::ValidateFunctionCallbackInfo (const FunctionCallbackInfo< T > &info)
 
template<typename T >
bool v8::internal::ValidatePropertyCallbackInfo (const PropertyCallbackInfo< T > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const FunctionCallbackInfo< void > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const FunctionCallbackInfo< v8::Value > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const PropertyCallbackInfo< v8::Value > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const PropertyCallbackInfo< v8::Array > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const PropertyCallbackInfo< v8::Boolean > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const PropertyCallbackInfo< v8::Integer > &info)
 
template<>
bool V8_EXPORT v8::internal::ValidateCallbackInfo (const PropertyCallbackInfo< void > &info)
 

Variables

static OOMErrorCallback v8::g_oom_error_callback = nullptr
 
static const uintptr_t v8::kOneByteMask = OneByteMask<sizeof(uintptr_t)>::value
 
static const uintptr_t v8::kAlignmentMask = sizeof(uintptr_t) - 1
 

Macro Definition Documentation

◆ CALLBACK_SETTER

#define CALLBACK_SETTER ( ExternalName,
Type,
InternalName )
Value:
void Isolate::Set##ExternalName(Type callback) { \
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this); \
i_isolate->set_##InternalName(callback); \
}
TNode< Object > callback

Definition at line 10745 of file api.cc.

◆ CHECK_TYPED_ARRAY_CAST

#define CHECK_TYPED_ARRAY_CAST ( Type,
typeName,
TYPE,
ctype )
Value:
void v8::Type##Array::CheckCast(Value* that) { \
auto obj = *Utils::OpenDirectHandle(that); \
Utils::ApiCheck( \
i::IsJSTypedArray(obj) && i::Cast<i::JSTypedArray>(obj)->type() == \
i::kExternal##Type##Array, \
"v8::" #Type "Array::Cast()", "Value is not a " #Type "Array"); \
}
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
wasm::ValueType type

Definition at line 4080 of file api.cc.

◆ DEFINE_ERROR

#define DEFINE_ERROR ( NAME,
name )
Value:
Local<Value> Exception::NAME(v8::Local<v8::String> raw_message, \
v8::Local<v8::Value> raw_options) { \
i::Isolate* i_isolate = i::Isolate::Current(); \
API_RCS_SCOPE(i_isolate, NAME, New); \
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); \
{ \
i::HandleScope scope(i_isolate); \
if (!raw_options.IsEmpty()) { \
options = Utils::OpenDirectHandle(*raw_options); \
} \
auto message = Utils::OpenDirectHandle(*raw_message); \
i_isolate->name##_function(); \
error = *i_isolate->factory()->NewError(constructor, message, options); \
} \
return Utils::ToLocal(i::direct_handle(error, i_isolate)); \
}
Handle< JSObject > NewError(DirectHandle< JSFunction > constructor, DirectHandle< String > message, DirectHandle< Object > options={})
Definition factory.cc:2799
v8::internal::Factory * factory()
Definition isolate.h:1527
DirectHandle< JSReceiver > options
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
#define NAME(feat,...)

Definition at line 11109 of file api.cc.

◆ NEW_STRING

#define NEW_STRING ( v8_isolate,
class_name,
function_name,
Char,
data,
type,
length )
Value:
MaybeLocal<String> result; \
if (length == 0) { \
result = String::Empty(v8_isolate); \
} else if (length > 0 && \
static_cast<uint32_t>(length) > i::String::kMaxLength) { \
result = MaybeLocal<String>(); \
} else { \
i::Isolate* i_isolate = reinterpret_cast<internal::Isolate*>(v8_isolate); \
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); \
API_RCS_SCOPE(i_isolate, class_name, function_name); \
if (length < 0) length = StringLength(data); \
i::DirectHandle<i::String> handle_result = \
NewString(i_isolate->factory(), type, \
base::Vector<const Char>(data, length)) \
.ToHandleChecked(); \
result = Utils::ToLocal(handle_result); \
}
ZoneVector< RpoNumber > & result

Definition at line 7559 of file api.cc.

◆ REGEXP_FLAG_ASSERT_EQ

#define REGEXP_FLAG_ASSERT_EQ ( flag)
Value:
static_assert(static_cast<int>(v8::RegExp::flag) == \
static_cast<int>(i::JSRegExp::flag))

Definition at line 8079 of file api.cc.

◆ SET_CALLBACK_FIELD

#define SET_CALLBACK_FIELD ( Name,
name )
Value:
if (name != nullptr) { \
if constexpr (property_type == PropertyType::kNamed) { \
obj->set_named_##name(i_isolate, reinterpret_cast<i::Address>(name)); \
} else { \
obj->set_indexed_##name(i_isolate, reinterpret_cast<i::Address>(name)); \
} \
}
const char * name
Definition builtins.cc:39

◆ SET_FIELD_WRAPPED

#define SET_FIELD_WRAPPED ( i_isolate,
obj,
setter,
cdata,
tag )
Value:
do { \
FromCData<tag>(i_isolate, cdata); \
(obj)->setter(*foreign); \
} while (false)
PropertyT * setter

Definition at line 1209 of file api.cc.

◆ SYMBOL_GETTER

#define SYMBOL_GETTER ( Name,
name )
Value:
Local<Symbol> v8::Symbol::Get##Name(Isolate* v8_isolate) { \
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(v8_isolate); \
return Utils::ToLocal(i_isolate->factory()->name##_symbol()); \
}

Definition at line 9527 of file api.cc.

◆ TIME_ZONE_DETECTION_ASSERT_EQ

#define TIME_ZONE_DETECTION_ASSERT_EQ ( value)
Value:
static_assert( \
static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
static_cast<int>(base::TimezoneCache::TimeZoneDetection::value));

Definition at line 8033 of file api.cc.

◆ TYPED_ARRAY_CASE

#define TYPED_ARRAY_CASE ( Type,
type,
TYPE,
ctype )
Value:
case TYPE##_ELEMENTS:

◆ TYPED_ARRAY_NEW

#define TYPED_ARRAY_NEW ( Type,
type,
TYPE,
ctype )

Definition at line 9275 of file api.cc.

◆ V

#define V ( Name)
Value:
case k##Name##Type: \
return #Name;

◆ VALUE_IS_SPECIFIC_TYPE

#define VALUE_IS_SPECIFIC_TYPE ( Type,
Check )
Value:
bool Value::Is##Type() const { \
return i::Is##Check(*Utils::OpenDirectHandle(this)); \
}
bool Is(IndirectHandle< U > value)
Definition handles-inl.h:51

Definition at line 3588 of file api.cc.

◆ VALUE_IS_TYPED_ARRAY

#define VALUE_IS_TYPED_ARRAY ( Type,
typeName,
TYPE,
ctype )
Value:
bool Value::Is##Type##Array() const { \
auto obj = *Utils::OpenDirectHandle(this); \
return i::IsJSTypedArray(obj) && \
i::Cast<i::JSTypedArray>(obj)->type() == i::kExternal##Type##Array; \
}

Definition at line 3543 of file api.cc.

◆ WELL_KNOWN_SYMBOLS

#define WELL_KNOWN_SYMBOLS ( V)
Value:
V(AsyncIterator, async_iterator) \
V(HasInstance, has_instance) \
V(IsConcatSpreadable, is_concat_spreadable) \
V(Iterator, iterator) \
V(Match, match) \
V(Replace, replace) \
V(Search, search) \
V(Split, split) \
V(ToPrimitive, to_primitive) \
V(ToStringTag, to_string_tag) \
V(Unscopables, unscopables) \
V(Dispose, dispose) \
V(AsyncDispose, async_dispose)
#define V(Name)

Definition at line 9512 of file api.cc.