diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index d46f41179..0e95830d9 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -579,8 +579,11 @@ static void GenStruct(const Parser &parser, StructDef &struct_def, code += " builder.startVector(" + NumToString(elem_size); code += ", data.length, " + NumToString(alignment) + ");\n"; code += " for (var i = data.length - 1; i >= 0; i--) {\n"; - code += " builder.add" + GenWriteMethod(vector_type); - code += "(data[i]);\n"; + code += " builder.add" + GenWriteMethod(vector_type) + "("; + if (vector_type.base_type == BASE_TYPE_BOOL) { + code += "+"; + } + code += "data[i]);\n"; code += " }\n"; code += " return builder.endVector();\n"; code += "};\n\n"; diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index e5f51face..8d54ead7e 100644 Binary files a/tests/monster_test.bfbs and b/tests/monster_test.bfbs differ diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index 39cd3d2e8..5687308e8 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -631,11 +631,28 @@ MyGame.Example.Monster.prototype.testhashu64Fnv1a = function() { return offset ? this.bb.readUint64(this.bb_pos + offset) : flatbuffers.Long.ZERO; }; +/** + * @param {number} index + * @returns {boolean} + */ +MyGame.Example.Monster.prototype.testarrayofbools = function(index) { + var offset = this.bb.__offset(this.bb_pos, 52); + return offset ? !!this.bb.readInt8(this.bb.__vector(this.bb_pos + offset) + index) : false; +}; + +/** + * @returns {number} + */ +MyGame.Example.Monster.prototype.testarrayofboolsLength = function() { + var offset = this.bb.__offset(this.bb_pos, 52); + return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; +}; + /** * @param {flatbuffers.Builder} builder */ MyGame.Example.Monster.startMonster = function(builder) { - builder.startObject(24); + builder.startObject(25); }; /** @@ -914,6 +931,35 @@ MyGame.Example.Monster.addTesthashu64Fnv1a = function(builder, testhashu64Fnv1a) builder.addFieldInt64(23, testhashu64Fnv1a, flatbuffers.Long.ZERO); }; +/** + * @param {flatbuffers.Builder} builder + * @param {flatbuffers.Offset} testarrayofboolsOffset + */ +MyGame.Example.Monster.addTestarrayofbools = function(builder, testarrayofboolsOffset) { + builder.addFieldOffset(24, testarrayofboolsOffset, 0); +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {Array.} data + * @returns {flatbuffers.Offset} + */ +MyGame.Example.Monster.createTestarrayofboolsVector = function(builder, data) { + builder.startVector(1, data.length, 1); + for (var i = data.length - 1; i >= 0; i--) { + builder.addInt8(+data[i]); + } + return builder.endVector(); +}; + +/** + * @param {flatbuffers.Builder} builder + * @param {number} numElems + */ +MyGame.Example.Monster.startTestarrayofboolsVector = function(builder, numElems) { + builder.startVector(1, numElems, 1); +}; + /** * @param {flatbuffers.Builder} builder * @returns {flatbuffers.Offset}