diff options
Diffstat (limited to 'js/src/Ice/Operation.js')
-rw-r--r-- | js/src/Ice/Operation.js | 247 |
1 files changed, 118 insertions, 129 deletions
diff --git a/js/src/Ice/Operation.js b/js/src/Ice/Operation.js index bc115ba8c0e..c79af7f8721 100644 --- a/js/src/Ice/Operation.js +++ b/js/src/Ice/Operation.js @@ -8,11 +8,10 @@ // ********************************************************************** -var Ice = require("../Ice/ModuleRegistry").Ice; -var __M = Ice.__M; +const Ice = require("../Ice/ModuleRegistry").Ice; +const __M = Ice.__M; __M.require(module, [ - "../Ice/Class", "../Ice/Current", "../Ice/DispatchStatus", "../Ice/Exception", @@ -23,9 +22,7 @@ __M.require(module, "../Ice/StreamHelpers" ]); -var Class = Ice.Class; - -var builtinHelpers = +const builtinHelpers = [ Ice.ByteHelper, Ice.BoolHelper, @@ -41,17 +38,15 @@ var builtinHelpers = function parseParam(p) { - var type = p[0]; - var t = typeof(type); + let type = p[0]; + const t = typeof(type); if(t === 'number') { type = builtinHelpers[p[0]]; } else if(t === 'string') { - /*jshint -W061 */ type = __M.type(type); - /*jshint +W061 */ } return { @@ -80,9 +75,7 @@ function parseParam(p) // function parseOperation(name, arr) { - var r = {}; - var i; - var p; + const r = {}; r.name = name; r.mode = arr[1] ? Ice.OperationMode.valueOf(arr[1]) : Ice.OperationMode.Normal; @@ -99,7 +92,7 @@ function parseOperation(name, arr) r.servantMethod = arr[0] ? arr[0] : name; } - var ret; + let ret; if(arr[5]) { ret = parseParam(arr[5]); @@ -107,13 +100,13 @@ function parseOperation(name, arr) } r.returns = ret; - var inParams = []; - var inParamsOpt = []; + const inParams = []; + const inParamsOpt = []; if(arr[6]) { - for(i = 0; i < arr[6].length; ++i) + for(let i = 0; i < arr[6].length; ++i) { - p = parseParam(arr[6][i]); + let p = parseParam(arr[6][i]); p.pos = i; inParams.push(p); if(p.tag) @@ -126,14 +119,14 @@ function parseOperation(name, arr) r.inParams = inParams; r.inParamsOpt = inParamsOpt; - var outParams = []; - var outParamsOpt = []; + const outParams = []; + const outParamsOpt = []; if(arr[7]) { - var offs = ret ? 1 : 0; - for(i = 0; i < arr[7].length; ++i) + const offs = ret ? 1 : 0; + for(let i = 0; i < arr[7].length; ++i) { - p = parseParam(arr[7][i]); + let p = parseParam(arr[7][i]); p.pos = i + offs; outParams.push(p); if(p.tag) @@ -150,10 +143,10 @@ function parseOperation(name, arr) r.outParams = outParams; r.outParamsOpt = outParamsOpt; - var exceptions = []; + const exceptions = []; if(arr[8]) { - for(i = 0; i < arr[8].length; ++i) + for(let i = 0; i < arr[8].length; ++i) { exceptions.push(arr[8][i]); } @@ -166,18 +159,20 @@ function parseOperation(name, arr) return r; } -var OpTable = Class({ - __init__: function(ops) +class OpTable +{ + constructor(ops) { this.raw = ops; this.parsed = {}; - }, - find: function(name) + } + + find(name) { // // Check if we've already parsed the operation. // - var op = this.parsed[name]; + let op = this.parsed[name]; if(op === undefined && this.raw[name] !== undefined) { // @@ -188,20 +183,19 @@ var OpTable = Class({ } return op; } -}); +} function unmarshalParams(is, retvalInfo, allParamInfo, optParamInfo, usesClasses, params, offset) { - var i, p, v; // // First read all required params. // - for(i = 0; i < allParamInfo.length; ++i) + for(let i = 0; i < allParamInfo.length; ++i) { - p = allParamInfo[i]; + let p = allParamInfo[i]; if(!p.tag) { - v = p.type.read(is); + let v = p.type.read(is); params[p.pos + offset] = v; } } @@ -211,17 +205,17 @@ function unmarshalParams(is, retvalInfo, allParamInfo, optParamInfo, usesClasses // if(retvalInfo) { - v = retvalInfo.type.read(is); + let v = retvalInfo.type.read(is); params[retvalInfo.pos + offset] = v; } // // Then read all optional params. // - for(i = 0; i < optParamInfo.length; ++i) + for(let i = 0; i < optParamInfo.length; ++i) { - p = optParamInfo[i]; - v = p.type.readOptional(is, p.tag); + let p = optParamInfo[i]; + let v = p.type.readOptional(is, p.tag); params[p.pos + offset] = v; } @@ -233,14 +227,12 @@ function unmarshalParams(is, retvalInfo, allParamInfo, optParamInfo, usesClasses function marshalParams(os, params, retvalInfo, paramInfo, optParamInfo, usesClasses) { - var i, p; - // // Write the required params. // - for(i = 0; i < paramInfo.length; ++i) + for(let i = 0; i < paramInfo.length; ++i) { - p = paramInfo[i]; + let p = paramInfo[i]; if(!p.tag) { p.type.write(os, params[p.pos]); @@ -258,9 +250,9 @@ function marshalParams(os, params, retvalInfo, paramInfo, optParamInfo, usesClas // // Write the optional params. // - for(i = 0; i < optParamInfo.length; ++i) + for(let i = 0; i < optParamInfo.length; ++i) { - p = optParamInfo[i]; + let p = optParamInfo[i]; p.type.writeOptional(os, p.tag, params[p.pos]); } @@ -270,21 +262,21 @@ function marshalParams(os, params, retvalInfo, paramInfo, optParamInfo, usesClas } } -var Upcall = Class({ - __init__: function(incomingAsync, op) +class Upcall +{ + constructor(incomingAsync, op) { this.incomingAsync = incomingAsync; this.op = op; - }, - ice_response: function() - { - var args = arguments; + } + ice_response() + { if(this.incomingAsync.__validateResponse(true)) { try { - this.__sendResponse(args); + this.__sendResponse(arguments); this.incomingAsync.__response(); } catch(ex) @@ -292,8 +284,9 @@ var Upcall = Class({ this.incomingAsync.__exception(ex); } } - }, - ice_exception: function(ex) + } + + ice_exception(ex) { if(this.__checkException(ex)) { @@ -307,8 +300,9 @@ var Upcall = Class({ { this.incomingAsync.ice_exception(ex); } - }, - __sendResponse: function(results) + } + + __sendResponse(results) { if(this.op.returns === undefined && this.op.outParams.length === 0) { @@ -326,8 +320,8 @@ var Upcall = Class({ } else { - var __os = this.incomingAsync.__startWriteParams(this.op.format); - var retvalInfo; + const __os = this.incomingAsync.__startWriteParams(this.op.format); + let retvalInfo; if(this.op.returns && !this.op.returns.tag) { retvalInfo = this.op.returns; @@ -336,14 +330,15 @@ var Upcall = Class({ this.op.returnsClasses); this.incomingAsync.__endWriteParams(true); } - }, - __checkException: function(ex) + } + + __checkException(ex) { // // Make sure the given exception is an instance of one of the declared user exceptions // for this operation. // - for(var i = 0; i < this.op.exceptions.length; ++i) + for(let i = 0; i < this.op.exceptions.length; ++i) { if(ex instanceof this.op.exceptions[i]) { @@ -355,46 +350,44 @@ var Upcall = Class({ } return false; - }, - __sendException: function(ex) + } + + __sendException(ex) { // // User exception is valid, now marshal it. // this.incomingAsync.__writeUserException(ex, this.op.format); } -}); +} -var __dispatchImpl = function(servant, op, incomingAsync, current) +function __dispatchImpl(servant, op, incomingAsync, current) { // // Check to make sure the servant implements the operation. // - var method = servant[op.servantMethod]; + const method = servant[op.servantMethod]; if(method === undefined || typeof(method) !== "function") { - var comm = current.adapter.getCommunicator(); - var msg = "servant for identity " + Ice.identityToString(current.id) + - " does not define operation `" + op.servantMethod + "'"; - throw new Ice.UnknownException(msg); + throw new Ice.UnknownException("servant for identity " + Ice.identityToString(current.id) + + " does not define operation `" + op.servantMethod + "'"); } - var up = new Upcall(incomingAsync, op); - + const up = new Upcall(incomingAsync, op); try { // // Unmarshal the in params (if any). // - var params = op.amd ? [null] : []; + const params = op.amd ? [null] : []; if(op.inParams.length === 0) { incomingAsync.readEmptyParams(); } else { - var __is = incomingAsync.startReadParams(); - var offset = op.amd ? 1 : 0; + const __is = incomingAsync.startReadParams(); + const offset = op.amd ? 1 : 0; unmarshalParams(__is, undefined, op.inParams, op.inParamsOpt, op.sendsClasses, params, offset); incomingAsync.endReadParams(); @@ -406,17 +399,16 @@ var __dispatchImpl = function(servant, op, incomingAsync, current) // if(op.inParams.length > 0 && (op.sendsClasses || op.inParamsOpt.length > 0)) { - for(var i = 0; i < op.inParams.length; ++i) - { - var p = op.inParams[i]; - // - // Optional parameters may be undefined. - // - if(p.isObject && params[p.pos + offset] !== undefined) + op.inParams.forEach(p => { - params[p.pos + offset] = params[p.pos + offset].value; - } - } + // + // Optional parameters may be undefined. + // + if(p.isObject && params[p.pos + offset] !== undefined) + { + params[p.pos + offset] = params[p.pos + offset].value; + } + }); } } @@ -440,13 +432,13 @@ var __dispatchImpl = function(servant, op, incomingAsync, current) // // Determine how many out parameters to expect. // - var numExpectedResults = op.outParams.length; + let numExpectedResults = op.outParams.length; if(op.returns) { ++numExpectedResults; } - var results = method.apply(servant, params); + let results = method.apply(servant, params); // // Complain if we expect more than out parameter and the servant doesn't return an array. @@ -480,14 +472,14 @@ var __dispatchImpl = function(servant, op, incomingAsync, current) throw ex; } } -}; +} function getServantMethodFromInterfaces(interfaces, methodName, all) { - var method; - for(var i = 0; method === undefined && i < interfaces.length; ++i) + let method; + for(let i = 0; method === undefined && i < interfaces.length; ++i) { - var intf = interfaces[i]; + let intf = interfaces[i]; method = intf[methodName]; if(method === undefined) { @@ -504,21 +496,21 @@ function getServantMethodFromInterfaces(interfaces, methodName, all) return method; } -var dispatchPrefix = "__op_"; +const dispatchPrefix = "__op_"; function getServantMethod(servantType, name) { // // The dispatch method is named __op_<Slice name> and is stored in the type (not the prototype). // - var methodName = dispatchPrefix + name; + const methodName = dispatchPrefix + name; // // First check the servant type. // - var method = servantType[methodName]; + let method = servantType[methodName]; - var allInterfaces; + let allInterfaces; if(method === undefined) { @@ -527,7 +519,7 @@ function getServantMethod(servantType, name) // // Now check the prototypes of the implemented interfaces. // - var curr = servantType; + let curr = servantType; while(curr && method === undefined) { if(curr.__implements) @@ -551,19 +543,19 @@ function getServantMethod(servantType, name) // // Next check the op table for the servant's type. // - var op; + let op; if(servantType.__ops) { op = servantType.__ops.find(name); } - var source; + let source; if(op === undefined) { // // Now check the op tables of the base types. // - var parent = servantType.__parent; + let parent = servantType.__parent; while(op === undefined && parent) { if(parent.__ops) @@ -579,9 +571,9 @@ function getServantMethod(servantType, name) // // Now check the op tables of all base interfaces. // - for(var i = 0; op === undefined && i < allInterfaces.length; ++i) + for(let i = 0; op === undefined && i < allInterfaces.length; ++i) { - var intf = allInterfaces[i]; + let intf = allInterfaces[i]; if(intf.__ops) { if((op = intf.__ops.find(name)) !== undefined) @@ -619,13 +611,13 @@ function getServantMethod(servantType, name) function addProxyOperation(proxyType, name, data) { - var method = data[0] ? data[0] : name; + let method = data[0] ? data[0] : name; - var op = null; + let op = null; proxyType.prototype[method] = function() { - var args = arguments; + let args = arguments; // // Parse the operation data on the first invocation of a proxy method. @@ -635,22 +627,20 @@ function addProxyOperation(proxyType, name, data) op = parseOperation(name, data); } - var ctx = args[op.inParams.length]; // The request context is the last argument (if present). + let ctx = args[op.inParams.length]; // The request context is the last argument (if present). - var marshalFn = null; + let marshalFn = null; if(op.inParams.length > 0) { marshalFn = function(os, params) { - var i, p, v; - // // Validate the parameters. // - for(i = 0; i < op.inParams.length; ++i) + for(let i = 0; i < op.inParams.length; ++i) { - p = op.inParams[i]; - v = params[p.pos]; + let p = op.inParams[i]; + let v = params[p.pos]; if(!p.tag || v !== undefined) { if(typeof p.type.validate === "function") @@ -668,7 +658,7 @@ function addProxyOperation(proxyType, name, data) }; } - var unmarshalFn = null; + let unmarshalFn = null; if(op.returns || op.outParams.length > 0) { unmarshalFn = function(asyncResult) @@ -678,11 +668,11 @@ function addProxyOperation(proxyType, name, data) // // [retval, out1, out2, ..., asyncResult] // - var results = []; + let results = []; - var is = asyncResult.__startReadParams(); + let is = asyncResult.__startReadParams(); - var retvalInfo; + let retvalInfo; if(op.returns && !op.returns.tag) { retvalInfo = op.returns; @@ -699,14 +689,14 @@ function addProxyOperation(proxyType, name, data) // if(op.returnsClasses || op.outParamsOpt.length > 0) { - var offset = 0; // Skip asyncResult in results. + let offset = 0; // Skip asyncResult in results. if(op.returns && op.returns.isObject && results[op.returns.pos + offset] !== undefined) { results[op.returns.pos + offset] = results[op.returns.pos + offset].value; } - for(var i = 0; i < op.outParams.length; ++i) + for(let i = 0; i < op.outParams.length; ++i) { - var p = op.outParams[i]; + let p = op.outParams[i]; // // Optional parameters may be undefined. // @@ -716,17 +706,16 @@ function addProxyOperation(proxyType, name, data) } } } - results.push(asyncResult); - return results; + + return results.length == 1 ? results[0] : results; }; } - - return Ice.ObjectPrx.__invoke(this, op.name, op.sendMode, op.format, ctx, marshalFn, unmarshalFn, - op.exceptions, Array.prototype.slice.call(args)); + return Ice.ObjectPrx.__invoke(this, op.name, op.sendMode, op.format, ctx, marshalFn, unmarshalFn, + op.exceptions, Array.prototype.slice.call(args)); }; } -var Slice = Ice.Slice; +const Slice = Ice.Slice; Slice.defineOperations = function(classType, proxyType, ops) { if(ops) @@ -739,7 +728,7 @@ Slice.defineOperations = function(classType, proxyType, ops) // // Retrieve the dispatch method for this operation. // - var method = getServantMethod(classType, current.operation); + const method = getServantMethod(classType, current.operation); if(method === undefined || typeof(method) !== 'function') { @@ -751,7 +740,7 @@ Slice.defineOperations = function(classType, proxyType, ops) if(ops) { - for(var name in ops) + for(let name in ops) { addProxyOperation(proxyType, name, ops[name]); } @@ -762,10 +751,10 @@ Slice.defineOperations = function(classType, proxyType, ops) // if(proxyType.__implements) { - for(var intf in proxyType.__implements) + for(let intf in proxyType.__implements) { - var proto = proxyType.__implements[intf].prototype; - for(var f in proto) + let proto = proxyType.__implements[intf].prototype; + for(let f in proto) { if(typeof proto[f] == "function" && proxyType.prototype[f] === undefined) { |