mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 11:11:11 +08:00
5611d90ad0
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)
35 lines
1.4 KiB
Rust
35 lines
1.4 KiB
Rust
//! with 语句 emit:求值对象压入 with 作用域栈,动态解析体内自由标识符。
|
|
//!
|
|
//! with 自身不创建声明式作用域;body 为块时由块语句建立块作用域,
|
|
//! 块内 let/const/函数声明优先于 with 对象属性(对象环境在块环境外层)。
|
|
|
|
use crate::{CompileCtx, Emitter};
|
|
use oxide_bytecode::opcode::OpCode;
|
|
use oxide_ir::inst::Inst;
|
|
use oxide_ir::operand::Operand;
|
|
use oxide_parser::Statement;
|
|
|
|
impl Emitter {
|
|
fn emit_with_statement(&self, stmt: &Statement, ctx: &mut CompileCtx) -> Result<Option<u32>, String> {
|
|
let Statement::WithStatement(with) = stmt else {
|
|
return Ok(None);
|
|
};
|
|
|
|
// 求值 with 对象并 ToObject(对象环境记录要求);压入动态作用域栈,
|
|
// body 编译完成后弹出。
|
|
let obj_reg = self.emit_expression(&with.object, ctx)?;
|
|
ctx.inst(Inst::new(OpCode::TO_OBJECT, Operand::Reg(obj_reg), Operand::None, Operand::None));
|
|
ctx.push_with(obj_reg);
|
|
let result = self.emit_statement(&with.body, ctx)?;
|
|
ctx.pop_with();
|
|
Ok(result)
|
|
}
|
|
|
|
pub(crate) fn emit_with_domain(&self, stmt: &Statement, ctx: &mut CompileCtx) -> Result<Option<u32>, String> {
|
|
match stmt {
|
|
Statement::WithStatement(_) => self.emit_with_statement(stmt, ctx),
|
|
_ => Ok(None),
|
|
}
|
|
}
|
|
}
|