Phase 5: Complete destination pattern unification (28 sites, 53 lines)
Unified remaining destination write patterns with new helpers: - write_string() for VMValue::String writes - write_from_box() for VMValue::from_nyash_box() patterns Files updated: - boxes.rs: 8 sites unified (-14 lines) - boxes_plugin.rs: 9 sites unified (-17 lines) - boxes_object_fields.rs: 7 sites unified (-14 lines) - boxes_instance.rs: 2 sites unified (-4 lines) - calls.rs: 2 sites unified (-4 lines) - destination_helpers.rs: +28 lines (new helpers) Impact: 28 sites unified, net -25 lines, improved maintainability Tests: Phase 21.0 PASS (2/2, 100%) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -36,9 +36,7 @@ pub(super) fn invoke_plugin_box(
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some(d) = dst {
|
||||
this.regs.insert(d, VMValue::String(s));
|
||||
}
|
||||
this.write_string(dst, s);
|
||||
return Ok(());
|
||||
}
|
||||
let host = crate::runtime::plugin_loader_unified::get_global_plugin_host();
|
||||
@ -49,15 +47,11 @@ pub(super) fn invoke_plugin_box(
|
||||
}
|
||||
match host.invoke_instance_method(&p.box_type, method, p.inner.instance_id, &argv) {
|
||||
Ok(Some(ret)) => {
|
||||
if let Some(d) = dst {
|
||||
this.regs.insert(d, VMValue::from_nyash_box(ret));
|
||||
}
|
||||
this.write_from_box(dst, ret);
|
||||
Ok(())
|
||||
}
|
||||
Ok(None) => {
|
||||
if let Some(d) = dst {
|
||||
this.regs.insert(d, VMValue::Void);
|
||||
}
|
||||
this.write_void(dst);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => Err(this.err_with_context(
|
||||
@ -75,9 +69,7 @@ pub(super) fn invoke_plugin_box(
|
||||
if let Some(arg_id) = args.get(0) {
|
||||
let needle = this.reg_load(*arg_id)?.to_string();
|
||||
let result_box = string_box.lastIndexOf(&needle);
|
||||
if let Some(d) = dst {
|
||||
this.regs.insert(d, VMValue::from_nyash_box(result_box));
|
||||
}
|
||||
this.write_from_box(dst, result_box);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(this.err_invalid("lastIndexOf requires 1 argument"))
|
||||
@ -87,9 +79,7 @@ pub(super) fn invoke_plugin_box(
|
||||
if let Some(arg_id) = args.get(0) {
|
||||
let needle = this.reg_load(*arg_id)?.to_string();
|
||||
let result_box = string_box.find(&needle);
|
||||
if let Some(d) = dst {
|
||||
this.regs.insert(d, VMValue::from_nyash_box(result_box));
|
||||
}
|
||||
this.write_from_box(dst, result_box);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(this.err_invalid("indexOf/find requires 1 argument"))
|
||||
@ -122,15 +112,13 @@ pub(super) fn invoke_plugin_box(
|
||||
}
|
||||
// Generic toString fallback for any non-plugin box
|
||||
if method == "toString" {
|
||||
if let Some(d) = dst {
|
||||
// Map VoidBox.toString → "null" for JSON-friendly semantics
|
||||
let s = if recv_box.as_any().downcast_ref::<crate::box_trait::VoidBox>().is_some() {
|
||||
"null".to_string()
|
||||
} else {
|
||||
recv_box.to_string_box().value
|
||||
};
|
||||
this.regs.insert(d, VMValue::String(s));
|
||||
}
|
||||
// Map VoidBox.toString → "null" for JSON-friendly semantics
|
||||
let s = if recv_box.as_any().downcast_ref::<crate::box_trait::VoidBox>().is_some() {
|
||||
"null".to_string()
|
||||
} else {
|
||||
recv_box.to_string_box().value
|
||||
};
|
||||
this.write_string(dst, s);
|
||||
return Ok(());
|
||||
}
|
||||
// Minimal runtime fallback for common InstanceBox.is_eof when lowered function is not present.
|
||||
@ -167,7 +155,7 @@ pub(super) fn invoke_plugin_box(
|
||||
argv.push(this.reg_load(*a)?);
|
||||
}
|
||||
let ret = this.exec_function_inner(&func, Some(&argv))?;
|
||||
if let Some(d) = dst { this.regs.insert(d, ret); }
|
||||
this.write_result(dst, ret);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@ -175,7 +163,7 @@ pub(super) fn invoke_plugin_box(
|
||||
// when no class-specific handler is available. This avoids hard stops in JSON lint smokes
|
||||
// while builder rewrite and instance dispatch stabilize.
|
||||
if method == "current" && args.is_empty() {
|
||||
if let Some(d) = dst { this.regs.insert(d, VMValue::String(String::new())); }
|
||||
this.write_string(dst, String::new());
|
||||
return Ok(());
|
||||
}
|
||||
// VoidBox graceful handling for common container-like methods
|
||||
@ -187,7 +175,7 @@ pub(super) fn invoke_plugin_box(
|
||||
return Ok(());
|
||||
}
|
||||
"stringify" => {
|
||||
if let Some(d) = dst { this.regs.insert(d, VMValue::String("null".to_string())); }
|
||||
this.write_string(dst, "null".to_string());
|
||||
return Ok(());
|
||||
}
|
||||
"array_size" | "length" | "size" => {
|
||||
|
||||
Reference in New Issue
Block a user