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

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

Issue 1430213002: Remove CFX_PtrArray usage in fpdfsdk. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 1 month 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/Field.cpp ('k') | no next file » | 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 "../../include/jsapi/fxjs_v8.h" 7 #include "../../include/jsapi/fxjs_v8.h"
8 8
9 #include "core/include/fxcrt/fx_basic.h" 9 #include "core/include/fxcrt/fx_basic.h"
10 10
(...skipping 12 matching lines...) Expand all
23 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3. 23 // kPerContextDataStartIndex + kEmbedderPDFium, which is 3.
24 static const unsigned int kPerContextDataIndex = 3u; 24 static const unsigned int kPerContextDataIndex = 3u;
25 static unsigned int g_embedderDataSlot = 1u; 25 static unsigned int g_embedderDataSlot = 1u;
26 static v8::Isolate* g_isolate = nullptr; 26 static v8::Isolate* g_isolate = nullptr;
27 static size_t g_isolate_ref_count = 0; 27 static size_t g_isolate_ref_count = 0;
28 static FXJS_ArrayBufferAllocator* g_arrayBufferAllocator = nullptr; 28 static FXJS_ArrayBufferAllocator* g_arrayBufferAllocator = nullptr;
29 static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr; 29 static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr;
30 30
31 class CFXJS_PerObjectData { 31 class CFXJS_PerObjectData {
32 public: 32 public:
33 CFXJS_PerObjectData(int nObjDefID) 33 explicit CFXJS_PerObjectData(int nObjDefID)
34 : m_ObjDefID(nObjDefID), m_pPrivate(nullptr) {} 34 : m_ObjDefID(nObjDefID), m_pPrivate(nullptr) {}
35 35
36 int m_ObjDefID; 36 const int m_ObjDefID;
37 void* m_pPrivate; 37 void* m_pPrivate;
38 }; 38 };
39 39
40 class CFXJS_ObjDefinition { 40 class CFXJS_ObjDefinition {
41 public: 41 public:
42 static int MaxID(v8::Isolate* pIsolate) { 42 static int MaxID(v8::Isolate* pIsolate) {
43 return static_cast<int>( 43 return FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.size();
44 FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.GetSize());
45 } 44 }
45
46 static CFXJS_ObjDefinition* ForID(v8::Isolate* pIsolate, int id) { 46 static CFXJS_ObjDefinition* ForID(v8::Isolate* pIsolate, int id) {
47 // Note: GetAt() halts if out-of-range even in release builds. 47 // Note: GetAt() halts if out-of-range even in release builds.
48 return static_cast<CFXJS_ObjDefinition*>( 48 return FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray[id];
49 FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.GetAt(id));
50 } 49 }
50
51 CFXJS_ObjDefinition(v8::Isolate* isolate, 51 CFXJS_ObjDefinition(v8::Isolate* isolate,
52 const wchar_t* sObjName, 52 const wchar_t* sObjName,
53 FXJSOBJTYPE eObjType, 53 FXJSOBJTYPE eObjType,
54 FXJS_CONSTRUCTOR pConstructor, 54 FXJS_CONSTRUCTOR pConstructor,
55 FXJS_DESTRUCTOR pDestructor) 55 FXJS_DESTRUCTOR pDestructor)
56 : m_ObjName(sObjName), 56 : m_ObjName(sObjName),
57 m_ObjType(eObjType), 57 m_ObjType(eObjType),
58 m_pConstructor(pConstructor), 58 m_pConstructor(pConstructor),
59 m_pDestructor(pDestructor), 59 m_pDestructor(pDestructor),
60 m_pIsolate(isolate) { 60 m_pIsolate(isolate) {
61 v8::Isolate::Scope isolate_scope(isolate); 61 v8::Isolate::Scope isolate_scope(isolate);
62 v8::HandleScope handle_scope(isolate); 62 v8::HandleScope handle_scope(isolate);
63 63
64 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); 64 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
65 fun->InstanceTemplate()->SetInternalFieldCount(2); 65 fun->InstanceTemplate()->SetInternalFieldCount(2);
66 m_FunctionTemplate.Reset(isolate, fun); 66 m_FunctionTemplate.Reset(isolate, fun);
67 67
68 v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun); 68 v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun);
69 m_Signature.Reset(isolate, sig); 69 m_Signature.Reset(isolate, sig);
70 } 70 }
71 71
72 int AssignID() { 72 int AssignID() {
73 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_pIsolate); 73 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_pIsolate);
74 pData->m_ObjectDefnArray.Add(this); 74 pData->m_ObjectDefnArray.push_back(this);
75 return pData->m_ObjectDefnArray.GetSize() - 1; 75 return pData->m_ObjectDefnArray.size() - 1;
76 } 76 }
77 77
78 v8::Local<v8::ObjectTemplate> GetInstanceTemplate() { 78 v8::Local<v8::ObjectTemplate> GetInstanceTemplate() {
79 v8::EscapableHandleScope scope(m_pIsolate); 79 v8::EscapableHandleScope scope(m_pIsolate);
80 v8::Local<v8::FunctionTemplate> function = 80 v8::Local<v8::FunctionTemplate> function =
81 m_FunctionTemplate.Get(m_pIsolate); 81 m_FunctionTemplate.Get(m_pIsolate);
82 return scope.Escape(function->InstanceTemplate()); 82 return scope.Escape(function->InstanceTemplate());
83 } 83 }
84 84
85 v8::Local<v8::Signature> GetSignature() { 85 v8::Local<v8::Signature> GetSignature() {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 return v8::Local<v8::Array>(); 546 return v8::Local<v8::Array>();
547 v8::Local<v8::Array> val; 547 v8::Local<v8::Array> val;
548 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val)) 548 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val))
549 return v8::Local<v8::Array>(); 549 return v8::Local<v8::Array>();
550 return val; 550 return val;
551 } 551 }
552 552
553 void FXJS_PutObjectString(v8::Isolate* pIsolate, 553 void FXJS_PutObjectString(v8::Isolate* pIsolate,
554 v8::Local<v8::Object> pObj, 554 v8::Local<v8::Object> pObj,
555 const wchar_t* PropertyName, 555 const wchar_t* PropertyName,
556 const wchar_t* sValue) // VT_string 556 const wchar_t* sValue) {
557 {
558 if (pObj.IsEmpty()) 557 if (pObj.IsEmpty())
559 return; 558 return;
560 pObj->Set(pIsolate->GetCurrentContext(), 559 pObj->Set(pIsolate->GetCurrentContext(),
561 FXJS_WSToJSString(pIsolate, PropertyName), 560 FXJS_WSToJSString(pIsolate, PropertyName),
562 FXJS_WSToJSString(pIsolate, sValue)).FromJust(); 561 FXJS_WSToJSString(pIsolate, sValue)).FromJust();
563 } 562 }
564 563
565 void FXJS_PutObjectNumber(v8::Isolate* pIsolate, 564 void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
566 v8::Local<v8::Object> pObj, 565 v8::Local<v8::Object> pObj,
567 const wchar_t* PropertyName, 566 const wchar_t* PropertyName,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 return v8::Local<v8::Array>(); 744 return v8::Local<v8::Array>();
746 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 745 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
747 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 746 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
748 } 747 }
749 748
750 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 749 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
751 pTo = pFrom; 750 pTo = pFrom;
752 } 751 }
753 752
754 753
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/Field.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698