summaryrefslogtreecommitdiff
path: root/deps/v8/test/debugger/debug/debug-evaluate-no-side-effect-ops.js
blob: b7e49dc88f82c563a42d4963c1b630b09a1f871e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// 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.

Debug = debug.Debug

var exception = null;
var date = new Date();
var T = true;
var F = false;
var one = 1;
var two = 2;
var string = "s";
var array = [1, 2, 3];
function max(...rest) {
  return Math.max(...rest);
}

function def(a = 1) {
  return a;
}

function d1([a, b = 'b']) {
  return a + b;
}

function d2({ x: c, y, z = 'z' } = {x: 'x', y: 'y' }) {
  return c + y + z;
}

function listener(event, exec_state, event_data, data) {
  if (event != Debug.DebugEvent.Break) return;
  try {
    function success(expectation, source) {
      var result = exec_state.frame(0).evaluate(source, true).value();
      if (expectation !== undefined) assertEquals(expectation, result);
    }
    function fail(source) {
      assertThrows(() => exec_state.frame(0).evaluate(source, true),
                   EvalError);
    }
    success(false, `Object == {}`);
    success(false, `Object === {}`);
    success(true, `Object != {}`);
    success(true, `Object !== {}`);
    success(true, `'s' == string`);
    success(true, `'s' === string`);
    success(true, `1 < Math.cos(0) * 2`);
    success(false, `1 < string`);
    success(true, `'a' < string`);
    success("s", `string[0]`);
    success(0, `[0][0]`);
    success(1, `T^F`);
    success(0, `T&F`);
    success(1, `T|F`);
    success(false, `T&&F`);
    success(true, `T||F`);
    success(false, `T?F:T`);
    success(false, `!T`);
    success(1, `+one`);
    success(-1, `-one`);
    success(-2, `~one`);
    success(4, `one << two`);
    success(1, `two >> one`);
    success(1, `two >>> one`);
    success(3, `two + one`);
    success(2, `two * one`);
    success(0.5, `one / two`);
    success(0, `(one / two) | 0`);
    success(1, `one ** two`);
    success(NaN, `string * two`);
    success("s2", `string + two`);
    success("s2", `string + two`);
    fail(`[...array]`);
    success(3, `max(...array)`);
    fail(`({[string]:1})`);
    fail(`[a, b] = [1, 2]`);
    success(2, `def(2)`);
    success(1, `def()`);
    fail(`d1(['a'])`);  // Iterator.prototype.next performs stores.
    success("XYz", `d2({x:'X', y:'Y'})`);
  } catch (e) {
    exception = e;
    print(e, e.stack);
  };
};

// Add the debug event listener.
Debug.setListener(listener);

function f() {
  debugger;
};

f();

assertNull(exception);