Skip to content

Commit

Permalink
Fixed javascript helper for typed arrays of scalars not taking into
Browse files Browse the repository at this point in the history
account underlying buffer's byte offset.
  • Loading branch information
benssson committed Oct 26, 2016
1 parent af21b90 commit be24eb6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/idl_gen_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void GenStruct(const Parser &parser, StructDef &struct_def, std::string *code_pt
code += object_name + ".prototype." + MakeCamel(field.name, false);
code += "Array = function() {\n" + offset_prefix;
code += "new " + GenType(vectorType) + "Array(this.bb.bytes().buffer, "
"this.bb.__vector(this.bb_pos + offset), "
"this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), "
"this.bb.__vector_len(this.bb_pos + offset)) : null;\n};\n\n";
}
}
Expand Down
Binary file modified tests/monster_test.bfbs
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/monster_test_generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ MyGame.Example.Monster.prototype.inventoryLength = function() {
*/
MyGame.Example.Monster.prototype.inventoryArray = function() {
var offset = this.bb.__offset(this.bb_pos, 14);
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
};

/**
Expand Down Expand Up @@ -839,7 +839,7 @@ MyGame.Example.Monster.prototype.testnestedflatbufferLength = function() {
*/
MyGame.Example.Monster.prototype.testnestedflatbufferArray = function() {
var offset = this.bb.__offset(this.bb_pos, 30);
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
};

/**
Expand Down Expand Up @@ -1080,7 +1080,7 @@ MyGame.Example.Monster.prototype.testarrayofboolsLength = function() {
*/
MyGame.Example.Monster.prototype.testarrayofboolsArray = function() {
var offset = this.bb.__offset(this.bb_pos, 52);
return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
return offset ? new Int8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
};

/**
Expand Down

0 comments on commit be24eb6

Please sign in to comment.