提交 15d15c1f 编写于 作者: J Johannes Rieken

remove dynamic marshalling contributions cos they aren't needed anymore

上级 5e36bffc
......@@ -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
......@@ -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: <any>{}
};
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
......@@ -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<void>;
......@@ -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
}
......
......@@ -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 {
......
/*---------------------------------------------------------------------------------------------
* 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 = <ObjWithRegExp>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
/*---------------------------------------------------------------------------------------------
* 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
......@@ -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<any> {
......
......@@ -163,63 +163,6 @@ export abstract class AbstractThreadService implements remote.IManyHandler {
return result;
}
public createDynamicProxyFromMethods<T>(obj:T): IDynamicProxy<T> {
let id = AbstractThreadService.generateDynamicProxyId();
let proxyDefinition = this._proxifyMethods(id, obj);
return new DynamicProxy(proxyDefinition, () => {
delete this._localObjMap[id];
});
}
public createDynamicProxyFromMembers<T>(obj:T, allowedMembers:string[]): IDynamicProxy<T> {
let id = AbstractThreadService.generateDynamicProxyId();
let proxyDefinition = this._proxifyMembers(id, obj, allowedMembers);
return new DynamicProxy(proxyDefinition, () => {
delete this._localObjMap[id];
});
}
private _proxifyMethods<T>(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<T>(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<T>(obj: T): boolean {
return obj && !!((<any>obj).$__IS_REMOTE_OBJ);
}
getRemotable<T>(ctor: instantiation.INewConstructorSignature0<T>): T {
var id = Remotable.getId(ctor);
if (!id) {
......
......@@ -46,10 +46,6 @@ export interface IThreadService {
// --- END deprecated methods
createDynamicProxyFromMethods<T>(obj:T): IDynamicProxy<T>;
createDynamicProxyFromMembers<T>(obj:T, allowedMembers:string[]): IDynamicProxy<T>;
isProxyObject<T>(obj: T): boolean;
getRemotable<T>(ctor: instantiation.INewConstructorSignature0<T>): T;
registerRemotableInstance(ctor: any, instance: any): void;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册