From 09ee3f1dd7cd331bd6223029d41e4acbc712d976 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Fri, 5 Jun 2026 18:06:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=20JsObject=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E8=BE=85=E5=8A=A9=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/value.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/oxide_vm/src/value.rs b/crates/oxide_vm/src/value.rs index fbaf8425..8e718584 100644 --- a/crates/oxide_vm/src/value.rs +++ b/crates/oxide_vm/src/value.rs @@ -1,5 +1,7 @@ use std::fmt; +use crate::object::JsObject; + /// Quiet NaN prefix — bits 63-51 = sign(1) + exponent(0x7FF) + quiet_bit(1) const QNAN_PREFIX: u64 = 0xFFF8_0000_0000_0000; @@ -178,6 +180,17 @@ impl JsValue { (self.0 & PTR_MASK) as *mut u8 } + pub fn as_js_object_ptr(&self) -> *mut JsObject { + debug_assert!(self.is_object(), "JsValue is not an object"); + (self.0 & PTR_MASK) as *mut JsObject + } + + pub fn from_js_object(ptr: *mut JsObject) -> Self { + let addr = ptr as u64; + debug_assert!(addr <= PTR_MASK, "object pointer must fit in 48 bits"); + Self(make_tag(TAG_OBJECT) | addr) + } + pub fn as_string_index(&self) -> u32 { debug_assert!(self.is_string(), "JsValue is not a string"); (self.0 & STRING_INDEX_MASK) as u32