Commit f658e41d authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] make console.assert much faster

New console.assert implementation is faster then custom user implementation.

BUG=chromium:663845
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2505493002
Cr-Commit-Position: refs/heads/master@{#41227}
parent d094fa76
......@@ -714,6 +714,28 @@ v8::Local<v8::Object> V8Console::createConsole(
createBoundFunctionProperty(context, console, "timeStamp",
V8Console::timeStampCallback);
const char* jsConsoleAssert =
"(function(){\n"
" var originAssert = this.assert;\n"
" originAssert.apply = Function.prototype.apply;\n"
" this.assert = assertWrapper;\n"
" assertWrapper.toString = () => originAssert.toString();\n"
" function assertWrapper(){\n"
" if (!!arguments[0]) return;\n"
" originAssert.apply(null, arguments);\n"
" }\n"
"})";
v8::Local<v8::String> assertSource = toV8String(isolate, jsConsoleAssert);
V8InspectorImpl* inspector = inspectedContext->inspector();
v8::Local<v8::Value> setupFunction;
if (inspector->compileAndRunInternalScript(context, assertSource)
.ToLocal(&setupFunction) &&
setupFunction->IsFunction()) {
inspector->callFunction(v8::Local<v8::Function>::Cast(setupFunction),
context, console, 0, nullptr);
}
if (hasMemoryAttribute)
console->SetAccessorProperty(
toV8StringInternalized(isolate, "memory"),
......
......@@ -80,7 +80,7 @@ assertTrue(extension_count == 2 || extension_count == 3);
// This script, test-api.js and mjsunit.js has been loaded. If using d8, d8
// loads a normal script during startup too.
assertTrue(normal_count == 3 || normal_count == 4);
assertTrue(inspector_count == 1);
assertTrue(inspector_count == 2);
// Test a builtins script.
var array_script = Debug.findScript('native array.js');
......
Checks that console.assert works and points to correct call frame.
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : console.assert
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 4
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url : evaluate.js
}
]
}
timestamp : <timestamp>
type : assert
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
description : 1
type : number
value : 1
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 5
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url : evaluate.js
}
]
}
timestamp : <timestamp>
type : assert
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
description : 1
type : number
value : 1
}
[1] : {
description : 2
type : number
value : 2
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 6
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url : evaluate.js
}
]
}
timestamp : <timestamp>
type : assert
}
}
{
method : Runtime.consoleAPICalled
params : {
args : [
[0] : {
type : string
value : console.assert
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : testFunction
lineNumber : 7
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url : evaluate.js
}
]
}
timestamp : <timestamp>
type : assert
}
}
{
id : <messageId>
result : {
result : {
className : Function
description : function assert() { [native code] }
objectId : <objectId>
type : function
}
}
}
// 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.
print("Checks that console.assert works and points to correct call frame.");
InspectorTest.addScript(`
function testFunction() {
Function.prototype.apply = () => console.error('Should never call this');
console.assert(true);
console.assert(false);
console.assert(false, 1);
console.assert(false, 1, 2);
console.assert();
return console.assert;
}
//# sourceURL=test.js`);
Protocol.Runtime.onConsoleAPICalled(InspectorTest.logMessage);
Protocol.Runtime.enable();
Protocol.Runtime.evaluate({
expression: "testFunction()//# sourceURL=evaluate.js" })
.then(InspectorTest.logMessage)
.then(InspectorTest.completeTest);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment