Commit 019d446c 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

Committed: https://crrev.com/f658e41d864267fb9e99ea76faa7758b0b63d5c9
Review-Url: https://codereview.chromium.org/2505493002
Cr-Original-Commit-Position: refs/heads/master@{#41227}
Cr-Commit-Position: refs/heads/master@{#41232}
parent c1622945
......@@ -714,6 +714,29 @@ 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->callInternalFunction(
v8::Local<v8::Function>::Cast(setupFunction), context, console, 0,
nullptr);
}
if (hasMemoryAttribute)
console->SetAccessorProperty(
toV8StringInternalized(isolate, "memory"),
......
......@@ -97,8 +97,22 @@ v8::MaybeLocal<v8::Value> V8InspectorImpl::runCompiledScript(
v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(
v8::Local<v8::Function> function, v8::Local<v8::Context> context,
v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) {
v8::MicrotasksScope microtasksScope(m_isolate,
v8::MicrotasksScope::kRunMicrotasks);
return callFunction(function, context, receiver, argc, info,
v8::MicrotasksScope::kRunMicrotasks);
}
v8::MaybeLocal<v8::Value> V8InspectorImpl::callInternalFunction(
v8::Local<v8::Function> function, v8::Local<v8::Context> context,
v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) {
return callFunction(function, context, receiver, argc, info,
v8::MicrotasksScope::kDoNotRunMicrotasks);
}
v8::MaybeLocal<v8::Value> V8InspectorImpl::callFunction(
v8::Local<v8::Function> function, v8::Local<v8::Context> context,
v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[],
v8::MicrotasksScope::Type runMicrotasks) {
v8::MicrotasksScope microtasksScope(m_isolate, runMicrotasks);
int groupId = V8Debugger::getGroupId(context);
if (V8DebuggerAgentImpl* agent = enabledDebuggerAgentForGroup(groupId))
agent->willExecuteScript(function->ScriptId());
......
......@@ -67,6 +67,11 @@ class V8InspectorImpl : public V8Inspector {
int argc, v8::Local<v8::Value> info[]);
v8::MaybeLocal<v8::Value> compileAndRunInternalScript(v8::Local<v8::Context>,
v8::Local<v8::String>);
v8::MaybeLocal<v8::Value> callInternalFunction(v8::Local<v8::Function>,
v8::Local<v8::Context>,
v8::Local<v8::Value> receiver,
int argc,
v8::Local<v8::Value> info[]);
v8::MaybeLocal<v8::Script> compileScript(v8::Local<v8::Context>,
const String16& code,
const String16& fileName);
......@@ -120,6 +125,11 @@ class V8InspectorImpl : public V8Inspector {
V8ProfilerAgentImpl* enabledProfilerAgentForGroup(int contextGroupId);
private:
v8::MaybeLocal<v8::Value> callFunction(
v8::Local<v8::Function>, v8::Local<v8::Context>,
v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[],
v8::MicrotasksScope::Type runMicrotasks);
v8::Isolate* m_isolate;
V8InspectorClient* m_client;
std::unique_ptr<V8Debugger> m_debugger;
......
......@@ -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