summaryrefslogtreecommitdiff
path: root/chromium/v8/src/d8.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-12 14:07:37 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 10:29:26 +0000
commitec02ee4181c49b61fce1c8fb99292dbb8139cc90 (patch)
tree25cde714b2b71eb639d1cd53f5a22e9ba76e14ef /chromium/v8/src/d8.cc
parentbb09965444b5bb20b096a291445170876225268d (diff)
downloadqtwebengine-chromium-ec02ee4181c49b61fce1c8fb99292dbb8139cc90.tar.gz
BASELINE: Update Chromium to 59.0.3071.134
Change-Id: Id02ef6fb2204c5fd21668a1c3e6911c83b17585a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/v8/src/d8.cc')
-rw-r--r--chromium/v8/src/d8.cc230
1 files changed, 171 insertions, 59 deletions
diff --git a/chromium/v8/src/d8.cc b/chromium/v8/src/d8.cc
index 64349f2761f..cb29f4fd303 100644
--- a/chromium/v8/src/d8.cc
+++ b/chromium/v8/src/d8.cc
@@ -22,9 +22,9 @@
#include "include/libplatform/libplatform.h"
#include "include/libplatform/v8-tracing.h"
+#include "include/v8-inspector.h"
#include "src/api.h"
#include "src/base/cpu.h"
-#include "src/base/debug/stack_trace.h"
#include "src/base/logging.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/time.h"
@@ -36,13 +36,10 @@
#include "src/msan.h"
#include "src/objects-inl.h"
#include "src/snapshot/natives.h"
+#include "src/trap-handler/trap-handler.h"
#include "src/utils.h"
#include "src/v8.h"
-#ifdef V8_INSPECTOR_ENABLED
-#include "include/v8-inspector.h"
-#endif // V8_INSPECTOR_ENABLED
-
#if !defined(_WIN32) && !defined(_WIN64)
#include <unistd.h> // NOLINT
#else
@@ -226,7 +223,6 @@ static Local<Value> Throw(Isolate* isolate, const char* message) {
.ToLocalChecked());
}
-
Worker* GetWorkerFromInternalField(Isolate* isolate, Local<Object> object) {
if (object->InternalFieldCount() != 1) {
Throw(isolate, "this is not a Worker");
@@ -439,6 +435,8 @@ ScriptCompiler::CachedData* CompileForCachedData(
}
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
+ create_params.host_import_module_dynamically_callback_ =
+ Shell::HostImportModuleDynamically;
Isolate* temp_isolate = Isolate::New(create_params);
ScriptCompiler::CachedData* result = NULL;
{
@@ -447,19 +445,21 @@ ScriptCompiler::CachedData* CompileForCachedData(
Context::Scope context_scope(Context::New(temp_isolate));
Local<String> source_copy =
v8::String::NewFromTwoByte(temp_isolate, source_buffer,
- v8::NewStringType::kNormal,
- source_length).ToLocalChecked();
+ v8::NewStringType::kNormal, source_length)
+ .ToLocalChecked();
Local<Value> name_copy;
if (name_buffer) {
- name_copy = v8::String::NewFromTwoByte(temp_isolate, name_buffer,
- v8::NewStringType::kNormal,
- name_length).ToLocalChecked();
+ name_copy =
+ v8::String::NewFromTwoByte(temp_isolate, name_buffer,
+ v8::NewStringType::kNormal, name_length)
+ .ToLocalChecked();
} else {
name_copy = v8::Undefined(temp_isolate);
}
ScriptCompiler::Source script_source(source_copy, ScriptOrigin(name_copy));
if (!ScriptCompiler::CompileUnboundScript(temp_isolate, &script_source,
- compile_options).IsEmpty() &&
+ compile_options)
+ .IsEmpty() &&
script_source.GetCachedData()) {
int length = script_source.GetCachedData()->length;
uint8_t* cache = new uint8_t[length];
@@ -684,12 +684,11 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
const std::string& file_name) {
DCHECK(IsAbsolutePath(file_name));
Isolate* isolate = context->GetIsolate();
- TryCatch try_catch(isolate);
- try_catch.SetVerbose(true);
Local<String> source_text = ReadFile(isolate, file_name.c_str());
if (source_text.IsEmpty()) {
- printf("Error reading '%s'\n", file_name.c_str());
- Shell::Exit(1);
+ std::string msg = "Error reading: " + file_name;
+ Throw(isolate, msg.c_str());
+ return MaybeLocal<Module>();
}
ScriptOrigin origin(
String::NewFromUtf8(isolate, file_name.c_str(), NewStringType::kNormal)
@@ -699,7 +698,6 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
ScriptCompiler::Source source(source_text, origin);
Local<Module> module;
if (!ScriptCompiler::CompileModule(isolate, &source).ToLocal(&module)) {
- ReportException(isolate, &try_catch);
return MaybeLocal<Module>();
}
@@ -726,6 +724,85 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
return module;
}
+namespace {
+
+struct DynamicImportData {
+ DynamicImportData(Isolate* isolate_, Local<String> referrer_,
+ Local<String> specifier_,
+ Local<DynamicImportResult> result_)
+ : isolate(isolate_) {
+ referrer.Reset(isolate, referrer_);
+ specifier.Reset(isolate, specifier_);
+ result.Reset(isolate, result_);
+ }
+
+ Isolate* isolate;
+ Global<String> referrer;
+ Global<String> specifier;
+ Global<DynamicImportResult> result;
+};
+
+} // namespace
+void Shell::HostImportModuleDynamically(Isolate* isolate,
+ Local<String> referrer,
+ Local<String> specifier,
+ Local<DynamicImportResult> result) {
+ DynamicImportData* data =
+ new DynamicImportData(isolate, referrer, specifier, result);
+ isolate->EnqueueMicrotask(Shell::DoHostImportModuleDynamically, data);
+}
+
+void Shell::DoHostImportModuleDynamically(void* import_data) {
+ std::unique_ptr<DynamicImportData> import_data_(
+ static_cast<DynamicImportData*>(import_data));
+ Isolate* isolate(import_data_->isolate);
+ HandleScope handle_scope(isolate);
+
+ Local<String> referrer(import_data_->referrer.Get(isolate));
+ Local<String> specifier(import_data_->specifier.Get(isolate));
+ Local<DynamicImportResult> result(import_data_->result.Get(isolate));
+
+ PerIsolateData* data = PerIsolateData::Get(isolate);
+ Local<Context> realm = data->realms_[data->realm_current_].Get(isolate);
+ Context::Scope context_scope(realm);
+
+ std::string source_url = ToSTLString(referrer);
+ std::string dir_name =
+ IsAbsolutePath(source_url) ? DirName(source_url) : GetWorkingDirectory();
+ std::string file_name = ToSTLString(specifier);
+ std::string absolute_path = NormalizePath(file_name.c_str(), dir_name);
+
+ TryCatch try_catch(isolate);
+ try_catch.SetVerbose(true);
+
+ ModuleEmbedderData* d = GetModuleDataFromContext(realm);
+ Local<Module> root_module;
+ auto module_it = d->specifier_to_module_map.find(absolute_path);
+ if (module_it != d->specifier_to_module_map.end()) {
+ root_module = module_it->second.Get(isolate);
+ } else if (!FetchModuleTree(realm, absolute_path).ToLocal(&root_module)) {
+ CHECK(try_catch.HasCaught());
+ CHECK(result->FinishDynamicImportFailure(realm, try_catch.Exception()));
+ return;
+ }
+
+ MaybeLocal<Value> maybe_result;
+ if (root_module->Instantiate(realm, ResolveModuleCallback)) {
+ maybe_result = root_module->Evaluate(realm);
+ EmptyMessageQueues(isolate);
+ }
+
+ Local<Value> module;
+ if (!maybe_result.ToLocal(&module)) {
+ DCHECK(try_catch.HasCaught());
+ CHECK(result->FinishDynamicImportFailure(realm, try_catch.Exception()));
+ return;
+ }
+
+ DCHECK(!try_catch.HasCaught());
+ CHECK(result->FinishDynamicImportSuccess(realm, root_module));
+}
+
bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
HandleScope handle_scope(isolate);
@@ -735,14 +812,18 @@ bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
std::string absolute_path = NormalizePath(file_name, GetWorkingDirectory());
+ TryCatch try_catch(isolate);
+ try_catch.SetVerbose(true);
+
Local<Module> root_module;
+ MaybeLocal<Value> maybe_exception;
+
if (!FetchModuleTree(realm, absolute_path).ToLocal(&root_module)) {
+ CHECK(try_catch.HasCaught());
+ ReportException(isolate, &try_catch);
return false;
}
- TryCatch try_catch(isolate);
- try_catch.SetVerbose(true);
-
MaybeLocal<Value> maybe_result;
if (root_module->Instantiate(realm, ResolveModuleCallback)) {
maybe_result = root_module->Evaluate(realm);
@@ -881,11 +962,8 @@ MaybeLocal<Context> Shell::CreateRealm(
Local<ObjectTemplate> global_template = CreateGlobalTemplate(isolate);
Local<Context> context =
Context::New(isolate, NULL, global_template, global_object);
- if (context.IsEmpty()) {
- DCHECK(try_catch.HasCaught());
- try_catch.ReThrow();
- return MaybeLocal<Context>();
- }
+ DCHECK(!try_catch.HasCaught());
+ if (context.IsEmpty()) return MaybeLocal<Context>();
InitializeModuleEmbedderData(context);
data->realms_[index].Reset(isolate, context);
args.GetReturnValue().Set(index);
@@ -1150,7 +1228,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
return;
}
- // Initialize the internal field to NULL; if we return early without
+ // Initialize the embedder field to NULL; if we return early without
// creating a new Worker (because the main thread is terminating) we can
// early-out from the instance calls.
args.Holder()->SetAlignedPointerInInternalField(0, NULL);
@@ -1696,7 +1774,7 @@ void Shell::WriteIgnitionDispatchCountersFile(v8::Isolate* isolate) {
void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
if (!file) return;
HandleScope handle_scope(isolate);
- debug::Coverage coverage = debug::Coverage::Collect(isolate, false);
+ debug::Coverage coverage = debug::Coverage::CollectPrecise(isolate);
std::ofstream sink(file, std::ofstream::app);
for (size_t i = 0; i < coverage.ScriptCount(); i++) {
debug::Coverage::ScriptData script_data = coverage.GetScriptData(i);
@@ -1713,8 +1791,12 @@ void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
for (size_t j = 0; j < script_data.FunctionCount(); j++) {
debug::Coverage::FunctionData function_data =
script_data.GetFunctionData(j);
- int start_line = function_data.Start().GetLineNumber();
- int end_line = function_data.End().GetLineNumber();
+ debug::Location start =
+ script->GetSourceLocation(function_data.StartOffset());
+ debug::Location end =
+ script->GetSourceLocation(function_data.EndOffset());
+ int start_line = start.GetLineNumber();
+ int end_line = end.GetLineNumber();
uint32_t count = function_data.Count();
// Ensure space in the array.
lines.resize(std::max(static_cast<size_t>(end_line + 1), lines.size()),
@@ -1732,7 +1814,7 @@ void Shell::WriteLcovData(v8::Isolate* isolate, const char* file) {
name_stream << ToSTLString(name);
} else {
name_stream << "<" << start_line + 1 << "-";
- name_stream << function_data.Start().GetColumnNumber() << ">";
+ name_stream << start.GetColumnNumber() << ">";
}
sink << "FN:" << start_line + 1 << "," << name_stream.str() << std::endl;
sink << "FNDA:" << count << "," << name_stream.str() << std::endl;
@@ -1832,8 +1914,7 @@ static FILE* FOpen(const char* path, const char* mode) {
#endif
}
-
-static char* ReadChars(Isolate* isolate, const char* name, int* size_out) {
+static char* ReadChars(const char* name, int* size_out) {
FILE* file = FOpen(name, "rb");
if (file == NULL) return NULL;
@@ -1880,18 +1961,17 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
DCHECK(sizeof(char) == sizeof(uint8_t)); // NOLINT
String::Utf8Value filename(args[0]);
int length;
+ Isolate* isolate = args.GetIsolate();
if (*filename == NULL) {
- Throw(args.GetIsolate(), "Error loading file");
+ Throw(isolate, "Error loading file");
return;
}
- Isolate* isolate = args.GetIsolate();
DataAndPersistent* data = new DataAndPersistent;
- data->data = reinterpret_cast<uint8_t*>(
- ReadChars(args.GetIsolate(), *filename, &length));
+ data->data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length));
if (data->data == NULL) {
delete data;
- Throw(args.GetIsolate(), "Error reading file");
+ Throw(isolate, "Error reading file");
return;
}
data->byte_length = length;
@@ -1909,7 +1989,7 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
// Reads a file into a v8 string.
Local<String> Shell::ReadFile(Isolate* isolate, const char* name) {
int size = 0;
- char* chars = ReadChars(isolate, name, &size);
+ char* chars = ReadChars(name, &size);
if (chars == NULL) return Local<String>();
Local<String> result =
String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size)
@@ -1939,7 +2019,6 @@ void Shell::RunShell(Isolate* isolate) {
printf("\n");
}
-#ifdef V8_INSPECTOR_ENABLED
class InspectorFrontend final : public v8_inspector::V8Inspector::Channel {
public:
explicit InspectorFrontend(Local<Context> context) {
@@ -1983,8 +2062,8 @@ class InspectorFrontend final : public v8_inspector::V8Inspector::Channel {
if (callback->IsFunction()) {
v8::TryCatch try_catch(isolate_);
Local<Value> args[] = {message};
- MaybeLocal<Value> result = Local<Function>::Cast(callback)->Call(
- context, Undefined(isolate_), 1, args);
+ USE(Local<Function>::Cast(callback)->Call(context, Undefined(isolate_), 1,
+ args));
#ifdef DEBUG
if (try_catch.HasCaught()) {
Local<Object> exception = Local<Object>::Cast(try_catch.Exception());
@@ -2029,6 +2108,8 @@ class InspectorClient : public v8_inspector::V8InspectorClient {
.ToLocalChecked();
CHECK(context->Global()->Set(context, function_name, function).FromJust());
+ v8::debug::SetLiveEditEnabled(isolate_, true);
+
context_.Reset(isolate_, context);
}
@@ -2070,12 +2151,6 @@ class InspectorClient : public v8_inspector::V8InspectorClient {
Global<Context> context_;
Isolate* isolate_;
};
-#else // V8_INSPECTOR_ENABLED
-class InspectorClient {
- public:
- InspectorClient(Local<Context> context, bool connect) { CHECK(!connect); }
-};
-#endif // V8_INSPECTOR_ENABLED
SourceGroup::~SourceGroup() {
delete thread_;
@@ -2141,7 +2216,7 @@ void SourceGroup::Execute(Isolate* isolate) {
Local<String> SourceGroup::ReadFile(Isolate* isolate, const char* name) {
int size;
- char* chars = ReadChars(isolate, name, &size);
+ char* chars = ReadChars(name, &size);
if (chars == NULL) return Local<String>();
Local<String> result =
String::NewFromUtf8(isolate, chars, NewStringType::kNormal, size)
@@ -2162,6 +2237,8 @@ base::Thread::Options SourceGroup::GetThreadOptions() {
void SourceGroup::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
+ create_params.host_import_module_dynamically_callback_ =
+ Shell::HostImportModuleDynamically;
Isolate* isolate = Isolate::New(create_params);
for (int i = 0; i < Shell::options.stress_runs; ++i) {
next_semaphore_.Wait();
@@ -2300,6 +2377,8 @@ void Worker::WaitForThread() {
void Worker::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
+ create_params.host_import_module_dynamically_callback_ =
+ Shell::HostImportModuleDynamically;
Isolate* isolate = Isolate::New(create_params);
{
Isolate::Scope iscope(isolate);
@@ -2537,7 +2616,9 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[], bool last_run) {
options.isolate_sources[i].StartExecuteInThread();
}
{
- if (options.lcov_file) debug::Coverage::TogglePrecise(isolate, true);
+ if (options.lcov_file) {
+ debug::Coverage::SelectMode(isolate, debug::Coverage::kPreciseCount);
+ }
HandleScope scope(isolate);
Local<Context> context = CreateEvaluationContext(isolate);
if (last_run && options.use_interactive_shell()) {
@@ -2581,12 +2662,23 @@ void Shell::CollectGarbage(Isolate* isolate) {
}
}
-
void Shell::EmptyMessageQueues(Isolate* isolate) {
- if (!i::FLAG_verify_predictable) {
- while (v8::platform::PumpMessageLoop(g_platform, isolate)) continue;
+ if (i::FLAG_verify_predictable) return;
+ while (true) {
+ // Pump the message loop until it is empty.
+ while (v8::platform::PumpMessageLoop(g_platform, isolate)) {
+ isolate->RunMicrotasks();
+ }
+ // Run the idle tasks.
v8::platform::RunIdleTasks(g_platform, isolate,
50.0 / base::Time::kMillisecondsPerSecond);
+ // If there are still outstanding waiters, sleep a little (to wait for
+ // background tasks) and then try everything again.
+ if (reinterpret_cast<i::Isolate*>(isolate)->GetWaitCountForTesting() > 0) {
+ base::OS::Sleep(base::TimeDelta::FromMilliseconds(1));
+ } else {
+ break;
+ }
}
}
@@ -2823,7 +2915,10 @@ void Shell::CleanupWorkers() {
static void DumpHeapConstants(i::Isolate* isolate) {
i::Heap* heap = isolate->heap();
-
+ printf(
+ "# Copyright 2017 the V8 project authors. All rights reserved.\n"
+ "# Use of this source code is governed by a BSD-style license that can\n"
+ "# be found in the LICENSE file.\n\n");
// Dump the INSTANCE_TYPES table to the console.
printf("# List of known V8 instance types.\n");
#define DUMP_TYPE(T) printf(" %d: \"%s\",\n", i::T, #T);
@@ -2843,7 +2938,7 @@ static void DumpHeapConstants(i::Isolate* isolate) {
for (i::Object* o = it.Next(); o != NULL; o = it.Next()) {
i::Map* m = i::Map::cast(o);
const char* n = NULL;
- intptr_t p = reinterpret_cast<intptr_t>(m) & 0xfffff;
+ intptr_t p = reinterpret_cast<intptr_t>(m) & 0x7ffff;
int t = m->instance_type();
ROOT_LIST(ROOT_LIST_CASE)
STRUCT_LIST(STRUCT_LIST_CASE)
@@ -2865,7 +2960,7 @@ static void DumpHeapConstants(i::Isolate* isolate) {
const char* sname = AllocationSpaceName(s->identity());
for (i::Object* o = it.Next(); o != NULL; o = it.Next()) {
const char* n = NULL;
- intptr_t p = reinterpret_cast<intptr_t>(o) & 0xfffff;
+ intptr_t p = reinterpret_cast<intptr_t>(o) & 0x7ffff;
ROOT_LIST(ROOT_LIST_CASE)
if (n == NULL) continue;
printf(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n);
@@ -2873,12 +2968,19 @@ static void DumpHeapConstants(i::Isolate* isolate) {
}
printf("}\n");
#undef ROOT_LIST_CASE
+
+ // Dump frame markers
+ printf("\n# List of known V8 Frame Markers.\n");
+#define DUMP_MARKER(T, class) printf(" \"%s\",\n", #T);
+ printf("FRAME_MARKERS = (\n");
+ STACK_FRAME_TYPE_LIST(DUMP_MARKER)
+ printf(")\n");
+#undef DUMP_TYPE
}
int Shell::Main(int argc, char* argv[]) {
std::ofstream trace_file;
- v8::base::debug::EnableInProcessStackDumping();
#if (defined(_WIN32) || defined(_WIN64))
UINT new_flags =
SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX;
@@ -2898,7 +3000,8 @@ int Shell::Main(int argc, char* argv[]) {
v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file);
g_platform = i::FLAG_verify_predictable
? new PredictablePlatform()
- : v8::platform::CreateDefaultPlatform();
+ : v8::platform::CreateDefaultPlatform(
+ 0, v8::platform::IdleTaskSupport::kEnabled);
platform::tracing::TracingController* tracing_controller;
if (options.trace_enabled) {
@@ -2949,6 +3052,16 @@ int Shell::Main(int argc, char* argv[]) {
create_params.add_histogram_sample_callback = AddHistogramSample;
}
+ create_params.host_import_module_dynamically_callback_ =
+ Shell::HostImportModuleDynamically;
+
+ if (i::trap_handler::UseTrapHandler()) {
+ if (!v8::V8::RegisterDefaultSignalHandler()) {
+ fprintf(stderr, "Could not register signal handler");
+ exit(1);
+ }
+ }
+
Isolate* isolate = Isolate::New(create_params);
{
Isolate::Scope scope(isolate);
@@ -2959,8 +3072,7 @@ int Shell::Main(int argc, char* argv[]) {
platform::tracing::TraceConfig* trace_config;
if (options.trace_config) {
int size = 0;
- char* trace_config_json_str =
- ReadChars(nullptr, options.trace_config, &size);
+ char* trace_config_json_str = ReadChars(options.trace_config, &size);
trace_config =
tracing::CreateTraceConfigFromJSON(isolate, trace_config_json_str);
delete[] trace_config_json_str;