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