Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix #166 by waiting on global and non-global eval
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Feb 3, 2017
1 parent c25ef7b commit 77310bd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
return this.handleScriptsCommand(args);
}

const evalResponse = await this.doEvaluate(args.expression, args.frameId, { generatePreview: true });
const evalResponse = await this.waitThenDoEvaluate(args.expression, args.frameId, { generatePreview: true });

// Convert to a Variable object then just copy the relevant fields off
const variable = await this.remoteObjectToVariable('', evalResponse.result, /*parentEvaluateName=*/undefined, /*stringify=*/undefined, <VariableContext>args.context);
Expand Down Expand Up @@ -1450,10 +1450,17 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
* Allow consumers to override just because of https://github.com/nodejs/node/issues/8426
*/
protected globalEvaluate(args: Crdp.Runtime.EvaluateRequest): Promise<Crdp.Runtime.EvaluateResponse> {
return this._waitAfterStep.then(() => this.chrome.Runtime.evaluate(args));
return this.chrome.Runtime.evaluate(args);
}

private doEvaluate(expression: string, frameId?: number, extraArgs?: utils.Partial<Crdp.Runtime.EvaluateRequest>): Promise<Crdp.Debugger.EvaluateOnCallFrameResponse | Crdp.Runtime.EvaluateResponse> {
private async waitThenDoEvaluate(expression: string, frameId?: number, extraArgs?: utils.Partial<Crdp.Runtime.EvaluateRequest>): Promise<Crdp.Debugger.EvaluateOnCallFrameResponse | Crdp.Runtime.EvaluateResponse> {
const waitThenEval = this._waitAfterStep.then(() => this.doEvaluate(expression, frameId, extraArgs));
this._waitAfterStep = waitThenEval.then(() => { }, () => { }); // to Promise<void> and handle failed evals
return waitThenEval;

}

private async doEvaluate(expression: string, frameId?: number, extraArgs?: utils.Partial<Crdp.Runtime.EvaluateRequest>): Promise<Crdp.Debugger.EvaluateOnCallFrameResponse | Crdp.Runtime.EvaluateResponse> {
if (typeof frameId === 'number') {
const frame = this._frameHandles.get(frameId);
if (!frame) {
Expand Down Expand Up @@ -1644,7 +1651,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
if (expression) {
logger.verbose(`Completions: Returning for expression '${expression}'`);
const getCompletionsFn = `(function(x){var a=[];for(var o=x;o!==null&&typeof o !== 'undefined';o=o.__proto__){a.push(Object.getOwnPropertyNames(o))};return a})(${expression})`;
const response = await this.doEvaluate(getCompletionsFn, args.frameId, { returnByValue: true });
const response = await this.waitThenDoEvaluate(getCompletionsFn, args.frameId, { returnByValue: true });
if (response.exceptionDetails) {
return { targets: [] };
} else {
Expand Down

0 comments on commit 77310bd

Please sign in to comment.