remote-object-get-properties.js 1.61 KB
Newer Older
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
// 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.

const {session, contextGroup, Protocol} =
    InspectorTest.start('Tests Runtime.getProperties.');

InspectorTest.runAsyncTestSuite([
  async function testObject() {
    await getProperties('({a: 1})', { ownProperties: true });
    await getProperties(`(function(){
      let b = {};
      Object.defineProperty(b, 'a', {
        configurable: false,
        enumerable: false,
        value: 42,
        writable: false
      });
      Object.defineProperty(b, 'b', {
        configurable: false,
        enumerable: false,
        value: 42,
        writable: true
      });
      Object.defineProperty(b, 'c', {
        configurable: true,
        enumerable: false,
        value: 42,
        writable: false
      });
      Object.defineProperty(b, 'd', {
        configurable: false,
        enumerable: true,
        value: 42,
        writable: false
      });
      Object.defineProperty(b, 'e', {
        set: () => 0,
        get: () => 42
      });
      Object.defineProperty(b, Symbol(42), {
        value: 239
      });
      return b;
    })()`, { ownProperties: true });
  }
]);

async function getProperties(expression, options) {
  try {
    const { result: { result: { objectId } } } =
        await Protocol.Runtime.evaluate({ expression });
    const result = await Protocol.Runtime.getProperties({
      objectId,
      ownProperties: options.ownProperties
    });
    InspectorTest.logMessage(result);
  } catch (e) {
    InspectorTest.log(e.stack);
  }
}