fix: type name can f itself
This commit is contained in:
parent
0dacaaeb4c
commit
9c65bacbac
@ -54,7 +54,6 @@ interface Internals {
|
|||||||
var env: Environment = arguments[0], internals: Internals = arguments[1];
|
var env: Environment = arguments[0], internals: Internals = arguments[1];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const values = {
|
const values = {
|
||||||
Object: env.global.Object = internals.object,
|
Object: env.global.Object = internals.object,
|
||||||
Function: env.global.Function = internals.function,
|
Function: env.global.Function = internals.function,
|
||||||
@ -86,16 +85,12 @@ try {
|
|||||||
env.setProto('rangeErr', env.global.RangeError.prototype);
|
env.setProto('rangeErr', env.global.RangeError.prototype);
|
||||||
env.setProto('typeErr', env.global.TypeError.prototype);
|
env.setProto('typeErr', env.global.TypeError.prototype);
|
||||||
env.setProto('syntaxErr', env.global.SyntaxError.prototype);
|
env.setProto('syntaxErr', env.global.SyntaxError.prototype);
|
||||||
|
|
||||||
(env.global.Object.prototype as any).__proto__ = null;
|
(env.global.Object.prototype as any).__proto__ = null;
|
||||||
|
|
||||||
internals.getEnv(run)?.setProto('array', Array.prototype);
|
internals.getEnv(run)?.setProto('array', Array.prototype);
|
||||||
globalThis.log = (...args) => internals.apply(internals.log, internals, args);
|
globalThis.log = (...args) => internals.apply(internals.log, internals, args);
|
||||||
|
|
||||||
for (const key in values) {
|
|
||||||
(values as any)[key].prototype[env.symbol('Symbol.typeName')] = key;
|
|
||||||
log();
|
|
||||||
}
|
|
||||||
|
|
||||||
run('timeout');
|
run('timeout');
|
||||||
|
|
||||||
env.global.log = log;
|
env.global.log = log;
|
||||||
|
7
src/me/topchetoeu/jscript/interop/InitType.java
Normal file
7
src/me/topchetoeu/jscript/interop/InitType.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package me.topchetoeu.jscript.interop;
|
||||||
|
|
||||||
|
public enum InitType {
|
||||||
|
CONSTRUCTOR,
|
||||||
|
PROTOTYPE,
|
||||||
|
NAMESPACE,
|
||||||
|
}
|
12
src/me/topchetoeu/jscript/interop/NativeInit.java
Normal file
12
src/me/topchetoeu/jscript/interop/NativeInit.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package me.topchetoeu.jscript.interop;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ ElementType.METHOD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface NativeInit {
|
||||||
|
InitType value();
|
||||||
|
}
|
@ -33,7 +33,7 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
|
|
||||||
if (!(val instanceof OverloadFunction)) target.defineProperty(null, name, val = new OverloadFunction(name.toString()));
|
if (!(val instanceof OverloadFunction)) target.defineProperty(null, name, val = new OverloadFunction(name.toString()));
|
||||||
|
|
||||||
((OverloadFunction)val).overloads.add(Overload.fromMethod(method, nat.thisArg()));
|
((OverloadFunction)val).add(Overload.fromMethod(method, nat.thisArg()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (get != null) {
|
if (get != null) {
|
||||||
@ -50,7 +50,7 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
if (prop != null && prop.getter instanceof OverloadFunction) getter = (OverloadFunction)prop.getter;
|
if (prop != null && prop.getter instanceof OverloadFunction) getter = (OverloadFunction)prop.getter;
|
||||||
else getter = new OverloadFunction("get " + name);
|
else getter = new OverloadFunction("get " + name);
|
||||||
|
|
||||||
getter.overloads.add(Overload.fromMethod(method, get.thisArg()));
|
getter.add(Overload.fromMethod(method, get.thisArg()));
|
||||||
target.defineProperty(null, name, getter, setter, true, true);
|
target.defineProperty(null, name, getter, setter, true, true);
|
||||||
}
|
}
|
||||||
if (set != null) {
|
if (set != null) {
|
||||||
@ -67,7 +67,7 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
if (prop != null && prop.setter instanceof OverloadFunction) setter = (OverloadFunction)prop.setter;
|
if (prop != null && prop.setter instanceof OverloadFunction) setter = (OverloadFunction)prop.setter;
|
||||||
else setter = new OverloadFunction("set " + name);
|
else setter = new OverloadFunction("set " + name);
|
||||||
|
|
||||||
setter.overloads.add(Overload.fromMethod(method, set.thisArg()));
|
setter.add(Overload.fromMethod(method, set.thisArg()));
|
||||||
target.defineProperty(null, name, getter, setter, true, true);
|
target.defineProperty(null, name, getter, setter, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,8 +83,8 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
if (((String)name).startsWith("@@")) name = env.symbol(((String)name).substring(2));
|
if (((String)name).startsWith("@@")) name = env.symbol(((String)name).substring(2));
|
||||||
else if (name.equals("")) name = field.getName();
|
else if (name.equals("")) name = field.getName();
|
||||||
|
|
||||||
var getter = new OverloadFunction("get " + name).add(Overload.getterFromField(field));
|
var getter = OverloadFunction.of("get " + name, Overload.getterFromField(field));
|
||||||
var setter = new OverloadFunction("set " + name).add(Overload.setterFromField(field));
|
var setter = OverloadFunction.of("set " + name, Overload.setterFromField(field));
|
||||||
target.defineProperty(null, name, getter, setter, true, false);
|
target.defineProperty(null, name, getter, setter, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,6 +115,13 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
public static ObjectValue makeProto(Environment ctx, Class<?> clazz) {
|
public static ObjectValue makeProto(Environment ctx, Class<?> clazz) {
|
||||||
var res = new ObjectValue();
|
var res = new ObjectValue();
|
||||||
|
|
||||||
|
for (var overload : clazz.getDeclaredMethods()) {
|
||||||
|
var init = overload.getAnnotation(NativeInit.class);
|
||||||
|
if (init == null || init.value() != InitType.PROTOTYPE) continue;
|
||||||
|
try { overload.invoke(null, ctx, res); }
|
||||||
|
catch (ReflectiveOperationException e) { e.printStackTrace(); }
|
||||||
|
}
|
||||||
|
|
||||||
applyMethods(ctx, true, res, clazz);
|
applyMethods(ctx, true, res, clazz);
|
||||||
applyFields(ctx, true, res, clazz);
|
applyFields(ctx, true, res, clazz);
|
||||||
applyClasses(ctx, true, res, clazz);
|
applyClasses(ctx, true, res, clazz);
|
||||||
@ -140,6 +147,12 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
if (constr == null) continue;
|
if (constr == null) continue;
|
||||||
((OverloadFunction)func).add(Overload.fromMethod(overload, constr.thisArg()));
|
((OverloadFunction)func).add(Overload.fromMethod(overload, constr.thisArg()));
|
||||||
}
|
}
|
||||||
|
for (var overload : clazz.getDeclaredMethods()) {
|
||||||
|
var init = overload.getAnnotation(NativeInit.class);
|
||||||
|
if (init == null || init.value() != InitType.CONSTRUCTOR) continue;
|
||||||
|
try { overload.invoke(null, ctx, func); }
|
||||||
|
catch (ReflectiveOperationException e) { e.printStackTrace(); }
|
||||||
|
}
|
||||||
|
|
||||||
if (((OverloadFunction)func).overloads.size() == 0) {
|
if (((OverloadFunction)func).overloads.size() == 0) {
|
||||||
func = new NativeFunction(clazz.getName(), (a, b, c) -> { throw EngineException.ofError("This constructor is not invokable."); });
|
func = new NativeFunction(clazz.getName(), (a, b, c) -> { throw EngineException.ofError("This constructor is not invokable."); });
|
||||||
@ -162,6 +175,13 @@ public class NativeWrapperProvider implements WrappersProvider {
|
|||||||
public static ObjectValue makeNamespace(Environment ctx, Class<?> clazz) {
|
public static ObjectValue makeNamespace(Environment ctx, Class<?> clazz) {
|
||||||
ObjectValue res = new ObjectValue();
|
ObjectValue res = new ObjectValue();
|
||||||
|
|
||||||
|
for (var overload : clazz.getDeclaredMethods()) {
|
||||||
|
var init = overload.getAnnotation(NativeInit.class);
|
||||||
|
if (init == null || init.value() != InitType.NAMESPACE) continue;
|
||||||
|
try { overload.invoke(null, ctx, res); }
|
||||||
|
catch (ReflectiveOperationException e) { e.printStackTrace(); }
|
||||||
|
}
|
||||||
|
|
||||||
applyMethods(ctx, false, res, clazz);
|
applyMethods(ctx, false, res, clazz);
|
||||||
applyFields(ctx, false, res, clazz);
|
applyFields(ctx, false, res, clazz);
|
||||||
applyClasses(ctx, false, res, clazz);
|
applyClasses(ctx, false, res, clazz);
|
||||||
|
@ -113,4 +113,9 @@ public class OverloadFunction extends FunctionValue {
|
|||||||
public OverloadFunction(String name) {
|
public OverloadFunction(String name) {
|
||||||
super(name, 0);
|
super(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static OverloadFunction of(String name, Overload overload) {
|
||||||
|
if (overload == null) return null;
|
||||||
|
else return new OverloadFunction(name).add(overload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,16 @@ import java.util.Iterator;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
import me.topchetoeu.jscript.interop.NativeGetter;
|
import me.topchetoeu.jscript.interop.NativeGetter;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
import me.topchetoeu.jscript.interop.NativeSetter;
|
import me.topchetoeu.jscript.interop.NativeSetter;
|
||||||
|
|
||||||
public class ArrayPolyfill {
|
public class ArrayPolyfill {
|
||||||
@ -347,4 +350,8 @@ public class ArrayPolyfill {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Array");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,11 @@ import me.topchetoeu.jscript.engine.values.CodeFunction;
|
|||||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||||
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
|
||||||
|
|
||||||
public class AsyncFunctionPolyfill extends FunctionValue {
|
public class AsyncFunctionPolyfill extends FunctionValue {
|
||||||
public final FunctionValue factory;
|
public final FunctionValue factory;
|
||||||
|
|
||||||
public static class AsyncHelper {
|
public static class AsyncHelper {
|
||||||
@Native("@@Symbol.typeName") public final String name = "AsyncFunction";
|
|
||||||
public PromisePolyfill promise = new PromisePolyfill();
|
public PromisePolyfill promise = new PromisePolyfill();
|
||||||
public CodeFrame frame;
|
public CodeFrame frame;
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package me.topchetoeu.jscript.polyfills;
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class BooleanPolyfill {
|
public class BooleanPolyfill {
|
||||||
public static final BooleanPolyfill TRUE = new BooleanPolyfill(true);
|
public static final BooleanPolyfill TRUE = new BooleanPolyfill(true);
|
||||||
@ -27,4 +30,7 @@ public class BooleanPolyfill {
|
|||||||
public BooleanPolyfill(boolean val) {
|
public BooleanPolyfill(boolean val) {
|
||||||
this.value = val;
|
this.value = val;
|
||||||
}
|
}
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Boolean");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,16 @@
|
|||||||
package me.topchetoeu.jscript.polyfills;
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class ErrorPolyfill {
|
public class ErrorPolyfill {
|
||||||
public static class SyntaxErrorPolyfill extends ErrorPolyfill {
|
|
||||||
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) throws InterruptedException {
|
|
||||||
var target = ErrorPolyfill.constructor(ctx, thisArg, message);
|
|
||||||
target.defineProperty(ctx, "name", "SyntaxError");
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static class TypeErrorPolyfill extends ErrorPolyfill {
|
|
||||||
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) throws InterruptedException {
|
|
||||||
var target = ErrorPolyfill.constructor(ctx, thisArg, message);
|
|
||||||
target.defineProperty(ctx, "name", "TypeError");
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static class RangeErrorPolyfill extends ErrorPolyfill {
|
|
||||||
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) throws InterruptedException {
|
|
||||||
var target = ErrorPolyfill.constructor(ctx, thisArg, message);
|
|
||||||
target.defineProperty(ctx, "name", "RangeError");
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String toString(Context ctx, Object cause, Object name, Object message, ArrayValue stack) throws InterruptedException {
|
private static String toString(Context ctx, Object cause, Object name, Object message, ArrayValue stack) throws InterruptedException {
|
||||||
if (name == null) name = "";
|
if (name == null) name = "";
|
||||||
else name = Values.toString(ctx, name).trim();
|
else name = Values.toString(ctx, name).trim();
|
||||||
@ -78,4 +59,9 @@ public class ErrorPolyfill {
|
|||||||
|
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Error");
|
||||||
|
target.defineProperty(null, "name", "Error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package me.topchetoeu.jscript.polyfills;
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||||
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
import me.topchetoeu.jscript.engine.values.NativeFunction;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class FunctionPolyfill {
|
public class FunctionPolyfill {
|
||||||
@Native(thisArg = true) public static Object apply(Context ctx, FunctionValue func, Object thisArg, ArrayValue args) throws InterruptedException {
|
@Native(thisArg = true) public static Object apply(Context ctx, FunctionValue func, Object thisArg, ArrayValue args) throws InterruptedException {
|
||||||
@ -40,4 +44,8 @@ public class FunctionPolyfill {
|
|||||||
@Native public static FunctionValue generator(FunctionValue func) {
|
@Native public static FunctionValue generator(FunctionValue func) {
|
||||||
return new GeneratorPolyfill(func);
|
return new GeneratorPolyfill(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Function");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package me.topchetoeu.jscript.polyfills;
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.frame.CodeFrame;
|
import me.topchetoeu.jscript.engine.frame.CodeFrame;
|
||||||
import me.topchetoeu.jscript.engine.frame.Runners;
|
import me.topchetoeu.jscript.engine.frame.Runners;
|
||||||
import me.topchetoeu.jscript.engine.values.CodeFunction;
|
import me.topchetoeu.jscript.engine.values.CodeFunction;
|
||||||
|
@ -10,9 +10,6 @@ import me.topchetoeu.jscript.engine.values.ObjectValue;
|
|||||||
import me.topchetoeu.jscript.engine.values.Symbol;
|
import me.topchetoeu.jscript.engine.values.Symbol;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.polyfills.ErrorPolyfill.RangeErrorPolyfill;
|
|
||||||
import me.topchetoeu.jscript.polyfills.ErrorPolyfill.SyntaxErrorPolyfill;
|
|
||||||
import me.topchetoeu.jscript.polyfills.ErrorPolyfill.TypeErrorPolyfill;
|
|
||||||
|
|
||||||
public class Internals {
|
public class Internals {
|
||||||
public final Environment targetEnv;
|
public final Environment targetEnv;
|
||||||
|
@ -15,6 +15,7 @@ import me.topchetoeu.jscript.interop.NativeGetter;
|
|||||||
public class MapPolyfill {
|
public class MapPolyfill {
|
||||||
private LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
|
private LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
@Native("@@Symbol.typeName") public final String name = "Map";
|
||||||
@Native("@@Symbol.iterator") public ObjectValue iterator(Context ctx) throws InterruptedException {
|
@Native("@@Symbol.iterator") public ObjectValue iterator(Context ctx) throws InterruptedException {
|
||||||
return this.entries(ctx);
|
return this.entries(ctx);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package me.topchetoeu.jscript.polyfills;
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class NumberPolyfill {
|
public class NumberPolyfill {
|
||||||
@Native public static final double EPSILON = java.lang.Math.ulp(1.0);
|
@Native public static final double EPSILON = java.lang.Math.ulp(1.0);
|
||||||
@ -49,4 +52,8 @@ public class NumberPolyfill {
|
|||||||
public NumberPolyfill(double val) {
|
public NumberPolyfill(double val) {
|
||||||
this.value = val;
|
this.value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Number");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
package me.topchetoeu.jscript.polyfills;
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Symbol;
|
import me.topchetoeu.jscript.engine.values.Symbol;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class ObjectPolyfill {
|
public class ObjectPolyfill {
|
||||||
@Native public static ObjectValue assign(Context ctx, ObjectValue dst, Object... src) throws InterruptedException {
|
@Native public static ObjectValue assign(Context ctx, ObjectValue dst, Object... src) throws InterruptedException {
|
||||||
@ -209,4 +212,8 @@ public class ObjectPolyfill {
|
|||||||
// else if (arg instanceof Symbol) return SymbolPolyfill.constructor(ctx, thisArg, arg);
|
// else if (arg instanceof Symbol) return SymbolPolyfill.constructor(ctx, thisArg, arg);
|
||||||
else return arg;
|
else return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Object");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.MessageContext;
|
import me.topchetoeu.jscript.engine.MessageContext;
|
||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||||
@ -13,7 +14,9 @@ import me.topchetoeu.jscript.engine.values.NativeWrapper;
|
|||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class PromisePolyfill {
|
public class PromisePolyfill {
|
||||||
private static class Handle {
|
private static class Handle {
|
||||||
@ -338,4 +341,8 @@ public class PromisePolyfill {
|
|||||||
public PromisePolyfill() {
|
public PromisePolyfill() {
|
||||||
this(STATE_PENDING, null);
|
this(STATE_PENDING, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Promise");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
20
src/me/topchetoeu/jscript/polyfills/RangeErrorPolyfill.java
Normal file
20
src/me/topchetoeu/jscript/polyfills/RangeErrorPolyfill.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
|
public class RangeErrorPolyfill extends ErrorPolyfill {
|
||||||
|
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) throws InterruptedException {
|
||||||
|
var target = ErrorPolyfill.constructor(ctx, thisArg, message);
|
||||||
|
target.defineProperty(ctx, "name", "RangeError");
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "RangeError");
|
||||||
|
target.defineProperty(null, "name", "RangeError");
|
||||||
|
}
|
||||||
|
}
|
@ -62,6 +62,7 @@ public class RegExpPolyfill {
|
|||||||
@Native public final boolean hasIndices;
|
@Native public final boolean hasIndices;
|
||||||
@Native public final boolean global;
|
@Native public final boolean global;
|
||||||
@Native public final boolean sticky;
|
@Native public final boolean sticky;
|
||||||
|
@Native("@@Symbol.typeName") public final String name = "RegExp";
|
||||||
|
|
||||||
@NativeGetter public boolean ignoreCase() { return (flags & Pattern.CASE_INSENSITIVE) != 0; }
|
@NativeGetter public boolean ignoreCase() { return (flags & Pattern.CASE_INSENSITIVE) != 0; }
|
||||||
@NativeGetter public boolean multiline() { return (flags & Pattern.MULTILINE) != 0; }
|
@NativeGetter public boolean multiline() { return (flags & Pattern.MULTILINE) != 0; }
|
||||||
|
@ -15,6 +15,7 @@ import me.topchetoeu.jscript.interop.NativeGetter;
|
|||||||
public class SetPolyfill {
|
public class SetPolyfill {
|
||||||
private LinkedHashSet<Object> set = new LinkedHashSet<>();
|
private LinkedHashSet<Object> set = new LinkedHashSet<>();
|
||||||
|
|
||||||
|
@Native("@@Symbol.typeName") public final String name = "Set";
|
||||||
@Native("@@Symbol.iterator") public ObjectValue iterator(Context ctx) throws InterruptedException {
|
@Native("@@Symbol.iterator") public ObjectValue iterator(Context ctx) throws InterruptedException {
|
||||||
return this.values(ctx);
|
return this.values(ctx);
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,17 @@ package me.topchetoeu.jscript.polyfills;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
import me.topchetoeu.jscript.engine.values.ArrayValue;
|
||||||
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
import me.topchetoeu.jscript.engine.values.FunctionValue;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
import me.topchetoeu.jscript.interop.NativeGetter;
|
import me.topchetoeu.jscript.interop.NativeGetter;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
// TODO: implement index wrapping properly
|
// TODO: implement index wrapping properly
|
||||||
public class StringPolyfill {
|
public class StringPolyfill {
|
||||||
@ -250,4 +253,8 @@ public class StringPolyfill {
|
|||||||
public StringPolyfill(String val) {
|
public StringPolyfill(String val) {
|
||||||
this.value = val;
|
this.value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "String");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,16 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
import me.topchetoeu.jscript.engine.values.Symbol;
|
import me.topchetoeu.jscript.engine.values.Symbol;
|
||||||
import me.topchetoeu.jscript.engine.values.Values;
|
import me.topchetoeu.jscript.engine.values.Values;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.interop.NativeConstructor;
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
import me.topchetoeu.jscript.interop.NativeGetter;
|
import me.topchetoeu.jscript.interop.NativeGetter;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
public class SymbolPolyfill {
|
public class SymbolPolyfill {
|
||||||
private static final Map<String, Symbol> symbols = new HashMap<>();
|
private static final Map<String, Symbol> symbols = new HashMap<>();
|
||||||
@ -59,4 +62,8 @@ public class SymbolPolyfill {
|
|||||||
public SymbolPolyfill(Symbol val) {
|
public SymbolPolyfill(Symbol val) {
|
||||||
this.value = val;
|
this.value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "Symbol");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
20
src/me/topchetoeu/jscript/polyfills/SyntaxErrorPolyfill.java
Normal file
20
src/me/topchetoeu/jscript/polyfills/SyntaxErrorPolyfill.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
|
public class SyntaxErrorPolyfill extends ErrorPolyfill {
|
||||||
|
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) throws InterruptedException {
|
||||||
|
var target = ErrorPolyfill.constructor(ctx, thisArg, message);
|
||||||
|
target.defineProperty(ctx, "name", "SyntaxError");
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "SyntaxError");
|
||||||
|
target.defineProperty(null, "name", "SyntaxError");
|
||||||
|
}
|
||||||
|
}
|
20
src/me/topchetoeu/jscript/polyfills/TypeErrorPolyfill.java
Normal file
20
src/me/topchetoeu/jscript/polyfills/TypeErrorPolyfill.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package me.topchetoeu.jscript.polyfills;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
|
import me.topchetoeu.jscript.engine.Environment;
|
||||||
|
import me.topchetoeu.jscript.engine.values.ObjectValue;
|
||||||
|
import me.topchetoeu.jscript.interop.InitType;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeConstructor;
|
||||||
|
import me.topchetoeu.jscript.interop.NativeInit;
|
||||||
|
|
||||||
|
public class TypeErrorPolyfill extends ErrorPolyfill {
|
||||||
|
@NativeConstructor(thisArg = true) public static ObjectValue constructor(Context ctx, Object thisArg, Object message) throws InterruptedException {
|
||||||
|
var target = ErrorPolyfill.constructor(ctx, thisArg, message);
|
||||||
|
target.defineProperty(ctx, "name", "TypeError");
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
@NativeInit(InitType.PROTOTYPE) public static void init(Environment env, ObjectValue target) {
|
||||||
|
target.defineProperty(null, env.symbol("Symbol.typeName"), "TypeError");
|
||||||
|
target.defineProperty(null, "name", "TypeError");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user