Skip to content

Commit

Permalink
Update references from deprecated to new methods.
Browse files Browse the repository at this point in the history
ScriptableObject.getProperty methods have been replaced by Scriptable.getProperty. Also remove redundant super interface Scriptable from classes which implement SymbolScriptable.
  • Loading branch information
tonygermano committed Sep 13, 2024
1 parent 872049a commit 519cb58
Show file tree
Hide file tree
Showing 45 changed files with 164 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.mozilla.javascript.Function;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.openjdk.jmh.annotations.*;

@OutputTimeUnit(TimeUnit.NANOSECONDS)
Expand Down Expand Up @@ -43,21 +42,21 @@ public void setup() throws IOException {
try (FileReader rdr = new FileReader("testsrc/benchmarks/micro/math-benchmarks.js")) {
cx.evaluateReader(scope, rdr, "math-benchmarks.js", 1, null);
}
addConstantInts = (Function) ScriptableObject.getProperty(scope, "addConstantInts");
addIntAndConstant = (Function) ScriptableObject.getProperty(scope, "addIntAndConstant");
addTwoInts = (Function) ScriptableObject.getProperty(scope, "addTwoInts");
addConstantFloats = (Function) ScriptableObject.getProperty(scope, "addConstantFloats");
addTwoFloats = (Function) ScriptableObject.getProperty(scope, "addTwoFloats");
addStringsInLoop = (Function) ScriptableObject.getProperty(scope, "addStringsInLoop");
addMixedStrings = (Function) ScriptableObject.getProperty(scope, "addMixedStrings");
subtractInts = (Function) ScriptableObject.getProperty(scope, "subtractInts");
subtractFloats = (Function) ScriptableObject.getProperty(scope, "subtractFloats");
subtractTwoFloats = (Function) ScriptableObject.getProperty(scope, "subtractTwoFloats");
bitwiseAnd = (Function) ScriptableObject.getProperty(scope, "bitwiseAnd");
bitwiseOr = (Function) ScriptableObject.getProperty(scope, "bitwiseOr");
bitwiseLsh = (Function) ScriptableObject.getProperty(scope, "bitwiseLsh");
bitwiseRsh = (Function) ScriptableObject.getProperty(scope, "bitwiseRsh");
bitwiseSignedRsh = (Function) ScriptableObject.getProperty(scope, "bitwiseSignedRsh");
addConstantInts = (Function) Scriptable.getProperty(scope, "addConstantInts");
addIntAndConstant = (Function) Scriptable.getProperty(scope, "addIntAndConstant");
addTwoInts = (Function) Scriptable.getProperty(scope, "addTwoInts");
addConstantFloats = (Function) Scriptable.getProperty(scope, "addConstantFloats");
addTwoFloats = (Function) Scriptable.getProperty(scope, "addTwoFloats");
addStringsInLoop = (Function) Scriptable.getProperty(scope, "addStringsInLoop");
addMixedStrings = (Function) Scriptable.getProperty(scope, "addMixedStrings");
subtractInts = (Function) Scriptable.getProperty(scope, "subtractInts");
subtractFloats = (Function) Scriptable.getProperty(scope, "subtractFloats");
subtractTwoFloats = (Function) Scriptable.getProperty(scope, "subtractTwoFloats");
bitwiseAnd = (Function) Scriptable.getProperty(scope, "bitwiseAnd");
bitwiseOr = (Function) Scriptable.getProperty(scope, "bitwiseOr");
bitwiseLsh = (Function) Scriptable.getProperty(scope, "bitwiseLsh");
bitwiseRsh = (Function) Scriptable.getProperty(scope, "bitwiseRsh");
bitwiseSignedRsh = (Function) Scriptable.getProperty(scope, "bitwiseSignedRsh");
}

@TearDown(Level.Trial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.tools.shell.Global;
import org.openjdk.jmh.annotations.*;

Expand Down Expand Up @@ -72,19 +71,19 @@ public void close() {
@OperationsPerInvocation(1000)
@SuppressWarnings("unused")
public void createFields(FieldTestState state) {
Function create = (Function) ScriptableObject.getProperty(state.scope, "createObject");
Function create = (Function) Scriptable.getProperty(state.scope, "createObject");
create.call(state.cx, state.scope, null, new Object[] {count, state.strings, state.ints});
}

@Benchmark
@OperationsPerInvocation(1000)
@SuppressWarnings("unused")
public void accessFields(FieldTestState state) {
Function create = (Function) ScriptableObject.getProperty(state.scope, "createObject");
Function create = (Function) Scriptable.getProperty(state.scope, "createObject");
Object o =
create.call(
state.cx, state.scope, null, new Object[] {1, state.strings, state.ints});
Function access = (Function) ScriptableObject.getProperty(state.scope, "accessObject");
Function access = (Function) Scriptable.getProperty(state.scope, "accessObject");
access.call(
state.cx, state.scope, null, new Object[] {count, o, state.strings, state.ints});
}
Expand All @@ -93,36 +92,35 @@ public void accessFields(FieldTestState state) {
@OperationsPerInvocation(1000)
@SuppressWarnings("unused")
public void iterateFields(FieldTestState state) {
Function create = (Function) ScriptableObject.getProperty(state.scope, "createObject");
Function create = (Function) Scriptable.getProperty(state.scope, "createObject");
Object o =
create.call(
state.cx, state.scope, null, new Object[] {1, state.strings, state.ints});
Function iterate = (Function) ScriptableObject.getProperty(state.scope, "iterateObject");
Function iterate = (Function) Scriptable.getProperty(state.scope, "iterateObject");
iterate.call(state.cx, state.scope, null, new Object[] {count, o});
}

@Benchmark
@OperationsPerInvocation(1000)
@SuppressWarnings("unused")
public void ownKeysFields(FieldTestState state) {
Function create = (Function) ScriptableObject.getProperty(state.scope, "createObject");
Function create = (Function) Scriptable.getProperty(state.scope, "createObject");
Object o =
create.call(
state.cx, state.scope, null, new Object[] {1, state.strings, state.ints});
Function iterate =
(Function) ScriptableObject.getProperty(state.scope, "iterateOwnKeysObject");
Function iterate = (Function) Scriptable.getProperty(state.scope, "iterateOwnKeysObject");
iterate.call(state.cx, state.scope, null, new Object[] {count, o});
}

@Benchmark
@OperationsPerInvocation(1000)
@SuppressWarnings("unused")
public void deleteFields(FieldTestState state) {
Function create = (Function) ScriptableObject.getProperty(state.scope, "createObject");
Function create = (Function) Scriptable.getProperty(state.scope, "createObject");
Object o =
create.call(
state.cx, state.scope, null, new Object[] {1, state.strings, state.ints});
Function delete = (Function) ScriptableObject.getProperty(state.scope, "deleteObject");
Function delete = (Function) Scriptable.getProperty(state.scope, "deleteObject");
delete.call(
state.cx, state.scope, null, new Object[] {count, o, state.strings, state.ints});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.mozilla.javascript.Function;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.openjdk.jmh.annotations.*;

@OutputTimeUnit(TimeUnit.NANOSECONDS)
Expand Down Expand Up @@ -35,11 +34,11 @@ public void setup() throws IOException {
new FileReader("testsrc/benchmarks/micro/property-benchmarks.js")) {
cx.evaluateReader(scope, rdr, "property-benchmarks.js", 1, null);
}
create = (Function) ScriptableObject.getProperty(scope, "createObject");
create = (Function) Scriptable.getProperty(scope, "createObject");
createFieldByField =
(Function) ScriptableObject.getProperty(scope, "createObjectFieldByField");
getName = (Function) ScriptableObject.getProperty(scope, "getName");
check = (Function) ScriptableObject.getProperty(scope, "check");
(Function) Scriptable.getProperty(scope, "createObjectFieldByField");
getName = (Function) Scriptable.getProperty(scope, "getName");
check = (Function) Scriptable.getProperty(scope, "check");

object = create.call(cx, scope, null, new Object[] {"testing"});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.mozilla.javascript.Callable;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.openjdk.jmh.annotations.*;

@OutputTimeUnit(TimeUnit.MICROSECONDS)
Expand All @@ -18,7 +17,7 @@ abstract static class AbstractState {
Scriptable scope;

Callable getFunc(String name) {
Object f = ScriptableObject.getProperty(scope, name);
Object f = Scriptable.getProperty(scope, name);
if (!(f instanceof Callable)) {
throw new RuntimeException("Benchmark function " + name + " not found");
}
Expand Down
3 changes: 1 addition & 2 deletions examples/src/main/java/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

/**
* Example of controlling the JavaScript execution engine.
Expand Down Expand Up @@ -57,7 +56,7 @@ public static void main(String[] args) {
System.out.println("obj.b[1] == " + b.get(1, b));

// Should print {a:1, b:["x", "y"]}
Function fn = (Function) ScriptableObject.getProperty(obj, "toString");
Function fn = (Function) Scriptable.getProperty(obj, "toString");
System.out.println(fn.call(cx, scope, obj, new Object[0]));
} finally {
Context.exit();
Expand Down
6 changes: 3 additions & 3 deletions examples/src/main/java/CounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ public static void main(String[] args) throws Exception {

Scriptable testCounter = cx.newObject(scope, "Counter");

Object count = ScriptableObject.getProperty(testCounter, "count");
Object count = Scriptable.getProperty(testCounter, "count");
System.out.println("count = " + count);

count = ScriptableObject.getProperty(testCounter, "count");
count = Scriptable.getProperty(testCounter, "count");
System.out.println("count = " + count);

ScriptableObject.callMethod(testCounter, "resetCount", new Object[0]);
System.out.println("resetCount");

count = ScriptableObject.getProperty(testCounter, "count");
count = Scriptable.getProperty(testCounter, "count");
System.out.println("count = " + count);
} finally {
Context.exit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Object invokeMethodRaw(Object thiz, String name, Class<?> returnType, Object...
localThis = Context.toObject(thiz, scope);
}

Object f = ScriptableObject.getProperty(localThis, name);
Object f = Scriptable.getProperty(localThis, name);
if (f == Scriptable.NOT_FOUND) {
throw new NoSuchMethodException(name);
}
Expand Down Expand Up @@ -306,7 +306,7 @@ private static boolean methodsMissing(Scriptable scope, Class<?> clasz) {
if (m.getDeclaringClass() == Object.class) {
continue;
}
Object methodObj = ScriptableObject.getProperty(scope, m.getName());
Object methodObj = Scriptable.getProperty(scope, m.getName());
if (!(methodObj instanceof Callable)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ private Object getObjectPropertyImpl(Context cx, Object object, Object id) {
} else if (name.equals("__parent__")) {
result = scriptable.getParentScope();
} else {
result = ScriptableObject.getProperty(scriptable, name);
result = Scriptable.getProperty(scriptable, name);
if (result == ScriptableObject.NOT_FOUND) {
result = Undefined.instance;
}
}
} else {
int index = ((Integer) id).intValue();
result = ScriptableObject.getProperty(scriptable, index);
result = Scriptable.getProperty(scriptable, index);
if (result == ScriptableObject.NOT_FOUND) {
result = Undefined.instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,16 @@ public static Object deserialize(Context cx, Scriptable thisObj, Object[] args,

public String[] getPrompts(Context cx) {
if (ScriptableObject.hasProperty(this, "prompts")) {
Object promptsJS = ScriptableObject.getProperty(this, "prompts");
Object promptsJS = Scriptable.getProperty(this, "prompts");
if (promptsJS instanceof Scriptable) {
Scriptable s = (Scriptable) promptsJS;
if (ScriptableObject.hasProperty(s, 0) && ScriptableObject.hasProperty(s, 1)) {
Object elem0 = ScriptableObject.getProperty(s, 0);
Object elem0 = Scriptable.getProperty(s, 0);
if (elem0 instanceof Function) {
elem0 = ((Function) elem0).call(cx, this, s, new Object[0]);
}
prompts[0] = Context.toString(elem0);
Object elem1 = ScriptableObject.getProperty(s, 1);
Object elem1 = Scriptable.getProperty(s, 1);
if (elem1 instanceof Function) {
elem1 = ((Function) elem1).call(cx, this, s, new Object[0]);
}
Expand Down Expand Up @@ -616,7 +616,7 @@ public static Object runCommand(Context cx, Scriptable thisObj, Object[] args, F
if (args[L - 1] instanceof Scriptable) {
params = (Scriptable) args[L - 1];
--L;
Object envObj = ScriptableObject.getProperty(params, "env");
Object envObj = Scriptable.getProperty(params, "env");
if (envObj != Scriptable.NOT_FOUND) {
if (envObj == null) {
environment = new String[0];
Expand All @@ -632,11 +632,11 @@ public static Object runCommand(Context cx, Scriptable thisObj, Object[] args, F
String key;
if (keyObj instanceof String) {
key = (String) keyObj;
val = ScriptableObject.getProperty(envHash, key);
val = Scriptable.getProperty(envHash, key);
} else {
int ikey = ((Number) keyObj).intValue();
key = Integer.toString(ikey);
val = ScriptableObject.getProperty(envHash, ikey);
val = Scriptable.getProperty(envHash, ikey);
}
if (val == ScriptableObject.NOT_FOUND) {
val = Undefined.instance;
Expand All @@ -645,32 +645,32 @@ public static Object runCommand(Context cx, Scriptable thisObj, Object[] args, F
}
}
}
Object wdObj = ScriptableObject.getProperty(params, "dir");
Object wdObj = Scriptable.getProperty(params, "dir");
if (wdObj != Scriptable.NOT_FOUND) {
wd = new File(ScriptRuntime.toString(wdObj));
}

Object inObj = ScriptableObject.getProperty(params, "input");
Object inObj = Scriptable.getProperty(params, "input");
if (inObj != Scriptable.NOT_FOUND) {
in = toInputStream(inObj);
}
outObj = ScriptableObject.getProperty(params, "output");
outObj = Scriptable.getProperty(params, "output");
if (outObj != Scriptable.NOT_FOUND) {
out = toOutputStream(outObj);
if (out == null) {
outBytes = new ByteArrayOutputStream();
out = outBytes;
}
}
errObj = ScriptableObject.getProperty(params, "err");
errObj = Scriptable.getProperty(params, "err");
if (errObj != Scriptable.NOT_FOUND) {
err = toOutputStream(errObj);
if (err == null) {
errBytes = new ByteArrayOutputStream();
err = errBytes;
}
}
Object addArgsObj = ScriptableObject.getProperty(params, "args");
Object addArgsObj = Scriptable.getProperty(params, "args");
if (addArgsObj != Scriptable.NOT_FOUND) {
Scriptable s = Context.toObject(addArgsObj, getTopLevelScope(thisObj));
addArgs = cx.getElements(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ private static void printPromiseWarnings(Context cx) {
Object result = unhandled.get(0);
String msg = "Unhandled rejected promise: " + Context.toString(result);
if (result instanceof Scriptable) {
Object stack = ScriptableObject.getProperty((Scriptable) result, "stack");
Object stack = Scriptable.getProperty((Scriptable) result, "stack");
if (stack != null && stack != Scriptable.NOT_FOUND) {
msg += '\n' + Context.toString(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void readSettings(Scriptable source) {
for (int i = 1; i <= MAX_INSTANCE_ID; ++i) {
int id = super.getMaxInstanceId() + i;
String name = getInstanceIdName(id);
Object value = ScriptableObject.getProperty(source, name);
Object value = Scriptable.getProperty(source, name);
if (value == Scriptable.NOT_FOUND) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.mozilla.javascript.Function;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Undefined;
import org.mozilla.javascript.xml.XMLObject;

Expand Down Expand Up @@ -772,7 +771,7 @@ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] ar
if (sobj != null) {
thisObj = sobj;
if (!(sobj instanceof XMLObject)) {
func = ScriptableObject.getProperty(sobj, methodName);
func = Scriptable.getProperty(sobj, methodName);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ The abstract operation SpeciesConstructor takes arguments O (an Object) and
7. If IsConstructor(S) is true, return S.
8. Throw a TypeError exception.
*/
Object constructor = ScriptableObject.getProperty(s, "constructor");
Object constructor = Scriptable.getProperty(s, "constructor");
if (constructor == Scriptable.NOT_FOUND || Undefined.isUndefined(constructor)) {
return defaultConstructor;
}
if (!ScriptRuntime.isObject(constructor)) {
throw ScriptRuntime.typeErrorById(
"msg.arg.not.object", ScriptRuntime.typeof(constructor));
}
Object species = ScriptableObject.getProperty((Scriptable) constructor, SymbolKey.SPECIES);
Object species = Scriptable.getProperty((Scriptable) constructor, SymbolKey.SPECIES);
if (species == Scriptable.NOT_FOUND || species == null || Undefined.isUndefined(species)) {
return defaultConstructor;
}
Expand Down
4 changes: 2 additions & 2 deletions rhino/src/main/java/org/mozilla/javascript/Arguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ protected void defineOwnProperty(
return;
}

Object newValue = getProperty(desc, "value");
Object newValue = Scriptable.getProperty(desc, "value");
if (newValue == NOT_FOUND) return;

replaceArg(index, newValue);

if (isFalse(getProperty(desc, "writable"))) {
if (isFalse(Scriptable.getProperty(desc, "writable"))) {
removeArg(index);
}
}
Expand Down
Loading

0 comments on commit 519cb58

Please sign in to comment.