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