Client: js,nodejs,ts generate_deserialize_map_element emitted map[key] = value with key read from the peer. On a plain object "__proto__" is not an ordinary member name: the assignment runs the setter inherited from Object.prototype, which swaps the object's prototype when the value is an object and silently discards the entry when it is not. Neither stores the pair. Measured on generated code before the change, over a map<string, struct>: a map entry whose key is "__proto__" left the decoded map with no own keys and its prototype replaced by the value, so a member the application never received resolved to something the peer chose. For map<string, string> the entry simply vanished. defineProperty stores the pair in both cases, keeps Object.prototype, and leaves every other key on the plain assignment. The guard is emitted for every map, not only those whose values can be objects, because the silent-drop half applies to the rest. Three alternatives were built out as generated code and round-tripped before settling on this one. Object.create(null) is not viable: the generated writer calls this.<field>.hasOwnProperty(kiter), which such an object does not have, and Thrift.objectLength() returns 0 for it, so a decoded map could not be sent on. A Map changes the decoded type and breaks every caller that indexes it. Skipping the key discards data a peer may legitimately send. The generator has no mode switch here, so this covers browser js, js:node, js:es6, js:ts, js:jquery and the esm variant alike; all eight were generated, syntax-checked and confirmed to carry the guard. Stacked on the json_parse change, and it needs it: under TJSONProtocol the map arrives as an object json_parse built, so without that fix the key has already gone into the prototype before any generated code runs. Seven of the 54 cases below fail on this commit alone for exactly that reason, and pass on the pair. lib/nodejs/test/MapKeyTest.thrift and lib/nodejs/test/map_keys.test.js, written first: 54 cases over the binary, compact and JSON protocols, 27 failing before the change. The IDL sits with the test that uses it rather than in test/, which is the cross-language suite: nothing outside lib/nodejs generates from it, and lib/nodejs/Makefile.am already ships test/ wholesale, so it needs no EXTRA_DIST entry of its own the way test/Makefile.am does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Build Thrift IDL compiler using CMake
- Build Thrift IDL compiler using CMake
- Other cases
- Unit tests for compiler
- Have a Happy free time and holidays
Build on Unix-like System
Prerequisites
- Install CMake
- Install flex and bison
Build using CMake
- Go to thrift\compiler\cpp
- Use the following steps to build using cmake:
mkdir cmake-build && cd cmake-build
cmake ..
make
Build with Eclipse IDE
- Go to thrift\compiler\cpp
- Use the following steps to build using cmake:
mkdir cmake-ec && cd cmake-ec
cmake -G "Eclipse CDT4 - Unix Makefiles" ..
make
Now open the folder cmake-ec using eclipse.
Build with XCode IDE in MacOS
- Install/update flex, bison and cmake with brew
brew install flex
brew install bison
brew install cmake
- Go to thrift\compiler\cpp
- Run commands in command line:
mkdir cmake-build && cd cmake-build
cmake -G "Xcode" ..
cmake --build .
Usage of other IDEs
Please check list of supported IDE
cmake --help
Build on Windows
Prerequisites
- Install CMake - https://cmake.org/download/
- In case if you want to build without Git Bash - install winflexbison - https://sourceforge.net/projects/winflexbison/
- In case if you want to build with Visual Studio - install Visual Studio
- Better to use the latest stable Visual Studio Community Edition - https://www.visualstudio.com/vs/whatsnew/ (ensure that you installed workload "Desktop Development with C++" for VS2017) - Microsoft added some support for CMake and improving it in Visual Studio
Build using Git Bash
Git Bash provides flex and bison
- Go to thrift\compiler\cpp
- Use the following steps to build using cmake:
mkdir cmake-vs && cd cmake-vs
cmake -DWITH_SHARED_LIB=off ..
cmake --build .
Using Visual Studio and Win flex-bison
- Generate a Visual Studio project for version of Visual Studio which you have (cmake --help can show list of supportable VS versions):
- Run commands in command line:
mkdir cmake-vs
cd cmake-vs
cmake -G "Visual Studio 15 2017" ..
- Now open the folder cmake-vs using Visual Studio.
Cross compile using mingw32 and generate a Windows Installer with CPack
mkdir cmake-mingw32 && cd cmake-mingw32
cmake -DCMAKE_TOOLCHAIN_FILE=../build/cmake/mingw32-toolchain.cmake -DBUILD_COMPILER=ON -DBUILD_LIBRARIES=OFF -DBUILD_TESTING=OFF ..
cpack
Other cases
Building the Thrift IDL compiler in Windows without CMake
If you don't want to use CMake you can use the already available Visual Studio 2010 solution.
The Visual Studio project contains pre-build commands to generate the thriftl.cc, thrifty.cc and thrifty.hh files which are necessary to build the compiler.
These depend on bison, flex and their dependencies to work properly.
Download flex & bison as described above.
Place these binaries somewhere in the path and rename win_flex.exe and win_bison.exe to flex.exe and bison.exe respectively.
If this doesn't work on a system, try these manual pre-build steps.
Open compiler.slnx and remove the Pre-build commands under the project's: Properties -> Build Events -> Pre-Build Events.
From a command prompt:
cd thrift/compiler/cpp
flex -o src\thrift\thriftl.cc src\thrift\thriftl.ll
In the generated thriftl.cc, comment out #include <unistd.h>
Place a copy of bison.simple in thrift/compiler/cpp
bison -y -o "src/thrift/thrifty.cc" --defines src/thrift/thrifty.yy
move src\thrift\thrifty.cc.hh src\thrift\thrifty.hh
Bison might generate the yacc header file "thrifty.cc.h" with just one h ".h" extension; in this case you'll have to rename to "thrifty.h".
move src\thrift\version.h.in src\thrift\version.h
Download inttypes.h from the interwebs and place it in an include path location (e.g. thrift/compiler/cpp/src).
Build the compiler in Visual Studio.
Unit tests for compiler
Using boost test
- pls check test folder
Using Catch C++ test library
Added generic way to cover code by tests for many languages (you just need to make a correct header file for generator for your language - example in netstd implementation)
- pls check tests folder