mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-23 22:29:55 +00:00
8006678: Avoid too many Context.getGlobal() calls
Reviewed-by: lagergren, jlaskey
This commit is contained in:
parent
245ec829ff
commit
7014b0cced
@ -216,7 +216,7 @@ run.test.xms=2G
|
||||
# add '-Dtest.js.outofprocess' to run each test in a new sub-process
|
||||
run.test.jvmargs=-server -Xmx${run.test.xmx} -XX:-TieredCompilation -esa -ea -Dnashorn.debug=true -Dfile.encoding=UTF-8
|
||||
#-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M
|
||||
run.test.jvmargs.octane=-Xms${run.test.xms} -${run.test.jvmargs}
|
||||
run.test.jvmargs.octane=-Xms${run.test.xms} ${run.test.jvmargs}
|
||||
|
||||
run.test.jvmsecurityargs=-Xverify:all -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
|
||||
|
||||
|
||||
@ -216,7 +216,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
realSelf = self;
|
||||
}
|
||||
try {
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = getNashornGlobal();
|
||||
try {
|
||||
if(oldGlobal != global) {
|
||||
setNashornGlobal(global);
|
||||
@ -343,7 +343,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
}
|
||||
|
||||
private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException {
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = getNashornGlobal();
|
||||
final boolean globalChanged = (oldGlobal != global);
|
||||
|
||||
Object self = selfObject;
|
||||
@ -395,7 +395,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
if (script == null) {
|
||||
return null;
|
||||
}
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = getNashornGlobal();
|
||||
final boolean globalChanged = (oldGlobal != global);
|
||||
try {
|
||||
if (globalChanged) {
|
||||
@ -457,7 +457,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
}
|
||||
|
||||
private ScriptFunction compileImpl(final char[] buf, final ScriptContext ctxt) throws ScriptException {
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = getNashornGlobal();
|
||||
final boolean globalChanged = (oldGlobal != global);
|
||||
try {
|
||||
final Object val = ctxt.getAttribute(ScriptEngine.FILENAME);
|
||||
@ -479,13 +479,17 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
}
|
||||
}
|
||||
|
||||
// don't make this public!!
|
||||
// don't make these public!!
|
||||
static ScriptObject getNashornGlobal() {
|
||||
return Context.getGlobal();
|
||||
}
|
||||
|
||||
static void setNashornGlobal(final ScriptObject global) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
Context.setGlobal(global);
|
||||
return null;
|
||||
Context.setGlobal(global);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ final class ScriptObjectMirror extends JSObject implements Bindings {
|
||||
}
|
||||
|
||||
private <V> V inGlobal(final Callable<V> callable) {
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal();
|
||||
final boolean globalChanged = (oldGlobal != global);
|
||||
if (globalChanged) {
|
||||
NashornScriptEngine.setNashornGlobal(global);
|
||||
@ -105,7 +105,7 @@ final class ScriptObjectMirror extends JSObject implements Bindings {
|
||||
@Override
|
||||
public Object call(final String methodName, final Object args[]) {
|
||||
final Object val = sobj.get(methodName);
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal();
|
||||
final boolean globalChanged = (oldGlobal != global);
|
||||
|
||||
if (val instanceof ScriptFunction) {
|
||||
@ -180,7 +180,7 @@ final class ScriptObjectMirror extends JSObject implements Bindings {
|
||||
|
||||
@Override
|
||||
public void setMember(final String name, final Object value) {
|
||||
put(name, wrap(value, Context.getGlobal()));
|
||||
put(name, wrap(value, NashornScriptEngine.getNashornGlobal()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1080,10 +1080,10 @@ final class Lower extends NodeOperatorVisitor {
|
||||
/*
|
||||
* For a script, add scope symbols as defined in the property map
|
||||
*/
|
||||
private static void initFromPropertyMap(final FunctionNode functionNode) {
|
||||
private static void initFromPropertyMap(final Context context, final FunctionNode functionNode) {
|
||||
assert functionNode.isScript();
|
||||
|
||||
final PropertyMap map = Context.getGlobal().getMap();
|
||||
final PropertyMap map = context.getGlobalMap();
|
||||
|
||||
for (final Property property : map.getProperties()) {
|
||||
final String key = property.getKey();
|
||||
@ -1130,7 +1130,7 @@ final class Lower extends NodeOperatorVisitor {
|
||||
}
|
||||
|
||||
if (functionNode.isScript()) {
|
||||
initFromPropertyMap(functionNode);
|
||||
initFromPropertyMap(compiler.getContext(), functionNode);
|
||||
}
|
||||
|
||||
// Add function name as local symbol
|
||||
|
||||
@ -71,7 +71,6 @@ import jdk.nashorn.internal.parser.Parser;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ParserException;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
|
||||
/**
|
||||
@ -87,7 +86,6 @@ public final class JSONWriter extends NodeVisitor {
|
||||
* @return JSON string representation of AST of the supplied code
|
||||
*/
|
||||
public static String parse(final String code, final String name, final boolean includeLoc) {
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final Context context = AccessController.doPrivileged(
|
||||
new PrivilegedAction<Context>() {
|
||||
@Override
|
||||
@ -103,7 +101,7 @@ public final class JSONWriter extends NodeVisitor {
|
||||
functionNode.accept(jsonWriter);
|
||||
return jsonWriter.getString();
|
||||
} catch (final ParserException e) {
|
||||
e.throwAsEcmaException(global);
|
||||
e.throwAsEcmaException();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ public final class AccessorPropertyDescriptor extends ScriptObject implements Pr
|
||||
if (getter == UNDEFINED || getter instanceof ScriptFunction) {
|
||||
this.get = getter;
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(getter));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(getter));
|
||||
}
|
||||
} else {
|
||||
delete(GET, strict);
|
||||
@ -168,7 +168,7 @@ public final class AccessorPropertyDescriptor extends ScriptObject implements Pr
|
||||
if (setter == UNDEFINED || setter instanceof ScriptFunction) {
|
||||
this.set = setter;
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(setter));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(setter));
|
||||
}
|
||||
} else {
|
||||
delete(SET, strict);
|
||||
|
||||
@ -1157,7 +1157,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
|
||||
*/
|
||||
public static Object toObject(final Object obj) {
|
||||
if (obj == null || obj == UNDEFINED) {
|
||||
typeError(instance(), "not.an.object", ScriptRuntime.safeToString(obj));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
|
||||
if (obj instanceof ScriptObject) {
|
||||
@ -1274,7 +1274,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
|
||||
*/
|
||||
public static void checkObject(final Object obj) {
|
||||
if (!(obj instanceof ScriptObject)) {
|
||||
typeError(instance(), "not.an.object", ScriptRuntime.safeToString(obj));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1286,7 +1286,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
|
||||
*/
|
||||
public static void checkObjectCoercible(final Object obj) {
|
||||
if (obj == null || obj == UNDEFINED) {
|
||||
typeError(instance(), "not.an.object", ScriptRuntime.safeToString(obj));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -485,7 +485,7 @@ public final class NativeArguments extends ScriptObject {
|
||||
final boolean allowed = super.defineOwnProperty(key, propertyDesc, false);
|
||||
if (!allowed) {
|
||||
if (reject) {
|
||||
typeError(Global.instance(), "cant.redefine.property", key, ScriptRuntime.safeToString(this));
|
||||
typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -47,7 +47,6 @@ import jdk.nashorn.internal.objects.annotations.ScriptClass;
|
||||
import jdk.nashorn.internal.objects.annotations.Setter;
|
||||
import jdk.nashorn.internal.objects.annotations.SpecializedConstructor;
|
||||
import jdk.nashorn.internal.objects.annotations.Where;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.PropertyDescriptor;
|
||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||
@ -182,7 +181,7 @@ public final class NativeArray extends ScriptObject {
|
||||
// Step 3g
|
||||
if (!oldLenDesc.isWritable()) {
|
||||
if (reject) {
|
||||
typeError(Global.instance(), "property.not.writable", "length", ScriptRuntime.safeToString(this));
|
||||
typeError("property.not.writable", "length", ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -211,7 +210,7 @@ public final class NativeArray extends ScriptObject {
|
||||
}
|
||||
super.defineOwnProperty("length", newLenDesc, false);
|
||||
if (reject) {
|
||||
typeError(Global.instance(), "property.not.writable", "length", ScriptRuntime.safeToString(this));
|
||||
typeError("property.not.writable", "length", ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -236,7 +235,7 @@ public final class NativeArray extends ScriptObject {
|
||||
// setting an element beyond current length, but 'length' is not writable
|
||||
if (longIndex >= oldLen && !oldLenDesc.isWritable()) {
|
||||
if (reject) {
|
||||
typeError(Global.instance(), "property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
|
||||
typeError("property.not.writable", Long.toString(longIndex), ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -248,7 +247,7 @@ public final class NativeArray extends ScriptObject {
|
||||
// Step 4d
|
||||
if (!succeeded) {
|
||||
if (reject) {
|
||||
typeError(Global.instance(), "cant.redefine.property", key, ScriptRuntime.safeToString(this));
|
||||
typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -325,7 +324,7 @@ public final class NativeArray extends ScriptObject {
|
||||
}
|
||||
}
|
||||
if (reject) {
|
||||
rangeError(Global.instance(), "inappropriate.array.length", ScriptRuntime.safeToString(length));
|
||||
rangeError("inappropriate.array.length", ScriptRuntime.safeToString(length));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -371,7 +370,7 @@ public final class NativeArray extends ScriptObject {
|
||||
final Object obj = iter.next();
|
||||
|
||||
if (obj != null && obj != ScriptRuntime.UNDEFINED) {
|
||||
final Object val = JSType.toObject(Global.instance(), obj);
|
||||
final Object val = JSType.toScriptObject(obj);
|
||||
|
||||
try {
|
||||
if (val instanceof ScriptObject) {
|
||||
@ -381,7 +380,7 @@ public final class NativeArray extends ScriptObject {
|
||||
if (toLocaleString instanceof ScriptFunction) {
|
||||
sb.append((String)TO_LOCALE_STRING.getInvoker().invokeExact(toLocaleString, sobj));
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.function", "toLocaleString");
|
||||
typeError("not.a.function", "toLocaleString");
|
||||
}
|
||||
}
|
||||
} catch (final Error|RuntimeException t) {
|
||||
@ -434,7 +433,7 @@ public final class NativeArray extends ScriptObject {
|
||||
*/
|
||||
final double numberLength = ((Number) len).doubleValue();
|
||||
if (length != numberLength) {
|
||||
rangeError(Global.instance(), "inappropriate.array.length", JSType.toString(numberLength));
|
||||
rangeError("inappropriate.array.length", JSType.toString(numberLength));
|
||||
}
|
||||
|
||||
return new NativeArray(length);
|
||||
@ -624,7 +623,7 @@ public final class NativeArray extends ScriptObject {
|
||||
|
||||
return element;
|
||||
} catch (final ClassCastException | NullPointerException e) {
|
||||
typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(self));
|
||||
return ScriptRuntime.UNDEFINED;
|
||||
}
|
||||
}
|
||||
@ -660,7 +659,7 @@ public final class NativeArray extends ScriptObject {
|
||||
|
||||
return len;
|
||||
} catch (final ClassCastException | NullPointerException e) {
|
||||
typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(self));
|
||||
return ScriptRuntime.UNDEFINED;
|
||||
}
|
||||
}
|
||||
@ -699,7 +698,7 @@ public final class NativeArray extends ScriptObject {
|
||||
}
|
||||
return sobj;
|
||||
} catch (final ClassCastException | NullPointerException e) {
|
||||
typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(self));
|
||||
return ScriptRuntime.UNDEFINED;
|
||||
}
|
||||
}
|
||||
@ -805,7 +804,7 @@ public final class NativeArray extends ScriptObject {
|
||||
final ScriptFunction cmp = compareFunction(comparefn);
|
||||
|
||||
final List<Object> list = Arrays.asList(array);
|
||||
final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Context.getGlobal();
|
||||
final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance();
|
||||
|
||||
Collections.sort(list, new Comparator<Object>() {
|
||||
@Override
|
||||
@ -865,7 +864,7 @@ public final class NativeArray extends ScriptObject {
|
||||
|
||||
return sobj;
|
||||
} catch (final ClassCastException | NullPointerException e) {
|
||||
typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(self));
|
||||
return ScriptRuntime.UNDEFINED;
|
||||
}
|
||||
}
|
||||
@ -1080,7 +1079,7 @@ public final class NativeArray extends ScriptObject {
|
||||
}
|
||||
}
|
||||
} catch (final ClassCastException | NullPointerException e) {
|
||||
typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(self));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(self));
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -1202,14 +1201,14 @@ public final class NativeArray extends ScriptObject {
|
||||
Object initialValue = initialValuePresent ? args[1] : ScriptRuntime.UNDEFINED;
|
||||
|
||||
if (callbackfn == ScriptRuntime.UNDEFINED) {
|
||||
typeError(Global.instance(), "not.a.function", "undefined");
|
||||
typeError("not.a.function", "undefined");
|
||||
}
|
||||
|
||||
if (!initialValuePresent) {
|
||||
if (iter.hasNext()) {
|
||||
initialValue = iter.next();
|
||||
} else {
|
||||
typeError(Global.instance(), "array.reduce.invalid.init");
|
||||
typeError("array.reduce.invalid.init");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -145,7 +145,7 @@ public final class NativeBoolean extends ScriptObject {
|
||||
} else if (self != null && self == Global.instance().getBooleanPrototype()) {
|
||||
return false;
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.boolean", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.boolean", ScriptRuntime.safeToString(self));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -867,7 +867,7 @@ public final class NativeDate extends ScriptObject {
|
||||
if (func instanceof ScriptFunction) {
|
||||
return TO_ISO_STRING.getInvoker().invokeExact(func, sobj, key);
|
||||
}
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(func));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(func));
|
||||
} catch (final RuntimeException | Error e) {
|
||||
throw e;
|
||||
} catch (final Throwable t) {
|
||||
@ -1006,7 +1006,7 @@ public final class NativeDate extends ScriptObject {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
rangeError(Global.instance(), "invalid.date");
|
||||
rangeError("invalid.date");
|
||||
|
||||
return INVALID_DATE;
|
||||
}
|
||||
@ -1035,7 +1035,7 @@ public final class NativeDate extends ScriptObject {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
rangeError(Global.instance(), "invalid.date");
|
||||
rangeError("invalid.date");
|
||||
|
||||
return INVALID_DATE;
|
||||
}
|
||||
@ -1268,7 +1268,7 @@ public final class NativeDate extends ScriptObject {
|
||||
} else if (self != null && self == Global.instance().getDatePrototype()) {
|
||||
return Global.instance().DEFAULT_DATE;
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.date", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.date", ScriptRuntime.safeToString(self));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public final class NativeFunction {
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE)
|
||||
public static Object toString(final Object self) {
|
||||
if (!(self instanceof ScriptFunction)) {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
return UNDEFINED;
|
||||
}
|
||||
return ((ScriptFunction)self).toSource();
|
||||
@ -71,7 +71,7 @@ public final class NativeFunction {
|
||||
if (thiz == UNDEFINED || thiz == null) {
|
||||
return Global.instance();
|
||||
}
|
||||
return JSType.toObject(Global.instance(), thiz);
|
||||
return JSType.toScriptObject(thiz);
|
||||
}
|
||||
|
||||
return thiz;
|
||||
@ -88,7 +88,7 @@ public final class NativeFunction {
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE)
|
||||
public static Object apply(final Object self, final Object thiz, final Object array) {
|
||||
if (!(self instanceof ScriptFunction)) {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -102,12 +102,12 @@ public final class NativeFunction {
|
||||
final Object len = sobj.getLength();
|
||||
|
||||
if (len == UNDEFINED || len == null) {
|
||||
typeError(Global.instance(), "function.apply.expects.array");
|
||||
typeError("function.apply.expects.array");
|
||||
}
|
||||
|
||||
final int n = (int)JSType.toUint32(len);
|
||||
if (n != JSType.toNumber(len)) {
|
||||
typeError(Global.instance(), "function.apply.expects.array");
|
||||
typeError("function.apply.expects.array");
|
||||
}
|
||||
|
||||
args = new Object[(int)JSType.toUint32(len)];
|
||||
@ -122,7 +122,7 @@ public final class NativeFunction {
|
||||
} else if (array == null || array == UNDEFINED) {
|
||||
args = ScriptRuntime.EMPTY_ARRAY;
|
||||
} else {
|
||||
typeError(Global.instance(), "function.apply.expects.array");
|
||||
typeError("function.apply.expects.array");
|
||||
}
|
||||
|
||||
final ScriptFunction func = (ScriptFunction)self;
|
||||
@ -143,7 +143,7 @@ public final class NativeFunction {
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
|
||||
public static Object call(final Object self, final Object... args) {
|
||||
if (!(self instanceof ScriptFunction)) {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ public final class NativeFunction {
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
|
||||
public static Object bind(final Object self, final Object... args) {
|
||||
if (!(self instanceof ScriptFunction)) {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ public final class NativeFunction {
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE)
|
||||
public static Object toSource(final Object self) {
|
||||
if (!(self instanceof ScriptFunction)) {
|
||||
typeError(Global.instance(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
return UNDEFINED;
|
||||
}
|
||||
return ((ScriptFunction)self).toSource();
|
||||
|
||||
@ -540,7 +540,7 @@ public final class NativeJSAdapter extends ScriptObject {
|
||||
Object adaptee;
|
||||
|
||||
if (args == null || args.length == 0) {
|
||||
typeError(Global.instance(), "not.an.object", "null");
|
||||
typeError("not.an.object", "null");
|
||||
return null; //won't reach, but fixed warning
|
||||
}
|
||||
|
||||
@ -564,7 +564,7 @@ public final class NativeJSAdapter extends ScriptObject {
|
||||
}
|
||||
|
||||
if (!(adaptee instanceof ScriptObject)) {
|
||||
typeError(Global.instance(), "not.an.object", ScriptRuntime.safeToString(adaptee));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(adaptee));
|
||||
}
|
||||
|
||||
if (proto != null && !(proto instanceof ScriptObject)) {
|
||||
@ -623,7 +623,7 @@ public final class NativeJSAdapter extends ScriptObject {
|
||||
func.makeBoundFunction(this, new Object[] { name })), 0, Object.class),
|
||||
adaptee.getMap().getProtoGetSwitchPoint(__call__), testJSAdaptor(adaptee, null, null, null));
|
||||
}
|
||||
typeError(Global.instance(), "no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
|
||||
typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -696,7 +696,7 @@ public final class NativeJSAdapter extends ScriptObject {
|
||||
|
||||
switch (hook) {
|
||||
case __call__:
|
||||
typeError(Global.instance(), "no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
|
||||
typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));
|
||||
throw new AssertionError("should not reach here");
|
||||
default:
|
||||
final MethodHandle methodHandle = hook.equals(__put__) ?
|
||||
|
||||
@ -101,7 +101,7 @@ public final class NativeJSON extends ScriptObject {
|
||||
try {
|
||||
node = parser.parse();
|
||||
} catch (final ParserException e) {
|
||||
syntaxError(Global.instance(), e, "invalid.json", e.getMessage());
|
||||
syntaxError(e, "invalid.json", e.getMessage());
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -404,7 +404,7 @@ public final class NativeJSON extends ScriptObject {
|
||||
// Spec: The abstract operation JO(value) serializes an object.
|
||||
private static String JO(final ScriptObject value, final StringifyState state) {
|
||||
if (state.stack.containsKey(value)) {
|
||||
typeError(Global.instance(), "JSON.stringify.cyclic");
|
||||
typeError("JSON.stringify.cyclic");
|
||||
}
|
||||
|
||||
state.stack.put(value, value);
|
||||
@ -480,7 +480,7 @@ public final class NativeJSON extends ScriptObject {
|
||||
// Spec: The abstract operation JA(value) serializes an array.
|
||||
private static Object JA(final NativeArray value, final StringifyState state) {
|
||||
if (state.stack.containsKey(value)) {
|
||||
typeError(Global.instance(), "JSON.stringify.cyclic");
|
||||
typeError("JSON.stringify.cyclic");
|
||||
}
|
||||
|
||||
state.stack.put(value, value);
|
||||
|
||||
@ -287,7 +287,7 @@ public class NativeJava {
|
||||
return new NativeArray(copyArray((boolean[])objArray));
|
||||
}
|
||||
|
||||
typeError(Global.instance(), "cant.convert.to.javascript.array", objArray.getClass().getName());
|
||||
typeError("cant.convert.to.javascript.array", objArray.getClass().getName());
|
||||
|
||||
throw new AssertionError();
|
||||
}
|
||||
@ -384,7 +384,7 @@ public class NativeJava {
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
|
||||
public static Object extend(final Object self, final Object... types) {
|
||||
if(types == null || types.length == 0) {
|
||||
typeError(Global.instance(), "extend.expects.at.least.one.argument");
|
||||
typeError("extend.expects.at.least.one.argument");
|
||||
}
|
||||
final Class<?>[] stypes = new Class<?>[types.length];
|
||||
try {
|
||||
@ -392,7 +392,7 @@ public class NativeJava {
|
||||
stypes[i] = ((StaticClass)types[i]).getRepresentedClass();
|
||||
}
|
||||
} catch(final ClassCastException e) {
|
||||
typeError(Global.instance(), "extend.expects.java.types");
|
||||
typeError("extend.expects.java.types");
|
||||
}
|
||||
return JavaAdapterFactory.getAdapterClassFor(stypes);
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ public final class NativeNumber extends ScriptObject {
|
||||
public static Object toFixed(final Object self, final Object fractionDigits) {
|
||||
final int f = JSType.toInteger(fractionDigits);
|
||||
if (f < 0 || f > 20) {
|
||||
rangeError(Global.instance(), "invalid.fraction.digits", "toFixed");
|
||||
rangeError("invalid.fraction.digits", "toFixed");
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ public final class NativeNumber extends ScriptObject {
|
||||
}
|
||||
|
||||
if (fractionDigits != UNDEFINED && (f < 0 || f > 20)) {
|
||||
rangeError(Global.instance(), "invalid.fraction.digits", "toExponential");
|
||||
rangeError("invalid.fraction.digits", "toExponential");
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ public final class NativeNumber extends ScriptObject {
|
||||
}
|
||||
|
||||
if (p < 1 || p > 21) {
|
||||
rangeError(Global.instance(), "invalid.precision");
|
||||
rangeError("invalid.precision");
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ public final class NativeNumber extends ScriptObject {
|
||||
final int intRadix = JSType.toInteger(radix);
|
||||
if (intRadix != 10) {
|
||||
if (intRadix < 2 || intRadix > 36) {
|
||||
rangeError(Global.instance(), "invalid.radix");
|
||||
rangeError("invalid.radix");
|
||||
}
|
||||
return JSType.toString(getNumberValue(self), intRadix);
|
||||
}
|
||||
@ -338,7 +338,7 @@ public final class NativeNumber extends ScriptObject {
|
||||
} else if (self != null && self == Global.instance().getNumberPrototype()) {
|
||||
return 0.0;
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.number", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.number", ScriptRuntime.safeToString(self));
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ public final class NativeObject {
|
||||
*/
|
||||
@Function(attributes = Attribute.NOT_ENUMERABLE)
|
||||
public static Object toLocaleString(final Object self) {
|
||||
final Object obj = JSType.toObject(Global.instance(), self);
|
||||
final Object obj = JSType.toScriptObject(self);
|
||||
if (obj instanceof ScriptObject) {
|
||||
final ScriptObject sobj = (ScriptObject)self;
|
||||
try {
|
||||
@ -331,7 +331,7 @@ public final class NativeObject {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
|
||||
typeError(Global.instance(), "not.a.function", "toString");
|
||||
typeError("not.a.function", "toString");
|
||||
throw new AssertionError(); // never reached
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ public final class NativeRegExp extends ScriptObject {
|
||||
regExp = new RegExp(input, flagString);
|
||||
} catch (final ParserException e) {
|
||||
// translate it as SyntaxError object and throw it
|
||||
e.throwAsEcmaException(Global.instance());
|
||||
e.throwAsEcmaException();
|
||||
throw new AssertionError(); //guard against null warnings below
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ public final class NativeRegExp extends ScriptObject {
|
||||
if (!flagsDefined) {
|
||||
return (NativeRegExp)regexp; // 15.10.3.1 - undefined flags and regexp as
|
||||
}
|
||||
typeError(Global.instance(), "regex.cant.supply.flags");
|
||||
typeError("regex.cant.supply.flags");
|
||||
}
|
||||
patternString = JSType.toString(regexp);
|
||||
}
|
||||
@ -716,7 +716,7 @@ public final class NativeRegExp extends ScriptObject {
|
||||
} else if (self != null && self == Global.instance().getRegExpPrototype()) {
|
||||
return Global.instance().DEFAULT_REGEXP;
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.regexp", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.regexp", ScriptRuntime.safeToString(self));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ public final class NativeString extends ScriptObject {
|
||||
private boolean checkDeleteIndex(final int index, final boolean strict) {
|
||||
if (isValid(index)) {
|
||||
if (strict) {
|
||||
typeError(Global.instance(), "cant.delete.property", Integer.toString(index), ScriptRuntime.safeToString(this));
|
||||
typeError("cant.delete.property", Integer.toString(index), ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -904,7 +904,7 @@ public final class NativeString extends ScriptObject {
|
||||
} else if (self != null && self == Global.instance().getStringPrototype()) {
|
||||
return "";
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.string", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.string", ScriptRuntime.safeToString(self));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -919,7 +919,7 @@ public final class NativeString extends ScriptObject {
|
||||
} else if (self != null && self == Global.instance().getStringPrototype()) {
|
||||
return "";
|
||||
} else {
|
||||
typeError(Global.instance(), "not.a.string", ScriptRuntime.safeToString(self));
|
||||
typeError( "not.a.string", ScriptRuntime.safeToString(self));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,10 +50,12 @@ import jdk.nashorn.internal.codegen.ClassEmitter;
|
||||
import jdk.nashorn.internal.codegen.Compiler;
|
||||
import jdk.nashorn.internal.codegen.Namespace;
|
||||
import jdk.nashorn.internal.codegen.objects.ObjectClassGenerator;
|
||||
import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
|
||||
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
|
||||
import jdk.nashorn.internal.runtime.options.KeyValueOption;
|
||||
import jdk.nashorn.internal.runtime.options.Option;
|
||||
import jdk.nashorn.internal.runtime.options.Options;
|
||||
import sun.reflect.Reflection;
|
||||
|
||||
/**
|
||||
* This class manages the global state of execution. Context is immutable.
|
||||
@ -72,11 +74,27 @@ public final class Context {
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the current global scope
|
||||
* @return current global scope
|
||||
* Get the current global scope
|
||||
* @return the current global scope
|
||||
*/
|
||||
public static ScriptObject getGlobal() {
|
||||
return currentGlobal.get();
|
||||
final SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
// skip getCallerClass and getGlobal and get to the real caller
|
||||
Class<?> caller = Reflection.getCallerClass(2);
|
||||
ClassLoader callerLoader = caller.getClassLoader();
|
||||
|
||||
// Allow this method only for nashorn's own classes, script
|
||||
// generated classes and Java adapter classes. Rest should
|
||||
// have the necessary security permission.
|
||||
if (callerLoader != myLoader &&
|
||||
!(callerLoader instanceof NashornLoader) &&
|
||||
!(JavaAdapterFactory.isAdapterClass(caller))) {
|
||||
sm.checkPermission(new RuntimePermission("getNashornGlobal"));
|
||||
}
|
||||
}
|
||||
|
||||
return getGlobalTrusted();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +111,7 @@ public final class Context {
|
||||
throw new IllegalArgumentException("global does not implement GlobalObject!");
|
||||
}
|
||||
|
||||
currentGlobal.set(global);
|
||||
setGlobalTrusted(global);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +132,7 @@ public final class Context {
|
||||
* @return error writer of the current context
|
||||
*/
|
||||
public static PrintWriter getCurrentErr() {
|
||||
final ScriptObject global = getGlobal();
|
||||
final ScriptObject global = getGlobalTrusted();
|
||||
return (global != null)? global.getContext().getErr() : new PrintWriter(System.err);
|
||||
}
|
||||
|
||||
@ -456,6 +474,14 @@ public final class Context {
|
||||
return _timezone;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the PropertyMap of the current global scope
|
||||
* @return the property map of the current global scope
|
||||
*/
|
||||
public PropertyMap getGlobalMap() {
|
||||
return Context.getGlobalTrusted().getMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a top level script.
|
||||
*
|
||||
@ -501,7 +527,7 @@ public final class Context {
|
||||
final String file = (location == UNDEFINED || location == null) ? "<eval>" : location.toString();
|
||||
final Source source = new Source(file, string);
|
||||
final boolean directEval = location != UNDEFINED; // is this direct 'eval' call or indirectly invoked eval?
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final ScriptObject global = Context.getGlobalTrusted();
|
||||
|
||||
ScriptObject scope = initialScope;
|
||||
|
||||
@ -624,7 +650,7 @@ public final class Context {
|
||||
}
|
||||
}
|
||||
|
||||
typeError(Context.getGlobal(), "cant.load.script", ScriptRuntime.safeToString(source));
|
||||
typeError("cant.load.script", ScriptRuntime.safeToString(source));
|
||||
|
||||
return UNDEFINED;
|
||||
}
|
||||
@ -726,13 +752,13 @@ public final class Context {
|
||||
final ScriptObject global = newGlobal();
|
||||
// Need only minimal global object, if we are just compiling.
|
||||
if (!_compile_only) {
|
||||
final ScriptObject oldGlobal = Context.getGlobal();
|
||||
final ScriptObject oldGlobal = Context.getGlobalTrusted();
|
||||
try {
|
||||
Context.setGlobal(global);
|
||||
Context.setGlobalTrusted(global);
|
||||
// initialize global scope with builtin global objects
|
||||
((GlobalObject)global).initBuiltinObjects();
|
||||
} finally {
|
||||
Context.setGlobal(oldGlobal);
|
||||
Context.setGlobalTrusted(oldGlobal);
|
||||
}
|
||||
}
|
||||
|
||||
@ -740,10 +766,30 @@ public final class Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* Trusted variant package-private
|
||||
* Trusted variants - package-private
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the current global scope
|
||||
* @return current global scope
|
||||
*/
|
||||
static ScriptObject getGlobalTrusted() {
|
||||
return currentGlobal.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current global scope
|
||||
*/
|
||||
static void setGlobalTrusted(ScriptObject global) {
|
||||
currentGlobal.set(global);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current global's context
|
||||
* @return current global's context
|
||||
*/
|
||||
static Context getContextTrusted() {
|
||||
return Context.getGlobal().getContext();
|
||||
return Context.getGlobalTrusted().getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -770,7 +816,7 @@ public final class Context {
|
||||
try {
|
||||
script = compileScript(name, url, scope, new Context.ThrowErrorManager(), _strict);
|
||||
} catch (final ParserException e) {
|
||||
e.throwAsEcmaException(Context.getGlobal());
|
||||
e.throwAsEcmaException();
|
||||
}
|
||||
|
||||
return ScriptRuntime.apply(script, thiz);
|
||||
@ -782,7 +828,7 @@ public final class Context {
|
||||
try {
|
||||
script = compileScript(source, scope, new Context.ThrowErrorManager(), _strict);
|
||||
} catch (final ParserException e) {
|
||||
e.throwAsEcmaException(Context.getGlobal());
|
||||
e.throwAsEcmaException();
|
||||
}
|
||||
|
||||
return ScriptRuntime.apply(script, thiz);
|
||||
@ -813,7 +859,7 @@ public final class Context {
|
||||
}
|
||||
|
||||
// Package as a JavaScript function and pass function back to shell.
|
||||
return ((GlobalObject)Context.getGlobal()).newScriptFunction(RUN_SCRIPT.tag(), runMethodHandle, scope, strict);
|
||||
return ((GlobalObject)Context.getGlobalTrusted()).newScriptFunction(RUN_SCRIPT.tag(), runMethodHandle, scope, strict);
|
||||
}
|
||||
|
||||
private ScriptFunction compileScript(final String name, final URL url, final ScriptObject scope, final ErrorManager errMan, final boolean strict) throws IOException {
|
||||
@ -836,7 +882,7 @@ public final class Context {
|
||||
Class<?> script;
|
||||
|
||||
if (_class_cache_size > 0) {
|
||||
global = (GlobalObject)Context.getGlobal();
|
||||
global = (GlobalObject)Context.getGlobalTrusted();
|
||||
script = global.findCachedClass(source);
|
||||
if (script != null) {
|
||||
return script;
|
||||
|
||||
@ -56,6 +56,16 @@ public final class ECMAErrors {
|
||||
throw new ECMAException(thrown, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error dispatch mechanism.
|
||||
* Throw a {@link ParserException} as the correct JavaScript error
|
||||
*
|
||||
* @param e {@code ParserException} for error dispatcher
|
||||
*/
|
||||
public static void throwAsEcmaException(final ParserException e) {
|
||||
throwAsEcmaException(Context.getGlobalTrusted(), e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error dispatch mechanism.
|
||||
* Throw a {@link ParserException} as the correct JavaScript error
|
||||
@ -103,6 +113,15 @@ public final class ECMAErrors {
|
||||
// should not happen - perhaps unknown error type?
|
||||
throw e;
|
||||
}
|
||||
/**
|
||||
* Throw a syntax error (ECMA 15.11.6.4)
|
||||
*
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void syntaxError(final String msgId, final String... args) {
|
||||
syntaxError(Context.getGlobalTrusted(), msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a syntax error (ECMA 15.11.6.4)
|
||||
@ -115,6 +134,17 @@ public final class ECMAErrors {
|
||||
syntaxError(global, null, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a syntax error (ECMA 15.11.6.4)
|
||||
*
|
||||
* @param cause native Java {@code Throwable} that is the cause of error
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void syntaxError(final Throwable cause, final String msgId, final String... args) {
|
||||
syntaxError(Context.getGlobalTrusted(), cause, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a syntax error (ECMA 15.11.6.4)
|
||||
*
|
||||
@ -128,6 +158,16 @@ public final class ECMAErrors {
|
||||
throwError(((GlobalObject)global).newSyntaxError(msg), cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a type error (ECMA 15.11.6.5)
|
||||
*
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void typeError(final String msgId, final String... args) {
|
||||
typeError(Context.getGlobalTrusted(), msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a type error (ECMA 15.11.6.5)
|
||||
*
|
||||
@ -139,6 +179,17 @@ public final class ECMAErrors {
|
||||
typeError(global, null, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a type error (ECMA 15.11.6.5)
|
||||
*
|
||||
* @param cause native Java {@code Throwable} that is the cause of error
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void typeError(final Throwable cause, final String msgId, final String... args) {
|
||||
typeError(Context.getGlobalTrusted(), cause, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a type error (ECMA 15.11.6.5)
|
||||
*
|
||||
@ -152,6 +203,16 @@ public final class ECMAErrors {
|
||||
throwError(((GlobalObject)global).newTypeError(msg), cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a range error (ECMA 15.11.6.2)
|
||||
*
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void rangeError(final String msgId, final String... args) {
|
||||
rangeError(Context.getGlobalTrusted(), msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a range error (ECMA 15.11.6.2)
|
||||
*
|
||||
@ -163,6 +224,17 @@ public final class ECMAErrors {
|
||||
rangeError(global, null, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a range error (ECMA 15.11.6.2)
|
||||
*
|
||||
* @param cause native Java {@code Throwable} that is the cause of error
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void rangeError(final Throwable cause, final String msgId, final String... args) {
|
||||
rangeError(Context.getGlobalTrusted(), cause, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a range error (ECMA 15.11.6.2)
|
||||
*
|
||||
@ -176,6 +248,16 @@ public final class ECMAErrors {
|
||||
throwError(((GlobalObject)global).newRangeError(msg), cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a reference error (ECMA 15.11.6.3)
|
||||
*
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void referenceError(final String msgId, final String... args) {
|
||||
referenceError(Context.getGlobalTrusted(), msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a reference error (ECMA 15.11.6.3)
|
||||
*
|
||||
@ -187,6 +269,17 @@ public final class ECMAErrors {
|
||||
referenceError(global, null, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a reference error (ECMA 15.11.6.3)
|
||||
*
|
||||
* @param cause native Java {@code Throwable} that is the cause of error
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void referenceError(final Throwable cause, final String msgId, final String... args) {
|
||||
referenceError(Context.getGlobalTrusted(), cause, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a reference error (ECMA 15.11.6.3)
|
||||
*
|
||||
@ -200,6 +293,16 @@ public final class ECMAErrors {
|
||||
throwError(((GlobalObject)global).newReferenceError(msg), cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a URI error (ECMA 15.11.6.6)
|
||||
*
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void uriError(final String msgId, final String... args) {
|
||||
uriError(Context.getGlobalTrusted(), msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a URI error (ECMA 15.11.6.6)
|
||||
*
|
||||
@ -211,6 +314,17 @@ public final class ECMAErrors {
|
||||
uriError(global, null, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a URI error (ECMA 15.11.6.6)
|
||||
*
|
||||
* @param cause native Java {@code Throwable} that is the cause of error
|
||||
* @param msgId resource tag for error message
|
||||
* @param args arguments to resource
|
||||
*/
|
||||
public static void uriError(final Throwable cause, final String msgId, final String... args) {
|
||||
uriError(Context.getGlobalTrusted(), cause, msgId, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw a URI error (ECMA 15.11.6.6)
|
||||
*
|
||||
|
||||
@ -79,7 +79,7 @@ public class ErrorManager {
|
||||
}
|
||||
|
||||
if (limit != 0 && count > limit) {
|
||||
rangeError(Context.getGlobal(), "too.many.errors", Integer.toString(limit));
|
||||
rangeError("too.many.errors", Integer.toString(limit));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -248,7 +248,7 @@ public enum JSType {
|
||||
final Object result = sobj.getDefaultValue(hint);
|
||||
|
||||
if (!isPrimitive(result)) {
|
||||
typeError(Context.getGlobal(), "bad.default.value", result.toString());
|
||||
typeError("bad.default.value", result.toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -798,6 +798,19 @@ public enum JSType {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object conversion. This is used to convert objects and numbers to their corresponding
|
||||
* NativeObject type
|
||||
* See ECMA 9.9 ToObject
|
||||
*
|
||||
* @param obj the object to convert
|
||||
*
|
||||
* @return the wrapped object
|
||||
*/
|
||||
public static Object toScriptObject(final Object obj) {
|
||||
return toScriptObject(Context.getGlobalTrusted(), obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Object conversion. This is used to convert objects and numbers to their corresponding
|
||||
* NativeObject type
|
||||
@ -808,7 +821,7 @@ public enum JSType {
|
||||
*
|
||||
* @return the wrapped object
|
||||
*/
|
||||
public static Object toObject(final ScriptObject global, final Object obj) {
|
||||
public static Object toScriptObject(final ScriptObject global, final Object obj) {
|
||||
if (nullOrUndefined(obj)) {
|
||||
typeError(global, "not.an.object", ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
@ -851,7 +864,7 @@ public enum JSType {
|
||||
if (obj instanceof ScriptObject) {
|
||||
if (safe) {
|
||||
final ScriptObject sobj = (ScriptObject)obj;
|
||||
final GlobalObject gobj = (GlobalObject)Context.getGlobal();
|
||||
final GlobalObject gobj = (GlobalObject)Context.getGlobalTrusted();
|
||||
return gobj.isError(sobj) ?
|
||||
ECMAException.safeToString(sobj) :
|
||||
sobj.safeToString();
|
||||
|
||||
@ -127,6 +127,13 @@ public final class ParserException extends NashornException {
|
||||
this.errorType = errorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw this {@code ParserException} as one of the 7 native JavaScript errors
|
||||
*/
|
||||
public void throwAsEcmaException() {
|
||||
ECMAErrors.throwAsEcmaException(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw this {@code ParserException} as one of the 7 native JavaScript errors
|
||||
* @param global global scope object
|
||||
|
||||
@ -289,7 +289,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
@Override
|
||||
public boolean isInstance(final ScriptObject instance) {
|
||||
if (!(prototype instanceof ScriptObject)) {
|
||||
typeError(Context.getGlobal(), "prototype.not.an.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(prototype));
|
||||
typeError("prototype.not.an.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(prototype));
|
||||
}
|
||||
|
||||
for (ScriptObject proto = instance.getProto(); proto != null; proto = proto.getProto()) {
|
||||
@ -401,7 +401,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
*/
|
||||
public Object construct(final Object self, final Object... args) throws Throwable {
|
||||
if (constructHandle == null) {
|
||||
typeError(Context.getGlobal(), "not.a.constructor", ScriptRuntime.safeToString(this));
|
||||
typeError("not.a.constructor", ScriptRuntime.safeToString(this));
|
||||
}
|
||||
|
||||
if (isVarArg(constructHandle)) {
|
||||
@ -480,7 +480,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
}
|
||||
|
||||
if (getConstructHandle() == null) {
|
||||
typeError(Context.getGlobal(), "not.a.constructor", ScriptRuntime.safeToString(this));
|
||||
typeError("not.a.constructor", ScriptRuntime.safeToString(this));
|
||||
}
|
||||
|
||||
ScriptObject object = null;
|
||||
@ -863,7 +863,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
MethodHandle constructor = getConstructHandle(type);
|
||||
|
||||
if (constructor == null) {
|
||||
typeError(Context.getGlobal(), "not.a.constructor", ScriptRuntime.safeToString(this));
|
||||
typeError("not.a.constructor", ScriptRuntime.safeToString(this));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -925,7 +925,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
|
||||
if(NashornCallSiteDescriptor.isScope(desc)) {
|
||||
// (this, callee, args...) => (callee, args...) => (callee, [this], args...)
|
||||
boundHandle = MH.bindTo(callHandle, isNonStrictFunction() ? Context.getGlobal(): ScriptRuntime.UNDEFINED);
|
||||
boundHandle = MH.bindTo(callHandle, isNonStrictFunction() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED);
|
||||
boundHandle = MH.dropArguments(boundHandle, 1, Object.class);
|
||||
} else {
|
||||
// (this, callee, args...) permute => (callee, this, args...) which is what we get in
|
||||
@ -943,7 +943,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
final MethodHandle callHandle = getBestSpecializedInvokeHandle(type.dropParameterTypes(0, 1));
|
||||
|
||||
if(NashornCallSiteDescriptor.isScope(desc)) {
|
||||
boundHandle = MH.bindTo(callHandle, isNonStrictFunction()? Context.getGlobal() : ScriptRuntime.UNDEFINED);
|
||||
boundHandle = MH.bindTo(callHandle, isNonStrictFunction()? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED);
|
||||
boundHandle = MH.dropArguments(boundHandle, 0, Object.class, Object.class);
|
||||
} else {
|
||||
boundHandle = MH.dropArguments(callHandle, 0, Object.class);
|
||||
@ -952,7 +952,7 @@ public abstract class ScriptFunction extends ScriptObject {
|
||||
|
||||
boundHandle = pairArguments(boundHandle, type);
|
||||
return new NashornGuardedInvocation(boundHandle, null, NashornGuards.getFunctionGuard(this), isNonStrictFunction());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for noSuchMethod/noSuchProperty and JSAdapter hooks.
|
||||
|
||||
@ -274,7 +274,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
* @return property descriptor
|
||||
*/
|
||||
public final PropertyDescriptor toPropertyDescriptor() {
|
||||
final GlobalObject global = (GlobalObject) Context.getGlobal();
|
||||
final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
|
||||
|
||||
final PropertyDescriptor desc;
|
||||
if (isDataDescriptor()) {
|
||||
@ -324,7 +324,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
public Object getOwnPropertyDescriptor(final String key) {
|
||||
final Property property = getMap().findProperty(key);
|
||||
|
||||
final GlobalObject global = (GlobalObject)Context.getGlobal();
|
||||
final GlobalObject global = (GlobalObject)Context.getGlobalTrusted();
|
||||
|
||||
if (property != null) {
|
||||
final ScriptFunction get = property.getGetterFunction(this);
|
||||
@ -389,7 +389,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
* @return true if property was successfully defined
|
||||
*/
|
||||
public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) {
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final ScriptObject global = Context.getGlobalTrusted();
|
||||
final PropertyDescriptor desc = toPropertyDescriptor(global, propertyDesc);
|
||||
final Object current = getOwnPropertyDescriptor(key);
|
||||
final String name = JSType.toString(key);
|
||||
@ -594,7 +594,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
final int propFlags = Property.toFlags(pdesc);
|
||||
|
||||
if (pdesc.type() == PropertyDescriptor.GENERIC) {
|
||||
final GlobalObject global = (GlobalObject) Context.getGlobal();
|
||||
final GlobalObject global = (GlobalObject) Context.getGlobalTrusted();
|
||||
final PropertyDescriptor dDesc = global.newDataDescriptor(UNDEFINED, false, false, false);
|
||||
|
||||
dDesc.fillFrom((ScriptObject)pdesc);
|
||||
@ -1142,8 +1142,8 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
if (newProto == null || newProto instanceof ScriptObject) {
|
||||
setProto((ScriptObject)newProto);
|
||||
} else {
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final Object newProtoObject = JSType.toObject(global, newProto);
|
||||
final ScriptObject global = Context.getGlobalTrusted();
|
||||
final Object newProtoObject = JSType.toScriptObject(global, newProto);
|
||||
|
||||
if (newProtoObject instanceof ScriptObject) {
|
||||
setProto((ScriptObject)newProtoObject);
|
||||
@ -1246,7 +1246,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
// "valueOf" methods, and in order to avoid those call sites from becoming megamorphic when multiple contexts
|
||||
// are being executed in a long-running program, we move the code and their associated dynamic call sites
|
||||
// (Global.TO_STRING and Global.VALUE_OF) into per-context code.
|
||||
return ((GlobalObject)Context.getGlobal()).getDefaultValue(this, typeHint);
|
||||
return ((GlobalObject)Context.getGlobalTrusted()).getDefaultValue(this, typeHint);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1575,7 +1575,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
}
|
||||
|
||||
private GuardedInvocation notAFunction() {
|
||||
typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(this));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(this));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1754,7 +1754,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
private GuardedInvocation createEmptySetMethod(final CallSiteDescriptor desc, String strictErrorMessage, boolean canBeFastScope) {
|
||||
final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
|
||||
if (NashornCallSiteDescriptor.isStrict(desc)) {
|
||||
typeError(Context.getGlobal(), strictErrorMessage, name, ScriptRuntime.safeToString((this)));
|
||||
typeError(strictErrorMessage, name, ScriptRuntime.safeToString((this)));
|
||||
}
|
||||
assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc);
|
||||
final PropertyMap myMap = getMap();
|
||||
@ -1781,7 +1781,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
private boolean trySetEmbedOrSpill(final CallSiteDescriptor desc, final PropertyMap oldMap, final PropertyMap newMap, final Object value) {
|
||||
final boolean isStrict = NashornCallSiteDescriptor.isStrict(desc);
|
||||
if (!isExtensible() && isStrict) {
|
||||
typeError(Context.getGlobal(), "object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(this));
|
||||
typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(this));
|
||||
throw new AssertionError(); // never reached
|
||||
} else if (compareAndSetMap(oldMap, newMap)) {
|
||||
return true;
|
||||
@ -1798,7 +1798,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
|
||||
if (!obj.isExtensible()) {
|
||||
if (isStrict) {
|
||||
typeError(Context.getGlobal(), "object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
|
||||
typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
} else if (obj.compareAndSetMap(oldMap, newMap)) {
|
||||
obj.spill = new Object[SPILL_RATE];
|
||||
@ -1815,7 +1815,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
|
||||
if (!obj.isExtensible()) {
|
||||
if (isStrict) {
|
||||
typeError(Context.getGlobal(), "object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
|
||||
typeError("object.non.extensible", desc.getNameToken(2), ScriptRuntime.safeToString(obj));
|
||||
}
|
||||
} else if (obj.compareAndSetMap(oldMap, newMap)) {
|
||||
final int oldLength = obj.spill.length;
|
||||
@ -1870,7 +1870,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
|
||||
if (find == null) {
|
||||
if (scopeCall) {
|
||||
ECMAErrors.referenceError(Context.getGlobal(), "not.defined", name);
|
||||
ECMAErrors.referenceError("not.defined", name);
|
||||
throw new AssertionError(); // never reached
|
||||
}
|
||||
return createEmptyGetter(desc, name);
|
||||
@ -1909,7 +1909,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
}
|
||||
|
||||
if (scopeAccess) {
|
||||
referenceError(Context.getGlobal(), "not.defined", name);
|
||||
referenceError("not.defined", name);
|
||||
}
|
||||
|
||||
return createEmptyGetter(desc, name);
|
||||
@ -2510,7 +2510,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
if (longIndex >= oldLength) {
|
||||
if (!isExtensible()) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this));
|
||||
typeError("object.non.extensible", JSType.toString(index), ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2559,7 +2559,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
if (f != null) {
|
||||
if (!f.isWritable()) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "property.not.writable", key, ScriptRuntime.safeToString(this));
|
||||
typeError("property.not.writable", key, ScriptRuntime.safeToString(this));
|
||||
}
|
||||
|
||||
return;
|
||||
@ -2575,7 +2575,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
}
|
||||
} else if (!isExtensible()) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "object.non.extensible", key, ScriptRuntime.safeToString(this));
|
||||
typeError("object.non.extensible", key, ScriptRuntime.safeToString(this));
|
||||
}
|
||||
} else {
|
||||
spill(key, value);
|
||||
@ -3062,7 +3062,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
|
||||
if (!find.isConfigurable()) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "cant.delete.property", propName, ScriptRuntime.safeToString(this));
|
||||
typeError("cant.delete.property", propName, ScriptRuntime.safeToString(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -3232,7 +3232,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
} else if (name != null) {
|
||||
typeError(Context.getGlobal(), "property.has.no.setter", name, ScriptRuntime.safeToString(self));
|
||||
typeError("property.has.no.setter", name, ScriptRuntime.safeToString(self));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -385,14 +385,14 @@ public final class ScriptRuntime {
|
||||
* @return {@link WithObject} that is the new scope
|
||||
*/
|
||||
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final ScriptObject global = Context.getGlobalTrusted();
|
||||
if (expression == UNDEFINED) {
|
||||
typeError(global, "cant.apply.with.to.undefined");
|
||||
} else if (expression == null) {
|
||||
typeError(global, "cant.apply.with.to.null");
|
||||
}
|
||||
|
||||
final ScriptObject withObject = new WithObject(scope, JSType.toObject(global, expression));
|
||||
final ScriptObject withObject = new WithObject(scope, JSType.toScriptObject(global, expression));
|
||||
|
||||
return withObject;
|
||||
}
|
||||
@ -488,9 +488,9 @@ public final class ScriptRuntime {
|
||||
} else if (object instanceof Undefined) {
|
||||
obj = ((Undefined)obj).get(property);
|
||||
} else if (object == null) {
|
||||
typeError(Context.getGlobal(), "cant.get.property", safeToString(property), "null");
|
||||
typeError("cant.get.property", safeToString(property), "null");
|
||||
} else if (JSType.isPrimitive(obj)) {
|
||||
obj = ((ScriptObject)JSType.toObject(Context.getGlobal(), obj)).get(property);
|
||||
obj = ((ScriptObject)JSType.toScriptObject(obj)).get(property);
|
||||
} else {
|
||||
obj = UNDEFINED;
|
||||
}
|
||||
@ -526,7 +526,7 @@ public final class ScriptRuntime {
|
||||
* @return undefined
|
||||
*/
|
||||
public static Object REFERENCE_ERROR(final Object lhs, final Object rhs, final Object msg) {
|
||||
referenceError(Context.getGlobal(), "cant.be.used.as.lhs", Objects.toString(msg));
|
||||
referenceError("cant.be.used.as.lhs", Objects.toString(msg));
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -549,11 +549,11 @@ public final class ScriptRuntime {
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
typeError(Context.getGlobal(), "cant.delete.property", safeToString(property), "null");
|
||||
typeError("cant.delete.property", safeToString(property), "null");
|
||||
}
|
||||
|
||||
if (JSType.isPrimitive(obj)) {
|
||||
return ((ScriptObject) JSType.toObject(Context.getGlobal(), obj)).delete(property, Boolean.TRUE.equals(strict));
|
||||
return ((ScriptObject) JSType.toScriptObject(obj)).delete(property, Boolean.TRUE.equals(strict));
|
||||
}
|
||||
|
||||
// if object is not reference type, vacuously delete is successful.
|
||||
@ -574,7 +574,7 @@ public final class ScriptRuntime {
|
||||
*/
|
||||
public static boolean FAIL_DELETE(final Object obj, final Object property, final Object strict) {
|
||||
if (Boolean.TRUE.equals(strict)) {
|
||||
syntaxError(Context.getGlobal(), "strict.cant.delete", safeToString(property));
|
||||
syntaxError("strict.cant.delete", safeToString(property));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -751,7 +751,7 @@ public final class ScriptRuntime {
|
||||
return false;
|
||||
}
|
||||
|
||||
typeError(Context.getGlobal(), "in.with.non.object", rvalType.toString().toLowerCase());
|
||||
typeError("in.with.non.object", rvalType.toString().toLowerCase());
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -776,7 +776,7 @@ public final class ScriptRuntime {
|
||||
return ((StaticClass)clazz).getRepresentedClass().isInstance(obj);
|
||||
}
|
||||
|
||||
typeError(Context.getGlobal(), "instanceof.on.non.object");
|
||||
typeError("instanceof.on.non.object");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public class ScriptingFunctions {
|
||||
}
|
||||
|
||||
if (f == null || !f.isFile()) {
|
||||
typeError(Context.getGlobal(), "not.a.file", ScriptRuntime.safeToString(file));
|
||||
typeError("not.a.file", ScriptRuntime.safeToString(file));
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@ class SetMethodCreator {
|
||||
// In strict mode, assignment can not create a new variable.
|
||||
// See also ECMA Annex C item 4. ReferenceError is thrown.
|
||||
if (NashornCallSiteDescriptor.isScope(desc) && NashornCallSiteDescriptor.isStrict(desc)) {
|
||||
referenceError(Context.getGlobal(), "not.defined", getName());
|
||||
referenceError("not.defined", getName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ class SetMethodCreator {
|
||||
}
|
||||
|
||||
private SetMethod createGlobalPropertySetter() {
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final ScriptObject global = Context.getGlobalTrusted();
|
||||
return new SetMethod(ScriptObject.bindTo(global.addSpill(getName()), global), null, false);
|
||||
}
|
||||
|
||||
|
||||
@ -71,7 +71,7 @@ public final class URIUtils {
|
||||
}
|
||||
|
||||
if (C >= 0xDC00 && C <= 0xDFFF) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
int V;
|
||||
@ -80,12 +80,12 @@ public final class URIUtils {
|
||||
} else {
|
||||
k++;
|
||||
if (k == len) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
final char kChar = string.charAt(k);
|
||||
if (kChar < 0xDC00 || kChar > 0xDFFF) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
V = ((C - 0xD800) * 0x400 + (kChar - 0xDC00) + 0x10000);
|
||||
}
|
||||
@ -93,7 +93,7 @@ public final class URIUtils {
|
||||
try {
|
||||
sb.append(toHexEscape(V));
|
||||
} catch (final Exception e) {
|
||||
uriError(Context.getGlobal(), e, "bad.uri", string, Integer.toString(k));
|
||||
uriError( e, "bad.uri", string, Integer.toString(k));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -118,12 +118,12 @@ public final class URIUtils {
|
||||
}
|
||||
final int start = k;
|
||||
if (k + 2 >= len) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
int B = toHexByte(string.charAt(k + 1), string.charAt(k + 2));
|
||||
if (B < 0) {
|
||||
return error(Context.getGlobal(), string, k + 1);
|
||||
return error(string, k + 1);
|
||||
}
|
||||
|
||||
k += 2;
|
||||
@ -146,11 +146,11 @@ public final class URIUtils {
|
||||
}
|
||||
|
||||
if (n == 1 || n > 4) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
if ((k + (3 * (n - 1))) >= len) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
final byte[] bbuf = new byte[n];
|
||||
@ -159,16 +159,16 @@ public final class URIUtils {
|
||||
for (int j = 1; j < n; j++) {
|
||||
k++;
|
||||
if (string.charAt(k) != '%') {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
if (k + 2 == len) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
|
||||
B = toHexByte(string.charAt(k + 1), string.charAt(k + 2));
|
||||
if (B < 0 || (B & 0xC0) != 0x80) {
|
||||
return error(Context.getGlobal(), string, k + 1);
|
||||
return error(string, k + 1);
|
||||
}
|
||||
|
||||
k += 2;
|
||||
@ -179,7 +179,7 @@ public final class URIUtils {
|
||||
try {
|
||||
V = ucs4Char(bbuf);
|
||||
} catch (final Exception e) {
|
||||
uriError(Context.getGlobal(), e, "bad.uri", string, Integer.toString(k));
|
||||
uriError(e, "bad.uri", string, Integer.toString(k));
|
||||
return null;
|
||||
}
|
||||
if (V < 0x10000) {
|
||||
@ -193,7 +193,7 @@ public final class URIUtils {
|
||||
}
|
||||
} else { // V >= 0x10000
|
||||
if (V > 0x10FFFF) {
|
||||
return error(Context.getGlobal(), string, k);
|
||||
return error(string, k);
|
||||
}
|
||||
final int L = ((V - 0x10000) & 0x3FF) + 0xDC00;
|
||||
final int H = (((V - 0x10000) >> 10) & 0x3FF) + 0xD800;
|
||||
@ -268,8 +268,8 @@ public final class URIUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String error(final ScriptObject global, final String string, final int index) {
|
||||
uriError(global, "bad.uri", string, Integer.toString(index));
|
||||
private static String error(final String string, final int index) {
|
||||
uriError("bad.uri", string, Integer.toString(index));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ public final class Undefined extends DefaultPropertyAccess {
|
||||
}
|
||||
|
||||
private static void lookupTypeError(final String msg, final CallSiteDescriptor desc) {
|
||||
typeError(Context.getGlobal(), msg, desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null);
|
||||
typeError(msg, desc.getNameTokenCount() > 2 ? desc.getNameToken(2) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,18 +174,18 @@ public final class Undefined extends DefaultPropertyAccess {
|
||||
|
||||
@Override
|
||||
public Object get(final Object key) {
|
||||
typeError(Context.getGlobal(), "cant.read.property.of.undefined", ScriptRuntime.safeToString(key));
|
||||
typeError("cant.read.property.of.undefined", ScriptRuntime.safeToString(key));
|
||||
return ScriptRuntime.UNDEFINED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(final Object key, final Object value, final boolean strict) {
|
||||
typeError(Context.getGlobal(), "cant.set.property.of.undefined", ScriptRuntime.safeToString(key));
|
||||
typeError("cant.set.property.of.undefined", ScriptRuntime.safeToString(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(final Object key, final boolean strict) {
|
||||
typeError(Context.getGlobal(), "cant.delete.property.of.undefined", ScriptRuntime.safeToString(key));
|
||||
typeError("cant.delete.property.of.undefined", ScriptRuntime.safeToString(key));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ abstract public class ArrayLikeIterator<T> implements Iterator<T> {
|
||||
return new ArrayIterator((ScriptObject) obj, includeUndefined);
|
||||
}
|
||||
|
||||
obj = JSType.toObject(Context.getGlobal(), obj);
|
||||
obj = JSType.toScriptObject(obj);
|
||||
if (obj instanceof ScriptObject) {
|
||||
return new MapIterator((ScriptObject)obj, includeUndefined);
|
||||
}
|
||||
@ -143,7 +143,7 @@ abstract public class ArrayLikeIterator<T> implements Iterator<T> {
|
||||
return new ReverseArrayIterator((ScriptObject) obj, includeUndefined);
|
||||
}
|
||||
|
||||
obj = JSType.toObject(Context.getGlobal(), obj);
|
||||
obj = JSType.toScriptObject(obj);
|
||||
if (obj instanceof ScriptObject) {
|
||||
return new ReverseMapIterator((ScriptObject)obj, includeUndefined);
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ final class FrozenArrayFilter extends SealedArrayFilter {
|
||||
@Override
|
||||
public ArrayData set(final int index, final int value, final boolean strict) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
|
||||
typeError("cant.set.property", Integer.toString(index), "frozen array");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -55,7 +55,7 @@ final class FrozenArrayFilter extends SealedArrayFilter {
|
||||
@Override
|
||||
public ArrayData set(final int index, final long value, final boolean strict) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
|
||||
typeError("cant.set.property", Integer.toString(index), "frozen array");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -63,7 +63,7 @@ final class FrozenArrayFilter extends SealedArrayFilter {
|
||||
@Override
|
||||
public ArrayData set(final int index, final double value, final boolean strict) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
|
||||
typeError("cant.set.property", Integer.toString(index), "frozen array");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -71,7 +71,7 @@ final class FrozenArrayFilter extends SealedArrayFilter {
|
||||
@Override
|
||||
public ArrayData set(final int index, final Object value, final boolean strict) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "cant.set.property", Integer.toString(index), "frozen array");
|
||||
typeError("cant.set.property", Integer.toString(index), "frozen array");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ public abstract class IteratorAction<T> {
|
||||
*/
|
||||
public final T apply() {
|
||||
if (!(callbackfn instanceof ScriptFunction)) {
|
||||
typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(callbackfn));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(callbackfn));
|
||||
return result;
|
||||
}
|
||||
final ScriptFunction func = ((ScriptFunction)callbackfn);
|
||||
@ -136,4 +136,5 @@ public abstract class IteratorAction<T> {
|
||||
* @throws Throwable if invocation throws an exception/error
|
||||
*/
|
||||
protected abstract boolean forEach(final Object val, final int i) throws Throwable;
|
||||
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ class SealedArrayFilter extends ArrayFilter {
|
||||
@Override
|
||||
public boolean canDelete(final int index, final boolean strict) {
|
||||
if (strict) {
|
||||
typeError(Context.getGlobal(), "cant.delete.property", Integer.toString(index), "sealed array");
|
||||
typeError("cant.delete.property", Integer.toString(index), "sealed array");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -430,6 +430,21 @@ public final class JavaAdapterFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the given Class is an adapter or support class
|
||||
* @param clazz Class object
|
||||
* @return true if the Class given is adapter or support class
|
||||
*/
|
||||
public static boolean isAdapterClass(Class<?> clazz) {
|
||||
return clazz.getClassLoader() instanceof AdapterLoader;
|
||||
}
|
||||
|
||||
private static class AdapterLoader extends SecureClassLoader {
|
||||
AdapterLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
}
|
||||
|
||||
// Creation of class loader is in a separate static method so that it doesn't retain a reference to the factory
|
||||
// instance. Note that the adapter class is created in the protection domain of the class/interface being
|
||||
// extended/implemented, and only the privileged global setter action class is generated in the protection domain
|
||||
@ -440,7 +455,7 @@ public final class JavaAdapterFactory {
|
||||
// security tradeoff...
|
||||
private static ClassLoader createClassLoader(final ClassLoader parentLoader, final String className,
|
||||
final byte[] classBytes, final String privilegedActionClassName) {
|
||||
return new SecureClassLoader(parentLoader) {
|
||||
return new AdapterLoader(parentLoader) {
|
||||
@Override
|
||||
protected Class<?> findClass(final String name) throws ClassNotFoundException {
|
||||
if(name.equals(className)) {
|
||||
@ -688,7 +703,7 @@ public final class JavaAdapterFactory {
|
||||
*/
|
||||
public static MethodHandle getHandle(final Object obj, final String name, final MethodType type, final boolean varArg) {
|
||||
if (! (obj instanceof ScriptObject)) {
|
||||
typeError(Context.getGlobal(), "not.an.object", ScriptRuntime.safeToString(obj));
|
||||
typeError("not.an.object", ScriptRuntime.safeToString(obj));
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@ -704,7 +719,7 @@ public final class JavaAdapterFactory {
|
||||
} else if(fnObj == null || fnObj instanceof Undefined) {
|
||||
return null;
|
||||
} else {
|
||||
typeError(Context.getGlobal(), "not.a.function", name);
|
||||
typeError("not.a.function", name);
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
@ -1076,7 +1091,7 @@ public final class JavaAdapterFactory {
|
||||
|
||||
void typeError() {
|
||||
assert adaptationOutcome != AdaptationOutcome.SUCCESS;
|
||||
ECMAErrors.typeError(Context.getGlobal(), "extend." + adaptationOutcome, classList);
|
||||
ECMAErrors.typeError("extend." + adaptationOutcome, classList);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1219,7 +1234,7 @@ public final class JavaAdapterFactory {
|
||||
while(it.hasNext()) {
|
||||
b.append(", ").append(it.next().clazz.getCanonicalName());
|
||||
}
|
||||
typeError(Context.getGlobal(), "extend.ambiguous.defining.class", b.toString());
|
||||
typeError("extend.ambiguous.defining.class", b.toString());
|
||||
throw new AssertionError(); // never reached
|
||||
}
|
||||
|
||||
|
||||
@ -34,7 +34,6 @@ import java.lang.invoke.MethodHandles;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.runtime.ConsString;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import org.dynalang.dynalink.support.TypeUtilities;
|
||||
@ -110,7 +109,7 @@ public class JavaArgumentConverters {
|
||||
return Character.valueOf((char) ival);
|
||||
}
|
||||
|
||||
typeError(Context.getGlobal(), "cant.convert.number.to.char");
|
||||
typeError("cant.convert.number.to.char");
|
||||
}
|
||||
|
||||
final String s = toString(o);
|
||||
@ -119,7 +118,7 @@ public class JavaArgumentConverters {
|
||||
}
|
||||
|
||||
if (s.length() != 1) {
|
||||
typeError(Context.getGlobal(), "cant.convert.string.to.char");
|
||||
typeError("cant.convert.string.to.char");
|
||||
}
|
||||
|
||||
return s.charAt(0);
|
||||
|
||||
@ -31,7 +31,6 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.Property;
|
||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||
@ -112,7 +111,7 @@ public final class Lookup {
|
||||
* @return undefined (but throws error before return point)
|
||||
*/
|
||||
public static Object typeErrorThrowerGetter(final Object self) {
|
||||
typeError(Context.getGlobal(), "strict.getter.setter.poison", ScriptRuntime.safeToString(self));
|
||||
typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));
|
||||
return UNDEFINED;
|
||||
}
|
||||
|
||||
@ -123,7 +122,7 @@ public final class Lookup {
|
||||
* @param value (ignored)
|
||||
*/
|
||||
public static void typeErrorThrowerSetter(final Object self, final Object value) {
|
||||
typeError(Context.getGlobal(), "strict.getter.setter.poison", ScriptRuntime.safeToString(self));
|
||||
typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -30,8 +30,6 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
|
||||
import static jdk.nashorn.internal.runtime.linker.Lookup.MH;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
import org.dynalang.dynalink.CallSiteDescriptor;
|
||||
import org.dynalang.dynalink.linker.GuardedInvocation;
|
||||
@ -81,21 +79,21 @@ class NashornBottomLinker implements GuardingDynamicLinker {
|
||||
switch (operator) {
|
||||
case "new":
|
||||
if(isJavaDynamicMethod(self)) {
|
||||
typeError(Context.getGlobal(), "method.not.constructor", ScriptRuntime.safeToString(self));
|
||||
typeError("method.not.constructor", ScriptRuntime.safeToString(self));
|
||||
} else {
|
||||
typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
}
|
||||
break;
|
||||
case "call":
|
||||
if(isJavaDynamicMethod(self)) {
|
||||
typeError(Context.getGlobal(), "no.method.matches.args", ScriptRuntime.safeToString(self));
|
||||
typeError("no.method.matches.args", ScriptRuntime.safeToString(self));
|
||||
} else {
|
||||
typeError(Context.getGlobal(), "not.a.function", ScriptRuntime.safeToString(self));
|
||||
typeError("not.a.function", ScriptRuntime.safeToString(self));
|
||||
}
|
||||
break;
|
||||
case "callMethod":
|
||||
case "getMethod":
|
||||
typeError(Context.getGlobal(), "no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
|
||||
typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self));
|
||||
break;
|
||||
case "getProp":
|
||||
case "getElem":
|
||||
@ -136,25 +134,24 @@ class NashornBottomLinker implements GuardingDynamicLinker {
|
||||
}
|
||||
|
||||
private static GuardedInvocation linkNull(final LinkRequest linkRequest) {
|
||||
final ScriptObject global = Context.getGlobal();
|
||||
final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor();
|
||||
final String operator = desc.getFirstOperator();
|
||||
switch (operator) {
|
||||
case "new":
|
||||
case "call":
|
||||
typeError(global, "not.a.function", "null");
|
||||
typeError("not.a.function", "null");
|
||||
break;
|
||||
case "callMethod":
|
||||
case "getMethod":
|
||||
typeError(global, "no.such.function", getArgument(linkRequest), "null");
|
||||
typeError("no.such.function", getArgument(linkRequest), "null");
|
||||
break;
|
||||
case "getProp":
|
||||
case "getElem":
|
||||
typeError(global, "cant.get.property", getArgument(linkRequest), "null");
|
||||
typeError("cant.get.property", getArgument(linkRequest), "null");
|
||||
break;
|
||||
case "setProp":
|
||||
case "setElem":
|
||||
typeError(global, "cant.set.property", getArgument(linkRequest), "null");
|
||||
typeError("cant.set.property", getArgument(linkRequest), "null");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
|
||||
package jdk.nashorn.internal.runtime.linker;
|
||||
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ECMAErrors;
|
||||
import org.dynalang.dynalink.CallSiteDescriptor;
|
||||
import org.dynalang.dynalink.beans.BeansLinker;
|
||||
@ -94,7 +93,7 @@ class NashornStaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
||||
|
||||
private static GuardedInvocation checkNullConstructor(final GuardedInvocation ctorInvocation, final Class<?> receiverClass) {
|
||||
if(ctorInvocation == null) {
|
||||
ECMAErrors.typeError(Context.getGlobal(), "no.constructor.matches.args", receiverClass.getName());
|
||||
ECMAErrors.typeError("no.constructor.matches.args", receiverClass.getName());
|
||||
}
|
||||
return ctorInvocation;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user