[api] Add v8::Isolate::ThrowError helper
Add a ThrowError helper to encourage throwing full Error objects instead of just v8::Strings. Bug: v8:11195 Change-Id: I15d75b1d39b817de3b9026a836b57a70d7c16a28 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2811738 Commit-Queue: Camillo Bruni <cbruni@chromium.org> Reviewed-by: Dan Elphick <delphick@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/master@{#73958}
This commit is contained in:
parent
e43e1dcd17
commit
d435eaa5e4
11
include/v8.h
11
include/v8.h
@ -8872,6 +8872,17 @@ class V8_EXPORT Isolate {
|
|||||||
*/
|
*/
|
||||||
Local<Context> GetIncumbentContext();
|
Local<Context> GetIncumbentContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules a v8::Exception::Error with the given message.
|
||||||
|
* See ThrowException for more details. Templatized to provide compile-time
|
||||||
|
* errors in case of too long strings (see v8::String::NewFromUtf8Literal).
|
||||||
|
*/
|
||||||
|
template <int N>
|
||||||
|
Local<Value> ThrowError(const char (&message)[N]) {
|
||||||
|
return ThrowError(String::NewFromUtf8Literal(this, message));
|
||||||
|
}
|
||||||
|
Local<Value> ThrowError(Local<String> message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules an exception to be thrown when returning to JavaScript. When an
|
* Schedules an exception to be thrown when returning to JavaScript. When an
|
||||||
* exception has been scheduled it is illegal to invoke any JavaScript
|
* exception has been scheduled it is illegal to invoke any JavaScript
|
||||||
|
@ -147,20 +147,17 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
// the argument into a JavaScript string.
|
// the argument into a JavaScript string.
|
||||||
void Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
void Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
if (args.Length() != 1) {
|
if (args.Length() != 1) {
|
||||||
args.GetIsolate()->ThrowException(
|
args.GetIsolate()->ThrowError("Bad parameters");
|
||||||
v8::String::NewFromUtf8Literal(args.GetIsolate(), "Bad parameters"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v8::String::Utf8Value file(args.GetIsolate(), args[0]);
|
v8::String::Utf8Value file(args.GetIsolate(), args[0]);
|
||||||
if (*file == NULL) {
|
if (*file == NULL) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
args.GetIsolate(), "Error loading file"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v8::Local<v8::String> source;
|
v8::Local<v8::String> source;
|
||||||
if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
|
if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
args.GetIsolate(), "Error loading file"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,19 +172,16 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
v8::HandleScope handle_scope(args.GetIsolate());
|
v8::HandleScope handle_scope(args.GetIsolate());
|
||||||
v8::String::Utf8Value file(args.GetIsolate(), args[i]);
|
v8::String::Utf8Value file(args.GetIsolate(), args[i]);
|
||||||
if (*file == NULL) {
|
if (*file == NULL) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
args.GetIsolate(), "Error loading file"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
v8::Local<v8::String> source;
|
v8::Local<v8::String> source;
|
||||||
if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
|
if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
args.GetIsolate(), "Error loading file"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!ExecuteString(args.GetIsolate(), source, args[i], false, false)) {
|
if (!ExecuteString(args.GetIsolate(), source, args[i], false, false)) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Error executing file");
|
||||||
args.GetIsolate(), "Error executing file"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8012,6 +8012,10 @@ v8::Local<v8::Context> Isolate::GetIncumbentContext() {
|
|||||||
return Utils::ToLocal(context);
|
return Utils::ToLocal(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<Value> Isolate::ThrowError(v8::Local<v8::String> message) {
|
||||||
|
return ThrowException(v8::Exception::Error(message));
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) {
|
v8::Local<Value> Isolate::ThrowException(v8::Local<v8::Value> value) {
|
||||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
||||||
ENTER_V8_DO_NOT_USE(isolate);
|
ENTER_V8_DO_NOT_USE(isolate);
|
||||||
|
@ -47,8 +47,7 @@ static AsyncHooksWrap* UnwrapHook(
|
|||||||
AsyncHooks* hooks = PerIsolateData::Get(isolate)->GetAsyncHooks();
|
AsyncHooks* hooks = PerIsolateData::Get(isolate)->GetAsyncHooks();
|
||||||
|
|
||||||
if (!hooks->async_hook_ctor.Get(isolate)->HasInstance(hook)) {
|
if (!hooks->async_hook_ctor.Get(isolate)->HasInstance(hook)) {
|
||||||
isolate->ThrowException(String::NewFromUtf8Literal(
|
isolate->ThrowError("Invalid 'this' passed instead of AsyncHooks instance");
|
||||||
isolate, "Invalid 'this' passed instead of AsyncHooks instance"));
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +86,7 @@ Local<Object> AsyncHooks::CreateHook(
|
|||||||
Local<Context> currentContext = isolate->GetCurrentContext();
|
Local<Context> currentContext = isolate->GetCurrentContext();
|
||||||
|
|
||||||
if (args.Length() != 1 || !args[0]->IsObject()) {
|
if (args.Length() != 1 || !args[0]->IsObject()) {
|
||||||
isolate->ThrowException(String::NewFromUtf8Literal(
|
isolate->ThrowError("Invalid arguments passed to createHook");
|
||||||
isolate, "Invalid arguments passed to createHook"));
|
|
||||||
return Local<Object>();
|
return Local<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ void D8Console::Assert(const debug::ConsoleCallArguments& args,
|
|||||||
// false-ish.
|
// false-ish.
|
||||||
if (args.Length() > 0 && args[0]->BooleanValue(isolate_)) return;
|
if (args.Length() > 0 && args[0]->BooleanValue(isolate_)) return;
|
||||||
WriteToFile("console.assert", stdout, isolate_, args);
|
WriteToFile("console.assert", stdout, isolate_, args);
|
||||||
isolate_->ThrowException(v8::Exception::Error(
|
isolate_->ThrowError("console.assert failed");
|
||||||
v8::String::NewFromUtf8Literal(isolate_, "console.assert failed")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void D8Console::Log(const debug::ConsoleCallArguments& args,
|
void D8Console::Log(const debug::ConsoleCallArguments& args,
|
||||||
|
@ -159,8 +159,8 @@ class ExecArgs {
|
|||||||
bool Init(Isolate* isolate, Local<Value> arg0, Local<Array> command_args) {
|
bool Init(Isolate* isolate, Local<Value> arg0, Local<Array> command_args) {
|
||||||
String::Utf8Value prog(isolate, arg0);
|
String::Utf8Value prog(isolate, arg0);
|
||||||
if (*prog == nullptr) {
|
if (*prog == nullptr) {
|
||||||
isolate->ThrowException(String::NewFromUtf8Literal(
|
isolate->ThrowError(
|
||||||
isolate, "os.system(): String conversion of program name failed"));
|
"os.system(): String conversion of program name failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int len = prog.length() + 3;
|
int len = prog.length() + 3;
|
||||||
@ -176,8 +176,8 @@ class ExecArgs {
|
|||||||
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.
|
||||||
isolate->ThrowException(String::NewFromUtf8Literal(
|
isolate->ThrowError(
|
||||||
isolate, "os.system(): String conversion of argument failed."));
|
"os.system(): String conversion of argument failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int len = utf8_arg.length() + 1;
|
int len = utf8_arg.length() + 1;
|
||||||
@ -214,8 +214,7 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
|
|||||||
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
||||||
.FromJust();
|
.FromJust();
|
||||||
} else {
|
} else {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("system: Argument 4 must be a number");
|
||||||
args.GetIsolate(), "system: Argument 4 must be a number"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,14 +224,19 @@ static bool GetTimeouts(const v8::FunctionCallbackInfo<v8::Value>& args,
|
|||||||
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
||||||
.FromJust();
|
.FromJust();
|
||||||
} else {
|
} else {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("system: Argument 3 must be a number");
|
||||||
args.GetIsolate(), "system: Argument 3 must be a number"));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
v8::Local<v8::String> v8_strerror(v8::Isolate* isolate, int err) {
|
||||||
|
return v8::String::NewFromUtf8(isolate, strerror(err)).ToLocalChecked();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
static const int kReadFD = 0;
|
static const int kReadFD = 0;
|
||||||
static const int kWriteFD = 1;
|
static const int kWriteFD = 1;
|
||||||
|
|
||||||
@ -267,8 +271,7 @@ static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
|
|||||||
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
|
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
|
||||||
} while (bytes_read == -1 && errno == EINTR);
|
} while (bytes_read == -1 && errno == EINTR);
|
||||||
if (bytes_read != 0) {
|
if (bytes_read != 0) {
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(v8_strerror(isolate, err));
|
||||||
String::NewFromUtf8(isolate, strerror(err)).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -286,8 +289,7 @@ static Local<Value> GetStdout(Isolate* isolate, int child_fd,
|
|||||||
char buffer[kStdoutReadBufferSize];
|
char buffer[kStdoutReadBufferSize];
|
||||||
|
|
||||||
if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) {
|
if (fcntl(child_fd, F_SETFL, O_NONBLOCK) != 0) {
|
||||||
return isolate->ThrowException(
|
return isolate->ThrowError(v8_strerror(isolate, errno));
|
||||||
String::NewFromUtf8(isolate, strerror(errno)).ToLocalChecked());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes_read;
|
int bytes_read;
|
||||||
@ -298,8 +300,7 @@ static Local<Value> GetStdout(Isolate* isolate, int child_fd,
|
|||||||
if (errno == EAGAIN) {
|
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))) {
|
(TimeIsOut(start_time, total_timeout))) {
|
||||||
return isolate->ThrowException(String::NewFromUtf8Literal(
|
return isolate->ThrowError("Timed out waiting for output");
|
||||||
isolate, "Timed out waiting for output"));
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else if (errno == EINTR) {
|
} else if (errno == EINTR) {
|
||||||
@ -357,8 +358,7 @@ static bool WaitForChild(Isolate* isolate, int pid,
|
|||||||
if (useconds < 1000000) useconds <<= 1;
|
if (useconds < 1000000) useconds <<= 1;
|
||||||
if ((read_timeout != -1 && useconds / 1000 > read_timeout) ||
|
if ((read_timeout != -1 && useconds / 1000 > read_timeout) ||
|
||||||
(TimeIsOut(start_time, total_timeout))) {
|
(TimeIsOut(start_time, total_timeout))) {
|
||||||
isolate->ThrowException(String::NewFromUtf8Literal(
|
isolate->ThrowError("Timed out waiting for process to terminate");
|
||||||
isolate, "Timed out waiting for process to terminate"));
|
|
||||||
kill(pid, SIGINT);
|
kill(pid, SIGINT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -367,16 +367,14 @@ static bool WaitForChild(Isolate* isolate, int pid,
|
|||||||
char message[999];
|
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);
|
child_info.si_status);
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(message);
|
||||||
String::NewFromUtf8(isolate, message).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
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, sizeof(message), "Child exited with status %d",
|
snprintf(message, sizeof(message), "Child exited with status %d",
|
||||||
child_info.si_status);
|
child_info.si_status);
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(message);
|
||||||
String::NewFromUtf8(isolate, message).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,8 +387,7 @@ static bool WaitForChild(Isolate* isolate, int pid,
|
|||||||
char message[999];
|
char message[999];
|
||||||
snprintf(message, sizeof(message), "Child killed by signal %d",
|
snprintf(message, sizeof(message), "Child killed by signal %d",
|
||||||
WTERMSIG(child_status));
|
WTERMSIG(child_status));
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(message);
|
||||||
String::NewFromUtf8(isolate, message).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (WEXITSTATUS(child_status) != 0) {
|
if (WEXITSTATUS(child_status) != 0) {
|
||||||
@ -398,8 +395,7 @@ static bool WaitForChild(Isolate* isolate, int pid,
|
|||||||
int exit_status = WEXITSTATUS(child_status);
|
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);
|
exit_status);
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(message);
|
||||||
String::NewFromUtf8(isolate, message).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,8 +415,7 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
Local<Array> command_args;
|
Local<Array> command_args;
|
||||||
if (args.Length() > 1) {
|
if (args.Length() > 1) {
|
||||||
if (!args[1]->IsArray()) {
|
if (!args[1]->IsArray()) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("system: Argument 2 must be an array");
|
||||||
args.GetIsolate(), "system: Argument 2 must be an array"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
command_args = args[1].As<Array>();
|
command_args = args[1].As<Array>();
|
||||||
@ -428,13 +423,11 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
command_args = Array::New(args.GetIsolate(), 0);
|
command_args = Array::New(args.GetIsolate(), 0);
|
||||||
}
|
}
|
||||||
if (command_args->Length() > ExecArgs::kMaxArgs) {
|
if (command_args->Length() > ExecArgs::kMaxArgs) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Too many arguments to system()");
|
||||||
args.GetIsolate(), "Too many arguments to system()"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args.Length() < 1) {
|
if (args.Length() < 1) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("Too few arguments to system()");
|
||||||
args.GetIsolate(), "Too few arguments to system()"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,13 +442,11 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
int stdout_fds[2];
|
int stdout_fds[2];
|
||||||
|
|
||||||
if (pipe(exec_error_fds) != 0) {
|
if (pipe(exec_error_fds) != 0) {
|
||||||
args.GetIsolate()->ThrowException(
|
args.GetIsolate()->ThrowError("pipe syscall failed.");
|
||||||
String::NewFromUtf8Literal(args.GetIsolate(), "pipe syscall failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pipe(stdout_fds) != 0) {
|
if (pipe(stdout_fds) != 0) {
|
||||||
args.GetIsolate()->ThrowException(
|
args.GetIsolate()->ThrowError("pipe syscall failed.");
|
||||||
String::NewFromUtf8Literal(args.GetIsolate(), "pipe syscall failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,29 +484,24 @@ void Shell::System(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
|
|
||||||
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) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("chdir() takes one argument");
|
||||||
args.GetIsolate(), "chdir() takes one argument"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String::Utf8Value directory(args.GetIsolate(), args[0]);
|
String::Utf8Value directory(args.GetIsolate(), args[0]);
|
||||||
if (*directory == nullptr) {
|
if (*directory == nullptr) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"os.chdir(): String conversion of argument failed.");
|
||||||
"os.chdir(): String conversion of argument failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (chdir(*directory) != 0) {
|
if (chdir(*directory) != 0) {
|
||||||
args.GetIsolate()->ThrowException(
|
args.GetIsolate()->ThrowError(v8_strerror(args.GetIsolate(), errno));
|
||||||
String::NewFromUtf8(args.GetIsolate(), strerror(errno))
|
|
||||||
.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) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("umask() takes one argument");
|
||||||
args.GetIsolate(), "umask() takes one argument"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args[0]->IsNumber()) {
|
if (args[0]->IsNumber()) {
|
||||||
@ -524,8 +510,7 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
args.GetReturnValue().Set(previous);
|
args.GetReturnValue().Set(previous);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("umask() argument must be numeric");
|
||||||
args.GetIsolate(), "umask() argument must be numeric"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -534,13 +519,11 @@ 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);
|
||||||
if (stat_result != 0) {
|
if (stat_result != 0) {
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(v8_strerror(isolate, errno));
|
||||||
String::NewFromUtf8(isolate, strerror(errno)).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((stat_buf.st_mode & S_IFDIR) != 0) return true;
|
if ((stat_buf.st_mode & S_IFDIR) != 0) return true;
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(v8_strerror(isolate, EEXIST));
|
||||||
String::NewFromUtf8(isolate, strerror(EEXIST)).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,8 +537,7 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
|
|||||||
} else if (errno == ENOENT) { // Intermediate path element is missing.
|
} else if (errno == ENOENT) { // Intermediate path element is missing.
|
||||||
char* last_slash = strrchr(directory, '/');
|
char* last_slash = strrchr(directory, '/');
|
||||||
if (last_slash == nullptr) {
|
if (last_slash == nullptr) {
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(v8_strerror(isolate, errno));
|
||||||
String::NewFromUtf8(isolate, strerror(errno)).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*last_slash = 0;
|
*last_slash = 0;
|
||||||
@ -566,12 +548,10 @@ static bool mkdirp(Isolate* isolate, char* directory, mode_t mask) {
|
|||||||
if (errno == EEXIST) {
|
if (errno == EEXIST) {
|
||||||
return CheckItsADirectory(isolate, directory);
|
return CheckItsADirectory(isolate, directory);
|
||||||
}
|
}
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(v8_strerror(isolate, errno));
|
||||||
String::NewFromUtf8(isolate, strerror(errno)).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
isolate->ThrowException(
|
isolate->ThrowError(v8_strerror(isolate, errno));
|
||||||
String::NewFromUtf8(isolate, strerror(errno)).ToLocalChecked());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -584,20 +564,17 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
||||||
.FromJust();
|
.FromJust();
|
||||||
} else {
|
} else {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("mkdirp() second argument must be numeric");
|
||||||
args.GetIsolate(), "mkdirp() second argument must be numeric"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (args.Length() != 1) {
|
} else if (args.Length() != 1) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("mkdirp() takes one or two arguments");
|
||||||
args.GetIsolate(), "mkdirp() takes one or two arguments"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String::Utf8Value directory(args.GetIsolate(), args[0]);
|
String::Utf8Value directory(args.GetIsolate(), args[0]);
|
||||||
if (*directory == nullptr) {
|
if (*directory == nullptr) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"os.mkdirp(): String conversion of argument failed.");
|
||||||
"os.mkdirp(): String conversion of argument failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mkdirp(args.GetIsolate(), *directory, mask);
|
mkdirp(args.GetIsolate(), *directory, mask);
|
||||||
@ -605,15 +582,13 @@ void Shell::MakeDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
|
|
||||||
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) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("rmdir() takes one or two arguments");
|
||||||
args.GetIsolate(), "rmdir() takes one or two arguments"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String::Utf8Value directory(args.GetIsolate(), args[0]);
|
String::Utf8Value directory(args.GetIsolate(), args[0]);
|
||||||
if (*directory == nullptr) {
|
if (*directory == nullptr) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"os.rmdir(): String conversion of argument failed.");
|
||||||
"os.rmdir(): String conversion of argument failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rmdir(*directory);
|
rmdir(*directory);
|
||||||
@ -621,22 +596,19 @@ void Shell::RemoveDirectory(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
|
|
||||||
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) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("setenv() takes two arguments");
|
||||||
args.GetIsolate(), "setenv() takes two arguments"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String::Utf8Value var(args.GetIsolate(), args[0]);
|
String::Utf8Value var(args.GetIsolate(), args[0]);
|
||||||
String::Utf8Value value(args.GetIsolate(), args[1]);
|
String::Utf8Value value(args.GetIsolate(), args[1]);
|
||||||
if (*var == nullptr) {
|
if (*var == nullptr) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"os.setenv(): String conversion of variable name failed.");
|
||||||
"os.setenv(): String conversion of variable name failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (*value == nullptr) {
|
if (*value == nullptr) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"os.setenv(): String conversion of variable contents failed.");
|
||||||
"os.setenv(): String conversion of variable contents failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setenv(*var, *value, 1);
|
setenv(*var, *value, 1);
|
||||||
@ -644,15 +616,13 @@ void Shell::SetEnvironment(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
|
|
||||||
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) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("unsetenv() takes one argument");
|
||||||
args.GetIsolate(), "unsetenv() takes one argument"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String::Utf8Value var(args.GetIsolate(), args[0]);
|
String::Utf8Value var(args.GetIsolate(), args[0]);
|
||||||
if (*var == nullptr) {
|
if (*var == nullptr) {
|
||||||
args.GetIsolate()->ThrowException(String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"os.setenv(): String conversion of variable name failed.");
|
||||||
"os.setenv(): String conversion of variable name failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsetenv(*var);
|
unsetenv(*var);
|
||||||
|
@ -170,10 +170,8 @@ thread_local FastCApiObject kFastCApiObject;
|
|||||||
// TODO(mslekova): Rename the fast_c_api helper to FastCAPI.
|
// TODO(mslekova): Rename the fast_c_api helper to FastCAPI.
|
||||||
void CreateObject(const FunctionCallbackInfo<Value>& info) {
|
void CreateObject(const FunctionCallbackInfo<Value>& info) {
|
||||||
if (!info.IsConstructCall()) {
|
if (!info.IsConstructCall()) {
|
||||||
info.GetIsolate()->ThrowException(
|
info.GetIsolate()->ThrowError(
|
||||||
v8::Exception::Error(String::NewFromUtf8Literal(
|
"FastCAPI helper must be constructed with new.");
|
||||||
info.GetIsolate(),
|
|
||||||
"FastCAPI helper must be constructed with new.")));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Local<Object> api_object = info.Holder();
|
Local<Object> api_object = info.Holder();
|
||||||
|
110
src/d8/d8.cc
110
src/d8/d8.cc
@ -333,11 +333,6 @@ class MultiMappedAllocator : public ArrayBufferAllocatorBase {
|
|||||||
v8::Platform* g_default_platform;
|
v8::Platform* g_default_platform;
|
||||||
std::unique_ptr<v8::Platform> g_platform;
|
std::unique_ptr<v8::Platform> g_platform;
|
||||||
|
|
||||||
static Local<Value> Throw(Isolate* isolate, const char* message) {
|
|
||||||
return isolate->ThrowException(v8::Exception::Error(
|
|
||||||
String::NewFromUtf8(isolate, message).ToLocalChecked()));
|
|
||||||
}
|
|
||||||
|
|
||||||
static MaybeLocal<Value> TryGetValue(v8::Isolate* isolate,
|
static MaybeLocal<Value> TryGetValue(v8::Isolate* isolate,
|
||||||
Local<Context> context,
|
Local<Context> context,
|
||||||
Local<v8::Object> object,
|
Local<v8::Object> object,
|
||||||
@ -355,13 +350,13 @@ static Local<Value> GetValue(v8::Isolate* isolate, Local<Context> context,
|
|||||||
std::shared_ptr<Worker> GetWorkerFromInternalField(Isolate* isolate,
|
std::shared_ptr<Worker> GetWorkerFromInternalField(Isolate* isolate,
|
||||||
Local<Object> object) {
|
Local<Object> object) {
|
||||||
if (object->InternalFieldCount() != 1) {
|
if (object->InternalFieldCount() != 1) {
|
||||||
Throw(isolate, "this is not a Worker");
|
isolate->ThrowError("this is not a Worker");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
i::Handle<i::Object> handle = Utils::OpenHandle(*object->GetInternalField(0));
|
i::Handle<i::Object> handle = Utils::OpenHandle(*object->GetInternalField(0));
|
||||||
if (handle->IsSmi()) {
|
if (handle->IsSmi()) {
|
||||||
Throw(isolate, "Worker is defunct because main thread is terminating");
|
isolate->ThrowError("Worker is defunct because main thread is terminating");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto managed = i::Handle<i::Managed<Worker>>::cast(handle);
|
auto managed = i::Handle<i::Managed<Worker>>::cast(handle);
|
||||||
@ -728,7 +723,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
|
|||||||
if (options.web_snapshot_config) {
|
if (options.web_snapshot_config) {
|
||||||
std::vector<std::string> exports;
|
std::vector<std::string> exports;
|
||||||
if (!ReadLines(options.web_snapshot_config, exports)) {
|
if (!ReadLines(options.web_snapshot_config, exports)) {
|
||||||
Throw(isolate, "Web snapshots: unable to read config");
|
isolate->ThrowError("Web snapshots: unable to read config");
|
||||||
CHECK(try_catch.HasCaught());
|
CHECK(try_catch.HasCaught());
|
||||||
ReportException(isolate, &try_catch);
|
ReportException(isolate, &try_catch);
|
||||||
return false;
|
return false;
|
||||||
@ -965,7 +960,8 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Module> referrer,
|
|||||||
CHECK(specifier_it != d->module_to_specifier_map.end());
|
CHECK(specifier_it != d->module_to_specifier_map.end());
|
||||||
msg += "\n imported by " + specifier_it->second;
|
msg += "\n imported by " + specifier_it->second;
|
||||||
}
|
}
|
||||||
Throw(isolate, msg.c_str());
|
isolate->ThrowError(
|
||||||
|
v8::String::NewFromUtf8(isolate, msg.c_str()).ToLocalChecked());
|
||||||
return MaybeLocal<Module>();
|
return MaybeLocal<Module>();
|
||||||
}
|
}
|
||||||
ScriptOrigin origin(
|
ScriptOrigin origin(
|
||||||
@ -1024,7 +1020,7 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Module> referrer,
|
|||||||
context, import_assertions, true);
|
context, import_assertions, true);
|
||||||
|
|
||||||
if (request_module_type == ModuleType::kInvalid) {
|
if (request_module_type == ModuleType::kInvalid) {
|
||||||
Throw(isolate, "Invalid module type was asserted");
|
isolate->ThrowError("Invalid module type was asserted");
|
||||||
return MaybeLocal<Module>();
|
return MaybeLocal<Module>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1211,7 +1207,7 @@ void Shell::DoHostImportModuleDynamically(void* import_data) {
|
|||||||
try_catch.SetVerbose(true);
|
try_catch.SetVerbose(true);
|
||||||
|
|
||||||
if (module_type == ModuleType::kInvalid) {
|
if (module_type == ModuleType::kInvalid) {
|
||||||
Throw(isolate, "Invalid module type was asserted");
|
isolate->ThrowError("Invalid module type was asserted");
|
||||||
CHECK(try_catch.HasCaught());
|
CHECK(try_catch.HasCaught());
|
||||||
resolver->Reject(realm, try_catch.Exception()).ToChecked();
|
resolver->Reject(realm, try_catch.Exception()).ToChecked();
|
||||||
return;
|
return;
|
||||||
@ -1358,7 +1354,7 @@ bool Shell::ExecuteWebSnapshot(Isolate* isolate, const char* file_name) {
|
|||||||
std::unique_ptr<uint8_t[]> snapshot_data(
|
std::unique_ptr<uint8_t[]> snapshot_data(
|
||||||
reinterpret_cast<uint8_t*>(ReadChars(absolute_path.c_str(), &length)));
|
reinterpret_cast<uint8_t*>(ReadChars(absolute_path.c_str(), &length)));
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
Throw(isolate, "Error reading the web snapshot");
|
isolate->ThrowError("Error reading the web snapshot");
|
||||||
DCHECK(try_catch.HasCaught());
|
DCHECK(try_catch.HasCaught());
|
||||||
ReportException(isolate, &try_catch);
|
ReportException(isolate, &try_catch);
|
||||||
return false;
|
return false;
|
||||||
@ -1500,14 +1496,14 @@ int PerIsolateData::RealmFind(Local<Context> context) {
|
|||||||
int PerIsolateData::RealmIndexOrThrow(
|
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()) {
|
if (args.Length() < arg_offset || !args[arg_offset]->IsNumber()) {
|
||||||
Throw(args.GetIsolate(), "Invalid argument");
|
args.GetIsolate()->ThrowError("Invalid argument");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int index = args[arg_offset]
|
int index = args[arg_offset]
|
||||||
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
->Int32Value(args.GetIsolate()->GetCurrentContext())
|
||||||
.FromMaybe(-1);
|
.FromMaybe(-1);
|
||||||
if (index < 0 || index >= realm_count_ || realms_[index].IsEmpty()) {
|
if (index < 0 || index >= realm_count_ || realms_[index].IsEmpty()) {
|
||||||
Throw(args.GetIsolate(), "Invalid realm index");
|
args.GetIsolate()->ThrowError("Invalid realm index");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
@ -1565,7 +1561,7 @@ void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
Isolate* isolate = args.GetIsolate();
|
Isolate* isolate = args.GetIsolate();
|
||||||
PerIsolateData* data = PerIsolateData::Get(isolate);
|
PerIsolateData* data = PerIsolateData::Get(isolate);
|
||||||
if (args.Length() < 1 || !args[0]->IsObject()) {
|
if (args.Length() < 1 || !args[0]->IsObject()) {
|
||||||
Throw(args.GetIsolate(), "Invalid argument");
|
args.GetIsolate()->ThrowError("Invalid argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Local<Object> object =
|
Local<Object> object =
|
||||||
@ -1577,7 +1573,7 @@ void Shell::RealmOwner(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
}
|
}
|
||||||
Local<Context> creation_context;
|
Local<Context> creation_context;
|
||||||
if (!object->GetCreationContext().ToLocal(&creation_context)) {
|
if (!object->GetCreationContext().ToLocal(&creation_context)) {
|
||||||
Throw(args.GetIsolate(), "object doesn't have creation context");
|
args.GetIsolate()->ThrowError("object doesn't have creation context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int index = data->RealmFind(creation_context);
|
int index = data->RealmFind(creation_context);
|
||||||
@ -1661,7 +1657,7 @@ void Shell::RealmNavigate(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
if (index == 0 || index == data->realm_current_ ||
|
if (index == 0 || index == data->realm_current_ ||
|
||||||
index == data->realm_switch_) {
|
index == data->realm_switch_) {
|
||||||
Throw(args.GetIsolate(), "Invalid realm index");
|
args.GetIsolate()->ThrowError("Invalid realm index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1690,7 +1686,7 @@ void Shell::RealmDetachGlobal(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
if (index == 0 || index == data->realm_current_ ||
|
if (index == 0 || index == data->realm_current_ ||
|
||||||
index == data->realm_switch_) {
|
index == data->realm_switch_) {
|
||||||
Throw(args.GetIsolate(), "Invalid realm index");
|
args.GetIsolate()->ThrowError("Invalid realm index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1707,7 +1703,7 @@ void Shell::RealmDispose(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
if (index == 0 || index == data->realm_current_ ||
|
if (index == 0 || index == data->realm_current_ ||
|
||||||
index == data->realm_switch_) {
|
index == data->realm_switch_) {
|
||||||
Throw(args.GetIsolate(), "Invalid realm index");
|
args.GetIsolate()->ThrowError("Invalid realm index");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DisposeRealm(args, index);
|
DisposeRealm(args, index);
|
||||||
@ -1729,7 +1725,7 @@ void Shell::RealmEval(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
int index = data->RealmIndexOrThrow(args, 0);
|
int index = data->RealmIndexOrThrow(args, 0);
|
||||||
if (index == -1) return;
|
if (index == -1) return;
|
||||||
if (args.Length() < 2 || !args[1]->IsString()) {
|
if (args.Length() < 2 || !args[1]->IsString()) {
|
||||||
Throw(args.GetIsolate(), "Invalid argument");
|
args.GetIsolate()->ThrowError("Invalid argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ScriptOrigin origin(isolate,
|
ScriptOrigin origin(isolate,
|
||||||
@ -1780,18 +1776,18 @@ void Shell::LogGetAndStop(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
|
|
||||||
std::string file_name = i_isolate->logger()->file_name();
|
std::string file_name = i_isolate->logger()->file_name();
|
||||||
if (!i::Log::IsLoggingToTemporaryFile(file_name)) {
|
if (!i::Log::IsLoggingToTemporaryFile(file_name)) {
|
||||||
Throw(isolate, "Only capturing from temporary files is supported.");
|
isolate->ThrowError("Only capturing from temporary files is supported.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!i_isolate->logger()->is_logging()) {
|
if (!i_isolate->logger()->is_logging()) {
|
||||||
Throw(isolate, "Logging not enabled.");
|
isolate->ThrowError("Logging not enabled.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string raw_log;
|
std::string raw_log;
|
||||||
FILE* log_file = i_isolate->logger()->TearDownAndGetLogFile();
|
FILE* log_file = i_isolate->logger()->TearDownAndGetLogFile();
|
||||||
if (!log_file) {
|
if (!log_file) {
|
||||||
Throw(isolate, "Log file does not exist.");
|
isolate->ThrowError("Log file does not exist.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1800,7 +1796,7 @@ void Shell::LogGetAndStop(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
base::Fclose(log_file);
|
base::Fclose(log_file);
|
||||||
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
Throw(isolate, "Unable to read log file.");
|
isolate->ThrowError("Unable to read log file.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Local<String> result =
|
Local<String> result =
|
||||||
@ -1816,13 +1812,13 @@ void Shell::TestVerifySourcePositions(
|
|||||||
Isolate* isolate = args.GetIsolate();
|
Isolate* isolate = args.GetIsolate();
|
||||||
// Check if the argument is a valid function.
|
// Check if the argument is a valid function.
|
||||||
if (args.Length() != 1) {
|
if (args.Length() != 1) {
|
||||||
Throw(isolate, "Expected function as single argument.");
|
isolate->ThrowError("Expected function as single argument.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto arg_handle = Utils::OpenHandle(*args[0]);
|
auto arg_handle = Utils::OpenHandle(*args[0]);
|
||||||
if (!arg_handle->IsHeapObject() || !i::Handle<i::HeapObject>::cast(arg_handle)
|
if (!arg_handle->IsHeapObject() || !i::Handle<i::HeapObject>::cast(arg_handle)
|
||||||
->IsJSFunctionOrBoundFunction()) {
|
->IsJSFunctionOrBoundFunction()) {
|
||||||
Throw(isolate, "Expected function as single argument.");
|
isolate->ThrowError("Expected function as single argument.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1839,7 +1835,7 @@ void Shell::TestVerifySourcePositions(
|
|||||||
|
|
||||||
i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast(callable);
|
i::Handle<i::JSFunction> function = i::Handle<i::JSFunction>::cast(callable);
|
||||||
if (!function->shared().HasBytecodeArray()) {
|
if (!function->shared().HasBytecodeArray()) {
|
||||||
Throw(isolate, "Function has no BytecodeArray attached.");
|
isolate->ThrowError("Function has no BytecodeArray attached.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
i::Handle<i::BytecodeArray> bytecodes =
|
i::Handle<i::BytecodeArray> bytecodes =
|
||||||
@ -1865,7 +1861,7 @@ void Shell::TestVerifySourcePositions(
|
|||||||
if (has_baseline) {
|
if (has_baseline) {
|
||||||
if (offset_iterator->current_bytecode_offset() !=
|
if (offset_iterator->current_bytecode_offset() !=
|
||||||
bytecode_iterator.current_offset()) {
|
bytecode_iterator.current_offset()) {
|
||||||
Throw(isolate, "Baseline bytecode offset mismatch.");
|
isolate->ThrowError("Baseline bytecode offset mismatch.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check that we map every address to this bytecode correctly.
|
// Check that we map every address to this bytecode correctly.
|
||||||
@ -1877,7 +1873,8 @@ void Shell::TestVerifySourcePositions(
|
|||||||
pc_lookup.AdvanceToPCOffset(pc);
|
pc_lookup.AdvanceToPCOffset(pc);
|
||||||
if (pc_lookup.current_bytecode_offset() !=
|
if (pc_lookup.current_bytecode_offset() !=
|
||||||
bytecode_iterator.current_offset()) {
|
bytecode_iterator.current_offset()) {
|
||||||
Throw(isolate, "Baseline bytecode offset mismatch for PC lookup.");
|
isolate->ThrowError(
|
||||||
|
"Baseline bytecode offset mismatch for PC lookup.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1885,14 +1882,14 @@ void Shell::TestVerifySourcePositions(
|
|||||||
bytecode_iterator.Advance();
|
bytecode_iterator.Advance();
|
||||||
if (has_baseline && !bytecode_iterator.done()) {
|
if (has_baseline && !bytecode_iterator.done()) {
|
||||||
if (offset_iterator->done()) {
|
if (offset_iterator->done()) {
|
||||||
Throw(isolate, "Missing bytecode(s) in baseline offset mapping.");
|
isolate->ThrowError("Missing bytecode(s) in baseline offset mapping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
offset_iterator->Advance();
|
offset_iterator->Advance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (has_baseline && !offset_iterator->done()) {
|
if (has_baseline && !offset_iterator->done()) {
|
||||||
Throw(isolate, "Excess offsets in baseline offset mapping.");
|
isolate->ThrowError("Excess offsets in baseline offset mapping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1978,7 +1975,7 @@ void Shell::Write(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
String::Utf8Value file(args.GetIsolate(), args[0]);
|
String::Utf8Value file(args.GetIsolate(), args[0]);
|
||||||
if (*file == nullptr) {
|
if (*file == nullptr) {
|
||||||
Throw(args.GetIsolate(), "Error loading file");
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args.Length() == 2) {
|
if (args.Length() == 2) {
|
||||||
@ -1990,7 +1987,7 @@ void Shell::Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
}
|
}
|
||||||
Local<String> source = ReadFile(args.GetIsolate(), *file);
|
Local<String> source = ReadFile(args.GetIsolate(), *file);
|
||||||
if (source.IsEmpty()) {
|
if (source.IsEmpty()) {
|
||||||
Throw(args.GetIsolate(), "Error loading file");
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
args.GetReturnValue().Set(source);
|
args.GetReturnValue().Set(source);
|
||||||
@ -2038,12 +2035,12 @@ void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
HandleScope handle_scope(args.GetIsolate());
|
HandleScope handle_scope(args.GetIsolate());
|
||||||
String::Utf8Value file(args.GetIsolate(), args[i]);
|
String::Utf8Value file(args.GetIsolate(), args[i]);
|
||||||
if (*file == nullptr) {
|
if (*file == nullptr) {
|
||||||
Throw(args.GetIsolate(), "Error loading file");
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Local<String> source = ReadFile(args.GetIsolate(), *file);
|
Local<String> source = ReadFile(args.GetIsolate(), *file);
|
||||||
if (source.IsEmpty()) {
|
if (source.IsEmpty()) {
|
||||||
Throw(args.GetIsolate(), "Error loading file");
|
args.GetIsolate()->ThrowError("Error loading file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!ExecuteString(
|
if (!ExecuteString(
|
||||||
@ -2052,7 +2049,7 @@ void Shell::Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
kNoPrintResult,
|
kNoPrintResult,
|
||||||
options.quiet_load ? kNoReportExceptions : kReportExceptions,
|
options.quiet_load ? kNoReportExceptions : kReportExceptions,
|
||||||
kNoProcessMessageQueue)) {
|
kNoProcessMessageQueue)) {
|
||||||
Throw(args.GetIsolate(), "Error executing file");
|
args.GetIsolate()->ThrowError("Error executing file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2115,7 +2112,7 @@ bool FunctionAndArgumentsToString(Local<Function> function,
|
|||||||
function->FunctionProtoToString(context);
|
function->FunctionProtoToString(context);
|
||||||
Local<String> function_string;
|
Local<String> function_string;
|
||||||
if (!maybe_function_string.ToLocal(&function_string)) {
|
if (!maybe_function_string.ToLocal(&function_string)) {
|
||||||
Throw(isolate, "Failed to convert function to string");
|
isolate->ThrowError("Failed to convert function to string");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*source = String::NewFromUtf8Literal(isolate, "(");
|
*source = String::NewFromUtf8Literal(isolate, "(");
|
||||||
@ -2124,7 +2121,7 @@ bool FunctionAndArgumentsToString(Local<Function> function,
|
|||||||
*source = String::Concat(isolate, *source, middle);
|
*source = String::Concat(isolate, *source, middle);
|
||||||
if (!arguments.IsEmpty() && !arguments->IsUndefined()) {
|
if (!arguments.IsEmpty() && !arguments->IsUndefined()) {
|
||||||
if (!arguments->IsArray()) {
|
if (!arguments->IsArray()) {
|
||||||
Throw(isolate, "'arguments' must be an array");
|
isolate->ThrowError("'arguments' must be an array");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Local<String> comma = String::NewFromUtf8Literal(isolate, ",");
|
Local<String> comma = String::NewFromUtf8Literal(isolate, ",");
|
||||||
@ -2136,12 +2133,12 @@ bool FunctionAndArgumentsToString(Local<Function> function,
|
|||||||
MaybeLocal<Value> maybe_argument = array->Get(context, i);
|
MaybeLocal<Value> maybe_argument = array->Get(context, i);
|
||||||
Local<Value> argument;
|
Local<Value> argument;
|
||||||
if (!maybe_argument.ToLocal(&argument)) {
|
if (!maybe_argument.ToLocal(&argument)) {
|
||||||
Throw(isolate, "Failed to get argument");
|
isolate->ThrowError("Failed to get argument");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Local<String> argument_string;
|
Local<String> argument_string;
|
||||||
if (!JSON::Stringify(context, argument).ToLocal(&argument_string)) {
|
if (!JSON::Stringify(context, argument).ToLocal(&argument_string)) {
|
||||||
Throw(isolate, "Failed to convert argument to string");
|
isolate->ThrowError("Failed to convert argument to string");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*source = String::Concat(isolate, *source, argument_string);
|
*source = String::Concat(isolate, *source, argument_string);
|
||||||
@ -2156,7 +2153,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
Isolate* isolate = args.GetIsolate();
|
Isolate* isolate = args.GetIsolate();
|
||||||
HandleScope handle_scope(isolate);
|
HandleScope handle_scope(isolate);
|
||||||
if (args.Length() < 1 || (!args[0]->IsString() && !args[0]->IsFunction())) {
|
if (args.Length() < 1 || (!args[0]->IsString() && !args[0]->IsFunction())) {
|
||||||
Throw(isolate, "1st argument must be a string or a function");
|
isolate->ThrowError("1st argument must be a string or a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2170,7 +2167,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
Local<Value> arguments;
|
Local<Value> arguments;
|
||||||
ReadWorkerTypeAndArguments(args, &worker_type, &arguments);
|
ReadWorkerTypeAndArguments(args, &worker_type, &arguments);
|
||||||
if (worker_type != WorkerType::kFunction) {
|
if (worker_type != WorkerType::kFunction) {
|
||||||
Throw(isolate, "Invalid or missing worker type");
|
isolate->ThrowError("Invalid or missing worker type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2189,7 +2186,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
load_from_file = false;
|
load_from_file = false;
|
||||||
} else if (worker_type != WorkerType::kNone &&
|
} else if (worker_type != WorkerType::kNone &&
|
||||||
worker_type != WorkerType::kClassic) {
|
worker_type != WorkerType::kClassic) {
|
||||||
Throw(isolate, "Invalid worker type");
|
isolate->ThrowError("Invalid worker type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2197,7 +2194,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
String::Utf8Value filename(isolate, args[0]);
|
String::Utf8Value filename(isolate, args[0]);
|
||||||
source = ReadFile(isolate, *filename);
|
source = ReadFile(isolate, *filename);
|
||||||
if (source.IsEmpty()) {
|
if (source.IsEmpty()) {
|
||||||
Throw(args.GetIsolate(), "Error loading worker script");
|
args.GetIsolate()->ThrowError("Error loading worker script");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2206,7 +2203,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!args.IsConstructCall()) {
|
if (!args.IsConstructCall()) {
|
||||||
Throw(isolate, "Worker must be constructed with new");
|
isolate->ThrowError("Worker must be constructed with new");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2223,7 +2220,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
|
|
||||||
String::Utf8Value script(isolate, source);
|
String::Utf8Value script(isolate, source);
|
||||||
if (!*script) {
|
if (!*script) {
|
||||||
Throw(isolate, "Can't get worker script");
|
isolate->ThrowError("Can't get worker script");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2237,7 +2234,7 @@ void Shell::WorkerNew(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
i_isolate, kWorkerSizeEstimate, worker);
|
i_isolate, kWorkerSizeEstimate, worker);
|
||||||
args.Holder()->SetInternalField(0, Utils::ToLocal(managed));
|
args.Holder()->SetInternalField(0, Utils::ToLocal(managed));
|
||||||
if (!Worker::StartWorkerThread(std::move(worker))) {
|
if (!Worker::StartWorkerThread(std::move(worker))) {
|
||||||
Throw(isolate, "Can't start thread");
|
isolate->ThrowError("Can't start thread");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2248,7 +2245,7 @@ void Shell::WorkerPostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
HandleScope handle_scope(isolate);
|
HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
if (args.Length() < 1) {
|
if (args.Length() < 1) {
|
||||||
Throw(isolate, "Invalid argument");
|
isolate->ThrowError("Invalid argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3187,13 +3184,13 @@ void Shell::ReadBuffer(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
String::Utf8Value filename(isolate, args[0]);
|
String::Utf8Value filename(isolate, args[0]);
|
||||||
int length;
|
int length;
|
||||||
if (*filename == nullptr) {
|
if (*filename == nullptr) {
|
||||||
Throw(isolate, "Error loading file");
|
isolate->ThrowError("Error loading file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length));
|
uint8_t* data = reinterpret_cast<uint8_t*>(ReadChars(*filename, &length));
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
Throw(isolate, "Error reading file");
|
isolate->ThrowError("Error reading file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::unique_ptr<v8::BackingStore> backing_store =
|
std::unique_ptr<v8::BackingStore> backing_store =
|
||||||
@ -3860,7 +3857,7 @@ void Worker::PostMessageOut(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||||||
HandleScope handle_scope(isolate);
|
HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
if (args.Length() < 1) {
|
if (args.Length() < 1) {
|
||||||
Throw(isolate, "Invalid argument");
|
isolate->ThrowError("Invalid argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4432,7 +4429,8 @@ class Serializer : public ValueSerializer::Delegate {
|
|||||||
Local<Value> element;
|
Local<Value> element;
|
||||||
if (transfer_array->Get(context, i).ToLocal(&element)) {
|
if (transfer_array->Get(context, i).ToLocal(&element)) {
|
||||||
if (!element->IsArrayBuffer()) {
|
if (!element->IsArrayBuffer()) {
|
||||||
Throw(isolate_, "Transfer array elements must be an ArrayBuffer");
|
isolate_->ThrowError(
|
||||||
|
"Transfer array elements must be an ArrayBuffer");
|
||||||
return Nothing<bool>();
|
return Nothing<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4440,8 +4438,8 @@ class Serializer : public ValueSerializer::Delegate {
|
|||||||
|
|
||||||
if (std::find(array_buffers_.begin(), array_buffers_.end(),
|
if (std::find(array_buffers_.begin(), array_buffers_.end(),
|
||||||
array_buffer) != array_buffers_.end()) {
|
array_buffer) != array_buffers_.end()) {
|
||||||
Throw(isolate_,
|
isolate_->ThrowError(
|
||||||
"ArrayBuffer occurs in the transfer array more than once");
|
"ArrayBuffer occurs in the transfer array more than once");
|
||||||
return Nothing<bool>();
|
return Nothing<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4456,7 +4454,7 @@ class Serializer : public ValueSerializer::Delegate {
|
|||||||
} else if (transfer->IsUndefined()) {
|
} else if (transfer->IsUndefined()) {
|
||||||
return Just(true);
|
return Just(true);
|
||||||
} else {
|
} else {
|
||||||
Throw(isolate_, "Transfer list must be an Array or undefined");
|
isolate_->ThrowError("Transfer list must be an Array or undefined");
|
||||||
return Nothing<bool>();
|
return Nothing<bool>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4466,7 +4464,7 @@ class Serializer : public ValueSerializer::Delegate {
|
|||||||
Local<ArrayBuffer> array_buffer =
|
Local<ArrayBuffer> array_buffer =
|
||||||
Local<ArrayBuffer>::New(isolate_, global_array_buffer);
|
Local<ArrayBuffer>::New(isolate_, global_array_buffer);
|
||||||
if (!array_buffer->IsDetachable()) {
|
if (!array_buffer->IsDetachable()) {
|
||||||
Throw(isolate_, "ArrayBuffer could not be transferred");
|
isolate_->ThrowError("ArrayBuffer could not be transferred");
|
||||||
return Nothing<bool>();
|
return Nothing<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,9 +16,8 @@ CpuTraceMarkExtension::GetNativeFunctionTemplate(v8::Isolate* isolate,
|
|||||||
void CpuTraceMarkExtension::Mark(
|
void CpuTraceMarkExtension::Mark(
|
||||||
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
if (args.Length() < 1 || !args[0]->IsUint32()) {
|
if (args.Length() < 1 || !args[0]->IsUint32()) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"First parameter to cputracemark() must be a unsigned int32.");
|
||||||
"First parameter to cputracemark() must be a unsigned int32."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +59,8 @@ ExternalizeStringExtension::GetNativeFunctionTemplate(
|
|||||||
void ExternalizeStringExtension::Externalize(
|
void ExternalizeStringExtension::Externalize(
|
||||||
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
if (args.Length() < 1 || !args[0]->IsString()) {
|
if (args.Length() < 1 || !args[0]->IsString()) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"First parameter to externalizeString() must be a string.");
|
||||||
"First parameter to externalizeString() must be a string."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool force_two_byte = false;
|
bool force_two_byte = false;
|
||||||
@ -69,17 +68,15 @@ void ExternalizeStringExtension::Externalize(
|
|||||||
if (args[1]->IsBoolean()) {
|
if (args[1]->IsBoolean()) {
|
||||||
force_two_byte = args[1]->BooleanValue(args.GetIsolate());
|
force_two_byte = args[1]->BooleanValue(args.GetIsolate());
|
||||||
} else {
|
} else {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"Second parameter to externalizeString() must be a boolean.");
|
||||||
"Second parameter to externalizeString() must be a boolean."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool result = false;
|
bool result = false;
|
||||||
Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
|
Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
|
||||||
if (!string->SupportsExternalization()) {
|
if (!string->SupportsExternalization()) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("string does not support externalization.");
|
||||||
args.GetIsolate(), "string does not support externalization."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (string->IsOneByteRepresentation() && !force_two_byte) {
|
if (string->IsOneByteRepresentation() && !force_two_byte) {
|
||||||
@ -98,8 +95,7 @@ void ExternalizeStringExtension::Externalize(
|
|||||||
if (!result) delete resource;
|
if (!result) delete resource;
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError("externalizeString() failed.");
|
||||||
args.GetIsolate(), "externalizeString() failed."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,9 +104,8 @@ void ExternalizeStringExtension::Externalize(
|
|||||||
void ExternalizeStringExtension::IsOneByte(
|
void ExternalizeStringExtension::IsOneByte(
|
||||||
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
if (args.Length() != 1 || !args[0]->IsString()) {
|
if (args.Length() != 1 || !args[0]->IsString()) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
"isOneByteString() requires a single string argument.");
|
||||||
"isOneByteString() requires a single string argument."));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool is_one_byte =
|
bool is_one_byte =
|
||||||
|
@ -109,10 +109,9 @@ void VTuneDomainSupportExtension::Mark(
|
|||||||
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||||
if (args.Length() != 3 || !args[0]->IsString() || !args[1]->IsString() ||
|
if (args.Length() != 3 || !args[0]->IsString() || !args[1]->IsString() ||
|
||||||
!args[2]->IsString()) {
|
!args[2]->IsString()) {
|
||||||
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
|
args.GetIsolate()->ThrowError(
|
||||||
args.GetIsolate(),
|
|
||||||
"Parameter number should be exactly three, first domain name"
|
"Parameter number should be exactly three, first domain name"
|
||||||
"second task name, third start/end"));
|
"second task name, third start/end");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,9 +129,7 @@ void VTuneDomainSupportExtension::Mark(
|
|||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
if ((r = libvtune::invoke(params.str().c_str())) != 0) {
|
if ((r = libvtune::invoke(params.str().c_str())) != 0) {
|
||||||
args.GetIsolate()->ThrowException(
|
args.GetIsolate()->ThrowError(std::to_string(r).c_str());
|
||||||
v8::String::NewFromUtf8(args.GetIsolate(), std::to_string(r).c_str())
|
|
||||||
.ToLocalChecked());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,8 +743,8 @@ void V8RuntimeAgentImpl::bindingCallback(
|
|||||||
const v8::FunctionCallbackInfo<v8::Value>& info) {
|
const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||||
v8::Isolate* isolate = info.GetIsolate();
|
v8::Isolate* isolate = info.GetIsolate();
|
||||||
if (info.Length() != 1 || !info[0]->IsString()) {
|
if (info.Length() != 1 || !info[0]->IsString()) {
|
||||||
info.GetIsolate()->ThrowException(toV8String(
|
info.GetIsolate()->ThrowError(
|
||||||
isolate, "Invalid arguments: should be exactly one string."));
|
"Invalid arguments: should be exactly one string.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
V8InspectorImpl* inspector =
|
V8InspectorImpl* inspector =
|
||||||
|
@ -34,8 +34,8 @@ void WebSnapshotSerializerDeserializer::Throw(const char* message) {
|
|||||||
error_message_ = message;
|
error_message_ = message;
|
||||||
if (!isolate_->has_pending_exception()) {
|
if (!isolate_->has_pending_exception()) {
|
||||||
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
|
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
|
||||||
v8_isolate->ThrowException(v8::Exception::Error(
|
v8_isolate->ThrowError(
|
||||||
v8::String::NewFromUtf8(v8_isolate, message).ToLocalChecked()));
|
v8::String::NewFromUtf8(v8_isolate, message).ToLocalChecked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3957,7 +3957,7 @@ struct FastApiReceiver {
|
|||||||
static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
||||||
v8::Object* receiver_obj = v8::Object::Cast(*info.Holder());
|
v8::Object* receiver_obj = v8::Object::Cast(*info.Holder());
|
||||||
if (!IsValidUnwrapObject(receiver_obj)) {
|
if (!IsValidUnwrapObject(receiver_obj)) {
|
||||||
info.GetIsolate()->ThrowException(v8_str("Called with a non-object."));
|
info.GetIsolate()->ThrowError("Called with a non-object.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FastApiReceiver* receiver =
|
FastApiReceiver* receiver =
|
||||||
|
@ -439,14 +439,14 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
|
|||||||
static void AccessorGetter(v8::Local<v8::String> property,
|
static void AccessorGetter(v8::Local<v8::String> property,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||||
v8::Isolate* isolate = info.GetIsolate();
|
v8::Isolate* isolate = info.GetIsolate();
|
||||||
isolate->ThrowException(ToV8String(isolate, "Getter is called"));
|
isolate->ThrowError("Getter is called");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AccessorSetter(v8::Local<v8::String> property,
|
static void AccessorSetter(v8::Local<v8::String> property,
|
||||||
v8::Local<v8::Value> value,
|
v8::Local<v8::Value> value,
|
||||||
const v8::PropertyCallbackInfo<void>& info) {
|
const v8::PropertyCallbackInfo<void>& info) {
|
||||||
v8::Isolate* isolate = info.GetIsolate();
|
v8::Isolate* isolate = info.GetIsolate();
|
||||||
isolate->ThrowException(ToV8String(isolate, "Setter is called"));
|
isolate->ThrowError("Setter is called");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StoreCurrentStackTrace(
|
static void StoreCurrentStackTrace(
|
||||||
|
@ -171,7 +171,7 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
|
|||||||
std::string filename(*str, str.length());
|
std::string filename(*str, str.length());
|
||||||
*chars = v8::internal::ReadFile(filename.c_str(), &exists);
|
*chars = v8::internal::ReadFile(filename.c_str(), &exists);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
isolate->ThrowException(ToV8String(isolate, "Error reading file"));
|
isolate->ThrowError("Error reading file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -632,14 +632,14 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
|
|||||||
static void AccessorGetter(v8::Local<v8::String> property,
|
static void AccessorGetter(v8::Local<v8::String> property,
|
||||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||||
v8::Isolate* isolate = info.GetIsolate();
|
v8::Isolate* isolate = info.GetIsolate();
|
||||||
isolate->ThrowException(ToV8String(isolate, "Getter is called"));
|
isolate->ThrowError("Getter is called");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AccessorSetter(v8::Local<v8::String> property,
|
static void AccessorSetter(v8::Local<v8::String> property,
|
||||||
v8::Local<v8::Value> value,
|
v8::Local<v8::Value> value,
|
||||||
const v8::PropertyCallbackInfo<void>& info) {
|
const v8::PropertyCallbackInfo<void>& info) {
|
||||||
v8::Isolate* isolate = info.GetIsolate();
|
v8::Isolate* isolate = info.GetIsolate();
|
||||||
isolate->ThrowException(ToV8String(isolate, "Setter is called"));
|
isolate->ThrowError("Setter is called");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StoreCurrentStackTrace(
|
static void StoreCurrentStackTrace(
|
||||||
|
Loading…
Reference in New Issue
Block a user