From cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 11 Dec 2017 22:01:08 +0000 Subject: [xfa] Refactor CJX method signatures. This CL changes the CJX methods from void (*)(CFXJSE_Arguments*) to CJS_Return (*)(CJS_V8* runtime, const std::vector>& params) which is closer to how CJS works in practice. Change-Id: I3a3129268acfe4262dfeb04179919ed19f6c24e1 Reviewed-on: https://pdfium-review.googlesource.com/20491 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cfxjse_class.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'fxjs/cfxjse_class.cpp') diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index 09976d1aa5..9515ef4b74 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -12,6 +12,8 @@ #include "fxjs/cfxjse_arguments.h" #include "fxjs/cfxjse_context.h" #include "fxjs/cfxjse_value.h" +#include "fxjs/cjs_return.h" +#include "fxjs/js_resources.h" #include "third_party/base/ptr_util.h" namespace { @@ -78,15 +80,21 @@ void DynPropGetterAdapter_MethodCallback( v8::Local hPropName = hCallBackInfo->GetInternalField(1).As(); ASSERT(lpClass && !hPropName.IsEmpty()); + v8::String::Utf8Value szPropName(hPropName); - ByteStringView szFxPropName = *szPropName; - auto lpThisValue = pdfium::MakeUnique(info.GetIsolate()); - lpThisValue->ForceSetValue(info.Holder()); - auto lpRetValue = pdfium::MakeUnique(info.GetIsolate()); - CFXJSE_Arguments impl(&info, lpRetValue.get()); - lpClass->dynMethodCall(lpThisValue.get(), szFxPropName, impl); - if (!lpRetValue->DirectGetValue().IsEmpty()) - info.GetReturnValue().Set(lpRetValue->DirectGetValue()); + WideString szFxPropName = WideString::FromUTF8(*szPropName); + + CJS_Return result = lpClass->dynMethodCall(info, szFxPropName); + if (result.HasError()) { + WideString err = JSFormatErrorString(*szPropName, "", result.Error()); + v8::MaybeLocal str = v8::String::NewFromUtf8( + info.GetIsolate(), ByteString::FromUnicode(err).c_str(), + v8::NewStringType::kNormal); + info.GetIsolate()->ThrowException(str.ToLocalChecked()); + return; + } + if (result.HasReturn()) + info.GetReturnValue().Set(result.Return()); } void DynPropGetterAdapter(const FXJSE_CLASS_DESCRIPTOR* lpClass, @@ -94,6 +102,7 @@ void DynPropGetterAdapter(const FXJSE_CLASS_DESCRIPTOR* lpClass, const ByteStringView& szPropName, CFXJSE_Value* pValue) { ASSERT(lpClass); + int32_t nPropType = lpClass->dynPropTypeGetter == nullptr ? FXJSE_ClassPropType_Property -- cgit v1.2.3