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

Commit

Permalink
Tweaks from PR #326
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed May 5, 2018
1 parent bc7fbaf commit bc83d79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
38 changes: 21 additions & 17 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2125,30 +2125,34 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
});
}

public propertyDescriptorToVariable(propDesc: Crdp.Runtime.PropertyDescriptor, owningObjectId?: string, parentEvaluateName?: string): Promise<DebugProtocol.Variable> {
public async propertyDescriptorToVariable(propDesc: Crdp.Runtime.PropertyDescriptor, owningObjectId?: string, parentEvaluateName?: string): Promise<DebugProtocol.Variable> {
if (propDesc.get) {
// Getter
const grabGetterValue = 'function remoteFunction(propName) { return this[propName]; }';
return this.chrome.Runtime.callFunctionOn({
objectId: owningObjectId,
functionDeclaration: grabGetterValue,
arguments: [{ value: propDesc.name }]
}).then(response => {
if (response.exceptionDetails) {
// Not an error, getter could be `get foo() { throw new Error('bar'); }`
const exceptionMessage = ChromeUtils.errorMessageFromExceptionDetails(response.exceptionDetails);
logger.verbose('Exception thrown evaluating getter - ' + exceptionMessage);
return { name: propDesc.name, value: exceptionMessage, variablesReference: 0 };
} else {
return this.remoteObjectToVariable(propDesc.name, response.result, parentEvaluateName);
}
}).catch(error => {

let response: Crdp.Runtime.CallFunctionOnResponse;
try {
response = await this.chrome.Runtime.callFunctionOn({
objectId: owningObjectId,
functionDeclaration: grabGetterValue,
arguments: [{ value: propDesc.name }]
});
} catch (error) {
logger.error(`Error evaluating getter for '${propDesc.name}' - ${error.toString()}`);
return { name: propDesc.name, value: error.toString(), variablesReference: 0 };
});
}

if (response.exceptionDetails) {
// Not an error, getter could be `get foo() { throw new Error('bar'); }`
const exceptionMessage = ChromeUtils.errorMessageFromExceptionDetails(response.exceptionDetails);
logger.verbose('Exception thrown evaluating getter - ' + exceptionMessage);
return { name: propDesc.name, value: exceptionMessage, variablesReference: 0 };
} else {
return this.remoteObjectToVariable(propDesc.name, response.result, parentEvaluateName);
}
} else if (propDesc.set) {
// setter without a getter, unlikely
return Promise.resolve({ name: propDesc.name, value: 'setter', variablesReference: 0 });
return { name: propDesc.name, value: 'setter', variablesReference: 0 };
} else {
// Non getter/setter
return this.internalPropertyDescriptorToVariable(propDesc, parentEvaluateName);
Expand Down
9 changes: 4 additions & 5 deletions src/chrome/chromeDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ export class ChromeDebugSession extends LoggingDebugSession implements IObservab
telemetry.reportEvent(ErrorTelemetryEventName, properties);
};

// While using the debug adapter in a debug server, we create several connections. To prevent accumulating listeners we remove existing listeners before adding new ones
process.removeAllListeners('uncaughtException');
process.removeAllListeners('unhandledRejection');

process.on('uncaughtException', (err: any) => {
process.addListener('uncaughtException', (err: any) => {
reportErrorTelemetry(err, 'uncaughtException');

logger.error(`******** Unhandled error in debug adapter: ${safeGetErrDetails(err)}`);
Expand Down Expand Up @@ -284,6 +280,9 @@ export class ChromeDebugSession extends LoggingDebugSession implements IObservab
}

public shutdown(): void {
process.removeAllListeners('uncaughtException');
process.removeAllListeners('unhandledRejection');

this.reportTimingsWhileStartingUpIfNeeded(/*requestedContentWasDetected*/false, /*reasonForNotDetected*/'shutdown');
super.shutdown();
}
Expand Down

0 comments on commit bc83d79

Please sign in to comment.