Skip to content

Commit

Permalink
feat, fix: enable running on 32 bits and several minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectLaugh committed Oct 6, 2022
1 parent 8f8636b commit 000ebfc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
22 changes: 14 additions & 8 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,18 @@ pub type PrepareStackTraceCallback<'s> = extern "C" fn(
) -> *mut *const Value;

// System V ABI: MaybeLocal<Value> returned in a register.
// System V i386 ABI: Local<Value> returned in hidden pointer (struct).
#[cfg(not(target_os = "windows"))]
pub type PrepareStackTraceCallback<'s> = extern "C" fn(
Local<'s, Context>,
Local<'s, Value>,
Local<'s, Array>,
) -> *const Value;
#[repr(C)]
pub struct PrepareStackTraceCallbackRet(*const Value);

#[cfg(not(target_os = "windows"))]
pub type PrepareStackTraceCallback<'s> =
extern "C" fn(
Local<'s, Context>,
Local<'s, Value>,
Local<'s, Array>,
) -> PrepareStackTraceCallbackRet;

extern "C" {
fn v8__Isolate__New(params: *const raw::CreateParams) -> *mut Isolate;
Expand Down Expand Up @@ -1228,13 +1234,13 @@ where
f.to_c_fn()
}

// System V ABI: MaybeLocal<Value> returned in a register.
// System V ABI
#[cfg(not(target_os = "windows"))]
fn mapping() -> Self {
let f = |context, error, sites| {
let mut scope: CallbackScope = unsafe { CallbackScope::new(context) };
let r = (F::get())(&mut scope, error, sites);
&*r as *const _
PrepareStackTraceCallbackRet(&*r as *const _)
};
f.to_c_fn()
}
Expand Down Expand Up @@ -1282,7 +1288,7 @@ impl BuildHasher for BuildTypeIdHasher {

const _: () = {
assert!(size_of::<TypeId>() == size_of::<u64>());
assert!(align_of::<TypeId>() == size_of::<u64>());
assert!(align_of::<TypeId>() == align_of::<u64>());
};

pub(crate) struct RawSlot {
Expand Down
41 changes: 28 additions & 13 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ use crate::Value;
/// }
/// ```

// System V AMD64 ABI: Local<Module> returned in a register.
// System V ABI
#[cfg(not(target_os = "windows"))]
#[repr(C)]
pub struct ResolveModuleCallbackRet(*const Module);

#[cfg(not(target_os = "windows"))]
pub type ResolveModuleCallback<'a> = extern "C" fn(
Local<'a, Context>,
Local<'a, String>,
Local<'a, FixedArray>,
Local<'a, Module>,
) -> *const Module;
) -> ResolveModuleCallbackRet;

// Windows x64 ABI: Local<Module> returned on the stack.
#[cfg(target_os = "windows")]
Expand All @@ -70,9 +74,11 @@ where
#[cfg(not(target_os = "windows"))]
fn mapping() -> Self {
let f = |context, specifier, import_assertions, referrer| {
(F::get())(context, specifier, import_assertions, referrer)
.map(|r| -> *const Module { &*r })
.unwrap_or(null())
ResolveModuleCallbackRet(
(F::get())(context, specifier, import_assertions, referrer)
.map(|r| -> *const Module { &*r })
.unwrap_or(null()),
)
};
f.to_c_fn()
}
Expand All @@ -90,10 +96,17 @@ where
}
}

// System V AMD64 ABI: Local<Value> returned in a register.
// System V ABI.
#[cfg(not(target_os = "windows"))]
#[repr(C)]
pub struct SyntheticModuleEvaluationStepsRet(*const Value);

#[cfg(not(target_os = "windows"))]
pub type SyntheticModuleEvaluationSteps<'a> =
extern "C" fn(Local<'a, Context>, Local<'a, Module>) -> *const Value;
extern "C" fn(
Local<'a, Context>,
Local<'a, Module>,
) -> SyntheticModuleEvaluationStepsRet;

// Windows x64 ABI: Local<Value> returned on the stack.
#[cfg(target_os = "windows")]
Expand All @@ -112,9 +125,11 @@ where
#[cfg(not(target_os = "windows"))]
fn mapping() -> Self {
let f = |context, module| {
(F::get())(context, module)
.map(|r| -> *const Value { &*r })
.unwrap_or(null())
SyntheticModuleEvaluationStepsRet(
(F::get())(context, module)
.map(|r| -> *const Value { &*r })
.unwrap_or(null()),
)
};
f.to_c_fn()
}
Expand All @@ -139,8 +154,8 @@ extern "C" {
fn v8__Module__SourceOffsetToLocation(
this: *const Module,
offset: int,
out: *mut MaybeUninit<Location>,
) -> Location;
out: *mut Location,
);
fn v8__Module__GetModuleNamespace(this: *const Module) -> *const Value;
fn v8__Module__GetIdentityHash(this: *const Module) -> int;
fn v8__Module__ScriptId(this: *const Module) -> int;
Expand Down Expand Up @@ -240,7 +255,7 @@ impl Module {
pub fn source_offset_to_location(&self, offset: int) -> Location {
let mut out = MaybeUninit::<Location>::uninit();
unsafe {
v8__Module__SourceOffsetToLocation(self, offset, &mut out);
v8__Module__SourceOffsetToLocation(self, offset, out.as_mut_ptr());
out.assume_init()
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4012,9 +4012,14 @@ fn typed_array_constructors() {
let t = v8::BigInt64Array::new(scope, ab, 0, 0).unwrap();
assert!(t.is_big_int64_array());

// TypedArray::max_length() ought to be >= 2^30 < 2^32
// TypedArray::max_length() ought to be >= 2^30 < 2^32 in 64 bits
#[cfg(target_pointer_width = "64")]
assert!(((2 << 30)..(2 << 32)).contains(&v8::TypedArray::max_length()));

// TypedArray::max_length() ought to be >= 2^28 < 2^30 in 32 bits
#[cfg(target_pointer_width = "32")]
assert!(((2 << 28)..(2 << 30)).contains(&v8::TypedArray::max_length()));

// v8::ArrayBuffer::new raises a fatal if the length is > kMaxLength, so we test this behavior
// through the JS side of things, where a non-fatal RangeError is thrown in such cases.
{
Expand Down

0 comments on commit 000ebfc

Please sign in to comment.