@@ -6,7 +6,7 @@ use crate::{
66 js_array:: is_array,
77 js_class:: ClassDefinition ,
88 js_promise:: JSPromise ,
9- raise_type_error,
9+ raise_eval_error , raise_type_error,
1010} ;
1111
1212#[ derive( Clone , Debug ) ]
@@ -37,6 +37,13 @@ pub struct JSGenerator {
3737 pub state : GeneratorState ,
3838}
3939
40+ #[ derive( Clone , Debug ) ]
41+ pub struct JSProxy {
42+ pub target : Value , // The target object being proxied
43+ pub handler : Value , // The handler object with traps
44+ pub revoked : bool , // Whether this proxy has been revoked
45+ }
46+
4047#[ derive( Clone , Debug ) ]
4148pub enum GeneratorState {
4249 NotStarted ,
@@ -136,6 +143,7 @@ pub enum Value {
136143 WeakMap ( Rc < RefCell < JSWeakMap > > ) , // WeakMap object
137144 WeakSet ( Rc < RefCell < JSWeakSet > > ) , // WeakSet object
138145 Generator ( Rc < RefCell < JSGenerator > > ) , // Generator object
146+ Proxy ( Rc < RefCell < JSProxy > > ) , // Proxy object
139147}
140148
141149impl std:: fmt:: Debug for Value {
@@ -162,6 +170,7 @@ impl std::fmt::Debug for Value {
162170 Value :: WeakMap ( wm) => write ! ( f, "WeakMap({:p})" , Rc :: as_ptr( wm) ) ,
163171 Value :: WeakSet ( ws) => write ! ( f, "WeakSet({:p})" , Rc :: as_ptr( ws) ) ,
164172 Value :: Generator ( g) => write ! ( f, "Generator({:p})" , Rc :: as_ptr( g) ) ,
173+ Value :: Proxy ( p) => write ! ( f, "Proxy({:p})" , Rc :: as_ptr( p) ) ,
165174 }
166175 }
167176}
@@ -203,6 +212,7 @@ pub fn is_truthy(val: &Value) -> bool {
203212 Value :: WeakMap ( _) => true ,
204213 Value :: WeakSet ( _) => true ,
205214 Value :: Generator ( _) => true ,
215+ Value :: Proxy ( _) => true ,
206216 }
207217}
208218
@@ -247,6 +257,7 @@ pub fn value_to_string(val: &Value) -> String {
247257 Value :: WeakMap ( _) => "[object WeakMap]" . to_string ( ) ,
248258 Value :: WeakSet ( _) => "[object WeakSet]" . to_string ( ) ,
249259 Value :: Generator ( _) => "[object Generator]" . to_string ( ) ,
260+ Value :: Proxy ( _) => "[object Proxy]" . to_string ( ) ,
250261 }
251262}
252263
@@ -346,11 +357,19 @@ pub fn value_to_sort_string(val: &Value) -> String {
346357 Value :: WeakMap ( _) => "[object WeakMap]" . to_string ( ) ,
347358 Value :: WeakSet ( _) => "[object WeakSet]" . to_string ( ) ,
348359 Value :: Generator ( _) => "[object Generator]" . to_string ( ) ,
360+ Value :: Proxy ( _) => "[object Proxy]" . to_string ( ) ,
349361 }
350362}
351363
352364// Helper accessors for objects and environments
353365pub fn obj_get_value ( js_obj : & JSObjectDataPtr , key : & PropertyKey ) -> Result < Option < Rc < RefCell < Value > > > , JSError > {
366+ // Check if this object is a proxy wrapper
367+ if let Some ( proxy_val) = js_obj. borrow ( ) . get ( & "__proxy__" . into ( ) )
368+ && let Value :: Proxy ( proxy) = & * proxy_val. borrow ( )
369+ {
370+ return crate :: js_proxy:: proxy_get_property ( proxy, key) ;
371+ }
372+
354373 // Search own properties and then walk the prototype chain until we find
355374 // a matching property or run out of prototypes.
356375 let mut current: Option < JSObjectDataPtr > = Some ( js_obj. clone ( ) ) ;
@@ -690,6 +709,17 @@ pub fn obj_get_value(js_obj: &JSObjectDataPtr, key: &PropertyKey) -> Result<Opti
690709}
691710
692711pub fn obj_set_value ( js_obj : & JSObjectDataPtr , key : & PropertyKey , val : Value ) -> Result < ( ) , JSError > {
712+ // Check if this object is a proxy wrapper
713+ if let Some ( proxy_val) = js_obj. borrow ( ) . get ( & "__proxy__" . into ( ) )
714+ && let Value :: Proxy ( proxy) = & * proxy_val. borrow ( )
715+ {
716+ let success = crate :: js_proxy:: proxy_set_property ( proxy, key, val) ?;
717+ if !success {
718+ return Err ( raise_eval_error ! ( "Proxy set trap returned false" ) ) ;
719+ }
720+ return Ok ( ( ) ) ;
721+ }
722+
693723 // Check if there's a setter for this property
694724 let existing_opt = js_obj. borrow ( ) . get ( key) ;
695725 if let Some ( existing) = existing_opt {
@@ -731,9 +761,16 @@ pub fn obj_set_rc(map: &JSObjectDataPtr, key: &PropertyKey, val_rc: Rc<RefCell<V
731761 map. borrow_mut ( ) . insert ( key. clone ( ) , val_rc) ;
732762}
733763
734- pub fn obj_delete ( map : & JSObjectDataPtr , key : & PropertyKey ) -> bool {
764+ pub fn obj_delete ( map : & JSObjectDataPtr , key : & PropertyKey ) -> Result < bool , JSError > {
765+ // Check if this object is a proxy wrapper
766+ if let Some ( proxy_val) = map. borrow ( ) . get ( & "__proxy__" . into ( ) )
767+ && let Value :: Proxy ( proxy) = & * proxy_val. borrow ( )
768+ {
769+ return crate :: js_proxy:: proxy_delete_property ( proxy, key) ;
770+ }
771+
735772 map. borrow_mut ( ) . remove ( key) ;
736- true // In JavaScript, delete always returns true
773+ Ok ( true ) // In JavaScript, delete always returns true
737774}
738775
739776pub fn env_get < T : AsRef < str > > ( env : & JSObjectDataPtr , key : T ) -> Option < Rc < RefCell < Value > > > {
0 commit comments