aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/update-call-frame-scopes.js
blob: e0b7307b92b401f1b279ef5be58271f101e7b28e (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
// Copyright 2016 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.

let {session, contextGroup, Protocol} = InspectorTest.start('Tests updating call frame scopes');

contextGroup.addScript(
`function TestFunction()
{
    var a = 2;
    debugger;
    debugger;
}`);

var newVariableValue = 55;

Protocol.Debugger.enable();

Protocol.Debugger.oncePaused().then(handleDebuggerPaused);

Protocol.Runtime.evaluate({ "expression": "setTimeout(TestFunction, 0)" });

function handleDebuggerPaused(messageObject)
{
  InspectorTest.log("Paused on 'debugger;'");

  var topFrame = messageObject.params.callFrames[0];
  var topFrameId = topFrame.callFrameId;
  Protocol.Debugger.evaluateOnCallFrame({ "callFrameId": topFrameId, "expression": "a = " + newVariableValue }).then(callbackChangeValue);
}

function callbackChangeValue(response)
{
  InspectorTest.log("Variable value changed");
  Protocol.Debugger.oncePaused().then(callbackGetBacktrace);
  Protocol.Debugger.resume();
}

function callbackGetBacktrace(response)
{
  InspectorTest.log("Stacktrace re-read again");
  var localScope = response.params.callFrames[0].scopeChain[0];
  Protocol.Runtime.getProperties({ "objectId": localScope.object.objectId }).then(callbackGetProperties);
}

function callbackGetProperties(response)
{
  InspectorTest.log("Scope variables downloaded anew");
  var varNamedA;
  var propertyList = response.result.result;
  for (var i = 0; i < propertyList.length; i++) {
    if (propertyList[i].name === "a") {
      varNamedA = propertyList[i];
      break;
    }
  }
  if (varNamedA) {
    var actualValue = varNamedA.value.value;
    InspectorTest.log("New variable is " + actualValue + ", expected is " + newVariableValue + ", old was: 2");
    InspectorTest.log(actualValue === newVariableValue ? "SUCCESS" : "FAIL");
  } else {
    InspectorTest.log("Failed to find variable in scope");
  }
  InspectorTest.completeTest();
}