From 4b10656f9bd0d5b7fa2b068af6db3ad62c2a7267 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Fri, 21 Sep 2018 09:41:11 -0700 Subject: [PATCH] Changed JS/TS codegen to use stable non-compiler dependent hash. Different implementations of std::hash kept littering commits with namespace changes. Change-Id: Ic2d4fdcd76f8fef9802bc1572eb74ae7427085e3 --- src/idl_gen_js.cpp | 3 +-- .../namespace_test2_generated.ts | 20 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/idl_gen_js.cpp b/src/idl_gen_js.cpp index 71e7a54a3..3b0535bcf 100644 --- a/src/idl_gen_js.cpp +++ b/src/idl_gen_js.cpp @@ -507,8 +507,7 @@ class JsGenerator : public BaseGenerator { } static std::string GenFileNamespacePrefix(const std::string &file) { - return "NS" + std::to_string(static_cast( - std::hash()(file))); + return "NS" + std::to_string(HashFnv1a(file.c_str())); } static std::string GenPrefixedImport(const std::string &full_file_name, diff --git a/tests/namespace_test/namespace_test2_generated.ts b/tests/namespace_test/namespace_test2_generated.ts index d1a305f91..371ea1383 100644 --- a/tests/namespace_test/namespace_test2_generated.ts +++ b/tests/namespace_test/namespace_test2_generated.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -import * as NS9459827973991502386 from "./namespace_test1_generated"; +import * as NS8755221360535654258 from "./namespace_test1_generated"; /** * @constructor */ @@ -33,24 +33,24 @@ static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):T * @param NamespaceA.NamespaceB.TableInNestedNS= obj * @returns NamespaceA.NamespaceB.TableInNestedNS|null */ -fooTable(obj?:NS9459827973991502386.NamespaceA.NamespaceB.TableInNestedNS):NS9459827973991502386.NamespaceA.NamespaceB.TableInNestedNS|null { +fooTable(obj?:NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNS):NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNS|null { var offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? (obj || new NS9459827973991502386.NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; + return offset ? (obj || new NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; }; /** * @returns NamespaceA.NamespaceB.EnumInNestedNS */ -fooEnum():NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS { +fooEnum():NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS { var offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? /** */ (this.bb!.readInt8(this.bb_pos + offset)) : NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS.A; + return offset ? /** */ (this.bb!.readInt8(this.bb_pos + offset)) : NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS.A; }; /** * @param NamespaceA.NamespaceB.EnumInNestedNS value * @returns boolean */ -mutate_foo_enum(value:NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS):boolean { +mutate_foo_enum(value:NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS):boolean { var offset = this.bb!.__offset(this.bb_pos, 6); if (offset === 0) { @@ -65,9 +65,9 @@ mutate_foo_enum(value:NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS * @param NamespaceA.NamespaceB.StructInNestedNS= obj * @returns NamespaceA.NamespaceB.StructInNestedNS|null */ -fooStruct(obj?:NS9459827973991502386.NamespaceA.NamespaceB.StructInNestedNS):NS9459827973991502386.NamespaceA.NamespaceB.StructInNestedNS|null { +fooStruct(obj?:NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNS):NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNS|null { var offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? (obj || new NS9459827973991502386.NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb!) : null; + return offset ? (obj || new NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb!) : null; }; /** @@ -89,8 +89,8 @@ static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offse * @param flatbuffers.Builder builder * @param NamespaceA.NamespaceB.EnumInNestedNS fooEnum */ -static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS) { - builder.addFieldInt8(1, fooEnum, NS9459827973991502386.NamespaceA.NamespaceB.EnumInNestedNS.A); +static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS) { + builder.addFieldInt8(1, fooEnum, NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS.A); }; /**