提交 f2e07e14 编写于 作者: A Alex Dima

Remove support for custom marshaller (#40169)

上级 fabd8a57
......@@ -27,29 +27,22 @@ export class ProxyIdentifier<T> {
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<T>(identifier: string, type: ProxyType = ProxyType.NativeJSON): ProxyIdentifier<T> {
return new ProxyIdentifier(true, 'm' + identifier, type === ProxyType.CustomMarshaller);
export function createMainContextProxyIdentifier<T>(identifier: string): ProxyIdentifier<T> {
return new ProxyIdentifier(true, 'm' + identifier);
}
export function createExtHostContextProxyIdentifier<T>(identifier: string, type: ProxyType = ProxyType.NativeJSON): ProxyIdentifier<T> {
return new ProxyIdentifier(false, 'e' + identifier, type === ProxyType.CustomMarshaller);
export function createExtHostContextProxyIdentifier<T>(identifier: string): ProxyIdentifier<T> {
return new ProxyIdentifier(false, 'e' + identifier);
}
......@@ -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<T>(identifier: ProxyIdentifier<T>): 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<T>(proxyId: string, isFancy: boolean): T {
private _createProxy<T>(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<any> {
private _remoteCall(proxyId: string, methodName: string, args: any[]): TPromise<any> {
if (this._isDisposed) {
return TPromise.wrapError<any>(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;
......@@ -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<T>(identifier: ProxyIdentifier<T>): 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<T>(proxyId: string, isFancy: boolean): T {
private _createProxy<T>(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<any> {
protected _remoteCall(proxyId: string, path: string, args: any[]): TPromise<any> {
this._callCount++;
return new TPromise<any>((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<any>;
try {
let result = (<Function>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<T>(obj: T, isFancy: boolean): T {
function simulateWireTransfer<T>(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));
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册