summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/object-preview-internal-properties.js
blob: cfbdba816b8b6f73d9537c35fd143727e9146c59 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// 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.
//
// Flags: --harmony-class-fields

let {session, contextGroup, Protocol} = InspectorTest.start("Check internal properties reported in object preview.");

Protocol.Debugger.enable();
Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(dumpInternalPropertiesAndEntries);

contextGroup.setupInjectedScriptEnvironment();

InspectorTest.runTestSuite([
  function boxedObjects(next)
  {
    checkExpression("new Number(239)")
      .then(() => checkExpression("new Boolean(false)"))
      .then(() => checkExpression("new String(\"abc\")"))
      .then(() => checkExpression("Object(Symbol(42))"))
      .then(() => checkExpression("Object(BigInt(2))"))
      .then(next);
  },

  function promise(next)
  {
    checkExpression("Promise.resolve(42)")
      .then(() => checkExpression("new Promise(() => undefined)"))
      .then(next);
  },

  function generatorObject(next)
  {
    checkExpression("(function* foo() { yield 1 })()")
      .then(next);
  },

  function entriesInMapAndSet(next)
  {
    checkExpression("new Map([[1,2]])")
      .then(() => checkExpression("new Set([1])"))
      .then(() => checkExpression("new WeakMap([[{}, 42]])"))
      .then(() => checkExpression("new WeakSet([{}])"))
      .then(next);
  },

  function iteratorObject(next)
  {
    checkExpression("(new Map([[1,2]])).entries()")
      .then(() => checkExpression("(new Set([1,2])).entries()"))
      .then(next);
  },

  function noPreviewForFunctionObject(next)
  {
    var expression = "(function foo(){})";
    InspectorTest.log(expression);
    Protocol.Runtime.evaluate({ expression: expression, generatePreview: true})
      .then(message => InspectorTest.logMessage(message))
      .then(next);
  },

  function otherObjects(next)
  {
    checkExpression("[1,2,3]")
      .then(() => checkExpression("/123/"))
      .then(() => checkExpression("({})"))
      .then(next);
  },

  function overridenArrayGetter(next)
  {
    Protocol.Runtime.evaluate({ expression: "Array.prototype.__defineGetter__(\"0\",() => { throw new Error() }) "})
      .then(() => checkExpression("Promise.resolve(42)"))
      .then(next);
  },

  function privateNames(next)
  {
    checkExpression("new class { #foo = 1; #bar = 2; baz = 3;}")
      .then(() => checkExpression("new class extends class { #baz = 3; } { #foo = 1; #bar = 2; }"))
      .then(() => checkExpression("new class extends class { constructor() { return new Proxy({}, {}); } } { #foo = 1; #bar = 2; }"))
      .then(next);
  }
]);

function checkExpression(expression)
{
  InspectorTest.log(`expression: ${expression}`);
  // console.table has higher limits for internal properties amount in preview.
  return Protocol.Runtime.evaluate({ expression: `console.table(${expression})`, generatePreview: true });
}

function dumpInternalPropertiesAndEntries(message)
{
  var properties;
  var entries;
  try {
    var preview = message.params.args[0].preview;
    properties = preview.properties;
    entries = preview.entries;
  } catch (e) {
    InspectorTest.logMessage(message);
    return;
  }
  if (!properties) {
    InspectorTest.logMessage(message);
    return;
  }
  for (var property of properties)
    InspectorTest.logMessage(property);
  if (entries) {
    InspectorTest.log("[[Entries]]:");
    InspectorTest.logMessage(entries);
  }
  InspectorTest.log("");
}