6666import com .oracle .truffle .js .builtins .RegExpPrototypeBuiltinsFactory .JSRegExpExecES5NodeGen ;
6767import com .oracle .truffle .js .builtins .StringPrototypeBuiltinsFactory .CreateHTMLNodeGen ;
6868import com .oracle .truffle .js .builtins .StringPrototypeBuiltinsFactory .CreateStringIteratorNodeGen ;
69+ import com .oracle .truffle .js .builtins .StringPrototypeBuiltinsFactory .JSStringAtNodeGen ;
6970import com .oracle .truffle .js .builtins .StringPrototypeBuiltinsFactory .JSStringCharAtNodeGen ;
7071import com .oracle .truffle .js .builtins .StringPrototypeBuiltinsFactory .JSStringCharCodeAtNodeGen ;
7172import com .oracle .truffle .js .builtins .StringPrototypeBuiltinsFactory .JSStringCodePointAtNodeGen ;
@@ -193,7 +194,7 @@ public enum StringPrototype implements BuiltinEnum<StringPrototype> {
193194 sub (0 ),
194195 sup (0 ),
195196
196- // ES6
197+ // ES6/ES2015
197198 startsWith (1 ),
198199 endsWith (1 ),
199200 includes (1 ),
@@ -202,13 +203,18 @@ public enum StringPrototype implements BuiltinEnum<StringPrototype> {
202203 _iterator (0 ),
203204 normalize (0 ),
204205
205- // ES8
206+ // ES2017
206207 padStart (1 ),
207208 padEnd (1 ),
208209
209210 // ES2020
210211 matchAll (1 ),
211- replaceAll (2 );
212+
213+ // ES2021
214+ replaceAll (2 ),
215+
216+ // ES2022
217+ at (1 );
212218
213219 private final int length ;
214220
@@ -236,6 +242,8 @@ public int getECMAScriptVersion() {
236242 return JSConfig .ECMAScript2020 ;
237243 } else if (replaceAll == this ) {
238244 return JSConfig .ECMAScript2021 ;
245+ } else if (at == this ) {
246+ return JSConfig .ECMAScript2022 ;
239247 }
240248 return BuiltinEnum .super .getECMAScriptVersion ();
241249 }
@@ -364,6 +372,9 @@ protected Object createNode(JSContext context, JSBuiltin builtin, boolean constr
364372 return createHTMLNode (context , builtin , "sub" , "" );
365373 case sup :
366374 return createHTMLNode (context , builtin , "sup" , "" );
375+
376+ case at :
377+ return JSStringAtNodeGen .create (context , builtin , args ().withThis ().fixedArgs (1 ).createArgumentNodes (context ));
367378 }
368379 return null ;
369380 }
@@ -2862,4 +2873,22 @@ private String wrapInTagWithAttribute(String string, String attrVal) {
28622873 return "<" + tag + " " + attribute + "=\" " + escapedVal + "\" " + ">" + string + "</" + tag + ">" ;
28632874 }
28642875 }
2876+
2877+ public abstract static class JSStringAtNode extends JSStringOperation {
2878+ public JSStringAtNode (JSContext context , JSBuiltin builtin ) {
2879+ super (context , builtin );
2880+ }
2881+
2882+ @ Specialization
2883+ protected Object at (Object thisObj , Object index ) {
2884+ requireObjectCoercible (thisObj );
2885+ String thisStr = toString (thisObj );
2886+ int relativeIndex = toIntegerAsInt (index );
2887+ int k = (relativeIndex >= 0 ) ? relativeIndex : thisStr .length () + relativeIndex ;
2888+ if (k < 0 || k >= thisStr .length ()) {
2889+ return Undefined .instance ;
2890+ }
2891+ return String .valueOf (thisStr .charAt (k ));
2892+ }
2893+ }
28652894}
0 commit comments