Re: Small usage simplification for Rhino
       Date:
            Mon, 22 Jan 2001 20:32:12 +0100
      From:
            Igor Bukanov <igor@icesoft.no>
        To:
            Norris Boyd <nboyd@atg.com>
 References:
            1 , 2




Norris Boyd wrote:

> Sounds like a good change to reduce codesize. I'll take the patches for the
> changes.
>
> Thanks,
> Norris

I made this patch, the files in the attachment were produced via:
diff -bB javascript.orig javascript -c > patch_context
and
diff -bB javascript.orig javascript > patch_std

run from org/mozilla directory.

This patch reduces uncopressed Rhino jar by 3K.

>
> Igor Bukanov wrote:
>
>
>> Hi, Noris!
>>
>> To shorten/cleanup usage of getMessage and reportRuntimeError methods
>> from org/mozilla/javascript/Context.java I suggest to add few utility
>> methods like
>>
>>      static String getMessage0(String messageId) {
>>          return getMessage(messageId, null);
>>      }
>>
>>      static String getMessage1(String messageId, Object arg1) {
>>          Object[] arguments = {arg1};
>>          return getMessage(messageId, arguments);
>>      }
>>
>>      static String getMessage2(String messageId, Object arg1, Object arg2) {
>>          Object[] arguments = {arg1, arg2};
>>          return getMessage(messageId, arguments);
>>      }
>>
>>      static String getMessage3
>>          (String messageId, Object arg1, Object arg2, Object arg3) {
>>          Object[] arguments = {arg1, arg2, arg3};
>>          return getMessage(messageId, arguments);
>>      }
>>
>> and
>>
>>      static EvaluatorException reportRuntimeError0(String messageId) {
>>          return reportRuntimeError(getMessage0(messageId));
>>      }
>>
>>      static EvaluatorException reportRuntimeError1
>>          (String messageId, Object arg1)
>>      {
>>          return reportRuntimeError(getMessage1(messageId, arg1));
>>      }
>>
>>      static EvaluatorException reportRuntimeError2
>>          (String messageId, Object arg1, Object arg2)
>>      {
>>          return reportRuntimeError(getMessage2(messageId, arg1, arg2));
>>      }
>>
>>      static EvaluatorException reportRuntimeError3
>>          (String messageId, Object arg1, Object arg2, Object arg3)
>>      {
>>          return reportRuntimeError(getMessage3(messageId, arg1, arg2,
>> arg3));
>>      }
>>
>> This allows to write, for example, instead of
>>
>>               Object[] args = { Integer.toString(base) };
>>               throw Context.reportRuntimeError(getMessage
>>                                                ("msg.bad.radix", args));
>> simply
>>               throw Context.reportRuntimeError1(
>>                   "msg.bad.radix", Integer.toString(base));
>>
>> which is not only easy to read but also generates less code.
>>
>> I attach my patch to Context.java to implement this plus a patch to
>> ScriptRuntime.java that utilizes the additions. The patches are in
>> standard and context versions.
>>
>> If you think that this make sense to incorporate, I can send a patch
>> that utilizes this everywhere.
>>
>>   ------------------------------------------------------------------------
>>                                  Name: patch.context.Context.java
>>    patch.context.Context.java    Type: Plain Text (text/plain)
>>                              Encoding: base64
>>
>>                              Name: patch.std.Context.java
>>    patch.std.Context.java    Type: Plain Text (text/plain)
>>                          Encoding: base64
>>
>>                                        Name: patch.context.ScriptRuntime.java
>>    patch.context.ScriptRuntime.java    Type: Plain Text (text/plain)
>>                                    Encoding: base64
>>
>>                                    Name: patch.std.ScriptRuntime.java
>>    patch.std.ScriptRuntime.java    Type: Plain Text (text/plain)
>>                                Encoding: base64
>>
>>               Name: all.zip
>>    all.zip    Type: Zip Compressed Data (application/x-zip-compressed)
>>           Encoding: base64
This commit is contained in:
nboyd%atg.com 2001-01-22 20:28:34 +00:00
Родитель 02192bd867
Коммит e737c6d867
54 изменённых файлов: 528 добавлений и 604 удалений

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

@ -532,6 +532,28 @@ public final class Context {
} }
} }
static EvaluatorException reportRuntimeError0(String messageId) {
return reportRuntimeError(getMessage0(messageId));
}
static EvaluatorException reportRuntimeError1
(String messageId, Object arg1)
{
return reportRuntimeError(getMessage1(messageId, arg1));
}
static EvaluatorException reportRuntimeError2
(String messageId, Object arg1, Object arg2)
{
return reportRuntimeError(getMessage2(messageId, arg1, arg2));
}
static EvaluatorException reportRuntimeError3
(String messageId, Object arg1, Object arg2, Object arg3)
{
return reportRuntimeError(getMessage3(messageId, arg1, arg2, arg3));
}
/** /**
* Report a runtime error using the error reporter for the current thread. * Report a runtime error using the error reporter for the current thread.
* *
@ -1010,13 +1032,11 @@ public final class Context {
{ {
Object ctorVal = ScriptRuntime.getTopLevelProp(scope, constructorName); Object ctorVal = ScriptRuntime.getTopLevelProp(scope, constructorName);
if (ctorVal == Scriptable.NOT_FOUND) { if (ctorVal == Scriptable.NOT_FOUND) {
Object[] errArgs = { constructorName }; String message = getMessage1("msg.ctor.not.found", constructorName);
String message = getMessage("msg.ctor.not.found", errArgs);
throw new PropertyException(message); throw new PropertyException(message);
} }
if (!(ctorVal instanceof Function)) { if (!(ctorVal instanceof Function)) {
Object[] errArgs = { constructorName }; String message = getMessage1("msg.not.ctor", constructorName);
String message = getMessage("msg.not.ctor", errArgs);
throw new NotAFunctionException(message); throw new NotAFunctionException(message);
} }
Function ctor = (Function) ctorVal; Function ctor = (Function) ctorVal;
@ -1528,6 +1548,26 @@ public final class Context {
} }
static String getMessage0(String messageId) {
return getMessage(messageId, null);
}
static String getMessage1(String messageId, Object arg1) {
Object[] arguments = {arg1};
return getMessage(messageId, arguments);
}
static String getMessage2(String messageId, Object arg1, Object arg2) {
Object[] arguments = {arg1, arg2};
return getMessage(messageId, arguments);
}
static String getMessage3
(String messageId, Object arg1, Object arg2, Object arg3) {
Object[] arguments = {arg1, arg2, arg3};
return getMessage(messageId, arguments);
}
/** /**
* Internal method that reports an error for missing calls to * Internal method that reports an error for missing calls to
* enter(). * enter().

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

@ -306,8 +306,7 @@ public class FlattenedObject {
JavaScriptException JavaScriptException
{ {
if (!hasProperty(id)) { if (!hasProperty(id)) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
Object o = getProperty(id); Object o = getProperty(id);
if (o instanceof FlattenedObject) if (o instanceof FlattenedObject)

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

@ -138,10 +138,8 @@ public class FunctionObject extends NativeFunction {
types[2] != ScriptRuntime.FunctionClass || types[2] != ScriptRuntime.FunctionClass ||
types[3] != Boolean.TYPE) types[3] != Boolean.TYPE)
{ {
String[] args = { methodName }; throw Context.reportRuntimeError1(
String message = Context.getMessage("msg.varargs.ctor", "msg.varargs.ctor", methodName);
args);
throw Context.reportRuntimeError(message);
} }
parmsLength = VARARGS_CTOR; parmsLength = VARARGS_CTOR;
} else { } else {
@ -151,10 +149,8 @@ public class FunctionObject extends NativeFunction {
types[2].getComponentType() != ScriptRuntime.ObjectClass || types[2].getComponentType() != ScriptRuntime.ObjectClass ||
types[3] != ScriptRuntime.FunctionClass) types[3] != ScriptRuntime.FunctionClass)
{ {
String[] args = { methodName }; throw Context.reportRuntimeError1(
String message = Context.getMessage("msg.varargs.fun", "msg.varargs.fun", methodName);
args);
throw Context.reportRuntimeError(message);
} }
parmsLength = VARARGS_METHOD; parmsLength = VARARGS_METHOD;
} }
@ -176,10 +172,9 @@ public class FunctionObject extends NativeFunction {
type != Float.TYPE && type != Float.TYPE &&
type != Double.TYPE) type != Double.TYPE)
{ {
// Note that long is not supported; see comments above // Note that long is not supported.
Object[] errArgs = { methodName }; throw Context.reportRuntimeError1("msg.bad.parms",
throw Context.reportRuntimeError( methodName);
Context.getMessage("msg.bad.parms", errArgs));
} }
} }
length = parmsLength; length = parmsLength;
@ -426,9 +421,8 @@ public class FunctionObject extends NativeFunction {
// Note that the long type is not supported; see the javadoc for // Note that the long type is not supported; see the javadoc for
// the constructor for this class // the constructor for this class
Object[] errArgs = { desired.getName() }; throw Context.reportRuntimeError1
throw Context.reportRuntimeError( ("msg.cant.convert", desired.getName());
Context.getMessage("msg.cant.convert", errArgs));
} }
/** /**
@ -463,8 +457,8 @@ public class FunctionObject extends NativeFunction {
thisObj = thisObj.getPrototype(); thisObj = thisObj.getPrototype();
if (thisObj == null || !useDynamicScope) { if (thisObj == null || !useDynamicScope) {
// Couldn't find an object to call this on. // Couldn't find an object to call this on.
Object[] errArgs = { names[0] }; String msg = Context.getMessage1
String msg = Context.getMessage("msg.incompat.call", errArgs); ("msg.incompat.call", names[0]);
throw NativeGlobal.constructError(cx, "TypeError", msg, scope); throw NativeGlobal.constructError(cx, "TypeError", msg, scope);
} }
} }

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

@ -1036,10 +1036,10 @@ public class IRFactory {
if (scope != null) if (scope != null)
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError", Context.getContext(), "SyntaxError",
ScriptRuntime.getMessage(msgResource, null), ScriptRuntime.getMessage0(msgResource),
scope); scope);
else { else {
String message = Context.getMessage(msgResource, null); String message = Context.getMessage0(msgResource);
Context.reportError(message, ts.getSourceName(), ts.getLineno(), Context.reportError(message, ts.getSourceName(), ts.getLineno(),
ts.getLine(), ts.getOffset()); ts.getLine(), ts.getOffset());
} }

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

@ -106,10 +106,8 @@ public class ImporterTopLevel extends ScriptableObject {
if (result == NOT_FOUND) { if (result == NOT_FOUND) {
result = v; result = v;
} else { } else {
String[] args = { result.toString(), v.toString() }; throw Context.reportRuntimeError2(
throw Context.reportRuntimeError( "msg.ambig.import", result.toString(), v.toString());
Context.getMessage("msg.ambig.import",
args));
} }
} }
} }
@ -121,15 +119,14 @@ public class ImporterTopLevel extends ScriptableObject {
for (int i=0; i<args.length; i++) { for (int i=0; i<args.length; i++) {
Object cl = args[i]; Object cl = args[i];
if (!(cl instanceof NativeJavaClass)) { if (!(cl instanceof NativeJavaClass)) {
String[] eargs = { Context.toString(cl) }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage("msg.not.class", eargs)); "msg.not.class", Context.toString(cl));
} }
String s = ((NativeJavaClass) cl).getClassObject().getName(); String s = ((NativeJavaClass) cl).getClassObject().getName();
String n = s.substring(s.lastIndexOf('.')+1); String n = s.substring(s.lastIndexOf('.')+1);
Object val = thisObj.get(n, thisObj); Object val = thisObj.get(n, thisObj);
if (val != NOT_FOUND && val != cl) { if (val != NOT_FOUND && val != cl) {
String[] eargs = { n }; throw Context.reportRuntimeError1("msg.prop.defined", n);
throw Context.reportRuntimeError(Context.getMessage("msg.prop.defined", eargs));
} }
//thisObj.defineProperty(n, cl, DONTENUM); //thisObj.defineProperty(n, cl, DONTENUM);
thisObj.put(n,thisObj,cl); thisObj.put(n,thisObj,cl);
@ -150,8 +147,8 @@ public class ImporterTopLevel extends ScriptableObject {
for (int i=0; i<args.length; i++) { for (int i=0; i<args.length; i++) {
Object pkg = args[i]; Object pkg = args[i];
if (!(pkg instanceof NativeJavaPackage)) { if (!(pkg instanceof NativeJavaPackage)) {
String[] eargs = { Context.toString(pkg) }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage("msg.not.pkg", eargs)); "msg.not.pkg", Context.toString(pkg));
} }
Object[] elements = cx.getElements(importedPackages); Object[] elements = cx.getElements(importedPackages);
for (int j=0; j < elements.length; j++) { for (int j=0; j < elements.length; j++) {

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

@ -220,25 +220,22 @@ class JavaMembers {
try { try {
field = (Field) member; field = (Field) member;
if (field == null) { if (field == null) {
Object[] args = {name}; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError( "msg.java.internal.private", name);
Context.getMessage("msg.java.internal.private", args));
} }
field.set(javaObject, NativeJavaObject.coerceType(field.getType(), field.set(javaObject,
value)); NativeJavaObject.coerceType(field.getType(), value));
} catch (ClassCastException e) { } catch (ClassCastException e) {
Object errArgs[] = { name }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage "msg.java.method.assign", name);
("msg.java.method.assign",
errArgs));
} catch (IllegalAccessException accessEx) { } catch (IllegalAccessException accessEx) {
throw new RuntimeException("unexpected IllegalAccessException "+ throw new RuntimeException("unexpected IllegalAccessException "+
"accessing Java field"); "accessing Java field");
} catch (IllegalArgumentException argEx) { } catch (IllegalArgumentException argEx) {
Object errArgs[] = { value.getClass().getName(), field, throw Context.reportRuntimeError3(
javaObject.getClass().getName() }; "msg.java.internal.field.type",
throw Context.reportRuntimeError(Context.getMessage( value.getClass().getName(), field,
"msg.java.internal.field.type", errArgs)); javaObject.getClass().getName());
} }
} }
} }
@ -516,11 +513,8 @@ class JavaMembers {
} }
RuntimeException reportMemberNotFound(String memberName) { RuntimeException reportMemberNotFound(String memberName) {
Object errArgs[] = { cl.getName(), return Context.reportRuntimeError2(
memberName }; "msg.java.member.not.found", cl.getName(), memberName);
return Context.reportRuntimeError(
Context.getMessage("msg.java.member.not.found",
errArgs));
} }
static Hashtable classTable = new Hashtable(); static Hashtable classTable = new Hashtable();
@ -573,9 +567,8 @@ class FieldAndMethods extends NativeJavaMethod {
rval = field.get(javaObject); rval = field.get(javaObject);
type = field.getType(); type = field.getType();
} catch (IllegalAccessException accEx) { } catch (IllegalAccessException accEx) {
Object[] args = {getName()}; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage "msg.java.internal.private", getName());
("msg.java.internal.private", args));
} }
rval = NativeJavaObject.wrap(this, rval, type); rval = NativeJavaObject.wrap(this, rval, type);
if (rval instanceof Scriptable) { if (rval instanceof Scriptable) {

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

@ -219,8 +219,7 @@ public class NativeArray extends ScriptableObject {
else { else {
long len = ScriptRuntime.toUint32(args[0]); long len = ScriptRuntime.toUint32(args[0]);
if (len != (((Number)(args[0])).doubleValue())) if (len != (((Number)(args[0])).doubleValue()))
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.arraylength.bad");
("msg.arraylength.bad", null));
return new NativeArray(len); return new NativeArray(len);
} }
} }
@ -242,13 +241,11 @@ public class NativeArray extends ScriptableObject {
*/ */
if (!(val instanceof Number)) if (!(val instanceof Number))
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.arraylength.bad");
("msg.arraylength.bad", null));
long longVal = ScriptRuntime.toUint32(val); long longVal = ScriptRuntime.toUint32(val);
if (longVal != (((Number)val).doubleValue())) if (longVal != (((Number)val).doubleValue()))
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.arraylength.bad");
("msg.arraylength.bad", null));
if (longVal < length) { if (longVal < length) {
// remove all properties between longVal and length // remove all properties between longVal and length

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

@ -91,9 +91,7 @@ public final class NativeCall extends ScriptableObject {
Function ctorObj, boolean inNewExpr) Function ctorObj, boolean inNewExpr)
{ {
if (!inNewExpr) { if (!inNewExpr) {
Object[] errArgs = { "Call" }; throw Context.reportRuntimeError1("msg.only.from.new", "Call");
throw Context.reportRuntimeError(Context.getMessage
("msg.only.from.new", errArgs));
} }
ScriptRuntime.checkDeprecated(cx, "Call"); ScriptRuntime.checkDeprecated(cx, "Call");
NativeCall result = new NativeCall(); NativeCall result = new NativeCall();

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

@ -1148,8 +1148,8 @@ public class NativeDate extends ScriptableObject {
Function funObj) { Function funObj) {
if (obj == null || !(obj instanceof NativeDate)) { if (obj == null || !(obj instanceof NativeDate)) {
Context cx = Context.getCurrentContext(); Context cx = Context.getCurrentContext();
Object[] args = { ((NativeFunction) funObj).names[0] }; String name = ((NativeFunction) funObj).names[0];
String msg = Context.getMessage("msg.incompat.call", args); String msg = Context.getMessage1("msg.incompat.call", name);
throw NativeGlobal.constructError(cx, "TypeError", msg, funObj); throw NativeGlobal.constructError(cx, "TypeError", msg, funObj);
} }
return (NativeDate) obj; return (NativeDate) obj;

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

@ -117,9 +117,8 @@ public class NativeFunction extends ScriptableObject implements Function {
if (protoProp instanceof Scriptable && protoProp != Undefined.instance) { if (protoProp instanceof Scriptable && protoProp != Undefined.instance) {
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp); return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
} }
Object[] args = { names[0] }; String m = ScriptRuntime.getMessage1("msg.instanceof.bad.prototype",
String m = ScriptRuntime.getMessage("msg.instanceof.bad.prototype", names[0]);
args);
throw NativeGlobal.constructError(Context.getContext(), "TypeError", throw NativeGlobal.constructError(Context.getContext(), "TypeError",
m, instance); m, instance);
} }
@ -404,15 +403,13 @@ public class NativeFunction extends ScriptableObject implements Function {
if (names != null && names.length > 0 if (names != null && names.length > 0
&& names[0].length() > 0) && names[0].length() > 0)
{ {
Object[] errArgs = { new Integer((int)source.charAt(i)), message = Context.getMessage2
names[0] }; ("msg.no.function.ref.found.in",
message = Context.getMessage new Integer((int)source.charAt(i)), names[0]);
("msg.no.function.ref.found.in", errArgs);
} else { } else {
Object[] errArgs message = Context.getMessage1
= { new Integer((int)source.charAt(i)) }; ("msg.no.function.ref.found",
message = Context.getMessage new Integer((int)source.charAt(i)));
("msg.no.function.ref.found", errArgs);
} }
throw Context.reportRuntimeError(message); throw Context.reportRuntimeError(message);
} }
@ -844,9 +841,8 @@ public class NativeFunction extends ScriptableObject implements Function {
{ {
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass); Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (!(val instanceof NativeFunction)) { if (!(val instanceof NativeFunction)) {
Object[] errArgs = { "toString" }; String m = Context.getMessage1("msg.incompat.call", "toString");
String message = Context.getMessage("msg.incompat.call", errArgs); throw NativeGlobal.constructError(cx, "TypeError", m, funObj);
throw NativeGlobal.constructError(cx, "TypeError", message, funObj);
} }
if (val instanceof NativeJavaMethod) { if (val instanceof NativeJavaMethod) {
return "\nfunction " + ((NativeFunction) val).jsGet_name() + return "\nfunction " + ((NativeFunction) val).jsGet_name() +
@ -932,7 +928,7 @@ public class NativeFunction extends ScriptableObject implements Function {
else else
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
cx, "TypeError", cx, "TypeError",
ScriptRuntime.getMessage("msg.arg.isnt.array", null), ScriptRuntime.getMessage0("msg.arg.isnt.array"),
thisObj); thisObj);
} }
else else

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

@ -386,8 +386,7 @@ public class NativeGlobal {
Object[] args, Function funObj) Object[] args, Function funObj)
throws JavaScriptException throws JavaScriptException
{ {
Object[] a = { "eval" }; String m = ScriptRuntime.getMessage1("msg.cant.call.indirect", "eval");
String m = ScriptRuntime.getMessage("msg.cant.call.indirect", a);
throw NativeGlobal.constructError(cx, "EvalError", m, funObj); throw NativeGlobal.constructError(cx, "EvalError", m, funObj);
} }
@ -405,7 +404,7 @@ public class NativeGlobal {
return Undefined.instance; return Undefined.instance;
Object x = args[0]; Object x = args[0];
if (!(x instanceof String)) { if (!(x instanceof String)) {
String message = Context.getMessage("msg.eval.nonstring", null); String message = Context.getMessage0("msg.eval.nonstring");
Context.reportWarning(message); Context.reportWarning(message);
return x; return x;
} }
@ -435,7 +434,7 @@ public class NativeGlobal {
// infinite looping on while(true) { eval('foo bar') } - // infinite looping on while(true) { eval('foo bar') } -
// so we throw an EvaluatorException. // so we throw an EvaluatorException.
if (script == null) { if (script == null) {
String message = Context.getMessage("msg.syntax", null); String message = Context.getMessage0("msg.syntax");
throw new EvaluatorException(message); throw new EvaluatorException(message);
} }
@ -544,21 +543,18 @@ public class NativeGlobal {
R.append(C); R.append(C);
} else { } else {
if ((C >= 0xDC00) && (C <= 0xDFFF)) { if ((C >= 0xDC00) && (C <= 0xDFFF)) {
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
} }
if ((C < 0xD800) || (C > 0xDBFF)) if ((C < 0xD800) || (C > 0xDBFF))
V = C; V = C;
else { else {
k++; k++;
if (k == str.length()) { if (k == str.length()) {
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
} }
C2 = str.charAt(k); C2 = str.charAt(k);
if ((C2 < 0xDC00) || (C2 > 0xDFFF)) { if ((C2 < 0xDC00) || (C2 > 0xDFFF)) {
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
} }
V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000; V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000;
} }
@ -607,11 +603,9 @@ public class NativeGlobal {
if (C == '%') { if (C == '%') {
start = k; start = k;
if ((k + 2) >= str.length()) if ((k + 2) >= str.length())
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
if (!isHex(str.charAt(k + 1)) || !isHex(str.charAt(k + 2))) if (!isHex(str.charAt(k + 1)) || !isHex(str.charAt(k + 2)))
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
B = unHex(str.charAt(k + 1)) * 16 + unHex(str.charAt(k + 2)); B = unHex(str.charAt(k + 1)) * 16 + unHex(str.charAt(k + 2));
k += 2; k += 2;
if ((B & 0x80) == 0) if ((B & 0x80) == 0)
@ -620,26 +614,21 @@ public class NativeGlobal {
n = 1; n = 1;
while ((B & (0x80 >>> n)) != 0) n++; while ((B & (0x80 >>> n)) != 0) n++;
if ((n == 1) || (n > 6)) if ((n == 1) || (n > 6))
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
octets[0] = (char)B; octets[0] = (char)B;
if ((k + 3 * (n - 1)) >= str.length()) if ((k + 3 * (n - 1)) >= str.length())
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
for (j = 1; j < n; j++) { for (j = 1; j < n; j++) {
k++; k++;
if (str.charAt(k) != '%') if (str.charAt(k) != '%')
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
if (!isHex(str.charAt(k + 1)) if (!isHex(str.charAt(k + 1))
|| !isHex(str.charAt(k + 2))) || !isHex(str.charAt(k + 2)))
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
B = unHex(str.charAt(k + 1)) * 16 B = unHex(str.charAt(k + 1)) * 16
+ unHex(str.charAt(k + 2)); + unHex(str.charAt(k + 2));
if ((B & 0xC0) != 0x80) if ((B & 0xC0) != 0x80)
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
k += 2; k += 2;
octets[j] = (char)B; octets[j] = (char)B;
} }
@ -647,8 +636,7 @@ public class NativeGlobal {
if (V >= 0x10000) { if (V >= 0x10000) {
V -= 0x10000; V -= 0x10000;
if (V > 0xFFFFF) if (V > 0xFFFFF)
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
C = (char)((V & 0x3FF) + 0xDC00); C = (char)((V & 0x3FF) + 0xDC00);
H = (char)((V >>> 10) + 0xD800); H = (char)((V >>> 10) + 0xD800);
R.append(H); R.append(H);

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

@ -88,11 +88,8 @@ public class NativeJavaArray extends NativeJavaObject {
if (result == NOT_FOUND && if (result == NOT_FOUND &&
!ScriptRuntime.hasProp(getPrototype(), id)) !ScriptRuntime.hasProp(getPrototype(), id))
{ {
Object errArgs[] = { array.getClass().getName(), throw Context.reportRuntimeError2(
id }; "msg.java.member.not.found", array.getClass().getName(), id);
throw Context.reportRuntimeError(
Context.getMessage("msg.java.member.not.found",
errArgs));
} }
return result; return result;
} }

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

@ -172,9 +172,8 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
Constructor ctor = (Constructor) member; Constructor ctor = (Constructor) member;
if (ctor == null) { if (ctor == null) {
String sig = NativeJavaMethod.scriptSignature(args); String sig = NativeJavaMethod.scriptSignature(args);
Object errArgs[] = { classObject.getName(), sig }; throw Context.reportRuntimeError2(
throw Context.reportRuntimeError(Context.getMessage( "msg.no.java.ctor", classObject.getName(), sig);
"msg.no.java.ctor", errArgs));
} }
// Found the constructor, so try invoking it. // Found the constructor, so try invoking it.
@ -200,10 +199,8 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
if (m != null) if (m != null)
msg = m; msg = m;
} }
Object[] errArgs = { msg, classObject.getName() }; throw Context.reportRuntimeError2(
throw Context.reportRuntimeError(Context.getMessage "msg.cant.instantiate", msg, classObject.getName());
("msg.cant.instantiate",
errArgs));
} }
} }
@ -230,24 +227,19 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
classObject); classObject);
} catch (InstantiationException instEx) { } catch (InstantiationException instEx) {
Object[] errArgs = { instEx.getMessage(), throw Context.reportRuntimeError2(
classObject.getName() }; "msg.cant.instantiate",
throw Context.reportRuntimeError(Context.getMessage instEx.getMessage(), classObject.getName());
("msg.cant.instantiate",
errArgs));
} catch (IllegalArgumentException argEx) { } catch (IllegalArgumentException argEx) {
String signature = NativeJavaMethod.scriptSignature(args); String signature = NativeJavaMethod.scriptSignature(args);
String ctorString = ctor.toString(); String ctorString = ctor.toString();
Object[] errArgs = { argEx.getMessage(),ctorString,signature }; throw Context.reportRuntimeError3(
throw Context.reportRuntimeError(Context.getMessage "msg.bad.ctor.sig", argEx.getMessage(), ctorString, signature);
("msg.bad.ctor.sig",
errArgs));
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw JavaScriptException.wrapException(scope, e); throw JavaScriptException.wrapException(scope, e);
} catch (IllegalAccessException accessEx) { } catch (IllegalAccessException accessEx) {
Object[] errArgs = { accessEx.getMessage() }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage "msg.java.internal.private", accessEx.getMessage());
("msg.java.internal.private", errArgs));
} }
} }

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

@ -180,9 +180,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
Class c = methods[0].getDeclaringClass(); Class c = methods[0].getDeclaringClass();
String sig = c.getName() + "." + names[0] + "(" + String sig = c.getName() + "." + names[0] + "(" +
scriptSignature(args) + ")"; scriptSignature(args) + ")";
Object errArgs[] = { sig }; throw Context.reportRuntimeError1("msg.java.no_such_method", sig);
throw Context.reportRuntimeError(
Context.getMessage("msg.java.no_such_method", errArgs));
} }
// OPT: already retrieved in findFunction, so we should inline that // OPT: already retrieved in findFunction, so we should inline that
@ -201,9 +199,8 @@ public class NativeJavaMethod extends NativeFunction implements Function {
while (!(o instanceof Wrapper)) { while (!(o instanceof Wrapper)) {
o = o.getPrototype(); o = o.getPrototype();
if (o == null) { if (o == null) {
Object errArgs[] = { names[0] }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError( "msg.nonjava.method", names[0]);
Context.getMessage("msg.nonjava.method", errArgs));
} }
} }
javaObject = ((Wrapper) o).unwrap(); javaObject = ((Wrapper) o).unwrap();

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

@ -222,10 +222,10 @@ public class NativeJavaObject implements Scriptable, Wrapper {
{ {
Function converter = getConverter(converterName); Function converter = getConverter(converterName);
if (converter == null) { if (converter == null) {
Object[] errArgs = { converterName, javaObject.getClass().getName() }; String className = javaObject.getClass().getName();
throw Context.reportRuntimeError( throw Context.reportRuntimeError2
Context.getMessage("msg.java.conversion.implicit_method", ("msg.java.conversion.implicit_method",
errArgs)); converterName, className);
} }
return callConverter(converter); return callConverter(converter);
} }
@ -243,8 +243,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
} catch (JavaScriptException jse) { } catch (JavaScriptException jse) {
// fall through to error message // fall through to error message
} }
throw Context.reportRuntimeError( throw Context.reportRuntimeError0("msg.default.value");
Context.getMessage("msg.default.value", null));
} }
@ -888,11 +887,9 @@ public class NativeJavaObject implements Scriptable, Wrapper {
} }
static void reportConversionError(Object value, Class type) { static void reportConversionError(Object value, Class type) {
Object[] args = { value.toString(), throw Context.reportRuntimeError2
NativeJavaMethod.javaSignature(type) ("msg.conversion.not.allowed",
}; value.toString(), NativeJavaMethod.javaSignature(type));
throw Context.reportRuntimeError(
Context.getMessage("msg.conversion.not.allowed", args));
} }
public static void initJSObject() { public static void initJSObject() {

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

@ -145,8 +145,7 @@ public class NativeJavaPackage extends ScriptableObject {
} }
public void put(int index, Scriptable start, Object value) { public void put(int index, Scriptable start, Object value) {
throw Context.reportRuntimeError( throw Context.reportRuntimeError0("msg.pkg.int");
Context.getMessage("msg.pkg.int", null));
} }
public Object get(String id, Scriptable start) { public Object get(String id, Scriptable start) {
@ -230,7 +229,7 @@ public class NativeJavaPackage extends ScriptableObject {
} }
} }
throw Context.reportRuntimeError( throw Context.reportRuntimeError(
Context.getMessage("msg.not.java.obj", null)); Context.getMessage0("msg.not.java.obj"));
} }
private String packageName; private String packageName;

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

@ -144,11 +144,10 @@ public class NativeNumber extends ScriptableObject {
} else { } else {
precision = ScriptRuntime.toInt32(arg); precision = ScriptRuntime.toInt32(arg);
if (precision < precisionMin || precision > precisionMax) { if (precision < precisionMin || precision > precisionMax) {
Object args[] = new Object[1];
args[0] = Integer.toString(precision);
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getCurrentContext(), "RangeError", Context.getCurrentContext(), "RangeError",
ScriptRuntime.getMessage("msg.bad.precision", args), ScriptRuntime.getMessage1(
"msg.bad.precision", Integer.toString(precision)),
this); this);
} }
} }

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

@ -120,9 +120,8 @@ public class NativeScript extends NativeFunction implements Script {
} }
public Object jsFunction_exec() throws JavaScriptException { public Object jsFunction_exec() throws JavaScriptException {
Object[] msgArgs = { "exec" }; throw Context.reportRuntimeError1
throw Context.reportRuntimeError( ("msg.cant.call.indirect", "exec");
Context.getMessage("msg.cant.call.indirect", msgArgs));
} }
public static Object jsFunction_toString(Context cx, Scriptable thisObj, public static Object jsFunction_toString(Context cx, Scriptable thisObj,
@ -163,8 +162,7 @@ public class NativeScript extends NativeFunction implements Script {
public Scriptable construct(Context cx, Scriptable scope, Object[] args) public Scriptable construct(Context cx, Scriptable scope, Object[] args)
throws JavaScriptException throws JavaScriptException
{ {
String message = Context.getMessage("msg.script.is.not.constructor", null); throw Context.reportRuntimeError0("msg.script.is.not.constructor");
throw Context.reportRuntimeError(message);
} }
private Script script; private Script script;

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

@ -726,7 +726,7 @@ public class NativeString extends ScriptableObject {
private static RegExpProxy checkReProxy(Context cx) { private static RegExpProxy checkReProxy(Context cx) {
RegExpProxy result = cx.getRegExpProxy(); RegExpProxy result = cx.getRegExpProxy();
if (result == null) { if (result == null) {
throw cx.reportRuntimeError(cx.getMessage("msg.no.regexp", null)); throw cx.reportRuntimeError0("msg.no.regexp");
} }
return result; return result;
} }

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

@ -141,18 +141,14 @@ public class NativeWith implements Scriptable {
public static Object jsConstructor(Context cx, Object[] args, public static Object jsConstructor(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr) Function ctorObj, boolean inNewExpr)
{ {
Object[] msgArgs = { "With" }; throw Context.reportRuntimeError1("msg.cant.call.indirect", "With");
throw Context.reportRuntimeError(
Context.getMessage("msg.cant.call.indirect", msgArgs));
} }
public static Object newWithSpecial(Context cx, Object[] args, public static Object newWithSpecial(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr) Function ctorObj, boolean inNewExpr)
{ {
if (!inNewExpr) { if (!inNewExpr) {
Object[] errArgs = { "With" }; throw Context.reportRuntimeError1("msg.only.from.new", "With");
throw Context.reportRuntimeError(Context.getMessage
("msg.only.from.new", errArgs));
} }
ScriptRuntime.checkDeprecated(cx, "With"); ScriptRuntime.checkDeprecated(cx, "With");

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

@ -133,9 +133,8 @@ public class NodeTransformer {
if (n.getType() == TokenStream.LABEL) { if (n.getType() == TokenStream.LABEL) {
String otherId = (String)n.getProp(Node.LABEL_PROP); String otherId = (String)n.getProp(Node.LABEL_PROP);
if (id.equals(otherId)) { if (id.equals(otherId)) {
Object[] errArgs = { id }; String message = Context.getMessage1(
String message = Context.getMessage("msg.dup.label", "msg.dup.label", id);
errArgs);
reportMessage(Context.getContext(), message, node, reportMessage(Context.getContext(), message, node,
tree, true, scope); tree, true, scope);
break typeswitch; break typeswitch;
@ -361,8 +360,7 @@ public class NodeTransformer {
("msg.bad.break", null); ("msg.bad.break", null);
} }
} else if (loop != null) { } else if (loop != null) {
message = Context.getMessage("msg.continue.nonloop", message = Context.getMessage0("msg.continue.nonloop");
null);
} else { } else {
Object[] errArgs = { id }; Object[] errArgs = { id };
message = Context.getMessage message = Context.getMessage

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

@ -47,4 +47,19 @@ public class PropertyException extends Exception {
super(detail); super(detail);
} }
static PropertyException withMessage0(String messageId) {
return new PropertyException(Context.getMessage0(messageId));
}
static PropertyException withMessage1(String messageId, Object arg1) {
return new PropertyException(Context.getMessage1(messageId, arg1));
}
static PropertyException withMessage2
(String messageId, Object arg1, Object arg2)
{
return new PropertyException
(Context.getMessage2(messageId, arg1, arg2));
}
} }

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

@ -432,9 +432,8 @@ public class ScriptRuntime {
return "0"; return "0";
if ((base < 2) || (base > 36)) { if ((base < 2) || (base > 36)) {
Object[] args = { Integer.toString(base) }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(getMessage "msg.bad.radix", Integer.toString(base));
("msg.bad.radix", args));
} }
if (base != 10) { if (base != 10) {
@ -462,14 +461,14 @@ public class ScriptRuntime {
if (val == null) { if (val == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
if (val instanceof Scriptable) { if (val instanceof Scriptable) {
if (val == Undefined.instance) { if (val == Undefined.instance) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.undef.to.object", null), ScriptRuntime.getMessage0("msg.undef.to.object"),
scope); scope);
} }
return (Scriptable) val; return (Scriptable) val;
@ -683,7 +682,7 @@ public class ScriptRuntime {
: "msg.undefined"; : "msg.undefined";
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "ConversionError", Context.getContext(), "ConversionError",
ScriptRuntime.getMessage(msg, null), ScriptRuntime.getMessage0(msg),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -722,7 +721,7 @@ public class ScriptRuntime {
if (s == null) { if (s == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
return s.getPrototype(); return s.getPrototype();
@ -752,7 +751,7 @@ public class ScriptRuntime {
if (s == null) { if (s == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
return s.getParentScope(); return s.getParentScope();
@ -769,16 +768,15 @@ public class ScriptRuntime {
Scriptable s = result; Scriptable s = result;
while (s != null) { while (s != null) {
if (s == start) { if (s == start) {
Object[] args = { "__proto__" }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(getMessage "msg.cyclic.value", "__proto__");
("msg.cyclic.value", args));
} }
s = s.getPrototype(); s = s.getPrototype();
} }
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
start.setPrototype(result); start.setPrototype(result);
@ -796,16 +794,15 @@ public class ScriptRuntime {
Scriptable s = result; Scriptable s = result;
while (s != null) { while (s != null) {
if (s == start) { if (s == start) {
Object[] args = { "__parent__" }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(getMessage "msg.cyclic.value", "__parent__");
("msg.cyclic.value", args));
} }
s = s.getParentScope(); s = s.getParentScope();
} }
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
start.setParentScope(result); start.setParentScope(result);
@ -824,7 +821,7 @@ public class ScriptRuntime {
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -1090,10 +1087,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object[] args = { id.toString() }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "ReferenceError",
Context.getContext(), "ReferenceError", ScriptRuntime.getMessage1("msg.is.not.defined", id.toString()),
ScriptRuntime.getMessage("msg.is.not.defined", args),
scopeChain); scopeChain);
} }
@ -1137,10 +1133,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object[] args = { id };
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "ReferenceError", Context.getContext(), "ReferenceError",
ScriptRuntime.getMessage("msg.is.not.defined", args), ScriptRuntime.getMessage1("msg.is.not.defined", id),
scope); scope);
} }
@ -1171,8 +1166,7 @@ public class ScriptRuntime {
This code is causing immense performance problems in This code is causing immense performance problems in
scripts that assign to the variables as a way of creating them. scripts that assign to the variables as a way of creating them.
XXX need strict mode XXX need strict mode
String[] args = { id }; String message = getMessage1("msg.assn.create", id);
String message = getMessage("msg.assn.create", args);
Context.reportWarning(message); Context.reportWarning(message);
*/ */
return value; return value;
@ -1213,11 +1207,9 @@ public class ScriptRuntime {
function = (Function) fun; function = (Function) fun;
} }
catch (ClassCastException e) { catch (ClassCastException e) {
Object[] errorArgs = { toString(fun) }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "TypeError",
Context.getContext(), "TypeError", ScriptRuntime.getMessage1("msg.isnt.function", toString(fun)),
ScriptRuntime.getMessage("msg.isnt.function",
errorArgs),
scope); scope);
} }
@ -1293,10 +1285,9 @@ public class ScriptRuntime {
} catch (ClassCastException e) { } catch (ClassCastException e) {
// fall through to error // fall through to error
} }
Object[] errorArgs = { toString(fun) }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "TypeError",
Context.getContext(), "TypeError", ScriptRuntime.getMessage1("msg.isnt.function", toString(fun)),
ScriptRuntime.getMessage("msg.isnt.function", errorArgs),
scope); scope);
} }
@ -1396,10 +1387,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object args[] = { id }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "ReferenceError",
Context.getContext(), "ReferenceError", ScriptRuntime.getMessage1("msg.is.not.defined", id),
ScriptRuntime.getMessage("msg.is.not.defined", args),
scopeChain); scopeChain);
} }
@ -1413,7 +1403,7 @@ public class ScriptRuntime {
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -1493,10 +1483,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object args[] = { id }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "ReferenceError",
Context.getContext(), "ReferenceError", ScriptRuntime.getMessage1("msg.is.not.defined", id),
ScriptRuntime.getMessage("msg.is.not.defined", args),
scopeChain); scopeChain);
} }
@ -1510,7 +1499,7 @@ public class ScriptRuntime {
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -1543,7 +1532,7 @@ public class ScriptRuntime {
if (result != null && result instanceof Scriptable) if (result != null && result instanceof Scriptable)
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.bad.default.value", null), ScriptRuntime.getMessage0("msg.bad.default.value"),
val); val);
return result; return result;
} }
@ -1696,7 +1685,7 @@ public class ScriptRuntime {
if (! (b instanceof Scriptable)) { if (! (b instanceof Scriptable)) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.instanceof.not.object", null), ScriptRuntime.getMessage0("msg.instanceof.not.object"),
scope); scope);
} }
@ -1744,7 +1733,7 @@ public class ScriptRuntime {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), Context.getContext(),
"TypeError", "TypeError",
ScriptRuntime.getMessage("msg.instanceof.not.object", null), ScriptRuntime.getMessage0("msg.instanceof.not.object"),
scope); scope);
} }
String s = getStringId(a); String s = getStringId(a);
@ -2002,9 +1991,7 @@ public class ScriptRuntime {
static void checkDeprecated(Context cx, String name) { static void checkDeprecated(Context cx, String name) {
int version = cx.getLanguageVersion(); int version = cx.getLanguageVersion();
if (version >= Context.VERSION_1_4 || version == Context.VERSION_DEFAULT) { if (version >= Context.VERSION_1_4 || version == Context.VERSION_DEFAULT) {
Object[] errArgs = { name }; String msg = getMessage1("msg.deprec.ctor", name);
String msg = getMessage("msg.deprec.ctor",
errArgs);
if (version == Context.VERSION_DEFAULT) if (version == Context.VERSION_DEFAULT)
Context.reportWarning(msg); Context.reportWarning(msg);
else else
@ -2012,6 +1999,20 @@ public class ScriptRuntime {
} }
} }
public static String getMessage0(String messageId) {
return Context.getMessage0(messageId);
}
public static String getMessage1(String messageId, Object arg1) {
return Context.getMessage1(messageId, arg1);
}
public static String getMessage2
(String messageId, Object arg1, Object arg2)
{
return Context.getMessage2(messageId, arg1, arg2);
}
public static String getMessage(String messageId, Object[] arguments) { public static String getMessage(String messageId, Object[] arguments) {
return Context.getMessage(messageId, arguments); return Context.getMessage(messageId, arguments);
} }
@ -2085,8 +2086,7 @@ public class ScriptRuntime {
private static RuntimeException errorWithClassName(String msg, Object val) private static RuntimeException errorWithClassName(String msg, Object val)
{ {
Object[] args = { val.getClass().getName() }; return Context.reportRuntimeError1(msg, val.getClass().getName());
return Context.reportRuntimeError(getMessage(msg, args));
} }
static public Object[] emptyArgs = new Object[0]; static public Object[] emptyArgs = new Object[0];

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

@ -356,8 +356,7 @@ public abstract class ScriptableObject implements Scriptable {
{ {
int slotIndex = getSlot(name, name.hashCode()); int slotIndex = getSlot(name, name.hashCode());
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
return slots[slotIndex].attributes; return slots[slotIndex].attributes;
} }
@ -381,8 +380,7 @@ public abstract class ScriptableObject implements Scriptable {
{ {
int slotIndex = getSlot(null, index); int slotIndex = getSlot(null, index);
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
return slots[slotIndex].attributes; return slots[slotIndex].attributes;
} }
@ -418,8 +416,7 @@ public abstract class ScriptableObject implements Scriptable {
attributes &= mask; // mask out unused bits attributes &= mask; // mask out unused bits
int slotIndex = getSlot(name, name.hashCode()); int slotIndex = getSlot(name, name.hashCode());
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
slots[slotIndex].attributes = (short) attributes; slots[slotIndex].attributes = (short) attributes;
} }
@ -444,8 +441,7 @@ public abstract class ScriptableObject implements Scriptable {
{ {
int slotIndex = getSlot(null, index); int slotIndex = getSlot(null, index);
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
slots[slotIndex].attributes = (short) attributes; slots[slotIndex].attributes = (short) attributes;
} }
@ -562,9 +558,8 @@ public abstract class ScriptableObject implements Scriptable {
typeHint == Double.TYPE) typeHint == Double.TYPE)
hint = "number"; hint = "number";
else { else {
Object[] args = { typeHint.toString() }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError( "msg.invalid.type", typeHint.toString());
Context.getMessage("msg.invalid.type", args));
} }
Object v = getProperty(this, "valueOf"); Object v = getProperty(this, "valueOf");
if (!(v instanceof Function)) if (!(v instanceof Function))
@ -596,10 +591,9 @@ public abstract class ScriptableObject implements Scriptable {
// fall through to error // fall through to error
} }
Object arg = typeHint == null ? "undefined" : typeHint.toString(); Object arg = typeHint == null ? "undefined" : typeHint.toString();
Object[] args = { arg };
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.default.value", args), ScriptRuntime.getMessage1("msg.default.value", arg),
this); this);
} }
@ -782,9 +776,8 @@ public abstract class ScriptableObject implements Scriptable {
} }
} }
if (protoCtor == null) { if (protoCtor == null) {
Object[] args = { clazz.getName() };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.zero.arg.ctor", args)); Context.getMessage1("msg.zero.arg.ctor", clazz.getName()));
} }
Scriptable proto = (Scriptable) Scriptable proto = (Scriptable)
@ -808,9 +801,9 @@ public abstract class ScriptableObject implements Scriptable {
Member ctorMember = null; Member ctorMember = null;
if (ctorMeths != null) { if (ctorMeths != null) {
if (ctorMeths.length > 1) { if (ctorMeths.length > 1) {
Object[] args = { ctorMeths[0], ctorMeths[1] };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.multiple.ctors", args)); Context.getMessage2("msg.multiple.ctors",
ctorMeths[0], ctorMeths[1]));
} }
ctorMember = ctorMeths[0]; ctorMember = ctorMeths[0];
} }
@ -841,9 +834,9 @@ public abstract class ScriptableObject implements Scriptable {
} }
if (name.equals(className)) { if (name.equals(className)) {
if (ctorMember != null) { if (ctorMember != null) {
Object[] args = { ctorMember, methods[i] };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.multiple.ctors", args)); Context.getMessage2("msg.multiple.ctors",
ctorMember, methods[i]));
} }
ctorMember = methods[i]; ctorMember = methods[i];
} }
@ -859,17 +852,16 @@ public abstract class ScriptableObject implements Scriptable {
ctorMember = ctors[0]; ctorMember = ctors[0];
} }
if (ctorMember == null) { if (ctorMember == null) {
Object[] args = { clazz.getName() };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.ctor.multiple.parms", args)); Context.getMessage1("msg.ctor.multiple.parms",
clazz.getName()));
} }
} }
FunctionObject ctor = new FunctionObject(className, ctorMember, scope); FunctionObject ctor = new FunctionObject(className, ctorMember, scope);
if (ctor.isVarArgsMethod()) { if (ctor.isVarArgsMethod()) {
Object[] args = { ctorMember.getName() }; throw Context.reportRuntimeError1
String message = Context.getMessage("msg.varargs.ctor", args); ("msg.varargs.ctor", ctorMember.getName());
throw Context.reportRuntimeError(message);
} }
ctor.addAsConstructor(scope, proto); ctor.addAsConstructor(scope, proto);
@ -928,17 +920,15 @@ public abstract class ScriptableObject implements Scriptable {
continue; // deal with set when we see get continue; // deal with set when we see get
if (prefix != null && prefix.equals(getterPrefix)) { if (prefix != null && prefix.equals(getterPrefix)) {
if (!(proto instanceof ScriptableObject)) { if (!(proto instanceof ScriptableObject)) {
Object[] args = { proto.getClass().toString(), name }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.extend.scriptable", proto.getClass().toString(), name);
Context.getMessage("msg.extend.scriptable", args));
} }
Method[] setter = FunctionObject.findMethods( Method[] setter = FunctionObject.findMethods(
clazz, clazz,
setterPrefix + name); setterPrefix + name);
if (setter != null && setter.length != 1) { if (setter != null && setter.length != 1) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", name, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
int attr = ScriptableObject.PERMANENT | int attr = ScriptableObject.PERMANENT |
ScriptableObject.DONTENUM | ScriptableObject.DONTENUM |
@ -956,9 +946,9 @@ public abstract class ScriptableObject implements Scriptable {
prefix.equals(staticFunctionPrefix)))) prefix.equals(staticFunctionPrefix))))
{ {
if (!(proto instanceof ScriptableObject)) { if (!(proto instanceof ScriptableObject)) {
Object[] args = { proto.getClass().toString(), name }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.extend.scriptable",
Context.getMessage("msg.extend.scriptable", args)); proto.getClass().toString(), name);
} }
if (name.startsWith("set")) if (name.startsWith("set"))
continue; // deal with set when we see get continue; // deal with set when we see get
@ -976,9 +966,8 @@ public abstract class ScriptableObject implements Scriptable {
hasPrefix ? genericPrefix + setterName hasPrefix ? genericPrefix + setterName
: setterName); : setterName);
if (setter != null && setter.length != 1) { if (setter != null && setter.length != 1) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", name, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
if (setter == null && hasPrefix) if (setter == null && hasPrefix)
setter = FunctionObject.findMethods( setter = FunctionObject.findMethods(
@ -996,9 +985,8 @@ public abstract class ScriptableObject implements Scriptable {
} }
FunctionObject f = new FunctionObject(name, methods[i], proto); FunctionObject f = new FunctionObject(name, methods[i], proto);
if (f.isVarArgsConstructor()) { if (f.isVarArgsConstructor()) {
Object[] args = { ctorMember.getName() }; throw Context.reportRuntimeError1
String message = Context.getMessage("msg.varargs.fun", args); ("msg.varargs.fun", ctorMember.getName());
throw Context.reportRuntimeError(message);
} }
Scriptable dest = prefix == staticFunctionPrefix Scriptable dest = prefix == staticFunctionPrefix
? ctor ? ctor
@ -1087,9 +1075,8 @@ public abstract class ScriptableObject implements Scriptable {
if (setter == null) if (setter == null)
attributes |= ScriptableObject.READONLY; attributes |= ScriptableObject.READONLY;
if (getter.length != 1 || (setter != null && setter.length != 1)) { if (getter.length != 1 || (setter != null && setter.length != 1)) {
Object[] errArgs = { propertyName, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", propertyName, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
defineProperty(propertyName, null, getter[0], defineProperty(propertyName, null, getter[0],
setter == null ? null : setter[0], attributes); setter == null ? null : setter[0], attributes);
@ -1150,43 +1137,36 @@ public abstract class ScriptableObject implements Scriptable {
if (parmTypes.length != 1 || if (parmTypes.length != 1 ||
parmTypes[0] != ScriptableObject.class) parmTypes[0] != ScriptableObject.class)
{ {
Object[] args = { getter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.bad.getter.parms", getter.toString());
Context.getMessage("msg.bad.getter.parms", args));
} }
} else if (delegateTo != null) { } else if (delegateTo != null) {
Object[] args = { getter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.obj.getter.parms", getter.toString());
Context.getMessage("msg.obj.getter.parms", args));
} }
if (setter != null) { if (setter != null) {
flags |= Slot.HAS_SETTER; flags |= Slot.HAS_SETTER;
if ((delegateTo == HAS_STATIC_ACCESSORS) != if ((delegateTo == HAS_STATIC_ACCESSORS) !=
(Modifier.isStatic(setter.getModifiers()))) (Modifier.isStatic(setter.getModifiers())))
{ {
throw new PropertyException( throw PropertyException.withMessage0("msg.getter.static");
Context.getMessage("msg.getter.static", null));
} }
parmTypes = setter.getParameterTypes(); parmTypes = setter.getParameterTypes();
if (parmTypes.length == 2) { if (parmTypes.length == 2) {
if (parmTypes[0] != ScriptableObject.class) { if (parmTypes[0] != ScriptableObject.class) {
throw new PropertyException( throw PropertyException.withMessage0("msg.setter2.parms");
Context.getMessage("msg.setter2.parms", null));
} }
if (delegateTo == null) { if (delegateTo == null) {
Object[] args = { setter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.setter1.parms", setter.toString());
Context.getMessage("msg.setter1.parms", args));
} }
} else if (parmTypes.length == 1) { } else if (parmTypes.length == 1) {
if (delegateTo != null) { if (delegateTo != null) {
Object[] args = { setter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.setter2.expected", setter.toString());
Context.getMessage("msg.setter2.expected", args));
} }
} else { } else {
throw new PropertyException( throw PropertyException.withMessage0("msg.setter.parms");
Context.getMessage("msg.setter.parms", null));
} }
} }
int slotIndex = getSlotToSet(propertyName, int slotIndex = getSlotToSet(propertyName,
@ -1226,14 +1206,12 @@ public abstract class ScriptableObject implements Scriptable {
String name = names[i]; String name = names[i];
Method[] m = FunctionObject.findMethods(clazz, name); Method[] m = FunctionObject.findMethods(clazz, name);
if (m == null) { if (m == null) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.method.not.found", name, clazz.getName());
Context.getMessage("msg.method.not.found", errArgs));
} }
if (m.length > 1) { if (m.length > 1) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", name, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
FunctionObject f = new FunctionObject(name, m[0], this); FunctionObject f = new FunctionObject(name, m[0], this);
defineProperty(name, f, attributes); defineProperty(name, f, attributes);
@ -1639,8 +1617,7 @@ public abstract class ScriptableObject implements Scriptable {
private synchronized int addSlot(String id, int index, boolean getterSlot) private synchronized int addSlot(String id, int index, boolean getterSlot)
{ {
if (count == -1) if (count == -1)
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.add.sealed");
("msg.add.sealed", null));
int start = (index & 0x7fffffff) % slots.length; int start = (index & 0x7fffffff) % slots.length;
int i = start; int i = start;
do { do {
@ -1678,8 +1655,7 @@ public abstract class ScriptableObject implements Scriptable {
*/ */
private synchronized void removeSlot(String name, int index) { private synchronized void removeSlot(String name, int index) {
if (count == -1) if (count == -1)
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.remove.sealed");
("msg.remove.sealed", null));
int slotIndex = getSlot(name, index); int slotIndex = getSlot(name, index);
if (slotIndex == SLOT_NOT_FOUND) if (slotIndex == SLOT_NOT_FOUND)
return; return;

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

@ -635,10 +635,8 @@ public class TokenStream {
public void ungetToken(int tt) { public void ungetToken(int tt) {
if (this.pushbackToken != EOF && tt != ERROR) { if (this.pushbackToken != EOF && tt != ERROR) {
Object[] errArgs = { tokenToString(tt), String message = Context.getMessage2("msg.token.replaces.pushback",
tokenToString(this.pushbackToken) }; tokenToString(tt), tokenToString(this.pushbackToken));
String message = Context.getMessage("msg.token.replaces.pushback",
errArgs);
throw new RuntimeException(message); throw new RuntimeException(message);
} }
this.pushbackToken = tt; this.pushbackToken = tt;

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

@ -133,7 +133,6 @@ public class Undefined implements Scriptable {
} }
private RuntimeException reportError() { private RuntimeException reportError() {
String message = Context.getMessage("msg.undefined", null); return Context.reportRuntimeError0("msg.undefined");
return Context.reportRuntimeError(message);
} }
} }

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

@ -90,8 +90,7 @@ public class VariableTable {
LocalVariable p = (LocalVariable) LocalVariable p = (LocalVariable)
(itsVariables.elementAt(pIndex.intValue())); (itsVariables.elementAt(pIndex.intValue()));
if (p.isParameter()) { if (p.isParameter()) {
Object[] errorArgs = { pName }; String message = Context.getMessage1("msg.dup.parms", pName);
String message = Context.getMessage("msg.dup.parms", errorArgs);
Context.reportWarning(message, null, 0, null, 0); Context.reportWarning(message, null, 0, null, 0);
} }
else { // there's a local variable with this name, blow it off else { // there's a local variable with this name, blow it off

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

@ -532,6 +532,28 @@ public final class Context {
} }
} }
static EvaluatorException reportRuntimeError0(String messageId) {
return reportRuntimeError(getMessage0(messageId));
}
static EvaluatorException reportRuntimeError1
(String messageId, Object arg1)
{
return reportRuntimeError(getMessage1(messageId, arg1));
}
static EvaluatorException reportRuntimeError2
(String messageId, Object arg1, Object arg2)
{
return reportRuntimeError(getMessage2(messageId, arg1, arg2));
}
static EvaluatorException reportRuntimeError3
(String messageId, Object arg1, Object arg2, Object arg3)
{
return reportRuntimeError(getMessage3(messageId, arg1, arg2, arg3));
}
/** /**
* Report a runtime error using the error reporter for the current thread. * Report a runtime error using the error reporter for the current thread.
* *
@ -1010,13 +1032,11 @@ public final class Context {
{ {
Object ctorVal = ScriptRuntime.getTopLevelProp(scope, constructorName); Object ctorVal = ScriptRuntime.getTopLevelProp(scope, constructorName);
if (ctorVal == Scriptable.NOT_FOUND) { if (ctorVal == Scriptable.NOT_FOUND) {
Object[] errArgs = { constructorName }; String message = getMessage1("msg.ctor.not.found", constructorName);
String message = getMessage("msg.ctor.not.found", errArgs);
throw new PropertyException(message); throw new PropertyException(message);
} }
if (!(ctorVal instanceof Function)) { if (!(ctorVal instanceof Function)) {
Object[] errArgs = { constructorName }; String message = getMessage1("msg.not.ctor", constructorName);
String message = getMessage("msg.not.ctor", errArgs);
throw new NotAFunctionException(message); throw new NotAFunctionException(message);
} }
Function ctor = (Function) ctorVal; Function ctor = (Function) ctorVal;
@ -1528,6 +1548,26 @@ public final class Context {
} }
static String getMessage0(String messageId) {
return getMessage(messageId, null);
}
static String getMessage1(String messageId, Object arg1) {
Object[] arguments = {arg1};
return getMessage(messageId, arguments);
}
static String getMessage2(String messageId, Object arg1, Object arg2) {
Object[] arguments = {arg1, arg2};
return getMessage(messageId, arguments);
}
static String getMessage3
(String messageId, Object arg1, Object arg2, Object arg3) {
Object[] arguments = {arg1, arg2, arg3};
return getMessage(messageId, arguments);
}
/** /**
* Internal method that reports an error for missing calls to * Internal method that reports an error for missing calls to
* enter(). * enter().

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

@ -306,8 +306,7 @@ public class FlattenedObject {
JavaScriptException JavaScriptException
{ {
if (!hasProperty(id)) { if (!hasProperty(id)) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
Object o = getProperty(id); Object o = getProperty(id);
if (o instanceof FlattenedObject) if (o instanceof FlattenedObject)

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

@ -138,10 +138,8 @@ public class FunctionObject extends NativeFunction {
types[2] != ScriptRuntime.FunctionClass || types[2] != ScriptRuntime.FunctionClass ||
types[3] != Boolean.TYPE) types[3] != Boolean.TYPE)
{ {
String[] args = { methodName }; throw Context.reportRuntimeError1(
String message = Context.getMessage("msg.varargs.ctor", "msg.varargs.ctor", methodName);
args);
throw Context.reportRuntimeError(message);
} }
parmsLength = VARARGS_CTOR; parmsLength = VARARGS_CTOR;
} else { } else {
@ -151,10 +149,8 @@ public class FunctionObject extends NativeFunction {
types[2].getComponentType() != ScriptRuntime.ObjectClass || types[2].getComponentType() != ScriptRuntime.ObjectClass ||
types[3] != ScriptRuntime.FunctionClass) types[3] != ScriptRuntime.FunctionClass)
{ {
String[] args = { methodName }; throw Context.reportRuntimeError1(
String message = Context.getMessage("msg.varargs.fun", "msg.varargs.fun", methodName);
args);
throw Context.reportRuntimeError(message);
} }
parmsLength = VARARGS_METHOD; parmsLength = VARARGS_METHOD;
} }
@ -176,10 +172,9 @@ public class FunctionObject extends NativeFunction {
type != Float.TYPE && type != Float.TYPE &&
type != Double.TYPE) type != Double.TYPE)
{ {
// Note that long is not supported; see comments above // Note that long is not supported.
Object[] errArgs = { methodName }; throw Context.reportRuntimeError1("msg.bad.parms",
throw Context.reportRuntimeError( methodName);
Context.getMessage("msg.bad.parms", errArgs));
} }
} }
length = parmsLength; length = parmsLength;
@ -426,9 +421,8 @@ public class FunctionObject extends NativeFunction {
// Note that the long type is not supported; see the javadoc for // Note that the long type is not supported; see the javadoc for
// the constructor for this class // the constructor for this class
Object[] errArgs = { desired.getName() }; throw Context.reportRuntimeError1
throw Context.reportRuntimeError( ("msg.cant.convert", desired.getName());
Context.getMessage("msg.cant.convert", errArgs));
} }
/** /**
@ -463,8 +457,8 @@ public class FunctionObject extends NativeFunction {
thisObj = thisObj.getPrototype(); thisObj = thisObj.getPrototype();
if (thisObj == null || !useDynamicScope) { if (thisObj == null || !useDynamicScope) {
// Couldn't find an object to call this on. // Couldn't find an object to call this on.
Object[] errArgs = { names[0] }; String msg = Context.getMessage1
String msg = Context.getMessage("msg.incompat.call", errArgs); ("msg.incompat.call", names[0]);
throw NativeGlobal.constructError(cx, "TypeError", msg, scope); throw NativeGlobal.constructError(cx, "TypeError", msg, scope);
} }
} }

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

@ -1036,10 +1036,10 @@ public class IRFactory {
if (scope != null) if (scope != null)
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "SyntaxError", Context.getContext(), "SyntaxError",
ScriptRuntime.getMessage(msgResource, null), ScriptRuntime.getMessage0(msgResource),
scope); scope);
else { else {
String message = Context.getMessage(msgResource, null); String message = Context.getMessage0(msgResource);
Context.reportError(message, ts.getSourceName(), ts.getLineno(), Context.reportError(message, ts.getSourceName(), ts.getLineno(),
ts.getLine(), ts.getOffset()); ts.getLine(), ts.getOffset());
} }

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

@ -106,10 +106,8 @@ public class ImporterTopLevel extends ScriptableObject {
if (result == NOT_FOUND) { if (result == NOT_FOUND) {
result = v; result = v;
} else { } else {
String[] args = { result.toString(), v.toString() }; throw Context.reportRuntimeError2(
throw Context.reportRuntimeError( "msg.ambig.import", result.toString(), v.toString());
Context.getMessage("msg.ambig.import",
args));
} }
} }
} }
@ -121,15 +119,14 @@ public class ImporterTopLevel extends ScriptableObject {
for (int i=0; i<args.length; i++) { for (int i=0; i<args.length; i++) {
Object cl = args[i]; Object cl = args[i];
if (!(cl instanceof NativeJavaClass)) { if (!(cl instanceof NativeJavaClass)) {
String[] eargs = { Context.toString(cl) }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage("msg.not.class", eargs)); "msg.not.class", Context.toString(cl));
} }
String s = ((NativeJavaClass) cl).getClassObject().getName(); String s = ((NativeJavaClass) cl).getClassObject().getName();
String n = s.substring(s.lastIndexOf('.')+1); String n = s.substring(s.lastIndexOf('.')+1);
Object val = thisObj.get(n, thisObj); Object val = thisObj.get(n, thisObj);
if (val != NOT_FOUND && val != cl) { if (val != NOT_FOUND && val != cl) {
String[] eargs = { n }; throw Context.reportRuntimeError1("msg.prop.defined", n);
throw Context.reportRuntimeError(Context.getMessage("msg.prop.defined", eargs));
} }
//thisObj.defineProperty(n, cl, DONTENUM); //thisObj.defineProperty(n, cl, DONTENUM);
thisObj.put(n,thisObj,cl); thisObj.put(n,thisObj,cl);
@ -150,8 +147,8 @@ public class ImporterTopLevel extends ScriptableObject {
for (int i=0; i<args.length; i++) { for (int i=0; i<args.length; i++) {
Object pkg = args[i]; Object pkg = args[i];
if (!(pkg instanceof NativeJavaPackage)) { if (!(pkg instanceof NativeJavaPackage)) {
String[] eargs = { Context.toString(pkg) }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage("msg.not.pkg", eargs)); "msg.not.pkg", Context.toString(pkg));
} }
Object[] elements = cx.getElements(importedPackages); Object[] elements = cx.getElements(importedPackages);
for (int j=0; j < elements.length; j++) { for (int j=0; j < elements.length; j++) {

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

@ -220,25 +220,22 @@ class JavaMembers {
try { try {
field = (Field) member; field = (Field) member;
if (field == null) { if (field == null) {
Object[] args = {name}; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError( "msg.java.internal.private", name);
Context.getMessage("msg.java.internal.private", args));
} }
field.set(javaObject, NativeJavaObject.coerceType(field.getType(), field.set(javaObject,
value)); NativeJavaObject.coerceType(field.getType(), value));
} catch (ClassCastException e) { } catch (ClassCastException e) {
Object errArgs[] = { name }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage "msg.java.method.assign", name);
("msg.java.method.assign",
errArgs));
} catch (IllegalAccessException accessEx) { } catch (IllegalAccessException accessEx) {
throw new RuntimeException("unexpected IllegalAccessException "+ throw new RuntimeException("unexpected IllegalAccessException "+
"accessing Java field"); "accessing Java field");
} catch (IllegalArgumentException argEx) { } catch (IllegalArgumentException argEx) {
Object errArgs[] = { value.getClass().getName(), field, throw Context.reportRuntimeError3(
javaObject.getClass().getName() }; "msg.java.internal.field.type",
throw Context.reportRuntimeError(Context.getMessage( value.getClass().getName(), field,
"msg.java.internal.field.type", errArgs)); javaObject.getClass().getName());
} }
} }
} }
@ -516,11 +513,8 @@ class JavaMembers {
} }
RuntimeException reportMemberNotFound(String memberName) { RuntimeException reportMemberNotFound(String memberName) {
Object errArgs[] = { cl.getName(), return Context.reportRuntimeError2(
memberName }; "msg.java.member.not.found", cl.getName(), memberName);
return Context.reportRuntimeError(
Context.getMessage("msg.java.member.not.found",
errArgs));
} }
static Hashtable classTable = new Hashtable(); static Hashtable classTable = new Hashtable();
@ -573,9 +567,8 @@ class FieldAndMethods extends NativeJavaMethod {
rval = field.get(javaObject); rval = field.get(javaObject);
type = field.getType(); type = field.getType();
} catch (IllegalAccessException accEx) { } catch (IllegalAccessException accEx) {
Object[] args = {getName()}; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage "msg.java.internal.private", getName());
("msg.java.internal.private", args));
} }
rval = NativeJavaObject.wrap(this, rval, type); rval = NativeJavaObject.wrap(this, rval, type);
if (rval instanceof Scriptable) { if (rval instanceof Scriptable) {

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

@ -219,8 +219,7 @@ public class NativeArray extends ScriptableObject {
else { else {
long len = ScriptRuntime.toUint32(args[0]); long len = ScriptRuntime.toUint32(args[0]);
if (len != (((Number)(args[0])).doubleValue())) if (len != (((Number)(args[0])).doubleValue()))
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.arraylength.bad");
("msg.arraylength.bad", null));
return new NativeArray(len); return new NativeArray(len);
} }
} }
@ -242,13 +241,11 @@ public class NativeArray extends ScriptableObject {
*/ */
if (!(val instanceof Number)) if (!(val instanceof Number))
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.arraylength.bad");
("msg.arraylength.bad", null));
long longVal = ScriptRuntime.toUint32(val); long longVal = ScriptRuntime.toUint32(val);
if (longVal != (((Number)val).doubleValue())) if (longVal != (((Number)val).doubleValue()))
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.arraylength.bad");
("msg.arraylength.bad", null));
if (longVal < length) { if (longVal < length) {
// remove all properties between longVal and length // remove all properties between longVal and length

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

@ -91,9 +91,7 @@ public final class NativeCall extends ScriptableObject {
Function ctorObj, boolean inNewExpr) Function ctorObj, boolean inNewExpr)
{ {
if (!inNewExpr) { if (!inNewExpr) {
Object[] errArgs = { "Call" }; throw Context.reportRuntimeError1("msg.only.from.new", "Call");
throw Context.reportRuntimeError(Context.getMessage
("msg.only.from.new", errArgs));
} }
ScriptRuntime.checkDeprecated(cx, "Call"); ScriptRuntime.checkDeprecated(cx, "Call");
NativeCall result = new NativeCall(); NativeCall result = new NativeCall();

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

@ -1148,8 +1148,8 @@ public class NativeDate extends ScriptableObject {
Function funObj) { Function funObj) {
if (obj == null || !(obj instanceof NativeDate)) { if (obj == null || !(obj instanceof NativeDate)) {
Context cx = Context.getCurrentContext(); Context cx = Context.getCurrentContext();
Object[] args = { ((NativeFunction) funObj).names[0] }; String name = ((NativeFunction) funObj).names[0];
String msg = Context.getMessage("msg.incompat.call", args); String msg = Context.getMessage1("msg.incompat.call", name);
throw NativeGlobal.constructError(cx, "TypeError", msg, funObj); throw NativeGlobal.constructError(cx, "TypeError", msg, funObj);
} }
return (NativeDate) obj; return (NativeDate) obj;

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

@ -117,9 +117,8 @@ public class NativeFunction extends ScriptableObject implements Function {
if (protoProp instanceof Scriptable && protoProp != Undefined.instance) { if (protoProp instanceof Scriptable && protoProp != Undefined.instance) {
return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp); return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp);
} }
Object[] args = { names[0] }; String m = ScriptRuntime.getMessage1("msg.instanceof.bad.prototype",
String m = ScriptRuntime.getMessage("msg.instanceof.bad.prototype", names[0]);
args);
throw NativeGlobal.constructError(Context.getContext(), "TypeError", throw NativeGlobal.constructError(Context.getContext(), "TypeError",
m, instance); m, instance);
} }
@ -404,15 +403,13 @@ public class NativeFunction extends ScriptableObject implements Function {
if (names != null && names.length > 0 if (names != null && names.length > 0
&& names[0].length() > 0) && names[0].length() > 0)
{ {
Object[] errArgs = { new Integer((int)source.charAt(i)), message = Context.getMessage2
names[0] }; ("msg.no.function.ref.found.in",
message = Context.getMessage new Integer((int)source.charAt(i)), names[0]);
("msg.no.function.ref.found.in", errArgs);
} else { } else {
Object[] errArgs message = Context.getMessage1
= { new Integer((int)source.charAt(i)) }; ("msg.no.function.ref.found",
message = Context.getMessage new Integer((int)source.charAt(i)));
("msg.no.function.ref.found", errArgs);
} }
throw Context.reportRuntimeError(message); throw Context.reportRuntimeError(message);
} }
@ -844,9 +841,8 @@ public class NativeFunction extends ScriptableObject implements Function {
{ {
Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass); Object val = thisObj.getDefaultValue(ScriptRuntime.FunctionClass);
if (!(val instanceof NativeFunction)) { if (!(val instanceof NativeFunction)) {
Object[] errArgs = { "toString" }; String m = Context.getMessage1("msg.incompat.call", "toString");
String message = Context.getMessage("msg.incompat.call", errArgs); throw NativeGlobal.constructError(cx, "TypeError", m, funObj);
throw NativeGlobal.constructError(cx, "TypeError", message, funObj);
} }
if (val instanceof NativeJavaMethod) { if (val instanceof NativeJavaMethod) {
return "\nfunction " + ((NativeFunction) val).jsGet_name() + return "\nfunction " + ((NativeFunction) val).jsGet_name() +
@ -932,7 +928,7 @@ public class NativeFunction extends ScriptableObject implements Function {
else else
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
cx, "TypeError", cx, "TypeError",
ScriptRuntime.getMessage("msg.arg.isnt.array", null), ScriptRuntime.getMessage0("msg.arg.isnt.array"),
thisObj); thisObj);
} }
else else

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

@ -386,8 +386,7 @@ public class NativeGlobal {
Object[] args, Function funObj) Object[] args, Function funObj)
throws JavaScriptException throws JavaScriptException
{ {
Object[] a = { "eval" }; String m = ScriptRuntime.getMessage1("msg.cant.call.indirect", "eval");
String m = ScriptRuntime.getMessage("msg.cant.call.indirect", a);
throw NativeGlobal.constructError(cx, "EvalError", m, funObj); throw NativeGlobal.constructError(cx, "EvalError", m, funObj);
} }
@ -405,7 +404,7 @@ public class NativeGlobal {
return Undefined.instance; return Undefined.instance;
Object x = args[0]; Object x = args[0];
if (!(x instanceof String)) { if (!(x instanceof String)) {
String message = Context.getMessage("msg.eval.nonstring", null); String message = Context.getMessage0("msg.eval.nonstring");
Context.reportWarning(message); Context.reportWarning(message);
return x; return x;
} }
@ -435,7 +434,7 @@ public class NativeGlobal {
// infinite looping on while(true) { eval('foo bar') } - // infinite looping on while(true) { eval('foo bar') } -
// so we throw an EvaluatorException. // so we throw an EvaluatorException.
if (script == null) { if (script == null) {
String message = Context.getMessage("msg.syntax", null); String message = Context.getMessage0("msg.syntax");
throw new EvaluatorException(message); throw new EvaluatorException(message);
} }
@ -544,21 +543,18 @@ public class NativeGlobal {
R.append(C); R.append(C);
} else { } else {
if ((C >= 0xDC00) && (C <= 0xDFFF)) { if ((C >= 0xDC00) && (C <= 0xDFFF)) {
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
} }
if ((C < 0xD800) || (C > 0xDBFF)) if ((C < 0xD800) || (C > 0xDBFF))
V = C; V = C;
else { else {
k++; k++;
if (k == str.length()) { if (k == str.length()) {
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
} }
C2 = str.charAt(k); C2 = str.charAt(k);
if ((C2 < 0xDC00) || (C2 > 0xDFFF)) { if ((C2 < 0xDC00) || (C2 > 0xDFFF)) {
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
} }
V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000; V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000;
} }
@ -607,11 +603,9 @@ public class NativeGlobal {
if (C == '%') { if (C == '%') {
start = k; start = k;
if ((k + 2) >= str.length()) if ((k + 2) >= str.length())
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
if (!isHex(str.charAt(k + 1)) || !isHex(str.charAt(k + 2))) if (!isHex(str.charAt(k + 1)) || !isHex(str.charAt(k + 2)))
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
B = unHex(str.charAt(k + 1)) * 16 + unHex(str.charAt(k + 2)); B = unHex(str.charAt(k + 1)) * 16 + unHex(str.charAt(k + 2));
k += 2; k += 2;
if ((B & 0x80) == 0) if ((B & 0x80) == 0)
@ -620,26 +614,21 @@ public class NativeGlobal {
n = 1; n = 1;
while ((B & (0x80 >>> n)) != 0) n++; while ((B & (0x80 >>> n)) != 0) n++;
if ((n == 1) || (n > 6)) if ((n == 1) || (n > 6))
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
octets[0] = (char)B; octets[0] = (char)B;
if ((k + 3 * (n - 1)) >= str.length()) if ((k + 3 * (n - 1)) >= str.length())
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
for (j = 1; j < n; j++) { for (j = 1; j < n; j++) {
k++; k++;
if (str.charAt(k) != '%') if (str.charAt(k) != '%')
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
if (!isHex(str.charAt(k + 1)) if (!isHex(str.charAt(k + 1))
|| !isHex(str.charAt(k + 2))) || !isHex(str.charAt(k + 2)))
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
B = unHex(str.charAt(k + 1)) * 16 B = unHex(str.charAt(k + 1)) * 16
+ unHex(str.charAt(k + 2)); + unHex(str.charAt(k + 2));
if ((B & 0xC0) != 0x80) if ((B & 0xC0) != 0x80)
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
k += 2; k += 2;
octets[j] = (char)B; octets[j] = (char)B;
} }
@ -647,8 +636,7 @@ public class NativeGlobal {
if (V >= 0x10000) { if (V >= 0x10000) {
V -= 0x10000; V -= 0x10000;
if (V > 0xFFFFF) if (V > 0xFFFFF)
throw cx.reportRuntimeError( throw cx.reportRuntimeError0("msg.bad.uri");
cx.getMessage("msg.bad.uri", null));
C = (char)((V & 0x3FF) + 0xDC00); C = (char)((V & 0x3FF) + 0xDC00);
H = (char)((V >>> 10) + 0xD800); H = (char)((V >>> 10) + 0xD800);
R.append(H); R.append(H);

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

@ -88,11 +88,8 @@ public class NativeJavaArray extends NativeJavaObject {
if (result == NOT_FOUND && if (result == NOT_FOUND &&
!ScriptRuntime.hasProp(getPrototype(), id)) !ScriptRuntime.hasProp(getPrototype(), id))
{ {
Object errArgs[] = { array.getClass().getName(), throw Context.reportRuntimeError2(
id }; "msg.java.member.not.found", array.getClass().getName(), id);
throw Context.reportRuntimeError(
Context.getMessage("msg.java.member.not.found",
errArgs));
} }
return result; return result;
} }

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

@ -172,9 +172,8 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
Constructor ctor = (Constructor) member; Constructor ctor = (Constructor) member;
if (ctor == null) { if (ctor == null) {
String sig = NativeJavaMethod.scriptSignature(args); String sig = NativeJavaMethod.scriptSignature(args);
Object errArgs[] = { classObject.getName(), sig }; throw Context.reportRuntimeError2(
throw Context.reportRuntimeError(Context.getMessage( "msg.no.java.ctor", classObject.getName(), sig);
"msg.no.java.ctor", errArgs));
} }
// Found the constructor, so try invoking it. // Found the constructor, so try invoking it.
@ -200,10 +199,8 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
if (m != null) if (m != null)
msg = m; msg = m;
} }
Object[] errArgs = { msg, classObject.getName() }; throw Context.reportRuntimeError2(
throw Context.reportRuntimeError(Context.getMessage "msg.cant.instantiate", msg, classObject.getName());
("msg.cant.instantiate",
errArgs));
} }
} }
@ -230,24 +227,19 @@ public class NativeJavaClass extends NativeJavaObject implements Function {
classObject); classObject);
} catch (InstantiationException instEx) { } catch (InstantiationException instEx) {
Object[] errArgs = { instEx.getMessage(), throw Context.reportRuntimeError2(
classObject.getName() }; "msg.cant.instantiate",
throw Context.reportRuntimeError(Context.getMessage instEx.getMessage(), classObject.getName());
("msg.cant.instantiate",
errArgs));
} catch (IllegalArgumentException argEx) { } catch (IllegalArgumentException argEx) {
String signature = NativeJavaMethod.scriptSignature(args); String signature = NativeJavaMethod.scriptSignature(args);
String ctorString = ctor.toString(); String ctorString = ctor.toString();
Object[] errArgs = { argEx.getMessage(),ctorString,signature }; throw Context.reportRuntimeError3(
throw Context.reportRuntimeError(Context.getMessage "msg.bad.ctor.sig", argEx.getMessage(), ctorString, signature);
("msg.bad.ctor.sig",
errArgs));
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw JavaScriptException.wrapException(scope, e); throw JavaScriptException.wrapException(scope, e);
} catch (IllegalAccessException accessEx) { } catch (IllegalAccessException accessEx) {
Object[] errArgs = { accessEx.getMessage() }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(Context.getMessage "msg.java.internal.private", accessEx.getMessage());
("msg.java.internal.private", errArgs));
} }
} }

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

@ -180,9 +180,7 @@ public class NativeJavaMethod extends NativeFunction implements Function {
Class c = methods[0].getDeclaringClass(); Class c = methods[0].getDeclaringClass();
String sig = c.getName() + "." + names[0] + "(" + String sig = c.getName() + "." + names[0] + "(" +
scriptSignature(args) + ")"; scriptSignature(args) + ")";
Object errArgs[] = { sig }; throw Context.reportRuntimeError1("msg.java.no_such_method", sig);
throw Context.reportRuntimeError(
Context.getMessage("msg.java.no_such_method", errArgs));
} }
// OPT: already retrieved in findFunction, so we should inline that // OPT: already retrieved in findFunction, so we should inline that
@ -201,9 +199,8 @@ public class NativeJavaMethod extends NativeFunction implements Function {
while (!(o instanceof Wrapper)) { while (!(o instanceof Wrapper)) {
o = o.getPrototype(); o = o.getPrototype();
if (o == null) { if (o == null) {
Object errArgs[] = { names[0] }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError( "msg.nonjava.method", names[0]);
Context.getMessage("msg.nonjava.method", errArgs));
} }
} }
javaObject = ((Wrapper) o).unwrap(); javaObject = ((Wrapper) o).unwrap();

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

@ -222,10 +222,10 @@ public class NativeJavaObject implements Scriptable, Wrapper {
{ {
Function converter = getConverter(converterName); Function converter = getConverter(converterName);
if (converter == null) { if (converter == null) {
Object[] errArgs = { converterName, javaObject.getClass().getName() }; String className = javaObject.getClass().getName();
throw Context.reportRuntimeError( throw Context.reportRuntimeError2
Context.getMessage("msg.java.conversion.implicit_method", ("msg.java.conversion.implicit_method",
errArgs)); converterName, className);
} }
return callConverter(converter); return callConverter(converter);
} }
@ -243,8 +243,7 @@ public class NativeJavaObject implements Scriptable, Wrapper {
} catch (JavaScriptException jse) { } catch (JavaScriptException jse) {
// fall through to error message // fall through to error message
} }
throw Context.reportRuntimeError( throw Context.reportRuntimeError0("msg.default.value");
Context.getMessage("msg.default.value", null));
} }
@ -888,11 +887,9 @@ public class NativeJavaObject implements Scriptable, Wrapper {
} }
static void reportConversionError(Object value, Class type) { static void reportConversionError(Object value, Class type) {
Object[] args = { value.toString(), throw Context.reportRuntimeError2
NativeJavaMethod.javaSignature(type) ("msg.conversion.not.allowed",
}; value.toString(), NativeJavaMethod.javaSignature(type));
throw Context.reportRuntimeError(
Context.getMessage("msg.conversion.not.allowed", args));
} }
public static void initJSObject() { public static void initJSObject() {

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

@ -145,8 +145,7 @@ public class NativeJavaPackage extends ScriptableObject {
} }
public void put(int index, Scriptable start, Object value) { public void put(int index, Scriptable start, Object value) {
throw Context.reportRuntimeError( throw Context.reportRuntimeError0("msg.pkg.int");
Context.getMessage("msg.pkg.int", null));
} }
public Object get(String id, Scriptable start) { public Object get(String id, Scriptable start) {
@ -230,7 +229,7 @@ public class NativeJavaPackage extends ScriptableObject {
} }
} }
throw Context.reportRuntimeError( throw Context.reportRuntimeError(
Context.getMessage("msg.not.java.obj", null)); Context.getMessage0("msg.not.java.obj"));
} }
private String packageName; private String packageName;

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

@ -144,11 +144,10 @@ public class NativeNumber extends ScriptableObject {
} else { } else {
precision = ScriptRuntime.toInt32(arg); precision = ScriptRuntime.toInt32(arg);
if (precision < precisionMin || precision > precisionMax) { if (precision < precisionMin || precision > precisionMax) {
Object args[] = new Object[1];
args[0] = Integer.toString(precision);
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getCurrentContext(), "RangeError", Context.getCurrentContext(), "RangeError",
ScriptRuntime.getMessage("msg.bad.precision", args), ScriptRuntime.getMessage1(
"msg.bad.precision", Integer.toString(precision)),
this); this);
} }
} }

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

@ -120,9 +120,8 @@ public class NativeScript extends NativeFunction implements Script {
} }
public Object jsFunction_exec() throws JavaScriptException { public Object jsFunction_exec() throws JavaScriptException {
Object[] msgArgs = { "exec" }; throw Context.reportRuntimeError1
throw Context.reportRuntimeError( ("msg.cant.call.indirect", "exec");
Context.getMessage("msg.cant.call.indirect", msgArgs));
} }
public static Object jsFunction_toString(Context cx, Scriptable thisObj, public static Object jsFunction_toString(Context cx, Scriptable thisObj,
@ -163,8 +162,7 @@ public class NativeScript extends NativeFunction implements Script {
public Scriptable construct(Context cx, Scriptable scope, Object[] args) public Scriptable construct(Context cx, Scriptable scope, Object[] args)
throws JavaScriptException throws JavaScriptException
{ {
String message = Context.getMessage("msg.script.is.not.constructor", null); throw Context.reportRuntimeError0("msg.script.is.not.constructor");
throw Context.reportRuntimeError(message);
} }
private Script script; private Script script;

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

@ -726,7 +726,7 @@ public class NativeString extends ScriptableObject {
private static RegExpProxy checkReProxy(Context cx) { private static RegExpProxy checkReProxy(Context cx) {
RegExpProxy result = cx.getRegExpProxy(); RegExpProxy result = cx.getRegExpProxy();
if (result == null) { if (result == null) {
throw cx.reportRuntimeError(cx.getMessage("msg.no.regexp", null)); throw cx.reportRuntimeError0("msg.no.regexp");
} }
return result; return result;
} }

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

@ -141,18 +141,14 @@ public class NativeWith implements Scriptable {
public static Object jsConstructor(Context cx, Object[] args, public static Object jsConstructor(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr) Function ctorObj, boolean inNewExpr)
{ {
Object[] msgArgs = { "With" }; throw Context.reportRuntimeError1("msg.cant.call.indirect", "With");
throw Context.reportRuntimeError(
Context.getMessage("msg.cant.call.indirect", msgArgs));
} }
public static Object newWithSpecial(Context cx, Object[] args, public static Object newWithSpecial(Context cx, Object[] args,
Function ctorObj, boolean inNewExpr) Function ctorObj, boolean inNewExpr)
{ {
if (!inNewExpr) { if (!inNewExpr) {
Object[] errArgs = { "With" }; throw Context.reportRuntimeError1("msg.only.from.new", "With");
throw Context.reportRuntimeError(Context.getMessage
("msg.only.from.new", errArgs));
} }
ScriptRuntime.checkDeprecated(cx, "With"); ScriptRuntime.checkDeprecated(cx, "With");

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

@ -133,9 +133,8 @@ public class NodeTransformer {
if (n.getType() == TokenStream.LABEL) { if (n.getType() == TokenStream.LABEL) {
String otherId = (String)n.getProp(Node.LABEL_PROP); String otherId = (String)n.getProp(Node.LABEL_PROP);
if (id.equals(otherId)) { if (id.equals(otherId)) {
Object[] errArgs = { id }; String message = Context.getMessage1(
String message = Context.getMessage("msg.dup.label", "msg.dup.label", id);
errArgs);
reportMessage(Context.getContext(), message, node, reportMessage(Context.getContext(), message, node,
tree, true, scope); tree, true, scope);
break typeswitch; break typeswitch;
@ -361,8 +360,7 @@ public class NodeTransformer {
("msg.bad.break", null); ("msg.bad.break", null);
} }
} else if (loop != null) { } else if (loop != null) {
message = Context.getMessage("msg.continue.nonloop", message = Context.getMessage0("msg.continue.nonloop");
null);
} else { } else {
Object[] errArgs = { id }; Object[] errArgs = { id };
message = Context.getMessage message = Context.getMessage

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

@ -47,4 +47,19 @@ public class PropertyException extends Exception {
super(detail); super(detail);
} }
static PropertyException withMessage0(String messageId) {
return new PropertyException(Context.getMessage0(messageId));
}
static PropertyException withMessage1(String messageId, Object arg1) {
return new PropertyException(Context.getMessage1(messageId, arg1));
}
static PropertyException withMessage2
(String messageId, Object arg1, Object arg2)
{
return new PropertyException
(Context.getMessage2(messageId, arg1, arg2));
}
} }

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

@ -432,9 +432,8 @@ public class ScriptRuntime {
return "0"; return "0";
if ((base < 2) || (base > 36)) { if ((base < 2) || (base > 36)) {
Object[] args = { Integer.toString(base) }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(getMessage "msg.bad.radix", Integer.toString(base));
("msg.bad.radix", args));
} }
if (base != 10) { if (base != 10) {
@ -462,14 +461,14 @@ public class ScriptRuntime {
if (val == null) { if (val == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
if (val instanceof Scriptable) { if (val instanceof Scriptable) {
if (val == Undefined.instance) { if (val == Undefined.instance) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.undef.to.object", null), ScriptRuntime.getMessage0("msg.undef.to.object"),
scope); scope);
} }
return (Scriptable) val; return (Scriptable) val;
@ -683,7 +682,7 @@ public class ScriptRuntime {
: "msg.undefined"; : "msg.undefined";
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "ConversionError", Context.getContext(), "ConversionError",
ScriptRuntime.getMessage(msg, null), ScriptRuntime.getMessage0(msg),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -722,7 +721,7 @@ public class ScriptRuntime {
if (s == null) { if (s == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
return s.getPrototype(); return s.getPrototype();
@ -752,7 +751,7 @@ public class ScriptRuntime {
if (s == null) { if (s == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
return s.getParentScope(); return s.getParentScope();
@ -769,16 +768,15 @@ public class ScriptRuntime {
Scriptable s = result; Scriptable s = result;
while (s != null) { while (s != null) {
if (s == start) { if (s == start) {
Object[] args = { "__proto__" }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(getMessage "msg.cyclic.value", "__proto__");
("msg.cyclic.value", args));
} }
s = s.getPrototype(); s = s.getPrototype();
} }
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
start.setPrototype(result); start.setPrototype(result);
@ -796,16 +794,15 @@ public class ScriptRuntime {
Scriptable s = result; Scriptable s = result;
while (s != null) { while (s != null) {
if (s == start) { if (s == start) {
Object[] args = { "__parent__" }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError(getMessage "msg.cyclic.value", "__parent__");
("msg.cyclic.value", args));
} }
s = s.getParentScope(); s = s.getParentScope();
} }
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
start.setParentScope(result); start.setParentScope(result);
@ -824,7 +821,7 @@ public class ScriptRuntime {
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -1090,10 +1087,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object[] args = { id.toString() }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "ReferenceError",
Context.getContext(), "ReferenceError", ScriptRuntime.getMessage1("msg.is.not.defined", id.toString()),
ScriptRuntime.getMessage("msg.is.not.defined", args),
scopeChain); scopeChain);
} }
@ -1137,10 +1133,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object[] args = { id };
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "ReferenceError", Context.getContext(), "ReferenceError",
ScriptRuntime.getMessage("msg.is.not.defined", args), ScriptRuntime.getMessage1("msg.is.not.defined", id),
scope); scope);
} }
@ -1171,8 +1166,7 @@ public class ScriptRuntime {
This code is causing immense performance problems in This code is causing immense performance problems in
scripts that assign to the variables as a way of creating them. scripts that assign to the variables as a way of creating them.
XXX need strict mode XXX need strict mode
String[] args = { id }; String message = getMessage1("msg.assn.create", id);
String message = getMessage("msg.assn.create", args);
Context.reportWarning(message); Context.reportWarning(message);
*/ */
return value; return value;
@ -1213,11 +1207,9 @@ public class ScriptRuntime {
function = (Function) fun; function = (Function) fun;
} }
catch (ClassCastException e) { catch (ClassCastException e) {
Object[] errorArgs = { toString(fun) }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "TypeError",
Context.getContext(), "TypeError", ScriptRuntime.getMessage1("msg.isnt.function", toString(fun)),
ScriptRuntime.getMessage("msg.isnt.function",
errorArgs),
scope); scope);
} }
@ -1293,10 +1285,9 @@ public class ScriptRuntime {
} catch (ClassCastException e) { } catch (ClassCastException e) {
// fall through to error // fall through to error
} }
Object[] errorArgs = { toString(fun) }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "TypeError",
Context.getContext(), "TypeError", ScriptRuntime.getMessage1("msg.isnt.function", toString(fun)),
ScriptRuntime.getMessage("msg.isnt.function", errorArgs),
scope); scope);
} }
@ -1396,10 +1387,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object args[] = { id }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "ReferenceError",
Context.getContext(), "ReferenceError", ScriptRuntime.getMessage1("msg.is.not.defined", id),
ScriptRuntime.getMessage("msg.is.not.defined", args),
scopeChain); scopeChain);
} }
@ -1413,7 +1403,7 @@ public class ScriptRuntime {
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -1493,10 +1483,9 @@ public class ScriptRuntime {
} while (m != null); } while (m != null);
obj = obj.getParentScope(); obj = obj.getParentScope();
} }
Object args[] = { id }; throw NativeGlobal.constructError
throw NativeGlobal.constructError( (Context.getContext(), "ReferenceError",
Context.getContext(), "ReferenceError", ScriptRuntime.getMessage1("msg.is.not.defined", id),
ScriptRuntime.getMessage("msg.is.not.defined", args),
scopeChain); scopeChain);
} }
@ -1510,7 +1499,7 @@ public class ScriptRuntime {
if (start == null) { if (start == null) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.null.to.object", null), ScriptRuntime.getMessage0("msg.null.to.object"),
scope); scope);
} }
Scriptable m = start; Scriptable m = start;
@ -1543,7 +1532,7 @@ public class ScriptRuntime {
if (result != null && result instanceof Scriptable) if (result != null && result instanceof Scriptable)
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.bad.default.value", null), ScriptRuntime.getMessage0("msg.bad.default.value"),
val); val);
return result; return result;
} }
@ -1696,7 +1685,7 @@ public class ScriptRuntime {
if (! (b instanceof Scriptable)) { if (! (b instanceof Scriptable)) {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.instanceof.not.object", null), ScriptRuntime.getMessage0("msg.instanceof.not.object"),
scope); scope);
} }
@ -1744,7 +1733,7 @@ public class ScriptRuntime {
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), Context.getContext(),
"TypeError", "TypeError",
ScriptRuntime.getMessage("msg.instanceof.not.object", null), ScriptRuntime.getMessage0("msg.instanceof.not.object"),
scope); scope);
} }
String s = getStringId(a); String s = getStringId(a);
@ -2002,9 +1991,7 @@ public class ScriptRuntime {
static void checkDeprecated(Context cx, String name) { static void checkDeprecated(Context cx, String name) {
int version = cx.getLanguageVersion(); int version = cx.getLanguageVersion();
if (version >= Context.VERSION_1_4 || version == Context.VERSION_DEFAULT) { if (version >= Context.VERSION_1_4 || version == Context.VERSION_DEFAULT) {
Object[] errArgs = { name }; String msg = getMessage1("msg.deprec.ctor", name);
String msg = getMessage("msg.deprec.ctor",
errArgs);
if (version == Context.VERSION_DEFAULT) if (version == Context.VERSION_DEFAULT)
Context.reportWarning(msg); Context.reportWarning(msg);
else else
@ -2012,6 +1999,20 @@ public class ScriptRuntime {
} }
} }
public static String getMessage0(String messageId) {
return Context.getMessage0(messageId);
}
public static String getMessage1(String messageId, Object arg1) {
return Context.getMessage1(messageId, arg1);
}
public static String getMessage2
(String messageId, Object arg1, Object arg2)
{
return Context.getMessage2(messageId, arg1, arg2);
}
public static String getMessage(String messageId, Object[] arguments) { public static String getMessage(String messageId, Object[] arguments) {
return Context.getMessage(messageId, arguments); return Context.getMessage(messageId, arguments);
} }
@ -2085,8 +2086,7 @@ public class ScriptRuntime {
private static RuntimeException errorWithClassName(String msg, Object val) private static RuntimeException errorWithClassName(String msg, Object val)
{ {
Object[] args = { val.getClass().getName() }; return Context.reportRuntimeError1(msg, val.getClass().getName());
return Context.reportRuntimeError(getMessage(msg, args));
} }
static public Object[] emptyArgs = new Object[0]; static public Object[] emptyArgs = new Object[0];

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

@ -356,8 +356,7 @@ public abstract class ScriptableObject implements Scriptable {
{ {
int slotIndex = getSlot(name, name.hashCode()); int slotIndex = getSlot(name, name.hashCode());
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
return slots[slotIndex].attributes; return slots[slotIndex].attributes;
} }
@ -381,8 +380,7 @@ public abstract class ScriptableObject implements Scriptable {
{ {
int slotIndex = getSlot(null, index); int slotIndex = getSlot(null, index);
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
return slots[slotIndex].attributes; return slots[slotIndex].attributes;
} }
@ -418,8 +416,7 @@ public abstract class ScriptableObject implements Scriptable {
attributes &= mask; // mask out unused bits attributes &= mask; // mask out unused bits
int slotIndex = getSlot(name, name.hashCode()); int slotIndex = getSlot(name, name.hashCode());
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
slots[slotIndex].attributes = (short) attributes; slots[slotIndex].attributes = (short) attributes;
} }
@ -444,8 +441,7 @@ public abstract class ScriptableObject implements Scriptable {
{ {
int slotIndex = getSlot(null, index); int slotIndex = getSlot(null, index);
if (slotIndex == SLOT_NOT_FOUND) { if (slotIndex == SLOT_NOT_FOUND) {
throw new PropertyException( throw PropertyException.withMessage0("msg.prop.not.found");
Context.getMessage("msg.prop.not.found", null));
} }
slots[slotIndex].attributes = (short) attributes; slots[slotIndex].attributes = (short) attributes;
} }
@ -562,9 +558,8 @@ public abstract class ScriptableObject implements Scriptable {
typeHint == Double.TYPE) typeHint == Double.TYPE)
hint = "number"; hint = "number";
else { else {
Object[] args = { typeHint.toString() }; throw Context.reportRuntimeError1(
throw Context.reportRuntimeError( "msg.invalid.type", typeHint.toString());
Context.getMessage("msg.invalid.type", args));
} }
Object v = getProperty(this, "valueOf"); Object v = getProperty(this, "valueOf");
if (!(v instanceof Function)) if (!(v instanceof Function))
@ -596,10 +591,9 @@ public abstract class ScriptableObject implements Scriptable {
// fall through to error // fall through to error
} }
Object arg = typeHint == null ? "undefined" : typeHint.toString(); Object arg = typeHint == null ? "undefined" : typeHint.toString();
Object[] args = { arg };
throw NativeGlobal.constructError( throw NativeGlobal.constructError(
Context.getContext(), "TypeError", Context.getContext(), "TypeError",
ScriptRuntime.getMessage("msg.default.value", args), ScriptRuntime.getMessage1("msg.default.value", arg),
this); this);
} }
@ -782,9 +776,8 @@ public abstract class ScriptableObject implements Scriptable {
} }
} }
if (protoCtor == null) { if (protoCtor == null) {
Object[] args = { clazz.getName() };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.zero.arg.ctor", args)); Context.getMessage1("msg.zero.arg.ctor", clazz.getName()));
} }
Scriptable proto = (Scriptable) Scriptable proto = (Scriptable)
@ -808,9 +801,9 @@ public abstract class ScriptableObject implements Scriptable {
Member ctorMember = null; Member ctorMember = null;
if (ctorMeths != null) { if (ctorMeths != null) {
if (ctorMeths.length > 1) { if (ctorMeths.length > 1) {
Object[] args = { ctorMeths[0], ctorMeths[1] };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.multiple.ctors", args)); Context.getMessage2("msg.multiple.ctors",
ctorMeths[0], ctorMeths[1]));
} }
ctorMember = ctorMeths[0]; ctorMember = ctorMeths[0];
} }
@ -841,9 +834,9 @@ public abstract class ScriptableObject implements Scriptable {
} }
if (name.equals(className)) { if (name.equals(className)) {
if (ctorMember != null) { if (ctorMember != null) {
Object[] args = { ctorMember, methods[i] };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.multiple.ctors", args)); Context.getMessage2("msg.multiple.ctors",
ctorMember, methods[i]));
} }
ctorMember = methods[i]; ctorMember = methods[i];
} }
@ -859,17 +852,16 @@ public abstract class ScriptableObject implements Scriptable {
ctorMember = ctors[0]; ctorMember = ctors[0];
} }
if (ctorMember == null) { if (ctorMember == null) {
Object[] args = { clazz.getName() };
throw new ClassDefinitionException( throw new ClassDefinitionException(
Context.getMessage("msg.ctor.multiple.parms", args)); Context.getMessage1("msg.ctor.multiple.parms",
clazz.getName()));
} }
} }
FunctionObject ctor = new FunctionObject(className, ctorMember, scope); FunctionObject ctor = new FunctionObject(className, ctorMember, scope);
if (ctor.isVarArgsMethod()) { if (ctor.isVarArgsMethod()) {
Object[] args = { ctorMember.getName() }; throw Context.reportRuntimeError1
String message = Context.getMessage("msg.varargs.ctor", args); ("msg.varargs.ctor", ctorMember.getName());
throw Context.reportRuntimeError(message);
} }
ctor.addAsConstructor(scope, proto); ctor.addAsConstructor(scope, proto);
@ -928,17 +920,15 @@ public abstract class ScriptableObject implements Scriptable {
continue; // deal with set when we see get continue; // deal with set when we see get
if (prefix != null && prefix.equals(getterPrefix)) { if (prefix != null && prefix.equals(getterPrefix)) {
if (!(proto instanceof ScriptableObject)) { if (!(proto instanceof ScriptableObject)) {
Object[] args = { proto.getClass().toString(), name }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.extend.scriptable", proto.getClass().toString(), name);
Context.getMessage("msg.extend.scriptable", args));
} }
Method[] setter = FunctionObject.findMethods( Method[] setter = FunctionObject.findMethods(
clazz, clazz,
setterPrefix + name); setterPrefix + name);
if (setter != null && setter.length != 1) { if (setter != null && setter.length != 1) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", name, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
int attr = ScriptableObject.PERMANENT | int attr = ScriptableObject.PERMANENT |
ScriptableObject.DONTENUM | ScriptableObject.DONTENUM |
@ -956,9 +946,9 @@ public abstract class ScriptableObject implements Scriptable {
prefix.equals(staticFunctionPrefix)))) prefix.equals(staticFunctionPrefix))))
{ {
if (!(proto instanceof ScriptableObject)) { if (!(proto instanceof ScriptableObject)) {
Object[] args = { proto.getClass().toString(), name }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.extend.scriptable",
Context.getMessage("msg.extend.scriptable", args)); proto.getClass().toString(), name);
} }
if (name.startsWith("set")) if (name.startsWith("set"))
continue; // deal with set when we see get continue; // deal with set when we see get
@ -976,9 +966,8 @@ public abstract class ScriptableObject implements Scriptable {
hasPrefix ? genericPrefix + setterName hasPrefix ? genericPrefix + setterName
: setterName); : setterName);
if (setter != null && setter.length != 1) { if (setter != null && setter.length != 1) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", name, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
if (setter == null && hasPrefix) if (setter == null && hasPrefix)
setter = FunctionObject.findMethods( setter = FunctionObject.findMethods(
@ -996,9 +985,8 @@ public abstract class ScriptableObject implements Scriptable {
} }
FunctionObject f = new FunctionObject(name, methods[i], proto); FunctionObject f = new FunctionObject(name, methods[i], proto);
if (f.isVarArgsConstructor()) { if (f.isVarArgsConstructor()) {
Object[] args = { ctorMember.getName() }; throw Context.reportRuntimeError1
String message = Context.getMessage("msg.varargs.fun", args); ("msg.varargs.fun", ctorMember.getName());
throw Context.reportRuntimeError(message);
} }
Scriptable dest = prefix == staticFunctionPrefix Scriptable dest = prefix == staticFunctionPrefix
? ctor ? ctor
@ -1087,9 +1075,8 @@ public abstract class ScriptableObject implements Scriptable {
if (setter == null) if (setter == null)
attributes |= ScriptableObject.READONLY; attributes |= ScriptableObject.READONLY;
if (getter.length != 1 || (setter != null && setter.length != 1)) { if (getter.length != 1 || (setter != null && setter.length != 1)) {
Object[] errArgs = { propertyName, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", propertyName, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
defineProperty(propertyName, null, getter[0], defineProperty(propertyName, null, getter[0],
setter == null ? null : setter[0], attributes); setter == null ? null : setter[0], attributes);
@ -1150,43 +1137,36 @@ public abstract class ScriptableObject implements Scriptable {
if (parmTypes.length != 1 || if (parmTypes.length != 1 ||
parmTypes[0] != ScriptableObject.class) parmTypes[0] != ScriptableObject.class)
{ {
Object[] args = { getter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.bad.getter.parms", getter.toString());
Context.getMessage("msg.bad.getter.parms", args));
} }
} else if (delegateTo != null) { } else if (delegateTo != null) {
Object[] args = { getter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.obj.getter.parms", getter.toString());
Context.getMessage("msg.obj.getter.parms", args));
} }
if (setter != null) { if (setter != null) {
flags |= Slot.HAS_SETTER; flags |= Slot.HAS_SETTER;
if ((delegateTo == HAS_STATIC_ACCESSORS) != if ((delegateTo == HAS_STATIC_ACCESSORS) !=
(Modifier.isStatic(setter.getModifiers()))) (Modifier.isStatic(setter.getModifiers())))
{ {
throw new PropertyException( throw PropertyException.withMessage0("msg.getter.static");
Context.getMessage("msg.getter.static", null));
} }
parmTypes = setter.getParameterTypes(); parmTypes = setter.getParameterTypes();
if (parmTypes.length == 2) { if (parmTypes.length == 2) {
if (parmTypes[0] != ScriptableObject.class) { if (parmTypes[0] != ScriptableObject.class) {
throw new PropertyException( throw PropertyException.withMessage0("msg.setter2.parms");
Context.getMessage("msg.setter2.parms", null));
} }
if (delegateTo == null) { if (delegateTo == null) {
Object[] args = { setter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.setter1.parms", setter.toString());
Context.getMessage("msg.setter1.parms", args));
} }
} else if (parmTypes.length == 1) { } else if (parmTypes.length == 1) {
if (delegateTo != null) { if (delegateTo != null) {
Object[] args = { setter.toString() }; throw PropertyException.withMessage1
throw new PropertyException( ("msg.setter2.expected", setter.toString());
Context.getMessage("msg.setter2.expected", args));
} }
} else { } else {
throw new PropertyException( throw PropertyException.withMessage0("msg.setter.parms");
Context.getMessage("msg.setter.parms", null));
} }
} }
int slotIndex = getSlotToSet(propertyName, int slotIndex = getSlotToSet(propertyName,
@ -1226,14 +1206,12 @@ public abstract class ScriptableObject implements Scriptable {
String name = names[i]; String name = names[i];
Method[] m = FunctionObject.findMethods(clazz, name); Method[] m = FunctionObject.findMethods(clazz, name);
if (m == null) { if (m == null) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.method.not.found", name, clazz.getName());
Context.getMessage("msg.method.not.found", errArgs));
} }
if (m.length > 1) { if (m.length > 1) {
Object[] errArgs = { name, clazz.getName() }; throw PropertyException.withMessage2
throw new PropertyException( ("msg.no.overload", name, clazz.getName());
Context.getMessage("msg.no.overload", errArgs));
} }
FunctionObject f = new FunctionObject(name, m[0], this); FunctionObject f = new FunctionObject(name, m[0], this);
defineProperty(name, f, attributes); defineProperty(name, f, attributes);
@ -1639,8 +1617,7 @@ public abstract class ScriptableObject implements Scriptable {
private synchronized int addSlot(String id, int index, boolean getterSlot) private synchronized int addSlot(String id, int index, boolean getterSlot)
{ {
if (count == -1) if (count == -1)
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.add.sealed");
("msg.add.sealed", null));
int start = (index & 0x7fffffff) % slots.length; int start = (index & 0x7fffffff) % slots.length;
int i = start; int i = start;
do { do {
@ -1678,8 +1655,7 @@ public abstract class ScriptableObject implements Scriptable {
*/ */
private synchronized void removeSlot(String name, int index) { private synchronized void removeSlot(String name, int index) {
if (count == -1) if (count == -1)
throw Context.reportRuntimeError(Context.getMessage throw Context.reportRuntimeError0("msg.remove.sealed");
("msg.remove.sealed", null));
int slotIndex = getSlot(name, index); int slotIndex = getSlot(name, index);
if (slotIndex == SLOT_NOT_FOUND) if (slotIndex == SLOT_NOT_FOUND)
return; return;

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

@ -635,10 +635,8 @@ public class TokenStream {
public void ungetToken(int tt) { public void ungetToken(int tt) {
if (this.pushbackToken != EOF && tt != ERROR) { if (this.pushbackToken != EOF && tt != ERROR) {
Object[] errArgs = { tokenToString(tt), String message = Context.getMessage2("msg.token.replaces.pushback",
tokenToString(this.pushbackToken) }; tokenToString(tt), tokenToString(this.pushbackToken));
String message = Context.getMessage("msg.token.replaces.pushback",
errArgs);
throw new RuntimeException(message); throw new RuntimeException(message);
} }
this.pushbackToken = tt; this.pushbackToken = tt;

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

@ -133,7 +133,6 @@ public class Undefined implements Scriptable {
} }
private RuntimeException reportError() { private RuntimeException reportError() {
String message = Context.getMessage("msg.undefined", null); return Context.reportRuntimeError0("msg.undefined");
return Context.reportRuntimeError(message);
} }
} }

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

@ -90,8 +90,7 @@ public class VariableTable {
LocalVariable p = (LocalVariable) LocalVariable p = (LocalVariable)
(itsVariables.elementAt(pIndex.intValue())); (itsVariables.elementAt(pIndex.intValue()));
if (p.isParameter()) { if (p.isParameter()) {
Object[] errorArgs = { pName }; String message = Context.getMessage1("msg.dup.parms", pName);
String message = Context.getMessage("msg.dup.parms", errorArgs);
Context.reportWarning(message, null, 0, null, 0); Context.reportWarning(message, null, 0, null, 0);
} }
else { // there's a local variable with this name, blow it off else { // there's a local variable with this name, blow it off