2012-01-24 08:43:12 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2011-06-29 13:02:00 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2016-11-23 07:30:01 +00:00
|
|
|
// Flags: --expose-gc
|
2012-08-10 12:26:33 +00:00
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
Debug = debug.Debug
|
|
|
|
|
2011-07-08 08:55:26 +00:00
|
|
|
var listenerComplete = false;
|
|
|
|
var exception = false;
|
|
|
|
|
|
|
|
var testingConstructCall = false;
|
2011-06-29 13:02:00 +00:00
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
var input = [
|
|
|
|
{a: 1, b: 2},
|
|
|
|
{a: 3, b: 4},
|
|
|
|
{a: 5, b: 6},
|
|
|
|
{a: 7, b: 8},
|
|
|
|
{a: 9, b: 10}
|
|
|
|
];
|
|
|
|
|
|
|
|
var expected = [
|
2016-11-11 12:07:41 +00:00
|
|
|
{ locals: {i: 0, x0: 3.03, y0: 4.04, a0: 1.01, b0: 2.02},
|
2012-08-10 12:26:33 +00:00
|
|
|
args: { names: ["i", "x0", "y0"], values: [0, 3.03, 4.04] } },
|
2016-11-11 12:07:41 +00:00
|
|
|
{ locals: {i: 1, x1: 5.05, y1: 6.06, a1: 3.03, b1: 4.04},
|
2012-08-10 12:26:33 +00:00
|
|
|
args: { names: ["i", "x1", "y1"], values: [1, 5.05, 6.06] } },
|
2016-11-11 12:07:41 +00:00
|
|
|
{ locals: {i: 2, a2: 5.05, b2: 6.06},
|
2012-08-10 12:26:33 +00:00
|
|
|
args: { names: ["i"], values: [2] } },
|
2016-11-11 12:07:41 +00:00
|
|
|
{ locals: {i: 3, x3: 9.09, y3: 10.10, z3: undefined, a3: 7.07, b3: 8.08},
|
2012-08-10 12:26:33 +00:00
|
|
|
args: { names: ["i", "x3", "y3", "z3"],
|
|
|
|
values: [3, 9.09, 10.10, undefined] } },
|
2016-11-11 12:07:41 +00:00
|
|
|
{ locals: {i: 4, x4: 11.11, y4: 12.12, a4: 9.09, b4: 10.10},
|
2012-08-10 12:26:33 +00:00
|
|
|
args: { names: ["i", "x4", "y4"], values: [4, 11.11, 12.12] } }
|
2012-01-24 08:43:12 +00:00
|
|
|
];
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
|
|
try {
|
|
|
|
if (event == Debug.DebugEvent.Break)
|
|
|
|
{
|
|
|
|
assertEquals(6, exec_state.frameCount());
|
|
|
|
|
|
|
|
for (var i = 0; i < exec_state.frameCount(); i++) {
|
|
|
|
var frame = exec_state.frame(i);
|
|
|
|
if (i < exec_state.frameCount() - 1) {
|
2012-01-24 08:43:12 +00:00
|
|
|
var expected_args = expected[i].args;
|
|
|
|
var expected_locals = expected[i].locals;
|
|
|
|
|
|
|
|
// All frames except the bottom one have expected locals.
|
|
|
|
var locals = {};
|
|
|
|
for (var j = 0; j < frame.localCount(); j++) {
|
|
|
|
locals[frame.localName(j)] = frame.localValue(j).value();
|
|
|
|
}
|
|
|
|
assertPropertiesEqual(expected_locals, locals);
|
|
|
|
|
2011-07-13 12:49:27 +00:00
|
|
|
// All frames except the bottom one have two scopes.
|
2014-11-17 17:57:56 +00:00
|
|
|
assertEquals(3, frame.scopeCount());
|
2011-07-13 12:49:27 +00:00
|
|
|
assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType());
|
2014-11-17 17:57:56 +00:00
|
|
|
assertEquals(debug.ScopeType.Script, frame.scope(1).scopeType());
|
|
|
|
assertEquals(debug.ScopeType.Global, frame.scope(2).scopeType());
|
2012-01-24 08:43:12 +00:00
|
|
|
|
|
|
|
Object.keys(expected_locals).forEach(function (name) {
|
2012-08-10 12:26:33 +00:00
|
|
|
assertEquals(expected_locals[name],
|
|
|
|
frame.scope(0).scopeObject().value()[name]);
|
2012-01-24 08:43:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (var j = 0; j < expected_args.names.length; j++) {
|
|
|
|
var arg_name = expected_args.names[j];
|
|
|
|
var arg_value = expected_args.values[j];
|
2012-08-10 12:26:33 +00:00
|
|
|
assertEquals(arg_value,
|
|
|
|
frame.scope(0).scopeObject().value()[arg_name]);
|
2012-01-24 08:43:12 +00:00
|
|
|
}
|
2011-07-13 12:49:27 +00:00
|
|
|
|
|
|
|
// Evaluate in the inlined frame.
|
2012-01-24 08:43:12 +00:00
|
|
|
Object.keys(expected_locals).forEach(function (name) {
|
|
|
|
assertEquals(expected_locals[name], frame.evaluate(name).value());
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var j = 0; j < expected_args.names.length; j++) {
|
|
|
|
var arg_name = expected_args.names[j];
|
|
|
|
var arg_value = expected_args.values[j];
|
|
|
|
assertEquals(arg_value, frame.evaluate(arg_name).value());
|
|
|
|
assertEquals(arg_value, frame.evaluate('arguments['+j+']').value());
|
|
|
|
}
|
2011-07-13 12:49:27 +00:00
|
|
|
} else {
|
|
|
|
// The bottom frame only have the global scope.
|
2014-11-17 17:57:56 +00:00
|
|
|
assertEquals(2, frame.scopeCount());
|
|
|
|
assertEquals(debug.ScopeType.Script, frame.scope(0).scopeType());
|
|
|
|
assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType());
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 13:02:17 +00:00
|
|
|
// Check the frame function.
|
|
|
|
switch (i) {
|
2016-11-11 12:07:41 +00:00
|
|
|
case 0: assertEquals("h", frame.func().name()); break;
|
|
|
|
case 1: assertEquals("g3", frame.func().name()); break;
|
|
|
|
case 2: assertEquals("g2", frame.func().name()); break;
|
|
|
|
case 3: assertEquals("g1", frame.func().name()); break;
|
|
|
|
case 4: assertEquals("f", frame.func().name()); break;
|
2011-07-06 13:02:17 +00:00
|
|
|
case 5: break;
|
|
|
|
default: assertUnreachable();
|
|
|
|
}
|
2011-06-29 13:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that all was processed.
|
|
|
|
listenerComplete = true;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2012-01-24 08:43:12 +00:00
|
|
|
exception = e.toString() + e.stack;
|
2011-06-29 13:02:00 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
for (var i = 0; i < 4; i++) f(input.length - 1, 11.11, 12.12);
|
2011-06-29 13:02:00 +00:00
|
|
|
%OptimizeFunctionOnNextCall(f);
|
2012-01-24 08:43:12 +00:00
|
|
|
f(input.length - 1, 11.11, 12.12);
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
// Add the debug event listener.
|
|
|
|
Debug.setListener(listener);
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
function h(i, x0, y0) {
|
|
|
|
var a0 = input[i].a;
|
|
|
|
var b0 = input[i].b;
|
|
|
|
a0 = a0 + a0 / 100;
|
|
|
|
b0 = b0 + b0 / 100;
|
2011-06-29 13:02:00 +00:00
|
|
|
debugger; // Breakpoint.
|
2013-06-04 16:41:24 +00:00
|
|
|
return a0 + b0;
|
2011-06-29 13:02:00 +00:00
|
|
|
};
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
function g3(i, x1, y1) {
|
|
|
|
var a1 = input[i].a;
|
|
|
|
var b1 = input[i].b;
|
|
|
|
a1 = a1 + a1 / 100;
|
|
|
|
b1 = b1 + b1 / 100;
|
|
|
|
h(i - 1, a1, b1);
|
2013-06-04 16:41:24 +00:00
|
|
|
return a1 + b1;
|
2011-06-29 13:02:00 +00:00
|
|
|
};
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
function g2(i) {
|
|
|
|
var a2 = input[i].a;
|
|
|
|
var b2 = input[i].b;
|
|
|
|
a2 = a2 + a2 / 100;
|
|
|
|
b2 = b2 + b2 / 100;
|
|
|
|
g3(i - 1, a2, b2);
|
2013-06-04 16:41:24 +00:00
|
|
|
return a2 + b2;
|
2011-06-29 13:02:00 +00:00
|
|
|
};
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
function g1(i, x3, y3, z3) {
|
|
|
|
var a3 = input[i].a;
|
|
|
|
var b3 = input[i].b;
|
|
|
|
a3 = a3 + a3 / 100;
|
|
|
|
b3 = b3 + b3 / 100;
|
2012-02-28 09:05:55 +00:00
|
|
|
new g2(i - 1, a3, b3);
|
2013-06-04 16:41:24 +00:00
|
|
|
return a3 + b3;
|
2011-06-29 13:02:00 +00:00
|
|
|
};
|
|
|
|
|
2012-01-24 08:43:12 +00:00
|
|
|
function f(i, x4, y4) {
|
|
|
|
var a4 = input[i].a;
|
|
|
|
var b4 = input[i].b;
|
|
|
|
a4 = a4 + a4 / 100;
|
|
|
|
b4 = b4 + b4 / 100;
|
|
|
|
g1(i - 1, a4, b4);
|
2013-06-04 16:41:24 +00:00
|
|
|
return a4 + b4;
|
2011-06-29 13:02:00 +00:00
|
|
|
};
|
|
|
|
|
2011-07-08 08:55:26 +00:00
|
|
|
// Test calling f normally and as a constructor.
|
2012-01-24 08:43:12 +00:00
|
|
|
f(input.length - 1, 11.11, 12.12);
|
|
|
|
f(input.length - 1, 11.11, 12.12, "");
|
2011-07-08 08:55:26 +00:00
|
|
|
testingConstructCall = true;
|
2012-01-24 08:43:12 +00:00
|
|
|
new f(input.length - 1, 11.11, 12.12);
|
|
|
|
new f(input.length - 1, 11.11, 12.12, "");
|
2011-06-29 13:02:00 +00:00
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
// Make sure that the debug event listener was invoked.
|
2011-06-29 13:02:00 +00:00
|
|
|
assertFalse(exception, "exception in listener " + exception)
|
|
|
|
assertTrue(listenerComplete);
|
|
|
|
|
2012-02-28 09:05:55 +00:00
|
|
|
//Throw away type information for next run.
|
|
|
|
gc();
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
Debug.setListener(null);
|