0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-11 16:42:32 -05:00

Enable running on 32 bits and several minor fixes (#976)

This commit is contained in:
PerfectLaugh 2022-10-07 21:02:51 +08:00 committed by GitHub
parent 5635a82d40
commit 403d6c525d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 22 deletions

View file

@ -195,12 +195,18 @@ pub type PrepareStackTraceCallback<'s> = extern "C" fn(
) -> *mut *const Value; ) -> *mut *const Value;
// System V ABI: MaybeLocal<Value> returned in a register. // 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"))] #[cfg(not(target_os = "windows"))]
pub type PrepareStackTraceCallback<'s> = extern "C" fn( #[repr(C)]
pub struct PrepareStackTraceCallbackRet(*const Value);
#[cfg(not(target_os = "windows"))]
pub type PrepareStackTraceCallback<'s> =
extern "C" fn(
Local<'s, Context>, Local<'s, Context>,
Local<'s, Value>, Local<'s, Value>,
Local<'s, Array>, Local<'s, Array>,
) -> *const Value; ) -> PrepareStackTraceCallbackRet;
extern "C" { extern "C" {
fn v8__Isolate__New(params: *const raw::CreateParams) -> *mut Isolate; fn v8__Isolate__New(params: *const raw::CreateParams) -> *mut Isolate;
@ -1240,13 +1246,13 @@ where
f.to_c_fn() f.to_c_fn()
} }
// System V ABI: MaybeLocal<Value> returned in a register. // System V ABI
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
fn mapping() -> Self { fn mapping() -> Self {
let f = |context, error, sites| { let f = |context, error, sites| {
let mut scope: CallbackScope = unsafe { CallbackScope::new(context) }; let mut scope: CallbackScope = unsafe { CallbackScope::new(context) };
let r = (F::get())(&mut scope, error, sites); let r = (F::get())(&mut scope, error, sites);
&*r as *const _ PrepareStackTraceCallbackRet(&*r as *const _)
}; };
f.to_c_fn() f.to_c_fn()
} }
@ -1294,7 +1300,7 @@ impl BuildHasher for BuildTypeIdHasher {
const _: () = { const _: () = {
assert!(size_of::<TypeId>() == size_of::<u64>()); 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 { pub(crate) struct RawSlot {

View file

@ -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"))] #[cfg(not(target_os = "windows"))]
pub type ResolveModuleCallback<'a> = extern "C" fn( pub type ResolveModuleCallback<'a> = extern "C" fn(
Local<'a, Context>, Local<'a, Context>,
Local<'a, String>, Local<'a, String>,
Local<'a, FixedArray>, Local<'a, FixedArray>,
Local<'a, Module>, Local<'a, Module>,
) -> *const Module; ) -> ResolveModuleCallbackRet;
// Windows x64 ABI: Local<Module> returned on the stack. // Windows x64 ABI: Local<Module> returned on the stack.
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -70,9 +74,11 @@ where
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
fn mapping() -> Self { fn mapping() -> Self {
let f = |context, specifier, import_assertions, referrer| { let f = |context, specifier, import_assertions, referrer| {
ResolveModuleCallbackRet(
(F::get())(context, specifier, import_assertions, referrer) (F::get())(context, specifier, import_assertions, referrer)
.map(|r| -> *const Module { &*r }) .map(|r| -> *const Module { &*r })
.unwrap_or(null()) .unwrap_or(null()),
)
}; };
f.to_c_fn() f.to_c_fn()
} }
@ -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"))] #[cfg(not(target_os = "windows"))]
pub type SyntheticModuleEvaluationSteps<'a> = 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. // Windows x64 ABI: Local<Value> returned on the stack.
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -112,9 +125,11 @@ where
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
fn mapping() -> Self { fn mapping() -> Self {
let f = |context, module| { let f = |context, module| {
SyntheticModuleEvaluationStepsRet(
(F::get())(context, module) (F::get())(context, module)
.map(|r| -> *const Value { &*r }) .map(|r| -> *const Value { &*r })
.unwrap_or(null()) .unwrap_or(null()),
)
}; };
f.to_c_fn() f.to_c_fn()
} }
@ -139,8 +154,8 @@ extern "C" {
fn v8__Module__SourceOffsetToLocation( fn v8__Module__SourceOffsetToLocation(
this: *const Module, this: *const Module,
offset: int, offset: int,
out: *mut MaybeUninit<Location>, out: *mut Location,
) -> Location; );
fn v8__Module__GetModuleNamespace(this: *const Module) -> *const Value; fn v8__Module__GetModuleNamespace(this: *const Module) -> *const Value;
fn v8__Module__GetIdentityHash(this: *const Module) -> int; fn v8__Module__GetIdentityHash(this: *const Module) -> int;
fn v8__Module__ScriptId(this: *const Module) -> int; fn v8__Module__ScriptId(this: *const Module) -> int;
@ -240,7 +255,7 @@ impl Module {
pub fn source_offset_to_location(&self, offset: int) -> Location { pub fn source_offset_to_location(&self, offset: int) -> Location {
let mut out = MaybeUninit::<Location>::uninit(); let mut out = MaybeUninit::<Location>::uninit();
unsafe { unsafe {
v8__Module__SourceOffsetToLocation(self, offset, &mut out); v8__Module__SourceOffsetToLocation(self, offset, out.as_mut_ptr());
out.assume_init() out.assume_init()
} }
} }

View file

@ -4021,9 +4021,14 @@ fn typed_array_constructors() {
let t = v8::BigInt64Array::new(scope, ab, 0, 0).unwrap(); let t = v8::BigInt64Array::new(scope, ab, 0, 0).unwrap();
assert!(t.is_big_int64_array()); 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())); 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 // 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. // through the JS side of things, where a non-fatal RangeError is thrown in such cases.
{ {