Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit cf36b7a

Browse files
committed
fix: some string polyfill fixes
1 parent ff9b57a commit cf36b7a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/me/topchetoeu/jscript/polyfills/StringPolyfill.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)