Remove some calls to CFXJSE_Value::ForceSetValue() Prefer the two-arg form of the constructor when setting a value immediately after creation. -- Convert some |lp| to |p| while at it as |p| is bad enough. Change-Id: I424106e55281009e837ba874e49a1110e403b4a8 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75953 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/fxjs/xfa/cfxjse_class.cpp b/fxjs/xfa/cfxjse_class.cpp index 3a85760..b34c172 100644 --- a/fxjs/xfa/cfxjse_class.cpp +++ b/fxjs/xfa/cfxjse_class.cpp
@@ -181,17 +181,17 @@ v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = + const FXJSE_CLASS_DESCRIPTOR* pClass = AsClassDescriptor(info.Data().As<v8::External>()->Value()); - if (!lpClass) + if (!pClass) return; v8::HandleScope scope(info.GetIsolate()); v8::String::Utf8Value szPropName(info.GetIsolate(), property); ByteStringView szFxPropName(*szPropName, szPropName.length()); - auto lpThisValue = std::make_unique<CFXJSE_Value>(); - lpThisValue->ForceSetValue(info.GetIsolate(), thisObject); - if (DynPropQueryAdapter(info.GetIsolate(), lpClass, lpThisValue.get(), + auto pThisValue = + std::make_unique<CFXJSE_Value>(info.GetIsolate(), thisObject); + if (DynPropQueryAdapter(info.GetIsolate(), pClass, pThisValue.get(), szFxPropName)) { info.GetReturnValue().Set(v8::DontDelete); return; @@ -204,19 +204,19 @@ v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = + const FXJSE_CLASS_DESCRIPTOR* pClass = AsClassDescriptor(info.Data().As<v8::External>()->Value()); - if (!lpClass) + if (!pClass) return; v8::String::Utf8Value szPropName(info.GetIsolate(), property); ByteStringView szFxPropName(*szPropName, szPropName.length()); - auto lpThisValue = std::make_unique<CFXJSE_Value>(); - lpThisValue->ForceSetValue(info.GetIsolate(), thisObject); - auto lpNewValue = std::make_unique<CFXJSE_Value>(); - DynPropGetterAdapter(info.GetIsolate(), lpClass, lpThisValue.get(), - szFxPropName, lpNewValue.get()); - info.GetReturnValue().Set(lpNewValue->DirectGetValue()); + auto pThisValue = + std::make_unique<CFXJSE_Value>(info.GetIsolate(), thisObject); + auto pNewValue = std::make_unique<CFXJSE_Value>(); + DynPropGetterAdapter(info.GetIsolate(), pClass, pThisValue.get(), + szFxPropName, pNewValue.get()); + info.GetReturnValue().Set(pNewValue->DirectGetValue()); } void NamedPropertySetterCallback( @@ -224,19 +224,18 @@ v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = + const FXJSE_CLASS_DESCRIPTOR* pClass = AsClassDescriptor(info.Data().As<v8::External>()->Value()); - if (!lpClass) + if (!pClass) return; v8::String::Utf8Value szPropName(info.GetIsolate(), property); ByteStringView szFxPropName(*szPropName, szPropName.length()); - auto lpThisValue = std::make_unique<CFXJSE_Value>(); - lpThisValue->ForceSetValue(info.GetIsolate(), thisObject); - auto lpNewValue = std::make_unique<CFXJSE_Value>(); - lpNewValue->ForceSetValue(info.GetIsolate(), value); - DynPropSetterAdapter(info.GetIsolate(), lpClass, lpThisValue.get(), - szFxPropName, lpNewValue.get()); + auto pThisValue = + std::make_unique<CFXJSE_Value>(info.GetIsolate(), thisObject); + auto pNewValue = std::make_unique<CFXJSE_Value>(info.GetIsolate(), value); + DynPropSetterAdapter(info.GetIsolate(), pClass, pThisValue.get(), + szFxPropName, pNewValue.get()); info.GetReturnValue().Set(value); }
diff --git a/fxjs/xfa/cfxjse_context.cpp b/fxjs/xfa/cfxjse_context.cpp index 0515934..a22dcaa 100644 --- a/fxjs/xfa/cfxjse_context.cpp +++ b/fxjs/xfa/cfxjse_context.cpp
@@ -218,14 +218,12 @@ CFXJSE_Context::~CFXJSE_Context() = default; std::unique_ptr<CFXJSE_Value> CFXJSE_Context::GetGlobalObject() { - auto pValue = std::make_unique<CFXJSE_Value>(); CFXJSE_ScopeUtil_IsolateHandleContext scope(this); v8::Local<v8::Context> hContext = v8::Local<v8::Context>::New(GetIsolate(), m_hContext); v8::Local<v8::Object> hGlobalObject = hContext->Global()->GetPrototype().As<v8::Object>(); - pValue->ForceSetValue(GetIsolate(), hGlobalObject); - return pValue; + return std::make_unique<CFXJSE_Value>(GetIsolate(), hGlobalObject); } v8::Local<v8::Context> CFXJSE_Context::GetContext() {