evaluate-with-generate-preview.js 4.57 KB
Newer Older
1 2 3 4
// 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.

5
let {session, contextGroup, Protocol} = InspectorTest.start("Tests that Runtime.evaluate will generate correct previews.");
6

7
contextGroup.addScript(
8
`
9 10
var f1 = function(){};

11
Object.prototype[0] = 'default-first';
12
var obj = {p1: {a:1}, p2: {b:'foo'}, p3: f1};
13
Object.defineProperties(obj, {
14
  p4: {
15 16
    get() { return 2 }
  },
17
  p5: {
18 19
    set(x) { return x }
  },
20
  p6: {
21 22 23 24 25 26
    get() { return 2 },
    set(x) { return x }
  }
});

Array.prototype[0] = 'default-first';
27
var arr = [,, 1, [2], f1];
28
Object.defineProperties(arr, {
29
  5: {
30 31
    get() { return 2 }
  },
32
  6: {
33 34
    set(x) { return x }
  },
35
  7: {
36 37 38 39
    get() { return 2 },
    set(x) { return x }
  }
});
40 41 42 43 44 45
arr.nonEntryFunction = f1;

var inheritingObj = {};
var inheritingArr = [];
inheritingObj.prototype = obj;
inheritingArr.prototype = arr;
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

var shortTypedArray = new Uint8Array(3);
var longTypedArray = new Uint8Array(500001);
var set = new Set([1, 2, 3]);
var bigSet = new Set();
var mixedSet = new Set();
for (var i = 0; i < 10; i++) {
  bigSet.add(i);
  mixedSet["_prop_" + i] = 1;
  mixedSet.add(i);
}

var deterministicNativeFunction = Math.log;
var parentObj = {};
Object.defineProperty(parentObj, 'propNotNamedProto', {
  get: deterministicNativeFunction,
  set: function() {}
});
64
inspector.allowAccessorFormatting(parentObj);
65
var objInheritsGetterProperty = {__proto__: parentObj};
66
inspector.allowAccessorFormatting(objInheritsGetterProperty);
67 68

var arrayWithLongValues = ["a".repeat(101), 2n**401n];
69 70
`);

71
contextGroup.setupInjectedScriptEnvironment();
72

73 74 75 76 77 78 79 80 81 82 83 84 85
InspectorTest.runTestSuite([
  function testObjectPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "obj", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testArrayPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "arr", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
86 87 88 89 90 91 92 93 94 95 96 97 98 99
  },

  function testInheritingObjectPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "inheritingObj", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testInheritingArrayPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "inheritingArr", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  },

  function testShortTypedArrayPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "shortTypedArray", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testLongTypedArrayPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "longTypedArray", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testSetPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "set", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testBigSetPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "bigSet", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testMixedSetPropertiesPreview(next)
  {
    Protocol.Runtime.evaluate({ "expression": "mixedSet", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
  },

  function testObjInheritsGetterProperty(next)
  {
    Protocol.Runtime.evaluate({ "expression": "objInheritsGetterProperty", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
142 143 144 145 146 147 148
  },

  function testObjWithArrayAsProto(next)
  {
    Protocol.Runtime.evaluate({ "expression": "Object.create([1,2])", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
149 150 151 152 153 154 155
  },

  function testArrayWithLongValues(next)
  {
    Protocol.Runtime.evaluate({ "expression": "arrayWithLongValues", "generatePreview": true })
        .then(result => InspectorTest.logMessage(result.result.result.preview))
        .then(next);
156 157
  }
]);