This commit is contained in:
Rob 2015-10-20 13:54:05 -07:00
Родитель 33254488ae
Коммит 27782ee71b
5 изменённых файлов: 25 добавлений и 25 удалений

Просмотреть файл

@ -7,7 +7,7 @@ import Utilities = require('../webkit/utilities');
export type EventHandler = (event: DebugProtocol.Event) => void;
export class AdapterProxy {
public constructor(private _requestTranslators: IDebugTranslator[], private _debugAdapter: IDebugAdapter, private _eventHandler: EventHandler) {
public constructor(private _requestTransformers: IDebugTransformer[], private _debugAdapter: IDebugAdapter, private _eventHandler: EventHandler) {
this._debugAdapter.registerEventHandler(this._eventHandler);
}
@ -16,45 +16,45 @@ export class AdapterProxy {
Promise.reject('unknowncommand');
}
return this.translateRequest(request)
return this.transformRequest(request)
// Pass the modified args to the adapter
.then(() => this._debugAdapter[request.command](request.arguments))
// Pass the body back through the translators and ensure the body is returned
// Pass the body back through the transformers and ensure the body is returned
.then((body?) => {
return this.translateResponse(request, body)
return this.transformResponse(request, body)
.then(() => body);
});
}
/**
* Pass the request arguments through the translators. They modify the object in place.
* Pass the request arguments through the transformers. They modify the object in place.
*/
private translateRequest(request: DebugProtocol.Request): Promise<void> {
return this._requestTranslators.reduce(
(p, translator) => {
// If the translator implements this command, give it a chance to modify the args. Otherwise skip it
return request.command in translator ?
p.then(() => translator[request.command](request.arguments)) :
private transformRequest(request: DebugProtocol.Request): Promise<void> {
return this._requestTransformers.reduce(
(p, transformer) => {
// If the transformer implements this command, give it a chance to modify the args. Otherwise skip it
return request.command in transformer ?
p.then(() => transformer[request.command](request.arguments)) :
p;
}, Promise.resolve<void>())
}
/**
* Pass the response body back through the translators in reverse order. They modify the body in place.
* Pass the response body back through the transformers in reverse order. They modify the body in place.
*/
private translateResponse(request: DebugProtocol.Request, body: any): Promise<void> {
private transformResponse(request: DebugProtocol.Request, body: any): Promise<void> {
if (!body) {
return Promise.resolve<void>();
}
const reversedTranslators = Utilities.reversedArr(this._requestTranslators);
return reversedTranslators.reduce(
(p, translator) => {
// If the translator implements this command, give it a chance to modify the args. Otherwise skip it
const bodyTranslateMethodName = request.command + "Response";
return bodyTranslateMethodName in translator ?
p.then(() => translator[bodyTranslateMethodName](body)) :
const reversedTransformers = Utilities.reversedArr(this._requestTransformers);
return reversedTransformers.reduce(
(p, transformer) => {
// If the transformer implements this command, give it a chance to modify the args. Otherwise skip it
const bodyTransformMethodName = request.command + "Response";
return bodyTransformMethodName in transformer ?
p.then(() => transformer[bodyTransformMethodName](body)) :
p;
}, Promise.resolve<void>());
}

Просмотреть файл

@ -5,7 +5,7 @@
/**
* Converts from 1 based lines on the client side to 0 based lines on the target side
*/
export class LineNumberTranslator {
export class LineNumberTransformer implements IDebugTransformer {
private _targetLinesStartAt1: boolean;
private _clientLinesStartAt1: boolean;

Просмотреть файл

@ -9,7 +9,7 @@
},
"files": [
"adapter/adapterProxy.ts",
"adapter/lineNumberTranslator.ts",
"adapter/lineNumberTransformer.ts",
"webkit/openDebugWebKit.ts",
"webkit/pathUtilities.ts",
"webkit/sourceMaps.ts",

2
webkit/webKitAdapterInterfaces.d.ts поставляемый
Просмотреть файл

@ -76,7 +76,7 @@ interface IDebugAdapter {
}
declare type PromiseOrNot<T> = T | Promise<T>;
interface IDebugTranslator {
interface IDebugTransformer {
initialize?(args: IInitializeRequestArgs): PromiseOrNot<void>;
launch?(args: ILaunchRequestArgs): PromiseOrNot<void>;
attach?(args: IAttachRequestArgs): PromiseOrNot<void>;

Просмотреть файл

@ -7,7 +7,7 @@ import {DebugSession, ErrorDestination} from '../common/debugSession';
import {WebKitDebugAdapter} from './webKitDebugAdapter';
import {AdapterProxy} from '../adapter/adapterProxy';
import {LineNumberTranslator} from '../adapter/lineNumberTranslator';
import {LineNumberTransformer} from '../adapter/lineNumberTransformer';
export class WebKitDebugSession extends DebugSession {
private _adapterProxy: AdapterProxy;
@ -16,7 +16,7 @@ export class WebKitDebugSession extends DebugSession {
super(targetLinesStartAt1, isServer);
this._adapterProxy = new AdapterProxy(
[new LineNumberTranslator(targetLinesStartAt1)],
[new LineNumberTransformer(targetLinesStartAt1)],
new WebKitDebugAdapter(),
event => this.sendEvent(event));
}