Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit fedd5f4

Browse files
author
Matt Loring
committed
Special case array length reporting
1 parent 8c0d15f commit fedd5f4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/state.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,10 @@ StateResolver.prototype.getMirrorProperties_ = function(mirror) {
460460

461461
StateResolver.prototype.resolveMirrorProperty_ = function(property) {
462462
var name = String(property.name());
463-
if (property.isNative()) {
463+
// Array length must be special cased as it is a native property that
464+
// we know to be safe to evaluate which is not generally true.
465+
var isArrayLen = property.mirror_.isArray() && name === 'length';
466+
if (property.isNative() && !isArrayLen) {
464467
return {
465468
name: name,
466469
varTableIndex: NATIVE_PROPERTY_MESSAGE_INDEX

test/test-v8debugapi.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var config = require('../config.js').debug;
3838
var StatusMessage = require('../lib/apiclasses.js').StatusMessage;
3939
var scanner = require('../lib/scanner.js');
4040
var path = require('path');
41+
var semver = require('semver');
4142

4243
function stateIsClean(api) {
4344
assert.equal(api.numBreakpoints_(), 0,
@@ -543,6 +544,40 @@ describe('v8debugapi', function() {
543544
});
544545
});
545546

547+
it('should work with array length despite being native', function(done) {
548+
if (semver.satisfies(process.version, '<1.0')) {
549+
return done();
550+
}
551+
var bp = {
552+
id: breakpointInFoo.id,
553+
location: { path: 'test-v8debugapi.js', line: 5 },
554+
expressions: ['A']
555+
};
556+
api.set(bp, function(err) {
557+
assert.ifError(err);
558+
api.wait(bp, function(err) {
559+
assert.ifError(err);
560+
561+
var arrEnv = bp.evaluatedExpressions[0];
562+
assert.equal(arrEnv.name, 'A');
563+
var envVal = bp.variableTable[arrEnv.varTableIndex];
564+
var found = false;
565+
envVal.members.forEach(function(member) {
566+
if (member.name === 'length') {
567+
assert(!member.varTableIndex);
568+
assert.equal(member.value, 3);
569+
found = true;
570+
}
571+
});
572+
assert(found);
573+
574+
api.clear(bp);
575+
done();
576+
});
577+
process.nextTick(function() {foo();});
578+
});
579+
});
580+
546581
it('should limit string length', function(done) {
547582
var bp = {
548583
id: 'fake-id-124',

0 commit comments

Comments
 (0)