shape_jit/ffi/call_method/result.rs
1// Heap allocation audit (PR-9 V8 Gap Closure):
2// Category A (NaN-boxed returns): 0 sites
3// Category B (intermediate/consumed): 0 sites
4// Category C (heap islands): 0 sites
5//!
6//! Result type method implementations for JIT
7
8use crate::nan_boxing::*;
9
10/// Call a method on a Result type (Ok/Err)
11#[inline(always)]
12pub fn call_result_method(receiver_bits: u64, method_name: &str, args: &[u64]) -> u64 {
13 match method_name {
14 "is_ok" => {
15 if is_ok_tag(receiver_bits) {
16 TAG_BOOL_TRUE
17 } else {
18 TAG_BOOL_FALSE
19 }
20 }
21 "is_err" => {
22 if is_err_tag(receiver_bits) {
23 TAG_BOOL_TRUE
24 } else {
25 TAG_BOOL_FALSE
26 }
27 }
28 "unwrap" => {
29 if is_ok_tag(receiver_bits) {
30 unsafe { unbox_result_inner(receiver_bits) }
31 } else {
32 // Calling unwrap on Err should probably panic in a real implementation
33 // For now, return NULL
34 TAG_NULL
35 }
36 }
37 "unwrap_err" => {
38 if is_err_tag(receiver_bits) {
39 unsafe { unbox_result_inner(receiver_bits) }
40 } else {
41 TAG_NULL
42 }
43 }
44 "unwrap_or" => {
45 if is_ok_tag(receiver_bits) {
46 unsafe { unbox_result_inner(receiver_bits) }
47 } else if !args.is_empty() {
48 args[0] // Return the default value
49 } else {
50 TAG_NULL
51 }
52 }
53 "unwrap_or_else" => {
54 // For now, same as unwrap_or - closure support would need more work
55 if is_ok_tag(receiver_bits) {
56 unsafe { unbox_result_inner(receiver_bits) }
57 } else if !args.is_empty() {
58 args[0]
59 } else {
60 TAG_NULL
61 }
62 }
63 "ok" => {
64 // Convert Result to Option - returns Some(value) if Ok, None if Err
65 // For now, just return the inner value or NULL
66 if is_ok_tag(receiver_bits) {
67 unsafe { unbox_result_inner(receiver_bits) }
68 } else {
69 TAG_NULL
70 }
71 }
72 "err" => {
73 // Convert Result to Option - returns Some(err) if Err, None if Ok
74 if is_err_tag(receiver_bits) {
75 unsafe { unbox_result_inner(receiver_bits) }
76 } else {
77 TAG_NULL
78 }
79 }
80 _ => TAG_NULL,
81 }
82}