diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 2133283..ebc2cad 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -13,7 +13,9 @@ jobs: with: os: 'ubuntu-latest' version: '8, 10, 12, 14, 16, 18, 20, 22' - + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + build-with-zig: strategy: fail-fast: false diff --git a/lib/object.js b/lib/object.js index f3e8048..f534643 100644 --- a/lib/object.js +++ b/lib/object.js @@ -11,7 +11,6 @@ 'use strict'; var util = require('util'); -var has = require('utility').has; exports.DEFAULT_CLASSNAME = { boolean: 'boolean', @@ -167,6 +166,10 @@ function JavaExceptionError(obj, withType) { util.inherits(JavaExceptionError, Error); +function has(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} + exports.isJavaException = function (obj) { if (has(obj, 'detailMessage') && has(obj, 'stackTrace')) { return true; diff --git a/lib/utils.js b/lib/utils.js index 67d0218..7607070 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -9,7 +9,7 @@ 'use strict'; -var debug = require('debug')('hessian.js:utils'); +var debug = require('util').debuglog('hessian.js:utils'); var object = require('./object'); var MAX_INT_8 = exports.MAX_INT_8 = Math.pow(2, 7); diff --git a/lib/v1/decoder.js b/lib/v1/decoder.js index b1e929b..3528418 100644 --- a/lib/v1/decoder.js +++ b/lib/v1/decoder.js @@ -10,7 +10,7 @@ 'use strict'; -var debug = require('debug')('hessian:v1:decoder'); +var debug = require('util').debuglog('hessian:v1:decoder'); var ByteBuffer = require('byte'); var is = require('is-type-of'); var utils = require('../utils'); diff --git a/lib/v1/encoder.js b/lib/v1/encoder.js index c6c3ac7..ad7edd3 100644 --- a/lib/v1/encoder.js +++ b/lib/v1/encoder.js @@ -11,7 +11,7 @@ 'use strict'; var ByteBuffer = require('byte'); -var debug = require('debug')('hessian:v1:encoder'); +var debug = require('util').debuglog('hessian:v1:encoder'); var utils = require('../utils'); var javaObject = require('../object'); var is = require('is-type-of'); diff --git a/lib/v2/decoder.js b/lib/v2/decoder.js index 3706c46..d9cd357 100644 --- a/lib/v2/decoder.js +++ b/lib/v2/decoder.js @@ -16,7 +16,7 @@ var util = require('util'); var is = require('is-type-of'); -var debug = require('debug')('hessian:v2:decoder'); +var debug = require('util').debuglog('hessian:v2:decoder'); var DecoderV1 = require('../v1/decoder'); var utils = require('../utils'); var isJavaException = require('../object').isJavaException; diff --git a/lib/v2/encoder.js b/lib/v2/encoder.js index 9a1bdab..1e6ceaf 100644 --- a/lib/v2/encoder.js +++ b/lib/v2/encoder.js @@ -1,11 +1,8 @@ 'use strict'; -var debug = require('debug')('hessian:v2:encoder'); -var is = require('is-type-of'); +var debug = require('util').debuglog('hessian:v2:encoder'); var util = require('util'); var EncoderV1 = require('../v1/encoder'); -var javaObject = require('../object'); -var utility = require('utility'); var Long = require('long'); var float32Test = require('../utils').float32Test; @@ -82,6 +79,31 @@ proto.writeInt = function (val) { return this; }; +// fork from https://github.com/node-modules/utility/blob/master/src/number.ts#L13 +// http://www.2ality.com/2013/10/safe-integers.html +// http://es6.ruanyifeng.com/#docs/number +const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; +// const MIN_SAFE_INTEGER = -MAX_SAFE_INTEGER; +const MAX_SAFE_INTEGER_STR = String(MAX_SAFE_INTEGER); +const MAX_SAFE_INTEGER_STR_LENGTH = MAX_SAFE_INTEGER_STR.length; + +/** + * Detect a number string can safe convert to Javascript Number. + * + * @param {String} s number format string, like `"123"`, `"-1000123123123123123123"` + * @return {Boolean} + */ +function isSafeNumberString(s) { + if (s[0] === '-') { + s = s.substring(1); + } + if (s.length < MAX_SAFE_INTEGER_STR_LENGTH || + (s.length === MAX_SAFE_INTEGER_STR_LENGTH && s <= MAX_SAFE_INTEGER_STR)) { + return true; + } + return false; +} + /** * encode long * @@ -129,7 +151,7 @@ proto.writeInt = function (val) { */ proto.writeLong = function (val) { if (typeof val === 'string') { - if (!utility.isSafeNumberString(val)) { + if (!isSafeNumberString(val)) { val = Long.fromString(val); } else { val = Number(val); diff --git a/package.json b/package.json index 547836a..8183839 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "lint": "make jshint", "test": "make test", - "ci": "npm run lint && npm run test", + "ci": "npm run lint && make cov", "build::platform": "napi build --cargo-cwd ./lib/v2rust --platform --release ./lib/v2rust/harness/dist" }, "repository": { @@ -33,11 +33,9 @@ "homepage": "https://github.com/node-modules/hessian.js", "dependencies": { "@protobufjs/codegen": "^2.0.4", - "byte": "^1.4.1", - "debug": "^3.2.6", + "byte": "^2.0.0", "is-type-of": "^1.2.1", - "long": "^4.0.0", - "utility": "^1.15.0" + "long": "^4.0.0" }, "devDependencies": { "beautify-benchmark": "^0.2.4",