@@ -154,6 +154,7 @@ protected void fillConstructorProperties(IdFunctionObject ctor) {
154
154
addIdFunctionProperty (ctor , ARRAY_TAG , ConstructorId_isArray , "isArray" , 1 );
155
155
addIdFunctionProperty (ctor , ARRAY_TAG , ConstructorId_of , "of" , 0 );
156
156
addIdFunctionProperty (ctor , ARRAY_TAG , ConstructorId_from , "from" , 1 );
157
+ addIdFunctionProperty (ctor , ARRAY_TAG , ConstructorId_toReversed , "toReversed" , 0 );
157
158
super .fillConstructorProperties (ctor );
158
159
}
159
160
@@ -303,6 +304,10 @@ protected void initPrototypeId(int id) {
303
304
arity = 1 ;
304
305
s = "flatMap" ;
305
306
break ;
307
+ case Id_toReversed :
308
+ arity = 0 ;
309
+ s = "toReversed" ;
310
+ break ;
306
311
default :
307
312
throw new IllegalArgumentException (String .valueOf (id ));
308
313
}
@@ -341,7 +346,8 @@ public Object execIdCall(
341
346
case ConstructorId_findIndex :
342
347
case ConstructorId_reduce :
343
348
case ConstructorId_reduceRight :
344
- {
349
+ case ConstructorId_toReversed :
350
+ {
345
351
// this is a small trick; we will handle all the ConstructorId_xxx calls
346
352
// the same way the object calls are processed
347
353
// so we adjust the args, inverting the id and
@@ -448,6 +454,9 @@ public Object execIdCall(
448
454
case Id_flatMap :
449
455
return js_flatMap (cx , scope , thisObj , args );
450
456
457
+ case Id_toReversed :
458
+ return js_toReversed (cx , scope , thisObj , args );
459
+
451
460
case Id_every :
452
461
case Id_filter :
453
462
case Id_forEach :
@@ -2252,6 +2261,19 @@ private static boolean js_isArray(Object o) {
2252
2261
return "Array" .equals (((Scriptable ) o ).getClassName ());
2253
2262
}
2254
2263
2264
+ private static Scriptable js_toReversed (
2265
+ Context cx , Scriptable scope , Scriptable thisObj , Object [] args ) {
2266
+ Scriptable o = ScriptRuntime .toObject (cx , scope , thisObj );
2267
+ int len = (getLengthProperty (cx , o ) > Integer .MAX_VALUE ) ? 0 :(int ) getLengthProperty (cx , o );
2268
+
2269
+ Scriptable result = cx .newArray (scope , len );
2270
+
2271
+ for (int k = len -1 ; k >= 0 ; k --){
2272
+ Object temp1 = getRawElem (o , k );
2273
+ setRawElem (cx , result , k , temp1 );
2274
+ }
2275
+ return result ;
2276
+ }
2255
2277
// methods to implement java.util.List
2256
2278
2257
2279
@ Override
@@ -2688,6 +2710,9 @@ protected int findPrototypeId(String s) {
2688
2710
case "flatMap" :
2689
2711
id = Id_flatMap ;
2690
2712
break ;
2713
+ case "toReversed" :
2714
+ id = Id_toReversed ;
2715
+ break ;
2691
2716
default :
2692
2717
id = 0 ;
2693
2718
break ;
@@ -2730,6 +2755,7 @@ protected int findPrototypeId(String s) {
2730
2755
Id_flat = 33 ,
2731
2756
Id_flatMap = 34 ,
2732
2757
SymbolId_iterator = 35 ,
2758
+ Id_toReversed =36 ,
2733
2759
MAX_PROTOTYPE_ID = SymbolId_iterator ;
2734
2760
private static final int ConstructorId_join = -Id_join ,
2735
2761
ConstructorId_reverse = -Id_reverse ,
@@ -2752,6 +2778,7 @@ protected int findPrototypeId(String s) {
2752
2778
ConstructorId_findIndex = -Id_findIndex ,
2753
2779
ConstructorId_reduce = -Id_reduce ,
2754
2780
ConstructorId_reduceRight = -Id_reduceRight ,
2781
+ ConstructorId_toReversed = -Id_toReversed ,
2755
2782
ConstructorId_isArray = -26 ,
2756
2783
ConstructorId_of = -27 ,
2757
2784
ConstructorId_from = -28 ;
0 commit comments