| 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" |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 v8::Global<v8::ObjectTemplate> m_objTemplate; | 74 v8::Global<v8::ObjectTemplate> m_objTemplate; |
| 74 v8::Global<v8::Object> m_StaticObj; | 75 v8::Global<v8::Object> m_StaticObj; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
ObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApply
New) | 78 int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
ObjType, LP_CONSTRUCTOR pConstructor, LP_DESTRUCTOR pDestructor, unsigned bApply
New) |
| 78 { | 79 { |
| 79 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 80 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 80 v8::Isolate::Scope isolate_scope(isolate); | 81 v8::Isolate::Scope isolate_scope(isolate); |
| 81 v8::HandleScope handle_scope(isolate); | 82 v8::HandleScope handle_scope(isolate); |
| 82 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 83 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 83 if(!pArray) | 84 if(!pArray) |
| 84 { | 85 { |
| 85 pArray = new CFX_PtrArray(); | 86 pArray = new CFX_PtrArray(); |
| 86 » » isolate->SetData(0, pArray); | 87 » » isolate->SetData(g_embedderDataSlot, pArray); |
| 87 } | 88 } |
| 88 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(isolate, sObjName, eObj
Type, pConstructor, pDestructor, bApplyNew); | 89 CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(isolate, sObjName, eObj
Type, pConstructor, pDestructor, bApplyNew); |
| 89 pArray->Add(pObjDef); | 90 pArray->Add(pObjDef); |
| 90 return pArray->GetSize()-1; | 91 return pArray->GetSize()-1; |
| 91 } | 92 } |
| 92 | 93 |
| 93 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
MethodName, v8::FunctionCallback pMethodCall) | 94 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
MethodName, v8::FunctionCallback pMethodCall) |
| 94 { | 95 { |
| 95 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 96 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 96 v8::Isolate::Scope isolate_scope(isolate); | 97 v8::Isolate::Scope isolate_scope(isolate); |
| 97 v8::HandleScope handle_scope(isolate); | 98 v8::HandleScope handle_scope(isolate); |
| 98 | 99 |
| 99 CFX_WideString ws = CFX_WideString(sMethodName); | 100 CFX_WideString ws = CFX_WideString(sMethodName); |
| 100 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 101 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
| 101 | 102 |
| 102 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 103 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 103 if(!pArray) return 0; | 104 if(!pArray) return 0; |
| 104 | 105 |
| 105 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 106 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 106 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 107 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 107 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 108 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 108 objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), v8::
NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, pMe
thodCall), v8::ReadOnly); | 109 objTemp->Set(v8::String::NewFromUtf8(isolate, bsMethodName.c_str(), v8::
NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate, pMe
thodCall), v8::ReadOnly); |
| 109 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 110 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 110 return 0; | 111 return 0; |
| 111 } | 112 } |
| 112 | 113 |
| 113 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro
pPut) | 114 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro
pPut) |
| 114 { | 115 { |
| 115 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 116 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 116 v8::Isolate::Scope isolate_scope(isolate); | 117 v8::Isolate::Scope isolate_scope(isolate); |
| 117 v8::HandleScope handle_scope(isolate); | 118 v8::HandleScope handle_scope(isolate); |
| 118 | 119 |
| 119 CFX_WideString ws = CFX_WideString(sPropName); | 120 CFX_WideString ws = CFX_WideString(sPropName); |
| 120 CFX_ByteString bsPropertyName = ws.UTF8Encode(); | 121 CFX_ByteString bsPropertyName = ws.UTF8Encode(); |
| 121 | 122 |
| 122 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 123 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 123 if(!pArray) return 0; | 124 if(!pArray) return 0; |
| 124 | 125 |
| 125 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 126 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 126 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 127 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 127 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 128 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 128 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, bsPropertyName.c_s
tr(), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut); | 129 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, bsPropertyName.c_s
tr(), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut); |
| 129 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 130 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 130 return 0; | 131 return 0; |
| 131 } | 132 } |
| 132 | 133 |
| 133 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::N
amedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet,
v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pProp
Del) | 134 int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::N
amedPropertyQueryCallback pPropQurey, v8::NamedPropertyGetterCallback pPropGet,
v8::NamedPropertySetterCallback pPropPut, v8::NamedPropertyDeleterCallback pProp
Del) |
| 134 { | 135 { |
| 135 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 136 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 136 v8::Isolate::Scope isolate_scope(isolate); | 137 v8::Isolate::Scope isolate_scope(isolate); |
| 137 v8::HandleScope handle_scope(isolate); | 138 v8::HandleScope handle_scope(isolate); |
| 138 | 139 |
| 139 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 140 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 140 if(!pArray) return 0; | 141 if(!pArray) return 0; |
| 141 | 142 |
| 142 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 143 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 143 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 144 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 144 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 145 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 145 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDe
l); | 146 objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDe
l); |
| 146 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 147 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 147 return 0; | 148 return 0; |
| 148 } | 149 } |
| 149 | 150 |
| 150 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
onstName, v8::Local<v8::Value> pDefault) | 151 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
onstName, v8::Local<v8::Value> pDefault) |
| 151 { | 152 { |
| 152 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 153 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 153 v8::Isolate::Scope isolate_scope(isolate); | 154 v8::Isolate::Scope isolate_scope(isolate); |
| 154 v8::HandleScope handle_scope(isolate); | 155 v8::HandleScope handle_scope(isolate); |
| 155 | 156 |
| 156 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 157 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 157 if(!pArray) return 0; | 158 if(!pArray) return 0; |
| 158 | 159 |
| 159 CFX_WideString ws = CFX_WideString(sConstName); | 160 CFX_WideString ws = CFX_WideString(sConstName); |
| 160 CFX_ByteString bsConstName = ws.UTF8Encode(); | 161 CFX_ByteString bsConstName = ws.UTF8Encode(); |
| 161 | 162 |
| 162 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 163 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 163 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 164 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 164 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 165 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 165 objTemp->Set(isolate, bsConstName.c_str(), pDefault); | 166 objTemp->Set(isolate, bsConstName.c_str(), pDefault); |
| 166 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 167 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 167 return 0; | 168 return 0; |
| 168 } | 169 } |
| 169 | 170 |
| 170 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
Runtime) | 171 static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
Runtime) |
| 171 { | 172 { |
| 172 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 173 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 173 v8::Isolate::Scope isolate_scope(isolate); | 174 v8::Isolate::Scope isolate_scope(isolate); |
| 174 v8::HandleScope handle_scope(isolate); | 175 v8::HandleScope handle_scope(isolate); |
| 175 | 176 |
| 176 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 177 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 177 ASSERT(pArray != NULL); | 178 ASSERT(pArray != NULL); |
| 178 for(int i=0; i<pArray->GetSize(); i++) | 179 for(int i=0; i<pArray->GetSize(); i++) |
| 179 { | 180 { |
| 180 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 181 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 181 if(pObjDef->m_bSetAsGlobalObject) | 182 if(pObjDef->m_bSetAsGlobalObject) |
| 182 return pObjDef->m_objTemplate; | 183 return pObjDef->m_objTemplate; |
| 183 } | 184 } |
| 184 static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate; | 185 static v8::Global<v8::ObjectTemplate> gloabalObjectTemplate; |
| 185 return gloabalObjectTemplate; | 186 return gloabalObjectTemplate; |
| 186 } | 187 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 v8::Isolate::Scope isolate_scope(isolate); | 240 v8::Isolate::Scope isolate_scope(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<v8::External> ptr = v8::External::New(isolate, pFXRuntime); | 247 v8::Local<v8::External> ptr = v8::External::New(isolate, pFXRuntime); |
| 247 v8Context->SetEmbedderData(1, ptr); | 248 v8Context->SetEmbedderData(1, ptr); |
| 248 | 249 |
| 249 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 250 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 250 if(!pArray) return; | 251 if(!pArray) return; |
| 251 | 252 |
| 252 for(int i=0; i<pArray->GetSize(); i++) | 253 for(int i=0; i<pArray->GetSize(); i++) |
| 253 { | 254 { |
| 254 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 255 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 255 CFX_WideString ws = CFX_WideString(pObjDef->objName); | 256 CFX_WideString ws = CFX_WideString(pObjDef->objName); |
| 256 CFX_ByteString bs = ws.UTF8Encode(); | 257 CFX_ByteString bs = ws.UTF8Encode(); |
| 257 v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate,
bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); | 258 v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate,
bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); |
| 258 | 259 |
| 259 | 260 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 283 } | 284 } |
| 284 | 285 |
| 285 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
stentContext) | 286 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
stentContext) |
| 286 { | 287 { |
| 287 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 288 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 288 v8::Isolate::Scope isolate_scope(isolate); | 289 v8::Isolate::Scope isolate_scope(isolate); |
| 289 v8::HandleScope handle_scope(isolate); | 290 v8::HandleScope handle_scope(isolate); |
| 290 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8
PersistentContext); | 291 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8
PersistentContext); |
| 291 v8::Context::Scope context_scope(context); | 292 v8::Context::Scope context_scope(context); |
| 292 | 293 |
| 293 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 294 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 294 if(!pArray) return ; | 295 if(!pArray) return ; |
| 295 | 296 |
| 296 for(int i=0; i<pArray->GetSize(); i++) | 297 for(int i=0; i<pArray->GetSize(); i++) |
| 297 { | 298 { |
| 298 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 299 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 299 if(!pObjDef->m_StaticObj.IsEmpty()) | 300 if(!pObjDef->m_StaticObj.IsEmpty()) |
| 300 { | 301 { |
| 301 v8::Local<v8::Object> pObj = v8::Local<v8::Object>::New(
isolate, pObjDef->m_StaticObj); | 302 v8::Local<v8::Object> pObj = v8::Local<v8::Object>::New(
isolate, pObjDef->m_StaticObj); |
| 302 if(pObjDef->m_pDestructor) | 303 if(pObjDef->m_pDestructor) |
| 303 pObjDef->m_pDestructor(pObj); | 304 pObjDef->m_pDestructor(pObj); |
| 304 JS_FreePrivate(pObj); | 305 JS_FreePrivate(pObj); |
| 305 } | 306 } |
| 306 delete pObjDef; | 307 delete pObjDef; |
| 307 } | 308 } |
| 308 delete pArray; | 309 delete pArray; |
| 309 » isolate->SetData(0,NULL); | 310 » isolate->SetData(g_embedderDataSlot,NULL); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void JS_Initial() | 313 void JS_Initial(unsigned int embedderDataSlot) |
| 313 { | 314 { |
| 315 g_embedderDataSlot = embedderDataSlot; |
| 314 } | 316 } |
| 315 void JS_Release() | 317 void JS_Release() |
| 316 { | 318 { |
| 317 | 319 |
| 318 } | 320 } |
| 319 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
script, long length, FXJSErr* perror) | 321 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
script, long length, FXJSErr* perror) |
| 320 { | 322 { |
| 321 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 323 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 322 v8::Isolate::Scope isolate_scope(isolate); | 324 v8::Isolate::Scope isolate_scope(isolate); |
| 323 v8::TryCatch try_catch(isolate); | 325 v8::TryCatch try_catch(isolate); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 v8::Isolate::Scope isolate_scope(isolate); | 367 v8::Isolate::Scope isolate_scope(isolate); |
| 366 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 368 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 367 if(-1 == nObjDefnID) | 369 if(-1 == nObjDefnID) |
| 368 { | 370 { |
| 369 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); | 371 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); |
| 370 v8::Local<v8::Object> obj; | 372 v8::Local<v8::Object> obj; |
| 371 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; | 373 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; |
| 372 return v8::Local<v8::Object>(); | 374 return v8::Local<v8::Object>(); |
| 373 } | 375 } |
| 374 | 376 |
| 375 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 377 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 376 if(!pArray) return v8::Local<v8::Object>(); | 378 if(!pArray) return v8::Local<v8::Object>(); |
| 377 | 379 |
| 378 | 380 |
| 379 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); | 381 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); |
| 380 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 382 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 381 | 383 |
| 382 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 384 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 383 v8::Local<v8::Object> obj; | 385 v8::Local<v8::Object> obj; |
| 384 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O
bject>(); | 386 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O
bject>(); |
| 385 | 387 |
| 386 CJS_PrivateData* pPrivateData = new CJS_PrivateData; | 388 CJS_PrivateData* pPrivateData = new CJS_PrivateData; |
| 387 pPrivateData->ObjDefID = nObjDefnID; | 389 pPrivateData->ObjDefID = nObjDefnID; |
| 388 | 390 |
| 389 obj->SetAlignedPointerInInternalField(0, pPrivateData); | 391 obj->SetAlignedPointerInInternalField(0, pPrivateData); |
| 390 if(pObjDef->m_pConstructor) | 392 if(pObjDef->m_pConstructor) |
| 391 pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject(context).ToLocalChecked()); | 393 pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject(context).ToLocalChecked()); |
| 392 | 394 |
| 393 return obj; | 395 return obj; |
| 394 } | 396 } |
| 395 | 397 |
| 396 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) | 398 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) |
| 397 { | 399 { |
| 398 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 400 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 399 v8::Isolate::Scope isolate_scope(isolate); | 401 v8::Isolate::Scope isolate_scope(isolate); |
| 400 | 402 |
| 401 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 403 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 402 if(!pArray) return v8::Local<v8::Object>(); | 404 if(!pArray) return v8::Local<v8::Object>(); |
| 403 | 405 |
| 404 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); | 406 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); |
| 405 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 407 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 406 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef->
m_StaticObj); | 408 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New(isolate,pObjDef->
m_StaticObj); |
| 407 return obj; | 409 return obj; |
| 408 } | 410 } |
| 409 | 411 |
| 410 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) | 412 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) |
| 411 { | 413 { |
| 412 //Do nothing. | 414 //Do nothing. |
| 413 } | 415 } |
| 414 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime) | 416 v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime) |
| 415 { | 417 { |
| 416 //Return the global object. | 418 //Return the global object. |
| 417 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 419 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 418 v8::Isolate::Scope isolate_scope(isolate); | 420 v8::Isolate::Scope isolate_scope(isolate); |
| 419 | 421 |
| 420 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 422 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 421 if(!pArray) return v8::Local<v8::Object>(); | 423 if(!pArray) return v8::Local<v8::Object>(); |
| 422 | 424 |
| 423 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 425 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 424 return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck
ed(); | 426 return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck
ed(); |
| 425 } | 427 } |
| 426 | 428 |
| 427 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) | 429 int JS_GetObjDefnID(v8::Local<v8::Object> pObj) |
| 428 { | 430 { |
| 429 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; | 431 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; |
| 430 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); | 432 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); |
| 431 if(pPrivateData) | 433 if(pPrivateData) |
| 432 return pPrivateData->ObjDefID; | 434 return pPrivateData->ObjDefID; |
| 433 return -1; | 435 return -1; |
| 434 } | 436 } |
| 435 | 437 |
| 436 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) | 438 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) |
| 437 { | 439 { |
| 438 if(pObj.IsEmpty()) return NULL; | 440 if(pObj.IsEmpty()) return NULL; |
| 439 v8::Local<v8::Context> context = pObj->CreationContext(); | 441 v8::Local<v8::Context> context = pObj->CreationContext(); |
| 440 if(context.IsEmpty()) return NULL; | 442 if(context.IsEmpty()) return NULL; |
| 441 return context->GetIsolate(); | 443 return context->GetIsolate(); |
| 442 } | 444 } |
| 443 | 445 |
| 444 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) | 446 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) |
| 445 { | 447 { |
| 446 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 448 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 447 v8::Isolate::Scope isolate_scope(isolate); | 449 v8::Isolate::Scope isolate_scope(isolate); |
| 448 | 450 |
| 449 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 451 » CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlo
t); |
| 450 if(!pArray) return -1; | 452 if(!pArray) return -1; |
| 451 | 453 |
| 452 for(int i=0; i<pArray->GetSize(); i++) | 454 for(int i=0; i<pArray->GetSize(); i++) |
| 453 { | 455 { |
| 454 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 456 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 455 if(FXSYS_wcscmp(pObjDef->objName, pObjName) == 0) | 457 if(FXSYS_wcscmp(pObjDef->objName, pObjName) == 0) |
| 456 return i; | 458 return i; |
| 457 } | 459 } |
| 458 return -1; | 460 return -1; |
| 459 } | 461 } |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 { | 1062 { |
| 1061 return d != d; | 1063 return d != d; |
| 1062 } | 1064 } |
| 1063 | 1065 |
| 1064 double JS_LocalTime(double d) | 1066 double JS_LocalTime(double d) |
| 1065 { | 1067 { |
| 1066 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1068 return JS_GetDateTime() + _getDaylightSavingTA(d); |
| 1067 } | 1069 } |
| 1068 | 1070 |
| 1069 //JavaScript time implement End. | 1071 //JavaScript time implement End. |
| OLD | NEW |