diff --git a/compiler/cpp/src/thrift/generate/t_js_generator.cc b/compiler/cpp/src/thrift/generate/t_js_generator.cc index f8f1beed89a..d30ce41537c 100644 --- a/compiler/cpp/src/thrift/generate/t_js_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_js_generator.cc @@ -698,8 +698,12 @@ string t_js_generator::render_const_value(t_type* type, t_const_value* value) { for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) { if (v_iter != val.begin()) out << "," << endl; - - out << indent() << render_const_value(ktype, v_iter->first); + + if (ktype->is_base_type() && ((t_base_type*)get_true_type(ktype))->get_base() == t_base_type::TYPE_I64){ + out << indent() << "\"" << v_iter->first->get_integer() << "\""; + } else { + out << indent() << render_const_value(ktype, v_iter->first); + } out << " : "; out << render_const_value(vtype, v_iter->second); diff --git a/lib/js/package.json b/lib/js/package.json index c4bcc6d6c3b..a35ac15a323 100644 --- a/lib/js/package.json +++ b/lib/js/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "jsdoc": "^3.5.5", - "json-int64": "^0.0.3", + "json-int64": "^1.0.0", "nopt": "^4.0.1" } } diff --git a/lib/js/test/test-int64.html b/lib/js/test/test-int64.html index 620e6ff861d..bcb05fb371e 100644 --- a/lib/js/test/test-int64.html +++ b/lib/js/test/test-int64.html @@ -25,6 +25,7 @@ + diff --git a/lib/js/test/test-int64.js b/lib/js/test/test-int64.js index 4df87e1d398..cf7e8282b79 100644 --- a/lib/js/test/test-int64.js +++ b/lib/js/test/test-int64.js @@ -86,6 +86,12 @@ QUnit.module('Int64'); for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { assert.ok(EXPECTED_INT64_LIST[i].equals(Int64Test.INT64_LIST[i])); } + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){ + let int64Object = EXPECTED_INT64_LIST[i]; + assert.ok(Int64Test.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object)); + } + console.log('Int64 test -- ends'); }); diff --git a/lib/nodejs/test/int64.test.js b/lib/nodejs/test/int64.test.js index 106e446b11e..27ad28c003f 100644 --- a/lib/nodejs/test/int64.test.js +++ b/lib/nodejs/test/int64.test.js @@ -18,6 +18,7 @@ */ const Int64 = require("node-int64"); +const JSONInt64 = require("json-int64"); const i64types = require("./gen-nodejs-es6/Int64Test_types.js"); const test = require("tape"); @@ -72,6 +73,16 @@ const cases = { for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { assert.ok(EXPECTED_INT64_LIST[i].equals(i64types.INT64_LIST[i])); } + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { + const int64Object = EXPECTED_INT64_LIST[i]; + assert.ok( + i64types.INT64_2_INT64_MAP[ + JSONInt64.toDecimalString(int64Object) + ].equals(int64Object) + ); + } + assert.end(); } }; diff --git a/lib/nodets/test/int64.test.ts b/lib/nodets/test/int64.test.ts index 3ff0d85b470..d209234b50c 100644 --- a/lib/nodets/test/int64.test.ts +++ b/lib/nodets/test/int64.test.ts @@ -18,6 +18,7 @@ */ import Int64 = require("node-int64"); +import JSONInt64 = require('json-int64'); import i64types = require("./gen-nodejs/Int64Test_types"); import test = require("tape"); @@ -72,6 +73,12 @@ const cases = { for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { assert.ok(EXPECTED_INT64_LIST[i].equals(i64types.INT64_LIST[i])); } + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){ + let int64Object = EXPECTED_INT64_LIST[i]; + assert.ok(i64types.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object)); + } + assert.end(); } }; diff --git a/lib/ts/package.json b/lib/ts/package.json index 47eec6277a8..1a1ccdc85a8 100644 --- a/lib/ts/package.json +++ b/lib/ts/package.json @@ -23,7 +23,7 @@ "dependencies": { "bufferutil": "^4.0.1", "jsdoc": "^3.5.5", - "json-int64": "^0.0.3", + "json-int64": "^1.0.0", "nopt": "^4.0.1" }, "types": "./thrift.d.ts" diff --git a/lib/ts/test/test-int64.ts b/lib/ts/test/test-int64.ts index 3ea7919e2c8..254d8d7bfcc 100644 --- a/lib/ts/test/test-int64.ts +++ b/lib/ts/test/test-int64.ts @@ -19,6 +19,7 @@ /* jshint -W100 */ var Int64 = require("node-int64"); +var JSONInt64 = require("json-int64"); import { Int64Test } from "./gen-js/Int64Test_types"; @@ -89,6 +90,12 @@ QUnit.module('Int64'); for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i) { assert.ok(EXPECTED_INT64_LIST[i].equals(Int64Test.INT64_LIST[i])); } + + for (let i = 0; i < EXPECTED_INT64_LIST.length; ++i){ + let int64Object = EXPECTED_INT64_LIST[i]; + assert.ok(Int64Test.INT64_2_INT64_MAP[JSONInt64.toDecimalString(int64Object)].equals(int64Object)); + } + console.log('Int64 test -- ends'); }); diff --git a/package-lock.json b/package-lock.json index 1e089d94eb3..7c39c2a2b59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1223,6 +1223,15 @@ "underscore": "~1.8.3" } }, + "json-int64": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-int64/-/json-int64-1.0.0.tgz", + "integrity": "sha512-yrTg9swToElhEPETLMdZkEzDhbXLs+cxkw/b2rglMPOBlM1DE0utH1EReSMLcnpYJk5iUvD12r0fP2/xHitF5Q==", + "dev": true, + "requires": { + "node-int64": "0.4.0" + } + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", diff --git a/package.json b/package.json index 97b7abf9a1d..b850a71b298 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "eslint-plugin-prettier": "^3.0.0", "istanbul": "^0.4.5", "jsdoc": "^3.5.5", + "json-int64": "^1.0.0", "prettier": "^1.14.3", "tape": "^4.9.0", "utf-8-validate": "^4.0.0", diff --git a/test/Int64Test.thrift b/test/Int64Test.thrift index 7a9ed2ffc64..348cc9c4753 100644 --- a/test/Int64Test.thrift +++ b/test/Int64Test.thrift @@ -32,3 +32,13 @@ const i64 MAX_SIGNED_INT64 = 9223372036854775807 const i64 MIN_SIGNED_INT64 = -9223372036854775808 const list INT64_LIST = [SMALL_INT64, MAX_JS_SAFE_INT64, MIN_JS_SAFE_INT64, MAX_JS_SAFE_PLUS_ONE_INT64, MIN_JS_SAFE_MINUS_ONE_INT64, MAX_SIGNED_INT64, MIN_SIGNED_INT64] + +const map INT64_2_INT64_MAP = { + SMALL_INT64: SMALL_INT64, + MAX_JS_SAFE_INT64: MAX_JS_SAFE_INT64, + MIN_JS_SAFE_INT64: MIN_JS_SAFE_INT64, + MAX_JS_SAFE_PLUS_ONE_INT64: MAX_JS_SAFE_PLUS_ONE_INT64, + MIN_JS_SAFE_MINUS_ONE_INT64: MIN_JS_SAFE_MINUS_ONE_INT64, + MAX_SIGNED_INT64: MAX_SIGNED_INT64, + MIN_SIGNED_INT64: MIN_SIGNED_INT64 + }