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

Side by Side Diff: fpdfsdk/src/jsapi/fxjs_v8.cpp

Issue 1367033002: Pass v8::Isolate to PDFium at init time. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: kill include Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../core/include/fxcrt/fx_basic.h" 7 #include "../../../core/include/fxcrt/fx_basic.h"
8 #include "../../include/jsapi/fxjs_v8.h" 8 #include "../../include/jsapi/fxjs_v8.h"
9 9
10 const wchar_t kFXJSValueNameString[] = L"string"; 10 const wchar_t kFXJSValueNameString[] = L"string";
11 const wchar_t kFXJSValueNameNumber[] = L"number"; 11 const wchar_t kFXJSValueNameNumber[] = L"number";
12 const wchar_t kFXJSValueNameBoolean[] = L"boolean"; 12 const wchar_t kFXJSValueNameBoolean[] = L"boolean";
13 const wchar_t kFXJSValueNameDate[] = L"date"; 13 const wchar_t kFXJSValueNameDate[] = L"date";
14 const wchar_t kFXJSValueNameObject[] = L"object"; 14 const wchar_t kFXJSValueNameObject[] = L"object";
15 const wchar_t kFXJSValueNameFxobj[] = L"fxobj"; 15 const wchar_t kFXJSValueNameFxobj[] = L"fxobj";
16 const wchar_t kFXJSValueNameNull[] = L"null"; 16 const wchar_t kFXJSValueNameNull[] = L"null";
17 const wchar_t kFXJSValueNameUndefined[] = L"undefined"; 17 const wchar_t kFXJSValueNameUndefined[] = L"undefined";
18 18
19 static unsigned int g_embedderDataSlot = 1u;
20
21 // Keep this consistent with the values defined in gin/public/context_holder.h 19 // Keep this consistent with the values defined in gin/public/context_holder.h
22 // (without actually requiring a dependency on gin itself for the standalone 20 // (without actually requiring a dependency on gin itself for the standalone
23 // embedders of PDFIum). The value we want to use is: 21 // embedders of PDFIum). The value we want to use is:
24 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3. 22 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3.
25 static const unsigned int kPerContextDataIndex = 3u; 23 static const unsigned int kPerContextDataIndex = 3u;
26 24 static unsigned int g_embedderDataSlot = 1u;
25 static v8::Isolate* g_isolate = nullptr;
26 static FXJS_ArrayBufferAllocator* g_arrayBufferAllocator = nullptr;
27 static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr; 27 static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr;
28 28
29 class CFXJS_PrivateData { 29 class CFXJS_PrivateData {
30 public: 30 public:
31 CFXJS_PrivateData(int nObjDefID) : ObjDefID(nObjDefID), pPrivate(NULL) {} 31 CFXJS_PrivateData(int nObjDefID) : ObjDefID(nObjDefID), pPrivate(NULL) {}
32 32
33 int ObjDefID; 33 int ObjDefID;
34 void* pPrivate; 34 void* pPrivate;
35 }; 35 };
36 36
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 void* FXJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { 126 void* FXJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) {
127 return malloc(length); 127 return malloc(length);
128 } 128 }
129 129
130 void FXJS_ArrayBufferAllocator::Free(void* data, size_t length) { 130 void FXJS_ArrayBufferAllocator::Free(void* data, size_t length) {
131 free(data); 131 free(data);
132 } 132 }
133 133
134 void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate) {
135 g_embedderDataSlot = embedderDataSlot;
136 g_isolate = pIsolate;
137 }
138
139 void FXJS_Release() {
140 g_DefaultGlobalObjectTemplate = nullptr;
141 g_isolate = nullptr;
142
143 delete g_arrayBufferAllocator;
144 g_arrayBufferAllocator = nullptr;
145 }
146
147 bool FXJS_GetIsolate(v8::Isolate** pResultIsolate) {
148 if (g_isolate) {
149 *pResultIsolate = g_isolate;
150 return false;
151 }
152 // Provide backwards compatibility when no external isolate.
153 if (!g_arrayBufferAllocator)
154 g_arrayBufferAllocator = new FXJS_ArrayBufferAllocator();
155 v8::Isolate::CreateParams params;
156 params.array_buffer_allocator = g_arrayBufferAllocator;
157 *pResultIsolate = v8::Isolate::New(params);
158 return true;
159 }
160
134 // static 161 // static
135 void FXJS_PerIsolateData::SetUp(v8::Isolate* pIsolate) { 162 void FXJS_PerIsolateData::SetUp(v8::Isolate* pIsolate) {
136 if (!pIsolate->GetData(g_embedderDataSlot)) 163 if (!pIsolate->GetData(g_embedderDataSlot))
137 pIsolate->SetData(g_embedderDataSlot, new FXJS_PerIsolateData()); 164 pIsolate->SetData(g_embedderDataSlot, new FXJS_PerIsolateData());
138 } 165 }
139 166
140 // static 167 // static
141 FXJS_PerIsolateData* FXJS_PerIsolateData::Get(v8::Isolate* pIsolate) { 168 FXJS_PerIsolateData* FXJS_PerIsolateData::Get(v8::Isolate* pIsolate) {
142 return static_cast<FXJS_PerIsolateData*>( 169 return static_cast<FXJS_PerIsolateData*>(
143 pIsolate->GetData(g_embedderDataSlot)); 170 pIsolate->GetData(g_embedderDataSlot));
144 } 171 }
145 172
146 void FXJS_Initialize(unsigned int embedderDataSlot) {
147 g_embedderDataSlot = embedderDataSlot;
148 }
149
150 void FXJS_Release() {
151 }
152
153 int FXJS_DefineObj(v8::Isolate* pIsolate, 173 int FXJS_DefineObj(v8::Isolate* pIsolate,
154 const wchar_t* sObjName, 174 const wchar_t* sObjName,
155 FXJSOBJTYPE eObjType, 175 FXJSOBJTYPE eObjType,
156 FXJS_CONSTRUCTOR pConstructor, 176 FXJS_CONSTRUCTOR pConstructor,
157 FXJS_DESTRUCTOR pDestructor) { 177 FXJS_DESTRUCTOR pDestructor) {
158 v8::Isolate::Scope isolate_scope(pIsolate); 178 v8::Isolate::Scope isolate_scope(pIsolate);
159 v8::HandleScope handle_scope(pIsolate); 179 v8::HandleScope handle_scope(pIsolate);
160 180
161 FXJS_PerIsolateData::SetUp(pIsolate); 181 FXJS_PerIsolateData::SetUp(pIsolate);
162 CFXJS_ObjDefinition* pObjDef = new CFXJS_ObjDefinition( 182 CFXJS_ObjDefinition* pObjDef = new CFXJS_ObjDefinition(
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 return v8::Local<v8::Array>(); 760 return v8::Local<v8::Array>();
741 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 761 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
742 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 762 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
743 } 763 }
744 764
745 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 765 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
746 pTo = pFrom; 766 pTo = pFrom;
747 } 767 }
748 768
749 769
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698