mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-22 04:40:01 +00:00
Always use raw pointers to send V8 handles between C++ and Rust (#349)
And other pointer usage touch-ups on the C++ side: - const parameters are passed by & reference. - mutable parameters are passed by * pointer.
This commit is contained in:
parent
675d585977
commit
d1ac68f0c8
@ -12,7 +12,7 @@ use crate::support::UniquePtr;
|
||||
extern "C" {
|
||||
fn v8__V8__SetFlagsFromCommandLine(argc: *mut c_int, argv: *mut *mut c_char);
|
||||
fn v8__V8__GetVersion() -> *const c_char;
|
||||
fn v8__V8__InitializePlatform(platform: &'static mut Platform);
|
||||
fn v8__V8__InitializePlatform(platform: *mut Platform);
|
||||
fn v8__V8__Initialize();
|
||||
fn v8__V8__Dispose() -> bool;
|
||||
fn v8__V8__ShutdownPlatform() -> ();
|
||||
|
@ -20,18 +20,18 @@ use crate::ToLocal;
|
||||
|
||||
extern "C" {
|
||||
fn v8__ArrayBuffer__Allocator__NewDefaultAllocator() -> *mut Allocator;
|
||||
fn v8__ArrayBuffer__Allocator__DELETE(this: &'static mut Allocator);
|
||||
fn v8__ArrayBuffer__Allocator__DELETE(this: *mut Allocator);
|
||||
fn v8__ArrayBuffer__New__with_byte_length(
|
||||
isolate: *mut Isolate,
|
||||
byte_length: usize,
|
||||
) -> *mut ArrayBuffer;
|
||||
) -> *const ArrayBuffer;
|
||||
fn v8__ArrayBuffer__New__with_backing_store(
|
||||
isolate: *mut Isolate,
|
||||
backing_store: *mut SharedRef<BackingStore>,
|
||||
) -> *mut ArrayBuffer;
|
||||
fn v8__ArrayBuffer__ByteLength(self_: *const ArrayBuffer) -> usize;
|
||||
backing_store: *const SharedRef<BackingStore>,
|
||||
) -> *const ArrayBuffer;
|
||||
fn v8__ArrayBuffer__ByteLength(this: *const ArrayBuffer) -> usize;
|
||||
fn v8__ArrayBuffer__GetBackingStore(
|
||||
self_: *const ArrayBuffer,
|
||||
this: *const ArrayBuffer,
|
||||
) -> SharedRef<BackingStore>;
|
||||
fn v8__ArrayBuffer__NewBackingStore__with_byte_length(
|
||||
isolate: *mut Isolate,
|
||||
@ -44,10 +44,10 @@ extern "C" {
|
||||
deleter_data: *mut c_void,
|
||||
) -> *mut BackingStore;
|
||||
|
||||
fn v8__BackingStore__Data(this: *mut BackingStore) -> *mut c_void;
|
||||
fn v8__BackingStore__Data(this: *const BackingStore) -> *mut c_void;
|
||||
fn v8__BackingStore__ByteLength(this: *const BackingStore) -> usize;
|
||||
fn v8__BackingStore__IsShared(this: *const BackingStore) -> bool;
|
||||
fn v8__BackingStore__DELETE(this: &mut BackingStore);
|
||||
fn v8__BackingStore__DELETE(this: *mut BackingStore);
|
||||
|
||||
fn std__shared_ptr__v8__BackingStore__COPY(
|
||||
ptr: *const SharedRef<BackingStore>,
|
||||
@ -255,11 +255,11 @@ impl ArrayBuffer {
|
||||
|
||||
pub fn with_backing_store<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
backing_store: &mut SharedRef<BackingStore>,
|
||||
backing_store: &SharedRef<BackingStore>,
|
||||
) -> Local<'sc, ArrayBuffer> {
|
||||
let isolate = scope.isolate();
|
||||
let ptr = unsafe {
|
||||
v8__ArrayBuffer__New__with_backing_store(isolate, &mut *backing_store)
|
||||
v8__ArrayBuffer__New__with_backing_store(isolate, backing_store)
|
||||
};
|
||||
unsafe { scope.to_local(ptr) }.unwrap()
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::convert::TryInto;
|
||||
use std::ffi::c_void;
|
||||
|
||||
use crate::support::int;
|
||||
use crate::ArrayBuffer;
|
||||
@ -8,12 +9,12 @@ use crate::Local;
|
||||
extern "C" {
|
||||
fn v8__ArrayBufferView__Buffer(
|
||||
this: *const ArrayBufferView,
|
||||
) -> *mut ArrayBuffer;
|
||||
) -> *const ArrayBuffer;
|
||||
fn v8__ArrayBufferView__ByteLength(this: *const ArrayBufferView) -> usize;
|
||||
fn v8__ArrayBufferView__ByteOffset(this: *const ArrayBufferView) -> usize;
|
||||
fn v8__ArrayBufferView__CopyContents(
|
||||
this: *const ArrayBufferView,
|
||||
dest: *mut u8,
|
||||
dest: *mut c_void,
|
||||
byte_length: int,
|
||||
) -> usize;
|
||||
}
|
||||
@ -42,7 +43,7 @@ impl ArrayBufferView {
|
||||
unsafe {
|
||||
v8__ArrayBufferView__CopyContents(
|
||||
self,
|
||||
dest.as_mut_ptr(),
|
||||
dest.as_mut_ptr() as *mut c_void,
|
||||
dest.len().try_into().unwrap(),
|
||||
)
|
||||
}
|
||||
|
980
src/binding.cc
980
src/binding.cc
File diff suppressed because it is too large
Load Diff
@ -10,13 +10,13 @@ use std::ptr::null;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Context__New(
|
||||
isolate: &Isolate,
|
||||
isolate: *mut Isolate,
|
||||
templ: *const ObjectTemplate,
|
||||
data: *const Value,
|
||||
) -> *mut Context;
|
||||
fn v8__Context__Enter(this: &mut Context);
|
||||
fn v8__Context__Exit(this: &mut Context);
|
||||
fn v8__Context__Global(this: *mut Context) -> *mut Object;
|
||||
global_object: *const Value,
|
||||
) -> *const Context;
|
||||
fn v8__Context__Enter(this: *const Context);
|
||||
fn v8__Context__Exit(this: *const Context);
|
||||
fn v8__Context__Global(this: *const Context) -> *const Object;
|
||||
}
|
||||
|
||||
impl Context {
|
||||
@ -51,22 +51,21 @@ impl Context {
|
||||
&self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Local<'sc, Object> {
|
||||
let context = self as *const _ as *mut Context;
|
||||
unsafe { scope.to_local(v8__Context__Global(context)) }.unwrap()
|
||||
unsafe { scope.to_local(v8__Context__Global(self)) }.unwrap()
|
||||
}
|
||||
|
||||
/// Enter this context. After entering a context, all code compiled
|
||||
/// and run is compiled and run in this context. If another context
|
||||
/// is already entered, this old context is saved so it can be
|
||||
/// restored when the new context is exited.
|
||||
pub(crate) fn enter(&mut self) {
|
||||
pub(crate) fn enter(&self) {
|
||||
// TODO: enter/exit should be controlled by a scope.
|
||||
unsafe { v8__Context__Enter(self) };
|
||||
}
|
||||
|
||||
/// Exit this context. Exiting the current context restores the
|
||||
/// context that was in place when entering the current context.
|
||||
pub(crate) fn exit(&mut self) {
|
||||
pub(crate) fn exit(&self) {
|
||||
// TODO: enter/exit should be controlled by a scope.
|
||||
unsafe { v8__Context__Exit(self) };
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
use std::convert::From;
|
||||
use std::convert::TryFrom;
|
||||
use std::error::Error;
|
||||
use std::ffi::c_void;
|
||||
use std::fmt;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Formatter;
|
||||
@ -72,7 +71,7 @@ macro_rules! impl_partial_eq {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn v8__Local__EQ(this: Local<c_void>, other: Local<c_void>) -> bool;
|
||||
fn v8__Local__EQ(this: *const Data, other: *const Data) -> bool;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
102
src/exception.rs
102
src/exception.rs
@ -12,58 +12,58 @@ use crate::ToLocal;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Message__Get(message: *const Message) -> *mut String;
|
||||
fn v8__Message__Get(this: *const Message) -> *const String;
|
||||
fn v8__Message__GetSourceLine(
|
||||
message: &Message,
|
||||
context: *mut Context,
|
||||
) -> *mut String;
|
||||
fn v8__Message__GetScriptResourceName(message: &Message) -> *mut Value;
|
||||
this: *const Message,
|
||||
context: *const Context,
|
||||
) -> *const String;
|
||||
fn v8__Message__GetScriptResourceName(this: *const Message) -> *const Value;
|
||||
fn v8__Message__GetLineNumber(
|
||||
message: &Message,
|
||||
context: *mut Context,
|
||||
this: *const Message,
|
||||
context: *const Context,
|
||||
) -> int;
|
||||
fn v8__Message__GetStartPosition(message: &Message) -> int;
|
||||
fn v8__Message__GetEndPosition(message: &Message) -> int;
|
||||
fn v8__Message__GetWasmFunctionIndex(message: &Message) -> int;
|
||||
fn v8__Message__ErrorLevel(message: &Message) -> int;
|
||||
fn v8__Message__GetStartColumn(message: &Message) -> int;
|
||||
fn v8__Message__GetEndColumn(message: &Message) -> int;
|
||||
fn v8__Message__IsSharedCrossOrigin(message: &Message) -> bool;
|
||||
fn v8__Message__IsOpaque(message: &Message) -> bool;
|
||||
fn v8__Message__GetStackTrace(message: &Message) -> *mut StackTrace;
|
||||
fn v8__Message__GetStartPosition(this: *const Message) -> int;
|
||||
fn v8__Message__GetEndPosition(this: *const Message) -> int;
|
||||
fn v8__Message__GetWasmFunctionIndex(this: *const Message) -> int;
|
||||
fn v8__Message__ErrorLevel(this: *const Message) -> int;
|
||||
fn v8__Message__GetStartColumn(this: *const Message) -> int;
|
||||
fn v8__Message__GetEndColumn(this: *const Message) -> int;
|
||||
fn v8__Message__IsSharedCrossOrigin(this: *const Message) -> bool;
|
||||
fn v8__Message__IsOpaque(this: *const Message) -> bool;
|
||||
fn v8__Message__GetStackTrace(this: *const Message) -> *const StackTrace;
|
||||
|
||||
fn v8__StackTrace__GetFrameCount(self_: &StackTrace) -> int;
|
||||
fn v8__StackTrace__GetFrameCount(this: *const StackTrace) -> int;
|
||||
fn v8__StackTrace__GetFrame(
|
||||
self_: &StackTrace,
|
||||
this: *const StackTrace,
|
||||
isolate: *mut Isolate,
|
||||
index: u32,
|
||||
) -> *mut StackFrame;
|
||||
) -> *const StackFrame;
|
||||
|
||||
fn v8__StackFrame__GetLineNumber(self_: &StackFrame) -> int;
|
||||
fn v8__StackFrame__GetColumn(self_: &StackFrame) -> int;
|
||||
fn v8__StackFrame__GetScriptId(self_: &StackFrame) -> int;
|
||||
fn v8__StackFrame__GetScriptName(self_: &StackFrame) -> *mut String;
|
||||
fn v8__StackFrame__GetLineNumber(this: *const StackFrame) -> int;
|
||||
fn v8__StackFrame__GetColumn(this: *const StackFrame) -> int;
|
||||
fn v8__StackFrame__GetScriptId(this: *const StackFrame) -> int;
|
||||
fn v8__StackFrame__GetScriptName(this: *const StackFrame) -> *const String;
|
||||
fn v8__StackFrame__GetScriptNameOrSourceURL(
|
||||
self_: &StackFrame,
|
||||
) -> *mut String;
|
||||
fn v8__StackFrame__GetFunctionName(self_: &StackFrame) -> *mut String;
|
||||
fn v8__StackFrame__IsEval(self_: &StackFrame) -> bool;
|
||||
fn v8__StackFrame__IsConstructor(self_: &StackFrame) -> bool;
|
||||
fn v8__StackFrame__IsWasm(self_: &StackFrame) -> bool;
|
||||
fn v8__StackFrame__IsUserJavaScript(self_: &StackFrame) -> bool;
|
||||
this: *const StackFrame,
|
||||
) -> *const String;
|
||||
fn v8__StackFrame__GetFunctionName(this: *const StackFrame) -> *const String;
|
||||
fn v8__StackFrame__IsEval(this: *const StackFrame) -> bool;
|
||||
fn v8__StackFrame__IsConstructor(this: *const StackFrame) -> bool;
|
||||
fn v8__StackFrame__IsWasm(this: *const StackFrame) -> bool;
|
||||
fn v8__StackFrame__IsUserJavaScript(this: *const StackFrame) -> bool;
|
||||
|
||||
fn v8__Exception__Error(message: Local<String>) -> *mut Value;
|
||||
fn v8__Exception__RangeError(message: Local<String>) -> *mut Value;
|
||||
fn v8__Exception__ReferenceError(message: Local<String>) -> *mut Value;
|
||||
fn v8__Exception__SyntaxError(message: Local<String>) -> *mut Value;
|
||||
fn v8__Exception__TypeError(message: Local<String>) -> *mut Value;
|
||||
fn v8__Exception__Error(message: *const String) -> *const Value;
|
||||
fn v8__Exception__RangeError(message: *const String) -> *const Value;
|
||||
fn v8__Exception__ReferenceError(message: *const String) -> *const Value;
|
||||
fn v8__Exception__SyntaxError(message: *const String) -> *const Value;
|
||||
fn v8__Exception__TypeError(message: *const String) -> *const Value;
|
||||
|
||||
fn v8__Exception__CreateMessage(
|
||||
isolate: &Isolate,
|
||||
exception: Local<Value>,
|
||||
) -> *mut Message;
|
||||
|
||||
fn v8__Exception__GetStackTrace(exception: Local<Value>) -> *mut StackTrace;
|
||||
isolate: *mut Isolate,
|
||||
exception: *const Value,
|
||||
) -> *const Message;
|
||||
fn v8__Exception__GetStackTrace(exception: *const Value)
|
||||
-> *const StackTrace;
|
||||
}
|
||||
|
||||
impl StackTrace {
|
||||
@ -180,9 +180,9 @@ impl Message {
|
||||
pub fn get_source_line<'s>(
|
||||
&self,
|
||||
scope: &mut impl ToLocal<'s>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'s, String>> {
|
||||
unsafe { scope.to_local(v8__Message__GetSourceLine(self, &mut *context)) }
|
||||
unsafe { scope.to_local(v8__Message__GetSourceLine(self, &*context)) }
|
||||
}
|
||||
|
||||
/// Returns the resource name for the script from where the function causing
|
||||
@ -195,8 +195,8 @@ impl Message {
|
||||
}
|
||||
|
||||
/// Returns the number, 1-based, of the line where the error occurred.
|
||||
pub fn get_line_number(&self, mut context: Local<Context>) -> Option<usize> {
|
||||
let i = unsafe { v8__Message__GetLineNumber(self, &mut *context) };
|
||||
pub fn get_line_number(&self, context: Local<Context>) -> Option<usize> {
|
||||
let i = unsafe { v8__Message__GetLineNumber(self, &*context) };
|
||||
if i < 0 {
|
||||
None
|
||||
} else {
|
||||
@ -261,7 +261,7 @@ impl Exception {
|
||||
) -> Local<'sc, Value> {
|
||||
let isolate = scope.isolate();
|
||||
isolate.enter();
|
||||
let e = unsafe { v8__Exception__Error(message) };
|
||||
let e = unsafe { v8__Exception__Error(&*message) };
|
||||
isolate.exit();
|
||||
unsafe { scope.to_local(e) }.unwrap()
|
||||
}
|
||||
@ -272,7 +272,7 @@ impl Exception {
|
||||
) -> Local<'sc, Value> {
|
||||
let isolate = scope.isolate();
|
||||
isolate.enter();
|
||||
let e = unsafe { v8__Exception__RangeError(message) };
|
||||
let e = unsafe { v8__Exception__RangeError(&*message) };
|
||||
isolate.exit();
|
||||
unsafe { scope.to_local(e) }.unwrap()
|
||||
}
|
||||
@ -283,7 +283,7 @@ impl Exception {
|
||||
) -> Local<'sc, Value> {
|
||||
let isolate = scope.isolate();
|
||||
isolate.enter();
|
||||
let e = unsafe { v8__Exception__ReferenceError(message) };
|
||||
let e = unsafe { v8__Exception__ReferenceError(&*message) };
|
||||
isolate.exit();
|
||||
unsafe { scope.to_local(e) }.unwrap()
|
||||
}
|
||||
@ -294,7 +294,7 @@ impl Exception {
|
||||
) -> Local<'sc, Value> {
|
||||
let isolate = scope.isolate();
|
||||
isolate.enter();
|
||||
let e = unsafe { v8__Exception__SyntaxError(message) };
|
||||
let e = unsafe { v8__Exception__SyntaxError(&*message) };
|
||||
isolate.exit();
|
||||
unsafe { scope.to_local(e) }.unwrap()
|
||||
}
|
||||
@ -305,7 +305,7 @@ impl Exception {
|
||||
) -> Local<'sc, Value> {
|
||||
let isolate = scope.isolate();
|
||||
isolate.enter();
|
||||
let e = unsafe { v8__Exception__TypeError(message) };
|
||||
let e = unsafe { v8__Exception__TypeError(&*message) };
|
||||
isolate.exit();
|
||||
unsafe { scope.to_local(e) }.unwrap()
|
||||
}
|
||||
@ -318,7 +318,7 @@ impl Exception {
|
||||
exception: Local<Value>,
|
||||
) -> Local<'sc, Message> {
|
||||
let isolate = scope.isolate();
|
||||
let ptr = unsafe { v8__Exception__CreateMessage(isolate, exception) };
|
||||
let ptr = unsafe { v8__Exception__CreateMessage(isolate, &*exception) };
|
||||
unsafe { scope.to_local(ptr) }.unwrap()
|
||||
}
|
||||
|
||||
@ -328,6 +328,6 @@ impl Exception {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
exception: Local<Value>,
|
||||
) -> Option<Local<'sc, StackTrace>> {
|
||||
unsafe { scope.to_local(v8__Exception__GetStackTrace(exception)) }
|
||||
unsafe { scope.to_local(v8__Exception__GetStackTrace(&*exception)) }
|
||||
}
|
||||
}
|
||||
|
@ -19,48 +19,47 @@ use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Function__New(
|
||||
context: *mut Context,
|
||||
context: *const Context,
|
||||
callback: FunctionCallback,
|
||||
) -> *mut Function;
|
||||
) -> *const Function;
|
||||
fn v8__Function__NewWithData(
|
||||
context: *mut Context,
|
||||
context: *const Context,
|
||||
callback: FunctionCallback,
|
||||
data: Local<Value>,
|
||||
) -> *mut Function;
|
||||
data: *const Value,
|
||||
) -> *const Function;
|
||||
fn v8__Function__Call(
|
||||
function: *const Function,
|
||||
context: Local<Context>,
|
||||
recv: Local<Value>,
|
||||
this: *const Function,
|
||||
context: *const Context,
|
||||
recv: *const Value,
|
||||
argc: int,
|
||||
argv: *const Local<Value>,
|
||||
) -> *mut Value;
|
||||
argv: *const *const Value,
|
||||
) -> *const Value;
|
||||
|
||||
fn v8__FunctionCallbackInfo__GetReturnValue(
|
||||
info: *const FunctionCallbackInfo,
|
||||
) -> *mut Value;
|
||||
fn v8__FunctionCallbackInfo__This(
|
||||
info: *const FunctionCallbackInfo,
|
||||
) -> *mut Object;
|
||||
fn v8__FunctionCallbackInfo__Length(info: *const FunctionCallbackInfo)
|
||||
this: *const FunctionCallbackInfo,
|
||||
) -> *const Object;
|
||||
fn v8__FunctionCallbackInfo__Length(this: *const FunctionCallbackInfo)
|
||||
-> int;
|
||||
fn v8__FunctionCallbackInfo__GetArgument(
|
||||
info: *const FunctionCallbackInfo,
|
||||
this: *const FunctionCallbackInfo,
|
||||
i: int,
|
||||
) -> *mut Value;
|
||||
) -> *const Value;
|
||||
fn v8__FunctionCallbackInfo__Data(
|
||||
info: *const FunctionCallbackInfo,
|
||||
) -> *mut Value;
|
||||
this: *const FunctionCallbackInfo,
|
||||
) -> *const Value;
|
||||
|
||||
fn v8__PropertyCallbackInfo__GetReturnValue(
|
||||
info: *const PropertyCallbackInfo,
|
||||
this: *const PropertyCallbackInfo,
|
||||
) -> *mut Value;
|
||||
fn v8__PropertyCallbackInfo__This(
|
||||
info: *const PropertyCallbackInfo,
|
||||
) -> *mut Object;
|
||||
|
||||
fn v8__ReturnValue__Set(rv: &mut ReturnValue, value: *mut Value);
|
||||
fn v8__ReturnValue__Get(rv: &ReturnValue) -> *mut Value;
|
||||
this: *const PropertyCallbackInfo,
|
||||
) -> *const Object;
|
||||
|
||||
fn v8__ReturnValue__Set(this: *mut ReturnValue, value: *const Value);
|
||||
fn v8__ReturnValue__Get(this: *const ReturnValue) -> *const Value;
|
||||
}
|
||||
|
||||
// Npte: the 'cb lifetime is required because the ReturnValue object must not
|
||||
@ -86,8 +85,8 @@ impl<'cb> ReturnValue<'cb> {
|
||||
|
||||
// NOTE: simplest setter, possibly we'll need to add
|
||||
// more setters specialized per type
|
||||
pub fn set(&mut self, mut value: Local<Value>) {
|
||||
unsafe { v8__ReturnValue__Set(&mut *self, &mut *value) }
|
||||
pub fn set(&mut self, value: Local<Value>) {
|
||||
unsafe { v8__ReturnValue__Set(&mut *self, &*value) }
|
||||
}
|
||||
|
||||
/// Getter. Creates a new Local<> so it comes with a certain performance
|
||||
@ -110,7 +109,7 @@ pub struct FunctionCallbackInfo {
|
||||
// The layout of this struct must match that of `class FunctionCallbackInfo`
|
||||
// as defined in v8.h.
|
||||
implicit_args: *mut Opaque,
|
||||
values: *mut Value,
|
||||
values: *const Value,
|
||||
length: int,
|
||||
}
|
||||
|
||||
@ -288,11 +287,11 @@ impl Function {
|
||||
/// for a given FunctionCallback.
|
||||
pub fn new<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
callback: impl MapFnTo<FunctionCallback>,
|
||||
) -> Option<Local<'sc, Function>> {
|
||||
unsafe {
|
||||
scope.to_local(v8__Function__New(&mut *context, callback.map_fn_to()))
|
||||
scope.to_local(v8__Function__New(&*context, callback.map_fn_to()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,15 +299,15 @@ impl Function {
|
||||
/// for a given FunctionCallback and associated data.
|
||||
pub fn new_with_data<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
data: Local<Value>,
|
||||
callback: impl MapFnTo<FunctionCallback>,
|
||||
) -> Option<Local<'sc, Function>> {
|
||||
unsafe {
|
||||
scope.to_local(v8__Function__NewWithData(
|
||||
&mut *context,
|
||||
&*context,
|
||||
callback.map_fn_to(),
|
||||
data,
|
||||
&*data,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -320,10 +319,11 @@ impl Function {
|
||||
recv: Local<Value>,
|
||||
args: &[Local<Value>],
|
||||
) -> Option<Local<'sc, Value>> {
|
||||
let argv = args.as_ptr();
|
||||
let args = Local::slice_into_raw(args);
|
||||
let argc = int::try_from(args.len()).unwrap();
|
||||
let argv = args.as_ptr();
|
||||
unsafe {
|
||||
scope.to_local(v8__Function__Call(self, context, recv, argc, argv))
|
||||
scope.to_local(v8__Function__Call(self, &*context, &*recv, argc, argv))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
use std::mem::transmute;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
use crate::Data;
|
||||
use crate::InIsolate;
|
||||
use crate::Isolate;
|
||||
use crate::IsolateHandle;
|
||||
use crate::Local;
|
||||
use crate::ToLocal;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Local__New(isolate: *mut Isolate, other: *mut Value) -> *mut Value;
|
||||
fn v8__Local__New(isolate: *mut Isolate, other: *const Data) -> *const Data;
|
||||
|
||||
fn v8__Global__New(isolate: *mut Isolate, other: *mut Value) -> *mut Value;
|
||||
fn v8__Global__New(isolate: *mut Isolate, other: *const Data) -> *const Data;
|
||||
|
||||
fn v8__Global__Reset__0(this: &mut *mut Value);
|
||||
fn v8__Global__Reset__0(this: *mut *const Data);
|
||||
|
||||
fn v8__Global__Reset__2(
|
||||
this: &mut *mut Value,
|
||||
this: *mut *const Data,
|
||||
isolate: *mut Isolate,
|
||||
other: &*mut Value,
|
||||
other: *const *const Data,
|
||||
);
|
||||
}
|
||||
|
||||
@ -78,9 +78,9 @@ impl<T> Global<T> {
|
||||
self.check_isolate(isolate);
|
||||
self
|
||||
.value
|
||||
.map(|g| g.as_ptr() as *mut Value)
|
||||
.map(|g| g.as_ptr() as *const Data)
|
||||
.map(|g| unsafe { v8__Local__New(isolate, g) })
|
||||
.and_then(|l| unsafe { scope.to_local(l as *mut T) })
|
||||
.and_then(|l| unsafe { scope.to_local(l as *const T) })
|
||||
}
|
||||
|
||||
/// If non-empty, destroy the underlying storage cell
|
||||
@ -93,14 +93,14 @@ impl<T> Global<T> {
|
||||
(None, None) => {}
|
||||
(target, None) => unsafe {
|
||||
v8__Global__Reset__0(
|
||||
&mut *(target as *mut Option<NonNull<T>> as *mut *mut Value),
|
||||
&mut *(target as *mut Option<NonNull<T>> as *mut *const Data),
|
||||
)
|
||||
},
|
||||
(target, source) => unsafe {
|
||||
v8__Global__Reset__2(
|
||||
&mut *(target as *mut Option<NonNull<T>> as *mut *mut Value),
|
||||
&mut *(target as *mut Option<NonNull<T>> as *mut *const Data),
|
||||
isolate,
|
||||
&*(source as *const Option<NonNull<T>> as *const *mut Value),
|
||||
&*(source as *const Option<NonNull<T>> as *const *const Data),
|
||||
)
|
||||
},
|
||||
}
|
||||
@ -153,7 +153,7 @@ impl<T> Drop for Global<T> {
|
||||
addr @ Some(_) => unsafe {
|
||||
// Destroy the storage cell that contains the contents of this Global.
|
||||
v8__Global__Reset__0(
|
||||
&mut *(addr as *mut Option<NonNull<T>> as *mut *mut Value),
|
||||
&mut *(addr as *mut Option<NonNull<T>> as *mut *const Data),
|
||||
)
|
||||
},
|
||||
}
|
||||
|
@ -4,22 +4,22 @@ use crate::isolate::Isolate;
|
||||
use crate::scope::Scope;
|
||||
use crate::scope::ScopeDefinition;
|
||||
use crate::scope_traits::ToLocalOrReturnsLocal;
|
||||
use crate::Data;
|
||||
use crate::InIsolate;
|
||||
use crate::Local;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__HandleScope__CONSTRUCT(buf: *mut HandleScope, isolate: *mut Isolate);
|
||||
fn v8__HandleScope__DESTRUCT(this: &mut HandleScope);
|
||||
fn v8__HandleScope__DESTRUCT(this: *mut HandleScope);
|
||||
fn v8__EscapableHandleScope__CONSTRUCT(
|
||||
buf: *mut EscapableHandleScope,
|
||||
isolate: *mut Isolate,
|
||||
);
|
||||
fn v8__EscapableHandleScope__DESTRUCT(this: &mut EscapableHandleScope);
|
||||
fn v8__EscapableHandleScope__DESTRUCT(this: *mut EscapableHandleScope);
|
||||
fn v8__EscapableHandleScope__Escape(
|
||||
this: &mut EscapableHandleScope,
|
||||
value: *mut Value,
|
||||
) -> *mut Value;
|
||||
this: *mut EscapableHandleScope,
|
||||
value: *const Data,
|
||||
) -> *const Data;
|
||||
}
|
||||
|
||||
/// A stack-allocated class that governs a number of local handles.
|
||||
@ -82,8 +82,8 @@ impl<'s> EscapableHandleScope {
|
||||
) -> Local<'p, T> {
|
||||
Local::from_raw(v8__EscapableHandleScope__Escape(
|
||||
self,
|
||||
value.as_ptr() as *mut Value,
|
||||
) as *mut T)
|
||||
value.as_ptr() as *const Data,
|
||||
) as *const T)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
@ -102,10 +102,10 @@ extern "C" {
|
||||
state: *const StringView,
|
||||
) -> *mut V8InspectorSession;
|
||||
fn v8_inspector__V8Inspector__contextCreated(
|
||||
inspector: *mut V8Inspector,
|
||||
context: *mut Context,
|
||||
context_group_id: int,
|
||||
human_readable_name: *const StringView,
|
||||
this: *mut V8Inspector,
|
||||
context: *const Context,
|
||||
contextGroupId: int,
|
||||
humanReadableName: *const StringView,
|
||||
);
|
||||
}
|
||||
|
||||
@ -878,14 +878,14 @@ impl V8Inspector {
|
||||
/// work to bind the V8ContextInfo, which is not used elsewhere.
|
||||
pub fn context_created(
|
||||
&mut self,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
context_group_id: i32,
|
||||
human_readable_name: &StringView,
|
||||
) {
|
||||
unsafe {
|
||||
v8_inspector__V8Inspector__contextCreated(
|
||||
self,
|
||||
&mut *context,
|
||||
&*context,
|
||||
context_group_id,
|
||||
human_readable_name,
|
||||
)
|
||||
|
@ -85,7 +85,7 @@ extern "C" {
|
||||
frame_limit: i32,
|
||||
);
|
||||
fn v8__Isolate__AddMessageListener(
|
||||
this: &mut Isolate,
|
||||
isolate: *mut Isolate,
|
||||
callback: MessageCallback,
|
||||
) -> bool;
|
||||
fn v8__Isolate__SetPromiseRejectCallback(
|
||||
@ -107,29 +107,29 @@ extern "C" {
|
||||
);
|
||||
fn v8__Isolate__ThrowException(
|
||||
isolate: *mut Isolate,
|
||||
exception: Local<Value>,
|
||||
) -> *mut Value;
|
||||
exception: *const Value,
|
||||
) -> *const Value;
|
||||
fn v8__Isolate__TerminateExecution(isolate: *const Isolate);
|
||||
fn v8__Isolate__IsExecutionTerminating(isolate: *const Isolate) -> bool;
|
||||
fn v8__Isolate__CancelTerminateExecution(isolate: *const Isolate);
|
||||
fn v8__Isolate__RunMicrotasks(isolate: *mut Isolate);
|
||||
fn v8__Isolate__EnqueueMicrotask(
|
||||
isolate: *mut Isolate,
|
||||
microtask: Local<Function>,
|
||||
function: *const Function,
|
||||
);
|
||||
|
||||
fn v8__Isolate__CreateParams__NEW() -> *mut CreateParams;
|
||||
fn v8__Isolate__CreateParams__DELETE(this: &mut CreateParams);
|
||||
fn v8__Isolate__CreateParams__DELETE(this: *mut CreateParams);
|
||||
fn v8__Isolate__CreateParams__SET__array_buffer_allocator(
|
||||
this: &mut CreateParams,
|
||||
allocator: &SharedRef<Allocator>,
|
||||
this: *mut CreateParams,
|
||||
allocator: *const SharedRef<Allocator>,
|
||||
);
|
||||
fn v8__Isolate__CreateParams__SET__external_references(
|
||||
this: &mut CreateParams,
|
||||
this: *mut CreateParams,
|
||||
value: *const intptr_t,
|
||||
);
|
||||
fn v8__Isolate__CreateParams__SET__snapshot_blob(
|
||||
this: &mut CreateParams,
|
||||
this: *mut CreateParams,
|
||||
snapshot_blob: *mut StartupData,
|
||||
);
|
||||
fn v8__HeapProfiler__TakeHeapSnapshot(
|
||||
@ -279,7 +279,7 @@ impl Isolate {
|
||||
exception: Local<Value>,
|
||||
) -> Local<'sc, Value> {
|
||||
unsafe {
|
||||
let ptr = v8__Isolate__ThrowException(self, exception);
|
||||
let ptr = v8__Isolate__ThrowException(self, &*exception);
|
||||
Local::from_raw(ptr).unwrap()
|
||||
}
|
||||
}
|
||||
@ -292,7 +292,7 @@ impl Isolate {
|
||||
|
||||
/// Enqueues the callback to the default MicrotaskQueue
|
||||
pub fn enqueue_microtask(&mut self, microtask: Local<Function>) {
|
||||
unsafe { v8__Isolate__EnqueueMicrotask(self, microtask) }
|
||||
unsafe { v8__Isolate__EnqueueMicrotask(self, &*microtask) }
|
||||
}
|
||||
|
||||
/// Disposes the isolate. The isolate must not be entered by any
|
||||
|
26
src/json.rs
26
src/json.rs
@ -7,31 +7,29 @@ use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__JSON__Parse(
|
||||
context: *mut Context,
|
||||
json_string: *mut String,
|
||||
) -> *mut Value;
|
||||
context: *const Context,
|
||||
json_string: *const String,
|
||||
) -> *const Value;
|
||||
fn v8__JSON__Stringify(
|
||||
context: *mut Context,
|
||||
json_object: *mut Value,
|
||||
) -> *mut String;
|
||||
context: *const Context,
|
||||
json_object: *const Value,
|
||||
) -> *const String;
|
||||
}
|
||||
|
||||
/// Tries to parse the string `json_string` and returns it as value if
|
||||
/// successful.
|
||||
pub fn parse<'sc>(
|
||||
mut context: Local<'sc, Context>,
|
||||
mut json_string: Local<'sc, String>,
|
||||
context: Local<'sc, Context>,
|
||||
json_string: Local<'sc, String>,
|
||||
) -> Option<Local<'sc, Value>> {
|
||||
unsafe { Local::from_raw(v8__JSON__Parse(&mut *context, &mut *json_string)) }
|
||||
unsafe { Local::from_raw(v8__JSON__Parse(&*context, &*json_string)) }
|
||||
}
|
||||
|
||||
/// Tries to stringify the JSON-serializable object `json_object` and returns
|
||||
/// it as string if successful.
|
||||
pub fn stringify<'sc>(
|
||||
mut context: Local<'sc, Context>,
|
||||
mut json_object: Local<'sc, Value>,
|
||||
context: Local<'sc, Context>,
|
||||
json_object: Local<'sc, Value>,
|
||||
) -> Option<Local<'sc, String>> {
|
||||
unsafe {
|
||||
Local::from_raw(v8__JSON__Stringify(&mut *context, &mut *json_object))
|
||||
}
|
||||
unsafe { Local::from_raw(v8__JSON__Stringify(&*context, &*json_object)) }
|
||||
}
|
||||
|
10
src/local.rs
10
src/local.rs
@ -58,17 +58,21 @@ impl<'sc, T> Local<'sc, T> {
|
||||
transmute(other)
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn from_raw(ptr: *mut T) -> Option<Self> {
|
||||
Some(Self(NonNull::new(ptr)?, PhantomData))
|
||||
pub(crate) unsafe fn from_raw(ptr: *const T) -> Option<Self> {
|
||||
Some(Self(NonNull::new(ptr as *mut _)?, PhantomData))
|
||||
}
|
||||
|
||||
pub(crate) fn as_non_null(self) -> NonNull<T> {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub(crate) fn as_ptr(self) -> *mut T {
|
||||
pub(crate) fn as_ptr(self) -> *const T {
|
||||
self.0.as_ptr()
|
||||
}
|
||||
|
||||
pub(crate) fn slice_into_raw(slice: &[Self]) -> &[*const T] {
|
||||
unsafe { &*(slice as *const [Self] as *const [*const T]) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'sc, T> Deref for Local<'sc, T> {
|
||||
|
@ -84,27 +84,28 @@ where
|
||||
|
||||
extern "C" {
|
||||
fn v8__Module__GetStatus(this: *const Module) -> ModuleStatus;
|
||||
fn v8__Module__GetException(this: *const Module) -> *mut Value;
|
||||
fn v8__Module__GetException(this: *const Module) -> *const Value;
|
||||
fn v8__Module__GetModuleRequestsLength(this: *const Module) -> int;
|
||||
fn v8__Module__GetModuleRequest(this: *const Module, i: int) -> *mut String;
|
||||
fn v8__Module__GetModuleRequest(this: *const Module, i: int)
|
||||
-> *const String;
|
||||
fn v8__Module__GetModuleRequestLocation(
|
||||
this: *const Module,
|
||||
i: usize,
|
||||
out: &mut MaybeUninit<Location>,
|
||||
out: *mut MaybeUninit<Location>,
|
||||
) -> Location;
|
||||
fn v8__Module__GetModuleNamespace(this: *mut Module) -> *mut Value;
|
||||
fn v8__Module__GetModuleNamespace(this: *const Module) -> *const Value;
|
||||
fn v8__Module__GetIdentityHash(this: *const Module) -> int;
|
||||
fn v8__Module__InstantiateModule(
|
||||
this: *mut Module,
|
||||
context: Local<Context>,
|
||||
callback: ResolveCallback,
|
||||
this: *const Module,
|
||||
context: *const Context,
|
||||
cb: ResolveCallback,
|
||||
) -> MaybeBool;
|
||||
fn v8__Module__Evaluate(
|
||||
this: *mut Module,
|
||||
context: *mut Context,
|
||||
) -> *mut Value;
|
||||
fn v8__Location__GetLineNumber(this: &Location) -> int;
|
||||
fn v8__Location__GetColumnNumber(this: &Location) -> int;
|
||||
this: *const Module,
|
||||
context: *const Context,
|
||||
) -> *const Value;
|
||||
fn v8__Location__GetLineNumber(this: *const Location) -> int;
|
||||
fn v8__Location__GetColumnNumber(this: *const Location) -> int;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -195,7 +196,7 @@ impl Module {
|
||||
callback: impl MapFnTo<ResolveCallback<'a>>,
|
||||
) -> Option<bool> {
|
||||
unsafe {
|
||||
v8__Module__InstantiateModule(self, context, callback.map_fn_to())
|
||||
v8__Module__InstantiateModule(self, &*context, callback.map_fn_to())
|
||||
}
|
||||
.into()
|
||||
}
|
||||
@ -208,10 +209,10 @@ impl Module {
|
||||
/// via |GetException|).
|
||||
#[must_use]
|
||||
pub fn evaluate<'sc>(
|
||||
&mut self,
|
||||
&self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'sc, Value>> {
|
||||
unsafe { scope.to_local(v8__Module__Evaluate(&mut *self, &mut *context)) }
|
||||
unsafe { scope.to_local(v8__Module__Evaluate(&*self, &*context)) }
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ use crate::Number;
|
||||
use crate::ToLocal;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Number__New(isolate: *mut Isolate, value: f64) -> *mut Number;
|
||||
fn v8__Number__Value(this: &Number) -> f64;
|
||||
fn v8__Integer__New(isolate: *mut Isolate, value: i32) -> *mut Integer;
|
||||
fn v8__Number__New(isolate: *mut Isolate, value: f64) -> *const Number;
|
||||
fn v8__Number__Value(this: *const Number) -> f64;
|
||||
fn v8__Integer__New(isolate: *mut Isolate, value: i32) -> *const Integer;
|
||||
fn v8__Integer__NewFromUnsigned(
|
||||
isolate: *mut Isolate,
|
||||
value: u32,
|
||||
) -> *mut Integer;
|
||||
) -> *const Integer;
|
||||
fn v8__Integer__Value(this: *const Integer) -> i64;
|
||||
}
|
||||
|
||||
|
120
src/object.rs
120
src/object.rs
@ -14,73 +14,73 @@ use crate::ToLocal;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Object__New(isolate: *mut Isolate) -> *mut Object;
|
||||
fn v8__Object__New(isolate: *mut Isolate) -> *const Object;
|
||||
fn v8__Object__New__with_prototype_and_properties(
|
||||
isolate: *mut Isolate,
|
||||
prototype_or_null: Local<Value>,
|
||||
names: *mut Local<Name>,
|
||||
values: *mut Local<Value>,
|
||||
prototype_or_null: *const Value,
|
||||
names: *const *const Name,
|
||||
values: *const *const Value,
|
||||
length: usize,
|
||||
) -> *mut Object;
|
||||
) -> *const Object;
|
||||
fn v8__Object__SetAccessor(
|
||||
self_: &Object,
|
||||
context: Local<Context>,
|
||||
name: Local<Name>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
key: *const Name,
|
||||
getter: AccessorNameGetterCallback,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__Get(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
key: Local<Value>,
|
||||
) -> *mut Value;
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
key: *const Value,
|
||||
) -> *const Value;
|
||||
fn v8__Object__GetIndex(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
index: u32,
|
||||
) -> *mut Value;
|
||||
fn v8__Object__GetPrototype(object: &Object) -> *mut Value;
|
||||
) -> *const Value;
|
||||
fn v8__Object__GetPrototype(this: *const Object) -> *const Value;
|
||||
fn v8__Object__Set(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
key: Local<Value>,
|
||||
value: Local<Value>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
key: *const Value,
|
||||
value: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__SetIndex(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
index: u32,
|
||||
value: Local<Value>,
|
||||
value: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__SetPrototype(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
prototype: Local<Value>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
prototype: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__CreateDataProperty(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
key: Local<Name>,
|
||||
value: Local<Value>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
key: *const Name,
|
||||
value: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__DefineOwnProperty(
|
||||
object: &Object,
|
||||
context: Local<Context>,
|
||||
key: Local<Name>,
|
||||
value: Local<Value>,
|
||||
this: *const Object,
|
||||
context: *const Context,
|
||||
key: *const Name,
|
||||
value: *const Value,
|
||||
attr: PropertyAttribute,
|
||||
) -> MaybeBool;
|
||||
fn v8__Object__GetIdentityHash(object: &Object) -> int;
|
||||
fn v8__Object__CreationContext(object: &Object) -> *mut Context;
|
||||
fn v8__Object__GetIdentityHash(this: *const Object) -> int;
|
||||
fn v8__Object__CreationContext(this: *const Object) -> *const Context;
|
||||
|
||||
fn v8__Array__New(isolate: *mut Isolate, length: int) -> *mut Array;
|
||||
fn v8__Array__New(isolate: *mut Isolate, length: int) -> *const Array;
|
||||
fn v8__Array__New_with_elements(
|
||||
isolate: *mut Isolate,
|
||||
elements: *const Local<Value>,
|
||||
elements: *const *const Value,
|
||||
length: usize,
|
||||
) -> *mut Array;
|
||||
fn v8__Array__Length(array: &Array) -> u32;
|
||||
fn v8__Map__Size(map: &Map) -> usize;
|
||||
fn v8__Map__As__Array(map: &Map) -> *mut Array;
|
||||
) -> *const Array;
|
||||
fn v8__Array__Length(array: *const Array) -> u32;
|
||||
fn v8__Map__Size(map: *const Map) -> usize;
|
||||
fn v8__Map__As__Array(this: *const Map) -> *const Array;
|
||||
}
|
||||
|
||||
impl Object {
|
||||
@ -103,12 +103,14 @@ impl Object {
|
||||
values: &[Local<Value>],
|
||||
) -> Local<'sc, Object> {
|
||||
assert_eq!(names.len(), values.len());
|
||||
let names = Local::slice_into_raw(names);
|
||||
let values = Local::slice_into_raw(values);
|
||||
unsafe {
|
||||
let object = v8__Object__New__with_prototype_and_properties(
|
||||
scope.isolate(),
|
||||
prototype_or_null,
|
||||
names.as_ptr() as *mut Local<Name>,
|
||||
values.as_ptr() as *mut Local<Value>,
|
||||
&*prototype_or_null,
|
||||
names.as_ptr(),
|
||||
values.as_ptr(),
|
||||
names.len(),
|
||||
);
|
||||
scope.to_local(object).unwrap()
|
||||
@ -123,7 +125,7 @@ impl Object {
|
||||
key: Local<Value>,
|
||||
value: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__Set(self, context, key, value) }.into()
|
||||
unsafe { v8__Object__Set(self, &*context, &*key, &*value) }.into()
|
||||
}
|
||||
|
||||
/// Set only return Just(true) or Empty(), so if it should never fail, use
|
||||
@ -134,7 +136,7 @@ impl Object {
|
||||
index: u32,
|
||||
value: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__SetIndex(self, context, index, value) }.into()
|
||||
unsafe { v8__Object__SetIndex(self, &*context, index, &*value) }.into()
|
||||
}
|
||||
|
||||
/// Set the prototype object. This does not skip objects marked to be
|
||||
@ -144,7 +146,7 @@ impl Object {
|
||||
context: Local<Context>,
|
||||
prototype: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__SetPrototype(self, context, prototype) }.into()
|
||||
unsafe { v8__Object__SetPrototype(self, &*context, &*prototype) }.into()
|
||||
}
|
||||
|
||||
/// Implements CreateDataProperty (ECMA-262, 7.3.4).
|
||||
@ -160,7 +162,8 @@ impl Object {
|
||||
key: Local<Name>,
|
||||
value: Local<Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__CreateDataProperty(self, context, key, value) }.into()
|
||||
unsafe { v8__Object__CreateDataProperty(self, &*context, &*key, &*value) }
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Implements DefineOwnProperty.
|
||||
@ -176,8 +179,10 @@ impl Object {
|
||||
value: Local<Value>,
|
||||
attr: PropertyAttribute,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__DefineOwnProperty(self, context, key, value, attr) }
|
||||
.into()
|
||||
unsafe {
|
||||
v8__Object__DefineOwnProperty(self, &*context, &*key, &*value, attr)
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn get<'a>(
|
||||
@ -187,7 +192,7 @@ impl Object {
|
||||
key: Local<Value>,
|
||||
) -> Option<Local<'a, Value>> {
|
||||
unsafe {
|
||||
let ptr = v8__Object__Get(self, context, key);
|
||||
let ptr = v8__Object__Get(self, &*context, &*key);
|
||||
scope.to_local(ptr)
|
||||
}
|
||||
}
|
||||
@ -199,7 +204,7 @@ impl Object {
|
||||
index: u32,
|
||||
) -> Option<Local<'a, Value>> {
|
||||
unsafe {
|
||||
let ptr = v8__Object__GetIndex(self, context, index);
|
||||
let ptr = v8__Object__GetIndex(self, &*context, index);
|
||||
scope.to_local(ptr)
|
||||
}
|
||||
}
|
||||
@ -223,8 +228,10 @@ impl Object {
|
||||
name: Local<Name>,
|
||||
getter: impl for<'s> MapFnTo<AccessorNameGetterCallback<'s>>,
|
||||
) -> Option<bool> {
|
||||
unsafe { v8__Object__SetAccessor(self, context, name, getter.map_fn_to()) }
|
||||
.into()
|
||||
unsafe {
|
||||
v8__Object__SetAccessor(self, &*context, &*name, getter.map_fn_to())
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Returns the identity hash for this object. The current implementation
|
||||
@ -267,10 +274,11 @@ impl Array {
|
||||
if elements.is_empty() {
|
||||
return Self::new(scope, 0);
|
||||
}
|
||||
let elements = Local::slice_into_raw(elements);
|
||||
let ptr = unsafe {
|
||||
v8__Array__New_with_elements(
|
||||
scope.isolate(),
|
||||
&elements[0],
|
||||
elements.as_ptr(),
|
||||
elements.len(),
|
||||
)
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ extern "C" {
|
||||
// TODO: move this to libplatform.rs?
|
||||
fn v8__platform__NewDefaultPlatform() -> *mut Platform;
|
||||
|
||||
fn v8__Platform__DELETE(this: &'static mut Platform) -> ();
|
||||
fn v8__Platform__DELETE(this: *mut Platform) -> ();
|
||||
}
|
||||
|
||||
pub fn new_default_platform() -> UniquePtr<Platform> {
|
||||
|
@ -15,9 +15,9 @@ use crate::support::UniquePtr;
|
||||
// };
|
||||
|
||||
extern "C" {
|
||||
fn v8__Task__BASE__CONSTRUCT(buf: &mut std::mem::MaybeUninit<Task>) -> ();
|
||||
fn v8__Task__DELETE(this: &'static mut Task) -> ();
|
||||
fn v8__Task__Run(this: &mut Task) -> ();
|
||||
fn v8__Task__BASE__CONSTRUCT(buf: *mut std::mem::MaybeUninit<Task>) -> ();
|
||||
fn v8__Task__DELETE(this: *mut Task) -> ();
|
||||
fn v8__Task__Run(this: *mut Task) -> ();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -10,22 +10,22 @@ extern "C" {
|
||||
fn v8__PrimitiveArray__New(
|
||||
isolate: *mut Isolate,
|
||||
length: int,
|
||||
) -> *mut PrimitiveArray;
|
||||
) -> *const PrimitiveArray;
|
||||
|
||||
fn v8__PrimitiveArray__Length(this: &PrimitiveArray) -> int;
|
||||
fn v8__PrimitiveArray__Length(this: *const PrimitiveArray) -> int;
|
||||
|
||||
fn v8__PrimitiveArray__Set(
|
||||
this: &PrimitiveArray,
|
||||
this: *const PrimitiveArray,
|
||||
isolate: *mut Isolate,
|
||||
index: int,
|
||||
item: &Primitive,
|
||||
item: *const Primitive,
|
||||
);
|
||||
|
||||
fn v8__PrimitiveArray__Get(
|
||||
this: &PrimitiveArray,
|
||||
this: *const PrimitiveArray,
|
||||
isolate: *mut Isolate,
|
||||
index: int,
|
||||
) -> *mut Primitive;
|
||||
) -> *const Primitive;
|
||||
}
|
||||
|
||||
impl PrimitiveArray {
|
||||
@ -49,7 +49,7 @@ impl PrimitiveArray {
|
||||
item: Local<'_, Primitive>,
|
||||
) {
|
||||
unsafe {
|
||||
v8__PrimitiveArray__Set(self, scope.isolate(), index as int, &item)
|
||||
v8__PrimitiveArray__Set(self, scope.isolate(), index as int, &*item)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,10 @@ use crate::Primitive;
|
||||
use crate::ToLocal;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Null(isolate: *mut Isolate) -> *mut Primitive;
|
||||
fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive;
|
||||
fn v8__Null(isolate: *mut Isolate) -> *const Primitive;
|
||||
fn v8__Undefined(isolate: *mut Isolate) -> *const Primitive;
|
||||
|
||||
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *mut Boolean;
|
||||
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *const Boolean;
|
||||
}
|
||||
|
||||
pub fn null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> {
|
||||
|
148
src/promise.rs
148
src/promise.rs
@ -10,48 +10,50 @@ use crate::ToLocal;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Promise__Resolver__New(context: *mut Context) -> *mut PromiseResolver;
|
||||
fn v8__Promise__Resolver__New(
|
||||
context: *const Context,
|
||||
) -> *const PromiseResolver;
|
||||
fn v8__Promise__Resolver__GetPromise(
|
||||
resolver: *mut PromiseResolver,
|
||||
) -> *mut Promise;
|
||||
this: *const PromiseResolver,
|
||||
) -> *const Promise;
|
||||
fn v8__Promise__Resolver__Resolve(
|
||||
resolver: *mut PromiseResolver,
|
||||
context: *mut Context,
|
||||
value: *mut Value,
|
||||
this: *const PromiseResolver,
|
||||
context: *const Context,
|
||||
value: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Promise__Resolver__Reject(
|
||||
resolver: *mut PromiseResolver,
|
||||
context: *mut Context,
|
||||
value: *mut Value,
|
||||
this: *const PromiseResolver,
|
||||
context: *const Context,
|
||||
value: *const Value,
|
||||
) -> MaybeBool;
|
||||
fn v8__Promise__State(promise: *mut Promise) -> PromiseState;
|
||||
fn v8__Promise__HasHandler(promise: *mut Promise) -> bool;
|
||||
fn v8__Promise__Result(promise: *mut Promise) -> *mut Value;
|
||||
fn v8__Promise__State(this: *const Promise) -> PromiseState;
|
||||
fn v8__Promise__HasHandler(this: *const Promise) -> bool;
|
||||
fn v8__Promise__Result(this: *const Promise) -> *const Value;
|
||||
fn v8__Promise__Catch(
|
||||
promise: *mut Promise,
|
||||
context: *mut Context,
|
||||
handler: *mut Function,
|
||||
) -> *mut Promise;
|
||||
this: *const Promise,
|
||||
context: *const Context,
|
||||
handler: *const Function,
|
||||
) -> *const Promise;
|
||||
fn v8__Promise__Then(
|
||||
promise: *mut Promise,
|
||||
context: *mut Context,
|
||||
handler: *mut Function,
|
||||
) -> *mut Promise;
|
||||
this: *const Promise,
|
||||
context: *const Context,
|
||||
handler: *const Function,
|
||||
) -> *const Promise;
|
||||
fn v8__Promise__Then2(
|
||||
promise: *mut Promise,
|
||||
context: *mut Context,
|
||||
on_fulfilled: *mut Function,
|
||||
on_rejected: *mut Function,
|
||||
) -> *mut Promise;
|
||||
this: *const Promise,
|
||||
context: *const Context,
|
||||
on_fulfilled: *const Function,
|
||||
on_rejected: *const Function,
|
||||
) -> *const Promise;
|
||||
|
||||
fn v8__PromiseRejectMessage__GetPromise(
|
||||
this: &PromiseRejectMessage,
|
||||
) -> *mut Promise;
|
||||
this: *const PromiseRejectMessage,
|
||||
) -> *const Promise;
|
||||
fn v8__PromiseRejectMessage__GetValue(
|
||||
this: &PromiseRejectMessage,
|
||||
) -> *mut Value;
|
||||
this: *const PromiseRejectMessage,
|
||||
) -> *const Value;
|
||||
fn v8__PromiseRejectMessage__GetEvent(
|
||||
this: &PromiseRejectMessage,
|
||||
this: *const PromiseRejectMessage,
|
||||
) -> PromiseRejectEvent;
|
||||
}
|
||||
|
||||
@ -65,57 +67,45 @@ pub enum PromiseState {
|
||||
|
||||
impl Promise {
|
||||
/// Returns the value of the [[PromiseState]] field.
|
||||
pub fn state(&mut self) -> PromiseState {
|
||||
unsafe { v8__Promise__State(&mut *self) }
|
||||
pub fn state(&self) -> PromiseState {
|
||||
unsafe { v8__Promise__State(&*self) }
|
||||
}
|
||||
|
||||
/// Returns true if the promise has at least one derived promise, and
|
||||
/// therefore resolve/reject handlers (including default handler).
|
||||
pub fn has_handler(&mut self) -> bool {
|
||||
unsafe { v8__Promise__HasHandler(&mut *self) }
|
||||
pub fn has_handler(&self) -> bool {
|
||||
unsafe { v8__Promise__HasHandler(&*self) }
|
||||
}
|
||||
|
||||
/// Returns the content of the [[PromiseResult]] field. The Promise must not
|
||||
/// be pending.
|
||||
pub fn result<'sc>(
|
||||
&mut self,
|
||||
&self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Local<'sc, Value> {
|
||||
unsafe { scope.to_local(v8__Promise__Result(&mut *self)) }.unwrap()
|
||||
unsafe { scope.to_local(v8__Promise__Result(&*self)) }.unwrap()
|
||||
}
|
||||
|
||||
/// Register a rejection handler with a promise.
|
||||
///
|
||||
/// See `Self::then2`.
|
||||
pub fn catch<'sc>(
|
||||
&mut self,
|
||||
mut context: Local<'sc, Context>,
|
||||
mut handler: Local<'sc, Function>,
|
||||
&self,
|
||||
context: Local<'sc, Context>,
|
||||
handler: Local<'sc, Function>,
|
||||
) -> Option<Local<'sc, Promise>> {
|
||||
unsafe {
|
||||
Local::from_raw(v8__Promise__Catch(
|
||||
&mut *self,
|
||||
&mut *context,
|
||||
&mut *handler,
|
||||
))
|
||||
}
|
||||
unsafe { Local::from_raw(v8__Promise__Catch(&*self, &*context, &*handler)) }
|
||||
}
|
||||
|
||||
/// Register a resolution handler with a promise.
|
||||
///
|
||||
/// See `Self::then2`.
|
||||
pub fn then<'sc>(
|
||||
&mut self,
|
||||
mut context: Local<'sc, Context>,
|
||||
mut handler: Local<'sc, Function>,
|
||||
&self,
|
||||
context: Local<'sc, Context>,
|
||||
handler: Local<'sc, Function>,
|
||||
) -> Option<Local<'sc, Promise>> {
|
||||
unsafe {
|
||||
Local::from_raw(v8__Promise__Then(
|
||||
&mut *self,
|
||||
&mut *context,
|
||||
&mut *handler,
|
||||
))
|
||||
}
|
||||
unsafe { Local::from_raw(v8__Promise__Then(&*self, &*context, &*handler)) }
|
||||
}
|
||||
|
||||
/// Register a resolution/rejection handler with a promise.
|
||||
@ -123,17 +113,17 @@ impl Promise {
|
||||
/// an argument. If the promise is already resolved/rejected, the handler is
|
||||
/// invoked at the end of turn.
|
||||
pub fn then2<'sc>(
|
||||
&mut self,
|
||||
mut context: Local<'sc, Context>,
|
||||
mut on_fulfilled: Local<'sc, Function>,
|
||||
mut on_rejected: Local<'sc, Function>,
|
||||
&self,
|
||||
context: Local<'sc, Context>,
|
||||
on_fulfilled: Local<'sc, Function>,
|
||||
on_rejected: Local<'sc, Function>,
|
||||
) -> Option<Local<'sc, Promise>> {
|
||||
unsafe {
|
||||
Local::from_raw(v8__Promise__Then2(
|
||||
&mut *self,
|
||||
&mut *context,
|
||||
&mut *on_fulfilled,
|
||||
&mut *on_rejected,
|
||||
&*self,
|
||||
&*context,
|
||||
&*on_fulfilled,
|
||||
&*on_rejected,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -143,44 +133,38 @@ impl PromiseResolver {
|
||||
/// Create a new resolver, along with an associated promise in pending state.
|
||||
pub fn new<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<'sc, Context>,
|
||||
context: Local<'sc, Context>,
|
||||
) -> Option<Local<'sc, PromiseResolver>> {
|
||||
unsafe { scope.to_local(v8__Promise__Resolver__New(&mut *context)) }
|
||||
unsafe { scope.to_local(v8__Promise__Resolver__New(&*context)) }
|
||||
}
|
||||
|
||||
/// Extract the associated promise.
|
||||
pub fn get_promise<'sc>(
|
||||
&mut self,
|
||||
&self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Local<'sc, Promise> {
|
||||
unsafe { scope.to_local(v8__Promise__Resolver__GetPromise(&mut *self)) }
|
||||
unsafe { scope.to_local(v8__Promise__Resolver__GetPromise(&*self)) }
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Resolve the associated promise with a given value.
|
||||
/// Ignored if the promise is no longer pending.
|
||||
pub fn resolve<'sc>(
|
||||
&mut self,
|
||||
mut context: Local<'sc, Context>,
|
||||
mut value: Local<'sc, Value>,
|
||||
&self,
|
||||
context: Local<'sc, Context>,
|
||||
value: Local<'sc, Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe {
|
||||
v8__Promise__Resolver__Resolve(&mut *self, &mut *context, &mut *value)
|
||||
.into()
|
||||
}
|
||||
unsafe { v8__Promise__Resolver__Resolve(&*self, &*context, &*value).into() }
|
||||
}
|
||||
|
||||
/// Reject the associated promise with a given value.
|
||||
/// Ignored if the promise is no longer pending.
|
||||
pub fn reject<'sc>(
|
||||
&mut self,
|
||||
mut context: Local<'sc, Context>,
|
||||
mut value: Local<'sc, Value>,
|
||||
&self,
|
||||
context: Local<'sc, Context>,
|
||||
value: Local<'sc, Value>,
|
||||
) -> Option<bool> {
|
||||
unsafe {
|
||||
v8__Promise__Resolver__Reject(&mut *self, &mut *context, &mut *value)
|
||||
.into()
|
||||
}
|
||||
unsafe { v8__Promise__Resolver__Reject(&*self, &*context, &*value).into() }
|
||||
}
|
||||
}
|
||||
|
||||
|
28
src/proxy.rs
28
src/proxy.rs
@ -7,25 +7,25 @@ use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Proxy__New(
|
||||
context: *mut Context,
|
||||
target: *mut Object,
|
||||
handler: *mut Object,
|
||||
) -> *mut Proxy;
|
||||
fn v8__Proxy__GetHandler(proxy: *mut Proxy) -> *mut Value;
|
||||
fn v8__Proxy__GetTarget(proxy: *mut Proxy) -> *mut Value;
|
||||
fn v8__Proxy__IsRevoked(proxy: *mut Proxy) -> bool;
|
||||
fn v8__Proxy__Revoke(proxy: *mut Proxy);
|
||||
context: *const Context,
|
||||
target: *const Object,
|
||||
handler: *const Object,
|
||||
) -> *const Proxy;
|
||||
fn v8__Proxy__GetHandler(this: *const Proxy) -> *const Value;
|
||||
fn v8__Proxy__GetTarget(this: *const Proxy) -> *const Value;
|
||||
fn v8__Proxy__IsRevoked(this: *const Proxy) -> bool;
|
||||
fn v8__Proxy__Revoke(this: *const Proxy);
|
||||
}
|
||||
|
||||
impl Proxy {
|
||||
pub fn new<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
mut target: Local<Object>,
|
||||
mut handler: Local<Object>,
|
||||
context: Local<Context>,
|
||||
target: Local<Object>,
|
||||
handler: Local<Object>,
|
||||
) -> Option<Local<'sc, Proxy>> {
|
||||
unsafe {
|
||||
let ptr = v8__Proxy__New(&mut *context, &mut *target, &mut *handler);
|
||||
let ptr = v8__Proxy__New(&*context, &*target, &*handler);
|
||||
scope.to_local(ptr)
|
||||
}
|
||||
}
|
||||
@ -34,14 +34,14 @@ impl Proxy {
|
||||
&mut self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Local<'sc, Value> {
|
||||
unsafe { scope.to_local(v8__Proxy__GetHandler(&mut *self)) }.unwrap()
|
||||
unsafe { scope.to_local(v8__Proxy__GetHandler(&*self)) }.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_target<'sc>(
|
||||
&mut self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Local<'sc, Value> {
|
||||
unsafe { scope.to_local(v8__Proxy__GetTarget(&mut *self)) }.unwrap()
|
||||
unsafe { scope.to_local(v8__Proxy__GetTarget(&*self)) }.unwrap()
|
||||
}
|
||||
|
||||
pub fn is_revoked(&mut self) -> bool {
|
||||
|
@ -18,18 +18,18 @@ pub(crate) mod internal {
|
||||
use super::*;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Context__GetIsolate(self_: &Context) -> *mut Isolate;
|
||||
fn v8__Context__GetIsolate(this: *const Context) -> *mut Isolate;
|
||||
fn v8__EscapableHandleScope__GetIsolate(
|
||||
self_: &EscapableHandleScope,
|
||||
this: &EscapableHandleScope,
|
||||
) -> *mut Isolate;
|
||||
fn v8__FunctionCallbackInfo__GetIsolate(
|
||||
self_: &FunctionCallbackInfo,
|
||||
this: &FunctionCallbackInfo,
|
||||
) -> *mut Isolate;
|
||||
fn v8__HandleScope__GetIsolate(self_: &HandleScope) -> *mut Isolate;
|
||||
fn v8__Message__GetIsolate(self_: &Message) -> *mut Isolate;
|
||||
fn v8__Object__GetIsolate(self_: &Object) -> *mut Isolate;
|
||||
fn v8__HandleScope__GetIsolate(this: &HandleScope) -> *mut Isolate;
|
||||
fn v8__Message__GetIsolate(this: *const Message) -> *mut Isolate;
|
||||
fn v8__Object__GetIsolate(this: *const Object) -> *mut Isolate;
|
||||
fn v8__PropertyCallbackInfo__GetIsolate(
|
||||
self_: &PropertyCallbackInfo,
|
||||
this: &PropertyCallbackInfo,
|
||||
) -> *mut Isolate;
|
||||
}
|
||||
|
||||
@ -142,16 +142,16 @@ where
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn v8__Isolate__GetCurrentContext(this: *mut Isolate) -> *mut Context;
|
||||
fn v8__Isolate__GetCurrentContext(isolate: *mut Isolate) -> *const Context;
|
||||
fn v8__Isolate__GetEnteredOrMicrotaskContext(
|
||||
this: *mut Isolate,
|
||||
) -> *mut Context;
|
||||
isolate: *mut Isolate,
|
||||
) -> *const Context;
|
||||
}
|
||||
|
||||
/// When scope implements this trait, this means that Local handles can be
|
||||
/// created inside it.
|
||||
pub trait ToLocal<'s>: InIsolate {
|
||||
unsafe fn to_local<T>(&mut self, ptr: *mut T) -> Option<Local<'s, T>> {
|
||||
unsafe fn to_local<T>(&mut self, ptr: *const T) -> Option<Local<'s, T>> {
|
||||
Local::from_raw(ptr)
|
||||
}
|
||||
|
||||
|
@ -17,23 +17,26 @@ pub struct ScriptOrigin<'sc>([usize; 7], PhantomData<&'sc ()>);
|
||||
|
||||
extern "C" {
|
||||
fn v8__Script__Compile(
|
||||
context: *mut Context,
|
||||
source: *mut String,
|
||||
context: *const Context,
|
||||
source: *const String,
|
||||
origin: *const ScriptOrigin,
|
||||
) -> *mut Script;
|
||||
fn v8__Script__Run(this: &mut Script, context: *mut Context) -> *mut Value;
|
||||
) -> *const Script;
|
||||
fn v8__Script__Run(
|
||||
script: *const Script,
|
||||
context: *const Context,
|
||||
) -> *const Value;
|
||||
|
||||
fn v8__ScriptOrigin__CONSTRUCT(
|
||||
buf: &mut MaybeUninit<ScriptOrigin>,
|
||||
resource_name: *mut Value,
|
||||
resource_line_offset: *mut Integer,
|
||||
resource_column_offset: *mut Integer,
|
||||
resource_is_shared_cross_origin: *mut Boolean,
|
||||
script_id: *mut Integer,
|
||||
source_map_url: *mut Value,
|
||||
resource_is_opaque: *mut Boolean,
|
||||
is_wasm: *mut Boolean,
|
||||
is_module: *mut Boolean,
|
||||
buf: *mut MaybeUninit<ScriptOrigin>,
|
||||
resource_name: *const Value,
|
||||
resource_line_offset: *const Integer,
|
||||
resource_column_offset: *const Integer,
|
||||
resource_is_shared_cross_origin: *const Boolean,
|
||||
script_id: *const Integer,
|
||||
source_map_url: *const Value,
|
||||
resource_is_opaque: *const Boolean,
|
||||
is_wasm: *const Boolean,
|
||||
is_module: *const Boolean,
|
||||
);
|
||||
}
|
||||
|
||||
@ -41,16 +44,14 @@ impl Script {
|
||||
/// A shorthand for ScriptCompiler::Compile().
|
||||
pub fn compile<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
mut source: Local<String>,
|
||||
context: Local<Context>,
|
||||
source: Local<String>,
|
||||
origin: Option<&ScriptOrigin>,
|
||||
) -> Option<Local<'sc, Script>> {
|
||||
// TODO: use the type system to enforce that a Context has been entered.
|
||||
// TODO: `context` and `source` probably shouldn't be mut.
|
||||
let ptr = unsafe {
|
||||
v8__Script__Compile(
|
||||
&mut *context,
|
||||
&mut *source,
|
||||
&*context,
|
||||
&*source,
|
||||
origin.map(|r| r as *const _).unwrap_or(null()),
|
||||
)
|
||||
};
|
||||
@ -63,9 +64,9 @@ impl Script {
|
||||
pub fn run<'sc>(
|
||||
&mut self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'sc, Value>> {
|
||||
unsafe { scope.to_local(v8__Script__Run(self, &mut *context)) }
|
||||
unsafe { scope.to_local(v8__Script__Run(self, &*context)) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,29 +74,29 @@ impl Script {
|
||||
impl<'sc> ScriptOrigin<'sc> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
mut resource_name: Local<'sc, Value>,
|
||||
mut resource_line_offset: Local<'sc, Integer>,
|
||||
mut resource_column_offset: Local<'sc, Integer>,
|
||||
mut resource_is_shared_cross_origin: Local<'sc, Boolean>,
|
||||
mut script_id: Local<'sc, Integer>,
|
||||
mut source_map_url: Local<'sc, Value>,
|
||||
mut resource_is_opaque: Local<'sc, Boolean>,
|
||||
mut is_wasm: Local<'sc, Boolean>,
|
||||
mut is_module: Local<'sc, Boolean>,
|
||||
resource_name: Local<'sc, Value>,
|
||||
resource_line_offset: Local<'sc, Integer>,
|
||||
resource_column_offset: Local<'sc, Integer>,
|
||||
resource_is_shared_cross_origin: Local<'sc, Boolean>,
|
||||
script_id: Local<'sc, Integer>,
|
||||
source_map_url: Local<'sc, Value>,
|
||||
resource_is_opaque: Local<'sc, Boolean>,
|
||||
is_wasm: Local<'sc, Boolean>,
|
||||
is_module: Local<'sc, Boolean>,
|
||||
) -> Self {
|
||||
unsafe {
|
||||
let mut buf = std::mem::MaybeUninit::<ScriptOrigin>::uninit();
|
||||
v8__ScriptOrigin__CONSTRUCT(
|
||||
&mut buf,
|
||||
&mut *resource_name,
|
||||
&mut *resource_line_offset,
|
||||
&mut *resource_column_offset,
|
||||
&mut *resource_is_shared_cross_origin,
|
||||
&mut *script_id,
|
||||
&mut *source_map_url,
|
||||
&mut *resource_is_opaque,
|
||||
&mut *is_wasm,
|
||||
&mut *is_module,
|
||||
&*resource_name,
|
||||
&*resource_line_offset,
|
||||
&*resource_column_offset,
|
||||
&*resource_is_shared_cross_origin,
|
||||
&*script_id,
|
||||
&*source_map_url,
|
||||
&*resource_is_opaque,
|
||||
&*is_wasm,
|
||||
&*is_module,
|
||||
);
|
||||
buf.assume_init()
|
||||
}
|
||||
|
@ -10,18 +10,18 @@ use std::mem::MaybeUninit;
|
||||
|
||||
extern "C" {
|
||||
fn v8__ScriptCompiler__Source__CONSTRUCT(
|
||||
buf: &mut MaybeUninit<Source>,
|
||||
source_string: &String,
|
||||
origin: &ScriptOrigin,
|
||||
buf: *mut MaybeUninit<Source>,
|
||||
source_string: *const String,
|
||||
origin: *const ScriptOrigin,
|
||||
);
|
||||
fn v8__ScriptCompiler__Source__DESTRUCT(this: &mut Source);
|
||||
fn v8__ScriptCompiler__Source__DESTRUCT(this: *mut Source);
|
||||
|
||||
fn v8__ScriptCompiler__CompileModule(
|
||||
isoate: &Isolate,
|
||||
source: &Source,
|
||||
isolate: *mut Isolate,
|
||||
source: *mut Source,
|
||||
options: CompileOptions,
|
||||
no_cache_reason: NoCacheReason,
|
||||
) -> *mut Module;
|
||||
) -> *const Module;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -33,7 +33,7 @@ impl Source {
|
||||
pub fn new(source_string: Local<String>, origin: &ScriptOrigin) -> Self {
|
||||
let mut buf = MaybeUninit::<Self>::uninit();
|
||||
unsafe {
|
||||
v8__ScriptCompiler__Source__CONSTRUCT(&mut buf, &source_string, origin);
|
||||
v8__ScriptCompiler__Source__CONSTRUCT(&mut buf, &*source_string, origin);
|
||||
buf.assume_init()
|
||||
}
|
||||
}
|
||||
@ -92,14 +92,14 @@ pub fn compile_module<'a>(
|
||||
/// Same as compile_module with more options.
|
||||
pub fn compile_module2<'a>(
|
||||
scope: &mut impl InIsolate,
|
||||
source: Source,
|
||||
mut source: Source,
|
||||
options: CompileOptions,
|
||||
no_cache_reason: NoCacheReason,
|
||||
) -> Option<Local<'a, Module>> {
|
||||
unsafe {
|
||||
Local::from_raw(v8__ScriptCompiler__CompileModule(
|
||||
scope.isolate(),
|
||||
&source,
|
||||
&mut source,
|
||||
options,
|
||||
no_cache_reason,
|
||||
))
|
||||
|
@ -5,11 +5,13 @@ use crate::ScriptOrModule;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__ScriptOrModule__GetResourceName(this: &ScriptOrModule) -> *mut Value;
|
||||
fn v8__ScriptOrModule__GetResourceName(
|
||||
this: *const ScriptOrModule,
|
||||
) -> *const Value;
|
||||
|
||||
fn v8__ScriptOrModule__GetHostDefinedOptions(
|
||||
this: &ScriptOrModule,
|
||||
) -> *mut PrimitiveArray;
|
||||
this: *const ScriptOrModule,
|
||||
) -> *const PrimitiveArray;
|
||||
}
|
||||
|
||||
impl ScriptOrModule {
|
||||
|
@ -18,16 +18,15 @@ extern "C" {
|
||||
fn v8__SharedArrayBuffer__New__with_byte_length(
|
||||
isolate: *mut Isolate,
|
||||
byte_length: usize,
|
||||
) -> *mut SharedArrayBuffer;
|
||||
) -> *const SharedArrayBuffer;
|
||||
fn v8__SharedArrayBuffer__New__with_backing_store(
|
||||
isolate: *mut Isolate,
|
||||
backing_store: *mut SharedRef<BackingStore>,
|
||||
) -> *mut SharedArrayBuffer;
|
||||
fn v8__SharedArrayBuffer__ByteLength(
|
||||
self_: *const SharedArrayBuffer,
|
||||
) -> usize;
|
||||
backing_store: *const SharedRef<BackingStore>,
|
||||
) -> *const SharedArrayBuffer;
|
||||
fn v8__SharedArrayBuffer__ByteLength(this: *const SharedArrayBuffer)
|
||||
-> usize;
|
||||
fn v8__SharedArrayBuffer__GetBackingStore(
|
||||
self_: *const SharedArrayBuffer,
|
||||
this: *const SharedArrayBuffer,
|
||||
) -> SharedRef<BackingStore>;
|
||||
fn v8__SharedArrayBuffer__NewBackingStore__with_byte_length(
|
||||
isolate: *mut Isolate,
|
||||
@ -60,14 +59,11 @@ impl SharedArrayBuffer {
|
||||
|
||||
pub fn with_backing_store<'sc>(
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
backing_store: &mut SharedRef<BackingStore>,
|
||||
backing_store: &SharedRef<BackingStore>,
|
||||
) -> Local<'sc, SharedArrayBuffer> {
|
||||
let isolate = scope.isolate();
|
||||
let ptr = unsafe {
|
||||
v8__SharedArrayBuffer__New__with_backing_store(
|
||||
isolate,
|
||||
&mut *backing_store,
|
||||
)
|
||||
v8__SharedArrayBuffer__New__with_backing_store(isolate, backing_store)
|
||||
};
|
||||
unsafe { scope.to_local(ptr) }.unwrap()
|
||||
}
|
||||
|
@ -13,20 +13,22 @@ use std::ops::DerefMut;
|
||||
|
||||
extern "C" {
|
||||
fn v8__SnapshotCreator__CONSTRUCT(
|
||||
buf: &mut MaybeUninit<SnapshotCreator>,
|
||||
buf: *mut MaybeUninit<SnapshotCreator>,
|
||||
external_references: *const intptr_t,
|
||||
);
|
||||
fn v8__SnapshotCreator__DESTRUCT(this: &mut SnapshotCreator);
|
||||
fn v8__SnapshotCreator__GetIsolate(this: &SnapshotCreator) -> &mut Isolate;
|
||||
fn v8__SnapshotCreator__DESTRUCT(this: *mut SnapshotCreator);
|
||||
fn v8__SnapshotCreator__GetIsolate(
|
||||
this: *mut SnapshotCreator,
|
||||
) -> *mut Isolate;
|
||||
fn v8__SnapshotCreator__CreateBlob(
|
||||
this: *mut SnapshotCreator,
|
||||
function_code_handling: FunctionCodeHandling,
|
||||
) -> OwnedStartupData;
|
||||
fn v8__SnapshotCreator__SetDefaultContext(
|
||||
this: &mut SnapshotCreator,
|
||||
context: *mut Context,
|
||||
this: *mut SnapshotCreator,
|
||||
context: *const Context,
|
||||
);
|
||||
fn v8__StartupData__DESTRUCT(this: &mut StartupData);
|
||||
fn v8__StartupData__DESTRUCT(this: *mut StartupData);
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -119,8 +121,8 @@ impl SnapshotCreator {
|
||||
/// Set the default context to be included in the snapshot blob.
|
||||
/// The snapshot will not contain the global proxy, and we expect one or a
|
||||
/// global object template to create one, to be provided upon deserialization.
|
||||
pub fn set_default_context<'sc>(&mut self, mut context: Local<'sc, Context>) {
|
||||
unsafe { v8__SnapshotCreator__SetDefaultContext(self, &mut *context) };
|
||||
pub fn set_default_context<'sc>(&mut self, context: Local<'sc, Context>) {
|
||||
unsafe { v8__SnapshotCreator__SetDefaultContext(self, &*context) };
|
||||
}
|
||||
|
||||
/// Creates a snapshot data blob.
|
||||
|
@ -12,21 +12,21 @@ use crate::String;
|
||||
use crate::ToLocal;
|
||||
|
||||
extern "C" {
|
||||
fn v8__String__Empty(isolate: *mut Isolate) -> *mut String;
|
||||
fn v8__String__Empty(isolate: *mut Isolate) -> *const String;
|
||||
|
||||
fn v8__String__NewFromUtf8(
|
||||
isolate: *mut Isolate,
|
||||
data: *const char,
|
||||
new_type: NewStringType,
|
||||
length: int,
|
||||
) -> *mut String;
|
||||
) -> *const String;
|
||||
|
||||
fn v8__String__Length(this: &String) -> int;
|
||||
fn v8__String__Length(this: *const String) -> int;
|
||||
|
||||
fn v8__String__Utf8Length(this: &String, isolate: *mut Isolate) -> int;
|
||||
fn v8__String__Utf8Length(this: *const String, isolate: *mut Isolate) -> int;
|
||||
|
||||
fn v8__String__WriteUtf8(
|
||||
this: &String,
|
||||
this: *const String,
|
||||
isolate: *mut Isolate,
|
||||
buffer: *mut char,
|
||||
length: int,
|
||||
|
@ -22,7 +22,7 @@ using uninit_t = typename std::aligned_storage<sizeof(T), alignof(T)>::type;
|
||||
template <class T, class... Args>
|
||||
class construct_in_place_helper {
|
||||
public:
|
||||
construct_in_place_helper(uninit_t<T>& buf, Args... args)
|
||||
construct_in_place_helper(uninit_t<T>* buf, Args... args)
|
||||
: inner_(std::forward<Args>(args)...) {}
|
||||
|
||||
private:
|
||||
@ -30,8 +30,8 @@ class construct_in_place_helper {
|
||||
};
|
||||
|
||||
template <class T, class... Args>
|
||||
void construct_in_place(uninit_t<T>& buf, Args... args) {
|
||||
new (&buf)
|
||||
void construct_in_place(uninit_t<T>* buf, Args... args) {
|
||||
new (buf)
|
||||
construct_in_place_helper<T, Args...>(buf, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -97,28 +97,37 @@ inline static T* local_to_ptr(v8::Local<T> local) {
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static v8::Local<T> ptr_to_local(T* ptr) {
|
||||
inline static const v8::Local<T> ptr_to_local(const T* ptr) {
|
||||
static_assert(sizeof(v8::Local<T>) == sizeof(T*), "");
|
||||
auto local = *reinterpret_cast<v8::Local<T>*>(&ptr);
|
||||
auto local = *reinterpret_cast<const v8::Local<T>*>(&ptr);
|
||||
assert(*local == ptr);
|
||||
return local;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static v8::Local<T>* const_ptr_array_to_local_array(
|
||||
const T* const ptr_array[]) {
|
||||
static_assert(sizeof(v8::Local<T>[42]) == sizeof(T* [42]), "");
|
||||
auto mut_ptr_array = const_cast<T**>(ptr_array);
|
||||
auto mut_local_array = reinterpret_cast<v8::Local<T>*>(mut_ptr_array);
|
||||
return mut_local_array;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static T* maybe_local_to_ptr(v8::MaybeLocal<T> local) {
|
||||
return *local.FromMaybe(v8::Local<T>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static v8::MaybeLocal<T> ptr_to_maybe_local(T* ptr) {
|
||||
inline static const v8::MaybeLocal<T> ptr_to_maybe_local(const T* ptr) {
|
||||
static_assert(sizeof(v8::MaybeLocal<T>) == sizeof(T*), "");
|
||||
return *reinterpret_cast<v8::MaybeLocal<T>*>(&ptr);
|
||||
return *reinterpret_cast<const v8::MaybeLocal<T>*>(&ptr);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline static v8::Global<T> ptr_to_global(T* ptr) {
|
||||
inline static v8::Global<T> ptr_to_global(const T* ptr) {
|
||||
v8::Global<T> global;
|
||||
std::swap(ptr, *reinterpret_cast<T**>(&global));
|
||||
std::swap(ptr, *reinterpret_cast<const T**>(&global));
|
||||
return global;
|
||||
}
|
||||
|
||||
|
@ -17,33 +17,33 @@ use crate::NONE;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Template__Set(
|
||||
self_: &Template,
|
||||
this: *const Template,
|
||||
key: *const Name,
|
||||
value: *const Data,
|
||||
attr: PropertyAttribute,
|
||||
);
|
||||
|
||||
fn v8__FunctionTemplate__New(
|
||||
isolate: &Isolate,
|
||||
isolate: *mut Isolate,
|
||||
callback: FunctionCallback,
|
||||
) -> *mut FunctionTemplate;
|
||||
) -> *const FunctionTemplate;
|
||||
fn v8__FunctionTemplate__GetFunction(
|
||||
fn_template: *mut FunctionTemplate,
|
||||
context: *mut Context,
|
||||
) -> *mut Function;
|
||||
this: *const FunctionTemplate,
|
||||
context: *const Context,
|
||||
) -> *const Function;
|
||||
fn v8__FunctionTemplate__SetClassName(
|
||||
fn_template: *mut FunctionTemplate,
|
||||
name: Local<String>,
|
||||
) -> *mut Function;
|
||||
this: *const FunctionTemplate,
|
||||
name: *const String,
|
||||
);
|
||||
|
||||
fn v8__ObjectTemplate__New(
|
||||
isolate: *mut Isolate,
|
||||
templ: *const FunctionTemplate,
|
||||
) -> *mut ObjectTemplate;
|
||||
) -> *const ObjectTemplate;
|
||||
fn v8__ObjectTemplate__NewInstance(
|
||||
self_: &ObjectTemplate,
|
||||
context: *mut Context,
|
||||
) -> *mut Object;
|
||||
this: *const ObjectTemplate,
|
||||
context: *const Context,
|
||||
) -> *const Object;
|
||||
}
|
||||
|
||||
impl Template {
|
||||
@ -80,11 +80,10 @@ impl FunctionTemplate {
|
||||
pub fn get_function<'sc>(
|
||||
&mut self,
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'sc, Function>> {
|
||||
unsafe {
|
||||
scope
|
||||
.to_local(v8__FunctionTemplate__GetFunction(&mut *self, &mut *context))
|
||||
scope.to_local(v8__FunctionTemplate__GetFunction(&*self, &*context))
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +91,7 @@ impl FunctionTemplate {
|
||||
/// printing objects created with the function created from the
|
||||
/// FunctionTemplate as its constructor.
|
||||
pub fn set_class_name(&mut self, name: Local<String>) {
|
||||
unsafe { v8__FunctionTemplate__SetClassName(&mut *self, name) };
|
||||
unsafe { v8__FunctionTemplate__SetClassName(&*self, &*name) };
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,9 +116,9 @@ impl ObjectTemplate {
|
||||
pub fn new_instance<'a>(
|
||||
&self,
|
||||
scope: &mut impl ToLocal<'a>,
|
||||
mut context: Local<Context>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'a, Object>> {
|
||||
let ptr = unsafe { v8__ObjectTemplate__NewInstance(self, &mut *context) };
|
||||
let ptr = unsafe { v8__ObjectTemplate__NewInstance(self, &*context) };
|
||||
unsafe { scope.to_local(ptr) }
|
||||
}
|
||||
}
|
||||
|
@ -16,36 +16,36 @@ extern "C" {
|
||||
// Note: the C++ CxxTryCatch object *must* live on the stack, and it must
|
||||
// not move after it is constructed.
|
||||
fn v8__TryCatch__CONSTRUCT(
|
||||
buf: &mut MaybeUninit<CxxTryCatch>,
|
||||
buf: *mut MaybeUninit<CxxTryCatch>,
|
||||
isolate: *mut Isolate,
|
||||
);
|
||||
|
||||
fn v8__TryCatch__DESTRUCT(this: &mut CxxTryCatch);
|
||||
fn v8__TryCatch__DESTRUCT(this: *mut CxxTryCatch);
|
||||
|
||||
fn v8__TryCatch__HasCaught(this: &CxxTryCatch) -> bool;
|
||||
fn v8__TryCatch__HasCaught(this: *const CxxTryCatch) -> bool;
|
||||
|
||||
fn v8__TryCatch__CanContinue(this: &CxxTryCatch) -> bool;
|
||||
fn v8__TryCatch__CanContinue(this: *const CxxTryCatch) -> bool;
|
||||
|
||||
fn v8__TryCatch__HasTerminated(this: &CxxTryCatch) -> bool;
|
||||
fn v8__TryCatch__HasTerminated(this: *const CxxTryCatch) -> bool;
|
||||
|
||||
fn v8__TryCatch__Exception(this: &CxxTryCatch) -> *mut Value;
|
||||
fn v8__TryCatch__Exception(this: *const CxxTryCatch) -> *const Value;
|
||||
|
||||
fn v8__TryCatch__StackTrace(
|
||||
this: &CxxTryCatch,
|
||||
context: Local<Context>,
|
||||
) -> *mut Value;
|
||||
this: *const CxxTryCatch,
|
||||
context: *const Context,
|
||||
) -> *const Value;
|
||||
|
||||
fn v8__TryCatch__Message(this: &CxxTryCatch) -> *mut Message;
|
||||
fn v8__TryCatch__Message(this: *const CxxTryCatch) -> *const Message;
|
||||
|
||||
fn v8__TryCatch__Reset(this: &mut CxxTryCatch);
|
||||
fn v8__TryCatch__Reset(this: *mut CxxTryCatch);
|
||||
|
||||
fn v8__TryCatch__ReThrow(this: &mut CxxTryCatch) -> *mut Value;
|
||||
fn v8__TryCatch__ReThrow(this: *mut CxxTryCatch) -> *const Value;
|
||||
|
||||
fn v8__TryCatch__IsVerbose(this: &CxxTryCatch) -> bool;
|
||||
fn v8__TryCatch__IsVerbose(this: *const CxxTryCatch) -> bool;
|
||||
|
||||
fn v8__TryCatch__SetVerbose(this: &mut CxxTryCatch, value: bool);
|
||||
fn v8__TryCatch__SetVerbose(this: *mut CxxTryCatch, value: bool);
|
||||
|
||||
fn v8__TryCatch__SetCaptureMessage(this: &mut CxxTryCatch, value: bool);
|
||||
fn v8__TryCatch__SetCaptureMessage(this: *mut CxxTryCatch, value: bool);
|
||||
}
|
||||
|
||||
// Note: the 'tc lifetime is there to ensure that after entering a TryCatchScope
|
||||
@ -122,7 +122,7 @@ impl<'tc> TryCatch<'tc> {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
context: Local<Context>,
|
||||
) -> Option<Local<'sc, Value>> {
|
||||
unsafe { scope.to_local(v8__TryCatch__StackTrace(&self.0, context)) }
|
||||
unsafe { scope.to_local(v8__TryCatch__StackTrace(&self.0, &*context)) }
|
||||
}
|
||||
|
||||
/// Returns the message associated with this exception. If there is
|
||||
|
@ -6,10 +6,10 @@ use crate::Uint8Array;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Uint8Array__New(
|
||||
buf: *mut ArrayBuffer,
|
||||
buf_ptr: *const ArrayBuffer,
|
||||
byte_offset: usize,
|
||||
length: usize,
|
||||
) -> *mut Uint8Array;
|
||||
) -> *const Uint8Array;
|
||||
}
|
||||
|
||||
impl Uint8Array {
|
||||
|
200
src/value.rs
200
src/value.rs
@ -12,97 +12,115 @@ use crate::Uint32;
|
||||
use crate::Value;
|
||||
|
||||
extern "C" {
|
||||
fn v8__Value__IsUndefined(this: &Value) -> bool;
|
||||
fn v8__Value__IsNull(this: &Value) -> bool;
|
||||
fn v8__Value__IsNullOrUndefined(this: &Value) -> bool;
|
||||
fn v8__Value__IsTrue(this: &Value) -> bool;
|
||||
fn v8__Value__IsFalse(this: &Value) -> bool;
|
||||
fn v8__Value__IsName(this: &Value) -> bool;
|
||||
fn v8__Value__IsString(this: &Value) -> bool;
|
||||
fn v8__Value__IsSymbol(this: &Value) -> bool;
|
||||
fn v8__Value__IsFunction(this: &Value) -> bool;
|
||||
fn v8__Value__IsArray(this: &Value) -> bool;
|
||||
fn v8__Value__IsObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsBigInt(this: &Value) -> bool;
|
||||
fn v8__Value__IsBoolean(this: &Value) -> bool;
|
||||
fn v8__Value__IsNumber(this: &Value) -> bool;
|
||||
fn v8__Value__IsExternal(this: &Value) -> bool;
|
||||
fn v8__Value__IsInt32(this: &Value) -> bool;
|
||||
fn v8__Value__IsUint32(this: &Value) -> bool;
|
||||
fn v8__Value__IsDate(this: &Value) -> bool;
|
||||
fn v8__Value__IsArgumentsObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsBigIntObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsBooleanObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsNumberObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsStringObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsSymbolObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsNativeError(this: &Value) -> bool;
|
||||
fn v8__Value__IsRegExp(this: &Value) -> bool;
|
||||
fn v8__Value__IsAsyncFunction(this: &Value) -> bool;
|
||||
fn v8__Value__IsGeneratorFunction(this: &Value) -> bool;
|
||||
fn v8__Value__IsGeneratorObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsPromise(this: &Value) -> bool;
|
||||
fn v8__Value__IsMap(this: &Value) -> bool;
|
||||
fn v8__Value__IsSet(this: &Value) -> bool;
|
||||
fn v8__Value__IsMapIterator(this: &Value) -> bool;
|
||||
fn v8__Value__IsSetIterator(this: &Value) -> bool;
|
||||
fn v8__Value__IsWeakMap(this: &Value) -> bool;
|
||||
fn v8__Value__IsWeakSet(this: &Value) -> bool;
|
||||
fn v8__Value__IsArrayBuffer(this: &Value) -> bool;
|
||||
fn v8__Value__IsArrayBufferView(this: &Value) -> bool;
|
||||
fn v8__Value__IsTypedArray(this: &Value) -> bool;
|
||||
fn v8__Value__IsUint8Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsUint8ClampedArray(this: &Value) -> bool;
|
||||
fn v8__Value__IsInt8Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsUint16Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsInt16Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsUint32Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsInt32Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsFloat32Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsFloat64Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsBigInt64Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsBigUint64Array(this: &Value) -> bool;
|
||||
fn v8__Value__IsDataView(this: &Value) -> bool;
|
||||
fn v8__Value__IsSharedArrayBuffer(this: &Value) -> bool;
|
||||
fn v8__Value__IsProxy(this: &Value) -> bool;
|
||||
fn v8__Value__IsWasmModuleObject(this: &Value) -> bool;
|
||||
fn v8__Value__IsModuleNamespaceObject(this: &Value) -> bool;
|
||||
fn v8__Value__StrictEquals(this: &Value, that: &Value) -> bool;
|
||||
fn v8__Value__SameValue(this: &Value, that: &Value) -> bool;
|
||||
fn v8__Value__IsUndefined(this: *const Value) -> bool;
|
||||
fn v8__Value__IsNull(this: *const Value) -> bool;
|
||||
fn v8__Value__IsNullOrUndefined(this: *const Value) -> bool;
|
||||
fn v8__Value__IsTrue(this: *const Value) -> bool;
|
||||
fn v8__Value__IsFalse(this: *const Value) -> bool;
|
||||
fn v8__Value__IsName(this: *const Value) -> bool;
|
||||
fn v8__Value__IsString(this: *const Value) -> bool;
|
||||
fn v8__Value__IsSymbol(this: *const Value) -> bool;
|
||||
fn v8__Value__IsFunction(this: *const Value) -> bool;
|
||||
fn v8__Value__IsArray(this: *const Value) -> bool;
|
||||
fn v8__Value__IsObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsBigInt(this: *const Value) -> bool;
|
||||
fn v8__Value__IsBoolean(this: *const Value) -> bool;
|
||||
fn v8__Value__IsNumber(this: *const Value) -> bool;
|
||||
fn v8__Value__IsExternal(this: *const Value) -> bool;
|
||||
fn v8__Value__IsInt32(this: *const Value) -> bool;
|
||||
fn v8__Value__IsUint32(this: *const Value) -> bool;
|
||||
fn v8__Value__IsDate(this: *const Value) -> bool;
|
||||
fn v8__Value__IsArgumentsObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsBigIntObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsBooleanObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsNumberObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsStringObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsSymbolObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsNativeError(this: *const Value) -> bool;
|
||||
fn v8__Value__IsRegExp(this: *const Value) -> bool;
|
||||
fn v8__Value__IsAsyncFunction(this: *const Value) -> bool;
|
||||
fn v8__Value__IsGeneratorFunction(this: *const Value) -> bool;
|
||||
fn v8__Value__IsGeneratorObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsPromise(this: *const Value) -> bool;
|
||||
fn v8__Value__IsMap(this: *const Value) -> bool;
|
||||
fn v8__Value__IsSet(this: *const Value) -> bool;
|
||||
fn v8__Value__IsMapIterator(this: *const Value) -> bool;
|
||||
fn v8__Value__IsSetIterator(this: *const Value) -> bool;
|
||||
fn v8__Value__IsWeakMap(this: *const Value) -> bool;
|
||||
fn v8__Value__IsWeakSet(this: *const Value) -> bool;
|
||||
fn v8__Value__IsArrayBuffer(this: *const Value) -> bool;
|
||||
fn v8__Value__IsArrayBufferView(this: *const Value) -> bool;
|
||||
fn v8__Value__IsTypedArray(this: *const Value) -> bool;
|
||||
fn v8__Value__IsUint8Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsUint8ClampedArray(this: *const Value) -> bool;
|
||||
fn v8__Value__IsInt8Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsUint16Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsInt16Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsUint32Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsInt32Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsFloat32Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsFloat64Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsBigInt64Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsBigUint64Array(this: *const Value) -> bool;
|
||||
fn v8__Value__IsDataView(this: *const Value) -> bool;
|
||||
fn v8__Value__IsSharedArrayBuffer(this: *const Value) -> bool;
|
||||
fn v8__Value__IsProxy(this: *const Value) -> bool;
|
||||
fn v8__Value__IsWasmModuleObject(this: *const Value) -> bool;
|
||||
fn v8__Value__IsModuleNamespaceObject(this: *const Value) -> bool;
|
||||
fn v8__Value__StrictEquals(this: *const Value, that: *const Value) -> bool;
|
||||
fn v8__Value__SameValue(this: *const Value, that: *const Value) -> bool;
|
||||
|
||||
fn v8__Value__ToBigInt(this: &Value, context: Local<Context>) -> *mut BigInt;
|
||||
fn v8__Value__ToNumber(this: &Value, context: Local<Context>) -> *mut Number;
|
||||
fn v8__Value__ToString(this: &Value, context: Local<Context>) -> *mut String;
|
||||
fn v8__Value__ToBigInt(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const BigInt;
|
||||
fn v8__Value__ToNumber(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const Number;
|
||||
fn v8__Value__ToString(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const String;
|
||||
fn v8__Value__ToDetailString(
|
||||
this: &Value,
|
||||
context: Local<Context>,
|
||||
) -> *mut String;
|
||||
fn v8__Value__ToObject(this: &Value, context: Local<Context>) -> *mut Object;
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const String;
|
||||
fn v8__Value__ToObject(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const Object;
|
||||
fn v8__Value__ToInteger(
|
||||
this: &Value,
|
||||
context: Local<Context>,
|
||||
) -> *mut Integer;
|
||||
fn v8__Value__ToUint32(this: &Value, context: Local<Context>) -> *mut Uint32;
|
||||
fn v8__Value__ToInt32(this: &Value, context: Local<Context>) -> *mut Int32;
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const Integer;
|
||||
fn v8__Value__ToUint32(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const Uint32;
|
||||
fn v8__Value__ToInt32(
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
) -> *const Int32;
|
||||
|
||||
fn v8__Value__NumberValue(
|
||||
this: &Value,
|
||||
context: Local<Context>,
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
out: *mut Maybe<f64>,
|
||||
);
|
||||
fn v8__Value__IntegerValue(
|
||||
this: &Value,
|
||||
context: Local<Context>,
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
out: *mut Maybe<i64>,
|
||||
);
|
||||
fn v8__Value__Uint32Value(
|
||||
this: &Value,
|
||||
context: Local<Context>,
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
out: *mut Maybe<u32>,
|
||||
);
|
||||
fn v8__Value__Int32Value(
|
||||
this: &Value,
|
||||
context: Local<Context>,
|
||||
this: *const Value,
|
||||
context: *const Context,
|
||||
out: *mut Maybe<i32>,
|
||||
);
|
||||
}
|
||||
@ -394,11 +412,11 @@ impl Value {
|
||||
}
|
||||
|
||||
pub fn strict_equals<'sc>(&self, that: Local<'sc, Value>) -> bool {
|
||||
unsafe { v8__Value__StrictEquals(self, &that) }
|
||||
unsafe { v8__Value__StrictEquals(self, &*that) }
|
||||
}
|
||||
|
||||
pub fn same_value<'sc>(&self, that: Local<'sc, Value>) -> bool {
|
||||
unsafe { v8__Value__SameValue(self, &that) }
|
||||
unsafe { v8__Value__SameValue(self, &*that) }
|
||||
}
|
||||
|
||||
pub fn to_big_int<'sc>(
|
||||
@ -406,7 +424,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, BigInt>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToBigInt(self, context))
|
||||
Local::from_raw(v8__Value__ToBigInt(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -415,7 +433,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, Number>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToNumber(self, context))
|
||||
Local::from_raw(v8__Value__ToNumber(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -424,7 +442,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, String>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToString(self, context))
|
||||
Local::from_raw(v8__Value__ToString(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -433,7 +451,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, String>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToDetailString(self, context))
|
||||
Local::from_raw(v8__Value__ToDetailString(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -442,7 +460,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, Object>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToObject(self, context))
|
||||
Local::from_raw(v8__Value__ToObject(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -451,7 +469,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, Integer>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToInteger(self, context))
|
||||
Local::from_raw(v8__Value__ToInteger(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -460,7 +478,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, Uint32>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToUint32(self, context))
|
||||
Local::from_raw(v8__Value__ToUint32(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -469,7 +487,7 @@ impl Value {
|
||||
scope: &mut impl ToLocal<'sc>,
|
||||
) -> Option<Local<'sc, Int32>> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
Local::from_raw(v8__Value__ToInt32(self, context))
|
||||
Local::from_raw(v8__Value__ToInt32(self, &*context))
|
||||
})
|
||||
}
|
||||
|
||||
@ -479,7 +497,7 @@ impl Value {
|
||||
) -> Option<f64> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
let mut out = Maybe::<f64>::default();
|
||||
v8__Value__NumberValue(self, context, &mut out);
|
||||
v8__Value__NumberValue(self, &*context, &mut out);
|
||||
out.into()
|
||||
})
|
||||
}
|
||||
@ -490,7 +508,7 @@ impl Value {
|
||||
) -> Option<i64> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
let mut out = Maybe::<i64>::default();
|
||||
v8__Value__IntegerValue(self, context, &mut out);
|
||||
v8__Value__IntegerValue(self, &*context, &mut out);
|
||||
out.into()
|
||||
})
|
||||
}
|
||||
@ -501,7 +519,7 @@ impl Value {
|
||||
) -> Option<u32> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
let mut out = Maybe::<u32>::default();
|
||||
v8__Value__Uint32Value(self, context, &mut out);
|
||||
v8__Value__Uint32Value(self, &*context, &mut out);
|
||||
out.into()
|
||||
})
|
||||
}
|
||||
@ -509,7 +527,7 @@ impl Value {
|
||||
pub fn int32_value<'sc>(&self, scope: &mut impl ToLocal<'sc>) -> Option<i32> {
|
||||
scope.get_current_context().and_then(|context| unsafe {
|
||||
let mut out = Maybe::<i32>::default();
|
||||
v8__Value__Int32Value(self, context, &mut out);
|
||||
v8__Value__Int32Value(self, &*context, &mut out);
|
||||
out.into()
|
||||
})
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ fn microtasks() {
|
||||
fn get_isolate_from_handle() {
|
||||
extern "C" {
|
||||
fn v8__internal__GetIsolateFromHeapObject(
|
||||
handle: *const v8::Data,
|
||||
location: *const v8::Data,
|
||||
) -> *mut v8::Isolate;
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ fn array_buffer() {
|
||||
assert_eq!(unique_bs[0], 0);
|
||||
assert_eq!(unique_bs[9], 9);
|
||||
|
||||
let mut shared_bs_1 = unique_bs.make_shared();
|
||||
let shared_bs_1 = unique_bs.make_shared();
|
||||
{
|
||||
let bs = unsafe { &mut *shared_bs_1.get() };
|
||||
assert_eq!(10, bs.byte_length());
|
||||
@ -407,7 +407,7 @@ fn array_buffer() {
|
||||
assert_eq!(bs[9], 9);
|
||||
}
|
||||
|
||||
let ab = v8::ArrayBuffer::with_backing_store(scope, &mut shared_bs_1);
|
||||
let ab = v8::ArrayBuffer::with_backing_store(scope, &shared_bs_1);
|
||||
let shared_bs_2 = ab.get_backing_store();
|
||||
{
|
||||
let bs = unsafe { &mut *shared_bs_2.get() };
|
||||
@ -471,7 +471,7 @@ fn array_buffer_with_shared_backing_store() {
|
||||
assert_eq!(3, v8::SharedRef::use_count(&bs1));
|
||||
assert_eq!(3, v8::SharedRef::use_count(&bs2));
|
||||
|
||||
let mut bs3 = ab1.get_backing_store();
|
||||
let bs3 = ab1.get_backing_store();
|
||||
assert_eq!(ab1.byte_length(), unsafe { (*bs3.get()).byte_length() });
|
||||
assert_eq!(4, v8::SharedRef::use_count(&bs1));
|
||||
assert_eq!(4, v8::SharedRef::use_count(&bs2));
|
||||
@ -484,7 +484,7 @@ fn array_buffer_with_shared_backing_store() {
|
||||
drop(bs1);
|
||||
assert_eq!(2, v8::SharedRef::use_count(&bs3));
|
||||
|
||||
let ab2 = v8::ArrayBuffer::with_backing_store(scope, &mut bs3);
|
||||
let ab2 = v8::ArrayBuffer::with_backing_store(scope, &bs3);
|
||||
assert_eq!(ab1.byte_length(), ab2.byte_length());
|
||||
assert_eq!(3, v8::SharedRef::use_count(&bs3));
|
||||
|
||||
@ -1325,8 +1325,8 @@ fn promise_resolved() {
|
||||
let scope = cs.enter();
|
||||
let maybe_resolver = v8::PromiseResolver::new(scope, context);
|
||||
assert!(maybe_resolver.is_some());
|
||||
let mut resolver = maybe_resolver.unwrap();
|
||||
let mut promise = resolver.get_promise(scope);
|
||||
let resolver = maybe_resolver.unwrap();
|
||||
let promise = resolver.get_promise(scope);
|
||||
assert!(!promise.has_handler());
|
||||
assert_eq!(promise.state(), v8::PromiseState::Pending);
|
||||
let value = v8::String::new(scope, "test").unwrap();
|
||||
@ -1359,8 +1359,8 @@ fn promise_rejected() {
|
||||
let scope = cs.enter();
|
||||
let maybe_resolver = v8::PromiseResolver::new(scope, context);
|
||||
assert!(maybe_resolver.is_some());
|
||||
let mut resolver = maybe_resolver.unwrap();
|
||||
let mut promise = resolver.get_promise(scope);
|
||||
let resolver = maybe_resolver.unwrap();
|
||||
let promise = resolver.get_promise(scope);
|
||||
assert!(!promise.has_handler());
|
||||
assert_eq!(promise.state(), v8::PromiseState::Pending);
|
||||
let value = v8::String::new(scope, "test").unwrap();
|
||||
@ -1512,7 +1512,7 @@ extern "C" fn promise_reject_callback(msg: v8::PromiseRejectMessage) {
|
||||
let scope = scope.enter();
|
||||
let event = msg.get_event();
|
||||
assert_eq!(event, v8::PromiseRejectEvent::PromiseRejectWithNoHandler);
|
||||
let mut promise = msg.get_promise();
|
||||
let promise = msg.get_promise();
|
||||
assert_eq!(promise.state(), v8::PromiseState::Rejected);
|
||||
let value = msg.get_value();
|
||||
{
|
||||
@ -1537,7 +1537,7 @@ fn set_promise_reject_callback() {
|
||||
let context = v8::Context::new(scope);
|
||||
let mut cs = v8::ContextScope::new(scope, context);
|
||||
let scope = cs.enter();
|
||||
let mut resolver = v8::PromiseResolver::new(scope, context).unwrap();
|
||||
let resolver = v8::PromiseResolver::new(scope, context).unwrap();
|
||||
let value = v8::String::new(scope, "promise rejected").unwrap();
|
||||
resolver.reject(context, value.into());
|
||||
}
|
||||
@ -2091,14 +2091,14 @@ fn shared_array_buffer() {
|
||||
assert_eq!(bs.byte_length(), 10);
|
||||
assert_eq!(bs.is_shared(), true);
|
||||
|
||||
let mut shared_bs_2 = bs.make_shared();
|
||||
let shared_bs_2 = bs.make_shared();
|
||||
{
|
||||
let bs = unsafe { &*shared_bs_2.get() };
|
||||
assert_eq!(bs.byte_length(), 10);
|
||||
assert_eq!(bs.is_shared(), true);
|
||||
}
|
||||
|
||||
let ab = v8::SharedArrayBuffer::with_backing_store(scope, &mut shared_bs_2);
|
||||
let ab = v8::SharedArrayBuffer::with_backing_store(scope, &shared_bs_2);
|
||||
let shared_bs_3 = ab.get_backing_store();
|
||||
{
|
||||
let bs = unsafe { &*shared_bs_3.get() };
|
||||
|
Loading…
Reference in New Issue
Block a user