v8/test/debugger/debug/side-effect/debug-evaluate-no-side-effect-runtime-check.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

203 lines
4.1 KiB
JavaScript
Raw Normal View History

Reland "[debug] introduced runtime side effect check" This is a reland of 7a2c3713839f0915bd01738bf4633d8e5693651f Original change's description: > [debug] introduced runtime side effect check > > This CL demonstrates minimum valuable addition to existing debug evaluate > without side effects mechanism. > With this CL user can evaluate expressions like: > [a,b] // create any kind of temporary array literals > [a,b].reduce((x,y) => x + y, 0); // use reduce method > [1,2,3].fill(2); // change temporary arrays > > The core idea: any change of the object created during evaluation without > side effects is side effect free. As soon as we try to store this temporary > object to object existed before evaluation we will terminate execution. > > Implementation: > - track all objects allocated during evaluation and mark them as temporary, > - patch all bytecodes which change objects. > > A little more details (including performance analysis): [1]. > > [1] https://docs.google.com/document/d/10qqAtZADspPnpYa6SEdYRxrddfKIZJIzbLtGpsZQkRo/edit# > > Bug: v8:7588 > Change-Id: I69f7b96e1ebd7ad0022219e8213211c7be72a111 > Reviewed-on: https://chromium-review.googlesource.com/972615 > Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#52370} Bug: v8:7588 Change-Id: Ibc92bf19155f2ddaedae39b0c576b994e84afcf8 Reviewed-on: https://chromium-review.googlesource.com/996760 Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#52373}
2018-04-05 02:01:34 +00:00
// Copyright 2018 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.
Debug = debug.Debug;
// StaCurrentContextSlot
success(10, `(function(){
const x = 10;
function f1() {return x;}
return x;
})()`);
Reland "[debug] introduced runtime side effect check" This is a reland of 7a2c3713839f0915bd01738bf4633d8e5693651f Original change's description: > [debug] introduced runtime side effect check > > This CL demonstrates minimum valuable addition to existing debug evaluate > without side effects mechanism. > With this CL user can evaluate expressions like: > [a,b] // create any kind of temporary array literals > [a,b].reduce((x,y) => x + y, 0); // use reduce method > [1,2,3].fill(2); // change temporary arrays > > The core idea: any change of the object created during evaluation without > side effects is side effect free. As soon as we try to store this temporary > object to object existed before evaluation we will terminate execution. > > Implementation: > - track all objects allocated during evaluation and mark them as temporary, > - patch all bytecodes which change objects. > > A little more details (including performance analysis): [1]. > > [1] https://docs.google.com/document/d/10qqAtZADspPnpYa6SEdYRxrddfKIZJIzbLtGpsZQkRo/edit# > > Bug: v8:7588 > Change-Id: I69f7b96e1ebd7ad0022219e8213211c7be72a111 > Reviewed-on: https://chromium-review.googlesource.com/972615 > Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#52370} Bug: v8:7588 Change-Id: Ibc92bf19155f2ddaedae39b0c576b994e84afcf8 Reviewed-on: https://chromium-review.googlesource.com/996760 Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#52373}
2018-04-05 02:01:34 +00:00
// StaNamedProperty
var a = {name: 'foo'};
function set_name(a) {
a.name = 'bar';
return a.name;
}
fail(`set_name(a)`);
success('bar', `set_name({name: 'foo'})`);
// StaNamedOwnProperty
var name_value = 'value';
function create_object_literal() {
var obj = {name: name_value};
return obj.name;
};
success('value', `create_object_literal()`);
// StaKeyedProperty
var arrayValue = 1;
function create_array_literal() {
return [arrayValue];
}
var b = { 1: 2 };
success([arrayValue], `create_array_literal()`)
fail(`b[1] ^= 2`);
// StaInArrayLiteral
function return_array_use_spread(a) {
return [...a];
}
success([1], `return_array_use_spread([1])`);
Reland "[debug] introduced runtime side effect check" This is a reland of 7a2c3713839f0915bd01738bf4633d8e5693651f Original change's description: > [debug] introduced runtime side effect check > > This CL demonstrates minimum valuable addition to existing debug evaluate > without side effects mechanism. > With this CL user can evaluate expressions like: > [a,b] // create any kind of temporary array literals > [a,b].reduce((x,y) => x + y, 0); // use reduce method > [1,2,3].fill(2); // change temporary arrays > > The core idea: any change of the object created during evaluation without > side effects is side effect free. As soon as we try to store this temporary > object to object existed before evaluation we will terminate execution. > > Implementation: > - track all objects allocated during evaluation and mark them as temporary, > - patch all bytecodes which change objects. > > A little more details (including performance analysis): [1]. > > [1] https://docs.google.com/document/d/10qqAtZADspPnpYa6SEdYRxrddfKIZJIzbLtGpsZQkRo/edit# > > Bug: v8:7588 > Change-Id: I69f7b96e1ebd7ad0022219e8213211c7be72a111 > Reviewed-on: https://chromium-review.googlesource.com/972615 > Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#52370} Bug: v8:7588 Change-Id: Ibc92bf19155f2ddaedae39b0c576b994e84afcf8 Reviewed-on: https://chromium-review.googlesource.com/996760 Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#52373}
2018-04-05 02:01:34 +00:00
// CallAccessorSetter
var array = [1,2,3];
fail(`array.length = 2`);
// TODO(7515): this one should be side effect free
fail(`[1,2,3].length = 2`);
// StaDataPropertyInLiteral
function return_literal_with_data_property(a) {
return {[a] : 1};
}
success({foo: 1}, `return_literal_with_data_property('foo')`);
// Set builtins with temporary objects
var set = new Set([1,2]);
fail(`set.add(3).size`);
success(1, `new Set().add(1).size`);
success(0, `(() => { const s = new Set([1]); s.delete(1); return s.size; })()`);
fail(`set.delete(1)`);
success(0, `(() => { const s = new Set([1]); s.clear(); return s.size; })()`);
fail(`set.clear()`);
// new set
success(3, `(() => {
let s = 0;
for (const a of new Set([1,2]))
s += a;
return s;
})()`);
// existing set
success(3, `(() => {
let s = 0;
for (const a of set)
s += a;
return s;
})()`);
// existing iterator
var setIterator = set.entries();
fail(`(() => {
let s = 0;
for (const a of setIterator)
s += a;
return s;
})()`);
// Array builtins with temporary objects
success([1,1,1], '[1,2,3].fill(1)');
fail(`array.fill(1)`);
success([1], `(() => { const a = []; a.push(1); return a; })()`);
fail(`array.push(1)`);
success([1], `(() => { const a = [1,2]; a.pop(); return a; })()`);
fail(`array.pop()`);
success([3,2,1], `[1,2,3].reverse()`);
fail(`array.reverse()`);
success([1,2,3], `[2,1,3].sort()`);
fail(`array.sort()`);
success([2,3], `[1,2,3].splice(1,2)`);
fail(`array.splice(1,2)`);
success([1,2], `(() => { const a = [2]; a.unshift(1); return a; })()`);
fail(`array.unshift(1)`);
success(1, `[1,2].shift()`);
fail(`array.shift()`);
// new array
success(6, `(() => {
let s = 0;
for (const a of [1,2,3])
s += a;
return s;
})()`);
// existing array
success(6, `(() => {
let s = 0;
for (const a of array)
s += a;
return s;
})()`);
// existing iterator
var arrayIterator = array.entries();
fail(`(() => {
let s = 0;
for (const a of arrayIterator)
s += a;
return s;
})()`);
success(6, `array.reduce((a,b) => a + b, 0)`);
// Map builtins with temporary objects
var map = new Map([[1,2]]);
fail(`map.set(3, 4).size`);
success(1, `new Map().set(1, 2).size`);
success(0, `(() => {
const m = new Map([[1, 2]]);
m.delete(1);
return m.size;
})()`);
fail(`map.delete(1)`);
success(0, `(() => {
const m = new Map([[1, 2]]);
m.clear();
return m.size;
})()`);
fail(`map.clear()`);
// new set
success(2, `(() => {
let s = 0;
for (const [a, b] of new Map([[1,2]]))
s += b;
return s;
})()`);
// existing set
success(2, `(() => {
let s = 0;
for (const [a,b] of map)
s += b;
return s;
})()`);
// existing iterator
var mapIterator = map.entries();
fail(`(() => {
let s = 0;
for (const [a,b] of mapIterator)
s += a;
return s;
})()`);
// Regexps
var regExp = /a/;
success(true, `/a/.test('a')`);
fail(`/a/.test({toString: () => {map.clear(); return 'a';}})`)
fail(`regExp.test('a')`);
Reland "[debug] introduced runtime side effect check" This is a reland of 7a2c3713839f0915bd01738bf4633d8e5693651f Original change's description: > [debug] introduced runtime side effect check > > This CL demonstrates minimum valuable addition to existing debug evaluate > without side effects mechanism. > With this CL user can evaluate expressions like: > [a,b] // create any kind of temporary array literals > [a,b].reduce((x,y) => x + y, 0); // use reduce method > [1,2,3].fill(2); // change temporary arrays > > The core idea: any change of the object created during evaluation without > side effects is side effect free. As soon as we try to store this temporary > object to object existed before evaluation we will terminate execution. > > Implementation: > - track all objects allocated during evaluation and mark them as temporary, > - patch all bytecodes which change objects. > > A little more details (including performance analysis): [1]. > > [1] https://docs.google.com/document/d/10qqAtZADspPnpYa6SEdYRxrddfKIZJIzbLtGpsZQkRo/edit# > > Bug: v8:7588 > Change-Id: I69f7b96e1ebd7ad0022219e8213211c7be72a111 > Reviewed-on: https://chromium-review.googlesource.com/972615 > Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> > Reviewed-by: Yang Guo <yangguo@chromium.org> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org> > Cr-Commit-Position: refs/heads/master@{#52370} Bug: v8:7588 Change-Id: Ibc92bf19155f2ddaedae39b0c576b994e84afcf8 Reviewed-on: https://chromium-review.googlesource.com/996760 Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#52373}
2018-04-05 02:01:34 +00:00
function success(expectation, source) {
const result = Debug.evaluateGlobal(source, true).value();
if (expectation !== undefined) assertEquals(expectation, result);
}
function fail(source) {
assertThrows(() => Debug.evaluateGlobal(source, true),
EvalError);
}