0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-24 15:19:31 -05:00

Inline API functions (#1078)

This commit is contained in:
Divy Srivastava 2022-09-21 08:15:33 +05:30 committed by GitHub
parent 6444cb9d61
commit 9f78b0abe7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 505 additions and 3 deletions

View file

@ -151,6 +151,7 @@ impl Shared for Allocator {
}
/// malloc/free based convenience allocator.
#[inline(always)]
pub fn new_default_allocator() -> UniqueRef<Allocator> {
unsafe {
UniqueRef::from_raw(v8__ArrayBuffer__Allocator__NewDefaultAllocator())
@ -160,6 +161,7 @@ pub fn new_default_allocator() -> UniqueRef<Allocator> {
/// Creates an allocator managed by Rust code.
///
/// Marked `unsafe` because the caller must ensure that `handle` is valid and matches what `vtable` expects.
#[inline(always)]
pub unsafe fn new_rust_allocator<T: Sized + Send + Sync + 'static>(
handle: *const T,
vtable: &'static RustAllocatorVtable<T>,
@ -275,6 +277,7 @@ impl BackingStore {
/// lives.
///
/// Might return `None` if the backing store has zero length.
#[inline(always)]
pub fn data(&self) -> Option<NonNull<c_void>> {
let raw_ptr =
unsafe { v8__BackingStore__Data(self as *const _ as *mut Self) };
@ -282,12 +285,14 @@ impl BackingStore {
}
/// The length (in bytes) of this backing store.
#[inline(always)]
pub fn byte_length(&self) -> usize {
unsafe { v8__BackingStore__ByteLength(self) }
}
/// Indicates whether the backing store was created for an ArrayBuffer or
/// a SharedArrayBuffer.
#[inline(always)]
pub fn is_shared(&self) -> bool {
unsafe { v8__BackingStore__IsShared(self) }
}
@ -340,6 +345,7 @@ impl ArrayBuffer {
/// Allocated memory will be owned by a created ArrayBuffer and
/// will be deallocated when it is garbage-collected,
/// unless the object is externalized.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
byte_length: usize,
@ -355,6 +361,7 @@ impl ArrayBuffer {
.unwrap()
}
#[inline(always)]
pub fn with_backing_store<'s>(
scope: &mut HandleScope<'s>,
backing_store: &SharedRef<BackingStore>,
@ -371,11 +378,13 @@ impl ArrayBuffer {
}
/// Data length in bytes.
#[inline(always)]
pub fn byte_length(&self) -> usize {
unsafe { v8__ArrayBuffer__ByteLength(self) }
}
/// Returns true if this ArrayBuffer may be detached.
#[inline(always)]
pub fn is_detachable(&self) -> bool {
unsafe { v8__ArrayBuffer__IsDetachable(self) }
}
@ -384,6 +393,7 @@ impl ArrayBuffer {
/// Detaching sets the byte length of the buffer and all typed arrays to zero,
/// preventing JavaScript from ever accessing underlying backing store.
/// ArrayBuffer should have been externalized and must be detachable.
#[inline(always)]
pub fn detach(&self) {
// V8 terminates when the ArrayBuffer is not detachable. Non-detachable
// buffers are buffers that are in use by WebAssembly or asm.js.
@ -394,7 +404,7 @@ impl ArrayBuffer {
/// More efficient shortcut for GetBackingStore()->Data().
/// The returned pointer is valid as long as the ArrayBuffer is alive.
#[inline]
#[inline(always)]
pub fn data(&self) -> *mut c_void {
unsafe { v8__ArrayBuffer__Data(self) }
}
@ -403,6 +413,7 @@ impl ArrayBuffer {
/// pointer coordinates the lifetime management of the internal storage
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
/// should not attempt to manage lifetime of the storage through other means.
#[inline(always)]
pub fn get_backing_store(&self) -> SharedRef<BackingStore> {
unsafe { v8__ArrayBuffer__GetBackingStore(self) }
}
@ -414,6 +425,7 @@ impl ArrayBuffer {
/// If the allocator returns nullptr, then the function may cause GCs in the
/// given isolate and re-try the allocation. If GCs do not help, then the
/// function will crash with an out-of-memory error.
#[inline(always)]
pub fn new_backing_store(
scope: &mut Isolate,
byte_length: usize,
@ -433,6 +445,7 @@ impl ArrayBuffer {
///
/// The result can be later passed to ArrayBuffer::New. The raw pointer
/// to the buffer must not be passed again to any V8 API function.
#[inline(always)]
pub fn new_backing_store_from_boxed_slice(
data: Box<[u8]>,
) -> UniqueRef<BackingStore> {
@ -455,6 +468,7 @@ impl ArrayBuffer {
///
/// The result can be later passed to ArrayBuffer::New. The raw pointer
/// to the buffer must not be passed again to any V8 API function.
#[inline(always)]
pub fn new_backing_store_from_vec(
mut data: Vec<u8>,
) -> UniqueRef<BackingStore> {
@ -476,6 +490,7 @@ impl ArrayBuffer {
///
/// SAFETY: This API consumes raw pointers so is inherently
/// unsafe. Usually you should use new_backing_store_from_boxed_slice.
#[inline(always)]
pub unsafe fn new_backing_store_from_ptr(
data_ptr: *mut c_void,
byte_length: usize,

View file

@ -22,6 +22,7 @@ extern "C" {
impl ArrayBufferView {
/// Returns underlying ArrayBuffer.
#[inline(always)]
pub fn buffer<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -30,11 +31,13 @@ impl ArrayBufferView {
}
/// Size of a view in bytes.
#[inline(always)]
pub fn byte_length(&self) -> usize {
unsafe { v8__ArrayBufferView__ByteLength(self) }
}
/// Byte offset in |Buffer|.
#[inline(always)]
pub fn byte_offset(&self) -> usize {
unsafe { v8__ArrayBufferView__ByteOffset(self) }
}
@ -43,6 +46,7 @@ impl ArrayBufferView {
/// memory without additional overhead that calling ArrayBufferView::Buffer
/// might incur.
/// Returns the number of bytes actually written.
#[inline(always)]
pub fn copy_contents(&self, dest: &mut [u8]) -> usize {
unsafe {
v8__ArrayBufferView__CopyContents(

View file

@ -31,6 +31,7 @@ extern "C" {
}
impl BigInt {
#[inline(always)]
pub fn new_from_i64<'s>(
scope: &mut HandleScope<'s>,
value: i64,
@ -41,6 +42,7 @@ impl BigInt {
.unwrap()
}
#[inline(always)]
pub fn new_from_u64<'s>(
scope: &mut HandleScope<'s>,
value: u64,
@ -58,6 +60,7 @@ impl BigInt {
/// The resulting number is calculated as:
///
/// (-1)^sign_bit * (words[0] * (2^64)^0 + words[1] * (2^64)^1 + ...)
#[inline(always)]
pub fn new_from_words<'s>(
scope: &mut HandleScope<'s>,
sign_bit: bool,
@ -79,6 +82,7 @@ impl BigInt {
/// `bool` indicating whether the return value was truncated was truncated or
/// wrapped around. In particular, it will be `false` if this BigInt is
/// negative.
#[inline(always)]
pub fn u64_value(&self) -> (u64, bool) {
let mut lossless = MaybeUninit::uninit();
let v = unsafe { v8__BigInt__Uint64Value(&*self, lossless.as_mut_ptr()) };
@ -88,6 +92,7 @@ impl BigInt {
/// Returns the value of this BigInt as a signed 64-bit integer, and a `bool`
/// indicating whether this BigInt was truncated or not.
#[inline(always)]
pub fn i64_value(&self) -> (i64, bool) {
let mut lossless = MaybeUninit::uninit();
let v = unsafe { v8__BigInt__Int64Value(&*self, lossless.as_mut_ptr()) };
@ -97,6 +102,7 @@ impl BigInt {
/// Returns the number of 64-bit words needed to store the result of
/// `to_words_array`.
#[inline(always)]
pub fn word_count(&self) -> usize {
unsafe { v8__BigInt__WordCount(&*self) as usize }
}
@ -104,6 +110,7 @@ impl BigInt {
/// Converts this BigInt to a (sign_bit, words) pair. `sign_bit` will be true
/// if this BigInt is negative. If `words` has too few elements, the result will
/// be truncated to fit.
#[inline]
pub fn to_words_array<'a>(
&self,
words: &'a mut [u64],

View file

@ -50,6 +50,7 @@ impl Context {
const ANNEX_SLOT: c_int = 1;
/// Creates a new context.
#[inline(always)]
pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Context> {
// TODO: optional arguments;
unsafe {
@ -61,6 +62,7 @@ impl Context {
/// Creates a new context using the object template as the template for
/// the global object.
#[inline(always)]
pub fn new_from_template<'s>(
scope: &mut HandleScope<'s, ()>,
templ: Local<ObjectTemplate>,
@ -73,6 +75,7 @@ impl Context {
.unwrap()
}
#[inline(always)]
pub fn get_extras_binding_object<'s>(
&self,
scope: &mut HandleScope<'s, ()>,
@ -91,6 +94,7 @@ impl Context {
/// Please note that changes to global proxy object prototype most probably
/// would break VM---v8 expects only global object as a prototype of global
/// proxy object.
#[inline(always)]
pub fn global<'s>(
&self,
scope: &mut HandleScope<'s, ()>,
@ -98,6 +102,7 @@ impl Context {
unsafe { scope.cast_local(|_| v8__Context__Global(self)) }.unwrap()
}
#[inline(always)]
pub fn set_promise_hooks(
&self,
init_hook: Local<Function>,
@ -116,6 +121,7 @@ impl Context {
}
}
#[inline]
fn get_annex_mut<'a>(
&'a self,
isolate: &'a mut Isolate,
@ -199,6 +205,7 @@ impl Context {
}
/// Get a reference to embedder data added with [`Self::set_slot()`].
#[inline(always)]
pub fn get_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate,
@ -215,6 +222,7 @@ impl Context {
}
/// Get a mutable reference to embedder data added with [`Self::set_slot()`].
#[inline(always)]
pub fn get_slot_mut<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate,
@ -241,6 +249,7 @@ impl Context {
/// Returns true if value was set without replacing an existing value.
///
/// The value will be dropped when the context is garbage collected.
#[inline(always)]
pub fn set_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate,
@ -256,6 +265,7 @@ impl Context {
/// Removes the embedder data added with [`Self::set_slot()`] and returns it
/// if it exists.
#[inline(always)]
pub fn remove_slot<'a, T: 'static>(
&'a self,
isolate: &'a mut Isolate,
@ -278,6 +288,7 @@ impl Context {
/// [`SnapshotCreator`](crate::SnapshotCreator), since the internal embedder
/// state uses [`Weak`] handles, which cannot be alive at the time of
/// snapshotting.
#[inline(always)]
pub fn clear_all_slots<'a>(&'a self, isolate: &'a mut Isolate) {
if let Some(annex_mut) = self.get_annex_mut(isolate, false) {
let annex_ptr = annex_mut as *mut ContextAnnex;

View file

@ -39,76 +39,91 @@ extern "C" {
impl Data {
/// Returns true if this data is a `BigInt`.
#[inline(always)]
pub fn is_big_int(&self) -> bool {
unsafe { v8__Data__IsBigInt(self) }
}
/// Returns true if this data is a `Boolean`.
#[inline(always)]
pub fn is_boolean(&self) -> bool {
unsafe { v8__Data__IsBoolean(self) }
}
/// Returns true if this data is a `Context`.
#[inline(always)]
pub fn is_context(&self) -> bool {
unsafe { v8__Data__IsContext(self) }
}
/// Returns true if this data is a `FixedArray`.
#[inline(always)]
pub fn is_fixed_array(&self) -> bool {
unsafe { v8__Data__IsFixedArray(self) }
}
/// Returns true if this data is a `FunctionTemplate`.
#[inline(always)]
pub fn is_function_template(&self) -> bool {
unsafe { v8__Data__IsFunctionTemplate(self) }
}
/// Returns true if this data is a `Module`.
#[inline(always)]
pub fn is_module(&self) -> bool {
unsafe { v8__Data__IsModule(self) }
}
/// Returns true if this data is a `ModuleRequest`.
#[inline(always)]
pub fn is_module_request(&self) -> bool {
unsafe { v8__Data__IsModuleRequest(self) }
}
/// Returns true if this data is a `Name`.
#[inline(always)]
pub fn is_name(&self) -> bool {
unsafe { v8__Data__IsName(self) }
}
/// Returns true if this data is a `Number`.
#[inline(always)]
pub fn is_number(&self) -> bool {
unsafe { v8__Data__IsNumber(self) }
}
/// Returns true if this data is a `ObjectTemplate`.
#[inline(always)]
pub fn is_object_template(&self) -> bool {
unsafe { v8__Data__IsObjectTemplate(self) }
}
/// Returns true if this data is a `Primitive`.
#[inline(always)]
pub fn is_primitive(&self) -> bool {
unsafe { v8__Data__IsPrimitive(self) }
}
/// Returns true if this data is a `Private`.
#[inline(always)]
pub fn is_private(&self) -> bool {
unsafe { v8__Data__IsPrivate(self) }
}
/// Returns true if this data is a `String`.
#[inline(always)]
pub fn is_string(&self) -> bool {
unsafe { v8__Data__IsString(self) }
}
/// Returns true if this data is a `Symbol`.
#[inline(always)]
pub fn is_symbol(&self) -> bool {
unsafe { v8__Data__IsSymbol(self) }
}
/// Returns true if this data is a `Value`.
#[inline(always)]
pub fn is_value(&self) -> bool {
unsafe { v8__Data__IsValue(self) }
}

View file

@ -12,6 +12,7 @@ extern "C" {
/// An instance of the built-in Date constructor (ECMA-262, 15.9).
impl Date {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
value: f64,
@ -23,6 +24,7 @@ impl Date {
/// A specialization of Value::NumberValue that is more efficient
/// because we know the structure of this object.
#[inline(always)]
pub fn value_of(&self) -> f64 {
unsafe { v8__Date__ValueOf(self) }
}

View file

@ -74,6 +74,7 @@ extern "C" {
impl StackTrace {
/// Grab a snapshot of the current JavaScript execution stack.
#[inline(always)]
pub fn current_stack_trace<'s>(
scope: &mut HandleScope<'s>,
frame_limit: usize,
@ -87,11 +88,13 @@ impl StackTrace {
}
/// Returns the number of StackFrames.
#[inline(always)]
pub fn get_frame_count(&self) -> usize {
unsafe { v8__StackTrace__GetFrameCount(self) as usize }
}
/// Returns a StackFrame at a particular index.
#[inline(always)]
pub fn get_frame<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -110,6 +113,7 @@ impl StackFrame {
/// This method will return Message::kNoLineNumberInfo if it is unable to
/// retrieve the line number, or if kLineNumber was not passed as an option
/// when capturing the StackTrace.
#[inline(always)]
pub fn get_line_number(&self) -> usize {
unsafe { v8__StackFrame__GetLineNumber(self) as usize }
}
@ -119,6 +123,7 @@ impl StackFrame {
/// This method will return Message::kNoColumnInfo if it is unable to retrieve
/// the column number, or if kColumnOffset was not passed as an option when
/// capturing the StackTrace.
#[inline(always)]
pub fn get_column(&self) -> usize {
unsafe { v8__StackFrame__GetColumn(self) as usize }
}
@ -127,12 +132,14 @@ impl StackFrame {
/// This method will return Message::kNoScriptIdInfo if it is unable to
/// retrieve the script id, or if kScriptId was not passed as an option when
/// capturing the StackTrace.
#[inline(always)]
pub fn get_script_id(&self) -> usize {
unsafe { v8__StackFrame__GetScriptId(self) as usize }
}
/// Returns the name of the resource that contains the script for the
/// function for this StackFrame.
#[inline(always)]
pub fn get_script_name<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -144,6 +151,7 @@ impl StackFrame {
/// function for this StackFrame or sourceURL value if the script name
/// is undefined and its source ends with //# sourceURL=... string or
/// deprecated //@ sourceURL=... string.
#[inline(always)]
pub fn get_script_name_or_source_url<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -154,6 +162,7 @@ impl StackFrame {
}
/// Returns the name of the function associated with this stack frame.
#[inline(always)]
pub fn get_function_name<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -163,28 +172,33 @@ impl StackFrame {
/// Returns whether or not the associated function is compiled via a call to
/// eval().
#[inline(always)]
pub fn is_eval(&self) -> bool {
unsafe { v8__StackFrame__IsEval(self) }
}
/// Returns whether or not the associated function is called as a
/// constructor via "new".
#[inline(always)]
pub fn is_constructor(&self) -> bool {
unsafe { v8__StackFrame__IsConstructor(self) }
}
/// Returns whether or not the associated functions is defined in wasm.
#[inline(always)]
pub fn is_wasm(&self) -> bool {
unsafe { v8__StackFrame__IsWasm(self) }
}
/// Returns whether or not the associated function is defined by the user.
#[inline(always)]
pub fn is_user_javascript(&self) -> bool {
unsafe { v8__StackFrame__IsUserJavaScript(self) }
}
}
impl Message {
#[inline(always)]
pub fn get<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, String> {
unsafe { scope.cast_local(|_| v8__Message__Get(self)) }.unwrap()
}
@ -192,6 +206,7 @@ impl Message {
/// Exception stack trace. By default stack traces are not captured for
/// uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
/// to change this option.
#[inline(always)]
pub fn get_stack_trace<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -199,6 +214,7 @@ impl Message {
unsafe { scope.cast_local(|_| v8__Message__GetStackTrace(self)) }
}
#[inline(always)]
pub fn get_source_line<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -212,6 +228,7 @@ impl Message {
/// Returns the resource name for the script from where the function causing
/// the error originates.
#[inline(always)]
pub fn get_script_resource_name<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -220,6 +237,7 @@ impl Message {
}
/// Returns the number, 1-based, of the line where the error occurred.
#[inline(always)]
pub fn get_line_number(&self, scope: &mut HandleScope) -> Option<usize> {
let i = unsafe {
v8__Message__GetLineNumber(self, &*scope.get_current_context())
@ -233,45 +251,53 @@ impl Message {
/// Returns the index within the script of the first character where
/// the error occurred.
#[inline(always)]
pub fn get_start_position(&self) -> int {
unsafe { v8__Message__GetStartPosition(self) }
}
/// Returns the index within the script of the last character where
/// the error occurred.
#[inline(always)]
pub fn get_end_position(&self) -> int {
unsafe { v8__Message__GetEndPosition(self) }
}
/// Returns the Wasm function index where the error occurred. Returns -1 if
/// message is not from a Wasm script.
#[inline(always)]
pub fn get_wasm_function_index(&self) -> int {
unsafe { v8__Message__GetWasmFunctionIndex(self) }
}
/// Returns the error level of the message.
#[inline(always)]
pub fn error_level(&self) -> int {
unsafe { v8__Message__ErrorLevel(self) }
}
/// Returns the index within the line of the first character where
/// the error occurred.
#[inline(always)]
pub fn get_start_column(&self) -> usize {
unsafe { v8__Message__GetStartColumn(self) as usize }
}
/// Returns the index within the line of the last character where
/// the error occurred.
#[inline(always)]
pub fn get_end_column(&self) -> usize {
unsafe { v8__Message__GetEndColumn(self) as usize }
}
/// Passes on the value set by the embedder when it fed the script from which
/// this Message was generated to V8.
#[inline(always)]
pub fn is_shared_cross_origin(&self) -> bool {
unsafe { v8__Message__IsSharedCrossOrigin(self) }
}
#[inline(always)]
pub fn is_opaque(&self) -> bool {
unsafe { v8__Message__IsOpaque(self) }
}
@ -283,6 +309,7 @@ impl Message {
pub struct Exception;
impl Exception {
#[inline(always)]
pub fn error<'s>(
scope: &mut HandleScope<'s>,
message: Local<String>,
@ -290,6 +317,7 @@ impl Exception {
Self::new_error_with(scope, message, v8__Exception__Error)
}
#[inline(always)]
pub fn range_error<'s>(
scope: &mut HandleScope<'s>,
message: Local<String>,
@ -297,6 +325,7 @@ impl Exception {
Self::new_error_with(scope, message, v8__Exception__RangeError)
}
#[inline(always)]
pub fn reference_error<'s>(
scope: &mut HandleScope<'s>,
message: Local<String>,
@ -304,6 +333,7 @@ impl Exception {
Self::new_error_with(scope, message, v8__Exception__ReferenceError)
}
#[inline(always)]
pub fn syntax_error<'s>(
scope: &mut HandleScope<'s>,
message: Local<String>,
@ -311,6 +341,7 @@ impl Exception {
Self::new_error_with(scope, message, v8__Exception__SyntaxError)
}
#[inline(always)]
pub fn type_error<'s>(
scope: &mut HandleScope<'s>,
message: Local<String>,
@ -319,6 +350,7 @@ impl Exception {
}
/// Internal helper to make the above error constructors less repetitive.
#[inline(always)]
fn new_error_with<'s>(
scope: &mut HandleScope<'s>,
message: Local<String>,
@ -335,6 +367,7 @@ impl Exception {
/// Creates an error message for the given exception.
/// Will try to reconstruct the original stack trace from the exception value,
/// or capture the current stack trace if not available.
#[inline(always)]
pub fn create_message<'s>(
scope: &mut HandleScope<'s>,
exception: Local<Value>,
@ -349,6 +382,7 @@ impl Exception {
/// Returns the original stack trace that was captured at the creation time
/// of a given exception, or an empty handle if not available.
#[inline(always)]
pub fn get_stack_trace<'s>(
scope: &mut HandleScope<'s>,
exception: Local<Value>,

View file

@ -16,6 +16,7 @@ extern "C" {
}
impl External {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
value: *mut c_void,
@ -26,6 +27,7 @@ impl External {
.unwrap()
}
#[inline(always)]
pub fn value(&self) -> *mut c_void {
unsafe { v8__External__Value(self) }
}

View file

@ -21,6 +21,7 @@ pub struct ExternalReferences {
unsafe impl Sync for ExternalReferences {}
impl ExternalReferences {
#[inline(always)]
pub fn new(refs: &[ExternalReference]) -> Self {
let null_terminated = refs
.iter()
@ -30,6 +31,7 @@ impl ExternalReferences {
Self { null_terminated }
}
#[inline(always)]
pub fn as_ptr(&self) -> *const intptr_t {
self.null_terminated.as_ptr()
}

View file

@ -29,6 +29,7 @@ pub struct CFunctionInfo(Opaque);
pub struct CFunction(Opaque);
impl CFunctionInfo {
#[inline(always)]
pub(crate) unsafe fn new(
args: *const CTypeInfo,
args_len: usize,
@ -43,6 +44,7 @@ impl CFunctionInfo {
pub struct CTypeInfo(Opaque);
impl CTypeInfo {
#[inline(always)]
pub(crate) fn new(ty: CType) -> NonNull<CTypeInfo> {
unsafe { NonNull::new_unchecked(v8__CTypeInfo__New(ty)) }
}
@ -203,7 +205,7 @@ pub struct FastApiTypedArray<T: Default> {
}
impl<T: Default> FastApiTypedArray<T> {
#[inline]
#[inline(always)]
pub fn get(&self, index: usize) -> T {
debug_assert!(index < self.length);
let mut t: T = Default::default();
@ -213,7 +215,7 @@ impl<T: Default> FastApiTypedArray<T> {
t
}
#[inline]
#[inline(always)]
pub fn get_storage_if_aligned(&self) -> Option<&mut [T]> {
if (self.data as usize) % align_of::<T>() != 0 {
return None;

View file

@ -17,10 +17,12 @@ extern "C" {
}
impl FixedArray {
#[inline(always)]
pub fn length(&self) -> usize {
unsafe { v8__FixedArray__Length(self) as usize }
}
#[inline(always)]
pub fn get<'s>(
&self,
scope: &mut HandleScope<'s>,

View file

@ -129,6 +129,7 @@ pub struct ReturnValue<'cb>(*mut Value, PhantomData<&'cb ()>);
/// and for our purposes we currently don't need
/// other types. So for now it's a simplified version.
impl<'cb> ReturnValue<'cb> {
#[inline(always)]
pub unsafe fn from_function_callback_info(
info: *const FunctionCallbackInfo,
) -> Self {
@ -136,39 +137,48 @@ impl<'cb> ReturnValue<'cb> {
Self(slot, PhantomData)
}
#[inline(always)]
fn from_property_callback_info(info: *const PropertyCallbackInfo) -> Self {
let slot = unsafe { v8__PropertyCallbackInfo__GetReturnValue(info) };
Self(slot, PhantomData)
}
#[inline(always)]
pub fn set(&mut self, value: Local<Value>) {
unsafe { v8__ReturnValue__Set(&mut *self, &*value) }
}
#[inline(always)]
pub fn set_bool(&mut self, value: bool) {
unsafe { v8__ReturnValue__Set__Bool(&mut *self, value) }
}
#[inline(always)]
pub fn set_int32(&mut self, value: i32) {
unsafe { v8__ReturnValue__Set__Int32(&mut *self, value) }
}
#[inline(always)]
pub fn set_uint32(&mut self, value: u32) {
unsafe { v8__ReturnValue__Set__Uint32(&mut *self, value) }
}
#[inline(always)]
pub fn set_double(&mut self, value: f64) {
unsafe { v8__ReturnValue__Set__Double(&mut *self, value) }
}
#[inline(always)]
pub fn set_null(&mut self) {
unsafe { v8__ReturnValue__SetNull(&mut *self) }
}
#[inline(always)]
pub fn set_undefined(&mut self) {
unsafe { v8__ReturnValue__SetUndefined(&mut *self) }
}
#[inline(always)]
pub fn set_empty_string(&mut self) {
unsafe { v8__ReturnValue__SetEmptyString(&mut *self) }
}
@ -176,6 +186,7 @@ impl<'cb> ReturnValue<'cb> {
/// Getter. Creates a new Local<> so it comes with a certain performance
/// hit. If the ReturnValue was not yet set, this will return the undefined
/// value.
#[inline(always)]
pub fn get<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__ReturnValue__Get(self)) }.unwrap()
}
@ -212,6 +223,7 @@ pub struct FunctionCallbackArguments<'s> {
}
impl<'s> FunctionCallbackArguments<'s> {
#[inline(always)]
pub unsafe fn from_function_callback_info(
info: *const FunctionCallbackInfo,
) -> Self {
@ -222,6 +234,7 @@ impl<'s> FunctionCallbackArguments<'s> {
}
/// Returns the receiver. This corresponds to the "this" value.
#[inline(always)]
pub fn this(&self) -> Local<'s, Object> {
unsafe {
Local::from_raw(v8__FunctionCallbackInfo__This(self.info)).unwrap()
@ -229,11 +242,13 @@ impl<'s> FunctionCallbackArguments<'s> {
}
/// Returns the data argument specified when creating the callback.
#[inline(always)]
pub fn data(&self) -> Option<Local<'s, Value>> {
unsafe { Local::from_raw(v8__FunctionCallbackInfo__Data(self.info)) }
}
/// The number of available arguments.
#[inline(always)]
pub fn length(&self) -> int {
unsafe {
let length = (*self.info).length;
@ -244,6 +259,7 @@ impl<'s> FunctionCallbackArguments<'s> {
/// Accessor for the available arguments. Returns `undefined` if the index is
/// out of bounds.
#[inline(always)]
pub fn get(&self, i: int) -> Local<'s, Value> {
unsafe {
Local::from_raw(v8__FunctionCallbackInfo__GetArgument(self.info, i))
@ -252,6 +268,7 @@ impl<'s> FunctionCallbackArguments<'s> {
}
/// For construct calls, this returns the "new.target" value.
#[inline(always)]
pub fn new_target(&self) -> Local<'s, Value> {
unsafe {
Local::from_raw(v8__FunctionCallbackInfo__NewTarget(self.info)).unwrap()
@ -266,6 +283,7 @@ pub struct PropertyCallbackArguments<'s> {
}
impl<'s> PropertyCallbackArguments<'s> {
#[inline(always)]
pub(crate) fn from_property_callback_info(
info: *const PropertyCallbackInfo,
) -> Self {
@ -314,6 +332,7 @@ impl<'s> PropertyCallbackArguments<'s> {
///
/// CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)");
/// ```
#[inline(always)]
pub fn this(&self) -> Local<'s, Object> {
unsafe {
Local::from_raw(v8__PropertyCallbackInfo__This(self.info)).unwrap()
@ -394,10 +413,12 @@ pub struct FunctionBuilder<'s, T> {
impl<'s, T> FunctionBuilder<'s, T> {
/// Create a new FunctionBuilder.
#[inline(always)]
pub fn new(callback: impl MapFnTo<FunctionCallback>) -> Self {
Self::new_raw(callback.map_fn_to())
}
#[inline(always)]
pub fn new_raw(callback: FunctionCallback) -> Self {
Self {
callback,
@ -411,18 +432,21 @@ impl<'s, T> FunctionBuilder<'s, T> {
}
/// Set the associated data. The default is no associated data.
#[inline(always)]
pub fn data(mut self, data: Local<'s, Value>) -> Self {
self.data = Some(data);
self
}
/// Set the function length. The default is 0.
#[inline(always)]
pub fn length(mut self, length: i32) -> Self {
self.length = length;
self
}
/// Set the constructor behavior. The default is ConstructorBehavior::Allow.
#[inline(always)]
pub fn constructor_behavior(
mut self,
constructor_behavior: ConstructorBehavior,
@ -432,6 +456,7 @@ impl<'s, T> FunctionBuilder<'s, T> {
}
/// Set the side effect type. The default is SideEffectType::HasSideEffect.
#[inline(always)]
pub fn side_effect_type(mut self, side_effect_type: SideEffectType) -> Self {
self.side_effect_type = side_effect_type;
self
@ -440,6 +465,7 @@ impl<'s, T> FunctionBuilder<'s, T> {
impl<'s> FunctionBuilder<'s, Function> {
/// Create the function in the current execution context.
#[inline(always)]
pub fn build(
self,
scope: &mut HandleScope<'s>,
@ -462,12 +488,14 @@ impl<'s> FunctionBuilder<'s, Function> {
impl Function {
/// Create a FunctionBuilder to configure a Function.
/// This is the same as FunctionBuilder::<Function>::new().
#[inline(always)]
pub fn builder<'s>(
callback: impl MapFnTo<FunctionCallback>,
) -> FunctionBuilder<'s, Self> {
FunctionBuilder::new(callback)
}
#[inline(always)]
pub fn builder_raw<'s>(
callback: FunctionCallback,
) -> FunctionBuilder<'s, Self> {
@ -476,6 +504,7 @@ impl Function {
/// Create a function in the current execution context
/// for a given FunctionCallback.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
callback: impl MapFnTo<FunctionCallback>,
@ -483,6 +512,7 @@ impl Function {
Self::builder(callback).build(scope)
}
#[inline(always)]
pub fn new_raw<'s>(
scope: &mut HandleScope<'s>,
callback: FunctionCallback,
@ -490,6 +520,7 @@ impl Function {
Self::builder_raw(callback).build(scope)
}
#[inline(always)]
pub fn call<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -506,6 +537,7 @@ impl Function {
}
}
#[inline(always)]
pub fn new_instance<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -521,21 +553,25 @@ impl Function {
}
}
#[inline(always)]
pub fn get_name<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, String> {
unsafe { scope.cast_local(|_| v8__Function__GetName(self)).unwrap() }
}
#[inline(always)]
pub fn set_name(&self, name: Local<String>) {
unsafe { v8__Function__SetName(self, &*name) }
}
/// Get the (zero-indexed) column number of the function's definition, if available.
#[inline(always)]
pub fn get_script_column_number(&self) -> Option<u32> {
let ret = unsafe { v8__Function__GetScriptColumnNumber(self) };
(ret >= 0).then(|| ret as u32)
}
/// Get the (zero-indexed) line number of the function's definition, if available.
#[inline(always)]
pub fn get_script_line_number(&self) -> Option<u32> {
let ret = unsafe { v8__Function__GetScriptLineNumber(self) };
(ret >= 0).then(|| ret as u32)
@ -544,6 +580,7 @@ impl Function {
/// Creates and returns code cache for the specified unbound_script.
/// This will return nullptr if the script cannot be serialized. The
/// CachedData returned by this function should be owned by the caller.
#[inline(always)]
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
let code_cache =
unsafe { UniqueRef::try_from_raw(v8__Function__CreateCodeCache(self)) };

View file

@ -68,6 +68,7 @@ impl Default for GetPropertyNamesArgsBuilder {
}
impl GetPropertyNamesArgsBuilder {
#[inline(always)]
pub fn new() -> Self {
Self {
mode: KeyCollectionMode::IncludePrototypes,
@ -77,6 +78,7 @@ impl GetPropertyNamesArgsBuilder {
}
}
#[inline(always)]
pub fn build(&self) -> GetPropertyNamesArgs {
GetPropertyNamesArgs {
mode: self.mode,
@ -86,6 +88,7 @@ impl GetPropertyNamesArgsBuilder {
}
}
#[inline(always)]
pub fn mode(
&mut self,
mode: KeyCollectionMode,
@ -94,6 +97,7 @@ impl GetPropertyNamesArgsBuilder {
self
}
#[inline(always)]
pub fn property_filter(
&mut self,
property_filter: PropertyFilter,
@ -102,6 +106,7 @@ impl GetPropertyNamesArgsBuilder {
self
}
#[inline(always)]
pub fn index_filter(
&mut self,
index_filter: IndexFilter,
@ -110,6 +115,7 @@ impl GetPropertyNamesArgsBuilder {
self
}
#[inline(always)]
pub fn key_conversion(
&mut self,
key_conversion: KeyConversionMode,

View file

@ -77,6 +77,7 @@ pub struct Local<'s, T>(NonNull<T>, PhantomData<&'s ()>);
impl<'s, T> Local<'s, T> {
/// Construct a new Local from an existing Handle.
#[inline(always)]
pub fn new(
scope: &mut HandleScope<'s, ()>,
handle: impl Handle<Data = T>,
@ -93,6 +94,7 @@ impl<'s, T> Local<'s, T> {
/// Create a local handle by downcasting from one of its super types.
/// This function is unsafe because the cast is unchecked.
#[inline(always)]
pub unsafe fn cast<A>(other: Local<'s, A>) -> Self
where
Local<'s, A>: From<Self>,
@ -100,18 +102,22 @@ impl<'s, T> Local<'s, T> {
transmute(other)
}
#[inline(always)]
pub(crate) unsafe fn from_raw(ptr: *const T) -> Option<Self> {
NonNull::new(ptr as *mut _).map(|nn| Self::from_non_null(nn))
}
#[inline(always)]
pub(crate) unsafe fn from_non_null(nn: NonNull<T>) -> Self {
Self(nn, PhantomData)
}
#[inline(always)]
pub(crate) fn as_non_null(self) -> NonNull<T> {
self.0
}
#[inline(always)]
pub(crate) fn slice_into_raw(slice: &[Self]) -> &[*const T] {
unsafe { &*(slice as *const [Self] as *const [*const T]) }
}
@ -148,6 +154,7 @@ pub struct Global<T> {
impl<T> Global<T> {
/// Construct a new Global from an existing Handle.
#[inline(always)]
pub fn new(isolate: &mut Isolate, handle: impl Handle<Data = T>) -> Self {
let HandleInfo { data, host } = handle.get_handle_info();
host.assert_match_isolate(isolate);
@ -156,6 +163,7 @@ impl<T> Global<T> {
/// Implementation helper function that contains the code that can be shared
/// between `Global::new()` and `Global::clone()`.
#[inline(always)]
unsafe fn new_raw(isolate: *mut Isolate, data: NonNull<T>) -> Self {
let data = data.cast().as_ptr();
let data = v8__Global__New(isolate, data) as *const T;
@ -173,6 +181,7 @@ impl<T> Global<T> {
/// [`Global::from_raw`], otherwise the V8 value referenced by this global
/// handle will be pinned on the V8 heap permanently and never get garbage
/// collected.
#[inline(always)]
pub fn into_raw(self) -> NonNull<T> {
let data = self.data;
forget(self);
@ -181,6 +190,7 @@ impl<T> Global<T> {
/// Converts a raw pointer created with [`Global::into_raw()`] back to its
/// original `Global`.
#[inline(always)]
pub unsafe fn from_raw(isolate: &mut Isolate, data: NonNull<T>) -> Self {
let isolate_handle = isolate.thread_safe_handle();
Self {
@ -189,6 +199,7 @@ impl<T> Global<T> {
}
}
#[inline(always)]
pub fn open<'a>(&'a self, scope: &mut Isolate) -> &'a T {
Handle::open(self, scope)
}
@ -231,6 +242,7 @@ impl<'a, T> UnsafeRefHandle<'a, T> {
/// isolate associated with the handle (for [`Local`], the current isolate;
/// for [`Global`], the isolate you would pass to the [`Global::open()`]
/// method).
#[inline(always)]
pub unsafe fn new(reference: &'a T, isolate: &mut Isolate) -> Self {
UnsafeRefHandle {
reference,

View file

@ -35,6 +35,7 @@ extern "C" {
/// This function has no effect on application (non ICU) data. See udata_setAppData() for similar
/// functionality for application data.
// TODO(ry) Map error code to something useful.
#[inline(always)]
pub fn set_common_data_71(data: &'static [u8]) -> Result<(), i32> {
let mut error_code = 0i32;
unsafe {

View file

@ -378,25 +378,30 @@ impl Isolate {
}
/// Initial configuration parameters for a new Isolate.
#[inline(always)]
pub fn create_params() -> CreateParams {
CreateParams::default()
}
#[inline(always)]
pub fn thread_safe_handle(&self) -> IsolateHandle {
IsolateHandle::new(self)
}
/// See [`IsolateHandle::terminate_execution`]
#[inline(always)]
pub fn terminate_execution(&self) -> bool {
self.thread_safe_handle().terminate_execution()
}
/// See [`IsolateHandle::cancel_terminate_execution`]
#[inline(always)]
pub fn cancel_terminate_execution(&self) -> bool {
self.thread_safe_handle().cancel_terminate_execution()
}
/// See [`IsolateHandle::is_execution_terminating`]
#[inline(always)]
pub fn is_execution_terminating(&self) -> bool {
self.thread_safe_handle().is_execution_terminating()
}
@ -413,6 +418,7 @@ impl Isolate {
};
}
#[inline(always)]
fn get_annex(&self) -> &IsolateAnnex {
unsafe {
&*(v8__Isolate__GetData(self, Self::ANNEX_SLOT) as *const _
@ -420,6 +426,7 @@ impl Isolate {
}
}
#[inline(always)]
fn get_annex_mut(&mut self) -> &mut IsolateAnnex {
unsafe {
&mut *(v8__Isolate__GetData(self, Self::ANNEX_SLOT) as *mut IsolateAnnex)
@ -443,6 +450,7 @@ impl Isolate {
/// Associate embedder-specific data with the isolate. `slot` has to be
/// between 0 and `Isolate::get_number_of_data_slots()`.
#[inline(always)]
unsafe fn set_data(&mut self, slot: u32, ptr: *mut c_void) {
v8__Isolate__SetData(self, slot + Self::INTERNAL_SLOT_COUNT, ptr)
}
@ -464,6 +472,7 @@ impl Isolate {
}
/// Returns a pointer to the `ScopeData` struct for the current scope.
#[inline(always)]
pub(crate) fn get_current_scope_data(&self) -> Option<NonNull<ScopeData>> {
let scope_data_ptr =
unsafe { v8__Isolate__GetData(self, Self::CURRENT_SCOPE_DATA_SLOT) };
@ -471,6 +480,7 @@ impl Isolate {
}
/// Updates the slot that stores a `ScopeData` pointer for the current scope.
#[inline(always)]
pub(crate) fn set_current_scope_data(
&mut self,
scope_data: Option<NonNull<ScopeData>>,
@ -485,6 +495,7 @@ impl Isolate {
}
/// Get a reference to embedder data added with `set_slot()`.
#[inline(always)]
pub fn get_slot<T: 'static>(&self) -> Option<&T> {
self
.get_annex()
@ -494,6 +505,7 @@ impl Isolate {
}
/// Get a mutable reference to embedder data added with `set_slot()`.
#[inline(always)]
pub fn get_slot_mut<T: 'static>(&mut self) -> Option<&mut T> {
self
.get_annex_mut()
@ -513,6 +525,7 @@ impl Isolate {
/// Returns true if value was set without replacing an existing value.
///
/// The value will be dropped when the isolate is dropped.
#[inline(always)]
pub fn set_slot<T: 'static>(&mut self, value: T) -> bool {
self
.get_annex_mut()
@ -522,6 +535,7 @@ impl Isolate {
}
/// Removes the embedder data added with `set_slot()` and returns it if it exists.
#[inline(always)]
pub fn remove_slot<T: 'static>(&mut self) -> Option<T> {
self
.get_annex_mut()
@ -536,6 +550,7 @@ impl Isolate {
///
/// rusty_v8 note: Unlike in the C++ API, the isolate is entered when it is
/// constructed and exited when dropped.
#[inline(always)]
pub unsafe fn enter(&mut self) {
v8__Isolate__Enter(self)
}
@ -548,6 +563,7 @@ impl Isolate {
///
/// rusty_v8 note: Unlike in the C++ API, the isolate is entered when it is
/// constructed and exited when dropped.
#[inline(always)]
pub unsafe fn exit(&mut self) {
v8__Isolate__Exit(self)
}
@ -563,23 +579,27 @@ impl Isolate {
/// running microtasks via a custom MicrotaskQueue class's PerformCheckpoint.
/// In that case, it is the embedder's responsibility to make this call at a
/// time which does not interrupt synchronous ECMAScript code execution.
#[inline(always)]
pub fn clear_kept_objects(&mut self) {
unsafe { v8__Isolate__ClearKeptObjects(self) }
}
/// Optional notification that the system is running low on memory.
/// V8 uses these notifications to attempt to free memory.
#[inline(always)]
pub fn low_memory_notification(&mut self) {
unsafe { v8__Isolate__LowMemoryNotification(self) }
}
/// Get statistics about the heap memory usage.
#[inline(always)]
pub fn get_heap_statistics(&mut self, s: &mut HeapStatistics) {
unsafe { v8__Isolate__GetHeapStatistics(self, s) }
}
/// Tells V8 to capture current stack trace when uncaught exception occurs
/// and report it to the message listeners. The option is off by default.
#[inline(always)]
pub fn set_capture_stack_trace_for_uncaught_exceptions(
&mut self,
capture: bool,
@ -600,6 +620,7 @@ impl Isolate {
/// case it will be called more than once for each message.
///
/// The exception object will be passed to the callback.
#[inline(always)]
pub fn add_message_listener(&mut self, callback: MessageCallback) -> bool {
unsafe { v8__Isolate__AddMessageListener(self, callback) }
}
@ -612,6 +633,7 @@ impl Isolate {
/// callback is registed, the |Error.prepareStackTrace| API will be disabled.
/// |sites| is an array of call sites, specified in
/// https://v8.dev/docs/stack-trace-api
#[inline(always)]
pub fn set_prepare_stack_trace_callback<'s>(
&mut self,
callback: impl MapFnTo<PrepareStackTraceCallback<'s>>,
@ -626,12 +648,14 @@ impl Isolate {
/// Set the PromiseHook callback for various promise lifecycle
/// events.
#[inline(always)]
pub fn set_promise_hook(&mut self, hook: PromiseHook) {
unsafe { v8__Isolate__SetPromiseHook(self, hook) }
}
/// Set callback to notify about promise reject with no handler, or
/// revocation of such a previous notification once the handler is added.
#[inline(always)]
pub fn set_promise_reject_callback(
&mut self,
callback: PromiseRejectCallback,
@ -639,6 +663,7 @@ impl Isolate {
unsafe { v8__Isolate__SetPromiseRejectCallback(self, callback) }
}
#[inline(always)]
pub fn set_wasm_async_resolve_promise_callback(
&mut self,
callback: WasmAsyncResolvePromiseCallback,
@ -646,6 +671,7 @@ impl Isolate {
unsafe { v8__Isolate__SetWasmAsyncResolvePromiseCallback(self, callback) }
}
#[inline(always)]
/// This specifies the callback called by the upcoming importa.meta
/// language feature to retrieve host-defined meta data for a module.
pub fn set_host_initialize_import_meta_object_callback(
@ -659,6 +685,7 @@ impl Isolate {
/// This specifies the callback called by the upcoming dynamic
/// import() language feature to load modules.
#[inline(always)]
pub fn set_host_import_module_dynamically_callback(
&mut self,
callback: HostImportModuleDynamicallyCallback,
@ -722,6 +749,7 @@ impl Isolate {
/// If multiple callbacks are added, only the most recently added callback is
/// invoked.
#[allow(clippy::not_unsafe_ptr_arg_deref)] // False positive.
#[inline(always)]
pub fn add_near_heap_limit_callback(
&mut self,
callback: NearHeapLimitCallback,
@ -734,6 +762,7 @@ impl Isolate {
/// If the given limit is zero, then it is ignored. If the current heap size
/// is greater than the given limit, then the heap limit is restored to the
/// minimal limit that is possible for the current heap size.
#[inline(always)]
pub fn remove_near_heap_limit_callback(
&mut self,
callback: NearHeapLimitCallback,
@ -751,6 +780,7 @@ impl Isolate {
/// will trigger global garbage collections more often than it would
/// otherwise in an attempt to garbage collect the JavaScript objects
/// that keep the externally allocated memory alive.
#[inline(always)]
pub fn adjust_amount_of_external_allocated_memory(
&mut self,
change_in_bytes: i64,
@ -760,16 +790,19 @@ impl Isolate {
}
}
#[inline(always)]
pub fn set_oom_error_handler(&mut self, callback: OomErrorCallback) {
unsafe { v8__Isolate__SetOOMErrorHandler(self, callback) };
}
/// Returns the policy controlling how Microtasks are invoked.
#[inline(always)]
pub fn get_microtasks_policy(&self) -> MicrotasksPolicy {
unsafe { v8__Isolate__GetMicrotasksPolicy(self) }
}
/// Returns the policy controlling how Microtasks are invoked.
#[inline(always)]
pub fn set_microtasks_policy(&mut self, policy: MicrotasksPolicy) {
unsafe { v8__Isolate__SetMicrotasksPolicy(self, policy) }
}
@ -778,6 +811,7 @@ impl Isolate {
/// microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
/// the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
/// callbacks are swallowed.
#[inline(always)]
pub fn perform_microtask_checkpoint(&mut self) {
unsafe { v8__Isolate__PerformMicrotaskCheckpoint(self) }
}
@ -789,6 +823,7 @@ impl Isolate {
}
/// Enqueues the callback to the default MicrotaskQueue
#[inline(always)]
pub fn enqueue_microtask(&mut self, microtask: Local<Function>) {
unsafe { v8__Isolate__EnqueueMicrotask(self, &*microtask) }
}
@ -796,6 +831,7 @@ impl Isolate {
/// Set whether calling Atomics.wait (a function that may block) is allowed in
/// this isolate. This can also be configured via
/// CreateParams::allow_atomics_wait.
#[inline(always)]
pub fn set_allow_atomics_wait(&mut self, allow: bool) {
unsafe { v8__Isolate__SetAllowAtomicsWait(self, allow) }
}
@ -807,6 +843,7 @@ impl Isolate {
/// and an instance of [WasmStreaming]. The [WasmStreaming] instance
/// can outlive the callback and is used to feed data chunks to V8
/// asynchronously.
#[inline(always)]
pub fn set_wasm_streaming_callback<F>(&mut self, _: F)
where
F: UnitType + Fn(&mut HandleScope, Local<Value>, WasmStreaming),
@ -817,6 +854,7 @@ impl Isolate {
/// Returns true if there is ongoing background work within V8 that will
/// eventually post a foreground task, like asynchronous WebAssembly
/// compilation.
#[inline(always)]
pub fn has_pending_background_tasks(&self) -> bool {
unsafe { v8__Isolate__HasPendingBackgroundTasks(self) }
}
@ -946,6 +984,7 @@ impl IsolateHandle {
self.0.isolate
}
#[inline(always)]
fn new(isolate: &Isolate) -> Self {
Self(isolate.get_annex_arc())
}
@ -957,6 +996,7 @@ impl IsolateHandle {
/// acquired the V8 lock with a Locker object.
///
/// Returns false if Isolate was already destroyed.
#[inline(always)]
pub fn terminate_execution(&self) -> bool {
let _lock = self.0.isolate_mutex.lock().unwrap();
if self.0.isolate.is_null() {
@ -981,6 +1021,7 @@ impl IsolateHandle {
/// acquired the V8 lock with a Locker object.
///
/// Returns false if Isolate was already destroyed.
#[inline(always)]
pub fn cancel_terminate_execution(&self) -> bool {
let _lock = self.0.isolate_mutex.lock().unwrap();
if self.0.isolate.is_null() {
@ -999,6 +1040,7 @@ impl IsolateHandle {
/// exception is still active.
///
/// Returns false if Isolate was already destroyed.
#[inline(always)]
pub fn is_execution_terminating(&self) -> bool {
let _lock = self.0.isolate_mutex.lock().unwrap();
if self.0.isolate.is_null() {
@ -1019,6 +1061,7 @@ impl IsolateHandle {
// Clippy warns that this method is dereferencing a raw pointer, but it is
// not: https://github.com/rust-lang/rust-clippy/issues/3045
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[inline(always)]
pub fn request_interrupt(
&self,
callback: InterruptCallback,
@ -1070,60 +1113,74 @@ impl DerefMut for OwnedIsolate {
}
impl HeapStatistics {
#[inline(always)]
pub fn total_heap_size(&self) -> usize {
unsafe { v8__HeapStatistics__total_heap_size(self) }
}
#[inline(always)]
pub fn total_heap_size_executable(&self) -> usize {
unsafe { v8__HeapStatistics__total_heap_size_executable(self) }
}
#[inline(always)]
pub fn total_physical_size(&self) -> usize {
unsafe { v8__HeapStatistics__total_physical_size(self) }
}
#[inline(always)]
pub fn total_available_size(&self) -> usize {
unsafe { v8__HeapStatistics__total_available_size(self) }
}
#[inline(always)]
pub fn total_global_handles_size(&self) -> usize {
unsafe { v8__HeapStatistics__total_global_handles_size(self) }
}
#[inline(always)]
pub fn used_global_handles_size(&self) -> usize {
unsafe { v8__HeapStatistics__used_global_handles_size(self) }
}
#[inline(always)]
pub fn used_heap_size(&self) -> usize {
unsafe { v8__HeapStatistics__used_heap_size(self) }
}
#[inline(always)]
pub fn heap_size_limit(&self) -> usize {
unsafe { v8__HeapStatistics__heap_size_limit(self) }
}
#[inline(always)]
pub fn malloced_memory(&self) -> usize {
unsafe { v8__HeapStatistics__malloced_memory(self) }
}
#[inline(always)]
pub fn external_memory(&self) -> usize {
unsafe { v8__HeapStatistics__external_memory(self) }
}
#[inline(always)]
pub fn peak_malloced_memory(&self) -> usize {
unsafe { v8__HeapStatistics__peak_malloced_memory(self) }
}
#[inline(always)]
pub fn number_of_native_contexts(&self) -> usize {
unsafe { v8__HeapStatistics__number_of_native_contexts(self) }
}
#[inline(always)]
pub fn number_of_detached_contexts(&self) -> usize {
unsafe { v8__HeapStatistics__number_of_detached_contexts(self) }
}
/// Returns a 0/1 boolean, which signifies whether the V8 overwrite heap
/// garbage with a bit pattern.
#[inline(always)]
pub fn does_zap_garbage(&self) -> usize {
unsafe { v8__HeapStatistics__does_zap_garbage(self) }
}

View file

@ -19,6 +19,7 @@ extern "C" {
/// Tries to parse the string `json_string` and returns it as value if
/// successful.
#[inline(always)]
pub fn parse<'s>(
scope: &mut HandleScope<'s>,
json_string: Local<'_, String>,
@ -31,6 +32,7 @@ pub fn parse<'s>(
/// Tries to stringify the JSON-serializable object `json_object` and returns
/// it as string if successful.
#[inline(always)]
pub fn stringify<'s>(
scope: &mut HandleScope<'s>,
json_object: Local<'_, Value>,

View file

@ -215,11 +215,13 @@ pub enum ModuleStatus {
impl Module {
/// Returns the module's current status.
#[inline(always)]
pub fn get_status(&self) -> ModuleStatus {
unsafe { v8__Module__GetStatus(self) }
}
/// For a module in kErrored status, this returns the corresponding exception.
#[inline(always)]
pub fn get_exception(&self) -> Local<Value> {
// Note: the returned value is not actually stored in a HandleScope,
// therefore we don't need a scope object here.
@ -227,12 +229,14 @@ impl Module {
}
/// Returns the ModuleRequests for this module.
#[inline(always)]
pub fn get_module_requests(&self) -> Local<FixedArray> {
unsafe { Local::from_raw(v8__Module__GetModuleRequests(self)) }.unwrap()
}
/// For the given source text offset in this module, returns the corresponding
/// Location with line and column numbers.
#[inline(always)]
pub fn source_offset_to_location(&self, offset: int) -> Location {
let mut out = MaybeUninit::<Location>::uninit();
unsafe {
@ -246,6 +250,7 @@ impl Module {
///
/// The return value will never be 0. Also, it is not guaranteed to be
/// unique.
#[inline(always)]
pub fn get_identity_hash(&self) -> NonZeroI32 {
unsafe { NonZeroI32::new_unchecked(v8__Module__GetIdentityHash(self)) }
}
@ -253,6 +258,7 @@ impl Module {
/// Returns the underlying script's id.
///
/// The module must be a SourceTextModule and must not have an Errored status.
#[inline(always)]
pub fn script_id(&self) -> Option<int> {
if !self.is_source_text_module() {
return None;
@ -266,6 +272,7 @@ impl Module {
/// Returns the namespace object of this module.
///
/// The module's status must be at least kInstantiated.
#[inline(always)]
pub fn get_module_namespace(&self) -> Local<Value> {
// Note: the returned value is not actually stored in a HandleScope,
// therefore we don't need a scope object here.
@ -280,6 +287,7 @@ impl Module {
///
/// NOTE: requires to set `--harmony-import-assertions` V8 flag.
#[must_use]
#[inline(always)]
pub fn instantiate_module<'a>(
&self,
scope: &mut HandleScope,
@ -302,6 +310,7 @@ impl Module {
/// kErrored and propagate the thrown exception (which is then also available
/// via |GetException|).
#[must_use]
#[inline(always)]
pub fn evaluate<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -313,11 +322,13 @@ impl Module {
}
/// Returns whether the module is a SourceTextModule.
#[inline(always)]
pub fn is_source_text_module(&self) -> bool {
unsafe { v8__Module__IsSourceTextModule(&*self) }
}
/// Returns whether the module is a SyntheticModule.
#[inline(always)]
pub fn is_synthetic_module(&self) -> bool {
unsafe { v8__Module__IsSyntheticModule(&*self) }
}
@ -327,6 +338,7 @@ impl Module {
/// export_names must not contain duplicates.
/// module_name is used solely for logging/debugging and doesn't affect module
/// behavior.
#[inline(always)]
pub fn create_synthetic_module<'s, 'a>(
scope: &mut HandleScope<'s>,
module_name: Local<String>,
@ -357,6 +369,7 @@ impl Module {
/// of the export_names that were passed in that create_synthetic_module call.
/// Returns Some(true) on success, None if an error was thrown.
#[must_use]
#[inline(always)]
pub fn set_synthetic_module_export(
&self,
scope: &mut HandleScope,
@ -374,6 +387,7 @@ impl Module {
.into()
}
#[inline(always)]
pub fn get_unbound_module_script<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -388,12 +402,14 @@ impl Module {
impl ModuleRequest {
/// Returns the module specifier for this ModuleRequest.
#[inline(always)]
pub fn get_specifier(&self) -> Local<String> {
unsafe { Local::from_raw(v8__ModuleRequest__GetSpecifier(self)) }.unwrap()
}
/// Returns the source code offset of this module request.
/// Use Module::source_offset_to_location to convert this to line/column numbers.
#[inline(always)]
pub fn get_source_offset(&self) -> int {
unsafe { v8__ModuleRequest__GetSourceOffset(self) }
}
@ -410,6 +426,7 @@ impl ModuleRequest {
/// hosts are expected to ignore assertions that they do not support (as
/// opposed to, for example, triggering an error if an unsupported assertion is
/// present).
#[inline(always)]
pub fn get_import_assertions(&self) -> Local<FixedArray> {
unsafe { Local::from_raw(v8__ModuleRequest__GetImportAssertions(self)) }
.unwrap()

View file

@ -15,6 +15,7 @@ impl Name {
///
/// The return value will never be 0. Also, it is not guaranteed to be
/// unique.
#[inline(always)]
pub fn get_identity_hash(&self) -> NonZeroI32 {
unsafe { NonZeroI32::new_unchecked(v8__Name__GetIdentityHash(self)) }
}

View file

@ -23,6 +23,7 @@ extern "C" {
}
impl Number {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
value: f64,
@ -33,12 +34,14 @@ impl Number {
.unwrap()
}
#[inline(always)]
pub fn value(&self) -> f64 {
unsafe { v8__Number__Value(self) }
}
}
impl Integer {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
value: i32,
@ -49,6 +52,7 @@ impl Integer {
.unwrap()
}
#[inline(always)]
pub fn new_from_unsigned<'s>(
scope: &mut HandleScope<'s, ()>,
value: u32,
@ -61,6 +65,7 @@ impl Integer {
.unwrap()
}
#[inline(always)]
pub fn value(&self) -> i64 {
unsafe { v8__Integer__Value(self) }
}
@ -68,6 +73,7 @@ impl Integer {
/// Internal helper function to produce a handle containing a SMI zero value,
/// without the need for the caller to provide (or have entered) a
/// `HandleScope`.
#[inline(always)]
pub(crate) fn zero<'s>() -> Local<'s, Integer> {
// The SMI representation of zero is also zero. In debug builds, double
// check this, so in the unlikely event that V8 changes its internal
@ -84,12 +90,14 @@ impl Integer {
}
impl Uint32 {
#[inline(always)]
pub fn value(&self) -> u32 {
unsafe { v8__Uint32__Value(self) }
}
}
impl Int32 {
#[inline(always)]
pub fn value(&self) -> i32 {
unsafe { v8__Int32__Value(self) }
}

View file

@ -210,6 +210,7 @@ extern "C" {
impl Object {
/// Creates an empty object.
#[inline(always)]
pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Object> {
unsafe { scope.cast_local(|sd| v8__Object__New(sd.get_isolate_ptr())) }
.unwrap()
@ -220,6 +221,7 @@ impl Object {
/// the newly created object won't have a prototype at all). This is similar
/// to Object.create(). All properties will be created as enumerable,
/// configurable and writable properties.
#[inline(always)]
pub fn with_prototype_and_properties<'s>(
scope: &mut HandleScope<'s>,
prototype_or_null: Local<'s, Value>,
@ -245,6 +247,7 @@ impl Object {
/// Set only return Just(true) or Empty(), so if it should never fail, use
/// result.Check().
#[inline(always)]
pub fn set(
&self,
scope: &mut HandleScope,
@ -259,6 +262,7 @@ impl Object {
/// Set only return Just(true) or Empty(), so if it should never fail, use
/// result.Check().
#[inline(always)]
pub fn set_index(
&self,
scope: &mut HandleScope,
@ -273,6 +277,7 @@ impl Object {
/// Set the prototype object. This does not skip objects marked to be
/// skipped by proto and it does not consult the security handler.
#[inline(always)]
pub fn set_prototype(
&self,
scope: &mut HandleScope,
@ -291,6 +296,7 @@ impl Object {
/// or the object is not extensible.
///
/// Returns true on success.
#[inline(always)]
pub fn create_data_property(
&self,
scope: &mut HandleScope,
@ -314,6 +320,7 @@ impl Object {
/// for specifying attributes.
///
/// Returns true on success.
#[inline(always)]
pub fn define_own_property(
&self,
scope: &mut HandleScope,
@ -333,6 +340,7 @@ impl Object {
.into()
}
#[inline(always)]
pub fn get<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -344,6 +352,7 @@ impl Object {
}
}
#[inline(always)]
pub fn get_index<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -358,6 +367,7 @@ impl Object {
/// Get the prototype object. This does not skip objects marked to be
/// skipped by proto and it does not consult the security handler.
#[inline(always)]
pub fn get_prototype<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -366,6 +376,7 @@ impl Object {
}
/// Note: SideEffectType affects the getter only, not the setter.
#[inline(always)]
pub fn set_accessor(
&self,
scope: &mut HandleScope,
@ -383,6 +394,7 @@ impl Object {
.into()
}
#[inline(always)]
pub fn set_accessor_with_setter(
&self,
scope: &mut HandleScope,
@ -407,11 +419,13 @@ impl Object {
///
/// The return value will never be 0. Also, it is not guaranteed to be
/// unique.
#[inline(always)]
pub fn get_identity_hash(&self) -> NonZeroI32 {
unsafe { NonZeroI32::new_unchecked(v8__Object__GetIdentityHash(self)) }
}
/// Returns the context in which the object was created.
#[inline(always)]
pub fn get_creation_context<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -422,6 +436,7 @@ impl Object {
/// This function has the same functionality as GetPropertyNames but the
/// returned array doesn't contain the names of properties from prototype
/// objects.
#[inline(always)]
pub fn get_own_property_names<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -443,6 +458,7 @@ impl Object {
/// object, including properties from prototype objects. The array returned by
/// this method contains the same values as would be enumerated by a for-in
/// statement over this object.
#[inline(always)]
pub fn get_property_names<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -472,6 +488,7 @@ impl Object {
//
// Note: This function converts the key to a name, which possibly calls back
// into JavaScript.
#[inline(always)]
pub fn has<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -481,6 +498,7 @@ impl Object {
.into()
}
#[inline(always)]
pub fn has_index<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -491,6 +509,7 @@ impl Object {
}
/// HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
#[inline(always)]
pub fn has_own_property<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -502,6 +521,7 @@ impl Object {
.into()
}
#[inline(always)]
pub fn delete<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -523,12 +543,14 @@ impl Object {
}
/// Gets the number of internal fields for this Object.
#[inline(always)]
pub fn internal_field_count(&self) -> usize {
let count = unsafe { v8__Object__InternalFieldCount(self) };
usize::try_from(count).expect("bad internal field count") // Can't happen.
}
/// Gets the value from an internal field.
#[inline(always)]
pub fn get_internal_field<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -552,6 +574,7 @@ impl Object {
///
/// # Safety
/// This field must have been set by SetAlignedPointerInInternalField, everything else leads to undefined behavior.
#[inline(always)]
pub unsafe fn get_aligned_pointer_from_internal_field(
&self,
index: i32,
@ -562,6 +585,7 @@ impl Object {
/// Sets a 2-byte-aligned native pointer in an internal field.
/// To retrieve such a field, GetAlignedPointerFromInternalField must be used.
#[allow(clippy::not_unsafe_ptr_arg_deref)]
#[inline(always)]
pub fn set_aligned_pointer_in_internal_field(
&self,
index: i32,
@ -571,6 +595,7 @@ impl Object {
}
/// Sets the integrity level of the object.
#[inline(always)]
pub fn set_integrity_level(
&self,
scope: &mut HandleScope,
@ -584,6 +609,7 @@ impl Object {
/// Sets the value in an internal field. Returns false when the index
/// is out of bounds, true otherwise.
#[inline(always)]
pub fn set_internal_field(&self, index: usize, value: Local<Value>) -> bool {
// Trying to access out-of-bounds internal fields makes V8 abort
// in debug mode and access out-of-bounds memory in release mode.
@ -602,6 +628,7 @@ impl Object {
/// This is an experimental feature, use at your own risk.
/// Note: Private properties are not inherited. Do not rely on this, since it
/// may change.
#[inline(always)]
pub fn get_private<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -618,6 +645,7 @@ impl Object {
/// This is an experimental feature, use at your own risk.
/// Note: Private properties are not inherited. Do not rely on this, since it
/// may change.
#[inline(always)]
pub fn set_private<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -639,6 +667,7 @@ impl Object {
/// This is an experimental feature, use at your own risk.
/// Note: Private properties are not inherited. Do not rely on this, since it
/// may change.
#[inline(always)]
pub fn delete_private<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -654,6 +683,7 @@ impl Object {
/// This is an experimental feature, use at your own risk.
/// Note: Private properties are not inherited. Do not rely on this, since it
/// may change.
#[inline(always)]
pub fn has_private<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -683,6 +713,7 @@ pub enum IntegrityLevel {
impl Array {
/// Creates a JavaScript array with the given length. If the length
/// is negative the returned array will have length 0.
#[inline(always)]
pub fn new<'s>(scope: &mut HandleScope<'s>, length: i32) -> Local<'s, Array> {
unsafe {
scope.cast_local(|sd| v8__Array__New(sd.get_isolate_ptr(), length))
@ -692,6 +723,7 @@ impl Array {
/// Creates a JavaScript array out of a Local<Value> array with a known
/// length.
#[inline(always)]
pub fn new_with_elements<'s>(
scope: &mut HandleScope<'s>,
elements: &[Local<Value>],
@ -712,25 +744,30 @@ impl Array {
.unwrap()
}
#[inline(always)]
pub fn length(&self) -> u32 {
unsafe { v8__Array__Length(self) }
}
}
impl Map {
#[inline(always)]
pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Map> {
unsafe { scope.cast_local(|sd| v8__Map__New(sd.get_isolate_ptr())) }
.unwrap()
}
#[inline(always)]
pub fn size(&self) -> usize {
unsafe { v8__Map__Size(self) }
}
#[inline(always)]
pub fn clear(&self) {
unsafe { v8__Map__Clear(self) }
}
#[inline(always)]
pub fn get<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -741,6 +778,7 @@ impl Map {
}
}
#[inline(always)]
pub fn set<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -754,6 +792,7 @@ impl Map {
}
}
#[inline(always)]
pub fn has(
&self,
scope: &mut HandleScope,
@ -762,6 +801,7 @@ impl Map {
unsafe { v8__Map__Has(self, &*scope.get_current_context(), &*key) }.into()
}
#[inline(always)]
pub fn delete(
&self,
scope: &mut HandleScope,
@ -773,6 +813,7 @@ impl Map {
/// Returns an array of length size() * 2, where index N is the Nth key and
/// index N + 1 is the Nth value.
#[inline(always)]
pub fn as_array<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Array> {
unsafe { scope.cast_local(|_| v8__Map__As__Array(self)) }.unwrap()
}

View file

@ -58,6 +58,7 @@ pub struct Platform(Opaque);
/// If |idle_task_support| is enabled then the platform will accept idle
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
/// calling v8::platform::RunIdleTasks to process the idle tasks.
#[inline(always)]
pub fn new_default_platform(
thread_pool_size: u32,
idle_task_support: bool,
@ -71,6 +72,7 @@ pub fn new_default_platform(
/// If |idle_task_support| is enabled then the platform will accept idle
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
/// calling v8::platform::RunIdleTasks to process the idle tasks.
#[inline(always)]
pub fn new_single_threaded_default_platform(
idle_task_support: bool,
) -> UniqueRef<Platform> {
@ -86,6 +88,7 @@ impl Platform {
/// If |idle_task_support| is enabled then the platform will accept idle
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
/// calling v8::platform::RunIdleTasks to process the idle tasks.
#[inline(always)]
pub fn new(
thread_pool_size: u32,
idle_task_support: bool,
@ -104,6 +107,7 @@ impl Platform {
/// If |idle_task_support| is enabled then the platform will accept idle
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
/// calling v8::platform::RunIdleTasks to process the idle tasks.
#[inline(always)]
pub fn new_single_threaded(idle_task_support: bool) -> UniqueRef<Self> {
unsafe {
UniqueRef::from_raw(v8__Platform__NewSingleThreadedDefaultPlatform(
@ -121,6 +125,7 @@ impl Platform {
/// PumpMessageLoop is nested within another call to PumpMessageLoop, only
/// nestable tasks may run. Otherwise, any task may run. Unless requested through
/// the |wait_for_work| parameter, this call does not block if no task is pending.
#[inline(always)]
pub fn pump_message_loop(
platform: &SharedRef<Self>,
isolate: &mut Isolate,
@ -139,6 +144,7 @@ impl Platform {
///
/// The caller has to make sure that this is called from the right thread.
/// This call does not block if no task is pending.
#[inline(always)]
pub fn run_idle_tasks(
platform: &SharedRef<Self>,
isolate: &mut Isolate,

View file

@ -29,6 +29,7 @@ extern "C" {
}
impl PrimitiveArray {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
length: usize,
@ -41,10 +42,12 @@ impl PrimitiveArray {
.unwrap()
}
#[inline(always)]
pub fn length(&self) -> usize {
unsafe { v8__PrimitiveArray__Length(self) as usize }
}
#[inline(always)]
pub fn set<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -61,6 +64,7 @@ impl PrimitiveArray {
}
}
#[inline(always)]
pub fn get<'s>(
&self,
scope: &mut HandleScope<'s>,

View file

@ -11,15 +11,18 @@ extern "C" {
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *const Boolean;
}
#[inline(always)]
pub fn null<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Primitive> {
unsafe { scope.cast_local(|sd| v8__Null(sd.get_isolate_ptr())) }.unwrap()
}
#[inline(always)]
pub fn undefined<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Primitive> {
unsafe { scope.cast_local(|sd| v8__Undefined(sd.get_isolate_ptr())) }.unwrap()
}
impl Boolean {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
value: bool,

View file

@ -19,6 +19,7 @@ extern "C" {
impl Private {
/// Create a private symbol. If name is not empty, it will be the description.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
name: Option<Local<String>>,
@ -41,6 +42,7 @@ impl Private {
/// Also, there is only one global name space for the names used as keys.
/// To minimize the potential for clashes, use qualified names as keys,
/// e.g., "Class#property".
#[inline(always)]
pub fn for_api<'s>(
scope: &mut HandleScope<'s, ()>,
name: Option<Local<String>>,
@ -57,6 +59,7 @@ impl Private {
}
/// Returns the print name string of the private symbol, or undefined if none.
#[inline(always)]
pub fn name<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Private__Name(&*self)) }.unwrap()
}

View file

@ -67,18 +67,21 @@ pub enum PromiseState {
impl Promise {
/// Returns the value of the [[PromiseState]] field.
#[inline(always)]
pub fn state(&self) -> PromiseState {
unsafe { v8__Promise__State(&*self) }
}
/// Returns true if the promise has at least one derived promise, and
/// therefore resolve/reject handlers (including default handler).
#[inline(always)]
pub fn has_handler(&self) -> bool {
unsafe { v8__Promise__HasHandler(&*self) }
}
/// Returns the content of the [[PromiseResult]] field. The Promise must not
/// be pending.
#[inline(always)]
pub fn result<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Promise__Result(&*self)) }.unwrap()
}
@ -86,6 +89,7 @@ impl Promise {
/// Register a rejection handler with a promise.
///
/// See `Self::then2`.
#[inline(always)]
pub fn catch<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -101,6 +105,7 @@ impl Promise {
/// Register a resolution handler with a promise.
///
/// See `Self::then2`.
#[inline(always)]
pub fn then<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -117,6 +122,7 @@ impl Promise {
/// The handler is given the respective resolution/rejection value as
/// an argument. If the promise is already resolved/rejected, the handler is
/// invoked at the end of turn.
#[inline(always)]
pub fn then2<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -138,6 +144,7 @@ impl Promise {
impl PromiseResolver {
/// Create a new resolver, along with an associated promise in pending state.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
) -> Option<Local<'s, PromiseResolver>> {
@ -148,6 +155,7 @@ impl PromiseResolver {
}
/// Extract the associated promise.
#[inline(always)]
pub fn get_promise<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -158,6 +166,7 @@ impl PromiseResolver {
/// Resolve the associated promise with a given value.
/// Ignored if the promise is no longer pending.
#[inline(always)]
pub fn resolve(
&self,
scope: &mut HandleScope,
@ -175,6 +184,7 @@ impl PromiseResolver {
/// Reject the associated promise with a given value.
/// Ignored if the promise is no longer pending.
#[inline(always)]
pub fn reject(
&self,
scope: &mut HandleScope,
@ -205,15 +215,18 @@ pub enum PromiseRejectEvent {
pub struct PromiseRejectMessage<'msg>([usize; 3], PhantomData<&'msg ()>);
impl<'msg> PromiseRejectMessage<'msg> {
#[inline(always)]
pub fn get_promise(&self) -> Local<'msg, Promise> {
unsafe { Local::from_raw(v8__PromiseRejectMessage__GetPromise(self)) }
.unwrap()
}
#[inline(always)]
pub fn get_event(&self) -> PromiseRejectEvent {
unsafe { v8__PromiseRejectMessage__GetEvent(self) }
}
#[inline(always)]
pub fn get_value(&self) -> Option<Local<'msg, Value>> {
unsafe { Local::from_raw(v8__PromiseRejectMessage__GetValue(self)) }
}

View file

@ -19,25 +19,30 @@ pub const DONT_DELETE: PropertyAttribute = PropertyAttribute(4);
impl PropertyAttribute {
/// Test if no property attributes are set.
#[inline(always)]
pub fn is_none(&self) -> bool {
*self == NONE
}
/// Test if the read-only property attribute is set.
#[inline(always)]
pub fn is_read_only(&self) -> bool {
self.has(READ_ONLY)
}
/// Test if the non-enumerable property attribute is set.
#[inline(always)]
pub fn is_dont_enum(&self) -> bool {
self.has(DONT_ENUM)
}
/// Test if the non-configurable property attribute is set.
#[inline(always)]
pub fn is_dont_delete(&self) -> bool {
self.has(DONT_DELETE)
}
#[inline(always)]
fn has(&self, that: Self) -> bool {
let Self(lhs) = self;
let Self(rhs) = that;

View file

@ -16,35 +16,42 @@ pub const SKIP_SYMBOLS: PropertyFilter = PropertyFilter(16);
impl PropertyFilter {
/// Test if all property filters are set.
#[inline(always)]
pub fn is_all_properties(&self) -> bool {
*self == ALL_PROPERTIES
}
/// Test if the only-writable property filter is set.
#[inline(always)]
pub fn is_only_writable(&self) -> bool {
self.has(ONLY_WRITABLE)
}
/// Test if the only-enumerable property filter is set.
#[inline(always)]
pub fn is_only_enumerable(&self) -> bool {
self.has(ONLY_ENUMERABLE)
}
/// Test if the only-configurable property filter is set.
#[inline(always)]
pub fn is_only_configurable(&self) -> bool {
self.has(ONLY_CONFIGURABLE)
}
/// Test if the skip-strings property filter is set.
#[inline(always)]
pub fn is_skip_strings(&self) -> bool {
self.has(SKIP_STRINGS)
}
/// Test if the skip-symbols property filter is set.
#[inline(always)]
pub fn is_skip_symbols(&self) -> bool {
self.has(SKIP_SYMBOLS)
}
#[inline(always)]
fn has(&self, that: Self) -> bool {
let Self(lhs) = self;
let Self(rhs) = that;

View file

@ -18,6 +18,7 @@ extern "C" {
}
impl Proxy {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
target: Local<Object>,
@ -30,6 +31,7 @@ impl Proxy {
}
}
#[inline(always)]
pub fn get_handler<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -37,6 +39,7 @@ impl Proxy {
unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap()
}
#[inline(always)]
pub fn get_target<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -44,10 +47,12 @@ impl Proxy {
unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap()
}
#[inline(always)]
pub fn is_revoked(&self) -> bool {
unsafe { v8__Proxy__IsRevoked(self) }
}
#[inline(always)]
pub fn revoke(&self) {
unsafe { v8__Proxy__Revoke(self) };
}

View file

@ -179,6 +179,7 @@ impl<'s> HandleScope<'s> {
/// Returns the context of the currently running JavaScript, or the context
/// on the top of the stack if no JavaScript is running.
#[inline(always)]
pub fn get_current_context(&self) -> Local<'s, Context> {
let context_ptr = data::ScopeData::get(self).get_current_context();
unsafe { Local::from_raw(context_ptr) }.unwrap()
@ -205,6 +206,7 @@ impl<'s> HandleScope<'s, ()> {
/// JavaScript operations.
///
/// This function always returns the `undefined` value.
#[inline(always)]
pub fn throw_exception(
&mut self,
exception: Local<Value>,
@ -217,6 +219,7 @@ impl<'s> HandleScope<'s, ()> {
.unwrap()
}
#[inline(always)]
pub(crate) unsafe fn cast_local<T>(
&mut self,
f: impl FnOnce(&mut data::ScopeData) -> *const T,
@ -224,6 +227,7 @@ impl<'s> HandleScope<'s, ()> {
Local::from_raw(f(data::ScopeData::get_mut(self)))
}
#[inline(always)]
pub(crate) fn get_isolate_ptr(&self) -> *mut Isolate {
data::ScopeData::get(self).get_isolate_ptr()
}
@ -342,6 +346,7 @@ impl<'s, P: param::NewTryCatch<'s>> TryCatch<'s, P> {
impl<'s, P> TryCatch<'s, P> {
/// Returns true if an exception has been caught by this try/catch block.
#[inline(always)]
pub fn has_caught(&self) -> bool {
unsafe { raw::v8__TryCatch__HasCaught(self.get_raw()) }
}
@ -352,6 +357,7 @@ impl<'s, P> TryCatch<'s, P> {
/// cleanup needed and then return. If CanContinue returns false and
/// HasTerminated returns true, it is possible to call
/// CancelTerminateExecution in order to continue calling into the engine.
#[inline(always)]
pub fn can_continue(&self) -> bool {
unsafe { raw::v8__TryCatch__CanContinue(self.get_raw()) }
}
@ -366,11 +372,13 @@ impl<'s, P> TryCatch<'s, P> {
/// If such an exception has been thrown, HasTerminated will return true,
/// indicating that it is possible to call CancelTerminateExecution in order
/// to continue calling into the engine.
#[inline(always)]
pub fn has_terminated(&self) -> bool {
unsafe { raw::v8__TryCatch__HasTerminated(self.get_raw()) }
}
/// Returns true if verbosity is enabled.
#[inline(always)]
pub fn is_verbose(&self) -> bool {
unsafe { raw::v8__TryCatch__IsVerbose(self.get_raw()) }
}
@ -381,6 +389,7 @@ impl<'s, P> TryCatch<'s, P> {
/// handler are not reported. Call SetVerbose with true on an
/// external exception handler to have exceptions caught by the
/// handler reported as if they were not caught.
#[inline(always)]
pub fn set_verbose(&mut self, value: bool) {
unsafe { raw::v8__TryCatch__SetVerbose(self.get_raw_mut(), value) };
}
@ -388,6 +397,7 @@ impl<'s, P> TryCatch<'s, P> {
/// Set whether or not this TryCatch should capture a Message object
/// which holds source information about where the exception
/// occurred. True by default.
#[inline(always)]
pub fn set_capture_message(&mut self, value: bool) {
unsafe { raw::v8__TryCatch__SetCaptureMessage(self.get_raw_mut(), value) };
}
@ -401,14 +411,17 @@ impl<'s, P> TryCatch<'s, P> {
/// another exception is thrown the previously caught exception will just be
/// overwritten. However, it is often a good idea since it makes it easier
/// to determine which operation threw a given exception.
#[inline(always)]
pub fn reset(&mut self) {
unsafe { raw::v8__TryCatch__Reset(self.get_raw_mut()) };
}
#[inline(always)]
fn get_raw(&self) -> &raw::TryCatch {
data::ScopeData::get(self).get_try_catch()
}
#[inline(always)]
fn get_raw_mut(&mut self) -> &mut raw::TryCatch {
data::ScopeData::get_mut(self).get_try_catch_mut()
}

View file

@ -47,6 +47,7 @@ extern "C" {
impl Script {
/// A shorthand for ScriptCompiler::Compile().
#[inline(always)]
pub fn compile<'s>(
scope: &mut HandleScope<'s>,
source: Local<String>,
@ -64,6 +65,7 @@ impl Script {
}
/// Returns the corresponding context-unbound script.
#[inline(always)]
pub fn get_unbound_script<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -78,6 +80,7 @@ impl Script {
/// Runs the script returning the resulting value. It will be run in the
/// context in which it was created (ScriptCompiler::CompileBound or
/// UnboundScript::BindToCurrentContext()).
#[inline(always)]
pub fn run<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -91,6 +94,7 @@ impl Script {
/// The origin, within a file, of a script.
impl<'s> ScriptOrigin<'s> {
#[allow(clippy::too_many_arguments)]
#[inline(always)]
pub fn new(
scope: &mut HandleScope<'s, ()>,
resource_name: Local<'s, Value>,

View file

@ -111,6 +111,7 @@ impl<'a> CachedData<'a> {
cached_data
}
#[inline(always)]
pub(crate) fn buffer_policy(&self) -> BufferPolicy {
self.buffer_policy
}
@ -132,6 +133,7 @@ pub(crate) enum BufferPolicy {
}
impl Source {
#[inline(always)]
pub fn new(
source_string: Local<String>,
origin: Option<&ScriptOrigin>,
@ -148,6 +150,7 @@ impl Source {
}
}
#[inline(always)]
pub fn new_with_cached_data(
source_string: Local<String>,
origin: Option<&ScriptOrigin>,
@ -165,6 +168,7 @@ impl Source {
}
}
#[inline(always)]
pub fn get_cached_data(&self) -> Option<&CachedData> {
unsafe {
let cached_data = v8__ScriptCompiler__Source__GetCachedData(self);
@ -217,6 +221,7 @@ pub enum NoCacheReason {
///
/// Corresponds to the ParseModule abstract operation in the ECMAScript
/// specification.
#[inline(always)]
pub fn compile_module<'s>(
scope: &mut HandleScope<'s>,
source: Source,
@ -230,6 +235,7 @@ pub fn compile_module<'s>(
}
/// Same as compile_module with more options.
#[inline(always)]
pub fn compile_module2<'s>(
scope: &mut HandleScope<'s>,
mut source: Source,
@ -248,6 +254,7 @@ pub fn compile_module2<'s>(
}
}
#[inline(always)]
pub fn compile<'s>(
scope: &mut HandleScope<'s>,
mut source: Source,
@ -266,6 +273,7 @@ pub fn compile<'s>(
}
}
#[inline(always)]
pub fn compile_function<'s>(
scope: &mut HandleScope<'s>,
mut source: Source,
@ -292,6 +300,7 @@ pub fn compile_function<'s>(
}
}
#[inline(always)]
pub fn compile_unbound_script<'s>(
scope: &mut HandleScope<'s>,
mut source: Source,
@ -325,6 +334,7 @@ pub fn compile_unbound_script<'s>(
///
/// Alternatively, this tag can be stored alongside the cached data and compared
/// when it is being used.
#[inline(always)]
pub fn cached_data_version_tag() -> u32 {
unsafe { v8__ScriptCompiler__CachedDataVersionTag() }
}

View file

@ -17,6 +17,7 @@ extern "C" {
impl ScriptOrModule {
/// The name that was passed by the embedder as ResourceName to the
/// ScriptOrigin. This can be either a v8::String or v8::Undefined.
#[inline(always)]
pub fn get_resource_name(&self) -> Local<Value> {
// Note: the C++ `v8::ScriptOrModule::GetResourceName()` does not actually
// return a local handle, but rather a handle whose lifetime is bound to
@ -29,6 +30,7 @@ impl ScriptOrModule {
/// The options that were passed by the embedder as HostDefinedOptions to the
/// ScriptOrigin.
#[inline(always)]
pub fn host_defined_options(&self) -> Local<Data> {
// Note: the C++ `v8::ScriptOrModule::HostDefinedOptions()` does not
// actually return a local handle, but rather a handle whose lifetime is

View file

@ -45,6 +45,7 @@ impl SharedArrayBuffer {
/// Allocated memory will be owned by a created SharedArrayBuffer and
/// will be deallocated when it is garbage-collected,
/// unless the object is externalized.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
byte_length: usize,
@ -59,6 +60,7 @@ impl SharedArrayBuffer {
}
}
#[inline(always)]
pub fn with_backing_store<'s>(
scope: &mut HandleScope<'s>,
backing_store: &SharedRef<BackingStore>,
@ -75,6 +77,7 @@ impl SharedArrayBuffer {
}
/// Data length in bytes.
#[inline(always)]
pub fn byte_length(&self) -> usize {
unsafe { v8__SharedArrayBuffer__ByteLength(self) }
}
@ -83,6 +86,7 @@ impl SharedArrayBuffer {
/// pointer coordinates the lifetime management of the internal storage
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
/// should not attempt to manage lifetime of the storage through other means.
#[inline(always)]
pub fn get_backing_store(&self) -> SharedRef<BackingStore> {
unsafe { v8__SharedArrayBuffer__GetBackingStore(self) }
}
@ -94,6 +98,7 @@ impl SharedArrayBuffer {
/// If the allocator returns nullptr, then the function may cause GCs in the
/// given isolate and re-try the allocation. If GCs do not help, then the
/// function will crash with an out-of-memory error.
#[inline(always)]
pub fn new_backing_store(
scope: &mut Isolate,
byte_length: usize,
@ -115,6 +120,7 @@ impl SharedArrayBuffer {
///
/// The result can be later passed to SharedArrayBuffer::New. The raw pointer
/// to the buffer must not be passed again to any V8 API function.
#[inline(always)]
pub fn new_backing_store_from_boxed_slice(
data: Box<[u8]>,
) -> UniqueRef<BackingStore> {
@ -137,6 +143,7 @@ impl SharedArrayBuffer {
///
/// The result can be later passed to SharedArrayBuffer::New. The raw pointer
/// to the buffer must not be passed again to any V8 API function.
#[inline(always)]
pub fn new_backing_store_from_vec(
mut data: Vec<u8>,
) -> UniqueRef<BackingStore> {

View file

@ -94,6 +94,7 @@ pub struct SnapshotCreator([usize; 1]);
impl SnapshotCreator {
/// Create and enter an isolate, and set it up for serialization.
/// The isolate is created from scratch.
#[inline(always)]
pub fn new(external_references: Option<&'static ExternalReferences>) -> Self {
let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit();
let external_references_ptr = if let Some(er) = external_references {
@ -121,6 +122,7 @@ impl SnapshotCreator {
/// Set the default context to be included in the snapshot blob.
/// The snapshot will not contain the global proxy, and we expect one or a
/// global object template to create one, to be provided upon deserialization.
#[inline(always)]
pub fn set_default_context(&mut self, context: Local<Context>) {
unsafe { v8__SnapshotCreator__SetDefaultContext(self, &*context) };
}
@ -129,6 +131,7 @@ impl SnapshotCreator {
/// retrieved via `HandleScope::get_context_data_from_snapshot_once()` after
/// deserialization. This data does not survive when a new snapshot is created
/// from an existing snapshot.
#[inline(always)]
pub fn add_isolate_data<T>(&mut self, data: Local<T>) -> usize
where
for<'l> Local<'l, T>: Into<Local<'l, Data>>,
@ -140,6 +143,7 @@ impl SnapshotCreator {
/// retrieved via `HandleScope::get_context_data_from_snapshot_once()` after
/// deserialization. This data does not survive when a new snapshot is
/// created from an existing snapshot.
#[inline(always)]
pub fn add_context_data<T>(
&mut self,
context: Local<Context>,
@ -155,6 +159,7 @@ impl SnapshotCreator {
/// Creates a snapshot data blob.
/// This must not be called from within a handle scope.
#[inline(always)]
pub fn create_blob(
&mut self,
function_code_handling: FunctionCodeHandling,
@ -179,6 +184,7 @@ impl SnapshotCreator {
// TODO Because the SnapshotCreator creates its own isolate, we need a way to
// get an owned handle to it. This is a questionable design which ought to be
// revisited after the libdeno integration is complete.
#[inline(always)]
pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate {
let isolate_ptr = v8__SnapshotCreator__GetIsolate(self);
let mut owned_isolate = OwnedIsolate::new(isolate_ptr);

View file

@ -120,10 +120,12 @@ impl String {
/// The maximum length (in bytes) of a buffer that a v8::String can be built
/// from. Attempting to create a v8::String from a larger buffer will result
/// in None being returned.
#[inline(always)]
pub fn max_length() -> usize {
unsafe { v8__String__kMaxLength() }
}
#[inline(always)]
pub fn empty<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, String> {
// FIXME(bnoordhuis) v8__String__Empty() is infallible so there
// is no need to box up the result, only to unwrap it again.
@ -133,6 +135,7 @@ impl String {
/// Allocates a new string from UTF-8 data. Only returns an empty value when
/// length > kMaxLength
#[inline(always)]
pub fn new_from_utf8<'s>(
scope: &mut HandleScope<'s, ()>,
buffer: &[u8],
@ -156,6 +159,7 @@ impl String {
/// Allocates a new string from Latin-1 data. Only returns an empty value when
/// length > kMaxLength.
#[inline(always)]
pub fn new_from_one_byte<'s>(
scope: &mut HandleScope<'s, ()>,
buffer: &[u8],
@ -176,6 +180,7 @@ impl String {
/// Allocates a new string from UTF-16 data. Only returns an empty value when
/// length > kMaxLength.
#[inline(always)]
pub fn new_from_two_byte<'s>(
scope: &mut HandleScope<'s, ()>,
buffer: &[u16],
@ -195,18 +200,21 @@ impl String {
}
/// Returns the number of characters (UTF-16 code units) in this string.
#[inline(always)]
pub fn length(&self) -> usize {
unsafe { v8__String__Length(self) as usize }
}
/// Returns the number of bytes in the UTF-8 encoded representation of this
/// string.
#[inline(always)]
pub fn utf8_length(&self, scope: &mut Isolate) -> usize {
unsafe { v8__String__Utf8Length(self, scope) as usize }
}
/// Writes the contents of the string to an external buffer, as 16-bit
/// (UTF-16) character codes.
#[inline(always)]
pub fn write(
&self,
scope: &mut Isolate,
@ -228,6 +236,7 @@ impl String {
/// Writes the contents of the string to an external buffer, as one-byte
/// (Latin-1) characters.
#[inline(always)]
pub fn write_one_byte(
&self,
scope: &mut Isolate,
@ -248,6 +257,7 @@ impl String {
}
/// Writes the contents of the string to an external buffer, as UTF-8.
#[inline(always)]
pub fn write_utf8(
&self,
scope: &mut Isolate,
@ -273,6 +283,7 @@ impl String {
}
// Convenience function not present in the original V8 API.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
value: &str,
@ -282,6 +293,7 @@ impl String {
// Creates a v8::String from a `&'static [u8]`,
// must be Latin-1 or ASCII, not UTF-8 !
#[inline(always)]
pub fn new_external_onebyte_static<'s>(
scope: &mut HandleScope<'s, ()>,
buffer: &'static [u8],
@ -299,6 +311,7 @@ impl String {
}
// Creates a v8::String from a `&'static [u16]`.
#[inline(always)]
pub fn new_external_twobyte_static<'s>(
scope: &mut HandleScope<'s, ()>,
buffer: &'static [u16],
@ -316,6 +329,7 @@ impl String {
}
/// True if string is external
#[inline(always)]
pub fn is_external(&self) -> bool {
// TODO: re-enable on next v8-release
// Right now it fallbacks to Value::IsExternal, which is incorrect
@ -328,12 +342,14 @@ impl String {
/// True if string is external & one-byte
/// (e.g: created with new_external_onebyte_static)
#[inline(always)]
pub fn is_external_onebyte(&self) -> bool {
unsafe { v8__String__IsExternalOneByte(self) }
}
/// True if string is external & two-byte
/// (e.g: created with new_external_twobyte_static)
#[inline(always)]
pub fn is_external_twobyte(&self) -> bool {
unsafe { v8__String__IsExternalTwoByte(self) }
}
@ -345,17 +361,20 @@ impl String {
/// potentially reading the entire string, use [`contains_only_onebyte()`].
///
/// [`contains_only_onebyte()`]: String::contains_only_onebyte
#[inline(always)]
pub fn is_onebyte(&self) -> bool {
unsafe { v8__String__IsExternalOneByte(self) }
}
/// True if the string contains only one-byte data.
/// Will read the entire string in some cases.
#[inline(always)]
pub fn contains_only_onebyte(&self) -> bool {
unsafe { v8__String__ContainsOnlyOneByte(self) }
}
/// Convenience function not present in the original V8 API.
#[inline(always)]
pub fn to_rust_string_lossy(
&self,
scope: &mut Isolate,

View file

@ -34,6 +34,7 @@ macro_rules! well_known {
impl Symbol {
/// Create a symbol. If description is not empty, it will be used as the
/// description.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
description: Option<Local<String>>,
@ -56,6 +57,7 @@ impl Symbol {
/// keys.
/// To minimize the potential for clashes, use qualified descriptions as keys.
/// Corresponds to v8::Symbol::For() in C++.
#[inline(always)]
pub fn for_global<'s>(
scope: &mut HandleScope<'s, ()>,
description: Local<String>,
@ -69,6 +71,7 @@ impl Symbol {
}
/// Returns the description string of the symbol, or undefined if none.
#[inline(always)]
pub fn description<'s>(
&self,
scope: &mut HandleScope<'s, ()>,

View file

@ -112,12 +112,14 @@ extern "C" {
impl Template {
/// Adds a property to each instance created by this template.
#[inline(always)]
pub fn set(&self, key: Local<Name>, value: Local<Data>) {
self.set_with_attr(key, value, NONE)
}
/// Adds a property to each instance created by this template with
/// the specified property attributes.
#[inline(always)]
pub fn set_with_attr(
&self,
key: Local<Name>,
@ -130,12 +132,14 @@ impl Template {
impl<'s> FunctionBuilder<'s, FunctionTemplate> {
/// Set the function call signature. The default is no signature.
#[inline(always)]
pub fn signature(mut self, signature: Local<'s, Signature>) -> Self {
self.signature = Some(signature);
self
}
/// Creates the function template.
#[inline(always)]
pub fn build(
self,
scope: &mut HandleScope<'s, ()>,
@ -208,6 +212,7 @@ impl<'s> FunctionBuilder<'s, FunctionTemplate> {
/// from a FunctionTemplate that inherits directly or indirectly from the
/// signature's FunctionTemplate.
impl Signature {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
templ: Local<FunctionTemplate>,
@ -222,12 +227,14 @@ impl Signature {
impl FunctionTemplate {
/// Create a FunctionBuilder to configure a FunctionTemplate.
/// This is the same as FunctionBuilder::<FunctionTemplate>::new().
#[inline(always)]
pub fn builder<'s>(
callback: impl MapFnTo<FunctionCallback>,
) -> FunctionBuilder<'s, Self> {
FunctionBuilder::new(callback)
}
#[inline(always)]
pub fn builder_raw<'s>(
callback: FunctionCallback,
) -> FunctionBuilder<'s, Self> {
@ -235,6 +242,7 @@ impl FunctionTemplate {
}
/// Creates a function template.
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
callback: impl MapFnTo<FunctionCallback>,
@ -242,6 +250,7 @@ impl FunctionTemplate {
Self::builder(callback).build(scope)
}
#[inline(always)]
pub fn new_raw<'s>(
scope: &mut HandleScope<'s, ()>,
callback: FunctionCallback,
@ -250,6 +259,7 @@ impl FunctionTemplate {
}
/// Returns the unique function instance in the current execution context.
#[inline(always)]
pub fn get_function<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -264,12 +274,14 @@ impl FunctionTemplate {
/// Set the class name of the FunctionTemplate. This is used for
/// printing objects created with the function created from the
/// FunctionTemplate as its constructor.
#[inline(always)]
pub fn set_class_name(&self, name: Local<String>) {
unsafe { v8__FunctionTemplate__SetClassName(self, &*name) };
}
/// Returns the ObjectTemplate that is used by this
/// FunctionTemplate as a PrototypeTemplate
#[inline(always)]
pub fn prototype_template<'s>(
&self,
scope: &mut HandleScope<'s, ()>,
@ -282,6 +294,7 @@ impl FunctionTemplate {
/// Returns the object template that is used for instances created when this function
/// template is called as a constructor.
#[inline(always)]
pub fn instance_template<'s>(
&self,
scope: &mut HandleScope<'s, ()>,
@ -294,17 +307,20 @@ impl FunctionTemplate {
/// Causes the function template to inherit from a parent function template.
/// This means the function's prototype.__proto__ is set to the parent function's prototype.
#[inline(always)]
pub fn inherit(&self, parent: Local<FunctionTemplate>) {
unsafe { v8__FunctionTemplate__Inherit(self, &*parent) };
}
/// Sets the ReadOnly flag in the attributes of the 'prototype' property
/// of functions created from this FunctionTemplate to true.
#[inline(always)]
pub fn read_only_prototype(&self) {
unsafe { v8__FunctionTemplate__ReadOnlyPrototype(self) };
}
/// Removes the prototype property from functions created from this FunctionTemplate.
#[inline(always)]
pub fn remove_prototype(&self) {
unsafe { v8__FunctionTemplate__RemovePrototype(self) };
}
@ -312,6 +328,7 @@ impl FunctionTemplate {
impl ObjectTemplate {
/// Creates an object template.
#[inline(always)]
pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, ObjectTemplate> {
unsafe {
scope.cast_local(|sd| {
@ -322,6 +339,7 @@ impl ObjectTemplate {
}
/// Creates an object template from a function template.
#[inline(always)]
pub fn new_from_template<'s>(
scope: &mut HandleScope<'s, ()>,
templ: Local<FunctionTemplate>,
@ -334,6 +352,7 @@ impl ObjectTemplate {
}
/// Creates a new instance of this object template.
#[inline(always)]
pub fn new_instance<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -347,6 +366,7 @@ impl ObjectTemplate {
/// Gets the number of internal fields for objects generated from
/// this template.
#[inline(always)]
pub fn internal_field_count(&self) -> usize {
let count = unsafe { v8__ObjectTemplate__InternalFieldCount(self) };
usize::try_from(count).expect("bad internal field count") // Can't happen.
@ -354,6 +374,7 @@ impl ObjectTemplate {
/// Sets the number of internal fields for objects generated from
/// this template.
#[inline(always)]
pub fn set_internal_field_count(&self, value: usize) -> bool {
// The C++ API takes an i32 but trying to set a value < 0
// results in unpredictable behavior, hence we disallow it.
@ -366,6 +387,7 @@ impl ObjectTemplate {
}
}
#[inline(always)]
pub fn set_accessor(
&self,
key: Local<Name>,
@ -374,6 +396,7 @@ impl ObjectTemplate {
unsafe { v8__ObjectTemplate__SetAccessor(self, &*key, getter.map_fn_to()) }
}
#[inline(always)]
pub fn set_accessor_with_setter(
&self,
key: Local<Name>,
@ -396,6 +419,7 @@ impl ObjectTemplate {
/// # Panics
///
/// Panics if both `getter` and `setter` are `None`.
#[inline(always)]
pub fn set_accessor_property(
&self,
key: Local<Name>,
@ -416,6 +440,7 @@ impl ObjectTemplate {
/// Makes the ObjectTemplate for an immutable prototype exotic object,
/// with an immutable proto.
#[inline(always)]
pub fn set_immutable_proto(&self) {
unsafe { v8__ObjectTemplate__SetImmutableProto(self) };
}

View file

@ -12,6 +12,7 @@ impl TypedArray {
/// The maximum length (in bytes) of the buffer backing a v8::TypedArray
/// instance. Attempting to create a v8::ArrayBuffer from a larger buffer will
/// result in a fatal error.
#[inline(always)]
pub fn max_length() -> usize {
unsafe { v8__TypedArray__kMaxLength() }
}
@ -21,6 +22,7 @@ macro_rules! typed_array {
($name:ident, $func:ident) => {
use crate::$name;
impl $name {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
buf: Local<ArrayBuffer>,

View file

@ -12,6 +12,7 @@ impl UnboundModuleScript {
/// Creates and returns code cache for the specified unbound_module_script.
/// This will return nullptr if the script cannot be serialized. The
/// CachedData returned by this function should be owned by the caller.
#[inline(always)]
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
let code_cache = unsafe {
UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self))

View file

@ -15,6 +15,7 @@ extern "C" {
impl UnboundScript {
/// Binds the script to the currently entered context.
#[inline(always)]
pub fn bind_to_current_context<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -28,6 +29,7 @@ impl UnboundScript {
/// Creates and returns code cache for the specified unbound_script.
/// This will return nullptr if the script cannot be serialized. The
/// CachedData returned by this function should be owned by the caller.
#[inline(always)]
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
let code_cache = unsafe {
UniqueRef::try_from_raw(v8__UnboundScript__CreateCodeCache(self))

View file

@ -146,17 +146,20 @@ extern "C" {
impl Value {
/// Returns true if this value is the undefined value. See ECMA-262 4.3.10.
#[inline(always)]
pub fn is_undefined(&self) -> bool {
unsafe { v8__Value__IsUndefined(self) }
}
/// Returns true if this value is the null value. See ECMA-262 4.3.11.
#[inline(always)]
pub fn is_null(&self) -> bool {
unsafe { v8__Value__IsNull(self) }
}
/// Returns true if this value is either the null or the undefined value.
/// See ECMA-262 4.3.11. and 4.3.12
#[inline(always)]
pub fn is_null_or_undefined(&self) -> bool {
unsafe { v8__Value__IsNullOrUndefined(self) }
}
@ -165,6 +168,7 @@ impl Value {
/// This is not the same as `BooleanValue()`. The latter performs a
/// conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas
/// this checks `value === true`.
#[inline(always)]
pub fn is_true(&self) -> bool {
unsafe { v8__Value__IsTrue(self) }
}
@ -173,6 +177,7 @@ impl Value {
/// This is not the same as `!BooleanValue()`. The latter performs a
/// conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas
/// this checks `value === false`.
#[inline(always)]
pub fn is_false(&self) -> bool {
unsafe { v8__Value__IsFalse(self) }
}
@ -180,265 +185,317 @@ impl Value {
/// Returns true if this value is a symbol or a string.
/// This is equivalent to
/// `typeof value === 'string' || typeof value === 'symbol'` in JS.
#[inline(always)]
pub fn is_name(&self) -> bool {
unsafe { v8__Value__IsName(self) }
}
/// Returns true if this value is an instance of the String type.
/// See ECMA-262 8.4.
#[inline(always)]
pub fn is_string(&self) -> bool {
unsafe { v8__Value__IsString(self) }
}
/// Returns true if this value is a symbol.
/// This is equivalent to `typeof value === 'symbol'` in JS.
#[inline(always)]
pub fn is_symbol(&self) -> bool {
unsafe { v8__Value__IsSymbol(self) }
}
/// Returns true if this value is a function.
#[inline(always)]
pub fn is_function(&self) -> bool {
unsafe { v8__Value__IsFunction(self) }
}
/// Returns true if this value is an array. Note that it will return false for
/// an Proxy for an array.
#[inline(always)]
pub fn is_array(&self) -> bool {
unsafe { v8__Value__IsArray(self) }
}
/// Returns true if this value is an object.
#[inline(always)]
pub fn is_object(&self) -> bool {
unsafe { v8__Value__IsObject(self) }
}
/// Returns true if this value is a bigint.
/// This is equivalent to `typeof value === 'bigint'` in JS.
#[inline(always)]
pub fn is_big_int(&self) -> bool {
unsafe { v8__Value__IsBigInt(self) }
}
/// Returns true if this value is boolean.
/// This is equivalent to `typeof value === 'boolean'` in JS.
#[inline(always)]
pub fn is_boolean(&self) -> bool {
unsafe { v8__Value__IsBoolean(self) }
}
/// Returns true if this value is a number.
#[inline(always)]
pub fn is_number(&self) -> bool {
unsafe { v8__Value__IsNumber(self) }
}
/// Returns true if this value is an `External` object.
#[inline(always)]
pub fn is_external(&self) -> bool {
unsafe { v8__Value__IsExternal(self) }
}
/// Returns true if this value is a 32-bit signed integer.
#[inline(always)]
pub fn is_int32(&self) -> bool {
unsafe { v8__Value__IsInt32(self) }
}
/// Returns true if this value is a 32-bit unsigned integer.
#[inline(always)]
pub fn is_uint32(&self) -> bool {
unsafe { v8__Value__IsUint32(self) }
}
/// Returns true if this value is a Date.
#[inline(always)]
pub fn is_date(&self) -> bool {
unsafe { v8__Value__IsDate(self) }
}
/// Returns true if this value is an Arguments object.
#[inline(always)]
pub fn is_arguments_object(&self) -> bool {
unsafe { v8__Value__IsArgumentsObject(self) }
}
/// Returns true if this value is a BigInt object.
#[inline(always)]
pub fn is_big_int_object(&self) -> bool {
unsafe { v8__Value__IsBigIntObject(self) }
}
/// Returns true if this value is a Boolean object.
#[inline(always)]
pub fn is_boolean_object(&self) -> bool {
unsafe { v8__Value__IsBooleanObject(self) }
}
/// Returns true if this value is a Number object.
#[inline(always)]
pub fn is_number_object(&self) -> bool {
unsafe { v8__Value__IsNumberObject(self) }
}
/// Returns true if this value is a String object.
#[inline(always)]
pub fn is_string_object(&self) -> bool {
unsafe { v8__Value__IsStringObject(self) }
}
/// Returns true if this value is a Symbol object.
#[inline(always)]
pub fn is_symbol_object(&self) -> bool {
unsafe { v8__Value__IsSymbolObject(self) }
}
/// Returns true if this value is a NativeError.
#[inline(always)]
pub fn is_native_error(&self) -> bool {
unsafe { v8__Value__IsNativeError(self) }
}
/// Returns true if this value is a RegExp.
#[inline(always)]
pub fn is_reg_exp(&self) -> bool {
unsafe { v8__Value__IsRegExp(self) }
}
/// Returns true if this value is an async function.
#[inline(always)]
pub fn is_async_function(&self) -> bool {
unsafe { v8__Value__IsAsyncFunction(self) }
}
/// Returns true if this value is a Generator function.
#[inline(always)]
pub fn is_generator_function(&self) -> bool {
unsafe { v8__Value__IsGeneratorFunction(self) }
}
/// Returns true if this value is a Promise.
#[inline(always)]
pub fn is_promise(&self) -> bool {
unsafe { v8__Value__IsPromise(self) }
}
/// Returns true if this value is a Map.
#[inline(always)]
pub fn is_map(&self) -> bool {
unsafe { v8__Value__IsMap(self) }
}
/// Returns true if this value is a Set.
#[inline(always)]
pub fn is_set(&self) -> bool {
unsafe { v8__Value__IsSet(self) }
}
/// Returns true if this value is a Map Iterator.
#[inline(always)]
pub fn is_map_iterator(&self) -> bool {
unsafe { v8__Value__IsMapIterator(self) }
}
/// Returns true if this value is a Set Iterator.
#[inline(always)]
pub fn is_set_iterator(&self) -> bool {
unsafe { v8__Value__IsSetIterator(self) }
}
/// Returns true if this value is a WeakMap.
#[inline(always)]
pub fn is_weak_map(&self) -> bool {
unsafe { v8__Value__IsWeakMap(self) }
}
/// Returns true if this value is a WeakSet.
#[inline(always)]
pub fn is_weak_set(&self) -> bool {
unsafe { v8__Value__IsWeakSet(self) }
}
/// Returns true if this value is an ArrayBuffer.
#[inline(always)]
pub fn is_array_buffer(&self) -> bool {
unsafe { v8__Value__IsArrayBuffer(self) }
}
/// Returns true if this value is an ArrayBufferView.
#[inline(always)]
pub fn is_array_buffer_view(&self) -> bool {
unsafe { v8__Value__IsArrayBufferView(self) }
}
/// Returns true if this value is one of TypedArrays.
#[inline(always)]
pub fn is_typed_array(&self) -> bool {
unsafe { v8__Value__IsTypedArray(self) }
}
/// Returns true if this value is an Uint8Array.
#[inline(always)]
pub fn is_uint8_array(&self) -> bool {
unsafe { v8__Value__IsUint8Array(self) }
}
/// Returns true if this value is an Uint8ClampedArray.
#[inline(always)]
pub fn is_uint8_clamped_array(&self) -> bool {
unsafe { v8__Value__IsUint8ClampedArray(self) }
}
/// Returns true if this value is an Int8Array.
#[inline(always)]
pub fn is_int8_array(&self) -> bool {
unsafe { v8__Value__IsInt8Array(self) }
}
/// Returns true if this value is an Uint16Array.
#[inline(always)]
pub fn is_uint16_array(&self) -> bool {
unsafe { v8__Value__IsUint16Array(self) }
}
/// Returns true if this value is an Int16Array.
#[inline(always)]
pub fn is_int16_array(&self) -> bool {
unsafe { v8__Value__IsInt16Array(self) }
}
/// Returns true if this value is an Uint32Array.
#[inline(always)]
pub fn is_uint32_array(&self) -> bool {
unsafe { v8__Value__IsUint32Array(self) }
}
/// Returns true if this value is an Int32Array.
#[inline(always)]
pub fn is_int32_array(&self) -> bool {
unsafe { v8__Value__IsInt32Array(self) }
}
/// Returns true if this value is a Float32Array.
#[inline(always)]
pub fn is_float32_array(&self) -> bool {
unsafe { v8__Value__IsFloat32Array(self) }
}
/// Returns true if this value is a Float64Array.
#[inline(always)]
pub fn is_float64_array(&self) -> bool {
unsafe { v8__Value__IsFloat64Array(self) }
}
/// Returns true if this value is a BigInt64Array.
#[inline(always)]
pub fn is_big_int64_array(&self) -> bool {
unsafe { v8__Value__IsBigInt64Array(self) }
}
/// Returns true if this value is a BigUint64Array.
#[inline(always)]
pub fn is_big_uint64_array(&self) -> bool {
unsafe { v8__Value__IsBigUint64Array(self) }
}
/// Returns true if this value is a DataView.
#[inline(always)]
pub fn is_data_view(&self) -> bool {
unsafe { v8__Value__IsDataView(self) }
}
/// Returns true if this value is a SharedArrayBuffer.
/// This is an experimental feature.
#[inline(always)]
pub fn is_shared_array_buffer(&self) -> bool {
unsafe { v8__Value__IsSharedArrayBuffer(self) }
}
/// Returns true if this value is a JavaScript Proxy.
#[inline(always)]
pub fn is_proxy(&self) -> bool {
unsafe { v8__Value__IsProxy(self) }
}
/// Returns true if this value is a WasmMemoryObject.
#[inline(always)]
pub fn is_wasm_memory_object(&self) -> bool {
unsafe { v8__Value__IsWasmMemoryObject(self) }
}
/// Returns true if this value is a WasmModuleObject.
#[inline(always)]
pub fn is_wasm_module_object(&self) -> bool {
unsafe { v8__Value__IsWasmModuleObject(self) }
}
/// Returns true if the value is a Module Namespace Object.
#[inline(always)]
pub fn is_module_namespace_object(&self) -> bool {
unsafe { v8__Value__IsModuleNamespaceObject(self) }
}
#[inline(always)]
pub fn strict_equals(&self, that: Local<Value>) -> bool {
unsafe { v8__Value__StrictEquals(self, &*that) }
}
#[inline(always)]
pub fn same_value(&self, that: Local<Value>) -> bool {
unsafe { v8__Value__SameValue(self, &*that) }
}
@ -453,6 +510,7 @@ impl Value {
/// following important distinctions:
/// - It considers `NaN` equal to `NaN` (unlike `strict_equals()`).
/// - It considers `-0` equal to `0` (unlike `same_value()`).
#[inline(always)]
pub fn same_value_zero(&self, that: Local<Value>) -> bool {
// The SMI representation of zero is also zero. In debug builds, double
// check this, so in the unlikely event that V8 changes its internal
@ -464,6 +522,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_big_int<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -474,6 +533,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_number<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -484,6 +544,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_string<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -495,6 +556,7 @@ impl Value {
}
/// Convenience function not present in the original V8 API.
#[inline(always)]
pub fn to_rust_string_lossy<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -504,6 +566,7 @@ impl Value {
.map_or_else(std::string::String::new, |s| s.to_rust_string_lossy(scope))
}
#[inline(always)]
pub fn to_detail_string<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -515,6 +578,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_object<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -525,6 +589,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_integer<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -535,6 +600,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_uint32<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -545,6 +611,7 @@ impl Value {
}
}
#[inline(always)]
pub fn to_int32<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -556,6 +623,7 @@ impl Value {
}
/// Perform the equivalent of Boolean(value) in JS. This can never fail.
#[inline(always)]
pub fn to_boolean<'s>(
&self,
scope: &mut HandleScope<'s, ()>,
@ -566,6 +634,7 @@ impl Value {
.unwrap()
}
#[inline(always)]
pub fn instance_of<'s>(
&self,
scope: &mut HandleScope<'s>,
@ -583,6 +652,7 @@ impl Value {
out.into()
}
#[inline(always)]
pub fn number_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<f64> {
let mut out = Maybe::<f64>::default();
unsafe {
@ -591,6 +661,7 @@ impl Value {
out.into()
}
#[inline(always)]
pub fn integer_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i64> {
let mut out = Maybe::<i64>::default();
unsafe {
@ -599,6 +670,7 @@ impl Value {
out.into()
}
#[inline(always)]
pub fn uint32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<u32> {
let mut out = Maybe::<u32>::default();
unsafe {
@ -607,6 +679,7 @@ impl Value {
out.into()
}
#[inline(always)]
pub fn int32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i32> {
let mut out = Maybe::<i32>::default();
unsafe {
@ -615,6 +688,7 @@ impl Value {
out.into()
}
#[inline(always)]
pub fn boolean_value<'s>(&self, scope: &mut HandleScope<'s, ()>) -> bool {
unsafe { v8__Value__BooleanValue(self, scope.get_isolate_ptr()) }
}
@ -624,6 +698,7 @@ impl Value {
///
/// The return value will never be 0. Also, it is not guaranteed to be
/// unique.
#[inline(always)]
pub fn get_hash(&self) -> NonZeroI32 {
unsafe { NonZeroI32::new_unchecked(v8__Value__GetHash(self)) }
}

View file

@ -36,6 +36,7 @@ pub struct WasmStreaming(WasmStreamingSharedPtr);
impl WasmStreaming {
/// Pass a new chunk of bytes to WebAssembly streaming compilation.
#[inline(always)]
pub fn on_bytes_received(&mut self, data: &[u8]) {
unsafe {
v8__WasmStreaming__OnBytesReceived(&mut self.0, data.as_ptr(), data.len())
@ -46,6 +47,7 @@ impl WasmStreaming {
/// [`Self::on_bytes_received()`] to tell V8 that there will be no
/// more bytes. Does not have to be called after [`Self::abort()`]
/// has been called already.
#[inline(always)]
pub fn finish(mut self) {
unsafe { v8__WasmStreaming__Finish(&mut self.0) }
}
@ -53,6 +55,7 @@ impl WasmStreaming {
/// Abort streaming compilation. If {exception} has a value, then the promise
/// associated with streaming compilation is rejected with that value. If
/// {exception} does not have value, the promise does not get rejected.
#[inline(always)]
pub fn abort(mut self, exception: Option<Local<Value>>) {
let exception = exception.map(|v| &*v as *const Value).unwrap_or(null());
unsafe { v8__WasmStreaming__Abort(&mut self.0, exception) }
@ -60,6 +63,7 @@ impl WasmStreaming {
/// Sets the UTF-8 encoded source URL for the `Script` object. This must be
/// called before [`Self::finish()`].
#[inline(always)]
pub fn set_url(&mut self, url: &str) {
// Although not documented, V8 requires the url to be null terminated.
// See https://chromium-review.googlesource.com/c/v8/v8/+/3289148.
@ -83,6 +87,7 @@ impl Drop for WasmStreaming {
impl WasmModuleObject {
/// Efficiently re-create a WasmModuleObject, without recompiling, from
/// a CompiledWasmModule.
#[inline(always)]
pub fn from_compiled_module<'s>(
scope: &mut HandleScope<'s>,
compiled_module: &CompiledWasmModule,
@ -99,12 +104,14 @@ impl WasmModuleObject {
/// Get the compiled module for this module object. The compiled module can be
/// shared by several module objects.
#[inline(always)]
pub fn get_compiled_module(&self) -> CompiledWasmModule {
let ptr = unsafe { v8__WasmModuleObject__GetCompiledModule(self) };
CompiledWasmModule(ptr)
}
/// Compile a Wasm module from the provided uncompiled bytes.
#[inline(always)]
pub fn compile<'s>(
scope: &mut HandleScope<'s>,
wire_bytes: &[u8],
@ -136,6 +143,7 @@ pub struct CompiledWasmModule(*mut InternalCompiledWasmModule);
impl CompiledWasmModule {
/// Get the (wasm-encoded) wire bytes that were used to compile this module.
#[inline(always)]
pub fn get_wire_bytes_ref(&self) -> &[u8] {
let mut len = 0isize;
unsafe {
@ -144,6 +152,7 @@ impl CompiledWasmModule {
}
}
#[inline(always)]
pub fn source_url(&self) -> &str {
let mut len = 0;
unsafe {