This repository has been archived on 2026-09-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
OxideJS/crates/oxide_builtins/src/global.rs
T
爱特每羊队 2f8f1c3b71 feat: with 语句、成员位/移位复合赋值、CALL_NATIVE 无目标修复
with 语句:新增 emit 支持,with 体内自由标识符动态解析(对象属性优先,
回退外层),支持读/写/复合赋值/自增自减/delete/var 初始化动态化,
TO_OBJECT opcode 处理原始值对象,顶层 this 绑定全局对象。

复合赋值:新增 6 个 COMPOUND_MEMBER_BIT_* opcode 支持成员位/移位复合赋值,
修复 computed member 复合赋值覆盖 bug,with 内标识符复合赋值动态化。

CALL_NATIVE:实现全局 isNaN/isFinite 并绑定,用户覆盖 builtin 名时
回退通用调用路径而非报错,局部遮蔽 builtin 名走普通 CALL。

test262: with 34 pass(基线 0),compound-assignment 320 pass(基线 223)
2026-08-09 07:22:46 +08:00

43 lines
1.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use oxide_runtime_api::{NativeResult, VmHost};
use oxide_types::value::JsValue;
mod annex_b;
mod uri;
/// 全局函数模块:聚合 Annex B 的 `escape`/`unescape` 与 URI 处理函数
/// (`encodeURI`/`decodeURI`/`encodeURIComponent`/`decodeURIComponent`)。
pub use annex_b::{js_escape, js_unescape};
/// URI 编解码全局函数(`encodeURI`/`decodeURI` 等)。
pub use uri::{decode_uri, decode_uri_component, encode_uri, encode_uri_component};
/// `isNaN(x)`:ToNumber 后检查是否为 NaN(隐式类型转换)。
pub fn global_is_nan<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let n = if args.len() < 2 {
f64::NAN
} else {
oxide_runtime_api::to_number(vm.reg(args[1]))
};
NativeResult::Ok(JsValue::bool(n.is_nan()))
}
/// `isFinite(x)`:ToNumber 后检查是否为有限数(隐式类型转换)。
pub fn global_is_finite<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let n = if args.len() < 2 {
f64::NAN
} else {
oxide_runtime_api::to_number(vm.reg(args[1]))
};
NativeResult::Ok(JsValue::bool(n.is_finite()))
}
fn string_arg<H: VmHost>(vm: &mut H, args: &[u8]) -> String {
if args.len() > 1 {
oxide_runtime_api::to_string(vm.reg(args[1]))
} else {
"undefined".to_string()
}
}
fn parse_hex_u8(slice: &[u8]) -> Option<u8> {
std::str::from_utf8(slice).ok().and_then(|s| u8::from_str_radix(s, 16).ok())
}