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

Added exception handlers for React Native Hermes debugging #548

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/chrome/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export function getRemoteObjectPreview_primitive(object: Crdp.Runtime.RemoteObje
} else if (object.type === 'number') {
// .value is truncated, so use .description, the full string representation
// Should be like '3' or 'Infinity'.
return object.description;
return object.description || '' + object.value;
} else if (object.type === 'boolean') {
// Never stringified
return '' + object.value;
Expand Down Expand Up @@ -367,14 +367,19 @@ export function createFunctionVariable(name: string,
parentEvaluateName?: string): DebugProtocol.Variable {

let value: string;
const firstBraceIdx = object.description.indexOf('{');
if (firstBraceIdx >= 0) {
value = object.description.substring(0, firstBraceIdx) + '{ … }';

if (object.description) {
const firstBraceIdx = object.description.indexOf('{');
if (firstBraceIdx >= 0) {
value = object.description.substring(0, firstBraceIdx) + '{ … }';
} else {
const firstArrowIdx = object.description.indexOf('=>');
value = firstArrowIdx >= 0 ?
object.description.substring(0, firstArrowIdx + 2) + ' …' :
object.description;
}
} else {
const firstArrowIdx = object.description.indexOf('=>');
value = firstArrowIdx >= 0 ?
object.description.substring(0, firstArrowIdx + 2) + ' …' :
object.description;
value = 'function() { … }';
}

const evaluateName = ChromeUtils.getEvaluateName(parentEvaluateName, name);
Expand Down
7 changes: 6 additions & 1 deletion src/chrome/variablesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,18 @@ export class VariablesManager {
if (response.exceptionDetails) {
const errMsg = ChromeUtils.errorMessageFromExceptionDetails(response.exceptionDetails);
return Promise.reject<IPropCount>(errors.errorFromEvaluate(errMsg));
} else {
} else if (response.result) {
const resultProps = response.result.value;
if (resultProps.length !== 2) {
return Promise.reject<IPropCount>(errors.errorFromEvaluate('Did not get expected props, got ' + JSON.stringify(resultProps)));
}

return { indexedVariables: resultProps[0], namedVariables: resultProps[1] };
} else {
return {
indexedVariables: undefined,
namedVariables: undefined
};
}
},
error => Promise.reject<IPropCount>(errors.errorFromEvaluate(error.message)));
Expand Down
63 changes: 63 additions & 0 deletions test/chrome/variables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,69 @@ suite('Variables', () => {
});
});

suite('createFunctionVariable()', () => {

const _variableHandles = new Variables.VariableHandles();

function getFunctionRemoteObject(func: any, funcName: string): any {
return {
name: funcName,
value: <Crdp.Runtime.RemoteObject>{
className: 'Function',
description: func && func.toString(),
objectId: '123',
type: 'function',
}
};
}

test('not empty description', () => {
const rawObject = getFunctionRemoteObject(() => { console.log(123); return 123; }, 'testFunction');
const processedObject = Variables.createFunctionVariable(rawObject.name, rawObject.value, 'variables', _variableHandles, '');
assert.equal(processedObject.value, '() => { … }');
});

test('empty description', () => {
const rawObject = getFunctionRemoteObject(undefined, 'testFunction');
const processedObject = Variables.createFunctionVariable(rawObject.name, rawObject.value, 'variables', _variableHandles, '');
assert.equal(processedObject.value, 'function() { … }');
});
});

suite('getRemoteObjectPreview_primitive()', () => {
function getPrimitiveRemoteObject(value: any, hasDescription: boolean): Crdp.Runtime.RemoteObject {
return {
description: hasDescription ? '' + value : undefined,
value: value,
type: typeof value,
};
}

function testPrimitiveRemoteObject(obj: any, expected: string): void {
assert.equal(Variables.getRemoteObjectPreview_primitive(obj, true), expected);
}

test('number with description', () => {
testPrimitiveRemoteObject(getPrimitiveRemoteObject(123, true), '123');
});

test('number without description', () => {
testPrimitiveRemoteObject(getPrimitiveRemoteObject(123, false), '123');
});

test('boolean with description', () => {
testPrimitiveRemoteObject(getPrimitiveRemoteObject(false, true), 'false');
});

test('string with description', () => {
testPrimitiveRemoteObject(getPrimitiveRemoteObject('string', true), '"string"');
});

test('undefined with description', () => {
testPrimitiveRemoteObject(getPrimitiveRemoteObject(undefined, true), 'undefined');
});
});

suite('isIndexedPropName()', () => {
test('true for positive integers', () => {
assert(Variables.isIndexedPropName('0'));
Expand Down