2017-02-10 17:06:22 +00:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
2017-05-19 00:35:45 +00:00
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start('Tests side-effect-free evaluation');
|
2017-02-10 17:06:22 +00:00
|
|
|
|
2017-05-19 00:35:45 +00:00
|
|
|
contextGroup.addScript(`
|
2021-02-18 04:52:02 +00:00
|
|
|
var someGlobalDate = new Date();
|
2017-02-10 17:06:22 +00:00
|
|
|
function testFunction()
|
|
|
|
{
|
|
|
|
var o = 0;
|
|
|
|
function f() { return 1; }
|
|
|
|
function g() { o = 2; return o; }
|
2019-01-24 17:00:48 +00:00
|
|
|
f,g;
|
2017-02-10 17:06:22 +00:00
|
|
|
debugger;
|
|
|
|
}
|
|
|
|
//# sourceURL=foo.js`);
|
|
|
|
|
2021-02-18 04:52:02 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function basicTest() {
|
|
|
|
Protocol.Debugger.enable();
|
|
|
|
Protocol.Runtime.evaluate({ 'expression': 'setTimeout(testFunction, 0)' });
|
|
|
|
const {params:{callFrames:[{callFrameId: topFrameId}]}} = await Protocol.Debugger.oncePaused();
|
|
|
|
InspectorTest.log('Paused on "debugger;"');
|
|
|
|
const {result:{result:{value: fResult}}} = await Protocol.Debugger.evaluateOnCallFrame({ callFrameId: topFrameId, expression: 'f()' });
|
|
|
|
InspectorTest.log('f() returns ' + fResult);
|
|
|
|
const {result:{result:{value: gResult}}} = await Protocol.Debugger.evaluateOnCallFrame({ callFrameId: topFrameId, expression: 'g()' });
|
|
|
|
InspectorTest.log('g() returns ' + gResult);
|
|
|
|
const {result:{result:{value: fResultSideEffect}}} = await Protocol.Debugger.evaluateOnCallFrame({ callFrameId: topFrameId, expression: 'f()', throwOnSideEffect: true});
|
|
|
|
InspectorTest.log('f() returns ' + fResultSideEffect);
|
|
|
|
const {result:{result:{className}}} = await Protocol.Debugger.evaluateOnCallFrame({ callFrameId: topFrameId, expression: 'g()', throwOnSideEffect: true});
|
|
|
|
InspectorTest.log('g() throws ' + className);
|
|
|
|
},
|
|
|
|
|
|
|
|
async function testDate() {
|
|
|
|
const check = async (expression) => {
|
|
|
|
const {result:{exceptionDetails}} = await Protocol.Runtime.evaluate({expression, throwOnSideEffect: true});
|
|
|
|
InspectorTest.log(expression + ' : ' + (exceptionDetails ? 'throws' : 'ok'));
|
|
|
|
};
|
|
|
|
// setters are only ok on temporary objects
|
|
|
|
await check('someGlobalDate.setDate(10)');
|
|
|
|
await check('new Date().setDate(10)');
|
|
|
|
await check('someGlobalDate.setFullYear(1991)');
|
|
|
|
await check('new Date().setFullYear(1991)');
|
|
|
|
await check('someGlobalDate.setHours(0)');
|
|
|
|
await check('new Date().setHours(0)');
|
|
|
|
// getters are ok on any Date
|
|
|
|
await check('someGlobalDate.getDate()');
|
|
|
|
await check('new Date().getDate()');
|
|
|
|
await check('someGlobalDate.getFullYear()');
|
|
|
|
await check('new Date().getFullYear()');
|
|
|
|
await check('someGlobalDate.getHours()');
|
|
|
|
await check('new Date().getHours()');
|
|
|
|
}
|
|
|
|
]);
|