pass ClassInfo instead of class name to getMethod

This commit is contained in:
Andreas Gal 2014-07-13 18:50:53 -07:00
Родитель 0e899fbc7e
Коммит fd1d46cb7f
2 изменённых файлов: 7 добавлений и 7 удалений

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

@ -89,7 +89,7 @@ Classes.prototype.getClass = function(caller, className) {
return this.getArrayClass(caller, className); return this.getArrayClass(caller, className);
if (!!(classInfo = this.loadClassFile(className + ".class"))) { if (!!(classInfo = this.loadClassFile(className + ".class"))) {
classInfo.staticFields = {}; classInfo.staticFields = {};
var clinit = this.getMethod(caller, className, "<clinit>", "()V", true); var clinit = this.getMethod(caller, classInfo, "<clinit>", "()V", true);
if (clinit) if (clinit)
caller.invoke(clinit); caller.invoke(clinit);
classInfo.constructor = function () { classInfo.constructor = function () {
@ -128,10 +128,8 @@ Classes.prototype.setStaticField = function(caller, className, fieldName, value)
this.getClass(caller, className).staticFields[fieldName] = value; this.getClass(caller, className).staticFields[fieldName] = value;
} }
Classes.prototype.getMethod = function(caller, className, methodName, signature, staticFlag) { Classes.prototype.getMethod = function(caller, classInfo, methodName, signature, staticFlag) {
console.log(className, methodName, signature); console.log(classInfo.className, methodName, signature);
// Only force initialization when accessing a static method.
var classInfo = this.getClass(caller, className);
var methods = classInfo.methods; var methods = classInfo.methods;
for (var i=0; i<methods.length; i++) { for (var i=0; i<methods.length; i++) {
if (ACCESS_FLAGS.isStatic(methods[i].access_flags) === !!staticFlag) { if (ACCESS_FLAGS.isStatic(methods[i].access_flags) === !!staticFlag) {

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

@ -98,7 +98,7 @@ Frame.prototype.throw = function(ex) {
Frame.prototype.raiseException = function(className, message) { Frame.prototype.raiseException = function(className, message) {
var ex = CLASSES.newObject(this, className); var ex = CLASSES.newObject(this, className);
var ctor = CLASSES.getMethod(this, className, "<init>", "(Ljava/lang/String;)V", false); var ctor = CLASSES.getMethod(this, ex.class, "<init>", "(Ljava/lang/String;)V", false);
this.stack.push(ex); this.stack.push(ex);
this.stack.push(message); this.stack.push(message);
this.invoke(ctor); this.invoke(ctor);
@ -983,11 +983,13 @@ Frame.prototype.invokestatic = Frame.prototype.invokevirtual = Frame.prototype.i
} }
var cp = this.cp; var cp = this.cp;
var className = cp[cp[cp[idx].class_index].name_index].bytes; var className = cp[cp[cp[idx].class_index].name_index].bytes;
var methodName = cp[cp[cp[idx].name_and_type_index].name_index].bytes; var methodName = cp[cp[cp[idx].name_and_type_index].name_index].bytes;
var signature = cp[cp[cp[idx].name_and_type_index].signature_index].bytes; var signature = cp[cp[cp[idx].name_and_type_index].signature_index].bytes;
var method = CLASSES.getMethod(this, className, methodName, signature, op === OPCODES.invokestatic); var classInfo = CLASSES.getClass(this, className);
var method = CLASSES.getMethod(this, classInfo, methodName, signature, op === OPCODES.invokestatic);
this.invoke(method); this.invoke(method);
} }