Skip to content

Commit

Permalink
Post-PR reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jan 21, 2025
1 parent 0c6f1eb commit 28271f1
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 75 deletions.
4 changes: 2 additions & 2 deletions src/main/java/dev/latvian/mods/rhino/JavaMembers.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public MethodSignature(Method method) {

@Override
public boolean equals(Object o) {
if (o instanceof MethodSignature ms) {
return ms.name.equals(name) && Arrays.equals(args, ms.args);
if (o instanceof MethodSignature(String name1, Class<?>[] args1)) {
return name1.equals(name) && Arrays.equals(args, args1);
}
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/dev/latvian/mods/rhino/NativeIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scrip

return switch (id) {
case Id_next -> iterator.objectIterator.nextExec(cx, scope);
case Id___iterator__ ->
/// XXX: what about argument? SpiderMonkey apparently ignores it
thisObj;
case Id___iterator__ -> thisObj; // XXX: what about argument? SpiderMonkey apparently ignores it
default -> throw new IllegalArgumentException(String.valueOf(id));
};
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/dev/latvian/mods/rhino/NativeMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,15 @@ protected int findPrototypeId(String s) {
case "log2" -> Id_log2;
case "fround" -> Id_fround;
case "clz32" -> Id_clz32;
case "E" -> Id_E;
case "PI" -> Id_PI;
case "LN10" -> Id_LN10;
case "LN2" -> Id_LN2;
case "LOG2E" -> Id_LOG2E;
case "LOG10E" -> Id_LOG10E;
case "SQRT1_2" -> Id_SQRT1_2;
case "SQRT2" -> Id_SQRT2;
default -> 0;
case "E" -> Id_E;
case "PI" -> Id_PI;
case "LN10" -> Id_LN10;
case "LN2" -> Id_LN2;
case "LOG2E" -> Id_LOG2E;
case "LOG10E" -> Id_LOG10E;
case "SQRT1_2" -> Id_SQRT1_2;
case "SQRT2" -> Id_SQRT2;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/latvian/mods/rhino/NativeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ private static String js_repeat(Context cx, Scriptable thisObj, IdFunctionObject
i *= 2;
}
if (i < icnt) {
retval.append(retval.substring(0, str.length() * (icnt - i)));
retval.append(retval, 0, str.length() * (icnt - i));
}

return retval.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ private static int sizeOfParameters(String pString) {
stringLoop:
while (index != rightParenthesis) {
switch (pString.charAt(index)) {
default:
ok = false;
break stringLoop;
case 'J':
case 'D':
--stackDiff;
Expand All @@ -269,9 +266,6 @@ private static int sizeOfParameters(String pString) {
c = pString.charAt(index);
}
switch (c) {
default:
ok = false;
break stringLoop;
case 'J':
case 'D':
case 'B':
Expand All @@ -286,6 +280,9 @@ private static int sizeOfParameters(String pString) {
continue;
case 'L':
// fall through
default:
ok = false;
break stringLoop;
}
// fall through
case 'L': {
Expand All @@ -300,13 +297,13 @@ private static int sizeOfParameters(String pString) {
index = semicolon + 1;
continue;
}
default:
ok = false;
break stringLoop;
}
}
if (ok) {
switch (pString.charAt(rightParenthesis + 1)) {
default:
ok = false;
break;
case 'J':
case 'D':
++stackDiff;
Expand All @@ -323,6 +320,9 @@ private static int sizeOfParameters(String pString) {
// fall through
case 'V':
break;
default:
ok = false;
break;
}
if (ok) {
return ((count << 16) | (0xFFFF & stackDiff));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/latvian/mods/rhino/type/JSOrTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public Class<?> asClass() {

@Override
public TypeInfo or(TypeInfo info) {
if (info instanceof JSOrTypeInfo or) {
var list = new ArrayList<TypeInfo>(types.size() + or.types.size());
if (info instanceof JSOrTypeInfo(List<TypeInfo> types1)) {
var list = new ArrayList<TypeInfo>(types.size() + types1.size());
list.addAll(types);
list.addAll(or.types);
list.addAll(types1);
return new JSOrTypeInfo(List.copyOf(list));
} else {
var list = new ArrayList<TypeInfo>(types.size() + 1);
Expand Down
86 changes: 43 additions & 43 deletions src/main/java/dev/latvian/mods/rhino/type/VariableTypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,51 @@
* @author ZZZank
*/
public class VariableTypeInfo extends TypeInfoBase {
private static final Map<TypeVariable<?>, TypeInfo> CACHE = new HashMap<>();
private static final Lock READ;
private static final Lock WRITE;
private static final Map<TypeVariable<?>, TypeInfo> CACHE = new HashMap<>();
private static final Lock READ;
private static final Lock WRITE;

static {
ReentrantReadWriteLock l = new ReentrantReadWriteLock();
READ = l.readLock();
WRITE = l.writeLock();
}
static {
ReentrantReadWriteLock l = new ReentrantReadWriteLock();
READ = l.readLock();
WRITE = l.writeLock();
}

private TypeInfo consolidated = null;
/**
* we don't need type name to match a TypeVariable, it's designed to be unique
*/
// private final String name;
private TypeInfo consolidated = null;

static TypeInfo of(TypeVariable<?> t) {
READ.lock();
var got = CACHE.get(t);
READ.unlock();
if (got == null) {
WRITE.lock();
// a variable type can have multiple bounds, but we only resolves the first one, since type wrapper cannot
// magically find or create a class that meets multiple bounds
Type bound = t.getBounds()[0];
if (bound == Object.class) {
CACHE.put(t, got = TypeInfo.NONE);
} else {
VariableTypeInfo variable = new VariableTypeInfo();
CACHE.put(t, got = variable);
/*
* we cannot create VariableTypeInfo directly, because types like {@code Enum<T extends Enum<T>>} will
* cause TypeInfo.of() to parse the same variable type `T` infinitely, instead we push it into cache
* before next TypeInfo.of(...) call to make sure that `T` in `Enum<T>` in `T extends Enum<T>` is
* already parsed, so that we can break the loop
*/
variable.consolidated = TypeInfo.of(bound);
}
WRITE.unlock();
}
return got;
}
/**
* we don't need type name to match a TypeVariable, it's designed to be unique
*/
// private final String name;
static TypeInfo of(TypeVariable<?> t) {
READ.lock();
var got = CACHE.get(t);
READ.unlock();
if (got == null) {
WRITE.lock();
// a variable type can have multiple bounds, but we only resolves the first one, since type wrapper cannot
// magically find or create a class that meets multiple bounds
Type bound = t.getBounds()[0];
if (bound == Object.class) {
CACHE.put(t, got = TypeInfo.NONE);
} else {
VariableTypeInfo variable = new VariableTypeInfo();
CACHE.put(t, got = variable);
/*
* we cannot create VariableTypeInfo directly, because types like {@code Enum<T extends Enum<T>>} will
* cause TypeInfo.of() to parse the same variable type `T` infinitely, instead we push it into cache
* before next TypeInfo.of(...) call to make sure that `T` in `Enum<T>` in `T extends Enum<T>` is
* already parsed, so that we can break the loop
*/
variable.consolidated = TypeInfo.of(bound);
}
WRITE.unlock();
}
return got;
}

@Override
public Class<?> asClass() {
return consolidated.asClass();
}
@Override
public Class<?> asClass() {
return consolidated.asClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public interface DirectTypeWrapperFactory<T> extends TypeWrapperFactory<T> {
T wrap(Object from);

@Override
default T wrap(Context cx, Object from, TypeInfo target) {
return wrap(from);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void init() {
shared.testObject = {
a: -39, b: 2, c: 3439438
}
shared.testList = console.testList
""", "");
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/dev/latvian/mods/rhino/test/MiscTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public void init() {
const testObject = {
a: -39, b: 2, c: 3439438
}
let testList = console.testList
for (let string of testList) {
console.info(string)
}
shared.testObject = testObject
shared.testList = testList
""", """
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/dev/latvian/mods/rhino/test/ScopeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public void constInTwoBlocks() {
if (false) {
const xxx = 1
}
if (true) {
const xxx = 2
}
console.info(true)
""", """
true
Expand Down

0 comments on commit 28271f1

Please sign in to comment.