@@ -81,6 +81,7 @@ protected Object getInstanceIdValue(int id) {
8181 protected void fillConstructorProperties (IdFunctionObject ctor ) {
8282 addIdFunctionProperty (ctor , STRING_TAG , ConstructorId_fromCharCode , "fromCharCode" , 1 );
8383 addIdFunctionProperty (ctor , STRING_TAG , ConstructorId_fromCodePoint , "fromCodePoint" , 1 );
84+ addIdFunctionProperty (ctor , STRING_TAG , ConstructorId_raw , "raw" , 1 );
8485 addIdFunctionProperty (ctor , STRING_TAG , ConstructorId_charAt , "charAt" , 2 );
8586 addIdFunctionProperty (ctor , STRING_TAG , ConstructorId_charCodeAt , "charCodeAt" , 2 );
8687 addIdFunctionProperty (ctor , STRING_TAG , ConstructorId_indexOf , "indexOf" , 2 );
@@ -393,6 +394,9 @@ public Object execIdCall(
393394 return new String (chars );
394395 }
395396
397+ case ConstructorId_raw :
398+ return js_raw (cx , scope , args );
399+
396400 case Id_constructor :
397401 {
398402 CharSequence s ;
@@ -1106,6 +1110,47 @@ protected int findPrototypeId(Symbol k) {
11061110 return 0 ;
11071111 }
11081112
1113+ /**
1114+ *
1115+ *
1116+ * <h1>String.raw (template, ...substitutions)</h1>
1117+ *
1118+ * <p>22.1.2.4 String.raw [Draft ECMA-262 / April 28, 2021]
1119+ */
1120+ private static CharSequence js_raw (Context cx , Scriptable scope , Object [] args ) {
1121+ /* step 1-2 */
1122+ Object arg0 = args .length > 0 ? args [0 ] : Undefined .instance ;
1123+ Scriptable cooked = ScriptRuntime .toObject (cx , scope , arg0 );
1124+ /* step 3 */
1125+ Object rawValue = ScriptRuntime .getObjectProp (cooked , "raw" , cx );
1126+ Scriptable raw = ScriptRuntime .toObject (cx , scope , rawValue );
1127+ /* step 4-5 */
1128+ long rawLength = NativeArray .getLengthProperty (cx , raw );
1129+ if (rawLength > Integer .MAX_VALUE ) {
1130+ throw ScriptRuntime .rangeError ("raw.length > " + Integer .toString (Integer .MAX_VALUE ));
1131+ }
1132+ int literalSegments = (int ) rawLength ;
1133+ if (literalSegments <= 0 ) return "" ;
1134+ /* step 6-7 */
1135+ StringBuilder elements = new StringBuilder ();
1136+ int nextIndex = 0 ;
1137+ for (; ; ) {
1138+ /* step 8 a-i */
1139+ Object next ;
1140+ next = ScriptRuntime .getObjectIndex (raw , nextIndex , cx );
1141+ String nextSeg = ScriptRuntime .toString (next );
1142+ elements .append (nextSeg );
1143+ nextIndex += 1 ;
1144+ if (nextIndex == literalSegments ) {
1145+ break ;
1146+ }
1147+ next = args .length > nextIndex ? args [nextIndex ] : "" ;
1148+ String nextSub = ScriptRuntime .toString (next );
1149+ elements .append (nextSub );
1150+ }
1151+ return elements ;
1152+ }
1153+
11091154 // #string_id_map#
11101155
11111156 @ Override
@@ -1270,6 +1315,7 @@ protected int findPrototypeId(String s) {
12701315
12711316 private static final int ConstructorId_fromCharCode = -1 ,
12721317 ConstructorId_fromCodePoint = -2 ,
1318+ ConstructorId_raw = -3 ,
12731319 Id_constructor = 1 ,
12741320 Id_toString = 2 ,
12751321 Id_toSource = 3 ,
0 commit comments