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

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

Issue 1263963002: Merge to XFA: Plumb in an externally created v8::Isolate (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 4 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') | public/fpdf_formfill.h » ('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 "../../../core/include/fxcrt/fx_ext.h" 8 #include "../../../core/include/fxcrt/fx_ext.h"
9 #include "../../include/jsapi/fxjs_v8.h" 9 #include "../../include/jsapi/fxjs_v8.h"
10 #include "../../include/fsdk_define.h" 10 #include "../../include/fsdk_define.h"
11 #include "time.h" 11 #include "time.h"
12 #include <cmath> 12 #include <cmath>
13 #include <limits> 13 #include <limits>
14 14
15 #define VALUE_NAME_STRING L"string" 15 #define VALUE_NAME_STRING L"string"
16 #define VALUE_NAME_NUMBER L"number" 16 #define VALUE_NAME_NUMBER L"number"
17 #define VALUE_NAME_BOOLEAN L"boolean" 17 #define VALUE_NAME_BOOLEAN L"boolean"
18 #define VALUE_NAME_DATE L"date" 18 #define VALUE_NAME_DATE L"date"
19 #define VALUE_NAME_OBJECT L"object" 19 #define VALUE_NAME_OBJECT L"object"
20 #define VALUE_NAME_FXOBJ L"fxobj" 20 #define VALUE_NAME_FXOBJ L"fxobj"
21 #define VALUE_NAME_NULL L"null" 21 #define VALUE_NAME_NULL L"null"
22 #define VALUE_NAME_UNDEFINED L"undefined" 22 #define VALUE_NAME_UNDEFINED L"undefined"
23 23
24 const static FX_DWORD g_nan[2] = {0,0x7FF80000 }; 24 const static FX_DWORD g_nan[2] = {0,0x7FF80000 };
25 static double GetNan() 25 static double GetNan()
26 { 26 {
27 return *(double*)g_nan; 27 return *(double*)g_nan;
28 } 28 }
29 static unsigned int g_embedderDataSlot = 0u;
29 30
30 31
31 class CJS_PrivateData 32 class CJS_PrivateData
32 { 33 {
33 public: 34 public:
34 CJS_PrivateData():ObjDefID(-1), pPrivate(NULL) {} 35 CJS_PrivateData():ObjDefID(-1), pPrivate(NULL) {}
35 int ObjDefID; 36 int ObjDefID;
36 void* pPrivate; 37 void* pPrivate;
37 }; 38 };
38 39
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 72
72 v8::Global<v8::ObjectTemplate> m_objTemplate; 73 v8::Global<v8::ObjectTemplate> m_objTemplate;
73 v8::Global<v8::Object> m_StaticObj; 74 v8::Global<v8::Object> m_StaticObj;
74 }; 75 };
75 76
76 int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e ObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor) 77 int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e ObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor)
77 { 78 {
78 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 79 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
79 v8::Isolate::Scope isolate_scope(isolate); 80 v8::Isolate::Scope isolate_scope(isolate);
80 v8::HandleScope handle_scope(isolate); 81 v8::HandleScope handle_scope(isolate);
81 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 82 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
82 if(!pArray) 83 if(!pArray)
83 { 84 {
84 pArray = FX_NEW CFX_PtrArray(); 85 pArray = FX_NEW CFX_PtrArray();
85 » » isolate->SetData(1, pArray); 86 » » isolate->SetData(g_embedderDataSlot, pArray);
86 } 87 }
87 CJS_ObjDefintion* pObjDef = FX_NEW CJS_ObjDefintion(isolate, sObjName, e ObjType, pConstructor, pDestructor); 88 CJS_ObjDefintion* pObjDef = FX_NEW CJS_ObjDefintion(isolate, sObjName, e ObjType, pConstructor, pDestructor);
88 pArray->Add(pObjDef); 89 pArray->Add(pObjDef);
89 return pArray->GetSize()-1; 90 return pArray->GetSize()-1;
90 } 91 }
91 92
92 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s MethodName, v8::FunctionCallback pMethodCall) 93 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s MethodName, v8::FunctionCallback pMethodCall)
93 { 94 {
94 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 95 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
95 v8::Isolate::Scope isolate_scope(isolate); 96 v8::Isolate::Scope isolate_scope(isolate);
96 v8::HandleScope handle_scope(isolate); 97 v8::HandleScope handle_scope(isolate);
97 98
98 CFX_WideString ws = CFX_WideString(sMethodName); 99 CFX_WideString ws = CFX_WideString(sMethodName);
99 CFX_ByteString bsMethodName = ws.UTF8Encode(); 100 CFX_ByteString bsMethodName = ws.UTF8Encode();
100 101
101 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 102 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
102 if(!pArray) return 0; 103 if(!pArray) return 0;
103 104
104 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; 105 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
105 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ; 106 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ;
106 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate); 107 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate);
107 objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), v8:: NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, pMe thodCall), v8::ReadOnly); 108 objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), v8:: NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, pMe thodCall), v8::ReadOnly);
108 pObjDef->m_objTemplate.Reset(isolate,objTemp); 109 pObjDef->m_objTemplate.Reset(isolate,objTemp);
109 return 0; 110 return 0;
110 } 111 }
111 112
112 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro pPut) 113 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro pPut)
113 { 114 {
114 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 115 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
115 v8::Isolate::Scope isolate_scope(isolate); 116 v8::Isolate::Scope isolate_scope(isolate);
116 v8::HandleScope handle_scope(isolate); 117 v8::HandleScope handle_scope(isolate);
117 118
118 CFX_WideString ws = CFX_WideString(sPropName); 119 CFX_WideString ws = CFX_WideString(sPropName);
119 CFX_ByteString bsPropertyName = ws.UTF8Encode(); 120 CFX_ByteString bsPropertyName = ws.UTF8Encode();
120 121
121 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 122 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
122 if(!pArray) return 0; 123 if(!pArray) return 0;
123 124
124 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; 125 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
125 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ; 126 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ;
126 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate); 127 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate);
127 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, bsPropertyName.c_s tr(), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut); 128 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, bsPropertyName.c_s tr(), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut);
128 pObjDef->m_objTemplate.Reset(isolate,objTemp); 129 pObjDef->m_objTemplate.Reset(isolate,objTemp);
129 return 0; 130 return 0;
130 } 131 }
131 132
132 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::N amedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pProp Del) 133 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::N amedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet, v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pProp Del)
133 { 134 {
134 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 135 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
135 v8::Isolate::Scope isolate_scope(isolate); 136 v8::Isolate::Scope isolate_scope(isolate);
136 v8::HandleScope handle_scope(isolate); 137 v8::HandleScope handle_scope(isolate);
137 138
138 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 139 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
139 if(!pArray) return 0; 140 if(!pArray) return 0;
140 141
141 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; 142 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
142 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ; 143 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ;
143 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate); 144 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate);
144 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDe l); 145 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDe l);
145 pObjDef->m_objTemplate.Reset(isolate,objTemp); 146 pObjDef->m_objTemplate.Reset(isolate,objTemp);
146 return 0; 147 return 0;
147 } 148 }
148 149
149 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC onstName, v8::Local<v8::Value> pDefault) 150 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC onstName, v8::Local<v8::Value> pDefault)
150 { 151 {
151 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 152 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
152 v8::Isolate::Scope isolate_scope(isolate); 153 v8::Isolate::Scope isolate_scope(isolate);
153 v8::HandleScope handle_scope(isolate); 154 v8::HandleScope handle_scope(isolate);
154 155
155 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 156 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
156 if(!pArray) return 0; 157 if(!pArray) return 0;
157 158
158 CFX_WideString ws = CFX_WideString(sConstName); 159 CFX_WideString ws = CFX_WideString(sConstName);
159 CFX_ByteString bsConstName = ws.UTF8Encode(); 160 CFX_ByteString bsConstName = ws.UTF8Encode();
160 161
161 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; 162 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
162 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ; 163 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ;
163 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate); 164 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate);
164 objTemp->Set(isolate, bsConstName.c_str(), pDefault); 165 objTemp->Set(isolate, bsConstName.c_str(), pDefault);
165 pObjDef->m_objTemplate.Reset(isolate,objTemp); 166 pObjDef->m_objTemplate.Reset(isolate,objTemp);
166 return 0; 167 return 0;
167 } 168 }
168 169
169 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS Runtime) 170 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS Runtime)
170 { 171 {
171 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 172 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
172 v8::Isolate::Scope isolate_scope(isolate); 173 v8::Isolate::Scope isolate_scope(isolate);
173 v8::HandleScope handle_scope(isolate); 174 v8::HandleScope handle_scope(isolate);
174 175
175 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 176 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
176 ASSERT(pArray != NULL); 177 ASSERT(pArray != NULL);
177 for(int i=0; i<pArray->GetSize(); i++) 178 for(int i=0; i<pArray->GetSize(); i++)
178 { 179 {
179 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 180 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
180 if(pObjDef->m_bSetAsGlobalObject) 181 if(pObjDef->m_bSetAsGlobalObject)
181 return pObjDef->m_objTemplate; 182 return pObjDef->m_objTemplate;
182 } 183 }
183 static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate; 184 static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate;
184 return gloabalObjectTemplate; 185 return gloabalObjectTemplate;
185 } 186 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 v8::Isolate::Scope isolate_scope(isolate); 239 v8::Isolate::Scope isolate_scope(isolate);
239 v8::Locker locker(isolate); 240 v8::Locker locker(isolate);
240 v8::HandleScope handle_scope(isolate); 241 v8::HandleScope handle_scope(isolate);
241 242
242 v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate (pJSRuntime); 243 v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate (pJSRuntime);
243 v8::Local<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::L ocal<v8::ObjectTemplate>::New(isolate, globalObjTemp)); 244 v8::Local<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::L ocal<v8::ObjectTemplate>::New(isolate, globalObjTemp));
244 v8::Context::Scope context_scope(v8Context); 245 v8::Context::Scope context_scope(v8Context);
245 246
246 //v8::Local<External> ptr = External::New(isolate, pFXRuntime); 247 //v8::Local<External> ptr = External::New(isolate, pFXRuntime);
247 //v8Context->SetEmbedderData(1, ptr); 248 //v8Context->SetEmbedderData(1, ptr);
249 // TODO(tsepez): Don't use more than one embedder data slot.
248 isolate->SetData(2, pFXRuntime); 250 isolate->SetData(2, pFXRuntime);
249 251
250 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 252 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
251 if(!pArray) return; 253 if(!pArray) return;
252 254
253 for(int i=0; i<pArray->GetSize(); i++) 255 for(int i=0; i<pArray->GetSize(); i++)
254 { 256 {
255 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 257 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
256 CFX_WideString ws = CFX_WideString(pObjDef->objName); 258 CFX_WideString ws = CFX_WideString(pObjDef->objName);
257 CFX_ByteString bs = ws.UTF8Encode(); 259 CFX_ByteString bs = ws.UTF8Encode();
258 v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); 260 v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked();
259 261
260 262
(...skipping 23 matching lines...) Expand all
284 v8PersistentContext.Reset(isolate, v8Context); 286 v8PersistentContext.Reset(isolate, v8Context);
285 } 287 }
286 288
287 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi stentContext) 289 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi stentContext)
288 { 290 {
289 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 291 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
290 v8::Isolate::Scope isolate_scope(isolate); 292 v8::Isolate::Scope isolate_scope(isolate);
291 v8::Locker locker(isolate); 293 v8::Locker locker(isolate);
292 v8::HandleScope handle_scope(isolate); 294 v8::HandleScope handle_scope(isolate);
293 295
294 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 296 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
295 if(!pArray) return ; 297 if(!pArray) return ;
296 298
297 for(int i=0; i<pArray->GetSize(); i++) 299 for(int i=0; i<pArray->GetSize(); i++)
298 { 300 {
299 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 301 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
300 if(!pObjDef->m_StaticObj.IsEmpty()) 302 if(!pObjDef->m_StaticObj.IsEmpty())
301 { 303 {
302 v8::Local<v8::Object> pObj = v8::Local<v8::Object>::New( isolate, pObjDef->m_StaticObj); 304 v8::Local<v8::Object> pObj = v8::Local<v8::Object>::New( isolate, pObjDef->m_StaticObj);
303 if(pObjDef->m_pDestructor) 305 if(pObjDef->m_pDestructor)
304 pObjDef->m_pDestructor(pObj); 306 pObjDef->m_pDestructor(pObj);
305 JS_FreePrivate(pObj); 307 JS_FreePrivate(pObj);
306 } 308 }
307 delete pObjDef; 309 delete pObjDef;
308 } 310 }
309 delete pArray; 311 delete pArray;
310 isolate->SetData(1,NULL); 312 isolate->SetData(1,NULL);
313 isolate->SetData(g_embedderDataSlot,NULL);
314 // TODO(tsepez): Don't use more than one embedder data slot.
311 isolate->SetData(2,NULL); 315 isolate->SetData(2,NULL);
312 } 316 }
313 317
314 void JS_Initial() 318 void JS_Initial(unsigned int embedderDataSlot)
315 { 319 {
320 g_embedderDataSlot = embedderDataSlot;
316 } 321 }
317 void JS_Release() 322 void JS_Release()
318 { 323 {
319 324
320 } 325 }
321 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror) 326 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror)
322 { 327 {
323 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 328 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
324 v8::Isolate::Scope isolate_scope(isolate); 329 v8::Isolate::Scope isolate_scope(isolate);
325 v8::TryCatch try_catch(isolate); 330 v8::TryCatch try_catch(isolate);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 v8::Isolate::Scope isolate_scope(isolate); 372 v8::Isolate::Scope isolate_scope(isolate);
368 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 373 v8::Local<v8::Context> context = isolate->GetCurrentContext();
369 if(-1 == nObjDefnID) 374 if(-1 == nObjDefnID)
370 { 375 {
371 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New (isolate); 376 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New (isolate);
372 v8::Local<v8::Object> obj; 377 v8::Local<v8::Object> obj;
373 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; 378 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj;
374 return v8::Local<v8::Object>(); 379 return v8::Local<v8::Object>();
375 } 380 }
376 381
377 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 382 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
378 if(!pArray) return v8::Local<v8::Object>(); 383 if(!pArray) return v8::Local<v8::Object>();
379 384
380 385
381 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8:: Object>(); 386 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8:: Object>();
382 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ; 387 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ;
383 388
384 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate); 389 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N ew(isolate, pObjDef->m_objTemplate);
385 v8::Local<v8::Object> obj; 390 v8::Local<v8::Object> obj;
386 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O bject>(); 391 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O bject>();
387 CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData; 392 CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData;
388 pPrivateData->ObjDefID = nObjDefnID; 393 pPrivateData->ObjDefID = nObjDefnID;
389 394
390 obj->SetAlignedPointerInInternalField(0, pPrivateData); 395 obj->SetAlignedPointerInInternalField(0, pPrivateData);
391 if(pObjDef->m_pConstructor) 396 if(pObjDef->m_pConstructor)
392 pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP rototype()->ToObject(context).ToLocalChecked()); 397 pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP rototype()->ToObject(context).ToLocalChecked());
393 398
394 return obj; 399 return obj;
395 } 400 }
396 401
397 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) 402 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID)
398 { 403 {
399 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 404 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
400 v8::Isolate::Scope isolate_scope(isolate); 405 v8::Isolate::Scope isolate_scope(isolate);
401 406
402 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 407 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
403 if(!pArray) return v8::Local<v8::Object>(); 408 if(!pArray) return v8::Local<v8::Object>();
404 409
405 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8:: Object>(); 410 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8:: Object>();
406 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ; 411 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID) ;
407 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef-> m_StaticObj); 412 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef-> m_StaticObj);
408 return obj; 413 return obj;
409 } 414 }
410 415
411 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) 416 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID)
412 { 417 {
413 //Do nothing. 418 //Do nothing.
414 } 419 }
415 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime) 420 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime)
416 { 421 {
417 //Return the global object. 422 //Return the global object.
418 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 423 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
419 v8::Isolate::Scope isolate_scope(isolate); 424 v8::Isolate::Scope isolate_scope(isolate);
420 425
421 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 426 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
422 if(!pArray) return v8::Local<v8::Object>(); 427 if(!pArray) return v8::Local<v8::Object>();
423 428
424 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 429 v8::Local<v8::Context> context = isolate->GetCurrentContext();
425 return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck ed(); 430 return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck ed();
426 } 431 }
427 432
428 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) 433 int JS_GetObjDefnID(v8::Local<v8::Object> pObj)
429 { 434 {
430 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; 435 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1;
431 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe rFromInternalField(0); 436 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe rFromInternalField(0);
432 if(pPrivateData) 437 if(pPrivateData)
433 return pPrivateData->ObjDefID; 438 return pPrivateData->ObjDefID;
434 return -1; 439 return -1;
435 } 440 }
436 441
437 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) 442 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj)
438 { 443 {
439 if(pObj.IsEmpty()) return NULL; 444 if(pObj.IsEmpty()) return NULL;
440 v8::Local<v8::Context> context = pObj->CreationContext(); 445 v8::Local<v8::Context> context = pObj->CreationContext();
441 if(context.IsEmpty()) return NULL; 446 if(context.IsEmpty()) return NULL;
442 return context->GetIsolate(); 447 return context->GetIsolate();
443 } 448 }
444 449
445 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) 450 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName)
446 { 451 {
447 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; 452 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
448 v8::Isolate::Scope isolate_scope(isolate); 453 v8::Isolate::Scope isolate_scope(isolate);
449 454
450 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); 455 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo t);
451 if(!pArray) return -1; 456 if(!pArray) return -1;
452 457
453 for(int i=0; i<pArray->GetSize(); i++) 458 for(int i=0; i<pArray->GetSize(); i++)
454 { 459 {
455 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); 460 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i);
456 if(FXSYS_wcscmp(pObjDef->objName, pObjName) == 0) 461 if(FXSYS_wcscmp(pObjDef->objName, pObjName) == 0)
457 return i; 462 return i;
458 } 463 }
459 return -1; 464 return -1;
460 } 465 }
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 { 1066 {
1062 return d != d; 1067 return d != d;
1063 } 1068 }
1064 1069
1065 double JS_LocalTime(double d) 1070 double JS_LocalTime(double d)
1066 { 1071 {
1067 return JS_GetDateTime() + _getDaylightSavingTA(d); 1072 return JS_GetDateTime() + _getDaylightSavingTA(d);
1068 } 1073 }
1069 1074
1070 //JavaScript time implement End. 1075 //JavaScript time implement End.
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | public/fpdf_formfill.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698