mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
Inline API functions (#1078)
This commit is contained in:
parent
6444cb9d61
commit
9f78b0abe7
43 changed files with 505 additions and 3 deletions
|
@ -151,6 +151,7 @@ impl Shared for Allocator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// malloc/free based convenience allocator.
|
/// malloc/free based convenience allocator.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_default_allocator() -> UniqueRef<Allocator> {
|
pub fn new_default_allocator() -> UniqueRef<Allocator> {
|
||||||
unsafe {
|
unsafe {
|
||||||
UniqueRef::from_raw(v8__ArrayBuffer__Allocator__NewDefaultAllocator())
|
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.
|
/// Creates an allocator managed by Rust code.
|
||||||
///
|
///
|
||||||
/// Marked `unsafe` because the caller must ensure that `handle` is valid and matches what `vtable` expects.
|
/// 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>(
|
pub unsafe fn new_rust_allocator<T: Sized + Send + Sync + 'static>(
|
||||||
handle: *const T,
|
handle: *const T,
|
||||||
vtable: &'static RustAllocatorVtable<T>,
|
vtable: &'static RustAllocatorVtable<T>,
|
||||||
|
@ -275,6 +277,7 @@ impl BackingStore {
|
||||||
/// lives.
|
/// lives.
|
||||||
///
|
///
|
||||||
/// Might return `None` if the backing store has zero length.
|
/// Might return `None` if the backing store has zero length.
|
||||||
|
#[inline(always)]
|
||||||
pub fn data(&self) -> Option<NonNull<c_void>> {
|
pub fn data(&self) -> Option<NonNull<c_void>> {
|
||||||
let raw_ptr =
|
let raw_ptr =
|
||||||
unsafe { v8__BackingStore__Data(self as *const _ as *mut Self) };
|
unsafe { v8__BackingStore__Data(self as *const _ as *mut Self) };
|
||||||
|
@ -282,12 +285,14 @@ impl BackingStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The length (in bytes) of this backing store.
|
/// The length (in bytes) of this backing store.
|
||||||
|
#[inline(always)]
|
||||||
pub fn byte_length(&self) -> usize {
|
pub fn byte_length(&self) -> usize {
|
||||||
unsafe { v8__BackingStore__ByteLength(self) }
|
unsafe { v8__BackingStore__ByteLength(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Indicates whether the backing store was created for an ArrayBuffer or
|
/// Indicates whether the backing store was created for an ArrayBuffer or
|
||||||
/// a SharedArrayBuffer.
|
/// a SharedArrayBuffer.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_shared(&self) -> bool {
|
pub fn is_shared(&self) -> bool {
|
||||||
unsafe { v8__BackingStore__IsShared(self) }
|
unsafe { v8__BackingStore__IsShared(self) }
|
||||||
}
|
}
|
||||||
|
@ -340,6 +345,7 @@ impl ArrayBuffer {
|
||||||
/// Allocated memory will be owned by a created ArrayBuffer and
|
/// Allocated memory will be owned by a created ArrayBuffer and
|
||||||
/// will be deallocated when it is garbage-collected,
|
/// will be deallocated when it is garbage-collected,
|
||||||
/// unless the object is externalized.
|
/// unless the object is externalized.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
byte_length: usize,
|
byte_length: usize,
|
||||||
|
@ -355,6 +361,7 @@ impl ArrayBuffer {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn with_backing_store<'s>(
|
pub fn with_backing_store<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
backing_store: &SharedRef<BackingStore>,
|
backing_store: &SharedRef<BackingStore>,
|
||||||
|
@ -371,11 +378,13 @@ impl ArrayBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data length in bytes.
|
/// Data length in bytes.
|
||||||
|
#[inline(always)]
|
||||||
pub fn byte_length(&self) -> usize {
|
pub fn byte_length(&self) -> usize {
|
||||||
unsafe { v8__ArrayBuffer__ByteLength(self) }
|
unsafe { v8__ArrayBuffer__ByteLength(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this ArrayBuffer may be detached.
|
/// Returns true if this ArrayBuffer may be detached.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_detachable(&self) -> bool {
|
pub fn is_detachable(&self) -> bool {
|
||||||
unsafe { v8__ArrayBuffer__IsDetachable(self) }
|
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,
|
/// Detaching sets the byte length of the buffer and all typed arrays to zero,
|
||||||
/// preventing JavaScript from ever accessing underlying backing store.
|
/// preventing JavaScript from ever accessing underlying backing store.
|
||||||
/// ArrayBuffer should have been externalized and must be detachable.
|
/// ArrayBuffer should have been externalized and must be detachable.
|
||||||
|
#[inline(always)]
|
||||||
pub fn detach(&self) {
|
pub fn detach(&self) {
|
||||||
// V8 terminates when the ArrayBuffer is not detachable. Non-detachable
|
// V8 terminates when the ArrayBuffer is not detachable. Non-detachable
|
||||||
// buffers are buffers that are in use by WebAssembly or asm.js.
|
// buffers are buffers that are in use by WebAssembly or asm.js.
|
||||||
|
@ -394,7 +404,7 @@ impl ArrayBuffer {
|
||||||
|
|
||||||
/// More efficient shortcut for GetBackingStore()->Data().
|
/// More efficient shortcut for GetBackingStore()->Data().
|
||||||
/// The returned pointer is valid as long as the ArrayBuffer is alive.
|
/// The returned pointer is valid as long as the ArrayBuffer is alive.
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
pub fn data(&self) -> *mut c_void {
|
pub fn data(&self) -> *mut c_void {
|
||||||
unsafe { v8__ArrayBuffer__Data(self) }
|
unsafe { v8__ArrayBuffer__Data(self) }
|
||||||
}
|
}
|
||||||
|
@ -403,6 +413,7 @@ impl ArrayBuffer {
|
||||||
/// pointer coordinates the lifetime management of the internal storage
|
/// pointer coordinates the lifetime management of the internal storage
|
||||||
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
|
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
|
||||||
/// should not attempt to manage lifetime of the storage through other means.
|
/// should not attempt to manage lifetime of the storage through other means.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_backing_store(&self) -> SharedRef<BackingStore> {
|
pub fn get_backing_store(&self) -> SharedRef<BackingStore> {
|
||||||
unsafe { v8__ArrayBuffer__GetBackingStore(self) }
|
unsafe { v8__ArrayBuffer__GetBackingStore(self) }
|
||||||
}
|
}
|
||||||
|
@ -414,6 +425,7 @@ impl ArrayBuffer {
|
||||||
/// If the allocator returns nullptr, then the function may cause GCs in the
|
/// 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
|
/// given isolate and re-try the allocation. If GCs do not help, then the
|
||||||
/// function will crash with an out-of-memory error.
|
/// function will crash with an out-of-memory error.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_backing_store(
|
pub fn new_backing_store(
|
||||||
scope: &mut Isolate,
|
scope: &mut Isolate,
|
||||||
byte_length: usize,
|
byte_length: usize,
|
||||||
|
@ -433,6 +445,7 @@ impl ArrayBuffer {
|
||||||
///
|
///
|
||||||
/// The result can be later passed to ArrayBuffer::New. The raw pointer
|
/// 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.
|
/// to the buffer must not be passed again to any V8 API function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_backing_store_from_boxed_slice(
|
pub fn new_backing_store_from_boxed_slice(
|
||||||
data: Box<[u8]>,
|
data: Box<[u8]>,
|
||||||
) -> UniqueRef<BackingStore> {
|
) -> UniqueRef<BackingStore> {
|
||||||
|
@ -455,6 +468,7 @@ impl ArrayBuffer {
|
||||||
///
|
///
|
||||||
/// The result can be later passed to ArrayBuffer::New. The raw pointer
|
/// 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.
|
/// to the buffer must not be passed again to any V8 API function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_backing_store_from_vec(
|
pub fn new_backing_store_from_vec(
|
||||||
mut data: Vec<u8>,
|
mut data: Vec<u8>,
|
||||||
) -> UniqueRef<BackingStore> {
|
) -> UniqueRef<BackingStore> {
|
||||||
|
@ -476,6 +490,7 @@ impl ArrayBuffer {
|
||||||
///
|
///
|
||||||
/// SAFETY: This API consumes raw pointers so is inherently
|
/// SAFETY: This API consumes raw pointers so is inherently
|
||||||
/// unsafe. Usually you should use new_backing_store_from_boxed_slice.
|
/// unsafe. Usually you should use new_backing_store_from_boxed_slice.
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn new_backing_store_from_ptr(
|
pub unsafe fn new_backing_store_from_ptr(
|
||||||
data_ptr: *mut c_void,
|
data_ptr: *mut c_void,
|
||||||
byte_length: usize,
|
byte_length: usize,
|
||||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
||||||
|
|
||||||
impl ArrayBufferView {
|
impl ArrayBufferView {
|
||||||
/// Returns underlying ArrayBuffer.
|
/// Returns underlying ArrayBuffer.
|
||||||
|
#[inline(always)]
|
||||||
pub fn buffer<'s>(
|
pub fn buffer<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -30,11 +31,13 @@ impl ArrayBufferView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Size of a view in bytes.
|
/// Size of a view in bytes.
|
||||||
|
#[inline(always)]
|
||||||
pub fn byte_length(&self) -> usize {
|
pub fn byte_length(&self) -> usize {
|
||||||
unsafe { v8__ArrayBufferView__ByteLength(self) }
|
unsafe { v8__ArrayBufferView__ByteLength(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Byte offset in |Buffer|.
|
/// Byte offset in |Buffer|.
|
||||||
|
#[inline(always)]
|
||||||
pub fn byte_offset(&self) -> usize {
|
pub fn byte_offset(&self) -> usize {
|
||||||
unsafe { v8__ArrayBufferView__ByteOffset(self) }
|
unsafe { v8__ArrayBufferView__ByteOffset(self) }
|
||||||
}
|
}
|
||||||
|
@ -43,6 +46,7 @@ impl ArrayBufferView {
|
||||||
/// memory without additional overhead that calling ArrayBufferView::Buffer
|
/// memory without additional overhead that calling ArrayBufferView::Buffer
|
||||||
/// might incur.
|
/// might incur.
|
||||||
/// Returns the number of bytes actually written.
|
/// Returns the number of bytes actually written.
|
||||||
|
#[inline(always)]
|
||||||
pub fn copy_contents(&self, dest: &mut [u8]) -> usize {
|
pub fn copy_contents(&self, dest: &mut [u8]) -> usize {
|
||||||
unsafe {
|
unsafe {
|
||||||
v8__ArrayBufferView__CopyContents(
|
v8__ArrayBufferView__CopyContents(
|
||||||
|
|
|
@ -31,6 +31,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BigInt {
|
impl BigInt {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_i64<'s>(
|
pub fn new_from_i64<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
value: i64,
|
value: i64,
|
||||||
|
@ -41,6 +42,7 @@ impl BigInt {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_u64<'s>(
|
pub fn new_from_u64<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
value: u64,
|
value: u64,
|
||||||
|
@ -58,6 +60,7 @@ impl BigInt {
|
||||||
/// The resulting number is calculated as:
|
/// The resulting number is calculated as:
|
||||||
///
|
///
|
||||||
/// (-1)^sign_bit * (words[0] * (2^64)^0 + words[1] * (2^64)^1 + ...)
|
/// (-1)^sign_bit * (words[0] * (2^64)^0 + words[1] * (2^64)^1 + ...)
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_words<'s>(
|
pub fn new_from_words<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
sign_bit: bool,
|
sign_bit: bool,
|
||||||
|
@ -79,6 +82,7 @@ impl BigInt {
|
||||||
/// `bool` indicating whether the return value was truncated was truncated or
|
/// `bool` indicating whether the return value was truncated was truncated or
|
||||||
/// wrapped around. In particular, it will be `false` if this BigInt is
|
/// wrapped around. In particular, it will be `false` if this BigInt is
|
||||||
/// negative.
|
/// negative.
|
||||||
|
#[inline(always)]
|
||||||
pub fn u64_value(&self) -> (u64, bool) {
|
pub fn u64_value(&self) -> (u64, bool) {
|
||||||
let mut lossless = MaybeUninit::uninit();
|
let mut lossless = MaybeUninit::uninit();
|
||||||
let v = unsafe { v8__BigInt__Uint64Value(&*self, lossless.as_mut_ptr()) };
|
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`
|
/// Returns the value of this BigInt as a signed 64-bit integer, and a `bool`
|
||||||
/// indicating whether this BigInt was truncated or not.
|
/// indicating whether this BigInt was truncated or not.
|
||||||
|
#[inline(always)]
|
||||||
pub fn i64_value(&self) -> (i64, bool) {
|
pub fn i64_value(&self) -> (i64, bool) {
|
||||||
let mut lossless = MaybeUninit::uninit();
|
let mut lossless = MaybeUninit::uninit();
|
||||||
let v = unsafe { v8__BigInt__Int64Value(&*self, lossless.as_mut_ptr()) };
|
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
|
/// Returns the number of 64-bit words needed to store the result of
|
||||||
/// `to_words_array`.
|
/// `to_words_array`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn word_count(&self) -> usize {
|
pub fn word_count(&self) -> usize {
|
||||||
unsafe { v8__BigInt__WordCount(&*self) as 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
|
/// 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
|
/// if this BigInt is negative. If `words` has too few elements, the result will
|
||||||
/// be truncated to fit.
|
/// be truncated to fit.
|
||||||
|
#[inline]
|
||||||
pub fn to_words_array<'a>(
|
pub fn to_words_array<'a>(
|
||||||
&self,
|
&self,
|
||||||
words: &'a mut [u64],
|
words: &'a mut [u64],
|
||||||
|
|
|
@ -50,6 +50,7 @@ impl Context {
|
||||||
const ANNEX_SLOT: c_int = 1;
|
const ANNEX_SLOT: c_int = 1;
|
||||||
|
|
||||||
/// Creates a new context.
|
/// Creates a new context.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Context> {
|
pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Context> {
|
||||||
// TODO: optional arguments;
|
// TODO: optional arguments;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -61,6 +62,7 @@ impl Context {
|
||||||
|
|
||||||
/// Creates a new context using the object template as the template for
|
/// Creates a new context using the object template as the template for
|
||||||
/// the global object.
|
/// the global object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_template<'s>(
|
pub fn new_from_template<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
templ: Local<ObjectTemplate>,
|
templ: Local<ObjectTemplate>,
|
||||||
|
@ -73,6 +75,7 @@ impl Context {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_extras_binding_object<'s>(
|
pub fn get_extras_binding_object<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
@ -91,6 +94,7 @@ impl Context {
|
||||||
/// Please note that changes to global proxy object prototype most probably
|
/// Please note that changes to global proxy object prototype most probably
|
||||||
/// would break VM---v8 expects only global object as a prototype of global
|
/// would break VM---v8 expects only global object as a prototype of global
|
||||||
/// proxy object.
|
/// proxy object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn global<'s>(
|
pub fn global<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
@ -98,6 +102,7 @@ impl Context {
|
||||||
unsafe { scope.cast_local(|_| v8__Context__Global(self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Context__Global(self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_promise_hooks(
|
pub fn set_promise_hooks(
|
||||||
&self,
|
&self,
|
||||||
init_hook: Local<Function>,
|
init_hook: Local<Function>,
|
||||||
|
@ -116,6 +121,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn get_annex_mut<'a>(
|
fn get_annex_mut<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
isolate: &'a mut Isolate,
|
isolate: &'a mut Isolate,
|
||||||
|
@ -199,6 +205,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to embedder data added with [`Self::set_slot()`].
|
/// Get a reference to embedder data added with [`Self::set_slot()`].
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_slot<'a, T: 'static>(
|
pub fn get_slot<'a, T: 'static>(
|
||||||
&'a self,
|
&'a self,
|
||||||
isolate: &'a mut Isolate,
|
isolate: &'a mut Isolate,
|
||||||
|
@ -215,6 +222,7 @@ impl Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to embedder data added with [`Self::set_slot()`].
|
/// Get a mutable reference to embedder data added with [`Self::set_slot()`].
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_slot_mut<'a, T: 'static>(
|
pub fn get_slot_mut<'a, T: 'static>(
|
||||||
&'a self,
|
&'a self,
|
||||||
isolate: &'a mut Isolate,
|
isolate: &'a mut Isolate,
|
||||||
|
@ -241,6 +249,7 @@ impl Context {
|
||||||
/// Returns true if value was set without replacing an existing value.
|
/// Returns true if value was set without replacing an existing value.
|
||||||
///
|
///
|
||||||
/// The value will be dropped when the context is garbage collected.
|
/// The value will be dropped when the context is garbage collected.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_slot<'a, T: 'static>(
|
pub fn set_slot<'a, T: 'static>(
|
||||||
&'a self,
|
&'a self,
|
||||||
isolate: &'a mut Isolate,
|
isolate: &'a mut Isolate,
|
||||||
|
@ -256,6 +265,7 @@ impl Context {
|
||||||
|
|
||||||
/// Removes the embedder data added with [`Self::set_slot()`] and returns it
|
/// Removes the embedder data added with [`Self::set_slot()`] and returns it
|
||||||
/// if it exists.
|
/// if it exists.
|
||||||
|
#[inline(always)]
|
||||||
pub fn remove_slot<'a, T: 'static>(
|
pub fn remove_slot<'a, T: 'static>(
|
||||||
&'a self,
|
&'a self,
|
||||||
isolate: &'a mut Isolate,
|
isolate: &'a mut Isolate,
|
||||||
|
@ -278,6 +288,7 @@ impl Context {
|
||||||
/// [`SnapshotCreator`](crate::SnapshotCreator), since the internal embedder
|
/// [`SnapshotCreator`](crate::SnapshotCreator), since the internal embedder
|
||||||
/// state uses [`Weak`] handles, which cannot be alive at the time of
|
/// state uses [`Weak`] handles, which cannot be alive at the time of
|
||||||
/// snapshotting.
|
/// snapshotting.
|
||||||
|
#[inline(always)]
|
||||||
pub fn clear_all_slots<'a>(&'a self, isolate: &'a mut Isolate) {
|
pub fn clear_all_slots<'a>(&'a self, isolate: &'a mut Isolate) {
|
||||||
if let Some(annex_mut) = self.get_annex_mut(isolate, false) {
|
if let Some(annex_mut) = self.get_annex_mut(isolate, false) {
|
||||||
let annex_ptr = annex_mut as *mut ContextAnnex;
|
let annex_ptr = annex_mut as *mut ContextAnnex;
|
||||||
|
|
15
src/data.rs
15
src/data.rs
|
@ -39,76 +39,91 @@ extern "C" {
|
||||||
|
|
||||||
impl Data {
|
impl Data {
|
||||||
/// Returns true if this data is a `BigInt`.
|
/// Returns true if this data is a `BigInt`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_big_int(&self) -> bool {
|
pub fn is_big_int(&self) -> bool {
|
||||||
unsafe { v8__Data__IsBigInt(self) }
|
unsafe { v8__Data__IsBigInt(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Boolean`.
|
/// Returns true if this data is a `Boolean`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_boolean(&self) -> bool {
|
pub fn is_boolean(&self) -> bool {
|
||||||
unsafe { v8__Data__IsBoolean(self) }
|
unsafe { v8__Data__IsBoolean(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Context`.
|
/// Returns true if this data is a `Context`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_context(&self) -> bool {
|
pub fn is_context(&self) -> bool {
|
||||||
unsafe { v8__Data__IsContext(self) }
|
unsafe { v8__Data__IsContext(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `FixedArray`.
|
/// Returns true if this data is a `FixedArray`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_fixed_array(&self) -> bool {
|
pub fn is_fixed_array(&self) -> bool {
|
||||||
unsafe { v8__Data__IsFixedArray(self) }
|
unsafe { v8__Data__IsFixedArray(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `FunctionTemplate`.
|
/// Returns true if this data is a `FunctionTemplate`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_function_template(&self) -> bool {
|
pub fn is_function_template(&self) -> bool {
|
||||||
unsafe { v8__Data__IsFunctionTemplate(self) }
|
unsafe { v8__Data__IsFunctionTemplate(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Module`.
|
/// Returns true if this data is a `Module`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_module(&self) -> bool {
|
pub fn is_module(&self) -> bool {
|
||||||
unsafe { v8__Data__IsModule(self) }
|
unsafe { v8__Data__IsModule(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `ModuleRequest`.
|
/// Returns true if this data is a `ModuleRequest`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_module_request(&self) -> bool {
|
pub fn is_module_request(&self) -> bool {
|
||||||
unsafe { v8__Data__IsModuleRequest(self) }
|
unsafe { v8__Data__IsModuleRequest(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Name`.
|
/// Returns true if this data is a `Name`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_name(&self) -> bool {
|
pub fn is_name(&self) -> bool {
|
||||||
unsafe { v8__Data__IsName(self) }
|
unsafe { v8__Data__IsName(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Number`.
|
/// Returns true if this data is a `Number`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_number(&self) -> bool {
|
pub fn is_number(&self) -> bool {
|
||||||
unsafe { v8__Data__IsNumber(self) }
|
unsafe { v8__Data__IsNumber(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `ObjectTemplate`.
|
/// Returns true if this data is a `ObjectTemplate`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_object_template(&self) -> bool {
|
pub fn is_object_template(&self) -> bool {
|
||||||
unsafe { v8__Data__IsObjectTemplate(self) }
|
unsafe { v8__Data__IsObjectTemplate(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Primitive`.
|
/// Returns true if this data is a `Primitive`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_primitive(&self) -> bool {
|
pub fn is_primitive(&self) -> bool {
|
||||||
unsafe { v8__Data__IsPrimitive(self) }
|
unsafe { v8__Data__IsPrimitive(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Private`.
|
/// Returns true if this data is a `Private`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_private(&self) -> bool {
|
pub fn is_private(&self) -> bool {
|
||||||
unsafe { v8__Data__IsPrivate(self) }
|
unsafe { v8__Data__IsPrivate(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `String`.
|
/// Returns true if this data is a `String`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_string(&self) -> bool {
|
pub fn is_string(&self) -> bool {
|
||||||
unsafe { v8__Data__IsString(self) }
|
unsafe { v8__Data__IsString(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Symbol`.
|
/// Returns true if this data is a `Symbol`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_symbol(&self) -> bool {
|
pub fn is_symbol(&self) -> bool {
|
||||||
unsafe { v8__Data__IsSymbol(self) }
|
unsafe { v8__Data__IsSymbol(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this data is a `Value`.
|
/// Returns true if this data is a `Value`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_value(&self) -> bool {
|
pub fn is_value(&self) -> bool {
|
||||||
unsafe { v8__Data__IsValue(self) }
|
unsafe { v8__Data__IsValue(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ extern "C" {
|
||||||
|
|
||||||
/// An instance of the built-in Date constructor (ECMA-262, 15.9).
|
/// An instance of the built-in Date constructor (ECMA-262, 15.9).
|
||||||
impl Date {
|
impl Date {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
value: f64,
|
value: f64,
|
||||||
|
@ -23,6 +24,7 @@ impl Date {
|
||||||
|
|
||||||
/// A specialization of Value::NumberValue that is more efficient
|
/// A specialization of Value::NumberValue that is more efficient
|
||||||
/// because we know the structure of this object.
|
/// because we know the structure of this object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn value_of(&self) -> f64 {
|
pub fn value_of(&self) -> f64 {
|
||||||
unsafe { v8__Date__ValueOf(self) }
|
unsafe { v8__Date__ValueOf(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ extern "C" {
|
||||||
|
|
||||||
impl StackTrace {
|
impl StackTrace {
|
||||||
/// Grab a snapshot of the current JavaScript execution stack.
|
/// Grab a snapshot of the current JavaScript execution stack.
|
||||||
|
#[inline(always)]
|
||||||
pub fn current_stack_trace<'s>(
|
pub fn current_stack_trace<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
frame_limit: usize,
|
frame_limit: usize,
|
||||||
|
@ -87,11 +88,13 @@ impl StackTrace {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of StackFrames.
|
/// Returns the number of StackFrames.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_frame_count(&self) -> usize {
|
pub fn get_frame_count(&self) -> usize {
|
||||||
unsafe { v8__StackTrace__GetFrameCount(self) as usize }
|
unsafe { v8__StackTrace__GetFrameCount(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a StackFrame at a particular index.
|
/// Returns a StackFrame at a particular index.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_frame<'s>(
|
pub fn get_frame<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -110,6 +113,7 @@ impl StackFrame {
|
||||||
/// This method will return Message::kNoLineNumberInfo if it is unable to
|
/// This method will return Message::kNoLineNumberInfo if it is unable to
|
||||||
/// retrieve the line number, or if kLineNumber was not passed as an option
|
/// retrieve the line number, or if kLineNumber was not passed as an option
|
||||||
/// when capturing the StackTrace.
|
/// when capturing the StackTrace.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_line_number(&self) -> usize {
|
pub fn get_line_number(&self) -> usize {
|
||||||
unsafe { v8__StackFrame__GetLineNumber(self) as 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
|
/// 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
|
/// the column number, or if kColumnOffset was not passed as an option when
|
||||||
/// capturing the StackTrace.
|
/// capturing the StackTrace.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_column(&self) -> usize {
|
pub fn get_column(&self) -> usize {
|
||||||
unsafe { v8__StackFrame__GetColumn(self) as 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
|
/// 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
|
/// retrieve the script id, or if kScriptId was not passed as an option when
|
||||||
/// capturing the StackTrace.
|
/// capturing the StackTrace.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_script_id(&self) -> usize {
|
pub fn get_script_id(&self) -> usize {
|
||||||
unsafe { v8__StackFrame__GetScriptId(self) as usize }
|
unsafe { v8__StackFrame__GetScriptId(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the name of the resource that contains the script for the
|
/// Returns the name of the resource that contains the script for the
|
||||||
/// function for this StackFrame.
|
/// function for this StackFrame.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_script_name<'s>(
|
pub fn get_script_name<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -144,6 +151,7 @@ impl StackFrame {
|
||||||
/// function for this StackFrame or sourceURL value if the script name
|
/// function for this StackFrame or sourceURL value if the script name
|
||||||
/// is undefined and its source ends with //# sourceURL=... string or
|
/// is undefined and its source ends with //# sourceURL=... string or
|
||||||
/// deprecated //@ sourceURL=... string.
|
/// deprecated //@ sourceURL=... string.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_script_name_or_source_url<'s>(
|
pub fn get_script_name_or_source_url<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -154,6 +162,7 @@ impl StackFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the name of the function associated with this stack frame.
|
/// Returns the name of the function associated with this stack frame.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_function_name<'s>(
|
pub fn get_function_name<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -163,28 +172,33 @@ impl StackFrame {
|
||||||
|
|
||||||
/// Returns whether or not the associated function is compiled via a call to
|
/// Returns whether or not the associated function is compiled via a call to
|
||||||
/// eval().
|
/// eval().
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_eval(&self) -> bool {
|
pub fn is_eval(&self) -> bool {
|
||||||
unsafe { v8__StackFrame__IsEval(self) }
|
unsafe { v8__StackFrame__IsEval(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether or not the associated function is called as a
|
/// Returns whether or not the associated function is called as a
|
||||||
/// constructor via "new".
|
/// constructor via "new".
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_constructor(&self) -> bool {
|
pub fn is_constructor(&self) -> bool {
|
||||||
unsafe { v8__StackFrame__IsConstructor(self) }
|
unsafe { v8__StackFrame__IsConstructor(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether or not the associated functions is defined in wasm.
|
/// Returns whether or not the associated functions is defined in wasm.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_wasm(&self) -> bool {
|
pub fn is_wasm(&self) -> bool {
|
||||||
unsafe { v8__StackFrame__IsWasm(self) }
|
unsafe { v8__StackFrame__IsWasm(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether or not the associated function is defined by the user.
|
/// Returns whether or not the associated function is defined by the user.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_user_javascript(&self) -> bool {
|
pub fn is_user_javascript(&self) -> bool {
|
||||||
unsafe { v8__StackFrame__IsUserJavaScript(self) }
|
unsafe { v8__StackFrame__IsUserJavaScript(self) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
|
#[inline(always)]
|
||||||
pub fn get<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, String> {
|
pub fn get<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, String> {
|
||||||
unsafe { scope.cast_local(|_| v8__Message__Get(self)) }.unwrap()
|
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
|
/// Exception stack trace. By default stack traces are not captured for
|
||||||
/// uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
|
/// uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
|
||||||
/// to change this option.
|
/// to change this option.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_stack_trace<'s>(
|
pub fn get_stack_trace<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -199,6 +214,7 @@ impl Message {
|
||||||
unsafe { scope.cast_local(|_| v8__Message__GetStackTrace(self)) }
|
unsafe { scope.cast_local(|_| v8__Message__GetStackTrace(self)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_source_line<'s>(
|
pub fn get_source_line<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -212,6 +228,7 @@ impl Message {
|
||||||
|
|
||||||
/// Returns the resource name for the script from where the function causing
|
/// Returns the resource name for the script from where the function causing
|
||||||
/// the error originates.
|
/// the error originates.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_script_resource_name<'s>(
|
pub fn get_script_resource_name<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -220,6 +237,7 @@ impl Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number, 1-based, of the line where the error occurred.
|
/// 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> {
|
pub fn get_line_number(&self, scope: &mut HandleScope) -> Option<usize> {
|
||||||
let i = unsafe {
|
let i = unsafe {
|
||||||
v8__Message__GetLineNumber(self, &*scope.get_current_context())
|
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
|
/// Returns the index within the script of the first character where
|
||||||
/// the error occurred.
|
/// the error occurred.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_start_position(&self) -> int {
|
pub fn get_start_position(&self) -> int {
|
||||||
unsafe { v8__Message__GetStartPosition(self) }
|
unsafe { v8__Message__GetStartPosition(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the index within the script of the last character where
|
/// Returns the index within the script of the last character where
|
||||||
/// the error occurred.
|
/// the error occurred.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_end_position(&self) -> int {
|
pub fn get_end_position(&self) -> int {
|
||||||
unsafe { v8__Message__GetEndPosition(self) }
|
unsafe { v8__Message__GetEndPosition(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the Wasm function index where the error occurred. Returns -1 if
|
/// Returns the Wasm function index where the error occurred. Returns -1 if
|
||||||
/// message is not from a Wasm script.
|
/// message is not from a Wasm script.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_wasm_function_index(&self) -> int {
|
pub fn get_wasm_function_index(&self) -> int {
|
||||||
unsafe { v8__Message__GetWasmFunctionIndex(self) }
|
unsafe { v8__Message__GetWasmFunctionIndex(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the error level of the message.
|
/// Returns the error level of the message.
|
||||||
|
#[inline(always)]
|
||||||
pub fn error_level(&self) -> int {
|
pub fn error_level(&self) -> int {
|
||||||
unsafe { v8__Message__ErrorLevel(self) }
|
unsafe { v8__Message__ErrorLevel(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the index within the line of the first character where
|
/// Returns the index within the line of the first character where
|
||||||
/// the error occurred.
|
/// the error occurred.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_start_column(&self) -> usize {
|
pub fn get_start_column(&self) -> usize {
|
||||||
unsafe { v8__Message__GetStartColumn(self) as usize }
|
unsafe { v8__Message__GetStartColumn(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the index within the line of the last character where
|
/// Returns the index within the line of the last character where
|
||||||
/// the error occurred.
|
/// the error occurred.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_end_column(&self) -> usize {
|
pub fn get_end_column(&self) -> usize {
|
||||||
unsafe { v8__Message__GetEndColumn(self) as usize }
|
unsafe { v8__Message__GetEndColumn(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Passes on the value set by the embedder when it fed the script from which
|
/// Passes on the value set by the embedder when it fed the script from which
|
||||||
/// this Message was generated to V8.
|
/// this Message was generated to V8.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_shared_cross_origin(&self) -> bool {
|
pub fn is_shared_cross_origin(&self) -> bool {
|
||||||
unsafe { v8__Message__IsSharedCrossOrigin(self) }
|
unsafe { v8__Message__IsSharedCrossOrigin(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_opaque(&self) -> bool {
|
pub fn is_opaque(&self) -> bool {
|
||||||
unsafe { v8__Message__IsOpaque(self) }
|
unsafe { v8__Message__IsOpaque(self) }
|
||||||
}
|
}
|
||||||
|
@ -283,6 +309,7 @@ impl Message {
|
||||||
pub struct Exception;
|
pub struct Exception;
|
||||||
|
|
||||||
impl Exception {
|
impl Exception {
|
||||||
|
#[inline(always)]
|
||||||
pub fn error<'s>(
|
pub fn error<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
message: Local<String>,
|
message: Local<String>,
|
||||||
|
@ -290,6 +317,7 @@ impl Exception {
|
||||||
Self::new_error_with(scope, message, v8__Exception__Error)
|
Self::new_error_with(scope, message, v8__Exception__Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn range_error<'s>(
|
pub fn range_error<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
message: Local<String>,
|
message: Local<String>,
|
||||||
|
@ -297,6 +325,7 @@ impl Exception {
|
||||||
Self::new_error_with(scope, message, v8__Exception__RangeError)
|
Self::new_error_with(scope, message, v8__Exception__RangeError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn reference_error<'s>(
|
pub fn reference_error<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
message: Local<String>,
|
message: Local<String>,
|
||||||
|
@ -304,6 +333,7 @@ impl Exception {
|
||||||
Self::new_error_with(scope, message, v8__Exception__ReferenceError)
|
Self::new_error_with(scope, message, v8__Exception__ReferenceError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn syntax_error<'s>(
|
pub fn syntax_error<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
message: Local<String>,
|
message: Local<String>,
|
||||||
|
@ -311,6 +341,7 @@ impl Exception {
|
||||||
Self::new_error_with(scope, message, v8__Exception__SyntaxError)
|
Self::new_error_with(scope, message, v8__Exception__SyntaxError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn type_error<'s>(
|
pub fn type_error<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
message: Local<String>,
|
message: Local<String>,
|
||||||
|
@ -319,6 +350,7 @@ impl Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal helper to make the above error constructors less repetitive.
|
/// Internal helper to make the above error constructors less repetitive.
|
||||||
|
#[inline(always)]
|
||||||
fn new_error_with<'s>(
|
fn new_error_with<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
message: Local<String>,
|
message: Local<String>,
|
||||||
|
@ -335,6 +367,7 @@ impl Exception {
|
||||||
/// Creates an error message for the given exception.
|
/// Creates an error message for the given exception.
|
||||||
/// Will try to reconstruct the original stack trace from the exception value,
|
/// Will try to reconstruct the original stack trace from the exception value,
|
||||||
/// or capture the current stack trace if not available.
|
/// or capture the current stack trace if not available.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_message<'s>(
|
pub fn create_message<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
exception: Local<Value>,
|
exception: Local<Value>,
|
||||||
|
@ -349,6 +382,7 @@ impl Exception {
|
||||||
|
|
||||||
/// Returns the original stack trace that was captured at the creation time
|
/// Returns the original stack trace that was captured at the creation time
|
||||||
/// of a given exception, or an empty handle if not available.
|
/// of a given exception, or an empty handle if not available.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_stack_trace<'s>(
|
pub fn get_stack_trace<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
exception: Local<Value>,
|
exception: Local<Value>,
|
||||||
|
|
|
@ -16,6 +16,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl External {
|
impl External {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
value: *mut c_void,
|
value: *mut c_void,
|
||||||
|
@ -26,6 +27,7 @@ impl External {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn value(&self) -> *mut c_void {
|
pub fn value(&self) -> *mut c_void {
|
||||||
unsafe { v8__External__Value(self) }
|
unsafe { v8__External__Value(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub struct ExternalReferences {
|
||||||
unsafe impl Sync for ExternalReferences {}
|
unsafe impl Sync for ExternalReferences {}
|
||||||
|
|
||||||
impl ExternalReferences {
|
impl ExternalReferences {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(refs: &[ExternalReference]) -> Self {
|
pub fn new(refs: &[ExternalReference]) -> Self {
|
||||||
let null_terminated = refs
|
let null_terminated = refs
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -30,6 +31,7 @@ impl ExternalReferences {
|
||||||
Self { null_terminated }
|
Self { null_terminated }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn as_ptr(&self) -> *const intptr_t {
|
pub fn as_ptr(&self) -> *const intptr_t {
|
||||||
self.null_terminated.as_ptr()
|
self.null_terminated.as_ptr()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub struct CFunctionInfo(Opaque);
|
||||||
pub struct CFunction(Opaque);
|
pub struct CFunction(Opaque);
|
||||||
|
|
||||||
impl CFunctionInfo {
|
impl CFunctionInfo {
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) unsafe fn new(
|
pub(crate) unsafe fn new(
|
||||||
args: *const CTypeInfo,
|
args: *const CTypeInfo,
|
||||||
args_len: usize,
|
args_len: usize,
|
||||||
|
@ -43,6 +44,7 @@ impl CFunctionInfo {
|
||||||
pub struct CTypeInfo(Opaque);
|
pub struct CTypeInfo(Opaque);
|
||||||
|
|
||||||
impl CTypeInfo {
|
impl CTypeInfo {
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn new(ty: CType) -> NonNull<CTypeInfo> {
|
pub(crate) fn new(ty: CType) -> NonNull<CTypeInfo> {
|
||||||
unsafe { NonNull::new_unchecked(v8__CTypeInfo__New(ty)) }
|
unsafe { NonNull::new_unchecked(v8__CTypeInfo__New(ty)) }
|
||||||
}
|
}
|
||||||
|
@ -203,7 +205,7 @@ pub struct FastApiTypedArray<T: Default> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Default> FastApiTypedArray<T> {
|
impl<T: Default> FastApiTypedArray<T> {
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
pub fn get(&self, index: usize) -> T {
|
pub fn get(&self, index: usize) -> T {
|
||||||
debug_assert!(index < self.length);
|
debug_assert!(index < self.length);
|
||||||
let mut t: T = Default::default();
|
let mut t: T = Default::default();
|
||||||
|
@ -213,7 +215,7 @@ impl<T: Default> FastApiTypedArray<T> {
|
||||||
t
|
t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline(always)]
|
||||||
pub fn get_storage_if_aligned(&self) -> Option<&mut [T]> {
|
pub fn get_storage_if_aligned(&self) -> Option<&mut [T]> {
|
||||||
if (self.data as usize) % align_of::<T>() != 0 {
|
if (self.data as usize) % align_of::<T>() != 0 {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -17,10 +17,12 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FixedArray {
|
impl FixedArray {
|
||||||
|
#[inline(always)]
|
||||||
pub fn length(&self) -> usize {
|
pub fn length(&self) -> usize {
|
||||||
unsafe { v8__FixedArray__Length(self) as usize }
|
unsafe { v8__FixedArray__Length(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get<'s>(
|
pub fn get<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
|
|
@ -129,6 +129,7 @@ pub struct ReturnValue<'cb>(*mut Value, PhantomData<&'cb ()>);
|
||||||
/// and for our purposes we currently don't need
|
/// and for our purposes we currently don't need
|
||||||
/// other types. So for now it's a simplified version.
|
/// other types. So for now it's a simplified version.
|
||||||
impl<'cb> ReturnValue<'cb> {
|
impl<'cb> ReturnValue<'cb> {
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn from_function_callback_info(
|
pub unsafe fn from_function_callback_info(
|
||||||
info: *const FunctionCallbackInfo,
|
info: *const FunctionCallbackInfo,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -136,39 +137,48 @@ impl<'cb> ReturnValue<'cb> {
|
||||||
Self(slot, PhantomData)
|
Self(slot, PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn from_property_callback_info(info: *const PropertyCallbackInfo) -> Self {
|
fn from_property_callback_info(info: *const PropertyCallbackInfo) -> Self {
|
||||||
let slot = unsafe { v8__PropertyCallbackInfo__GetReturnValue(info) };
|
let slot = unsafe { v8__PropertyCallbackInfo__GetReturnValue(info) };
|
||||||
Self(slot, PhantomData)
|
Self(slot, PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set(&mut self, value: Local<Value>) {
|
pub fn set(&mut self, value: Local<Value>) {
|
||||||
unsafe { v8__ReturnValue__Set(&mut *self, &*value) }
|
unsafe { v8__ReturnValue__Set(&mut *self, &*value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_bool(&mut self, value: bool) {
|
pub fn set_bool(&mut self, value: bool) {
|
||||||
unsafe { v8__ReturnValue__Set__Bool(&mut *self, value) }
|
unsafe { v8__ReturnValue__Set__Bool(&mut *self, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_int32(&mut self, value: i32) {
|
pub fn set_int32(&mut self, value: i32) {
|
||||||
unsafe { v8__ReturnValue__Set__Int32(&mut *self, value) }
|
unsafe { v8__ReturnValue__Set__Int32(&mut *self, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_uint32(&mut self, value: u32) {
|
pub fn set_uint32(&mut self, value: u32) {
|
||||||
unsafe { v8__ReturnValue__Set__Uint32(&mut *self, value) }
|
unsafe { v8__ReturnValue__Set__Uint32(&mut *self, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_double(&mut self, value: f64) {
|
pub fn set_double(&mut self, value: f64) {
|
||||||
unsafe { v8__ReturnValue__Set__Double(&mut *self, value) }
|
unsafe { v8__ReturnValue__Set__Double(&mut *self, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_null(&mut self) {
|
pub fn set_null(&mut self) {
|
||||||
unsafe { v8__ReturnValue__SetNull(&mut *self) }
|
unsafe { v8__ReturnValue__SetNull(&mut *self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_undefined(&mut self) {
|
pub fn set_undefined(&mut self) {
|
||||||
unsafe { v8__ReturnValue__SetUndefined(&mut *self) }
|
unsafe { v8__ReturnValue__SetUndefined(&mut *self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_empty_string(&mut self) {
|
pub fn set_empty_string(&mut self) {
|
||||||
unsafe { v8__ReturnValue__SetEmptyString(&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
|
/// 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
|
/// hit. If the ReturnValue was not yet set, this will return the undefined
|
||||||
/// value.
|
/// value.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
|
pub fn get<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
|
||||||
unsafe { scope.cast_local(|_| v8__ReturnValue__Get(self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__ReturnValue__Get(self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -212,6 +223,7 @@ pub struct FunctionCallbackArguments<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> FunctionCallbackArguments<'s> {
|
impl<'s> FunctionCallbackArguments<'s> {
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn from_function_callback_info(
|
pub unsafe fn from_function_callback_info(
|
||||||
info: *const FunctionCallbackInfo,
|
info: *const FunctionCallbackInfo,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -222,6 +234,7 @@ impl<'s> FunctionCallbackArguments<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the receiver. This corresponds to the "this" value.
|
/// Returns the receiver. This corresponds to the "this" value.
|
||||||
|
#[inline(always)]
|
||||||
pub fn this(&self) -> Local<'s, Object> {
|
pub fn this(&self) -> Local<'s, Object> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Local::from_raw(v8__FunctionCallbackInfo__This(self.info)).unwrap()
|
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.
|
/// Returns the data argument specified when creating the callback.
|
||||||
|
#[inline(always)]
|
||||||
pub fn data(&self) -> Option<Local<'s, Value>> {
|
pub fn data(&self) -> Option<Local<'s, Value>> {
|
||||||
unsafe { Local::from_raw(v8__FunctionCallbackInfo__Data(self.info)) }
|
unsafe { Local::from_raw(v8__FunctionCallbackInfo__Data(self.info)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number of available arguments.
|
/// The number of available arguments.
|
||||||
|
#[inline(always)]
|
||||||
pub fn length(&self) -> int {
|
pub fn length(&self) -> int {
|
||||||
unsafe {
|
unsafe {
|
||||||
let length = (*self.info).length;
|
let length = (*self.info).length;
|
||||||
|
@ -244,6 +259,7 @@ impl<'s> FunctionCallbackArguments<'s> {
|
||||||
|
|
||||||
/// Accessor for the available arguments. Returns `undefined` if the index is
|
/// Accessor for the available arguments. Returns `undefined` if the index is
|
||||||
/// out of bounds.
|
/// out of bounds.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get(&self, i: int) -> Local<'s, Value> {
|
pub fn get(&self, i: int) -> Local<'s, Value> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Local::from_raw(v8__FunctionCallbackInfo__GetArgument(self.info, i))
|
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.
|
/// For construct calls, this returns the "new.target" value.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_target(&self) -> Local<'s, Value> {
|
pub fn new_target(&self) -> Local<'s, Value> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Local::from_raw(v8__FunctionCallbackInfo__NewTarget(self.info)).unwrap()
|
Local::from_raw(v8__FunctionCallbackInfo__NewTarget(self.info)).unwrap()
|
||||||
|
@ -266,6 +283,7 @@ pub struct PropertyCallbackArguments<'s> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> PropertyCallbackArguments<'s> {
|
impl<'s> PropertyCallbackArguments<'s> {
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn from_property_callback_info(
|
pub(crate) fn from_property_callback_info(
|
||||||
info: *const PropertyCallbackInfo,
|
info: *const PropertyCallbackInfo,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -314,6 +332,7 @@ impl<'s> PropertyCallbackArguments<'s> {
|
||||||
///
|
///
|
||||||
/// CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)");
|
/// CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)");
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline(always)]
|
||||||
pub fn this(&self) -> Local<'s, Object> {
|
pub fn this(&self) -> Local<'s, Object> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Local::from_raw(v8__PropertyCallbackInfo__This(self.info)).unwrap()
|
Local::from_raw(v8__PropertyCallbackInfo__This(self.info)).unwrap()
|
||||||
|
@ -394,10 +413,12 @@ pub struct FunctionBuilder<'s, T> {
|
||||||
|
|
||||||
impl<'s, T> FunctionBuilder<'s, T> {
|
impl<'s, T> FunctionBuilder<'s, T> {
|
||||||
/// Create a new FunctionBuilder.
|
/// Create a new FunctionBuilder.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(callback: impl MapFnTo<FunctionCallback>) -> Self {
|
pub fn new(callback: impl MapFnTo<FunctionCallback>) -> Self {
|
||||||
Self::new_raw(callback.map_fn_to())
|
Self::new_raw(callback.map_fn_to())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_raw(callback: FunctionCallback) -> Self {
|
pub fn new_raw(callback: FunctionCallback) -> Self {
|
||||||
Self {
|
Self {
|
||||||
callback,
|
callback,
|
||||||
|
@ -411,18 +432,21 @@ impl<'s, T> FunctionBuilder<'s, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the associated data. The default is no associated data.
|
/// Set the associated data. The default is no associated data.
|
||||||
|
#[inline(always)]
|
||||||
pub fn data(mut self, data: Local<'s, Value>) -> Self {
|
pub fn data(mut self, data: Local<'s, Value>) -> Self {
|
||||||
self.data = Some(data);
|
self.data = Some(data);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the function length. The default is 0.
|
/// Set the function length. The default is 0.
|
||||||
|
#[inline(always)]
|
||||||
pub fn length(mut self, length: i32) -> Self {
|
pub fn length(mut self, length: i32) -> Self {
|
||||||
self.length = length;
|
self.length = length;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the constructor behavior. The default is ConstructorBehavior::Allow.
|
/// Set the constructor behavior. The default is ConstructorBehavior::Allow.
|
||||||
|
#[inline(always)]
|
||||||
pub fn constructor_behavior(
|
pub fn constructor_behavior(
|
||||||
mut self,
|
mut self,
|
||||||
constructor_behavior: ConstructorBehavior,
|
constructor_behavior: ConstructorBehavior,
|
||||||
|
@ -432,6 +456,7 @@ impl<'s, T> FunctionBuilder<'s, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the side effect type. The default is SideEffectType::HasSideEffect.
|
/// Set the side effect type. The default is SideEffectType::HasSideEffect.
|
||||||
|
#[inline(always)]
|
||||||
pub fn side_effect_type(mut self, side_effect_type: SideEffectType) -> Self {
|
pub fn side_effect_type(mut self, side_effect_type: SideEffectType) -> Self {
|
||||||
self.side_effect_type = side_effect_type;
|
self.side_effect_type = side_effect_type;
|
||||||
self
|
self
|
||||||
|
@ -440,6 +465,7 @@ impl<'s, T> FunctionBuilder<'s, T> {
|
||||||
|
|
||||||
impl<'s> FunctionBuilder<'s, Function> {
|
impl<'s> FunctionBuilder<'s, Function> {
|
||||||
/// Create the function in the current execution context.
|
/// Create the function in the current execution context.
|
||||||
|
#[inline(always)]
|
||||||
pub fn build(
|
pub fn build(
|
||||||
self,
|
self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -462,12 +488,14 @@ impl<'s> FunctionBuilder<'s, Function> {
|
||||||
impl Function {
|
impl Function {
|
||||||
/// Create a FunctionBuilder to configure a Function.
|
/// Create a FunctionBuilder to configure a Function.
|
||||||
/// This is the same as FunctionBuilder::<Function>::new().
|
/// This is the same as FunctionBuilder::<Function>::new().
|
||||||
|
#[inline(always)]
|
||||||
pub fn builder<'s>(
|
pub fn builder<'s>(
|
||||||
callback: impl MapFnTo<FunctionCallback>,
|
callback: impl MapFnTo<FunctionCallback>,
|
||||||
) -> FunctionBuilder<'s, Self> {
|
) -> FunctionBuilder<'s, Self> {
|
||||||
FunctionBuilder::new(callback)
|
FunctionBuilder::new(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn builder_raw<'s>(
|
pub fn builder_raw<'s>(
|
||||||
callback: FunctionCallback,
|
callback: FunctionCallback,
|
||||||
) -> FunctionBuilder<'s, Self> {
|
) -> FunctionBuilder<'s, Self> {
|
||||||
|
@ -476,6 +504,7 @@ impl Function {
|
||||||
|
|
||||||
/// Create a function in the current execution context
|
/// Create a function in the current execution context
|
||||||
/// for a given FunctionCallback.
|
/// for a given FunctionCallback.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
callback: impl MapFnTo<FunctionCallback>,
|
callback: impl MapFnTo<FunctionCallback>,
|
||||||
|
@ -483,6 +512,7 @@ impl Function {
|
||||||
Self::builder(callback).build(scope)
|
Self::builder(callback).build(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_raw<'s>(
|
pub fn new_raw<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
callback: FunctionCallback,
|
callback: FunctionCallback,
|
||||||
|
@ -490,6 +520,7 @@ impl Function {
|
||||||
Self::builder_raw(callback).build(scope)
|
Self::builder_raw(callback).build(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn call<'s>(
|
pub fn call<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -506,6 +537,7 @@ impl Function {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_instance<'s>(
|
pub fn new_instance<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
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> {
|
pub fn get_name<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, String> {
|
||||||
unsafe { scope.cast_local(|_| v8__Function__GetName(self)).unwrap() }
|
unsafe { scope.cast_local(|_| v8__Function__GetName(self)).unwrap() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_name(&self, name: Local<String>) {
|
pub fn set_name(&self, name: Local<String>) {
|
||||||
unsafe { v8__Function__SetName(self, &*name) }
|
unsafe { v8__Function__SetName(self, &*name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the (zero-indexed) column number of the function's definition, if available.
|
/// Get the (zero-indexed) column number of the function's definition, if available.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_script_column_number(&self) -> Option<u32> {
|
pub fn get_script_column_number(&self) -> Option<u32> {
|
||||||
let ret = unsafe { v8__Function__GetScriptColumnNumber(self) };
|
let ret = unsafe { v8__Function__GetScriptColumnNumber(self) };
|
||||||
(ret >= 0).then(|| ret as u32)
|
(ret >= 0).then(|| ret as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the (zero-indexed) line number of the function's definition, if available.
|
/// Get the (zero-indexed) line number of the function's definition, if available.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_script_line_number(&self) -> Option<u32> {
|
pub fn get_script_line_number(&self) -> Option<u32> {
|
||||||
let ret = unsafe { v8__Function__GetScriptLineNumber(self) };
|
let ret = unsafe { v8__Function__GetScriptLineNumber(self) };
|
||||||
(ret >= 0).then(|| ret as u32)
|
(ret >= 0).then(|| ret as u32)
|
||||||
|
@ -544,6 +580,7 @@ impl Function {
|
||||||
/// Creates and returns code cache for the specified unbound_script.
|
/// Creates and returns code cache for the specified unbound_script.
|
||||||
/// This will return nullptr if the script cannot be serialized. The
|
/// This will return nullptr if the script cannot be serialized. The
|
||||||
/// CachedData returned by this function should be owned by the caller.
|
/// CachedData returned by this function should be owned by the caller.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
|
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
|
||||||
let code_cache =
|
let code_cache =
|
||||||
unsafe { UniqueRef::try_from_raw(v8__Function__CreateCodeCache(self)) };
|
unsafe { UniqueRef::try_from_raw(v8__Function__CreateCodeCache(self)) };
|
||||||
|
|
|
@ -68,6 +68,7 @@ impl Default for GetPropertyNamesArgsBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetPropertyNamesArgsBuilder {
|
impl GetPropertyNamesArgsBuilder {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
mode: KeyCollectionMode::IncludePrototypes,
|
mode: KeyCollectionMode::IncludePrototypes,
|
||||||
|
@ -77,6 +78,7 @@ impl GetPropertyNamesArgsBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn build(&self) -> GetPropertyNamesArgs {
|
pub fn build(&self) -> GetPropertyNamesArgs {
|
||||||
GetPropertyNamesArgs {
|
GetPropertyNamesArgs {
|
||||||
mode: self.mode,
|
mode: self.mode,
|
||||||
|
@ -86,6 +88,7 @@ impl GetPropertyNamesArgsBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn mode(
|
pub fn mode(
|
||||||
&mut self,
|
&mut self,
|
||||||
mode: KeyCollectionMode,
|
mode: KeyCollectionMode,
|
||||||
|
@ -94,6 +97,7 @@ impl GetPropertyNamesArgsBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn property_filter(
|
pub fn property_filter(
|
||||||
&mut self,
|
&mut self,
|
||||||
property_filter: PropertyFilter,
|
property_filter: PropertyFilter,
|
||||||
|
@ -102,6 +106,7 @@ impl GetPropertyNamesArgsBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn index_filter(
|
pub fn index_filter(
|
||||||
&mut self,
|
&mut self,
|
||||||
index_filter: IndexFilter,
|
index_filter: IndexFilter,
|
||||||
|
@ -110,6 +115,7 @@ impl GetPropertyNamesArgsBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn key_conversion(
|
pub fn key_conversion(
|
||||||
&mut self,
|
&mut self,
|
||||||
key_conversion: KeyConversionMode,
|
key_conversion: KeyConversionMode,
|
||||||
|
|
|
@ -77,6 +77,7 @@ pub struct Local<'s, T>(NonNull<T>, PhantomData<&'s ()>);
|
||||||
|
|
||||||
impl<'s, T> Local<'s, T> {
|
impl<'s, T> Local<'s, T> {
|
||||||
/// Construct a new Local from an existing Handle.
|
/// Construct a new Local from an existing Handle.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
handle: impl Handle<Data = T>,
|
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.
|
/// Create a local handle by downcasting from one of its super types.
|
||||||
/// This function is unsafe because the cast is unchecked.
|
/// This function is unsafe because the cast is unchecked.
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn cast<A>(other: Local<'s, A>) -> Self
|
pub unsafe fn cast<A>(other: Local<'s, A>) -> Self
|
||||||
where
|
where
|
||||||
Local<'s, A>: From<Self>,
|
Local<'s, A>: From<Self>,
|
||||||
|
@ -100,18 +102,22 @@ impl<'s, T> Local<'s, T> {
|
||||||
transmute(other)
|
transmute(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) unsafe fn from_raw(ptr: *const T) -> Option<Self> {
|
pub(crate) unsafe fn from_raw(ptr: *const T) -> Option<Self> {
|
||||||
NonNull::new(ptr as *mut _).map(|nn| Self::from_non_null(nn))
|
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 {
|
pub(crate) unsafe fn from_non_null(nn: NonNull<T>) -> Self {
|
||||||
Self(nn, PhantomData)
|
Self(nn, PhantomData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn as_non_null(self) -> NonNull<T> {
|
pub(crate) fn as_non_null(self) -> NonNull<T> {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn slice_into_raw(slice: &[Self]) -> &[*const T] {
|
pub(crate) fn slice_into_raw(slice: &[Self]) -> &[*const T] {
|
||||||
unsafe { &*(slice as *const [Self] as *const [*const T]) }
|
unsafe { &*(slice as *const [Self] as *const [*const T]) }
|
||||||
}
|
}
|
||||||
|
@ -148,6 +154,7 @@ pub struct Global<T> {
|
||||||
|
|
||||||
impl<T> Global<T> {
|
impl<T> Global<T> {
|
||||||
/// Construct a new Global from an existing Handle.
|
/// Construct a new Global from an existing Handle.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(isolate: &mut Isolate, handle: impl Handle<Data = T>) -> Self {
|
pub fn new(isolate: &mut Isolate, handle: impl Handle<Data = T>) -> Self {
|
||||||
let HandleInfo { data, host } = handle.get_handle_info();
|
let HandleInfo { data, host } = handle.get_handle_info();
|
||||||
host.assert_match_isolate(isolate);
|
host.assert_match_isolate(isolate);
|
||||||
|
@ -156,6 +163,7 @@ impl<T> Global<T> {
|
||||||
|
|
||||||
/// Implementation helper function that contains the code that can be shared
|
/// Implementation helper function that contains the code that can be shared
|
||||||
/// between `Global::new()` and `Global::clone()`.
|
/// between `Global::new()` and `Global::clone()`.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn new_raw(isolate: *mut Isolate, data: NonNull<T>) -> Self {
|
unsafe fn new_raw(isolate: *mut Isolate, data: NonNull<T>) -> Self {
|
||||||
let data = data.cast().as_ptr();
|
let data = data.cast().as_ptr();
|
||||||
let data = v8__Global__New(isolate, data) as *const T;
|
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
|
/// [`Global::from_raw`], otherwise the V8 value referenced by this global
|
||||||
/// handle will be pinned on the V8 heap permanently and never get garbage
|
/// handle will be pinned on the V8 heap permanently and never get garbage
|
||||||
/// collected.
|
/// collected.
|
||||||
|
#[inline(always)]
|
||||||
pub fn into_raw(self) -> NonNull<T> {
|
pub fn into_raw(self) -> NonNull<T> {
|
||||||
let data = self.data;
|
let data = self.data;
|
||||||
forget(self);
|
forget(self);
|
||||||
|
@ -181,6 +190,7 @@ impl<T> Global<T> {
|
||||||
|
|
||||||
/// Converts a raw pointer created with [`Global::into_raw()`] back to its
|
/// Converts a raw pointer created with [`Global::into_raw()`] back to its
|
||||||
/// original `Global`.
|
/// original `Global`.
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn from_raw(isolate: &mut Isolate, data: NonNull<T>) -> Self {
|
pub unsafe fn from_raw(isolate: &mut Isolate, data: NonNull<T>) -> Self {
|
||||||
let isolate_handle = isolate.thread_safe_handle();
|
let isolate_handle = isolate.thread_safe_handle();
|
||||||
Self {
|
Self {
|
||||||
|
@ -189,6 +199,7 @@ impl<T> Global<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn open<'a>(&'a self, scope: &mut Isolate) -> &'a T {
|
pub fn open<'a>(&'a self, scope: &mut Isolate) -> &'a T {
|
||||||
Handle::open(self, scope)
|
Handle::open(self, scope)
|
||||||
}
|
}
|
||||||
|
@ -231,6 +242,7 @@ impl<'a, T> UnsafeRefHandle<'a, T> {
|
||||||
/// isolate associated with the handle (for [`Local`], the current isolate;
|
/// isolate associated with the handle (for [`Local`], the current isolate;
|
||||||
/// for [`Global`], the isolate you would pass to the [`Global::open()`]
|
/// for [`Global`], the isolate you would pass to the [`Global::open()`]
|
||||||
/// method).
|
/// method).
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn new(reference: &'a T, isolate: &mut Isolate) -> Self {
|
pub unsafe fn new(reference: &'a T, isolate: &mut Isolate) -> Self {
|
||||||
UnsafeRefHandle {
|
UnsafeRefHandle {
|
||||||
reference,
|
reference,
|
||||||
|
|
|
@ -35,6 +35,7 @@ extern "C" {
|
||||||
/// This function has no effect on application (non ICU) data. See udata_setAppData() for similar
|
/// This function has no effect on application (non ICU) data. See udata_setAppData() for similar
|
||||||
/// functionality for application data.
|
/// functionality for application data.
|
||||||
// TODO(ry) Map error code to something useful.
|
// TODO(ry) Map error code to something useful.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_common_data_71(data: &'static [u8]) -> Result<(), i32> {
|
pub fn set_common_data_71(data: &'static [u8]) -> Result<(), i32> {
|
||||||
let mut error_code = 0i32;
|
let mut error_code = 0i32;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -378,25 +378,30 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initial configuration parameters for a new Isolate.
|
/// Initial configuration parameters for a new Isolate.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_params() -> CreateParams {
|
pub fn create_params() -> CreateParams {
|
||||||
CreateParams::default()
|
CreateParams::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn thread_safe_handle(&self) -> IsolateHandle {
|
pub fn thread_safe_handle(&self) -> IsolateHandle {
|
||||||
IsolateHandle::new(self)
|
IsolateHandle::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`IsolateHandle::terminate_execution`]
|
/// See [`IsolateHandle::terminate_execution`]
|
||||||
|
#[inline(always)]
|
||||||
pub fn terminate_execution(&self) -> bool {
|
pub fn terminate_execution(&self) -> bool {
|
||||||
self.thread_safe_handle().terminate_execution()
|
self.thread_safe_handle().terminate_execution()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`IsolateHandle::cancel_terminate_execution`]
|
/// See [`IsolateHandle::cancel_terminate_execution`]
|
||||||
|
#[inline(always)]
|
||||||
pub fn cancel_terminate_execution(&self) -> bool {
|
pub fn cancel_terminate_execution(&self) -> bool {
|
||||||
self.thread_safe_handle().cancel_terminate_execution()
|
self.thread_safe_handle().cancel_terminate_execution()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See [`IsolateHandle::is_execution_terminating`]
|
/// See [`IsolateHandle::is_execution_terminating`]
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_execution_terminating(&self) -> bool {
|
pub fn is_execution_terminating(&self) -> bool {
|
||||||
self.thread_safe_handle().is_execution_terminating()
|
self.thread_safe_handle().is_execution_terminating()
|
||||||
}
|
}
|
||||||
|
@ -413,6 +418,7 @@ impl Isolate {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn get_annex(&self) -> &IsolateAnnex {
|
fn get_annex(&self) -> &IsolateAnnex {
|
||||||
unsafe {
|
unsafe {
|
||||||
&*(v8__Isolate__GetData(self, Self::ANNEX_SLOT) as *const _
|
&*(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 {
|
fn get_annex_mut(&mut self) -> &mut IsolateAnnex {
|
||||||
unsafe {
|
unsafe {
|
||||||
&mut *(v8__Isolate__GetData(self, Self::ANNEX_SLOT) as *mut IsolateAnnex)
|
&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
|
/// Associate embedder-specific data with the isolate. `slot` has to be
|
||||||
/// between 0 and `Isolate::get_number_of_data_slots()`.
|
/// between 0 and `Isolate::get_number_of_data_slots()`.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn set_data(&mut self, slot: u32, ptr: *mut c_void) {
|
unsafe fn set_data(&mut self, slot: u32, ptr: *mut c_void) {
|
||||||
v8__Isolate__SetData(self, slot + Self::INTERNAL_SLOT_COUNT, ptr)
|
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.
|
/// Returns a pointer to the `ScopeData` struct for the current scope.
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn get_current_scope_data(&self) -> Option<NonNull<ScopeData>> {
|
pub(crate) fn get_current_scope_data(&self) -> Option<NonNull<ScopeData>> {
|
||||||
let scope_data_ptr =
|
let scope_data_ptr =
|
||||||
unsafe { v8__Isolate__GetData(self, Self::CURRENT_SCOPE_DATA_SLOT) };
|
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.
|
/// Updates the slot that stores a `ScopeData` pointer for the current scope.
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn set_current_scope_data(
|
pub(crate) fn set_current_scope_data(
|
||||||
&mut self,
|
&mut self,
|
||||||
scope_data: Option<NonNull<ScopeData>>,
|
scope_data: Option<NonNull<ScopeData>>,
|
||||||
|
@ -485,6 +495,7 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a reference to embedder data added with `set_slot()`.
|
/// Get a reference to embedder data added with `set_slot()`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_slot<T: 'static>(&self) -> Option<&T> {
|
pub fn get_slot<T: 'static>(&self) -> Option<&T> {
|
||||||
self
|
self
|
||||||
.get_annex()
|
.get_annex()
|
||||||
|
@ -494,6 +505,7 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a mutable reference to embedder data added with `set_slot()`.
|
/// 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> {
|
pub fn get_slot_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
||||||
self
|
self
|
||||||
.get_annex_mut()
|
.get_annex_mut()
|
||||||
|
@ -513,6 +525,7 @@ impl Isolate {
|
||||||
/// Returns true if value was set without replacing an existing value.
|
/// Returns true if value was set without replacing an existing value.
|
||||||
///
|
///
|
||||||
/// The value will be dropped when the isolate is dropped.
|
/// The value will be dropped when the isolate is dropped.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_slot<T: 'static>(&mut self, value: T) -> bool {
|
pub fn set_slot<T: 'static>(&mut self, value: T) -> bool {
|
||||||
self
|
self
|
||||||
.get_annex_mut()
|
.get_annex_mut()
|
||||||
|
@ -522,6 +535,7 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the embedder data added with `set_slot()` and returns it if it exists.
|
/// 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> {
|
pub fn remove_slot<T: 'static>(&mut self) -> Option<T> {
|
||||||
self
|
self
|
||||||
.get_annex_mut()
|
.get_annex_mut()
|
||||||
|
@ -536,6 +550,7 @@ impl Isolate {
|
||||||
///
|
///
|
||||||
/// rusty_v8 note: Unlike in the C++ API, the isolate is entered when it is
|
/// rusty_v8 note: Unlike in the C++ API, the isolate is entered when it is
|
||||||
/// constructed and exited when dropped.
|
/// constructed and exited when dropped.
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn enter(&mut self) {
|
pub unsafe fn enter(&mut self) {
|
||||||
v8__Isolate__Enter(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
|
/// rusty_v8 note: Unlike in the C++ API, the isolate is entered when it is
|
||||||
/// constructed and exited when dropped.
|
/// constructed and exited when dropped.
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn exit(&mut self) {
|
pub unsafe fn exit(&mut self) {
|
||||||
v8__Isolate__Exit(self)
|
v8__Isolate__Exit(self)
|
||||||
}
|
}
|
||||||
|
@ -563,23 +579,27 @@ impl Isolate {
|
||||||
/// running microtasks via a custom MicrotaskQueue class's PerformCheckpoint.
|
/// running microtasks via a custom MicrotaskQueue class's PerformCheckpoint.
|
||||||
/// In that case, it is the embedder's responsibility to make this call at a
|
/// In that case, it is the embedder's responsibility to make this call at a
|
||||||
/// time which does not interrupt synchronous ECMAScript code execution.
|
/// time which does not interrupt synchronous ECMAScript code execution.
|
||||||
|
#[inline(always)]
|
||||||
pub fn clear_kept_objects(&mut self) {
|
pub fn clear_kept_objects(&mut self) {
|
||||||
unsafe { v8__Isolate__ClearKeptObjects(self) }
|
unsafe { v8__Isolate__ClearKeptObjects(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optional notification that the system is running low on memory.
|
/// Optional notification that the system is running low on memory.
|
||||||
/// V8 uses these notifications to attempt to free memory.
|
/// V8 uses these notifications to attempt to free memory.
|
||||||
|
#[inline(always)]
|
||||||
pub fn low_memory_notification(&mut self) {
|
pub fn low_memory_notification(&mut self) {
|
||||||
unsafe { v8__Isolate__LowMemoryNotification(self) }
|
unsafe { v8__Isolate__LowMemoryNotification(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get statistics about the heap memory usage.
|
/// Get statistics about the heap memory usage.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_heap_statistics(&mut self, s: &mut HeapStatistics) {
|
pub fn get_heap_statistics(&mut self, s: &mut HeapStatistics) {
|
||||||
unsafe { v8__Isolate__GetHeapStatistics(self, s) }
|
unsafe { v8__Isolate__GetHeapStatistics(self, s) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tells V8 to capture current stack trace when uncaught exception occurs
|
/// Tells V8 to capture current stack trace when uncaught exception occurs
|
||||||
/// and report it to the message listeners. The option is off by default.
|
/// and report it to the message listeners. The option is off by default.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_capture_stack_trace_for_uncaught_exceptions(
|
pub fn set_capture_stack_trace_for_uncaught_exceptions(
|
||||||
&mut self,
|
&mut self,
|
||||||
capture: bool,
|
capture: bool,
|
||||||
|
@ -600,6 +620,7 @@ impl Isolate {
|
||||||
/// case it will be called more than once for each message.
|
/// case it will be called more than once for each message.
|
||||||
///
|
///
|
||||||
/// The exception object will be passed to the callback.
|
/// The exception object will be passed to the callback.
|
||||||
|
#[inline(always)]
|
||||||
pub fn add_message_listener(&mut self, callback: MessageCallback) -> bool {
|
pub fn add_message_listener(&mut self, callback: MessageCallback) -> bool {
|
||||||
unsafe { v8__Isolate__AddMessageListener(self, callback) }
|
unsafe { v8__Isolate__AddMessageListener(self, callback) }
|
||||||
}
|
}
|
||||||
|
@ -612,6 +633,7 @@ impl Isolate {
|
||||||
/// callback is registed, the |Error.prepareStackTrace| API will be disabled.
|
/// callback is registed, the |Error.prepareStackTrace| API will be disabled.
|
||||||
/// |sites| is an array of call sites, specified in
|
/// |sites| is an array of call sites, specified in
|
||||||
/// https://v8.dev/docs/stack-trace-api
|
/// https://v8.dev/docs/stack-trace-api
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_prepare_stack_trace_callback<'s>(
|
pub fn set_prepare_stack_trace_callback<'s>(
|
||||||
&mut self,
|
&mut self,
|
||||||
callback: impl MapFnTo<PrepareStackTraceCallback<'s>>,
|
callback: impl MapFnTo<PrepareStackTraceCallback<'s>>,
|
||||||
|
@ -626,12 +648,14 @@ impl Isolate {
|
||||||
|
|
||||||
/// Set the PromiseHook callback for various promise lifecycle
|
/// Set the PromiseHook callback for various promise lifecycle
|
||||||
/// events.
|
/// events.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_promise_hook(&mut self, hook: PromiseHook) {
|
pub fn set_promise_hook(&mut self, hook: PromiseHook) {
|
||||||
unsafe { v8__Isolate__SetPromiseHook(self, hook) }
|
unsafe { v8__Isolate__SetPromiseHook(self, hook) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set callback to notify about promise reject with no handler, or
|
/// Set callback to notify about promise reject with no handler, or
|
||||||
/// revocation of such a previous notification once the handler is added.
|
/// revocation of such a previous notification once the handler is added.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_promise_reject_callback(
|
pub fn set_promise_reject_callback(
|
||||||
&mut self,
|
&mut self,
|
||||||
callback: PromiseRejectCallback,
|
callback: PromiseRejectCallback,
|
||||||
|
@ -639,6 +663,7 @@ impl Isolate {
|
||||||
unsafe { v8__Isolate__SetPromiseRejectCallback(self, callback) }
|
unsafe { v8__Isolate__SetPromiseRejectCallback(self, callback) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_wasm_async_resolve_promise_callback(
|
pub fn set_wasm_async_resolve_promise_callback(
|
||||||
&mut self,
|
&mut self,
|
||||||
callback: WasmAsyncResolvePromiseCallback,
|
callback: WasmAsyncResolvePromiseCallback,
|
||||||
|
@ -646,6 +671,7 @@ impl Isolate {
|
||||||
unsafe { v8__Isolate__SetWasmAsyncResolvePromiseCallback(self, callback) }
|
unsafe { v8__Isolate__SetWasmAsyncResolvePromiseCallback(self, callback) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
/// This specifies the callback called by the upcoming importa.meta
|
/// This specifies the callback called by the upcoming importa.meta
|
||||||
/// language feature to retrieve host-defined meta data for a module.
|
/// language feature to retrieve host-defined meta data for a module.
|
||||||
pub fn set_host_initialize_import_meta_object_callback(
|
pub fn set_host_initialize_import_meta_object_callback(
|
||||||
|
@ -659,6 +685,7 @@ impl Isolate {
|
||||||
|
|
||||||
/// This specifies the callback called by the upcoming dynamic
|
/// This specifies the callback called by the upcoming dynamic
|
||||||
/// import() language feature to load modules.
|
/// import() language feature to load modules.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_host_import_module_dynamically_callback(
|
pub fn set_host_import_module_dynamically_callback(
|
||||||
&mut self,
|
&mut self,
|
||||||
callback: HostImportModuleDynamicallyCallback,
|
callback: HostImportModuleDynamicallyCallback,
|
||||||
|
@ -722,6 +749,7 @@ impl Isolate {
|
||||||
/// If multiple callbacks are added, only the most recently added callback is
|
/// If multiple callbacks are added, only the most recently added callback is
|
||||||
/// invoked.
|
/// invoked.
|
||||||
#[allow(clippy::not_unsafe_ptr_arg_deref)] // False positive.
|
#[allow(clippy::not_unsafe_ptr_arg_deref)] // False positive.
|
||||||
|
#[inline(always)]
|
||||||
pub fn add_near_heap_limit_callback(
|
pub fn add_near_heap_limit_callback(
|
||||||
&mut self,
|
&mut self,
|
||||||
callback: NearHeapLimitCallback,
|
callback: NearHeapLimitCallback,
|
||||||
|
@ -734,6 +762,7 @@ impl Isolate {
|
||||||
/// If the given limit is zero, then it is ignored. If the current heap size
|
/// 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
|
/// is greater than the given limit, then the heap limit is restored to the
|
||||||
/// minimal limit that is possible for the current heap size.
|
/// minimal limit that is possible for the current heap size.
|
||||||
|
#[inline(always)]
|
||||||
pub fn remove_near_heap_limit_callback(
|
pub fn remove_near_heap_limit_callback(
|
||||||
&mut self,
|
&mut self,
|
||||||
callback: NearHeapLimitCallback,
|
callback: NearHeapLimitCallback,
|
||||||
|
@ -751,6 +780,7 @@ impl Isolate {
|
||||||
/// will trigger global garbage collections more often than it would
|
/// will trigger global garbage collections more often than it would
|
||||||
/// otherwise in an attempt to garbage collect the JavaScript objects
|
/// otherwise in an attempt to garbage collect the JavaScript objects
|
||||||
/// that keep the externally allocated memory alive.
|
/// that keep the externally allocated memory alive.
|
||||||
|
#[inline(always)]
|
||||||
pub fn adjust_amount_of_external_allocated_memory(
|
pub fn adjust_amount_of_external_allocated_memory(
|
||||||
&mut self,
|
&mut self,
|
||||||
change_in_bytes: i64,
|
change_in_bytes: i64,
|
||||||
|
@ -760,16 +790,19 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_oom_error_handler(&mut self, callback: OomErrorCallback) {
|
pub fn set_oom_error_handler(&mut self, callback: OomErrorCallback) {
|
||||||
unsafe { v8__Isolate__SetOOMErrorHandler(self, callback) };
|
unsafe { v8__Isolate__SetOOMErrorHandler(self, callback) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the policy controlling how Microtasks are invoked.
|
/// Returns the policy controlling how Microtasks are invoked.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_microtasks_policy(&self) -> MicrotasksPolicy {
|
pub fn get_microtasks_policy(&self) -> MicrotasksPolicy {
|
||||||
unsafe { v8__Isolate__GetMicrotasksPolicy(self) }
|
unsafe { v8__Isolate__GetMicrotasksPolicy(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the policy controlling how Microtasks are invoked.
|
/// Returns the policy controlling how Microtasks are invoked.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_microtasks_policy(&mut self, policy: MicrotasksPolicy) {
|
pub fn set_microtasks_policy(&mut self, policy: MicrotasksPolicy) {
|
||||||
unsafe { v8__Isolate__SetMicrotasksPolicy(self, policy) }
|
unsafe { v8__Isolate__SetMicrotasksPolicy(self, policy) }
|
||||||
}
|
}
|
||||||
|
@ -778,6 +811,7 @@ impl Isolate {
|
||||||
/// microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
|
/// microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that
|
||||||
/// the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
|
/// the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask
|
||||||
/// callbacks are swallowed.
|
/// callbacks are swallowed.
|
||||||
|
#[inline(always)]
|
||||||
pub fn perform_microtask_checkpoint(&mut self) {
|
pub fn perform_microtask_checkpoint(&mut self) {
|
||||||
unsafe { v8__Isolate__PerformMicrotaskCheckpoint(self) }
|
unsafe { v8__Isolate__PerformMicrotaskCheckpoint(self) }
|
||||||
}
|
}
|
||||||
|
@ -789,6 +823,7 @@ impl Isolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enqueues the callback to the default MicrotaskQueue
|
/// Enqueues the callback to the default MicrotaskQueue
|
||||||
|
#[inline(always)]
|
||||||
pub fn enqueue_microtask(&mut self, microtask: Local<Function>) {
|
pub fn enqueue_microtask(&mut self, microtask: Local<Function>) {
|
||||||
unsafe { v8__Isolate__EnqueueMicrotask(self, &*microtask) }
|
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
|
/// Set whether calling Atomics.wait (a function that may block) is allowed in
|
||||||
/// this isolate. This can also be configured via
|
/// this isolate. This can also be configured via
|
||||||
/// CreateParams::allow_atomics_wait.
|
/// CreateParams::allow_atomics_wait.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_allow_atomics_wait(&mut self, allow: bool) {
|
pub fn set_allow_atomics_wait(&mut self, allow: bool) {
|
||||||
unsafe { v8__Isolate__SetAllowAtomicsWait(self, allow) }
|
unsafe { v8__Isolate__SetAllowAtomicsWait(self, allow) }
|
||||||
}
|
}
|
||||||
|
@ -807,6 +843,7 @@ impl Isolate {
|
||||||
/// and an instance of [WasmStreaming]. The [WasmStreaming] instance
|
/// and an instance of [WasmStreaming]. The [WasmStreaming] instance
|
||||||
/// can outlive the callback and is used to feed data chunks to V8
|
/// can outlive the callback and is used to feed data chunks to V8
|
||||||
/// asynchronously.
|
/// asynchronously.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_wasm_streaming_callback<F>(&mut self, _: F)
|
pub fn set_wasm_streaming_callback<F>(&mut self, _: F)
|
||||||
where
|
where
|
||||||
F: UnitType + Fn(&mut HandleScope, Local<Value>, WasmStreaming),
|
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
|
/// Returns true if there is ongoing background work within V8 that will
|
||||||
/// eventually post a foreground task, like asynchronous WebAssembly
|
/// eventually post a foreground task, like asynchronous WebAssembly
|
||||||
/// compilation.
|
/// compilation.
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_pending_background_tasks(&self) -> bool {
|
pub fn has_pending_background_tasks(&self) -> bool {
|
||||||
unsafe { v8__Isolate__HasPendingBackgroundTasks(self) }
|
unsafe { v8__Isolate__HasPendingBackgroundTasks(self) }
|
||||||
}
|
}
|
||||||
|
@ -946,6 +984,7 @@ impl IsolateHandle {
|
||||||
self.0.isolate
|
self.0.isolate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn new(isolate: &Isolate) -> Self {
|
fn new(isolate: &Isolate) -> Self {
|
||||||
Self(isolate.get_annex_arc())
|
Self(isolate.get_annex_arc())
|
||||||
}
|
}
|
||||||
|
@ -957,6 +996,7 @@ impl IsolateHandle {
|
||||||
/// acquired the V8 lock with a Locker object.
|
/// acquired the V8 lock with a Locker object.
|
||||||
///
|
///
|
||||||
/// Returns false if Isolate was already destroyed.
|
/// Returns false if Isolate was already destroyed.
|
||||||
|
#[inline(always)]
|
||||||
pub fn terminate_execution(&self) -> bool {
|
pub fn terminate_execution(&self) -> bool {
|
||||||
let _lock = self.0.isolate_mutex.lock().unwrap();
|
let _lock = self.0.isolate_mutex.lock().unwrap();
|
||||||
if self.0.isolate.is_null() {
|
if self.0.isolate.is_null() {
|
||||||
|
@ -981,6 +1021,7 @@ impl IsolateHandle {
|
||||||
/// acquired the V8 lock with a Locker object.
|
/// acquired the V8 lock with a Locker object.
|
||||||
///
|
///
|
||||||
/// Returns false if Isolate was already destroyed.
|
/// Returns false if Isolate was already destroyed.
|
||||||
|
#[inline(always)]
|
||||||
pub fn cancel_terminate_execution(&self) -> bool {
|
pub fn cancel_terminate_execution(&self) -> bool {
|
||||||
let _lock = self.0.isolate_mutex.lock().unwrap();
|
let _lock = self.0.isolate_mutex.lock().unwrap();
|
||||||
if self.0.isolate.is_null() {
|
if self.0.isolate.is_null() {
|
||||||
|
@ -999,6 +1040,7 @@ impl IsolateHandle {
|
||||||
/// exception is still active.
|
/// exception is still active.
|
||||||
///
|
///
|
||||||
/// Returns false if Isolate was already destroyed.
|
/// Returns false if Isolate was already destroyed.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_execution_terminating(&self) -> bool {
|
pub fn is_execution_terminating(&self) -> bool {
|
||||||
let _lock = self.0.isolate_mutex.lock().unwrap();
|
let _lock = self.0.isolate_mutex.lock().unwrap();
|
||||||
if self.0.isolate.is_null() {
|
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
|
// Clippy warns that this method is dereferencing a raw pointer, but it is
|
||||||
// not: https://github.com/rust-lang/rust-clippy/issues/3045
|
// not: https://github.com/rust-lang/rust-clippy/issues/3045
|
||||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||||
|
#[inline(always)]
|
||||||
pub fn request_interrupt(
|
pub fn request_interrupt(
|
||||||
&self,
|
&self,
|
||||||
callback: InterruptCallback,
|
callback: InterruptCallback,
|
||||||
|
@ -1070,60 +1113,74 @@ impl DerefMut for OwnedIsolate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeapStatistics {
|
impl HeapStatistics {
|
||||||
|
#[inline(always)]
|
||||||
pub fn total_heap_size(&self) -> usize {
|
pub fn total_heap_size(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__total_heap_size(self) }
|
unsafe { v8__HeapStatistics__total_heap_size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn total_heap_size_executable(&self) -> usize {
|
pub fn total_heap_size_executable(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__total_heap_size_executable(self) }
|
unsafe { v8__HeapStatistics__total_heap_size_executable(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn total_physical_size(&self) -> usize {
|
pub fn total_physical_size(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__total_physical_size(self) }
|
unsafe { v8__HeapStatistics__total_physical_size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn total_available_size(&self) -> usize {
|
pub fn total_available_size(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__total_available_size(self) }
|
unsafe { v8__HeapStatistics__total_available_size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn total_global_handles_size(&self) -> usize {
|
pub fn total_global_handles_size(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__total_global_handles_size(self) }
|
unsafe { v8__HeapStatistics__total_global_handles_size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn used_global_handles_size(&self) -> usize {
|
pub fn used_global_handles_size(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__used_global_handles_size(self) }
|
unsafe { v8__HeapStatistics__used_global_handles_size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn used_heap_size(&self) -> usize {
|
pub fn used_heap_size(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__used_heap_size(self) }
|
unsafe { v8__HeapStatistics__used_heap_size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn heap_size_limit(&self) -> usize {
|
pub fn heap_size_limit(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__heap_size_limit(self) }
|
unsafe { v8__HeapStatistics__heap_size_limit(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn malloced_memory(&self) -> usize {
|
pub fn malloced_memory(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__malloced_memory(self) }
|
unsafe { v8__HeapStatistics__malloced_memory(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn external_memory(&self) -> usize {
|
pub fn external_memory(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__external_memory(self) }
|
unsafe { v8__HeapStatistics__external_memory(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn peak_malloced_memory(&self) -> usize {
|
pub fn peak_malloced_memory(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__peak_malloced_memory(self) }
|
unsafe { v8__HeapStatistics__peak_malloced_memory(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn number_of_native_contexts(&self) -> usize {
|
pub fn number_of_native_contexts(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__number_of_native_contexts(self) }
|
unsafe { v8__HeapStatistics__number_of_native_contexts(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn number_of_detached_contexts(&self) -> usize {
|
pub fn number_of_detached_contexts(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__number_of_detached_contexts(self) }
|
unsafe { v8__HeapStatistics__number_of_detached_contexts(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a 0/1 boolean, which signifies whether the V8 overwrite heap
|
/// Returns a 0/1 boolean, which signifies whether the V8 overwrite heap
|
||||||
/// garbage with a bit pattern.
|
/// garbage with a bit pattern.
|
||||||
|
#[inline(always)]
|
||||||
pub fn does_zap_garbage(&self) -> usize {
|
pub fn does_zap_garbage(&self) -> usize {
|
||||||
unsafe { v8__HeapStatistics__does_zap_garbage(self) }
|
unsafe { v8__HeapStatistics__does_zap_garbage(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern "C" {
|
||||||
|
|
||||||
/// Tries to parse the string `json_string` and returns it as value if
|
/// Tries to parse the string `json_string` and returns it as value if
|
||||||
/// successful.
|
/// successful.
|
||||||
|
#[inline(always)]
|
||||||
pub fn parse<'s>(
|
pub fn parse<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
json_string: Local<'_, String>,
|
json_string: Local<'_, String>,
|
||||||
|
@ -31,6 +32,7 @@ pub fn parse<'s>(
|
||||||
|
|
||||||
/// Tries to stringify the JSON-serializable object `json_object` and returns
|
/// Tries to stringify the JSON-serializable object `json_object` and returns
|
||||||
/// it as string if successful.
|
/// it as string if successful.
|
||||||
|
#[inline(always)]
|
||||||
pub fn stringify<'s>(
|
pub fn stringify<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
json_object: Local<'_, Value>,
|
json_object: Local<'_, Value>,
|
||||||
|
|
|
@ -215,11 +215,13 @@ pub enum ModuleStatus {
|
||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
/// Returns the module's current status.
|
/// Returns the module's current status.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_status(&self) -> ModuleStatus {
|
pub fn get_status(&self) -> ModuleStatus {
|
||||||
unsafe { v8__Module__GetStatus(self) }
|
unsafe { v8__Module__GetStatus(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For a module in kErrored status, this returns the corresponding exception.
|
/// For a module in kErrored status, this returns the corresponding exception.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_exception(&self) -> Local<Value> {
|
pub fn get_exception(&self) -> Local<Value> {
|
||||||
// Note: the returned value is not actually stored in a HandleScope,
|
// Note: the returned value is not actually stored in a HandleScope,
|
||||||
// therefore we don't need a scope object here.
|
// therefore we don't need a scope object here.
|
||||||
|
@ -227,12 +229,14 @@ impl Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the ModuleRequests for this module.
|
/// Returns the ModuleRequests for this module.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_module_requests(&self) -> Local<FixedArray> {
|
pub fn get_module_requests(&self) -> Local<FixedArray> {
|
||||||
unsafe { Local::from_raw(v8__Module__GetModuleRequests(self)) }.unwrap()
|
unsafe { Local::from_raw(v8__Module__GetModuleRequests(self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For the given source text offset in this module, returns the corresponding
|
/// For the given source text offset in this module, returns the corresponding
|
||||||
/// Location with line and column numbers.
|
/// Location with line and column numbers.
|
||||||
|
#[inline(always)]
|
||||||
pub fn source_offset_to_location(&self, offset: int) -> Location {
|
pub fn source_offset_to_location(&self, offset: int) -> Location {
|
||||||
let mut out = MaybeUninit::<Location>::uninit();
|
let mut out = MaybeUninit::<Location>::uninit();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -246,6 +250,7 @@ impl Module {
|
||||||
///
|
///
|
||||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||||
/// unique.
|
/// unique.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
||||||
unsafe { NonZeroI32::new_unchecked(v8__Module__GetIdentityHash(self)) }
|
unsafe { NonZeroI32::new_unchecked(v8__Module__GetIdentityHash(self)) }
|
||||||
}
|
}
|
||||||
|
@ -253,6 +258,7 @@ impl Module {
|
||||||
/// Returns the underlying script's id.
|
/// Returns the underlying script's id.
|
||||||
///
|
///
|
||||||
/// The module must be a SourceTextModule and must not have an Errored status.
|
/// The module must be a SourceTextModule and must not have an Errored status.
|
||||||
|
#[inline(always)]
|
||||||
pub fn script_id(&self) -> Option<int> {
|
pub fn script_id(&self) -> Option<int> {
|
||||||
if !self.is_source_text_module() {
|
if !self.is_source_text_module() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -266,6 +272,7 @@ impl Module {
|
||||||
/// Returns the namespace object of this module.
|
/// Returns the namespace object of this module.
|
||||||
///
|
///
|
||||||
/// The module's status must be at least kInstantiated.
|
/// The module's status must be at least kInstantiated.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_module_namespace(&self) -> Local<Value> {
|
pub fn get_module_namespace(&self) -> Local<Value> {
|
||||||
// Note: the returned value is not actually stored in a HandleScope,
|
// Note: the returned value is not actually stored in a HandleScope,
|
||||||
// therefore we don't need a scope object here.
|
// therefore we don't need a scope object here.
|
||||||
|
@ -280,6 +287,7 @@ impl Module {
|
||||||
///
|
///
|
||||||
/// NOTE: requires to set `--harmony-import-assertions` V8 flag.
|
/// NOTE: requires to set `--harmony-import-assertions` V8 flag.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline(always)]
|
||||||
pub fn instantiate_module<'a>(
|
pub fn instantiate_module<'a>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -302,6 +310,7 @@ impl Module {
|
||||||
/// kErrored and propagate the thrown exception (which is then also available
|
/// kErrored and propagate the thrown exception (which is then also available
|
||||||
/// via |GetException|).
|
/// via |GetException|).
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline(always)]
|
||||||
pub fn evaluate<'s>(
|
pub fn evaluate<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -313,11 +322,13 @@ impl Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the module is a SourceTextModule.
|
/// Returns whether the module is a SourceTextModule.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_source_text_module(&self) -> bool {
|
pub fn is_source_text_module(&self) -> bool {
|
||||||
unsafe { v8__Module__IsSourceTextModule(&*self) }
|
unsafe { v8__Module__IsSourceTextModule(&*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the module is a SyntheticModule.
|
/// Returns whether the module is a SyntheticModule.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_synthetic_module(&self) -> bool {
|
pub fn is_synthetic_module(&self) -> bool {
|
||||||
unsafe { v8__Module__IsSyntheticModule(&*self) }
|
unsafe { v8__Module__IsSyntheticModule(&*self) }
|
||||||
}
|
}
|
||||||
|
@ -327,6 +338,7 @@ impl Module {
|
||||||
/// export_names must not contain duplicates.
|
/// export_names must not contain duplicates.
|
||||||
/// module_name is used solely for logging/debugging and doesn't affect module
|
/// module_name is used solely for logging/debugging and doesn't affect module
|
||||||
/// behavior.
|
/// behavior.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_synthetic_module<'s, 'a>(
|
pub fn create_synthetic_module<'s, 'a>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
module_name: Local<String>,
|
module_name: Local<String>,
|
||||||
|
@ -357,6 +369,7 @@ impl Module {
|
||||||
/// of the export_names that were passed in that create_synthetic_module call.
|
/// of the export_names that were passed in that create_synthetic_module call.
|
||||||
/// Returns Some(true) on success, None if an error was thrown.
|
/// Returns Some(true) on success, None if an error was thrown.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_synthetic_module_export(
|
pub fn set_synthetic_module_export(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -374,6 +387,7 @@ impl Module {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_unbound_module_script<'s>(
|
pub fn get_unbound_module_script<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -388,12 +402,14 @@ impl Module {
|
||||||
|
|
||||||
impl ModuleRequest {
|
impl ModuleRequest {
|
||||||
/// Returns the module specifier for this ModuleRequest.
|
/// Returns the module specifier for this ModuleRequest.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_specifier(&self) -> Local<String> {
|
pub fn get_specifier(&self) -> Local<String> {
|
||||||
unsafe { Local::from_raw(v8__ModuleRequest__GetSpecifier(self)) }.unwrap()
|
unsafe { Local::from_raw(v8__ModuleRequest__GetSpecifier(self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the source code offset of this module request.
|
/// Returns the source code offset of this module request.
|
||||||
/// Use Module::source_offset_to_location to convert this to line/column numbers.
|
/// Use Module::source_offset_to_location to convert this to line/column numbers.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_source_offset(&self) -> int {
|
pub fn get_source_offset(&self) -> int {
|
||||||
unsafe { v8__ModuleRequest__GetSourceOffset(self) }
|
unsafe { v8__ModuleRequest__GetSourceOffset(self) }
|
||||||
}
|
}
|
||||||
|
@ -410,6 +426,7 @@ impl ModuleRequest {
|
||||||
/// hosts are expected to ignore assertions that they do not support (as
|
/// hosts are expected to ignore assertions that they do not support (as
|
||||||
/// opposed to, for example, triggering an error if an unsupported assertion is
|
/// opposed to, for example, triggering an error if an unsupported assertion is
|
||||||
/// present).
|
/// present).
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_import_assertions(&self) -> Local<FixedArray> {
|
pub fn get_import_assertions(&self) -> Local<FixedArray> {
|
||||||
unsafe { Local::from_raw(v8__ModuleRequest__GetImportAssertions(self)) }
|
unsafe { Local::from_raw(v8__ModuleRequest__GetImportAssertions(self)) }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -15,6 +15,7 @@ impl Name {
|
||||||
///
|
///
|
||||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||||
/// unique.
|
/// unique.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
||||||
unsafe { NonZeroI32::new_unchecked(v8__Name__GetIdentityHash(self)) }
|
unsafe { NonZeroI32::new_unchecked(v8__Name__GetIdentityHash(self)) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Number {
|
impl Number {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
value: f64,
|
value: f64,
|
||||||
|
@ -33,12 +34,14 @@ impl Number {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn value(&self) -> f64 {
|
pub fn value(&self) -> f64 {
|
||||||
unsafe { v8__Number__Value(self) }
|
unsafe { v8__Number__Value(self) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Integer {
|
impl Integer {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
value: i32,
|
value: i32,
|
||||||
|
@ -49,6 +52,7 @@ impl Integer {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_unsigned<'s>(
|
pub fn new_from_unsigned<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
value: u32,
|
value: u32,
|
||||||
|
@ -61,6 +65,7 @@ impl Integer {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn value(&self) -> i64 {
|
pub fn value(&self) -> i64 {
|
||||||
unsafe { v8__Integer__Value(self) }
|
unsafe { v8__Integer__Value(self) }
|
||||||
}
|
}
|
||||||
|
@ -68,6 +73,7 @@ impl Integer {
|
||||||
/// Internal helper function to produce a handle containing a SMI zero value,
|
/// Internal helper function to produce a handle containing a SMI zero value,
|
||||||
/// without the need for the caller to provide (or have entered) a
|
/// without the need for the caller to provide (or have entered) a
|
||||||
/// `HandleScope`.
|
/// `HandleScope`.
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn zero<'s>() -> Local<'s, Integer> {
|
pub(crate) fn zero<'s>() -> Local<'s, Integer> {
|
||||||
// The SMI representation of zero is also zero. In debug builds, double
|
// The SMI representation of zero is also zero. In debug builds, double
|
||||||
// check this, so in the unlikely event that V8 changes its internal
|
// check this, so in the unlikely event that V8 changes its internal
|
||||||
|
@ -84,12 +90,14 @@ impl Integer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Uint32 {
|
impl Uint32 {
|
||||||
|
#[inline(always)]
|
||||||
pub fn value(&self) -> u32 {
|
pub fn value(&self) -> u32 {
|
||||||
unsafe { v8__Uint32__Value(self) }
|
unsafe { v8__Uint32__Value(self) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Int32 {
|
impl Int32 {
|
||||||
|
#[inline(always)]
|
||||||
pub fn value(&self) -> i32 {
|
pub fn value(&self) -> i32 {
|
||||||
unsafe { v8__Int32__Value(self) }
|
unsafe { v8__Int32__Value(self) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,6 +210,7 @@ extern "C" {
|
||||||
|
|
||||||
impl Object {
|
impl Object {
|
||||||
/// Creates an empty object.
|
/// Creates an empty object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Object> {
|
pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Object> {
|
||||||
unsafe { scope.cast_local(|sd| v8__Object__New(sd.get_isolate_ptr())) }
|
unsafe { scope.cast_local(|sd| v8__Object__New(sd.get_isolate_ptr())) }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -220,6 +221,7 @@ impl Object {
|
||||||
/// the newly created object won't have a prototype at all). This is similar
|
/// the newly created object won't have a prototype at all). This is similar
|
||||||
/// to Object.create(). All properties will be created as enumerable,
|
/// to Object.create(). All properties will be created as enumerable,
|
||||||
/// configurable and writable properties.
|
/// configurable and writable properties.
|
||||||
|
#[inline(always)]
|
||||||
pub fn with_prototype_and_properties<'s>(
|
pub fn with_prototype_and_properties<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
prototype_or_null: Local<'s, Value>,
|
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
|
/// Set only return Just(true) or Empty(), so if it should never fail, use
|
||||||
/// result.Check().
|
/// result.Check().
|
||||||
|
#[inline(always)]
|
||||||
pub fn set(
|
pub fn set(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -259,6 +262,7 @@ impl Object {
|
||||||
|
|
||||||
/// Set only return Just(true) or Empty(), so if it should never fail, use
|
/// Set only return Just(true) or Empty(), so if it should never fail, use
|
||||||
/// result.Check().
|
/// result.Check().
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_index(
|
pub fn set_index(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -273,6 +277,7 @@ impl Object {
|
||||||
|
|
||||||
/// Set the prototype object. This does not skip objects marked to be
|
/// Set the prototype object. This does not skip objects marked to be
|
||||||
/// skipped by proto and it does not consult the security handler.
|
/// skipped by proto and it does not consult the security handler.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_prototype(
|
pub fn set_prototype(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -291,6 +296,7 @@ impl Object {
|
||||||
/// or the object is not extensible.
|
/// or the object is not extensible.
|
||||||
///
|
///
|
||||||
/// Returns true on success.
|
/// Returns true on success.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_data_property(
|
pub fn create_data_property(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -314,6 +320,7 @@ impl Object {
|
||||||
/// for specifying attributes.
|
/// for specifying attributes.
|
||||||
///
|
///
|
||||||
/// Returns true on success.
|
/// Returns true on success.
|
||||||
|
#[inline(always)]
|
||||||
pub fn define_own_property(
|
pub fn define_own_property(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -333,6 +340,7 @@ impl Object {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get<'s>(
|
pub fn get<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -344,6 +352,7 @@ impl Object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_index<'s>(
|
pub fn get_index<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -358,6 +367,7 @@ impl Object {
|
||||||
|
|
||||||
/// Get the prototype object. This does not skip objects marked to be
|
/// Get the prototype object. This does not skip objects marked to be
|
||||||
/// skipped by proto and it does not consult the security handler.
|
/// skipped by proto and it does not consult the security handler.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_prototype<'s>(
|
pub fn get_prototype<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -366,6 +376,7 @@ impl Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Note: SideEffectType affects the getter only, not the setter.
|
/// Note: SideEffectType affects the getter only, not the setter.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_accessor(
|
pub fn set_accessor(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -383,6 +394,7 @@ impl Object {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_accessor_with_setter(
|
pub fn set_accessor_with_setter(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -407,11 +419,13 @@ impl Object {
|
||||||
///
|
///
|
||||||
/// The return value will never be 0. Also, it is not guaranteed to be
|
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||||
/// unique.
|
/// unique.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
pub fn get_identity_hash(&self) -> NonZeroI32 {
|
||||||
unsafe { NonZeroI32::new_unchecked(v8__Object__GetIdentityHash(self)) }
|
unsafe { NonZeroI32::new_unchecked(v8__Object__GetIdentityHash(self)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the context in which the object was created.
|
/// Returns the context in which the object was created.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_creation_context<'s>(
|
pub fn get_creation_context<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -422,6 +436,7 @@ impl Object {
|
||||||
/// This function has the same functionality as GetPropertyNames but the
|
/// This function has the same functionality as GetPropertyNames but the
|
||||||
/// returned array doesn't contain the names of properties from prototype
|
/// returned array doesn't contain the names of properties from prototype
|
||||||
/// objects.
|
/// objects.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_own_property_names<'s>(
|
pub fn get_own_property_names<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -443,6 +458,7 @@ impl Object {
|
||||||
/// object, including properties from prototype objects. The array returned by
|
/// object, including properties from prototype objects. The array returned by
|
||||||
/// this method contains the same values as would be enumerated by a for-in
|
/// this method contains the same values as would be enumerated by a for-in
|
||||||
/// statement over this object.
|
/// statement over this object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_property_names<'s>(
|
pub fn get_property_names<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -472,6 +488,7 @@ impl Object {
|
||||||
//
|
//
|
||||||
// Note: This function converts the key to a name, which possibly calls back
|
// Note: This function converts the key to a name, which possibly calls back
|
||||||
// into JavaScript.
|
// into JavaScript.
|
||||||
|
#[inline(always)]
|
||||||
pub fn has<'s>(
|
pub fn has<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -481,6 +498,7 @@ impl Object {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_index<'s>(
|
pub fn has_index<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -491,6 +509,7 @@ impl Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
|
/// HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_own_property<'s>(
|
pub fn has_own_property<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -502,6 +521,7 @@ impl Object {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn delete<'s>(
|
pub fn delete<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -523,12 +543,14 @@ impl Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the number of internal fields for this Object.
|
/// Gets the number of internal fields for this Object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn internal_field_count(&self) -> usize {
|
pub fn internal_field_count(&self) -> usize {
|
||||||
let count = unsafe { v8__Object__InternalFieldCount(self) };
|
let count = unsafe { v8__Object__InternalFieldCount(self) };
|
||||||
usize::try_from(count).expect("bad internal field count") // Can't happen.
|
usize::try_from(count).expect("bad internal field count") // Can't happen.
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the value from an internal field.
|
/// Gets the value from an internal field.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_internal_field<'s>(
|
pub fn get_internal_field<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -552,6 +574,7 @@ impl Object {
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// This field must have been set by SetAlignedPointerInInternalField, everything else leads to undefined behavior.
|
/// 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(
|
pub unsafe fn get_aligned_pointer_from_internal_field(
|
||||||
&self,
|
&self,
|
||||||
index: i32,
|
index: i32,
|
||||||
|
@ -562,6 +585,7 @@ impl Object {
|
||||||
/// Sets a 2-byte-aligned native pointer in an internal field.
|
/// Sets a 2-byte-aligned native pointer in an internal field.
|
||||||
/// To retrieve such a field, GetAlignedPointerFromInternalField must be used.
|
/// To retrieve such a field, GetAlignedPointerFromInternalField must be used.
|
||||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_aligned_pointer_in_internal_field(
|
pub fn set_aligned_pointer_in_internal_field(
|
||||||
&self,
|
&self,
|
||||||
index: i32,
|
index: i32,
|
||||||
|
@ -571,6 +595,7 @@ impl Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the integrity level of the object.
|
/// Sets the integrity level of the object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_integrity_level(
|
pub fn set_integrity_level(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -584,6 +609,7 @@ impl Object {
|
||||||
|
|
||||||
/// Sets the value in an internal field. Returns false when the index
|
/// Sets the value in an internal field. Returns false when the index
|
||||||
/// is out of bounds, true otherwise.
|
/// is out of bounds, true otherwise.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_internal_field(&self, index: usize, value: Local<Value>) -> bool {
|
pub fn set_internal_field(&self, index: usize, value: Local<Value>) -> bool {
|
||||||
// Trying to access out-of-bounds internal fields makes V8 abort
|
// Trying to access out-of-bounds internal fields makes V8 abort
|
||||||
// in debug mode and access out-of-bounds memory in release mode.
|
// 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.
|
/// This is an experimental feature, use at your own risk.
|
||||||
/// Note: Private properties are not inherited. Do not rely on this, since it
|
/// Note: Private properties are not inherited. Do not rely on this, since it
|
||||||
/// may change.
|
/// may change.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_private<'s>(
|
pub fn get_private<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -618,6 +645,7 @@ impl Object {
|
||||||
/// This is an experimental feature, use at your own risk.
|
/// This is an experimental feature, use at your own risk.
|
||||||
/// Note: Private properties are not inherited. Do not rely on this, since it
|
/// Note: Private properties are not inherited. Do not rely on this, since it
|
||||||
/// may change.
|
/// may change.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_private<'s>(
|
pub fn set_private<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -639,6 +667,7 @@ impl Object {
|
||||||
/// This is an experimental feature, use at your own risk.
|
/// This is an experimental feature, use at your own risk.
|
||||||
/// Note: Private properties are not inherited. Do not rely on this, since it
|
/// Note: Private properties are not inherited. Do not rely on this, since it
|
||||||
/// may change.
|
/// may change.
|
||||||
|
#[inline(always)]
|
||||||
pub fn delete_private<'s>(
|
pub fn delete_private<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -654,6 +683,7 @@ impl Object {
|
||||||
/// This is an experimental feature, use at your own risk.
|
/// This is an experimental feature, use at your own risk.
|
||||||
/// Note: Private properties are not inherited. Do not rely on this, since it
|
/// Note: Private properties are not inherited. Do not rely on this, since it
|
||||||
/// may change.
|
/// may change.
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_private<'s>(
|
pub fn has_private<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -683,6 +713,7 @@ pub enum IntegrityLevel {
|
||||||
impl Array {
|
impl Array {
|
||||||
/// Creates a JavaScript array with the given length. If the length
|
/// Creates a JavaScript array with the given length. If the length
|
||||||
/// is negative the returned array will have length 0.
|
/// is negative the returned array will have length 0.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(scope: &mut HandleScope<'s>, length: i32) -> Local<'s, Array> {
|
pub fn new<'s>(scope: &mut HandleScope<'s>, length: i32) -> Local<'s, Array> {
|
||||||
unsafe {
|
unsafe {
|
||||||
scope.cast_local(|sd| v8__Array__New(sd.get_isolate_ptr(), length))
|
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
|
/// Creates a JavaScript array out of a Local<Value> array with a known
|
||||||
/// length.
|
/// length.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_with_elements<'s>(
|
pub fn new_with_elements<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
elements: &[Local<Value>],
|
elements: &[Local<Value>],
|
||||||
|
@ -712,25 +744,30 @@ impl Array {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn length(&self) -> u32 {
|
pub fn length(&self) -> u32 {
|
||||||
unsafe { v8__Array__Length(self) }
|
unsafe { v8__Array__Length(self) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Map {
|
impl Map {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Map> {
|
pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Map> {
|
||||||
unsafe { scope.cast_local(|sd| v8__Map__New(sd.get_isolate_ptr())) }
|
unsafe { scope.cast_local(|sd| v8__Map__New(sd.get_isolate_ptr())) }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn size(&self) -> usize {
|
pub fn size(&self) -> usize {
|
||||||
unsafe { v8__Map__Size(self) }
|
unsafe { v8__Map__Size(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
unsafe { v8__Map__Clear(self) }
|
unsafe { v8__Map__Clear(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get<'s>(
|
pub fn get<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -741,6 +778,7 @@ impl Map {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set<'s>(
|
pub fn set<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -754,6 +792,7 @@ impl Map {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn has(
|
pub fn has(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -762,6 +801,7 @@ impl Map {
|
||||||
unsafe { v8__Map__Has(self, &*scope.get_current_context(), &*key) }.into()
|
unsafe { v8__Map__Has(self, &*scope.get_current_context(), &*key) }.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn delete(
|
pub fn delete(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -773,6 +813,7 @@ impl Map {
|
||||||
|
|
||||||
/// Returns an array of length size() * 2, where index N is the Nth key and
|
/// Returns an array of length size() * 2, where index N is the Nth key and
|
||||||
/// index N + 1 is the Nth value.
|
/// index N + 1 is the Nth value.
|
||||||
|
#[inline(always)]
|
||||||
pub fn as_array<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Array> {
|
pub fn as_array<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Array> {
|
||||||
unsafe { scope.cast_local(|_| v8__Map__As__Array(self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Map__As__Array(self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ pub struct Platform(Opaque);
|
||||||
/// If |idle_task_support| is enabled then the platform will accept idle
|
/// If |idle_task_support| is enabled then the platform will accept idle
|
||||||
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
||||||
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_default_platform(
|
pub fn new_default_platform(
|
||||||
thread_pool_size: u32,
|
thread_pool_size: u32,
|
||||||
idle_task_support: bool,
|
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
|
/// If |idle_task_support| is enabled then the platform will accept idle
|
||||||
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
||||||
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_single_threaded_default_platform(
|
pub fn new_single_threaded_default_platform(
|
||||||
idle_task_support: bool,
|
idle_task_support: bool,
|
||||||
) -> UniqueRef<Platform> {
|
) -> UniqueRef<Platform> {
|
||||||
|
@ -86,6 +88,7 @@ impl Platform {
|
||||||
/// If |idle_task_support| is enabled then the platform will accept idle
|
/// If |idle_task_support| is enabled then the platform will accept idle
|
||||||
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
||||||
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
thread_pool_size: u32,
|
thread_pool_size: u32,
|
||||||
idle_task_support: bool,
|
idle_task_support: bool,
|
||||||
|
@ -104,6 +107,7 @@ impl Platform {
|
||||||
/// If |idle_task_support| is enabled then the platform will accept idle
|
/// If |idle_task_support| is enabled then the platform will accept idle
|
||||||
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
/// tasks (IdleTasksEnabled will return true) and will rely on the embedder
|
||||||
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
/// calling v8::platform::RunIdleTasks to process the idle tasks.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_single_threaded(idle_task_support: bool) -> UniqueRef<Self> {
|
pub fn new_single_threaded(idle_task_support: bool) -> UniqueRef<Self> {
|
||||||
unsafe {
|
unsafe {
|
||||||
UniqueRef::from_raw(v8__Platform__NewSingleThreadedDefaultPlatform(
|
UniqueRef::from_raw(v8__Platform__NewSingleThreadedDefaultPlatform(
|
||||||
|
@ -121,6 +125,7 @@ impl Platform {
|
||||||
/// PumpMessageLoop is nested within another call to PumpMessageLoop, only
|
/// PumpMessageLoop is nested within another call to PumpMessageLoop, only
|
||||||
/// nestable tasks may run. Otherwise, any task may run. Unless requested through
|
/// 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.
|
/// the |wait_for_work| parameter, this call does not block if no task is pending.
|
||||||
|
#[inline(always)]
|
||||||
pub fn pump_message_loop(
|
pub fn pump_message_loop(
|
||||||
platform: &SharedRef<Self>,
|
platform: &SharedRef<Self>,
|
||||||
isolate: &mut Isolate,
|
isolate: &mut Isolate,
|
||||||
|
@ -139,6 +144,7 @@ impl Platform {
|
||||||
///
|
///
|
||||||
/// The caller has to make sure that this is called from the right thread.
|
/// The caller has to make sure that this is called from the right thread.
|
||||||
/// This call does not block if no task is pending.
|
/// This call does not block if no task is pending.
|
||||||
|
#[inline(always)]
|
||||||
pub fn run_idle_tasks(
|
pub fn run_idle_tasks(
|
||||||
platform: &SharedRef<Self>,
|
platform: &SharedRef<Self>,
|
||||||
isolate: &mut Isolate,
|
isolate: &mut Isolate,
|
||||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrimitiveArray {
|
impl PrimitiveArray {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
length: usize,
|
length: usize,
|
||||||
|
@ -41,10 +42,12 @@ impl PrimitiveArray {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn length(&self) -> usize {
|
pub fn length(&self) -> usize {
|
||||||
unsafe { v8__PrimitiveArray__Length(self) as usize }
|
unsafe { v8__PrimitiveArray__Length(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set<'s>(
|
pub fn set<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -61,6 +64,7 @@ impl PrimitiveArray {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get<'s>(
|
pub fn get<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
|
|
@ -11,15 +11,18 @@ extern "C" {
|
||||||
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *const Boolean;
|
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *const Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn null<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Primitive> {
|
pub fn null<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Primitive> {
|
||||||
unsafe { scope.cast_local(|sd| v8__Null(sd.get_isolate_ptr())) }.unwrap()
|
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> {
|
pub fn undefined<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, Primitive> {
|
||||||
unsafe { scope.cast_local(|sd| v8__Undefined(sd.get_isolate_ptr())) }.unwrap()
|
unsafe { scope.cast_local(|sd| v8__Undefined(sd.get_isolate_ptr())) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Boolean {
|
impl Boolean {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
value: bool,
|
value: bool,
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern "C" {
|
||||||
|
|
||||||
impl Private {
|
impl Private {
|
||||||
/// Create a private symbol. If name is not empty, it will be the description.
|
/// Create a private symbol. If name is not empty, it will be the description.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
name: Option<Local<String>>,
|
name: Option<Local<String>>,
|
||||||
|
@ -41,6 +42,7 @@ impl Private {
|
||||||
/// Also, there is only one global name space for the names used as keys.
|
/// 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,
|
/// To minimize the potential for clashes, use qualified names as keys,
|
||||||
/// e.g., "Class#property".
|
/// e.g., "Class#property".
|
||||||
|
#[inline(always)]
|
||||||
pub fn for_api<'s>(
|
pub fn for_api<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
name: Option<Local<String>>,
|
name: Option<Local<String>>,
|
||||||
|
@ -57,6 +59,7 @@ impl Private {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the print name string of the private symbol, or undefined if none.
|
/// 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> {
|
pub fn name<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, Value> {
|
||||||
unsafe { scope.cast_local(|_| v8__Private__Name(&*self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Private__Name(&*self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,18 +67,21 @@ pub enum PromiseState {
|
||||||
|
|
||||||
impl Promise {
|
impl Promise {
|
||||||
/// Returns the value of the [[PromiseState]] field.
|
/// Returns the value of the [[PromiseState]] field.
|
||||||
|
#[inline(always)]
|
||||||
pub fn state(&self) -> PromiseState {
|
pub fn state(&self) -> PromiseState {
|
||||||
unsafe { v8__Promise__State(&*self) }
|
unsafe { v8__Promise__State(&*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the promise has at least one derived promise, and
|
/// Returns true if the promise has at least one derived promise, and
|
||||||
/// therefore resolve/reject handlers (including default handler).
|
/// therefore resolve/reject handlers (including default handler).
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_handler(&self) -> bool {
|
pub fn has_handler(&self) -> bool {
|
||||||
unsafe { v8__Promise__HasHandler(&*self) }
|
unsafe { v8__Promise__HasHandler(&*self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the content of the [[PromiseResult]] field. The Promise must not
|
/// Returns the content of the [[PromiseResult]] field. The Promise must not
|
||||||
/// be pending.
|
/// be pending.
|
||||||
|
#[inline(always)]
|
||||||
pub fn result<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
|
pub fn result<'s>(&self, scope: &mut HandleScope<'s>) -> Local<'s, Value> {
|
||||||
unsafe { scope.cast_local(|_| v8__Promise__Result(&*self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Promise__Result(&*self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -86,6 +89,7 @@ impl Promise {
|
||||||
/// Register a rejection handler with a promise.
|
/// Register a rejection handler with a promise.
|
||||||
///
|
///
|
||||||
/// See `Self::then2`.
|
/// See `Self::then2`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn catch<'s>(
|
pub fn catch<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -101,6 +105,7 @@ impl Promise {
|
||||||
/// Register a resolution handler with a promise.
|
/// Register a resolution handler with a promise.
|
||||||
///
|
///
|
||||||
/// See `Self::then2`.
|
/// See `Self::then2`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn then<'s>(
|
pub fn then<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -117,6 +122,7 @@ impl Promise {
|
||||||
/// The handler is given the respective resolution/rejection value as
|
/// The handler is given the respective resolution/rejection value as
|
||||||
/// an argument. If the promise is already resolved/rejected, the handler is
|
/// an argument. If the promise is already resolved/rejected, the handler is
|
||||||
/// invoked at the end of turn.
|
/// invoked at the end of turn.
|
||||||
|
#[inline(always)]
|
||||||
pub fn then2<'s>(
|
pub fn then2<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -138,6 +144,7 @@ impl Promise {
|
||||||
|
|
||||||
impl PromiseResolver {
|
impl PromiseResolver {
|
||||||
/// Create a new resolver, along with an associated promise in pending state.
|
/// Create a new resolver, along with an associated promise in pending state.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
) -> Option<Local<'s, PromiseResolver>> {
|
) -> Option<Local<'s, PromiseResolver>> {
|
||||||
|
@ -148,6 +155,7 @@ impl PromiseResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the associated promise.
|
/// Extract the associated promise.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_promise<'s>(
|
pub fn get_promise<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -158,6 +166,7 @@ impl PromiseResolver {
|
||||||
|
|
||||||
/// Resolve the associated promise with a given value.
|
/// Resolve the associated promise with a given value.
|
||||||
/// Ignored if the promise is no longer pending.
|
/// Ignored if the promise is no longer pending.
|
||||||
|
#[inline(always)]
|
||||||
pub fn resolve(
|
pub fn resolve(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -175,6 +184,7 @@ impl PromiseResolver {
|
||||||
|
|
||||||
/// Reject the associated promise with a given value.
|
/// Reject the associated promise with a given value.
|
||||||
/// Ignored if the promise is no longer pending.
|
/// Ignored if the promise is no longer pending.
|
||||||
|
#[inline(always)]
|
||||||
pub fn reject(
|
pub fn reject(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope,
|
scope: &mut HandleScope,
|
||||||
|
@ -205,15 +215,18 @@ pub enum PromiseRejectEvent {
|
||||||
pub struct PromiseRejectMessage<'msg>([usize; 3], PhantomData<&'msg ()>);
|
pub struct PromiseRejectMessage<'msg>([usize; 3], PhantomData<&'msg ()>);
|
||||||
|
|
||||||
impl<'msg> PromiseRejectMessage<'msg> {
|
impl<'msg> PromiseRejectMessage<'msg> {
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_promise(&self) -> Local<'msg, Promise> {
|
pub fn get_promise(&self) -> Local<'msg, Promise> {
|
||||||
unsafe { Local::from_raw(v8__PromiseRejectMessage__GetPromise(self)) }
|
unsafe { Local::from_raw(v8__PromiseRejectMessage__GetPromise(self)) }
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_event(&self) -> PromiseRejectEvent {
|
pub fn get_event(&self) -> PromiseRejectEvent {
|
||||||
unsafe { v8__PromiseRejectMessage__GetEvent(self) }
|
unsafe { v8__PromiseRejectMessage__GetEvent(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_value(&self) -> Option<Local<'msg, Value>> {
|
pub fn get_value(&self) -> Option<Local<'msg, Value>> {
|
||||||
unsafe { Local::from_raw(v8__PromiseRejectMessage__GetValue(self)) }
|
unsafe { Local::from_raw(v8__PromiseRejectMessage__GetValue(self)) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,25 +19,30 @@ pub const DONT_DELETE: PropertyAttribute = PropertyAttribute(4);
|
||||||
|
|
||||||
impl PropertyAttribute {
|
impl PropertyAttribute {
|
||||||
/// Test if no property attributes are set.
|
/// Test if no property attributes are set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_none(&self) -> bool {
|
pub fn is_none(&self) -> bool {
|
||||||
*self == NONE
|
*self == NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the read-only property attribute is set.
|
/// Test if the read-only property attribute is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_read_only(&self) -> bool {
|
pub fn is_read_only(&self) -> bool {
|
||||||
self.has(READ_ONLY)
|
self.has(READ_ONLY)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the non-enumerable property attribute is set.
|
/// Test if the non-enumerable property attribute is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_dont_enum(&self) -> bool {
|
pub fn is_dont_enum(&self) -> bool {
|
||||||
self.has(DONT_ENUM)
|
self.has(DONT_ENUM)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the non-configurable property attribute is set.
|
/// Test if the non-configurable property attribute is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_dont_delete(&self) -> bool {
|
pub fn is_dont_delete(&self) -> bool {
|
||||||
self.has(DONT_DELETE)
|
self.has(DONT_DELETE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn has(&self, that: Self) -> bool {
|
fn has(&self, that: Self) -> bool {
|
||||||
let Self(lhs) = self;
|
let Self(lhs) = self;
|
||||||
let Self(rhs) = that;
|
let Self(rhs) = that;
|
||||||
|
|
|
@ -16,35 +16,42 @@ pub const SKIP_SYMBOLS: PropertyFilter = PropertyFilter(16);
|
||||||
|
|
||||||
impl PropertyFilter {
|
impl PropertyFilter {
|
||||||
/// Test if all property filters are set.
|
/// Test if all property filters are set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_all_properties(&self) -> bool {
|
pub fn is_all_properties(&self) -> bool {
|
||||||
*self == ALL_PROPERTIES
|
*self == ALL_PROPERTIES
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the only-writable property filter is set.
|
/// Test if the only-writable property filter is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_only_writable(&self) -> bool {
|
pub fn is_only_writable(&self) -> bool {
|
||||||
self.has(ONLY_WRITABLE)
|
self.has(ONLY_WRITABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the only-enumerable property filter is set.
|
/// Test if the only-enumerable property filter is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_only_enumerable(&self) -> bool {
|
pub fn is_only_enumerable(&self) -> bool {
|
||||||
self.has(ONLY_ENUMERABLE)
|
self.has(ONLY_ENUMERABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the only-configurable property filter is set.
|
/// Test if the only-configurable property filter is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_only_configurable(&self) -> bool {
|
pub fn is_only_configurable(&self) -> bool {
|
||||||
self.has(ONLY_CONFIGURABLE)
|
self.has(ONLY_CONFIGURABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the skip-strings property filter is set.
|
/// Test if the skip-strings property filter is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_skip_strings(&self) -> bool {
|
pub fn is_skip_strings(&self) -> bool {
|
||||||
self.has(SKIP_STRINGS)
|
self.has(SKIP_STRINGS)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if the skip-symbols property filter is set.
|
/// Test if the skip-symbols property filter is set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_skip_symbols(&self) -> bool {
|
pub fn is_skip_symbols(&self) -> bool {
|
||||||
self.has(SKIP_SYMBOLS)
|
self.has(SKIP_SYMBOLS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn has(&self, that: Self) -> bool {
|
fn has(&self, that: Self) -> bool {
|
||||||
let Self(lhs) = self;
|
let Self(lhs) = self;
|
||||||
let Self(rhs) = that;
|
let Self(rhs) = that;
|
||||||
|
|
|
@ -18,6 +18,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Proxy {
|
impl Proxy {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
target: Local<Object>,
|
target: Local<Object>,
|
||||||
|
@ -30,6 +31,7 @@ impl Proxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_handler<'s>(
|
pub fn get_handler<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -37,6 +39,7 @@ impl Proxy {
|
||||||
unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_target<'s>(
|
pub fn get_target<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -44,10 +47,12 @@ impl Proxy {
|
||||||
unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap()
|
unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_revoked(&self) -> bool {
|
pub fn is_revoked(&self) -> bool {
|
||||||
unsafe { v8__Proxy__IsRevoked(self) }
|
unsafe { v8__Proxy__IsRevoked(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn revoke(&self) {
|
pub fn revoke(&self) {
|
||||||
unsafe { v8__Proxy__Revoke(self) };
|
unsafe { v8__Proxy__Revoke(self) };
|
||||||
}
|
}
|
||||||
|
|
13
src/scope.rs
13
src/scope.rs
|
@ -179,6 +179,7 @@ impl<'s> HandleScope<'s> {
|
||||||
|
|
||||||
/// Returns the context of the currently running JavaScript, or the context
|
/// Returns the context of the currently running JavaScript, or the context
|
||||||
/// on the top of the stack if no JavaScript is running.
|
/// on the top of the stack if no JavaScript is running.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_current_context(&self) -> Local<'s, Context> {
|
pub fn get_current_context(&self) -> Local<'s, Context> {
|
||||||
let context_ptr = data::ScopeData::get(self).get_current_context();
|
let context_ptr = data::ScopeData::get(self).get_current_context();
|
||||||
unsafe { Local::from_raw(context_ptr) }.unwrap()
|
unsafe { Local::from_raw(context_ptr) }.unwrap()
|
||||||
|
@ -205,6 +206,7 @@ impl<'s> HandleScope<'s, ()> {
|
||||||
/// JavaScript operations.
|
/// JavaScript operations.
|
||||||
///
|
///
|
||||||
/// This function always returns the `undefined` value.
|
/// This function always returns the `undefined` value.
|
||||||
|
#[inline(always)]
|
||||||
pub fn throw_exception(
|
pub fn throw_exception(
|
||||||
&mut self,
|
&mut self,
|
||||||
exception: Local<Value>,
|
exception: Local<Value>,
|
||||||
|
@ -217,6 +219,7 @@ impl<'s> HandleScope<'s, ()> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) unsafe fn cast_local<T>(
|
pub(crate) unsafe fn cast_local<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
f: impl FnOnce(&mut data::ScopeData) -> *const T,
|
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)))
|
Local::from_raw(f(data::ScopeData::get_mut(self)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn get_isolate_ptr(&self) -> *mut Isolate {
|
pub(crate) fn get_isolate_ptr(&self) -> *mut Isolate {
|
||||||
data::ScopeData::get(self).get_isolate_ptr()
|
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> {
|
impl<'s, P> TryCatch<'s, P> {
|
||||||
/// Returns true if an exception has been caught by this try/catch block.
|
/// Returns true if an exception has been caught by this try/catch block.
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_caught(&self) -> bool {
|
pub fn has_caught(&self) -> bool {
|
||||||
unsafe { raw::v8__TryCatch__HasCaught(self.get_raw()) }
|
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
|
/// cleanup needed and then return. If CanContinue returns false and
|
||||||
/// HasTerminated returns true, it is possible to call
|
/// HasTerminated returns true, it is possible to call
|
||||||
/// CancelTerminateExecution in order to continue calling into the engine.
|
/// CancelTerminateExecution in order to continue calling into the engine.
|
||||||
|
#[inline(always)]
|
||||||
pub fn can_continue(&self) -> bool {
|
pub fn can_continue(&self) -> bool {
|
||||||
unsafe { raw::v8__TryCatch__CanContinue(self.get_raw()) }
|
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,
|
/// If such an exception has been thrown, HasTerminated will return true,
|
||||||
/// indicating that it is possible to call CancelTerminateExecution in order
|
/// indicating that it is possible to call CancelTerminateExecution in order
|
||||||
/// to continue calling into the engine.
|
/// to continue calling into the engine.
|
||||||
|
#[inline(always)]
|
||||||
pub fn has_terminated(&self) -> bool {
|
pub fn has_terminated(&self) -> bool {
|
||||||
unsafe { raw::v8__TryCatch__HasTerminated(self.get_raw()) }
|
unsafe { raw::v8__TryCatch__HasTerminated(self.get_raw()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if verbosity is enabled.
|
/// Returns true if verbosity is enabled.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_verbose(&self) -> bool {
|
pub fn is_verbose(&self) -> bool {
|
||||||
unsafe { raw::v8__TryCatch__IsVerbose(self.get_raw()) }
|
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
|
/// handler are not reported. Call SetVerbose with true on an
|
||||||
/// external exception handler to have exceptions caught by the
|
/// external exception handler to have exceptions caught by the
|
||||||
/// handler reported as if they were not caught.
|
/// handler reported as if they were not caught.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_verbose(&mut self, value: bool) {
|
pub fn set_verbose(&mut self, value: bool) {
|
||||||
unsafe { raw::v8__TryCatch__SetVerbose(self.get_raw_mut(), value) };
|
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
|
/// Set whether or not this TryCatch should capture a Message object
|
||||||
/// which holds source information about where the exception
|
/// which holds source information about where the exception
|
||||||
/// occurred. True by default.
|
/// occurred. True by default.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_capture_message(&mut self, value: bool) {
|
pub fn set_capture_message(&mut self, value: bool) {
|
||||||
unsafe { raw::v8__TryCatch__SetCaptureMessage(self.get_raw_mut(), value) };
|
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
|
/// another exception is thrown the previously caught exception will just be
|
||||||
/// overwritten. However, it is often a good idea since it makes it easier
|
/// overwritten. However, it is often a good idea since it makes it easier
|
||||||
/// to determine which operation threw a given exception.
|
/// to determine which operation threw a given exception.
|
||||||
|
#[inline(always)]
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
unsafe { raw::v8__TryCatch__Reset(self.get_raw_mut()) };
|
unsafe { raw::v8__TryCatch__Reset(self.get_raw_mut()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn get_raw(&self) -> &raw::TryCatch {
|
fn get_raw(&self) -> &raw::TryCatch {
|
||||||
data::ScopeData::get(self).get_try_catch()
|
data::ScopeData::get(self).get_try_catch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn get_raw_mut(&mut self) -> &mut raw::TryCatch {
|
fn get_raw_mut(&mut self) -> &mut raw::TryCatch {
|
||||||
data::ScopeData::get_mut(self).get_try_catch_mut()
|
data::ScopeData::get_mut(self).get_try_catch_mut()
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ extern "C" {
|
||||||
|
|
||||||
impl Script {
|
impl Script {
|
||||||
/// A shorthand for ScriptCompiler::Compile().
|
/// A shorthand for ScriptCompiler::Compile().
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile<'s>(
|
pub fn compile<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
source: Local<String>,
|
source: Local<String>,
|
||||||
|
@ -64,6 +65,7 @@ impl Script {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the corresponding context-unbound script.
|
/// Returns the corresponding context-unbound script.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_unbound_script<'s>(
|
pub fn get_unbound_script<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -78,6 +80,7 @@ impl Script {
|
||||||
/// Runs the script returning the resulting value. It will be run in the
|
/// Runs the script returning the resulting value. It will be run in the
|
||||||
/// context in which it was created (ScriptCompiler::CompileBound or
|
/// context in which it was created (ScriptCompiler::CompileBound or
|
||||||
/// UnboundScript::BindToCurrentContext()).
|
/// UnboundScript::BindToCurrentContext()).
|
||||||
|
#[inline(always)]
|
||||||
pub fn run<'s>(
|
pub fn run<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -91,6 +94,7 @@ impl Script {
|
||||||
/// The origin, within a file, of a script.
|
/// The origin, within a file, of a script.
|
||||||
impl<'s> ScriptOrigin<'s> {
|
impl<'s> ScriptOrigin<'s> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
resource_name: Local<'s, Value>,
|
resource_name: Local<'s, Value>,
|
||||||
|
|
|
@ -111,6 +111,7 @@ impl<'a> CachedData<'a> {
|
||||||
cached_data
|
cached_data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub(crate) fn buffer_policy(&self) -> BufferPolicy {
|
pub(crate) fn buffer_policy(&self) -> BufferPolicy {
|
||||||
self.buffer_policy
|
self.buffer_policy
|
||||||
}
|
}
|
||||||
|
@ -132,6 +133,7 @@ pub(crate) enum BufferPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Source {
|
impl Source {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
source_string: Local<String>,
|
source_string: Local<String>,
|
||||||
origin: Option<&ScriptOrigin>,
|
origin: Option<&ScriptOrigin>,
|
||||||
|
@ -148,6 +150,7 @@ impl Source {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_with_cached_data(
|
pub fn new_with_cached_data(
|
||||||
source_string: Local<String>,
|
source_string: Local<String>,
|
||||||
origin: Option<&ScriptOrigin>,
|
origin: Option<&ScriptOrigin>,
|
||||||
|
@ -165,6 +168,7 @@ impl Source {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_cached_data(&self) -> Option<&CachedData> {
|
pub fn get_cached_data(&self) -> Option<&CachedData> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let cached_data = v8__ScriptCompiler__Source__GetCachedData(self);
|
let cached_data = v8__ScriptCompiler__Source__GetCachedData(self);
|
||||||
|
@ -217,6 +221,7 @@ pub enum NoCacheReason {
|
||||||
///
|
///
|
||||||
/// Corresponds to the ParseModule abstract operation in the ECMAScript
|
/// Corresponds to the ParseModule abstract operation in the ECMAScript
|
||||||
/// specification.
|
/// specification.
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile_module<'s>(
|
pub fn compile_module<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
source: Source,
|
source: Source,
|
||||||
|
@ -230,6 +235,7 @@ pub fn compile_module<'s>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Same as compile_module with more options.
|
/// Same as compile_module with more options.
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile_module2<'s>(
|
pub fn compile_module2<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
mut source: Source,
|
mut source: Source,
|
||||||
|
@ -248,6 +254,7 @@ pub fn compile_module2<'s>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile<'s>(
|
pub fn compile<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
mut source: Source,
|
mut source: Source,
|
||||||
|
@ -266,6 +273,7 @@ pub fn compile<'s>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile_function<'s>(
|
pub fn compile_function<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
mut source: Source,
|
mut source: Source,
|
||||||
|
@ -292,6 +300,7 @@ pub fn compile_function<'s>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile_unbound_script<'s>(
|
pub fn compile_unbound_script<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
mut source: Source,
|
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
|
/// Alternatively, this tag can be stored alongside the cached data and compared
|
||||||
/// when it is being used.
|
/// when it is being used.
|
||||||
|
#[inline(always)]
|
||||||
pub fn cached_data_version_tag() -> u32 {
|
pub fn cached_data_version_tag() -> u32 {
|
||||||
unsafe { v8__ScriptCompiler__CachedDataVersionTag() }
|
unsafe { v8__ScriptCompiler__CachedDataVersionTag() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern "C" {
|
||||||
impl ScriptOrModule {
|
impl ScriptOrModule {
|
||||||
/// The name that was passed by the embedder as ResourceName to the
|
/// The name that was passed by the embedder as ResourceName to the
|
||||||
/// ScriptOrigin. This can be either a v8::String or v8::Undefined.
|
/// ScriptOrigin. This can be either a v8::String or v8::Undefined.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_resource_name(&self) -> Local<Value> {
|
pub fn get_resource_name(&self) -> Local<Value> {
|
||||||
// Note: the C++ `v8::ScriptOrModule::GetResourceName()` does not actually
|
// Note: the C++ `v8::ScriptOrModule::GetResourceName()` does not actually
|
||||||
// return a local handle, but rather a handle whose lifetime is bound to
|
// 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
|
/// The options that were passed by the embedder as HostDefinedOptions to the
|
||||||
/// ScriptOrigin.
|
/// ScriptOrigin.
|
||||||
|
#[inline(always)]
|
||||||
pub fn host_defined_options(&self) -> Local<Data> {
|
pub fn host_defined_options(&self) -> Local<Data> {
|
||||||
// Note: the C++ `v8::ScriptOrModule::HostDefinedOptions()` does not
|
// Note: the C++ `v8::ScriptOrModule::HostDefinedOptions()` does not
|
||||||
// actually return a local handle, but rather a handle whose lifetime is
|
// actually return a local handle, but rather a handle whose lifetime is
|
||||||
|
|
|
@ -45,6 +45,7 @@ impl SharedArrayBuffer {
|
||||||
/// Allocated memory will be owned by a created SharedArrayBuffer and
|
/// Allocated memory will be owned by a created SharedArrayBuffer and
|
||||||
/// will be deallocated when it is garbage-collected,
|
/// will be deallocated when it is garbage-collected,
|
||||||
/// unless the object is externalized.
|
/// unless the object is externalized.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
byte_length: usize,
|
byte_length: usize,
|
||||||
|
@ -59,6 +60,7 @@ impl SharedArrayBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn with_backing_store<'s>(
|
pub fn with_backing_store<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
backing_store: &SharedRef<BackingStore>,
|
backing_store: &SharedRef<BackingStore>,
|
||||||
|
@ -75,6 +77,7 @@ impl SharedArrayBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data length in bytes.
|
/// Data length in bytes.
|
||||||
|
#[inline(always)]
|
||||||
pub fn byte_length(&self) -> usize {
|
pub fn byte_length(&self) -> usize {
|
||||||
unsafe { v8__SharedArrayBuffer__ByteLength(self) }
|
unsafe { v8__SharedArrayBuffer__ByteLength(self) }
|
||||||
}
|
}
|
||||||
|
@ -83,6 +86,7 @@ impl SharedArrayBuffer {
|
||||||
/// pointer coordinates the lifetime management of the internal storage
|
/// pointer coordinates the lifetime management of the internal storage
|
||||||
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
|
/// with any live ArrayBuffers on the heap, even across isolates. The embedder
|
||||||
/// should not attempt to manage lifetime of the storage through other means.
|
/// should not attempt to manage lifetime of the storage through other means.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_backing_store(&self) -> SharedRef<BackingStore> {
|
pub fn get_backing_store(&self) -> SharedRef<BackingStore> {
|
||||||
unsafe { v8__SharedArrayBuffer__GetBackingStore(self) }
|
unsafe { v8__SharedArrayBuffer__GetBackingStore(self) }
|
||||||
}
|
}
|
||||||
|
@ -94,6 +98,7 @@ impl SharedArrayBuffer {
|
||||||
/// If the allocator returns nullptr, then the function may cause GCs in the
|
/// 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
|
/// given isolate and re-try the allocation. If GCs do not help, then the
|
||||||
/// function will crash with an out-of-memory error.
|
/// function will crash with an out-of-memory error.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_backing_store(
|
pub fn new_backing_store(
|
||||||
scope: &mut Isolate,
|
scope: &mut Isolate,
|
||||||
byte_length: usize,
|
byte_length: usize,
|
||||||
|
@ -115,6 +120,7 @@ impl SharedArrayBuffer {
|
||||||
///
|
///
|
||||||
/// The result can be later passed to SharedArrayBuffer::New. The raw pointer
|
/// 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.
|
/// to the buffer must not be passed again to any V8 API function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_backing_store_from_boxed_slice(
|
pub fn new_backing_store_from_boxed_slice(
|
||||||
data: Box<[u8]>,
|
data: Box<[u8]>,
|
||||||
) -> UniqueRef<BackingStore> {
|
) -> UniqueRef<BackingStore> {
|
||||||
|
@ -137,6 +143,7 @@ impl SharedArrayBuffer {
|
||||||
///
|
///
|
||||||
/// The result can be later passed to SharedArrayBuffer::New. The raw pointer
|
/// 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.
|
/// to the buffer must not be passed again to any V8 API function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_backing_store_from_vec(
|
pub fn new_backing_store_from_vec(
|
||||||
mut data: Vec<u8>,
|
mut data: Vec<u8>,
|
||||||
) -> UniqueRef<BackingStore> {
|
) -> UniqueRef<BackingStore> {
|
||||||
|
|
|
@ -94,6 +94,7 @@ pub struct SnapshotCreator([usize; 1]);
|
||||||
impl SnapshotCreator {
|
impl SnapshotCreator {
|
||||||
/// Create and enter an isolate, and set it up for serialization.
|
/// Create and enter an isolate, and set it up for serialization.
|
||||||
/// The isolate is created from scratch.
|
/// The isolate is created from scratch.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new(external_references: Option<&'static ExternalReferences>) -> Self {
|
pub fn new(external_references: Option<&'static ExternalReferences>) -> Self {
|
||||||
let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit();
|
let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit();
|
||||||
let external_references_ptr = if let Some(er) = external_references {
|
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.
|
/// 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
|
/// 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.
|
/// global object template to create one, to be provided upon deserialization.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_default_context(&mut self, context: Local<Context>) {
|
pub fn set_default_context(&mut self, context: Local<Context>) {
|
||||||
unsafe { v8__SnapshotCreator__SetDefaultContext(self, &*context) };
|
unsafe { v8__SnapshotCreator__SetDefaultContext(self, &*context) };
|
||||||
}
|
}
|
||||||
|
@ -129,6 +131,7 @@ impl SnapshotCreator {
|
||||||
/// retrieved via `HandleScope::get_context_data_from_snapshot_once()` after
|
/// retrieved via `HandleScope::get_context_data_from_snapshot_once()` after
|
||||||
/// deserialization. This data does not survive when a new snapshot is created
|
/// deserialization. This data does not survive when a new snapshot is created
|
||||||
/// from an existing snapshot.
|
/// from an existing snapshot.
|
||||||
|
#[inline(always)]
|
||||||
pub fn add_isolate_data<T>(&mut self, data: Local<T>) -> usize
|
pub fn add_isolate_data<T>(&mut self, data: Local<T>) -> usize
|
||||||
where
|
where
|
||||||
for<'l> Local<'l, T>: Into<Local<'l, Data>>,
|
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
|
/// retrieved via `HandleScope::get_context_data_from_snapshot_once()` after
|
||||||
/// deserialization. This data does not survive when a new snapshot is
|
/// deserialization. This data does not survive when a new snapshot is
|
||||||
/// created from an existing snapshot.
|
/// created from an existing snapshot.
|
||||||
|
#[inline(always)]
|
||||||
pub fn add_context_data<T>(
|
pub fn add_context_data<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: Local<Context>,
|
context: Local<Context>,
|
||||||
|
@ -155,6 +159,7 @@ impl SnapshotCreator {
|
||||||
|
|
||||||
/// Creates a snapshot data blob.
|
/// Creates a snapshot data blob.
|
||||||
/// This must not be called from within a handle scope.
|
/// This must not be called from within a handle scope.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_blob(
|
pub fn create_blob(
|
||||||
&mut self,
|
&mut self,
|
||||||
function_code_handling: FunctionCodeHandling,
|
function_code_handling: FunctionCodeHandling,
|
||||||
|
@ -179,6 +184,7 @@ impl SnapshotCreator {
|
||||||
// TODO Because the SnapshotCreator creates its own isolate, we need a way to
|
// 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
|
// get an owned handle to it. This is a questionable design which ought to be
|
||||||
// revisited after the libdeno integration is complete.
|
// revisited after the libdeno integration is complete.
|
||||||
|
#[inline(always)]
|
||||||
pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate {
|
pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate {
|
||||||
let isolate_ptr = v8__SnapshotCreator__GetIsolate(self);
|
let isolate_ptr = v8__SnapshotCreator__GetIsolate(self);
|
||||||
let mut owned_isolate = OwnedIsolate::new(isolate_ptr);
|
let mut owned_isolate = OwnedIsolate::new(isolate_ptr);
|
||||||
|
|
|
@ -120,10 +120,12 @@ impl String {
|
||||||
/// The maximum length (in bytes) of a buffer that a v8::String can be built
|
/// 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
|
/// from. Attempting to create a v8::String from a larger buffer will result
|
||||||
/// in None being returned.
|
/// in None being returned.
|
||||||
|
#[inline(always)]
|
||||||
pub fn max_length() -> usize {
|
pub fn max_length() -> usize {
|
||||||
unsafe { v8__String__kMaxLength() }
|
unsafe { v8__String__kMaxLength() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn empty<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, String> {
|
pub fn empty<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, String> {
|
||||||
// FIXME(bnoordhuis) v8__String__Empty() is infallible so there
|
// FIXME(bnoordhuis) v8__String__Empty() is infallible so there
|
||||||
// is no need to box up the result, only to unwrap it again.
|
// 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
|
/// Allocates a new string from UTF-8 data. Only returns an empty value when
|
||||||
/// length > kMaxLength
|
/// length > kMaxLength
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_utf8<'s>(
|
pub fn new_from_utf8<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
|
@ -156,6 +159,7 @@ impl String {
|
||||||
|
|
||||||
/// Allocates a new string from Latin-1 data. Only returns an empty value when
|
/// Allocates a new string from Latin-1 data. Only returns an empty value when
|
||||||
/// length > kMaxLength.
|
/// length > kMaxLength.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_one_byte<'s>(
|
pub fn new_from_one_byte<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
|
@ -176,6 +180,7 @@ impl String {
|
||||||
|
|
||||||
/// Allocates a new string from UTF-16 data. Only returns an empty value when
|
/// Allocates a new string from UTF-16 data. Only returns an empty value when
|
||||||
/// length > kMaxLength.
|
/// length > kMaxLength.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_two_byte<'s>(
|
pub fn new_from_two_byte<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
buffer: &[u16],
|
buffer: &[u16],
|
||||||
|
@ -195,18 +200,21 @@ impl String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of characters (UTF-16 code units) in this string.
|
/// Returns the number of characters (UTF-16 code units) in this string.
|
||||||
|
#[inline(always)]
|
||||||
pub fn length(&self) -> usize {
|
pub fn length(&self) -> usize {
|
||||||
unsafe { v8__String__Length(self) as usize }
|
unsafe { v8__String__Length(self) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the number of bytes in the UTF-8 encoded representation of this
|
/// Returns the number of bytes in the UTF-8 encoded representation of this
|
||||||
/// string.
|
/// string.
|
||||||
|
#[inline(always)]
|
||||||
pub fn utf8_length(&self, scope: &mut Isolate) -> usize {
|
pub fn utf8_length(&self, scope: &mut Isolate) -> usize {
|
||||||
unsafe { v8__String__Utf8Length(self, scope) as usize }
|
unsafe { v8__String__Utf8Length(self, scope) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the contents of the string to an external buffer, as 16-bit
|
/// Writes the contents of the string to an external buffer, as 16-bit
|
||||||
/// (UTF-16) character codes.
|
/// (UTF-16) character codes.
|
||||||
|
#[inline(always)]
|
||||||
pub fn write(
|
pub fn write(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Isolate,
|
scope: &mut Isolate,
|
||||||
|
@ -228,6 +236,7 @@ impl String {
|
||||||
|
|
||||||
/// Writes the contents of the string to an external buffer, as one-byte
|
/// Writes the contents of the string to an external buffer, as one-byte
|
||||||
/// (Latin-1) characters.
|
/// (Latin-1) characters.
|
||||||
|
#[inline(always)]
|
||||||
pub fn write_one_byte(
|
pub fn write_one_byte(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Isolate,
|
scope: &mut Isolate,
|
||||||
|
@ -248,6 +257,7 @@ impl String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes the contents of the string to an external buffer, as UTF-8.
|
/// Writes the contents of the string to an external buffer, as UTF-8.
|
||||||
|
#[inline(always)]
|
||||||
pub fn write_utf8(
|
pub fn write_utf8(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Isolate,
|
scope: &mut Isolate,
|
||||||
|
@ -273,6 +283,7 @@ impl String {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience function not present in the original V8 API.
|
// Convenience function not present in the original V8 API.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
value: &str,
|
value: &str,
|
||||||
|
@ -282,6 +293,7 @@ impl String {
|
||||||
|
|
||||||
// Creates a v8::String from a `&'static [u8]`,
|
// Creates a v8::String from a `&'static [u8]`,
|
||||||
// must be Latin-1 or ASCII, not UTF-8 !
|
// must be Latin-1 or ASCII, not UTF-8 !
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_external_onebyte_static<'s>(
|
pub fn new_external_onebyte_static<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
buffer: &'static [u8],
|
buffer: &'static [u8],
|
||||||
|
@ -299,6 +311,7 @@ impl String {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a v8::String from a `&'static [u16]`.
|
// Creates a v8::String from a `&'static [u16]`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_external_twobyte_static<'s>(
|
pub fn new_external_twobyte_static<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
buffer: &'static [u16],
|
buffer: &'static [u16],
|
||||||
|
@ -316,6 +329,7 @@ impl String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if string is external
|
/// True if string is external
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_external(&self) -> bool {
|
pub fn is_external(&self) -> bool {
|
||||||
// TODO: re-enable on next v8-release
|
// TODO: re-enable on next v8-release
|
||||||
// Right now it fallbacks to Value::IsExternal, which is incorrect
|
// Right now it fallbacks to Value::IsExternal, which is incorrect
|
||||||
|
@ -328,12 +342,14 @@ impl String {
|
||||||
|
|
||||||
/// True if string is external & one-byte
|
/// True if string is external & one-byte
|
||||||
/// (e.g: created with new_external_onebyte_static)
|
/// (e.g: created with new_external_onebyte_static)
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_external_onebyte(&self) -> bool {
|
pub fn is_external_onebyte(&self) -> bool {
|
||||||
unsafe { v8__String__IsExternalOneByte(self) }
|
unsafe { v8__String__IsExternalOneByte(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if string is external & two-byte
|
/// True if string is external & two-byte
|
||||||
/// (e.g: created with new_external_twobyte_static)
|
/// (e.g: created with new_external_twobyte_static)
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_external_twobyte(&self) -> bool {
|
pub fn is_external_twobyte(&self) -> bool {
|
||||||
unsafe { v8__String__IsExternalTwoByte(self) }
|
unsafe { v8__String__IsExternalTwoByte(self) }
|
||||||
}
|
}
|
||||||
|
@ -345,17 +361,20 @@ impl String {
|
||||||
/// potentially reading the entire string, use [`contains_only_onebyte()`].
|
/// potentially reading the entire string, use [`contains_only_onebyte()`].
|
||||||
///
|
///
|
||||||
/// [`contains_only_onebyte()`]: String::contains_only_onebyte
|
/// [`contains_only_onebyte()`]: String::contains_only_onebyte
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_onebyte(&self) -> bool {
|
pub fn is_onebyte(&self) -> bool {
|
||||||
unsafe { v8__String__IsExternalOneByte(self) }
|
unsafe { v8__String__IsExternalOneByte(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if the string contains only one-byte data.
|
/// True if the string contains only one-byte data.
|
||||||
/// Will read the entire string in some cases.
|
/// Will read the entire string in some cases.
|
||||||
|
#[inline(always)]
|
||||||
pub fn contains_only_onebyte(&self) -> bool {
|
pub fn contains_only_onebyte(&self) -> bool {
|
||||||
unsafe { v8__String__ContainsOnlyOneByte(self) }
|
unsafe { v8__String__ContainsOnlyOneByte(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function not present in the original V8 API.
|
/// Convenience function not present in the original V8 API.
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_rust_string_lossy(
|
pub fn to_rust_string_lossy(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut Isolate,
|
scope: &mut Isolate,
|
||||||
|
|
|
@ -34,6 +34,7 @@ macro_rules! well_known {
|
||||||
impl Symbol {
|
impl Symbol {
|
||||||
/// Create a symbol. If description is not empty, it will be used as the
|
/// Create a symbol. If description is not empty, it will be used as the
|
||||||
/// description.
|
/// description.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
description: Option<Local<String>>,
|
description: Option<Local<String>>,
|
||||||
|
@ -56,6 +57,7 @@ impl Symbol {
|
||||||
/// keys.
|
/// keys.
|
||||||
/// To minimize the potential for clashes, use qualified descriptions as keys.
|
/// To minimize the potential for clashes, use qualified descriptions as keys.
|
||||||
/// Corresponds to v8::Symbol::For() in C++.
|
/// Corresponds to v8::Symbol::For() in C++.
|
||||||
|
#[inline(always)]
|
||||||
pub fn for_global<'s>(
|
pub fn for_global<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
description: Local<String>,
|
description: Local<String>,
|
||||||
|
@ -69,6 +71,7 @@ impl Symbol {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the description string of the symbol, or undefined if none.
|
/// Returns the description string of the symbol, or undefined if none.
|
||||||
|
#[inline(always)]
|
||||||
pub fn description<'s>(
|
pub fn description<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
|
|
@ -112,12 +112,14 @@ extern "C" {
|
||||||
|
|
||||||
impl Template {
|
impl Template {
|
||||||
/// Adds a property to each instance created by this template.
|
/// Adds a property to each instance created by this template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set(&self, key: Local<Name>, value: Local<Data>) {
|
pub fn set(&self, key: Local<Name>, value: Local<Data>) {
|
||||||
self.set_with_attr(key, value, NONE)
|
self.set_with_attr(key, value, NONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a property to each instance created by this template with
|
/// Adds a property to each instance created by this template with
|
||||||
/// the specified property attributes.
|
/// the specified property attributes.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_with_attr(
|
pub fn set_with_attr(
|
||||||
&self,
|
&self,
|
||||||
key: Local<Name>,
|
key: Local<Name>,
|
||||||
|
@ -130,12 +132,14 @@ impl Template {
|
||||||
|
|
||||||
impl<'s> FunctionBuilder<'s, FunctionTemplate> {
|
impl<'s> FunctionBuilder<'s, FunctionTemplate> {
|
||||||
/// Set the function call signature. The default is no signature.
|
/// Set the function call signature. The default is no signature.
|
||||||
|
#[inline(always)]
|
||||||
pub fn signature(mut self, signature: Local<'s, Signature>) -> Self {
|
pub fn signature(mut self, signature: Local<'s, Signature>) -> Self {
|
||||||
self.signature = Some(signature);
|
self.signature = Some(signature);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the function template.
|
/// Creates the function template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn build(
|
pub fn build(
|
||||||
self,
|
self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
@ -208,6 +212,7 @@ impl<'s> FunctionBuilder<'s, FunctionTemplate> {
|
||||||
/// from a FunctionTemplate that inherits directly or indirectly from the
|
/// from a FunctionTemplate that inherits directly or indirectly from the
|
||||||
/// signature's FunctionTemplate.
|
/// signature's FunctionTemplate.
|
||||||
impl Signature {
|
impl Signature {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
templ: Local<FunctionTemplate>,
|
templ: Local<FunctionTemplate>,
|
||||||
|
@ -222,12 +227,14 @@ impl Signature {
|
||||||
impl FunctionTemplate {
|
impl FunctionTemplate {
|
||||||
/// Create a FunctionBuilder to configure a FunctionTemplate.
|
/// Create a FunctionBuilder to configure a FunctionTemplate.
|
||||||
/// This is the same as FunctionBuilder::<FunctionTemplate>::new().
|
/// This is the same as FunctionBuilder::<FunctionTemplate>::new().
|
||||||
|
#[inline(always)]
|
||||||
pub fn builder<'s>(
|
pub fn builder<'s>(
|
||||||
callback: impl MapFnTo<FunctionCallback>,
|
callback: impl MapFnTo<FunctionCallback>,
|
||||||
) -> FunctionBuilder<'s, Self> {
|
) -> FunctionBuilder<'s, Self> {
|
||||||
FunctionBuilder::new(callback)
|
FunctionBuilder::new(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn builder_raw<'s>(
|
pub fn builder_raw<'s>(
|
||||||
callback: FunctionCallback,
|
callback: FunctionCallback,
|
||||||
) -> FunctionBuilder<'s, Self> {
|
) -> FunctionBuilder<'s, Self> {
|
||||||
|
@ -235,6 +242,7 @@ impl FunctionTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a function template.
|
/// Creates a function template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
callback: impl MapFnTo<FunctionCallback>,
|
callback: impl MapFnTo<FunctionCallback>,
|
||||||
|
@ -242,6 +250,7 @@ impl FunctionTemplate {
|
||||||
Self::builder(callback).build(scope)
|
Self::builder(callback).build(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_raw<'s>(
|
pub fn new_raw<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
callback: FunctionCallback,
|
callback: FunctionCallback,
|
||||||
|
@ -250,6 +259,7 @@ impl FunctionTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the unique function instance in the current execution context.
|
/// Returns the unique function instance in the current execution context.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_function<'s>(
|
pub fn get_function<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -264,12 +274,14 @@ impl FunctionTemplate {
|
||||||
/// Set the class name of the FunctionTemplate. This is used for
|
/// Set the class name of the FunctionTemplate. This is used for
|
||||||
/// printing objects created with the function created from the
|
/// printing objects created with the function created from the
|
||||||
/// FunctionTemplate as its constructor.
|
/// FunctionTemplate as its constructor.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_class_name(&self, name: Local<String>) {
|
pub fn set_class_name(&self, name: Local<String>) {
|
||||||
unsafe { v8__FunctionTemplate__SetClassName(self, &*name) };
|
unsafe { v8__FunctionTemplate__SetClassName(self, &*name) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the ObjectTemplate that is used by this
|
/// Returns the ObjectTemplate that is used by this
|
||||||
/// FunctionTemplate as a PrototypeTemplate
|
/// FunctionTemplate as a PrototypeTemplate
|
||||||
|
#[inline(always)]
|
||||||
pub fn prototype_template<'s>(
|
pub fn prototype_template<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
@ -282,6 +294,7 @@ impl FunctionTemplate {
|
||||||
|
|
||||||
/// Returns the object template that is used for instances created when this function
|
/// Returns the object template that is used for instances created when this function
|
||||||
/// template is called as a constructor.
|
/// template is called as a constructor.
|
||||||
|
#[inline(always)]
|
||||||
pub fn instance_template<'s>(
|
pub fn instance_template<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
@ -294,17 +307,20 @@ impl FunctionTemplate {
|
||||||
|
|
||||||
/// Causes the function template to inherit from a parent function template.
|
/// 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.
|
/// This means the function's prototype.__proto__ is set to the parent function's prototype.
|
||||||
|
#[inline(always)]
|
||||||
pub fn inherit(&self, parent: Local<FunctionTemplate>) {
|
pub fn inherit(&self, parent: Local<FunctionTemplate>) {
|
||||||
unsafe { v8__FunctionTemplate__Inherit(self, &*parent) };
|
unsafe { v8__FunctionTemplate__Inherit(self, &*parent) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the ReadOnly flag in the attributes of the 'prototype' property
|
/// Sets the ReadOnly flag in the attributes of the 'prototype' property
|
||||||
/// of functions created from this FunctionTemplate to true.
|
/// of functions created from this FunctionTemplate to true.
|
||||||
|
#[inline(always)]
|
||||||
pub fn read_only_prototype(&self) {
|
pub fn read_only_prototype(&self) {
|
||||||
unsafe { v8__FunctionTemplate__ReadOnlyPrototype(self) };
|
unsafe { v8__FunctionTemplate__ReadOnlyPrototype(self) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the prototype property from functions created from this FunctionTemplate.
|
/// Removes the prototype property from functions created from this FunctionTemplate.
|
||||||
|
#[inline(always)]
|
||||||
pub fn remove_prototype(&self) {
|
pub fn remove_prototype(&self) {
|
||||||
unsafe { v8__FunctionTemplate__RemovePrototype(self) };
|
unsafe { v8__FunctionTemplate__RemovePrototype(self) };
|
||||||
}
|
}
|
||||||
|
@ -312,6 +328,7 @@ impl FunctionTemplate {
|
||||||
|
|
||||||
impl ObjectTemplate {
|
impl ObjectTemplate {
|
||||||
/// Creates an object template.
|
/// Creates an object template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, ObjectTemplate> {
|
pub fn new<'s>(scope: &mut HandleScope<'s, ()>) -> Local<'s, ObjectTemplate> {
|
||||||
unsafe {
|
unsafe {
|
||||||
scope.cast_local(|sd| {
|
scope.cast_local(|sd| {
|
||||||
|
@ -322,6 +339,7 @@ impl ObjectTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an object template from a function template.
|
/// Creates an object template from a function template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_from_template<'s>(
|
pub fn new_from_template<'s>(
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
templ: Local<FunctionTemplate>,
|
templ: Local<FunctionTemplate>,
|
||||||
|
@ -334,6 +352,7 @@ impl ObjectTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new instance of this object template.
|
/// Creates a new instance of this object template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn new_instance<'s>(
|
pub fn new_instance<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -347,6 +366,7 @@ impl ObjectTemplate {
|
||||||
|
|
||||||
/// Gets the number of internal fields for objects generated from
|
/// Gets the number of internal fields for objects generated from
|
||||||
/// this template.
|
/// this template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn internal_field_count(&self) -> usize {
|
pub fn internal_field_count(&self) -> usize {
|
||||||
let count = unsafe { v8__ObjectTemplate__InternalFieldCount(self) };
|
let count = unsafe { v8__ObjectTemplate__InternalFieldCount(self) };
|
||||||
usize::try_from(count).expect("bad internal field count") // Can't happen.
|
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
|
/// Sets the number of internal fields for objects generated from
|
||||||
/// this template.
|
/// this template.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_internal_field_count(&self, value: usize) -> bool {
|
pub fn set_internal_field_count(&self, value: usize) -> bool {
|
||||||
// The C++ API takes an i32 but trying to set a value < 0
|
// The C++ API takes an i32 but trying to set a value < 0
|
||||||
// results in unpredictable behavior, hence we disallow it.
|
// results in unpredictable behavior, hence we disallow it.
|
||||||
|
@ -366,6 +387,7 @@ impl ObjectTemplate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_accessor(
|
pub fn set_accessor(
|
||||||
&self,
|
&self,
|
||||||
key: Local<Name>,
|
key: Local<Name>,
|
||||||
|
@ -374,6 +396,7 @@ impl ObjectTemplate {
|
||||||
unsafe { v8__ObjectTemplate__SetAccessor(self, &*key, getter.map_fn_to()) }
|
unsafe { v8__ObjectTemplate__SetAccessor(self, &*key, getter.map_fn_to()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_accessor_with_setter(
|
pub fn set_accessor_with_setter(
|
||||||
&self,
|
&self,
|
||||||
key: Local<Name>,
|
key: Local<Name>,
|
||||||
|
@ -396,6 +419,7 @@ impl ObjectTemplate {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if both `getter` and `setter` are `None`.
|
/// Panics if both `getter` and `setter` are `None`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_accessor_property(
|
pub fn set_accessor_property(
|
||||||
&self,
|
&self,
|
||||||
key: Local<Name>,
|
key: Local<Name>,
|
||||||
|
@ -416,6 +440,7 @@ impl ObjectTemplate {
|
||||||
|
|
||||||
/// Makes the ObjectTemplate for an immutable prototype exotic object,
|
/// Makes the ObjectTemplate for an immutable prototype exotic object,
|
||||||
/// with an immutable proto.
|
/// with an immutable proto.
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_immutable_proto(&self) {
|
pub fn set_immutable_proto(&self) {
|
||||||
unsafe { v8__ObjectTemplate__SetImmutableProto(self) };
|
unsafe { v8__ObjectTemplate__SetImmutableProto(self) };
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ impl TypedArray {
|
||||||
/// The maximum length (in bytes) of the buffer backing a v8::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
|
/// instance. Attempting to create a v8::ArrayBuffer from a larger buffer will
|
||||||
/// result in a fatal error.
|
/// result in a fatal error.
|
||||||
|
#[inline(always)]
|
||||||
pub fn max_length() -> usize {
|
pub fn max_length() -> usize {
|
||||||
unsafe { v8__TypedArray__kMaxLength() }
|
unsafe { v8__TypedArray__kMaxLength() }
|
||||||
}
|
}
|
||||||
|
@ -21,6 +22,7 @@ macro_rules! typed_array {
|
||||||
($name:ident, $func:ident) => {
|
($name:ident, $func:ident) => {
|
||||||
use crate::$name;
|
use crate::$name;
|
||||||
impl $name {
|
impl $name {
|
||||||
|
#[inline(always)]
|
||||||
pub fn new<'s>(
|
pub fn new<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
buf: Local<ArrayBuffer>,
|
buf: Local<ArrayBuffer>,
|
||||||
|
|
|
@ -12,6 +12,7 @@ impl UnboundModuleScript {
|
||||||
/// Creates and returns code cache for the specified unbound_module_script.
|
/// Creates and returns code cache for the specified unbound_module_script.
|
||||||
/// This will return nullptr if the script cannot be serialized. The
|
/// This will return nullptr if the script cannot be serialized. The
|
||||||
/// CachedData returned by this function should be owned by the caller.
|
/// CachedData returned by this function should be owned by the caller.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
|
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
|
||||||
let code_cache = unsafe {
|
let code_cache = unsafe {
|
||||||
UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self))
|
UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self))
|
||||||
|
|
|
@ -15,6 +15,7 @@ extern "C" {
|
||||||
|
|
||||||
impl UnboundScript {
|
impl UnboundScript {
|
||||||
/// Binds the script to the currently entered context.
|
/// Binds the script to the currently entered context.
|
||||||
|
#[inline(always)]
|
||||||
pub fn bind_to_current_context<'s>(
|
pub fn bind_to_current_context<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -28,6 +29,7 @@ impl UnboundScript {
|
||||||
/// Creates and returns code cache for the specified unbound_script.
|
/// Creates and returns code cache for the specified unbound_script.
|
||||||
/// This will return nullptr if the script cannot be serialized. The
|
/// This will return nullptr if the script cannot be serialized. The
|
||||||
/// CachedData returned by this function should be owned by the caller.
|
/// CachedData returned by this function should be owned by the caller.
|
||||||
|
#[inline(always)]
|
||||||
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
|
pub fn create_code_cache(&self) -> Option<UniqueRef<CachedData<'static>>> {
|
||||||
let code_cache = unsafe {
|
let code_cache = unsafe {
|
||||||
UniqueRef::try_from_raw(v8__UnboundScript__CreateCodeCache(self))
|
UniqueRef::try_from_raw(v8__UnboundScript__CreateCodeCache(self))
|
||||||
|
|
75
src/value.rs
75
src/value.rs
|
@ -146,17 +146,20 @@ extern "C" {
|
||||||
|
|
||||||
impl Value {
|
impl Value {
|
||||||
/// Returns true if this value is the undefined value. See ECMA-262 4.3.10.
|
/// Returns true if this value is the undefined value. See ECMA-262 4.3.10.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_undefined(&self) -> bool {
|
pub fn is_undefined(&self) -> bool {
|
||||||
unsafe { v8__Value__IsUndefined(self) }
|
unsafe { v8__Value__IsUndefined(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is the null value. See ECMA-262 4.3.11.
|
/// Returns true if this value is the null value. See ECMA-262 4.3.11.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_null(&self) -> bool {
|
pub fn is_null(&self) -> bool {
|
||||||
unsafe { v8__Value__IsNull(self) }
|
unsafe { v8__Value__IsNull(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is either the null or the undefined value.
|
/// Returns true if this value is either the null or the undefined value.
|
||||||
/// See ECMA-262 4.3.11. and 4.3.12
|
/// See ECMA-262 4.3.11. and 4.3.12
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_null_or_undefined(&self) -> bool {
|
pub fn is_null_or_undefined(&self) -> bool {
|
||||||
unsafe { v8__Value__IsNullOrUndefined(self) }
|
unsafe { v8__Value__IsNullOrUndefined(self) }
|
||||||
}
|
}
|
||||||
|
@ -165,6 +168,7 @@ impl Value {
|
||||||
/// This is not the same as `BooleanValue()`. The latter performs a
|
/// This is not the same as `BooleanValue()`. The latter performs a
|
||||||
/// conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas
|
/// conversion to boolean, i.e. the result of `Boolean(value)` in JS, whereas
|
||||||
/// this checks `value === true`.
|
/// this checks `value === true`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_true(&self) -> bool {
|
pub fn is_true(&self) -> bool {
|
||||||
unsafe { v8__Value__IsTrue(self) }
|
unsafe { v8__Value__IsTrue(self) }
|
||||||
}
|
}
|
||||||
|
@ -173,6 +177,7 @@ impl Value {
|
||||||
/// This is not the same as `!BooleanValue()`. The latter performs a
|
/// This is not the same as `!BooleanValue()`. The latter performs a
|
||||||
/// conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas
|
/// conversion to boolean, i.e. the result of `!Boolean(value)` in JS, whereas
|
||||||
/// this checks `value === false`.
|
/// this checks `value === false`.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_false(&self) -> bool {
|
pub fn is_false(&self) -> bool {
|
||||||
unsafe { v8__Value__IsFalse(self) }
|
unsafe { v8__Value__IsFalse(self) }
|
||||||
}
|
}
|
||||||
|
@ -180,265 +185,317 @@ impl Value {
|
||||||
/// Returns true if this value is a symbol or a string.
|
/// Returns true if this value is a symbol or a string.
|
||||||
/// This is equivalent to
|
/// This is equivalent to
|
||||||
/// `typeof value === 'string' || typeof value === 'symbol'` in JS.
|
/// `typeof value === 'string' || typeof value === 'symbol'` in JS.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_name(&self) -> bool {
|
pub fn is_name(&self) -> bool {
|
||||||
unsafe { v8__Value__IsName(self) }
|
unsafe { v8__Value__IsName(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an instance of the String type.
|
/// Returns true if this value is an instance of the String type.
|
||||||
/// See ECMA-262 8.4.
|
/// See ECMA-262 8.4.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_string(&self) -> bool {
|
pub fn is_string(&self) -> bool {
|
||||||
unsafe { v8__Value__IsString(self) }
|
unsafe { v8__Value__IsString(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a symbol.
|
/// Returns true if this value is a symbol.
|
||||||
/// This is equivalent to `typeof value === 'symbol'` in JS.
|
/// This is equivalent to `typeof value === 'symbol'` in JS.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_symbol(&self) -> bool {
|
pub fn is_symbol(&self) -> bool {
|
||||||
unsafe { v8__Value__IsSymbol(self) }
|
unsafe { v8__Value__IsSymbol(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a function.
|
/// Returns true if this value is a function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_function(&self) -> bool {
|
pub fn is_function(&self) -> bool {
|
||||||
unsafe { v8__Value__IsFunction(self) }
|
unsafe { v8__Value__IsFunction(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an array. Note that it will return false for
|
/// Returns true if this value is an array. Note that it will return false for
|
||||||
/// an Proxy for an array.
|
/// an Proxy for an array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_array(&self) -> bool {
|
pub fn is_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsArray(self) }
|
unsafe { v8__Value__IsArray(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an object.
|
/// Returns true if this value is an object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_object(&self) -> bool {
|
pub fn is_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsObject(self) }
|
unsafe { v8__Value__IsObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a bigint.
|
/// Returns true if this value is a bigint.
|
||||||
/// This is equivalent to `typeof value === 'bigint'` in JS.
|
/// This is equivalent to `typeof value === 'bigint'` in JS.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_big_int(&self) -> bool {
|
pub fn is_big_int(&self) -> bool {
|
||||||
unsafe { v8__Value__IsBigInt(self) }
|
unsafe { v8__Value__IsBigInt(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is boolean.
|
/// Returns true if this value is boolean.
|
||||||
/// This is equivalent to `typeof value === 'boolean'` in JS.
|
/// This is equivalent to `typeof value === 'boolean'` in JS.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_boolean(&self) -> bool {
|
pub fn is_boolean(&self) -> bool {
|
||||||
unsafe { v8__Value__IsBoolean(self) }
|
unsafe { v8__Value__IsBoolean(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a number.
|
/// Returns true if this value is a number.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_number(&self) -> bool {
|
pub fn is_number(&self) -> bool {
|
||||||
unsafe { v8__Value__IsNumber(self) }
|
unsafe { v8__Value__IsNumber(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an `External` object.
|
/// Returns true if this value is an `External` object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_external(&self) -> bool {
|
pub fn is_external(&self) -> bool {
|
||||||
unsafe { v8__Value__IsExternal(self) }
|
unsafe { v8__Value__IsExternal(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a 32-bit signed integer.
|
/// Returns true if this value is a 32-bit signed integer.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_int32(&self) -> bool {
|
pub fn is_int32(&self) -> bool {
|
||||||
unsafe { v8__Value__IsInt32(self) }
|
unsafe { v8__Value__IsInt32(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a 32-bit unsigned integer.
|
/// Returns true if this value is a 32-bit unsigned integer.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_uint32(&self) -> bool {
|
pub fn is_uint32(&self) -> bool {
|
||||||
unsafe { v8__Value__IsUint32(self) }
|
unsafe { v8__Value__IsUint32(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Date.
|
/// Returns true if this value is a Date.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_date(&self) -> bool {
|
pub fn is_date(&self) -> bool {
|
||||||
unsafe { v8__Value__IsDate(self) }
|
unsafe { v8__Value__IsDate(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Arguments object.
|
/// Returns true if this value is an Arguments object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_arguments_object(&self) -> bool {
|
pub fn is_arguments_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsArgumentsObject(self) }
|
unsafe { v8__Value__IsArgumentsObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a BigInt object.
|
/// Returns true if this value is a BigInt object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_big_int_object(&self) -> bool {
|
pub fn is_big_int_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsBigIntObject(self) }
|
unsafe { v8__Value__IsBigIntObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Boolean object.
|
/// Returns true if this value is a Boolean object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_boolean_object(&self) -> bool {
|
pub fn is_boolean_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsBooleanObject(self) }
|
unsafe { v8__Value__IsBooleanObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Number object.
|
/// Returns true if this value is a Number object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_number_object(&self) -> bool {
|
pub fn is_number_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsNumberObject(self) }
|
unsafe { v8__Value__IsNumberObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a String object.
|
/// Returns true if this value is a String object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_string_object(&self) -> bool {
|
pub fn is_string_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsStringObject(self) }
|
unsafe { v8__Value__IsStringObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Symbol object.
|
/// Returns true if this value is a Symbol object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_symbol_object(&self) -> bool {
|
pub fn is_symbol_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsSymbolObject(self) }
|
unsafe { v8__Value__IsSymbolObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a NativeError.
|
/// Returns true if this value is a NativeError.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_native_error(&self) -> bool {
|
pub fn is_native_error(&self) -> bool {
|
||||||
unsafe { v8__Value__IsNativeError(self) }
|
unsafe { v8__Value__IsNativeError(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a RegExp.
|
/// Returns true if this value is a RegExp.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_reg_exp(&self) -> bool {
|
pub fn is_reg_exp(&self) -> bool {
|
||||||
unsafe { v8__Value__IsRegExp(self) }
|
unsafe { v8__Value__IsRegExp(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an async function.
|
/// Returns true if this value is an async function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_async_function(&self) -> bool {
|
pub fn is_async_function(&self) -> bool {
|
||||||
unsafe { v8__Value__IsAsyncFunction(self) }
|
unsafe { v8__Value__IsAsyncFunction(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Generator function.
|
/// Returns true if this value is a Generator function.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_generator_function(&self) -> bool {
|
pub fn is_generator_function(&self) -> bool {
|
||||||
unsafe { v8__Value__IsGeneratorFunction(self) }
|
unsafe { v8__Value__IsGeneratorFunction(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Promise.
|
/// Returns true if this value is a Promise.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_promise(&self) -> bool {
|
pub fn is_promise(&self) -> bool {
|
||||||
unsafe { v8__Value__IsPromise(self) }
|
unsafe { v8__Value__IsPromise(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Map.
|
/// Returns true if this value is a Map.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_map(&self) -> bool {
|
pub fn is_map(&self) -> bool {
|
||||||
unsafe { v8__Value__IsMap(self) }
|
unsafe { v8__Value__IsMap(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Set.
|
/// Returns true if this value is a Set.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_set(&self) -> bool {
|
pub fn is_set(&self) -> bool {
|
||||||
unsafe { v8__Value__IsSet(self) }
|
unsafe { v8__Value__IsSet(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Map Iterator.
|
/// Returns true if this value is a Map Iterator.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_map_iterator(&self) -> bool {
|
pub fn is_map_iterator(&self) -> bool {
|
||||||
unsafe { v8__Value__IsMapIterator(self) }
|
unsafe { v8__Value__IsMapIterator(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Set Iterator.
|
/// Returns true if this value is a Set Iterator.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_set_iterator(&self) -> bool {
|
pub fn is_set_iterator(&self) -> bool {
|
||||||
unsafe { v8__Value__IsSetIterator(self) }
|
unsafe { v8__Value__IsSetIterator(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a WeakMap.
|
/// Returns true if this value is a WeakMap.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_weak_map(&self) -> bool {
|
pub fn is_weak_map(&self) -> bool {
|
||||||
unsafe { v8__Value__IsWeakMap(self) }
|
unsafe { v8__Value__IsWeakMap(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a WeakSet.
|
/// Returns true if this value is a WeakSet.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_weak_set(&self) -> bool {
|
pub fn is_weak_set(&self) -> bool {
|
||||||
unsafe { v8__Value__IsWeakSet(self) }
|
unsafe { v8__Value__IsWeakSet(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an ArrayBuffer.
|
/// Returns true if this value is an ArrayBuffer.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_array_buffer(&self) -> bool {
|
pub fn is_array_buffer(&self) -> bool {
|
||||||
unsafe { v8__Value__IsArrayBuffer(self) }
|
unsafe { v8__Value__IsArrayBuffer(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an ArrayBufferView.
|
/// Returns true if this value is an ArrayBufferView.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_array_buffer_view(&self) -> bool {
|
pub fn is_array_buffer_view(&self) -> bool {
|
||||||
unsafe { v8__Value__IsArrayBufferView(self) }
|
unsafe { v8__Value__IsArrayBufferView(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is one of TypedArrays.
|
/// Returns true if this value is one of TypedArrays.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_typed_array(&self) -> bool {
|
pub fn is_typed_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsTypedArray(self) }
|
unsafe { v8__Value__IsTypedArray(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Uint8Array.
|
/// Returns true if this value is an Uint8Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_uint8_array(&self) -> bool {
|
pub fn is_uint8_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsUint8Array(self) }
|
unsafe { v8__Value__IsUint8Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Uint8ClampedArray.
|
/// Returns true if this value is an Uint8ClampedArray.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_uint8_clamped_array(&self) -> bool {
|
pub fn is_uint8_clamped_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsUint8ClampedArray(self) }
|
unsafe { v8__Value__IsUint8ClampedArray(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Int8Array.
|
/// Returns true if this value is an Int8Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_int8_array(&self) -> bool {
|
pub fn is_int8_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsInt8Array(self) }
|
unsafe { v8__Value__IsInt8Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Uint16Array.
|
/// Returns true if this value is an Uint16Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_uint16_array(&self) -> bool {
|
pub fn is_uint16_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsUint16Array(self) }
|
unsafe { v8__Value__IsUint16Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Int16Array.
|
/// Returns true if this value is an Int16Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_int16_array(&self) -> bool {
|
pub fn is_int16_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsInt16Array(self) }
|
unsafe { v8__Value__IsInt16Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Uint32Array.
|
/// Returns true if this value is an Uint32Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_uint32_array(&self) -> bool {
|
pub fn is_uint32_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsUint32Array(self) }
|
unsafe { v8__Value__IsUint32Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is an Int32Array.
|
/// Returns true if this value is an Int32Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_int32_array(&self) -> bool {
|
pub fn is_int32_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsInt32Array(self) }
|
unsafe { v8__Value__IsInt32Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Float32Array.
|
/// Returns true if this value is a Float32Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_float32_array(&self) -> bool {
|
pub fn is_float32_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsFloat32Array(self) }
|
unsafe { v8__Value__IsFloat32Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a Float64Array.
|
/// Returns true if this value is a Float64Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_float64_array(&self) -> bool {
|
pub fn is_float64_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsFloat64Array(self) }
|
unsafe { v8__Value__IsFloat64Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a BigInt64Array.
|
/// Returns true if this value is a BigInt64Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_big_int64_array(&self) -> bool {
|
pub fn is_big_int64_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsBigInt64Array(self) }
|
unsafe { v8__Value__IsBigInt64Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a BigUint64Array.
|
/// Returns true if this value is a BigUint64Array.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_big_uint64_array(&self) -> bool {
|
pub fn is_big_uint64_array(&self) -> bool {
|
||||||
unsafe { v8__Value__IsBigUint64Array(self) }
|
unsafe { v8__Value__IsBigUint64Array(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a DataView.
|
/// Returns true if this value is a DataView.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_data_view(&self) -> bool {
|
pub fn is_data_view(&self) -> bool {
|
||||||
unsafe { v8__Value__IsDataView(self) }
|
unsafe { v8__Value__IsDataView(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a SharedArrayBuffer.
|
/// Returns true if this value is a SharedArrayBuffer.
|
||||||
/// This is an experimental feature.
|
/// This is an experimental feature.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_shared_array_buffer(&self) -> bool {
|
pub fn is_shared_array_buffer(&self) -> bool {
|
||||||
unsafe { v8__Value__IsSharedArrayBuffer(self) }
|
unsafe { v8__Value__IsSharedArrayBuffer(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a JavaScript Proxy.
|
/// Returns true if this value is a JavaScript Proxy.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_proxy(&self) -> bool {
|
pub fn is_proxy(&self) -> bool {
|
||||||
unsafe { v8__Value__IsProxy(self) }
|
unsafe { v8__Value__IsProxy(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a WasmMemoryObject.
|
/// Returns true if this value is a WasmMemoryObject.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_wasm_memory_object(&self) -> bool {
|
pub fn is_wasm_memory_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsWasmMemoryObject(self) }
|
unsafe { v8__Value__IsWasmMemoryObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if this value is a WasmModuleObject.
|
/// Returns true if this value is a WasmModuleObject.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_wasm_module_object(&self) -> bool {
|
pub fn is_wasm_module_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsWasmModuleObject(self) }
|
unsafe { v8__Value__IsWasmModuleObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the value is a Module Namespace Object.
|
/// Returns true if the value is a Module Namespace Object.
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_module_namespace_object(&self) -> bool {
|
pub fn is_module_namespace_object(&self) -> bool {
|
||||||
unsafe { v8__Value__IsModuleNamespaceObject(self) }
|
unsafe { v8__Value__IsModuleNamespaceObject(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn strict_equals(&self, that: Local<Value>) -> bool {
|
pub fn strict_equals(&self, that: Local<Value>) -> bool {
|
||||||
unsafe { v8__Value__StrictEquals(self, &*that) }
|
unsafe { v8__Value__StrictEquals(self, &*that) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn same_value(&self, that: Local<Value>) -> bool {
|
pub fn same_value(&self, that: Local<Value>) -> bool {
|
||||||
unsafe { v8__Value__SameValue(self, &*that) }
|
unsafe { v8__Value__SameValue(self, &*that) }
|
||||||
}
|
}
|
||||||
|
@ -453,6 +510,7 @@ impl Value {
|
||||||
/// following important distinctions:
|
/// following important distinctions:
|
||||||
/// - It considers `NaN` equal to `NaN` (unlike `strict_equals()`).
|
/// - It considers `NaN` equal to `NaN` (unlike `strict_equals()`).
|
||||||
/// - It considers `-0` equal to `0` (unlike `same_value()`).
|
/// - It considers `-0` equal to `0` (unlike `same_value()`).
|
||||||
|
#[inline(always)]
|
||||||
pub fn same_value_zero(&self, that: Local<Value>) -> bool {
|
pub fn same_value_zero(&self, that: Local<Value>) -> bool {
|
||||||
// The SMI representation of zero is also zero. In debug builds, double
|
// The SMI representation of zero is also zero. In debug builds, double
|
||||||
// check this, so in the unlikely event that V8 changes its internal
|
// 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>(
|
pub fn to_big_int<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -474,6 +533,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_number<'s>(
|
pub fn to_number<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -484,6 +544,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_string<'s>(
|
pub fn to_string<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -495,6 +556,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function not present in the original V8 API.
|
/// Convenience function not present in the original V8 API.
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_rust_string_lossy<'s>(
|
pub fn to_rust_string_lossy<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -504,6 +566,7 @@ impl Value {
|
||||||
.map_or_else(std::string::String::new, |s| s.to_rust_string_lossy(scope))
|
.map_or_else(std::string::String::new, |s| s.to_rust_string_lossy(scope))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_detail_string<'s>(
|
pub fn to_detail_string<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -515,6 +578,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_object<'s>(
|
pub fn to_object<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -525,6 +589,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_integer<'s>(
|
pub fn to_integer<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -535,6 +600,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_uint32<'s>(
|
pub fn to_uint32<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -545,6 +611,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_int32<'s>(
|
pub fn to_int32<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -556,6 +623,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform the equivalent of Boolean(value) in JS. This can never fail.
|
/// Perform the equivalent of Boolean(value) in JS. This can never fail.
|
||||||
|
#[inline(always)]
|
||||||
pub fn to_boolean<'s>(
|
pub fn to_boolean<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
|
@ -566,6 +634,7 @@ impl Value {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn instance_of<'s>(
|
pub fn instance_of<'s>(
|
||||||
&self,
|
&self,
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
|
@ -583,6 +652,7 @@ impl Value {
|
||||||
out.into()
|
out.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn number_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<f64> {
|
pub fn number_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<f64> {
|
||||||
let mut out = Maybe::<f64>::default();
|
let mut out = Maybe::<f64>::default();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -591,6 +661,7 @@ impl Value {
|
||||||
out.into()
|
out.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn integer_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i64> {
|
pub fn integer_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i64> {
|
||||||
let mut out = Maybe::<i64>::default();
|
let mut out = Maybe::<i64>::default();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -599,6 +670,7 @@ impl Value {
|
||||||
out.into()
|
out.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn uint32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<u32> {
|
pub fn uint32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<u32> {
|
||||||
let mut out = Maybe::<u32>::default();
|
let mut out = Maybe::<u32>::default();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -607,6 +679,7 @@ impl Value {
|
||||||
out.into()
|
out.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn int32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i32> {
|
pub fn int32_value<'s>(&self, scope: &mut HandleScope<'s>) -> Option<i32> {
|
||||||
let mut out = Maybe::<i32>::default();
|
let mut out = Maybe::<i32>::default();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -615,6 +688,7 @@ impl Value {
|
||||||
out.into()
|
out.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn boolean_value<'s>(&self, scope: &mut HandleScope<'s, ()>) -> bool {
|
pub fn boolean_value<'s>(&self, scope: &mut HandleScope<'s, ()>) -> bool {
|
||||||
unsafe { v8__Value__BooleanValue(self, scope.get_isolate_ptr()) }
|
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
|
/// The return value will never be 0. Also, it is not guaranteed to be
|
||||||
/// unique.
|
/// unique.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_hash(&self) -> NonZeroI32 {
|
pub fn get_hash(&self) -> NonZeroI32 {
|
||||||
unsafe { NonZeroI32::new_unchecked(v8__Value__GetHash(self)) }
|
unsafe { NonZeroI32::new_unchecked(v8__Value__GetHash(self)) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ pub struct WasmStreaming(WasmStreamingSharedPtr);
|
||||||
|
|
||||||
impl WasmStreaming {
|
impl WasmStreaming {
|
||||||
/// Pass a new chunk of bytes to WebAssembly streaming compilation.
|
/// Pass a new chunk of bytes to WebAssembly streaming compilation.
|
||||||
|
#[inline(always)]
|
||||||
pub fn on_bytes_received(&mut self, data: &[u8]) {
|
pub fn on_bytes_received(&mut self, data: &[u8]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
v8__WasmStreaming__OnBytesReceived(&mut self.0, data.as_ptr(), data.len())
|
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
|
/// [`Self::on_bytes_received()`] to tell V8 that there will be no
|
||||||
/// more bytes. Does not have to be called after [`Self::abort()`]
|
/// more bytes. Does not have to be called after [`Self::abort()`]
|
||||||
/// has been called already.
|
/// has been called already.
|
||||||
|
#[inline(always)]
|
||||||
pub fn finish(mut self) {
|
pub fn finish(mut self) {
|
||||||
unsafe { v8__WasmStreaming__Finish(&mut self.0) }
|
unsafe { v8__WasmStreaming__Finish(&mut self.0) }
|
||||||
}
|
}
|
||||||
|
@ -53,6 +55,7 @@ impl WasmStreaming {
|
||||||
/// Abort streaming compilation. If {exception} has a value, then the promise
|
/// Abort streaming compilation. If {exception} has a value, then the promise
|
||||||
/// associated with streaming compilation is rejected with that value. If
|
/// associated with streaming compilation is rejected with that value. If
|
||||||
/// {exception} does not have value, the promise does not get rejected.
|
/// {exception} does not have value, the promise does not get rejected.
|
||||||
|
#[inline(always)]
|
||||||
pub fn abort(mut self, exception: Option<Local<Value>>) {
|
pub fn abort(mut self, exception: Option<Local<Value>>) {
|
||||||
let exception = exception.map(|v| &*v as *const Value).unwrap_or(null());
|
let exception = exception.map(|v| &*v as *const Value).unwrap_or(null());
|
||||||
unsafe { v8__WasmStreaming__Abort(&mut self.0, exception) }
|
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
|
/// Sets the UTF-8 encoded source URL for the `Script` object. This must be
|
||||||
/// called before [`Self::finish()`].
|
/// called before [`Self::finish()`].
|
||||||
|
#[inline(always)]
|
||||||
pub fn set_url(&mut self, url: &str) {
|
pub fn set_url(&mut self, url: &str) {
|
||||||
// Although not documented, V8 requires the url to be null terminated.
|
// Although not documented, V8 requires the url to be null terminated.
|
||||||
// See https://chromium-review.googlesource.com/c/v8/v8/+/3289148.
|
// See https://chromium-review.googlesource.com/c/v8/v8/+/3289148.
|
||||||
|
@ -83,6 +87,7 @@ impl Drop for WasmStreaming {
|
||||||
impl WasmModuleObject {
|
impl WasmModuleObject {
|
||||||
/// Efficiently re-create a WasmModuleObject, without recompiling, from
|
/// Efficiently re-create a WasmModuleObject, without recompiling, from
|
||||||
/// a CompiledWasmModule.
|
/// a CompiledWasmModule.
|
||||||
|
#[inline(always)]
|
||||||
pub fn from_compiled_module<'s>(
|
pub fn from_compiled_module<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
compiled_module: &CompiledWasmModule,
|
compiled_module: &CompiledWasmModule,
|
||||||
|
@ -99,12 +104,14 @@ impl WasmModuleObject {
|
||||||
|
|
||||||
/// Get the compiled module for this module object. The compiled module can be
|
/// Get the compiled module for this module object. The compiled module can be
|
||||||
/// shared by several module objects.
|
/// shared by several module objects.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_compiled_module(&self) -> CompiledWasmModule {
|
pub fn get_compiled_module(&self) -> CompiledWasmModule {
|
||||||
let ptr = unsafe { v8__WasmModuleObject__GetCompiledModule(self) };
|
let ptr = unsafe { v8__WasmModuleObject__GetCompiledModule(self) };
|
||||||
CompiledWasmModule(ptr)
|
CompiledWasmModule(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile a Wasm module from the provided uncompiled bytes.
|
/// Compile a Wasm module from the provided uncompiled bytes.
|
||||||
|
#[inline(always)]
|
||||||
pub fn compile<'s>(
|
pub fn compile<'s>(
|
||||||
scope: &mut HandleScope<'s>,
|
scope: &mut HandleScope<'s>,
|
||||||
wire_bytes: &[u8],
|
wire_bytes: &[u8],
|
||||||
|
@ -136,6 +143,7 @@ pub struct CompiledWasmModule(*mut InternalCompiledWasmModule);
|
||||||
|
|
||||||
impl CompiledWasmModule {
|
impl CompiledWasmModule {
|
||||||
/// Get the (wasm-encoded) wire bytes that were used to compile this module.
|
/// Get the (wasm-encoded) wire bytes that were used to compile this module.
|
||||||
|
#[inline(always)]
|
||||||
pub fn get_wire_bytes_ref(&self) -> &[u8] {
|
pub fn get_wire_bytes_ref(&self) -> &[u8] {
|
||||||
let mut len = 0isize;
|
let mut len = 0isize;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -144,6 +152,7 @@ impl CompiledWasmModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn source_url(&self) -> &str {
|
pub fn source_url(&self) -> &str {
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue