| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 pArray->Add(pObjDef); | 86 pArray->Add(pObjDef); |
| 87 return pArray->GetSize()-1; | 87 return pArray->GetSize()-1; |
| 88 } | 88 } |
| 89 | 89 |
| 90 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
MethodName, v8::FunctionCallback pMethodCall, unsigned nParamNum) | 90 int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
MethodName, v8::FunctionCallback pMethodCall, unsigned nParamNum) |
| 91 { | 91 { |
| 92 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 92 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 93 v8::Isolate::Scope isolate_scope(isolate); | 93 v8::Isolate::Scope isolate_scope(isolate); |
| 94 v8::HandleScope handle_scope(isolate); | 94 v8::HandleScope handle_scope(isolate); |
| 95 | 95 |
| 96 » CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sMethodName); | 96 » CFX_WideString ws = CFX_WideString(sMethodName); |
| 97 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 97 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
| 98 | 98 |
| 99 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 99 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 100 if(!pArray) return 0; | 100 if(!pArray) return 0; |
| 101 | 101 |
| 102 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 102 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 103 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 103 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 104 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 104 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 105 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly); | 105 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
v8::FunctionTemplate::New(isolate, pMethodCall), v8::ReadOnly); |
| 106 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 106 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 107 return 0; | 107 return 0; |
| 108 } | 108 } |
| 109 | 109 |
| 110 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro
pPut) | 110 int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
sPropName, v8::AccessorGetterCallback pPropGet, v8::AccessorSetterCallback pPro
pPut) |
| 111 { | 111 { |
| 112 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 112 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 113 v8::Isolate::Scope isolate_scope(isolate); | 113 v8::Isolate::Scope isolate_scope(isolate); |
| 114 v8::HandleScope handle_scope(isolate); | 114 v8::HandleScope handle_scope(isolate); |
| 115 | 115 |
| 116 » CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sPropName); | 116 » CFX_WideString ws = CFX_WideString(sPropName); |
| 117 CFX_ByteString bsPropertyName = ws.UTF8Encode(); | 117 CFX_ByteString bsPropertyName = ws.UTF8Encode(); |
| 118 | 118 |
| 119 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 119 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 120 if(!pArray) return 0; | 120 if(!pArray) return 0; |
| 121 | 121 |
| 122 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 122 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 123 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 123 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 124 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 124 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 125 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsProper
tyName)), pPropGet, pPropPut); | 125 objTemp->SetAccessor(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsProper
tyName)), pPropGet, pPropPut); |
| 126 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 126 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 146 | 146 |
| 147 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
onstName, v8::Handle<v8::Value> pDefault) | 147 int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
onstName, v8::Handle<v8::Value> pDefault) |
| 148 { | 148 { |
| 149 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 149 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 150 v8::Isolate::Scope isolate_scope(isolate); | 150 v8::Isolate::Scope isolate_scope(isolate); |
| 151 v8::HandleScope handle_scope(isolate); | 151 v8::HandleScope handle_scope(isolate); |
| 152 | 152 |
| 153 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); | 153 CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); |
| 154 if(!pArray) return 0; | 154 if(!pArray) return 0; |
| 155 | 155 |
| 156 » CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sConstName); | 156 » CFX_WideString ws = CFX_WideString(sConstName); |
| 157 CFX_ByteString bsConstName = ws.UTF8Encode(); | 157 CFX_ByteString bsConstName = ws.UTF8Encode(); |
| 158 | 158 |
| 159 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; | 159 if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0; |
| 160 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; | 160 CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID)
; |
| 161 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); | 161 v8::Local<v8::ObjectTemplate> objTemp = v8::Local<v8::ObjectTemplate>::N
ew(isolate, pObjDef->m_objTemplate); |
| 162 objTemp->Set(isolate, FX_LPCSTR(bsConstName), pDefault); | 162 objTemp->Set(isolate, FX_LPCSTR(bsConstName), pDefault); |
| 163 pObjDef->m_objTemplate.Reset(isolate,objTemp); | 163 pObjDef->m_objTemplate.Reset(isolate,objTemp); |
| 164 return 0; | 164 return 0; |
| 165 } | 165 } |
| 166 | 166 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 181 static v8::Persistent<v8::ObjectTemplate> gloabalObjectTemplate; | 181 static v8::Persistent<v8::ObjectTemplate> gloabalObjectTemplate; |
| 182 return gloabalObjectTemplate; | 182 return gloabalObjectTemplate; |
| 183 } | 183 } |
| 184 | 184 |
| 185 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v
8::FunctionCallback pMethodCall, unsigned nParamNum) | 185 int JS_DefineGlobalMethod(IJS_Runtime* pJSRuntime, const wchar_t* sMethodName, v
8::FunctionCallback pMethodCall, unsigned nParamNum) |
| 186 { | 186 { |
| 187 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 187 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 188 v8::Isolate::Scope isolate_scope(isolate); | 188 v8::Isolate::Scope isolate_scope(isolate); |
| 189 v8::HandleScope handle_scope(isolate); | 189 v8::HandleScope handle_scope(isolate); |
| 190 | 190 |
| 191 » CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sMethodName); | 191 » CFX_WideString ws = CFX_WideString(sMethodName); |
| 192 CFX_ByteString bsMethodName = ws.UTF8Encode(); | 192 CFX_ByteString bsMethodName = ws.UTF8Encode(); |
| 193 | 193 |
| 194 v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(iso
late, pMethodCall); | 194 v8::Local<v8::FunctionTemplate> funTempl = v8::FunctionTemplate::New(iso
late, pMethodCall); |
| 195 v8::Local<v8::ObjectTemplate> objTemp; | 195 v8::Local<v8::ObjectTemplate> objTemp; |
| 196 | 196 |
| 197 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 197 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); |
| 198 if(globalObjTemp.IsEmpty()) | 198 if(globalObjTemp.IsEmpty()) |
| 199 objTemp = v8::ObjectTemplate::New(isolate); | 199 objTemp = v8::ObjectTemplate::New(isolate); |
| 200 else | 200 else |
| 201 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); | 201 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); |
| 202 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
funTempl, v8::ReadOnly); | 202 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsMethodName)),
funTempl, v8::ReadOnly); |
| 203 | 203 |
| 204 globalObjTemp.Reset(isolate,objTemp); | 204 globalObjTemp.Reset(isolate,objTemp); |
| 205 | 205 |
| 206 return 0; | 206 return 0; |
| 207 } | 207 } |
| 208 | 208 |
| 209 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
:Handle<v8::Value> pDefault) | 209 int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstName, v8:
:Handle<v8::Value> pDefault) |
| 210 { | 210 { |
| 211 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; | 211 v8::Isolate* isolate = (v8::Isolate*)pJSRuntime; |
| 212 v8::Isolate::Scope isolate_scope(isolate); | 212 v8::Isolate::Scope isolate_scope(isolate); |
| 213 v8::HandleScope handle_scope(isolate); | 213 v8::HandleScope handle_scope(isolate); |
| 214 | 214 |
| 215 » CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sConstName); | 215 » CFX_WideString ws = CFX_WideString(sConstName); |
| 216 CFX_ByteString bsConst= ws.UTF8Encode(); | 216 CFX_ByteString bsConst= ws.UTF8Encode(); |
| 217 | 217 |
| 218 v8::Local<v8::ObjectTemplate> objTemp; | 218 v8::Local<v8::ObjectTemplate> objTemp; |
| 219 | 219 |
| 220 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); | 220 v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemp
late(pJSRuntime); |
| 221 if(globalObjTemp.IsEmpty()) | 221 if(globalObjTemp.IsEmpty()) |
| 222 objTemp = v8::ObjectTemplate::New(isolate); | 222 objTemp = v8::ObjectTemplate::New(isolate); |
| 223 else | 223 else |
| 224 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); | 224 objTemp = v8::Local<v8::ObjectTemplate>::New(isolate, globalObjT
emp); |
| 225 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst)), pDefa
ult, v8::ReadOnly); | 225 objTemp->Set(v8::String::NewFromUtf8(isolate, FX_LPCSTR(bsConst)), pDefa
ult, v8::ReadOnly); |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 { | 1034 { |
| 1035 return d != d; | 1035 return d != d; |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 double JS_LocalTime(double d) | 1038 double JS_LocalTime(double d) |
| 1039 { | 1039 { |
| 1040 return JS_GetDateTime() + _getDaylightSavingTA(d); | 1040 return JS_GetDateTime() + _getDaylightSavingTA(d); |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 //JavaScript time implement End. | 1043 //JavaScript time implement End. |
| OLD | NEW |