diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2015-02-17 11:50:20 -0330 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2015-02-17 11:50:20 -0330 |
commit | 1f67af38bba007582100f6775c5b9fab5b01b626 (patch) | |
tree | 8f96486d0b66e1426883cdd74031b9bcf1f74202 /js/src/Ice/BasicStream.js | |
parent | Fixed demo build failure with VS2012 (diff) | |
download | ice-1f67af38bba007582100f6775c5b9fab5b01b626.tar.bz2 ice-1f67af38bba007582100f6775c5b9fab5b01b626.tar.xz ice-1f67af38bba007582100f6775c5b9fab5b01b626.zip |
ICE-6306 added checks to javascript for byte/short/int
Diffstat (limited to 'js/src/Ice/BasicStream.js')
-rw-r--r-- | js/src/Ice/BasicStream.js | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/js/src/Ice/BasicStream.js b/js/src/Ice/BasicStream.js index b44c10104b1..057b7fd81e7 100644 --- a/js/src/Ice/BasicStream.js +++ b/js/src/Ice/BasicStream.js @@ -2890,6 +2890,23 @@ defineProperty(BasicStream.prototype, "buffer", { get: function() { return this._buf; } }); +var defineBuiltinHelperWithRangeCheck = function(write, read, sz, format, min, max) +{ + var helper = { + write: function(os, v) { return write.call(os, v); }, + read: function(is) { return read.call(is); }, + writeOpt: function(os, tag, v) { os.writeOptValue(tag, format, write, v); }, + readOpt: function(is, tag) { return is.readOptValue(tag, format, read); }, + validate: function(v) { + return v >= min && v <= max; + } + }; + defineProperty(helper, "minWireSize", { + get: function() { return sz; } + }); + return helper; +}; + var defineBuiltinHelper = function(write, read, sz, format) { var helper = { @@ -2905,13 +2922,18 @@ var defineBuiltinHelper = function(write, read, sz, format) }; var stream = BasicStream.prototype; -Ice.ByteHelper = defineBuiltinHelper(stream.writeByte, stream.readByte, 1, Ice.OptionalFormat.F1); -Ice.BoolHelper = defineBuiltinHelper(stream.writeBool, stream.readBool, 1, Ice.OptionalFormat.F1); -Ice.ShortHelper = defineBuiltinHelper(stream.writeShort, stream.readShort, 2, Ice.OptionalFormat.F2); -Ice.IntHelper = defineBuiltinHelper(stream.writeInt, stream.readInt, 4, Ice.OptionalFormat.F4); -Ice.LongHelper = defineBuiltinHelper(stream.writeLong, stream.readLong, 8, Ice.OptionalFormat.F8); +Ice.ByteHelper = + defineBuiltinHelperWithRangeCheck(stream.writeByte, stream.readByte, 1, Ice.OptionalFormat.F1, 0, 255); +Ice.ShortHelper = + defineBuiltinHelperWithRangeCheck(stream.writeShort, stream.readShort, 2, Ice.OptionalFormat.F2, -32768, 32767); +Ice.IntHelper = + defineBuiltinHelperWithRangeCheck(stream.writeInt, stream.readInt, 4, Ice.OptionalFormat.F4, -2147483648, 2147483647); + Ice.FloatHelper = defineBuiltinHelper(stream.writeFloat, stream.readFloat, 4, Ice.OptionalFormat.F4); Ice.DoubleHelper = defineBuiltinHelper(stream.writeDouble, stream.readDouble, 8, Ice.OptionalFormat.F8); + +Ice.BoolHelper = defineBuiltinHelper(stream.writeBool, stream.readBool, 1, Ice.OptionalFormat.F1); +Ice.LongHelper = defineBuiltinHelper(stream.writeLong, stream.readLong, 8, Ice.OptionalFormat.F8); Ice.StringHelper = defineBuiltinHelper(stream.writeString, stream.readString, 1, Ice.OptionalFormat.VSize); Ice.ObjectHelper = { |