mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 11:11:11 +08:00
fix: 补 Function 构造器残面与 TypedArray/Atomics 边
This commit is contained in:
@@ -425,7 +425,24 @@ pub fn atomics_wait_async<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
NativeResult::Ok(wait_async_result_object(vm, true, promise))
|
||||
}
|
||||
|
||||
/// `Atomics.pause(hint)`:零参语义(不校验、不延迟),任意实参形直返 undefined。
|
||||
pub fn atomics_pause<H: VmHost>(_vm: &mut H, _args: &[u8]) -> NativeResult {
|
||||
/// `Atomics.pause(hint)`:hint 为 undefined 或整数 Number 时直返 undefined;
|
||||
/// 其余值(布尔/串/BigInt/对象/非整数 Number 等)抛 TypeError。
|
||||
pub fn atomics_pause<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let hint = if args.len() > 1 { vm.reg(args[1]) } else { JsValue::undefined() };
|
||||
if hint.is_undefined() {
|
||||
return NativeResult::Ok(JsValue::undefined());
|
||||
}
|
||||
// hint 须为整数 Number:int 表示恒整数;double 表示须有限且无小数部分。
|
||||
let is_integral_number = if hint.is_int() {
|
||||
true
|
||||
} else if hint.is_double() {
|
||||
let v = hint.as_double();
|
||||
v.is_finite() && v.fract() == 0.0
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if !is_integral_number {
|
||||
return NativeResult::Err(crate::error::create_type_error(vm, "iterationNumber must be an integer"));
|
||||
}
|
||||
NativeResult::Ok(JsValue::undefined())
|
||||
}
|
||||
|
||||
@@ -342,6 +342,24 @@ fn bound_restricted_thrower<H: VmHost>(vm: &mut H, _args: &[u8]) -> NativeResult
|
||||
))
|
||||
}
|
||||
|
||||
/// %ThrowTypeError%:Function.prototype 的 caller/arguments 受限访问器共用。
|
||||
///
|
||||
/// 按接收者严格性分流:严格函数对象与 native 函数(含 Function.prototype 本身)
|
||||
/// 的 get/set 一律抛 TypeError;非严格函数对象读不抛、返回 undefined(写不抛、
|
||||
/// 丢弃写入),与规范"非严格函数 caller 可读"的残面一致。
|
||||
pub fn function_restricted_thrower<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
|
||||
let obj = match vm.checked_object_ptr(this_val, "restricted property access") {
|
||||
Ok(Some(obj)) => obj,
|
||||
Ok(None) => return NativeResult::Err(crate::error::create_type_error(vm, "restricted property access")),
|
||||
Err(e) => return NativeResult::Err(crate::error::create_type_error(vm, &e)),
|
||||
};
|
||||
if !vm.function_is_strict(unsafe { &*obj }) {
|
||||
return NativeResult::Ok(JsValue::undefined());
|
||||
}
|
||||
NativeResult::Err(crate::error::create_type_error(vm, "restricted property access"))
|
||||
}
|
||||
|
||||
/// `Function.prototype.toString`:返回 `function name() { [native code] }`
|
||||
/// 或 `[bytecode]` 形式;函数名取自 `name` 属性或字节码子模块名。
|
||||
pub fn function_to_string<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
|
||||
@@ -2699,6 +2699,11 @@ pub fn uint8array_set_from_base64<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeR
|
||||
let string = if args.len() > 1 { vm.reg(args[1]) } else { JsValue::undefined() };
|
||||
let options = if args.len() > 2 { vm.reg(args[2]) } else { JsValue::undefined() };
|
||||
let payload_ptr = native_try!(buffer_payload(vm, view.buffer));
|
||||
// 目标缓冲不可变(immutable):写前抛 TypeError(规范 ValidateUint8Array
|
||||
// 后的不可变守卫步)。
|
||||
if unsafe { (*payload_ptr).immutable } {
|
||||
return NativeResult::Err(type_error(vm, "ArrayBuffer is immutable"));
|
||||
}
|
||||
// SAFETY: payload_ptr 来自活动缓冲区对象(AB/SAB 双认),视图范围由构造保证界内。
|
||||
let Some(buffer) = unsafe { &mut *payload_ptr }.data.as_deref_mut() else {
|
||||
// buffer detach:按规范的视图校验步抛 TypeError;入口校验先行,
|
||||
@@ -2726,6 +2731,11 @@ pub fn uint8array_set_from_hex<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResu
|
||||
return NativeResult::Err(type_error(vm, "string argument required"));
|
||||
}
|
||||
let payload_ptr = native_try!(buffer_payload(vm, view.buffer));
|
||||
// 目标缓冲不可变(immutable):写前抛 TypeError(规范 ValidateUint8Array
|
||||
// 后的不可变守卫步)。
|
||||
if unsafe { (*payload_ptr).immutable } {
|
||||
return NativeResult::Err(type_error(vm, "ArrayBuffer is immutable"));
|
||||
}
|
||||
// SAFETY: payload_ptr 来自活动缓冲区对象(AB/SAB 双认),视图范围由构造保证界内。
|
||||
let Some(buffer) = unsafe { &mut *payload_ptr }.data.as_deref_mut() else {
|
||||
// buffer detach:按规范的视图校验步抛 TypeError;入口校验先行,
|
||||
|
||||
Reference in New Issue
Block a user