addressed comments

This commit is contained in:
Yury Semikhatsky 2019-12-10 14:33:18 -08:00
parent 137029760f
commit 4dcf886e5b

View file

@ -112,7 +112,7 @@ export class Connection extends EventEmitter {
private _dispatchMessage(message: string) { private _dispatchMessage(message: string) {
debugProtocol('◀ RECV ' + message); debugProtocol('◀ RECV ' + message);
const object = JSON.parse(message); const object = JSON.parse(message);
const eventWasEmitted = this._dispatchTargetMessageToSession(object, message); this._dispatchTargetMessageToSession(object, message);
if (object.id) { if (object.id) {
const callback = this._callbacks.get(object.id); const callback = this._callbacks.get(object.id);
// Callbacks could be all rejected if someone has called `.dispose()`. // Callbacks could be all rejected if someone has called `.dispose()`.
@ -125,21 +125,20 @@ export class Connection extends EventEmitter {
} else { } else {
assert(this._closed, 'Received response for unknown callback: ' + object.id); assert(this._closed, 'Received response for unknown callback: ' + object.id);
} }
} else if (!eventWasEmitted) { } else {
this.emit(object.method, object.params); this.emit(object.method, object.params);
} }
} }
_dispatchTargetMessageToSession(object: {method: string, params: any}, wrappedMessage: string) : boolean { _dispatchTargetMessageToSession(object: {method: string, params: any}, wrappedMessage: string) {
if (object.method === 'Target.targetCreated') { if (object.method === 'Target.targetCreated') {
const targetIndo = object.params.targetInfo as Protocol.Target.TargetInfo; const targetInfo = object.params.targetInfo as Protocol.Target.TargetInfo;
const session = new TargetSession(this, targetIndo); const session = new TargetSession(this, targetInfo);
this._sessions.set(session._sessionId, session); this._sessions.set(session._sessionId, session);
this.emit(ConnectionEvents.TargetCreated, session, object.params.targetInfo); this.emit(ConnectionEvents.TargetCreated, session, object.params.targetInfo);
if (targetIndo.isPaused) if (targetInfo.isPaused)
this.send('Target.resume', { targetId: targetIndo.targetId }).catch(debugError); this.send('Target.resume', { targetId: targetInfo.targetId }).catch(debugError);
} else if (object.method === 'Target.targetDestroyed') { } else if (object.method === 'Target.targetDestroyed') {
// log(`${object.method}`);
const session = this._sessions.get(object.params.targetId); const session = this._sessions.get(object.params.targetId);
if (session) { if (session) {
session._onClosed(); session._onClosed();
@ -165,7 +164,6 @@ export class Connection extends EventEmitter {
oldSession._swappedOut = true; oldSession._swappedOut = true;
this._enqueueMessages(newSession._takeProvisionalMessagesAndCommit()); this._enqueueMessages(newSession._takeProvisionalMessagesAndCommit());
} }
return false;
} }
_onClose() { _onClose() {
@ -212,7 +210,7 @@ export class TargetSession extends EventEmitter {
this._targetType = type; this._targetType = type;
this._sessionId = targetId; this._sessionId = targetId;
if (isProvisional) if (isProvisional)
this._provisionalMessages = []; this._provisionalMessages = [];
} }
isProvisional() : boolean { isProvisional() : boolean {