Chromium Code Reviews| 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..ac7c88b262fbdabc1c1a4f8e6c5a13f9bb919b6b 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,7 +281,7 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate, |
| FXJS_PerIsolateData::SetUp(pIsolate); |
| v8::Local<v8::External> ptr = v8::External::New(pIsolate, pFXRuntime); |
|
Tom Sepez
2015/09/25 17:32:18
Here's the spot where I'd like to use the AlignedP
jochen (gone - plz use gerrit)
2015/09/28 11:27:31
v8Context->SetAlignedPointerInEmbedderData(kPerCon
Tom Sepez
2015/09/28 16:20:18
Done. Appears to work (I thought I'd tried this ea
|
| - v8Context->SetEmbedderData(1, ptr); |
| + v8Context->SetEmbedderData(kPerContextDataIndex, ptr); |
| int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
| for (int i = 0; i < maxID; ++i) { |
| @@ -338,11 +350,13 @@ 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(); |
| + v8::Local<v8::Value> v = context->GetEmbedderData(kPerContextDataIndex); |
| + if (v.IsEmpty()) |
| + return nullptr; |
| + v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); |
| + return static_cast<IFXJS_Runtime*>(field->Value()); |
| } |
| int FXJS_Execute(v8::Isolate* pIsolate, |