refactor: 用 Value::get/set 简化属性访问,消除直接 borrow/borrow_mut 调用

- Value::set 签名改为接受 &str 并返回 RuntimeError,与 evaluator 对齐
- eval_get/eval_set/eval_index_get/eval_index_set 中统一使用 get/set
- 去掉 eval_index_get 和 eval_index_set 中不再使用的 map 绑定

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
0264408
2026-06-17 15:05:59 +08:00
co-authored by Claude
parent bc74b5ee91
commit 9428e270af
2 changed files with 35 additions and 15 deletions
+22
View File
@@ -33,6 +33,28 @@ pub enum Signal {
Continue, // continue 信号
}
impl Value {
pub fn get(&self, key: &str) -> Option<Value> {
match self {
Value::Object(obj) => obj.borrow().get(key).cloned(),
_ => None,
}
}
pub fn set(&self, key: &str, val: Value) -> Result<(), crate::error::RuntimeError> {
match self {
Value::Object(obj) => {
obj.borrow_mut().insert(key.to_string(), val);
Ok(())
},
_ => Err(crate::error::RuntimeError::RuntimeError {
message: "Only objects have properties".to_string(),
token: None,
}),
}
}
}
impl std::fmt::Debug for Value {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {