зеркало из https://github.com/mozilla/pluotsorbet.git
use proper String objects for strings
This commit is contained in:
Родитель
ee080b93ef
Коммит
7972db1598
29
classes.js
29
classes.js
|
@ -143,7 +143,30 @@ Classes.prototype.getStaticMethod = function(className, methodName, signature) {
|
|||
|
||||
Classes.prototype.newObject = function(className) {
|
||||
// Force initialization of the class (if not already done).
|
||||
this.getClass(className, true);
|
||||
|
||||
return {};
|
||||
return { class: this.getClass(className, true) };
|
||||
}
|
||||
|
||||
Classes.prototype.newArray = function(type, size) {
|
||||
switch (type) {
|
||||
case ARRAY_TYPE.T_BOOLEAN: return new Uint8Array(size);
|
||||
case ARRAY_TYPE.T_CHAR: return new Uint16Array(size);
|
||||
case ARRAY_TYPE.T_FLOAT: return new Float32Array(size);
|
||||
case ARRAY_TYPE.T_DOUBLE: return new Float64Array(size);
|
||||
case ARRAY_TYPE.T_BYTE: return new Int8Array(size);
|
||||
case ARRAY_TYPE.T_SHORT: return new Int16Array(size);
|
||||
case ARRAY_TYPE.T_INT: return new Int32Array(size);
|
||||
case ARRAY_TYPE.T_LONG: return new Int64Array(size);
|
||||
}
|
||||
}
|
||||
|
||||
Classes.prototype.newString = function(s) {
|
||||
var obj = this.newObject("java/lang/String");
|
||||
var length = s.length;
|
||||
var chars = this.newArray(ARRAY_TYPE.T_CHAR, length);
|
||||
for (var n = 0; n < length; ++n)
|
||||
chars[n] = s.charCodeAt(n);
|
||||
obj.value = chars;
|
||||
obj.offset = 0;
|
||||
obj.count = length;
|
||||
return obj;
|
||||
}
|
|
@ -56,15 +56,12 @@ var getClassImage = function(classBytes) {
|
|||
var classImage = {};
|
||||
|
||||
var getAttribues = function(attribute_name_index, bytes) {
|
||||
|
||||
var reader = new Reader(bytes);
|
||||
var attribute = { attribute_name_index: attribute_name_index };
|
||||
|
||||
|
||||
var item = classImage.constant_pool[attribute_name_index];
|
||||
|
||||
switch(item.tag) {
|
||||
|
||||
case TAGS.CONSTANT_Long:
|
||||
case TAGS.CONSTANT_Float:
|
||||
case TAGS.CONSTANT_Double:
|
||||
|
@ -74,11 +71,8 @@ var getClassImage = function(classBytes) {
|
|||
attribute.constantvalue_index = reader.read16();
|
||||
return attribute;
|
||||
|
||||
|
||||
case TAGS.CONSTANT_Utf8:
|
||||
|
||||
switch(item.bytes) {
|
||||
|
||||
case ATTRIBUTE_TYPES.Code:
|
||||
attribute.type = ATTRIBUTE_TYPES.Code;
|
||||
attribute.max_stack = reader.read16();
|
||||
|
|
6
frame.js
6
frame.js
|
@ -232,7 +232,7 @@ Frame.prototype.ldc = function(done) {
|
|||
var constant = this._cp[this._read8()];
|
||||
switch(constant.tag) {
|
||||
case TAGS.CONSTANT_String:
|
||||
this._stack.push(this._cp[constant.string_index].bytes);
|
||||
this._stack.push(CLASSES.newString(this._cp[constant.string_index].bytes));
|
||||
break;
|
||||
default:
|
||||
throw new Error("not support constant type");
|
||||
|
@ -1163,7 +1163,7 @@ Frame.prototype.newarray = function(done) {
|
|||
if (size < 0) {
|
||||
return this._newException("java/lang/NegativeSizeException", done);
|
||||
}
|
||||
this._stack.push(new Array(size));
|
||||
this._stack.push(CLASSES.newArray(type, size));
|
||||
return done();
|
||||
}
|
||||
|
||||
|
@ -1684,7 +1684,7 @@ Frame.prototype.instanceof = function(done) {
|
|||
var idx = this._read16();
|
||||
var className = this._cp[this._cp[idx].name_index].bytes;
|
||||
var obj = this._stack.pop();
|
||||
if (obj.getClassName() === className) {
|
||||
if (obj.class.getClassName() === className) {
|
||||
this._stack.push(true);
|
||||
} else {
|
||||
this._stack.push(false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче