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

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

Issue 1416113010: Merge to XFA: Remove CFX_PtrArray usage in fpdfsdk. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return v8::Local<v8::Array>(); 551 return v8::Local<v8::Array>();
552 v8::Local<v8::Array> val; 552 v8::Local<v8::Array> val;
553 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val)) 553 if (!pObj->GetPropertyNames(pIsolate->GetCurrentContext()).ToLocal(&val))
554 return v8::Local<v8::Array>(); 554 return v8::Local<v8::Array>();
555 return val; 555 return val;
556 } 556 }
557 557
558 void FXJS_PutObjectString(v8::Isolate* pIsolate, 558 void FXJS_PutObjectString(v8::Isolate* pIsolate,
559 v8::Local<v8::Object> pObj, 559 v8::Local<v8::Object> pObj,
560 const wchar_t* PropertyName, 560 const wchar_t* PropertyName,
561 const wchar_t* sValue) // VT_string 561 const wchar_t* sValue) {
562 {
563 if (pObj.IsEmpty()) 562 if (pObj.IsEmpty())
564 return; 563 return;
565 pObj->Set(pIsolate->GetCurrentContext(), 564 pObj->Set(pIsolate->GetCurrentContext(),
566 FXJS_WSToJSString(pIsolate, PropertyName), 565 FXJS_WSToJSString(pIsolate, PropertyName),
567 FXJS_WSToJSString(pIsolate, sValue)).FromJust(); 566 FXJS_WSToJSString(pIsolate, sValue)).FromJust();
568 } 567 }
569 568
570 void FXJS_PutObjectNumber(v8::Isolate* pIsolate, 569 void FXJS_PutObjectNumber(v8::Isolate* pIsolate,
571 v8::Local<v8::Object> pObj, 570 v8::Local<v8::Object> pObj,
572 const wchar_t* PropertyName, 571 const wchar_t* PropertyName,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 return v8::Local<v8::Array>(); 749 return v8::Local<v8::Array>();
751 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 750 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
752 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 751 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
753 } 752 }
754 753
755 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 754 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
756 pTo = pFrom; 755 pTo = pFrom;
757 } 756 }
758 757
759 758
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