Skip to main content

shape_jit/ffi/call_method/
object.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//! Object method implementations for JIT
7
8use crate::nan_boxing::*;
9use std::collections::HashMap;
10
11/// Call a method on an object value
12#[inline(always)]
13pub fn call_object_method(receiver_bits: u64, method_name: &str, args: &[u64]) -> u64 {
14    unsafe {
15        if !is_heap_kind(receiver_bits, HK_JIT_OBJECT) {
16            return TAG_NULL;
17        }
18        let obj = jit_unbox::<HashMap<String, u64>>(receiver_bits);
19
20        match method_name {
21            "hasOwnProperty" | "has" => {
22                if args.is_empty() {
23                    return TAG_BOOL_FALSE;
24                }
25                if is_heap_kind(args[0], HK_STRING) {
26                    let key = jit_unbox::<String>(args[0]);
27                    if obj.contains_key(key.as_str()) {
28                        return TAG_BOOL_TRUE;
29                    }
30                }
31                TAG_BOOL_FALSE
32            }
33            "length" | "len" => box_number(obj.len() as f64),
34            // RollingWindow methods
35            "mean" | "sum" | "min" | "max" | "std" => {
36                // Check if this is a RollingWindow object
37                if let Some(&type_bits) = obj.get("__type") {
38                    if is_heap_kind(type_bits, HK_STRING) {
39                        let type_str = jit_unbox::<String>(type_bits);
40                        if type_str == "RollingWindow" {
41                            // Get series and window
42                            let series_bits = obj.get("series").copied().unwrap_or(TAG_NULL);
43                            let window_bits = obj.get("window").copied().unwrap_or(TAG_NULL);
44
45                            if is_heap_kind(series_bits, HK_COLUMN_REF) && is_number(window_bits) {
46                                // TODO: Implement rolling methods using intrinsics (needs ExecutionContext)
47                                let _ = (series_bits, window_bits, method_name);
48                                return TAG_NULL;
49                            }
50                        }
51                    }
52                }
53                TAG_NULL
54            }
55            // BacktestResult-like object methods (stubbed - Series removed during Arrow migration)
56            "filter_by" => TAG_NULL,
57            "group_by_month" => TAG_NULL,
58            _ => TAG_NULL,
59        }
60    }
61}