@@ -19,7 +19,7 @@ public class StringPolyfill {
1919 private static String passThis (String funcName , Object val ) {
2020 if (val instanceof StringPolyfill ) return ((StringPolyfill )val ).value ;
2121 else if (val instanceof String ) return (String )val ;
22- else throw EngineException .ofType (String .format ("'%s' may be called upon object and primitve strings." , funcName ));
22+ else throw EngineException .ofType (String .format ("'%s' may only be called upon object and primitve strings." , funcName ));
2323 }
2424 private static int normalizeI (int i , int len , boolean clamp ) {
2525 if (i < 0 ) i += len ;
@@ -198,7 +198,7 @@ else if (ctx.env.regexConstructor != null) {
198198 if (parts .length > limit ) res = new ArrayValue (limit );
199199 else res = new ArrayValue (parts .length );
200200
201- for (var i = 0 ; i < parts .length ; i ++) res .set (ctx , i , parts [i ]);
201+ for (var i = 0 ; i < parts .length && i < limit ; i ++) res .set (ctx , i , parts [i ]);
202202
203203 return res ;
204204 }
@@ -235,11 +235,10 @@ else if (ctx.env.regexConstructor != null) {
235235 else return val ;
236236 }
237237 @ Native (thisArg = true ) public static String toString (Context ctx , Object thisArg ) throws InterruptedException {
238- return Values . toString ( ctx , Values . toNumber ( ctx , thisArg ) );
238+ return passThis ( "toString" , thisArg );
239239 }
240240 @ Native (thisArg = true ) public static String valueOf (Context ctx , Object thisArg ) throws InterruptedException {
241- if (thisArg instanceof StringPolyfill ) return ((StringPolyfill )thisArg ).value ;
242- else return Values .toString (ctx , thisArg );
241+ return passThis ("valueOf" , thisArg );
243242 }
244243
245244 @ Native public static String fromCharCode (int ...val ) {
0 commit comments