From cc3c04216e7d3355598a3e94798e350e736a3670 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Fri, 14 Aug 2026 05:45:46 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E7=B1=BB=E7=BC=96=E8=AF=91=E6=96=AD?= =?UTF-8?q?=E8=A8=80=E6=9B=B4=E6=96=B0=E4=B8=BA=E6=96=B0=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E7=AC=A6=E5=AD=97=E8=8A=82=E7=A0=81=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oxide_compiler/tests/compile_expr_tests.rs | 6 ++++-- .../oxide_compiler/tests/compile_stmt_tests.rs | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/oxide_compiler/tests/compile_expr_tests.rs b/crates/oxide_compiler/tests/compile_expr_tests.rs index fead3e84..3f708c32 100644 --- a/crates/oxide_compiler/tests/compile_expr_tests.rs +++ b/crates/oxide_compiler/tests/compile_expr_tests.rs @@ -565,7 +565,7 @@ fn compile_class_expression_emits_constructor_value() { module .bytecode .iter() - .filter(|&&i| opcode::opcode(i) == OpCode::SET_PROP) + .filter(|&&i| opcode::opcode(i) == OpCode::DEFINE_PROP_ATTRS) .count() >= 3, "class expression should wire method/constructor/prototype properties" @@ -594,7 +594,9 @@ fn compile_large_pure_expression_reuses_temp_registers() { #[test] fn compile_builtin_globals_are_registered_lazily() { - let module = compile_source("Object; Array; Math; JSON"); + // 数组字面量内全部 4 个引用均为活代码(结果即脚本值),DCE 不可删; + // 未被引用的其它内置全局不得占用槽位。 + let module = compile_source("[Object, Array, Math, JSON]"); assert_eq!(module.builtin_reg_map.len(), 4, "only referenced builtins should allocate registers"); } diff --git a/crates/oxide_compiler/tests/compile_stmt_tests.rs b/crates/oxide_compiler/tests/compile_stmt_tests.rs index 8c0ed02d..47ce4ea3 100644 --- a/crates/oxide_compiler/tests/compile_stmt_tests.rs +++ b/crates/oxide_compiler/tests/compile_stmt_tests.rs @@ -277,7 +277,7 @@ fn compile_class_declaration_emits_constructor_and_prototype_setup() { module .bytecode .iter() - .filter(|&&i| opcode::opcode(i) == OpCode::SET_PROP) + .filter(|&&i| opcode::opcode(i) == OpCode::DEFINE_PROP_ATTRS) .count() >= 3, "class should assign method, constructor, and prototype properties" @@ -304,8 +304,11 @@ fn compile_class_declaration_default_constructor_creates_submodule() { fn compile_class_instance_getter_emits_define_accessor() { let module = compile_source("class A { get x() { return 1; } }"); assert!( - module.bytecode.iter().any(|&i| opcode::opcode(i) == OpCode::DEFINE_ACCESSOR), - "class getter should emit DEFINE_ACCESSOR" + module + .bytecode + .iter() + .any(|&i| opcode::opcode(i) == OpCode::DEFINE_ACCESSOR_ATTRS), + "class getter should emit DEFINE_ACCESSOR_ATTRS" ); } @@ -313,8 +316,11 @@ fn compile_class_instance_getter_emits_define_accessor() { fn compile_class_static_setter_emits_define_accessor() { let module = compile_source("class A { static set x(v) { this.y = v; } }"); assert!( - module.bytecode.iter().any(|&i| opcode::opcode(i) == OpCode::DEFINE_ACCESSOR), - "static class setter should emit DEFINE_ACCESSOR" + module + .bytecode + .iter() + .any(|&i| opcode::opcode(i) == OpCode::DEFINE_ACCESSOR_ATTRS), + "static class setter should emit DEFINE_ACCESSOR_ATTRS" ); }