summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/xpcshell/test_watchpoint-03.js
blob: 33f4fbd2a2566371687b0e857bbad8079d0b0329 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint-disable no-shadow */

"use strict";
/*
See Bug 1601311.
Tests that removing a watchpoint does not change the value of the property that had the watchpoint.
*/

add_task(
  threadFrontTest(async ({ commands, threadFront, debuggee }) => {
    async function evaluateJS(input) {
      const { result } = await commands.scriptCommand.execute(input, {
        frameActor: packet.frame.actorID,
      });
      return result;
    }

    function evaluateTestCode(debuggee) {
      /* eslint-disable */
      Cu.evalInSandbox(
        `                                   // 1
                  function stopMe(obj) {              // 2
                    debugger;                         // 3
                    obj.a = 2;                        // 4
                    debugger;                         // 5
                  }                                   //

                  stopMe({a: 1})`,
        debuggee,
        "1.8",
        "test_watchpoint-03.js"
      );
      /* eslint-disable */
    }

    const packet = await executeOnNextTickAndWaitForPause(
      () => evaluateTestCode(debuggee),
      threadFront
    );

    info("Test that we paused on the debugger statement.");
    Assert.equal(packet.frame.where.line, 3);

    info("Add set watchpoint.");
    const args = packet.frame.arguments;
    const obj = args[0];
    const objClient = threadFront.pauseGrip(obj);
    await objClient.addWatchpoint("a", "obj.a", "set");

    info("Test that we pause on set.");
    const packet2 = await resumeAndWaitForPause(threadFront);
    Assert.equal(packet2.frame.where.line, 4);

    const packet3 = await resumeAndWaitForPause(threadFront);

    info("Test that we pause on the second debugger statement.");
    Assert.equal(packet3.frame.where.line, 5);
    Assert.equal(packet3.why.type, "debuggerStatement");

    info("Remove watchpoint.");
    await objClient.removeWatchpoint("a");

    info("Test that the value has updated.");
    const result = await evaluateJS("obj.a");
    Assert.equal(result, 2);

    info("Finish test.");
    await resume(threadFront);
  })
);