Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
*.class
node_modules/
16 changes: 13 additions & 3 deletions libs/classfile/classarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var getClassImage = function(classBytes) {

var classImage = {};

var getAttributes = function(attribute_name_index, bytes) {
var getAttribues = function(attribute_name_index, bytes) {

var reader = new Reader.create(bytes);
var attribute = { attribute_name_index: attribute_name_index };
Expand Down Expand Up @@ -172,11 +172,21 @@ var getClassImage = function(classBytes) {
var bytes = reader.readString(length);
classImage.constant_pool.push( { tag: tag, bytes: bytes } );
break;
case TAGS.CONSTANT_Methodref:
var class_index = reader.read16();
var name_and_type_index = reader.read16();
classImage.constant_pool.push( { tag: tag, class_index: class_index, name_and_type_index: name_and_type_index } );
break;
case TAGS.CONSTANT_NameAndType:
var name_index = reader.read16();
var signature_index = reader.read16();
classImage.constant_pool.push( { tag: tag, name_index: name_index, signature_index: signature_index } );
break;
case TAGS.CONSTANT_Fieldref:
var class_index = reader.read16();
var name_and_type_index = reader.read16();
classImage.constant_pool.push( { tag: tag, class_index: class_index, name_and_type_index: name_and_type_index } );
break;
case TAGS.CONSTANT_String:
var string_index = reader.read16();
classImage.constant_pool.push( { tag: tag, string_index: string_index } );
Expand Down Expand Up @@ -268,7 +278,7 @@ var getClassImage = function(classBytes) {
for(var j=0; j <attributes_count; j++) {
var attribute_name_index = reader.read16();
var attribute_length = reader.read32();
var info = getAttributes(attribute_name_index, reader.readBytes(attribute_length));
var info = getAttribues(attribute_name_index, reader.readBytes(attribute_length));
var attribute = {
attribute_name_index: attribute_name_index,
attribute_length: attribute_length,
Expand All @@ -286,7 +296,7 @@ var getClassImage = function(classBytes) {
for(var i=0; i<attributes_count; i++) {
var attribute_name_index = reader.read16();
var attribute_length = reader.read32();
var info = getAttributes(attribute_name_index, reader.readBytes(attribute_length));
var info = getAttribues(attribute_name_index, reader.readBytes(attribute_length));
var attribute = {
attribute_name_index: attribute_name_index,
attribute_length: attribute_length,
Expand Down
13 changes: 8 additions & 5 deletions libs/java/io/PrintStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ var out = module.exports = function() {
out.getClassName = function() {
return "java/io/PrintStream";
}


//TODO

out.prototype["print"] = function() {
util.print.apply(null, arguments);
console.log({arguments})
};

out.prototype["println"] = function() {
util.print.apply(null, arguments);
util.print("\n");
console.log({arguments})

};

out.prototype["format"] = function(fmt, args) {
util.print(util.format.apply(null, [fmt].concat(args)));
console.log({arguments})
}

2 changes: 1 addition & 1 deletion libs/util/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Reader.prototype.read32 = function() {
}

Reader.prototype.readString = function(length) {
var data = this.bytes.toString(undefined, this.offset, this.offset + length)
var data = this.bytes.toString('utf8', this.offset, this.offset + length)
this.offset += length;
return data;
}
Expand Down