From f2e07e14b90dfe98d517b6ff70c79fbf1089ca7a Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 24 Jan 2018 15:51:48 +0100 Subject: [PATCH] Remove support for custom marshaller (#40169) --- .../extensions/node/proxyIdentifier.ts | 17 ++--- .../services/extensions/node/rpcProtocol.ts | 67 ++++--------------- .../electron-browser/api/testRPCProtocol.ts | 21 +++--- 3 files changed, 25 insertions(+), 80 deletions(-) diff --git a/src/vs/workbench/services/extensions/node/proxyIdentifier.ts b/src/vs/workbench/services/extensions/node/proxyIdentifier.ts index 5d2c7484abd..3447bd4255f 100644 --- a/src/vs/workbench/services/extensions/node/proxyIdentifier.ts +++ b/src/vs/workbench/services/extensions/node/proxyIdentifier.ts @@ -27,29 +27,22 @@ export class ProxyIdentifier { public readonly isMain: boolean; public readonly id: string; - public readonly isFancy: boolean; - constructor(isMain: boolean, id: string, isFancy: boolean) { + constructor(isMain: boolean, id: string) { this.isMain = isMain; this.id = id; - this.isFancy = isFancy; } } -export const enum ProxyType { - NativeJSON = 0, - CustomMarshaller = 1 -} - /** * Using `isFancy` indicates that arguments or results of type `URI` or `RegExp` * will be serialized/deserialized automatically, but this has a performance cost, * as each argument/result must be visited. */ -export function createMainContextProxyIdentifier(identifier: string, type: ProxyType = ProxyType.NativeJSON): ProxyIdentifier { - return new ProxyIdentifier(true, 'm' + identifier, type === ProxyType.CustomMarshaller); +export function createMainContextProxyIdentifier(identifier: string): ProxyIdentifier { + return new ProxyIdentifier(true, 'm' + identifier); } -export function createExtHostContextProxyIdentifier(identifier: string, type: ProxyType = ProxyType.NativeJSON): ProxyIdentifier { - return new ProxyIdentifier(false, 'e' + identifier, type === ProxyType.CustomMarshaller); +export function createExtHostContextProxyIdentifier(identifier: string): ProxyIdentifier { + return new ProxyIdentifier(false, 'e' + identifier); } diff --git a/src/vs/workbench/services/extensions/node/rpcProtocol.ts b/src/vs/workbench/services/extensions/node/rpcProtocol.ts index d738ab50737..2e1ae6d2ee8 100644 --- a/src/vs/workbench/services/extensions/node/rpcProtocol.ts +++ b/src/vs/workbench/services/extensions/node/rpcProtocol.ts @@ -5,7 +5,6 @@ 'use strict'; import { TPromise } from 'vs/base/common/winjs.base'; -import * as marshalling from 'vs/base/common/marshalling'; import * as errors from 'vs/base/common/errors'; import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc'; import { LazyPromise } from 'vs/workbench/services/extensions/node/lazyPromise'; @@ -46,17 +45,17 @@ export class RPCProtocol implements IRPCProtocol { public getProxy(identifier: ProxyIdentifier): T { if (!this._proxies[identifier.id]) { - this._proxies[identifier.id] = this._createProxy(identifier.id, identifier.isFancy); + this._proxies[identifier.id] = this._createProxy(identifier.id); } return this._proxies[identifier.id]; } - private _createProxy(proxyId: string, isFancy: boolean): T { + private _createProxy(proxyId: string): T { let handler = { get: (target, name: string) => { if (!target[name] && name.charCodeAt(0) === CharCode.DollarSign) { target[name] = (...myArgs: any[]) => { - return this._remoteCall(proxyId, name, myArgs, isFancy); + return this._remoteCall(proxyId, name, myArgs); }; } return target[name]; @@ -90,38 +89,27 @@ export class RPCProtocol implements IRPCProtocol { case MessageType.Request: this._receiveRequest(msg); break; - case MessageType.FancyRequest: - this._receiveRequest(marshalling.revive(msg, 0)); - break; case MessageType.Cancel: this._receiveCancel(msg); break; case MessageType.Reply: this._receiveReply(msg); break; - case MessageType.FancyReply: - this._receiveReply(marshalling.revive(msg, 0)); - break; case MessageType.ReplyErr: this._receiveReplyErr(msg); break; } } - private _receiveRequest(msg: RequestMessage | FancyRequestMessage): void { + private _receiveRequest(msg: RequestMessage): void { const callId = msg.id; const proxyId = msg.proxyId; - const isFancy = (msg.type === MessageType.FancyRequest); // a fancy request gets a fancy reply this._invokedHandlers[callId] = this._invokeHandler(proxyId, msg.method, msg.args); this._invokedHandlers[callId].then((r) => { delete this._invokedHandlers[callId]; - if (isFancy) { - this._multiplexor.send(MessageFactory.fancyReplyOK(callId, r)); - } else { - this._multiplexor.send(MessageFactory.replyOK(callId, r)); - } + this._multiplexor.send(MessageFactory.replyOK(callId, r)); }, (err) => { delete this._invokedHandlers[callId]; this._multiplexor.send(MessageFactory.replyErr(callId, err)); @@ -135,7 +123,7 @@ export class RPCProtocol implements IRPCProtocol { } } - private _receiveReply(msg: ReplyMessage | FancyReplyMessage): void { + private _receiveReply(msg: ReplyMessage): void { const callId = msg.id; if (!this._pendingRPCReplies.hasOwnProperty(callId)) { return; @@ -186,7 +174,7 @@ export class RPCProtocol implements IRPCProtocol { return method.apply(actor, args); } - private _remoteCall(proxyId: string, methodName: string, args: any[], isFancy: boolean): TPromise { + private _remoteCall(proxyId: string, methodName: string, args: any[]): TPromise { if (this._isDisposed) { return TPromise.wrapError(errors.canceled()); } @@ -197,13 +185,7 @@ export class RPCProtocol implements IRPCProtocol { }); this._pendingRPCReplies[callId] = result; - - if (isFancy) { - this._multiplexor.send(MessageFactory.fancyRequest(callId, proxyId, methodName, args)); - } else { - this._multiplexor.send(MessageFactory.request(callId, proxyId, methodName, args)); - } - + this._multiplexor.send(MessageFactory.request(callId, proxyId, methodName, args)); return result; } } @@ -256,10 +238,6 @@ class MessageFactory { return `{"type":${MessageType.Request},"id":"${req}","proxyId":"${rpcId}","method":"${method}","args":${JSON.stringify(args)}}`; } - public static fancyRequest(req: string, rpcId: string, method: string, args: any[]): string { - return `{"type":${MessageType.FancyRequest},"id":"${req}","proxyId":"${rpcId}","method":"${method}","args":${marshalling.stringify(args)}}`; - } - public static replyOK(req: string, res: any): string { if (typeof res === 'undefined') { return `{"type":${MessageType.Reply},"id":"${req}"}`; @@ -267,13 +245,6 @@ class MessageFactory { return `{"type":${MessageType.Reply},"id":"${req}","res":${JSON.stringify(res)}}`; } - public static fancyReplyOK(req: string, res: any): string { - if (typeof res === 'undefined') { - return `{"type":${MessageType.Reply},"id":"${req}"}`; - } - return `{"type":${MessageType.FancyReply},"id":"${req}","res":${marshalling.stringify(res)}}`; - } - public static replyErr(req: string, err: any): string { if (err instanceof Error) { return `{"type":${MessageType.ReplyErr},"id":"${req}","err":${JSON.stringify(errors.transformErrorForSerialization(err))}}`; @@ -284,11 +255,9 @@ class MessageFactory { const enum MessageType { Request = 1, - FancyRequest = 2, - Cancel = 3, - Reply = 4, - FancyReply = 5, - ReplyErr = 6 + Cancel = 2, + Reply = 3, + ReplyErr = 4 } class RequestMessage { @@ -298,13 +267,6 @@ class RequestMessage { method: string; args: any[]; } -class FancyRequestMessage { - type: MessageType.FancyRequest; - id: string; - proxyId: string; - method: string; - args: any[]; -} class CancelMessage { type: MessageType.Cancel; id: string; @@ -314,15 +276,10 @@ class ReplyMessage { id: string; res: any; } -class FancyReplyMessage { - type: MessageType.FancyReply; - id: string; - res: any; -} class ReplyErrMessage { type: MessageType.ReplyErr; id: string; err: errors.SerializedError; } -type RPCMessage = RequestMessage | FancyRequestMessage | CancelMessage | ReplyMessage | FancyReplyMessage | ReplyErrMessage; +type RPCMessage = RequestMessage | CancelMessage | ReplyMessage | ReplyErrMessage; diff --git a/src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts b/src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts index f2effd9e861..12a3f397b04 100644 --- a/src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts +++ b/src/vs/workbench/test/electron-browser/api/testRPCProtocol.ts @@ -8,7 +8,6 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { ProxyIdentifier, IRPCProtocol } from 'vs/workbench/services/extensions/node/proxyIdentifier'; import { CharCode } from 'vs/base/common/charCode'; -import * as marshalling from 'vs/base/common/marshalling'; export function SingleProxyRPCProtocol(thing: any): IRPCProtocol { return { @@ -70,17 +69,17 @@ export class TestRPCProtocol implements IRPCProtocol { public getProxy(identifier: ProxyIdentifier): T { if (!this._proxies[identifier.id]) { - this._proxies[identifier.id] = this._createProxy(identifier.id, identifier.isFancy); + this._proxies[identifier.id] = this._createProxy(identifier.id); } return this._proxies[identifier.id]; } - private _createProxy(proxyId: string, isFancy: boolean): T { + private _createProxy(proxyId: string): T { let handler = { get: (target, name: string) => { if (!target[name] && name.charCodeAt(0) === CharCode.DollarSign) { target[name] = (...myArgs: any[]) => { - return this._remoteCall(proxyId, name, myArgs, isFancy); + return this._remoteCall(proxyId, name, myArgs); }; } return target[name]; @@ -94,7 +93,7 @@ export class TestRPCProtocol implements IRPCProtocol { return value; } - protected _remoteCall(proxyId: string, path: string, args: any[], isFancy: boolean): TPromise { + protected _remoteCall(proxyId: string, path: string, args: any[]): TPromise { this._callCount++; return new TPromise((c) => { @@ -102,7 +101,7 @@ export class TestRPCProtocol implements IRPCProtocol { }).then(() => { const instance = this._locals[proxyId]; // pretend the args went over the wire... (invoke .toJSON on objects...) - const wireArgs = simulateWireTransfer(args, isFancy); + const wireArgs = simulateWireTransfer(args); let p: Thenable; try { let result = (instance[path]).apply(instance, wireArgs); @@ -114,7 +113,7 @@ export class TestRPCProtocol implements IRPCProtocol { return p.then(result => { this._callCount--; // pretend the result went over the wire... (invoke .toJSON on objects...) - const wireResult = simulateWireTransfer(result, isFancy); + const wireResult = simulateWireTransfer(result); return wireResult; }, err => { this._callCount--; @@ -128,13 +127,9 @@ export class TestRPCProtocol implements IRPCProtocol { } } -function simulateWireTransfer(obj: T, isFancy: boolean): T { +function simulateWireTransfer(obj: T): T { if (!obj) { return obj; } - return ( - isFancy - ? marshalling.parse(marshalling.stringify(obj)) - : JSON.parse(JSON.stringify(obj)) - ); + return JSON.parse(JSON.stringify(obj)); } -- GitLab