Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1185)

Unified Diff: fpdfsdk/src/jsapi/fxjs_v8.cpp

Issue 1367813003: Introduce kPerIsolateDataIndex and tidy JS_Define.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: SetAlignedPointerInEmbedderData Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/include/jsapi/fxjs_v8.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/jsapi/fxjs_v8.cpp
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index d5673e6e87d40b3fc5225b4482230256a31be338..7b93a2ad268fa5f018d06405407714644c718d64 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,
@@ -268,8 +280,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) {
@@ -338,11 +349,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,
« no previous file with comments | « fpdfsdk/include/jsapi/fxjs_v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698