Commit 81ca62cf authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[d8] Extend Shell::Initialize helper

Extend the helper to setup module callbacks and the console delegate.

Change-Id: I253d5728b9720eadd532728ed6472f02176364e6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2062388Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66331}
parent db59a499
...@@ -2142,17 +2142,27 @@ static void PrintMessageCallback(Local<Message> message, Local<Value> error) { ...@@ -2142,17 +2142,27 @@ static void PrintMessageCallback(Local<Message> message, Local<Value> error) {
printf("%s:%i: %s\n", filename_string, linenum, msg_string); printf("%s:%i: %s\n", filename_string, linenum, msg_string);
} }
void Shell::Initialize(Isolate* isolate) { void Shell::Initialize(Isolate* isolate, D8Console* console,
// Set up counters bool isOnMainThread) {
if (i::FLAG_map_counters[0] != '\0') { if (isOnMainThread) {
MapCounters(isolate, i::FLAG_map_counters); // Set up counters
if (i::FLAG_map_counters[0] != '\0') {
MapCounters(isolate, i::FLAG_map_counters);
}
// Disable default message reporting.
isolate->AddMessageListenerWithErrorLevel(
PrintMessageCallback,
v8::Isolate::kMessageError | v8::Isolate::kMessageWarning |
v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug |
v8::Isolate::kMessageLog);
} }
// Disable default message reporting.
isolate->AddMessageListenerWithErrorLevel( isolate->SetHostImportModuleDynamicallyCallback(
PrintMessageCallback, Shell::HostImportModuleDynamically);
v8::Isolate::kMessageError | v8::Isolate::kMessageWarning | isolate->SetHostInitializeImportMetaObjectCallback(
v8::Isolate::kMessageInfo | v8::Isolate::kMessageDebug | Shell::HostInitializeImportMetaObject);
v8::Isolate::kMessageLog);
debug::SetConsoleDelegate(isolate, console);
} }
Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) { Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
...@@ -2726,13 +2736,10 @@ void SourceGroup::ExecuteInThread() { ...@@ -2726,13 +2736,10 @@ void SourceGroup::ExecuteInThread() {
Isolate::CreateParams create_params; Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator; create_params.array_buffer_allocator = Shell::array_buffer_allocator;
Isolate* isolate = Isolate::New(create_params); Isolate* isolate = Isolate::New(create_params);
isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
isolate->SetHostInitializeImportMetaObjectCallback(
Shell::HostInitializeImportMetaObject);
Shell::SetWaitUntilDone(isolate, false); Shell::SetWaitUntilDone(isolate, false);
D8Console console(isolate); D8Console console(isolate);
debug::SetConsoleDelegate(isolate, &console); Shell::Initialize(isolate, &console, false);
for (int i = 0; i < Shell::options.stress_runs; ++i) { for (int i = 0; i < Shell::options.stress_runs; ++i) {
next_semaphore_.Wait(); next_semaphore_.Wait();
{ {
...@@ -2871,12 +2878,8 @@ void Worker::ExecuteInThread() { ...@@ -2871,12 +2878,8 @@ void Worker::ExecuteInThread() {
Isolate::CreateParams create_params; Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator; create_params.array_buffer_allocator = Shell::array_buffer_allocator;
Isolate* isolate = Isolate::New(create_params); Isolate* isolate = Isolate::New(create_params);
isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
isolate->SetHostInitializeImportMetaObjectCallback(
Shell::HostInitializeImportMetaObject);
D8Console console(isolate); D8Console console(isolate);
debug::SetConsoleDelegate(isolate, &console); Shell::Initialize(isolate, &console, false);
{ {
Isolate::Scope iscope(isolate); Isolate::Scope iscope(isolate);
{ {
...@@ -3727,17 +3730,12 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -3727,17 +3730,12 @@ int Shell::Main(int argc, char* argv[]) {
} }
Isolate* isolate = Isolate::New(create_params); Isolate* isolate = Isolate::New(create_params);
isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
isolate->SetHostInitializeImportMetaObjectCallback(
Shell::HostInitializeImportMetaObject);
D8Console console(isolate);
{ {
D8Console console(isolate);
Isolate::Scope scope(isolate); Isolate::Scope scope(isolate);
Initialize(isolate); Initialize(isolate, &console);
PerIsolateData data(isolate); PerIsolateData data(isolate);
debug::SetConsoleDelegate(isolate, &console);
if (options.trace_enabled) { if (options.trace_enabled) {
platform::tracing::TraceConfig* trace_config; platform::tracing::TraceConfig* trace_config;
...@@ -3789,14 +3787,9 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -3789,14 +3787,9 @@ int Shell::Main(int argc, char* argv[]) {
i::FLAG_hash_seed ^= 1337; // Use a different hash seed. i::FLAG_hash_seed ^= 1337; // Use a different hash seed.
Isolate* isolate2 = Isolate::New(create_params); Isolate* isolate2 = Isolate::New(create_params);
i::FLAG_hash_seed ^= 1337; // Restore old hash seed. i::FLAG_hash_seed ^= 1337; // Restore old hash seed.
isolate2->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
isolate2->SetHostInitializeImportMetaObjectCallback(
Shell::HostInitializeImportMetaObject);
{ {
D8Console console(isolate2); D8Console console(isolate2);
Initialize(isolate2); Initialize(isolate2, &console);
debug::SetConsoleDelegate(isolate2, &console);
PerIsolateData data(isolate2); PerIsolateData data(isolate2);
Isolate::Scope isolate_scope(isolate2); Isolate::Scope isolate_scope(isolate2);
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
namespace v8 { namespace v8 {
class D8Console;
// A single counter in a counter collection. // A single counter in a counter collection.
class Counter { class Counter {
public: public:
...@@ -456,6 +458,9 @@ class Shell : public i::AllStatic { ...@@ -456,6 +458,9 @@ class Shell : public i::AllStatic {
static void AddRunningWorker(std::shared_ptr<Worker> worker); static void AddRunningWorker(std::shared_ptr<Worker> worker);
static void RemoveRunningWorker(const std::shared_ptr<Worker>& worker); static void RemoveRunningWorker(const std::shared_ptr<Worker>& worker);
static void Initialize(Isolate* isolate, D8Console* console,
bool isOnMainThread = true);
private: private:
static Global<Context> evaluation_context_; static Global<Context> evaluation_context_;
static base::OnceType quit_once_; static base::OnceType quit_once_;
...@@ -482,7 +487,6 @@ class Shell : public i::AllStatic { ...@@ -482,7 +487,6 @@ class Shell : public i::AllStatic {
static void WriteLcovData(v8::Isolate* isolate, const char* file); static void WriteLcovData(v8::Isolate* isolate, const char* file);
static Counter* GetCounter(const char* name, bool is_histogram); static Counter* GetCounter(const char* name, bool is_histogram);
static Local<String> Stringify(Isolate* isolate, Local<Value> value); static Local<String> Stringify(Isolate* isolate, Local<Value> value);
static void Initialize(Isolate* isolate);
static void RunShell(Isolate* isolate); static void RunShell(Isolate* isolate);
static bool SetOptions(int argc, char* argv[]); static bool SetOptions(int argc, char* argv[]);
static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate); static Local<ObjectTemplate> CreateGlobalTemplate(Isolate* isolate);
......
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