diff --git a/.gitignore b/.gitignore index 79c70d0cd..9dfabefad 100755 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ build/VS2010/FlatBuffers.sdf build/VS2010/FlatBuffers.opensdf build/VS2010/ipch/**/*.ipch *.so +Testing/Temporary diff --git a/php/FlatbufferBuilder.php b/php/FlatbufferBuilder.php index 6f0ee4831..5c18bf46a 100644 --- a/php/FlatbufferBuilder.php +++ b/php/FlatbufferBuilder.php @@ -593,6 +593,10 @@ class FlatbufferBuilder protected function is_utf8($bytes) { + if (function_exists('mb_detect_encoding')) { + return (bool) mb_detect_encoding($bytes, 'UTF-8', true); + } + $len = strlen($bytes); if ($len < 1) { /* NOTE: always return 1 when passed string is null */ diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index 23fd52c57..32c660c90 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -557,13 +557,13 @@ void GenStruct(const Parser &parser, StructDef &struct_def, std::string *code_pt "@returns {boolean}"); code += object_name + ".prototype.mutate_" + field.name + " = function(value) {\n"; - code += " var offset = this.bb.__offset(this.bb_pos, " + NumToString(field.value.offset) + ")\n\n"; + code += " var offset = this.bb.__offset(this.bb_pos, " + NumToString(field.value.offset) + ");\n\n"; code += " if (offset === 0) {\n"; code += " return false;\n"; code += " }\n\n"; code += " this.bb.write" + MakeCamel(GenType(field.value.type)) + "(this.bb_pos + offset, value);\n"; code += " return true;\n"; - code += "}\n\n"; + code += "};\n\n"; } // Emit vector helpers diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index f69ae4c07..0dc739240 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -1758,6 +1758,9 @@ CheckedError Parser::SkipAnyJsonValue() { case kTokenFloatConstant: EXPECT(kTokenFloatConstant); break; + case kTokenNull: + EXPECT(kTokenNull); + break; default: return Error(std::string("Unexpected token:") + std::string(1, static_cast(token_))); } diff --git a/tests/monster_test_generated.js b/tests/monster_test_generated.js index 6789ebb42..dbb5ba635 100644 --- a/tests/monster_test_generated.js +++ b/tests/monster_test_generated.js @@ -132,7 +132,7 @@ MyGame.Example.Test.prototype.a = function() { * @returns {boolean} */ MyGame.Example.Test.prototype.mutate_a = function(value) { - var offset = this.bb.__offset(this.bb_pos, 0) + var offset = this.bb.__offset(this.bb_pos, 0); if (offset === 0) { return false; @@ -140,7 +140,7 @@ MyGame.Example.Test.prototype.mutate_a = function(value) { this.bb.writeInt16(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -154,7 +154,7 @@ MyGame.Example.Test.prototype.b = function() { * @returns {boolean} */ MyGame.Example.Test.prototype.mutate_b = function(value) { - var offset = this.bb.__offset(this.bb_pos, 2) + var offset = this.bb.__offset(this.bb_pos, 2); if (offset === 0) { return false; @@ -162,7 +162,7 @@ MyGame.Example.Test.prototype.mutate_b = function(value) { this.bb.writeInt8(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Builder} builder @@ -226,7 +226,7 @@ MyGame.Example.TestSimpleTableWithEnum.prototype.color = function() { * @returns {boolean} */ MyGame.Example.TestSimpleTableWithEnum.prototype.mutate_color = function(value) { - var offset = this.bb.__offset(this.bb_pos, 4) + var offset = this.bb.__offset(this.bb_pos, 4); if (offset === 0) { return false; @@ -234,7 +234,7 @@ MyGame.Example.TestSimpleTableWithEnum.prototype.mutate_color = function(value) this.bb.writeInt8(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Builder} builder @@ -298,7 +298,7 @@ MyGame.Example.Vec3.prototype.x = function() { * @returns {boolean} */ MyGame.Example.Vec3.prototype.mutate_x = function(value) { - var offset = this.bb.__offset(this.bb_pos, 0) + var offset = this.bb.__offset(this.bb_pos, 0); if (offset === 0) { return false; @@ -306,7 +306,7 @@ MyGame.Example.Vec3.prototype.mutate_x = function(value) { this.bb.writeFloat32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -320,7 +320,7 @@ MyGame.Example.Vec3.prototype.y = function() { * @returns {boolean} */ MyGame.Example.Vec3.prototype.mutate_y = function(value) { - var offset = this.bb.__offset(this.bb_pos, 4) + var offset = this.bb.__offset(this.bb_pos, 4); if (offset === 0) { return false; @@ -328,7 +328,7 @@ MyGame.Example.Vec3.prototype.mutate_y = function(value) { this.bb.writeFloat32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -342,7 +342,7 @@ MyGame.Example.Vec3.prototype.z = function() { * @returns {boolean} */ MyGame.Example.Vec3.prototype.mutate_z = function(value) { - var offset = this.bb.__offset(this.bb_pos, 8) + var offset = this.bb.__offset(this.bb_pos, 8); if (offset === 0) { return false; @@ -350,7 +350,7 @@ MyGame.Example.Vec3.prototype.mutate_z = function(value) { this.bb.writeFloat32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -364,7 +364,7 @@ MyGame.Example.Vec3.prototype.test1 = function() { * @returns {boolean} */ MyGame.Example.Vec3.prototype.mutate_test1 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 16) + var offset = this.bb.__offset(this.bb_pos, 16); if (offset === 0) { return false; @@ -372,7 +372,7 @@ MyGame.Example.Vec3.prototype.mutate_test1 = function(value) { this.bb.writeFloat64(this.bb_pos + offset, value); return true; -} +}; /** * @returns {MyGame.Example.Color} @@ -386,7 +386,7 @@ MyGame.Example.Vec3.prototype.test2 = function() { * @returns {boolean} */ MyGame.Example.Vec3.prototype.mutate_test2 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 24) + var offset = this.bb.__offset(this.bb_pos, 24); if (offset === 0) { return false; @@ -394,7 +394,7 @@ MyGame.Example.Vec3.prototype.mutate_test2 = function(value) { this.bb.writeInt8(this.bb_pos + offset, value); return true; -} +}; /** * @param {MyGame.Example.Test=} obj @@ -489,7 +489,7 @@ MyGame.Example.Stat.prototype.val = function() { * @returns {boolean} */ MyGame.Example.Stat.prototype.mutate_val = function(value) { - var offset = this.bb.__offset(this.bb_pos, 6) + var offset = this.bb.__offset(this.bb_pos, 6); if (offset === 0) { return false; @@ -497,7 +497,7 @@ MyGame.Example.Stat.prototype.mutate_val = function(value) { this.bb.writeInt64(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -512,7 +512,7 @@ MyGame.Example.Stat.prototype.count = function() { * @returns {boolean} */ MyGame.Example.Stat.prototype.mutate_count = function(value) { - var offset = this.bb.__offset(this.bb_pos, 8) + var offset = this.bb.__offset(this.bb_pos, 8); if (offset === 0) { return false; @@ -520,7 +520,7 @@ MyGame.Example.Stat.prototype.mutate_count = function(value) { this.bb.writeUint16(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Builder} builder @@ -629,7 +629,7 @@ MyGame.Example.Monster.prototype.mana = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_mana = function(value) { - var offset = this.bb.__offset(this.bb_pos, 6) + var offset = this.bb.__offset(this.bb_pos, 6); if (offset === 0) { return false; @@ -637,7 +637,7 @@ MyGame.Example.Monster.prototype.mutate_mana = function(value) { this.bb.writeInt16(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -652,7 +652,7 @@ MyGame.Example.Monster.prototype.hp = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_hp = function(value) { - var offset = this.bb.__offset(this.bb_pos, 8) + var offset = this.bb.__offset(this.bb_pos, 8); if (offset === 0) { return false; @@ -660,7 +660,7 @@ MyGame.Example.Monster.prototype.mutate_hp = function(value) { this.bb.writeInt16(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Encoding=} optionalEncoding @@ -709,7 +709,7 @@ MyGame.Example.Monster.prototype.color = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_color = function(value) { - var offset = this.bb.__offset(this.bb_pos, 16) + var offset = this.bb.__offset(this.bb_pos, 16); if (offset === 0) { return false; @@ -717,7 +717,7 @@ MyGame.Example.Monster.prototype.mutate_color = function(value) { this.bb.writeInt8(this.bb_pos + offset, value); return true; -} +}; /** * @returns {MyGame.Example.Any} @@ -732,7 +732,7 @@ MyGame.Example.Monster.prototype.testType = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_test_type = function(value) { - var offset = this.bb.__offset(this.bb_pos, 18) + var offset = this.bb.__offset(this.bb_pos, 18); if (offset === 0) { return false; @@ -740,7 +740,7 @@ MyGame.Example.Monster.prototype.mutate_test_type = function(value) { this.bb.writeUint8(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Table} obj @@ -864,7 +864,7 @@ MyGame.Example.Monster.prototype.testbool = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testbool = function(value) { - var offset = this.bb.__offset(this.bb_pos, 34) + var offset = this.bb.__offset(this.bb_pos, 34); if (offset === 0) { return false; @@ -872,7 +872,7 @@ MyGame.Example.Monster.prototype.mutate_testbool = function(value) { this.bb.writeInt8(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -887,7 +887,7 @@ MyGame.Example.Monster.prototype.testhashs32Fnv1 = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashs32_fnv1 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 36) + var offset = this.bb.__offset(this.bb_pos, 36); if (offset === 0) { return false; @@ -895,7 +895,7 @@ MyGame.Example.Monster.prototype.mutate_testhashs32_fnv1 = function(value) { this.bb.writeInt32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -910,7 +910,7 @@ MyGame.Example.Monster.prototype.testhashu32Fnv1 = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashu32_fnv1 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 38) + var offset = this.bb.__offset(this.bb_pos, 38); if (offset === 0) { return false; @@ -918,7 +918,7 @@ MyGame.Example.Monster.prototype.mutate_testhashu32_fnv1 = function(value) { this.bb.writeUint32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {flatbuffers.Long} @@ -933,7 +933,7 @@ MyGame.Example.Monster.prototype.testhashs64Fnv1 = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashs64_fnv1 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 40) + var offset = this.bb.__offset(this.bb_pos, 40); if (offset === 0) { return false; @@ -941,7 +941,7 @@ MyGame.Example.Monster.prototype.mutate_testhashs64_fnv1 = function(value) { this.bb.writeInt64(this.bb_pos + offset, value); return true; -} +}; /** * @returns {flatbuffers.Long} @@ -956,7 +956,7 @@ MyGame.Example.Monster.prototype.testhashu64Fnv1 = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashu64_fnv1 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 42) + var offset = this.bb.__offset(this.bb_pos, 42); if (offset === 0) { return false; @@ -964,7 +964,7 @@ MyGame.Example.Monster.prototype.mutate_testhashu64_fnv1 = function(value) { this.bb.writeUint64(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -979,7 +979,7 @@ MyGame.Example.Monster.prototype.testhashs32Fnv1a = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashs32_fnv1a = function(value) { - var offset = this.bb.__offset(this.bb_pos, 44) + var offset = this.bb.__offset(this.bb_pos, 44); if (offset === 0) { return false; @@ -987,7 +987,7 @@ MyGame.Example.Monster.prototype.mutate_testhashs32_fnv1a = function(value) { this.bb.writeInt32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -1002,7 +1002,7 @@ MyGame.Example.Monster.prototype.testhashu32Fnv1a = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashu32_fnv1a = function(value) { - var offset = this.bb.__offset(this.bb_pos, 46) + var offset = this.bb.__offset(this.bb_pos, 46); if (offset === 0) { return false; @@ -1010,7 +1010,7 @@ MyGame.Example.Monster.prototype.mutate_testhashu32_fnv1a = function(value) { this.bb.writeUint32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {flatbuffers.Long} @@ -1025,7 +1025,7 @@ MyGame.Example.Monster.prototype.testhashs64Fnv1a = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashs64_fnv1a = function(value) { - var offset = this.bb.__offset(this.bb_pos, 48) + var offset = this.bb.__offset(this.bb_pos, 48); if (offset === 0) { return false; @@ -1033,7 +1033,7 @@ MyGame.Example.Monster.prototype.mutate_testhashs64_fnv1a = function(value) { this.bb.writeInt64(this.bb_pos + offset, value); return true; -} +}; /** * @returns {flatbuffers.Long} @@ -1048,7 +1048,7 @@ MyGame.Example.Monster.prototype.testhashu64Fnv1a = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testhashu64_fnv1a = function(value) { - var offset = this.bb.__offset(this.bb_pos, 50) + var offset = this.bb.__offset(this.bb_pos, 50); if (offset === 0) { return false; @@ -1056,7 +1056,7 @@ MyGame.Example.Monster.prototype.mutate_testhashu64_fnv1a = function(value) { this.bb.writeUint64(this.bb_pos + offset, value); return true; -} +}; /** * @param {number} index @@ -1096,7 +1096,7 @@ MyGame.Example.Monster.prototype.testf = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testf = function(value) { - var offset = this.bb.__offset(this.bb_pos, 54) + var offset = this.bb.__offset(this.bb_pos, 54); if (offset === 0) { return false; @@ -1104,7 +1104,7 @@ MyGame.Example.Monster.prototype.mutate_testf = function(value) { this.bb.writeFloat32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -1119,7 +1119,7 @@ MyGame.Example.Monster.prototype.testf2 = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testf2 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 56) + var offset = this.bb.__offset(this.bb_pos, 56); if (offset === 0) { return false; @@ -1127,7 +1127,7 @@ MyGame.Example.Monster.prototype.mutate_testf2 = function(value) { this.bb.writeFloat32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -1142,7 +1142,7 @@ MyGame.Example.Monster.prototype.testf3 = function() { * @returns {boolean} */ MyGame.Example.Monster.prototype.mutate_testf3 = function(value) { - var offset = this.bb.__offset(this.bb_pos, 58) + var offset = this.bb.__offset(this.bb_pos, 58); if (offset === 0) { return false; @@ -1150,7 +1150,7 @@ MyGame.Example.Monster.prototype.mutate_testf3 = function(value) { this.bb.writeFloat32(this.bb_pos + offset, value); return true; -} +}; /** * @param {number} index diff --git a/tests/namespace_test/namespace_test1_generated.js b/tests/namespace_test/namespace_test1_generated.js index a8fea9ea6..7551a185e 100644 --- a/tests/namespace_test/namespace_test1_generated.js +++ b/tests/namespace_test/namespace_test1_generated.js @@ -69,7 +69,7 @@ NamespaceA.NamespaceB.TableInNestedNS.prototype.foo = function() { * @returns {boolean} */ NamespaceA.NamespaceB.TableInNestedNS.prototype.mutate_foo = function(value) { - var offset = this.bb.__offset(this.bb_pos, 4) + var offset = this.bb.__offset(this.bb_pos, 4); if (offset === 0) { return false; @@ -77,7 +77,7 @@ NamespaceA.NamespaceB.TableInNestedNS.prototype.mutate_foo = function(value) { this.bb.writeInt32(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Builder} builder @@ -141,7 +141,7 @@ NamespaceA.NamespaceB.StructInNestedNS.prototype.a = function() { * @returns {boolean} */ NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_a = function(value) { - var offset = this.bb.__offset(this.bb_pos, 0) + var offset = this.bb.__offset(this.bb_pos, 0); if (offset === 0) { return false; @@ -149,7 +149,7 @@ NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_a = function(value) { this.bb.writeInt32(this.bb_pos + offset, value); return true; -} +}; /** * @returns {number} @@ -163,7 +163,7 @@ NamespaceA.NamespaceB.StructInNestedNS.prototype.b = function() { * @returns {boolean} */ NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_b = function(value) { - var offset = this.bb.__offset(this.bb_pos, 4) + var offset = this.bb.__offset(this.bb_pos, 4); if (offset === 0) { return false; @@ -171,7 +171,7 @@ NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_b = function(value) { this.bb.writeInt32(this.bb_pos + offset, value); return true; -} +}; /** * @param {flatbuffers.Builder} builder diff --git a/tests/namespace_test/namespace_test2_generated.js b/tests/namespace_test/namespace_test2_generated.js index 856bbff92..c1c25eff9 100644 --- a/tests/namespace_test/namespace_test2_generated.js +++ b/tests/namespace_test/namespace_test2_generated.js @@ -75,7 +75,7 @@ NamespaceA.TableInFirstNS.prototype.fooEnum = function() { * @returns {boolean} */ NamespaceA.TableInFirstNS.prototype.mutate_foo_enum = function(value) { - var offset = this.bb.__offset(this.bb_pos, 6) + var offset = this.bb.__offset(this.bb_pos, 6); if (offset === 0) { return false; @@ -83,7 +83,7 @@ NamespaceA.TableInFirstNS.prototype.mutate_foo_enum = function(value) { this.bb.writeInt8(this.bb_pos + offset, value); return true; -} +}; /** * @param {NamespaceA.NamespaceB.StructInNestedNS=} obj