Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ language: node_js
node_js:
- '5'
- '4'
- '3'
- '2'
- '1'
- '0.12'
- '0.10'
script:
- "npm run ci"
after_script:
Expand Down
4 changes: 2 additions & 2 deletions lib/object.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**!
/**
* hessian.js - lib/object.js
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
7 changes: 5 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**!
/**
* hessian.js - lib/utils.js
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand All @@ -19,6 +19,9 @@ var MIN_SAFE_INT = Long.fromNumber(1 - Math.pow(2, 53));
var MAX_BYTE_TRUNK_SIZE = exports.MAX_BYTE_TRUNK_SIZE = 0x8000;
var MAX_CHAR_TRUNK_SIZE = exports.MAX_CHAR_TRUNK_SIZE = 0x8000;

// Map feature detect
exports.supportES6Map = typeof Map === 'function' && typeof Map.prototype.forEach === 'function';

exports.getSerializer = function (type) {
// get from SERIALIZER_MAP
if (object.SERIALIZER_MAP[type]) {
Expand Down
21 changes: 18 additions & 3 deletions lib/v1/decoder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**!
/**
* hessian.js - lib/v1/decoder.js
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand All @@ -16,6 +16,7 @@ var is = require('is-type-of');
var utils = require('../utils');
var object = require('../object');
var JavaExceptionError = object.JavaExceptionError;
var supportES6Map = require('../utils').supportES6Map;

var BYTE_CODES = {};

Expand Down Expand Up @@ -402,12 +403,22 @@ proto.readObject = function (withType) {
$class: type,
$: {}
};
var isMap = (type.indexOf(object.DEFAULT_CLASSNAME.map) === 0 ||
type.indexOf(object.DEFAULT_CLASSNAME.iMap) === 0) && supportES6Map;

if (isMap) {
Object.defineProperty(result.$, '$map', {
value: new Map(),
enumerable: false,
});
}

this._addRef(result);

// get
var label = this.byteBuffer.getChar();
var key;
var t;

while (label !== 'z') {
this.byteBuffer.position(this.byteBuffer.position() - 1);
Expand All @@ -416,9 +427,13 @@ proto.readObject = function (withType) {
label = this.byteBuffer.getChar();
// property name will auto transfer to a String type.
debug('read object prop: %j with type: %s', key, withType);
if (!/^this\$\d+$/.test(key)) {
t = typeof key;
if ((t === 'string' || t === 'number') && !/^this\$\d+$/.test(key)) {
result.$[key] = value;
}
if (isMap) {
result.$.$map.set(key, value);
}
}
debug('read object finish');

Expand Down
9 changes: 4 additions & 5 deletions lib/v1/encoder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**!
/**
* hessian.js - lib/encoder.js
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand All @@ -15,8 +15,7 @@ var debug = require('debug')('hessian:v1:encoder');
var utils = require('../utils');
var javaObject = require('../object');
var is = require('is-type-of');

var SUPPORT_ES6_MAP = typeof Map === 'function' && typeof Map.prototype.forEach === 'function';
var supportES6Map = require('../utils').supportES6Map;

function Encoder(options) {
options = options || {};
Expand Down Expand Up @@ -265,7 +264,7 @@ proto._writeHashMap = function (obj) {
// hashmap's type is null
this.writeType('');

if (SUPPORT_ES6_MAP && obj instanceof Map) {
if (supportES6Map && obj instanceof Map) {
obj.forEach(function (value, key) {
this.write(key);
this.write(value);
Expand Down
24 changes: 21 additions & 3 deletions lib/v2/decoder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
/**
* hessian.js - lib/v2/decoder.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand All @@ -19,6 +19,7 @@ var debug = require('debug')('hessian:v2:decoder');
var DecoderV1 = require('../v1/decoder');
var utils = require('../utils');
var JavaExceptionError = require('../object').JavaExceptionError;
var supportES6Map = require('../utils').supportES6Map;

var BYTE_CODES = {};

Expand Down Expand Up @@ -714,13 +715,30 @@ utils.addByteCodes(BYTE_CODES, [
proto._readMap = function (map, withType) {
var code = this.byteBuffer.get(this.byteBuffer.position());
map = map || {};

if (supportES6Map) {
Object.defineProperty(map, '$map', {
value: new Map(),
enumerable: false,
});
}

var k;
var v;
var t;
// Z(0x5a) list/map terminator
while (code !== 0x5a) {
k = this.read(withType);
v = this.read(withType);
map[k] = v;
t = typeof k;

if (t === 'string' || t === 'number') {
map[k] = v;
}
if (supportES6Map) {
map.$map.set(k, v);
}

code = this.byteBuffer.get(this.byteBuffer.position());
}

Expand Down
9 changes: 4 additions & 5 deletions lib/v2/encoder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
/**
* hessian.js - lib/v2/encoder.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand All @@ -20,8 +20,7 @@ var util = require('util');
var EncoderV1 = require('../v1/encoder');
var javaObject = require('../object');
var utility = require('utility');

var SUPPORT_ES6_MAP = typeof Map === 'function' && typeof Map.prototype.forEach === 'function';
var supportES6Map = require('../utils').supportES6Map;

function Encoder(options) {
EncoderV1.call(this, options);
Expand Down Expand Up @@ -584,7 +583,7 @@ proto._writeHashMap = function (obj) {

this.byteBuffer.put(0x48); // H

if (SUPPORT_ES6_MAP && obj instanceof Map) {
if (supportES6Map && obj instanceof Map) {
obj.forEach(function (value, key) {
this.write(key);
this.write(value);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"js-to-java": "2",
"jshint": "*",
"mocha": "*",
"should": "5"
"should": "10"
},
"engines": {
"node": ">= 0.10.0"
"node": ">= 0.12.0"
}
}
2 changes: 1 addition & 1 deletion test/array.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**!
/**
* Copyright(c) node-modules and other contributors.
* MIT Licensed
*
Expand Down
4 changes: 2 additions & 2 deletions test/binary.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
/*
* hessian.js - test/binary.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/boolean.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
/**
* hessian.js - test/boolean.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/date.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
/**
* hessian.js - test/date.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/decode.circular.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
/**
* hessian.js - test/decode.circular.test.js
*
* Copyright(c) 2015
* Copyright(c)
*
* Authors:
* tangyao <tangyao@alipay.com> (http://tangyao.me/)
Expand Down
4 changes: 2 additions & 2 deletions test/double.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
/**
* hessian.js - test/double.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/exception.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
/**
* hessian.js - test/exception.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/int.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
/**
* hessian.js - test/int.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/list.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**!
/**
* hessian.js - test/list.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
4 changes: 2 additions & 2 deletions test/long.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
/**
* hessian.js - test/long.test.js
*
* Copyright(c) 2014
* Copyright(c)
* MIT Licensed
*
* Authors:
Expand Down
Loading