From 721f5fa5061f2dec8282b7bde48c9d4721208b7a Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 23 Jul 2018 18:03:44 +0000 Subject: Replace CFXJSE_HostObject::type_ with polymorphic conversion methods More foolproof technique, and saves one word in every instance at a cost of two pointers in every subclass vtable. Change-Id: Ied4f91d4d203b5e6d83abe751159eb7e55489bb5 Reviewed-on: https://pdfium-review.googlesource.com/38530 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fxjs/cfxjse_formcalc_context.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'fxjs/cfxjse_formcalc_context.cpp') diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index c7433b4b2b..b0a26d86a4 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -450,9 +450,7 @@ bool PatternStringType(const ByteStringView& szPattern, uint32_t& patternType) { CFXJSE_FormCalcContext* ToFormCalcContext(CFXJSE_Value* pValue) { CFXJSE_HostObject* pHostObj = pValue->ToHostObject(nullptr); - if (!pHostObj || pHostObj->type() != CFXJSE_HostObject::kFM2JS) - return nullptr; - return static_cast(pHostObj); + return pHostObj ? pHostObj->AsFormCalcContext() : nullptr; } bool IsWhitespace(char c) { @@ -6177,15 +6175,13 @@ bool CFXJSE_FormCalcContext::Translate(const WideStringView& wsFormcalc, return false; wsJavascript->AppendChar(0); - return !CXFA_IsTooBig(wsJavascript); } CFXJSE_FormCalcContext::CFXJSE_FormCalcContext(v8::Isolate* pScriptIsolate, CFXJSE_Context* pScriptContext, CXFA_Document* pDoc) - : CFXJSE_HostObject(kFM2JS), - m_pIsolate(pScriptIsolate), + : m_pIsolate(pScriptIsolate), m_pFMClass(CFXJSE_Class::Create(pScriptContext, &kFormCalcFM2JSDescriptor, false)), @@ -6194,7 +6190,11 @@ CFXJSE_FormCalcContext::CFXJSE_FormCalcContext(v8::Isolate* pScriptIsolate, m_pValue.get()->SetObject(this, m_pFMClass); } -CFXJSE_FormCalcContext::~CFXJSE_FormCalcContext() {} +CFXJSE_FormCalcContext::~CFXJSE_FormCalcContext() = default; + +CFXJSE_FormCalcContext* CFXJSE_FormCalcContext::AsFormCalcContext() { + return this; +} void CFXJSE_FormCalcContext::GlobalPropertyGetter(CFXJSE_Value* pValue) { pValue->Assign(m_pValue.get()); -- cgit v1.2.3