179
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeContinuation.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=0; s="constructor"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(FTAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeContinuation.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(FTAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor:
throw Context.reportRuntimeError("Direct call is not supported");
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeScript.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_exec: arity=0; s="exec"; break;
case Id_compile: arity=1; s="compile"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(SCRIPT_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeScript.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(SCRIPT_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor: {
String source = (args.length == 0)
? ""
: ScriptRuntime.toString(args[0]);
Script script = compile(cx, source);
NativeScript nscript = new NativeScript(script);
ScriptRuntime.setObjectProtoAndParent(nscript, scope);
return nscript;
}
case Id_toString: {
NativeScript real = realThis(thisObj, f);
Script realScript = real.script;
if (realScript == null) { return ""; }
return cx.decompileScript(realScript, 0);
}
case Id_exec: {
throw Context.reportRuntimeError1(
"msg.cant.call.indirect", "exec");
}
case Id_compile: {
NativeScript real = realThis(thisObj, f);
String source = ScriptRuntime.toString(args, 0);
real.script = compile(cx, source);
return real;
}
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeObject.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toLocaleString: arity=0; s="toLocaleString"; break;
case Id_valueOf: arity=0; s="valueOf"; break;
case Id_hasOwnProperty: arity=1; s="hasOwnProperty"; break;
case Id_propertyIsEnumerable:
arity=1; s="propertyIsEnumerable"; break;
case Id_isPrototypeOf: arity=1; s="isPrototypeOf"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id___defineGetter__:
arity=2; s="__defineGetter__"; break;
case Id___defineSetter__:
arity=2; s="__defineSetter__"; break;
case Id___lookupGetter__:
arity=1; s="__lookupGetter__"; break;
case Id___lookupSetter__:
arity=1; s="__lookupSetter__"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(OBJECT_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeObject.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(OBJECT_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor: {
if (thisObj != null) {
// BaseFunction.construct will set up parent, proto
return f.construct(cx, scope, args);
}
if (args.length == 0 || args[0] == null
|| args[0] == Undefined.instance)
{
return new NativeObject();
}
return ScriptRuntime.toObject(cx, scope, args[0]);
}
case Id_toLocaleString: // For now just alias toString
case Id_toString: {
if (cx.hasFeature(Context.FEATURE_TO_STRING_AS_SOURCE)) {
String s = ScriptRuntime.defaultObjectToSource(cx, scope,
thisObj, args);
int L = s.length();
if (L != 0 && s.charAt(0) == '(' && s.charAt(L - 1) == ')') {
// Strip () that surrounds toSource
s = s.substring(1, L - 1);
}
return s;
}
return ScriptRuntime.defaultObjectToString(thisObj);
}
case Id_valueOf:
return thisObj;
case Id_hasOwnProperty: {
boolean result;
if (args.length == 0) {
result = false;
} else {
String s = ScriptRuntime.toStringIdOrIndex(cx, args[0]);
if (s == null) {
int index = ScriptRuntime.lastIndexResult(cx);
result = thisObj.has(index, thisObj);
} else {
result = thisObj.has(s, thisObj);
}
}
return ScriptRuntime.wrapBoolean(result);
}
case Id_propertyIsEnumerable: {
boolean result;
if (args.length == 0) {
result = false;
} else {
String s = ScriptRuntime.toStringIdOrIndex(cx, args[0]);
if (s == null) {
int index = ScriptRuntime.lastIndexResult(cx);
result = thisObj.has(index, thisObj);
if (result && thisObj instanceof ScriptableObject) {
ScriptableObject so = (ScriptableObject)thisObj;
int attrs = so.getAttributes(index);
result = ((attrs & ScriptableObject.DONTENUM) == 0);
}
} else {
result = thisObj.has(s, thisObj);
if (result && thisObj instanceof ScriptableObject) {
ScriptableObject so = (ScriptableObject)thisObj;
int attrs = so.getAttributes(s);
result = ((attrs & ScriptableObject.DONTENUM) == 0);
}
}
}
return ScriptRuntime.wrapBoolean(result);
}
case Id_isPrototypeOf: {
boolean result = false;
if (args.length != 0 && args[0] instanceof Scriptable) {
Scriptable v = (Scriptable) args[0];
do {
v = v.getPrototype();
if (v == thisObj) {
result = true;
break;
}
} while (v != null);
}
return ScriptRuntime.wrapBoolean(result);
}
case Id_toSource:
return ScriptRuntime.defaultObjectToSource(cx, scope, thisObj,
args);
case Id___defineGetter__:
case Id___defineSetter__:
{
if (args.length < 2 || !(args[1] instanceof Callable)) {
Object badArg = (args.length >= 2 ? args[1]
: Undefined.instance);
throw ScriptRuntime.notFunctionError(badArg);
}
if (!(thisObj instanceof ScriptableObject)) {
throw Context.reportRuntimeError2(
"msg.extend.scriptable",
thisObj.getClass().getName(),
String.valueOf(args[0]));
}
ScriptableObject so = (ScriptableObject)thisObj;
String name = ScriptRuntime.toStringIdOrIndex(cx, args[0]);
int index = (name != null ? 0
: ScriptRuntime.lastIndexResult(cx));
Callable getterOrSetter = (Callable)args[1];
boolean isSetter = (id == Id___defineSetter__);
so.setGetterOrSetter(name, index, getterOrSetter, isSetter);
if (so instanceof NativeArray)
((NativeArray)so).setDenseOnly(false);
}
return Undefined.instance;
case Id___lookupGetter__:
case Id___lookupSetter__:
{
if (args.length < 1 ||
!(thisObj instanceof ScriptableObject))
return Undefined.instance;
ScriptableObject so = (ScriptableObject)thisObj;
String name = ScriptRuntime.toStringIdOrIndex(cx, args[0]);
int index = (name != null ? 0
: ScriptRuntime.lastIndexResult(cx));
boolean isSetter = (id == Id___lookupSetter__);
Object gs;
for (;;) {
gs = so.getGetterOrSetter(name, index, isSetter);
if (gs != null)
break;
// If there is no getter or setter for the object itself,
// how about the prototype?
Scriptable v = so.getPrototype();
if (v == null)
break;
if (v instanceof ScriptableObject)
so = (ScriptableObject)v;
else
break;
}
if (gs != null)
return gs;
}
return Undefined.instance;
case ConstructorId_getPrototypeOf:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
Scriptable obj = ensureScriptable(arg);
return obj.getPrototype();
}
case ConstructorId_keys:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
Scriptable obj = ensureScriptable(arg);
Object[] ids = obj.getIds();
for (int i = 0; i < ids.length; i++) {
ids[i] = ScriptRuntime.toString(ids[i]);
}
return cx.newArray(scope, ids);
}
case ConstructorId_getOwnPropertyNames:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
Object[] ids = obj.getAllIds();
for (int i = 0; i < ids.length; i++) {
ids[i] = ScriptRuntime.toString(ids[i]);
}
return cx.newArray(scope, ids);
}
case ConstructorId_getOwnPropertyDescriptor:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
// TODO(norris): There's a deeper issue here if
// arg instanceof Scriptable. Should we create a new
// interface to admit the new ECMAScript 5 operations?
ScriptableObject obj = ensureScriptableObject(arg);
Object nameArg = args.length < 2 ? Undefined.instance : args[1];
String name = ScriptRuntime.toString(nameArg);
Scriptable desc = obj.getOwnPropertyDescriptor(cx, name);
return desc == null ? Undefined.instance : desc;
}
case ConstructorId_defineProperty:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
Object name = args.length < 2 ? Undefined.instance : args[1];
Object descArg = args.length < 3 ? Undefined.instance : args[2];
ScriptableObject desc = ensureScriptableObject(descArg);
obj.defineOwnProperty(cx, name, desc);
return obj;
}
case ConstructorId_isExtensible:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
return Boolean.valueOf(obj.isExtensible());
}
case ConstructorId_preventExtensions:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
obj.preventExtensions();
return obj;
}
case ConstructorId_defineProperties:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
Object propsObj = args.length < 2 ? Undefined.instance : args[1];
Scriptable props = Context.toObject(propsObj, getParentScope());
obj.defineOwnProperties(cx, ensureScriptableObject(props));
return obj;
}
case ConstructorId_create:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
Scriptable obj = (arg == null) ? null : ensureScriptable(arg);
ScriptableObject newObject = new NativeObject();
newObject.setParentScope(this.getParentScope());
newObject.setPrototype(obj);
if (args.length > 1 && args[1] != Undefined.instance) {
Scriptable props = Context.toObject(args[1], getParentScope());
newObject.defineOwnProperties(cx, ensureScriptableObject(props));
}
return newObject;
}
case ConstructorId_isSealed:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
if (obj.isExtensible()) return Boolean.FALSE;
for (Object name: obj.getAllIds()) {
Object configurable = obj.getOwnPropertyDescriptor(cx, name).get("configurable");
if (Boolean.TRUE.equals(configurable))
return Boolean.FALSE;
}
return Boolean.TRUE;
}
case ConstructorId_isFrozen:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
if (obj.isExtensible()) return Boolean.FALSE;
for (Object name: obj.getAllIds()) {
ScriptableObject desc = obj.getOwnPropertyDescriptor(cx, name);
if (Boolean.TRUE.equals(desc.get("configurable")))
return Boolean.FALSE;
if (isDataDescriptor(desc) && Boolean.TRUE.equals(desc.get("writable")))
return Boolean.FALSE;
}
return Boolean.TRUE;
}
case ConstructorId_seal:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
for (Object name: obj.getAllIds()) {
ScriptableObject desc = obj.getOwnPropertyDescriptor(cx, name);
if (Boolean.TRUE.equals(desc.get("configurable"))) {
desc.put("configurable", desc, Boolean.FALSE);
obj.defineOwnProperty(cx, name, desc, false);
}
}
obj.preventExtensions();
return obj;
}
case ConstructorId_freeze:
{
Object arg = args.length < 1 ? Undefined.instance : args[0];
ScriptableObject obj = ensureScriptableObject(arg);
for (Object name: obj.getAllIds()) {
ScriptableObject desc = obj.getOwnPropertyDescriptor(cx, name);
if (isDataDescriptor(desc) && Boolean.TRUE.equals(desc.get("writable")))
desc.put("writable", desc, Boolean.FALSE);
if (Boolean.TRUE.equals(desc.get("configurable")))
desc.put("configurable", desc, Boolean.FALSE);
obj.defineOwnProperty(cx, name, desc, false);
}
obj.preventExtensions();
return obj;
}
default:
throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/regexp/NativeRegExp.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_compile: arity=1; s="compile"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id_exec: arity=1; s="exec"; break;
case Id_test: arity=1; s="test"; break;
case Id_prefix: arity=1; s="prefix"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(REGEXP_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/regexp/NativeRegExp.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(REGEXP_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_compile:
return realThis(thisObj, f).compile(cx, scope, args);
case Id_toString:
case Id_toSource:
return realThis(thisObj, f).toString();
case Id_exec:
return realThis(thisObj, f).execSub(cx, scope, args, MATCH);
case Id_test: {
Object x = realThis(thisObj, f).execSub(cx, scope, args, TEST);
return Boolean.TRUE.equals(x) ? Boolean.TRUE : Boolean.FALSE;
}
case Id_prefix:
return realThis(thisObj, f).execSub(cx, scope, args, PREFIX);
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/optimizer/OptRuntime.java
private static int[] decodeIntArray(String str, int arraySize)
{
// XXX: this extremely inefficient for small integers
if (arraySize == 0) {
if (str != null) throw new IllegalArgumentException();
return null;
}
if (str.length() != 1 + arraySize * 2 && str.charAt(0) != 1) {
throw new IllegalArgumentException();
}
int[] array = new int[arraySize];
for (int i = 0; i != arraySize; ++i) {
int shift = 1 + i * 2;
array[i] = (str.charAt(shift) << 16) | str.charAt(shift + 1);
}
return array;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/BaseFunction.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=1; s="toString"; break;
case Id_toSource: arity=1; s="toSource"; break;
case Id_apply: arity=2; s="apply"; break;
case Id_call: arity=1; s="call"; break;
case Id_bind: arity=1; s="bind"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(FUNCTION_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/BaseFunction.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(FUNCTION_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor:
return jsConstructor(cx, scope, args);
case Id_toString: {
BaseFunction realf = realFunction(thisObj, f);
int indent = ScriptRuntime.toInt32(args, 0);
return realf.decompile(indent, 0);
}
case Id_toSource: {
BaseFunction realf = realFunction(thisObj, f);
int indent = 0;
int flags = Decompiler.TO_SOURCE_FLAG;
if (args.length != 0) {
indent = ScriptRuntime.toInt32(args[0]);
if (indent >= 0) {
flags = 0;
} else {
indent = 0;
}
}
return realf.decompile(indent, flags);
}
case Id_apply:
case Id_call:
return ScriptRuntime.applyOrCall(id == Id_apply,
cx, scope, thisObj, args);
case Id_bind:
if ( !(thisObj instanceof Callable) ) {
throw ScriptRuntime.notFunctionError(thisObj);
}
Callable targetFunction = (Callable) thisObj;
int argc = args.length;
final Scriptable boundThis;
final Object[] boundArgs;
if (argc > 0) {
boundThis = ScriptRuntime.toObjectOrNull(cx, args[0], scope);
boundArgs = new Object[argc-1];
System.arraycopy(args, 1, boundArgs, 0, argc-1);
} else {
boundThis = null;
boundArgs = ScriptRuntime.emptyArgs;
}
return new BoundFunction(cx, scope, targetFunction, boundThis, boundArgs);
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/MemberBox.java
private static void writeMember(ObjectOutputStream out, Member member)
throws IOException
{
if (member == null) {
out.writeBoolean(false);
return;
}
out.writeBoolean(true);
if (!(member instanceof Method || member instanceof Constructor))
throw new IllegalArgumentException("not Method or Constructor");
out.writeBoolean(member instanceof Method);
out.writeObject(member.getName());
out.writeObject(member.getDeclaringClass());
if (member instanceof Method) {
writeParameters(out, ((Method) member).getParameterTypes());
} else {
writeParameters(out, ((Constructor<?>) member).getParameterTypes());
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/MemberBox.java
private static void writeParameters(ObjectOutputStream out, Class<?>[] parms)
throws IOException
{
out.writeShort(parms.length);
outer:
for (int i=0; i < parms.length; i++) {
Class<?> parm = parms[i];
boolean primitive = parm.isPrimitive();
out.writeBoolean(primitive);
if (!primitive) {
out.writeObject(parm);
continue;
}
for (int j=0; j < primitives.length; j++) {
if (parm.equals(primitives[j])) {
out.writeByte(j);
continue outer;
}
}
throw new IllegalArgumentException("Primitive " + parm +
" not found");
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeString.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id_valueOf: arity=0; s="valueOf"; break;
case Id_charAt: arity=1; s="charAt"; break;
case Id_charCodeAt: arity=1; s="charCodeAt"; break;
case Id_indexOf: arity=1; s="indexOf"; break;
case Id_lastIndexOf: arity=1; s="lastIndexOf"; break;
case Id_split: arity=2; s="split"; break;
case Id_substring: arity=2; s="substring"; break;
case Id_toLowerCase: arity=0; s="toLowerCase"; break;
case Id_toUpperCase: arity=0; s="toUpperCase"; break;
case Id_substr: arity=2; s="substr"; break;
case Id_concat: arity=1; s="concat"; break;
case Id_slice: arity=2; s="slice"; break;
case Id_bold: arity=0; s="bold"; break;
case Id_italics: arity=0; s="italics"; break;
case Id_fixed: arity=0; s="fixed"; break;
case Id_strike: arity=0; s="strike"; break;
case Id_small: arity=0; s="small"; break;
case Id_big: arity=0; s="big"; break;
case Id_blink: arity=0; s="blink"; break;
case Id_sup: arity=0; s="sup"; break;
case Id_sub: arity=0; s="sub"; break;
case Id_fontsize: arity=0; s="fontsize"; break;
case Id_fontcolor: arity=0; s="fontcolor"; break;
case Id_link: arity=0; s="link"; break;
case Id_anchor: arity=0; s="anchor"; break;
case Id_equals: arity=1; s="equals"; break;
case Id_equalsIgnoreCase: arity=1; s="equalsIgnoreCase"; break;
case Id_match: arity=1; s="match"; break;
case Id_search: arity=1; s="search"; break;
case Id_replace: arity=1; s="replace"; break;
case Id_localeCompare: arity=1; s="localeCompare"; break;
case Id_toLocaleLowerCase: arity=0; s="toLocaleLowerCase"; break;
case Id_toLocaleUpperCase: arity=0; s="toLocaleUpperCase"; break;
case Id_trim: arity=0; s="trim"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(STRING_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeString.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(STRING_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
again:
for(;;) {
switch (id) {
case ConstructorId_charAt:
case ConstructorId_charCodeAt:
case ConstructorId_indexOf:
case ConstructorId_lastIndexOf:
case ConstructorId_split:
case ConstructorId_substring:
case ConstructorId_toLowerCase:
case ConstructorId_toUpperCase:
case ConstructorId_substr:
case ConstructorId_concat:
case ConstructorId_slice:
case ConstructorId_equalsIgnoreCase:
case ConstructorId_match:
case ConstructorId_search:
case ConstructorId_replace:
case ConstructorId_localeCompare:
case ConstructorId_toLocaleLowerCase: {
if (args.length > 0) {
thisObj = ScriptRuntime.toObject(scope,
ScriptRuntime.toCharSequence(args[0]));
Object[] newArgs = new Object[args.length-1];
for (int i=0; i < newArgs.length; i++)
newArgs[i] = args[i+1];
args = newArgs;
} else {
thisObj = ScriptRuntime.toObject(scope,
ScriptRuntime.toCharSequence(thisObj));
}
id = -id;
continue again;
}
case ConstructorId_fromCharCode: {
int N = args.length;
if (N < 1)
return "";
StringBuffer sb = new StringBuffer(N);
for (int i = 0; i != N; ++i) {
sb.append(ScriptRuntime.toUint16(args[i]));
}
return sb.toString();
}
case Id_constructor: {
CharSequence s = (args.length >= 1)
? ScriptRuntime.toCharSequence(args[0]) : "";
if (thisObj == null) {
// new String(val) creates a new String object.
return new NativeString(s);
}
// String(val) converts val to a string value.
return s instanceof String ? s : s.toString();
}
case Id_toString:
case Id_valueOf:
// ECMA 15.5.4.2: 'the toString function is not generic.
CharSequence cs = realThis(thisObj, f).string;
return cs instanceof String ? cs : cs.toString();
case Id_toSource: {
CharSequence s = realThis(thisObj, f).string;
return "(new String(\""+ScriptRuntime.escapeString(s.toString())+"\"))";
}
case Id_charAt:
case Id_charCodeAt: {
// See ECMA 15.5.4.[4,5]
CharSequence target = ScriptRuntime.toCharSequence(thisObj);
double pos = ScriptRuntime.toInteger(args, 0);
if (pos < 0 || pos >= target.length()) {
if (id == Id_charAt) return "";
else return ScriptRuntime.NaNobj;
}
char c = target.charAt((int)pos);
if (id == Id_charAt) return String.valueOf(c);
else return ScriptRuntime.wrapInt(c);
}
case Id_indexOf:
return ScriptRuntime.wrapInt(js_indexOf(
ScriptRuntime.toString(thisObj), args));
case Id_lastIndexOf:
return ScriptRuntime.wrapInt(js_lastIndexOf(
ScriptRuntime.toString(thisObj), args));
case Id_split:
return ScriptRuntime.checkRegExpProxy(cx).
js_split(cx, scope, ScriptRuntime.toString(thisObj),
args);
case Id_substring:
return js_substring(cx, ScriptRuntime.toCharSequence(thisObj), args);
case Id_toLowerCase:
// See ECMA 15.5.4.11
return ScriptRuntime.toString(thisObj).toLowerCase(
ScriptRuntime.ROOT_LOCALE);
case Id_toUpperCase:
// See ECMA 15.5.4.12
return ScriptRuntime.toString(thisObj).toUpperCase(
ScriptRuntime.ROOT_LOCALE);
case Id_substr:
return js_substr(ScriptRuntime.toCharSequence(thisObj), args);
case Id_concat:
return js_concat(ScriptRuntime.toString(thisObj), args);
case Id_slice:
return js_slice(ScriptRuntime.toCharSequence(thisObj), args);
case Id_bold:
return tagify(thisObj, "b", null, null);
case Id_italics:
return tagify(thisObj, "i", null, null);
case Id_fixed:
return tagify(thisObj, "tt", null, null);
case Id_strike:
return tagify(thisObj, "strike", null, null);
case Id_small:
return tagify(thisObj, "small", null, null);
case Id_big:
return tagify(thisObj, "big", null, null);
case Id_blink:
return tagify(thisObj, "blink", null, null);
case Id_sup:
return tagify(thisObj, "sup", null, null);
case Id_sub:
return tagify(thisObj, "sub", null, null);
case Id_fontsize:
return tagify(thisObj, "font", "size", args);
case Id_fontcolor:
return tagify(thisObj, "font", "color", args);
case Id_link:
return tagify(thisObj, "a", "href", args);
case Id_anchor:
return tagify(thisObj, "a", "name", args);
case Id_equals:
case Id_equalsIgnoreCase: {
String s1 = ScriptRuntime.toString(thisObj);
String s2 = ScriptRuntime.toString(args, 0);
return ScriptRuntime.wrapBoolean(
(id == Id_equals) ? s1.equals(s2)
: s1.equalsIgnoreCase(s2));
}
case Id_match:
case Id_search:
case Id_replace:
{
int actionType;
if (id == Id_match) {
actionType = RegExpProxy.RA_MATCH;
} else if (id == Id_search) {
actionType = RegExpProxy.RA_SEARCH;
} else {
actionType = RegExpProxy.RA_REPLACE;
}
return ScriptRuntime.checkRegExpProxy(cx).
action(cx, scope, thisObj, args, actionType);
}
// ECMA-262 1 5.5.4.9
case Id_localeCompare:
{
// For now, create and configure a collator instance. I can't
// actually imagine that this'd be slower than caching them
// a la ClassCache, so we aren't trying to outsmart ourselves
// with a caching mechanism for now.
Collator collator = Collator.getInstance(cx.getLocale());
collator.setStrength(Collator.IDENTICAL);
collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
return ScriptRuntime.wrapNumber(collator.compare(
ScriptRuntime.toString(thisObj),
ScriptRuntime.toString(args, 0)));
}
case Id_toLocaleLowerCase:
{
return ScriptRuntime.toString(thisObj)
.toLowerCase(cx.getLocale());
}
case Id_toLocaleUpperCase:
{
return ScriptRuntime.toString(thisObj)
.toUpperCase(cx.getLocale());
}
case Id_trim:
{
String str = ScriptRuntime.toString(thisObj);
char[] chars = str.toCharArray();
int start = 0;
while (start < chars.length && ScriptRuntime.isJSWhitespaceOrLineTerminator(chars[start])) {
start++;
}
int end = chars.length;
while (end > start && ScriptRuntime.isJSWhitespaceOrLineTerminator(chars[end-1])) {
end--;
}
return str.substring(start, end);
}
}
throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/SpecialRef.java
static Ref createSpecial(Context cx, Object object, String name)
{
Scriptable target = ScriptRuntime.toObjectOrNull(cx, object);
if (target == null) {
throw ScriptRuntime.undefReadError(object, name);
}
int type;
if (name.equals("__proto__")) {
type = SPECIAL_PROTO;
} else if (name.equals("__parent__")) {
type = SPECIAL_PARENT;
} else {
throw new IllegalArgumentException(name);
}
if (!cx.hasFeature(Context.FEATURE_PARENT_PROTO_PROPERTIES)) {
// Clear special after checking for valid name!
type = SPECIAL_NONE;
}
return new SpecialRef(target, type, name);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptableObject.java
static void checkValidAttributes(int attributes)
{
final int mask = READONLY | DONTENUM | PERMANENT | UNINITIALIZED_CONST;
if ((attributes & ~mask) != 0) {
throw new IllegalArgumentException(String.valueOf(attributes));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptableObject.java
private void setGetterOrSetter(String name, int index, Callable getterOrSetter,
boolean isSetter, boolean force)
{
if (name != null && index != 0)
throw new IllegalArgumentException(name);
if (!force) {
checkNotSealed(name, index);
}
final GetterSlot gslot;
if (isExtensible()) {
gslot = (GetterSlot)getSlot(name, index, SLOT_MODIFY_GETTER_SETTER);
} else {
Slot slot = unwrapSlot(getSlot(name, index, SLOT_QUERY));
if (!(slot instanceof GetterSlot))
return;
gslot = (GetterSlot) slot;
}
if (!force) {
int attributes = gslot.getAttributes();
if ((attributes & READONLY) != 0) {
throw Context.reportRuntimeError1("msg.modify.readonly", name);
}
}
if (isSetter) {
gslot.setter = getterOrSetter;
} else {
gslot.getter = getterOrSetter;
}
gslot.value = Undefined.instance;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptableObject.java
public Object getGetterOrSetter(String name, int index, boolean isSetter)
{
if (name != null && index != 0)
throw new IllegalArgumentException(name);
Slot slot = unwrapSlot(getSlot(name, index, SLOT_QUERY));
if (slot == null)
return null;
if (slot instanceof GetterSlot) {
GetterSlot gslot = (GetterSlot)slot;
Object result = isSetter ? gslot.setter : gslot.getter;
return result != null ? result : Undefined.instance;
} else
return Undefined.instance;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptableObject.java
void addLazilyInitializedValue(String name, int index,
LazilyLoadedCtor init, int attributes)
{
if (name != null && index != 0)
throw new IllegalArgumentException(name);
checkNotSealed(name, index);
GetterSlot gslot = (GetterSlot)getSlot(name, index,
SLOT_MODIFY_GETTER_SETTER);
gslot.setAttributes(attributes);
gslot.getter = null;
gslot.setter = null;
gslot.value = init;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptableObject.java
public void defineProperty(String propertyName, Class<?> clazz,
int attributes)
{
int length = propertyName.length();
if (length == 0) throw new IllegalArgumentException();
char[] buf = new char[3 + length];
propertyName.getChars(0, length, buf, 3);
buf[3] = Character.toUpperCase(buf[3]);
buf[0] = 'g';
buf[1] = 'e';
buf[2] = 't';
String getterName = new String(buf);
buf[0] = 's';
String setterName = new String(buf);
Method[] methods = FunctionObject.getMethodList(clazz);
Method getter = FunctionObject.findSingleMethod(methods, getterName);
Method setter = FunctionObject.findSingleMethod(methods, setterName);
if (setter == null)
attributes |= ScriptableObject.READONLY;
defineProperty(propertyName, null, getter,
setter == null ? null : setter, attributes);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptableObject.java
public synchronized final Object associateValue(Object key, Object value)
{
if (value == null) throw new IllegalArgumentException();
Map<Object,Object> h = associatedValues;
if (h == null) {
h = new HashMap<Object,Object>();
associatedValues = h;
}
return Kit.initHash(h, key, value);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/InterfaceAdapter.java
static Object create(Context cx, Class<?> cl, ScriptableObject object)
{
if (!cl.isInterface()) throw new IllegalArgumentException();
Scriptable topScope = ScriptRuntime.getTopCallScope(cx);
ClassCache cache = ClassCache.get(topScope);
InterfaceAdapter adapter;
adapter = (InterfaceAdapter)cache.getInterfaceAdapter(cl);
ContextFactory cf = cx.getFactory();
if (adapter == null) {
Method[] methods = cl.getMethods();
if ( object instanceof Callable) {
// Check if interface can be implemented by a single function.
// We allow this if the interface has only one method or multiple
// methods with the same name (in which case they'd result in
// the same function to be invoked anyway).
int length = methods.length;
if (length == 0) {
throw Context.reportRuntimeError1(
"msg.no.empty.interface.conversion", cl.getName());
}
if (length > 1) {
String methodName = methods[0].getName();
for (int i = 1; i < length; i++) {
if (!methodName.equals(methods[i].getName())) {
throw Context.reportRuntimeError1(
"msg.no.function.interface.conversion",
cl.getName());
}
}
}
}
adapter = new InterfaceAdapter(cf, cl);
cache.cacheInterfaceAdapter(cl, adapter);
}
return VMBridge.instance.newInterfaceProxy(
adapter.proxyHelper, cf, adapter, object, topScope);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeBoolean.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id_valueOf: arity=0; s="valueOf"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(BOOLEAN_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeBoolean.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(BOOLEAN_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (id == Id_constructor) {
boolean b;
if (args.length == 0) {
b = false;
} else {
b = args[0] instanceof ScriptableObject &&
((ScriptableObject) args[0]).avoidObjectDetection()
? true
: ScriptRuntime.toBoolean(args[0]);
}
if (thisObj == null) {
// new Boolean(val) creates a new boolean object.
return new NativeBoolean(b);
}
// Boolean(val) converts val to a boolean.
return ScriptRuntime.wrapBoolean(b);
}
// The rest of Boolean.prototype methods require thisObj to be Boolean
if (!(thisObj instanceof NativeBoolean))
throw incompatibleCallError(f);
boolean value = ((NativeBoolean)thisObj).booleanValue;
switch (id) {
case Id_toString:
return value ? "true" : "false";
case Id_toSource:
return value ? "(new Boolean(true))" : "(new Boolean(false))";
case Id_valueOf:
return ScriptRuntime.wrapBoolean(value);
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeCall.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
if (id == Id_constructor) {
arity=1; s="constructor";
} else {
throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(CALL_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeCall.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(CALL_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (id == Id_constructor) {
if (thisObj != null) {
throw Context.reportRuntimeError1("msg.only.from.new", "Call");
}
ScriptRuntime.checkDeprecated(cx, "Call");
NativeCall result = new NativeCall();
result.setPrototype(getObjectPrototype(scope));
return result;
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Kit.java
public static Object addListener(Object bag, Object listener)
{
if (listener == null) throw new IllegalArgumentException();
if (listener instanceof Object[]) throw new IllegalArgumentException();
if (bag == null) {
bag = listener;
} else if (!(bag instanceof Object[])) {
bag = new Object[] { bag, listener };
} else {
Object[] array = (Object[])bag;
int L = array.length;
// bag has at least 2 elements if it is array
if (L < 2) throw new IllegalArgumentException();
Object[] tmp = new Object[L + 1];
System.arraycopy(array, 0, tmp, 0, L);
tmp[L] = listener;
bag = tmp;
}
return bag;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Kit.java
public static Object removeListener(Object bag, Object listener)
{
if (listener == null) throw new IllegalArgumentException();
if (listener instanceof Object[]) throw new IllegalArgumentException();
if (bag == listener) {
bag = null;
} else if (bag instanceof Object[]) {
Object[] array = (Object[])bag;
int L = array.length;
// bag has at least 2 elements if it is array
if (L < 2) throw new IllegalArgumentException();
if (L == 2) {
if (array[1] == listener) {
bag = array[0];
} else if (array[0] == listener) {
bag = array[1];
}
} else {
int i = L;
do {
--i;
if (array[i] == listener) {
Object[] tmp = new Object[L - 1];
System.arraycopy(array, 0, tmp, 0, i);
System.arraycopy(array, i + 1, tmp, i, L - (i + 1));
bag = tmp;
break;
}
} while (i != 0);
}
}
return bag;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Kit.java
public static Object getListener(Object bag, int index)
{
if (index == 0) {
if (bag == null)
return null;
if (!(bag instanceof Object[]))
return bag;
Object[] array = (Object[])bag;
// bag has at least 2 elements if it is array
if (array.length < 2) throw new IllegalArgumentException();
return array[0];
} else if (index == 1) {
if (!(bag instanceof Object[])) {
if (bag == null) throw new IllegalArgumentException();
return null;
}
Object[] array = (Object[])bag;
// the array access will check for index on its own
return array[1];
} else {
// bag has to array
Object[] array = (Object[])bag;
int L = array.length;
if (L < 2) throw new IllegalArgumentException();
if (index == L)
return null;
return array[index];
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Kit.java
public static Object makeHashKeyFromPair(Object key1, Object key2)
{
if (key1 == null) throw new IllegalArgumentException();
if (key2 == null) throw new IllegalArgumentException();
return new ComplexKey(key1, key2);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Kit.java
public static byte[] readStream(InputStream is, int initialBufferCapacity)
throws IOException
{
if (initialBufferCapacity <= 0) {
throw new IllegalArgumentException(
"Bad initialBufferCapacity: "+initialBufferCapacity);
}
byte[] buffer = new byte[initialBufferCapacity];
int cursor = 0;
for (;;) {
int n = is.read(buffer, cursor, buffer.length - cursor);
if (n < 0) { break; }
cursor += n;
if (cursor == buffer.length) {
byte[] tmp = new byte[buffer.length * 2];
System.arraycopy(buffer, 0, tmp, 0, cursor);
buffer = tmp;
}
}
if (cursor != buffer.length) {
byte[] tmp = new byte[cursor];
System.arraycopy(buffer, 0, tmp, 0, cursor);
buffer = tmp;
}
return buffer;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeIterator.java
Override
protected void initPrototypeId(int id) {
String s;
int arity;
switch (id) {
case Id_constructor: arity=2; s="constructor"; break;
case Id_next: arity=0; s="next"; break;
case Id___iterator__: arity=1; s=ITERATOR_PROPERTY_NAME; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(ITERATOR_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeIterator.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(ITERATOR_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (id == Id_constructor) {
return jsConstructor(cx, scope, thisObj, args);
}
if (!(thisObj instanceof NativeIterator))
throw incompatibleCallError(f);
NativeIterator iterator = (NativeIterator) thisObj;
switch (id) {
case Id_next:
return iterator.next(cx, scope);
case Id___iterator__:
/// XXX: what about argument? SpiderMonkey apparently ignores it
return thisObj;
default:
throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeNumber.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=1; s="toString"; break;
case Id_toLocaleString: arity=1; s="toLocaleString"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id_valueOf: arity=0; s="valueOf"; break;
case Id_toFixed: arity=1; s="toFixed"; break;
case Id_toExponential: arity=1; s="toExponential"; break;
case Id_toPrecision: arity=1; s="toPrecision"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(NUMBER_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeNumber.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(NUMBER_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (id == Id_constructor) {
double val = (args.length >= 1)
? ScriptRuntime.toNumber(args[0]) : 0.0;
if (thisObj == null) {
// new Number(val) creates a new Number object.
return new NativeNumber(val);
}
// Number(val) converts val to a number value.
return ScriptRuntime.wrapNumber(val);
}
// The rest of Number.prototype methods require thisObj to be Number
if (!(thisObj instanceof NativeNumber))
throw incompatibleCallError(f);
double value = ((NativeNumber)thisObj).doubleValue;
switch (id) {
case Id_toString:
case Id_toLocaleString:
{
// toLocaleString is just an alias for toString for now
int base = (args.length == 0 || args[0] == Undefined.instance)
? 10 : ScriptRuntime.toInt32(args[0]);
return ScriptRuntime.numberToString(value, base);
}
case Id_toSource:
return "(new Number("+ScriptRuntime.toString(value)+"))";
case Id_valueOf:
return ScriptRuntime.wrapNumber(value);
case Id_toFixed:
return num_to(value, args, DToA.DTOSTR_FIXED,
DToA.DTOSTR_FIXED, -20, 0);
case Id_toExponential: {
// Handle special values before range check
if(Double.isNaN(value)) {
return "NaN";
}
if(Double.isInfinite(value)) {
if(value >= 0) {
return "Infinity";
}
else {
return "-Infinity";
}
}
// General case
return num_to(value, args, DToA.DTOSTR_STANDARD_EXPONENTIAL,
DToA.DTOSTR_EXPONENTIAL, 0, 1);
}
case Id_toPrecision: {
// Undefined precision, fall back to ToString()
if(args.length == 0 || args[0] == Undefined.instance) {
return ScriptRuntime.numberToString(value, 10);
}
// Handle special values before range check
if(Double.isNaN(value)) {
return "NaN";
}
if(Double.isInfinite(value)) {
if(value >= 0) {
return "Infinity";
}
else {
return "-Infinity";
}
}
return num_to(value, args, DToA.DTOSTR_STANDARD,
DToA.DTOSTR_PRECISION, 1, 0);
}
default: throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ContextFactory.java
public synchronized static void initGlobal(ContextFactory factory)
{
if (factory == null) {
throw new IllegalArgumentException();
}
if (hasCustomGlobal) {
throw new IllegalStateException();
}
hasCustomGlobal = true;
global = factory;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ContextFactory.java
protected boolean hasFeature(Context cx, int featureIndex)
{
int version;
switch (featureIndex) {
case Context.FEATURE_NON_ECMA_GET_YEAR:
/*
* During the great date rewrite of 1.3, we tried to track the
* evolving ECMA standard, which then had a definition of
* getYear which always subtracted 1900. Which we
* implemented, not realizing that it was incompatible with
* the old behavior... now, rather than thrash the behavior
* yet again, we've decided to leave it with the - 1900
* behavior and point people to the getFullYear method. But
* we try to protect existing scripts that have specified a
* version...
*/
version = cx.getLanguageVersion();
return (version == Context.VERSION_1_0
|| version == Context.VERSION_1_1
|| version == Context.VERSION_1_2);
case Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME:
return false;
case Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER:
return true;
case Context.FEATURE_TO_STRING_AS_SOURCE:
version = cx.getLanguageVersion();
return version == Context.VERSION_1_2;
case Context.FEATURE_PARENT_PROTO_PROPERTIES:
return true;
case Context.FEATURE_E4X:
version = cx.getLanguageVersion();
return (version == Context.VERSION_DEFAULT
|| version >= Context.VERSION_1_6);
case Context.FEATURE_DYNAMIC_SCOPE:
return false;
case Context.FEATURE_STRICT_VARS:
return false;
case Context.FEATURE_STRICT_EVAL:
return false;
case Context.FEATURE_LOCATION_INFORMATION_IN_ERROR:
return false;
case Context.FEATURE_STRICT_MODE:
return false;
case Context.FEATURE_WARNING_AS_ERROR:
return false;
case Context.FEATURE_ENHANCED_JAVA_ACCESS:
return false;
}
// It is a bug to call the method with unknown featureIndex
throw new IllegalArgumentException(String.valueOf(featureIndex));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ContextFactory.java
public final void initApplicationClassLoader(ClassLoader loader)
{
if (loader == null)
throw new IllegalArgumentException("loader is null");
if (!Kit.testIfCanLoadRhinoClasses(loader))
throw new IllegalArgumentException(
"Loader can not resolve Rhino classes");
if (this.applicationClassLoader != null)
throw new IllegalStateException(
"applicationClassLoader can only be set once");
checkNotSealed();
this.applicationClassLoader = loader;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeArray.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toLocaleString: arity=0; s="toLocaleString"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id_join: arity=1; s="join"; break;
case Id_reverse: arity=0; s="reverse"; break;
case Id_sort: arity=1; s="sort"; break;
case Id_push: arity=1; s="push"; break;
case Id_pop: arity=0; s="pop"; break;
case Id_shift: arity=0; s="shift"; break;
case Id_unshift: arity=1; s="unshift"; break;
case Id_splice: arity=2; s="splice"; break;
case Id_concat: arity=1; s="concat"; break;
case Id_slice: arity=2; s="slice"; break;
case Id_indexOf: arity=1; s="indexOf"; break;
case Id_lastIndexOf: arity=1; s="lastIndexOf"; break;
case Id_every: arity=1; s="every"; break;
case Id_filter: arity=1; s="filter"; break;
case Id_forEach: arity=1; s="forEach"; break;
case Id_map: arity=1; s="map"; break;
case Id_some: arity=1; s="some"; break;
case Id_reduce: arity=1; s="reduce"; break;
case Id_reduceRight: arity=1; s="reduceRight"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(ARRAY_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeArray.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(ARRAY_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
again:
for (;;) {
switch (id) {
case ConstructorId_join:
case ConstructorId_reverse:
case ConstructorId_sort:
case ConstructorId_push:
case ConstructorId_pop:
case ConstructorId_shift:
case ConstructorId_unshift:
case ConstructorId_splice:
case ConstructorId_concat:
case ConstructorId_slice:
case ConstructorId_indexOf:
case ConstructorId_lastIndexOf:
case ConstructorId_every:
case ConstructorId_filter:
case ConstructorId_forEach:
case ConstructorId_map:
case ConstructorId_some:
case ConstructorId_reduce:
case ConstructorId_reduceRight: {
if (args.length > 0) {
thisObj = ScriptRuntime.toObject(scope, args[0]);
Object[] newArgs = new Object[args.length-1];
for (int i=0; i < newArgs.length; i++)
newArgs[i] = args[i+1];
args = newArgs;
}
id = -id;
continue again;
}
case ConstructorId_isArray:
return args.length > 0 && (args[0] instanceof NativeArray);
case Id_constructor: {
boolean inNewExpr = (thisObj == null);
if (!inNewExpr) {
// IdFunctionObject.construct will set up parent, proto
return f.construct(cx, scope, args);
}
return jsConstructor(cx, scope, args);
}
case Id_toString:
return toStringHelper(cx, scope, thisObj,
cx.hasFeature(Context.FEATURE_TO_STRING_AS_SOURCE), false);
case Id_toLocaleString:
return toStringHelper(cx, scope, thisObj, false, true);
case Id_toSource:
return toStringHelper(cx, scope, thisObj, true, false);
case Id_join:
return js_join(cx, thisObj, args);
case Id_reverse:
return js_reverse(cx, thisObj, args);
case Id_sort:
return js_sort(cx, scope, thisObj, args);
case Id_push:
return js_push(cx, thisObj, args);
case Id_pop:
return js_pop(cx, thisObj, args);
case Id_shift:
return js_shift(cx, thisObj, args);
case Id_unshift:
return js_unshift(cx, thisObj, args);
case Id_splice:
return js_splice(cx, scope, thisObj, args);
case Id_concat:
return js_concat(cx, scope, thisObj, args);
case Id_slice:
return js_slice(cx, thisObj, args);
case Id_indexOf:
return indexOfHelper(cx, thisObj, args, false);
case Id_lastIndexOf:
return indexOfHelper(cx, thisObj, args, true);
case Id_every:
case Id_filter:
case Id_forEach:
case Id_map:
case Id_some:
return iterativeMethod(cx, id, scope, thisObj, args);
case Id_reduce:
case Id_reduceRight:
return reduceMethod(cx, id, scope, thisObj, args);
}
throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeArray.java
void setDenseOnly(boolean denseOnly) {
if (denseOnly && !this.denseOnly)
throw new IllegalArgumentException();
this.denseOnly = denseOnly;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/CompilerEnvirons.java
public void setErrorReporter(ErrorReporter errorReporter)
{
if (errorReporter == null) throw new IllegalArgumentException();
this.errorReporter = errorReporter;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeError.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toSource: arity=0; s="toSource"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(ERROR_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeError.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(ERROR_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor:
return make(cx, scope, f, args);
case Id_toString:
return js_toString(thisObj);
case Id_toSource:
return js_toSource(cx, scope, thisObj);
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/DToA.java
static String JS_dtobasestr(int base, double d)
{
if (!(2 <= base && base <= 36))
throw new IllegalArgumentException("Bad base: "+base);
/* Check for Infinity and NaN */
if (Double.isNaN(d)) {
return "NaN";
} else if (Double.isInfinite(d)) {
return (d > 0.0) ? "Infinity" : "-Infinity";
} else if (d == 0) {
// ALERT: should it distinguish -0.0 from +0.0 ?
return "0";
}
boolean negative;
if (d >= 0.0) {
negative = false;
} else {
negative = true;
d = -d;
}
/* Get the integer part of d including '-' sign. */
String intDigits;
double dfloor = Math.floor(d);
long lfloor = (long)dfloor;
if (lfloor == dfloor) {
// int part fits long
intDigits = Long.toString((negative) ? -lfloor : lfloor, base);
} else {
// BigInteger should be used
long floorBits = Double.doubleToLongBits(dfloor);
int exp = (int)(floorBits >> Exp_shiftL) & Exp_mask_shifted;
long mantissa;
if (exp == 0) {
mantissa = (floorBits & Frac_maskL) << 1;
} else {
mantissa = (floorBits & Frac_maskL) | Exp_msk1L;
}
if (negative) {
mantissa = -mantissa;
}
exp -= 1075;
BigInteger x = BigInteger.valueOf(mantissa);
if (exp > 0) {
x = x.shiftLeft(exp);
} else if (exp < 0) {
x = x.shiftRight(-exp);
}
intDigits = x.toString(base);
}
if (d == dfloor) {
// No fraction part
return intDigits;
} else {
/* We have a fraction. */
StringBuilder buffer; /* The output string */
int digit;
double df; /* The fractional part of d */
BigInteger b;
buffer = new StringBuilder();
buffer.append(intDigits).append('.');
df = d - dfloor;
long dBits = Double.doubleToLongBits(d);
int word0 = (int)(dBits >> 32);
int word1 = (int)(dBits);
int[] e = new int[1];
int[] bbits = new int[1];
b = d2b(df, e, bbits);
// JS_ASSERT(e < 0);
/* At this point df = b * 2^e. e must be less than zero because 0 < df < 1. */
int s2 = -(word0 >>> Exp_shift1 & Exp_mask >> Exp_shift1);
if (s2 == 0)
s2 = -1;
s2 += Bias + P;
/* 1/2^s2 = (nextDouble(d) - d)/2 */
// JS_ASSERT(-s2 < e);
BigInteger mlo = BigInteger.valueOf(1);
BigInteger mhi = mlo;
if ((word1 == 0) && ((word0 & Bndry_mask) == 0)
&& ((word0 & (Exp_mask & Exp_mask << 1)) != 0)) {
/* The special case. Here we want to be within a quarter of the last input
significant digit instead of one half of it when the output string's value is less than d. */
s2 += Log2P;
mhi = BigInteger.valueOf(1<<Log2P);
}
b = b.shiftLeft(e[0] + s2);
BigInteger s = BigInteger.valueOf(1);
s = s.shiftLeft(s2);
/* At this point we have the following:
* s = 2^s2;
* 1 > df = b/2^s2 > 0;
* (d - prevDouble(d))/2 = mlo/2^s2;
* (nextDouble(d) - d)/2 = mhi/2^s2. */
BigInteger bigBase = BigInteger.valueOf(base);
boolean done = false;
do {
b = b.multiply(bigBase);
BigInteger[] divResult = b.divideAndRemainder(s);
b = divResult[1];
digit = (char)(divResult[0].intValue());
if (mlo == mhi)
mlo = mhi = mlo.multiply(bigBase);
else {
mlo = mlo.multiply(bigBase);
mhi = mhi.multiply(bigBase);
}
/* Do we yet have the shortest string that will round to d? */
int j = b.compareTo(mlo);
/* j is b/2^s2 compared with mlo/2^s2. */
BigInteger delta = s.subtract(mhi);
int j1 = (delta.signum() <= 0) ? 1 : b.compareTo(delta);
/* j1 is b/2^s2 compared with 1 - mhi/2^s2. */
if (j1 == 0 && ((word1 & 1) == 0)) {
if (j > 0)
digit++;
done = true;
} else
if (j < 0 || (j == 0 && ((word1 & 1) == 0))) {
if (j1 > 0) {
/* Either dig or dig+1 would work here as the least significant digit.
Use whichever would produce an output value closer to d. */
b = b.shiftLeft(1);
j1 = b.compareTo(s);
if (j1 > 0) /* The even test (|| (j1 == 0 && (digit & 1))) is not here because it messes up odd base output
* such as 3.5 in base 3. */
digit++;
}
done = true;
} else if (j1 > 0) {
digit++;
done = true;
}
// JS_ASSERT(digit < (uint32)base);
buffer.append(BASEDIGIT(digit));
} while (!done);
return buffer.toString();
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Icode.java
static String bytecodeName(int bytecode)
{
if (!validBytecode(bytecode)) {
throw new IllegalArgumentException(String.valueOf(bytecode));
}
if (!Token.printICode) {
return String.valueOf(bytecode);
}
if (validTokenCode(bytecode)) {
return Token.name(bytecode);
}
switch (bytecode) {
case Icode_DUP: return "DUP";
case Icode_DUP2: return "DUP2";
case Icode_SWAP: return "SWAP";
case Icode_POP: return "POP";
case Icode_POP_RESULT: return "POP_RESULT";
case Icode_IFEQ_POP: return "IFEQ_POP";
case Icode_VAR_INC_DEC: return "VAR_INC_DEC";
case Icode_NAME_INC_DEC: return "NAME_INC_DEC";
case Icode_PROP_INC_DEC: return "PROP_INC_DEC";
case Icode_ELEM_INC_DEC: return "ELEM_INC_DEC";
case Icode_REF_INC_DEC: return "REF_INC_DEC";
case Icode_SCOPE_LOAD: return "SCOPE_LOAD";
case Icode_SCOPE_SAVE: return "SCOPE_SAVE";
case Icode_TYPEOFNAME: return "TYPEOFNAME";
case Icode_NAME_AND_THIS: return "NAME_AND_THIS";
case Icode_PROP_AND_THIS: return "PROP_AND_THIS";
case Icode_ELEM_AND_THIS: return "ELEM_AND_THIS";
case Icode_VALUE_AND_THIS: return "VALUE_AND_THIS";
case Icode_CLOSURE_EXPR: return "CLOSURE_EXPR";
case Icode_CLOSURE_STMT: return "CLOSURE_STMT";
case Icode_CALLSPECIAL: return "CALLSPECIAL";
case Icode_RETUNDEF: return "RETUNDEF";
case Icode_GOSUB: return "GOSUB";
case Icode_STARTSUB: return "STARTSUB";
case Icode_RETSUB: return "RETSUB";
case Icode_LINE: return "LINE";
case Icode_SHORTNUMBER: return "SHORTNUMBER";
case Icode_INTNUMBER: return "INTNUMBER";
case Icode_LITERAL_NEW: return "LITERAL_NEW";
case Icode_LITERAL_SET: return "LITERAL_SET";
case Icode_SPARE_ARRAYLIT: return "SPARE_ARRAYLIT";
case Icode_REG_IND_C0: return "REG_IND_C0";
case Icode_REG_IND_C1: return "REG_IND_C1";
case Icode_REG_IND_C2: return "REG_IND_C2";
case Icode_REG_IND_C3: return "REG_IND_C3";
case Icode_REG_IND_C4: return "REG_IND_C4";
case Icode_REG_IND_C5: return "REG_IND_C5";
case Icode_REG_IND1: return "LOAD_IND1";
case Icode_REG_IND2: return "LOAD_IND2";
case Icode_REG_IND4: return "LOAD_IND4";
case Icode_REG_STR_C0: return "REG_STR_C0";
case Icode_REG_STR_C1: return "REG_STR_C1";
case Icode_REG_STR_C2: return "REG_STR_C2";
case Icode_REG_STR_C3: return "REG_STR_C3";
case Icode_REG_STR1: return "LOAD_STR1";
case Icode_REG_STR2: return "LOAD_STR2";
case Icode_REG_STR4: return "LOAD_STR4";
case Icode_GETVAR1: return "GETVAR1";
case Icode_SETVAR1: return "SETVAR1";
case Icode_UNDEF: return "UNDEF";
case Icode_ZERO: return "ZERO";
case Icode_ONE: return "ONE";
case Icode_ENTERDQ: return "ENTERDQ";
case Icode_LEAVEDQ: return "LEAVEDQ";
case Icode_TAIL_CALL: return "TAIL_CALL";
case Icode_LOCAL_CLEAR: return "LOCAL_CLEAR";
case Icode_LITERAL_GETTER: return "LITERAL_GETTER";
case Icode_LITERAL_SETTER: return "LITERAL_SETTER";
case Icode_SETCONST: return "SETCONST";
case Icode_SETCONSTVAR: return "SETCONSTVAR";
case Icode_SETCONSTVAR1: return "SETCONSTVAR1";
case Icode_GENERATOR: return "GENERATOR";
case Icode_GENERATOR_END: return "GENERATOR_END";
case Icode_DEBUGGER: return "DEBUGGER";
}
// icode without name
throw new IllegalStateException(String.valueOf(bytecode));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/IRFactory.java
public Node transform(AstNode node) {
switch (node.getType()) {
case Token.ARRAYCOMP:
return transformArrayComp((ArrayComprehension)node);
case Token.ARRAYLIT:
return transformArrayLiteral((ArrayLiteral)node);
case Token.BLOCK:
return transformBlock(node);
case Token.BREAK:
return transformBreak((BreakStatement)node);
case Token.CALL:
return transformFunctionCall((FunctionCall)node);
case Token.CONTINUE:
return transformContinue((ContinueStatement)node);
case Token.DO:
return transformDoLoop((DoLoop)node);
case Token.EMPTY:
return node;
case Token.FOR:
if (node instanceof ForInLoop) {
return transformForInLoop((ForInLoop)node);
} else {
return transformForLoop((ForLoop)node);
}
case Token.FUNCTION:
return transformFunction((FunctionNode)node);
case Token.GENEXPR:
return transformGenExpr((GeneratorExpression)node);
case Token.GETELEM:
return transformElementGet((ElementGet)node);
case Token.GETPROP:
return transformPropertyGet((PropertyGet)node);
case Token.HOOK:
return transformCondExpr((ConditionalExpression)node);
case Token.IF:
return transformIf((IfStatement)node);
case Token.TRUE:
case Token.FALSE:
case Token.THIS:
case Token.NULL:
case Token.DEBUGGER:
return transformLiteral(node);
case Token.NAME:
return transformName((Name)node);
case Token.NUMBER:
return transformNumber((NumberLiteral)node);
case Token.NEW:
return transformNewExpr((NewExpression)node);
case Token.OBJECTLIT:
return transformObjectLiteral((ObjectLiteral)node);
case Token.REGEXP:
return transformRegExp((RegExpLiteral)node);
case Token.RETURN:
return transformReturn((ReturnStatement)node);
case Token.SCRIPT:
return transformScript((ScriptNode)node);
case Token.STRING:
return transformString((StringLiteral)node);
case Token.SWITCH:
return transformSwitch((SwitchStatement)node);
case Token.THROW:
return transformThrow((ThrowStatement)node);
case Token.TRY:
return transformTry((TryStatement)node);
case Token.WHILE:
return transformWhileLoop((WhileLoop)node);
case Token.WITH:
return transformWith((WithStatement)node);
case Token.YIELD:
return transformYield((Yield)node);
default:
if (node instanceof ExpressionStatement) {
return transformExprStmt((ExpressionStatement)node);
}
if (node instanceof Assignment) {
return transformAssignment((Assignment)node);
}
if (node instanceof UnaryExpression) {
return transformUnary((UnaryExpression)node);
}
if (node instanceof XmlMemberGet) {
return transformXmlMemberGet((XmlMemberGet)node);
}
if (node instanceof InfixExpression) {
return transformInfix((InfixExpression)node);
}
if (node instanceof VariableDeclaration) {
return transformVariables((VariableDeclaration)node);
}
if (node instanceof ParenthesizedExpression) {
return transformParenExpr((ParenthesizedExpression)node);
}
if (node instanceof LabeledStatement) {
return transformLabeledStatement((LabeledStatement)node);
}
if (node instanceof LetNode) {
return transformLetNode((LetNode)node);
}
if (node instanceof XmlRef) {
return transformXmlRef((XmlRef)node);
}
if (node instanceof XmlLiteral) {
return transformXmlLiteral((XmlLiteral)node);
}
throw new IllegalArgumentException("Can't transform: " + node);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/Label.java
public void setName(String name) {
name = name == null ? null : name.trim();
if (name == null || "".equals(name))
throw new IllegalArgumentException("invalid label name");
this.name = name;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/KeywordLiteral.java
Override
public KeywordLiteral setType(int nodeType) {
if (!(nodeType == Token.THIS
|| nodeType == Token.NULL
|| nodeType == Token.TRUE
|| nodeType == Token.FALSE
|| nodeType == Token.DEBUGGER))
throw new IllegalArgumentException("Invalid node type: "
+ nodeType);
type = nodeType;
return this;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/Symbol.java
public void setDeclType(int declType) {
if (!(declType == Token.FUNCTION
|| declType == Token.LP
|| declType == Token.VAR
|| declType == Token.LET
|| declType == Token.CONST))
throw new IllegalArgumentException("Invalid declType: " + declType);
this.declType = declType;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/ObjectProperty.java
public void setNodeType(int nodeType) {
if (nodeType != Token.COLON
&& nodeType != Token.GET
&& nodeType != Token.SET)
throw new IllegalArgumentException("invalid node type: "
+ nodeType);
setType(nodeType);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/InfixExpression.java
public void setOperator(int operator) {
if (!Token.isValidToken(operator))
throw new IllegalArgumentException("Invalid token: " + operator);
setType(operator);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/UnaryExpression.java
public void setOperator(int operator) {
if (!Token.isValidToken(operator))
throw new IllegalArgumentException("Invalid token: " + operator);
setType(operator);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/Scope.java
public void putSymbol(Symbol symbol) {
if (symbol.getName() == null)
throw new IllegalArgumentException("null symbol name");
ensureSymbolTable();
symbolTable.put(symbol.getName(), symbol);
symbol.setContainingTable(this);
top.addSymbol(symbol);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/VariableDeclaration.java
Override
public org.mozilla.javascript.Node setType(int type) {
if (type != Token.VAR
&& type != Token.CONST
&& type != Token.LET)
throw new IllegalArgumentException("invalid decl type: " + type);
return super.setType(type);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/VariableInitializer.java
public void setNodeType(int nodeType) {
if (nodeType != Token.VAR
&& nodeType != Token.CONST
&& nodeType != Token.LET)
throw new IllegalArgumentException("invalid node type");
setType(nodeType);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/VariableInitializer.java
public void setTarget(AstNode target) {
// Don't throw exception if target is an "invalid" node type.
// See mozilla/js/tests/js1_7/block/regress-350279.js
if (target == null)
throw new IllegalArgumentException("invalid target arg");
this.target = target;
target.setParent(this);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/AstNode.java
public static String operatorToString(int op) {
String result = operatorNames.get(op);
if (result == null)
throw new IllegalArgumentException("Invalid operator: " + op);
return result;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ast/AstNode.java
protected void assertNotNull(Object arg) {
if (arg == null)
throw new IllegalArgumentException("arg cannot be null");
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/FunctionObject.java
public static Object convertArg(Context cx, Scriptable scope,
Object arg, int typeTag)
{
switch (typeTag) {
case JAVA_STRING_TYPE:
if (arg instanceof String)
return arg;
return ScriptRuntime.toString(arg);
case JAVA_INT_TYPE:
if (arg instanceof Integer)
return arg;
return Integer.valueOf(ScriptRuntime.toInt32(arg));
case JAVA_BOOLEAN_TYPE:
if (arg instanceof Boolean)
return arg;
return ScriptRuntime.toBoolean(arg) ? Boolean.TRUE
: Boolean.FALSE;
case JAVA_DOUBLE_TYPE:
if (arg instanceof Double)
return arg;
return new Double(ScriptRuntime.toNumber(arg));
case JAVA_SCRIPTABLE_TYPE:
return ScriptRuntime.toObjectOrNull(cx, arg, scope);
case JAVA_OBJECT_TYPE:
return arg;
default:
throw new IllegalArgumentException();
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/RhinoException.java
public final void initSourceName(String sourceName)
{
if (sourceName == null) throw new IllegalArgumentException();
if (this.sourceName != null) throw new IllegalStateException();
this.sourceName = sourceName;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/RhinoException.java
public final void initLineNumber(int lineNumber)
{
if (lineNumber <= 0) throw new IllegalArgumentException(String.valueOf(lineNumber));
if (this.lineNumber > 0) throw new IllegalStateException();
this.lineNumber = lineNumber;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/RhinoException.java
public final void initColumnNumber(int columnNumber)
{
if (columnNumber <= 0) throw new IllegalArgumentException(String.valueOf(columnNumber));
if (this.columnNumber > 0) throw new IllegalStateException();
this.columnNumber = columnNumber;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/RhinoException.java
public final void initLineSource(String lineSource)
{
if (lineSource == null) throw new IllegalArgumentException();
if (this.lineSource != null) throw new IllegalStateException();
this.lineSource = lineSource;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/SecurityController.java
public static void initGlobal(SecurityController controller)
{
if (controller == null) throw new IllegalArgumentException();
if (global != null) {
throw new SecurityException("Cannot overwrite already installed global SecurityController");
}
global = controller;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ImporterTopLevel.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=0; s="constructor"; break;
case Id_importClass: arity=1; s="importClass"; break;
case Id_importPackage: arity=1; s="importPackage"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(IMPORTER_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ImporterTopLevel.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(IMPORTER_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case Id_constructor:
return js_construct(scope, args);
case Id_importClass:
return realThis(thisObj, f).js_importClass(args);
case Id_importPackage:
return realThis(thisObj, f).js_importPackage(args);
}
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeDate.java
Override
protected void initPrototypeId(int id)
{
String s;
int arity;
switch (id) {
case Id_constructor: arity=1; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toTimeString: arity=0; s="toTimeString"; break;
case Id_toDateString: arity=0; s="toDateString"; break;
case Id_toLocaleString: arity=0; s="toLocaleString"; break;
case Id_toLocaleTimeString: arity=0; s="toLocaleTimeString"; break;
case Id_toLocaleDateString: arity=0; s="toLocaleDateString"; break;
case Id_toUTCString: arity=0; s="toUTCString"; break;
case Id_toSource: arity=0; s="toSource"; break;
case Id_valueOf: arity=0; s="valueOf"; break;
case Id_getTime: arity=0; s="getTime"; break;
case Id_getYear: arity=0; s="getYear"; break;
case Id_getFullYear: arity=0; s="getFullYear"; break;
case Id_getUTCFullYear: arity=0; s="getUTCFullYear"; break;
case Id_getMonth: arity=0; s="getMonth"; break;
case Id_getUTCMonth: arity=0; s="getUTCMonth"; break;
case Id_getDate: arity=0; s="getDate"; break;
case Id_getUTCDate: arity=0; s="getUTCDate"; break;
case Id_getDay: arity=0; s="getDay"; break;
case Id_getUTCDay: arity=0; s="getUTCDay"; break;
case Id_getHours: arity=0; s="getHours"; break;
case Id_getUTCHours: arity=0; s="getUTCHours"; break;
case Id_getMinutes: arity=0; s="getMinutes"; break;
case Id_getUTCMinutes: arity=0; s="getUTCMinutes"; break;
case Id_getSeconds: arity=0; s="getSeconds"; break;
case Id_getUTCSeconds: arity=0; s="getUTCSeconds"; break;
case Id_getMilliseconds: arity=0; s="getMilliseconds"; break;
case Id_getUTCMilliseconds: arity=0; s="getUTCMilliseconds"; break;
case Id_getTimezoneOffset: arity=0; s="getTimezoneOffset"; break;
case Id_setTime: arity=1; s="setTime"; break;
case Id_setMilliseconds: arity=1; s="setMilliseconds"; break;
case Id_setUTCMilliseconds: arity=1; s="setUTCMilliseconds"; break;
case Id_setSeconds: arity=2; s="setSeconds"; break;
case Id_setUTCSeconds: arity=2; s="setUTCSeconds"; break;
case Id_setMinutes: arity=3; s="setMinutes"; break;
case Id_setUTCMinutes: arity=3; s="setUTCMinutes"; break;
case Id_setHours: arity=4; s="setHours"; break;
case Id_setUTCHours: arity=4; s="setUTCHours"; break;
case Id_setDate: arity=1; s="setDate"; break;
case Id_setUTCDate: arity=1; s="setUTCDate"; break;
case Id_setMonth: arity=2; s="setMonth"; break;
case Id_setUTCMonth: arity=2; s="setUTCMonth"; break;
case Id_setFullYear: arity=3; s="setFullYear"; break;
case Id_setUTCFullYear: arity=3; s="setUTCFullYear"; break;
case Id_setYear: arity=1; s="setYear"; break;
case Id_toISOString: arity=0; s="toISOString"; break;
case Id_toJSON: arity=1; s="toJSON"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(DATE_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeDate.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(DATE_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case ConstructorId_now:
return ScriptRuntime.wrapNumber(now());
case ConstructorId_parse:
{
String dataStr = ScriptRuntime.toString(args, 0);
return ScriptRuntime.wrapNumber(date_parseString(dataStr));
}
case ConstructorId_UTC:
return ScriptRuntime.wrapNumber(jsStaticFunction_UTC(args));
case Id_constructor:
{
// if called as a function, just return a string
// representing the current time.
if (thisObj != null)
return date_format(now(), Id_toString);
return jsConstructor(args);
}
case Id_toJSON:
{
if (thisObj instanceof NativeDate) {
return ((NativeDate) thisObj).toISOString();
}
final String toISOString = "toISOString";
Scriptable o = ScriptRuntime.toObject(cx, scope, thisObj);
Object tv = ScriptRuntime.toPrimitive(o, ScriptRuntime.NumberClass);
if (tv instanceof Number) {
double d = ((Number) tv).doubleValue();
if (d != d || Double.isInfinite(d)) {
return null;
}
}
Object toISO = o.get(toISOString, o);
if (toISO == NOT_FOUND) {
throw ScriptRuntime.typeError2("msg.function.not.found.in",
toISOString,
ScriptRuntime.toString(o));
}
if ( !(toISO instanceof Callable) ) {
throw ScriptRuntime.typeError3("msg.isnt.function.in",
toISOString,
ScriptRuntime.toString(o),
ScriptRuntime.toString(toISO));
}
Object result = ((Callable) toISO).call(cx, scope, o,
ScriptRuntime.emptyArgs);
if ( !ScriptRuntime.isPrimitive(result) ) {
throw ScriptRuntime.typeError1("msg.toisostring.must.return.primitive",
ScriptRuntime.toString(result));
}
return result;
}
}
// The rest of Date.prototype methods require thisObj to be Date
if (!(thisObj instanceof NativeDate))
throw incompatibleCallError(f);
NativeDate realThis = (NativeDate)thisObj;
double t = realThis.date;
switch (id) {
case Id_toString:
case Id_toTimeString:
case Id_toDateString:
if (t == t) {
return date_format(t, id);
}
return js_NaN_date_str;
case Id_toLocaleString:
case Id_toLocaleTimeString:
case Id_toLocaleDateString:
if (t == t) {
return toLocale_helper(t, id);
}
return js_NaN_date_str;
case Id_toUTCString:
if (t == t) {
return js_toUTCString(t);
}
return js_NaN_date_str;
case Id_toSource:
return "(new Date("+ScriptRuntime.toString(t)+"))";
case Id_valueOf:
case Id_getTime:
return ScriptRuntime.wrapNumber(t);
case Id_getYear:
case Id_getFullYear:
case Id_getUTCFullYear:
if (t == t) {
if (id != Id_getUTCFullYear) t = LocalTime(t);
t = YearFromTime(t);
if (id == Id_getYear) {
if (cx.hasFeature(Context.FEATURE_NON_ECMA_GET_YEAR)) {
if (1900 <= t && t < 2000) {
t -= 1900;
}
} else {
t -= 1900;
}
}
}
return ScriptRuntime.wrapNumber(t);
case Id_getMonth:
case Id_getUTCMonth:
if (t == t) {
if (id == Id_getMonth) t = LocalTime(t);
t = MonthFromTime(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getDate:
case Id_getUTCDate:
if (t == t) {
if (id == Id_getDate) t = LocalTime(t);
t = DateFromTime(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getDay:
case Id_getUTCDay:
if (t == t) {
if (id == Id_getDay) t = LocalTime(t);
t = WeekDay(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getHours:
case Id_getUTCHours:
if (t == t) {
if (id == Id_getHours) t = LocalTime(t);
t = HourFromTime(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getMinutes:
case Id_getUTCMinutes:
if (t == t) {
if (id == Id_getMinutes) t = LocalTime(t);
t = MinFromTime(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getSeconds:
case Id_getUTCSeconds:
if (t == t) {
if (id == Id_getSeconds) t = LocalTime(t);
t = SecFromTime(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getMilliseconds:
case Id_getUTCMilliseconds:
if (t == t) {
if (id == Id_getMilliseconds) t = LocalTime(t);
t = msFromTime(t);
}
return ScriptRuntime.wrapNumber(t);
case Id_getTimezoneOffset:
if (t == t) {
t = (t - LocalTime(t)) / msPerMinute;
}
return ScriptRuntime.wrapNumber(t);
case Id_setTime:
t = TimeClip(ScriptRuntime.toNumber(args, 0));
realThis.date = t;
return ScriptRuntime.wrapNumber(t);
case Id_setMilliseconds:
case Id_setUTCMilliseconds:
case Id_setSeconds:
case Id_setUTCSeconds:
case Id_setMinutes:
case Id_setUTCMinutes:
case Id_setHours:
case Id_setUTCHours:
t = makeTime(t, args, id);
realThis.date = t;
return ScriptRuntime.wrapNumber(t);
case Id_setDate:
case Id_setUTCDate:
case Id_setMonth:
case Id_setUTCMonth:
case Id_setFullYear:
case Id_setUTCFullYear:
t = makeDate(t, args, id);
realThis.date = t;
return ScriptRuntime.wrapNumber(t);
case Id_setYear:
{
double year = ScriptRuntime.toNumber(args, 0);
if (year != year || Double.isInfinite(year)) {
t = ScriptRuntime.NaN;
} else {
if (t != t) {
t = 0;
} else {
t = LocalTime(t);
}
if (year >= 0 && year <= 99)
year += 1900;
double day = MakeDay(year, MonthFromTime(t),
DateFromTime(t));
t = MakeDate(day, TimeWithinDay(t));
t = internalUTC(t);
t = TimeClip(t);
}
}
realThis.date = t;
return ScriptRuntime.wrapNumber(t);
case Id_toISOString:
return realThis.toISOString();
default: throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeGenerator.java
Override
protected void initPrototypeId(int id) {
String s;
int arity;
switch (id) {
case Id_close: arity=1; s="close"; break;
case Id_next: arity=1; s="next"; break;
case Id_send: arity=0; s="send"; break;
case Id_throw: arity=0; s="throw"; break;
case Id___iterator__: arity=1; s="__iterator__"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(GENERATOR_TAG, id, s, arity);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/NativeGenerator.java
Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(GENERATOR_TAG)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (!(thisObj instanceof NativeGenerator))
throw incompatibleCallError(f);
NativeGenerator generator = (NativeGenerator) thisObj;
switch (id) {
case Id_close:
// need to run any pending finally clauses
return generator.resume(cx, scope, GENERATOR_CLOSE,
new GeneratorClosedException());
case Id_next:
// arguments to next() are ignored
generator.firstTime = false;
return generator.resume(cx, scope, GENERATOR_SEND,
Undefined.instance);
case Id_send: {
Object arg = args.length > 0 ? args[0] : Undefined.instance;
if (generator.firstTime && !arg.equals(Undefined.instance)) {
throw ScriptRuntime.typeError0("msg.send.newborn");
}
return generator.resume(cx, scope, GENERATOR_SEND, arg);
}
case Id_throw:
return generator.resume(cx, scope, GENERATOR_THROW,
args.length > 0 ? args[0] : Undefined.instance);
case Id___iterator__:
return thisObj;
default:
throw new IllegalArgumentException(String.valueOf(id));
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ObjArray.java
public final void setSize(int newSize)
{
if (newSize < 0) throw new IllegalArgumentException();
if (sealed) throw onSeledMutation();
int N = size;
if (newSize < N) {
for (int i = newSize; i != N; ++i) {
setImpl(i, null);
}
} else if (newSize > N) {
if (newSize > FIELDS_STORE_SIZE) {
ensureCapacity(newSize);
}
}
size = newSize;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ObjArray.java
private void ensureCapacity(int minimalCapacity)
{
int required = minimalCapacity - FIELDS_STORE_SIZE;
if (required <= 0) throw new IllegalArgumentException();
if (data == null) {
int alloc = FIELDS_STORE_SIZE * 2;
if (alloc < required) {
alloc = required;
}
data = new Object[alloc];
} else {
int alloc = data.length;
if (alloc < required) {
if (alloc <= FIELDS_STORE_SIZE) {
alloc = FIELDS_STORE_SIZE * 2;
} else {
alloc *= 2;
}
if (alloc < required) {
alloc = required;
}
Object[] tmp = new Object[alloc];
if (size > FIELDS_STORE_SIZE) {
System.arraycopy(data, 0, tmp, 0,
size - FIELDS_STORE_SIZE);
}
data = tmp;
}
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/IdScriptableObject.java
final void initValue(int id, String name, Object value, int attributes)
{
if (!(1 <= id && id <= maxId))
throw new IllegalArgumentException();
if (name == null)
throw new IllegalArgumentException();
if (value == NOT_FOUND)
throw new IllegalArgumentException();
ScriptableObject.checkValidAttributes(attributes);
if (obj.findPrototypeId(name) != id)
throw new IllegalArgumentException(name);
if (id == constructorId) {
if (!(value instanceof IdFunctionObject)) {
throw new IllegalArgumentException("consructor should be initialized with IdFunctionObject");
}
constructor = (IdFunctionObject)value;
constructorAttrs = (short)attributes;
return;
}
initSlot(id, name, value, attributes);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/IdScriptableObject.java
final void set(int id, Scriptable start, Object value)
{
if (value == NOT_FOUND) throw new IllegalArgumentException();
ensureId(id);
int attr = attributeArray[id - 1];
if ((attr & READONLY) == 0) {
if (start == obj) {
if (value == null) {
value = UniqueTag.NULL_VALUE;
}
int valueSlot = (id - 1) * SLOT_SPAN;
synchronized (this) {
valueArray[valueSlot] = value;
}
}
else {
int nameSlot = (id - 1) * SLOT_SPAN + NAME_SLOT;
String name = (String)valueArray[nameSlot];
start.put(name, start, value);
}
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/IdScriptableObject.java
protected String getInstanceIdName(int id)
{
throw new IllegalArgumentException(String.valueOf(id));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/IdScriptableObject.java
public final void initPrototypeConstructor(IdFunctionObject f)
{
int id = prototypeValues.constructorId;
if (id == 0)
throw new IllegalStateException();
if (f.methodId() != id)
throw new IllegalArgumentException();
if (isSealed()) { f.sealObject(); }
prototypeValues.initValue(id, "constructor", f, DONTENUM);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ClassCache.java
public boolean associate(ScriptableObject topScope)
{
if (topScope.getParentScope() != null) {
// Can only associate cache with top level scope
throw new IllegalArgumentException();
}
if (this == topScope.associateValue(AKEY, this)) {
associatedScope = topScope;
return true;
}
return false;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java
public void addOptionalExcludedName(String name) {
Object obj = lookupQualifiedName(scope, name);
if(obj != null && obj != UniqueTag.NOT_FOUND) {
if (!(obj instanceof Scriptable)) {
throw new IllegalArgumentException(
"Object for excluded name " + name +
" is not a Scriptable, it is " +
obj.getClass().getName());
}
table.put(obj, name);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java
public void addExcludedName(String name) {
Object obj = lookupQualifiedName(scope, name);
if (!(obj instanceof Scriptable)) {
throw new IllegalArgumentException("Object for excluded name " +
name + " not found.");
}
table.put(obj, name);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Decompiler.java
void addToken(int token)
{
if (!(0 <= token && token <= Token.LAST_TOKEN))
throw new IllegalArgumentException();
append((char)token);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Decompiler.java
void addEOL(int token)
{
if (!(0 <= token && token <= Token.LAST_TOKEN))
throw new IllegalArgumentException();
append((char)token);
append((char)Token.EOL);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Decompiler.java
public static String decompile(String source, int flags,
UintMap properties)
{
int length = source.length();
if (length == 0) { return ""; }
int indent = properties.getInt(INITIAL_INDENT_PROP, 0);
if (indent < 0) throw new IllegalArgumentException();
int indentGap = properties.getInt(INDENT_GAP_PROP, 4);
if (indentGap < 0) throw new IllegalArgumentException();
int caseGap = properties.getInt(CASE_GAP_PROP, 2);
if (caseGap < 0) throw new IllegalArgumentException();
StringBuffer result = new StringBuffer();
boolean justFunctionBody = (0 != (flags & Decompiler.ONLY_BODY_FLAG));
boolean toSource = (0 != (flags & Decompiler.TO_SOURCE_FLAG));
// Spew tokens in source, for debugging.
// as TYPE number char
if (printSource) {
System.err.println("length:" + length);
for (int i = 0; i < length; ++i) {
// Note that tokenToName will fail unless Context.printTrees
// is true.
String tokenname = null;
if (Token.printNames) {
tokenname = Token.name(source.charAt(i));
}
if (tokenname == null) {
tokenname = "---";
}
String pad = tokenname.length() > 7
? "\t"
: "\t\t";
System.err.println
(tokenname
+ pad + (int)source.charAt(i)
+ "\t'" + ScriptRuntime.escapeString
(source.substring(i, i+1))
+ "'");
}
System.err.println();
}
int braceNesting = 0;
boolean afterFirstEOL = false;
int i = 0;
int topFunctionType;
if (source.charAt(i) == Token.SCRIPT) {
++i;
topFunctionType = -1;
} else {
topFunctionType = source.charAt(i + 1);
}
if (!toSource) {
// add an initial newline to exactly match js.
result.append('\n');
for (int j = 0; j < indent; j++)
result.append(' ');
} else {
if (topFunctionType == FunctionNode.FUNCTION_EXPRESSION) {
result.append('(');
}
}
while (i < length) {
switch(source.charAt(i)) {
case Token.GET:
case Token.SET:
result.append(source.charAt(i) == Token.GET ? "get " : "set ");
++i;
i = printSourceString(source, i + 1, false, result);
// Now increment one more to get past the FUNCTION token
++i;
break;
case Token.NAME:
case Token.REGEXP: // re-wrapped in '/'s in parser...
i = printSourceString(source, i + 1, false, result);
continue;
case Token.STRING:
i = printSourceString(source, i + 1, true, result);
continue;
case Token.NUMBER:
i = printSourceNumber(source, i + 1, result);
continue;
case Token.TRUE:
result.append("true");
break;
case Token.FALSE:
result.append("false");
break;
case Token.NULL:
result.append("null");
break;
case Token.THIS:
result.append("this");
break;
case Token.FUNCTION:
++i; // skip function type
result.append("function ");
break;
case FUNCTION_END:
// Do nothing
break;
case Token.COMMA:
result.append(", ");
break;
case Token.LC:
++braceNesting;
if (Token.EOL == getNext(source, length, i))
indent += indentGap;
result.append('{');
break;
case Token.RC: {
--braceNesting;
/* don't print the closing RC if it closes the
* toplevel function and we're called from
* decompileFunctionBody.
*/
if (justFunctionBody && braceNesting == 0)
break;
result.append('}');
switch (getNext(source, length, i)) {
case Token.EOL:
case FUNCTION_END:
indent -= indentGap;
break;
case Token.WHILE:
case Token.ELSE:
indent -= indentGap;
result.append(' ');
break;
}
break;
}
case Token.LP:
result.append('(');
break;
case Token.RP:
result.append(')');
if (Token.LC == getNext(source, length, i))
result.append(' ');
break;
case Token.LB:
result.append('[');
break;
case Token.RB:
result.append(']');
break;
case Token.EOL: {
if (toSource) break;
boolean newLine = true;
if (!afterFirstEOL) {
afterFirstEOL = true;
if (justFunctionBody) {
/* throw away just added 'function name(...) {'
* and restore the original indent
*/
result.setLength(0);
indent -= indentGap;
newLine = false;
}
}
if (newLine) {
result.append('\n');
}
/* add indent if any tokens remain,
* less setback if next token is
* a label, case or default.
*/
if (i + 1 < length) {
int less = 0;
int nextToken = source.charAt(i + 1);
if (nextToken == Token.CASE
|| nextToken == Token.DEFAULT)
{
less = indentGap - caseGap;
} else if (nextToken == Token.RC) {
less = indentGap;
}
/* elaborate check against label... skip past a
* following inlined NAME and look for a COLON.
*/
else if (nextToken == Token.NAME) {
int afterName = getSourceStringEnd(source, i + 2);
if (source.charAt(afterName) == Token.COLON)
less = indentGap;
}
for (; less < indent; less++)
result.append(' ');
}
break;
}
case Token.DOT:
result.append('.');
break;
case Token.NEW:
result.append("new ");
break;
case Token.DELPROP:
result.append("delete ");
break;
case Token.IF:
result.append("if ");
break;
case Token.ELSE:
result.append("else ");
break;
case Token.FOR:
result.append("for ");
break;
case Token.IN:
result.append(" in ");
break;
case Token.WITH:
result.append("with ");
break;
case Token.WHILE:
result.append("while ");
break;
case Token.DO:
result.append("do ");
break;
case Token.TRY:
result.append("try ");
break;
case Token.CATCH:
result.append("catch ");
break;
case Token.FINALLY:
result.append("finally ");
break;
case Token.THROW:
result.append("throw ");
break;
case Token.SWITCH:
result.append("switch ");
break;
case Token.BREAK:
result.append("break");
if (Token.NAME == getNext(source, length, i))
result.append(' ');
break;
case Token.CONTINUE:
result.append("continue");
if (Token.NAME == getNext(source, length, i))
result.append(' ');
break;
case Token.CASE:
result.append("case ");
break;
case Token.DEFAULT:
result.append("default");
break;
case Token.RETURN:
result.append("return");
if (Token.SEMI != getNext(source, length, i))
result.append(' ');
break;
case Token.VAR:
result.append("var ");
break;
case Token.LET:
result.append("let ");
break;
case Token.SEMI:
result.append(';');
if (Token.EOL != getNext(source, length, i)) {
// separators in FOR
result.append(' ');
}
break;
case Token.ASSIGN:
result.append(" = ");
break;
case Token.ASSIGN_ADD:
result.append(" += ");
break;
case Token.ASSIGN_SUB:
result.append(" -= ");
break;
case Token.ASSIGN_MUL:
result.append(" *= ");
break;
case Token.ASSIGN_DIV:
result.append(" /= ");
break;
case Token.ASSIGN_MOD:
result.append(" %= ");
break;
case Token.ASSIGN_BITOR:
result.append(" |= ");
break;
case Token.ASSIGN_BITXOR:
result.append(" ^= ");
break;
case Token.ASSIGN_BITAND:
result.append(" &= ");
break;
case Token.ASSIGN_LSH:
result.append(" <<= ");
break;
case Token.ASSIGN_RSH:
result.append(" >>= ");
break;
case Token.ASSIGN_URSH:
result.append(" >>>= ");
break;
case Token.HOOK:
result.append(" ? ");
break;
case Token.OBJECTLIT:
// pun OBJECTLIT to mean colon in objlit property
// initialization.
// This needs to be distinct from COLON in the general case
// to distinguish from the colon in a ternary... which needs
// different spacing.
result.append(':');
break;
case Token.COLON:
if (Token.EOL == getNext(source, length, i))
// it's the end of a label
result.append(':');
else
// it's the middle part of a ternary
result.append(" : ");
break;
case Token.OR:
result.append(" || ");
break;
case Token.AND:
result.append(" && ");
break;
case Token.BITOR:
result.append(" | ");
break;
case Token.BITXOR:
result.append(" ^ ");
break;
case Token.BITAND:
result.append(" & ");
break;
case Token.SHEQ:
result.append(" === ");
break;
case Token.SHNE:
result.append(" !== ");
break;
case Token.EQ:
result.append(" == ");
break;
case Token.NE:
result.append(" != ");
break;
case Token.LE:
result.append(" <= ");
break;
case Token.LT:
result.append(" < ");
break;
case Token.GE:
result.append(" >= ");
break;
case Token.GT:
result.append(" > ");
break;
case Token.INSTANCEOF:
result.append(" instanceof ");
break;
case Token.LSH:
result.append(" << ");
break;
case Token.RSH:
result.append(" >> ");
break;
case Token.URSH:
result.append(" >>> ");
break;
case Token.TYPEOF:
result.append("typeof ");
break;
case Token.VOID:
result.append("void ");
break;
case Token.CONST:
result.append("const ");
break;
case Token.YIELD:
result.append("yield ");
break;
case Token.NOT:
result.append('!');
break;
case Token.BITNOT:
result.append('~');
break;
case Token.POS:
result.append('+');
break;
case Token.NEG:
result.append('-');
break;
case Token.INC:
result.append("++");
break;
case Token.DEC:
result.append("--");
break;
case Token.ADD:
result.append(" + ");
break;
case Token.SUB:
result.append(" - ");
break;
case Token.MUL:
result.append(" * ");
break;
case Token.DIV:
result.append(" / ");
break;
case Token.MOD:
result.append(" % ");
break;
case Token.COLONCOLON:
result.append("::");
break;
case Token.DOTDOT:
result.append("..");
break;
case Token.DOTQUERY:
result.append(".(");
break;
case Token.XMLATTR:
result.append('@');
break;
case Token.DEBUGGER:
result.append("debugger;\n");
break;
default:
// If we don't know how to decompile it, raise an exception.
throw new RuntimeException("Token: " +
Token.name(source.charAt(i)));
}
++i;
}
if (!toSource) {
// add that trailing newline if it's an outermost function.
if (!justFunctionBody)
result.append('\n');
} else {
if (topFunctionType == FunctionNode.FUNCTION_EXPRESSION) {
result.append(')');
}
}
return result.toString();
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptRuntime.java
public static Object doTopCall(Callable callable,
Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (scope == null)
throw new IllegalArgumentException();
if (cx.topCallScope != null) throw new IllegalStateException();
Object result;
cx.topCallScope = ScriptableObject.getTopLevelScope(scope);
cx.useDynamicScope = cx.hasFeature(Context.FEATURE_DYNAMIC_SCOPE);
ContextFactory f = cx.getFactory();
try {
result = f.doTopCall(callable, cx, scope, thisObj, args);
} finally {
cx.topCallScope = null;
// Cleanup cached references
cx.cachedXMLLib = null;
if (cx.currentActivationCall != null) {
// Function should always call exitActivationFunction
// if it creates activation record
throw new IllegalStateException();
}
}
return result;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptRuntime.java
public static Object[] getArrayElements(Scriptable object)
{
Context cx = Context.getContext();
long longLen = NativeArray.getLengthProperty(cx, object);
if (longLen > Integer.MAX_VALUE) {
// arrays beyond MAX_INT is not in Java in any case
throw new IllegalArgumentException();
}
int len = (int) longLen;
if (len == 0) {
return ScriptRuntime.emptyArgs;
} else {
Object[] result = new Object[len];
for (int i=0; i < len; i++) {
Object elem = ScriptableObject.getProperty(object, i);
result[i] = (elem == Scriptable.NOT_FOUND) ? Undefined.instance
: elem;
}
return result;
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptRuntime.java
public static void setRegExpProxy(Context cx, RegExpProxy proxy)
{
if (proxy == null) throw new IllegalArgumentException();
cx.regExpProxy = proxy;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/ScriptRuntime.java
public static void storeUint32Result(Context cx, long value)
{
if ((value >>> 32) != 0)
throw new IllegalArgumentException();
cx.scratchUint32 = value;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final void unseal(Object sealKey)
{
if (sealKey == null) throw new IllegalArgumentException();
if (this.sealKey != sealKey) throw new IllegalArgumentException();
if (!sealed) throw new IllegalStateException();
sealed = false;
this.sealKey = null;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public static void checkLanguageVersion(int version)
{
if (isValidLanguageVersion(version)) {
return;
}
throw new IllegalArgumentException("Bad language version: "+version);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final ErrorReporter setErrorReporter(ErrorReporter reporter)
{
if (sealed) onSealedMutation();
if (reporter == null) throw new IllegalArgumentException();
ErrorReporter old = getErrorReporter();
if (reporter == old) {
return old;
}
Object listeners = propertyListeners;
if (listeners != null) {
firePropertyChangeImpl(listeners, errorReporterProperty,
old, reporter);
}
this.errorReporter = reporter;
return old;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public Object executeScriptWithContinuations(Script script,
Scriptable scope)
throws ContinuationPending
{
if (!(script instanceof InterpretedFunction) ||
!((InterpretedFunction)script).isScript())
{
// Can only be applied to scripts
throw new IllegalArgumentException("Script argument was not" +
" a script or was not created by interpreted mode ");
}
return callFunctionWithContinuations((InterpretedFunction) script,
scope, ScriptRuntime.emptyArgs);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public Object callFunctionWithContinuations(Callable function,
Scriptable scope, Object[] args)
throws ContinuationPending
{
if (!(function instanceof InterpretedFunction)) {
// Can only be applied to scripts
throw new IllegalArgumentException("Function argument was not" +
" created by interpreted mode ");
}
if (ScriptRuntime.hasTopCall(this)) {
throw new IllegalStateException("Cannot have any pending top " +
"calls when executing a script with continuations");
}
// Annotate so we can check later to ensure no java code in
// intervening frames
isContinuationsTopCall = true;
return ScriptRuntime.doTopCall(function, this, scope, scope, args);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public Scriptable newArray(Scriptable scope, Object[] elements)
{
if (elements.getClass().getComponentType() != ScriptRuntime.ObjectClass)
throw new IllegalArgumentException();
NativeArray result = new NativeArray(elements);
ScriptRuntime.setBuiltinProtoAndParent(result, scope,
TopLevel.Builtins.Array);
return result;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public static void checkOptimizationLevel(int optimizationLevel)
{
if (isValidOptimizationLevel(optimizationLevel)) {
return;
}
throw new IllegalArgumentException(
"Optimization level outside [-1..9]: "+optimizationLevel);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final void setMaximumInterpreterStackDepth(int max)
{
if(sealed) onSealedMutation();
if(optimizationLevel != -1) {
throw new IllegalStateException("Cannot set maximumInterpreterStackDepth when optimizationLevel != -1");
}
if(max < 1) {
throw new IllegalArgumentException("Cannot set maximumInterpreterStackDepth to less than 1");
}
maximumInterpreterStackDepth = max;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final void setSecurityController(SecurityController controller)
{
if (sealed) onSealedMutation();
if (controller == null) throw new IllegalArgumentException();
if (securityController != null) {
throw new SecurityException("Can not overwrite existing SecurityController object");
}
if (SecurityController.hasGlobal()) {
throw new SecurityException("Can not overwrite existing global SecurityController object");
}
securityController = controller;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public synchronized final void setClassShutter(ClassShutter shutter)
{
if (sealed) onSealedMutation();
if (shutter == null) throw new IllegalArgumentException();
if (hasClassShutter) {
throw new SecurityException("Cannot overwrite existing " +
"ClassShutter object");
}
classShutter = shutter;
hasClassShutter = true;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final void setWrapFactory(WrapFactory wrapFactory)
{
if (sealed) onSealedMutation();
if (wrapFactory == null) throw new IllegalArgumentException();
this.wrapFactory = wrapFactory;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final void setInstructionObserverThreshold(int threshold)
{
if (sealed) onSealedMutation();
if (threshold < 0) throw new IllegalArgumentException();
instructionThreshold = threshold;
setGenerateObserverCount(threshold > 0);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
public final void setApplicationClassLoader(ClassLoader loader)
{
if (sealed) onSealedMutation();
if (loader == null) {
// restore default behaviour
applicationClassLoader = null;
return;
}
if (!Kit.testIfCanLoadRhinoClasses(loader)) {
throw new IllegalArgumentException(
"Loader can not resolve Rhino classes");
}
applicationClassLoader = loader;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/Context.java
private Object compileImpl(Scriptable scope,
Reader sourceReader, String sourceString,
String sourceName, int lineno,
Object securityDomain, boolean returnFunction,
Evaluator compiler,
ErrorReporter compilationErrorReporter)
throws IOException
{
if(sourceName == null) {
sourceName = "unnamed script";
}
if (securityDomain != null && getSecurityController() == null) {
throw new IllegalArgumentException(
"securityDomain should be null if setSecurityController() was never called");
}
// One of sourceReader or sourceString has to be null
if (!(sourceReader == null ^ sourceString == null)) Kit.codeBug();
// scope should be given if and only if compiling function
if (!(scope == null ^ returnFunction)) Kit.codeBug();
CompilerEnvirons compilerEnv = new CompilerEnvirons();
compilerEnv.initFromContext(this);
if (compilationErrorReporter == null) {
compilationErrorReporter = compilerEnv.getErrorReporter();
}
if (debugger != null) {
if (sourceReader != null) {
sourceString = Kit.readReader(sourceReader);
sourceReader = null;
}
}
Parser p = new Parser(compilerEnv, compilationErrorReporter);
if (returnFunction) {
p.calledByCompileFunction = true;
}
AstRoot ast;
if (sourceString != null) {
ast = p.parse(sourceString, sourceName, lineno);
} else {
ast = p.parse(sourceReader, sourceName, lineno);
}
if (returnFunction) {
// parser no longer adds function to script node
if (!(ast.getFirstChild() != null
&& ast.getFirstChild().getType() == Token.FUNCTION))
{
// XXX: the check just looks for the first child
// and allows for more nodes after it for compatibility
// with sources like function() {};;;
throw new IllegalArgumentException(
"compileFunction only accepts source with single JS function: "+sourceString);
}
}
IRFactory irf = new IRFactory(compilerEnv, compilationErrorReporter);
ScriptNode tree = irf.transformTree(ast);
// discard everything but the IR tree
p = null;
ast = null;
irf = null;
if (compiler == null) {
compiler = createCompiler();
}
Object bytecode = compiler.compile(compilerEnv,
tree, tree.getEncodedSource(),
returnFunction);
if (debugger != null) {
if (sourceString == null) Kit.codeBug();
if (bytecode instanceof DebuggableScript) {
DebuggableScript dscript = (DebuggableScript)bytecode;
notifyDebugger_r(this, dscript, sourceString);
} else {
throw new RuntimeException("NOT SUPPORTED");
}
}
Object result;
if (returnFunction) {
result = compiler.createFunctionObject(this, scope, bytecode, securityDomain);
} else {
result = compiler.createScriptObject(bytecode, securityDomain);
}
return result;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/javascript/IdFunctionObject.java
public void initFunction(String name, Scriptable scope)
{
if (name == null) throw new IllegalArgumentException();
if (scope == null) throw new IllegalArgumentException();
this.functionName = name;
setParentScope(scope);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void add(int theOpCode) {
if (opcodeCount(theOpCode) != 0)
throw new IllegalArgumentException("Unexpected operands");
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
if (DEBUGCODE)
System.out.println("Add " + bytecodeStr(theOpCode));
addToCodeBuffer(theOpCode);
itsStackTop = (short)newStack;
if (newStack > itsMaxStack) itsMaxStack = (short)newStack;
if (DEBUGSTACK) {
System.out.println("After "+bytecodeStr(theOpCode)
+" stack = "+itsStackTop);
}
if (theOpCode == ByteCode.ATHROW) {
addSuperBlockStart(itsCodeBufferTop);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void add(int theOpCode, int theOperand) {
if (DEBUGCODE) {
System.out.println("Add "+bytecodeStr(theOpCode)
+", "+Integer.toHexString(theOperand));
}
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
switch (theOpCode) {
case ByteCode.GOTO :
// This is necessary because dead code is seemingly being
// generated and Sun's verifier is expecting type state to be
// placed even at dead blocks of code.
addSuperBlockStart(itsCodeBufferTop + 3);
// fallthru...
case ByteCode.IFEQ :
case ByteCode.IFNE :
case ByteCode.IFLT :
case ByteCode.IFGE :
case ByteCode.IFGT :
case ByteCode.IFLE :
case ByteCode.IF_ICMPEQ :
case ByteCode.IF_ICMPNE :
case ByteCode.IF_ICMPLT :
case ByteCode.IF_ICMPGE :
case ByteCode.IF_ICMPGT :
case ByteCode.IF_ICMPLE :
case ByteCode.IF_ACMPEQ :
case ByteCode.IF_ACMPNE :
case ByteCode.JSR :
case ByteCode.IFNULL :
case ByteCode.IFNONNULL : {
if ((theOperand & 0x80000000) != 0x80000000) {
if ((theOperand < 0) || (theOperand > 65535))
throw new IllegalArgumentException(
"Bad label for branch");
}
int branchPC = itsCodeBufferTop;
addToCodeBuffer(theOpCode);
if ((theOperand & 0x80000000) != 0x80000000) {
// hard displacement
addToCodeInt16(theOperand);
int target = theOperand + branchPC;
addSuperBlockStart(target);
itsJumpFroms.put(target, branchPC);
}
else { // a label
int targetPC = getLabelPC(theOperand);
if (DEBUGLABELS) {
int theLabel = theOperand & 0x7FFFFFFF;
System.out.println("Fixing branch to " +
theLabel + " at " + targetPC +
" from " + branchPC);
}
if (targetPC != -1) {
int offset = targetPC - branchPC;
addToCodeInt16(offset);
addSuperBlockStart(targetPC);
itsJumpFroms.put(targetPC, branchPC);
}
else {
addLabelFixup(theOperand, branchPC + 1);
addToCodeInt16(0);
}
}
}
break;
case ByteCode.BIPUSH :
if ((byte)theOperand != theOperand)
throw new IllegalArgumentException("out of range byte");
addToCodeBuffer(theOpCode);
addToCodeBuffer((byte)theOperand);
break;
case ByteCode.SIPUSH :
if ((short)theOperand != theOperand)
throw new IllegalArgumentException("out of range short");
addToCodeBuffer(theOpCode);
addToCodeInt16(theOperand);
break;
case ByteCode.NEWARRAY :
if (!(0 <= theOperand && theOperand < 256))
throw new IllegalArgumentException("out of range index");
addToCodeBuffer(theOpCode);
addToCodeBuffer(theOperand);
break;
case ByteCode.GETFIELD :
case ByteCode.PUTFIELD :
if (!(0 <= theOperand && theOperand < 65536))
throw new IllegalArgumentException("out of range field");
addToCodeBuffer(theOpCode);
addToCodeInt16(theOperand);
break;
case ByteCode.LDC :
case ByteCode.LDC_W :
case ByteCode.LDC2_W :
if (!(0 <= theOperand && theOperand < 65536))
throw new IllegalArgumentException("out of range index");
if (theOperand >= 256
|| theOpCode == ByteCode.LDC_W
|| theOpCode == ByteCode.LDC2_W)
{
if (theOpCode == ByteCode.LDC) {
addToCodeBuffer(ByteCode.LDC_W);
} else {
addToCodeBuffer(theOpCode);
}
addToCodeInt16(theOperand);
} else {
addToCodeBuffer(theOpCode);
addToCodeBuffer(theOperand);
}
break;
case ByteCode.RET :
case ByteCode.ILOAD :
case ByteCode.LLOAD :
case ByteCode.FLOAD :
case ByteCode.DLOAD :
case ByteCode.ALOAD :
case ByteCode.ISTORE :
case ByteCode.LSTORE :
case ByteCode.FSTORE :
case ByteCode.DSTORE :
case ByteCode.ASTORE :
if (!(0 <= theOperand && theOperand < 65536))
throw new ClassFileFormatException("out of range variable");
if (theOperand >= 256) {
addToCodeBuffer(ByteCode.WIDE);
addToCodeBuffer(theOpCode);
addToCodeInt16(theOperand);
}
else {
addToCodeBuffer(theOpCode);
addToCodeBuffer(theOperand);
}
break;
default :
throw new IllegalArgumentException(
"Unexpected opcode for 1 operand");
}
itsStackTop = (short)newStack;
if (newStack > itsMaxStack) itsMaxStack = (short)newStack;
if (DEBUGSTACK) {
System.out.println("After "+bytecodeStr(theOpCode)
+" stack = "+itsStackTop);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void add(int theOpCode, int theOperand1, int theOperand2) {
if (DEBUGCODE) {
System.out.println("Add "+bytecodeStr(theOpCode)
+", "+Integer.toHexString(theOperand1)
+", "+Integer.toHexString(theOperand2));
}
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
if (theOpCode == ByteCode.IINC) {
if (!(0 <= theOperand1 && theOperand1 < 65536))
throw new ClassFileFormatException("out of range variable");
if (!(0 <= theOperand2 && theOperand2 < 65536))
throw new ClassFileFormatException("out of range increment");
if (theOperand1 > 255 || theOperand2 < -128 || theOperand2 > 127) {
addToCodeBuffer(ByteCode.WIDE);
addToCodeBuffer(ByteCode.IINC);
addToCodeInt16(theOperand1);
addToCodeInt16(theOperand2);
}
else {
addToCodeBuffer(ByteCode.IINC);
addToCodeBuffer(theOperand1);
addToCodeBuffer(theOperand2);
}
}
else if (theOpCode == ByteCode.MULTIANEWARRAY) {
if (!(0 <= theOperand1 && theOperand1 < 65536))
throw new IllegalArgumentException("out of range index");
if (!(0 <= theOperand2 && theOperand2 < 256))
throw new IllegalArgumentException("out of range dimensions");
addToCodeBuffer(ByteCode.MULTIANEWARRAY);
addToCodeInt16(theOperand1);
addToCodeBuffer(theOperand2);
}
else {
throw new IllegalArgumentException(
"Unexpected opcode for 2 operands");
}
itsStackTop = (short)newStack;
if (newStack > itsMaxStack) itsMaxStack = (short)newStack;
if (DEBUGSTACK) {
System.out.println("After "+bytecodeStr(theOpCode)
+" stack = "+itsStackTop);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void add(int theOpCode, String className) {
if (DEBUGCODE) {
System.out.println("Add "+bytecodeStr(theOpCode)
+", "+className);
}
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
switch (theOpCode) {
case ByteCode.NEW :
case ByteCode.ANEWARRAY :
case ByteCode.CHECKCAST :
case ByteCode.INSTANCEOF : {
short classIndex = itsConstantPool.addClass(className);
addToCodeBuffer(theOpCode);
addToCodeInt16(classIndex);
}
break;
default :
throw new IllegalArgumentException(
"bad opcode for class reference");
}
itsStackTop = (short)newStack;
if (newStack > itsMaxStack) itsMaxStack = (short)newStack;
if (DEBUGSTACK) {
System.out.println("After "+bytecodeStr(theOpCode)
+" stack = "+itsStackTop);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void add(int theOpCode, String className, String fieldName,
String fieldType)
{
if (DEBUGCODE) {
System.out.println("Add "+bytecodeStr(theOpCode)
+", "+className+", "+fieldName+", "+fieldType);
}
int newStack = itsStackTop + stackChange(theOpCode);
char fieldTypeChar = fieldType.charAt(0);
int fieldSize = (fieldTypeChar == 'J' || fieldTypeChar == 'D')
? 2 : 1;
switch (theOpCode) {
case ByteCode.GETFIELD :
case ByteCode.GETSTATIC :
newStack += fieldSize;
break;
case ByteCode.PUTSTATIC :
case ByteCode.PUTFIELD :
newStack -= fieldSize;
break;
default :
throw new IllegalArgumentException(
"bad opcode for field reference");
}
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
short fieldRefIndex = itsConstantPool.addFieldRef(className,
fieldName, fieldType);
addToCodeBuffer(theOpCode);
addToCodeInt16(fieldRefIndex);
itsStackTop = (short)newStack;
if (newStack > itsMaxStack) itsMaxStack = (short)newStack;
if (DEBUGSTACK) {
System.out.println("After "+bytecodeStr(theOpCode)
+" stack = "+itsStackTop);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void addInvoke(int theOpCode, String className, String methodName,
String methodType)
{
if (DEBUGCODE) {
System.out.println("Add "+bytecodeStr(theOpCode)
+", "+className+", "+methodName+", "
+methodType);
}
int parameterInfo = sizeOfParameters(methodType);
int parameterCount = parameterInfo >>> 16;
int stackDiff = (short)parameterInfo;
int newStack = itsStackTop + stackDiff;
newStack += stackChange(theOpCode); // adjusts for 'this'
if (newStack < 0 || Short.MAX_VALUE < newStack) badStack(newStack);
switch (theOpCode) {
case ByteCode.INVOKEVIRTUAL :
case ByteCode.INVOKESPECIAL :
case ByteCode.INVOKESTATIC :
case ByteCode.INVOKEINTERFACE : {
addToCodeBuffer(theOpCode);
if (theOpCode == ByteCode.INVOKEINTERFACE) {
short ifMethodRefIndex
= itsConstantPool.addInterfaceMethodRef(
className, methodName,
methodType);
addToCodeInt16(ifMethodRefIndex);
addToCodeBuffer(parameterCount + 1);
addToCodeBuffer(0);
}
else {
short methodRefIndex = itsConstantPool.addMethodRef(
className, methodName,
methodType);
addToCodeInt16(methodRefIndex);
}
}
break;
default :
throw new IllegalArgumentException(
"bad opcode for method reference");
}
itsStackTop = (short)newStack;
if (newStack > itsMaxStack) itsMaxStack = (short)newStack;
if (DEBUGSTACK) {
System.out.println("After "+bytecodeStr(theOpCode)
+" stack = "+itsStackTop);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public final void markTableSwitchCase(int switchStart, int caseIndex,
int stackTop)
{
if (!(0 <= stackTop && stackTop <= itsMaxStack))
throw new IllegalArgumentException("Bad stack index: "+stackTop);
itsStackTop = (short)stackTop;
addSuperBlockStart(itsCodeBufferTop);
itsJumpFroms.put(itsCodeBufferTop, switchStart);
setTableSwitchJump(switchStart, caseIndex, itsCodeBufferTop);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void setTableSwitchJump(int switchStart, int caseIndex,
int jumpTarget)
{
if (!(0 <= jumpTarget && jumpTarget <= itsCodeBufferTop))
throw new IllegalArgumentException("Bad jump target: "+jumpTarget);
if (!(caseIndex >= -1))
throw new IllegalArgumentException("Bad case index: "+caseIndex);
int padSize = 3 & ~switchStart; // == 3 - switchStart % 4
int caseOffset;
if (caseIndex < 0) {
// default label
caseOffset = switchStart + 1 + padSize;
} else {
caseOffset = switchStart + 1 + padSize + 4 * (3 + caseIndex);
}
if (!(0 <= switchStart
&& switchStart <= itsCodeBufferTop - 4 * 4 - padSize - 1))
{
throw new IllegalArgumentException(
switchStart+" is outside a possible range of tableswitch"
+" in already generated code");
}
if ((0xFF & itsCodeBuffer[switchStart]) != ByteCode.TABLESWITCH) {
throw new IllegalArgumentException(
switchStart+" is not offset of tableswitch statement");
}
if (!(0 <= caseOffset && caseOffset + 4 <= itsCodeBufferTop)) {
// caseIndex >= -1 does not guarantee that caseOffset >= 0 due
// to a possible overflow.
throw new ClassFileFormatException(
"Too big case index: "+caseIndex);
}
// ALERT: perhaps check against case bounds?
putInt32(jumpTarget - switchStart, itsCodeBuffer, caseOffset);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void markLabel(int label)
{
if (!(label < 0))
throw new IllegalArgumentException("Bad label, no biscuit");
label &= 0x7FFFFFFF;
if (label > itsLabelTableTop)
throw new IllegalArgumentException("Bad label");
if (itsLabelTable[label] != -1) {
throw new IllegalStateException("Can only mark label once");
}
itsLabelTable[label] = itsCodeBufferTop;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public int getLabelPC(int label)
{
if (!(label < 0))
throw new IllegalArgumentException("Bad label, no biscuit");
label &= 0x7FFFFFFF;
if (!(label < itsLabelTableTop))
throw new IllegalArgumentException("Bad label");
return itsLabelTable[label];
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private void addLabelFixup(int label, int fixupSite)
{
if (!(label < 0))
throw new IllegalArgumentException("Bad label, no biscuit");
label &= 0x7FFFFFFF;
if (!(label < itsLabelTableTop))
throw new IllegalArgumentException("Bad label");
int top = itsFixupTableTop;
if (itsFixupTable == null || top == itsFixupTable.length) {
if (itsFixupTable == null) {
itsFixupTable = new long[MIN_FIXUP_TABLE_SIZE];
}else {
long[] tmp = new long[itsFixupTable.length * 2];
System.arraycopy(itsFixupTable, 0, tmp, 0, top);
itsFixupTable = tmp;
}
}
itsFixupTableTop = top + 1;
itsFixupTable[top] = ((long)label << 32) | fixupSite;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private int addReservedCodeSpace(int size)
{
if (itsCurrentMethod == null)
throw new IllegalArgumentException("No method to add to");
int oldTop = itsCodeBufferTop;
int newTop = oldTop + size;
if (newTop > itsCodeBuffer.length) {
int newSize = itsCodeBuffer.length * 2;
if (newTop > newSize) { newSize = newTop; }
byte[] tmp = new byte[newSize];
System.arraycopy(itsCodeBuffer, 0, tmp, 0, oldTop);
itsCodeBuffer = tmp;
}
itsCodeBufferTop = newTop;
return oldTop;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void addExceptionHandler(int startLabel, int endLabel,
int handlerLabel, String catchClassName)
{
if ((startLabel & 0x80000000) != 0x80000000)
throw new IllegalArgumentException("Bad startLabel");
if ((endLabel & 0x80000000) != 0x80000000)
throw new IllegalArgumentException("Bad endLabel");
if ((handlerLabel & 0x80000000) != 0x80000000)
throw new IllegalArgumentException("Bad handlerLabel");
/*
* If catchClassName is null, use 0 for the catch_type_index; which
* means catch everything. (Even when the verifier has let you throw
* something other than a Throwable.)
*/
short catch_type_index = (catchClassName == null)
? 0
: itsConstantPool.addClass(catchClassName);
ExceptionTableEntry newEntry = new ExceptionTableEntry(
startLabel,
endLabel,
handlerLabel,
catch_type_index);
int N = itsExceptionTableTop;
if (N == 0) {
itsExceptionTable = new ExceptionTableEntry[ExceptionTableSize];
} else if (N == itsExceptionTable.length) {
ExceptionTableEntry[] tmp = new ExceptionTableEntry[N * 2];
System.arraycopy(itsExceptionTable, 0, tmp, 0, N);
itsExceptionTable = tmp;
}
itsExceptionTable[N] = newEntry;
itsExceptionTableTop = N + 1;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
public void addLineNumberEntry(short lineNumber) {
if (itsCurrentMethod == null)
throw new IllegalArgumentException("No method to stop");
int N = itsLineNumberTableTop;
if (N == 0) {
itsLineNumberTable = new int[LineNumberTableSize];
} else if (N == itsLineNumberTable.length) {
int[] tmp = new int[N * 2];
System.arraycopy(itsLineNumberTable, 0, tmp, 0, N);
itsLineNumberTable = tmp;
}
itsLineNumberTable[N] = (itsCodeBufferTop << 16) + lineNumber;
itsLineNumberTableTop = N + 1;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private SuperBlock getSuperBlockFromOffset(int offset) {
for (int i = 0; i < superBlocks.length; i++) {
SuperBlock sb = superBlocks[i];
if (sb == null) {
break;
} else if (offset >= sb.getStart() && offset < sb.getEnd()) {
return sb;
}
}
throw new IllegalArgumentException("bad offset: " + offset);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private int getOperand(int start, int size) {
int result = 0;
if (size > 4) {
throw new IllegalArgumentException("bad operand size");
}
for (int i = 0; i < size; i++) {
result = (result << 8) | (itsCodeBuffer[start + i] & 0xFF);
}
return result;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private int execute(int bci) {
int bc = itsCodeBuffer[bci] & 0xFF;
int type, type2, index;
int length = 0;
long lType, lType2;
String className;
switch (bc) {
case ByteCode.NOP:
case ByteCode.IINC:
case ByteCode.GOTO:
case ByteCode.GOTO_W:
// No change
break;
case ByteCode.CHECKCAST:
pop();
push(TypeInfo.OBJECT(getOperand(bci + 1, 2)));
break;
case ByteCode.IASTORE: // pop; pop; pop
case ByteCode.LASTORE:
case ByteCode.FASTORE:
case ByteCode.DASTORE:
case ByteCode.AASTORE:
case ByteCode.BASTORE:
case ByteCode.CASTORE:
case ByteCode.SASTORE:
pop();
case ByteCode.PUTFIELD: // pop; pop
case ByteCode.IF_ICMPEQ:
case ByteCode.IF_ICMPNE:
case ByteCode.IF_ICMPLT:
case ByteCode.IF_ICMPGE:
case ByteCode.IF_ICMPGT:
case ByteCode.IF_ICMPLE:
case ByteCode.IF_ACMPEQ:
case ByteCode.IF_ACMPNE:
pop();
case ByteCode.IFEQ: // pop
case ByteCode.IFNE:
case ByteCode.IFLT:
case ByteCode.IFGE:
case ByteCode.IFGT:
case ByteCode.IFLE:
case ByteCode.IFNULL:
case ByteCode.IFNONNULL:
case ByteCode.POP:
case ByteCode.MONITORENTER:
case ByteCode.MONITOREXIT:
case ByteCode.PUTSTATIC:
pop();
break;
case ByteCode.POP2:
pop2();
break;
case ByteCode.ACONST_NULL:
push(TypeInfo.NULL);
break;
case ByteCode.IALOAD: // pop; pop; push(INTEGER)
case ByteCode.BALOAD:
case ByteCode.CALOAD:
case ByteCode.SALOAD:
case ByteCode.IADD:
case ByteCode.ISUB:
case ByteCode.IMUL:
case ByteCode.IDIV:
case ByteCode.IREM:
case ByteCode.ISHL:
case ByteCode.ISHR:
case ByteCode.IUSHR:
case ByteCode.IAND:
case ByteCode.IOR:
case ByteCode.IXOR:
case ByteCode.LCMP:
case ByteCode.FCMPL:
case ByteCode.FCMPG:
case ByteCode.DCMPL:
case ByteCode.DCMPG:
pop();
case ByteCode.INEG: // pop; push(INTEGER)
case ByteCode.L2I:
case ByteCode.F2I:
case ByteCode.D2I:
case ByteCode.I2B:
case ByteCode.I2C:
case ByteCode.I2S:
case ByteCode.ARRAYLENGTH:
case ByteCode.INSTANCEOF:
pop();
case ByteCode.ICONST_M1: // push(INTEGER)
case ByteCode.ICONST_0:
case ByteCode.ICONST_1:
case ByteCode.ICONST_2:
case ByteCode.ICONST_3:
case ByteCode.ICONST_4:
case ByteCode.ICONST_5:
case ByteCode.ILOAD:
case ByteCode.ILOAD_0:
case ByteCode.ILOAD_1:
case ByteCode.ILOAD_2:
case ByteCode.ILOAD_3:
case ByteCode.BIPUSH:
case ByteCode.SIPUSH:
push(TypeInfo.INTEGER);
break;
case ByteCode.LALOAD: // pop; pop; push(LONG)
case ByteCode.LADD:
case ByteCode.LSUB:
case ByteCode.LMUL:
case ByteCode.LDIV:
case ByteCode.LREM:
case ByteCode.LSHL:
case ByteCode.LSHR:
case ByteCode.LUSHR:
case ByteCode.LAND:
case ByteCode.LOR:
case ByteCode.LXOR:
pop();
case ByteCode.LNEG: // pop; push(LONG)
case ByteCode.I2L:
case ByteCode.F2L:
case ByteCode.D2L:
pop();
case ByteCode.LCONST_0: // push(LONG)
case ByteCode.LCONST_1:
case ByteCode.LLOAD:
case ByteCode.LLOAD_0:
case ByteCode.LLOAD_1:
case ByteCode.LLOAD_2:
case ByteCode.LLOAD_3:
push(TypeInfo.LONG);
break;
case ByteCode.FALOAD: // pop; pop; push(FLOAT)
case ByteCode.FADD:
case ByteCode.FSUB:
case ByteCode.FMUL:
case ByteCode.FDIV:
case ByteCode.FREM:
pop();
case ByteCode.FNEG: // pop; push(FLOAT)
case ByteCode.I2F:
case ByteCode.L2F:
case ByteCode.D2F:
pop();
case ByteCode.FCONST_0: // push(FLOAT)
case ByteCode.FCONST_1:
case ByteCode.FCONST_2:
case ByteCode.FLOAD:
case ByteCode.FLOAD_0:
case ByteCode.FLOAD_1:
case ByteCode.FLOAD_2:
case ByteCode.FLOAD_3:
push(TypeInfo.FLOAT);
break;
case ByteCode.DALOAD: // pop; pop; push(DOUBLE)
case ByteCode.DADD:
case ByteCode.DSUB:
case ByteCode.DMUL:
case ByteCode.DDIV:
case ByteCode.DREM:
pop();
case ByteCode.DNEG: // pop; push(DOUBLE)
case ByteCode.I2D:
case ByteCode.L2D:
case ByteCode.F2D:
pop();
case ByteCode.DCONST_0: // push(DOUBLE)
case ByteCode.DCONST_1:
case ByteCode.DLOAD:
case ByteCode.DLOAD_0:
case ByteCode.DLOAD_1:
case ByteCode.DLOAD_2:
case ByteCode.DLOAD_3:
push(TypeInfo.DOUBLE);
break;
case ByteCode.ISTORE:
executeStore(getOperand(bci + 1, wide ? 2 : 1), TypeInfo.INTEGER);
break;
case ByteCode.ISTORE_0:
case ByteCode.ISTORE_1:
case ByteCode.ISTORE_2:
case ByteCode.ISTORE_3:
executeStore(bc - ByteCode.ISTORE_0, TypeInfo.INTEGER);
break;
case ByteCode.LSTORE:
executeStore(getOperand(bci + 1, wide ? 2 : 1), TypeInfo.LONG);
break;
case ByteCode.LSTORE_0:
case ByteCode.LSTORE_1:
case ByteCode.LSTORE_2:
case ByteCode.LSTORE_3:
executeStore(bc - ByteCode.LSTORE_0, TypeInfo.LONG);
break;
case ByteCode.FSTORE:
executeStore(getOperand(bci + 1, wide ? 2 : 1), TypeInfo.FLOAT);
break;
case ByteCode.FSTORE_0:
case ByteCode.FSTORE_1:
case ByteCode.FSTORE_2:
case ByteCode.FSTORE_3:
executeStore(bc - ByteCode.FSTORE_0, TypeInfo.FLOAT);
break;
case ByteCode.DSTORE:
executeStore(getOperand(bci + 1, wide ? 2 : 1), TypeInfo.DOUBLE);
break;
case ByteCode.DSTORE_0:
case ByteCode.DSTORE_1:
case ByteCode.DSTORE_2:
case ByteCode.DSTORE_3:
executeStore(bc - ByteCode.DSTORE_0, TypeInfo.DOUBLE);
break;
case ByteCode.ALOAD:
executeALoad(getOperand(bci + 1, wide ? 2 : 1));
break;
case ByteCode.ALOAD_0:
case ByteCode.ALOAD_1:
case ByteCode.ALOAD_2:
case ByteCode.ALOAD_3:
executeALoad(bc - ByteCode.ALOAD_0);
break;
case ByteCode.ASTORE:
executeAStore(getOperand(bci + 1, wide ? 2 : 1));
break;
case ByteCode.ASTORE_0:
case ByteCode.ASTORE_1:
case ByteCode.ASTORE_2:
case ByteCode.ASTORE_3:
executeAStore(bc - ByteCode.ASTORE_0);
break;
case ByteCode.IRETURN:
case ByteCode.LRETURN:
case ByteCode.FRETURN:
case ByteCode.DRETURN:
case ByteCode.ARETURN:
case ByteCode.RETURN:
clearStack();
break;
case ByteCode.ATHROW:
type = pop();
clearStack();
push(type);
break;
case ByteCode.SWAP:
type = pop();
type2 = pop();
push(type);
push(type2);
break;
case ByteCode.LDC:
case ByteCode.LDC_W:
case ByteCode.LDC2_W:
if (bc == ByteCode.LDC) {
index = getOperand(bci + 1);
} else {
index = getOperand(bci + 1, 2);
}
byte constType = itsConstantPool.getConstantType(index);
switch (constType) {
case ConstantPool.CONSTANT_Double:
push(TypeInfo.DOUBLE);
break;
case ConstantPool.CONSTANT_Float:
push(TypeInfo.FLOAT);
break;
case ConstantPool.CONSTANT_Long:
push(TypeInfo.LONG);
break;
case ConstantPool.CONSTANT_Integer:
push(TypeInfo.INTEGER);
break;
case ConstantPool.CONSTANT_String:
push(TypeInfo.OBJECT("java/lang/String",
itsConstantPool));
break;
default:
throw new IllegalArgumentException(
"bad const type " + constType);
}
break;
case ByteCode.NEW:
push(TypeInfo.UNINITIALIZED_VARIABLE(bci));
break;
case ByteCode.NEWARRAY:
pop();
char componentType =
arrayTypeToName(itsCodeBuffer[bci + 1]);
index = itsConstantPool.addClass("[" + componentType);
push(TypeInfo.OBJECT((short) index));
break;
case ByteCode.ANEWARRAY:
index = getOperand(bci + 1, 2);
className = (String) itsConstantPool.getConstantData(index);
pop();
push(TypeInfo.OBJECT("[L" + className + ';',
itsConstantPool));
break;
case ByteCode.INVOKEVIRTUAL:
case ByteCode.INVOKESPECIAL:
case ByteCode.INVOKESTATIC:
case ByteCode.INVOKEINTERFACE:
index = getOperand(bci + 1, 2);
FieldOrMethodRef m = (FieldOrMethodRef)
itsConstantPool.getConstantData(index);
String methodType = m.getType();
String methodName = m.getName();
int parameterCount = sizeOfParameters(methodType) >>> 16;
for (int i = 0; i < parameterCount; i++) {
pop();
}
if (bc != ByteCode.INVOKESTATIC) {
int instType = pop();
int tag = TypeInfo.getTag(instType);
if (tag == TypeInfo.UNINITIALIZED_VARIABLE(0) ||
tag == TypeInfo.UNINITIALIZED_THIS) {
if ("<init>".equals(methodName)) {
int newType =
TypeInfo.OBJECT(itsThisClassIndex);
initializeTypeInfo(instType, newType);
} else {
throw new IllegalStateException("bad instance");
}
}
}
int rParen = methodType.indexOf(')');
String returnType = methodType.substring(rParen + 1);
returnType = descriptorToInternalName(returnType);
if (!returnType.equals("V")) {
push(TypeInfo.fromType(returnType, itsConstantPool));
}
break;
case ByteCode.GETFIELD:
pop();
case ByteCode.GETSTATIC:
index = getOperand(bci + 1, 2);
FieldOrMethodRef f = (FieldOrMethodRef)
itsConstantPool.getConstantData(index);
String fieldType = descriptorToInternalName(f.getType());
push(TypeInfo.fromType(fieldType, itsConstantPool));
break;
case ByteCode.DUP:
type = pop();
push(type);
push(type);
break;
case ByteCode.DUP_X1:
type = pop();
type2 = pop();
push(type);
push(type2);
push(type);
break;
case ByteCode.DUP_X2:
type = pop();
lType = pop2();
push(type);
push2(lType);
push(type);
break;
case ByteCode.DUP2:
lType = pop2();
push2(lType);
push2(lType);
break;
case ByteCode.DUP2_X1:
lType = pop2();
type = pop();
push2(lType);
push(type);
push2(lType);
break;
case ByteCode.DUP2_X2:
lType = pop2();
lType2 = pop2();
push2(lType);
push2(lType2);
push2(lType);
break;
case ByteCode.TABLESWITCH:
int switchStart = bci + 1 + (3 & ~bci);
int low = getOperand(switchStart + 4, 4);
int high = getOperand(switchStart + 8, 4);
length = 4 * (high - low + 4) + switchStart - bci;
pop();
break;
case ByteCode.AALOAD:
pop();
int typeIndex = pop() >>> 8;
className =
(String) itsConstantPool.getConstantData(typeIndex);
String arrayType = className;
if (arrayType.charAt(0) != '[') {
throw new IllegalStateException("bad array type");
}
String elementDesc = arrayType.substring(1);
String elementType = descriptorToInternalName(elementDesc);
typeIndex = itsConstantPool.addClass(elementType);
push(TypeInfo.OBJECT(typeIndex));
break;
case ByteCode.WIDE:
// Alters behaviour of next instruction
wide = true;
break;
case ByteCode.MULTIANEWARRAY:
case ByteCode.LOOKUPSWITCH:
// Currently not used in any part of Rhino, so ignore it
case ByteCode.JSR: // TODO: JSR is deprecated
case ByteCode.RET:
case ByteCode.JSR_W:
default:
throw new IllegalArgumentException("bad opcode: " + bc);
}
if (length == 0) {
length = opcodeLength(bc, wide);
}
if (wide && bc != ByteCode.WIDE) {
wide = false;
}
return length;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private static char arrayTypeToName(int type) {
switch (type) {
case ByteCode.T_BOOLEAN:
return 'Z';
case ByteCode.T_CHAR:
return 'C';
case ByteCode.T_FLOAT:
return 'F';
case ByteCode.T_DOUBLE:
return 'D';
case ByteCode.T_BYTE:
return 'B';
case ByteCode.T_SHORT:
return 'S';
case ByteCode.T_INT:
return 'I';
case ByteCode.T_LONG:
return 'J';
default:
throw new IllegalArgumentException("bad operand");
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private static String descriptorToInternalName(String descriptor) {
switch (descriptor.charAt(0)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
case 'V':
case '[':
return descriptor;
case 'L':
return classDescriptorToInternalName(descriptor);
default:
throw new IllegalArgumentException("bad descriptor:" +
descriptor);
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private int[] createInitialLocals() {
int[] initialLocals = new int[itsMaxLocals];
int localsTop = 0;
// Instance methods require the first local variable in the array
// to be "this". However, if the method being created is a
// constructor, aka the method is <init>, then the type of "this"
// should be StackMapTable.UNINITIALIZED_THIS
if ((itsCurrentMethod.getFlags() & ACC_STATIC) == 0) {
if ("<init>".equals(itsCurrentMethod.getName())) {
initialLocals[localsTop++] = TypeInfo.UNINITIALIZED_THIS;
} else {
initialLocals[localsTop++] = TypeInfo.OBJECT(itsThisClassIndex);
}
}
// No error checking should be necessary, sizeOfParameters does this
String type = itsCurrentMethod.getType();
int lParenIndex = type.indexOf('(');
int rParenIndex = type.indexOf(')');
if (lParenIndex != 0 || rParenIndex < 0) {
throw new IllegalArgumentException("bad method type");
}
int start = lParenIndex + 1;
StringBuilder paramType = new StringBuilder();
while (start < rParenIndex) {
switch (type.charAt(start)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
paramType.append(type.charAt(start));
++start;
break;
case 'L':
int end = type.indexOf(';', start) + 1;
String name = type.substring(start, end);
paramType.append(name);
start = end;
break;
case '[':
paramType.append('[');
++start;
continue;
}
String internalType =
descriptorToInternalName(paramType.toString());
int typeInfo = TypeInfo.fromType(internalType, itsConstantPool);
initialLocals[localsTop++] = typeInfo;
if (TypeInfo.isTwoWords(typeInfo)) {
localsTop++;
}
paramType.setLength(0);
}
return initialLocals;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
private static int sizeOfParameters(String pString)
{
int length = pString.length();
int rightParenthesis = pString.lastIndexOf(')');
if (3 <= length /* minimal signature takes at least 3 chars: ()V */
&& pString.charAt(0) == '('
&& 1 <= rightParenthesis && rightParenthesis + 1 < length)
{
boolean ok = true;
int index = 1;
int stackDiff = 0;
int count = 0;
stringLoop:
while (index != rightParenthesis) {
switch (pString.charAt(index)) {
default:
ok = false;
break stringLoop;
case 'J' :
case 'D' :
--stackDiff;
// fall thru
case 'B' :
case 'S' :
case 'C' :
case 'I' :
case 'Z' :
case 'F' :
--stackDiff;
++count;
++index;
continue;
case '[' :
++index;
int c = pString.charAt(index);
while (c == '[') {
++index;
c = pString.charAt(index);
}
switch (c) {
default:
ok = false;
break stringLoop;
case 'J' :
case 'D' :
case 'B' :
case 'S' :
case 'C' :
case 'I' :
case 'Z' :
case 'F' :
--stackDiff;
++count;
++index;
continue;
case 'L':
// fall thru
}
// fall thru
case 'L' : {
--stackDiff;
++count;
++index;
int semicolon = pString.indexOf(';', index);
if (!(index + 1 <= semicolon
&& semicolon < rightParenthesis))
{
ok = false;
break stringLoop;
}
index = semicolon + 1;
continue;
}
}
}
if (ok) {
switch (pString.charAt(rightParenthesis + 1)) {
default:
ok = false;
break;
case 'J' :
case 'D' :
++stackDiff;
// fall thru
case 'B' :
case 'S' :
case 'C' :
case 'I' :
case 'Z' :
case 'F' :
case 'L' :
case '[' :
++stackDiff;
// fall thru
case 'V' :
break;
}
if (ok) {
return ((count << 16) | (0xFFFF & stackDiff));
}
}
}
throw new IllegalArgumentException(
"Bad parameter signature: "+pString);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static int opcodeLength(int opcode, boolean wide) {
switch (opcode) {
case ByteCode.AALOAD:
case ByteCode.AASTORE:
case ByteCode.ACONST_NULL:
case ByteCode.ALOAD_0:
case ByteCode.ALOAD_1:
case ByteCode.ALOAD_2:
case ByteCode.ALOAD_3:
case ByteCode.ARETURN:
case ByteCode.ARRAYLENGTH:
case ByteCode.ASTORE_0:
case ByteCode.ASTORE_1:
case ByteCode.ASTORE_2:
case ByteCode.ASTORE_3:
case ByteCode.ATHROW:
case ByteCode.BALOAD:
case ByteCode.BASTORE:
case ByteCode.BREAKPOINT:
case ByteCode.CALOAD:
case ByteCode.CASTORE:
case ByteCode.D2F:
case ByteCode.D2I:
case ByteCode.D2L:
case ByteCode.DADD:
case ByteCode.DALOAD:
case ByteCode.DASTORE:
case ByteCode.DCMPG:
case ByteCode.DCMPL:
case ByteCode.DCONST_0:
case ByteCode.DCONST_1:
case ByteCode.DDIV:
case ByteCode.DLOAD_0:
case ByteCode.DLOAD_1:
case ByteCode.DLOAD_2:
case ByteCode.DLOAD_3:
case ByteCode.DMUL:
case ByteCode.DNEG:
case ByteCode.DREM:
case ByteCode.DRETURN:
case ByteCode.DSTORE_0:
case ByteCode.DSTORE_1:
case ByteCode.DSTORE_2:
case ByteCode.DSTORE_3:
case ByteCode.DSUB:
case ByteCode.DUP:
case ByteCode.DUP2:
case ByteCode.DUP2_X1:
case ByteCode.DUP2_X2:
case ByteCode.DUP_X1:
case ByteCode.DUP_X2:
case ByteCode.F2D:
case ByteCode.F2I:
case ByteCode.F2L:
case ByteCode.FADD:
case ByteCode.FALOAD:
case ByteCode.FASTORE:
case ByteCode.FCMPG:
case ByteCode.FCMPL:
case ByteCode.FCONST_0:
case ByteCode.FCONST_1:
case ByteCode.FCONST_2:
case ByteCode.FDIV:
case ByteCode.FLOAD_0:
case ByteCode.FLOAD_1:
case ByteCode.FLOAD_2:
case ByteCode.FLOAD_3:
case ByteCode.FMUL:
case ByteCode.FNEG:
case ByteCode.FREM:
case ByteCode.FRETURN:
case ByteCode.FSTORE_0:
case ByteCode.FSTORE_1:
case ByteCode.FSTORE_2:
case ByteCode.FSTORE_3:
case ByteCode.FSUB:
case ByteCode.I2B:
case ByteCode.I2C:
case ByteCode.I2D:
case ByteCode.I2F:
case ByteCode.I2L:
case ByteCode.I2S:
case ByteCode.IADD:
case ByteCode.IALOAD:
case ByteCode.IAND:
case ByteCode.IASTORE:
case ByteCode.ICONST_0:
case ByteCode.ICONST_1:
case ByteCode.ICONST_2:
case ByteCode.ICONST_3:
case ByteCode.ICONST_4:
case ByteCode.ICONST_5:
case ByteCode.ICONST_M1:
case ByteCode.IDIV:
case ByteCode.ILOAD_0:
case ByteCode.ILOAD_1:
case ByteCode.ILOAD_2:
case ByteCode.ILOAD_3:
case ByteCode.IMPDEP1:
case ByteCode.IMPDEP2:
case ByteCode.IMUL:
case ByteCode.INEG:
case ByteCode.IOR:
case ByteCode.IREM:
case ByteCode.IRETURN:
case ByteCode.ISHL:
case ByteCode.ISHR:
case ByteCode.ISTORE_0:
case ByteCode.ISTORE_1:
case ByteCode.ISTORE_2:
case ByteCode.ISTORE_3:
case ByteCode.ISUB:
case ByteCode.IUSHR:
case ByteCode.IXOR:
case ByteCode.L2D:
case ByteCode.L2F:
case ByteCode.L2I:
case ByteCode.LADD:
case ByteCode.LALOAD:
case ByteCode.LAND:
case ByteCode.LASTORE:
case ByteCode.LCMP:
case ByteCode.LCONST_0:
case ByteCode.LCONST_1:
case ByteCode.LDIV:
case ByteCode.LLOAD_0:
case ByteCode.LLOAD_1:
case ByteCode.LLOAD_2:
case ByteCode.LLOAD_3:
case ByteCode.LMUL:
case ByteCode.LNEG:
case ByteCode.LOR:
case ByteCode.LREM:
case ByteCode.LRETURN:
case ByteCode.LSHL:
case ByteCode.LSHR:
case ByteCode.LSTORE_0:
case ByteCode.LSTORE_1:
case ByteCode.LSTORE_2:
case ByteCode.LSTORE_3:
case ByteCode.LSUB:
case ByteCode.LUSHR:
case ByteCode.LXOR:
case ByteCode.MONITORENTER:
case ByteCode.MONITOREXIT:
case ByteCode.NOP:
case ByteCode.POP:
case ByteCode.POP2:
case ByteCode.RETURN:
case ByteCode.SALOAD:
case ByteCode.SASTORE:
case ByteCode.SWAP:
case ByteCode.WIDE:
return 1;
case ByteCode.BIPUSH:
case ByteCode.LDC:
case ByteCode.NEWARRAY:
return 2;
case ByteCode.ALOAD:
case ByteCode.ASTORE:
case ByteCode.DLOAD:
case ByteCode.DSTORE:
case ByteCode.FLOAD:
case ByteCode.FSTORE:
case ByteCode.ILOAD:
case ByteCode.ISTORE:
case ByteCode.LLOAD:
case ByteCode.LSTORE:
case ByteCode.RET:
return wide ? 3 : 2;
case ByteCode.ANEWARRAY:
case ByteCode.CHECKCAST:
case ByteCode.GETFIELD:
case ByteCode.GETSTATIC:
case ByteCode.GOTO:
case ByteCode.IFEQ:
case ByteCode.IFGE:
case ByteCode.IFGT:
case ByteCode.IFLE:
case ByteCode.IFLT:
case ByteCode.IFNE:
case ByteCode.IFNONNULL:
case ByteCode.IFNULL:
case ByteCode.IF_ACMPEQ:
case ByteCode.IF_ACMPNE:
case ByteCode.IF_ICMPEQ:
case ByteCode.IF_ICMPGE:
case ByteCode.IF_ICMPGT:
case ByteCode.IF_ICMPLE:
case ByteCode.IF_ICMPLT:
case ByteCode.IF_ICMPNE:
case ByteCode.INSTANCEOF:
case ByteCode.INVOKESPECIAL:
case ByteCode.INVOKESTATIC:
case ByteCode.INVOKEVIRTUAL:
case ByteCode.JSR:
case ByteCode.LDC_W:
case ByteCode.LDC2_W:
case ByteCode.NEW:
case ByteCode.PUTFIELD:
case ByteCode.PUTSTATIC:
case ByteCode.SIPUSH:
return 3;
case ByteCode.IINC:
return wide ? 5 : 3;
case ByteCode.MULTIANEWARRAY:
return 4;
case ByteCode.GOTO_W:
case ByteCode.INVOKEINTERFACE:
case ByteCode.JSR_W:
return 5;
/*
case ByteCode.LOOKUPSWITCH:
case ByteCode.TABLESWITCH:
return -1;
*/
}
throw new IllegalArgumentException("Bad opcode: " + opcode);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static int opcodeCount(int opcode)
{
switch (opcode) {
case ByteCode.AALOAD:
case ByteCode.AASTORE:
case ByteCode.ACONST_NULL:
case ByteCode.ALOAD_0:
case ByteCode.ALOAD_1:
case ByteCode.ALOAD_2:
case ByteCode.ALOAD_3:
case ByteCode.ARETURN:
case ByteCode.ARRAYLENGTH:
case ByteCode.ASTORE_0:
case ByteCode.ASTORE_1:
case ByteCode.ASTORE_2:
case ByteCode.ASTORE_3:
case ByteCode.ATHROW:
case ByteCode.BALOAD:
case ByteCode.BASTORE:
case ByteCode.BREAKPOINT:
case ByteCode.CALOAD:
case ByteCode.CASTORE:
case ByteCode.D2F:
case ByteCode.D2I:
case ByteCode.D2L:
case ByteCode.DADD:
case ByteCode.DALOAD:
case ByteCode.DASTORE:
case ByteCode.DCMPG:
case ByteCode.DCMPL:
case ByteCode.DCONST_0:
case ByteCode.DCONST_1:
case ByteCode.DDIV:
case ByteCode.DLOAD_0:
case ByteCode.DLOAD_1:
case ByteCode.DLOAD_2:
case ByteCode.DLOAD_3:
case ByteCode.DMUL:
case ByteCode.DNEG:
case ByteCode.DREM:
case ByteCode.DRETURN:
case ByteCode.DSTORE_0:
case ByteCode.DSTORE_1:
case ByteCode.DSTORE_2:
case ByteCode.DSTORE_3:
case ByteCode.DSUB:
case ByteCode.DUP:
case ByteCode.DUP2:
case ByteCode.DUP2_X1:
case ByteCode.DUP2_X2:
case ByteCode.DUP_X1:
case ByteCode.DUP_X2:
case ByteCode.F2D:
case ByteCode.F2I:
case ByteCode.F2L:
case ByteCode.FADD:
case ByteCode.FALOAD:
case ByteCode.FASTORE:
case ByteCode.FCMPG:
case ByteCode.FCMPL:
case ByteCode.FCONST_0:
case ByteCode.FCONST_1:
case ByteCode.FCONST_2:
case ByteCode.FDIV:
case ByteCode.FLOAD_0:
case ByteCode.FLOAD_1:
case ByteCode.FLOAD_2:
case ByteCode.FLOAD_3:
case ByteCode.FMUL:
case ByteCode.FNEG:
case ByteCode.FREM:
case ByteCode.FRETURN:
case ByteCode.FSTORE_0:
case ByteCode.FSTORE_1:
case ByteCode.FSTORE_2:
case ByteCode.FSTORE_3:
case ByteCode.FSUB:
case ByteCode.I2B:
case ByteCode.I2C:
case ByteCode.I2D:
case ByteCode.I2F:
case ByteCode.I2L:
case ByteCode.I2S:
case ByteCode.IADD:
case ByteCode.IALOAD:
case ByteCode.IAND:
case ByteCode.IASTORE:
case ByteCode.ICONST_0:
case ByteCode.ICONST_1:
case ByteCode.ICONST_2:
case ByteCode.ICONST_3:
case ByteCode.ICONST_4:
case ByteCode.ICONST_5:
case ByteCode.ICONST_M1:
case ByteCode.IDIV:
case ByteCode.ILOAD_0:
case ByteCode.ILOAD_1:
case ByteCode.ILOAD_2:
case ByteCode.ILOAD_3:
case ByteCode.IMPDEP1:
case ByteCode.IMPDEP2:
case ByteCode.IMUL:
case ByteCode.INEG:
case ByteCode.IOR:
case ByteCode.IREM:
case ByteCode.IRETURN:
case ByteCode.ISHL:
case ByteCode.ISHR:
case ByteCode.ISTORE_0:
case ByteCode.ISTORE_1:
case ByteCode.ISTORE_2:
case ByteCode.ISTORE_3:
case ByteCode.ISUB:
case ByteCode.IUSHR:
case ByteCode.IXOR:
case ByteCode.L2D:
case ByteCode.L2F:
case ByteCode.L2I:
case ByteCode.LADD:
case ByteCode.LALOAD:
case ByteCode.LAND:
case ByteCode.LASTORE:
case ByteCode.LCMP:
case ByteCode.LCONST_0:
case ByteCode.LCONST_1:
case ByteCode.LDIV:
case ByteCode.LLOAD_0:
case ByteCode.LLOAD_1:
case ByteCode.LLOAD_2:
case ByteCode.LLOAD_3:
case ByteCode.LMUL:
case ByteCode.LNEG:
case ByteCode.LOR:
case ByteCode.LREM:
case ByteCode.LRETURN:
case ByteCode.LSHL:
case ByteCode.LSHR:
case ByteCode.LSTORE_0:
case ByteCode.LSTORE_1:
case ByteCode.LSTORE_2:
case ByteCode.LSTORE_3:
case ByteCode.LSUB:
case ByteCode.LUSHR:
case ByteCode.LXOR:
case ByteCode.MONITORENTER:
case ByteCode.MONITOREXIT:
case ByteCode.NOP:
case ByteCode.POP:
case ByteCode.POP2:
case ByteCode.RETURN:
case ByteCode.SALOAD:
case ByteCode.SASTORE:
case ByteCode.SWAP:
case ByteCode.WIDE:
return 0;
case ByteCode.ALOAD:
case ByteCode.ANEWARRAY:
case ByteCode.ASTORE:
case ByteCode.BIPUSH:
case ByteCode.CHECKCAST:
case ByteCode.DLOAD:
case ByteCode.DSTORE:
case ByteCode.FLOAD:
case ByteCode.FSTORE:
case ByteCode.GETFIELD:
case ByteCode.GETSTATIC:
case ByteCode.GOTO:
case ByteCode.GOTO_W:
case ByteCode.IFEQ:
case ByteCode.IFGE:
case ByteCode.IFGT:
case ByteCode.IFLE:
case ByteCode.IFLT:
case ByteCode.IFNE:
case ByteCode.IFNONNULL:
case ByteCode.IFNULL:
case ByteCode.IF_ACMPEQ:
case ByteCode.IF_ACMPNE:
case ByteCode.IF_ICMPEQ:
case ByteCode.IF_ICMPGE:
case ByteCode.IF_ICMPGT:
case ByteCode.IF_ICMPLE:
case ByteCode.IF_ICMPLT:
case ByteCode.IF_ICMPNE:
case ByteCode.ILOAD:
case ByteCode.INSTANCEOF:
case ByteCode.INVOKEINTERFACE:
case ByteCode.INVOKESPECIAL:
case ByteCode.INVOKESTATIC:
case ByteCode.INVOKEVIRTUAL:
case ByteCode.ISTORE:
case ByteCode.JSR:
case ByteCode.JSR_W:
case ByteCode.LDC:
case ByteCode.LDC2_W:
case ByteCode.LDC_W:
case ByteCode.LLOAD:
case ByteCode.LSTORE:
case ByteCode.NEW:
case ByteCode.NEWARRAY:
case ByteCode.PUTFIELD:
case ByteCode.PUTSTATIC:
case ByteCode.RET:
case ByteCode.SIPUSH:
return 1;
case ByteCode.IINC:
case ByteCode.MULTIANEWARRAY:
return 2;
case ByteCode.LOOKUPSWITCH:
case ByteCode.TABLESWITCH:
return -1;
}
throw new IllegalArgumentException("Bad opcode: "+opcode);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static int stackChange(int opcode)
{
// For INVOKE... accounts only for popping this (unless static),
// ignoring parameters and return type
switch (opcode) {
case ByteCode.DASTORE:
case ByteCode.LASTORE:
return -4;
case ByteCode.AASTORE:
case ByteCode.BASTORE:
case ByteCode.CASTORE:
case ByteCode.DCMPG:
case ByteCode.DCMPL:
case ByteCode.FASTORE:
case ByteCode.IASTORE:
case ByteCode.LCMP:
case ByteCode.SASTORE:
return -3;
case ByteCode.DADD:
case ByteCode.DDIV:
case ByteCode.DMUL:
case ByteCode.DREM:
case ByteCode.DRETURN:
case ByteCode.DSTORE:
case ByteCode.DSTORE_0:
case ByteCode.DSTORE_1:
case ByteCode.DSTORE_2:
case ByteCode.DSTORE_3:
case ByteCode.DSUB:
case ByteCode.IF_ACMPEQ:
case ByteCode.IF_ACMPNE:
case ByteCode.IF_ICMPEQ:
case ByteCode.IF_ICMPGE:
case ByteCode.IF_ICMPGT:
case ByteCode.IF_ICMPLE:
case ByteCode.IF_ICMPLT:
case ByteCode.IF_ICMPNE:
case ByteCode.LADD:
case ByteCode.LAND:
case ByteCode.LDIV:
case ByteCode.LMUL:
case ByteCode.LOR:
case ByteCode.LREM:
case ByteCode.LRETURN:
case ByteCode.LSTORE:
case ByteCode.LSTORE_0:
case ByteCode.LSTORE_1:
case ByteCode.LSTORE_2:
case ByteCode.LSTORE_3:
case ByteCode.LSUB:
case ByteCode.LXOR:
case ByteCode.POP2:
return -2;
case ByteCode.AALOAD:
case ByteCode.ARETURN:
case ByteCode.ASTORE:
case ByteCode.ASTORE_0:
case ByteCode.ASTORE_1:
case ByteCode.ASTORE_2:
case ByteCode.ASTORE_3:
case ByteCode.ATHROW:
case ByteCode.BALOAD:
case ByteCode.CALOAD:
case ByteCode.D2F:
case ByteCode.D2I:
case ByteCode.FADD:
case ByteCode.FALOAD:
case ByteCode.FCMPG:
case ByteCode.FCMPL:
case ByteCode.FDIV:
case ByteCode.FMUL:
case ByteCode.FREM:
case ByteCode.FRETURN:
case ByteCode.FSTORE:
case ByteCode.FSTORE_0:
case ByteCode.FSTORE_1:
case ByteCode.FSTORE_2:
case ByteCode.FSTORE_3:
case ByteCode.FSUB:
case ByteCode.GETFIELD:
case ByteCode.IADD:
case ByteCode.IALOAD:
case ByteCode.IAND:
case ByteCode.IDIV:
case ByteCode.IFEQ:
case ByteCode.IFGE:
case ByteCode.IFGT:
case ByteCode.IFLE:
case ByteCode.IFLT:
case ByteCode.IFNE:
case ByteCode.IFNONNULL:
case ByteCode.IFNULL:
case ByteCode.IMUL:
case ByteCode.INVOKEINTERFACE: //
case ByteCode.INVOKESPECIAL: // but needs to account for
case ByteCode.INVOKEVIRTUAL: // pops 'this' (unless static)
case ByteCode.IOR:
case ByteCode.IREM:
case ByteCode.IRETURN:
case ByteCode.ISHL:
case ByteCode.ISHR:
case ByteCode.ISTORE:
case ByteCode.ISTORE_0:
case ByteCode.ISTORE_1:
case ByteCode.ISTORE_2:
case ByteCode.ISTORE_3:
case ByteCode.ISUB:
case ByteCode.IUSHR:
case ByteCode.IXOR:
case ByteCode.L2F:
case ByteCode.L2I:
case ByteCode.LOOKUPSWITCH:
case ByteCode.LSHL:
case ByteCode.LSHR:
case ByteCode.LUSHR:
case ByteCode.MONITORENTER:
case ByteCode.MONITOREXIT:
case ByteCode.POP:
case ByteCode.PUTFIELD:
case ByteCode.SALOAD:
case ByteCode.TABLESWITCH:
return -1;
case ByteCode.ANEWARRAY:
case ByteCode.ARRAYLENGTH:
case ByteCode.BREAKPOINT:
case ByteCode.CHECKCAST:
case ByteCode.D2L:
case ByteCode.DALOAD:
case ByteCode.DNEG:
case ByteCode.F2I:
case ByteCode.FNEG:
case ByteCode.GETSTATIC:
case ByteCode.GOTO:
case ByteCode.GOTO_W:
case ByteCode.I2B:
case ByteCode.I2C:
case ByteCode.I2F:
case ByteCode.I2S:
case ByteCode.IINC:
case ByteCode.IMPDEP1:
case ByteCode.IMPDEP2:
case ByteCode.INEG:
case ByteCode.INSTANCEOF:
case ByteCode.INVOKESTATIC:
case ByteCode.L2D:
case ByteCode.LALOAD:
case ByteCode.LNEG:
case ByteCode.NEWARRAY:
case ByteCode.NOP:
case ByteCode.PUTSTATIC:
case ByteCode.RET:
case ByteCode.RETURN:
case ByteCode.SWAP:
case ByteCode.WIDE:
return 0;
case ByteCode.ACONST_NULL:
case ByteCode.ALOAD:
case ByteCode.ALOAD_0:
case ByteCode.ALOAD_1:
case ByteCode.ALOAD_2:
case ByteCode.ALOAD_3:
case ByteCode.BIPUSH:
case ByteCode.DUP:
case ByteCode.DUP_X1:
case ByteCode.DUP_X2:
case ByteCode.F2D:
case ByteCode.F2L:
case ByteCode.FCONST_0:
case ByteCode.FCONST_1:
case ByteCode.FCONST_2:
case ByteCode.FLOAD:
case ByteCode.FLOAD_0:
case ByteCode.FLOAD_1:
case ByteCode.FLOAD_2:
case ByteCode.FLOAD_3:
case ByteCode.I2D:
case ByteCode.I2L:
case ByteCode.ICONST_0:
case ByteCode.ICONST_1:
case ByteCode.ICONST_2:
case ByteCode.ICONST_3:
case ByteCode.ICONST_4:
case ByteCode.ICONST_5:
case ByteCode.ICONST_M1:
case ByteCode.ILOAD:
case ByteCode.ILOAD_0:
case ByteCode.ILOAD_1:
case ByteCode.ILOAD_2:
case ByteCode.ILOAD_3:
case ByteCode.JSR:
case ByteCode.JSR_W:
case ByteCode.LDC:
case ByteCode.LDC_W:
case ByteCode.MULTIANEWARRAY:
case ByteCode.NEW:
case ByteCode.SIPUSH:
return 1;
case ByteCode.DCONST_0:
case ByteCode.DCONST_1:
case ByteCode.DLOAD:
case ByteCode.DLOAD_0:
case ByteCode.DLOAD_1:
case ByteCode.DLOAD_2:
case ByteCode.DLOAD_3:
case ByteCode.DUP2:
case ByteCode.DUP2_X1:
case ByteCode.DUP2_X2:
case ByteCode.LCONST_0:
case ByteCode.LCONST_1:
case ByteCode.LDC2_W:
case ByteCode.LLOAD:
case ByteCode.LLOAD_0:
case ByteCode.LLOAD_1:
case ByteCode.LLOAD_2:
case ByteCode.LLOAD_3:
return 2;
}
throw new IllegalArgumentException("Bad opcode: "+opcode);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
short addUtf8(String k)
{
int theIndex = itsUtf8Hash.get(k, -1);
if (theIndex == -1) {
int strLen = k.length();
boolean tooBigString;
if (strLen > MAX_UTF_ENCODING_SIZE) {
tooBigString = true;
} else {
tooBigString = false;
// Ask for worst case scenario buffer when each char takes 3
// bytes
ensure(1 + 2 + strLen * 3);
int top = itsTop;
itsPool[top++] = CONSTANT_Utf8;
top += 2; // skip length
char[] chars = cfw.getCharBuffer(strLen);
k.getChars(0, strLen, chars, 0);
for (int i = 0; i != strLen; i++) {
int c = chars[i];
if (c != 0 && c <= 0x7F) {
itsPool[top++] = (byte)c;
} else if (c > 0x7FF) {
itsPool[top++] = (byte)(0xE0 | (c >> 12));
itsPool[top++] = (byte)(0x80 | ((c >> 6) & 0x3F));
itsPool[top++] = (byte)(0x80 | (c & 0x3F));
} else {
itsPool[top++] = (byte)(0xC0 | (c >> 6));
itsPool[top++] = (byte)(0x80 | (c & 0x3F));
}
}
int utfLen = top - (itsTop + 1 + 2);
if (utfLen > MAX_UTF_ENCODING_SIZE) {
tooBigString = true;
} else {
// Write back length
itsPool[itsTop + 1] = (byte)(utfLen >>> 8);
itsPool[itsTop + 2] = (byte)utfLen;
itsTop = top;
theIndex = itsTopIndex++;
itsUtf8Hash.put(k, theIndex);
}
}
if (tooBigString) {
throw new IllegalArgumentException("Too big string");
}
}
setConstantData(theIndex, k);
itsPoolTypes.put(theIndex, CONSTANT_Utf8);
return (short)theIndex;
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
boolean merge(int[] locals, int localsTop, int[] stack, int stackTop,
ConstantPool pool) {
if (!isInitialized) {
System.arraycopy(locals, 0, this.locals, 0, localsTop);
this.stack = new int[stackTop];
System.arraycopy(stack, 0, this.stack, 0, stackTop);
isInitialized = true;
return true;
} else if (this.locals.length == localsTop &&
this.stack.length == stackTop) {
boolean localsChanged = mergeState(this.locals, locals, localsTop,
pool);
boolean stackChanged = mergeState(this.stack, stack, stackTop,
pool);
return localsChanged || stackChanged;
} else {
if (ClassFileWriter.StackMapTable.DEBUGSTACKMAP) {
System.out.println("bad merge");
System.out.println("current type state:");
TypeInfo.print(this.locals, this.stack, pool);
System.out.println("incoming type state:");
TypeInfo.print(locals, localsTop, stack, stackTop, pool);
}
throw new IllegalArgumentException("bad merge attempt");
}
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static final String getPayloadAsType(int typeInfo, ConstantPool pool) {
if (getTag(typeInfo) == OBJECT_TAG) {
return (String) pool.getConstantData(getPayload(typeInfo));
}
throw new IllegalArgumentException("expecting object type");
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static final int fromType(String type, ConstantPool pool) {
if (type.length() == 1) {
switch (type.charAt(0)) {
case 'B': // sbyte
case 'C': // unicode char
case 'S': // short
case 'Z': // boolean
case 'I': // all of the above are verified as integers
return INTEGER;
case 'D':
return DOUBLE;
case 'F':
return FLOAT;
case 'J':
return LONG;
default:
throw new IllegalArgumentException("bad type");
}
}
return TypeInfo.OBJECT(type, pool);
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static int merge(int current, int incoming, ConstantPool pool) {
int currentTag = getTag(current);
int incomingTag = getTag(incoming);
boolean currentIsObject = currentTag == TypeInfo.OBJECT_TAG;
boolean incomingIsObject = incomingTag == TypeInfo.OBJECT_TAG;
if (current == incoming || (currentIsObject && incoming == NULL)) {
return current;
} else if (currentTag == TypeInfo.TOP ||
incomingTag == TypeInfo.TOP) {
return TypeInfo.TOP;
} else if (current == NULL && incomingIsObject) {
return incoming;
} else if (currentIsObject && incomingIsObject) {
String currentName = getPayloadAsType(current, pool);
String incomingName = getPayloadAsType(incoming, pool);
// The class file always has the class and super names in the same
// spot. The constant order is: class_data, class_name, super_data,
// super_name.
String currentlyGeneratedName = (String) pool.getConstantData(2);
String currentlyGeneratedSuperName =
(String) pool.getConstantData(4);
// If any of the merged types are the class that's currently being
// generated, automatically start at the super class instead. At
// this point, we already know the classes are different, so we
// don't need to handle that case.
if (currentName.equals(currentlyGeneratedName)) {
currentName = currentlyGeneratedSuperName;
}
if (incomingName.equals(currentlyGeneratedName)) {
incomingName = currentlyGeneratedSuperName;
}
Class<?> currentClass = getClassFromInternalName(currentName);
Class<?> incomingClass = getClassFromInternalName(incomingName);
if (currentClass.isAssignableFrom(incomingClass)) {
return current;
} else if (incomingClass.isAssignableFrom(currentClass)) {
return incoming;
} else if (incomingClass.isInterface() ||
currentClass.isInterface()) {
// For verification purposes, Sun specifies that interfaces are
// subtypes of Object. Therefore, we know that the merge result
// involving interfaces where one is not assignable to the
// other results in Object.
return OBJECT("java/lang/Object", pool);
} else {
Class<?> commonClass = incomingClass.getSuperclass();
while (commonClass != null) {
if (commonClass.isAssignableFrom(currentClass)) {
String name = commonClass.getName();
name = ClassFileWriter.getSlashedForm(name);
return OBJECT(name, pool);
}
commonClass = commonClass.getSuperclass();
}
}
}
throw new IllegalArgumentException("bad merge attempt between " +
toString(current, pool) + " and " +
toString(incoming, pool));
}
// in /home/martin-no-backup/testoss/rhino/src/org/mozilla/classfile/ClassFileWriter.java
static String toString(int type, ConstantPool pool) {
int tag = getTag(type);
switch (tag) {
case TypeInfo.TOP:
return "top";
case TypeInfo.INTEGER:
return "int";
case TypeInfo.FLOAT:
return "float";
case TypeInfo.DOUBLE:
return "double";
case TypeInfo.LONG:
return "long";
case TypeInfo.NULL:
return "null";
case TypeInfo.UNINITIALIZED_THIS:
return "uninitialized_this";
default:
if (tag == TypeInfo.OBJECT_TAG) {
return getPayloadAsType(type, pool);
} else if (tag == TypeInfo.UNINITIALIZED_VAR_TAG) {
return "uninitialized";
} else {
throw new IllegalArgumentException("bad type");
}
}
}