This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ScopeMirror traversal to state.js
Replace the `FrameMirror.localValue` code path with `ScopeMirror` traversal and rewrite the arguments collector to only serialize arguments which are not matched by name with a more deeply-scoped value. Add closure scope type to filter list because of confusion with node.JS requires. Add tests for nested, confounding variable names and try/catch. 03/08/2016-10:07 PST Update to use locals only becuase of 0.12 behaviour.
- Loading branch information
1 parent
df9276b
commit 065a8f8
Showing
5 changed files
with
467 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/*1* KEEP THIS CODE AT THE TOP TO AVOID LINE NUMBER CHANGES */ /* jshint shadow:true */ | ||
/*2*/'use strict'; | ||
/*3*/function foo(a) { | ||
/*4*/ var a = 10; | ||
/*5*/ a += 1; | ||
/*6*/ return (function (b) { | ||
/*7*/ var a = 10; | ||
/*8*/ return a; | ||
/*9*/ }()); | ||
/*10*/} | ||
/** | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
var assert = require('assert'); | ||
var v8debugapi = require('../../lib/v8debugapi.js'); | ||
var logModule = require('@google/cloud-diagnostics-common').logger; | ||
var config = require('../../config.js').debug; | ||
var scanner = require('../../lib/scanner.js'); | ||
var path = require('path'); | ||
var semver = require('semver'); | ||
|
||
function stateIsClean(api) { | ||
assert.equal(api.numBreakpoints_(), 0, | ||
'there should be no breakpoints active'); | ||
assert.equal(api.numListeners_(), 0, | ||
'there should be no listeners active'); | ||
return true; | ||
} | ||
|
||
describe('v8debugapi', function() { | ||
config.workingDirectory = path.join(process.cwd(), 'test', 'standalone'); | ||
var logger = logModule.create(config.logLevel); | ||
var api = null; | ||
|
||
beforeEach(function(done) { | ||
if (!api) { | ||
scanner.scan(true, config.workingDirectory, function(err, fileStats, hash) { | ||
assert(!err); | ||
api = v8debugapi.create(logger, config, fileStats); | ||
assert.ok(api, 'should be able to create the api'); | ||
done(); | ||
}); | ||
} else { | ||
assert(stateIsClean(api)); | ||
done(); | ||
} | ||
}); | ||
afterEach(function() { assert(stateIsClean(api)); }); | ||
it('Should read the argument before the name is confounded', function(done) { | ||
var brk = { | ||
id: 'fake-id-123', | ||
location: { path: 'test-duplicate-nested-expressions.js', line: 4 } | ||
}; | ||
api.set(brk, function(err) { | ||
assert.ifError(err); | ||
api.wait(brk, function(err) { | ||
assert.ifError(err); | ||
var frame = brk.stackFrames[0]; | ||
var args = frame.arguments; | ||
var locals = frame.locals; | ||
if (semver.satisfies(process.version, '<1.6')) { | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.deepEqual( | ||
args[0], | ||
{name: 'a', value: '11'} | ||
); | ||
} else { | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.equal(args[0].name, 'arguments_not_available'); | ||
assert.equal(locals.length, 1, 'There should be one locals'); | ||
assert.deepEqual( | ||
locals[0], | ||
{name: 'a', value: 'test'} | ||
); | ||
} | ||
api.clear(brk); | ||
done(); | ||
}); | ||
process.nextTick(foo.bind(null, 'test')); | ||
}); | ||
}); | ||
|
||
it('Should read an argument after the name is confounded', function(done) { | ||
var brk = { | ||
id: 'fake-id-1234', | ||
location: { path: 'test-duplicate-nested-expressions.js', line: 5 } | ||
}; | ||
api.set(brk, function(err) { | ||
assert.ifError(err); | ||
api.wait(brk, function(err) { | ||
assert.ifError(err); | ||
var frame = brk.stackFrames[0]; | ||
var args = frame.arguments; | ||
var locals = frame.locals; | ||
if (semver.satisfies(process.version, '<1.6')) { | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.deepEqual( | ||
args[0], | ||
{name: 'a', value: '11'} | ||
); | ||
} else { | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.equal(args[0].name, 'arguments_not_available'); | ||
assert.equal(locals.length, 1, 'There should be one local'); | ||
assert.deepEqual( | ||
locals[0], | ||
{name: 'a', value: '10'} | ||
); | ||
} | ||
api.clear(brk); | ||
done(); | ||
}); | ||
process.nextTick(foo.bind(null, 'test')); | ||
}); | ||
}); | ||
|
||
it('Should read an argument value after its value is modified', function(done) { | ||
var brk = { | ||
id: 'fake-id-1234', | ||
location: { path: 'test-duplicate-nested-expressions.js', line: 6 } | ||
}; | ||
api.set(brk, function(err) { | ||
assert.ifError(err); | ||
api.wait(brk, function(err) { | ||
assert.ifError(err); | ||
var frame = brk.stackFrames[0]; | ||
var args = frame.arguments; | ||
var locals = frame.locals; | ||
if (semver.satisfies(process.version, '<1.6')) { | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.deepEqual( | ||
args[0], | ||
{name: 'a', value: '11'} | ||
); | ||
} else { | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.equal(args[0].name, 'arguments_not_available'); | ||
assert.equal(locals.length, 1, 'There should be one local'); | ||
assert.deepEqual( | ||
locals[0], | ||
{name: 'a', value: '11'} | ||
); | ||
} | ||
api.clear(brk); | ||
done(); | ||
}); | ||
process.nextTick(foo.bind(null, 'test')); | ||
}); | ||
}); | ||
|
||
it('Should represent a var name at its local-scope when clearly defined', function(done) { | ||
var brk = { | ||
id: 'fake-id-1234', | ||
location: { path: 'test-duplicate-nested-expressions.js', line: 8 } | ||
}; | ||
if (semver.satisfies(process.version, '<1.6')) { | ||
// this IIFE test does not work on 0.12 | ||
done(); | ||
return; | ||
} | ||
api.set(brk, function(err) { | ||
assert.ifError(err); | ||
api.wait(brk, function(err) { | ||
assert.ifError(err); | ||
var frame = brk.stackFrames[0]; | ||
var args = frame.arguments; | ||
var locals = frame.locals; | ||
assert.equal(args.length, 1, 'There should be one argument'); | ||
assert.equal(args[0].name, 'arguments_not_available'); | ||
assert.equal(locals.length, 2, 'There should be two locals'); | ||
assert.deepEqual( | ||
locals[0], | ||
{name: 'b', value: 'undefined'} | ||
); | ||
assert.deepEqual( | ||
locals[1], | ||
{name: 'a', value: 10} | ||
); | ||
api.clear(brk); | ||
done(); | ||
}); | ||
process.nextTick(foo.bind(null, 'test')); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.