Commit a3187716 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

Move d8 into a dedicated subdirectory


Bug: v8:9247
Change-Id: I404e34a013b95c6a7cf03dd9ec0732d9ad796bdc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1613238
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61531}
parent fb36fd22
......@@ -4027,15 +4027,15 @@ if (is_component_build) {
v8_executable("d8") {
sources = [
"src/async-hooks-wrapper.cc",
"src/async-hooks-wrapper.h",
"src/d8-console.cc",
"src/d8-console.h",
"src/d8-js.cc",
"src/d8-platforms.cc",
"src/d8-platforms.h",
"src/d8.cc",
"src/d8.h",
"src/d8/async-hooks-wrapper.cc",
"src/d8/async-hooks-wrapper.h",
"src/d8/d8-console.cc",
"src/d8/d8-console.h",
"src/d8/d8-js.cc",
"src/d8/d8-platforms.cc",
"src/d8/d8-platforms.h",
"src/d8/d8.cc",
"src/d8/d8.h",
]
configs = [
......@@ -4053,9 +4053,9 @@ v8_executable("d8") {
]
if (is_posix || is_fuchsia) {
sources += [ "src/d8-posix.cc" ]
sources += [ "src/d8/d8-posix.cc" ]
} else if (is_win) {
sources += [ "src/d8-windows.cc" ]
sources += [ "src/d8/d8-windows.cc" ]
}
if (v8_correctness_fuzzer) {
......
binji@chromium.org
bmeurer@chromium.org
clemensh@chromium.org
verwaest@chromium.org
yangguo@chromium.org
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/async-hooks-wrapper.h"
#include "src/d8.h"
#include "src/d8/async-hooks-wrapper.h"
#include "src/d8/d8.h"
#include "src/isolate-inl.h"
namespace v8 {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_ASYNC_HOOKS_WRAPPER_H_
#define V8_ASYNC_HOOKS_WRAPPER_H_
#ifndef V8_D8_ASYNC_HOOKS_WRAPPER_H_
#define V8_D8_ASYNC_HOOKS_WRAPPER_H_
#include <stack>
......@@ -93,4 +93,4 @@ class AsyncHooks {
} // namespace v8
#endif // V8_ASYNC_HOOKS_WRAPPER_H_
#endif // V8_D8_ASYNC_HOOKS_WRAPPER_H_
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/d8-console.h"
#include "src/d8.h"
#include "src/d8/d8-console.h"
#include "src/d8/d8.h"
#include "src/isolate.h"
namespace v8 {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_D8_CONSOLE_H_
#define V8_D8_CONSOLE_H_
#ifndef V8_D8_D8_CONSOLE_H_
#define V8_D8_D8_CONSOLE_H_
#include "src/base/platform/time.h"
#include "src/debug/debug-interface.h"
......@@ -44,4 +44,4 @@ class D8Console : public debug::ConsoleDelegate {
} // namespace v8
#endif // V8_D8_CONSOLE_H_
#endif // V8_D8_D8_CONSOLE_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/d8.h"
#include "src/d8/d8.h"
const char* v8::Shell::stringify_source_ = R"D8(
(function() {
......
......@@ -13,7 +13,7 @@
#include "src/base/platform/time.h"
#include "src/base/template-utils.h"
#include "src/base/utils/random-number-generator.h"
#include "src/d8-platforms.h"
#include "src/d8/d8-platforms.h"
namespace v8 {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_D8_PLATFORMS_H_
#define V8_D8_PLATFORMS_H_
#ifndef V8_D8_D8_PLATFORMS_H_
#define V8_D8_D8_PLATFORMS_H_
#include <cstdint>
#include <memory>
......@@ -26,4 +26,4 @@ std::unique_ptr<Platform> MakeDelayedTasksPlatform(
} // namespace v8
#endif // V8_D8_PLATFORMS_H_
#endif // V8_D8_D8_PLATFORMS_H_
......@@ -16,11 +16,10 @@
#include <sys/wait.h>
#include <unistd.h>
#include "src/d8.h"
#include "src/d8/d8.h"
namespace v8 {
// If the buffer ends in the middle of a UTF-8 sequence then we return
// the length of the string up to but not including the incomplete UTF-8
// sequence. If the buffer ends with a valid UTF-8 sequence then we
......@@ -75,12 +74,9 @@ static int LengthWithoutIncompleteUtf8(char* buffer, int len) {
return 0;
}
// Suspends the thread until there is data available from the child process.
// Returns false on timeout, true on data ready.
static bool WaitOnFD(int fd,
int read_timeout,
int total_timeout,
static bool WaitOnFD(int fd, int read_timeout, int total_timeout,
const struct timeval& start_time) {
fd_set readfds, writefds, exceptfds;
struct timeval timeout;
......@@ -109,7 +105,6 @@ static bool WaitOnFD(int fd,
return number_of_fds_ready == 1;
}
// Checks whether we ran out of time on the timeout. Returns true if we ran out
// of time, false if we still have time.
static bool TimeIsOut(const struct timeval& start_time, const int& total_time) {
......@@ -129,32 +124,31 @@ static bool TimeIsOut(const struct timeval& start_time, const int& total_time) {
return false;
}
// A utility class that does a non-hanging waitpid on the child process if we
// bail out of the System() function early. If you don't ever do a waitpid on
// a subprocess then it turns into one of those annoying 'zombie processes'.
class ZombieProtector {
public:
explicit ZombieProtector(int pid): pid_(pid) { }
explicit ZombieProtector(int pid) : pid_(pid) {}
~ZombieProtector() {
if (pid_ != 0) waitpid(pid_, nullptr, 0);
}
void ChildIsDeadNow() { pid_ = 0; }
private:
int pid_;
};
// A utility class that closes a file descriptor when it goes out of scope.
class OpenFDCloser {
public:
explicit OpenFDCloser(int fd): fd_(fd) { }
explicit OpenFDCloser(int fd) : fd_(fd) {}
~OpenFDCloser() { close(fd_); }
private:
int fd_;
};
// A utility class that takes the array of command arguments and puts then in an
// array of new[]ed UTF-8 C strings. Deallocates them again when it goes out of
// scope.
......@@ -178,8 +172,9 @@ class ExecArgs {
int i = 1;
for (unsigned j = 0; j < command_args->Length(); i++, j++) {
Local<Value> arg(
command_args->Get(isolate->GetCurrentContext(),
Integer::New(isolate, j)).ToLocalChecked());
command_args
->Get(isolate->GetCurrentContext(), Integer::New(isolate, j))
.ToLocalChecked());
String::Utf8Value utf8_arg(isolate, arg);
if (*utf8_arg == nullptr) {
exec_args_[i] = nullptr; // Consistent state for destructor.
......@@ -203,7 +198,7 @@ class ExecArgs {
if (exec_args_[i] == nullptr) {
return;
}
delete [] exec_args_[i];
delete[] exec_args_[i];
exec_args_[i] = nullptr;
}
}
......@@ -215,11 +210,9 @@ class ExecArgs {
char* exec_args_[kMaxArgs + 1];
};
// Gets the optional timeouts from the arguments to the system() call.
static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
int* read_timeout,
int* total_timeout) {
int* read_timeout, int* total_timeout) {
if (args.Length() > 3) {
if (args[3]->IsNumber()) {
*total_timeout = args[3]
......@@ -229,7 +222,8 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(),
"system: Argument 4 must be a number",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return false;
}
}
......@@ -242,23 +236,21 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(),
"system: Argument 3 must be a number",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return false;
}
}
return true;
}
static const int kReadFD = 0;
static const int kWriteFD = 1;
// This is run in the child process after fork() but before exec(). It normally
// ends with the child process being replaced with the desired child program.
// It only returns if an error occurred.
static void ExecSubprocess(int* exec_error_fds,
int* stdout_fds,
static void ExecSubprocess(int* exec_error_fds, int* stdout_fds,
const ExecArgs& exec_args) {
close(exec_error_fds[kReadFD]); // Don't need this in the child.
close(stdout_fds[kReadFD]); // Don't need this in the child.
......@@ -277,7 +269,6 @@ static void ExecSubprocess(int* exec_error_fds,
// Return (and exit child process).
}
// Runs in the parent process. Checks that the child was able to exec (closing
// the file desriptor), or reports an error if it failed.
static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
......@@ -295,7 +286,6 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
return true;
}
// Accumulates the output from the child in a string handle. Returns true if it
// succeeded or false if an exception was thrown.
static Local<Value> GetStdout(Isolate* isolate, int child_fd,
......@@ -319,14 +309,12 @@ static Local<Value> GetStdout(Isolate* isolate, int child_fd,
read(child_fd, buffer + fullness, kStdoutReadBufferSize - fullness));
if (bytes_read == -1) {
if (errno == EAGAIN) {
if (!WaitOnFD(child_fd,
read_timeout,
total_timeout,
start_time) ||
if (!WaitOnFD(child_fd, read_timeout, total_timeout, start_time) ||
(TimeIsOut(start_time, total_timeout))) {
return isolate->ThrowException(
String::NewFromUtf8(isolate, "Timed out waiting for output",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
}
continue;
} else if (errno == EINTR) {
......@@ -336,9 +324,9 @@ static Local<Value> GetStdout(Isolate* isolate, int child_fd,
}
}
if (bytes_read + fullness > 0) {
int length = bytes_read == 0 ?
bytes_read + fullness :
LengthWithoutIncompleteUtf8(buffer, bytes_read + fullness);
int length = bytes_read == 0 ? bytes_read + fullness
: LengthWithoutIncompleteUtf8(
buffer, bytes_read + fullness);
Local<String> addition =
String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
.ToLocalChecked();
......@@ -350,7 +338,6 @@ static Local<Value> GetStdout(Isolate* isolate, int child_fd,
return accumulator;
}
// Modern Linux has the waitid call, which is like waitpid, but more useful
// if you want a timeout. If we don't have waitid we can't limit the time
// waiting for the process to exit without losing the information about
......@@ -368,13 +355,10 @@ static Local<Value> GetStdout(Isolate* isolate, int child_fd,
#endif
#endif
// Get exit status of child.
static bool WaitForChild(Isolate* isolate,
int pid,
static bool WaitForChild(Isolate* isolate, int pid,
ZombieProtector& child_waiter, // NOLINT
const struct timeval& start_time,
int read_timeout,
const struct timeval& start_time, int read_timeout,
int total_timeout) {
#ifdef HAS_WAITID
......@@ -391,16 +375,15 @@ static bool WaitForChild(Isolate* isolate,
isolate->ThrowException(
String::NewFromUtf8(isolate,
"Timed out waiting for process to terminate",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
kill(pid, SIGINT);
return false;
}
}
if (child_info.si_code == CLD_KILLED) {
char message[999];
snprintf(message,
sizeof(message),
"Child killed by signal %d",
snprintf(message, sizeof(message), "Child killed by signal %d",
child_info.si_status);
isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
......@@ -409,9 +392,7 @@ static bool WaitForChild(Isolate* isolate,
}
if (child_info.si_code == CLD_EXITED && child_info.si_status != 0) {
char message[999];
snprintf(message,
sizeof(message),
"Child exited with status %d",
snprintf(message, sizeof(message), "Child exited with status %d",
child_info.si_status);
isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
......@@ -426,9 +407,7 @@ static bool WaitForChild(Isolate* isolate,
child_waiter.ChildIsDeadNow();
if (WIFSIGNALED(child_status)) {
char message[999];
snprintf(message,
sizeof(message),
"Child killed by signal %d",
snprintf(message, sizeof(message), "Child killed by signal %d",
WTERMSIG(child_status));
isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
......@@ -438,9 +417,7 @@ static bool WaitForChild(Isolate* isolate,
if (WEXITSTATUS(child_status) != 0) {
char message[999];
int exit_status = WEXITSTATUS(child_status);
snprintf(message,
sizeof(message),
"Child exited with status %d",
snprintf(message, sizeof(message), "Child exited with status %d",
exit_status);
isolate->ThrowException(
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
......@@ -453,6 +430,7 @@ static bool WaitForChild(Isolate* isolate,
return true;
}
#undef HAS_WAITID
// Implementation of the system() function (see d8.h for details).
void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
......@@ -466,7 +444,8 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(),
"system: Argument 2 must be an array",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
command_args = Local<Array>::Cast(args[1]);
......@@ -476,13 +455,15 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (command_args->Length() > ExecArgs::kMaxArgs) {
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "Too many arguments to system()",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
if (args.Length() < 1) {
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "Too few arguments to system()",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
......@@ -499,13 +480,15 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (pipe(exec_error_fds) != 0) {
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
if (pipe(stdout_fds) != 0) {
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), "pipe syscall failed.",
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
......@@ -541,7 +524,6 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(accumulator);
}
void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "chdir() takes one argument";
......@@ -561,12 +543,12 @@ void Shell::ChangeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (chdir(*directory) != 0) {
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), strerror(errno),
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
}
void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "umask() takes one argument";
......@@ -589,7 +571,6 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
static bool CheckItsADirectory(Isolate* isolate, char* directory) {
struct stat stat_buf;
int stat_result = stat(directory, &stat_buf);
......@@ -606,7 +587,6 @@ static bool CheckItsADirectory(Isolate* isolate, char* directory) {
return false;
}
// Returns true for success. Creates intermediate directories as needed. No
// error if the directory exists already.
static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
......@@ -642,7 +622,6 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
}
}
void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
mode_t mask = 0777;
if (args.Length() == 2) {
......@@ -654,7 +633,8 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
const char* message = "mkdirp() second argument must be numeric";
args.GetIsolate()->ThrowException(
String::NewFromUtf8(args.GetIsolate(), message,
NewStringType::kNormal).ToLocalChecked());
NewStringType::kNormal)
.ToLocalChecked());
return;
}
} else if (args.Length() != 1) {
......@@ -675,7 +655,6 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
mkdirp(args.GetIsolate(), *directory, mask);
}
void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "rmdir() takes one or two arguments";
......@@ -695,7 +674,6 @@ void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
rmdir(*directory);
}
void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) {
const char* message = "setenv() takes two arguments";
......@@ -725,7 +703,6 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
setenv(*var, *value, 1);
}
void Shell::UnsetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
const char* message = "unsetenv() takes one argument";
......
......@@ -2,12 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/d8.h"
#include "src/d8/d8.h"
namespace v8 {
void Shell::AddOSMethods(Isolate* isolate, Local<ObjectTemplate> os_templ) {}
char* Shell::ReadCharsFromTcpPort(const char* name, int* size_out) {
......
......@@ -28,9 +28,9 @@
#include "src/base/platform/time.h"
#include "src/base/sys-info.h"
#include "src/basic-block-profiler.h"
#include "src/d8-console.h"
#include "src/d8-platforms.h"
#include "src/d8.h"
#include "src/d8/d8-console.h"
#include "src/d8/d8-platforms.h"
#include "src/d8/d8.h"
#include "src/debug/debug-interface.h"
#include "src/interpreter/interpreter.h"
#include "src/msan.h"
......@@ -51,7 +51,7 @@
#include <unistd.h> // NOLINT
#else
#include <windows.h> // NOLINT
#endif // !defined(_WIN32) && !defined(_WIN64)
#endif // !defined(_WIN32) && !defined(_WIN64)
#ifndef DCHECK
#define DCHECK(condition) assert(condition)
......@@ -342,7 +342,6 @@ static platform::tracing::TraceConfig* CreateTraceConfigFromJSON(
} // namespace tracing
class ExternalOwningOneByteStringResource
: public String::ExternalOneByteStringResource {
public:
......@@ -680,10 +679,7 @@ class ModuleEmbedderData {
module_to_specifier_map;
};
enum {
kModuleEmbedderDataIndex,
kInspectorClientIndex
};
enum { kModuleEmbedderDataIndex, kInspectorClientIndex };
void InitializeModuleEmbedderData(Local<Context> context) {
context->SetAlignedPointerInEmbedderData(
......@@ -956,7 +952,6 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) {
data_->isolate_->GetEnteredOrMicrotaskContext());
}
PerIsolateData::RealmScope::~RealmScope() {
// Drop realms to avoid keeping them alive. We don't dispose the
// module embedder data for the first realm here, but instead do
......@@ -970,7 +965,6 @@ PerIsolateData::RealmScope::~RealmScope() {
delete[] data_->realms_;
}
int PerIsolateData::RealmFind(Local<Context> context) {
for (int i = 0; i < realm_count_; ++i) {
if (realms_[i] == context) return i;
......@@ -978,10 +972,8 @@ int PerIsolateData::RealmFind(Local<Context> context) {
return -1;
}
int PerIsolateData::RealmIndexOrThrow(
const v8::FunctionCallbackInfo<v8::Value>& args,
int arg_offset) {
const v8::FunctionCallbackInfo<v8::Value>& args, int arg_offset) {
if (args.Length() < arg_offset || !args[arg_offset]->IsNumber()) {
Throw(args.GetIsolate(), "Invalid argument");
return -1;
......@@ -996,7 +988,6 @@ int PerIsolateData::RealmIndexOrThrow(
return index;
}
// performance.now() returns a time stamp as double, measured in milliseconds.
// When FLAG_verify_predictable mode is enabled it returns result of
// v8::Platform::MonotonicallyIncreasingTime().
......@@ -1010,7 +1001,6 @@ void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
// Realm.current() returns the index of the currently active realm.
void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
......@@ -1020,7 +1010,6 @@ void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(index);
}
// Realm.owner(o) returns the index of the realm that created o.
void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
......@@ -1037,7 +1026,6 @@ void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(index);
}
// Realm.global(i) returns the global object of realm i.
// (Note that properties of global objects cannot be read/written cross-realm.)
void Shell::RealmGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
......@@ -1155,15 +1143,14 @@ void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
PerIsolateData* data = PerIsolateData::Get(isolate);
int index = data->RealmIndexOrThrow(args, 0);
if (index == -1) return;
if (index == 0 ||
index == data->realm_current_ || index == data->realm_switch_) {
if (index == 0 || index == data->realm_current_ ||
index == data->realm_switch_) {
Throw(args.GetIsolate(), "Invalid realm index");
return;
}
DisposeRealm(args, index);
}
// Realm.switch(i) switches to the realm i for consecutive interactive inputs.
void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
......@@ -1173,7 +1160,6 @@ void Shell::RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) {
data->realm_switch_ = index;
}
// Realm.eval(i, s) evaluates s in realm i and returns the result.
void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
......@@ -1206,7 +1192,6 @@ void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(result);
}
// Realm.shared is an accessor for a single shared value across realms.
void Shell::RealmSharedGet(Local<String> property,
const PropertyCallbackInfo<Value>& info) {
......@@ -1216,8 +1201,7 @@ void Shell::RealmSharedGet(Local<String> property,
info.GetReturnValue().Set(data->realm_shared_);
}
void Shell::RealmSharedSet(Local<String> property,
Local<Value> value,
void Shell::RealmSharedSet(Local<String> property, Local<Value> value,
const PropertyCallbackInfo<void>& info) {
Isolate* isolate = info.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
......@@ -1323,7 +1307,6 @@ void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(source);
}
Local<String> Shell::ReadFromStdin(Isolate* isolate) {
static const int kBufferSize = 256;
char buffer[kBufferSize];
......@@ -1340,13 +1323,13 @@ Local<String> Shell::ReadFromStdin(Isolate* isolate) {
length = static_cast<int>(strlen(buffer));
if (length == 0) {
return accumulator;
} else if (buffer[length-1] != '\n') {
} else if (buffer[length - 1] != '\n') {
accumulator = String::Concat(
isolate, accumulator,
String::NewFromUtf8(isolate, buffer, NewStringType::kNormal, length)
.ToLocalChecked());
} else if (length > 1 && buffer[length-2] == '\\') {
buffer[length-2] = '\n';
} else if (length > 1 && buffer[length - 2] == '\\') {
buffer[length - 2] = '\n';
accumulator =
String::Concat(isolate, accumulator,
String::NewFromUtf8(isolate, buffer,
......@@ -1362,7 +1345,6 @@ Local<String> Shell::ReadFromStdin(Isolate* isolate) {
}
}
void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope(args.GetIsolate());
......@@ -1472,7 +1454,6 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);
......@@ -1497,7 +1478,6 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);
......@@ -1515,7 +1495,6 @@ void Shell::WorkerGetMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);
......@@ -1527,7 +1506,6 @@ void Shell::WorkerTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) {
worker->Terminate();
}
void Shell::QuitOnce(v8::FunctionCallbackInfo<v8::Value>* args) {
int exit_code = (*args)[0]
->Int32Value(args->GetIsolate()->GetCurrentContext())
......@@ -1538,7 +1516,6 @@ void Shell::QuitOnce(v8::FunctionCallbackInfo<v8::Value>* args) {
base::OS::ExitProcess(exit_code);
}
void Shell::Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
base::CallOnce(&quit_once_, &QuitOnce,
const_cast<v8::FunctionCallbackInfo<v8::Value>*>(&args));
......@@ -1553,12 +1530,12 @@ void Shell::NotifyDone(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
void Shell::Version(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(
String::NewFromUtf8(args.GetIsolate(), V8::GetVersion(),
NewStringType::kNormal).ToLocalChecked());
args.GetReturnValue().Set(String::NewFromUtf8(args.GetIsolate(),
V8::GetVersion(),
NewStringType::kNormal)
.ToLocalChecked());
}
void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
HandleScope handle_scope(isolate);
Local<Context> context = isolate->GetCurrentContext();
......@@ -1621,7 +1598,6 @@ void Shell::ReportException(Isolate* isolate, v8::TryCatch* try_catch) {
if (enter_context) context->Exit();
}
int32_t* Counter::Bind(const char* name, bool is_histogram) {
int i;
for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
......@@ -1631,13 +1607,11 @@ int32_t* Counter::Bind(const char* name, bool is_histogram) {
return ptr();
}
void Counter::AddSample(int32_t sample) {
count_++;
sample_total_ += sample;
}
CounterCollection::CounterCollection() {
magic_number_ = 0xDEADFACE;
max_counters_ = kMaxCounters;
......@@ -1645,13 +1619,11 @@ CounterCollection::CounterCollection() {
counters_in_use_ = 0;
}
Counter* CounterCollection::GetNextCounter() {
if (counters_in_use_ == kMaxCounters) return nullptr;
return &counters_[counters_in_use_++];
}
void Shell::MapCounters(v8::Isolate* isolate, const char* name) {
counters_file_ = base::OS::MemoryMappedFile::create(
name, sizeof(CounterCollection), &local_counters_);
......@@ -1684,7 +1656,6 @@ Counter* Shell::GetCounter(const char* name, bool is_histogram) {
return counter;
}
int* Shell::LookupCounter(const char* name) {
Counter* counter = GetCounter(name, false);
......@@ -1695,15 +1666,11 @@ int* Shell::LookupCounter(const char* name) {
}
}
void* Shell::CreateHistogram(const char* name,
int min,
int max,
void* Shell::CreateHistogram(const char* name, int min, int max,
size_t buckets) {
return GetCounter(name, true);
}
void Shell::AddHistogramSample(void* histogram, int sample) {
Counter* counter = reinterpret_cast<Counter*>(histogram);
counter->AddSample(sample);
......@@ -1734,7 +1701,6 @@ Local<String> Shell::Stringify(Isolate* isolate, Local<Value> value) {
return result.ToLocalChecked().As<String>();
}
Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
global_template->Set(
......@@ -1981,7 +1947,6 @@ void Shell::Initialize(Isolate* isolate) {
v8::Isolate::kMessageLog);
}
Local<Context> Shell::CreateEvaluationContext(Isolate* isolate) {
// This needs to be a critical section since this is not thread-safe
base::MutexGuard lock_guard(context_mutex_.Pointer());
......@@ -2176,7 +2141,6 @@ void Shell::OnExit(v8::Isolate* isolate) {
delete counter_map_;
}
static FILE* FOpen(const char* path, const char* mode) {
#if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64))
FILE* result;
......@@ -2224,14 +2188,12 @@ static char* ReadChars(const char* name, int* size_out) {
return chars;
}
struct DataAndPersistent {
uint8_t* data;
int byte_length;
Global<ArrayBuffer> handle;
};
static void ReadBufferWeakCallback(
const v8::WeakCallbackInfo<DataAndPersistent>& data) {
int byte_length = data.GetParameter()->byte_length;
......@@ -2243,7 +2205,6 @@ static void ReadBufferWeakCallback(
delete data.GetParameter();
}
void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
static_assert(sizeof(char) == sizeof(uint8_t),
"char and uint8_t should both have 1 byte");
......@@ -2293,7 +2254,6 @@ Local<String> Shell::ReadFile(Isolate* isolate, const char* name) {
return result;
}
void Shell::RunShell(Isolate* isolate) {
HandleScope outer_scope(isolate);
v8::Local<v8::Context> context =
......@@ -2576,7 +2536,6 @@ void SourceGroup::ExecuteInThread() {
isolate->Dispose();
}
void SourceGroup::StartExecuteInThread() {
if (thread_ == nullptr) {
thread_ = new IsolateThread(this);
......@@ -2585,13 +2544,11 @@ void SourceGroup::StartExecuteInThread() {
next_semaphore_.Signal();
}
void SourceGroup::WaitForThread() {
if (thread_ == nullptr) return;
done_semaphore_.Wait();
}
void SourceGroup::JoinThread() {
if (thread_ == nullptr) return;
thread_->Join();
......@@ -2618,13 +2575,11 @@ bool SerializationDataQueue::Dequeue(
return true;
}
bool SerializationDataQueue::IsEmpty() {
base::MutexGuard lock_guard(&mutex_);
return data_.empty();
}
void SerializationDataQueue::Clear() {
base::MutexGuard lock_guard(&mutex_);
data_.clear();
......@@ -2646,7 +2601,6 @@ Worker::~Worker() {
out_queue_.Clear();
}
void Worker::StartExecuteInThread(const char* script) {
running_ = true;
script_ = i::StrDup(script);
......@@ -2670,7 +2624,6 @@ std::unique_ptr<SerializationData> Worker::GetMessage() {
return result;
}
void Worker::Terminate() {
base::Relaxed_Store(&running_, false);
// Post nullptr to wake the Worker thread message loop, and tell it to stop
......@@ -2678,13 +2631,11 @@ void Worker::Terminate() {
PostMessage(nullptr);
}
void Worker::WaitForThread() {
Terminate();
thread_->Join();
}
void Worker::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
......@@ -2711,12 +2662,15 @@ void Worker::ExecuteInThread() {
FunctionTemplate::New(isolate, PostMessageOut, this_value);
Local<Function> postmessage_fun;
if (postmessage_fun_template->GetFunction(context)
.ToLocal(&postmessage_fun)) {
global->Set(context, String::NewFromUtf8(isolate, "postMessage",
NewStringType::kNormal)
.ToLocalChecked(),
postmessage_fun).FromJust();
if (postmessage_fun_template->GetFunction(context).ToLocal(
&postmessage_fun)) {
global
->Set(context,
String::NewFromUtf8(isolate, "postMessage",
NewStringType::kNormal)
.ToLocalChecked(),
postmessage_fun)
.FromJust();
}
// First run the script
......@@ -2731,9 +2685,11 @@ void Worker::ExecuteInThread() {
Shell::kReportExceptions, Shell::kProcessMessageQueue)) {
// Get the message handler
Local<Value> onmessage =
global->Get(context, String::NewFromUtf8(isolate, "onmessage",
NewStringType::kNormal)
.ToLocalChecked()).ToLocalChecked();
global
->Get(context, String::NewFromUtf8(isolate, "onmessage",
NewStringType::kNormal)
.ToLocalChecked())
.ToLocalChecked();
if (onmessage->IsFunction()) {
Local<Function> onmessage_fun = Local<Function>::Cast(onmessage);
// Now wait for messages
......@@ -2771,7 +2727,6 @@ void Worker::ExecuteInThread() {
out_semaphore_.Signal();
}
void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
HandleScope handle_scope(isolate);
......@@ -3018,7 +2973,6 @@ int Shell::RunMain(Isolate* isolate, int argc, char* argv[], bool last_run) {
return success == Shell::options.expected_to_throw ? 1 : 0;
}
void Shell::CollectGarbage(Isolate* isolate) {
if (options.send_idle_notification) {
const double kLongIdlePauseInSeconds = 1.0;
......@@ -3345,7 +3299,6 @@ MaybeLocal<Value> Shell::DeserializeValue(
return deserializer.ReadValue(context);
}
void Shell::CleanupWorkers() {
// Make a copy of workers_, because we don't want to call Worker::Terminate
// while holding the workers_mutex_ lock. Otherwise, if a worker is about to
......@@ -3492,9 +3445,8 @@ int Shell::Main(int argc, char* argv[]) {
}
if (options.stress_opt || options.stress_deopt) {
Testing::SetStressRunType(options.stress_opt
? Testing::kStressTypeOpt
: Testing::kStressTypeDeopt);
Testing::SetStressRunType(options.stress_opt ? Testing::kStressTypeOpt
: Testing::kStressTypeDeopt);
options.stress_runs = Testing::GetStressRuns();
for (int i = 0; i < options.stress_runs && result == 0; i++) {
printf("============ Stress %d/%d ============\n", i + 1,
......@@ -3582,11 +3534,8 @@ int Shell::Main(int argc, char* argv[]) {
} // namespace v8
#ifndef GOOGLE3
int main(int argc, char* argv[]) {
return v8::Shell::Main(argc, argv);
}
int main(int argc, char* argv[]) { return v8::Shell::Main(argc, argv); }
#endif
#undef CHECK
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_D8_H_
#define V8_D8_H_
#ifndef V8_D8_D8_H_
#define V8_D8_D8_H_
#include <iterator>
#include <map>
......@@ -14,17 +14,14 @@
#include <vector>
#include "src/allocation.h"
#include "src/async-hooks-wrapper.h"
#include "src/base/once.h"
#include "src/base/platform/time.h"
#include "src/d8/async-hooks-wrapper.h"
#include "src/string-hasher.h"
#include "src/utils.h"
#include "src/base/once.h"
namespace v8 {
// A single counter in a counter collection.
class Counter {
public:
......@@ -35,6 +32,7 @@ class Counter {
int32_t sample_total() { return sample_total_; }
bool is_histogram() { return is_histogram_; }
void AddSample(int32_t sample);
private:
int32_t count_;
int32_t sample_total_;
......@@ -42,7 +40,6 @@ class Counter {
uint8_t name_[kMaxNameSize];
};
// A set of counters and associated information. An instance of this
// class is stored directly in the memory-mapped counters file if
// the --map-counters options is used
......@@ -50,6 +47,7 @@ class CounterCollection {
public:
CounterCollection();
Counter* GetNextCounter();
private:
static const unsigned kMaxCounters = 512;
uint32_t magic_number_;
......@@ -195,7 +193,6 @@ class SerializationData {
DISALLOW_COPY_AND_ASSIGN(SerializationData);
};
class SerializationDataQueue {
public:
void Enqueue(std::unique_ptr<SerializationData> data);
......@@ -208,7 +205,6 @@ class SerializationDataQueue {
std::vector<std::unique_ptr<SerializationData>> data_;
};
class Worker {
public:
Worker();
......@@ -339,9 +335,7 @@ class ShellOptions {
disable_in_process_stack_traces(false),
read_from_tcp_port(-1) {}
~ShellOptions() {
delete[] isolate_sources;
}
~ShellOptions() { delete[] isolate_sources; }
bool send_idle_notification;
bool invoke_weak_callbacks;
......@@ -412,9 +406,7 @@ class Shell : public i::AllStatic {
Isolate* isolate, std::unique_ptr<SerializationData> data);
static void CleanupWorkers();
static int* LookupCounter(const char* name);
static void* CreateHistogram(const char* name,
int min,
int max,
static void* CreateHistogram(const char* name, int min, int max,
size_t buckets);
static void AddHistogramSample(void* histogram, int sample);
static void MapCounters(v8::Isolate* isolate, const char* name);
......@@ -434,10 +426,9 @@ class Shell : public i::AllStatic {
static void RealmSwitch(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args);
static void RealmSharedGet(Local<String> property,
const PropertyCallbackInfo<Value>& info);
static void RealmSharedSet(Local<String> property,
Local<Value> value,
const PropertyCallbackInfo<void>& info);
const PropertyCallbackInfo<Value>& info);
static void RealmSharedSet(Local<String> property, Local<Value> value,
const PropertyCallbackInfo<void>& info);
static void AsyncHooksCreateHook(
const v8::FunctionCallbackInfo<v8::Value>& args);
......@@ -580,8 +571,6 @@ class Shell : public i::AllStatic {
cached_code_map_;
};
} // namespace v8
#endif // V8_D8_H_
#endif // V8_D8_D8_H_
......@@ -49,7 +49,7 @@ _v8_flag() {
| sed -ne 's/^DEFINE-[^(]*(\([^,]*\).*/--\1/p'; \
echo "$defines" \
| sed -ne 's/^DEFINE-BOOL(\([^,]*\).*/--no\1/p'; \
cat $v8_source/src/d8.cc \
cat $v8_source/src/d8/d8.cc \
| grep "strcmp(argv\[i\]" \
| sed -ne 's/^[^"]*"--\([^"]*\)".*/--\1/p')
COMPREPLY=($(compgen -W "$targets" -- "$cur"))
......
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