@@ -3929,6 +3929,12 @@ impl<'gc> VM<'gc> {
39293929 return Ok ( OpcodeAction :: Continue ) ;
39303930 }
39313931 let borrow = map. borrow ( ) ;
3932+ if matches ! ( borrow. get( "__realm_id__" ) , Some ( Value :: Number ( _) ) ) {
3933+ drop ( borrow) ;
3934+ let result = self . read_named_property ( ctx, & obj, & key) ;
3935+ self . stack . push ( result) ;
3936+ return Ok ( OpcodeAction :: Continue ) ;
3937+ }
39323938 // Check for getter first
39333939 let getter_key = format ! ( "__get_{}" , key) ;
39343940 if let Some ( Value :: VmFunction ( ip, _) | Value :: VmClosure ( ip, _, _) ) = borrow. get ( & getter_key) {
@@ -4484,9 +4490,7 @@ impl<'gc> VM<'gc> {
44844490 } else {
44854491 let proto = lookup ( "__proto__" ) ;
44864492 match key. as_str ( ) {
4487- "call" => Value :: VmNativeFunction ( BUILTIN_FN_CALL ) ,
4488- "apply" => Value :: VmNativeFunction ( BUILTIN_FN_APPLY ) ,
4489- "bind" => Value :: VmNativeFunction ( BUILTIN_FN_BIND ) ,
4493+ "call" | "apply" | "bind" => self . read_named_property ( ctx, & obj, & key) ,
44904494 "caller" | "arguments" => {
44914495 // %ThrowTypeError% accessor on Function.prototype
44924496 let err = self . make_type_error_object (
@@ -6333,177 +6337,7 @@ impl<'gc> VM<'gc> {
63336337 return Ok ( OpcodeAction :: Continue ) ;
63346338 }
63356339 let method = match & obj {
6336- Value :: VmObject ( map) => {
6337- let borrow = map. borrow ( ) ;
6338- let getter_key = format ! ( "__get_{}" , key) ;
6339- if let Some ( getter_fn) = borrow. get ( & getter_key) . cloned ( ) {
6340- drop ( borrow) ;
6341- self . invoke_getter_with_receiver ( ctx, & getter_fn, & obj)
6342- } else if let Some ( v) = borrow. get ( & key) . cloned ( ) {
6343- match v {
6344- Value :: Property { getter : Some ( g) , .. } => {
6345- drop ( borrow) ;
6346- self . invoke_getter_with_receiver ( ctx, & g, & obj)
6347- }
6348- other => other,
6349- }
6350- } else {
6351- let is_callable_obj = borrow. contains_key ( "__host_fn__" )
6352- || borrow. contains_key ( "__bound_target__" )
6353- || borrow. contains_key ( "__fn_body__" )
6354- || borrow. contains_key ( "__native_id__" ) ;
6355- if is_callable_obj {
6356- match key. as_str ( ) {
6357- "call" => {
6358- drop ( borrow) ;
6359- self . stack . push ( Value :: VmNativeFunction ( BUILTIN_FN_CALL ) ) ;
6360- return Ok ( OpcodeAction :: Continue ) ;
6361- }
6362- "apply" => {
6363- drop ( borrow) ;
6364- self . stack . push ( Value :: VmNativeFunction ( BUILTIN_FN_APPLY ) ) ;
6365- return Ok ( OpcodeAction :: Continue ) ;
6366- }
6367- "bind" => {
6368- drop ( borrow) ;
6369- self . stack . push ( Value :: VmNativeFunction ( BUILTIN_FN_BIND ) ) ;
6370- return Ok ( OpcodeAction :: Continue ) ;
6371- }
6372- _ => { }
6373- }
6374- }
6375- // Check WeakRef
6376- let is_weakref = borrow. contains_key ( "__weakref__" ) ;
6377- // Check typed wrapper methods first
6378- let type_name = borrow. get ( "__type__" ) . map ( |v| value_to_string ( v) ) ;
6379- let mut proto = borrow. get ( "__proto__" ) . cloned ( ) ;
6380- drop ( borrow) ;
6381- if proto. is_none ( )
6382- && let Some ( type_name) = type_name. as_deref ( )
6383- && let Some ( Value :: VmObject ( ctor) ) = self . globals . get ( type_name)
6384- && let Some ( type_proto) = ctor. borrow ( ) . get ( "prototype" ) . cloned ( )
6385- {
6386- proto = Some ( type_proto) ;
6387- }
6388- if matches ! ( type_name. as_deref( ) , Some ( "Boolean" ) )
6389- && let Some ( Value :: VmObject ( boolean_ctor) ) = self . globals . get ( "Boolean" )
6390- && let Some ( bool_proto) = boolean_ctor. borrow ( ) . get ( "prototype" ) . cloned ( )
6391- {
6392- proto = Some ( bool_proto) ;
6393- }
6394- if matches ! ( type_name. as_deref( ) , Some ( "String" ) )
6395- && let Some ( Value :: VmObject ( string_ctor) ) = self . globals . get ( "String" )
6396- && let Some ( string_proto) = string_ctor. borrow ( ) . get ( "prototype" ) . cloned ( )
6397- {
6398- proto = Some ( string_proto) ;
6399- }
6400- if is_weakref && key == "deref" {
6401- Value :: VmNativeFunction ( BUILTIN_WEAKREF_DEREF )
6402- } else {
6403- let typed_result = match type_name. as_deref ( ) {
6404- Some ( "Number" ) => match key. as_str ( ) {
6405- "toFixed" | "toExponential" | "toPrecision" | "toString" | "toLocaleString" | "valueOf" | "constructor" => {
6406- if let Some ( Value :: VmObject ( num_ctor) ) = self . globals . get ( "Number" )
6407- && let Some ( Value :: VmObject ( num_proto) ) = num_ctor. borrow ( ) . get ( "prototype" ) . cloned ( )
6408- {
6409- num_proto. borrow ( ) . get ( & key) . cloned ( )
6410- } else {
6411- None
6412- }
6413- }
6414- _ => None ,
6415- } ,
6416- Some ( "BigInt" ) => {
6417- // Check if BigInt.prototype has a getter override
6418- if let Some ( Value :: VmObject ( bi_ctor) ) = self . globals . get ( "BigInt" )
6419- && let Some ( Value :: VmObject ( bi_proto) ) = bi_ctor. borrow ( ) . get ( "prototype" ) . cloned ( )
6420- {
6421- let getter_key = format ! ( "__get_{}" , key) ;
6422- let bp = bi_proto. borrow ( ) ;
6423- if bp. contains_key ( & getter_key) || bp. contains_key ( & key) {
6424- drop ( bp) ;
6425- let val = self . read_named_property ( ctx, & Value :: VmObject ( bi_proto) , & key) ;
6426- Some ( val)
6427- } else {
6428- match key. as_str ( ) {
6429- "toString" => Some ( Value :: VmNativeFunction ( BUILTIN_BIGINT_TOSTRING ) ) ,
6430- "toLocaleString" => Some ( Value :: VmNativeFunction ( BUILTIN_BIGINT_TOLOCALESTRING ) ) ,
6431- "valueOf" => Some ( Value :: VmNativeFunction ( BUILTIN_BIGINT_VALUEOF ) ) ,
6432- "constructor" => bp. get ( & key) . cloned ( ) ,
6433- _ => None ,
6434- }
6435- }
6436- } else {
6437- match key. as_str ( ) {
6438- "toString" => Some ( Value :: VmNativeFunction ( BUILTIN_BIGINT_TOSTRING ) ) ,
6439- "toLocaleString" => Some ( Value :: VmNativeFunction ( BUILTIN_BIGINT_TOLOCALESTRING ) ) ,
6440- "valueOf" => Some ( Value :: VmNativeFunction ( BUILTIN_BIGINT_VALUEOF ) ) ,
6441- _ => None ,
6442- }
6443- }
6444- }
6445- Some ( "String" ) => match key. as_str ( ) {
6446- "toString" | "valueOf" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_VALUEOF ) ) ,
6447- "constructor" => self . globals . get ( "String" ) . cloned ( ) ,
6448- "length" => {
6449- let b = map. borrow ( ) ;
6450- match b. get ( "__value__" ) {
6451- Some ( Value :: String ( sv) ) => Some ( Value :: Number ( sv. len ( ) as f64 ) ) ,
6452- _ => Some ( Value :: Number ( 0.0 ) ) ,
6453- }
6454- }
6455- "split" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_SPLIT ) ) ,
6456- "indexOf" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_INDEXOF ) ) ,
6457- "slice" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_SLICE ) ) ,
6458- "toUpperCase" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_TOUPPERCASE ) ) ,
6459- "toLowerCase" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_TOLOWERCASE ) ) ,
6460- "trim" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_TRIM ) ) ,
6461- "charAt" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_CHARAT ) ) ,
6462- "includes" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_INCLUDES ) ) ,
6463- "replace" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_REPLACE ) ) ,
6464- "replaceAll" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_REPLACEALL ) ) ,
6465- "match" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_MATCH ) ) ,
6466- "search" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_SEARCH ) ) ,
6467- "startsWith" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_STARTSWITH ) ) ,
6468- "endsWith" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_ENDSWITH ) ) ,
6469- "substring" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_SUBSTRING ) ) ,
6470- "padStart" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_PADSTART ) ) ,
6471- "padEnd" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_PADEND ) ) ,
6472- "repeat" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_REPEAT ) ) ,
6473- "charCodeAt" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_CHARCODEAT ) ) ,
6474- "trimStart" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_TRIMSTART ) ) ,
6475- "trimEnd" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_TRIMEND ) ) ,
6476- "lastIndexOf" => Some ( Value :: VmNativeFunction ( BUILTIN_STRING_LASTINDEXOF ) ) ,
6477- _ => None ,
6478- } ,
6479- Some ( "Boolean" ) => {
6480- let effective_proto = proto. clone ( ) . or_else ( || {
6481- if let Some ( Value :: VmObject ( obj_global) ) = self . globals . get ( "Object" ) {
6482- obj_global. borrow ( ) . get ( "prototype" ) . cloned ( )
6483- } else {
6484- None
6485- }
6486- } ) ;
6487- if self . lookup_proto_chain ( effective_proto. as_ref ( ) , & key) . is_none ( ) {
6488- match key. as_str ( ) {
6489- "toString" => Some ( Self :: make_host_fn ( ctx, "boolean.toString" ) ) ,
6490- "valueOf" => Some ( Self :: make_host_fn ( ctx, "boolean.valueOf" ) ) ,
6491- _ => None ,
6492- }
6493- } else {
6494- None
6495- }
6496- }
6497- Some ( "RegExp" ) => match key. as_str ( ) {
6498- "toString" => Some ( Self :: make_bound_host_fn ( ctx, "regexp.toString" , & obj) ) ,
6499- _ => None ,
6500- } ,
6501- _ => None ,
6502- } ;
6503- typed_result. unwrap_or_else ( || self . read_named_property_with_receiver ( ctx, & obj, & key, & obj) )
6504- }
6505- }
6506- }
6340+ Value :: VmObject ( _) => self . read_named_property ( ctx, & obj, & key) ,
65076341 Value :: VmArray ( arr) => {
65086342 let borrow = arr. borrow ( ) ;
65096343 let is_generator = matches ! ( borrow. props. get( "__generator__" ) , Some ( Value :: Boolean ( true ) ) ) ;
@@ -6624,9 +6458,7 @@ impl<'gc> VM<'gc> {
66246458 } else {
66256459 let proto = lookup ( "__proto__" ) ;
66266460 match key. as_str ( ) {
6627- "call" => Value :: VmNativeFunction ( BUILTIN_FN_CALL ) ,
6628- "apply" => Value :: VmNativeFunction ( BUILTIN_FN_APPLY ) ,
6629- "bind" => Value :: VmNativeFunction ( BUILTIN_FN_BIND ) ,
6461+ "call" | "apply" | "bind" => self . read_named_property ( ctx, & obj, & key) ,
66306462 _ => self . lookup_proto_chain ( proto. as_ref ( ) , & key) . unwrap_or ( Value :: Undefined ) ,
66316463 }
66326464 }
0 commit comments