2016-04-22 10:46:42 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the parameter initialization block scope set up for
|
|
|
|
// sloppy eval is visible to the debugger.
|
|
|
|
|
|
|
|
var Debug = debug.Debug;
|
|
|
|
var exception = null;
|
|
|
|
var break_count = 0;
|
|
|
|
|
|
|
|
function call_for_break() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
function test(x = eval("var y = 7; debugger; y") + call_for_break()) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
|
|
if (event != Debug.DebugEvent.Break) return;
|
|
|
|
try {
|
|
|
|
var frame = exec_state.frame(0);
|
2016-05-12 06:55:16 +00:00
|
|
|
var block_scope;
|
2016-04-22 10:46:42 +00:00
|
|
|
if (break_count++ == 0) {
|
|
|
|
// Inside eval.
|
2016-05-12 06:55:16 +00:00
|
|
|
assertEquals([ debug.ScopeType.Eval,
|
|
|
|
debug.ScopeType.Block,
|
2016-04-22 10:46:42 +00:00
|
|
|
debug.ScopeType.Closure,
|
|
|
|
debug.ScopeType.Script,
|
|
|
|
debug.ScopeType.Global ],
|
|
|
|
frame.allScopes().map(s => s.scopeType()));
|
|
|
|
exec_state.prepareStep(Debug.StepAction.StepOut);
|
2016-05-12 06:55:16 +00:00
|
|
|
block_scope = frame.scope(1);
|
2016-04-22 10:46:42 +00:00
|
|
|
} else {
|
|
|
|
// Outside of eval.
|
|
|
|
assertEquals([ debug.ScopeType.Block,
|
|
|
|
debug.ScopeType.Local,
|
|
|
|
debug.ScopeType.Script,
|
|
|
|
debug.ScopeType.Global ],
|
|
|
|
frame.allScopes().map(s => s.scopeType()));
|
2016-05-12 06:55:16 +00:00
|
|
|
block_scope = frame.scope(0);
|
2016-04-22 10:46:42 +00:00
|
|
|
}
|
2016-05-12 06:55:16 +00:00
|
|
|
assertTrue(block_scope.scopeObject().propertyNames().includes('y'));
|
|
|
|
assertEquals(7, block_scope.scopeObject().property('y').value().value());
|
2016-04-22 10:46:42 +00:00
|
|
|
} catch (e) {
|
2016-05-12 06:55:16 +00:00
|
|
|
print(e);
|
2016-04-22 10:46:42 +00:00
|
|
|
exception = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug.setListener(listener);
|
|
|
|
|
|
|
|
assertEquals(12, test());
|
|
|
|
|
|
|
|
Debug.setListener(null);
|
|
|
|
|
|
|
|
assertNull(exception);
|
|
|
|
assertEquals(2, break_count);
|