diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-10-25 13:30:31 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-25 18:40:45 +0000 |
commit | 8f524d6ff9c5c5e07388438e58aca7dc39f43a1f (patch) | |
tree | ec73d24ebdfb84e0c9a254a35912edc5ab54dae7 /fpdfsdk/javascript/JS_Define.h | |
parent | 2474a3b2d9fe987dac58813771f1fa66427e124f (diff) | |
download | pdfium-8f524d6ff9c5c5e07388438e58aca7dc39f43a1f.tar.xz |
Refactor JS method parameters and return values.
This CL removes the out parameters from the JS methods and changes the
return from a |bool| to a |CJS_Return| value. The return value holds the
returned v8 object, error string and a status code.
Change-Id: I82488ff0d916475d7e3c8e51ed868639806181c9
Reviewed-on: https://pdfium-review.googlesource.com/16751
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/JS_Define.h')
-rw-r--r-- | fpdfsdk/javascript/JS_Define.h | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/fpdfsdk/javascript/JS_Define.h b/fpdfsdk/javascript/JS_Define.h index 39346135c5..b5afc95e51 100644 --- a/fpdfsdk/javascript/JS_Define.h +++ b/fpdfsdk/javascript/JS_Define.h @@ -34,7 +34,7 @@ struct JSMethodSpec { v8::FunctionCallback pMethodCall; }; -template <class C, bool (C::*M)(CJS_Runtime*, CJS_Value*, WideString*)> +template <class C, CJS_Return (C::*M)(CJS_Runtime*)> void JSPropGetter(const char* prop_name_string, const char* class_name_string, v8::Local<v8::String> property, @@ -50,20 +50,18 @@ void JSPropGetter(const char* prop_name_string, return; C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); - WideString sError; - - CJS_Value prop_value; - if (!(pObj->*M)(pRuntime, &prop_value, &sError)) { - pRuntime->Error( - JSFormatErrorString(class_name_string, prop_name_string, sError)); + CJS_Return result = (pObj->*M)(pRuntime); + if (result.HasError()) { + pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string, + result.Error())); return; } - if (!prop_value.ToV8Value().IsEmpty()) - info.GetReturnValue().Set(prop_value.ToV8Value()); + + if (result.HasReturn()) + info.GetReturnValue().Set(result.Return()); } -template <class C, - bool (C::*M)(CJS_Runtime*, v8::Local<v8::Value>, WideString*)> +template <class C, CJS_Return (C::*M)(CJS_Runtime*, v8::Local<v8::Value>)> void JSPropSetter(const char* prop_name_string, const char* class_name_string, v8::Local<v8::String> property, @@ -80,11 +78,10 @@ void JSPropSetter(const char* prop_name_string, return; C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); - WideString sError; - - if (!(pObj->*M)(pRuntime, value, &sError)) { - pRuntime->Error( - JSFormatErrorString(class_name_string, prop_name_string, sError)); + CJS_Return result = (pObj->*M)(pRuntime, value); + if (result.HasError()) { + pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string, + result.Error())); } } @@ -103,10 +100,8 @@ void JSPropSetter(const char* prop_name_string, } template <class C, - bool (C::*M)(CJS_Runtime*, - const std::vector<v8::Local<v8::Value>>&, - CJS_Value&, - WideString&)> + CJS_Return (C::*M)(CJS_Runtime*, + const std::vector<v8::Local<v8::Value>>&)> void JSMethod(const char* method_name_string, const char* class_name_string, const v8::FunctionCallbackInfo<v8::Value>& info) { @@ -115,25 +110,25 @@ void JSMethod(const char* method_name_string, if (!pRuntime) return; - std::vector<v8::Local<v8::Value>> parameters; - for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) - parameters.push_back(info[i]); - CJS_Object* pJSObj = static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(info.Holder())); if (!pJSObj) return; + std::vector<v8::Local<v8::Value>> parameters; + for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) + parameters.push_back(info[i]); + C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); - WideString sError; - CJS_Value valueRes; - if (!(pObj->*M)(pRuntime, parameters, valueRes, sError)) { - pRuntime->Error( - JSFormatErrorString(class_name_string, method_name_string, sError)); + CJS_Return result = (pObj->*M)(pRuntime, parameters); + if (result.HasError()) { + pRuntime->Error(JSFormatErrorString(class_name_string, method_name_string, + result.Error())); return; } - if (!valueRes.ToV8Value().IsEmpty()) - info.GetReturnValue().Set(valueRes.ToV8Value()); + + if (result.HasReturn()) + info.GetReturnValue().Set(result.Return()); } #define JS_STATIC_METHOD(method_name, class_name) \ |