destroy-context-during-log.js 1.49 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 6
let {session, contextGroup, Protocol} = InspectorTest.start('Tests that destroying context from inside of console.log does not crash');

7 8 9 10
const expression = `
  Object.defineProperty(Object.prototype, 'RemoteObject', {
    configurable: true,
    set(v) {
11
      console.log("Should never be called");
12 13 14
      delete Object.prototype.RemoteObject;
      this.RemoteObject = v;

15
      inspector.fireContextDestroyed();
16 17 18
      setTimeout(function() {
        // Attach the inspector again for the sake of establishing a
        // communication channel with the frontend test runner.
19
        inspector.fireContextCreated();
20 21 22 23 24 25 26 27
        console.log("End of test");
      }, 0);
    },
  });

  // Before the whole script runs, the inspector is already attached.
  // Re-attach the inspector and trigger the console API to make sure that the
  // injected inspector script runs again (and triggers the above setter).
28 29
  inspector.fireContextDestroyed();
  inspector.fireContextCreated();
30
  console.log("First inspector activity after attaching inspector");
31
  console.log("End of test");
32 33 34 35 36 37 38 39 40 41 42
`;

Protocol.Runtime.enable();
Protocol.Runtime.evaluate({ expression: expression });

Protocol.Runtime.onConsoleAPICalled(function(result) {
  InspectorTest.logObject(result.params.args[0]);
  if (result.params.args[0].value == "End of test") {
    InspectorTest.completeTest();
  }
});