v8/test/inspector/runtime/console-context.js
Alexey Kozyatinskiy 701d79d08a [inspector] introduced console.context
console.context(name:string) method returns console instance, this console instance fully implements console interface (including fact that any method can be called without console as receiver).
Protocol.Runtime.consoleAPICalled notification contains additional context:string field:
- "anonymous#unique-id" for any method call on unnamed console context,
- "name#unique-id" for any method call on named console context.

console.count and console.timeEnd have context as a scope.
console.clear clear all messages regardless on what context instance it was called.

console calls is ~10% slower with this CL since we need to store and then fetch console_context_id and console_context_name from function object.
We recently (in April) made console calls twice faster so 10% doesn't sound critical and existing of console.log call in hot code is problem by itself.

R=pfeldman@chromium.org

Bug: chromium:728767
Change-Id: I5fc73216fb8b28bfe1e8c2c1b393ebfbe43cd02e
Reviewed-on: https://chromium-review.googlesource.com/522128
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45864}
2017-06-12 15:49:13 +00:00

107 lines
4.7 KiB
JavaScript

// Copyright 2017 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('Tests console.context');
InspectorTest.runAsyncTestSuite([
async function testConsoleContextMethod() {
InspectorTest.log('console.context description:');
var {result:{result}} = await Protocol.Runtime.evaluate({
expression: 'console.context'});
InspectorTest.logMessage(result);
InspectorTest.log('console.context() methods:');
var {result:{result:{value}}} = await Protocol.Runtime.evaluate({
expression: 'Object.keys(console.context())', returnByValue: true});
InspectorTest.logMessage(value);
},
async function testDefaultConsoleContext() {
await Protocol.Runtime.enable();
Protocol.Runtime.evaluate({expression: 'console.log(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
Protocol.Runtime.evaluate({expression: 'console.info(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
Protocol.Runtime.evaluate({expression: 'console.debug(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
await Protocol.Runtime.disable();
},
async function testAnonymousConsoleContext() {
await Protocol.Runtime.enable();
Protocol.Runtime.evaluate({expression: 'console.context().log(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
Protocol.Runtime.evaluate({expression: 'console.context().info(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
Protocol.Runtime.evaluate({expression: 'console.context().debug(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
await Protocol.Runtime.evaluate({expression: 'console.context().clear()'});
await Protocol.Runtime.disable();
},
async function testNamedConsoleContext() {
await Protocol.Runtime.enable();
Protocol.Runtime.evaluate({expression: `
var context = console.context('named-context');
context.log(239);
context.info(239);
context.debug(239);
`});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
await Protocol.Runtime.disable();
},
async function testTwoConsoleContextsWithTheSameName() {
await Protocol.Runtime.enable();
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').log(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').log(239)'});
var {params:{context}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.log(context);
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
await Protocol.Runtime.disable();
},
async function testConsoleCountInDifferentConsoleContexts() {
await Protocol.Runtime.enable();
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').count(239)'});
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.logMessage(args);
Protocol.Runtime.evaluate({expression: 'console.context(\'named-context\').count(239)'});
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.logMessage(args);
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
await Protocol.Runtime.disable();
},
async function testConsoleCountForNamedConsoleContext() {
await Protocol.Runtime.enable();
Protocol.Runtime.evaluate({expression: `
var context = console.context('named-context');
context.count(239);
context.count(239);
`});
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.logMessage(args);
var {params:{args}} = await Protocol.Runtime.onceConsoleAPICalled();
InspectorTest.logMessage(args);
await Protocol.Runtime.evaluate({expression: 'console.clear()'});
await Protocol.Runtime.disable();
}
]);