diff options
author | Mark Spruiell <mes@zeroc.com> | 2016-04-21 12:57:45 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2016-04-21 12:57:45 -0700 |
commit | d873f0afd752c707b7fe50c217c643ab4b8cdb18 (patch) | |
tree | 6323aa9486b181d0d2dc677f85a213029748650f /js/src | |
parent | Merge remote-tracking branch 'origin/3.6' (diff) | |
download | ice-d873f0afd752c707b7fe50c217c643ab4b8cdb18.tar.bz2 ice-d873f0afd752c707b7fe50c217c643ab4b8cdb18.tar.xz ice-d873f0afd752c707b7fe50c217c643ab4b8cdb18.zip |
ICE-6861 - JavaScript stream changes
Diffstat (limited to 'js/src')
27 files changed, 1649 insertions, 1301 deletions
diff --git a/js/src/Ice/AsyncResult.js b/js/src/Ice/AsyncResult.js index ee75db25e3a..55545393cb7 100644 --- a/js/src/Ice/AsyncResult.js +++ b/js/src/Ice/AsyncResult.js @@ -16,7 +16,7 @@ Ice.__M.require(module, "../Ice/Promise", "../Ice/Protocol", "../Ice/Exception", - "../Ice/BasicStream" + "../Ice/Stream" ]); var AsyncResultBase = Ice.AsyncResultBase; @@ -24,7 +24,7 @@ var Debug = Ice.Debug; var Promise = Ice.Promise; var Protocol = Ice.Protocol; var UserException = Ice.UserException; -var BasicStream = Ice.BasicStream; +var OutputStream = Ice.OutputStream; var AsyncResult = Ice.Class(AsyncResultBase, { __init__: function(com, op, connection, proxy, adapter, completedFn) @@ -41,7 +41,7 @@ var AsyncResult = Ice.Class(AsyncResultBase, { this._completed = completedFn; this._is = null; - this._os = com !== null ? new BasicStream(this._instance, Protocol.currentProtocolEncoding) : null; + this._os = com !== null ? new OutputStream(this._instance, Protocol.currentProtocolEncoding) : null; this._state = 0; this._exception = null; this._sentSynchronously = false; @@ -139,20 +139,20 @@ var AsyncResult = Ice.Class(AsyncResultBase, { }, __startReadParams: function() { - this._is.startReadEncaps(); + this._is.startEncapsulation(); return this._is; }, __endReadParams: function() { - this._is.endReadEncaps(); + this._is.endEncapsulation(); }, __readEmptyParams: function() { - this._is.skipEmptyEncaps(null); + this._is.skipEmptyEncapsulation(null); }, __readParamEncaps: function() { - return this._is.readEncaps(null); + return this._is.readEncapsulation(null); }, __throwUserException: function() { @@ -161,14 +161,14 @@ var AsyncResult = Ice.Class(AsyncResultBase, { { try { - this._is.startReadEncaps(); + this._is.startEncapsulation(); this._is.throwException(); } catch(ex) { if(ex instanceof UserException) { - this._is.endReadEncaps(); + this._is.endEncapsulation(); } throw ex; } diff --git a/js/src/Ice/BatchRequestQueue.js b/js/src/Ice/BatchRequestQueue.js index f28d4d30f4f..deab2209be5 100644 --- a/js/src/Ice/BatchRequestQueue.js +++ b/js/src/Ice/BatchRequestQueue.js @@ -11,13 +11,13 @@ var Ice = require("../Ice/ModuleRegistry").Ice; Ice.__M.require(module, [ "../Ice/Class", - "../Ice/BasicStream", + "../Ice/Stream", "../Ice/Debug", "../Ice/ExUtil", "../Ice/Protocol", ]); -var BasicStream = Ice.BasicStream; +var OutputStream = Ice.OutputStream; var Debug = Ice.Debug; var ExUtil = Ice.ExUtil; var Class = Ice.Class; @@ -30,7 +30,7 @@ var BatchRequestQueue = Class({ { this._batchStreamInUse = false; this._batchRequestNum = 0; - this._batchStream = new BasicStream(instance, Protocol.currentProtocolEncoding); + this._batchStream = new OutputStream(instance, Protocol.currentProtocolEncoding); this._batchStream.writeBlob(Protocol.requestBatchHdr); this._batchMarker = this._batchStream.size; this._exception = null; diff --git a/js/src/Ice/Communicator.js b/js/src/Ice/Communicator.js index 819627bb5b3..f80d3e56576 100644 --- a/js/src/Ice/Communicator.js +++ b/js/src/Ice/Communicator.js @@ -117,19 +117,15 @@ var Communicator = Ice.Class({ }, addObjectFactory: function(factory, id) { - this._instance.servantFactoryManager().addObjectFactory(factory, id); + this._instance.addObjectFactory(factory, id); }, findObjectFactory: function(id) { - return this._instance.servantFactoryManager().findObjectFactory(id); + return this._instance.findObjectFactory(id); }, - addValueFactory: function(factory, id) + getValueFactoryManager: function() { - this._instance.servantFactoryManager().add(factory, id); - }, - findValueFactory: function(id) - { - return this._instance.servantFactoryManager().find(id); + return this._instance.initializationData().valueFactoryManager; }, getImplicitContext: function() { diff --git a/js/src/Ice/ConnectRequestHandler.js b/js/src/Ice/ConnectRequestHandler.js index dce0adb9641..126421c726d 100644 --- a/js/src/Ice/ConnectRequestHandler.js +++ b/js/src/Ice/ConnectRequestHandler.js @@ -13,7 +13,7 @@ Ice.__M.require(module, "../Ice/Class", "../Ice/AsyncResult", "../Ice/AsyncStatus", - "../Ice/BasicStream", + "../Ice/Stream", "../Ice/ConnectionRequestHandler", "../Ice/Debug", "../Ice/ExUtil", @@ -27,7 +27,6 @@ Ice.__M.require(module, var AsyncResult = Ice.AsyncResult; var AsyncStatus = Ice.AsyncStatus; -var BasicStream = Ice.BasicStream; var ConnectionRequestHandler = Ice.ConnectionRequestHandler; var Debug = Ice.Debug; var ExUtil = Ice.ExUtil; diff --git a/js/src/Ice/ConnectionI.js b/js/src/Ice/ConnectionI.js index c368ca3a07f..76c2847da3b 100644 --- a/js/src/Ice/ConnectionI.js +++ b/js/src/Ice/ConnectionI.js @@ -12,7 +12,7 @@ Ice.__M.require(module, [ "../Ice/Class", "../Ice/AsyncStatus", - "../Ice/BasicStream", + "../Ice/Stream", "../Ice/OutgoingAsync", "../Ice/Debug", "../Ice/ExUtil", @@ -32,7 +32,8 @@ Ice.__M.require(module, var AsyncStatus = Ice.AsyncStatus; var AsyncResultBase = Ice.AsyncResultBase; -var BasicStream = Ice.BasicStream; +var InputStream = Ice.InputStream; +var OutputStream = Ice.OutputStream; var BatchRequestQueue = Ice.BatchRequestQueue; var ConnectionFlushBatch = Ice.ConnectionFlushBatch; var Debug = Ice.Debug; @@ -61,7 +62,7 @@ var StateFinished = 6; var MessageInfo = function(instance) { - this.stream = new BasicStream(instance, Protocol.currentProtocolEncoding); + this.stream = new InputStream(instance, Protocol.currentProtocolEncoding); this.invokeNum = 0; this.requestId = 0; @@ -106,9 +107,9 @@ var ConnectionI = Class({ this._sendStreams = []; - this._readStream = new BasicStream(instance, Protocol.currentProtocolEncoding); + this._readStream = new InputStream(instance, Protocol.currentProtocolEncoding); this._readHeader = false; - this._writeStream = new BasicStream(instance, Protocol.currentProtocolEncoding); + this._writeStream = new OutputStream(instance, Protocol.currentProtocolEncoding); this._readStreamPos = -1; this._writeStreamPos = -1; @@ -1411,7 +1412,7 @@ var ConnectionI = Class({ // Before we shut down, we send a close connection // message. // - var os = new BasicStream(this._instance, Protocol.currentProtocolEncoding); + var os = new OutputStream(this._instance, Protocol.currentProtocolEncoding); os.writeBlob(Protocol.magic); Protocol.currentProtocol.__write(os); Protocol.currentProtocolEncoding.__write(os); @@ -1445,7 +1446,7 @@ var ConnectionI = Class({ if(!this._endpoint.datagram()) { - var os = new BasicStream(this._instance, Protocol.currentProtocolEncoding); + var os = new OutputStream(this._instance, Protocol.currentProtocolEncoding); os.writeBlob(Protocol.magic); Protocol.currentProtocol.__write(os); Protocol.currentProtocolEncoding.__write(os); @@ -1636,7 +1637,7 @@ var ConnectionI = Class({ if(message.outAsync !== null) { - TraceUtil.trace("sending asynchronous request", stream, this._logger, this._traceLevels); + TraceUtil.traceOut("sending asynchronous request", stream, this._logger, this._traceLevels); } else { @@ -1699,7 +1700,7 @@ var ConnectionI = Class({ if(message.outAsync) { - TraceUtil.trace("sending asynchronous request", message.stream, this._logger, this._traceLevels); + TraceUtil.traceOut("sending asynchronous request", message.stream, this._logger, this._traceLevels); } else { @@ -1789,9 +1790,9 @@ var ConnectionI = Class({ { if(this._state === StateClosing) { - TraceUtil.trace("received request during closing\n" + - "(ignored by server, client will retry)", - info.stream, this._logger, this._traceLevels); + TraceUtil.traceIn("received request during closing\n" + + "(ignored by server, client will retry)", + info.stream, this._logger, this._traceLevels); } else { @@ -1809,9 +1810,9 @@ var ConnectionI = Class({ { if(this._state === StateClosing) { - TraceUtil.trace("received batch request during closing\n" + - "(ignored by server, client will retry)", - info.stream, this._logger, this._traceLevels); + TraceUtil.traceIn("received batch request during closing\n" + + "(ignored by server, client will retry)", + info.stream, this._logger, this._traceLevels); } else { @@ -1860,8 +1861,8 @@ var ConnectionI = Class({ default: { - TraceUtil.trace("received unknown message\n(invalid, closing connection)", - info.stream, this._logger, this._traceLevels); + TraceUtil.traceIn("received unknown message\n(invalid, closing connection)", + info.stream, this._logger, this._traceLevels); throw new Ice.UnknownMessageException(); } } @@ -2104,7 +2105,7 @@ var OutgoingMessage = Class({ { if(this.adopt) { - var stream = new BasicStream(this.stream.instance, Protocol.currentProtocolEncoding); + var stream = new OutputStream(this.stream.instance, Protocol.currentProtocolEncoding); stream.swap(this.stream); this.stream = stream; this.adopt = false; diff --git a/js/src/Ice/EndpointFactoryManager.js b/js/src/Ice/EndpointFactoryManager.js index 0561cf0a0fa..6c6692ee19f 100644 --- a/js/src/Ice/EndpointFactoryManager.js +++ b/js/src/Ice/EndpointFactoryManager.js @@ -12,7 +12,7 @@ Ice.__M.require(module, [ "../Ice/Class", "../Ice/StringUtil", - "../Ice/BasicStream", + "../Ice/Stream", "../Ice/Debug", "../Ice/OpaqueEndpointI", "../Ice/Protocol", @@ -23,7 +23,8 @@ Ice.__M.require(module, // Local aliases. // var Debug = Ice.Debug; -var BasicStream = Ice.BasicStream; +var InputStream = Ice.InputStream; +var OutputStream = Ice.OutputStream; var EndpointParseException = Ice.EndpointParseException; var OpaqueEndpointI = Ice.OpaqueEndpointI; var Protocol = Ice.Protocol; @@ -113,15 +114,16 @@ var EndpointFactoryManager = Ice.Class({ // and ask the factory to read the endpoint data from that stream to create // the actual endpoint. // - var bs = new BasicStream(this._instance, Protocol.currentProtocolEncoding); - bs.writeShort(ue.type()); - ue.streamWrite(bs); - bs.pos = 0; - bs.readShort(); // type - bs.startReadEncaps(); - var endpoint = this._factories[i].read(bs); - bs.endReadEncaps(); - return endpoint; + var os = new OutputStream(this._instance, Protocol.currentProtocolEncoding); + os.writeShort(ue.type()); + ue.streamWrite(os); + var is = new InputStream(this._instance, Protocol.currentProtocolEncoding, os.buffer); + is.pos = 0; + is.readShort(); // type + is.startEncapsulation(); + var e = this._factories[i].read(is); + is.endEncapsulation(); + return e; } } return ue; // Endpoint is opaque, but we don't have a factory for its type. @@ -137,16 +139,16 @@ var EndpointFactoryManager = Ice.Class({ { if(this._factories[i].type() == type) { - s.startReadEncaps(); + s.startEncapsulation(); e = this._factories[i].read(s); - s.endReadEncaps(); + s.endEncapsulation(); return e; } } - s.startReadEncaps(); + s.startEncapsulation(); e = new OpaqueEndpointI(type); e.initWithStream(s); - s.endReadEncaps(); + s.endEncapsulation(); return e; }, destroy: function() diff --git a/js/src/Ice/EnumBase.js b/js/src/Ice/EnumBase.js index 0ce4b6d6aac..56c6de335cd 100644 --- a/js/src/Ice/EnumBase.js +++ b/js/src/Ice/EnumBase.js @@ -65,7 +65,7 @@ var EnumHelper = Ice.Class({ { this._enumType.__write(os, v); }, - writeOpt: function(os, tag, v) + writeOptional: function(os, tag, v) { this._enumType.__writeOpt(os, tag, v); }, @@ -73,7 +73,7 @@ var EnumHelper = Ice.Class({ { return this._enumType.__read(is); }, - readOpt: function(is, tag) + readOptional: function(is, tag) { return this._enumType.__readOpt(is, tag); } @@ -137,7 +137,7 @@ Slice.defineEnum = function(enumerators) { if(v !== undefined) { - if(os.writeOpt(tag, Ice.OptionalFormat.Size)) + if(os.writeOptional(tag, Ice.OptionalFormat.Size)) { type.__write(os, v); } @@ -145,7 +145,7 @@ Slice.defineEnum = function(enumerators) }; type.__readOpt = function(is, tag) { - return is.readOptEnum(tag, type); + return is.readOptionalEnum(tag, type); }; type.__helper = new EnumHelper(type); diff --git a/js/src/Ice/Exception.js b/js/src/Ice/Exception.js index d7967b0ff8f..3b21ad75662 100644 --- a/js/src/Ice/Exception.js +++ b/js/src/Ice/Exception.js @@ -162,15 +162,15 @@ var UserException = Class(Exception, { }, __write: function(os) { - os.startWriteException(null); + os.startException(null); __writeImpl(this, os, this.__mostDerivedType()); - os.endWriteException(); + os.endException(); }, __read: function(is) { - is.startReadException(); + is.startException(); __readImpl(this, is, this.__mostDerivedType()); - is.endReadException(false); + is.endException(false); }, __usesClasses: function() { @@ -196,12 +196,12 @@ var __writeImpl = function(obj, os, type) return; // Don't marshal anything for Ice.UserException } - os.startWriteSlice(type.__id, -1, type.__parent === UserException); + os.startSlice(type.__id, -1, type.__parent === UserException); if(type.prototype.__writeMemberImpl) { type.prototype.__writeMemberImpl.call(obj, os); } - os.endWriteSlice(); + os.endSlice(); __writeImpl(obj, os, type.__parent); }; @@ -218,12 +218,12 @@ var __readImpl = function(obj, is, type) return; // Don't marshal anything for UserException } - is.startReadSlice(); + is.startSlice(); if(type.prototype.__readMemberImpl) { type.prototype.__readMemberImpl.call(obj, is); } - is.endReadSlice(); + is.endSlice(); __readImpl(obj, is, type.__parent); }; @@ -233,9 +233,9 @@ var __writePreserved = function(os) // For Slice exceptions which are marked "preserved", the implementation of this method // replaces the Ice.Object.prototype.__write method. // - os.startWriteException(this.__slicedData); + os.startException(this.__slicedData); __writeImpl(this, os, this.__mostDerivedType()); - os.endWriteException(); + os.endException(); }; var __readPreserved = function(is) @@ -244,9 +244,9 @@ var __readPreserved = function(is) // For Slice exceptions which are marked "preserved", the implementation of this method // replaces the Ice.Object.prototype.__read method. // - is.startReadException(); + is.startException(); __readImpl(this, is, this.__mostDerivedType()); - this.__slicedData = is.endReadException(true); + this.__slicedData = is.endException(true); }; Slice.defineUserException = function(constructor, base, name, writeImpl, readImpl, preserved, usesClasses) diff --git a/js/src/Ice/IPEndpointI.js b/js/src/Ice/IPEndpointI.js index 8648d1936d3..d27c73c0806 100644 --- a/js/src/Ice/IPEndpointI.js +++ b/js/src/Ice/IPEndpointI.js @@ -38,9 +38,9 @@ var IPEndpointI = Class(Ice.EndpointI, { // streamWrite: function(s) { - s.startWriteEncaps(); + s.startEncapsulation(); this.streamWriteImpl(s); - s.endWriteEncaps(); + s.endEncapsulation(); }, getInfo: function() { diff --git a/js/src/Ice/IncomingAsync.js b/js/src/Ice/IncomingAsync.js index 713d92d51fd..fe54c782876 100644 --- a/js/src/Ice/IncomingAsync.js +++ b/js/src/Ice/IncomingAsync.js @@ -11,7 +11,7 @@ var Ice = require("../Ice/ModuleRegistry").Ice; Ice.__M.require(module, [ "../Ice/Class", - "../Ice/BasicStream", + "../Ice/Stream", "../Ice/BuiltinSequences", "../Ice/Connection", "../Ice/Current", @@ -24,7 +24,7 @@ Ice.__M.require(module, "../Ice/StringUtil" ]); -var BasicStream = Ice.BasicStream; +var OutputStream = Ice.OutputStream; var Current = Ice.Current; var Debug = Ice.Debug; var FormatType = Ice.FormatType; @@ -41,7 +41,7 @@ var IncomingAsync = Ice.Class({ this._compress = compress; if(this._response) { - this._os = new BasicStream(instance, Protocol.currentProtocolEncoding); + this._os = new OutputStream(instance, Protocol.currentProtocolEncoding); } this._connection = connection; @@ -83,7 +83,7 @@ var IncomingAsync = Ice.Class({ Debug.assert(this._os.size == Protocol.headerSize + 4); // Reply status position. Debug.assert(this._current.encoding !== null); // Encoding for reply is known. this._os.writeByte(0); - this._os.startWriteEncaps(this._current.encoding, format); + this._os.startEncapsulation(this._current.encoding, format); return this._os; }, __endWriteParams: function(ok) @@ -94,7 +94,7 @@ var IncomingAsync = Ice.Class({ this._os.pos = Protocol.headerSize + 4; // Reply status position. this._os.writeByte(ok ? Protocol.replyOK : Protocol.replyUserException); this._os.pos = save; - this._os.endWriteEncaps(); + this._os.endEncapsulation(); } }, __writeEmptyParams: function() @@ -104,7 +104,7 @@ var IncomingAsync = Ice.Class({ Debug.assert(this._os.size === Protocol.headerSize + 4); // Reply status position. Debug.assert(this._current.encoding !== null); // Encoding for reply is known. this._os.writeByte(Protocol.replyOK); - this._os.writeEmptyEncaps(this._current.encoding); + this._os.writeEmptyEncapsulation(this._current.encoding); } }, __writeParamEncaps: function(v, ok) @@ -116,11 +116,11 @@ var IncomingAsync = Ice.Class({ this._os.writeByte(ok ? Protocol.replyOK : Protocol.replyUserException); if(v === null || v.length === 0) { - this._os.writeEmptyEncaps(this._current.encoding); + this._os.writeEmptyEncapsulation(this._current.encoding); } else { - this._os.writeEncaps(v); + this._os.writeEncapsulation(v); } } }, @@ -176,9 +176,9 @@ var IncomingAsync = Ice.Class({ { this._os.resize(Protocol.headerSize + 4); // Reply status position. this._os.writeByte(Protocol.replyUserException); - this._os.startWriteEncaps(); + this._os.startEncapsulation(); this._os.writeUserException(ex); - this._os.endWriteEncaps(); + this._os.endEncapsulation(); this._connection.sendResponse(this._os, this._compress); } else @@ -463,14 +463,14 @@ var IncomingAsync = Ice.Class({ { if(ex instanceof Ice.UserException) { - var encoding = this._is.skipEncaps(); // Required for batch requests. + var encoding = this._is.skipEncapsulation(); // Required for batch requests. if(this._response) { this._os.writeByte(Protocol.replyUserException); - this._os.startWriteEncaps(encoding, FormatType.DefaultFormat); + this._os.startEncapsulation(encoding, FormatType.DefaultFormat); this._os.writeUserException(ex); - this._os.endWriteEncaps(); + this._os.endEncapsulation(); this._connection.sendResponse(this._os, this._compress); } else @@ -483,7 +483,7 @@ var IncomingAsync = Ice.Class({ } else { - this._is.skipEncaps(); // Required for batch requests. + this._is.skipEncapsulation(); // Required for batch requests. this.__handleException(ex); return; } @@ -519,7 +519,7 @@ var IncomingAsync = Ice.Class({ // Skip the input parameters, this is required for reading // the next batch request if dispatching batch requests. // - this._is.skipEncaps(); + this._is.skipEncapsulation(); if(servantManager !== null && servantManager.hasServant(this._current.id)) { @@ -568,22 +568,22 @@ var IncomingAsync = Ice.Class({ // Remember the encoding used by the input parameters, we'll // encode the response parameters with the same encoding. // - this._current.encoding = this._is.startReadEncaps(); + this._current.encoding = this._is.startEncapsulation(); return this._is; }, endReadParams: function() { - this._is.endReadEncaps(); + this._is.endEncapsulation(); }, readEmptyParams: function() { this._current.encoding = new Ice.EncodingVersion(); - this._is.skipEmptyEncaps(this._current.encoding); + this._is.skipEmptyEncapsulation(this._current.encoding); }, readParamEncaps: function() { this._current.encoding = new Ice.EncodingVersion(); - return this._is.readEncaps(this._current.encoding); + return this._is.readEncapsulation(this._current.encoding); }, __response: function() { diff --git a/js/src/Ice/Initialize.js b/js/src/Ice/Initialize.js index 954ba48f57e..0f0ef6490a9 100644 --- a/js/src/Ice/Initialize.js +++ b/js/src/Ice/Initialize.js @@ -25,6 +25,7 @@ Ice.InitializationData = function() { this.properties = null; this.logger = null; + this.valueFactoryManager = null; }; Ice.InitializationData.prototype.clone = function() @@ -32,6 +33,7 @@ Ice.InitializationData.prototype.clone = function() var r = new Ice.InitializationData(); r.properties = this.properties; r.logger = this.logger; + r.valueFactoryManager = this.valueFactoryManager; return r; }; diff --git a/js/src/Ice/Instance.js b/js/src/Ice/Instance.js index d856904c412..d6a6d02822e 100644 --- a/js/src/Ice/Instance.js +++ b/js/src/Ice/Instance.js @@ -21,7 +21,7 @@ Ice.__M.require(module, "../Ice/LocatorManager", "../Ice/Logger", "../Ice/ObjectAdapterFactory", - "../Ice/ValueFactoryManager", + "../Ice/ValueFactoryManagerI", "../Ice/OutgoingConnectionFactory", "../Ice/Promise", "../Ice/Properties", @@ -52,7 +52,7 @@ var ImplicitContextI = Ice.ImplicitContextI; var LocatorManager = Ice.LocatorManager; var Logger = Ice.Logger; var ObjectAdapterFactory = Ice.ObjectAdapterFactory; -var ValueFactoryManager = Ice.ValueFactoryManager; +var ValueFactoryManagerI = Ice.ValueFactoryManagerI; var OutgoingConnectionFactory = Ice.OutgoingConnectionFactory; var Promise = Ice.Promise; var Properties = Ice.Properties; @@ -90,11 +90,11 @@ var Instance = Ice.Class({ this._requestHandlerFactory = null; this._proxyFactory = null; this._outgoingConnectionFactory = null; - this._servantFactoryManager = null; this._objectAdapterFactory = null; this._retryQueue = null; this._endpointHostResolver = null; this._endpointFactoryManager = null; + this._objectFactoryMap = null; }, initializationData: function() { @@ -178,16 +178,6 @@ var Instance = Ice.Class({ Debug.assert(this._outgoingConnectionFactory !== null); return this._outgoingConnectionFactory; }, - servantFactoryManager: function() - { - if(this._state === StateDestroyed) - { - throw new Ice.CommunicatorDestroyedException(); - } - - Debug.assert(this._servantFactoryManager !== null); - return this._servantFactoryManager; - }, objectAdapterFactory: function() { if(this._state === StateDestroyed) @@ -381,7 +371,11 @@ var Instance = Ice.Class({ this._endpointFactoryManager.add(wssEndpointFactory); this._outgoingConnectionFactory = new OutgoingConnectionFactory(communicator, this); - this._servantFactoryManager = new ValueFactoryManager(); + + if(this._initData.valueFactoryManager === null) + { + this._initData.valueFactoryManager = new ValueFactoryManagerI(); + } this._objectAdapterFactory = new ObjectAdapterFactory(this, communicator); @@ -500,10 +494,15 @@ var Instance = Ice.Class({ self._timer.destroy(); } - if(self._servantFactoryManager) + if(self._objectFactoryMap !== null) { - self._servantFactoryManager.destroy(); + self._objectFactoryMap.forEach(function(arg, id, factory) + { + factory.destroy(); + }); + self._objectFactoryMap.clear(); } + if(self._routerManager) { self._routerManager.destroy(); @@ -539,7 +538,6 @@ var Instance = Ice.Class({ self._retryQueue = null; self._timer = null; - self._servantFactoryManager = null; self._referenceFactory = null; self._requestHandlerFactory = null; self._proxyFactory = null; @@ -573,6 +571,33 @@ var Instance = Ice.Class({ ); return promise; }, + addObjectFactory: function(factory, id) + { + // + // Create a ValueFactory wrapper around the given ObjectFactory and register the wrapper + // with the value factory manager. This may raise AlreadyRegisteredException. + // + this._initData.valueFactoryManager.add(function(typeId) + { + return factory.create(typeId); + }, id); + + if(this._objectFactoryMap === null) + { + this._objectFactoryMap = new HashMap(); + } + + this._objectFactoryMap.set(id, factory); + }, + findObjectFactory: function(id) + { + var factory = null; + if(this._objectFactoryMap !== null) + { + factory = this._objectFactoryMap.get(id); + } + return factory !== undefined ? factory : null; + } }); Ice.Instance = Instance; diff --git a/js/src/Ice/Object.js b/js/src/Ice/Object.js index 3ccfa70102a..c7dc4fcabf5 100644 --- a/js/src/Ice/Object.js +++ b/js/src/Ice/Object.js @@ -64,15 +64,15 @@ var IceObject = Class({ }, __write: function(os) { - os.startWriteObject(null); + os.startObject(null); __writeImpl(this, os, this.__mostDerivedType()); - os.endWriteObject(); + os.endObject(); }, __read: function(is) { - is.startReadObject(); + is.startObject(); __readImpl(this, is, this.__mostDerivedType()); - is.endReadObject(false); + is.endObject(false); }, ice_instanceof: function(T) { @@ -118,9 +118,9 @@ IceObject.write = function(os, v) os.writeObject(v); }; -IceObject.writeOpt = function(os, tag, v) +IceObject.writeOptional = function(os, tag, v) { - os.writeOptObject(tag, v); + os.writeOptionalObject(tag, v); }; IceObject.read = function(is) @@ -130,10 +130,10 @@ IceObject.read = function(is) return v; }; -IceObject.readOpt = function(is, tag) +IceObject.readOptional = function(is, tag) { var v = { value: undefined }; - is.readOptObject(tag, function(o) { v.value = o; }, IceObject); + is.readOptionalObject(tag, function(o) { v.value = o; }, IceObject); return v; }; @@ -186,12 +186,12 @@ var __writeImpl = function(obj, os, type) return; // Don't marshal anything for IceObject } - os.startWriteSlice(type.__id, type.__compactId, type.__parent === IceObject); + os.startSlice(type.__id, type.__compactId, type.__parent === IceObject); if(type.prototype.__writeMemberImpl) { type.prototype.__writeMemberImpl.call(obj, os); } - os.endWriteSlice(); + os.endSlice(); __writeImpl(obj, os, type.__parent); }; @@ -208,12 +208,12 @@ var __readImpl = function(obj, is, type) return; // Don't marshal anything for IceObject } - is.startReadSlice(); + is.startSlice(); if(type.prototype.__readMemberImpl) { type.prototype.__readMemberImpl.call(obj, is); } - is.endReadSlice(); + is.endSlice(); __readImpl(obj, is, type.__parent); }; @@ -223,9 +223,9 @@ var __writePreserved = function(os) // For Slice classes which are marked "preserved", the implementation of this method // replaces the Ice.Object.prototype.__write method. // - os.startWriteObject(this.__slicedData); + os.startObject(this.__slicedData); __writeImpl(this, os, this.__mostDerivedType()); - os.endWriteObject(); + os.endObject(); }; var __readPreserved = function(is) @@ -234,9 +234,9 @@ var __readPreserved = function(is) // For Slice classes which are marked "preserved", the implementation of this method // replaces the Ice.Object.prototype.__read method. // - is.startReadObject(); + is.startObject(); __readImpl(this, is, this.__mostDerivedType()); - this.__slicedData = is.endReadObject(true); + this.__slicedData = is.endObject(true); }; Ice.Object = IceObject; @@ -275,9 +275,9 @@ Slice.defineObject = function(constructor, base, intfs, scope, ids, compactId, w { os.writeObject(v); }; - obj.writeOpt = function(os, tag, v) + obj.writeOptional = function(os, tag, v) { - os.writeOptObject(tag, v); + os.writeOptionalObject(tag, v); }; obj.read = function(is) { @@ -285,10 +285,10 @@ Slice.defineObject = function(constructor, base, intfs, scope, ids, compactId, w is.readObject(function(o) { v.value = o; }, obj); return v; }; - obj.readOpt = function(is, tag) + obj.readOptional = function(is, tag) { var v = { value: undefined }; - is.readOptObject(tag, function(o) { v.value = o; }, obj); + is.readOptionalObject(tag, function(o) { v.value = o; }, obj); return v; }; diff --git a/js/src/Ice/ObjectPrx.js b/js/src/Ice/ObjectPrx.js index 6e174996b9a..e8003686264 100644 --- a/js/src/Ice/ObjectPrx.js +++ b/js/src/Ice/ObjectPrx.js @@ -459,6 +459,11 @@ var ObjectPrx = Ice.Class({ return false; }, + __write: function(os) + { + this._reference.getIdentity().__write(os); + this._reference.streamWrite(os); + }, __reference: function() { return this._reference; @@ -872,14 +877,14 @@ ObjectPrx.read = function(is) return is.readProxy(this); }; -ObjectPrx.writeOpt = function(os, tag, v) +ObjectPrx.writeOptional = function(os, tag, v) { - os.writeOptProxy(tag, v); + os.writeOptionalProxy(tag, v); }; -ObjectPrx.readOpt = function(is, tag) +ObjectPrx.readOptional = function(is, tag) { - return is.readOptProxy(tag, this); + return is.readOptionalProxy(tag, this); }; ObjectPrx.__instanceof = function(T) @@ -925,9 +930,9 @@ Slice.defineProxy = function(base, staticId, prxInterfaces) prx.checkedCast = ObjectPrx.checkedCast; prx.uncheckedCast = ObjectPrx.uncheckedCast; prx.write = ObjectPrx.write; - prx.writeOpt = ObjectPrx.writeOpt; + prx.writeOptional = ObjectPrx.writeOptional; prx.read = ObjectPrx.read; - prx.readOpt = ObjectPrx.readOpt; + prx.readOptional = ObjectPrx.readOptional; prx.__instanceof = ObjectPrx.__instanceof; diff --git a/js/src/Ice/OpaqueEndpointI.js b/js/src/Ice/OpaqueEndpointI.js index 2fc0bb7d59d..a1d9e83d62c 100644 --- a/js/src/Ice/OpaqueEndpointI.js +++ b/js/src/Ice/OpaqueEndpointI.js @@ -42,9 +42,9 @@ var OpaqueEndpointI = Class(Ice.EndpointI, { // streamWrite: function(s) { - s.startWriteEncaps(this._rawEncoding, Ice.FormatType.DefaultFormat); + s.startEncapsulation(this._rawEncoding, Ice.FormatType.DefaultFormat); s.writeBlob(this._rawBytes); - s.endWriteEncaps(); + s.endEncapsulation(); }, // // Return the endpoint information. @@ -378,8 +378,8 @@ var OpaqueEndpointI = Class(Ice.EndpointI, { }, initWithStream: function(s) { - this._rawEncoding = s.getReadEncoding(); - var sz = s.getReadEncapsSize(); + this._rawEncoding = s.getEncoding(); + var sz = s.getEncapsulationSize(); this._rawBytes = s.readBlob(sz); } }); diff --git a/js/src/Ice/Operation.js b/js/src/Ice/Operation.js index bca38f7afdc..d63f4fb8adf 100644 --- a/js/src/Ice/Operation.js +++ b/js/src/Ice/Operation.js @@ -221,7 +221,7 @@ function unmarshalParams(is, retvalInfo, allParamInfo, optParamInfo, usesClasses for(i = 0; i < optParamInfo.length; ++i) { p = optParamInfo[i]; - v = p.type.readOpt(is, p.tag); + v = p.type.readOptional(is, p.tag); params[p.pos + offset] = v; } @@ -261,7 +261,7 @@ function marshalParams(os, params, retvalInfo, paramInfo, optParamInfo, usesClas for(i = 0; i < optParamInfo.length; ++i) { p = optParamInfo[i]; - p.type.writeOpt(os, p.tag, params[p.pos]); + p.type.writeOptional(os, p.tag, params[p.pos]); } if(usesClasses) @@ -333,7 +333,7 @@ var Upcall = Class({ retvalInfo = this.op.returns; } marshalParams(__os, results, retvalInfo, this.op.outParams, this.op.outParamsOpt, - this.op.returnsClasses); + this.op.returnsClasses); this.incomingAsync.__endWriteParams(true); } }, diff --git a/js/src/Ice/OutgoingAsync.js b/js/src/Ice/OutgoingAsync.js index 2b6214342de..452f2d1210d 100644 --- a/js/src/Ice/OutgoingAsync.js +++ b/js/src/Ice/OutgoingAsync.js @@ -13,7 +13,7 @@ Ice.__M.require(module, "../Ice/Class", "../Ice/AsyncStatus", "../Ice/AsyncResult", - "../Ice/BasicStream", + "../Ice/Stream", "../Ice/Debug", "../Ice/HashMap", "../Ice/RetryException", @@ -27,7 +27,8 @@ Ice.__M.require(module, var AsyncStatus = Ice.AsyncStatus; var AsyncResult = Ice.AsyncResult; -var BasicStream = Ice.BasicStream; +var InputStream = Ice.InputStream; +var OutputStream = Ice.OutputStream; var Debug = Ice.Debug; var HashMap = Ice.HashMap; var RetryException = Ice.RetryException; @@ -41,7 +42,7 @@ var OutgoingAsyncBase = Ice.Class(AsyncResult, { if(communicator !== undefined) { AsyncResult.call(this, communicator, operation, connection, proxy, adapter); - this._os = new BasicStream(this._instance, Protocol.currentProtocolEncoding); + this._os = new OutputStream(this._instance, Protocol.currentProtocolEncoding); } else { @@ -327,7 +328,7 @@ var OutgoingAsync = Ice.Class(ProxyOutgoingAsyncBase, { { if(this._is === null) // _is can already be initialized if the invocation is retried { - this._is = new BasicStream(this._instance, Protocol.currentProtocolEncoding); + this._is = new InputStream(this._instance, Protocol.currentProtocolEncoding); } this._is.swap(istr); replyStatus = this._is.readByte(); @@ -454,26 +455,26 @@ var OutgoingAsync = Ice.Class(ProxyOutgoingAsyncBase, { }, __startWriteParams: function(format) { - this._os.startWriteEncaps(this._encoding, format); + this._os.startEncapsulation(this._encoding, format); return this._os; }, __endWriteParams: function() { - this._os.endWriteEncaps(); + this._os.endEncapsulation(); }, __writeEmptyParams: function() { - this._os.writeEmptyEncaps(this._encoding); + this._os.writeEmptyEncapsulation(this._encoding); }, __writeParamEncaps: function(encaps) { if(encaps === null || encaps.length === 0) { - this._os.writeEmptyEncaps(this._encoding); + this._os.writeEmptyEncapsulation(this._encoding); } else { - this._os.writeEncaps(encaps); + this._os.writeEncapsulation(encaps); } }, __is: function() @@ -482,20 +483,20 @@ var OutgoingAsync = Ice.Class(ProxyOutgoingAsyncBase, { }, __startReadParams: function() { - this._is.startReadEncaps(); + this._is.startEncapsulation(); return this._is; }, __endReadParams: function() { - this._is.endReadEncaps(); + this._is.endEncapsulation(); }, __readEmptyParams: function() { - this._is.skipEmptyEncaps(null); + this._is.skipEmptyEncapsulation(null); }, __readParamEncaps: function() { - return this._is.readEncaps(null); + return this._is.readEncapsulation(null); }, __throwUserException: function() { @@ -504,14 +505,14 @@ var OutgoingAsync = Ice.Class(ProxyOutgoingAsyncBase, { { try { - this._is.startReadEncaps(); + this._is.startEncapsulation(); this._is.throwException(); } catch(ex) { if(ex instanceof Ice.UserException) { - this._is.endReadEncaps(); + this._is.endEncapsulation(); } throw ex; } diff --git a/js/src/Ice/Protocol.js b/js/src/Ice/Protocol.js index 6526810e2db..8f1d35dd0d3 100644 --- a/js/src/Ice/Protocol.js +++ b/js/src/Ice/Protocol.js @@ -253,6 +253,15 @@ Ice.encodingVersionToString = function(v) return majorMinorToString(v.major, v.minor); }; +Protocol.OPTIONAL_END_MARKER = 0xFF; +Protocol.FLAG_HAS_TYPE_ID_STRING = (1<<0); +Protocol.FLAG_HAS_TYPE_ID_INDEX = (1<<1); +Protocol.FLAG_HAS_TYPE_ID_COMPACT = (1<<1 | 1<<0); +Protocol.FLAG_HAS_OPTIONAL_MEMBERS = (1<<2); +Protocol.FLAG_HAS_INDIRECTION_TABLE = (1<<3); +Protocol.FLAG_HAS_SLICE_SIZE = (1<<4); +Protocol.FLAG_IS_LAST_SLICE = (1<<5); + Ice.Protocol = Protocol; module.exports.Ice = Ice; diff --git a/js/src/Ice/ProxyFactory.js b/js/src/Ice/ProxyFactory.js index 8ce6b575fe8..766e57c4ff7 100644 --- a/js/src/Ice/ProxyFactory.js +++ b/js/src/Ice/ProxyFactory.js @@ -123,20 +123,6 @@ var ProxyFactory = Ice.Class({ return null; } }, - proxyToStream: function(proxy, s) - { - if(proxy !== null) - { - var ref = proxy.__reference(); - ref.getIdentity().__write(s); - ref.streamWrite(s); - } - else - { - var ident = new Identity("", ""); - ident.__write(s); - } - }, checkRetryAfterException: function(ex, ref, sleepInterval, cnt) { var traceLevels = this._instance.traceLevels(); @@ -172,7 +158,7 @@ var ProxyFactory = Ice.Class({ if(traceLevels.retry >= 1) { logger.trace(traceLevels.retryCat, "retrying operation call to add proxy to router\n" + - ex.toString()); + ex.toString()); } if(sleepInterval !== null) diff --git a/js/src/Ice/Reference.js b/js/src/Ice/Reference.js index a7899644c6b..e548b6c4117 100644 --- a/js/src/Ice/Reference.js +++ b/js/src/Ice/Reference.js @@ -600,7 +600,7 @@ var ReferenceFactory = Class({ var protocol = null; var encoding = null; - if(!s.getReadEncoding().equals(Ice.Encoding_1_0)) + if(!s.getEncoding().equals(Ice.Encoding_1_0)) { protocol = new Ice.ProtocolVersion(); protocol.__read(s); @@ -1212,7 +1212,7 @@ var Reference = Class({ s.writeBool(this._secure); - if(!s.getWriteEncoding().equals(Ice.Encoding_1_0)) + if(!s.getEncoding().equals(Ice.Encoding_1_0)) { this._protocol.__write(s); this._encoding.__write(s); diff --git a/js/src/Ice/BasicStream.js b/js/src/Ice/Stream.js index 74164089264..caf3d6cf13c 100644 --- a/js/src/Ice/BasicStream.js +++ b/js/src/Ice/Stream.js @@ -26,7 +26,9 @@ __M.require(module, "../Ice/Version", "../Ice/CompactIdRegistry", "../Ice/ArrayUtil", - "../Ice/UnknownSlicedObject" + "../Ice/UnknownSlicedObject", + //"../Ice/Communicator", + //"../Ice/Instance" ]); var Debug = Ice.Debug; @@ -39,21 +41,13 @@ var Protocol = Ice.Protocol; var TraceUtil = Ice.TraceUtil; var ArrayUtil = Ice.ArrayUtil; var SlicedData = Ice.SlicedData; +var Class = Ice.Class; var SliceType = {}; SliceType.NoSlice = 0; SliceType.ObjectSlice = 1; SliceType.ExceptionSlice = 2; -var OPTIONAL_END_MARKER = 0xFF; -var FLAG_HAS_TYPE_ID_STRING = (1<<0); -var FLAG_HAS_TYPE_ID_INDEX = (1<<1); -var FLAG_HAS_TYPE_ID_COMPACT = (1<<1 | 1<<0); -var FLAG_HAS_OPTIONAL_MEMBERS = (1<<2); -var FLAG_HAS_INDIRECTION_TABLE = (1<<3); -var FLAG_HAS_SLICE_SIZE = (1<<4); -var FLAG_IS_LAST_SLICE = (1<<5); - // // Number.isNaN polyfill for compatibility with IE // @@ -64,28 +58,30 @@ Number.isNaN = Number.isNaN || function(value) return typeof value === "number" && isNaN(value); }; -var IndirectPatchEntry = function(index, patcher) +// +// InputStream +// + +var IndirectPatchEntry = function(index, cb) { this.index = index; - this.patcher = patcher; + this.cb = cb; }; -var Class = Ice.Class; - var EncapsDecoder = Class({ __init__: function(stream, encaps, sliceObjects, f) { this._stream = stream; this._encaps = encaps; this._sliceObjects = sliceObjects; - this._servantFactoryManager = f; + this._valueFactoryManager = f; this._patchMap = null; // Lazy initialized, HashMap<int, Patcher[] >() this._unmarshaledMap = new HashMap(); // HashMap<int, Ice.Object>() this._typeIdMap = null; // Lazy initialized, HashMap<int, String> this._typeIdIndex = 0; this._objectList = null; // Lazy initialized. Ice.Object[] }, - readOpt: function() + readOptional: function() { return false; }, @@ -121,7 +117,7 @@ var EncapsDecoder = Class({ // // Try to find a factory registered for the specific type. // - var userFactory = this._servantFactoryManager.find(typeId); + var userFactory = this._valueFactoryManager.find(typeId); var v = null; if(userFactory !== undefined) @@ -135,7 +131,7 @@ var EncapsDecoder = Class({ // if(v === null || v === undefined) { - userFactory = this._servantFactoryManager.find(""); + userFactory = this._valueFactoryManager.find(""); if(userFactory !== undefined) { v = userFactory(typeId); @@ -152,17 +148,18 @@ var EncapsDecoder = Class({ return v; }, - addPatchEntry: function(index, patcher) + addPatchEntry: function(index, cb) { Debug.assert(index > 0); + // - // Check if already un-marshalled the object. If that's the case, + // Check if we have already unmarshaled the object. If that's the case, // just patch the object smart pointer and we're done. // var obj = this._unmarshaledMap.get(index); if(obj !== undefined && obj !== null) { - patcher.call(null, obj); + cb.call(null, obj); return; } @@ -172,9 +169,9 @@ var EncapsDecoder = Class({ } // - // Add patch entry if the object isn't un-marshalled yet, + // Add patch entry if the object isn't unmarshaled yet, // the smart pointer will be patched when the instance is - // un-marshalled. + // unmarshaled. // var l = this._patchMap.get(index); if(l === undefined) @@ -183,20 +180,21 @@ var EncapsDecoder = Class({ // We have no outstanding instances to be patched for this // index, so make a new entry in the patch map. // - l = []; // Patcher[]; + l = []; // ReadObjectCallback[] this._patchMap.set(index, l); } // // Append a patch entry for this instance. // - l.push(patcher); + l.push(cb); }, unmarshal: function(index, v) { var i, length, l; + // - // Add the object to the map of un-marshalled objects, this must + // Add the object to the map of unmarshaled objects, this must // be done before reading the objects (for circular references). // this._unmarshaledMap.set(index, v); @@ -205,15 +203,17 @@ var EncapsDecoder = Class({ // Read the object. // v.__read(this._stream); + if(this._patchMap !== null) { // - // Patch all instances now that the object is un-marshalled. + // Patch all instances now that the object is unmarshaled. // l = this._patchMap.get(index); if(l !== undefined) { Debug.assert(l.length > 0); + // // Patch all pointers that refer to the instance. // @@ -221,6 +221,7 @@ var EncapsDecoder = Class({ { l[i](v); } + // // Clear out the patch map for that index -- there is nothing left // to patch for that index for the time being. @@ -253,7 +254,7 @@ var EncapsDecoder = Class({ { // // Iterate over the object list and invoke ice_postUnmarshal on - // each object. We must do this after all objects have been + // each object. We must do this after all objects have been // unmarshaled in order to ensure that any object data members // have been properly patched. // @@ -266,7 +267,7 @@ var EncapsDecoder = Class({ catch(ex) { this._stream.instance.initializationData().logger.warning( - "exception raised by ice_postUnmarshal:\n" + ex.toString()); + "exception raised by ice_postUnmarshal:\n" + ex.toString()); } } this._objectList = []; @@ -281,9 +282,9 @@ var EncapsDecoder10 = Class(EncapsDecoder, { EncapsDecoder.call(this, stream, encaps, sliceObjects, f); this._sliceType = SliceType.NoSlice; }, - readObject: function(patcher) + readObject: function(cb) { - Debug.assert(patcher !== null); + Debug.assert(cb !== null); // // Object references are encoded as a negative integer in 1.0. @@ -297,11 +298,11 @@ var EncapsDecoder10 = Class(EncapsDecoder, { if(index === 0) { - patcher.call(null, null); + cb.call(null, null); } else { - this.addPatchEntry(index, patcher); + this.addPatchEntry(index, cb); } }, throwException: function() @@ -309,13 +310,14 @@ var EncapsDecoder10 = Class(EncapsDecoder, { Debug.assert(this._sliceType === SliceType.NoSlice); // - // User exception with the 1.0 encoding start with a boolean flag + // User exceptions with the 1.0 encoding start with a boolean flag // that indicates whether or not the exception has classes. // // This allows reading the pending objects even if some part of // the exception was sliced. // var usesClasses = this._stream.readBool(); + this._sliceType = SliceType.ExceptionSlice; this._skipFirstSlice = false; @@ -436,18 +438,7 @@ var EncapsDecoder10 = Class(EncapsDecoder, { }, skipSlice: function() { - if(this._stream.instance.traceLevels().slicing > 0) - { - var logger = this._stream.instance.initializationData().logger; - if(this._sliceType === SliceType.ObjectSlice) - { - TraceUtil.traceSlicing("object", this._typeId, this._stream.instance.traceLevels().slicingCat, logger); - } - else - { - TraceUtil.traceSlicing("exception", this._typeId, this._stream.instance.traceLevels().slicingCat, logger); - } - } + this._stream.traceSkipSlice(this._typeId, this._sliceType); Debug.assert(this._sliceSize >= 4); this._stream.skip(this._sliceSize - 4); }, @@ -514,7 +505,7 @@ var EncapsDecoder10 = Class(EncapsDecoder, { } // - // If object slicing is disabled, stop un-marshalling. + // If object slicing is disabled, stop unmarshaling. // if(!this._sliceObjects) { @@ -530,37 +521,35 @@ var EncapsDecoder10 = Class(EncapsDecoder, { } // - // Un-marshal the object and add-it to the map of un-marshaled objects. + // Un-marshal the object and add-it to the map of unmarshaled objects. // this.unmarshal(index, v); } }); var EncapsDecoder11 = Class(EncapsDecoder, { - __init__: function(stream, encaps, sliceObjects, f) + __init__: function(stream, encaps, sliceObjects, f, r) { EncapsDecoder.call(this, stream, encaps, sliceObjects, f); + this._compactIdResolver = r; this._current = null; this._objectIdIndex = 1; }, - readObject: function(patcher) + readObject: function(cb) { - Debug.assert(patcher !== undefined); var index = this._stream.readSize(); - if(index < 0) { throw new Ice.MarshalException("invalid object id"); } - - if(index === 0) + else if(index === 0) { - if(patcher !== null) + if(cb !== null) { - patcher.call(null, null); + cb.call(null, null); } } - else if(this._current !== null && (this._current.sliceFlags & FLAG_HAS_INDIRECTION_TABLE) !== 0) + else if(this._current !== null && (this._current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) !== 0) { // // When reading an object within a slice and there's an @@ -573,7 +562,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // derive an index into the indirection table that we'll read // at the end of the slice. // - if(patcher !== null) + if(cb !== null) { if(this._current.indirectPatchList === null) // Lazy initialization { @@ -581,18 +570,19 @@ var EncapsDecoder11 = Class(EncapsDecoder, { } var e = new IndirectPatchEntry(); e.index = index - 1; - e.patcher = patcher; + e.cb = cb; this._current.indirectPatchList.push(e); } } else { - this.readInstance(index, patcher); + this.readInstance(index, cb); } }, throwException: function() { Debug.assert(this._current === null); + this.push(SliceType.ExceptionSlice); // @@ -621,7 +611,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // this.skipSlice(); - if((this._current.sliceFlags & FLAG_IS_LAST_SLICE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) !== 0) { if(mostDerivedId.indexOf("::") === 0) { @@ -675,19 +665,24 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // if(this._current.sliceType === SliceType.ObjectSlice) { - if((this._current.sliceFlags & FLAG_HAS_TYPE_ID_COMPACT) === FLAG_HAS_TYPE_ID_COMPACT) // Must be checked 1st! + if((this._current.sliceFlags & Protocol.FLAG_HAS_TYPE_ID_COMPACT) === + Protocol.FLAG_HAS_TYPE_ID_COMPACT) // Must be checked 1st! { this._current.typeId = ""; this._current.compactId = this._stream.readSize(); } - else if((this._current.sliceFlags & (FLAG_HAS_TYPE_ID_INDEX | FLAG_HAS_TYPE_ID_STRING)) !== 0) + else if((this._current.sliceFlags & (Protocol.FLAG_HAS_TYPE_ID_INDEX | + Protocol.FLAG_HAS_TYPE_ID_STRING)) !== 0) { - this._current.typeId = this.readTypeId((this._current.sliceFlags & FLAG_HAS_TYPE_ID_INDEX) !== 0); + this._current.typeId = + this.readTypeId((this._current.sliceFlags & Protocol.FLAG_HAS_TYPE_ID_INDEX) !== 0); this._current.compactId = -1; } else { + // // Only the most derived slice encodes the type ID for the compact format. + // this._current.typeId = ""; this._current.compactId = -1; } @@ -701,7 +696,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // // Read the slice size if necessary. // - if((this._current.sliceFlags & FLAG_HAS_SLICE_SIZE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) !== 0) { this._current.sliceSize = this._stream.readInt(); if(this._current.sliceSize < 4) @@ -713,6 +708,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { { this._current.sliceSize = 0; } + return this._current.typeId; }, endSlice: function() @@ -722,16 +718,16 @@ var EncapsDecoder11 = Class(EncapsDecoder, { indirectionTable = [], length; - if((this._current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) !== 0) { - this._stream.skipOpts(); + this._stream.skipOptionals(); } // // Read the indirection table if one is present and transform the // indirect patch list into patch entries with direct references. // - if((this._current.sliceFlags & FLAG_HAS_INDIRECTION_TABLE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) !== 0) { // // The table is written as a sequence<size> to conserve space. @@ -752,7 +748,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { throw new Ice.MarshalException("empty indirection table"); } if((this._current.indirectPatchList === null || this._current.indirectPatchList.length === 0) && - (this._current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) === 0) + (this._current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) === 0) { throw new Ice.MarshalException("no references to indirection table"); } @@ -770,7 +766,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { { throw new Ice.MarshalException("indirection out of range"); } - this.addPatchEntry(indirectionTable[e.index], e.patcher); + this.addPatchEntry(indirectionTable[e.index], e.cb); } this._current.indirectPatchList.length = 0; } @@ -778,23 +774,11 @@ var EncapsDecoder11 = Class(EncapsDecoder, { }, skipSlice: function() { - if(this._stream.instance.traceLevels().slicing > 0) - { - var logger = this._stream.instance.initializationData().logger; - var slicingCat = this._stream.instance.traceLevels().slicingCat; - if(this._current.sliceType === SliceType.ExceptionSlice) - { - TraceUtil.traceSlicing("exception", this._current.typeId, slicingCat, logger); - } - else - { - TraceUtil.traceSlicing("object", this._current.typeId, slicingCat, logger); - } - } + this._stream.traceSkipSlice(this._current.typeId, this._current.sliceType); var start = this._stream.pos; - if((this._current.sliceFlags & FLAG_HAS_SLICE_SIZE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) !== 0) { Debug.assert(this._current.sliceSize >= 4); this._stream.skip(this._current.sliceSize - 4); @@ -807,13 +791,17 @@ var EncapsDecoder11 = Class(EncapsDecoder, { "(the sender should use the sliced format instead)", this._current.typeId); } - - if(this._current.typeId.indexOf("::") === 0) + else { - throw new Ice.UnknownUserException(this._current.typeId.substring(2)); + if(this._current.typeId.indexOf("::") === 0) + { + throw new Ice.UnknownUserException(this._current.typeId.substring(2)); + } + else + { + throw new Ice.UnknownUserException(this._current.typeId); + } } - - throw new Ice.UnknownUserException(this._current.typeId); } // @@ -822,8 +810,8 @@ var EncapsDecoder11 = Class(EncapsDecoder, { var info = new Ice.SliceInfo(); info.typeId = this._current.typeId; info.compactId = this._current.compactId; - info.hasOptionalMembers = (this._current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) !== 0; - info.isLastSlice = (this._current.sliceFlags & FLAG_IS_LAST_SLICE) !== 0; + info.hasOptionalMembers = (this._current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) !== 0; + info.isLastSlice = (this._current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) !== 0; var b = this._stream._buf; var end = b.position; @@ -849,14 +837,14 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // // Read the indirect object table. We read the instances or their - // IDs if the instance is a reference to an already un-marhsaled + // IDs if the instance is a reference to an already unmarshaled // object. // // The SliceInfo object sequence is initialized only if // readSlicedData is called. // - if((this._current.sliceFlags & FLAG_HAS_INDIRECTION_TABLE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_INDIRECTION_TABLE) !== 0) { var length = this._stream.readAndCheckSeqSize(1); var indirectionTable = []; @@ -870,22 +858,22 @@ var EncapsDecoder11 = Class(EncapsDecoder, { { this._current.indirectionTables.push(null); } + this._current.slices.push(info); }, - readOpt: function(readTag, expectedFormat) + readOptional: function(readTag, expectedFormat) { if(this._current === null) { return this._stream.readOptImpl(readTag, expectedFormat); } - - if((this._current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) !== 0) + else if((this._current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) !== 0) { return this._stream.readOptImpl(readTag, expectedFormat); } return false; }, - readInstance: function(index, patcher) + readInstance: function(index, cb) { Debug.assert(index > 0); @@ -894,9 +882,9 @@ var EncapsDecoder11 = Class(EncapsDecoder, { if(index > 1) { - if(patcher !== null) + if(cb !== null) { - this.addPatchEntry(index, patcher); + this.addPatchEntry(index, cb); } return index; } @@ -905,7 +893,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // // Get the object ID before we start reading slices. If some - // slices are skiped, the indirect object table are still read and + // slices are skipped, the indirect object table are still read and // might read other objects. // index = ++this._objectIdIndex; @@ -923,26 +911,44 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // Translate a compact (numeric) type ID into a string type ID. // this._current.typeId = ""; + if(this._compactIdResolver !== null) + { + try + { + this._current.typeId = this._compactIdResolver.call(null, this._current.compactId); + } + catch(ex) + { + if(!(ex instanceof Ice.LocalException)) + { + throw new Ice.MarshalException("exception in CompactIdResolver for ID " + + this._current.compactId, ex); + } + throw ex; + } + } + if(this._current.typeId.length === 0) { - this._current.typeId = this._stream.getTypeId(this._current.compactId); + this._current.typeId = this._stream.resolveCompactId(this._current.compactId); } } if(this._current.typeId.length > 0) { v = this.newInstance(this._current.typeId); + } + + if(v !== null && v !== undefined) + { // - // We found a factory, we get out of this loop. + // We have an instance, we get out of this loop. // - if(v !== null && v !== undefined) - { - break; - } + break; } // - // If object slicing is disabled, stop un-marshalling. + // If object slicing is disabled, stop unmarshaling. // if(!this._sliceObjects) { @@ -954,11 +960,12 @@ var EncapsDecoder11 = Class(EncapsDecoder, { // Slice off what we don't understand. // this.skipSlice(); + // // If this is the last slice, keep the object as an opaque // UnknownSlicedData object. // - if((this._current.sliceFlags & FLAG_IS_LAST_SLICE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_IS_LAST_SLICE) !== 0) { v = new Ice.UnknownSlicedObject(mostDerivedId); break; @@ -968,9 +975,10 @@ var EncapsDecoder11 = Class(EncapsDecoder, { } // - // Un-marshal the object + // Unmarshal the object. // this.unmarshal(index, v); + if(this._current === null && this._patchMap !== null && this._patchMap.size !== 0) { // @@ -980,10 +988,11 @@ var EncapsDecoder11 = Class(EncapsDecoder, { throw new Ice.MarshalException("index for class received, but no instance"); } - if(patcher !== null) + if(cb !== null) { - patcher.call(null, v); + cb.call(null, v); } + return index; }, readSlicedData: function() @@ -994,6 +1003,7 @@ var EncapsDecoder11 = Class(EncapsDecoder, { { return null; } + // // The _indirectionTables member holds the indirection table for each slice // in _slices. @@ -1046,7 +1056,7 @@ EncapsDecoder11.InstanceData = function(previous) this.sliceType = null; this.skipFirstSlice = false; this.slices = null; // Preserved slices. Ice.SliceInfo[] - this.indirectionTables = null; // int[] + this.indirectionTables = null; // int[][] // Slice attributes this.sliceFlags = 0; @@ -1056,7 +1066,8 @@ EncapsDecoder11.InstanceData = function(previous) this.indirectPatchList = null; // Lazy initialized, IndirectPatchEntry[] }; -var sequencePatcher = function(seq, index, T){ +var sequencePatcher = function(seq, index, T) +{ return function(v) { if(v !== null && !(v instanceof T)) @@ -1067,6 +1078,1069 @@ var sequencePatcher = function(seq, index, T){ }; }; +var ReadEncaps = Class({ + __init__: function() + { + this.start = 0; + this.sz = 0; + this.encoding = null; + this.encoding_1_0 = false; + this.decoder = null; + this.next = null; + }, + reset: function() + { + this.decoder = null; + }, + setEncoding: function(encoding) + { + this.encoding = encoding; + this.encoding_1_0 = encoding.equals(Ice.Encoding_1_0); + } +}); + +var InputStream = Class({ + __init__: function(arg1, arg2, arg3) + { + var args = + { + instance: null, + encoding: null, + bytes: null, + buffer: null + }; + this._checkArgs([arg1, arg2, arg3], args); + this._initialize(args); + }, + _checkArgs: function(arr, args) + { + // + // The constructor can accept a variety of argument combinations: + // + // (<empty>) + // (communicator) + // (instance) + // (encoding) + // (array) + // (buffer) + // (communicator, encoding) + // (instance, encoding) + // (communicator, array) + // (instance, array) + // (communicator, buffer) + // (instance, buffer) + // (communicator, encoding, array) + // (instance, encoding, array) + // (communicator, encoding, buffer) + // (instance, encoding, buffer) + // (encoding, array) + // (encoding, array) + // (encoding, buffer) + // (encoding, buffer) + // + for(i = 0; i < arr.length; ++i) + { + var arg = arr[i]; + if(arg !== null && arg !== undefined) + { + if(arg.constructor === Ice.Communicator) + { + args.instance = arg.instance; + } + else if(arg.constructor === Ice.Instance) + { + args.instance = arg; + } + else if(arg.constructor === Ice.EncodingVersion) + { + args.encoding = arg; + } + else if(arg.constructor === Ice.Buffer) + { + args.buffer = arg; + } + else if(arg.constructor === Array) + { + args.bytes = arg; + } + else + { + throw new Ice.InitializationException("unknown argument to InputStream constructor"); + } + } + } + if(args.buffer !== null && args.bytes !== null) + { + throw new Ice.InitializationException("invalid argument to InputStream constructor"); + } + }, + _initialize: function(args) + { + this._instance = args.instance; + this._encoding = args.encoding; + this._encapsStack = null; + this._encapsCache = null; + this._closure = null; + this._sliceObjects = true; + this._startSeq = -1; + this._sizePos = -1; + this._compactIdResolver = null; + + if(this._instance !== null) + { + if(this._encoding === null) + { + this._encoding = this._instance.defaultsAndOverrides().defaultEncoding; + } + this._traceSlicing = this._instance.traceLevels().slicing > 0; + this._valueFactoryManager = this._instance.initializationData().valueFactoryManager; + this._logger = this._instance.initializationData().logger; + } + else + { + if(this._encoding === null) + { + this._encoding = Protocol.currentEncoding; + } + this._traceSlicing = false; + this._valueFactoryManager = null; + this._logger = null; + } + + if(args.bytes !== null) + { + this._buf = new Ice.Buffer(data); + } + else if(args.buffer !== null) + { + this._buf = args.buffer; + } + else + { + this._buf = new Ice.Buffer(); + } + }, + // + // This function allows this object to be reused, rather than reallocated. + // + reset: function() + { + this._buf.reset(); + this.clear(); + }, + clear: function() + { + if(this._encapsStack !== null) + { + Debug.assert(this._encapsStack.next); + this._encapsStack.next = this._encapsCache; + this._encapsCache = this._encapsStack; + this._encapsCache.reset(); + this._encapsStack = null; + } + + this._startSeq = -1; + this._sliceObjects = true; + }, + swap: function(other) + { + Debug.assert(this._instance === other._instance); + + var tmpBuf, tmpEncoding, tmpTraceSlicing, tmpClosure, tmpSliceObjects, tmpStartSeq, tmpMinSeqSize, tmpSizePos, + tmpVfm, tmpLogger, tmpCompactIdResolver; + + tmpBuf = other._buf; + other._buf = this._buf; + this._buf = tmpBuf; + + tmpEncoding = other._encoding; + other._encoding = this._encoding; + this._encoding = tmpEncoding; + + tmpTraceSlicing = other._traceSlicing; + other._traceSlicing = this._traceSlicing; + this._traceSlicing = tmpTraceSlicing; + + tmpClosure = other._closure; + other._closure = this._closure; + this._closure = tmpClosure; + + tmpSliceObjects = other._sliceObjects; + other._sliceObjects = this._sliceObjects; + this._sliceObjects = tmpSliceObjects; + + // + // Swap is never called for InputStreams that have encapsulations being read/write. However, + // encapsulations might still be set in case marshaling or unmarshaling failed. We just + // reset the encapsulations if there are still some set. + // + this.resetEncapsulation(); + other.resetEncapsulation(); + + tmpStartSeq = other._startSeq; + other._startSeq = this._startSeq; + this._startSeq = tmpStartSeq; + + tmpMinSeqSize = other._minSeqSize; + other._minSeqSize = this._minSeqSize; + this._minSeqSize = tmpMinSeqSize; + + tmpSizePos = other._sizePos; + other._sizePos = this._sizePos; + this._sizePos = tmpSizePos; + + tmpVfm = other._valueFactoryManager; + other._valueFactoryManager = this._valueFactoryManager; + this._valueFactoryManager = tmpVfm; + + tmpLogger = other._logger; + other._logger = this._logger; + this._logger = tmpLogger; + + tmpCompactIdResolver = other._compactIdResolver; + other._compactIdResolver = this._compactIdResolver; + this._compactIdResolver = tmpCompactIdResolver; + }, + resetEncapsulation: function() + { + this._encapsStack = null; + }, + resize: function(sz) + { + this._buf.resize(sz); + this._buf.position = sz; + }, + startObject: function() + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + this._encapsStack.decoder.startInstance(SliceType.ObjectSlice); + }, + endObject: function(preserve) + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + return this._encapsStack.decoder.endInstance(preserve); + }, + startException: function() + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + this._encapsStack.decoder.startInstance(SliceType.ExceptionSlice); + }, + endException: function(preserve) + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + return this._encapsStack.decoder.endInstance(preserve); + }, + startEncapsulation: function() + { + var curr = this._encapsCache; + if(curr !== null) + { + curr.reset(); + this._encapsCache = this._encapsCache.next; + } + else + { + curr = new ReadEncaps(); + } + curr.next = this._encapsStack; + this._encapsStack = curr; + + this._encapsStack.start = this._buf.position; + + // + // I don't use readSize() for encapsulations, because when creating an encapsulation, + // I must know in advance how many bytes the size information will require in the data + // stream. If I use an Int, it is always 4 bytes. For readSize(), it could be 1 or 5 bytes. + // + var sz = this.readInt(); + if(sz < 6) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + if(sz - 4 > this._buf.remaining) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + this._encapsStack.sz = sz; + + var encoding = new Ice.EncodingVersion(); + encoding.__read(this); + Protocol.checkSupportedEncoding(encoding); // Make sure the encoding is supported. + this._encapsStack.setEncoding(encoding); + + return encoding; + }, + endEncapsulation: function() + { + Debug.assert(this._encapsStack !== null); + + if(!this._encapsStack.encoding_1_0) + { + this.skipOptionals(); + if(this._buf.position !== this._encapsStack.start + this._encapsStack.sz) + { + throw new Ice.EncapsulationException(); + } + } + else if(this._buf.position !== this._encapsStack.start + this._encapsStack.sz) + { + if(this._buf.position + 1 !== this._encapsStack.start + this._encapsStack.sz) + { + throw new Ice.EncapsulationException(); + } + + // + // Ice version < 3.3 had a bug where user exceptions with + // class members could be encoded with a trailing byte + // when dispatched with AMD. So we tolerate an extra byte + // in the encapsulation. + // + + try + { + this._buf.get(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + } + + var curr = this._encapsStack; + this._encapsStack = curr.next; + curr.next = this._encapsCache; + this._encapsCache = curr; + this._encapsCache.reset(); + }, + skipEmptyEncapsulation: function(encoding) + { + Debug.assert(encoding !== undefined); + var sz = this.readInt(); + if(sz !== 6) + { + throw new Ice.EncapsulationException(); + } + + var pos = this._buf.position; + if(pos + 2 > this._buf.limit) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + + if(encoding !== null) + { + encoding.__read(this); + } + else + { + this._buf.position = pos + 2; + } + }, + readEncapsulation: function(encoding) + { + Debug.assert(encoding !== undefined); + var sz = this.readInt(); + if(sz < 6) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + + if(sz - 4 > this._buf.remaining) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + + if(encoding !== null) + { + encoding.__read(this); + this._buf.position = this._buf.position - 6; + } + else + { + this._buf.position = this._buf.position - 4; + } + + try + { + return this._buf.getArray(sz); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + getEncoding: function() + { + return this._encapsStack !== null ? this._encapsStack.encoding : this._encoding; + }, + getEncapsulationSize: function() + { + Debug.assert(this._encapsStack !== null); + return this._encapsStack.sz - 6; + }, + skipEncapsulation: function() + { + var sz = this.readInt(); + if(sz < 6) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + var encoding = new Ice.EncodingVersion(); + encoding.__read(this); + try + { + this._buf.position = this._buf.position + sz - 6; + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + return encoding; + }, + startSlice: function() // Returns type ID of next slice + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + return this._encapsStack.decoder.startSlice(); + }, + endSlice: function() + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + this._encapsStack.decoder.endSlice(); + }, + skipSlice: function() + { + Debug.assert(this._encapsStack !== null && this._encapsStack.decoder !== null); + this._encapsStack.decoder.skipSlice(); + }, + readPendingObjects: function() + { + if(this._encapsStack !== null && this._encapsStack.decoder !== null) + { + this._encapsStack.decoder.readPendingObjects(); + } + else if((this._encapsStack !== null && this._encapsStack.encoding_1_0) || + (this._encapsStack === null && this._encoding.equals(Ice.Encoding_1_0))) + { + // + // If using the 1.0 encoding and no objects were read, we + // still read an empty sequence of pending objects if + // requested (i.e.: if this is called). + // + // This is required by the 1.0 encoding, even if no objects + // are written we do marshal an empty sequence if marshaled + // data types use classes. + // + this.skipSize(); + } + }, + readSize: function() + { + try + { + var b = this._buf.get(); + if(b === 255) + { + var v = this._buf.getInt(); + if(v < 0) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + return v; + } + return b; + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readAndCheckSeqSize: function(minSize) + { + var sz = this.readSize(); + + if(sz === 0) + { + return sz; + } + + // + // The _startSeq variable points to the start of the sequence for which + // we expect to read at least _minSeqSize bytes from the stream. + // + // If not initialized or if we already read more data than _minSeqSize, + // we reset _startSeq and _minSeqSize for this sequence (possibly a + // top-level sequence or enclosed sequence it doesn't really matter). + // + // Otherwise, we are reading an enclosed sequence and we have to bump + // _minSeqSize by the minimum size that this sequence will require on + // the stream. + // + // The goal of this check is to ensure that when we start unmarshaling + // a new sequence, we check the minimal size of this new sequence against + // the estimated remaining buffer size. This estimatation is based on + // the minimum size of the enclosing sequences, it's _minSeqSize. + // + if(this._startSeq === -1 || this._buf.position > (this._startSeq + this._minSeqSize)) + { + this._startSeq = this._buf.position; + this._minSeqSize = sz * minSize; + } + else + { + this._minSeqSize += sz * minSize; + } + + // + // If there isn't enough data to read on the stream for the sequence (and + // possibly enclosed sequences), something is wrong with the marshaled + // data: it's claiming having more data that what is possible to read. + // + if(this._startSeq + this._minSeqSize > this._buf.limit) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + + return sz; + }, + readBlob: function(sz) + { + if(this._buf.remaining < sz) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + try + { + return this._buf.getArray(sz); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readOptional: function(tag, expectedFormat) + { + Debug.assert(this._encapsStack !== null); + if(this._encapsStack.decoder !== null) + { + return this._encapsStack.decoder.readOptional(tag, expectedFormat); + } + return this.readOptImpl(tag, expectedFormat); + }, + readOptionalValue: function(tag, format, read) + { + if(this.readOptional(tag, format)) + { + return read.call(this); + } + else + { + return undefined; + } + }, + readByte: function() + { + try + { + return this._buf.get(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readByteSeq: function() + { + return this._buf.getArray(this.readAndCheckSeqSize(1)); + }, + readBool: function() + { + try + { + return this._buf.get() === 1; + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readShort: function() + { + try + { + return this._buf.getShort(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readInt: function() + { + try + { + return this._buf.getInt(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readLong: function() + { + try + { + return this._buf.getLong(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readFloat: function() + { + try + { + return this._buf.getFloat(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readDouble: function() + { + try + { + return this._buf.getDouble(); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readString: function() + { + var len = this.readSize(); + if(len === 0) + { + return ""; + } + // + // Check the buffer has enough bytes to read. + // + if(this._buf.remaining < len) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + + try + { + return this._buf.getString(len); + } + catch(ex) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + }, + readProxy: function(type) + { + return this._instance.proxyFactory().streamToProxy(this, type); + }, + readOptionalProxy: function(tag, type) + { + if(this.readOptional(tag, OptionalFormat.FSize)) + { + this.skip(4); + return this.readProxy(type); + } + else + { + return undefined; + } + }, + readEnum: function(T) + { + var v; + if(this.getEncoding().equals(Ice.Encoding_1_0)) + { + if(T.maxValue < 127) + { + v = this.readByte(); + } + else if(T.maxValue < 32767) + { + v = this.readShort(); + } + else + { + v = this.readInt(); + } + } + else + { + v = this.readSize(); + } + + var e = T.valueOf(v); + if(e === undefined) + { + throw new Ice.MarshalException("enumerator value " + v + " is out of range"); + } + return e; + }, + readOptionalEnum: function(tag, T) + { + if(this.readOptional(tag, OptionalFormat.Size)) + { + return this.readEnum(T); + } + else + { + return undefined; + } + }, + readObject: function(cb, T) + { + this.initEncaps(); + // + // BUGFIX: + // With Chrome on Linux the invocation of readObject on the decoder sometimes + // calls InputStream.readObject with the decoder object as this param. + // Use call instead of directly invoking the method to workaround this bug. + // + this._encapsStack.decoder.readObject.call( + this._encapsStack.decoder, + function(obj) + { + if(obj !== null && !(obj.ice_instanceof(T))) + { + ExUtil.throwUOE(T.ice_staticId(), obj); + } + cb(obj); + }); + }, + readOptionalObject: function(tag, cb, T) + { + if(this.readOptional(tag, OptionalFormat.Class)) + { + this.readObject(cb, T); + } + else + { + cb(undefined); + } + }, + throwException: function() + { + this.initEncaps(); + this._encapsStack.decoder.throwException(); + }, + readOptImpl: function(readTag, expectedFormat) + { + var b, v, format, tag, offset; + + if(this.isEncoding_1_0()) + { + return false; // Optional members aren't supported with the 1.0 encoding. + } + + while(true) + { + if(this._buf.position >= this._encapsStack.start + this._encapsStack.sz) + { + return false; // End of encapsulation also indicates end of optionals. + } + + v = this.readByte(); + + if(v === Protocol.OPTIONAL_END_MARKER) + { + this._buf.position -= 1; // Rewind. + return false; + } + + format = OptionalFormat.valueOf(v & 0x07); // First 3 bits. + tag = v >> 3; + if(tag === 30) + { + tag = this.readSize(); + } + + if(tag > readTag) + { + offset = tag < 30 ? 1 : (tag < 255 ? 2 : 6); // Rewind + this._buf.position -= offset; + return false; // No optional data members with the requested tag. + } + else if(tag < readTag) + { + this.skipOptional(format); // Skip optional data members + } + else + { + if(format !== expectedFormat) + { + throw new Ice.MarshalException("invalid optional data member `" + tag + "': unexpected format"); + } + return true; + } + } + }, + skipOptional: function(format) + { + switch(format) + { + case OptionalFormat.F1: + this.skip(1); + break; + case OptionalFormat.F2: + this.skip(2); + break; + case OptionalFormat.F4: + this.skip(4); + break; + case OptionalFormat.F8: + this.skip(8); + break; + case OptionalFormat.Size: + this.skipSize(); + break; + case OptionalFormat.VSize: + this.skip(this.readSize()); + break; + case OptionalFormat.FSize: + this.skip(this.readInt()); + break; + case OptionalFormat.Class: + this.readObject(null, Ice.Object); + break; + } + }, + skipOptionals: function() + { + var b, v, format; + // + // Skip remaining un-read optional members. + // + while(true) + { + if(this._buf.position >= this._encapsStack.start + this._encapsStack.sz) + { + return; // End of encapsulation also indicates end of optionals. + } + + b = this.readByte(); + v = b < 0 ? b + 256 : b; + if(v === Protocol.OPTIONAL_END_MARKER) + { + return; + } + + format = OptionalFormat.valueOf(v & 0x07); // Read first 3 bits. + if((v >> 3) === 30) + { + this.skipSize(); + } + this.skipOptional(format); + } + }, + skip: function(size) + { + if(size > this._buf.remaining) + { + throw new Ice.UnmarshalOutOfBoundsException(); + } + this._buf.position += size; + }, + skipSize: function() + { + var b = this.readByte(); + if(b === 255) + { + this.skip(4); + } + }, + isEmpty: function() + { + return this._buf.empty(); + }, + expand: function(n) + { + this._buf.expand(n); + }, + createObject: function(id) + { + var obj = null, Class; + try + { + var typeId = id.length > 2 ? id.substr(2).replace(/::/g, ".") : ""; + /*jshint -W061 */ + Class = __M.type(typeId); + /*jshint +W061 */ + if(Class !== undefined) + { + obj = new Class(); + } + } + catch(ex) + { + throw new Ice.NoValueFactoryException("no value factory", id, ex); + } + + return obj; + }, + createUserException: function(id) + { + var userEx = null, Class; + + try + { + var typeId = id.length > 2 ? id.substr(2).replace(/::/g, ".") : ""; + /*jshint -W061 */ + Class = __M.type(typeId); + /*jshint +W061 */ + if(Class !== undefined) + { + userEx = new Class(); + } + } + catch(ex) + { + throw new Ice.MarshalException(ex); + } + + return userEx; + }, + resolveCompactId: function(compactId) + { + var typeId = Ice.CompactIdRegistry.get(compactId); + return typeId === undefined ? "" : typeId; + }, + isEncoding_1_0: function() + { + return this._encapsStack !== null ? this._encapsStack.encoding_1_0 : this._encoding.equals(Ice.Encoding_1_0); + }, + initEncaps: function() + { + if(this._encapsStack === null) // Lazy initialization + { + this._encapsStack = this._encapsCache; + if(this._encapsStack !== null) + { + this._encapsCache = this._encapsCache.next; + } + else + { + this._encapsStack = new ReadEncaps(); + } + this._encapsStack.setEncoding(this._encoding); + this._encapsStack.sz = this._buf.limit; + } + + if(this._encapsStack.decoder === null) // Lazy initialization. + { + if(this._encapsStack.encoding_1_0) + { + this._encapsStack.decoder = new EncapsDecoder10(this, this._encapsStack, this._sliceObjects, + this._valueFactoryManager); + } + else + { + this._encapsStack.decoder = new EncapsDecoder11(this, this._encapsStack, this._sliceObjects, + this._valueFactoryManager, this._compactIdResolver); + } + } + }, + traceSkipSlice: function(typeId, sliceType) + { + if(this._traceSlicing && this._logger !== null) + { + TraceUtil.traceSlicing(sliceType === SliceType.ExceptionSlice ? "exception" : "object", typeId, "Slicing", + this._logger); + } + } +}); + +var defineProperty = Object.defineProperty; + +// +// Sets the value factory manager to use when marshaling value instances. If the stream +// was initialized with a communicator, the communicator's value factory manager will +// be used by default. +// +defineProperty(InputStream.prototype, "valueFactoryManager", { + get: function() { return this._valueFactoryManager; }, + set: function(vfm) { this._valueFactoryManager = vfm !== undefined ? vfm : null; } +}); + +// +// Sets the logger to use when logging trace messages. If the stream +// was initialized with a communicator, the communicator's logger will +// be used by default. +// +defineProperty(InputStream.prototype, "logger", { + get: function() { return this._logger; }, + set: function(l) { this._logger = l !== undefined ? l : null; } +}); + +// +// Sets the compact ID resolver to use when unmarshaling value and exception +// instances. If the stream was initialized with a communicator, the communicator's +// resolver will be used by default. +// +defineProperty(InputStream.prototype, "compactIdResolver", { + get: function() { return this._compactIdResolver; }, + set: function(r) { this._compactIdResolver = r !== undefined ? r : null; } +}); + +// +// Determines the behavior of the stream when extracting Slice objects. +// A Slice object is "sliced" when a factory cannot be found for a Slice type ID. +// The stream's default behavior is to slice objects. +// +// If slicing is disabled and the stream encounters a Slice type ID +// during decoding for which no value factory is installed, it raises +// NoValueFactoryException. +// +defineProperty(InputStream.prototype, "sliceObjects", { + get: function() { return this._sliceObjects; }, + set: function(b) { this._sliceObjects = b; } +}); + +// +// Determines whether the stream logs messages about slicing instances of Slice values. +// +defineProperty(InputStream.prototype, "traceSlicing", { + get: function() { return this._traceSlicing; }, + set: function(b) { this._traceSlicing = b; } +}); + +defineProperty(InputStream.prototype, "pos", { + get: function() { return this._buf.position; }, + set: function(n) { this._buf.position = n; } +}); + +defineProperty(InputStream.prototype, "size", { + get: function() { return this._buf.limit; } +}); + +defineProperty(InputStream.prototype, "instance", { + get: function() { return this._instance; } +}); + +defineProperty(InputStream.prototype, "closure", { + get: function() { return this._type; }, + set: function(type) { this._type = type; } +}); + +defineProperty(InputStream.prototype, "buffer", { + get: function() { return this._buf; } +}); + +// +// OutputStream +// + var EncapsEncoder = Class({ __init__: function(stream, encaps) { @@ -1076,7 +2150,7 @@ var EncapsEncoder = Class({ this._typeIdMap = null; // Lazy initialized. HashMap<String, int> this._typeIdIndex = 0; }, - writeOpt: function() + writeOptional: function() { return false; }, @@ -1096,8 +2170,11 @@ var EncapsEncoder = Class({ { return p; } - this._typeIdMap.set(typeId, ++this._typeIdIndex); - return -1; + else + { + this._typeIdMap.set(typeId, ++this._typeIdIndex); + return -1; + } } }); @@ -1105,10 +2182,8 @@ var EncapsEncoder10 = Class(EncapsEncoder, { __init__: function(stream, encaps) { EncapsEncoder.call(this, stream, encaps); - // Instance attributes this._sliceType = SliceType.NoSlice; this._writeSlice = 0; // Position of the slice data members - // Encapsulation attributes for object marshalling. this._objectIdIndex = 0; this._toBeMarshaledMap = new HashMap(); // HashMap<Ice.Object, Integer>(); }, @@ -1299,7 +2374,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { } // - // If writting an object within a slice and using the sliced + // If writing an object within a slice and using the sliced // format, write an index from the object indirection // table. The indirect object table is encoded at the end of // each slice and is always read (even if the Slice is @@ -1340,7 +2415,8 @@ var EncapsEncoder11 = Class(EncapsEncoder, { } else { - this._current = (this._current.next === null) ? new EncapsEncoder11.InstanceData(this._current) : this._current.next; + this._current = + (this._current.next === null) ? new EncapsEncoder11.InstanceData(this._current) : this._current.next; } this._current.sliceType = sliceType; this._current.firstSlice = true; @@ -1364,11 +2440,12 @@ var EncapsEncoder11 = Class(EncapsEncoder, { this._current.sliceFlags = 0; if(this._encaps.format === FormatType.SlicedFormat) { - this._current.sliceFlags |= FLAG_HAS_SLICE_SIZE; // Encode the slice size if using the sliced format. + // Encode the slice size if using the sliced format. + this._current.sliceFlags |= Protocol.FLAG_HAS_SLICE_SIZE; } if(last) { - this._current.sliceFlags |= FLAG_IS_LAST_SLICE; // This is the last slice. + this._current.sliceFlags |= Protocol.FLAG_IS_LAST_SLICE; // This is the last slice. } this._stream.writeByte(0); // Placeholder for the slice flags @@ -1388,7 +2465,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { { if(compactId >= 0) { - this._current.sliceFlags |= FLAG_HAS_TYPE_ID_COMPACT; + this._current.sliceFlags |= Protocol.FLAG_HAS_TYPE_ID_COMPACT; this._stream.writeSize(compactId); } else @@ -1396,12 +2473,12 @@ var EncapsEncoder11 = Class(EncapsEncoder, { var index = this.registerTypeId(typeId); if(index < 0) { - this._current.sliceFlags |= FLAG_HAS_TYPE_ID_STRING; + this._current.sliceFlags |= Protocol.FLAG_HAS_TYPE_ID_STRING; this._stream.writeString(typeId); } else { - this._current.sliceFlags |= FLAG_HAS_TYPE_ID_INDEX; + this._current.sliceFlags |= Protocol.FLAG_HAS_TYPE_ID_INDEX; this._stream.writeSize(index); } } @@ -1412,7 +2489,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { this._stream.writeString(typeId); } - if((this._current.sliceFlags & FLAG_HAS_SLICE_SIZE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) !== 0) { this._stream.writeInt(0); // Placeholder for the slice length. } @@ -1429,15 +2506,15 @@ var EncapsEncoder11 = Class(EncapsEncoder, { // were encoded. Note that the optional members are encoded before // the indirection table and are included in the slice size. // - if((this._current.sliceFlags & FLAG_HAS_OPTIONAL_MEMBERS) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_OPTIONAL_MEMBERS) !== 0) { - this._stream.writeByte(OPTIONAL_END_MARKER); + this._stream.writeByte(Protocol.OPTIONAL_END_MARKER); } // // Write the slice length if necessary. // - if((this._current.sliceFlags & FLAG_HAS_SLICE_SIZE) !== 0) + if((this._current.sliceFlags & Protocol.FLAG_HAS_SLICE_SIZE) !== 0) { sz = this._stream.pos - this._current.writeSlice + 4; this._stream.rewriteInt(sz, this._current.writeSlice - 4); @@ -1449,7 +2526,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { if(this._current.indirectionTable !== null && this._current.indirectionTable.length !== 0) { Debug.assert(this._encaps.format === FormatType.SlicedFormat); - this._current.sliceFlags |= FLAG_HAS_INDIRECTION_TABLE; + this._current.sliceFlags |= Protocol.FLAG_HAS_INDIRECTION_TABLE; // // Write the indirection object table. @@ -1468,7 +2545,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { // this._stream.rewriteByte(this._current.sliceFlags, this._current.sliceFlagsPos); }, - writeOpt: function(tag, format) + writeOptional: function(tag, format) { if(this._current === null) { @@ -1477,7 +2554,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { if(this._stream.writeOptImpl(tag, format)) { - this._current.sliceFlags |= FLAG_HAS_OPTIONAL_MEMBERS; + this._current.sliceFlags |= Protocol.FLAG_HAS_OPTIONAL_MEMBERS; return true; } @@ -1513,7 +2590,7 @@ var EncapsEncoder11 = Class(EncapsEncoder, { if(info.hasOptionalMembers) { - this._current.sliceFlags |= FLAG_HAS_OPTIONAL_MEMBERS; + this._current.sliceFlags |= Protocol.FLAG_HAS_OPTIONAL_MEMBERS; } // @@ -1593,27 +2670,6 @@ EncapsEncoder11.InstanceData = function(previous) this.indirectionMap = null; // HashMap<Ice.Object, int> }; -var ReadEncaps = Class({ - __init__: function() - { - this.start = 0; - this.sz = 0; - this.encoding = null; - this.encoding_1_0 = false; - this.decoder = null; - this.next = null; - }, - reset: function() - { - this.decoder = null; - }, - setEncoding: function(encoding) - { - this.encoding = encoding; - this.encoding_1_0 = encoding.equals(Ice.Encoding_1_0); - } -}); - var WriteEncaps = Class({ __init__: function() { @@ -1635,35 +2691,70 @@ var WriteEncaps = Class({ } }); -var BasicStream = Class({ - __init__: function(instance, encoding, data) +var OutputStream = Class({ + __init__: function(arg1, arg2) { - this._instance = instance; - this._closure = null; - this._encoding = encoding; + this._instance = null; + this._encoding = null; - this._readEncapsStack = null; - this._writeEncapsStack = null; - this._readEncapsCache = null; - this._writeEncapsCache = null; + if(arg1 !== undefined && arg1 !== null) + { + if(arg1.constructor == Ice.Communicator) + { + this._instance = arg1.instance; + } + else if(arg1.constructor == Ice.Instance) + { + this._instance = arg1; + } + else if(arg1.constructor == Ice.EncodingVersion) + { + this._encoding = arg1; + } + else + { + throw new Ice.InitializationException("unknown argument to OutputStream constructor"); + } + } - this._sliceObjects = true; + if(arg2 !== undefined && arg2 !== null) + { + if(arg2.constructor == Ice.EncodingVersion) + { + this._encoding = arg2; + } + else + { + throw new Ice.InitializationException("unknown argument to OutputStream constructor"); + } + } - this._startSeq = -1; - this._sizePos = -1; + this._buf = new Ice.Buffer(); + + this._closure = null; - if(data !== undefined) + this._encapsStack = null; + this._encapsCache = null; + + if(this._instance !== null) { - this._buf = new Ice.Buffer(data); + if(this._encoding === null) + { + this._encoding = this._instance.defaultsAndOverrides().defaultEncoding; + } + this._format = this._instance.defaultsAndOverrides().defaultFormat; } else { - this._buf = new Ice.Buffer(); + if(this._encoding === null) + { + this._encoding = Protocol.currentEncoding; + } + this._format = FormatType.CompactFormat; } }, // - // This function allows this object to be reused, rather than - // reallocated. + // This function allows this object to be reused, rather than reallocated. // reset: function() { @@ -1672,64 +2763,49 @@ var BasicStream = Class({ }, clear: function() { - if(this._readEncapsStack !== null) + if(this._encapsStack !== null) { - Debug.assert(this._readEncapsStack.next); - this._readEncapsStack.next = this._readEncapsCache; - this._readEncapsCache = this._readEncapsStack; - this._readEncapsCache.reset(); - this._readEncapsStack = null; + Debug.assert(this._encapsStack.next); + this._encapsStack.next = this._encapsCache; + this._encapsCache = this._encapsStack; + this._encapsCache.reset(); + this._encapsStack = null; } - - if(this._writeEncapsStack !== null) - { - Debug.assert(this._writeEncapsStack.next); - this._writeEncapsStack.next = this._writeEncapsCache; - this._writeEncapsCache = this._writeEncapsStack; - this._writeEncapsCache.reset(); - this._writeEncapsStack = null; - } - this._startSeq = -1; - this._sliceObjects = true; + }, + finished: function() + { + var buf = this.prepareWrite(); + return buf.getArray(this.size); }, swap: function(other) { Debug.assert(this._instance === other._instance); - var tmpBuf, tmpClosure, tmpStartSeq, tmpMinSeqSize, tmpSizePos; + var tmpBuf, tmpEncoding, tmpClosure; tmpBuf = other._buf; other._buf = this._buf; this._buf = tmpBuf; + tmpEncoding = other._encoding; + other._encoding = this._encoding; + this._encoding = tmpEncoding; + tmpClosure = other._closure; other._closure = this._closure; this._closure = tmpClosure; // - // Swap is never called for BasicStreams that have encapsulations being read/write. However, - // encapsulations might still be set in case marshalling or un-marshalling failed. We just + // Swap is never called for streams that have encapsulations being written. However, + // encapsulations might still be set in case marshaling failed. We just // reset the encapsulations if there are still some set. // - this.resetEncaps(); - other.resetEncaps(); - - tmpStartSeq = other._startSeq; - other._startSeq = this._startSeq; - this._startSeq = tmpStartSeq; - - tmpMinSeqSize = other._minSeqSize; - other._minSeqSize = this._minSeqSize; - this._minSeqSize = tmpMinSeqSize; - - tmpSizePos = other._sizePos; - other._sizePos = this._sizePos; - this._sizePos = tmpSizePos; + this.resetEncapsulation(); + other.resetEncapsulation(); }, - resetEncaps: function() + resetEncapsulation: function() { - this._readEncapsStack = null; - this._writeEncapsStack = null; + this._encapsStack = null; }, resize: function(sz) { @@ -1741,47 +2817,27 @@ var BasicStream = Class({ this._buf.position = 0; return this._buf; }, - startWriteObject: function(data) - { - Debug.assert(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null); - this._writeEncapsStack.encoder.startInstance(SliceType.ObjectSlice, data); - }, - endWriteObject: function() + startObject: function(data) { - Debug.assert(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null); - this._writeEncapsStack.encoder.endInstance(); + Debug.assert(this._encapsStack !== null && this._encapsStack.encoder !== null); + this._encapsStack.encoder.startInstance(SliceType.ObjectSlice, data); }, - startReadObject: function() + endObject: function() { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - this._readEncapsStack.decoder.startInstance(SliceType.ObjectSlice); + Debug.assert(this._encapsStack !== null && this._encapsStack.encoder !== null); + this._encapsStack.encoder.endInstance(); }, - endReadObject: function(preserve) + startException: function(data) { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - return this._readEncapsStack.decoder.endInstance(preserve); + Debug.assert(this._encapsStack !== null && this._encapsStack.encoder !== null); + this._encapsStack.encoder.startInstance(SliceType.ExceptionSlice, data); }, - startWriteException: function(data) + endException: function() { - Debug.assert(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null); - this._writeEncapsStack.encoder.startInstance(SliceType.ExceptionSlice, data); + Debug.assert(this._encapsStack !== null && this._encapsStack.encoder !== null); + this._encapsStack.encoder.endInstance(); }, - endWriteException: function() - { - Debug.assert(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null); - this._writeEncapsStack.encoder.endInstance(); - }, - startReadException: function() - { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - this._readEncapsStack.decoder.startInstance(SliceType.ExceptionSlice); - }, - endReadException: function(preserve) - { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - return this._readEncapsStack.decoder.endInstance(preserve); - }, - startWriteEncaps: function(encoding, format) + startEncapsulation: function(encoding, format) { // // If no encoding version is specified, use the current write @@ -1791,10 +2847,10 @@ var BasicStream = Class({ if(encoding === undefined) { - if(this._writeEncapsStack !== null) + if(this._encapsStack !== null) { - encoding = this._writeEncapsStack.encoding; - format = this._writeEncapsStack.format; + encoding = this._encapsStack.encoding; + format = this._encapsStack.format; } else { @@ -1805,57 +2861,48 @@ var BasicStream = Class({ Protocol.checkSupportedEncoding(encoding); - var curr = this._writeEncapsCache; + var curr = this._encapsCache; if(curr !== null) { curr.reset(); - this._writeEncapsCache = this._writeEncapsCache.next; + this._encapsCache = this._encapsCache.next; } else { curr = new WriteEncaps(); } - curr.next = this._writeEncapsStack; - this._writeEncapsStack = curr; + curr.next = this._encapsStack; + this._encapsStack = curr; - this._writeEncapsStack.format = format; - this._writeEncapsStack.setEncoding(encoding); - this._writeEncapsStack.start = this._buf.limit; + this._encapsStack.format = format; + this._encapsStack.setEncoding(encoding); + this._encapsStack.start = this._buf.limit; this.writeInt(0); // Placeholder for the encapsulation length. - this._writeEncapsStack.encoding.__write(this); + this._encapsStack.encoding.__write(this); }, - endWriteEncaps: function() + endEncapsulation: function() { - Debug.assert(this._writeEncapsStack); + Debug.assert(this._encapsStack); // Size includes size and version. - var start = this._writeEncapsStack.start; - + var start = this._encapsStack.start; var sz = this._buf.limit - start; this._buf.putIntAt(start, sz); - var curr = this._writeEncapsStack; - this._writeEncapsStack = curr.next; - curr.next = this._writeEncapsCache; - this._writeEncapsCache = curr; - this._writeEncapsCache.reset(); + var curr = this._encapsStack; + this._encapsStack = curr.next; + curr.next = this._encapsCache; + this._encapsCache = curr; + this._encapsCache.reset(); }, - endWriteEncapsChecked: function() // Used by public stream API. - { - if(this._writeEncapsStack === null) - { - throw new Ice.EncapsulationException("not in an encapsulation"); - } - this.endWriteEncaps(); - }, - writeEmptyEncaps: function(encoding) + writeEmptyEncapsulation: function(encoding) { Protocol.checkSupportedEncoding(encoding); this.writeInt(6); // Size encoding.__write(this); }, - writeEncaps: function(v) + writeEncapsulation: function(v) { if(v.length < 6) { @@ -1864,241 +2911,28 @@ var BasicStream = Class({ this.expand(v.length); this._buf.putArray(v); }, - getWriteEncoding: function() - { - return this._writeEncapsStack !== null ? this._writeEncapsStack.encoding : this._encoding; - }, - startReadEncaps: function() - { - var curr = this._readEncapsCache; - if(curr !== null) - { - curr.reset(); - this._readEncapsCache = this._readEncapsCache.next; - } - else - { - curr = new ReadEncaps(); - } - curr.next = this._readEncapsStack; - this._readEncapsStack = curr; - - this._readEncapsStack.start = this._buf.position; - - // - // I don't use readSize() and writeSize() for encapsulations, - // because when creating an encapsulation, I must know in advance - // how many bytes the size information will require in the data - // stream. If I use an Int, it is always 4 bytes. For - // readSize()/writeSize(), it could be 1 or 5 bytes. - // - var sz = this.readInt(); - if(sz < 6) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - if(sz - 4 > this._buf.remaining) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - this._readEncapsStack.sz = sz; - - var encoding = new Ice.EncodingVersion(); - encoding.__read(this); - Protocol.checkSupportedEncoding(encoding); // Make sure the encoding is supported. - this._readEncapsStack.setEncoding(encoding); - - return encoding; - }, - endReadEncaps: function() - { - Debug.assert(this._readEncapsStack !== null); - - if(!this._readEncapsStack.encoding_1_0) - { - this.skipOpts(); - if(this._buf.position !== this._readEncapsStack.start + this._readEncapsStack.sz) - { - throw new Ice.EncapsulationException(); - } - } - else if(this._buf.position !== this._readEncapsStack.start + this._readEncapsStack.sz) - { - if(this._buf.position + 1 !== this._readEncapsStack.start + this._readEncapsStack.sz) - { - throw new Ice.EncapsulationException(); - } - - // - // Ice version < 3.3 had a bug where user exceptions with - // class members could be encoded with a trailing byte - // when dispatched with AMD. So we tolerate an extra byte - // in the encapsulation. - // - - try - { - this._buf.get(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - } - - var curr = this._readEncapsStack; - this._readEncapsStack = curr.next; - curr.next = this._readEncapsCache; - this._readEncapsCache = curr; - this._readEncapsCache.reset(); - }, - skipEmptyEncaps: function(encoding) - { - Debug.assert(encoding !== undefined); - var sz = this.readInt(); - if(sz !== 6) - { - throw new Ice.EncapsulationException(); - } - - var pos = this._buf.position; - if(pos + 2 > this._buf.limit) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - - if(encoding !== null) - { - encoding.__read(this); - } - else - { - this._buf.position = pos + 2; - } - }, - endReadEncapsChecked: function() // Used by public stream API. + getEncoding: function() { - if(this._readEncapsStack === null) - { - throw new Ice.EncapsulationException("not in an encapsulation"); - } - this.endReadEncaps(); - }, - readEncaps: function(encoding) - { - Debug.assert(encoding !== undefined); - var sz = this.readInt(); - if(sz < 6) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - - if(sz - 4 > this._buf.remaining) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - - if(encoding !== null) - { - encoding.__read(this); - this._buf.position = this._buf.position - 6; - } - else - { - this._buf.position = this._buf.position - 4; - } - - try - { - return this._buf.getArray(sz); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, - getReadEncoding: function() - { - return this._readEncapsStack !== null ? this._readEncapsStack.encoding : this._encoding; - }, - getReadEncapsSize: function() - { - Debug.assert(this._readEncapsStack !== null); - return this._readEncapsStack.sz - 6; + return this._encapsStack !== null ? this._encapsStack.encoding : this._encoding; }, - skipEncaps: function() - { - var sz = this.readInt(); - if(sz < 6) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - var encoding = new Ice.EncodingVersion(); - encoding.__read(this); - try - { - this._buf.position = this._buf.position + sz - 6; - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - return encoding; - }, - startWriteSlice: function(typeId, compactId, last) - { - Debug.assert(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null); - this._writeEncapsStack.encoder.startSlice(typeId, compactId, last); - }, - endWriteSlice: function() - { - Debug.assert(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null); - this._writeEncapsStack.encoder.endSlice(); - }, - startReadSlice: function() // Returns type ID of next slice - { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - return this._readEncapsStack.decoder.startSlice(); - }, - endReadSlice: function() - { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - this._readEncapsStack.decoder.endSlice(); - }, - skipSlice: function() + startSlice: function(typeId, compactId, last) { - Debug.assert(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null); - this._readEncapsStack.decoder.skipSlice(); + Debug.assert(this._encapsStack !== null && this._encapsStack.encoder !== null); + this._encapsStack.encoder.startSlice(typeId, compactId, last); }, - readPendingObjects: function() + endSlice: function() { - if(this._readEncapsStack !== null && this._readEncapsStack.decoder !== null) - { - this._readEncapsStack.decoder.readPendingObjects(); - } - else if((this._readEncapsStack !== null && this._readEncapsStack.encoding_1_0) || - (this._readEncapsStack === null && this._encoding.equals(Ice.Encoding_1_0))) - { - // - // If using the 1.0 encoding and no objects were read, we - // still read an empty sequence of pending objects if - // requested (i.e.: if this is called). - // - // This is required by the 1.0 encoding, even if no objects - // are written we do marshal an empty sequence if marshaled - // data types use classes. - // - this.skipSize(); - } + Debug.assert(this._encapsStack !== null && this._encapsStack.encoder !== null); + this._encapsStack.encoder.endSlice(); }, writePendingObjects: function() { - if(this._writeEncapsStack !== null && this._writeEncapsStack.encoder !== null) + if(this._encapsStack !== null && this._encapsStack.encoder !== null) { - this._writeEncapsStack.encoder.writePendingObjects(); + this._encapsStack.encoder.writePendingObjects(); } - else if((this._writeEncapsStack !== null && this._writeEncapsStack.encoding_1_0) || - (this._writeEncapsStack === null && this._encoding.equals(Ice.Encoding_1_0))) + else if((this._encapsStack !== null && this._encapsStack.encoding_1_0) || + (this._encapsStack === null && this._encoding.equals(Ice.Encoding_1_0))) { // // If using the 1.0 encoding and no objects were written, we @@ -2126,75 +2960,6 @@ var BasicStream = Class({ this._buf.put(v); } }, - readSize: function() - { - try - { - var b = this._buf.get(); - if(b === 255) - { - var v = this._buf.getInt(); - if(v < 0) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - return v; - } - return b; - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, - readAndCheckSeqSize: function(minSize) - { - var sz = this.readSize(); - - if(sz === 0) - { - return sz; - } - - // - // The _startSeq variable points to the start of the sequence for which - // we expect to read at least _minSeqSize bytes from the stream. - // - // If not initialized or if we already read more data than _minSeqSize, - // we reset _startSeq and _minSeqSize for this sequence (possibly a - // top-level sequence or enclosed sequence it doesn't really matter). - // - // Otherwise, we are reading an enclosed sequence and we have to bump - // _minSeqSize by the minimum size that this sequence will require on - // the stream. - // - // The goal of this check is to ensure that when we start un-marshalling - // a new sequence, we check the minimal size of this new sequence against - // the estimated remaining buffer size. This estimatation is based on - // the minimum size of the enclosing sequences, it's _minSeqSize. - // - if(this._startSeq === -1 || this._buf.position > (this._startSeq + this._minSeqSize)) - { - this._startSeq = this._buf.position; - this._minSeqSize = sz * minSize; - } - else - { - this._minSeqSize += sz * minSize; - } - - // - // If there isn't enough data to read on the stream for the sequence (and - // possibly enclosed sequences), something is wrong with the marshalled - // data: it's claiming having more data that what is possible to read. - // - if(this._startSeq + this._minSeqSize > this._buf.limit) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - - return sz; - }, startSize: function() { var pos = this._buf.position; @@ -2215,61 +2980,26 @@ var BasicStream = Class({ this.expand(v.length); this._buf.putArray(v); }, - readBlob: function(sz) - { - if(this._buf.remaining < sz) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - try - { - return this._buf.getArray(sz); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, // Read/write format and tag for optionals - writeOpt: function(tag, format) + writeOptional: function(tag, format) { - Debug.assert(this._writeEncapsStack !== null); - if(this._writeEncapsStack.encoder !== null) + Debug.assert(this._encapsStack !== null); + if(this._encapsStack.encoder !== null) { - return this._writeEncapsStack.encoder.writeOpt(tag, format); + return this._encapsStack.encoder.writeOptional(tag, format); } return this.writeOptImpl(tag, format); }, - readOpt: function(tag, expectedFormat) - { - Debug.assert(this._readEncapsStack !== null); - if(this._readEncapsStack.decoder !== null) - { - return this._readEncapsStack.decoder.readOpt(tag, expectedFormat); - } - return this.readOptImpl(tag, expectedFormat); - }, - writeOptValue: function(tag, format, write, v) + writeOptionalValue: function(tag, format, write, v) { if(v !== undefined) { - if(this.writeOpt(tag, format)) + if(this.writeOptional(tag, format)) { write.call(this, v); } } }, - readOptValue: function(tag, format, read) - { - if(this.readOpt(tag, format)) - { - return read.call(this); - } - else - { - return undefined; - } - }, writeByte: function(v) { this.expand(1); @@ -2279,17 +3009,6 @@ var BasicStream = Class({ { this._buf.putAt(dest, v); }, - readByte: function() - { - try - { - return this._buf.get(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeByteSeq: function(v) { if(v === null || v.length === 0) @@ -2303,10 +3022,6 @@ var BasicStream = Class({ this._buf.putArray(v); } }, - readByteSeq: function() - { - return this._buf.getArray(this.readAndCheckSeqSize(1)); - }, writeBool: function(v) { this.expand(1); @@ -2316,33 +3031,11 @@ var BasicStream = Class({ { this._buf.putAt(dest, v ? 1 : 0); }, - readBool: function() - { - try - { - return this._buf.get() === 1; - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeShort: function(v) { this.expand(2); this._buf.putShort(v); }, - readShort: function() - { - try - { - return this._buf.getShort(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeInt: function(v) { this.expand(4); @@ -2352,65 +3045,21 @@ var BasicStream = Class({ { this._buf.putIntAt(dest, v); }, - readInt: function() - { - try - { - return this._buf.getInt(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeLong: function(v) { this.expand(8); this._buf.putLong(v); }, - readLong: function() - { - try - { - return this._buf.getLong(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeFloat: function(v) { this.expand(4); this._buf.putFloat(v); }, - readFloat: function() - { - try - { - return this._buf.getFloat(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeDouble: function(v) { this.expand(8); this._buf.putDouble(v); }, - readDouble: function() - { - try - { - return this._buf.getDouble(); - } - catch(ex) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - }, writeString: function(v) { if(v === null || v.length === 0) @@ -2422,39 +3071,23 @@ var BasicStream = Class({ this._buf.writeString(this, v); } }, - readString: function() + writeProxy: function(v) { - var len = this.readSize(); - if(len === 0) - { - return ""; - } - // - // Check the buffer has enough bytes to read. - // - if(this._buf.remaining < len) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - - try + if(v !== null) { - return this._buf.getString(len); + v.__write(this); } - catch(ex) + else { - throw new Ice.UnmarshalOutOfBoundsException(); + var ident = new Ice.Identity(); + ident.__write(this); } }, - writeProxy: function(v) - { - this._instance.proxyFactory().proxyToStream(v, this); - }, - writeOptProxy: function(tag, v) + writeOptionalProxy: function(tag, v) { if(v !== undefined) { - if(this.writeOpt(tag, OptionalFormat.FSize)) + if(this.writeOptional(tag, OptionalFormat.FSize)) { var pos = this.startSize(); this.writeProxy(v); @@ -2462,25 +3095,9 @@ var BasicStream = Class({ } } }, - readProxy: function(type) - { - return this._instance.proxyFactory().streamToProxy(this, type); - }, - readOptProxy: function(tag, type) - { - if(this.readOpt(tag, OptionalFormat.FSize)) - { - this.skip(4); - return this.readProxy(type); - } - else - { - return undefined; - } - }, writeEnum: function(v) { - if(this.isWriteEncoding_1_0()) + if(this.isEncoding_1_0()) { if(v.maxValue < 127) { @@ -2500,161 +3117,29 @@ var BasicStream = Class({ this.writeSize(v.value); } }, - readEnum: function(T) - { - var v; - if(this.getReadEncoding().equals(Ice.Encoding_1_0)) - { - if(T.maxValue < 127) - { - v = this.readByte(); - } - else if(T.maxValue < 32767) - { - v = this.readShort(); - } - else - { - v = this.readInt(); - } - } - else - { - v = this.readSize(); - } - - var e = T.valueOf(v); - if(e === undefined) - { - throw new Ice.MarshalException("enumerator value " + v + " is out of range"); - } - return e; - }, - readOptEnum: function(tag, T) - { - if(this.readOpt(tag, OptionalFormat.Size)) - { - return this.readEnum(T); - } - else - { - return undefined; - } - }, writeObject: function(v) { - this.initWriteEncaps(); - this._writeEncapsStack.encoder.writeObject(v); + this.initEncaps(); + this._encapsStack.encoder.writeObject(v); }, - writeOptObject: function(tag, v) + writeOptionalObject: function(tag, v) { if(v !== undefined) { - if(this.writeOpt(tag, OptionalFormat.Class)) + if(this.writeOptional(tag, OptionalFormat.Class)) { this.writeObject(v); } } }, - readObject: function(patcher, T) - { - this.initReadEncaps(); - // - // BUGFIX: - // With Chrome linux the invokation of readObject on the decoder some times - // calls BasicStream.readObject with the decoder object as this param. - // Use call instead of directly invoke the method to workaround this bug. - // - this._readEncapsStack.decoder.readObject.call( - this._readEncapsStack.decoder, - function(obj){ - if(obj !== null && !(obj.ice_instanceof(T))) - { - ExUtil.throwUOE(T.ice_staticId(), obj); - } - patcher(obj); - }); - }, - readOptObject: function(tag, patcher, T) - { - if(this.readOpt(tag, OptionalFormat.Class)) - { - this.readObject(patcher, T); - } - else - { - patcher(undefined); - } - }, writeUserException: function(e) { - this.initWriteEncaps(); - this._writeEncapsStack.encoder.writeUserException(e); - }, - throwException: function() - { - this.initReadEncaps(); - this._readEncapsStack.decoder.throwException(); - }, - sliceObjects: function(b) - { - this._sliceObjects = b; - }, - readOptImpl: function(readTag, expectedFormat) - { - var b, v, format, tag, offset; - - if(this.isReadEncoding_1_0()) - { - return false; // Optional members aren't supported with the 1.0 encoding. - } - - while(true) - { - if(this._buf.position >= this._readEncapsStack.start + this._readEncapsStack.sz) - { - return false; // End of encapsulation also indicates end of optionals. - } - - v = this.readByte(); - - if(v === OPTIONAL_END_MARKER) - { - this._buf.position -= 1; // Rewind. - return false; - } - - format = OptionalFormat.valueOf(v & 0x07); // First 3 bits. - tag = v >> 3; - if(tag === 30) - { - tag = this.readSize(); - } - - if(tag > readTag) - { - offset = tag < 30 ? 1 : (tag < 255 ? 2 : 6); // Rewind - this._buf.position -= offset; - return false; // No optional data members with the requested tag. - } - - if(tag < readTag) - { - this.skipOpt(format); // Skip optional data members - } - else - { - if(format !== expectedFormat) - { - throw new Ice.MarshalException("invalid optional data member `" + tag + "': unexpected format"); - } - return true; - } - } + this.initEncaps(); + this._encapsStack.encoder.writeUserException(e); }, writeOptImpl: function(tag, format) { - if(this.isWriteEncoding_1_0()) + if(this.isEncoding_1_0()) { return false; // Optional members aren't supported with the 1.0 encoding. } @@ -2673,80 +3158,6 @@ var BasicStream = Class({ } return true; }, - skipOpt: function(format) - { - switch(format) - { - case OptionalFormat.F1: - this.skip(1); - break; - case OptionalFormat.F2: - this.skip(2); - break; - case OptionalFormat.F4: - this.skip(4); - break; - case OptionalFormat.F8: - this.skip(8); - break; - case OptionalFormat.Size: - this.skipSize(); - break; - case OptionalFormat.VSize: - this.skip(this.readSize()); - break; - case OptionalFormat.FSize: - this.skip(this.readInt()); - break; - case OptionalFormat.Class: - this.readObject(null, Ice.Object); - break; - } - }, - skipOpts: function() - { - var b, v, format; - // - // Skip remaining un-read optional members. - // - while(true) - { - if(this._buf.position >= this._readEncapsStack.start + this._readEncapsStack.sz) - { - return; // End of encapsulation also indicates end of optionals. - } - - b = this.readByte(); - v = b < 0 ? b + 256 : b; - if(v === OPTIONAL_END_MARKER) - { - return; - } - - format = OptionalFormat.valueOf(v & 0x07); // Read first 3 bits. - if((v >> 3) === 30) - { - this.skipSize(); - } - this.skipOpt(format); - } - }, - skip: function(size) - { - if(size > this._buf.remaining) - { - throw new Ice.UnmarshalOutOfBoundsException(); - } - this._buf.position += size; - }, - skipSize: function() - { - var b = this.readByte(); - if(b === 255) - { - this.skip(4); - } - }, isEmpty: function() { return this._buf.empty(); @@ -2755,148 +3166,72 @@ var BasicStream = Class({ { this._buf.expand(n); }, - createObject: function(id) + isEncoding_1_0: function() { - var obj = null, Class; - try - { - var typeId = id.length > 2 ? id.substr(2).replace(/::/g, ".") : ""; - /*jshint -W061 */ - Class = __M.type(typeId); - /*jshint +W061 */ - if(Class !== undefined) - { - obj = new Class(); - } - } - catch(ex) - { - throw new Ice.NoValueFactoryException("no value factory", id, ex); - } - - return obj; - }, - getTypeId: function(compactId) - { - var typeId = Ice.CompactIdRegistry.get(compactId); - return typeId === undefined ? "" : typeId; + return this._encapsStack ? this._encapsStack.encoding_1_0 : this._encoding.equals(Ice.Encoding_1_0); }, - isReadEncoding_1_0: function() + initEncaps: function() { - return this._readEncapsStack !== null ? this._readEncapsStack.encoding_1_0 : this._encoding.equals(Ice.Encoding_1_0); - }, - isWriteEncoding_1_0: function() - { - return this._writeEncapsStack ? this._writeEncapsStack.encoding_1_0 : this._encoding.equals(Ice.Encoding_1_0); - }, - initReadEncaps: function() - { - if(this._readEncapsStack === null) // Lazy initialization + if(!this._encapsStack) // Lazy initialization { - this._readEncapsStack = this._readEncapsCache; - if(this._readEncapsStack !== null) + this._encapsStack = this._encapsCache; + if(this._encapsStack) { - this._readEncapsCache = this._readEncapsCache.next; + this._encapsCache = this._encapsCache.next; } else { - this._readEncapsStack = new ReadEncaps(); + this._encapsStack = new WriteEncaps(); } - this._readEncapsStack.setEncoding(this._encoding); - this._readEncapsStack.sz = this._buf.limit; + this._encapsStack.setEncoding(this._encoding); } - if(this._readEncapsStack.decoder === null) // Lazy initialization. + if(this._encapsStack.format === FormatType.DefaultFormat) { - var factoryManager = this._instance.servantFactoryManager(); - if(this._readEncapsStack.encoding_1_0) - { - this._readEncapsStack.decoder = new EncapsDecoder10(this, this._readEncapsStack, this._sliceObjects, factoryManager); - } - else - { - this._readEncapsStack.decoder = new EncapsDecoder11(this, this._readEncapsStack, this._sliceObjects, factoryManager); - } - } - }, - initWriteEncaps: function() - { - if(!this._writeEncapsStack) // Lazy initialization - { - this._writeEncapsStack = this._writeEncapsCache; - if(this._writeEncapsStack) - { - this._writeEncapsCache = this._writeEncapsCache.next; - } - else - { - this._writeEncapsStack = new WriteEncaps(); - } - this._writeEncapsStack.setEncoding(this._encoding); - } - - if(this._writeEncapsStack.format === FormatType.DefaultFormat) - { - this._writeEncapsStack.format = this._instance.defaultsAndOverrides().defaultFormat; + this._encapsStack.format = this._instance.defaultsAndOverrides().defaultFormat; } - if(!this._writeEncapsStack.encoder) // Lazy initialization. + if(!this._encapsStack.encoder) // Lazy initialization. { - if(this._writeEncapsStack.encoding_1_0) + if(this._encapsStack.encoding_1_0) { - this._writeEncapsStack.encoder = new EncapsEncoder10(this, this._writeEncapsStack); + this._encapsStack.encoder = new EncapsEncoder10(this, this._encapsStack); } else { - this._writeEncapsStack.encoder = new EncapsEncoder11(this, this._writeEncapsStack); + this._encapsStack.encoder = new EncapsEncoder11(this, this._encapsStack); } } - }, - createUserException: function(id) - { - var userEx = null, Class; - - try - { - var typeId = id.length > 2 ? id.substr(2).replace(/::/g, ".") : ""; - /*jshint -W061 */ - Class = __M.type(typeId); - /*jshint +W061 */ - if(Class !== undefined) - { - userEx = new Class(); - } - } - catch(ex) - { - throw new Ice.MarshalException(ex); - } - - return userEx; } }); -var defineProperty = Object.defineProperty; +// +// Sets the encoding format for class and exception instances. +// +defineProperty(OutputStream.prototype, "format", { + get: function() { return this._format; }, + set: function(f) { this._format = f; } +}); -defineProperty(BasicStream.prototype, "pos", { +defineProperty(OutputStream.prototype, "pos", { get: function() { return this._buf.position; }, set: function(n) { this._buf.position = n; } }); -defineProperty(BasicStream.prototype, "size", { +defineProperty(OutputStream.prototype, "size", { get: function() { return this._buf.limit; } }); -defineProperty(BasicStream.prototype, "instance", { +defineProperty(OutputStream.prototype, "instance", { get: function() { return this._instance; } }); -defineProperty(BasicStream.prototype, "closure", { - get: function() { return this._type; }, - set: function(type) { this._type = type; } +defineProperty(OutputStream.prototype, "closure", { + get: function() { return this._closure; }, + set: function(closure) { this._closure = closure; } }); -defineProperty(BasicStream.prototype, "buffer", { +defineProperty(OutputStream.prototype, "buffer", { get: function() { return this._buf; } }); @@ -2905,8 +3240,8 @@ var defineBuiltinHelper = 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); }, + writeOptional: function(os, tag, v) { os.writeOptionalValue(tag, format, write, v); }, + readOptional: function(is, tag) { return is.readOptionalValue(tag, format, read); }, }; if(min !== undefined && max !== undefined) @@ -2921,8 +3256,8 @@ var defineBuiltinHelper = function(write, read, sz, format, min, max) return helper; }; -var stream = BasicStream.prototype; - +var istr = InputStream.prototype; +var ostr = OutputStream.prototype; // // Constants to use in number type range checks. @@ -2942,16 +3277,16 @@ var MAX_INT32_VALUE = 0x7FFFFFFF; var MIN_FLOAT32_VALUE = -3.4028234664e+38; var MAX_FLOAT32_VALUE = 3.4028234664e+38; -Ice.ByteHelper = defineBuiltinHelper(stream.writeByte, stream.readByte, 1, Ice.OptionalFormat.F1, +Ice.ByteHelper = defineBuiltinHelper(ostr.writeByte, istr.readByte, 1, Ice.OptionalFormat.F1, MIN_UINT8_VALUE, MAX_UINT8_VALUE); -Ice.ShortHelper = defineBuiltinHelper(stream.writeShort, stream.readShort, 2, Ice.OptionalFormat.F2, +Ice.ShortHelper = defineBuiltinHelper(ostr.writeShort, istr.readShort, 2, Ice.OptionalFormat.F2, MIN_INT16_VALUE, MAX_INT16_VALUE); -Ice.IntHelper = defineBuiltinHelper(stream.writeInt, stream.readInt, 4, Ice.OptionalFormat.F4, +Ice.IntHelper = defineBuiltinHelper(ostr.writeInt, istr.readInt, 4, Ice.OptionalFormat.F4, MIN_INT32_VALUE, MAX_INT32_VALUE); -Ice.FloatHelper = defineBuiltinHelper(stream.writeFloat, stream.readFloat, 4, Ice.OptionalFormat.F4, +Ice.FloatHelper = defineBuiltinHelper(ostr.writeFloat, istr.readFloat, 4, Ice.OptionalFormat.F4, MIN_FLOAT32_VALUE, MAX_FLOAT32_VALUE); Ice.FloatHelper.validate = function(v) { @@ -2959,7 +3294,7 @@ Ice.FloatHelper.validate = function(v) (v >= MIN_FLOAT32_VALUE && v <= MAX_FLOAT32_VALUE); }; -Ice.DoubleHelper = defineBuiltinHelper(stream.writeDouble, stream.readDouble, 8, Ice.OptionalFormat.F8, +Ice.DoubleHelper = defineBuiltinHelper(ostr.writeDouble, istr.readDouble, 8, Ice.OptionalFormat.F8, -Number.MAX_VALUE, Number.MAX_VALUE); Ice.DoubleHelper.validate = function(v) { @@ -2967,8 +3302,8 @@ Ice.DoubleHelper.validate = function(v) (v >= -Number.MAX_VALUE && v <= Number.MAX_VALUE); }; -Ice.BoolHelper = defineBuiltinHelper(stream.writeBool, stream.readBool, 1, Ice.OptionalFormat.F1); -Ice.LongHelper = defineBuiltinHelper(stream.writeLong, stream.readLong, 8, Ice.OptionalFormat.F8); +Ice.BoolHelper = defineBuiltinHelper(ostr.writeBool, istr.readBool, 1, Ice.OptionalFormat.F1); +Ice.LongHelper = defineBuiltinHelper(ostr.writeLong, istr.readLong, 8, Ice.OptionalFormat.F8); Ice.LongHelper.validate = function(v) { // @@ -2978,7 +3313,7 @@ Ice.LongHelper.validate = function(v) v.high >= MIN_UINT32_VALUE && v.high <= MAX_UINT32_VALUE; }; -Ice.StringHelper = defineBuiltinHelper(stream.writeString, stream.readString, 1, Ice.OptionalFormat.VSize); +Ice.StringHelper = defineBuiltinHelper(ostr.writeString, istr.readString, 1, Ice.OptionalFormat.VSize); Ice.ObjectHelper = { write: function(os, v) @@ -2991,14 +3326,14 @@ Ice.ObjectHelper = { is.readObject(function(v) { o = v; }, Ice.Object); return o; }, - writeOpt: function(os, tag, v) + writeOptional: function(os, tag, v) { - os.writeOptValue(tag, Ice.OptionalFormat.Class, stream.writeObject, v); + os.writeOptionalValue(tag, Ice.OptionalFormat.Class, ostr.writeObject, v); }, - readOpt: function(is, tag) + readOptional: function(is, tag) { var o; - is.readOptObject(tag, function(v) { o = v; }, Ice.Object); + is.readOptionalObject(tag, function(v) { o = v; }, Ice.Object); return o; }, }; @@ -3007,5 +3342,6 @@ defineProperty(Ice.ObjectHelper, "minWireSize", { get: function() { return 1; } }); -Ice.BasicStream = BasicStream; +Ice.InputStream = InputStream; +Ice.OutputStream = OutputStream; module.exports.Ice = Ice; diff --git a/js/src/Ice/StreamHelpers.js b/js/src/Ice/StreamHelpers.js index 2e460cb9355..c61b453127c 100644 --- a/js/src/Ice/StreamHelpers.js +++ b/js/src/Ice/StreamHelpers.js @@ -19,9 +19,9 @@ var StreamHelpers = {}; StreamHelpers.FSizeOptHelper = function() { - this.writeOpt = function(os, tag, v) + this.writeOptional = function(os, tag, v) { - if(v !== undefined && os.writeOpt(tag, OptionalFormat.FSize)) + if(v !== undefined && os.writeOptional(tag, OptionalFormat.FSize)) { var pos = os.startSize(); this.write(os, v); @@ -29,10 +29,10 @@ StreamHelpers.FSizeOptHelper = function() } }; - this.readOpt = function(is, tag) + this.readOptional = function(is, tag) { var v; - if(is.readOpt(tag, OptionalFormat.FSize)) + if(is.readOptional(tag, OptionalFormat.FSize)) { is.skip(4); v = this.read(is); @@ -43,19 +43,19 @@ StreamHelpers.FSizeOptHelper = function() StreamHelpers.VSizeOptHelper = function() { - this.writeOpt = function(os, tag, v) + this.writeOptional = function(os, tag, v) { - if(v !== undefined && os.writeOpt(tag, OptionalFormat.VSize)) + if(v !== undefined && os.writeOptional(tag, OptionalFormat.VSize)) { os.writeSize(this.minWireSize); this.write(os, v); } }; - this.readOpt = function(is, tag) + this.readOptional = function(is, tag) { var v; - if(is.readOpt(tag, OptionalFormat.VSize)) + if(is.readOptional(tag, OptionalFormat.VSize)) { is.skipSize(); v = this.read(is); @@ -66,9 +66,9 @@ StreamHelpers.VSizeOptHelper = function() StreamHelpers.VSizeContainerOptHelper = function(elementSize) { - this.writeOpt = function(os, tag, v) + this.writeOptional = function(os, tag, v) { - if(v !== undefined && os.writeOpt(tag, OptionalFormat.VSize)) + if(v !== undefined && os.writeOptional(tag, OptionalFormat.VSize)) { var sz = this.size(v); os.writeSize(sz > 254 ? sz * elementSize + 5 : sz * elementSize + 1); @@ -76,10 +76,10 @@ StreamHelpers.VSizeContainerOptHelper = function(elementSize) } }; - this.readOpt = function(is, tag) + this.readOptional = function(is, tag) { var v; - if(is.readOpt(tag, OptionalFormat.VSize)) + if(is.readOptional(tag, OptionalFormat.VSize)) { is.skipSize(); v = this.read(is); @@ -90,18 +90,18 @@ StreamHelpers.VSizeContainerOptHelper = function(elementSize) StreamHelpers.VSizeContainer1OptHelper = function() { - this.writeOpt = function(os, tag, v) + this.writeOptional = function(os, tag, v) { - if(v !== undefined && os.writeOpt(tag, OptionalFormat.VSize)) + if(v !== undefined && os.writeOptional(tag, OptionalFormat.VSize)) { this.write(os, v); } }; - this.readOpt = function(is, tag) + this.readOptional = function(is, tag) { var v; - if(is.readOpt(tag, OptionalFormat.VSize)) + if(is.readOptional(tag, OptionalFormat.VSize)) { v = this.read(is); } diff --git a/js/src/Ice/TraceUtil.js b/js/src/Ice/TraceUtil.js index 2da5cc88147..a1419ce9953 100644 --- a/js/src/Ice/TraceUtil.js +++ b/js/src/Ice/TraceUtil.js @@ -27,6 +27,7 @@ var Protocol = Ice.Protocol; var StringUtil = Ice.StringUtil; var OperationMode = Ice.OperationMode; var Identity = Ice.Identity; +var InputStream = Ice.InputStream; var TraceUtil = {}; @@ -35,10 +36,11 @@ TraceUtil.traceSend = function(stream, logger, traceLevels) if(traceLevels.protocol >= 1) { var p = stream.pos; - stream.pos = 0; + var is = new InputStream(stream.instance, stream.getEncoding(), stream.buffer); + is.pos = 0; var s = []; - var type = printMessage(s, stream); + var type = printMessage(s, is); logger.trace(traceLevels.protocolCat, "sending " + getMessageTypeAsString(type) + " " + s.join("")); @@ -62,7 +64,24 @@ TraceUtil.traceRecv = function(stream, logger, traceLevels) } }; -TraceUtil.trace = function(heading, stream, logger, traceLevels) +TraceUtil.traceOut = function(heading, stream, logger, traceLevels) +{ + if(traceLevels.protocol >= 1) + { + var p = stream.pos; + var is = new InputStream(stream.instance, stream.getEncoding(), stream.buffer); + is.pos = 0; + + var s = []; + s.push(heading); + printMessage(s, is); + + logger.trace(traceLevels.protocolCat, s.join("")); + stream.pos = p; + } +}; + +TraceUtil.traceIn = function(heading, stream, logger, traceLevels) { if(traceLevels.protocol >= 1) { @@ -305,7 +324,7 @@ function printReply(s, stream) if(replyStatus === Protocol.replyOK || replyStatus === Protocol.replyUserException) { - var ver = stream.skipEncaps(); + var ver = stream.skipEncapsulation(); if(!ver.equals(Ice.Encoding_1_0)) { s.push("\nencoding = "); @@ -360,7 +379,7 @@ function printRequestHeader(s, stream) } } - var ver = stream.skipEncaps(); + var ver = stream.skipEncapsulation(); if(!ver.equals(Ice.Encoding_1_0)) { s.push("\nencoding = "); diff --git a/js/src/Ice/UnknownSlicedObject.js b/js/src/Ice/UnknownSlicedObject.js index 33417043829..389e0232ab3 100644 --- a/js/src/Ice/UnknownSlicedObject.js +++ b/js/src/Ice/UnknownSlicedObject.js @@ -62,13 +62,13 @@ var UnknownSlicedObject = Ice.Class(Ice.Object, }, __write: function(os) { - os.startWriteObject(this._slicedData); - os.endWriteObject(); + os.startObject(this._slicedData); + os.endObject(); }, __read: function(is) { - is.startReadObject(); - this._slicedData = is.endReadObject(true); + is.startObject(); + this._slicedData = is.endObject(true); } }); Ice.UnknownSlicedObject = UnknownSlicedObject; diff --git a/js/src/Ice/ValueFactoryManager.js b/js/src/Ice/ValueFactoryManagerI.js index 957a5f28ecd..1026912cae2 100644 --- a/js/src/Ice/ValueFactoryManager.js +++ b/js/src/Ice/ValueFactoryManagerI.js @@ -17,11 +17,10 @@ var NotRegisteredException = Ice.NotRegisteredException; // // Only for use by Instance // -var ValueFactoryManager = Ice.Class({ +var ValueFactoryManagerI = Ice.Class({ __init__: function() { this._factoryMap = new HashMap(); // Map<String, ValueFactory> - this._objectFactoryMap = new HashMap(); // Map<String, ObjectFactory> }, add: function(factory, id) { @@ -36,47 +35,15 @@ var ValueFactoryManager = Ice.Class({ } this._factoryMap.set(id, factory); }, - addObjectFactory: function(factory, id) - { - var o, ex; - o = this._factoryMap.get(id); - if(o !== undefined) - { - ex = new AlreadyRegisteredException(); - ex.id = id; - ex.kindOfObject = "value factory"; - throw ex; - } - this._factoryMap.set(id, - function(s) - { - return factory.create(s); - } - ); - this._objectFactoryMap.set(id, factory); - }, find: function(id) { return this._factoryMap.get(id); }, - findObjectFactory: function(id) - { - return this._objectFactoryMap.get(id); - }, destroy: function() { - var oldMap = this._objectFactoryMap, - e = oldMap.entries; this._factoryMap = new HashMap(); // Map<String, ValueFactory> - this._objectFactoryMap = new HashMap(); // Map<String, ObjectFactory> - - while(e !== null) - { - e.value.destroy(); - e = e.next; - } } }); -Ice.ValueFactoryManager = ValueFactoryManager; +Ice.ValueFactoryManagerI = ValueFactoryManagerI; module.exports.Ice = Ice; diff --git a/js/src/Ice/WSEndpoint.js b/js/src/Ice/WSEndpoint.js index 9d86831fa3c..f466687f8d7 100644 --- a/js/src/Ice/WSEndpoint.js +++ b/js/src/Ice/WSEndpoint.js @@ -50,10 +50,10 @@ var WSEndpoint = Class(EndpointI, { }, streamWrite: function(s) { - s.startWriteEncaps(); + s.startEncapsulation(); this._delegate.streamWriteImpl(s); s.writeString(this._resource); - s.endWriteEncaps(); + s.endEncapsulation(); }, timeout: function() { diff --git a/js/src/Ice/sources.json b/js/src/Ice/sources.json index e97f75ae638..df7769b33de 100644 --- a/js/src/Ice/sources.json +++ b/js/src/Ice/sources.json @@ -32,7 +32,6 @@ "AsyncResultBase.js", "AsyncStatus.js", "Base64.js", - "BasicStream.js", "BatchRequestQueue.js", "Class.js", "Communicator.js", @@ -88,6 +87,7 @@ "RouterManager.js", "ServantManager.js", "SocketOperation.js", + "Stream.js", "StreamHelpers.js", "StringUtil.js", "Struct.js", @@ -98,7 +98,7 @@ "TraceUtil.js", "UnknownSlicedObject.js", "UUID.js", - "ValueFactoryManager.js", + "ValueFactoryManagerI.js", "WSEndpoint.js", "WSEndpointFactory.js"], |