summaryrefslogtreecommitdiff
path: root/fxjs/cfxjse_context.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-02-01 22:06:21 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-01 22:06:21 +0000
commit59790cef1a09565e8b6799141cf45455ef2dc752 (patch)
tree6d4aa8bcb68ac79360c386c37b7d368854d5e313 /fxjs/cfxjse_context.cpp
parent270283669b1f53edfce8b96a579e973c5de5f205 (diff)
downloadpdfium-59790cef1a09565e8b6799141cf45455ef2dc752.tar.xz
Make CFXJSE-created contexts refer to their CFXJS counteparts.chromium/3337
Bug: 773229 Change-Id: Ic3774c7f6abe3a195bbe09b91d91c549d4d7ac46 Reviewed-on: https://pdfium-review.googlesource.com/25110 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/cfxjse_context.cpp')
-rw-r--r--fxjs/cfxjse_context.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp
index 3ec3b47c14..e2a0540252 100644
--- a/fxjs/cfxjse_context.cpp
+++ b/fxjs/cfxjse_context.cpp
@@ -10,6 +10,7 @@
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
+#include "fxjs/fxjs_v8.h"
#include "third_party/base/ptr_util.h"
namespace {
@@ -159,10 +160,12 @@ CFXJSE_HostObject* FXJSE_RetrieveObjectBinding(v8::Local<v8::Object> hJSObject,
// static
std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
v8::Isolate* pIsolate,
+ CFXJS_Engine* pOptionalEngineToSet,
const FXJSE_CLASS_DESCRIPTOR* pGlobalClass,
CFXJSE_HostObject* pGlobalObject) {
CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate);
auto pContext = pdfium::MakeUnique<CFXJSE_Context>(pIsolate);
+
v8::Local<v8::ObjectTemplate> hObjectTemplate;
if (pGlobalClass) {
CFXJSE_Class* pGlobalClassObj =
@@ -176,18 +179,23 @@ std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create(
hObjectTemplate = v8::ObjectTemplate::New(pIsolate);
hObjectTemplate->SetInternalFieldCount(2);
}
-
hObjectTemplate->Set(
v8::Symbol::GetToStringTag(pIsolate),
v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal)
.ToLocalChecked());
+
v8::Local<v8::Context> hNewContext =
v8::Context::New(pIsolate, nullptr, hObjectTemplate);
+
v8::Local<v8::Context> hRootContext = v8::Local<v8::Context>::New(
pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext);
hNewContext->SetSecurityToken(hRootContext->GetSecurityToken());
+
v8::Local<v8::Object> hGlobalObject = GetGlobalObjectFromContext(hNewContext);
FXJSE_UpdateObjectBinding(hGlobalObject, pGlobalObject);
+ if (pOptionalEngineToSet)
+ CFXJS_Engine::SetEngineInContext(pOptionalEngineToSet, hNewContext);
+
pContext->m_hContext.Reset(pIsolate, hNewContext);
return pContext;
}