Commit 6ecbb857 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

Revert of [inspector] move console to builtins (patchset #6 id:120001 of...

Revert of [inspector] move console to builtins (patchset #6 id:120001 of https://codereview.chromium.org/2785293002/ )

Reason for revert:
console.toString() should return "[object Object]"

Original issue's description:
> [inspector] move console to builtins
>
> What will we get:
> - console would be included into snapshot and allow us to reduce time that we spent in contextCreated function (~5 times faster),
> - it allows us to make further small improvement of console methods, e.g. we can implement super quick return from console.assert if first argument is true,
> - console calls are ~ 15% faster.
>
> BUG=v8:6175
> R=dgozman@chromium.org
>
> Review-Url: https://codereview.chromium.org/2785293002
> Cr-Commit-Position: refs/heads/master@{#44353}
> Committed: https://chromium.googlesource.com/v8/v8/+/55905f85d63d75aaa9313e51eb7bede754a8e41c

TBR=dgozman@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:6175

Review-Url: https://codereview.chromium.org/2795003003
Cr-Commit-Position: refs/heads/master@{#44354}
parent 55905f85
......@@ -910,7 +910,6 @@ v8_source_set("v8_builtins_generators") {
"src/builtins/builtins-async-generator-gen.cc",
"src/builtins/builtins-async-iterator-gen.cc",
"src/builtins/builtins-boolean-gen.cc",
"src/builtins/builtins-console.cc",
"src/builtins/builtins-constructor-gen.cc",
"src/builtins/builtins-constructor-gen.h",
"src/builtins/builtins-constructor.h",
......
......@@ -150,9 +150,6 @@ class FunctionCallbackArguments;
class GlobalHandles;
} // namespace internal
namespace debug {
class ConsoleCallArguments;
} // namespace debug
// --- Handles ---
......@@ -3569,7 +3566,6 @@ class FunctionCallbackInfo {
protected:
friend class internal::FunctionCallbackArguments;
friend class internal::CustomArguments<FunctionCallbackInfo>;
friend class debug::ConsoleCallArguments;
static const int kHolderIndex = 0;
static const int kIsolateIndex = 1;
static const int kReturnValueDefaultValueIndex = 2;
......
......@@ -25,7 +25,6 @@
#include "src/base/safe_conversions.h"
#include "src/base/utils/random-number-generator.h"
#include "src/bootstrapper.h"
#include "src/builtins/builtins-utils.h"
#include "src/char-predicates-inl.h"
#include "src/code-stubs.h"
#include "src/compiler-dispatcher/compiler-dispatcher.h"
......@@ -9565,22 +9564,6 @@ Local<Function> debug::GetBuiltin(Isolate* v8_isolate, Builtin builtin) {
return Utils::ToLocal(handle_scope.CloseAndEscape(fun));
}
void debug::SetConsoleDelegate(Isolate* v8_isolate, ConsoleDelegate* delegate) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
ENTER_V8(isolate);
isolate->set_console_delegate(delegate);
}
debug::ConsoleCallArguments::ConsoleCallArguments(
const v8::FunctionCallbackInfo<v8::Value>& info)
: v8::FunctionCallbackInfo<v8::Value>(nullptr, info.values_, info.length_) {
}
debug::ConsoleCallArguments::ConsoleCallArguments(
internal::BuiltinArguments& args)
: v8::FunctionCallbackInfo<v8::Value>(nullptr, &args[0] - 1,
args.length() - 1) {}
MaybeLocal<debug::Script> debug::GeneratorObject::Script() {
i::Handle<i::JSGeneratorObject> obj = Utils::OpenHandle(this);
i::Object* maybe_script = obj->function()->shared()->script();
......
......@@ -2604,54 +2604,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
}
{ // -- C o n s o l e
Handle<String> name = factory->InternalizeUtf8String("console");
Handle<JSFunction> cons = factory->NewFunction(name);
Handle<JSObject> empty = factory->NewJSObject(isolate->object_function());
JSFunction::SetInstancePrototype(cons, empty);
Handle<JSObject> console = factory->NewJSObject(cons, TENURED);
DCHECK(console->IsJSObject());
JSObject::AddProperty(global, name, console, DONT_ENUM);
SimpleInstallFunction(console, "debug", Builtins::kConsoleDebug, 1, false);
SimpleInstallFunction(console, "error", Builtins::kConsoleError, 1, false);
SimpleInstallFunction(console, "info", Builtins::kConsoleInfo, 1, false);
SimpleInstallFunction(console, "log", Builtins::kConsoleLog, 1, false);
SimpleInstallFunction(console, "warn", Builtins::kConsoleWarn, 1, false);
SimpleInstallFunction(console, "dir", Builtins::kConsoleDir, 1, false);
SimpleInstallFunction(console, "dirxml", Builtins::kConsoleDirXml, 1,
false);
SimpleInstallFunction(console, "table", Builtins::kConsoleTable, 1, false);
SimpleInstallFunction(console, "trace", Builtins::kConsoleTrace, 1, false);
SimpleInstallFunction(console, "group", Builtins::kConsoleGroup, 1, false);
SimpleInstallFunction(console, "groupCollapsed",
Builtins::kConsoleGroupCollapsed, 1, false);
SimpleInstallFunction(console, "groupEnd", Builtins::kConsoleGroupEnd, 1,
false);
SimpleInstallFunction(console, "clear", Builtins::kConsoleClear, 1, false);
SimpleInstallFunction(console, "count", Builtins::kConsoleCount, 1, false);
SimpleInstallFunction(console, "assert", Builtins::kConsoleAssert, 1,
false);
SimpleInstallFunction(console, "markTimeline",
Builtins::kConsoleMarkTimeline, 1, false);
SimpleInstallFunction(console, "profile", Builtins::kConsoleProfile, 1,
false);
SimpleInstallFunction(console, "profileEnd", Builtins::kConsoleProfileEnd,
1, false);
SimpleInstallFunction(console, "timeline", Builtins::kConsoleTimeline, 1,
false);
SimpleInstallFunction(console, "timelineEnd", Builtins::kConsoleTimelineEnd,
1, false);
SimpleInstallFunction(console, "time", Builtins::kConsoleTime, 1, false);
SimpleInstallFunction(console, "timeEnd", Builtins::kConsoleTimeEnd, 1,
false);
SimpleInstallFunction(console, "timeStamp", Builtins::kConsoleTimeStamp, 1,
false);
JSObject::AddProperty(
console, factory->to_string_tag_symbol(),
factory->NewStringFromAsciiChecked("Console"),
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
}
#ifdef V8_I18N_SUPPORT
{ // -- I n t l
Handle<String> name = factory->InternalizeUtf8String("Intl");
......
// 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.
#include "src/builtins/builtins-utils.h"
#include "src/builtins/builtins.h"
#include "src/debug/interface-types.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
// -----------------------------------------------------------------------------
// Console
#define CONSOLE_METHOD_LIST(V) \
V(Debug) \
V(Error) \
V(Info) \
V(Log) \
V(Warn) \
V(Dir) \
V(DirXml) \
V(Table) \
V(Trace) \
V(Group) \
V(GroupCollapsed) \
V(GroupEnd) \
V(Clear) \
V(Count) \
V(Assert) \
V(MarkTimeline) \
V(Profile) \
V(ProfileEnd) \
V(Timeline) \
V(TimelineEnd) \
V(Time) \
V(TimeEnd) \
V(TimeStamp)
#define CONSOLE_BUILTIN_IMPLEMENTATION(name) \
BUILTIN(Console##name) { \
HandleScope scope(isolate); \
if (isolate->console_delegate()) { \
debug::ConsoleCallArguments wrapper(args); \
isolate->console_delegate()->name(wrapper); \
} \
return isolate->heap()->undefined_value(); \
}
CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_IMPLEMENTATION)
#undef CONSOLE_BUILTIN_IMPLEMENTATION
#undef CONSOLE_METHOD_LIST
} // namespace internal
} // namespace v8
......@@ -335,31 +335,6 @@ namespace internal {
CPP(CallSitePrototypeIsToplevel) \
CPP(CallSitePrototypeToString) \
\
/* Console */ \
CPP(ConsoleDebug) \
CPP(ConsoleError) \
CPP(ConsoleInfo) \
CPP(ConsoleLog) \
CPP(ConsoleWarn) \
CPP(ConsoleDir) \
CPP(ConsoleDirXml) \
CPP(ConsoleTable) \
CPP(ConsoleTrace) \
CPP(ConsoleGroup) \
CPP(ConsoleGroupCollapsed) \
CPP(ConsoleGroupEnd) \
CPP(ConsoleClear) \
CPP(ConsoleCount) \
CPP(ConsoleAssert) \
CPP(ConsoleMarkTimeline) \
CPP(ConsoleProfile) \
CPP(ConsoleProfileEnd) \
CPP(ConsoleTimeline) \
CPP(ConsoleTimelineEnd) \
CPP(ConsoleTime) \
CPP(ConsoleTimeEnd) \
CPP(ConsoleTimeStamp) \
\
/* DataView */ \
CPP(DataViewConstructor) \
CPP(DataViewConstructor_ConstructStub) \
......
......@@ -207,8 +207,6 @@ enum Builtin {
Local<Function> GetBuiltin(Isolate* isolate, Builtin builtin);
void SetConsoleDelegate(Isolate* isolate, ConsoleDelegate* delegate);
/**
* Native wrapper around v8::internal::JSGeneratorObject object.
*/
......
......@@ -9,15 +9,9 @@
#include <string>
#include <vector>
#include "include/v8.h"
#include "src/globals.h"
namespace v8 {
namespace internal {
class BuiltinArguments;
} // internal
namespace debug {
/**
......@@ -96,47 +90,6 @@ class V8_EXPORT_PRIVATE BreakLocation : public Location {
BreakLocationType type_;
};
class ConsoleCallArguments : private v8::FunctionCallbackInfo<v8::Value> {
public:
int Length() const { return v8::FunctionCallbackInfo<v8::Value>::Length(); }
V8_INLINE Local<Value> operator[](int i) const {
return v8::FunctionCallbackInfo<v8::Value>::operator[](i);
}
explicit ConsoleCallArguments(const v8::FunctionCallbackInfo<v8::Value>&);
explicit ConsoleCallArguments(internal::BuiltinArguments&);
};
// v8::FunctionCallbackInfo could be used for getting arguments only. Calling
// of any other getter will produce a crash.
class ConsoleDelegate {
public:
virtual void Debug(const ConsoleCallArguments& args) {}
virtual void Error(const ConsoleCallArguments& args) {}
virtual void Info(const ConsoleCallArguments& args) {}
virtual void Log(const ConsoleCallArguments& args) {}
virtual void Warn(const ConsoleCallArguments& args) {}
virtual void Dir(const ConsoleCallArguments& args) {}
virtual void DirXml(const ConsoleCallArguments& args) {}
virtual void Table(const ConsoleCallArguments& args) {}
virtual void Trace(const ConsoleCallArguments& args) {}
virtual void Group(const ConsoleCallArguments& args) {}
virtual void GroupCollapsed(const ConsoleCallArguments& args) {}
virtual void GroupEnd(const ConsoleCallArguments& args) {}
virtual void Clear(const ConsoleCallArguments& args) {}
virtual void Count(const ConsoleCallArguments& args) {}
virtual void Assert(const ConsoleCallArguments& args) {}
virtual void MarkTimeline(const ConsoleCallArguments& args) {}
virtual void Profile(const ConsoleCallArguments& args) {}
virtual void ProfileEnd(const ConsoleCallArguments& args) {}
virtual void Timeline(const ConsoleCallArguments& args) {}
virtual void TimelineEnd(const ConsoleCallArguments& args) {}
virtual void Time(const ConsoleCallArguments& args) {}
virtual void TimeEnd(const ConsoleCallArguments& args) {}
virtual void TimeStamp(const ConsoleCallArguments& args) {}
virtual ~ConsoleDelegate() = default;
};
} // namespace debug
} // namespace v8
......
......@@ -27,15 +27,17 @@ InspectedContext::InspectedContext(V8InspectorImpl* inspector,
v8::Isolate* isolate = m_inspector->isolate();
info.context->SetEmbedderData(static_cast<int>(v8::Context::kDebugIdIndex),
v8::Int32::New(isolate, contextId));
if (!info.hasMemoryOnConsole) return;
v8::Context::Scope contextScope(info.context);
v8::Local<v8::Object> global = info.context->Global();
v8::Local<v8::Value> console;
if (global->Get(info.context, toV8String(m_inspector->isolate(), "console"))
.ToLocal(&console) &&
console->IsObject()) {
m_inspector->console()->installMemoryGetter(
info.context, v8::Local<v8::Object>::Cast(console));
v8::Local<v8::Object> console =
m_inspector->console()->createConsole(info.context);
if (info.hasMemoryOnConsole) {
m_inspector->console()->installMemoryGetter(info.context, console);
}
if (!global
->Set(info.context, toV8StringInternalized(isolate, "console"),
console)
.FromMaybe(false)) {
return;
}
}
......
......@@ -25,11 +25,11 @@ namespace {
class ConsoleHelper {
public:
ConsoleHelper(const v8::debug::ConsoleCallArguments& info,
V8InspectorImpl* inspector)
explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info,
V8InspectorImpl* inspector)
: m_info(info),
m_isolate(inspector->isolate()),
m_context(m_isolate->GetCurrentContext()),
m_isolate(info.GetIsolate()),
m_context(info.GetIsolate()->GetCurrentContext()),
m_inspector(inspector),
m_contextId(InspectedContext::contextId(m_context)),
m_groupId(m_inspector->contextGroupId(m_contextId)) {}
......@@ -145,7 +145,7 @@ class ConsoleHelper {
}
private:
const v8::debug::ConsoleCallArguments& m_info;
const v8::FunctionCallbackInfo<v8::Value>& m_info;
v8::Isolate* m_isolate;
v8::Local<v8::Context> m_context;
V8InspectorImpl* m_inspector = nullptr;
......@@ -190,63 +190,66 @@ void createBoundFunctionProperty(v8::Local<v8::Context> context,
V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
void V8Console::Debug(const v8::debug::ConsoleCallArguments& info) {
void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug);
}
void V8Console::Error(const v8::debug::ConsoleCallArguments& info) {
void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError);
}
void V8Console::Info(const v8::debug::ConsoleCallArguments& info) {
void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo);
}
void V8Console::Log(const v8::debug::ConsoleCallArguments& info) {
void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog);
}
void V8Console::Warn(const v8::debug::ConsoleCallArguments& info) {
void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning);
}
void V8Console::Dir(const v8::debug::ConsoleCallArguments& info) {
void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir);
}
void V8Console::DirXml(const v8::debug::ConsoleCallArguments& info) {
void V8Console::dirxmlCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML);
}
void V8Console::Table(const v8::debug::ConsoleCallArguments& info) {
void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable);
}
void V8Console::Trace(const v8::debug::ConsoleCallArguments& info) {
void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
String16("console.trace"));
}
void V8Console::Group(const v8::debug::ConsoleCallArguments& info) {
void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
String16("console.group"));
}
void V8Console::GroupCollapsed(const v8::debug::ConsoleCallArguments& info) {
void V8Console::groupCollapsedCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
String16("console.groupCollapsed"));
}
void V8Console::GroupEnd(const v8::debug::ConsoleCallArguments& info) {
void V8Console::groupEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
String16("console.groupEnd"));
}
void V8Console::Clear(const v8::debug::ConsoleCallArguments& info) {
void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info, m_inspector);
if (!helper.groupId()) return;
m_inspector->client()->consoleClear(helper.groupId());
......@@ -254,7 +257,7 @@ void V8Console::Clear(const v8::debug::ConsoleCallArguments& info) {
String16("console.clear"));
}
void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info, m_inspector);
String16 title = helper.firstArgToString(String16());
String16 identifier;
......@@ -277,7 +280,8 @@ void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
title.isEmpty() ? countString : (title + ": " + countString));
}
void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
void V8Console::assertCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info, m_inspector);
if (helper.firstArgToBoolean(false)) return;
......@@ -285,7 +289,7 @@ void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]);
if (info.Length() < 2)
arguments.push_back(
toV8String(m_inspector->isolate(), String16("console.assert")));
toV8String(info.GetIsolate(), String16("console.assert")));
helper.reportCall(ConsoleAPIType::kAssert, arguments);
if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent())
......@@ -293,28 +297,31 @@ void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
protocol::Debugger::Paused::ReasonEnum::Assert, nullptr);
}
void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info) {
void V8Console::markTimelineCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportDeprecatedCall("V8Console#markTimelineDeprecated",
"'console.markTimeline' is "
"deprecated. Please use "
"'console.timeStamp' instead.");
TimeStamp(info);
timeStampCallback(info);
}
void V8Console::Profile(const v8::debug::ConsoleCallArguments& info) {
void V8Console::profileCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info, m_inspector);
if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
profilerAgent->consoleProfile(helper.firstArgToString(String16()));
}
void V8Console::ProfileEnd(const v8::debug::ConsoleCallArguments& info) {
void V8Console::profileEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info, m_inspector);
if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
}
static void timeFunction(const v8::debug::ConsoleCallArguments& info,
static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
bool timelinePrefix, V8InspectorImpl* inspector) {
ConsoleHelper helper(info, inspector);
String16 protocolTitle = helper.firstArgToString("default");
......@@ -323,7 +330,7 @@ static void timeFunction(const v8::debug::ConsoleCallArguments& info,
helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
}
static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info,
bool timelinePrefix, V8InspectorImpl* inspector) {
ConsoleHelper helper(info, inspector);
String16 protocolTitle = helper.firstArgToString("default");
......@@ -336,7 +343,8 @@ static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
}
void V8Console::Timeline(const v8::debug::ConsoleCallArguments& info) {
void V8Console::timelineCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportDeprecatedCall("V8Console#timeline",
"'console.timeline' is deprecated. Please use "
......@@ -344,7 +352,8 @@ void V8Console::Timeline(const v8::debug::ConsoleCallArguments& info) {
timeFunction(info, true, m_inspector);
}
void V8Console::TimelineEnd(const v8::debug::ConsoleCallArguments& info) {
void V8Console::timelineEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper(info, m_inspector)
.reportDeprecatedCall("V8Console#timelineEnd",
"'console.timelineEnd' is "
......@@ -353,15 +362,17 @@ void V8Console::TimelineEnd(const v8::debug::ConsoleCallArguments& info) {
timeEndFunction(info, true, m_inspector);
}
void V8Console::Time(const v8::debug::ConsoleCallArguments& info) {
void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
timeFunction(info, false, m_inspector);
}
void V8Console::TimeEnd(const v8::debug::ConsoleCallArguments& info) {
void V8Console::timeEndCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
timeEndFunction(info, false, m_inspector);
}
void V8Console::TimeStamp(const v8::debug::ConsoleCallArguments& info) {
void V8Console::timeStampCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
ConsoleHelper helper(info, m_inspector);
String16 title = helper.firstArgToString(String16());
m_inspector->client()->consoleTimeStamp(toStringView(title));
......@@ -389,8 +400,7 @@ void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Object> obj;
if (!helper.firstArgAsObject().ToLocal(&obj)) return;
v8::Local<v8::Array> names;
......@@ -404,8 +414,7 @@ void V8Console::valuesCallback(
v8::Isolate* isolate = info.GetIsolate();
info.GetReturnValue().Set(v8::Array::New(isolate));
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Object> obj;
if (!helper.firstArgAsObject().ToLocal(&obj)) return;
v8::Local<v8::Array> names;
......@@ -444,8 +453,7 @@ static void setFunctionBreakpoint(ConsoleHelper& helper,
void V8Console::debugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
setFunctionBreakpoint(helper, function,
......@@ -455,8 +463,7 @@ void V8Console::debugFunctionCallback(
void V8Console::undebugFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
setFunctionBreakpoint(helper, function,
......@@ -466,8 +473,7 @@ void V8Console::undebugFunctionCallback(
void V8Console::monitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
v8::Local<v8::Value> name = function->GetName();
......@@ -490,8 +496,7 @@ void V8Console::monitorFunctionCallback(
void V8Console::unmonitorFunctionCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
v8::Local<v8::Function> function;
if (!helper.firstArgAsFunction().ToLocal(&function)) return;
setFunctionBreakpoint(helper, function,
......@@ -501,8 +506,7 @@ void V8Console::unmonitorFunctionCallback(
void V8Console::lastEvaluationResultCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
InjectedScript* injectedScript = helper.injectedScript();
if (!injectedScript) return;
info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
......@@ -513,8 +517,7 @@ static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
if (info.Length() < 1) return;
if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, inspector);
ConsoleHelper helper(info, inspector);
InjectedScript* injectedScript = helper.injectedScript();
if (!injectedScript) return;
std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
......@@ -544,8 +547,7 @@ void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
unsigned num) {
DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
v8::debug::ConsoleCallArguments args(info);
ConsoleHelper helper(args, m_inspector);
ConsoleHelper helper(info, m_inspector);
if (V8InspectorSessionImpl* session = helper.currentSession()) {
V8InspectorSession::Inspectable* object = session->inspectedObject(num);
v8::Isolate* isolate = info.GetIsolate();
......@@ -556,6 +558,71 @@ void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
}
}
v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) {
v8::Context::Scope contextScope(context);
v8::Isolate* isolate = context->GetIsolate();
v8::MicrotasksScope microtasksScope(isolate,
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Object> console = v8::Object::New(isolate);
bool success =
console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false);
DCHECK(success);
USE(success);
v8::Local<v8::External> data = v8::External::New(isolate, this);
createBoundFunctionProperty(context, console, data, "debug",
&V8Console::call<&V8Console::debugCallback>);
createBoundFunctionProperty(context, console, data, "error",
&V8Console::call<&V8Console::errorCallback>);
createBoundFunctionProperty(context, console, data, "info",
&V8Console::call<&V8Console::infoCallback>);
createBoundFunctionProperty(context, console, data, "log",
&V8Console::call<&V8Console::logCallback>);
createBoundFunctionProperty(context, console, data, "warn",
&V8Console::call<&V8Console::warnCallback>);
createBoundFunctionProperty(context, console, data, "dir",
&V8Console::call<&V8Console::dirCallback>);
createBoundFunctionProperty(context, console, data, "dirxml",
&V8Console::call<&V8Console::dirxmlCallback>);
createBoundFunctionProperty(context, console, data, "table",
&V8Console::call<&V8Console::tableCallback>);
createBoundFunctionProperty(context, console, data, "trace",
&V8Console::call<&V8Console::traceCallback>);
createBoundFunctionProperty(context, console, data, "group",
&V8Console::call<&V8Console::groupCallback>);
createBoundFunctionProperty(
context, console, data, "groupCollapsed",
&V8Console::call<&V8Console::groupCollapsedCallback>);
createBoundFunctionProperty(context, console, data, "groupEnd",
&V8Console::call<&V8Console::groupEndCallback>);
createBoundFunctionProperty(context, console, data, "clear",
&V8Console::call<&V8Console::clearCallback>);
createBoundFunctionProperty(context, console, data, "count",
&V8Console::call<&V8Console::countCallback>);
createBoundFunctionProperty(context, console, data, "assert",
&V8Console::call<&V8Console::assertCallback>);
createBoundFunctionProperty(
context, console, data, "markTimeline",
&V8Console::call<&V8Console::markTimelineCallback>);
createBoundFunctionProperty(context, console, data, "profile",
&V8Console::call<&V8Console::profileCallback>);
createBoundFunctionProperty(context, console, data, "profileEnd",
&V8Console::call<&V8Console::profileEndCallback>);
createBoundFunctionProperty(context, console, data, "timeline",
&V8Console::call<&V8Console::timelineCallback>);
createBoundFunctionProperty(
context, console, data, "timelineEnd",
&V8Console::call<&V8Console::timelineEndCallback>);
createBoundFunctionProperty(context, console, data, "time",
&V8Console::call<&V8Console::timeCallback>);
createBoundFunctionProperty(context, console, data, "timeEnd",
&V8Console::call<&V8Console::timeEndCallback>);
createBoundFunctionProperty(context, console, data, "timeStamp",
&V8Console::call<&V8Console::timeStampCallback>);
return console;
}
void V8Console::installMemoryGetter(v8::Local<v8::Context> context,
v8::Local<v8::Object> console) {
v8::Isolate* isolate = context->GetIsolate();
......@@ -587,24 +654,24 @@ v8::Local<v8::Object> V8Console::createCommandLineAPI(
v8::Local<v8::External> data = v8::External::New(isolate, this);
createBoundFunctionProperty(context, commandLineAPI, data, "dir",
&V8Console::call<&V8Console::Dir>,
&V8Console::call<&V8Console::dirCallback>,
"function dir(value) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "dirxml",
&V8Console::call<&V8Console::DirXml>,
&V8Console::call<&V8Console::dirxmlCallback>,
"function dirxml(value) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "profile",
&V8Console::call<&V8Console::Profile>,
&V8Console::call<&V8Console::profileCallback>,
"function profile(title) { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "profileEnd",
&V8Console::call<&V8Console::ProfileEnd>,
&V8Console::call<&V8Console::profileEndCallback>,
"function profileEnd(title) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "clear",
&V8Console::call<&V8Console::Clear>,
&V8Console::call<&V8Console::clearCallback>,
"function clear() { [Command Line API] }");
createBoundFunctionProperty(
context, commandLineAPI, data, "table",
&V8Console::call<&V8Console::Table>,
&V8Console::call<&V8Console::tableCallback>,
"function table(data, [columns]) { [Command Line API] }");
createBoundFunctionProperty(context, commandLineAPI, data, "keys",
......
......@@ -8,7 +8,6 @@
#include "src/base/macros.h"
#include "include/v8.h"
#include "src/debug/interface-types.h"
namespace v8_inspector {
......@@ -17,8 +16,9 @@ class V8InspectorImpl;
// Console API
// https://console.spec.whatwg.org/#console-interface
class V8Console : public v8::debug::ConsoleDelegate {
class V8Console {
public:
v8::Local<v8::Object> createConsole(v8::Local<v8::Context> context);
v8::Local<v8::Object> createCommandLineAPI(v8::Local<v8::Context> context);
void installMemoryGetter(v8::Local<v8::Context> context,
v8::Local<v8::Object> console);
......@@ -49,29 +49,29 @@ class V8Console : public v8::debug::ConsoleDelegate {
explicit V8Console(V8InspectorImpl* inspector);
private:
void Debug(const v8::debug::ConsoleCallArguments&) override;
void Error(const v8::debug::ConsoleCallArguments&) override;
void Info(const v8::debug::ConsoleCallArguments&) override;
void Log(const v8::debug::ConsoleCallArguments&) override;
void Warn(const v8::debug::ConsoleCallArguments&) override;
void Dir(const v8::debug::ConsoleCallArguments&) override;
void DirXml(const v8::debug::ConsoleCallArguments&) override;
void Table(const v8::debug::ConsoleCallArguments&) override;
void Trace(const v8::debug::ConsoleCallArguments&) override;
void Group(const v8::debug::ConsoleCallArguments&) override;
void GroupCollapsed(const v8::debug::ConsoleCallArguments&) override;
void GroupEnd(const v8::debug::ConsoleCallArguments&) override;
void Clear(const v8::debug::ConsoleCallArguments&) override;
void Count(const v8::debug::ConsoleCallArguments&) override;
void Assert(const v8::debug::ConsoleCallArguments&) override;
void MarkTimeline(const v8::debug::ConsoleCallArguments&) override;
void Profile(const v8::debug::ConsoleCallArguments&) override;
void ProfileEnd(const v8::debug::ConsoleCallArguments&) override;
void Timeline(const v8::debug::ConsoleCallArguments&) override;
void TimelineEnd(const v8::debug::ConsoleCallArguments&) override;
void Time(const v8::debug::ConsoleCallArguments&) override;
void TimeEnd(const v8::debug::ConsoleCallArguments&) override;
void TimeStamp(const v8::debug::ConsoleCallArguments&) override;
void debugCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void errorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void infoCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void logCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void warnCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void dirCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void dirxmlCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void tableCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void traceCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void groupCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void groupCollapsedCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void groupEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void clearCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void countCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void assertCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void profileCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void profileEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timelineCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timelineEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timeCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timeEndCallback(const v8::FunctionCallbackInfo<v8::Value>&);
void timeStampCallback(const v8::FunctionCallbackInfo<v8::Value>&);
template <void (V8Console::*func)(const v8::FunctionCallbackInfo<v8::Value>&)>
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
......@@ -79,13 +79,6 @@ class V8Console : public v8::debug::ConsoleDelegate {
static_cast<V8Console*>(info.Data().As<v8::External>()->Value());
(console->*func)(info);
}
template <void (V8Console::*func)(const v8::debug::ConsoleCallArguments&)>
static void call(const v8::FunctionCallbackInfo<v8::Value>& info) {
V8Console* console =
static_cast<V8Console*>(info.Data().As<v8::External>()->Value());
v8::debug::ConsoleCallArguments args(info);
(console->*func)(args);
}
// TODO(foolip): There is no spec for the Memory Info API, see blink-dev:
// https://groups.google.com/a/chromium.org/d/msg/blink-dev/g5YRCGpC9vs/b4OJz71NmPwJ
......
......@@ -56,13 +56,9 @@ V8InspectorImpl::V8InspectorImpl(v8::Isolate* isolate,
m_debugger(new V8Debugger(isolate, this)),
m_capturingStackTracesCount(0),
m_lastExceptionId(0),
m_lastContextId(0) {
v8::debug::SetConsoleDelegate(m_isolate, console());
}
m_lastContextId(0) {}
V8InspectorImpl::~V8InspectorImpl() {
v8::debug::SetConsoleDelegate(m_isolate, nullptr);
}
V8InspectorImpl::~V8InspectorImpl() {}
int V8InspectorImpl::contextGroupId(v8::Local<v8::Context> context) {
return contextGroupId(InspectedContext::contextId(context));
......
......@@ -32,10 +32,6 @@ namespace base {
class RandomNumberGenerator;
}
namespace debug {
class ConsoleDelegate;
}
namespace internal {
class AccessCompilerData;
......@@ -741,11 +737,6 @@ class Isolate {
return MaybeHandle<T>();
}
void set_console_delegate(debug::ConsoleDelegate* delegate) {
console_delegate_ = delegate;
}
debug::ConsoleDelegate* console_delegate() { return console_delegate_; }
// Re-throw an exception. This involves no error reporting since error
// reporting was handled when the exception was thrown originally.
Object* ReThrow(Object* exception);
......@@ -1541,8 +1532,6 @@ class Isolate {
CancelableTaskManager* cancelable_task_manager_;
debug::ConsoleDelegate* console_delegate_ = nullptr;
v8::Isolate::AbortOnUncaughtExceptionCallback
abort_on_uncaught_exception_callback_;
......
......@@ -493,7 +493,6 @@
'builtins/builtins-boolean-gen.cc',
'builtins/builtins-call.cc',
'builtins/builtins-callsite.cc',
'builtins/builtins-console.cc',
'builtins/builtins-constructor-gen.cc',
'builtins/builtins-constructor-gen.h',
'builtins/builtins-constructor.h',
......
......@@ -207,7 +207,6 @@ void InspectorClientImpl::disconnect() {
states_[it.first] = it.second->stateJSON();
}
sessions_.clear();
inspector_.reset();
}
void InspectorClientImpl::scheduleCreateContextGroup(
......
Running test: consoleExistsOnGlobal
true
Running test: consoleHasRightPropertyDescriptor
{
configurable : true
enumerable : false
value : <value>
writable : true
}
Running test: ConsoleNotExistsOnGlobal
false
Running test: prototypeChainMustBeCorrect
true
// 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.
InspectorTest.addScript(`
var self = this;
function checkPrototype() {
const prototype1 = Object.getPrototypeOf(console);
const prototype2 = Object.getPrototypeOf(prototype1);
if (Object.getOwnPropertyNames(prototype1).length !== 0)
return "false: The [[Prototype]] must have no properties";
if (prototype2 !== Object.prototype)
return "false: The [[Prototype]]'s [[Prototype]] must be %ObjectPrototype%";
return "true";
}
`);
InspectorTest.runAsyncTestSuite([
async function consoleExistsOnGlobal() {
let message = await Protocol.Runtime.evaluate({
expression: 'self.hasOwnProperty(\'console\')', returnByValue: true});
InspectorTest.log(message.result.result.value);
},
async function consoleHasRightPropertyDescriptor() {
let message = await Protocol.Runtime.evaluate({
expression: 'Object.getOwnPropertyDescriptor(self, \'console\')',
returnByValue: true});
let result = message.result.result.value;
result.value = '<value>';
InspectorTest.logObject(result);
},
async function ConsoleNotExistsOnGlobal() {
let message = await Protocol.Runtime.evaluate({
expression: '\'Console\' in self', returnByValue: true})
InspectorTest.log(message.result.result.value);
},
async function prototypeChainMustBeCorrect() {
let message = await Protocol.Runtime.evaluate({
expression: "checkPrototype()", returnByValue: true });
InspectorTest.log(message.result.result.value);
}
]);
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