feat: 增加 CreateClosure 字节码,函数字面量每次执行创建新闭包
This commit is contained in:
@@ -739,6 +739,20 @@ impl Vm {
|
||||
self.dispatch_load_const(rd, instr)?;
|
||||
}
|
||||
|
||||
OpCode::CREATE_CLOSURE => {
|
||||
let sub_idx = opcode::imm16(instr) as u32;
|
||||
debug_assert!(sub_idx > 0 && (sub_idx as usize) <= self.sub_modules.len());
|
||||
let sub = &self.sub_modules[sub_idx as usize - 1];
|
||||
let result = self.create_function_object(
|
||||
sub_idx,
|
||||
sub.is_arrow,
|
||||
sub.is_class_constructor,
|
||||
sub.is_derived_constructor,
|
||||
sub.needs_home_object,
|
||||
);
|
||||
self.regs[rd] = result;
|
||||
}
|
||||
|
||||
OpCode::ADD => {
|
||||
self.dispatch_add(rd, a, b)?;
|
||||
}
|
||||
|
||||
@@ -158,8 +158,7 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
|
||||
let global_ptr = self.session.global_object().as_ptr() as *mut JsObject;
|
||||
self.regs[254] = JsValue::from_js_object(global_ptr);
|
||||
self.regs[254] = JsValue::undefined();
|
||||
|
||||
self.dispatch()
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ impl Vm {
|
||||
/// Create a function JsObject for a BytecodeFunc constant.
|
||||
/// When `is_arrow` is true, captures the current `this` (regs[254])
|
||||
/// for lexical this binding at call time.
|
||||
fn create_function_object(
|
||||
pub(crate) fn create_function_object(
|
||||
&mut self, sub_idx: u32, is_arrow: bool, is_class_constructor: bool, is_derived_constructor: bool,
|
||||
needs_home_object: bool,
|
||||
) -> JsValue {
|
||||
|
||||
Reference in New Issue
Block a user