Commit 872accf9 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] prepared console before moving into builtins

We need to split creating of console and installing memory getter and remove console.assert hack before migration to builtin. We can implement super fast console.assert after migration.

BUG=chromium:588893
R=dgozman@chromium.org
TBR=yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2781883003
Cr-Commit-Position: refs/heads/master@{#44256}
parent 85d731e9
......@@ -28,8 +28,10 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
v8::Int32::New(isolate, contextId));
v8::Local<v8::Object> global = info.context->Global();
v8::Local<v8::Object> console =
V8Console::createConsole(this, info.hasMemoryOnConsole);
v8::Local<v8::Object> console = V8Console::createConsole(this);
if (info.hasMemoryOnConsole) {
V8Console::installMemoryGetter(m_inspector, info.context, console);
}
if (!global
->Set(info.context, toV8StringInternalized(isolate, "console"),
console)
......
......@@ -557,7 +557,7 @@ void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
}
v8::Local<v8::Object> V8Console::createConsole(
InspectedContext* inspectedContext, bool hasMemoryAttribute) {
InspectedContext* inspectedContext) {
v8::Local<v8::Context> context = inspectedContext->context();
v8::Context::Scope contextScope(context);
v8::Isolate* isolate = context->GetIsolate();
......@@ -618,47 +618,25 @@ v8::Local<v8::Object> V8Console::createConsole(
V8Console::timeEndCallback);
createBoundFunctionProperty(context, console, data, "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()) {
v8::MicrotasksScope microtasksScope(
isolate, v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::MaybeLocal<v8::Value> result;
result = v8::Local<v8::Function>::Cast(setupFunction)
->Call(context, console, 0, nullptr);
}
if (hasMemoryAttribute) {
console->SetAccessorProperty(
toV8StringInternalized(isolate, "memory"),
v8::Function::New(context, V8Console::memoryGetterCallback, data, 0,
v8::ConstructorBehavior::kThrow)
.ToLocalChecked(),
v8::Function::New(context, V8Console::memorySetterCallback, data, 0,
v8::ConstructorBehavior::kThrow)
.ToLocalChecked(),
static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT);
}
return console;
}
void V8Console::installMemoryGetter(V8InspectorImpl* inspector,
v8::Local<v8::Context> context,
v8::Local<v8::Object> console) {
v8::Local<v8::External> data =
v8::External::New(inspector->isolate(), inspector);
console->SetAccessorProperty(
toV8StringInternalized(inspector->isolate(), "memory"),
v8::Function::New(context, V8Console::memoryGetterCallback, data, 0,
v8::ConstructorBehavior::kThrow)
.ToLocalChecked(),
v8::Function::New(context, V8Console::memorySetterCallback, data, 0,
v8::ConstructorBehavior::kThrow)
.ToLocalChecked(),
static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT);
}
v8::Local<v8::Object> V8Console::createCommandLineAPI(
InspectedContext* inspectedContext) {
v8::Local<v8::Context> context = inspectedContext->context();
......
......@@ -12,14 +12,17 @@
namespace v8_inspector {
class InspectedContext;
class V8InspectorImpl;
// Console API
// https://console.spec.whatwg.org/#console-interface
class V8Console {
public:
static v8::Local<v8::Object> createConsole(InspectedContext*,
bool hasMemoryAttribute);
static v8::Local<v8::Object> createConsole(InspectedContext*);
static v8::Local<v8::Object> createCommandLineAPI(InspectedContext*);
static void installMemoryGetter(V8InspectorImpl* inspector,
v8::Local<v8::Context> context,
v8::Local<v8::Object> console);
class CommandLineAPIScope {
public:
......
......@@ -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 == 2);
assertTrue(inspector_count == 1);
// Test a builtins script.
var array_script = Debug.findScript('native array.js');
......
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