THRIFT-1238 Thrift JS client cannot read map of structures
Patch: Henrique Mendonca
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1167032 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc
index b6ca05a..d7d83bf 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -1354,6 +1354,13 @@
scope_up(out);
if (ttype->is_map()) {
+ out <<
+ indent() << "if (" << i << " > 0 ) {" << endl <<
+ indent() << " if (input.rstack.length > input.rpos[input.rpos.length -1] + 1) {" << endl <<
+ indent() << " input.rstack.pop();" << endl <<
+ indent() << " }" << endl <<
+ indent() << "}" << endl;
+
generate_deserialize_map_element(out, (t_map*)ttype, prefix);
} else if (ttype->is_set()) {
generate_deserialize_set_element(out, (t_set*)ttype, prefix);
diff --git a/lib/js/test/build.xml b/lib/js/test/build.xml
index 86ab276..4409679 100755
--- a/lib/js/test/build.xml
+++ b/lib/js/test/build.xml
@@ -144,7 +144,7 @@
<exec executable="Xvfb" spawn="true" failonerror="false">
<arg line=":99" />
</exec>
- <java classname="test.Httpd" fork="true" timeout="5000"
+ <java classname="test.Httpd" fork="true" timeout="10000"
classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log">
<arg value="../" />
</java>
diff --git a/lib/js/test/test.js b/lib/js/test/test.js
index caf34a2..2d8fe23 100755
--- a/lib/js/test/test.js
+++ b/lib/js/test/test.js
@@ -28,7 +28,18 @@
// all Languages in UTF-8
var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語";
-
+
+function checkRecursively(map1, map2) {
+ if (typeof map1 !== 'function' && typeof map2 !== 'function') {
+ if (!map1 || typeof map1 !== 'object') {
+ equals(map1, map2);
+ } else {
+ for (var key in map1) {
+ checkRecursively(map1[key], map2[key]);
+ }
+ }
+ }
+}
module("Base Types");
@@ -161,7 +172,7 @@
}
}
- equals(JSON.stringify(mapMapTestOutput), JSON.stringify(mapMapTestExpectedResult));
+ checkRecursively(mapMapTestOutput, mapMapTestExpectedResult);
});
@@ -201,8 +212,8 @@
test("testInsanity", function() {
var insanity = {
"1":{
- "3":{
- "userMap":{ "8":8, "5":5 },
+ "2":{
+ "userMap":{ "5":5, "8":8 },
"xtructs":[{
"string_thing":"Goodbye4",
"byte_thing":4,
@@ -217,8 +228,8 @@
}
]
},
- "2":{
- "userMap":{ "8":8, "5":5 },
+ "3":{
+ "userMap":{ "5":5, "8":8 },
"xtructs":[{
"string_thing":"Goodbye4",
"byte_thing":4,
@@ -239,7 +250,8 @@
var res = client.testInsanity("");
ok(res, JSON.stringify(res));
ok(insanity, JSON.stringify(insanity));
- equals(JSON.stringify(res), JSON.stringify(insanity)); //TODO: read and compare maps recursively
+
+ checkRecursively(res, insanity);
});