Commit f9506988 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

Revert "[api] Add v8::Isolate::ThrowError helper"

This reverts commit d435eaa5.

Reason for revert: Breaks compilation on the vtunejit bot, see https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Linux%20-%20vtunejit/41247/overview

Original change's description:
> [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}

Bug: v8:11195
Change-Id: I2773d8ca7d73e7952d274381e2e0a2e5733a83da
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2826533
Auto-Submit: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/master@{#73959}
parent d435eaa5
......@@ -8872,17 +8872,6 @@ class V8_EXPORT Isolate {
*/
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
* exception has been scheduled it is illegal to invoke any JavaScript
......
......@@ -147,17 +147,20 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
// the argument into a JavaScript string.
void Read(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1) {
args.GetIsolate()->ThrowError("Bad parameters");
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8Literal(args.GetIsolate(), "Bad parameters"));
return;
}
v8::String::Utf8Value file(args.GetIsolate(), args[0]);
if (*file == NULL) {
args.GetIsolate()->ThrowError("Error loading file");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "Error loading file"));
return;
}
v8::Local<v8::String> source;
if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
args.GetIsolate()->ThrowError("Error loading file");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "Error loading file"));
return;
}
......@@ -172,16 +175,19 @@ void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope(args.GetIsolate());
v8::String::Utf8Value file(args.GetIsolate(), args[i]);
if (*file == NULL) {
args.GetIsolate()->ThrowError("Error loading file");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "Error loading file"));
return;
}
v8::Local<v8::String> source;
if (!ReadFile(args.GetIsolate(), *file).ToLocal(&source)) {
args.GetIsolate()->ThrowError("Error loading file");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "Error loading file"));
return;
}
if (!ExecuteString(args.GetIsolate(), source, args[i], false, false)) {
args.GetIsolate()->ThrowError("Error executing file");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "Error executing file"));
return;
}
}
......
......@@ -8012,10 +8012,6 @@ v8::Local<v8::Context> Isolate::GetIncumbentContext() {
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) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
ENTER_V8_DO_NOT_USE(isolate);
......
......@@ -47,7 +47,8 @@ static AsyncHooksWrap* UnwrapHook(
AsyncHooks* hooks = PerIsolateData::Get(isolate)->GetAsyncHooks();
if (!hooks->async_hook_ctor.Get(isolate)->HasInstance(hook)) {
isolate->ThrowError("Invalid 'this' passed instead of AsyncHooks instance");
isolate->ThrowException(String::NewFromUtf8Literal(
isolate, "Invalid 'this' passed instead of AsyncHooks instance"));
return nullptr;
}
......@@ -86,7 +87,8 @@ Local<Object> AsyncHooks::CreateHook(
Local<Context> currentContext = isolate->GetCurrentContext();
if (args.Length() != 1 || !args[0]->IsObject()) {
isolate->ThrowError("Invalid arguments passed to createHook");
isolate->ThrowException(String::NewFromUtf8Literal(
isolate, "Invalid arguments passed to createHook"));
return Local<Object>();
}
......
......@@ -43,7 +43,8 @@ void D8Console::Assert(const debug::ConsoleCallArguments& args,
// false-ish.
if (args.Length() > 0 && args[0]->BooleanValue(isolate_)) return;
WriteToFile("console.assert", stdout, isolate_, args);
isolate_->ThrowError("console.assert failed");
isolate_->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8Literal(isolate_, "console.assert failed")));
}
void D8Console::Log(const debug::ConsoleCallArguments& args,
......
This diff is collapsed.
......@@ -170,8 +170,10 @@ thread_local FastCApiObject kFastCApiObject;
// TODO(mslekova): Rename the fast_c_api helper to FastCAPI.
void CreateObject(const FunctionCallbackInfo<Value>& info) {
if (!info.IsConstructCall()) {
info.GetIsolate()->ThrowError(
"FastCAPI helper must be constructed with new.");
info.GetIsolate()->ThrowException(
v8::Exception::Error(String::NewFromUtf8Literal(
info.GetIsolate(),
"FastCAPI helper must be constructed with new.")));
return;
}
Local<Object> api_object = info.Holder();
......
This diff is collapsed.
......@@ -16,8 +16,9 @@ CpuTraceMarkExtension::GetNativeFunctionTemplate(v8::Isolate* isolate,
void CpuTraceMarkExtension::Mark(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1 || !args[0]->IsUint32()) {
args.GetIsolate()->ThrowError(
"First parameter to cputracemark() must be a unsigned int32.");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(),
"First parameter to cputracemark() must be a unsigned int32."));
return;
}
......
......@@ -59,8 +59,9 @@ ExternalizeStringExtension::GetNativeFunctionTemplate(
void ExternalizeStringExtension::Externalize(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() < 1 || !args[0]->IsString()) {
args.GetIsolate()->ThrowError(
"First parameter to externalizeString() must be a string.");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(),
"First parameter to externalizeString() must be a string."));
return;
}
bool force_two_byte = false;
......@@ -68,15 +69,17 @@ void ExternalizeStringExtension::Externalize(
if (args[1]->IsBoolean()) {
force_two_byte = args[1]->BooleanValue(args.GetIsolate());
} else {
args.GetIsolate()->ThrowError(
"Second parameter to externalizeString() must be a boolean.");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(),
"Second parameter to externalizeString() must be a boolean."));
return;
}
}
bool result = false;
Handle<String> string = Utils::OpenHandle(*args[0].As<v8::String>());
if (!string->SupportsExternalization()) {
args.GetIsolate()->ThrowError("string does not support externalization.");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "string does not support externalization."));
return;
}
if (string->IsOneByteRepresentation() && !force_two_byte) {
......@@ -95,7 +98,8 @@ void ExternalizeStringExtension::Externalize(
if (!result) delete resource;
}
if (!result) {
args.GetIsolate()->ThrowError("externalizeString() failed.");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(), "externalizeString() failed."));
return;
}
}
......@@ -104,8 +108,9 @@ void ExternalizeStringExtension::Externalize(
void ExternalizeStringExtension::IsOneByte(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsString()) {
args.GetIsolate()->ThrowError(
"isOneByteString() requires a single string argument.");
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(),
"isOneByteString() requires a single string argument."));
return;
}
bool is_one_byte =
......
......@@ -109,9 +109,10 @@ void VTuneDomainSupportExtension::Mark(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 3 || !args[0]->IsString() || !args[1]->IsString() ||
!args[2]->IsString()) {
args.GetIsolate()->ThrowError(
args.GetIsolate()->ThrowException(v8::String::NewFromUtf8Literal(
args.GetIsolate(),
"Parameter number should be exactly three, first domain name"
"second task name, third start/end");
"second task name, third start/end"));
return;
}
......@@ -129,7 +130,9 @@ void VTuneDomainSupportExtension::Mark(
int r = 0;
if ((r = libvtune::invoke(params.str().c_str())) != 0) {
args.GetIsolate()->ThrowError(std::to_string(r).c_str());
args.GetIsolate()->ThrowException(
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) {
v8::Isolate* isolate = info.GetIsolate();
if (info.Length() != 1 || !info[0]->IsString()) {
info.GetIsolate()->ThrowError(
"Invalid arguments: should be exactly one string.");
info.GetIsolate()->ThrowException(toV8String(
isolate, "Invalid arguments: should be exactly one string."));
return;
}
V8InspectorImpl* inspector =
......
......@@ -34,8 +34,8 @@ void WebSnapshotSerializerDeserializer::Throw(const char* message) {
error_message_ = message;
if (!isolate_->has_pending_exception()) {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
v8_isolate->ThrowError(
v8::String::NewFromUtf8(v8_isolate, message).ToLocalChecked());
v8_isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(v8_isolate, message).ToLocalChecked()));
}
}
......
......@@ -3957,7 +3957,7 @@ struct FastApiReceiver {
static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Object* receiver_obj = v8::Object::Cast(*info.Holder());
if (!IsValidUnwrapObject(receiver_obj)) {
info.GetIsolate()->ThrowError("Called with a non-object.");
info.GetIsolate()->ThrowException(v8_str("Called with a non-object."));
return;
}
FastApiReceiver* receiver =
......
......@@ -439,14 +439,14 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
static void AccessorGetter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
isolate->ThrowError("Getter is called");
isolate->ThrowException(ToV8String(isolate, "Getter is called"));
}
static void AccessorSetter(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
v8::Isolate* isolate = info.GetIsolate();
isolate->ThrowError("Setter is called");
isolate->ThrowException(ToV8String(isolate, "Setter is called"));
}
static void StoreCurrentStackTrace(
......
......@@ -171,7 +171,7 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
std::string filename(*str, str.length());
*chars = v8::internal::ReadFile(filename.c_str(), &exists);
if (!exists) {
isolate->ThrowError("Error reading file");
isolate->ThrowException(ToV8String(isolate, "Error reading file"));
return false;
}
return true;
......@@ -632,14 +632,14 @@ class InspectorExtension : public IsolateData::SetupGlobalTask {
static void AccessorGetter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
isolate->ThrowError("Getter is called");
isolate->ThrowException(ToV8String(isolate, "Getter is called"));
}
static void AccessorSetter(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const v8::PropertyCallbackInfo<void>& info) {
v8::Isolate* isolate = info.GetIsolate();
isolate->ThrowError("Setter is called");
isolate->ThrowException(ToV8String(isolate, "Setter is called"));
}
static void StoreCurrentStackTrace(
......
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