summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/runtime/stable-object-id.js
blob: 944bae0d3a5056bcd69044c90cf90e2223ba35a9 (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
// 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.

let {session, contextGroup, Protocol} = InspectorTest.start(
    'Checks that protocol returns the same RemoteObjectId for the same object');

InspectorTest.runAsyncTestSuite([
  async function testGlobal() {
    const {result:{result:{objectId:firstId}}} =
        await Protocol.Runtime.evaluate({expression: 'this'});
    const firstStableId = await stableObjectId(firstId);
    const {result:{result:{objectId:secondId}}} =
        await Protocol.Runtime.evaluate({expression: 'this'});
    const secondStableId = await stableObjectId(secondId);
    InspectorTest.log(
        `Compare global evaluated twice: ${firstStableId === secondStableId}`);
  },

  async function testObject() {
    const {result:{result:{objectId:firstId}}} =
        await Protocol.Runtime.evaluate({expression: 'this.a = {}, this.a'});
    const firstStableId = await stableObjectId(firstId);
    const {result:{result:{objectId:secondId}}} =
        await Protocol.Runtime.evaluate({expression: 'this.a'});
    const secondStableId = await stableObjectId(secondId);
    InspectorTest.log(
        `Compare object evaluated twice: ${firstStableId === secondStableId}`);
  },

  async function testObjectInArray() {
    await Protocol.Runtime.evaluate({expression: 'this.b = [this.a, this.a]'});
    const {result:{result:{objectId:firstId}}} =
        await Protocol.Runtime.evaluate({expression: 'this.b[0]'});
    const firstStableId = await stableObjectId(firstId);
    const {result:{result:{objectId:secondId}}} =
        await Protocol.Runtime.evaluate({expression: 'this.b[1]'});
    const secondStableId = await stableObjectId(secondId);
    InspectorTest.log(
        `Compare first and second element: ${firstStableId === secondStableId}`);
  },

  async function testObjectOnPause() {
    const {result:{result:{objectId:globalId}}} =
        await Protocol.Runtime.evaluate({expression: 'this'});
    const globalStableId = await stableObjectId(globalId);
    const {result:{result:{objectId:aId}}} =
        await Protocol.Runtime.evaluate({expression: 'this.a'});
    const aStableId = await stableObjectId(aId);
    await Protocol.Debugger.enable();
    Protocol.Runtime.evaluate({expression: 'debugger'});
    const {params:{callFrames:[topFrame]}} =
        await Protocol.Debugger.oncePaused();
    const topFrameThisStableId = await stableObjectId(topFrame.this.objectId);
    InspectorTest.log(
        `Compare global and this: ${globalStableId === topFrameThisStableId}`);

    const {result:{result:{objectId:globalIdOnPause}}} =
        await Protocol.Debugger.evaluateOnCallFrame({
          callFrameId: topFrame.callFrameId,
          expression: 'this'
        });
    const globalStableIdOnPause = await stableObjectId(globalIdOnPause);
    InspectorTest.log(
        `Compare global and global on pause: ${
            globalStableId === globalStableIdOnPause}`);

    const {result:{result: props}} = await Protocol.Runtime.getProperties({
      objectId: topFrame.scopeChain[0].object.objectId
    });
    const {value:{objectId: aIdOnPause}} = props.find(prop => prop.name === 'a');
    const aStableIdOnPause = await stableObjectId(aIdOnPause);
    InspectorTest.log(`Compare a and a on pause: ${
        aStableId === aStableIdOnPause}`);
  }
]);

async function stableObjectId(objectId) {
  const {result:{
    internalProperties: props
  }} = await Protocol.Runtime.getProperties({
    objectId,
    ownProperties: true,
    generatePreview: false
  });
  return props.find(prop => prop.name === '[[StableObjectId]]').value.value;
}