Added subtype property to RemoteObject

Checked: subtype of Array is array
Checked: subtype of Date is date, type is object
Checked: subtype of RegExp is regexp, type is object
Checked: subtype of null is null
This commit is contained in:
3y3 2014-02-21 18:12:26 +04:00
Родитель 5fd0da6d28
Коммит 61f3e08d7f
4 изменённых файлов: 40 добавлений и 9 удалений

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

@ -69,9 +69,11 @@ exports.v8ScopeTypeToString = function(v8ScopeType) {
exports.v8RefToInspectorObject = function(ref) { exports.v8RefToInspectorObject = function(ref) {
var desc = '', var desc = '',
type = ref.type, type = ref.type,
subtype,
size, size,
name, name,
objectId; objectId,
inspectorResult;
switch (type) { switch (type) {
case 'object': case 'object':
@ -81,14 +83,24 @@ exports.v8RefToInspectorObject = function(ref) {
if (desc === 'Array' || desc === 'Buffer') { if (desc === 'Array' || desc === 'Buffer') {
size = ref.properties.filter(function(p) { return /^\d+$/.test(p.name);}).length; size = ref.properties.filter(function(p) { return /^\d+$/.test(p.name);}).length;
desc += '[' + size + ']'; desc += '[' + size + ']';
subtype = 'array';
} }
} else if (ref.className === 'Date') { } else if (ref.className === 'Date') {
desc = new Date(ref.value || NaN).toString(); desc = new Date(ref.value || NaN).toString();
type = 'date'; subtype = 'date';
} else { } else {
desc = ref.className || 'Object'; desc = ref.className || 'Object';
} }
break; break;
case 'regexp':
type = 'object';
subtype = 'regexp';
desc = ref.text || '';
/*
We need to collect RegExp flags and append they to description,
or open issue in NodeJS same as 'RegExp text serialized without flags'
*/
break;
case 'function': case 'function':
desc = ref.text || 'function()'; desc = ref.text || 'function()';
break; break;
@ -108,12 +120,15 @@ exports.v8RefToInspectorObject = function(ref) {
if (objectId === undefined) if (objectId === undefined)
objectId = ref.ref; objectId = ref.ref;
return { inspectorResult = {
type: type, type: type,
subtype: subtype,
objectId: String(objectId), objectId: String(objectId),
className: ref.className, className: ref.className,
description: desc description: desc
}; };
return inspectorResult;
}; };
exports.v8ObjectToInspectorProperties = function(obj, refs, options) { exports.v8ObjectToInspectorProperties = function(obj, refs, options) {
@ -174,6 +189,8 @@ exports.v8ErrorToInspectorError = function(message) {
}; };
exports.v8ResultToInspectorResult = function(result) { exports.v8ResultToInspectorResult = function(result) {
var subtype,
inspectorResult;
if (['object', 'function', 'regexp', 'error'].indexOf(result.type) > -1) { if (['object', 'function', 'regexp', 'error'].indexOf(result.type) > -1) {
return exports.v8RefToInspectorObject(result); return exports.v8RefToInspectorObject(result);
} }
@ -182,13 +199,17 @@ exports.v8ResultToInspectorResult = function(result) {
// workaround for the problem with front-end's setVariableValue // workaround for the problem with front-end's setVariableValue
// implementation not preserving null type // implementation not preserving null type
result.value = null; result.value = null;
subtype = 'null';
} }
return { inspectorResult = {
type: result.type, type: result.type,
subtype: subtype,
value: result.value, value: result.value,
description: String(result.value) description: String(result.value)
}; };
return inspectorResult;
}; };
exports.inspectorValueToV8Value = function(value) { exports.inspectorValueToV8Value = function(value) {

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

@ -23,7 +23,7 @@ describe('DebuggerAgent', function() {
toValueType( toValueType(
'null', 'null',
{ value: null }, { value: null },
{ type: 'null', value: null, description: 'null' } { type: 'null', subtype: 'null', value: null, description: 'null'}
); );
toValueType( toValueType(

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

@ -35,6 +35,10 @@ describe('RuntimeAgent', function() {
expect(result.result.length, 'number of local variables') expect(result.result.length, 'number of local variables')
.to.equal(2); .to.equal(2);
var proto = result.result.filter(function(prop) {
return prop.name == '__proto__';
});
expect(proto.length == 0, 'proto in scope object is filtered').to.be.true;
expect(result.result[0], 'local var 1').to.deep.equal({ expect(result.result[0], 'local var 1').to.deep.equal({
name: 'msg', name: 'msg',
writable: true, writable: true,
@ -42,6 +46,7 @@ describe('RuntimeAgent', function() {
configurable: true, configurable: true,
value: { value: {
type: 'string', type: 'string',
subtype: undefined,
value: 'hello', value: 'hello',
description: 'hello' description: 'hello'
} }
@ -53,6 +58,7 @@ describe('RuntimeAgent', function() {
configurable: true, configurable: true,
value: { value: {
type: 'object', type: 'object',
subtype: undefined,
objectId: '7', objectId: '7',
className: 'Object', className: 'Object',
description: 'Object' description: 'Object'
@ -170,6 +176,7 @@ describe('RuntimeAgent', function() {
name: '__proto__', name: '__proto__',
value: { value: {
type: 'object', type: 'object',
subtype: undefined,
objectId: '17', objectId: '17',
className: 'Object', className: 'Object',
description: 'InspectedClass' description: 'InspectedClass'
@ -226,7 +233,7 @@ describe('RuntimeAgent', function() {
toValueType( toValueType(
'null', 'null',
{ type: 'null', value: null, description: 'null' } { type: 'null', subtype: 'null', value: null, description: 'null'}
); );
toValueType( toValueType(

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

@ -154,7 +154,8 @@ describe('convert', function() {
var converted = convert.v8RefToInspectorObject(ref); var converted = convert.v8RefToInspectorObject(ref);
expect(converted.description).to.equal(datestr); expect(converted.description).to.equal(datestr);
expect(converted.type).to.equal('date'); expect(converted.type).to.equal('object');
expect(converted.subtype).to.equal('date');
}); });
}); });
@ -181,7 +182,8 @@ describe('convert', function() {
text: '/\/[^a]abc/' text: '/\/[^a]abc/'
}, },
ref = { ref = {
type: 'regexp', type: 'object',
subtype: 'regexp',
objectId: '0', objectId: '0',
className: 'RegExp', className: 'RegExp',
description: '/\/[^a]abc/' description: '/\/[^a]abc/'
@ -218,10 +220,11 @@ describe('convert', function() {
expect(converted).to.eql({ expect(converted).to.eql({
type: 'object', type: 'object',
subtype: undefined,
objectId: '6', objectId: '6',
className: 'Error', className: 'Error',
description: v8Result.text description: v8Result.text
}); });
}) });
}); });
}); });