diff --git a/src/vs/base/common/marshalling.ts b/src/vs/base/common/marshalling.ts index eeb7773075d91178b1cad4671a5cf5f18ff378bd..b28460f743eded07f9a1854d546022f905faa8d0 100644 --- a/src/vs/base/common/marshalling.ts +++ b/src/vs/base/common/marshalling.ts @@ -25,17 +25,12 @@ export function registerMarshallingContribution(contribution:IMarshallingContrib marshallingContributions.push(contribution); } -var currentDynamicContrib:IMarshallingContribution = null; - export function canSerialize(obj: any): boolean { for (let contrib of marshallingContributions) { if (contrib.canSerialize(obj)) { return true; } } - if (currentDynamicContrib && currentDynamicContrib.canSerialize(obj)) { - return true; - } } export function serialize(obj:any): any { @@ -47,9 +42,6 @@ export function serialize(obj:any): any { return contrib.serialize(orig, serialize); } } - if (currentDynamicContrib && currentDynamicContrib.canSerialize(orig)) { - return currentDynamicContrib.serialize(orig, serialize); - } } return undefined; }); @@ -64,9 +56,6 @@ export function deserialize(obj:any): any { return contrib.deserialize(orig, deserialize); } } - if (currentDynamicContrib && currentDynamicContrib.canDeserialize(orig)) { - return currentDynamicContrib.deserialize(orig, deserialize); - } } return undefined; }); @@ -116,24 +105,18 @@ registerMarshallingContribution({ -export function marshallObject(obj: any, dynamicContrib: IMarshallingContribution = null): string { - currentDynamicContrib = dynamicContrib; - const r = serialize(obj); - currentDynamicContrib = null; - return r; +export function marshallObject(obj: any): string { + return serialize(obj); } -export function marshallObjectAndStringify(obj: any, dynamicContrib: IMarshallingContribution = null): string { - return JSON.stringify(marshallObject(obj, dynamicContrib)); +export function marshallObjectAndStringify(obj: any): string { + return JSON.stringify(marshallObject(obj)); } -export function demarshallObject(data: any, dynamicContrib: IMarshallingContribution = null) { - currentDynamicContrib = dynamicContrib; - const r = deserialize(data); - currentDynamicContrib = null; - return r; +export function demarshallObject(data: any) { + return deserialize(data); } -export function parseAndDemarshallObject(serialized: string, dynamicContrib: IMarshallingContribution = null): any { - return demarshallObject(JSON.parse(serialized), dynamicContrib); +export function parseAndDemarshallObject(serialized: string): any { + return demarshallObject(JSON.parse(serialized)); } \ No newline at end of file diff --git a/src/vs/base/common/remote.ts b/src/vs/base/common/remote.ts index 1822f479b89864313bbe557ee4f916156adc2146..83257ef42ca6d879f4d7e4def7ad3734733dd84d 100644 --- a/src/vs/base/common/remote.ts +++ b/src/vs/base/common/remote.ts @@ -38,76 +38,3 @@ function createMethodProxy(remote:IProxyHelper, proxyId: string, path: string): return remote.callOnRemote(proxyId, path, myArgs); }; } - -export interface IObjDescriptor { - methods: string[]; - props: {[name:string]:any;}; -} - -export interface ISerializedProxy { - $isProxyDescriptor: boolean; - proxyId: string; - desc: IObjDescriptor; -} - -export class ProxiesMarshallingContribution implements IMarshallingContribution { - - private _remoteCom:IProxyHelper; - - constructor(remoteCom:IProxyHelper) { - this._remoteCom = remoteCom; - } - - public canSerialize(obj:any): boolean { - return (typeof obj.$__CREATE__PROXY__REQUEST === 'string'); - } - - public serialize(obj:any, serialize:(obj:any)=>any): ISerializedProxy { - var desc: IObjDescriptor = { - methods: [], - props: {} - }; - - var keys = Object.keys(obj); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - - if (typeof obj[key] === 'function') { - desc.methods.push(key); - } else { - desc.props[key] = serialize(obj[key]); - } - } - - return { - $isProxyDescriptor: true, - proxyId: obj.$__CREATE__PROXY__REQUEST, - desc: desc - }; - } - - public canDeserialize(obj:ISerializedProxy): boolean { - return obj.$isProxyDescriptor === true; - } - - public deserialize(obj:ISerializedProxy, deserialize:(obj:any)=>any): any { - // this is an object - var result: any = { - $__IS_REMOTE_OBJ: true - }; - - var methods = obj.desc.methods; - for (var i = 0; i < methods.length; i++) { - result[methods[i]] = createMethodProxy(this._remoteCom, obj.proxyId, methods[i]); - } - - var props = obj.desc.props; - for (var prop in props) { - if (hasOwnProperty.call(props, prop)) { - result[prop] = deserialize(props[prop]); - } - } - - return result; - } -} \ No newline at end of file diff --git a/src/vs/base/common/worker/workerClient.ts b/src/vs/base/common/worker/workerClient.ts index b0e0a1ecf1798e4e4ad545f6d56e33bfe94133a7..66925733cc608940c0caa6641973d25f399fd029 100644 --- a/src/vs/base/common/worker/workerClient.ts +++ b/src/vs/base/common/worker/workerClient.ts @@ -49,7 +49,6 @@ export class WorkerClient { private _lastTimerEvent:timer.ITimerEvent; private _remoteCom: protocol.RemoteCom; - private _proxiesMarshalling: remote.ProxiesMarshallingContribution; private _decodeMessageName: (msg: protocol.IClientMessage) => string; public onModuleLoaded:TPromise; @@ -92,7 +91,6 @@ export class WorkerClient { this.onModuleLoaded.then(null, () => this._onError('Worker failed to load ' + moduleId)); this._remoteCom = new protocol.RemoteCom(this); - this._proxiesMarshalling = new remote.ProxiesMarshallingContribution(this._remoteCom); } public getRemoteCom(): remote.IRemoteCom { @@ -254,13 +252,13 @@ export class WorkerClient { } private _postMessage(msg:any): void { - this._worker.postMessage(marshalling.marshallObjectAndStringify(msg, this._proxiesMarshalling)); + this._worker.postMessage(marshalling.marshallObjectAndStringify(msg)); } private _onSerializedMessage(msg:string): void { var message:protocol.IServerMessage = null; try { - message = marshalling.parseAndDemarshallObject(msg, this._proxiesMarshalling); + message = marshalling.parseAndDemarshallObject(msg); } catch (e) { // nothing } diff --git a/src/vs/base/common/worker/workerServer.ts b/src/vs/base/common/worker/workerServer.ts index 3e7ae80fd80cadacd8d45b831831528ac3ccb2ce..8433bfc9be5f274bbc0d218362ff66b75efd5640 100644 --- a/src/vs/base/common/worker/workerServer.ts +++ b/src/vs/base/common/worker/workerServer.ts @@ -24,7 +24,6 @@ export class WorkerServer { private _lastReq: number; private _awaitedReplies: { [req:string]: IReplyCallbacks; }; private _remoteCom: protocol.RemoteCom; - private _proxiesMarshalling: remote.ProxiesMarshallingContribution; constructor(postSerializedMessage:(msg:string)=>void) { this._postSerializedMessage = postSerializedMessage; @@ -35,7 +34,6 @@ export class WorkerServer { this._bindConsole(); this._remoteCom = new protocol.RemoteCom(this); - this._proxiesMarshalling = new remote.ProxiesMarshallingContribution(this._remoteCom); } public getRemoteCom(): remote.IRemoteCom { @@ -122,11 +120,11 @@ export class WorkerServer { } public onmessage(msg:string): void { - this._onmessage(marshalling.parseAndDemarshallObject(msg, this._proxiesMarshalling)); + this._onmessage(marshalling.parseAndDemarshallObject(msg)); } private _postMessage(msg:protocol.IServerMessage): void { - this._postSerializedMessage(marshalling.marshallObjectAndStringify(msg, this._proxiesMarshalling)); + this._postSerializedMessage(marshalling.marshallObjectAndStringify(msg)); } private _onmessage(msg:protocol.IClientMessage): void { diff --git a/src/vs/base/test/common/marshalling.test.ts b/src/vs/base/test/common/marshalling.test.ts deleted file mode 100644 index 5ba9565a5042eee5647d4224a27e52127ea85b98..0000000000000000000000000000000000000000 --- a/src/vs/base/test/common/marshalling.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -'use strict'; - -import * as assert from 'assert'; -import { IMarshallingContribution, marshallObjectAndStringify, parseAndDemarshallObject } from 'vs/base/common/marshalling'; - -class ObjWithRegExp { - - public member:RegExp; - - constructor(something:RegExp) { - this.member = something; - } -} - -suite('Marshalling', () => { - test('bug #17587:[plugin] Language plugin can\'t define a TokenTypeClassificationSupport#wordDefinition', () => { - - var simpleMarshallingContrib: IMarshallingContribution = { - canSerialize: (obj:any) => { - return obj instanceof ObjWithRegExp; - }, - serialize: (obj:any, serialize:(obj:any)=>any) => { - return { - $ObjWithRegExp: true, - member: serialize(obj.member) - }; - }, - canDeserialize: (obj:any) => { - return (obj.$ObjWithRegExp === true); - }, - deserialize: (obj:any, deserialize:(obj:any)=>any) => { - return new ObjWithRegExp(deserialize(obj.member)); - } - }; - - var initial = new ObjWithRegExp(/test/g); - var transported = parseAndDemarshallObject(marshallObjectAndStringify(initial, simpleMarshallingContrib), simpleMarshallingContrib); - - assert(transported instanceof ObjWithRegExp); - assert(transported.member instanceof RegExp); - assert.equal(transported.member.source, 'test'); - assert.equal(transported.member.global, true); - assert.equal(transported.member.ignoreCase, false); - assert.equal(transported.member.multiline, false); - }); -}); \ No newline at end of file diff --git a/src/vs/base/test/common/remote.test.ts b/src/vs/base/test/common/remote.test.ts deleted file mode 100644 index 5092c70091fbbecfb5e30689c2512b51b84fdfb1..0000000000000000000000000000000000000000 --- a/src/vs/base/test/common/remote.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -'use strict'; - -import * as assert from 'assert'; -import { marshallObjectAndStringify, parseAndDemarshallObject } from 'vs/base/common/marshalling'; -import { ProxiesMarshallingContribution } from 'vs/base/common/remote'; -import { TPromise} from 'vs/base/common/winjs.base'; - -suite('Remote', () => { - test('bug #17587:[plugin] Language plugin can\'t define a TokenTypeClassificationSupport#wordDefinition', () => { - - var contrib = new ProxiesMarshallingContribution({ - callOnRemote: () => TPromise.as(true) - }); - - var initial = { - $__CREATE__PROXY__REQUEST: 'myId', - member: /test/g - }; - var transported = parseAndDemarshallObject(marshallObjectAndStringify(initial, contrib), contrib); - - assert.equal(transported.$__IS_REMOTE_OBJ, true); - assert(transported.member instanceof RegExp); - assert.equal(transported.member.source, 'test'); - assert.equal(transported.member.global, true); - assert.equal(transported.member.ignoreCase, false); - assert.equal(transported.member.multiline, false); - }); -}); \ No newline at end of file diff --git a/src/vs/platform/plugins/common/ipcRemoteCom.ts b/src/vs/platform/plugins/common/ipcRemoteCom.ts index 5efb34e7e6c662948cab09944d1aa78da507fe23..34835eee8686017fdb141f7c180e3ce9964af23e 100644 --- a/src/vs/platform/plugins/common/ipcRemoteCom.ts +++ b/src/vs/platform/plugins/common/ipcRemoteCom.ts @@ -68,7 +68,7 @@ export function create(send: (obj: string) => void): IPluginsIPC { bigHandler = _bigHandler; }, handle: (rawmsg) => { - var msg = marshalling.demarshallObject(rawmsg, proxiesMarshalling); + var msg = marshalling.demarshallObject(rawmsg); if (msg.seq) { if (!pendingRPCReplies.hasOwnProperty(msg.seq)) { @@ -132,10 +132,8 @@ export function create(send: (obj: string) => void): IPluginsIPC { } }; - var proxiesMarshalling = new remote.ProxiesMarshallingContribution(r); - function marshallAndSend(msg:any): void { - send(marshalling.marshallObject(msg, proxiesMarshalling)); + send(marshalling.marshallObject(msg)); } function invokeHandler(rpcId:string, method:string, args:any[]): winjs.TPromise { diff --git a/src/vs/platform/thread/common/abstractThreadService.ts b/src/vs/platform/thread/common/abstractThreadService.ts index 67ab4a186a35df54e983068030f86876d4a8959d..39230e69b10a912ad4a012dbddf61128d24a6455 100644 --- a/src/vs/platform/thread/common/abstractThreadService.ts +++ b/src/vs/platform/thread/common/abstractThreadService.ts @@ -163,63 +163,6 @@ export abstract class AbstractThreadService implements remote.IManyHandler { return result; } - public createDynamicProxyFromMethods(obj:T): IDynamicProxy { - let id = AbstractThreadService.generateDynamicProxyId(); - let proxyDefinition = this._proxifyMethods(id, obj); - return new DynamicProxy(proxyDefinition, () => { - delete this._localObjMap[id]; - }); - } - - public createDynamicProxyFromMembers(obj:T, allowedMembers:string[]): IDynamicProxy { - let id = AbstractThreadService.generateDynamicProxyId(); - let proxyDefinition = this._proxifyMembers(id, obj, allowedMembers); - return new DynamicProxy(proxyDefinition, () => { - delete this._localObjMap[id]; - }); - } - - private _proxifyMethods(uniqueIdentifier: string, obj:T): T { - if (!Types.isObject(obj)) { - return null; - } - this._localObjMap[uniqueIdentifier] = obj; - var r: any = { - $__CREATE__PROXY__REQUEST: uniqueIdentifier - }; - for (var prop in obj) { - if (typeof obj[prop] === 'function') { - r[prop] = obj[prop].bind(obj); - } - } - return r; - } - - private _proxifyMembers(uniqueIdentifier: string, obj:T, allowedMembers:string[]): T { - if (!Types.isObject(obj)) { - return null; - } - this._localObjMap[uniqueIdentifier] = obj; - var r: any = { - $__CREATE__PROXY__REQUEST: uniqueIdentifier - }; - for (var prop in obj) { - if (allowedMembers.indexOf(prop) === -1) { - continue; - } - if (typeof obj[prop] === 'function') { - r[prop] = obj[prop].bind(obj); - } else { - r[prop] = obj[prop]; - } - } - return r; - } - - public isProxyObject(obj: T): boolean { - return obj && !!((obj).$__IS_REMOTE_OBJ); - } - getRemotable(ctor: instantiation.INewConstructorSignature0): T { var id = Remotable.getId(ctor); if (!id) { diff --git a/src/vs/platform/thread/common/thread.ts b/src/vs/platform/thread/common/thread.ts index ce36c619d33c3c509423b4713d6efbe62d4f3a7e..24677bf7deff15cfaf5b9b5c19a30a82a4548961 100644 --- a/src/vs/platform/thread/common/thread.ts +++ b/src/vs/platform/thread/common/thread.ts @@ -46,10 +46,6 @@ export interface IThreadService { // --- END deprecated methods - createDynamicProxyFromMethods(obj:T): IDynamicProxy; - createDynamicProxyFromMembers(obj:T, allowedMembers:string[]): IDynamicProxy; - isProxyObject(obj: T): boolean; - getRemotable(ctor: instantiation.INewConstructorSignature0): T; registerRemotableInstance(ctor: any, instance: any): void;