diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-25 12:43:13 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-25 20:31:57 +0000 |
commit | 80547a165adf250f31ade57544771201bbc2690c (patch) | |
tree | 1c1669fdcbc6d2fc443172142b80c03cd1a4972a /fxjs/cfxjse_class.cpp | |
parent | 233360e3ea0d6d4acea76a7d9e7ce7700ea80b1a (diff) | |
download | pdfium-80547a165adf250f31ade57544771201bbc2690c.tar.xz |
Use unique_ptr in CXFA_ScriptContext::m_mapVariableToContext.
Remove unused CFXJSE_Arguments::GetRuntime().
Remove some default argument values.
Make members of CFXJSE_Context private.
Change-Id: Id21951f7d8d68929b2799a9d6a2cdd7a3677f52a
Reviewed-on: https://pdfium-review.googlesource.com/4493
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/cfxjse_class.cpp')
-rw-r--r-- | fxjs/cfxjse_class.cpp | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index 8924a48a47..da70583f45 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -7,7 +7,9 @@ #include "fxjs/cfxjse_class.h" #include <memory> +#include <utility> +#include "fxjs/cfxjse_arguments.h" #include "fxjs/cfxjse_context.h" #include "fxjs/cfxjse_value.h" #include "third_party/base/ptr_util.h" @@ -311,13 +313,13 @@ CFXJSE_Class* CFXJSE_Class::Create( if (!lpContext || !lpClassDefinition) return nullptr; - CFXJSE_Class* pClass = - GetClassFromContext(lpContext, lpClassDefinition->name); - if (pClass) - return pClass; + CFXJSE_Class* pExistingClass = + lpContext->GetClassByName(lpClassDefinition->name); + if (pExistingClass) + return pExistingClass; - v8::Isolate* pIsolate = lpContext->m_pIsolate; - pClass = new CFXJSE_Class(lpContext); + v8::Isolate* pIsolate = lpContext->GetIsolate(); + auto pClass = pdfium::MakeUnique<CFXJSE_Class>(lpContext); pClass->m_szClassName = lpClassDefinition->name; pClass->m_lpClassDefinition = lpClassDefinition; CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); @@ -369,8 +371,7 @@ CFXJSE_Class* CFXJSE_Class::Create( lpClassDefinition))), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); } else { - v8::Local<v8::Context> hLocalContext = - v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); + v8::Local<v8::Context> hLocalContext = lpContext->GetContext(); FXJSE_GetGlobalObjectFromContext(hLocalContext) ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), v8::Function::New( @@ -388,19 +389,10 @@ CFXJSE_Class* CFXJSE_Class::Create( fun->RemovePrototype(); hObjectTemplate->Set(v8::String::NewFromUtf8(pIsolate, "toString"), fun); } - pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); - lpContext->m_rgClasses.push_back(std::unique_ptr<CFXJSE_Class>(pClass)); - return pClass; -} - -// static -CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, - const CFX_ByteStringC& szName) { - for (const auto& pClass : pContext->m_rgClasses) { - if (pClass->m_szClassName == szName) - return pClass.get(); - } - return nullptr; + pClass->m_hTemplate.Reset(lpContext->GetIsolate(), hFunctionTemplate); + CFXJSE_Class* pResult = pClass.get(); + lpContext->AddClass(std::move(pClass)); + return pResult; } // static |