| 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(1); | 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(1); | 82 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 83 if(!pArray) | 83 if(!pArray) |
| 84 { | 84 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 98 | 98 |
| 99 CFX_WideString ws = CFX_WideString(sMethodName); | 99 CFX_WideString ws = CFX_WideString(sMethodName); |
| 100 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 100 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
| 101 | 101 |
| 102 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 102 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 103 if(!pArray) return 0; | 103 if(!pArray) return 0; |
| 104 | 104 |
| 105 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 105 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 106 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 106 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 107 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); |
| 108 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly); | 108 » objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName), v
8::NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New(isolate,
pMethodCall), v8::ReadOnly); |
| 109 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 109 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 110 return 0; | 110 return 0; |
| 111 } | 111 } |
| 112 | 112 |
| 113 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) |
| 114 { | 114 { |
| 115 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 115 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 116 v8::Isolate::Scope isolate_scope(isolate); | 116 v8::Isolate::Scope isolate_scope(isolate); |
| 117 v8::HandleScope handle_scope(isolate); | 117 v8::HandleScope handle_scope(isolate); |
| 118 | 118 |
| 119 CFX_WideString ws = CFX_WideString(sPropName); | 119 CFX_WideString ws = CFX_WideString(sPropName); |
| 120 CFX_ByteString bsPropertyName = ws.UTF8Encode(); | 120 CFX_ByteString bsPropertyName = ws.UTF8Encode(); |
| 121 | 121 |
| 122 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 122 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 123 if(!pArray) return 0; | 123 if(!pArray) return 0; |
| 124 | 124 |
| 125 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 125 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 126 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 126 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 127 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); |
| 128 » objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsProper
tyName)), pPropGet, pPropPut); | 128 » objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsProper
tyName), v8::NewStringType::kNormal).ToLocalChecked(), pPropGet, pPropPut); |
| 129 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 129 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 130 return 0; | 130 return 0; |
| 131 } | 131 } |
| 132 | 132 |
| 133 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) |
| 134 { | 134 { |
| 135 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 135 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 136 v8::Isolate::Scope isolate_scope(isolate); | 136 v8::Isolate::Scope isolate_scope(isolate); |
| 137 v8::HandleScope handle_scope(isolate); | 137 v8::HandleScope handle_scope(isolate); |
| 138 | 138 |
| 139 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 139 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 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(1); | 156 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 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(1); | 176 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 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)),
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)), pDefa
ult, 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::Locker locker(isolate); | 240 v8::Locker locker(isolate); |
| 241 v8::HandleScope handle_scope(isolate); | 241 v8::HandleScope handle_scope(isolate); |
| 242 | 242 |
| 243 » v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 243 » v8::Global<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate
(pJSRuntime); |
| 244 » v8::Handle<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::
Local<v8::ObjectTemplate>::New(isolate, globalObjTemp)); | 244 » v8::Local<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::L
ocal<v8::ObjectTemplate>::New(isolate, globalObjTemp)); |
| 245 v8::Context::Scope context_scope(v8Context); | 245 v8::Context::Scope context_scope(v8Context); |
| 246 | 246 |
| 247 » //v8::Handle<External> ptr = External::New(isolate, pFXRuntime); | 247 » //v8::Local<External> ptr = External::New(isolate, pFXRuntime); |
| 248 //v8Context->SetEmbedderData(1, ptr); | 248 //v8Context->SetEmbedderData(1, ptr); |
| 249 isolate->SetData(2, pFXRuntime); | 249 isolate->SetData(2, pFXRuntime); |
| 250 | 250 |
| 251 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 251 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 252 if(!pArray) return; | 252 if(!pArray) return; |
| 253 | 253 |
| 254 for(int i=0; i<pArray->GetSize(); i++) | 254 for(int i=0; i<pArray->GetSize(); i++) |
| 255 { | 255 { |
| 256 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); | 256 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(i); |
| 257 CFX_WideString ws = CFX_WideString(pObjDef->objName); | 257 CFX_WideString ws = CFX_WideString(pObjDef->objName); |
| 258 CFX_ByteString bs = ws.UTF8Encode(); | 258 CFX_ByteString bs = ws.UTF8Encode(); |
| 259 » » v8::Handle<v8::String> objName = v8::String::NewFromUtf8(isolate
, bs.c_str(), v8::String::kNormalString, bs.GetLength()); | 259 » » v8::Local<v8::String> objName = v8::String::NewFromUtf8(isolate,
bs.c_str(), v8::NewStringType::kNormal, bs.GetLength()).ToLocalChecked(); |
| 260 | 260 |
| 261 | 261 |
| 262 if(pObjDef->objType == JS_DYNAMIC) | 262 if(pObjDef->objType == JS_DYNAMIC) |
| 263 { | 263 { |
| 264 //Document is set as global object, need to construct it
first. | 264 //Document is set as global object, need to construct it
first. |
| 265 CFX_WideString wsString(L"Document"); | 265 CFX_WideString wsString(L"Document"); |
| 266 if(ws.Equal(wsString)) | 266 if(ws.Equal(wsString)) |
| 267 { | 267 { |
| 268 | 268 |
| 269 CJS_PrivateData* pPrivateData = FX_NEW CJS_Priva
teData; | 269 CJS_PrivateData* pPrivateData = FX_NEW CJS_Priva
teData; |
| 270 pPrivateData->ObjDefID = i; | 270 pPrivateData->ObjDefID = i; |
| 271 v8::Handle<v8::External> ptr = v8::External::New
(isolate, pPrivateData); | |
| 272 | 271 |
| 273 » » » » v8Context->Global()->GetPrototype()->ToObject()-
>SetInternalField(0, ptr); | 272 » » » » v8Context->Global()->GetPrototype()->ToObject(v8
Context).ToLocalChecked()->SetAlignedPointerInInternalField(0, pPrivateData); |
| 274 | 273 |
| 275 if(pObjDef->m_pConstructor) | 274 if(pObjDef->m_pConstructor) |
| 276 » » » » » pObjDef->m_pConstructor(context, v8Conte
xt->Global()->GetPrototype()->ToObject(), v8Context->Global()->GetPrototype()->T
oObject()); | 275 » » » » » pObjDef->m_pConstructor(context, v8Conte
xt->Global()->GetPrototype()->ToObject(v8Context).ToLocalChecked(), v8Context->G
lobal()->GetPrototype()->ToObject(v8Context).ToLocalChecked()); |
| 277 } | 276 } |
| 278 } | 277 } |
| 279 else | 278 else |
| 280 { | 279 { |
| 281 » » » v8::Handle<v8::Object> obj = JS_NewFxDynamicObj(pJSRunti
me, context, i); | 280 » » » v8::Local<v8::Object> obj = JS_NewFxDynamicObj(pJSRuntim
e, context, i); |
| 282 » » » v8Context->Global()->Set(objName, obj); | 281 » » » v8Context->Global()->Set(v8Context, objName, obj).FromJu
st(); |
| 283 pObjDef->m_StaticObj.Reset(isolate, obj); | 282 pObjDef->m_StaticObj.Reset(isolate, obj); |
| 284 } | 283 } |
| 285 } | 284 } |
| 286 v8PersistentContext.Reset(isolate, v8Context); | 285 v8PersistentContext.Reset(isolate, v8Context); |
| 287 } | 286 } |
| 288 | 287 |
| 289 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8P
ersistentContext) | 288 void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
stentContext) |
| 290 { | 289 { |
| 291 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 290 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 292 v8::Isolate::Scope isolate_scope(isolate); | 291 v8::Isolate::Scope isolate_scope(isolate); |
| 293 v8::Locker locker(isolate); | 292 v8::Locker locker(isolate); |
| 294 v8::HandleScope handle_scope(isolate); | 293 v8::HandleScope handle_scope(isolate); |
| 295 | 294 |
| 296 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 295 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 297 if(!pArray) return ; | 296 if(!pArray) return ; |
| 298 | 297 |
| 299 for(int i=0; i<pArray->GetSize(); i++) | 298 for(int i=0; i<pArray->GetSize(); i++) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 317 { | 316 { |
| 318 } | 317 } |
| 319 void JS_Release() | 318 void JS_Release() |
| 320 { | 319 { |
| 321 | 320 |
| 322 } | 321 } |
| 323 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
script, long length, FXJSErr* perror) | 322 int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t*
script, long length, FXJSErr* perror) |
| 324 { | 323 { |
| 325 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 324 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 326 v8::Isolate::Scope isolate_scope(isolate); | 325 v8::Isolate::Scope isolate_scope(isolate); |
| 327 » v8::TryCatch try_catch; | 326 » v8::TryCatch try_catch(isolate); |
| 328 | 327 |
| 329 CFX_WideString wsScript(script); | 328 CFX_WideString wsScript(script); |
| 330 CFX_ByteString bsScript = wsScript.UTF8Encode(); | 329 CFX_ByteString bsScript = wsScript.UTF8Encode(); |
| 331 | 330 |
| 332 | 331 |
| 333 » v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String:
:NewFromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetL
ength())); | 332 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 334 » if (compiled_script.IsEmpty()) { | 333 » v8::Local<v8::Script> compiled_script; |
| 334 if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScr
ipt.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked())
.ToLocal(&compiled_script)) { |
| 335 v8::String::Utf8Value error(try_catch.Exception()); | 335 v8::String::Utf8Value error(try_catch.Exception()); |
| 336 return -1; | 336 return -1; |
| 337 } | 337 } |
| 338 return 0; | 338 return 0; |
| 339 } | 339 } |
| 340 | 340 |
| 341 int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t
* script, long length, FXJSErr* perror) | 341 int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t
* script, long length, FXJSErr* perror) |
| 342 { | 342 { |
| 343 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 343 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 344 v8::Isolate::Scope isolate_scope(isolate); | 344 v8::Isolate::Scope isolate_scope(isolate); |
| 345 » v8::TryCatch try_catch; | 345 » v8::TryCatch try_catch(isolate); |
| 346 | 346 |
| 347 CFX_WideString wsScript(script); | 347 CFX_WideString wsScript(script); |
| 348 CFX_ByteString bsScript = wsScript.UTF8Encode(); | 348 CFX_ByteString bsScript = wsScript.UTF8Encode(); |
| 349 | 349 |
| 350 v8::Handle<v8::Script> compiled_script = v8::Script::Compile(v8::String::New
FromUtf8(isolate, bsScript.c_str(), v8::String::kNormalString, bsScript.GetLengt
h())); | 350 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 351 » if (compiled_script.IsEmpty()) { | 351 v8::Local<v8::Script> compiled_script; |
| 352 if (!v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, bsScr
ipt.c_str(), v8::NewStringType::kNormal, bsScript.GetLength()).ToLocalChecked())
.ToLocal(&compiled_script)) { |
| 352 v8::String::Utf8Value error(try_catch.Exception()); | 353 v8::String::Utf8Value error(try_catch.Exception()); |
| 353 return -1; | 354 return -1; |
| 354 } | 355 } |
| 355 | 356 |
| 356 » v8::Handle<v8::Value> result = compiled_script->Run(); | 357 » v8::Local<v8::Value> result; |
| 357 » if (result.IsEmpty()) { | 358 if (!compiled_script->Run(context).ToLocal(&result)) { |
| 358 v8::String::Utf8Value error(try_catch.Exception()); | 359 v8::String::Utf8Value error(try_catch.Exception()); |
| 359 return -1; | 360 return -1; |
| 360 } | 361 } |
| 361 return 0; | 362 return 0; |
| 362 } | 363 } |
| 363 | 364 |
| 364 v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context
* pJSContext, int nObjDefnID) | 365 v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context*
pJSContext, int nObjDefnID) |
| 365 { | 366 { |
| 366 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 367 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 367 v8::Isolate::Scope isolate_scope(isolate); | 368 v8::Isolate::Scope isolate_scope(isolate); |
| 369 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 368 if(-1 == nObjDefnID) | 370 if(-1 == nObjDefnID) |
| 369 { | 371 { |
| 370 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); | 372 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New
(isolate); |
| 371 » » return objTempl->NewInstance(); | 373 v8::Local<v8::Object> obj; |
| 374 if (objTempl->NewInstance(context).ToLocal(&obj)) return obj; |
| 375 return v8::Local<v8::Object>(); |
| 372 } | 376 } |
| 373 | 377 |
| 374 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 378 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 375 » if(!pArray) return v8::Handle<v8::Object>(); | 379 » if(!pArray) return v8::Local<v8::Object>(); |
| 376 | 380 |
| 377 | 381 |
| 378 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8:
:Object>(); | 382 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); |
| 379 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 383 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 380 | 384 |
| 381 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
| 382 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 385 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 383 | 386 » v8::Local<v8::Object> obj; |
| 384 » v8::Local<v8::Object> obj = objTemp->NewInstance(); | 387 if (!objTemp->NewInstance(context).ToLocal(&obj)) return v8::Local<v8::O
bject>(); |
| 385 » | |
| 386 CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData; | 388 CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData; |
| 387 pPrivateData->ObjDefID = nObjDefnID; | 389 pPrivateData->ObjDefID = nObjDefnID; |
| 388 v8::Handle<v8::External> ptr = v8::External::New(isolate, pPrivateData); | |
| 389 obj->SetInternalField(0, ptr); | |
| 390 | 390 |
| 391 obj->SetAlignedPointerInInternalField(0, pPrivateData); |
| 391 if(pObjDef->m_pConstructor) | 392 if(pObjDef->m_pConstructor) |
| 392 » » pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject()); | 393 » » pObjDef->m_pConstructor(pJSContext, obj, context->Global()->GetP
rototype()->ToObject(context).ToLocalChecked()); |
| 393 | 394 |
| 394 return obj; | 395 return obj; |
| 395 } | 396 } |
| 396 | 397 |
| 397 v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) | 398 v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID) |
| 398 { | 399 { |
| 399 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 400 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 400 v8::Isolate::Scope isolate_scope(isolate); | 401 v8::Isolate::Scope isolate_scope(isolate); |
| 401 | 402 |
| 402 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 403 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 403 » if(!pArray) return v8::Handle<v8::Object>(); | 404 » if(!pArray) return v8::Local<v8::Object>(); |
| 404 | 405 |
| 405 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8:
:Object>(); | 406 » if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::
Object>(); |
| 406 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 407 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 407 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); |
| 408 return obj; | 409 return obj; |
| 409 } | 410 } |
| 410 | 411 |
| 411 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) | 412 void JS_SetThisObj(IJS_Runtime* pJSRuntime, int nThisObjID) |
| 412 { | 413 { |
| 413 //Do nothing. | 414 //Do nothing. |
| 414 } | 415 } |
| 415 v8::Handle<v8::Object>» JS_GetThisObj(IJS_Runtime * pJSRuntime) | 416 v8::Local<v8::Object>» JS_GetThisObj(IJS_Runtime * pJSRuntime) |
| 416 { | 417 { |
| 417 //Return the global object. | 418 //Return the global object. |
| 418 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 419 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 419 v8::Isolate::Scope isolate_scope(isolate); | 420 v8::Isolate::Scope isolate_scope(isolate); |
| 420 | 421 |
| 421 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); | 422 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1); |
| 422 » if(!pArray) return v8::Handle<v8::Object>(); | 423 » if(!pArray) return v8::Local<v8::Object>(); |
| 423 | 424 |
| 424 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 425 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 425 » return context->Global()->GetPrototype()->ToObject(); | 426 » return context->Global()->GetPrototype()->ToObject(context).ToLocalCheck
ed(); |
| 426 } | 427 } |
| 427 | 428 |
| 428 int» JS_GetObjDefnID(v8::Handle<v8::Object> pObj) | 429 int» JS_GetObjDefnID(v8::Local<v8::Object> pObj) |
| 429 { | 430 { |
| 430 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; | 431 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return -1; |
| 431 » v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(pObj->Ge
tInternalField(0)); | 432 » CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointe
rFromInternalField(0); |
| 432 » CJS_PrivateData* pPrivateData = (CJS_PrivateData*)field->Value(); | |
| 433 if(pPrivateData) | 433 if(pPrivateData) |
| 434 return pPrivateData->ObjDefID; | 434 return pPrivateData->ObjDefID; |
| 435 return -1; | 435 return -1; |
| 436 } | 436 } |
| 437 | 437 |
| 438 IJS_Runtime* JS_GetRuntime(v8::Handle<v8::Object> pObj) | 438 IJS_Runtime* JS_GetRuntime(v8::Local<v8::Object> pObj) |
| 439 { | 439 { |
| 440 if(pObj.IsEmpty()) return NULL; | 440 if(pObj.IsEmpty()) return NULL; |
| 441 v8::Local<v8::Context> context = pObj->CreationContext(); | 441 v8::Local<v8::Context> context = pObj->CreationContext(); |
| 442 if(context.IsEmpty()) return NULL; | 442 if(context.IsEmpty()) return NULL; |
| 443 return context->GetIsolate(); | 443 return context->GetIsolate(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) | 446 int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName) |
| 447 { | 447 { |
| 448 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 448 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 460 return -1; | 460 return -1; |
| 461 } | 461 } |
| 462 | 462 |
| 463 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) | 463 void JS_Error(v8::Isolate* isolate, const CFX_WideString& message) |
| 464 { | 464 { |
| 465 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t | 465 // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t |
| 466 // wide-strings isn't handled by v8, so use UTF8 as a common | 466 // wide-strings isn't handled by v8, so use UTF8 as a common |
| 467 // intermediate format. | 467 // intermediate format. |
| 468 CFX_ByteString utf8_message = message.UTF8Encode(); | 468 CFX_ByteString utf8_message = message.UTF8Encode(); |
| 469 isolate->ThrowException(v8::String::NewFromUtf8(isolate, | 469 isolate->ThrowException(v8::String::NewFromUtf8(isolate, |
| 470 utf8_message.c_str())); | 470 utf8_message.c_str(), |
| 471 v8::NewStringType::kNormal).
ToLocalChecked()); |
| 471 } | 472 } |
| 472 | 473 |
| 473 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) | 474 unsigned JS_CalcHash(const wchar_t* main, unsigned nLen) |
| 474 { | 475 { |
| 475 return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, nLen); | 476 return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, nLen); |
| 476 } | 477 } |
| 477 | 478 |
| 478 unsigned JS_CalcHash(const wchar_t* main) | 479 unsigned JS_CalcHash(const wchar_t* main) |
| 479 { | 480 { |
| 480 return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, FXSYS_wcslen(
main)); | 481 return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, FXSYS_wcslen(
main)); |
| 481 } | 482 } |
| 482 const wchar_t*» JS_GetTypeof(v8::Handle<v8::Value> pObj) | 483 const wchar_t*» JS_GetTypeof(v8::Local<v8::Value> pObj) |
| 483 { | 484 { |
| 484 if(pObj.IsEmpty()) return NULL; | 485 if(pObj.IsEmpty()) return NULL; |
| 485 if(pObj->IsString()) | 486 if(pObj->IsString()) |
| 486 return VALUE_NAME_STRING; | 487 return VALUE_NAME_STRING; |
| 487 if(pObj->IsNumber()) | 488 if(pObj->IsNumber()) |
| 488 return VALUE_NAME_NUMBER; | 489 return VALUE_NAME_NUMBER; |
| 489 if(pObj->IsBoolean()) | 490 if(pObj->IsBoolean()) |
| 490 return VALUE_NAME_BOOLEAN; | 491 return VALUE_NAME_BOOLEAN; |
| 491 if(pObj->IsDate()) | 492 if(pObj->IsDate()) |
| 492 return VALUE_NAME_DATE; | 493 return VALUE_NAME_DATE; |
| 493 if(pObj->IsObject()) | 494 if(pObj->IsObject()) |
| 494 return VALUE_NAME_OBJECT; | 495 return VALUE_NAME_OBJECT; |
| 495 if(pObj->IsNull()) | 496 if(pObj->IsNull()) |
| 496 return VALUE_NAME_NULL; | 497 return VALUE_NAME_NULL; |
| 497 if(pObj->IsUndefined()) | 498 if(pObj->IsUndefined()) |
| 498 return VALUE_NAME_UNDEFINED; | 499 return VALUE_NAME_UNDEFINED; |
| 499 return NULL; | 500 return NULL; |
| 500 | 501 |
| 501 } | 502 } |
| 502 void JS_SetPrivate(v8::Handle<v8::Object> pObj, void* p) | 503 void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) |
| 503 { | 504 { |
| 504 JS_SetPrivate(NULL, pObj, p); | 505 JS_SetPrivate(NULL, pObj, p); |
| 505 } | 506 } |
| 506 | 507 |
| 507 void* JS_GetPrivate(v8::Handle<v8::Object> pObj) | 508 void* JS_GetPrivate(v8::Local<v8::Object> pObj) |
| 508 { | 509 { |
| 509 return JS_GetPrivate(NULL,pObj); | 510 return JS_GetPrivate(NULL,pObj); |
| 510 } | 511 } |
| 511 | 512 |
| 512 void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj, void* p
) | 513 void JS_SetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj, void* p) |
| 513 { | 514 { |
| 514 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; | 515 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; |
| 515 » v8::Handle<v8::External> ptr = v8::Handle<v8::External>::Cast(pObj->GetI
nternalField(0)); | 516 » CJS_PrivateData* pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPoint
erFromInternalField(0); |
| 516 » CJS_PrivateData* pPrivateData = (CJS_PrivateData*)ptr->Value(); | |
| 517 if(!pPrivateData) return; | 517 if(!pPrivateData) return; |
| 518 pPrivateData->pPrivate = p; | 518 pPrivateData->pPrivate = p; |
| 519 } | 519 } |
| 520 | 520 |
| 521 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Handle<v8::Object> pObj) | 521 void* JS_GetPrivate(IJS_Runtime* pJSRuntime, v8::Local<v8::Object> pObj) |
| 522 { | 522 { |
| 523 if(pObj.IsEmpty()) return NULL; | 523 if(pObj.IsEmpty()) return NULL; |
| 524 » v8::Local<v8::Value> value; | 524 » CJS_PrivateData* pPrivateData = NULL; |
| 525 if(pObj->InternalFieldCount()) | 525 if(pObj->InternalFieldCount()) |
| 526 » » value = pObj->GetInternalField(0); | 526 pPrivateData = (CJS_PrivateData*)pObj->GetAlignedPointerFromInte
rnalField(0); |
| 527 else | 527 else |
| 528 { | 528 { |
| 529 //It could be a global proxy object. | 529 //It could be a global proxy object. |
| 530 v8::Local<v8::Value> v = pObj->GetPrototype(); | 530 v8::Local<v8::Value> v = pObj->GetPrototype(); |
| 531 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 532 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 531 if(v->IsObject()) | 533 if(v->IsObject()) |
| 532 » » » value = v->ToObject()->GetInternalField(0); | 534 pPrivateData = (CJS_PrivateData*)v->ToObject(context).To
LocalChecked()->GetAlignedPointerFromInternalField(0); |
| 533 } | 535 } |
| 534 if(value.IsEmpty() || value->IsUndefined()) return NULL; | |
| 535 v8::Handle<v8::External> ptr = v8::Handle<v8::External>::Cast(value); | |
| 536 CJS_PrivateData* pPrivateData = (CJS_PrivateData*)ptr->Value(); | |
| 537 if(!pPrivateData) return NULL; | 536 if(!pPrivateData) return NULL; |
| 538 return pPrivateData->pPrivate; | 537 return pPrivateData->pPrivate; |
| 539 } | 538 } |
| 540 | 539 |
| 541 void JS_FreePrivate(v8::Handle<v8::Object> pObj) | 540 void JS_FreePrivate(void* pPrivateData) |
| 541 { |
| 542 delete (CJS_PrivateData*)pPrivateData; |
| 543 } |
| 544 |
| 545 void JS_FreePrivate(v8::Local<v8::Object> pObj) |
| 542 { | 546 { |
| 543 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; | 547 if(pObj.IsEmpty() || !pObj->InternalFieldCount()) return; |
| 544 » v8::Handle<v8::External> ptr = v8::Handle<v8::External>::Cast(pObj->GetI
nternalField(0)); | 548 » JS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); |
| 545 » delete (CJS_PrivateData*)ptr->Value(); | 549 » pObj->SetAlignedPointerInInternalField(0, NULL); |
| 546 » v8::Local<v8::Context> context = pObj->CreationContext(); | 550 } |
| 547 | 551 |
| 548 » pObj->SetInternalField(0, v8::External::New(context->GetIsolate(), NULL)
); | 552 |
| 549 } | 553 v8::Local<v8::Value> JS_GetObjectValue(v8::Local<v8::Object> pObj) |
| 550 | |
| 551 | |
| 552 v8::Handle<v8::Value> JS_GetObjectValue(v8::Handle<v8::Object> pObj) | |
| 553 { | 554 { |
| 554 return pObj; | 555 return pObj; |
| 555 } | 556 } |
| 556 | 557 |
| 557 v8::Handle<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prop
ertyName, int Len = -1) | 558 v8::Local<v8::String> WSToJSString(IJS_Runtime* pJSRuntime, const wchar_t* Prope
rtyName, int Len = -1) |
| 558 { | 559 { |
| 559 CFX_WideString ws = CFX_WideString(PropertyName,Len); | 560 CFX_WideString ws = CFX_WideString(PropertyName,Len); |
| 560 CFX_ByteString bs = ws.UTF8Encode(); | 561 CFX_ByteString bs = ws.UTF8Encode(); |
| 561 if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); | 562 if(!pJSRuntime) pJSRuntime = v8::Isolate::GetCurrent(); |
| 562 » return v8::String::NewFromUtf8(pJSRuntime, bs.c_str()); | 563 » return v8::String::NewFromUtf8(pJSRuntime, bs.c_str(), v8::NewStringType
::kNormal).ToLocalChecked(); |
| 563 } | 564 } |
| 564 | 565 |
| 565 v8::Handle<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Handle<v8
::Object> pObj,const wchar_t* PropertyName) | 566 v8::Local<v8::Value> JS_GetObjectElement(IJS_Runtime* pJSRuntime, v8::Local<v8::
Object> pObj,const wchar_t* PropertyName) |
| 566 { | 567 { |
| 567 » if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 568 » if(pObj.IsEmpty()) return v8::Local<v8::Value>(); |
| 568 » return pObj->Get(WSToJSString(pJSRuntime,PropertyName)); | 569 v8::Local<v8::Value> val; |
| 569 } | 570 » if (!pObj->Get(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,
PropertyName)).ToLocal(&val)) return v8::Local<v8::Value>(); |
| 570 | 571 return val; |
| 571 v8::Handle<v8::Array> JS_GetObjectElementNames(v8::Handle<v8::Object> pObj) | 572 } |
| 572 { | 573 |
| 573 » if(pObj.IsEmpty()) return v8::Handle<v8::Array>(); | 574 v8::Local<v8::Array> JS_GetObjectElementNames(IJS_Runtime* pJSRuntime, v8::Local
<v8::Object> pObj) |
| 574 » return pObj->GetPropertyNames(); | 575 { |
| 575 } | 576 » if(pObj.IsEmpty()) return v8::Local<v8::Array>(); |
| 576 | 577 v8::Local<v8::Array> val; |
| 577 void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, const wchar_t* sValue) //VT_string | 578 » if (!pObj->GetPropertyNames(pJSRuntime->GetCurrentContext()).ToLocal(&va
l)) return v8::Local<v8::Array>(); |
| 578 { | 579 return val; |
| 579 » if(pObj.IsEmpty()) return; | 580 } |
| 580 » pObj->Set(WSToJSString(pJSRuntime, PropertyName), WSToJSString(pJSRuntim
e, sValue)); | 581 |
| 581 } | 582 void JS_PutObjectString(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, const wchar_t* sValue) //VT_string |
| 582 | 583 { |
| 583 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, int nValue) | 584 » if(pObj.IsEmpty()) return; |
| 584 { | 585 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime, Prop
ertyName), WSToJSString(pJSRuntime, sValue)).FromJust(); |
| 585 » if(pObj.IsEmpty()) return; | 586 } |
| 586 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Int32::New(pJSRuntim
e, nValue)); | 587 |
| 587 } | 588 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, int nValue) |
| 588 | 589 { |
| 589 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, float fValue) | 590 » if(pObj.IsEmpty()) return; |
| 590 { | 591 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Int32::New(pJSRuntime, nValue)).FromJust(); |
| 591 » if(pObj.IsEmpty()) return; | 592 } |
| 592 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRunti
me, (double)fValue)); | 593 |
| 593 } | 594 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, float fValue) |
| 594 | 595 { |
| 595 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, double dValue) | 596 » if(pObj.IsEmpty()) return; |
| 596 { | 597 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)fValue)).FromJust(); |
| 597 » if(pObj.IsEmpty()) return; | 598 } |
| 598 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Number::New(pJSRunti
me, (double)dValue)); | 599 |
| 599 } | 600 void JS_PutObjectNumber(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, double dValue) |
| 600 | 601 { |
| 601 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, co
nst wchar_t* PropertyName, bool bValue) | 602 » if(pObj.IsEmpty()) return; |
| 602 { | 603 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Number::New(pJSRuntime, (double)dValue)).FromJust(); |
| 603 » if(pObj.IsEmpty()) return; | 604 } |
| 604 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Boolean::New(pJSRunt
ime, bValue)); | 605 |
| 605 } | 606 void JS_PutObjectBoolean(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, con
st wchar_t* PropertyName, bool bValue) |
| 606 | 607 { |
| 607 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, con
st wchar_t* PropertyName, v8::Handle<v8::Object> pPut) | 608 » if(pObj.IsEmpty()) return; |
| 608 { | 609 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Boolean::New(pJSRuntime, bValue)).FromJust(); |
| 609 » if(pObj.IsEmpty()) return; | 610 } |
| 610 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),pPut); | 611 |
| 611 } | 612 void JS_PutObjectObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, cons
t wchar_t* PropertyName, v8::Local<v8::Object> pPut) |
| 612 | 613 { |
| 613 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object> pObj, const
wchar_t* PropertyName) | 614 » if(pObj.IsEmpty()) return; |
| 614 { | 615 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),pPut).FromJust(); |
| 615 » if(pObj.IsEmpty()) return; | 616 } |
| 616 » pObj->Set(WSToJSString(pJSRuntime,PropertyName),v8::Handle<v8::Object>()
); | 617 |
| 617 } | 618 void JS_PutObjectNull(IJS_Runtime* pJSRuntime,v8::Local<v8::Object> pObj, const
wchar_t* PropertyName) |
| 618 | 619 { |
| 619 v8::Handle<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) | 620 » if(pObj.IsEmpty()) return; |
| 621 » pObj->Set(pJSRuntime->GetCurrentContext(), WSToJSString(pJSRuntime,Prope
rtyName),v8::Local<v8::Object>()).FromJust(); |
| 622 } |
| 623 |
| 624 v8::Local<v8::Array> JS_NewArray(IJS_Runtime* pJSRuntime) |
| 620 { | 625 { |
| 621 return v8::Array::New(pJSRuntime); | 626 return v8::Array::New(pJSRuntime); |
| 622 } | 627 } |
| 623 | 628 |
| 624 unsigned JS_PutArrayElement(v8::Handle<v8::Array> pArray,unsigned index,v8::Hand
le<v8::Value> pValue,FXJSVALUETYPE eType) | 629 unsigned JS_PutArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::Array> pArray
,unsigned index,v8::Local<v8::Value> pValue,FXJSVALUETYPE eType) |
| 625 { | 630 { |
| 626 if(pArray.IsEmpty()) return 0; | 631 if(pArray.IsEmpty()) return 0; |
| 627 » pArray->Set(index, pValue); | 632 » if (pArray->Set(pJSRuntime->GetCurrentContext(), index, pValue).IsNothin
g()) return 0; |
| 628 return 1; | 633 return 1; |
| 629 } | 634 } |
| 630 | 635 |
| 631 v8::Handle<v8::Value> JS_GetArrayElemnet(v8::Handle<v8::Array> pArray,unsigned i
ndex) | 636 v8::Local<v8::Value> JS_GetArrayElement(IJS_Runtime* pJSRuntime, v8::Local<v8::A
rray> pArray,unsigned index) |
| 632 { | 637 { |
| 633 » if(pArray.IsEmpty()) return v8::Handle<v8::Value>(); | 638 » if(pArray.IsEmpty()) return v8::Local<v8::Value>(); |
| 634 » return pArray->Get(index); | 639 v8::Local<v8::Value> val; |
| 635 } | 640 » if (pArray->Get(pJSRuntime->GetCurrentContext(), index).ToLocal(&val)) r
eturn v8::Local<v8::Value>(); |
| 636 | 641 return val; |
| 637 unsigned JS_GetArrayLength(v8::Handle<v8::Array> pArray) | 642 } |
| 643 |
| 644 unsigned JS_GetArrayLength(v8::Local<v8::Array> pArray) |
| 638 { | 645 { |
| 639 if(pArray.IsEmpty()) return 0; | 646 if(pArray.IsEmpty()) return 0; |
| 640 return pArray->Length(); | 647 return pArray->Length(); |
| 641 } | 648 } |
| 642 | 649 |
| 643 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number) | 650 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,int number) |
| 644 { | 651 { |
| 645 return v8::Int32::New(pJSRuntime, number); | 652 return v8::Int32::New(pJSRuntime, number); |
| 646 } | 653 } |
| 647 | 654 |
| 648 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number) | 655 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,double number) |
| 649 { | 656 { |
| 650 return v8::Number::New(pJSRuntime, number); | 657 return v8::Number::New(pJSRuntime, number); |
| 651 } | 658 } |
| 652 | 659 |
| 653 v8::Handle<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number) | 660 v8::Local<v8::Value> JS_NewNumber(IJS_Runtime* pJSRuntime,float number) |
| 654 { | 661 { |
| 655 return v8::Number::New(pJSRuntime, (float)number); | 662 return v8::Number::New(pJSRuntime, (float)number); |
| 656 } | 663 } |
| 657 | 664 |
| 658 v8::Handle<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b) | 665 v8::Local<v8::Value> JS_NewBoolean(IJS_Runtime* pJSRuntime,bool b) |
| 659 { | 666 { |
| 660 return v8::Boolean::New(pJSRuntime, b); | 667 return v8::Boolean::New(pJSRuntime, b); |
| 661 } | 668 } |
| 662 | 669 |
| 663 v8::Handle<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Handle<v8::Object
> pObj) | 670 v8::Local<v8::Value> JS_NewObject(IJS_Runtime* pJSRuntime,v8::Local<v8::Object>
pObj) |
| 664 { | 671 { |
| 665 » if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 672 » if(pObj.IsEmpty()) return v8::Local<v8::Value>(); |
| 666 return pObj->Clone(); | 673 return pObj->Clone(); |
| 667 } | 674 } |
| 668 | 675 |
| 669 v8::Handle<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Handle<v8::Array
> pObj) | 676 v8::Local<v8::Value> JS_NewObject2(IJS_Runtime* pJSRuntime,v8::Local<v8::Array>
pObj) |
| 670 { | 677 { |
| 671 » if(pObj.IsEmpty()) return v8::Handle<v8::Value>(); | 678 » if(pObj.IsEmpty()) return v8::Local<v8::Value>(); |
| 672 return pObj->Clone(); | 679 return pObj->Clone(); |
| 673 } | 680 } |
| 674 | 681 |
| 675 | 682 |
| 676 v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string
) | 683 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string) |
| 677 { | 684 { |
| 678 return WSToJSString(pJSRuntime, string); | 685 return WSToJSString(pJSRuntime, string); |
| 679 } | 686 } |
| 680 | 687 |
| 681 v8::Handle<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string
, unsigned nLen) | 688 v8::Local<v8::Value> JS_NewString(IJS_Runtime* pJSRuntime,const wchar_t* string,
unsigned nLen) |
| 682 { | 689 { |
| 683 return WSToJSString(pJSRuntime, string, nLen); | 690 return WSToJSString(pJSRuntime, string, nLen); |
| 684 } | 691 } |
| 685 | 692 |
| 686 v8::Handle<v8::Value> JS_NewNull() | 693 v8::Local<v8::Value> JS_NewNull() |
| 687 { | 694 { |
| 688 » return v8::Handle<v8::Value>(); | 695 » return v8::Local<v8::Value>(); |
| 689 } | 696 } |
| 690 | 697 |
| 691 v8::Handle<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d) | 698 v8::Local<v8::Value> JS_NewDate(IJS_Runtime* pJSRuntime,double d) |
| 692 { | 699 { |
| 693 » return v8::Date::New(pJSRuntime, d); | 700 » return v8::Date::New(pJSRuntime->GetCurrentContext(), d).ToLocalChecked(
); |
| 694 } | 701 } |
| 695 | 702 |
| 696 v8::Handle<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) | 703 v8::Local<v8::Value> JS_NewValue(IJS_Runtime* pJSRuntime) |
| 697 { | 704 { |
| 698 » return v8::Handle<v8::Value>(); | 705 » return v8::Local<v8::Value>(); |
| 699 } | 706 } |
| 700 | 707 |
| 701 v8::Handle<v8::Value> JS_GetListValue(v8::Handle<v8::Value> pList, int index) | 708 v8::Local<v8::Value> JS_GetListValue(IJS_Runtime* pJSRuntime, v8::Local<v8::Valu
e> pList, int index) |
| 702 { | 709 { |
| 703 | 710 |
| 711 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 704 if(!pList.IsEmpty() && pList->IsObject()) | 712 if(!pList.IsEmpty() && pList->IsObject()) |
| 705 { | 713 { |
| 706 » » v8::Local<v8::Object> obj = pList->ToObject(); | 714 » » v8::Local<v8::Object> obj; |
| 707 » » return obj->Get(index); | 715 if (pList->ToObject(context).ToLocal(&obj)) |
| 716 { |
| 717 v8::Local<v8::Value> val; |
| 718 if (obj->Get(context, index).ToLocal(&val)) return val; |
| 719 } |
| 708 } | 720 } |
| 709 » return v8::Handle<v8::Value>(); | 721 » return v8::Local<v8::Value>(); |
| 710 } | 722 } |
| 711 | 723 |
| 712 int» JS_ToInt32(v8::Handle<v8::Value> pValue) | 724 int» JS_ToInt32(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) |
| 713 { | 725 { |
| 714 if(pValue.IsEmpty()) return 0; | 726 if(pValue.IsEmpty()) return 0; |
| 715 » return pValue->ToInt32()->Value(); | 727 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 716 } | 728 » return pValue->ToInt32(context).ToLocalChecked()->Value(); |
| 717 | 729 } |
| 718 bool JS_ToBoolean(v8::Handle<v8::Value> pValue) | 730 |
| 731 bool JS_ToBoolean(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) |
| 719 { | 732 { |
| 720 if(pValue.IsEmpty()) return false; | 733 if(pValue.IsEmpty()) return false; |
| 721 » return pValue->ToBoolean()->Value(); | 734 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 722 } | 735 » return pValue->ToBoolean(context).ToLocalChecked()->Value(); |
| 723 | 736 } |
| 724 double JS_ToNumber(v8::Handle<v8::Value> pValue) | 737 |
| 738 double JS_ToNumber(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue) |
| 725 { | 739 { |
| 726 if(pValue.IsEmpty()) return 0.0; | 740 if(pValue.IsEmpty()) return 0.0; |
| 727 » return pValue->ToNumber()->Value(); | 741 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 728 } | 742 » return pValue->ToNumber(context).ToLocalChecked()->Value(); |
| 729 | 743 } |
| 730 v8::Handle<v8::Object> JS_ToObject(v8::Handle<v8::Value> pValue) | 744 |
| 731 { | 745 v8::Local<v8::Object> JS_ToObject(IJS_Runtime* pJSRuntime, v8::Local<v8::Value>
pValue) |
| 732 » if(pValue.IsEmpty()) return v8::Handle<v8::Object>(); | 746 { |
| 733 » return pValue->ToObject(); | 747 » if(pValue.IsEmpty()) return v8::Local<v8::Object>(); |
| 734 } | 748 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 735 | 749 » return pValue->ToObject(context).ToLocalChecked(); |
| 736 CFX_WideString» JS_ToString(v8::Handle<v8::Value> pValue) | 750 } |
| 751 |
| 752 CFX_WideString» JS_ToString(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pValue
) |
| 737 { | 753 { |
| 738 if(pValue.IsEmpty()) return L""; | 754 if(pValue.IsEmpty()) return L""; |
| 739 » v8::String::Utf8Value s(pValue->ToString()); | 755 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 756 » v8::String::Utf8Value s(pValue->ToString(context).ToLocalChecked()); |
| 740 return CFX_WideString::FromUTF8(*s, s.length()); | 757 return CFX_WideString::FromUTF8(*s, s.length()); |
| 741 } | 758 } |
| 742 | 759 |
| 743 v8::Handle<v8::Array> JS_ToArray(v8::Handle<v8::Value> pValue) | 760 v8::Local<v8::Array> JS_ToArray(IJS_Runtime* pJSRuntime, v8::Local<v8::Value> pV
alue) |
| 744 { | 761 { |
| 745 » if(pValue.IsEmpty()) return v8::Handle<v8::Array>(); | 762 » if(pValue.IsEmpty()) return v8::Local<v8::Array>(); |
| 746 » return v8::Handle<v8::Array>::Cast(pValue->ToObject()); | 763 v8::Local<v8::Context> context = pJSRuntime->GetCurrentContext(); |
| 747 } | 764 » return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalCheck
ed()); |
| 748 | 765 } |
| 749 void JS_ValueCopy(v8::Handle<v8::Value>& pTo, v8::Handle<v8::Value> pFrom) | 766 |
| 767 void JS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) |
| 750 { | 768 { |
| 751 pTo = pFrom; | 769 pTo = pFrom; |
| 752 } | 770 } |
| 753 | 771 |
| 754 | 772 |
| 755 //JavaScript time implement begin. | 773 //JavaScript time implement begin. |
| 756 | 774 |
| 757 double _getLocalTZA() | 775 double _getLocalTZA() |
| 758 { | 776 { |
| 759 if(!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) | 777 if(!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 | 988 |
| 971 double JS_DateParse(const wchar_t* string) | 989 double JS_DateParse(const wchar_t* string) |
| 972 { | 990 { |
| 973 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 991 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
| 974 v8::Isolate::Scope isolate_scope(pIsolate); | 992 v8::Isolate::Scope isolate_scope(pIsolate); |
| 975 v8::HandleScope scope(pIsolate); | 993 v8::HandleScope scope(pIsolate); |
| 976 | 994 |
| 977 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 995 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
| 978 | 996 |
| 979 //Use the built-in object method. | 997 //Use the built-in object method. |
| 980 » v8::Local<v8::Value> v = context->Global()->Get(v8::String::NewFromUtf8(
pIsolate, "Date")); | 998 » v8::Local<v8::Value> v = context->Global()->Get(context, v8::String::New
FromUtf8(pIsolate, "Date", v8::NewStringType::kNormal).ToLocalChecked()).ToLocal
Checked(); |
| 981 if(v->IsObject()) | 999 if(v->IsObject()) |
| 982 { | 1000 { |
| 983 » » v8::Local<v8::Object> o = v->ToObject(); | 1001 » » v8::Local<v8::Object> o = v->ToObject(context).ToLocalChecked(); |
| 984 » » v = o->Get(v8::String::NewFromUtf8(pIsolate, "parse")); | 1002 » » v = o->Get(context,v8::String::NewFromUtf8(pIsolate, "parse", v8
::NewStringType::kNormal).ToLocalChecked()).ToLocalChecked(); |
| 985 if(v->IsFunction()) | 1003 if(v->IsFunction()) |
| 986 { | 1004 { |
| 987 » » » v8::Local<v8::Function> funC = v8::Handle<v8::Function>:
:Cast(v); | 1005 » » » v8::Local<v8::Function> funC = v8::Local<v8::Function>::
Cast(v); |
| 988 | 1006 |
| 989 const int argc = 1; | 1007 const int argc = 1; |
| 990 v8::Local<v8::String> timeStr = WSToJSString(pIsolate, s
tring); | 1008 v8::Local<v8::String> timeStr = WSToJSString(pIsolate, s
tring); |
| 991 » » » v8::Handle<v8::Value> argv[argc] = {timeStr}; | 1009 » » » v8::Local<v8::Value> argv[argc] = {timeStr}; |
| 992 » » » v = funC->Call(context->Global(), argc, argv); | 1010 » » » v = funC->Call(context, context->Global(), argc, argv).T
oLocalChecked(); |
| 993 if(v->IsNumber()) | 1011 if(v->IsNumber()) |
| 994 { | 1012 { |
| 995 » » » » double date = v->ToNumber()->Value(); | 1013 » » » » double date = v->ToNumber(context).ToLocalCheck
ed()->Value(); |
| 996 if(!_isfinite(date)) return date; | 1014 if(!_isfinite(date)) return date; |
| 997 return date + _getLocalTZA() + _getDaylightSavin
gTA(date); | 1015 return date + _getLocalTZA() + _getDaylightSavin
gTA(date); |
| 998 } | 1016 } |
| 999 | 1017 |
| 1000 } | 1018 } |
| 1001 } | 1019 } |
| 1002 return 0; | 1020 return 0; |
| 1003 } | 1021 } |
| 1004 | 1022 |
| 1005 double JS_MakeDay(int nYear, int nMonth, int nDate) | 1023 double JS_MakeDay(int nYear, int nMonth, int nDate) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 { | 1062 { |
| 1045 return d != d; | 1063 return d != d; |
| 1046 } | 1064 } |
| 1047 | 1065 |
| 1048 double JS_LocalTime(double d) | 1066 double JS_LocalTime(double d) |
| 1049 { | 1067 { |
| 1050 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1068 return JS_GetDateTime() + _getDaylightSavingTA(d); |
| 1051 } | 1069 } |
| 1052 | 1070 |
| 1053 //JavaScript time implement End. | 1071 //JavaScript time implement End. |
| OLD | NEW |