| 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   v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pFXRuntime); | 
| 272   v8Context->SetEmbedderData(1, ptr); |  | 
| 273 | 284 | 
| 274   int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 285   int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 
| 275   for (int i = 0; i < maxID; ++i) { | 286   for (int i = 0; i < maxID; ++i) { | 
| 276     CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 287     CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 
| 277     CFX_WideString ws = CFX_WideString(pObjDef->objName); | 288     CFX_WideString ws = CFX_WideString(pObjDef->objName); | 
| 278     CFX_ByteString bs = ws.UTF8Encode(); | 289     CFX_ByteString bs = ws.UTF8Encode(); | 
| 279     v8::Local<v8::String> objName = | 290     v8::Local<v8::String> objName = | 
| 280         v8::String::NewFromUtf8(pIsolate, bs.c_str(), | 291         v8::String::NewFromUtf8(pIsolate, bs.c_str(), | 
| 281                                 v8::NewStringType::kNormal, | 292                                 v8::NewStringType::kNormal, | 
| 282                                 bs.GetLength()).ToLocalChecked(); | 293                                 bs.GetLength()).ToLocalChecked(); | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 331         pObjDef->m_pDestructor(pObj); | 342         pObjDef->m_pDestructor(pObj); | 
| 332       FXJS_FreePrivate(pObj); | 343       FXJS_FreePrivate(pObj); | 
| 333     } | 344     } | 
| 334     delete pObjDef; | 345     delete pObjDef; | 
| 335   } | 346   } | 
| 336 | 347 | 
| 337   pIsolate->SetData(g_embedderDataSlot, nullptr); | 348   pIsolate->SetData(g_embedderDataSlot, nullptr); | 
| 338   delete pData; | 349   delete pData; | 
| 339 } | 350 } | 
| 340 | 351 | 
| 341 void FXJS_Initialize(unsigned int embedderDataSlot) { | 352 IFXJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { | 
| 342   g_embedderDataSlot = embedderDataSlot; | 353   v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 
| 343 } | 354   return static_cast<IFXJS_Runtime*>( | 
| 344 | 355       context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); | 
| 345 void FXJS_Release() { |  | 
| 346 } | 356 } | 
| 347 | 357 | 
| 348 int FXJS_Execute(v8::Isolate* pIsolate, | 358 int FXJS_Execute(v8::Isolate* pIsolate, | 
| 349                  IFXJS_Context* pJSContext, | 359                  IFXJS_Context* pJSContext, | 
| 350                  const wchar_t* script, | 360                  const wchar_t* script, | 
| 351                  long length, | 361                  long length, | 
| 352                  FXJSErr* pError) { | 362                  FXJSErr* pError) { | 
| 353   v8::Isolate::Scope isolate_scope(pIsolate); | 363   v8::Isolate::Scope isolate_scope(pIsolate); | 
| 354   v8::TryCatch try_catch(pIsolate); | 364   v8::TryCatch try_catch(pIsolate); | 
| 355 | 365 | 
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 758     return v8::Local<v8::Array>(); | 768     return v8::Local<v8::Array>(); | 
| 759   v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 769   v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 
| 760   return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 770   return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 
| 761 } | 771 } | 
| 762 | 772 | 
| 763 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 773 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 
| 764   pTo = pFrom; | 774   pTo = pFrom; | 
| 765 } | 775 } | 
| 766 | 776 | 
| 767 | 777 | 
| OLD | NEW | 
|---|