Expand description
§Example
use rusty_v8 as v8;
let platform = v8::new_default_platform(0, false).make_shared();
v8::V8::initialize_platform(platform);
v8::V8::initialize();
let isolate = &mut v8::Isolate::new(Default::default());
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
let code = v8::String::new(scope, "'Hello' + ' World!'").unwrap();
println!("javascript code: {}", code.to_rust_string_lossy(scope));
let script = v8::Script::compile(scope, code, None).unwrap();
let result = script.run(scope).unwrap();
let result = result.to_string(scope).unwrap();
println!("result: {}", result.to_rust_string_lossy(scope));
Re-exports§
pub use script_compiler::CachedData;
Modules§
- V8
- icu
- inspector
- Bindings to the V8 Inspector API. Documentation for the V8 inspector API is very sparse, so here are a few references for the next sorry soul who has to dig into it.
- json
- A JSON Parser and Stringifier.
- script_
compiler
Structs§
- Accessor
Signature - An AccessorSignature specifies which receivers are valid parameters to an accessor callback.
- Allocator
- A thread-safe allocator that V8 uses to allocate |ArrayBuffer|’s memory. The allocator is a global V8 setting. It has to be set via Isolate::CreateParams.
- Array
- An instance of the built-in array constructor (ECMA-262, 15.4.2).
- Array
Buffer - An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
- Array
Buffer View - A base class for an instance of one of “views” over ArrayBuffer, including TypedArrays and DataView (ES6 draft 15.13).
- Backing
Store - A wrapper around the backing store (i.e. the raw memory) of an array buffer. See a document linked in http://crbug.com/v8/9908 for more information.
- BigInt
- A JavaScript BigInt value (https://tc39.github.io/proposal-bigint)
- BigInt64
Array - An instance of BigInt64Array constructor.
- BigInt
Object - A BigInt object (https://tc39.github.io/proposal-bigint)
- BigUint64
Array - An instance of BigUint64Array constructor.
- Boolean
- A primitive boolean value (ECMA-262, 4.3.14). Either the true or false value.
- Boolean
Object - A Boolean object (ECMA-262, 4.3.15).
- Callback
Scope - A
CallbackScope
can be used to bootstrap aHandleScope
andContextScope
inside a callback function that gets called by V8. Bootstrapping a scope inside a callback is the only valid use case of this type; using it in other places leads to undefined behavior, which is also the reasonCallbackScope::new()
is marked as being an unsafe function. - Compiled
Wasm Module - Wrapper around a compiled WebAssembly module, which is potentially shared by different WasmModuleObjects.
- Context
- A sandboxed execution context with its own set of built-in objects and functions.
- Context
Scope - Stack-allocated class which sets the execution context for all operations executed within a local scope. After entering a context, all code compiled and run is compiled and run in this context.
- Create
Params - Initial configuration parameters for a new Isolate.
- Data
- The superclass of objects that can reside on V8’s heap.
- Data
View - An instance of DataView constructor (ES6 draft 15.13.7).
- Date
- An instance of the built-in Date constructor (ECMA-262, 15.9).
- Escapable
Handle Scope - A HandleScope which first allocates a handle in the current scope which will be later filled with the escape value.
- Exception
- Create new error objects by calling the corresponding error object constructor with the message.
- External
- A JavaScript value that wraps a C++ void*. This type of value is mainly used to associate C++ data structures with JavaScript objects.
- External
References - Fixed
Array - A fixed-sized array with elements of type Data.
- Float32
Array - An instance of Float32Array constructor (ES6 draft 15.13.6).
- Float64
Array - An instance of Float64Array constructor (ES6 draft 15.13.6).
- Function
- A JavaScript function object (ECMA-262, 15.3).
- Function
Builder - A builder to construct the properties of a Function or FunctionTemplate.
- Function
Callback Arguments - Function
Callback Info - The argument information given to function call callbacks. This class provides access to information about the context of the call, including the receiver, the number and values of arguments, and the holder of the function.
- Function
Template - A FunctionTemplate is used to create functions at runtime. There can only be one function created from a FunctionTemplate in a context. The lifetime of the created function is equal to the lifetime of the context. So in case the embedder needs to create temporary functions that can be collected using Scripts is preferred.
- Global
- An object reference that is independent of any handle scope. Where a Local handle only lives as long as the HandleScope in which it was allocated, a global handle remains valid until it is explicitly disposed using reset().
- Handle
Scope - A stack-allocated class that governs a number of local handles. After a handle scope has been created, all local handles will be allocated within that handle scope until either the handle scope is deleted or another handle scope is created. If there is already a handle scope and a new one is created, all allocations will take place in the new handle scope until it is deleted. After that, new handles will again be allocated in the original handle scope.
- Heap
Statistics - Collection of V8 heap information.
- Int8
Array - An instance of Int8Array constructor (ES6 draft 15.13.6).
- Int32
- A JavaScript value representing a 32-bit signed integer.
- Int16
Array - An instance of Int16Array constructor (ES6 draft 15.13.6).
- Int32
Array - An instance of Int32Array constructor (ES6 draft 15.13.6).
- Integer
- A JavaScript value representing a signed integer.
- Isolate
- Isolate represents an isolated instance of the V8 engine. V8 isolates have completely separate states. Objects from one isolate must not be used in other isolates. The embedder can create multiple isolates and use them in parallel in multiple threads. An isolate can be entered by at most one thread at any given time. The Locker/Unlocker API must be used to synchronize.
- Isolate
Handle - IsolateHandle is a thread-safe reference to an Isolate. It’s main use is to terminate execution of a running isolate from another thread.
- Local
- An object reference managed by the v8 garbage collector.
- Location
- A location in JavaScript source.
- Map
- An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1).
- Message
- An error message.
- Module
- A compiled JavaScript module.
- Module
Request - Name
- A superclass for symbols and strings.
- Number
- A JavaScript number value (ECMA-262, 4.3.20)
- Number
Object - A Number object (ECMA-262, 4.3.21).
- Object
- A JavaScript object (ECMA-262, 4.3.3)
- Object
Template - An ObjectTemplate is used to create objects at runtime.
- Owned
Isolate - Same as Isolate but gets disposed when it goes out of scope.
- Platform
- Primitive
- The superclass of primitive values. See ECMA-262 4.3.2.
- Primitive
Array - An array to hold Primitive values. This is used by the embedder to pass host defined options to the ScriptOptions during compilation.
- Private
- A private symbol
- Promise
- An instance of the built-in Promise constructor (ES6 draft).
- Promise
Reject Message - Promise
Resolver - Property
Attribute - Property
Callback Arguments - Property
Callback Info - The information passed to a property callback about the context of the property access.
- Proxy
- An instance of the built-in Proxy constructor (ECMA-262, 6th Edition, 26.2.1).
- RegExp
- An instance of the built-in RegExp constructor (ECMA-262, 15.10).
- Return
Value - Rust
Allocator Vtable - A wrapper around the V8 Allocator class.
- Script
- A compiled JavaScript script, tied to a Context which was active when the script was compiled.
- Script
OrModule - A container type that holds relevant metadata for module loading.
- Script
Origin - The origin, within a file, of a script.
- Set
- An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1).
- Shared
Array Buffer - An instance of the built-in SharedArrayBuffer constructor.
- Shared
Ptr - Wrapper around a C++ shared_ptr. A shared_ptr may be be null.
- Shared
Ref - Wrapper around a C++ shared_ptr. The shared_ptr is assumed to contain a value and may not be null.
- Signature
- A Signature specifies which receiver is valid for a function.
- Snapshot
Creator - Helper class to create a snapshot data blob.
- Stack
Frame - A single JavaScript stack frame.
- Stack
Trace - Representation of a JavaScript stack trace. The information collected is a snapshot of the execution stack and the information remains valid after execution continues.
- Startup
Data - String
- A JavaScript string value (ECMA-262, 4.3.17).
- String
Object - A String object (ECMA-262, 4.3.18).
- Symbol
- A JavaScript symbol (ECMA-262 edition 6)
- Symbol
Object - A Symbol object (ECMA-262 edition 6).
- Template
- The superclass of object and function templates.
- TryCatch
- An external exception handler.
- Typed
Array - A base class for an instance of TypedArray series of constructors (ES6 draft 15.13.6).
- Uint8
Array - An instance of Uint8Array constructor (ES6 draft 15.13.6).
- Uint8
Clamped Array - An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
- Uint32
- A JavaScript value representing a 32-bit unsigned integer.
- Uint16
Array - An instance of Uint16Array constructor (ES6 draft 15.13.6).
- Uint32
Array - An instance of Uint32Array constructor (ES6 draft 15.13.6).
- Unbound
Module Script - A compiled JavaScript module, not yet tied to a Context.
- Unbound
Script - A compiled JavaScript script, not yet tied to a Context.
- Unique
Ptr - Pointer to object allocated on the C++ heap. The pointer may be null.
- Unique
Ref - Pointer to object allocated on the C++ heap. The pointer may not be null.
- Value
- The superclass of all JavaScript values and objects.
- Value
Deserializer - ValueDeserializer is a stack object used as entry-point for an owned and pinned heap object ValueDeserializerHeap. The ’a lifetime is the lifetime of the ValueDeserializerImpl implementation. The ’s lifetime is the lifetime of the HandleScope which is used to retrieve a Local<’s, Context> for the CallbackScopes
- Value
Serializer - Wasm
Module Object - An instance of WebAssembly.Module.
- Wasm
Streaming - The V8 interface for WebAssembly streaming compilation. When streaming compilation is initiated, V8 passes a Self object to the embedder such that the embedder can pass the input bytes for streaming compilation to V8.
- Write
Options
Enums§
- Constructor
Behavior - ConstructorBehavior::Allow creates a regular API function.
- Data
Error - Function
Code Handling - Microtasks
Policy - Policy for running microtasks:
- Module
Status - The different states a module can be in.
- NewString
Type - Promise
Hook Type - PromiseHook with type Init is called when a new promise is created. When a new promise is created as part of the chain in the case of Promise.then or in the intermediate promises created by Promise.{race, all}/AsyncFunctionAwait, we pass the parent promise otherwise we pass undefined.
- Promise
Reject Event - Promise
State - Side
Effect Type - Options for marking whether callbacks may trigger JS-observable side effects. Side-effect-free callbacks are allowlisted during debug evaluation with throwOnSideEffect. It applies when calling a Function, FunctionTemplate, or an Accessor callback. For Interceptors, please see PropertyHandlerFlags’s kHasNoSideEffect. Callbacks that only cause side effects to the receiver are allowlisted if invoked on receiver objects that are created within the same debug-evaluate call, as these objects are temporary and the side effect does not escape.
Constants§
- DONT_
DELETE - Not configurable. Corresponds to
Object.defineProperty(o, "p", { configurable: false })
. - DONT_
ENUM - Not enumerable. Corresponds to
Object.defineProperty(o, "p", { enumerable: false })
. - NONE
- No property attributes.
- READ_
ONLY - Not writable. Corresponds to
Object.defineProperty(o, "p", { writable: false })
.
Traits§
- Handle
- MapFnTo
- Value
Deserializer Helper - Trait used for direct read from the deserialization buffer. Mostly used by the read_host_object callback function in the ValueDeserializerImpl trait to create custom deserialization logic.
- Value
Deserializer Impl - The ValueDeserializerImpl trait allows for custom callback functions used by v8.
- Value
Serializer Helper - Trait used for direct write to the serialization buffer. Mostly used by the write_host_object callback function in the ValueSerializerImpl trait to create custom serialization logic.
- Value
Serializer Impl - The ValueSerializerImpl trait allows for custom callback functions used by v8.
Functions§
- backing_
store_ ⚠deleter_ callback - new_
default_ allocator - malloc/free based convenience allocator.
- new_
default_ platform - Returns a new instance of the default v8::Platform implementation.
- new_
rust_ ⚠allocator - Creates an allocator managed by Rust code.
- new_
single_ threaded_ default_ platform - The same as new_default_platform() but disables the worker thread pool. It must be used with the –single-threaded V8 flag.
- null
- undefined
Type Aliases§
- Accessor
Name Getter Callback - AccessorNameGetterCallback is used as callback functions when getting a particular property. See Object and ObjectTemplate’s method SetAccessor.
- Accessor
Name Setter Callback - Backing
Store Deleter Callback - Function
Callback - Host
Import Module Dynamically With Import Assertions Callback - HostImportModuleDynamicallyWithImportAssertionsCallback is called when we require the embedder to load a module. This is used as part of the dynamic import syntax.
- Host
Initialize Import Meta Object Callback - HostInitializeImportMetaObjectCallback is called the first time import.meta is accessed for a module. Subsequent access will reuse the same value.
- Message
Callback - Near
Heap Limit Callback - Promise
Hook - Promise
Reject Callback - Resolve
Module Callback - Called during Module::instantiate_module. Provided with arguments: (context, specifier, import_assertions, referrer). Return None on error.
- Synthetic
Module Evaluation Steps