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 "xfa/fxjse/value.h" | 7 #include "xfa/fxjse/value.h" |
8 | 8 |
9 #include <math.h> | 9 #include <math.h> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 FX_BOOL FXJSE_Value_IsUTF8String(FXJSE_HVALUE hValue) { | 29 FX_BOOL FXJSE_Value_IsUTF8String(FXJSE_HVALUE hValue) { |
30 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 30 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
31 return lpValue && lpValue->IsString(); | 31 return lpValue && lpValue->IsString(); |
32 } | 32 } |
33 | 33 |
34 FX_BOOL FXJSE_Value_IsNumber(FXJSE_HVALUE hValue) { | 34 FX_BOOL FXJSE_Value_IsNumber(FXJSE_HVALUE hValue) { |
35 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 35 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
36 return lpValue && lpValue->IsNumber(); | 36 return lpValue && lpValue->IsNumber(); |
37 } | 37 } |
38 | 38 |
39 FX_BOOL FXJSE_Value_IsInteger(FXJSE_HVALUE hValue) { | |
40 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | |
41 return lpValue && lpValue->IsInteger(); | |
42 } | |
43 | |
44 FX_BOOL FXJSE_Value_IsObject(FXJSE_HVALUE hValue) { | 39 FX_BOOL FXJSE_Value_IsObject(FXJSE_HVALUE hValue) { |
45 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 40 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
46 return lpValue && lpValue->IsObject(); | 41 return lpValue && lpValue->IsObject(); |
47 } | 42 } |
48 | 43 |
49 FX_BOOL FXJSE_Value_IsArray(FXJSE_HVALUE hValue) { | 44 FX_BOOL FXJSE_Value_IsArray(FXJSE_HVALUE hValue) { |
50 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 45 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
51 return lpValue && lpValue->IsArray(); | 46 return lpValue && lpValue->IsArray(); |
52 } | 47 } |
53 | 48 |
54 FX_BOOL FXJSE_Value_IsFunction(FXJSE_HVALUE hValue) { | 49 FX_BOOL FXJSE_Value_IsFunction(FXJSE_HVALUE hValue) { |
55 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 50 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
56 return lpValue && lpValue->IsFunction(); | 51 return lpValue && lpValue->IsFunction(); |
57 } | 52 } |
58 | 53 |
59 FX_BOOL FXJSE_Value_IsDate(FXJSE_HVALUE hValue) { | |
60 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | |
61 return lpValue && lpValue->IsDate(); | |
62 } | |
63 | |
64 FX_BOOL FXJSE_Value_ToBoolean(FXJSE_HVALUE hValue) { | 54 FX_BOOL FXJSE_Value_ToBoolean(FXJSE_HVALUE hValue) { |
65 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToBoolean(); | 55 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToBoolean(); |
66 } | 56 } |
67 | 57 |
68 FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue) { | 58 FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue) { |
69 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToFloat(); | 59 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToFloat(); |
70 } | 60 } |
71 | 61 |
72 double FXJSE_Value_ToDouble(FXJSE_HVALUE hValue) { | 62 double FXJSE_Value_ToDouble(FXJSE_HVALUE hValue) { |
73 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToDouble(); | 63 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToDouble(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 119 } |
130 } | 120 } |
131 | 121 |
132 void FXJSE_Value_SetArray(FXJSE_HVALUE hValue, | 122 void FXJSE_Value_SetArray(FXJSE_HVALUE hValue, |
133 uint32_t uValueCount, | 123 uint32_t uValueCount, |
134 FXJSE_HVALUE* rgValues) { | 124 FXJSE_HVALUE* rgValues) { |
135 reinterpret_cast<CFXJSE_Value*>(hValue) | 125 reinterpret_cast<CFXJSE_Value*>(hValue) |
136 ->SetArray(uValueCount, reinterpret_cast<CFXJSE_Value**>(rgValues)); | 126 ->SetArray(uValueCount, reinterpret_cast<CFXJSE_Value**>(rgValues)); |
137 } | 127 } |
138 | 128 |
139 void FXJSE_Value_SetDate(FXJSE_HVALUE hValue, double dDouble) { | |
140 reinterpret_cast<CFXJSE_Value*>(hValue)->SetDate(dDouble); | |
141 } | |
142 | |
143 void FXJSE_Value_Set(FXJSE_HVALUE hValue, FXJSE_HVALUE hOriginalValue) { | 129 void FXJSE_Value_Set(FXJSE_HVALUE hValue, FXJSE_HVALUE hOriginalValue) { |
144 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 130 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
145 CFXJSE_Value* lpOriginalValue = | 131 CFXJSE_Value* lpOriginalValue = |
146 reinterpret_cast<CFXJSE_Value*>(hOriginalValue); | 132 reinterpret_cast<CFXJSE_Value*>(hOriginalValue); |
147 ASSERT(lpValue && lpOriginalValue); | 133 ASSERT(lpValue && lpOriginalValue); |
148 lpValue->Assign(lpOriginalValue); | 134 lpValue->Assign(lpOriginalValue); |
149 } | 135 } |
150 | 136 |
151 FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue, | 137 FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue, |
152 const CFX_ByteStringC& szPropName, | 138 const CFX_ByteStringC& szPropName, |
(...skipping 15 matching lines...) Expand all Loading... |
168 | 154 |
169 FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue, | 155 FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue, |
170 uint32_t uPropIdx, | 156 uint32_t uPropIdx, |
171 FXJSE_HVALUE hPropValue) { | 157 FXJSE_HVALUE hPropValue) { |
172 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 158 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
173 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); | 159 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); |
174 ASSERT(lpValue && lpPropValue); | 160 ASSERT(lpValue && lpPropValue); |
175 return lpValue->GetObjectProperty(uPropIdx, lpPropValue); | 161 return lpValue->GetObjectProperty(uPropIdx, lpPropValue); |
176 } | 162 } |
177 | 163 |
178 FX_BOOL FXJSE_Value_SetObjectPropByIdx(FXJSE_HVALUE hValue, | |
179 uint32_t uPropIdx, | |
180 FXJSE_HVALUE hPropValue) { | |
181 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | |
182 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); | |
183 ASSERT(lpValue && lpPropValue); | |
184 return lpValue->SetObjectProperty(uPropIdx, lpPropValue); | |
185 } | |
186 | |
187 FX_BOOL FXJSE_Value_DeleteObjectProp(FXJSE_HVALUE hValue, | 164 FX_BOOL FXJSE_Value_DeleteObjectProp(FXJSE_HVALUE hValue, |
188 const CFX_ByteStringC& szPropName) { | 165 const CFX_ByteStringC& szPropName) { |
189 return reinterpret_cast<CFXJSE_Value*>(hValue) | 166 return reinterpret_cast<CFXJSE_Value*>(hValue) |
190 ->DeleteObjectProperty(szPropName); | 167 ->DeleteObjectProperty(szPropName); |
191 } | 168 } |
192 | 169 |
193 FX_BOOL FXJSE_Value_ObjectHasOwnProp(FXJSE_HVALUE hValue, | 170 FX_BOOL FXJSE_Value_ObjectHasOwnProp(FXJSE_HVALUE hValue, |
194 const CFX_ByteStringC& szPropName, | 171 const CFX_ByteStringC& szPropName, |
195 FX_BOOL bUseTypeGetter) { | 172 FX_BOOL bUseTypeGetter) { |
196 return reinterpret_cast<CFXJSE_Value*>(hValue) | 173 return reinterpret_cast<CFXJSE_Value*>(hValue) |
(...skipping 12 matching lines...) Expand all Loading... |
209 FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, | 186 FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, |
210 FXJSE_HVALUE hOldFunction, | 187 FXJSE_HVALUE hOldFunction, |
211 FXJSE_HVALUE hNewThis) { | 188 FXJSE_HVALUE hNewThis) { |
212 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 189 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
213 CFXJSE_Value* lpOldFunction = reinterpret_cast<CFXJSE_Value*>(hOldFunction); | 190 CFXJSE_Value* lpOldFunction = reinterpret_cast<CFXJSE_Value*>(hOldFunction); |
214 CFXJSE_Value* lpNewThis = reinterpret_cast<CFXJSE_Value*>(hNewThis); | 191 CFXJSE_Value* lpNewThis = reinterpret_cast<CFXJSE_Value*>(hNewThis); |
215 ASSERT(lpValue && lpOldFunction && lpNewThis); | 192 ASSERT(lpValue && lpOldFunction && lpNewThis); |
216 return lpValue->SetFunctionBind(lpOldFunction, lpNewThis); | 193 return lpValue->SetFunctionBind(lpOldFunction, lpNewThis); |
217 } | 194 } |
218 | 195 |
219 FX_BOOL FXJSE_Value_CallFunction(FXJSE_HVALUE hFunction, | |
220 FXJSE_HVALUE hThis, | |
221 FXJSE_HVALUE hRetValue, | |
222 uint32_t nArgCount, | |
223 FXJSE_HVALUE* lpArgs) { | |
224 CFXJSE_Value* lpThis = reinterpret_cast<CFXJSE_Value*>(hThis); | |
225 CFXJSE_Value* lpRetValue = reinterpret_cast<CFXJSE_Value*>(hRetValue); | |
226 return reinterpret_cast<CFXJSE_Value*>(hFunction) | |
227 ->Call(lpThis, lpRetValue, nArgCount, lpArgs); | |
228 } | |
229 | |
230 FXJSE_HVALUE FXJSE_Value_Create(FXJSE_HRUNTIME hRuntime) { | 196 FXJSE_HVALUE FXJSE_Value_Create(FXJSE_HRUNTIME hRuntime) { |
231 return reinterpret_cast<FXJSE_HVALUE>( | 197 return reinterpret_cast<FXJSE_HVALUE>( |
232 CFXJSE_Value::Create(reinterpret_cast<v8::Isolate*>(hRuntime))); | 198 CFXJSE_Value::Create(reinterpret_cast<v8::Isolate*>(hRuntime))); |
233 } | 199 } |
234 | 200 |
235 void FXJSE_Value_Release(FXJSE_HVALUE hValue) { | 201 void FXJSE_Value_Release(FXJSE_HVALUE hValue) { |
236 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 202 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); |
237 delete lpValue; | 203 delete lpValue; |
238 } | 204 } |
239 | 205 |
240 FXJSE_HRUNTIME FXJSE_Value_GetRuntime(FXJSE_HVALUE hValue) { | |
241 return reinterpret_cast<FXJSE_HRUNTIME>( | |
242 reinterpret_cast<CFXJSE_Value*>(hValue)->GetIsolate()); | |
243 } | |
244 | |
245 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, | 206 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, |
246 const CFX_ByteStringC& utf8Message) { | 207 const CFX_ByteStringC& utf8Message) { |
247 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 208 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
248 ASSERT(pIsolate); | 209 ASSERT(pIsolate); |
249 | 210 |
250 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); | 211 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); |
251 v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( | 212 v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( |
252 pIsolate, utf8Message.c_str(), v8::String::kNormalString, | 213 pIsolate, utf8Message.c_str(), v8::String::kNormalString, |
253 utf8Message.GetLength()); | 214 utf8Message.GetLength()); |
254 v8::Local<v8::Value> hError; | 215 v8::Local<v8::Value> hError; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 if (lpRetValue) | 534 if (lpRetValue) |
574 lpRetValue->ForceSetValue(hReturnValue); | 535 lpRetValue->ForceSetValue(hReturnValue); |
575 | 536 |
576 if (lpLocalArgs) { | 537 if (lpLocalArgs) { |
577 for (uint32_t i = 0; i < nArgCount; i++) | 538 for (uint32_t i = 0; i < nArgCount; i++) |
578 lpLocalArgs[i].~Local(); | 539 lpLocalArgs[i].~Local(); |
579 FX_Free(lpLocalArgs); | 540 FX_Free(lpLocalArgs); |
580 } | 541 } |
581 return bRetValue; | 542 return bRetValue; |
582 } | 543 } |
OLD | NEW |