Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/fsdk_define.h" | |
| 9 #include "../../include/jsapi/fxjs_v8.h" | 8 #include "../../include/jsapi/fxjs_v8.h" |
| 10 | 9 |
| 11 const wchar_t kFXJSValueNameString[] = L"string"; | 10 const wchar_t kFXJSValueNameString[] = L"string"; |
| 12 const wchar_t kFXJSValueNameNumber[] = L"number"; | 11 const wchar_t kFXJSValueNameNumber[] = L"number"; |
| 13 const wchar_t kFXJSValueNameBoolean[] = L"boolean"; | 12 const wchar_t kFXJSValueNameBoolean[] = L"boolean"; |
| 14 const wchar_t kFXJSValueNameDate[] = L"date"; | 13 const wchar_t kFXJSValueNameDate[] = L"date"; |
| 15 const wchar_t kFXJSValueNameObject[] = L"object"; | 14 const wchar_t kFXJSValueNameObject[] = L"object"; |
| 16 const wchar_t kFXJSValueNameFxobj[] = L"fxobj"; | 15 const wchar_t kFXJSValueNameFxobj[] = L"fxobj"; |
| 17 const wchar_t kFXJSValueNameNull[] = L"null"; | 16 const wchar_t kFXJSValueNameNull[] = L"null"; |
| 18 const wchar_t kFXJSValueNameUndefined[] = L"undefined"; | 17 const wchar_t kFXJSValueNameUndefined[] = L"undefined"; |
| 19 | 18 |
| 20 static unsigned int g_embedderDataSlot = 1u; | 19 static unsigned int g_embedderDataSlot = 1u; |
| 21 | 20 |
| 21 // 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 | |
| 23 // embedders of PDFIum). The value we want to use is: | |
| 24 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3. | |
| 25 static const unsigned int kPerContextDataIndex = 3u; | |
| 26 | |
| 22 class CFXJS_PrivateData { | 27 class CFXJS_PrivateData { |
| 23 public: | 28 public: |
| 24 CFXJS_PrivateData(int nObjDefID) : ObjDefID(nObjDefID), pPrivate(NULL) {} | 29 CFXJS_PrivateData(int nObjDefID) : ObjDefID(nObjDefID), pPrivate(NULL) {} |
| 25 | 30 |
| 26 int ObjDefID; | 31 int ObjDefID; |
| 27 void* pPrivate; | 32 void* pPrivate; |
| 28 }; | 33 }; |
| 29 | 34 |
| 30 class CFXJS_ObjDefinition { | 35 class CFXJS_ObjDefinition { |
| 31 public: | 36 public: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 if (!pIsolate->GetData(g_embedderDataSlot)) | 98 if (!pIsolate->GetData(g_embedderDataSlot)) |
| 94 pIsolate->SetData(g_embedderDataSlot, new FXJS_PerIsolateData()); | 99 pIsolate->SetData(g_embedderDataSlot, new FXJS_PerIsolateData()); |
| 95 } | 100 } |
| 96 | 101 |
| 97 // static | 102 // static |
| 98 FXJS_PerIsolateData* FXJS_PerIsolateData::Get(v8::Isolate* pIsolate) { | 103 FXJS_PerIsolateData* FXJS_PerIsolateData::Get(v8::Isolate* pIsolate) { |
| 99 return static_cast<FXJS_PerIsolateData*>( | 104 return static_cast<FXJS_PerIsolateData*>( |
| 100 pIsolate->GetData(g_embedderDataSlot)); | 105 pIsolate->GetData(g_embedderDataSlot)); |
| 101 } | 106 } |
| 102 | 107 |
| 108 void FXJS_Initialize(unsigned int embedderDataSlot) { | |
| 109 g_embedderDataSlot = embedderDataSlot; | |
| 110 } | |
| 111 | |
| 112 void FXJS_Release() { | |
| 113 } | |
| 114 | |
| 103 int FXJS_DefineObj(v8::Isolate* pIsolate, | 115 int FXJS_DefineObj(v8::Isolate* pIsolate, |
| 104 const wchar_t* sObjName, | 116 const wchar_t* sObjName, |
| 105 FXJSOBJTYPE eObjType, | 117 FXJSOBJTYPE eObjType, |
| 106 FXJS_CONSTRUCTOR pConstructor, | 118 FXJS_CONSTRUCTOR pConstructor, |
| 107 FXJS_DESTRUCTOR pDestructor) { | 119 FXJS_DESTRUCTOR pDestructor) { |
| 108 v8::Isolate::Scope isolate_scope(pIsolate); | 120 v8::Isolate::Scope isolate_scope(pIsolate); |
| 109 v8::HandleScope handle_scope(pIsolate); | 121 v8::HandleScope handle_scope(pIsolate); |
| 110 | 122 |
| 111 FXJS_PerIsolateData::SetUp(pIsolate); | 123 FXJS_PerIsolateData::SetUp(pIsolate); |
| 112 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); | 124 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 v8::HandleScope handle_scope(pIsolate); | 273 v8::HandleScope handle_scope(pIsolate); |
| 262 | 274 |
| 263 v8::Global<v8::ObjectTemplate>& globalObjTemp = | 275 v8::Global<v8::ObjectTemplate>& globalObjTemp = |
| 264 _getGlobalObjectTemplate(pIsolate); | 276 _getGlobalObjectTemplate(pIsolate); |
| 265 v8::Local<v8::Context> v8Context = v8::Context::New( | 277 v8::Local<v8::Context> v8Context = v8::Context::New( |
| 266 pIsolate, NULL, | 278 pIsolate, NULL, |
| 267 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); | 279 v8::Local<v8::ObjectTemplate>::New(pIsolate, globalObjTemp)); |
| 268 v8::Context::Scope context_scope(v8Context); | 280 v8::Context::Scope context_scope(v8Context); |
| 269 | 281 |
| 270 FXJS_PerIsolateData::SetUp(pIsolate); | 282 FXJS_PerIsolateData::SetUp(pIsolate); |
| 271 v8::Local<v8::External> ptr = v8::External::New(pIsolate, pFXRuntime); | 283 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
| |
| 272 v8Context->SetEmbedderData(1, ptr); | 284 v8Context->SetEmbedderData(kPerContextDataIndex, ptr); |
| 273 | 285 |
| 274 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 286 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
| 275 for (int i = 0; i < maxID; ++i) { | 287 for (int i = 0; i < maxID; ++i) { |
| 276 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 288 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); |
| 277 CFX_WideString ws = CFX_WideString(pObjDef->objName); | 289 CFX_WideString ws = CFX_WideString(pObjDef->objName); |
| 278 CFX_ByteString bs = ws.UTF8Encode(); | 290 CFX_ByteString bs = ws.UTF8Encode(); |
| 279 v8::Local<v8::String> objName = | 291 v8::Local<v8::String> objName = |
| 280 v8::String::NewFromUtf8(pIsolate, bs.c_str(), | 292 v8::String::NewFromUtf8(pIsolate, bs.c_str(), |
| 281 v8::NewStringType::kNormal, | 293 v8::NewStringType::kNormal, |
| 282 bs.GetLength()).ToLocalChecked(); | 294 bs.GetLength()).ToLocalChecked(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 pObjDef->m_pDestructor(pObj); | 343 pObjDef->m_pDestructor(pObj); |
| 332 FXJS_FreePrivate(pObj); | 344 FXJS_FreePrivate(pObj); |
| 333 } | 345 } |
| 334 delete pObjDef; | 346 delete pObjDef; |
| 335 } | 347 } |
| 336 | 348 |
| 337 pIsolate->SetData(g_embedderDataSlot, nullptr); | 349 pIsolate->SetData(g_embedderDataSlot, nullptr); |
| 338 delete pData; | 350 delete pData; |
| 339 } | 351 } |
| 340 | 352 |
| 341 void FXJS_Initialize(unsigned int embedderDataSlot) { | 353 IFXJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { |
| 342 g_embedderDataSlot = embedderDataSlot; | 354 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 343 } | 355 v8::Local<v8::Value> v = context->GetEmbedderData(kPerContextDataIndex); |
| 344 | 356 if (v.IsEmpty()) |
| 345 void FXJS_Release() { | 357 return nullptr; |
| 358 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); | |
| 359 return static_cast<IFXJS_Runtime*>(field->Value()); | |
| 346 } | 360 } |
| 347 | 361 |
| 348 int FXJS_Execute(v8::Isolate* pIsolate, | 362 int FXJS_Execute(v8::Isolate* pIsolate, |
| 349 IFXJS_Context* pJSContext, | 363 IFXJS_Context* pJSContext, |
| 350 const wchar_t* script, | 364 const wchar_t* script, |
| 351 long length, | 365 long length, |
| 352 FXJSErr* pError) { | 366 FXJSErr* pError) { |
| 353 v8::Isolate::Scope isolate_scope(pIsolate); | 367 v8::Isolate::Scope isolate_scope(pIsolate); |
| 354 v8::TryCatch try_catch(pIsolate); | 368 v8::TryCatch try_catch(pIsolate); |
| 355 | 369 |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 return v8::Local<v8::Array>(); | 772 return v8::Local<v8::Array>(); |
| 759 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 773 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 760 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 774 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
| 761 } | 775 } |
| 762 | 776 |
| 763 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 777 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
| 764 pTo = pFrom; | 778 pTo = pFrom; |
| 765 } | 779 } |
| 766 | 780 |
| 767 | 781 |
| OLD | NEW |