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) {
var desc = '',
type = ref.type,
subtype,
size,
name,
objectId;
objectId,
inspectorResult;
switch (type) {
case 'object':
@ -81,14 +83,24 @@ exports.v8RefToInspectorObject = function(ref) {
if (desc === 'Array' || desc === 'Buffer') {
size = ref.properties.filter(function(p) { return /^\d+$/.test(p.name);}).length;
desc += '[' + size + ']';
subtype = 'array';
}
} else if (ref.className === 'Date') {
desc = new Date(ref.value || NaN).toString();
type = 'date';
subtype = 'date';
} else {
desc = ref.className || 'Object';
}
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':
desc = ref.text || 'function()';
break;
@ -108,12 +120,15 @@ exports.v8RefToInspectorObject = function(ref) {
if (objectId === undefined)
objectId = ref.ref;
return {
inspectorResult = {
type: type,
subtype: subtype,
objectId: String(objectId),
className: ref.className,
description: desc
};
return inspectorResult;
};
exports.v8ObjectToInspectorProperties = function(obj, refs, options) {
@ -174,6 +189,8 @@ exports.v8ErrorToInspectorError = function(message) {
};
exports.v8ResultToInspectorResult = function(result) {
var subtype,
inspectorResult;
if (['object', 'function', 'regexp', 'error'].indexOf(result.type) > -1) {
return exports.v8RefToInspectorObject(result);
}
@ -182,13 +199,17 @@ exports.v8ResultToInspectorResult = function(result) {
// workaround for the problem with front-end's setVariableValue
// implementation not preserving null type
result.value = null;
subtype = 'null';
}
return {
inspectorResult = {
type: result.type,
subtype: subtype,
value: result.value,
description: String(result.value)
};
return inspectorResult;
};
exports.inspectorValueToV8Value = function(value) {

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

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

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

@ -35,6 +35,10 @@ describe('RuntimeAgent', function() {
expect(result.result.length, 'number of local variables')
.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({
name: 'msg',
writable: true,
@ -42,6 +46,7 @@ describe('RuntimeAgent', function() {
configurable: true,
value: {
type: 'string',
subtype: undefined,
value: 'hello',
description: 'hello'
}
@ -53,6 +58,7 @@ describe('RuntimeAgent', function() {
configurable: true,
value: {
type: 'object',
subtype: undefined,
objectId: '7',
className: 'Object',
description: 'Object'
@ -170,6 +176,7 @@ describe('RuntimeAgent', function() {
name: '__proto__',
value: {
type: 'object',
subtype: undefined,
objectId: '17',
className: 'Object',
description: 'InspectedClass'
@ -226,7 +233,7 @@ describe('RuntimeAgent', function() {
toValueType(
'null',
{ type: 'null', value: null, description: 'null' }
{ type: 'null', subtype: 'null', value: null, description: 'null'}
);
toValueType(

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

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