@@ -52,6 +52,7 @@ use boa_ast::{
5252use boa_gc:: Gc ;
5353use boa_interner:: { Interner , Sym } ;
5454use boa_macros:: js_str;
55+ use boa_string:: StaticJsStrings ;
5556use rustc_hash:: FxHashMap ;
5657use thin_vec:: ThinVec ;
5758
@@ -921,7 +922,7 @@ impl<'ctx> ByteCompiler<'ctx> {
921922 fn emit_get_property_by_name (
922923 & mut self ,
923924 dst : & Register ,
924- receiver : & Register ,
925+ receiver : Option < & Register > ,
925926 value : & Register ,
926927 ident : Sym ,
927928 ) {
@@ -933,18 +934,32 @@ impl<'ctx> ByteCompiler<'ctx> {
933934 } ;
934935 self . ic . push ( InlineCache :: new ( name. clone ( ) ) ) ;
935936
936- self . bytecode . emit_get_property_by_name (
937- dst. variable ( ) ,
938- receiver. variable ( ) ,
939- value. variable ( ) ,
940- ic_index. into ( ) ,
941- ) ;
937+ if let Some ( receiver) = receiver {
938+ self . bytecode . emit_get_property_by_name_with_this (
939+ dst. variable ( ) ,
940+ receiver. variable ( ) ,
941+ value. variable ( ) ,
942+ ic_index. into ( ) ,
943+ ) ;
944+ } else if name == & StaticJsStrings :: LENGTH {
945+ self . bytecode . emit_get_length_property (
946+ dst. variable ( ) ,
947+ value. variable ( ) ,
948+ ic_index. into ( ) ,
949+ ) ;
950+ } else {
951+ self . bytecode . emit_get_property_by_name (
952+ dst. variable ( ) ,
953+ value. variable ( ) ,
954+ ic_index. into ( ) ,
955+ ) ;
956+ }
942957 }
943958
944959 fn emit_set_property_by_name (
945960 & mut self ,
946961 value : & Register ,
947- receiver : & Register ,
962+ receiver : Option < & Register > ,
948963 object : & Register ,
949964 ident : Sym ,
950965 ) {
@@ -956,12 +971,20 @@ impl<'ctx> ByteCompiler<'ctx> {
956971 } ;
957972 self . ic . push ( InlineCache :: new ( name. clone ( ) ) ) ;
958973
959- self . bytecode . emit_set_property_by_name (
960- value. variable ( ) ,
961- receiver. variable ( ) ,
962- object. variable ( ) ,
963- ic_index. into ( ) ,
964- ) ;
974+ if let Some ( receiver) = receiver {
975+ self . bytecode . emit_set_property_by_name_with_this (
976+ value. variable ( ) ,
977+ receiver. variable ( ) ,
978+ object. variable ( ) ,
979+ ic_index. into ( ) ,
980+ ) ;
981+ } else {
982+ self . bytecode . emit_set_property_by_name (
983+ value. variable ( ) ,
984+ object. variable ( ) ,
985+ ic_index. into ( ) ,
986+ ) ;
987+ }
965988 }
966989
967990 fn emit_type_error ( & mut self , message : & str ) {
@@ -1119,7 +1142,7 @@ impl<'ctx> ByteCompiler<'ctx> {
11191142
11201143 match access. field ( ) {
11211144 PropertyAccessField :: Const ( ident) => {
1122- compiler. emit_get_property_by_name ( dst, & object , & object, ident. sym ( ) ) ;
1145+ compiler. emit_get_property_by_name ( dst, None , & object, ident. sym ( ) ) ;
11231146 }
11241147 PropertyAccessField :: Expr ( expr) => {
11251148 let key = compiler. register_allocator . alloc ( ) ;
@@ -1157,7 +1180,12 @@ impl<'ctx> ByteCompiler<'ctx> {
11571180 compiler. bytecode . emit_this ( receiver. variable ( ) ) ;
11581181 match access. field ( ) {
11591182 PropertyAccessField :: Const ( ident) => {
1160- compiler. emit_get_property_by_name ( dst, & receiver, & value, ident. sym ( ) ) ;
1183+ compiler. emit_get_property_by_name (
1184+ dst,
1185+ Some ( & receiver) ,
1186+ & value,
1187+ ident. sym ( ) ,
1188+ ) ;
11611189 }
11621190 PropertyAccessField :: Expr ( expr) => {
11631191 let key = compiler. register_allocator . alloc ( ) ;
@@ -1222,7 +1250,7 @@ impl<'ctx> ByteCompiler<'ctx> {
12221250 let object = self . register_allocator . alloc ( ) ;
12231251 self . compile_expr ( access. target ( ) , & object) ;
12241252 let value = expr_fn ( self ) ;
1225- self . emit_set_property_by_name ( value, & object , & object, name. sym ( ) ) ;
1253+ self . emit_set_property_by_name ( value, None , & object, name. sym ( ) ) ;
12261254 self . register_allocator . dealloc ( object) ;
12271255 }
12281256 PropertyAccessField :: Expr ( expr) => {
@@ -1271,7 +1299,7 @@ impl<'ctx> ByteCompiler<'ctx> {
12711299
12721300 let value = expr_fn ( self ) ;
12731301
1274- self . emit_set_property_by_name ( value, & receiver, & object, name. sym ( ) ) ;
1302+ self . emit_set_property_by_name ( value, Some ( & receiver) , & object, name. sym ( ) ) ;
12751303
12761304 self . register_allocator . dealloc ( receiver) ;
12771305 self . register_allocator . dealloc ( object) ;
@@ -1393,7 +1421,7 @@ impl<'ctx> ByteCompiler<'ctx> {
13931421
13941422 match access. field ( ) {
13951423 PropertyAccessField :: Const ( ident) => {
1396- self . emit_get_property_by_name ( dst, this , this, ident. sym ( ) ) ;
1424+ self . emit_get_property_by_name ( dst, None , this, ident. sym ( ) ) ;
13971425 }
13981426 PropertyAccessField :: Expr ( field) => {
13991427 let key = self . register_allocator . alloc ( ) ;
@@ -1422,7 +1450,7 @@ impl<'ctx> ByteCompiler<'ctx> {
14221450
14231451 match access. field ( ) {
14241452 PropertyAccessField :: Const ( ident) => {
1425- self . emit_get_property_by_name ( dst, this, & object, ident. sym ( ) ) ;
1453+ self . emit_get_property_by_name ( dst, Some ( this) , & object, ident. sym ( ) ) ;
14261454 }
14271455 PropertyAccessField :: Expr ( expr) => {
14281456 let key = self . register_allocator . alloc ( ) ;
@@ -1525,7 +1553,7 @@ impl<'ctx> ByteCompiler<'ctx> {
15251553 self . bytecode . emit_move ( this. variable ( ) , value. variable ( ) ) ;
15261554 match field {
15271555 PropertyAccessField :: Const ( name) => {
1528- self . emit_get_property_by_name ( value, value , value, name. sym ( ) ) ;
1556+ self . emit_get_property_by_name ( value, None , value, name. sym ( ) ) ;
15291557 }
15301558 PropertyAccessField :: Expr ( expr) => {
15311559 let key = self . register_allocator . alloc ( ) ;
0 commit comments