Add exception helper to fxv8.h.
Change-Id: I6fdfad87e7c36cbffd3ea59e74572eb22525e754
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67511
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cfxjs_engine.cpp b/fxjs/cfxjs_engine.cpp
index 2c05992..9624feb 100644
--- a/fxjs/cfxjs_engine.cpp
+++ b/fxjs/cfxjs_engine.cpp
@@ -157,13 +157,11 @@
static void CallHandler(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
if (!info.IsConstructCall()) {
- isolate->ThrowException(
- fxv8::NewStringHelper(isolate, "illegal constructor"));
+ fxv8::ThrowExceptionHelper(isolate, "illegal constructor");
return;
}
if (info.Data().As<v8::Int32>()->Value() != FXJSOBJTYPE_DYNAMIC) {
- isolate->ThrowException(
- fxv8::NewStringHelper(isolate, "not a dynamic object"));
+ fxv8::ThrowExceptionHelper(isolate, "not a dynamic object");
return;
}
v8::Local<v8::Object> holder = info.Holder();
@@ -612,7 +610,7 @@
}
void CFXJS_Engine::Error(const WideString& message) {
- GetIsolate()->ThrowException(NewString(message.AsStringView()));
+ fxv8::ThrowExceptionHelper(GetIsolate(), message.AsStringView());
}
v8::Local<v8::Context> CFXJS_Engine::GetV8Context() {
diff --git a/fxjs/fxv8.cpp b/fxjs/fxv8.cpp
index 8068f39..7b52d0b 100644
--- a/fxjs/fxv8.cpp
+++ b/fxjs/fxv8.cpp
@@ -115,4 +115,12 @@
return pObj->Set(pIsolate->GetCurrentContext(), name, pPut).IsJust();
}
+void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str) {
+ pIsolate->ThrowException(NewStringHelper(pIsolate, str));
+}
+
+void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str) {
+ pIsolate->ThrowException(NewStringHelper(pIsolate, str));
+}
+
} // namespace fxv8
diff --git a/fxjs/fxv8.h b/fxjs/fxv8.h
index b79ec27..6c05d76 100644
--- a/fxjs/fxv8.h
+++ b/fxjs/fxv8.h
@@ -41,6 +41,9 @@
ByteStringView bsUTF8PropertyName,
v8::Local<v8::Value> pPut);
+void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str);
+void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str);
+
} // namespace fxv8
#endif // FXJS_FXV8_H_
diff --git a/fxjs/xfa/cfxjse_class.cpp b/fxjs/xfa/cfxjse_class.cpp
index 75d4081..61215be 100644
--- a/fxjs/xfa/cfxjse_class.cpp
+++ b/fxjs/xfa/cfxjse_class.cpp
@@ -105,9 +105,7 @@
if (result.HasError()) {
WideString err = JSFormatErrorString(pClassDescriptor->name, *szPropName,
result.Error());
- v8::Local<v8::String> str =
- fxv8::NewStringHelper(info.GetIsolate(), err.AsStringView());
- info.GetIsolate()->ThrowException(str);
+ fxv8::ThrowExceptionHelper(info.GetIsolate(), err.AsStringView());
return;
}