Avoid unnecessary calls to Context.getContext() by passing Context directly as an argument

This commit is contained in:
igor%mir2.org 2002-02-10 21:10:35 +00:00
Родитель 582b069550
Коммит dd9357bec7
10 изменённых файлов: 49 добавлений и 33 удалений

Просмотреть файл

@ -392,7 +392,7 @@ public class BaseFunction extends IdScriptable implements Function {
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
Scriptable newThis = args[0] == null
? ScriptableObject.getTopLevelScope(thisObj)
: ScriptRuntime.toObject(scope, args[0]);
: ScriptRuntime.toObject(cx, scope, args[0]);
Object[] newArgs;
if (args.length > 1) {
if ((args[1] instanceof NativeArray)
@ -417,7 +417,7 @@ public class BaseFunction extends IdScriptable implements Function {
{
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (args.length == 0) {
Scriptable s = ScriptRuntime.toObject(scope, val);
Scriptable s = ScriptRuntime.toObject(cx, scope, val);
Scriptable topScope = s.getParentScope();
return ScriptRuntime.call(cx, val,
topScope, ScriptRuntime.emptyArgs,
@ -425,7 +425,7 @@ public class BaseFunction extends IdScriptable implements Function {
} else {
Scriptable newThis = args[0] == null
? ScriptableObject.getTopLevelScope(thisObj)
: ScriptRuntime.toObject(scope, args[0]);
: ScriptRuntime.toObject(cx, scope, args[0]);
Object[] newArgs = new Object[args.length - 1];
System.arraycopy(args, 1, newArgs, 0, newArgs.length);

Просмотреть файл

@ -349,7 +349,7 @@ public class FunctionObject extends NativeFunction {
setParentScope(scope);
}
static public Object convertArg(Scriptable scope,
static public Object convertArg(Context cx, Scriptable scope,
Object arg, Class desired)
{
if (desired == ScriptRuntime.StringClass)
@ -371,7 +371,7 @@ public class FunctionObject extends NativeFunction {
return new Double(ScriptRuntime.toNumber(arg));
}
if (desired == ScriptRuntime.ScriptableClass)
return ScriptRuntime.toObject(scope, arg);
return ScriptRuntime.toObject(cx, scope, arg);
if (desired == ScriptRuntime.ObjectClass)
return arg;
@ -426,7 +426,7 @@ public class FunctionObject extends NativeFunction {
? args[i]
: Undefined.instance;
if (types != null) {
arg = convertArg(this, arg, types[i]);
arg = convertArg(cx, this, arg, types[i]);
}
invokeArgs[i] = arg;
}

Просмотреть файл

@ -1827,11 +1827,11 @@ public class Interpreter extends LabelTable {
= ScriptRuntime.setProp(lhs, name, rhs, scope);
break;
case TokenStream.GETELEM :
do_getElem(stack, sDbl, stackTop, scope);
do_getElem(cx, stack, sDbl, stackTop, scope);
--stackTop;
break;
case TokenStream.SETELEM :
do_setElem(stack, sDbl, stackTop, scope);
do_setElem(cx, stack, sDbl, stackTop, scope);
stackTop -= 2;
break;
case TokenStream.PROPINC :
@ -2457,7 +2457,8 @@ public class Interpreter extends LabelTable {
return result;
}
private static void do_getElem(Object[] stack, double[] stackDbl,
private static void do_getElem(Context cx,
Object[] stack, double[] stackDbl,
int stackTop, Scriptable scope)
{
Object lhs = stack[stackTop - 1];
@ -2471,7 +2472,7 @@ public class Interpreter extends LabelTable {
else {
Scriptable obj = (lhs instanceof Scriptable)
? (Scriptable)lhs
: ScriptRuntime.toObject(scope, lhs);
: ScriptRuntime.toObject(cx, scope, lhs);
double val = stackDbl[stackTop];
int index = (int)val;
if (index == val) {
@ -2485,7 +2486,8 @@ public class Interpreter extends LabelTable {
stack[stackTop - 1] = result;
}
private static void do_setElem(Object[] stack, double[] stackDbl,
private static void do_setElem(Context cx,
Object[] stack, double[] stackDbl,
int stackTop, Scriptable scope)
{
Object rhs = stack[stackTop];
@ -2501,7 +2503,7 @@ public class Interpreter extends LabelTable {
else {
Scriptable obj = (lhs instanceof Scriptable)
? (Scriptable)lhs
: ScriptRuntime.toObject(scope, lhs);
: ScriptRuntime.toObject(cx, scope, lhs);
double val = stackDbl[stackTop - 1];
int index = (int)val;
if (index == val) {

Просмотреть файл

@ -375,9 +375,9 @@ public class JavaAdapter extends ScriptableObject {
public static Scriptable toObject(Object value, Scriptable scope,
Class staticType)
{
Context.enter();
Context cx = Context.enter();
try {
return Context.toObject(value, scope, staticType);
return ScriptRuntime.toObject(cx, scope, value, staticType);
} finally {
Context.exit();
}

Просмотреть файл

@ -510,9 +510,10 @@ public class NativeArray extends IdScriptable {
if (toLocale && elem != Undefined.instance &&
elem != null)
{
Scriptable obj = cx.toObject(elem, thisObj);
Object tls = ScriptRuntime.getProp(obj,
"toLocaleString", thisObj);
Scriptable obj = ScriptRuntime.
toObject(cx, thisObj, elem);
Object tls = ScriptRuntime.
getProp(obj, "toLocaleString", thisObj);
elem = ScriptRuntime.call(cx, tls, elem,
ScriptRuntime.emptyArgs);
}

Просмотреть файл

@ -115,7 +115,7 @@ public class NativeObject extends IdScriptable {
{
return new NativeObject();
}
return ScriptRuntime.toObject(ctorObj.getParentScope(), args[0]);
return ScriptRuntime.toObject(cx, ctorObj.getParentScope(), args[0]);
}
public String toString() {

Просмотреть файл

@ -59,7 +59,7 @@ import java.io.IOException;
public class NativeScript extends NativeFunction implements Script {
public static void init(Context cx, Scriptable scope, boolean sealed) {
static void init(Context cx, Scriptable scope, boolean sealed) {
NativeScript obj = new NativeScript();
obj.scopeInit(cx, scope, sealed);
}
@ -129,7 +129,7 @@ public class NativeScript extends NativeFunction implements Script {
case Id_compile:
return realThis(thisObj, f, false).
jsFunction_compile(ScriptRuntime.toString(args, 0));
jsFunction_compile(cx, ScriptRuntime.toString(args, 0));
}
}
@ -155,11 +155,11 @@ public class NativeScript extends NativeFunction implements Script {
String source = args.length == 0
? ""
: ScriptRuntime.toString(args[0]);
return compile(scope, source);
return compile(cx, scope, source);
}
public static Script compile(Scriptable scope, String source) {
Context cx = Context.getContext();
private static Script compile(Context cx, Scriptable scope, String source)
{
StringReader reader = new StringReader(source);
try {
int[] linep = { 0 };
@ -178,8 +178,8 @@ public class NativeScript extends NativeFunction implements Script {
}
}
private Scriptable jsFunction_compile(String source) {
script = compile(null, source);
private Scriptable jsFunction_compile(Context cx, String source) {
script = compile(cx, null, source);
return this;
}

Просмотреть файл

@ -179,7 +179,7 @@ public final class NativeWith implements Scriptable, IdFunctionMaster {
thisObj.setPrototype(args.length == 0
? ScriptableObject.getClassPrototype(scope,
"Object")
: ScriptRuntime.toObject(scope, args[0]));
: ScriptRuntime.toObject(cx, scope, args[0]));
thisObj.setParentScope(scope);
return thisObj;
}

Просмотреть файл

@ -464,16 +464,29 @@ public class ScriptRuntime {
}
// ALERT: should it be deprecated ?
public static Scriptable toObject(Scriptable scope, Object val) {
return toObject(Context.getContext(), scope, val, null);
}
// ALERT: should it be deprecated ?
public static Scriptable toObject(Scriptable scope, Object val,
Class staticClass)
{
return toObject(Context.getContext(), scope, val, staticClass);
}
/**
* Convert the value to an object.
*
* See ECMA 9.9.
*/
public static Scriptable toObject(Scriptable scope, Object val) {
return toObject(scope, val, null);
public static Scriptable toObject(Context cx, Scriptable scope, Object val)
{
return toObject(cx, scope, val, null);
}
public static Scriptable toObject(Scriptable scope, Object val,
public static Scriptable toObject(Context cx, Scriptable scope, Object val,
Class staticClass)
{
if (val == null) {
@ -500,8 +513,7 @@ public class ScriptRuntime {
Object[] args = { val };
scope = ScriptableObject.getTopLevelScope(scope);
Scriptable result = newObject(Context.getContext(), scope,
className, args);
Scriptable result = newObject(cx, scope, className, args);
return result;
}
@ -1220,7 +1232,7 @@ public class ScriptRuntime {
if (thisArg instanceof Scriptable || thisArg == null) {
thisObj = (Scriptable) thisArg;
} else {
thisObj = ScriptRuntime.toObject(scope, thisArg);
thisObj = ScriptRuntime.toObject(cx, scope, thisArg);
}
return function.call(cx, scope, thisObj, args);
}

Просмотреть файл

@ -258,12 +258,13 @@ public abstract class ScriptableObject implements Scriptable, Serializable {
private void setBySetter(GetterSlot slot,
String name, Scriptable start, Object value)
{
Context cx = Context.getContext();
Object setterResult;
try {
Class pTypes[] = slot.setter.getParameterTypes();
Class desired = pTypes[pTypes.length - 1];
Object actualArg
= FunctionObject.convertArg(start, value, desired);
= FunctionObject.convertArg(cx, start, value, desired);
if (slot.delegateTo == null) {
// Walk the prototype chain to find an appropriate
// object to invoke the setter on.