summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/jsapi/fxjs_v8.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-09-28 10:31:27 -0700
committerTom Sepez <tsepez@chromium.org>2015-09-28 10:31:27 -0700
commitbd7fabf61f41e5ac2ded12ac46a4193c3dbffc44 (patch)
tree0f4bfd65d3ca48aa2cfb16232e60ebf10991c411 /fpdfsdk/src/jsapi/fxjs_v8.cpp
parenta25fd09cd880ad82aea09a7ffffe3f8e5b121bbe (diff)
downloadpdfium-bd7fabf61f41e5ac2ded12ac46a4193c3dbffc44.tar.xz
Merge to XFA: Introduce kPerIsolateDataIndex and tidy JS_Define.h
(cherry picked from commit d6d9dc6b9a45368abdf43477592ee9f6cdb6102e) (cherry picked from commit cfff2f65aaec70247d020188bc68a0dc4fb34c3e) Original Review URL: https://codereview.chromium.org/1372963003 . Original Review URL: https://codereview.chromium.org/1367813003 . TBR=jochen@chromium.org Review URL: https://codereview.chromium.org/1370133007 .
Diffstat (limited to 'fpdfsdk/src/jsapi/fxjs_v8.cpp')
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index d7868f1586..7009b4442b 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -5,7 +5,6 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../../../core/include/fxcrt/fx_basic.h"
-#include "../../include/fsdk_define.h"
#include "../../include/jsapi/fxjs_v8.h"
const wchar_t kFXJSValueNameString[] = L"string";
@@ -19,6 +18,12 @@ const wchar_t kFXJSValueNameUndefined[] = L"undefined";
static unsigned int g_embedderDataSlot = 1u;
+// Keep this consistent with the values defined in gin/public/context_holder.h
+// (without actually requiring a dependency on gin itself for the standalone
+// embedders of PDFIum). The value we want to use is:
+// kPerContextDataStartIndex + kEmbedderPDFium, which is 3.
+static const unsigned int kPerContextDataIndex = 3u;
+
class CFXJS_PrivateData {
public:
CFXJS_PrivateData(int nObjDefID) : ObjDefID(nObjDefID), pPrivate(NULL) {}
@@ -100,6 +105,13 @@ FXJS_PerIsolateData* FXJS_PerIsolateData::Get(v8::Isolate* pIsolate) {
pIsolate->GetData(g_embedderDataSlot));
}
+void FXJS_Initialize(unsigned int embedderDataSlot) {
+ g_embedderDataSlot = embedderDataSlot;
+}
+
+void FXJS_Release() {
+}
+
int FXJS_DefineObj(v8::Isolate* pIsolate,
const wchar_t* sObjName,
FXJSOBJTYPE eObjType,
@@ -269,8 +281,7 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
v8::Context::Scope context_scope(v8Context);
FXJS_PerIsolateData::SetUp(pIsolate);
- v8::Local<v8::External> ptr = v8::External::New(pIsolate, pFXRuntime);
- v8Context->SetEmbedderData(1, ptr);
+ v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pFXRuntime);
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
for (int i = 0; i < maxID; ++i) {
@@ -343,11 +354,10 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate,
delete pData;
}
-void FXJS_Initialize(unsigned int embedderDataSlot) {
- g_embedderDataSlot = embedderDataSlot;
-}
-
-void FXJS_Release() {
+IFXJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
+ v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
+ return static_cast<IFXJS_Runtime*>(
+ context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
}
int FXJS_Execute(v8::Isolate* pIsolate,