All files / src/Ice ObjectPrxExtensions.js

89.66% Statements 434/484
86.71% Branches 124/143
96.72% Functions 59/61
89.66% Lines 434/484

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 48541x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 196x 41x 41x 41x 3790x 41x 41x 41x 11x 41x 41x 41x 115x 41x 41x 41x 9x     9x   9x 9x 9x 41x 41x 41x 12x 41x 41x 41x 15x 41x 41x 41x 38x 41x 41x 41x 19x     19x 19x   19x 19x 19x 41x 41x 41x 19x 41x 41x 41x 2x     2x 2x   2x 2x 2x 41x 41x 41x 159x 41x 41x 41x 60x     60x 60x   60x 60x 60x 41x 41x 41x 5x 41x 41x 41x 31x 1x 1x 31x 3x 31x 27x 27x 41x 41x 41x 4x 41x 41x 41x 17x 2x 2x 17x 1x 17x 14x 14x 41x 41x 41x 6x 41x 41x 41x 13x 5x 13x 8x 8x 41x 41x 41x 7x 41x 41x 41x 11x 6x 11x 5x 5x 41x 41x 41x 20x 41x 41x 41x 17x 5x 17x 12x 12x 41x 41x 41x 9x 9x 41x 41x 41x 32x 32x 24x 32x 8x 8x 41x 41x 41x 8x 8x 41x 41x 41x 168x 168x 157x 168x 11x 11x 41x 41x 41x 5961x 41x 41x 41x 2x 2x 2x     41x 41x 41x 3x 41x 41x 41x 13x   13x 13x 13x 41x 41x 41x 7075x 41x 41x 41x 18x   18x 18x 18x 41x 41x 41x 15x     15x     15x 15x 1x 15x 14x 14x 41x 41x 41x 2x 41x 41x 41x 2x 41x 41x 41x 12x   12x 12x 12x 41x 41x 41x 239x 239x 239x 239x     239x 41x 41x 41x 25x 41x 41x 41x 13x 13x 13x 13x     13x 41x 41x 41x 256x 4x 4x 252x 252x 249x 249x 3x 3x 41x 41x 41x 189x 189x 41x 41x 41x 15766x 41x 41x 41x 1095x 4x 4x 41x 41x 41x 41x 41x 41x 1415x 1415x 220x 220x     220x 1415x 870x 870x 1192x 325x 325x 325x     41x 41x 41x 219x 41x 41x 41x               41x 41x 41x 41x 41x 41x 3541x 1095x 1095x 3537x 3537x 2357x 3537x 3537x 3537x 3537x 3541x 2804x 3540x 732x 732x 732x 732x 3515x 3541x 22x 22x 3537x 41x 41x 41x 41x 41x 41x 2357x 66x 66x 2291x 2291x 2333x 1310x 1310x 2357x 981x 981x 2357x 2x 2x 41x 41x 41x 41x 41x 41x 2357x 2357x 2357x 2357x 2357x 2357x 66x 66x 66x 67x 55x 55x 55x 67x 11x 11x 11x 28x       66x 2291x 2291x 41x 41x 41x 2x 41x 41x 41x 29x 29x 29x 8x 8x 29x 29x 28x 28x 29x 28x 41x 41x 41x 326x 41x 41x 41x 41x 41x 167x 41x 41x 41x 468x 41x 41x 41x 30x 41x 41x 41x 27x 41x 41x 41x                       41x 41x 41x 29x 41x 41x 41x 41x  
// Copyright (c) ZeroC, Inc.
 
import { ObjectPrx } from "./ObjectPrx.js";
 
import { ArrayUtil } from "./ArrayUtil.js";
import { OutgoingAsync, ProxyFlushBatch, ProxyGetConnection } from "./OutgoingAsync.js";
import { ReferenceMode } from "./ReferenceMode.js";
import { UserException } from "./UserException.js";
import { ParseException, TwowayOnlyException, UnknownUserException } from "./LocalExceptions.js";
import { ConnectionI } from "./ConnectionI.js";
import { TypeRegistry } from "./TypeRegistry.js";
import { Communicator } from "./Communicator.js";
import { Reference } from "./Reference.js";
import { RequestHandlerCache } from "./RequestHandlerCache.js";
 
ObjectPrx.prototype.hashCode = function () {
    return this._reference.hashCode();
};
 
ObjectPrx.prototype.ice_getCommunicator = function () {
    return this._reference.getCommunicator();
};
 
ObjectPrx.prototype.toString = function () {
    return this._reference.toString();
};
 
ObjectPrx.prototype.ice_getIdentity = function () {
    return this._reference.getIdentity().clone();
};
 
ObjectPrx.prototype.ice_identity = function (newIdentity) {
    if (newIdentity === undefined || newIdentity === null || newIdentity.name.length === 0) {
        throw new TypeError("The name of an Ice object identity cannot be empty.");
    }
    if (newIdentity.equals(this._reference.getIdentity())) {
        return this;
    } else {
        return new ObjectPrx(this._reference.changeIdentity(newIdentity));
    }
};
 
ObjectPrx.prototype.ice_getContext = function () {
    return new Map(this._reference.getContext());
};
 
ObjectPrx.prototype.ice_context = function (newContext) {
    return this._newInstance(this._reference.changeContext(newContext));
};
 
ObjectPrx.prototype.ice_getFacet = function () {
    return this._reference.getFacet();
};
 
ObjectPrx.prototype.ice_facet = function (newFacet) {
    if (newFacet === undefined || newFacet === null) {
        newFacet = "";
    }
 
    if (newFacet === this._reference.getFacet()) {
        return this;
    } else {
        return new ObjectPrx(this._reference.changeFacet(newFacet));
    }
};
 
ObjectPrx.prototype.ice_getAdapterId = function () {
    return this._reference.getAdapterId();
};
 
ObjectPrx.prototype.ice_adapterId = function (newAdapterId) {
    if (newAdapterId === undefined || newAdapterId === null) {
        newAdapterId = "";
    }
 
    if (newAdapterId === this._reference.getAdapterId()) {
        return this;
    } else {
        return this._newInstance(this._reference.changeAdapterId(newAdapterId));
    }
};
 
ObjectPrx.prototype.ice_getEndpoints = function () {
    return ArrayUtil.clone(this._reference.getEndpoints());
};
 
ObjectPrx.prototype.ice_endpoints = function (newEndpoints) {
    if (newEndpoints === undefined || newEndpoints === null) {
        newEndpoints = [];
    }
 
    if (ArrayUtil.equals(newEndpoints, this._reference.getEndpoints())) {
        return this;
    } else {
        return this._newInstance(this._reference.changeEndpoints(newEndpoints));
    }
};
 
ObjectPrx.prototype.ice_getLocatorCacheTimeout = function () {
    return this._reference.getLocatorCacheTimeout();
};
 
ObjectPrx.prototype.ice_locatorCacheTimeout = function (newTimeout) {
    if (newTimeout < -1) {
        throw new RangeError("invalid value passed to ice_locatorCacheTimeout: " + newTimeout);
    }
    if (newTimeout === this._reference.getLocatorCacheTimeout()) {
        return this;
    } else {
        return this._newInstance(this._reference.changeLocatorCacheTimeout(newTimeout));
    }
};
 
ObjectPrx.prototype.ice_getInvocationTimeout = function () {
    return this._reference.getInvocationTimeout();
};
 
ObjectPrx.prototype.ice_invocationTimeout = function (newTimeout) {
    if (newTimeout < 1 && newTimeout !== -1) {
        throw new RangeError("invalid value passed to ice_invocationTimeout: " + newTimeout);
    }
    if (newTimeout === this._reference.getInvocationTimeout()) {
        return this;
    } else {
        return this._newInstance(this._reference.changeInvocationTimeout(newTimeout));
    }
};
 
ObjectPrx.prototype.ice_isConnectionCached = function () {
    return this._reference.getCacheConnection();
};
 
ObjectPrx.prototype.ice_connectionCached = function (newCache) {
    if (newCache === this._reference.getCacheConnection()) {
        return this;
    } else {
        return this._newInstance(this._reference.changeCacheConnection(newCache));
    }
};
 
ObjectPrx.prototype.ice_getEndpointSelection = function () {
    return this._reference.getEndpointSelection();
};
 
ObjectPrx.prototype.ice_endpointSelection = function (newType) {
    if (newType === this._reference.getEndpointSelection()) {
        return this;
    } else {
        return this._newInstance(this._reference.changeEndpointSelection(newType));
    }
};
 
ObjectPrx.prototype.ice_getEncodingVersion = function () {
    return this._reference.getEncoding().clone();
};
 
ObjectPrx.prototype.ice_encodingVersion = function (e) {
    if (e.equals(this._reference.getEncoding())) {
        return this;
    } else {
        return this._newInstance(this._reference.changeEncoding(e));
    }
};
 
ObjectPrx.prototype.ice_getRouter = function () {
    const ri = this._reference.getRouterInfo();
    return ri !== null ? ri.getRouter() : null;
};
 
ObjectPrx.prototype.ice_router = function (router) {
    const ref = this._reference.changeRouter(router);
    if (ref.equals(this._reference)) {
        return this;
    } else {
        return this._newInstance(ref);
    }
};
 
ObjectPrx.prototype.ice_getLocator = function () {
    const ri = this._reference.getLocatorInfo();
    return ri !== null ? ri.getLocator() : null;
};
 
ObjectPrx.prototype.ice_locator = function (locator) {
    const ref = this._reference.changeLocator(locator);
    if (ref.equals(this._reference)) {
        return this;
    } else {
        return this._newInstance(ref);
    }
};
 
ObjectPrx.prototype.ice_isTwoway = function () {
    return this._reference.getMode() === ReferenceMode.ModeTwoway;
};
 
ObjectPrx.prototype.ice_twoway = function () {
    if (this._reference.getMode() === ReferenceMode.ModeTwoway) {
        return this;
    } else {
        return this._newInstance(this._reference.changeMode(ReferenceMode.ModeTwoway));
    }
};
 
ObjectPrx.prototype.ice_isOneway = function () {
    return this._reference.getMode() === ReferenceMode.ModeOneway;
};
 
ObjectPrx.prototype.ice_oneway = function () {
    if (this._reference.getMode() === ReferenceMode.ModeOneway) {
        return this;
    } else {
        return this._newInstance(this._reference.changeMode(ReferenceMode.ModeOneway));
    }
};
 
ObjectPrx.prototype.ice_isBatchOneway = function () {
    return this._reference.getMode() === ReferenceMode.ModeBatchOneway;
};
 
ObjectPrx.prototype.ice_batchOneway = function () {
    if (this._reference.getMode() === ReferenceMode.ModeBatchOneway) {
        return this;
    } else {
        return this._newInstance(this._reference.changeMode(ReferenceMode.ModeBatchOneway));
    }
};
 
ObjectPrx.prototype.ice_fixed = function (connection) {
    if (connection === null) {
        throw new RangeError("invalid null connection passed to ice_fixed");
    }
    if (!(connection instanceof ConnectionI)) {
        throw new RangeError("invalid connection passed to ice_fixed");
    }
    const ref = this._reference.changeConnection(connection);
    if (ref.equals(this._reference)) {
        return this;
    } else {
        return this._newInstance(ref);
    }
};
 
ObjectPrx.prototype.ice_isFixed = function () {
    return this._reference.isFixed();
};
 
ObjectPrx.prototype.ice_getConnectionId = function () {
    return this._reference.getConnectionId();
};
 
ObjectPrx.prototype.ice_connectionId = function (id) {
    if (id == this._reference.getConnectionId()) {
        return this;
    } else {
        return this._newInstance(this._reference.changeConnectionId(id));
    }
};
 
ObjectPrx.prototype.ice_getConnection = function () {
    const r = new ProxyGetConnection(this, "ice_getConnection");
    try {
        r.invoke();
    } catch (ex) {
        r.abort(ex);
    }
    return r;
};
 
ObjectPrx.prototype.ice_getCachedConnection = function () {
    return this._requestHandlerCache.cachedConnection;
};
 
ObjectPrx.prototype.ice_flushBatchRequests = function () {
    const r = new ProxyFlushBatch(this, "ice_flushBatchRequests");
    try {
        r.invoke();
    } catch (ex) {
        r.abort(ex);
    }
    return r;
};
 
ObjectPrx.prototype.equals = function (r) {
    if (this === r) {
        return true;
    }
 
    if (r instanceof ObjectPrx) {
        return this._reference.equals(r._reference);
    }
 
    return false;
};
 
ObjectPrx.prototype._write = function (os) {
    this._reference.getIdentity()._write(os);
    this._reference.streamWrite(os);
};
 
ObjectPrx.prototype._getReference = function () {
    return this._reference;
};
 
ObjectPrx.prototype._checkAsyncTwowayOnly = function (name) {
    if (!this.ice_isTwoway()) {
        throw new TwowayOnlyException(name);
    }
};
 
//
// Only for use by ObjectPrx constructor
//
ObjectPrx.prototype._setup = function (arg0, proxyString = "") {
    console.assert(this._reference === undefined);
    if (arg0 instanceof Communicator) {
        this._reference = arg0.instance.referenceFactory().createFromString(proxyString, "");
        if (this._reference === null) {
            throw new ParseException("Invalid empty proxy string.");
        }
        this._requestHandlerCache = new RequestHandlerCache(this._reference);
    } else if (arg0 instanceof Reference) {
        this._reference = arg0;
        this._requestHandlerCache = new RequestHandlerCache(this._reference);
    } else if (arg0 instanceof ObjectPrx) {
        this._reference = arg0._reference;
        this._requestHandlerCache = arg0._requestHandlerCache;
    } else {
        throw new Error("invalid argument passed to ObjectPrx constructor");
    }
};
 
ObjectPrx.prototype._newInstance = function (ref) {
    return new this.constructor(ref);
};
 
ObjectPrx.prototype.ice_instanceof = function (T) {
    if (T) {
        if (this instanceof T) {
            return true;
        }
        return this.constructor._instanceof(T);
    }
    return false;
};
 
//
// Generic invocation for operations that have input parameters.
//
ObjectPrx._invoke = function (p, name, mode, fmt, ctx, marshalFn, unmarshalFn, userEx, args) {
    if (unmarshalFn !== null || userEx.length > 0) {
        p._checkAsyncTwowayOnly(name);
    }
 
    const r = new OutgoingAsync(p, name, res => {
        this._completed(res, unmarshalFn, userEx);
    });
 
    try {
        r.prepare(mode, ctx);
        if (marshalFn === null) {
            r.writeEmptyParams();
        } else {
            const ostr = r.startWriteParams(fmt);
            marshalFn(ostr, args);
            r.endWriteParams();
        }
        r.invoke();
    } catch (ex) {
        r.abort(ex);
    }
    return r;
};
 
//
// Handles the completion of an invocation.
//
ObjectPrx._completed = function (r, unmarshalFn, userEx) {
    if (!this._check(r, userEx)) {
        return;
    }
 
    try {
        if (unmarshalFn === null) {
            r.readEmptyParams();
            r.resolve();
        } else {
            r.resolve(unmarshalFn(r));
        }
    } catch (ex) {
        this.dispatchLocalException(r, ex);
    }
};
 
//
// Handles user exceptions.
//
ObjectPrx._check = function (r, uex) {
    //
    // If uex is non-null, it must be an array of exception types.
    //
    try {
        r.throwUserException();
    } catch (ex) {
        if (ex instanceof UserException) {
            if (uex !== null) {
                for (let i = 0; i < uex.length; ++i) {
                    if (ex instanceof uex[i]) {
                        r.reject(ex);
                        return false;
                    }
                }
            }
            r.reject(new UnknownUserException(ex.ice_id()));
            return false;
        } else {
            r.reject(ex);
            return false;
        }
    }
 
    return true;
};
 
ObjectPrx.dispatchLocalException = function (r, ex) {
    r.reject(ex);
};
 
ObjectPrx.checkedCast = async function (prx, facet, ctx) {
    let r = null;
    if (prx !== undefined && prx !== null) {
        if (facet !== undefined) {
            prx = prx.ice_facet(facet);
        }
 
        if (await prx.ice_isA(this.ice_staticId(), ctx)) {
            r = new this(prx);
        }
    }
    return r;
};
 
ObjectPrx.uncheckedCast = function (prx, facet) {
    return prx === null ? null : new this(facet === undefined ? prx : prx.ice_facet(facet));
};
 
Object.defineProperty(ObjectPrx, "minWireSize", { get: () => 2 });
 
ObjectPrx.write = function (os, v) {
    os.writeProxy(v);
};
 
ObjectPrx.read = function (is) {
    return is.readProxy(this);
};
 
ObjectPrx.writeOptional = function (os, tag, v) {
    os.writeOptionalProxy(tag, v);
};
 
ObjectPrx.readOptional = function (is, tag) {
    return is.readOptionalProxy(tag, this);
};
 
ObjectPrx._instanceof = function (T) {
    if (T === this) {
        return true;
    }

    for (const i in this._implements) {
        if (this._implements[i]._instanceof(T)) {
            return true;
        }
    }

    return false;
};
 
ObjectPrx.ice_staticId = function () {
    return this._id;
};
 
Object.defineProperty(ObjectPrx, "_implements", { get: () => [] });
TypeRegistry.declareProxyType("Ice.ObjectPrx", ObjectPrx);