From 4f8a523fa00eee667c32c2b61473c0f5efc98399 Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Fri, 9 Sep 2011 08:17:02 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_js_generator.cc | 7 ++++++ lib/js/test/build.xml | 2 +- lib/js/test/test.js | 26 +++++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc index b6ca05a3..d7d83bfb 100644 --- a/compiler/cpp/src/generate/t_js_generator.cc +++ b/compiler/cpp/src/generate/t_js_generator.cc @@ -1354,6 +1354,13 @@ void t_js_generator::generate_deserialize_container(ofstream &out, 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 86ab2767..4409679a 100755 --- a/lib/js/test/build.xml +++ b/lib/js/test/build.xml @@ -144,7 +144,7 @@ - diff --git a/lib/js/test/test.js b/lib/js/test/test.js index caf34a21..2d8fe237 100755 --- a/lib/js/test/test.js +++ b/lib/js/test/test.js @@ -28,7 +28,18 @@ var client = new ThriftTest.ThriftTestClient(protocol); // 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 @@ module("deeper!"); } } - equals(JSON.stringify(mapMapTestOutput), JSON.stringify(mapMapTestExpectedResult)); + checkRecursively(mapMapTestOutput, mapMapTestExpectedResult); }); @@ -201,8 +212,8 @@ module("Insanity"); 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 @@ module("Insanity"); } ] }, - "2":{ - "userMap":{ "8":8, "5":5 }, + "3":{ + "userMap":{ "5":5, "8":8 }, "xtructs":[{ "string_thing":"Goodbye4", "byte_thing":4, @@ -239,7 +250,8 @@ module("Insanity"); 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); }); -- 2.17.1