| 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 "../../../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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 class CJS_ObjDefintion | 40 class CJS_ObjDefintion |
| 41 { | 41 { |
| 42 public: | 42 public: |
| 43 CJS_ObjDefintion(v8::Isolate* isolate, const wchar_t* sObjName, FXJSOBJT
YPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned b
ApplyNew): | 43 CJS_ObjDefintion(v8::Isolate* isolate, const wchar_t* sObjName, FXJSOBJT
YPE eObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned b
ApplyNew): |
| 44 objName(sObjName), objType(eObjType), m_pConstructor(pConstructor), m_
pDestructor(pDestructor),m_bApplyNew(bApplyNew),m_bSetAsGlobalObject(FALSE) | 44 objName(sObjName), objType(eObjType), m_pConstructor(pConstructor), m_
pDestructor(pDestructor),m_bApplyNew(bApplyNew),m_bSetAsGlobalObject(FALSE) |
| 45 { | 45 { |
| 46 v8::Isolate::Scope isolate_scope(isolate); | 46 v8::Isolate::Scope isolate_scope(isolate); |
| 47 v8::HandleScope handle_scope(isolate); | 47 v8::HandleScope handle_scope(isolate); |
| 48 | 48 |
| 49 » » v8::Handle<v8::ObjectTemplate> objTemplate = v8::ObjectTemplat
e::New(isolate); | 49 » » v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate
::New(isolate); |
| 50 objTemplate->SetInternalFieldCount(2); | 50 objTemplate->SetInternalFieldCount(2); |
| 51 m_objTemplate.Reset(isolate, objTemplate); | 51 m_objTemplate.Reset(isolate, objTemplate); |
| 52 | 52 |
| 53 //Document as the global object. | 53 //Document as the global object. |
| 54 if(FXSYS_wcscmp(sObjName, L"Document") == 0) | 54 if(FXSYS_wcscmp(sObjName, L"Document") == 0) |
| 55 { | 55 { |
| 56 m_bSetAsGlobalObject = TRUE; | 56 m_bSetAsGlobalObject = TRUE; |
| 57 } | 57 } |
| 58 | 58 |
| 59 } | 59 } |
| 60 ~CJS_ObjDefintion() | 60 ~CJS_ObjDefintion() |
| 61 { | 61 { |
| 62 m_objTemplate.Reset(); | 62 m_objTemplate.Reset(); |
| 63 m_StaticObj.Reset(); | 63 m_StaticObj.Reset(); |
| 64 } | 64 } |
| 65 public: | 65 public: |
| 66 const wchar_t* objName; | 66 const wchar_t* objName; |
| 67 FXJSOBJTYPE objType; | 67 FXJSOBJTYPE objType; |
| 68 LP_CONSTRUCTOR m_pConstructor; | 68 LP_CONSTRUCTOR m_pConstructor; |
| 69 LP_DESTRUCTOR m_pDestructor; | 69 LP_DESTRUCTOR m_pDestructor; |
| 70 unsigned m_bApplyNew; | 70 unsigned m_bApplyNew; |
| 71 FX_BOOL m_bSetAsGlobalObject; | 71 FX_BOOL m_bSetAsGlobalObject; |
| 72 | 72 |
| 73 » v8::Persistent<v8::ObjectTemplate> m_objTemplate; | 73 » v8::Global<v8::ObjectTemplate> m_objTemplate; |
| 74 » v8::Persistent<v8::Object> m_StaticObj; | 74 » v8::Global<v8::Object> m_StaticObj; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
ObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApply
New) | 77 int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
ObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApply
New) |
| 78 { | 78 { |
| 79 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 79 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 80 v8::Isolate::Scope isolate_scope(isolate); | 80 v8::Isolate::Scope isolate_scope(isolate); |
| 81 v8::HandleScope handle_scope(isolate); | 81 v8::HandleScope handle_scope(isolate); |
| 82 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 82 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 83 if(!pArray) | 83 if(!pArray) |
| 84 { | 84 { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if(!pArray) return 0; | 140 if(!pArray) return 0; |
| 141 | 141 |
| 142 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 142 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 143 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 143 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 144 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); |
| 145 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDe
l); | 145 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDe
l); |
| 146 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 146 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 147 return 0; | 147 return 0; |
| 148 } | 148 } |
| 149 | 149 |
| 150 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
onstName, v8::Handle<v8::Value> pDefault) | 150 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
onstName, v8::Local<v8::Value> pDefault) |
| 151 { | 151 { |
| 152 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 152 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 153 v8::Isolate::Scope isolate_scope(isolate); | 153 v8::Isolate::Scope isolate_scope(isolate); |
| 154 v8::HandleScope handle_scope(isolate); | 154 v8::HandleScope handle_scope(isolate); |
| 155 | 155 |
| 156 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 156 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 157 if(!pArray) return 0; | 157 if(!pArray) return 0; |
| 158 | 158 |
| 159 CFX_WideString ws = CFX_WideString(sConstName); | 159 CFX_WideString ws = CFX_WideString(sConstName); |
| 160 CFX_ByteString bsConstName = ws.UTF8Encode(); | 160 CFX_ByteString bsConstName = ws.UTF8Encode(); |
| 161 | 161 |
| 162 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 162 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 163 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 163 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 164 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); |
| 165 objTemp->Set(isolate, FX_LPCSTR(bsConstName), pDefault); | 165 objTemp->Set(isolate, FX_LPCSTR(bsConstName), pDefault); |
| 166 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 166 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 167 return 0; | 167 return 0; |
| 168 } | 168 } |
| 169 | 169 |
| 170 static v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime*
pJSRuntime) | 170 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
Runtime) |
| 171 { | 171 { |
| 172 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 172 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 173 v8::Isolate::Scope isolate_scope(isolate); | 173 v8::Isolate::Scope isolate_scope(isolate); |
| 174 v8::HandleScope handle_scope(isolate); | 174 v8::HandleScope handle_scope(isolate); |
| 175 | 175 |
| 176 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 176 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 177 ASSERT(pArray != NULL); | 177 ASSERT(pArray != NULL); |
| 178 for(int i=0; i<pArray->GetSize(); i++) | 178 for(int i=0; i<pArray->GetSize(); i++) |
| 179 { | 179 { |
| 180 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 180 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 181 if(pObjDef->m_bSetAsGlobalObject) | 181 if(pObjDef->m_bSetAsGlobalObject) |
| 182 return pObjDef->m_objTemplate; | 182 return pObjDef->m_objTemplate; |
| 183 } | 183 } |
| 184 » static v8::Persistent<v8::ObjectTemplate> gloabalObjectTemplate; | 184 » static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate; |
| 185 return gloabalObjectTemplate; | 185 return gloabalObjectTemplate; |
| 186 } | 186 } |
| 187 | 187 |
| 188 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v
8::FunctionCallback pMethodCall) | 188 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v
8::FunctionCallback pMethodCall) |
| 189 { | 189 { |
| 190 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 190 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 191 v8::Isolate::Scope isolate_scope(isolate); | 191 v8::Isolate::Scope isolate_scope(isolate); |
| 192 v8::HandleScope handle_scope(isolate); | 192 v8::HandleScope handle_scope(isolate); |
| 193 | 193 |
| 194 CFX_WideString ws = CFX_WideString(sMethodName); | 194 CFX_WideString ws = CFX_WideString(sMethodName); |
| 195 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 195 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
| 196 | 196 |
| 197 v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(iso
late, pMethodCall); | 197 v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(iso
late, pMethodCall); |
| 198 v8::Local<v8::ObjectTemplate> objTemp; | 198 v8::Local<v8::ObjectTemplate> objTemp; |
| 199 | 199 |
| 200 » v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 200 » v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate
(pJSRuntime); |
| 201 if(globalObjTemp.IsEmpty()) | 201 if(globalObjTemp.IsEmpty()) |
| 202 objTemp = v8::ObjectTemplate::New(isolate); | 202 objTemp = v8::ObjectTemplate::New(isolate); |
| 203 else | 203 else |
| 204 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); | 204 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); |
| 205 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v
8::NewStringType::kNormal).ToLocalChecked(), funTempl, v8::ReadOnly); | 205 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v
8::NewStringType::kNormal).ToLocalChecked(), funTempl, v8::ReadOnly); |
| 206 | 206 |
| 207 globalObjTemp.Reset(isolate,objTemp); | 207 globalObjTemp.Reset(isolate,objTemp); |
| 208 | 208 |
| 209 return 0; | 209 return 0; |
| 210 } | 210 } |
| 211 | 211 |
| 212 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
:Handle<v8::Value> pDefault) | 212 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
:Local<v8::Value> pDefault) |
| 213 { | 213 { |
| 214 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 214 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 215 v8::Isolate::Scope isolate_scope(isolate); | 215 v8::Isolate::Scope isolate_scope(isolate); |
| 216 v8::HandleScope handle_scope(isolate); | 216 v8::HandleScope handle_scope(isolate); |
| 217 | 217 |
| 218 CFX_WideString ws = CFX_WideString(sConstName); | 218 CFX_WideString ws = CFX_WideString(sConstName); |
| 219 CFX_ByteString bsConst= ws.UTF8Encode(); | 219 CFX_ByteString bsConst= ws.UTF8Encode(); |
| 220 | 220 |
| 221 v8::Local<v8::ObjectTemplate> objTemp; | 221 v8::Local<v8::ObjectTemplate> objTemp; |
| 222 | 222 |
| 223 » v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 223 » v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate
(pJSRuntime); |
| 224 if(globalObjTemp.IsEmpty()) | 224 if(globalObjTemp.IsEmpty()) |
| 225 objTemp = v8::ObjectTemplate::New(isolate); | 225 objTemp = v8::ObjectTemplate::New(isolate); |
| 226 else | 226 else |
| 227 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); | 227 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); |
| 228 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst), v8::Ne
wStringType::kNormal).ToLocalChecked(), pDefault, v8::ReadOnly); | 228 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst), v8::Ne
wStringType::kNormal).ToLocalChecked(), pDefault, v8::ReadOnly); |
| 229 | 229 |
| 230 globalObjTemp.Reset(isolate,objTemp); | 230 globalObjTemp.Reset(isolate,objTemp); |
| 231 | 231 |
| 232 return 0; | 232 return 0; |
| 233 } | 233 } |
| 234 | 234 |
| 235 | 235 |
| 236 void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
Context* context, v8::Persistent<v8::Context>& v8PersistentContext) | 236 void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
Context* context, v8::Global<v8::Context>& v8PersistentContext) |
| 237 { | 237 { |
| 238 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 238 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 239 v8::Isolate::Scope isolate_scope(isolate); | 239 v8::Isolate::Scope isolate_scope(isolate); |
| 240 v8::HandleScope handle_scope(isolate); | 240 v8::HandleScope handle_scope(isolate); |
| 241 | 241 |
| 242 » v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 242 » v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate
(pJSRuntime); |
| 243 » v8::Handle<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::
Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); | 243 » 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); | 244 v8::Context::Scope context_scope(v8Context); |
| 245 | 245 |
| 246 » v8::Handle<v8::External> ptr = v8::External::New(isolate, pFXRuntime); | 246 » v8::Local<v8::External> ptr = v8::External::New(isolate, pFXRuntime); |
| 247 v8Context->SetEmbedderData(1, ptr); | 247 v8Context->SetEmbedderData(1, ptr); |
| 248 | 248 |
| 249 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 249 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 250 if(!pArray) return; | 250 if(!pArray) return; |
| 251 | 251 |
| 252 for(int i=0; i<pArray->GetSize(); i++) | 252 for(int i=0; i<pArray->GetSize(); i++) |
| 253 { | 253 { |
| 254 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 254 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 255 CFX_WideString ws = CFX_WideString(pObjDef->objName); | 255 CFX_WideString ws = CFX_WideString(pObjDef->objName); |
| 256 CFX_ByteString bs = ws.UTF8Encode(); | 256 CFX_ByteString bs = ws.UTF8Encode(); |
| 257 » » v8::Handle<v8::String> objName = v8::String::NewFromUtf8(isolate
, bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); | 257 » » v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate,
bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); |
| 258 | 258 |
| 259 | 259 |
| 260 if(pObjDef->objType == JS_DYNAMIC) | 260 if(pObjDef->objType == JS_DYNAMIC) |
| 261 { | 261 { |
| 262 //Document is set as global object, need to construct it
first. | 262 //Document is set as global object, need to construct it
first. |
| 263 if(ws.Equal(L"Document")) | 263 if(ws.Equal(L"Document")) |
| 264 { | 264 { |
| 265 | 265 |
| 266 CJS_PrivateData* pPrivateData = new CJS_PrivateD
ata; | 266 CJS_PrivateData* pPrivateData = new CJS_PrivateD
ata; |
| 267 pPrivateData->ObjDefID = i; | 267 pPrivateData->ObjDefID = i; |
| 268 | 268 |
| 269 v8Context->Global()->GetPrototype()->ToObject(v8
Context).ToLocalChecked()->SetAlignedPointerInInternalField(0, pPrivateData); | 269 v8Context->Global()->GetPrototype()->ToObject(v8
Context).ToLocalChecked()->SetAlignedPointerInInternalField(0, pPrivateData); |
| 270 | 270 |
| 271 if(pObjDef->m_pConstructor) | 271 if(pObjDef->m_pConstructor) |
| 272 pObjDef->m_pConstructor(context, v8Conte
xt->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked(), v8Context->G
lobal()->GetPrototype()->ToObject(v8Context).ToLocalChecked()); | 272 pObjDef->m_pConstructor(context, v8Conte
xt->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked(), v8Context->G
lobal()->GetPrototype()->ToObject(v8Context).ToLocalChecked()); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 else | 275 else |
| 276 { | 276 { |
| 277 » » » v8::Handle<v8::Object> obj = JS_NewFxDynamicObj(pJSRunti
me, context, i); | 277 » » » v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntim
e, context, i); |
| 278 v8Context->Global()->Set(v8Context, objName, obj).FromJu
st(); | 278 v8Context->Global()->Set(v8Context, objName, obj).FromJu
st(); |
| 279 pObjDef->m_StaticObj.Reset(isolate, obj); | 279 pObjDef->m_StaticObj.Reset(isolate, obj); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 v8PersistentContext.Reset(isolate, v8Context); | 282 v8PersistentContext.Reset(isolate, v8Context); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8P
ersistentContext) | 285 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
stentContext) |
| 286 { | 286 { |
| 287 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 287 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 288 v8::Isolate::Scope isolate_scope(isolate); | 288 v8::Isolate::Scope isolate_scope(isolate); |
| 289 v8::HandleScope handle_scope(isolate); | 289 v8::HandleScope handle_scope(isolate); |
| 290 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8
PersistentContext); | 290 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8
PersistentContext); |
| 291 v8::Context::Scope context_scope(context); | 291 v8::Context::Scope context_scope(context); |
| 292 | 292 |
| 293 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 293 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 294 if(!pArray) return ; | 294 if(!pArray) return ; |
| 295 | 295 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 CFX_WideString wsScript(script); | 344 CFX_WideString wsScript(script); |
| 345 CFX_ByteString bsScript = wsScript.UTF8Encode(); | 345 CFX_ByteString bsScript = wsScript.UTF8Encode(); |
| 346 | 346 |
| 347 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 347 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 348 v8::Local<v8::Script> compiled_script; | 348 v8::Local<v8::Script> compiled_script; |
| 349 if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScr
ipt.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked())
.ToLocal(&compiled_script)) { | 349 if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScr
ipt.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked())
.ToLocal(&compiled_script)) { |
| 350 v8::String::Utf8Value error(try_catch.Exception()); | 350 v8::String::Utf8Value error(try_catch.Exception()); |
| 351 return -1; | 351 return -1; |
| 352 } | 352 } |
| 353 | 353 |
| 354 » v8::Handle<v8::Value> result; | 354 » v8::Local<v8::Value> result; |
| 355 if (!compiled_script->Run(context).ToLocal(&result)) { | 355 if (!compiled_script->Run(context).ToLocal(&result)) { |
| 356 v8::String::Utf8Value error(try_catch.Exception()); | 356 v8::String::Utf8Value error(try_catch.Exception()); |
| 357 return -1; | 357 return -1; |
| 358 } | 358 } |
| 359 return 0; | 359 return 0; |
| 360 } | 360 } |
| 361 | 361 |
| 362 v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context
* pJSContext, int nObjDefnID) | 362 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context*
pJSContext, int nObjDefnID) |
| 363 { | 363 { |
| 364 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 364 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 365 v8::Isolate::Scope isolate_scope(isolate); | 365 v8::Isolate::Scope isolate_scope(isolate); |
| 366 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 366 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 367 if(-1 == nObjDefnID) | 367 if(-1 == nObjDefnID) |
| 368 { | 368 { |
| 369 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); | 369 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); |
| 370 v8::Local<v8::Object> obj; | 370 v8::Local<v8::Object> obj; |
| 371 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; | 371 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; |
| 372 return v8::Handle<v8::Object>(); | 372 return v8::Local<v8::Object>(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 375 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 376 » if(!pArray) return v8::Handle<v8::Object>(); | 376 » if(!pArray) return v8::Local<v8::Object>(); |
| 377 | 377 |
| 378 | 378 |
| 379 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8:
:Object>(); | 379 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); |
| 380 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 380 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 381 | 381 |
| 382 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 382 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 383 v8::Local<v8::Object> obj; | 383 v8::Local<v8::Object> obj; |
| 384 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O
bject>(); | 384 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O
bject>(); |
| 385 | 385 |
| 386 CJS_PrivateData* pPrivateData = new CJS_PrivateData; | 386 CJS_PrivateData* pPrivateData = new CJS_PrivateData; |
| 387 pPrivateData->ObjDefID = nObjDefnID; | 387 pPrivateData->ObjDefID = nObjDefnID; |
| 388 | 388 |
| 389 obj->SetAlignedPointerInInternalField(0, pPrivateData); | 389 obj->SetAlignedPointerInInternalField(0, pPrivateData); |
| 390 if(pObjDef->m_pConstructor) | 390 if(pObjDef->m_pConstructor) |
| 391 pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject(context).ToLocalChecked()); | 391 pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject(context).ToLocalChecked()); |
| 392 | 392 |
| 393 return obj; | 393 return obj; |
| 394 } | 394 } |
| 395 | 395 |
| 396 v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) | 396 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) |
| 397 { | 397 { |
| 398 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 398 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 399 v8::Isolate::Scope isolate_scope(isolate); | 399 v8::Isolate::Scope isolate_scope(isolate); |
| 400 | 400 |
| 401 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 401 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 402 » if(!pArray) return v8::Handle<v8::Object>(); | 402 » if(!pArray) return v8::Local<v8::Object>(); |
| 403 | 403 |
| 404 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8:
:Object>(); | 404 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); |
| 405 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 405 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 406 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef->
m_StaticObj); | 406 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef->
m_StaticObj); |
| 407 return obj; | 407 return obj; |
| 408 } | 408 } |
| 409 | 409 |
| 410 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) | 410 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) |
| 411 { | 411 { |
| 412 //Do nothing. | 412 //Do nothing. |
| 413 } | 413 } |
| 414 v8::Handle<v8::Object>» JS_GetThisObj(IJS_Runtime * pJSRuntime) | 414 v8::Local<v8::Object>» JS_GetThisObj(IJS_Runtime * pJSRuntime) |
| 415 { | 415 { |
| 416 //Return the global object. | 416 //Return the global object. |
| 417 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 417 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 418 v8::Isolate::Scope isolate_scope(isolate); | 418 v8::Isolate::Scope isolate_scope(isolate); |
| 419 | 419 |
| 420 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 420 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 421 » if(!pArray) return v8::Handle<v8::Object>(); | 421 » if(!pArray) return v8::Local<v8::Object>(); |
| 422 | 422 |
| 423 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 423 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 424 return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck
ed(); | 424 return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck
ed(); |
| 425 } | 425 } |
| 426 | 426 |
| 427 int» JS_GetObjDefnID(v8::Handle<v8::Object> pObj) | 427 int» JS_GetObjDefnID(v8::Local<v8::Object> pObj) |
| 428 { | 428 { |
| 429 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; | 429 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; |
| 430 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); | 430 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); |
| 431 if(pPrivateData) | 431 if(pPrivateData) |
| 432 return pPrivateData->ObjDefID; | 432 return pPrivateData->ObjDefID; |
| 433 return -1; | 433 return -1; |
| 434 } | 434 } |
| 435 | 435 |
| 436 IJS_Runtime* JS_GetRuntime(v8::Handle<v8::Object> pObj) | 436 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) |
| 437 { | 437 { |
| 438 if(pObj.IsEmpty()) return NULL; | 438 if(pObj.IsEmpty()) return NULL; |
| 439 v8::Local<v8::Context> context = pObj->CreationContext(); | 439 v8::Local<v8::Context> context = pObj->CreationContext(); |
| 440 if(context.IsEmpty()) return NULL; | 440 if(context.IsEmpty()) return NULL; |
| 441 return context->GetIsolate(); | 441 return context->GetIsolate(); |
| 442 } | 442 } |
| 443 | 443 |
| 444 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) | 444 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) |
| 445 { | 445 { |
| 446 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 446 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 471 | 471 |
| 472 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) | 472 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) |
| 473 { | 473 { |
| 474 return (unsigned)FX_HashCode_String_GetW(main, nLen); | 474 return (unsigned)FX_HashCode_String_GetW(main, nLen); |
| 475 } | 475 } |
| 476 | 476 |
| 477 unsigned JS_CalcHash(const wchar_t* main) | 477 unsigned JS_CalcHash(const wchar_t* main) |
| 478 { | 478 { |
| 479 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); | 479 return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); |
| 480 } | 480 } |
| 481 const wchar_t*» JS_GetTypeof(v8::Handle<v8::Value> pObj) | 481 const wchar_t*» JS_GetTypeof(v8::Local<v8::Value> pObj) |
| 482 { | 482 { |
| 483 if(pObj.IsEmpty()) return NULL; | 483 if(pObj.IsEmpty()) return NULL; |
| 484 if(pObj->IsString()) | 484 if(pObj->IsString()) |
| 485 return VALUE_NAME_STRING; | 485 return VALUE_NAME_STRING; |
| 486 if(pObj->IsNumber()) | 486 if(pObj->IsNumber()) |
| 487 return VALUE_NAME_NUMBER; | 487 return VALUE_NAME_NUMBER; |
| 488 if(pObj->IsBoolean()) | 488 if(pObj->IsBoolean()) |
| 489 return VALUE_NAME_BOOLEAN; | 489 return VALUE_NAME_BOOLEAN; |
| 490 if(pObj->IsDate()) | 490 if(pObj->IsDate()) |
| 491 return VALUE_NAME_DATE; | 491 return VALUE_NAME_DATE; |
| 492 if(pObj->IsObject()) | 492 if(pObj->IsObject()) |
| 493 return VALUE_NAME_OBJECT; | 493 return VALUE_NAME_OBJECT; |
| 494 if(pObj->IsNull()) | 494 if(pObj->IsNull()) |
| 495 return VALUE_NAME_NULL; | 495 return VALUE_NAME_NULL; |
| 496 if(pObj->IsUndefined()) | 496 if(pObj->IsUndefined()) |
| 497 return VALUE_NAME_UNDEFINED; | 497 return VALUE_NAME_UNDEFINED; |
| 498 return NULL; | 498 return NULL; |
| 499 | 499 |
| 500 } | 500 } |
| 501 void JS_SetPrivate(v8::Handle<v8::Object> pObj, void* p) | 501 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) |
| 502 { | 502 { |
| 503 JS_SetPrivate(NULL, pObj, p); | 503 JS_SetPrivate(NULL, pObj, p); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void* JS_GetPrivate(v8::Handle<v8::Object> pObj) | 506 void* JS_GetPrivate(v8::Local<v8::Object> pObj) |
| 507 { | 507 { |
| 508 return JS_GetPrivate(NULL,pObj); | 508 return JS_GetPrivate(NULL,pObj); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj, void* p
) | 511 void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj, void* p) |
| 512 { | 512 { |
| 513 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; | 513 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; |
| 514 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPoint
erFromInternalField(0); | 514 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPoint
erFromInternalField(0); |
| 515 if(!pPrivateData) return; | 515 if(!pPrivateData) return; |
| 516 pPrivateData->pPrivate = p; | 516 pPrivateData->pPrivate = p; |
| 517 } | 517 } |
| 518 | 518 |
| 519 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj) | 519 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj) |
| 520 { | 520 { |
| 521 if(pObj.IsEmpty()) return NULL; | 521 if(pObj.IsEmpty()) return NULL; |
| 522 CJS_PrivateData* pPrivateData = NULL; | 522 CJS_PrivateData* pPrivateData = NULL; |
| 523 if(pObj->InternalFieldCount()) | 523 if(pObj->InternalFieldCount()) |
| 524 pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInte
rnalField(0); | 524 pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInte
rnalField(0); |
| 525 else | 525 else |
| 526 { | 526 { |
| 527 //It could be a global proxy object. | 527 //It could be a global proxy object. |
| 528 v8::Local<v8::Value> v = pObj->GetPrototype(); | 528 v8::Local<v8::Value> v = pObj->GetPrototype(); |
| 529 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 529 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 530 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 530 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 531 if(v->IsObject()) | 531 if(v->IsObject()) |
| 532 pPrivateData = (CJS_PrivateData*)v->ToObject(context).To
LocalChecked()->GetAlignedPointerFromInternalField(0); | 532 pPrivateData = (CJS_PrivateData*)v->ToObject(context).To
LocalChecked()->GetAlignedPointerFromInternalField(0); |
| 533 } | 533 } |
| 534 if(!pPrivateData) return NULL; | 534 if(!pPrivateData) return NULL; |
| 535 return pPrivateData->pPrivate; | 535 return pPrivateData->pPrivate; |
| 536 } | 536 } |
| 537 | 537 |
| 538 void JS_FreePrivate(void* pPrivateData) | 538 void JS_FreePrivate(void* pPrivateData) |
| 539 { | 539 { |
| 540 delete (CJS_PrivateData*)pPrivateData; | 540 delete (CJS_PrivateData*)pPrivateData; |
| 541 } | 541 } |
| 542 | 542 |
| 543 void JS_FreePrivate(v8::Handle<v8::Object> pObj) | 543 void JS_FreePrivate(v8::Local<v8::Object> pObj) |
| 544 { | 544 { |
| 545 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; | 545 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; |
| 546 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); | 546 JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); |
| 547 pObj->SetAlignedPointerInInternalField(0, NULL); | 547 pObj->SetAlignedPointerInInternalField(0, NULL); |
| 548 } | 548 } |
| 549 | 549 |
| 550 | 550 |
| 551 v8::Handle<v8::Value> JS_GetObjectValue(v8::Handle<v8::Object> pObj) | 551 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) |
| 552 { | 552 { |
| 553 return pObj; | 553 return pObj; |
| 554 } | 554 } |
| 555 | 555 |
| 556 v8::Handle<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prop
ertyName, int Len = -1) | 556 v8::Local<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prope
rtyName, int Len = -1) |
| 557 { | 557 { |
| 558 CFX_WideString ws = CFX_WideString(PropertyName,Len); | 558 CFX_WideString ws = CFX_WideString(PropertyName,Len); |
| 559 CFX_ByteString bs = ws.UTF8Encode(); | 559 CFX_ByteString bs = ws.UTF8Encode(); |
| 560 if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); | 560 if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); |
| 561 return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), v8::NewStringType
::kNormal).ToLocalChecked(); | 561 return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), v8::NewStringType
::kNormal).ToLocalChecked(); |
| 562 } | 562 } |
| 563 | 563 |
| 564 v8::Handle<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8
::Object> pObj,const wchar_t* PropertyName) | 564 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Local<v8::
Object> pObj,const wchar_t* PropertyName) |
| 565 { | 565 { |
| 566 » if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 566 » if(pObj.IsEmpty()) return v8::Local<v8::Value>(); |
| 567 v8::Local<v8::Value> val; | 567 v8::Local<v8::Value> val; |
| 568 » if (!pObj->Get(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,
PropertyName)).ToLocal(&val)) return v8::Handle<v8::Value>(); | 568 » if (!pObj->Get(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,
PropertyName)).ToLocal(&val)) return v8::Local<v8::Value>(); |
| 569 return val; | 569 return val; |
| 570 } | 570 } |
| 571 | 571 |
| 572 v8::Handle<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Hand
le<v8::Object> pObj) | 572 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Local
<v8::Object> pObj) |
| 573 { | 573 { |
| 574 » if(pObj.IsEmpty()) return v8::Handle<v8::Array>(); | 574 » if(pObj.IsEmpty()) return v8::Local<v8::Array>(); |
| 575 v8::Local<v8::Array> val; | 575 v8::Local<v8::Array> val; |
| 576 if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&va
l)) return v8::Local<v8::Array>(); | 576 if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&va
l)) return v8::Local<v8::Array>(); |
| 577 return val; | 577 return val; |
| 578 } | 578 } |
| 579 | 579 |
| 580 void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, const wchar_t* sValue) //VT_string | 580 void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, const wchar_t* sValue) //VT_string |
| 581 { | 581 { |
| 582 if(pObj.IsEmpty()) return; | 582 if(pObj.IsEmpty()) return; |
| 583 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime, Prop
ertyName), WSToJSString(pJSRuntime, sValue)).FromJust(); | 583 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime, Prop
ertyName), WSToJSString(pJSRuntime, sValue)).FromJust(); |
| 584 } | 584 } |
| 585 | 585 |
| 586 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, int nValue) | 586 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, int nValue) |
| 587 { | 587 { |
| 588 if(pObj.IsEmpty()) return; | 588 if(pObj.IsEmpty()) return; |
| 589 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Int32::New(pJSRuntime, nValue)).FromJust(); | 589 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Int32::New(pJSRuntime, nValue)).FromJust(); |
| 590 } | 590 } |
| 591 | 591 |
| 592 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, float fValue) | 592 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, float fValue) |
| 593 { | 593 { |
| 594 if(pObj.IsEmpty()) return; | 594 if(pObj.IsEmpty()) return; |
| 595 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)fValue)).FromJust(); | 595 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)fValue)).FromJust(); |
| 596 } | 596 } |
| 597 | 597 |
| 598 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, double dValue) | 598 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, double dValue) |
| 599 { | 599 { |
| 600 if(pObj.IsEmpty()) return; | 600 if(pObj.IsEmpty()) return; |
| 601 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)dValue)).FromJust(); | 601 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)dValue)).FromJust(); |
| 602 } | 602 } |
| 603 | 603 |
| 604 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, co
nst wchar_t* PropertyName, bool bValue) | 604 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, con
st wchar_t* PropertyName, bool bValue) |
| 605 { | 605 { |
| 606 if(pObj.IsEmpty()) return; | 606 if(pObj.IsEmpty()) return; |
| 607 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Boolean::New(pJSRuntime, bValue)).FromJust(); | 607 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Boolean::New(pJSRuntime, bValue)).FromJust(); |
| 608 } | 608 } |
| 609 | 609 |
| 610 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, v8::Handle<v8::Object> pPut) | 610 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, v8::Local<v8::Object> pPut) |
| 611 { | 611 { |
| 612 if(pObj.IsEmpty()) return; | 612 if(pObj.IsEmpty()) return; |
| 613 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),pPut).FromJust(); | 613 pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),pPut).FromJust(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const
wchar_t* PropertyName) | 616 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const
wchar_t* PropertyName) |
| 617 { | 617 { |
| 618 if(pObj.IsEmpty()) return; | 618 if(pObj.IsEmpty()) return; |
| 619 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Handle<v8::Object>()).FromJust(); | 619 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Local<v8::Object>()).FromJust(); |
| 620 } | 620 } |
| 621 | 621 |
| 622 v8::Handle<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) | 622 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) |
| 623 { | 623 { |
| 624 return v8::Array::New(pJSRuntime); | 624 return v8::Array::New(pJSRuntime); |
| 625 } | 625 } |
| 626 | 626 |
| 627 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Handle<v8::Array> pArra
y,unsigned index,v8::Handle<v8::Value> pValue,FXJSVALUETYPE eType) | 627 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray
,unsigned index,v8::Local<v8::Value> pValue,FXJSVALUETYPE eType) |
| 628 { | 628 { |
| 629 if(pArray.IsEmpty()) return 0; | 629 if(pArray.IsEmpty()) return 0; |
| 630 if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothin
g()) return 0; | 630 if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothin
g()) return 0; |
| 631 return 1; | 631 return 1; |
| 632 } | 632 } |
| 633 | 633 |
| 634 v8::Handle<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Handle<v8:
:Array> pArray,unsigned index) | 634 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::A
rray> pArray,unsigned index) |
| 635 { | 635 { |
| 636 » if(pArray.IsEmpty()) return v8::Handle<v8::Value>(); | 636 » if(pArray.IsEmpty()) return v8::Local<v8::Value>(); |
| 637 v8::Local<v8::Value> val; | 637 v8::Local<v8::Value> val; |
| 638 if (pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) r
eturn v8::Local<v8::Value>(); | 638 if (pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) r
eturn v8::Local<v8::Value>(); |
| 639 return val; | 639 return val; |
| 640 } | 640 } |
| 641 | 641 |
| 642 unsigned JS_GetArrayLength(v8::Handle<v8::Array> pArray) | 642 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) |
| 643 { | 643 { |
| 644 if(pArray.IsEmpty()) return 0; | 644 if(pArray.IsEmpty()) return 0; |
| 645 return pArray->Length(); | 645 return pArray->Length(); |
| 646 } | 646 } |
| 647 | 647 |
| 648 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number) | 648 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number) |
| 649 { | 649 { |
| 650 return v8::Int32::New(pJSRuntime, number); | 650 return v8::Int32::New(pJSRuntime, number); |
| 651 } | 651 } |
| 652 | 652 |
| 653 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number) | 653 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number) |
| 654 { | 654 { |
| 655 return v8::Number::New(pJSRuntime, number); | 655 return v8::Number::New(pJSRuntime, number); |
| 656 } | 656 } |
| 657 | 657 |
| 658 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number) | 658 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number) |
| 659 { | 659 { |
| 660 return v8::Number::New(pJSRuntime, (float)number); | 660 return v8::Number::New(pJSRuntime, (float)number); |
| 661 } | 661 } |
| 662 | 662 |
| 663 v8::Handle<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b) | 663 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b) |
| 664 { | 664 { |
| 665 return v8::Boolean::New(pJSRuntime, b); | 665 return v8::Boolean::New(pJSRuntime, b); |
| 666 } | 666 } |
| 667 | 667 |
| 668 v8::Handle<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object
> pObj) | 668 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object>
pObj) |
| 669 { | 669 { |
| 670 » if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 670 » if(pObj.IsEmpty()) return v8::Local<v8::Value>(); |
| 671 return pObj->Clone(); | 671 return pObj->Clone(); |
| 672 } | 672 } |
| 673 | 673 |
| 674 v8::Handle<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Handle<v8::Array
> pObj) | 674 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Local<v8::Array>
pObj) |
| 675 { | 675 { |
| 676 » if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 676 » if(pObj.IsEmpty()) return v8::Local<v8::Value>(); |
| 677 return pObj->Clone(); | 677 return pObj->Clone(); |
| 678 } | 678 } |
| 679 | 679 |
| 680 | 680 |
| 681 v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string
) | 681 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string) |
| 682 { | 682 { |
| 683 return WSToJSString(pJSRuntime, string); | 683 return WSToJSString(pJSRuntime, string); |
| 684 } | 684 } |
| 685 | 685 |
| 686 v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string
, unsigned nLen) | 686 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string,
unsigned nLen) |
| 687 { | 687 { |
| 688 return WSToJSString(pJSRuntime, string, nLen); | 688 return WSToJSString(pJSRuntime, string, nLen); |
| 689 } | 689 } |
| 690 | 690 |
| 691 v8::Handle<v8::Value> JS_NewNull() | 691 v8::Local<v8::Value> JS_NewNull() |
| 692 { | 692 { |
| 693 » return v8::Handle<v8::Value>(); | 693 » return v8::Local<v8::Value>(); |
| 694 } | 694 } |
| 695 | 695 |
| 696 v8::Handle<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d) | 696 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d) |
| 697 { | 697 { |
| 698 return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(
); | 698 return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(
); |
| 699 } | 699 } |
| 700 | 700 |
| 701 v8::Handle<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) | 701 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) |
| 702 { | 702 { |
| 703 » return v8::Handle<v8::Value>(); | 703 » return v8::Local<v8::Value>(); |
| 704 } | 704 } |
| 705 | 705 |
| 706 v8::Handle<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Handle<v8::Va
lue> pList, int index) | 706 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Local<v8::Valu
e> pList, int index) |
| 707 { | 707 { |
| 708 | 708 |
| 709 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 709 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 710 if(!pList.IsEmpty() && pList->IsObject()) | 710 if(!pList.IsEmpty() && pList->IsObject()) |
| 711 { | 711 { |
| 712 v8::Local<v8::Object> obj; | 712 v8::Local<v8::Object> obj; |
| 713 if (pList->ToObject(context).ToLocal(&obj)) | 713 if (pList->ToObject(context).ToLocal(&obj)) |
| 714 { | 714 { |
| 715 v8::Local<v8::Value> val; | 715 v8::Local<v8::Value> val; |
| 716 if (obj->Get(context, index).ToLocal(&val)) return val; | 716 if (obj->Get(context, index).ToLocal(&val)) return val; |
| 717 } | 717 } |
| 718 } | 718 } |
| 719 » return v8::Handle<v8::Value>(); | 719 » return v8::Local<v8::Value>(); |
| 720 } | 720 } |
| 721 | 721 |
| 722 int» JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValue) | 722 int» JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) |
| 723 { | 723 { |
| 724 if(pValue.IsEmpty()) return 0; | 724 if(pValue.IsEmpty()) return 0; |
| 725 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 725 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 726 return pValue->ToInt32(context).ToLocalChecked()->Value(); | 726 return pValue->ToInt32(context).ToLocalChecked()->Value(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValue) | 729 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) |
| 730 { | 730 { |
| 731 if(pValue.IsEmpty()) return false; | 731 if(pValue.IsEmpty()) return false; |
| 732 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 732 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 733 return pValue->ToBoolean(context).ToLocalChecked()->Value(); | 733 return pValue->ToBoolean(context).ToLocalChecked()->Value(); |
| 734 } | 734 } |
| 735 | 735 |
| 736 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValue) | 736 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) |
| 737 { | 737 { |
| 738 if(pValue.IsEmpty()) return 0.0; | 738 if(pValue.IsEmpty()) return 0.0; |
| 739 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 739 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 740 return pValue->ToNumber(context).ToLocalChecked()->Value(); | 740 return pValue->ToNumber(context).ToLocalChecked()->Value(); |
| 741 } | 741 } |
| 742 | 742 |
| 743 v8::Handle<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value
> pValue) | 743 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Local<v8::Value>
pValue) |
| 744 { | 744 { |
| 745 » if(pValue.IsEmpty()) return v8::Handle<v8::Object>(); | 745 » if(pValue.IsEmpty()) return v8::Local<v8::Object>(); |
| 746 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 746 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 747 return pValue->ToObject(context).ToLocalChecked(); | 747 return pValue->ToObject(context).ToLocalChecked(); |
| 748 } | 748 } |
| 749 | 749 |
| 750 CFX_WideString» JS_ToString(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value> pValu
e) | 750 CFX_WideString» JS_ToString(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue
) |
| 751 { | 751 { |
| 752 if(pValue.IsEmpty()) return L""; | 752 if(pValue.IsEmpty()) return L""; |
| 753 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 753 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 754 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); | 754 v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); |
| 755 return CFX_WideString::FromUTF8(*s, s.length()); | 755 return CFX_WideString::FromUTF8(*s, s.length()); |
| 756 } | 756 } |
| 757 | 757 |
| 758 v8::Handle<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Handle<v8::Value>
pValue) | 758 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pV
alue) |
| 759 { | 759 { |
| 760 » if(pValue.IsEmpty()) return v8::Handle<v8::Array>(); | 760 » if(pValue.IsEmpty()) return v8::Local<v8::Array>(); |
| 761 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); | 761 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 762 » return v8::Handle<v8::Array>::Cast(pValue->ToObject(context).ToLocalChec
ked()); | 762 » return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalCheck
ed()); |
| 763 } | 763 } |
| 764 | 764 |
| 765 void JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom) | 765 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) |
| 766 { | 766 { |
| 767 pTo = pFrom; | 767 pTo = pFrom; |
| 768 } | 768 } |
| 769 | 769 |
| 770 | 770 |
| 771 //JavaScript time implement begin. | 771 //JavaScript time implement begin. |
| 772 | 772 |
| 773 double _getLocalTZA() | 773 double _getLocalTZA() |
| 774 { | 774 { |
| 775 if(!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) | 775 if(!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 993 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 994 | 994 |
| 995 //Use the built-in object method. | 995 //Use the built-in object method. |
| 996 v8::Local<v8::Value> v = context->Global()->Get(context, v8::String::New
FromUtf8(pIsolate, "Date", v8::NewStringType::kNormal).ToLocalChecked()).ToLocal
Checked(); | 996 v8::Local<v8::Value> v = context->Global()->Get(context, v8::String::New
FromUtf8(pIsolate, "Date", v8::NewStringType::kNormal).ToLocalChecked()).ToLocal
Checked(); |
| 997 if(v->IsObject()) | 997 if(v->IsObject()) |
| 998 { | 998 { |
| 999 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); | 999 v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); |
| 1000 v = o->Get(context,v8::String::NewFromUtf8(pIsolate, "parse", v8
::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); | 1000 v = o->Get(context,v8::String::NewFromUtf8(pIsolate, "parse", v8
::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); |
| 1001 if(v->IsFunction()) | 1001 if(v->IsFunction()) |
| 1002 { | 1002 { |
| 1003 » » » v8::Local<v8::Function> funC = v8::Handle<v8::Function>:
:Cast(v); | 1003 » » » v8::Local<v8::Function> funC = v8::Local<v8::Function>::
Cast(v); |
| 1004 | 1004 |
| 1005 const int argc = 1; | 1005 const int argc = 1; |
| 1006 v8::Local<v8::String> timeStr = WSToJSString(pIsolate, s
tring); | 1006 v8::Local<v8::String> timeStr = WSToJSString(pIsolate, s
tring); |
| 1007 » » » v8::Handle<v8::Value> argv[argc] = {timeStr}; | 1007 » » » v8::Local<v8::Value> argv[argc] = {timeStr}; |
| 1008 v = funC->Call(context, context->Global(), argc, argv).T
oLocalChecked(); | 1008 v = funC->Call(context, context->Global(), argc, argv).T
oLocalChecked(); |
| 1009 if(v->IsNumber()) | 1009 if(v->IsNumber()) |
| 1010 { | 1010 { |
| 1011 double date = v->ToNumber(context).ToLocalCheck
ed()->Value(); | 1011 double date = v->ToNumber(context).ToLocalCheck
ed()->Value(); |
| 1012 if(!_isfinite(date)) return date; | 1012 if(!_isfinite(date)) return date; |
| 1013 return date + _getLocalTZA() + _getDaylightSavin
gTA(date); | 1013 return date + _getLocalTZA() + _getDaylightSavin
gTA(date); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 } | 1016 } |
| 1017 } | 1017 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 { | 1060 { |
| 1061 return d != d; | 1061 return d != d; |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 double JS_LocalTime(double d) | 1064 double JS_LocalTime(double d) |
| 1065 { | 1065 { |
| 1066 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1066 return JS_GetDateTime() + _getDaylightSavingTA(d); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 //JavaScript time implement End. | 1069 //JavaScript time implement End. |
| OLD | NEW |