Module support #11

Merged
TopchetoEU merged 20 commits from TopchetoEU/modules into master 2023-12-26 12:20:55 +00:00
Showing only changes of commit 797585f539 - Show all commits

View File

@ -57,19 +57,16 @@ import me.topchetoeu.jscript.interop.NativeGetter;
@Native(thisArg = true) public static String charAt(Context ctx, Object thisArg, int i) {
return passThis(ctx, "charAt", thisArg).charAt(i) + "";
}
// @Native(thisArg = true) public static int charCodeAt(Context ctx, Object thisArg, int i) {
// return passThis(ctx, "charCodeAt", thisArg).charAt(i);
// }
// @Native(thisArg = true) public static String charAt(Context ctx, Object thisArg, int i) {
// var str = passThis(ctx, "charAt", thisArg);
// if (i < 0 || i >= str.length()) return "";
// else return str.charAt(i) + "";
// }
@Native(thisArg = true) public static double charCodeAt(Context ctx, Object thisArg, int i) {
var str = passThis(ctx, "charCodeAt", thisArg);
if (i < 0 || i >= str.length()) return Double.NaN;
else return str.charAt(i);
}
@Native(thisArg = true) public static double codePointAt(Context ctx, Object thisArg, int i) {
var str = passThis(ctx, "codePointAt", thisArg);
if (i < 0 || i >= str.length()) return Double.NaN;
else return str.codePointAt(i);
}
@Native(thisArg = true) public static boolean startsWith(Context ctx, Object thisArg, String term, int pos) {
return passThis(ctx, "startsWith", thisArg).startsWith(term, pos);
@ -105,7 +102,7 @@ import me.topchetoeu.jscript.interop.NativeGetter;
}
@Native(thisArg = true) public static boolean includes(Context ctx, Object thisArg, Object term, int pos) {
return lastIndexOf(ctx, passThis(ctx, "includes", thisArg), term, pos) >= 0;
return indexOf(ctx, passThis(ctx, "includes", thisArg), term, pos) >= 0;
}
@Native(thisArg = true) public static String replace(Context ctx, Object thisArg, Object term, Object replacement) {
@ -238,6 +235,12 @@ import me.topchetoeu.jscript.interop.NativeGetter;
@Native(thisArg = true) public static String trim(Context ctx, Object thisArg) {
return passThis(ctx, "trim", thisArg).trim();
}
@Native(thisArg = true) public static String trimStart(Context ctx, Object thisArg) {
return passThis(ctx, "trimStart", thisArg).replaceAll("^\\s+", "");
}
@Native(thisArg = true) public static String trimEnd(Context ctx, Object thisArg) {
return passThis(ctx, "trimEnd", thisArg).replaceAll("\\s+$", "");
}
@NativeConstructor(thisArg = true) public static Object constructor(Context ctx, Object thisArg, Object val) {
val = Values.toString(ctx, val);