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 |
11 #include "xfa/fxjse/class.h" | 11 #include "xfa/fxjse/class.h" |
12 #include "xfa/fxjse/util_inline.h" | 12 #include "xfa/fxjse/util_inline.h" |
13 | 13 |
14 FX_BOOL FXJSE_Value_IsUndefined(FXJSE_HVALUE hValue) { | 14 FX_BOOL FXJSE_Value_IsUndefined(CFXJSE_Value* pValue) { |
15 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 15 return pValue && pValue->IsUndefined(); |
16 return lpValue && lpValue->IsUndefined(); | |
17 } | 16 } |
18 | 17 |
19 FX_BOOL FXJSE_Value_IsNull(FXJSE_HVALUE hValue) { | 18 FX_BOOL FXJSE_Value_IsNull(CFXJSE_Value* pValue) { |
20 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 19 return pValue && pValue->IsNull(); |
21 return lpValue && lpValue->IsNull(); | |
22 } | 20 } |
23 | 21 |
24 FX_BOOL FXJSE_Value_IsBoolean(FXJSE_HVALUE hValue) { | 22 FX_BOOL FXJSE_Value_IsBoolean(CFXJSE_Value* pValue) { |
25 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 23 return pValue && pValue->IsBoolean(); |
26 return lpValue && lpValue->IsBoolean(); | |
27 } | 24 } |
28 | 25 |
29 FX_BOOL FXJSE_Value_IsUTF8String(FXJSE_HVALUE hValue) { | 26 FX_BOOL FXJSE_Value_IsUTF8String(CFXJSE_Value* pValue) { |
30 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 27 return pValue && pValue->IsString(); |
31 return lpValue && lpValue->IsString(); | |
32 } | 28 } |
33 | 29 |
34 FX_BOOL FXJSE_Value_IsNumber(FXJSE_HVALUE hValue) { | 30 FX_BOOL FXJSE_Value_IsNumber(CFXJSE_Value* pValue) { |
35 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 31 return pValue && pValue->IsNumber(); |
36 return lpValue && lpValue->IsNumber(); | |
37 } | 32 } |
38 | 33 |
39 FX_BOOL FXJSE_Value_IsObject(FXJSE_HVALUE hValue) { | 34 FX_BOOL FXJSE_Value_IsObject(CFXJSE_Value* pValue) { |
40 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 35 return pValue && pValue->IsObject(); |
41 return lpValue && lpValue->IsObject(); | |
42 } | 36 } |
43 | 37 |
44 FX_BOOL FXJSE_Value_IsArray(FXJSE_HVALUE hValue) { | 38 FX_BOOL FXJSE_Value_IsArray(CFXJSE_Value* pValue) { |
45 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 39 return pValue && pValue->IsArray(); |
46 return lpValue && lpValue->IsArray(); | |
47 } | 40 } |
48 | 41 |
49 FX_BOOL FXJSE_Value_IsFunction(FXJSE_HVALUE hValue) { | 42 FX_BOOL FXJSE_Value_IsFunction(CFXJSE_Value* pValue) { |
50 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 43 return pValue && pValue->IsFunction(); |
51 return lpValue && lpValue->IsFunction(); | |
52 } | 44 } |
53 | 45 |
54 FX_BOOL FXJSE_Value_ToBoolean(FXJSE_HVALUE hValue) { | 46 FX_BOOL FXJSE_Value_ToBoolean(CFXJSE_Value* pValue) { |
55 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToBoolean(); | 47 return pValue->ToBoolean(); |
56 } | 48 } |
57 | 49 |
58 FX_FLOAT FXJSE_Value_ToFloat(FXJSE_HVALUE hValue) { | 50 FX_FLOAT FXJSE_Value_ToFloat(CFXJSE_Value* pValue) { |
59 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToFloat(); | 51 return pValue->ToFloat(); |
60 } | 52 } |
61 | 53 |
62 double FXJSE_Value_ToDouble(FXJSE_HVALUE hValue) { | 54 double FXJSE_Value_ToDouble(CFXJSE_Value* pValue) { |
63 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToDouble(); | 55 return pValue->ToDouble(); |
64 } | 56 } |
65 | 57 |
66 void FXJSE_Value_ToUTF8String(FXJSE_HVALUE hValue, | 58 void FXJSE_Value_ToUTF8String(CFXJSE_Value* pValue, |
67 CFX_ByteString& szStrOutput) { | 59 CFX_ByteString& szStrOutput) { |
68 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToString(szStrOutput); | 60 pValue->ToString(szStrOutput); |
69 } | 61 } |
70 | 62 |
71 int32_t FXJSE_Value_ToInteger(FXJSE_HVALUE hValue) { | 63 int32_t FXJSE_Value_ToInteger(CFXJSE_Value* pValue) { |
72 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToInteger(); | 64 return pValue->ToInteger(); |
73 } | 65 } |
74 | 66 |
75 void* FXJSE_Value_ToObject(FXJSE_HVALUE hValue, CFXJSE_Class* pClass) { | 67 void* FXJSE_Value_ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { |
76 return reinterpret_cast<CFXJSE_Value*>(hValue)->ToObject(pClass); | 68 return pValue->ToObject(pClass); |
77 } | 69 } |
78 | 70 |
79 void FXJSE_Value_SetUndefined(FXJSE_HVALUE hValue) { | 71 void FXJSE_Value_SetUndefined(CFXJSE_Value* pValue) { |
80 reinterpret_cast<CFXJSE_Value*>(hValue)->SetUndefined(); | 72 pValue->SetUndefined(); |
81 } | 73 } |
82 | 74 |
83 void FXJSE_Value_SetNull(FXJSE_HVALUE hValue) { | 75 void FXJSE_Value_SetNull(CFXJSE_Value* pValue) { |
84 reinterpret_cast<CFXJSE_Value*>(hValue)->SetNull(); | 76 pValue->SetNull(); |
85 } | 77 } |
86 | 78 |
87 void FXJSE_Value_SetBoolean(FXJSE_HVALUE hValue, FX_BOOL bBoolean) { | 79 void FXJSE_Value_SetBoolean(CFXJSE_Value* pValue, FX_BOOL bBoolean) { |
88 reinterpret_cast<CFXJSE_Value*>(hValue)->SetBoolean(bBoolean); | 80 pValue->SetBoolean(bBoolean); |
89 } | 81 } |
90 | 82 |
91 void FXJSE_Value_SetUTF8String(FXJSE_HVALUE hValue, | 83 void FXJSE_Value_SetUTF8String(CFXJSE_Value* pValue, |
92 const CFX_ByteStringC& szString) { | 84 const CFX_ByteStringC& szString) { |
93 reinterpret_cast<CFXJSE_Value*>(hValue)->SetString(szString); | 85 pValue->SetString(szString); |
94 } | 86 } |
95 | 87 |
96 void FXJSE_Value_SetInteger(FXJSE_HVALUE hValue, int32_t nInteger) { | 88 void FXJSE_Value_SetInteger(CFXJSE_Value* pValue, int32_t nInteger) { |
97 reinterpret_cast<CFXJSE_Value*>(hValue)->SetInteger(nInteger); | 89 pValue->SetInteger(nInteger); |
98 } | 90 } |
99 | 91 |
100 void FXJSE_Value_SetFloat(FXJSE_HVALUE hValue, FX_FLOAT fFloat) { | 92 void FXJSE_Value_SetFloat(CFXJSE_Value* pValue, FX_FLOAT fFloat) { |
101 reinterpret_cast<CFXJSE_Value*>(hValue)->SetFloat(fFloat); | 93 pValue->SetFloat(fFloat); |
102 } | 94 } |
103 | 95 |
104 void FXJSE_Value_SetDouble(FXJSE_HVALUE hValue, double dDouble) { | 96 void FXJSE_Value_SetDouble(CFXJSE_Value* pValue, double dDouble) { |
105 reinterpret_cast<CFXJSE_Value*>(hValue)->SetDouble(dDouble); | 97 pValue->SetDouble(dDouble); |
106 } | 98 } |
107 | 99 |
108 void FXJSE_Value_SetObject(FXJSE_HVALUE hValue, | 100 void FXJSE_Value_SetObject(CFXJSE_Value* pValue, |
109 void* lpObject, | 101 void* lpObject, |
110 CFXJSE_Class* pClass) { | 102 CFXJSE_Class* pClass) { |
111 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | |
112 if (!pClass) { | 103 if (!pClass) { |
113 ASSERT(!lpObject); | 104 ASSERT(!lpObject); |
114 lpValue->SetJSObject(); | 105 pValue->SetJSObject(); |
115 } else { | 106 } else { |
116 lpValue->SetHostObject(lpObject, pClass); | 107 pValue->SetHostObject(lpObject, pClass); |
117 } | 108 } |
118 } | 109 } |
119 | 110 |
120 void FXJSE_Value_SetArray(FXJSE_HVALUE hValue, | 111 void FXJSE_Value_SetArray(CFXJSE_Value* pValue, |
121 uint32_t uValueCount, | 112 uint32_t uValueCount, |
122 FXJSE_HVALUE* rgValues) { | 113 CFXJSE_Value** rgValues) { |
123 reinterpret_cast<CFXJSE_Value*>(hValue) | 114 pValue->SetArray(uValueCount, rgValues); |
124 ->SetArray(uValueCount, reinterpret_cast<CFXJSE_Value**>(rgValues)); | |
125 } | 115 } |
126 | 116 |
127 void FXJSE_Value_Set(FXJSE_HVALUE hValue, FXJSE_HVALUE hOriginalValue) { | 117 void FXJSE_Value_Set(CFXJSE_Value* pValue, CFXJSE_Value* pOriginalValue) { |
128 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 118 ASSERT(pOriginalValue); |
129 CFXJSE_Value* lpOriginalValue = | 119 pValue->Assign(pOriginalValue); |
130 reinterpret_cast<CFXJSE_Value*>(hOriginalValue); | |
131 ASSERT(lpValue && lpOriginalValue); | |
132 lpValue->Assign(lpOriginalValue); | |
133 } | 120 } |
134 | 121 |
135 FX_BOOL FXJSE_Value_GetObjectProp(FXJSE_HVALUE hValue, | 122 FX_BOOL FXJSE_Value_GetObjectProp(CFXJSE_Value* pValue, |
136 const CFX_ByteStringC& szPropName, | 123 const CFX_ByteStringC& szPropName, |
137 FXJSE_HVALUE hPropValue) { | 124 CFXJSE_Value* pPropValue) { |
138 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 125 ASSERT(pPropValue); |
139 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); | 126 return pValue->GetObjectProperty(szPropName, pPropValue); |
140 ASSERT(lpValue && lpPropValue); | |
141 return lpValue->GetObjectProperty(szPropName, lpPropValue); | |
142 } | 127 } |
143 | 128 |
144 FX_BOOL FXJSE_Value_SetObjectProp(FXJSE_HVALUE hValue, | 129 FX_BOOL FXJSE_Value_SetObjectProp(CFXJSE_Value* pValue, |
145 const CFX_ByteStringC& szPropName, | 130 const CFX_ByteStringC& szPropName, |
146 FXJSE_HVALUE hPropValue) { | 131 CFXJSE_Value* pPropValue) { |
147 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 132 ASSERT(pPropValue); |
148 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); | 133 return pValue->SetObjectProperty(szPropName, pPropValue); |
149 ASSERT(lpValue && lpPropValue); | |
150 return lpValue->SetObjectProperty(szPropName, lpPropValue); | |
151 } | 134 } |
152 | 135 |
153 FX_BOOL FXJSE_Value_GetObjectPropByIdx(FXJSE_HVALUE hValue, | 136 FX_BOOL FXJSE_Value_GetObjectPropByIdx(CFXJSE_Value* pValue, |
154 uint32_t uPropIdx, | 137 uint32_t uPropIdx, |
155 FXJSE_HVALUE hPropValue) { | 138 CFXJSE_Value* pPropValue) { |
156 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 139 ASSERT(pPropValue); |
157 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); | 140 return pValue->GetObjectProperty(uPropIdx, pPropValue); |
158 ASSERT(lpValue && lpPropValue); | |
159 return lpValue->GetObjectProperty(uPropIdx, lpPropValue); | |
160 } | 141 } |
161 | 142 |
162 FX_BOOL FXJSE_Value_DeleteObjectProp(FXJSE_HVALUE hValue, | 143 FX_BOOL FXJSE_Value_DeleteObjectProp(CFXJSE_Value* pValue, |
163 const CFX_ByteStringC& szPropName) { | 144 const CFX_ByteStringC& szPropName) { |
164 return reinterpret_cast<CFXJSE_Value*>(hValue) | 145 return pValue->DeleteObjectProperty(szPropName); |
165 ->DeleteObjectProperty(szPropName); | |
166 } | 146 } |
167 | 147 |
168 FX_BOOL FXJSE_Value_ObjectHasOwnProp(FXJSE_HVALUE hValue, | 148 FX_BOOL FXJSE_Value_ObjectHasOwnProp(CFXJSE_Value* pValue, |
169 const CFX_ByteStringC& szPropName, | 149 const CFX_ByteStringC& szPropName, |
170 FX_BOOL bUseTypeGetter) { | 150 FX_BOOL bUseTypeGetter) { |
171 return reinterpret_cast<CFXJSE_Value*>(hValue) | 151 return pValue->HasObjectOwnProperty(szPropName, bUseTypeGetter); |
172 ->HasObjectOwnProperty(szPropName, bUseTypeGetter); | |
173 } | 152 } |
174 | 153 |
175 FX_BOOL FXJSE_Value_SetObjectOwnProp(FXJSE_HVALUE hValue, | 154 FX_BOOL FXJSE_Value_SetObjectOwnProp(CFXJSE_Value* pValue, |
176 const CFX_ByteStringC& szPropName, | 155 const CFX_ByteStringC& szPropName, |
177 FXJSE_HVALUE hPropValue) { | 156 CFXJSE_Value* pPropValue) { |
178 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 157 ASSERT(pPropValue); |
179 CFXJSE_Value* lpPropValue = reinterpret_cast<CFXJSE_Value*>(hPropValue); | 158 return pValue->SetObjectOwnProperty(szPropName, pPropValue); |
180 ASSERT(lpValue && lpPropValue); | |
181 return lpValue->SetObjectOwnProperty(szPropName, lpPropValue); | |
182 } | 159 } |
183 | 160 |
184 FX_BOOL FXJSE_Value_SetFunctionBind(FXJSE_HVALUE hValue, | 161 FX_BOOL FXJSE_Value_SetFunctionBind(CFXJSE_Value* pValue, |
185 FXJSE_HVALUE hOldFunction, | 162 CFXJSE_Value* pOldFunction, |
186 FXJSE_HVALUE hNewThis) { | 163 CFXJSE_Value* pNewThis) { |
187 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 164 ASSERT(pOldFunction && pNewThis); |
188 CFXJSE_Value* lpOldFunction = reinterpret_cast<CFXJSE_Value*>(hOldFunction); | 165 return pValue->SetFunctionBind(pOldFunction, pNewThis); |
189 CFXJSE_Value* lpNewThis = reinterpret_cast<CFXJSE_Value*>(hNewThis); | |
190 ASSERT(lpValue && lpOldFunction && lpNewThis); | |
191 return lpValue->SetFunctionBind(lpOldFunction, lpNewThis); | |
192 } | 166 } |
193 | 167 |
194 FXJSE_HVALUE FXJSE_Value_Create(v8::Isolate* pIsolate) { | 168 CFXJSE_Value* FXJSE_Value_Create(v8::Isolate* pIsolate) { |
195 return reinterpret_cast<FXJSE_HVALUE>(CFXJSE_Value::Create(pIsolate)); | 169 return CFXJSE_Value::Create(pIsolate); |
196 } | 170 } |
197 | 171 |
198 void FXJSE_Value_Release(FXJSE_HVALUE hValue) { | 172 void FXJSE_Value_Release(CFXJSE_Value* pValue) { |
199 CFXJSE_Value* lpValue = reinterpret_cast<CFXJSE_Value*>(hValue); | 173 delete pValue; |
200 delete lpValue; | |
201 } | 174 } |
202 | 175 |
203 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, | 176 void FXJSE_ThrowMessage(const CFX_ByteStringC& utf8Name, |
204 const CFX_ByteStringC& utf8Message) { | 177 const CFX_ByteStringC& utf8Message) { |
205 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); | 178 v8::Isolate* pIsolate = v8::Isolate::GetCurrent(); |
206 ASSERT(pIsolate); | 179 ASSERT(pIsolate); |
207 | 180 |
208 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); | 181 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); |
209 v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( | 182 v8::Local<v8::String> hMessage = v8::String::NewFromUtf8( |
210 pIsolate, utf8Message.c_str(), v8::String::kNormalString, | 183 pIsolate, utf8Message.c_str(), v8::String::kNormalString, |
(...skipping 22 matching lines...) Expand all Loading... |
233 } | 206 } |
234 | 207 |
235 CFXJSE_Value* CFXJSE_Value::Create(v8::Isolate* pIsolate) { | 208 CFXJSE_Value* CFXJSE_Value::Create(v8::Isolate* pIsolate) { |
236 return new CFXJSE_Value(pIsolate); | 209 return new CFXJSE_Value(pIsolate); |
237 } | 210 } |
238 | 211 |
239 void* CFXJSE_Value::ToObject(CFXJSE_Class* lpClass) const { | 212 void* CFXJSE_Value::ToObject(CFXJSE_Class* lpClass) const { |
240 ASSERT(!m_hValue.IsEmpty()); | 213 ASSERT(!m_hValue.IsEmpty()); |
241 | 214 |
242 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 215 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
243 v8::Local<v8::Value> hValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 216 v8::Local<v8::Value> pValue = v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
244 ASSERT(!hValue.IsEmpty()); | 217 ASSERT(!pValue.IsEmpty()); |
245 | 218 |
246 if (!hValue->IsObject()) | 219 if (!pValue->IsObject()) |
247 return nullptr; | 220 return nullptr; |
248 | 221 |
249 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), lpClass); | 222 return FXJSE_RetrieveObjectBinding(pValue.As<v8::Object>(), lpClass); |
250 } | 223 } |
251 | 224 |
252 V8_INLINE static double FXJSE_ftod(FX_FLOAT fNumber) { | 225 V8_INLINE static double FXJSE_ftod(FX_FLOAT fNumber) { |
253 if (sizeof(FX_FLOAT) != 4) { | 226 if (sizeof(FX_FLOAT) != 4) { |
254 ASSERT(FALSE); | 227 ASSERT(FALSE); |
255 return fNumber; | 228 return fNumber; |
256 } | 229 } |
257 | 230 |
258 uint32_t nFloatBits = (uint32_t&)fNumber; | 231 uint32_t nFloatBits = (uint32_t&)fNumber; |
259 uint8_t nExponent = (uint8_t)(nFloatBits >> 16 >> 7); | 232 uint8_t nExponent = (uint8_t)(nFloatBits >> 16 >> 7); |
(...skipping 24 matching lines...) Expand all Loading... |
284 } while (iErrPosMin < iErrPosMax); | 257 } while (iErrPosMin < iErrPosMax); |
285 iErrPos = iErrPosMax; | 258 iErrPos = iErrPosMax; |
286 } | 259 } |
287 double dPow = pow(10.0, iErrPos); | 260 double dPow = pow(10.0, iErrPos); |
288 return fNumber < 0 ? ceil(dNumber * dPow - 0.5) / dPow | 261 return fNumber < 0 ? ceil(dNumber * dPow - 0.5) / dPow |
289 : floor(dNumber * dPow + 0.5) / dPow; | 262 : floor(dNumber * dPow + 0.5) / dPow; |
290 } | 263 } |
291 | 264 |
292 void CFXJSE_Value::SetFloat(FX_FLOAT fFloat) { | 265 void CFXJSE_Value::SetFloat(FX_FLOAT fFloat) { |
293 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); | 266 CFXJSE_ScopeUtil_IsolateHandle scope(m_pIsolate); |
294 v8::Local<v8::Value> hValue = v8::Number::New(m_pIsolate, FXJSE_ftod(fFloat)); | 267 v8::Local<v8::Value> pValue = v8::Number::New(m_pIsolate, FXJSE_ftod(fFloat)); |
295 m_hValue.Reset(m_pIsolate, hValue); | 268 m_hValue.Reset(m_pIsolate, pValue); |
296 } | 269 } |
297 | 270 |
298 void CFXJSE_Value::SetHostObject(void* lpObject, CFXJSE_Class* lpClass) { | 271 void CFXJSE_Value::SetHostObject(void* lpObject, CFXJSE_Class* lpClass) { |
299 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 272 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
300 ASSERT(lpClass); | 273 ASSERT(lpClass); |
301 v8::Local<v8::FunctionTemplate> hClass = | 274 v8::Local<v8::FunctionTemplate> hClass = |
302 v8::Local<v8::FunctionTemplate>::New(m_pIsolate, lpClass->m_hTemplate); | 275 v8::Local<v8::FunctionTemplate>::New(m_pIsolate, lpClass->m_hTemplate); |
303 v8::Local<v8::Object> hObject = hClass->InstanceTemplate()->NewInstance(); | 276 v8::Local<v8::Object> hObject = hClass->InstanceTemplate()->NewInstance(); |
304 FXJSE_UpdateObjectBinding(hObject, lpObject); | 277 FXJSE_UpdateObjectBinding(hObject, lpObject); |
305 m_hValue.Reset(m_pIsolate, hObject); | 278 m_hValue.Reset(m_pIsolate, hObject); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 389 } |
417 | 390 |
418 FX_BOOL CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, | 391 FX_BOOL CFXJSE_Value::SetObjectOwnProperty(const CFX_ByteStringC& szPropName, |
419 CFXJSE_Value* lpPropValue) { | 392 CFXJSE_Value* lpPropValue) { |
420 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 393 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
421 v8::Local<v8::Value> hObject = | 394 v8::Local<v8::Value> hObject = |
422 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); | 395 v8::Local<v8::Value>::New(m_pIsolate, m_hValue); |
423 if (!hObject->IsObject()) | 396 if (!hObject->IsObject()) |
424 return FALSE; | 397 return FALSE; |
425 | 398 |
426 v8::Local<v8::Value> hValue = | 399 v8::Local<v8::Value> pValue = |
427 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->m_hValue); | 400 v8::Local<v8::Value>::New(m_pIsolate, lpPropValue->m_hValue); |
428 return hObject.As<v8::Object>() | 401 return hObject.As<v8::Object>() |
429 ->DefineOwnProperty( | 402 ->DefineOwnProperty( |
430 m_pIsolate->GetCurrentContext(), | 403 m_pIsolate->GetCurrentContext(), |
431 v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), | 404 v8::String::NewFromUtf8(m_pIsolate, szPropName.c_str(), |
432 v8::String::kNormalString, | 405 v8::String::kNormalString, |
433 szPropName.GetLength()), | 406 szPropName.GetLength()), |
434 hValue) | 407 pValue) |
435 .FromMaybe(false); | 408 .FromMaybe(false); |
436 } | 409 } |
437 | 410 |
438 FX_BOOL CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, | 411 FX_BOOL CFXJSE_Value::SetFunctionBind(CFXJSE_Value* lpOldFunction, |
439 CFXJSE_Value* lpNewThis) { | 412 CFXJSE_Value* lpNewThis) { |
440 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 413 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
441 v8::Local<v8::Value> rgArgs[2]; | 414 v8::Local<v8::Value> rgArgs[2]; |
442 v8::Local<v8::Value> hOldFunction = | 415 v8::Local<v8::Value> hOldFunction = |
443 v8::Local<v8::Value>::New(m_pIsolate, lpOldFunction->DirectGetValue()); | 416 v8::Local<v8::Value>::New(m_pIsolate, lpOldFunction->DirectGetValue()); |
444 if (hOldFunction.IsEmpty() || !hOldFunction->IsFunction()) | 417 if (hOldFunction.IsEmpty() || !hOldFunction->IsFunction()) |
(...skipping 18 matching lines...) Expand all Loading... |
463 return FALSE; | 436 return FALSE; |
464 | 437 |
465 m_hValue.Reset(m_pIsolate, hBoundFunction); | 438 m_hValue.Reset(m_pIsolate, hBoundFunction); |
466 return TRUE; | 439 return TRUE; |
467 } | 440 } |
468 | 441 |
469 #define FXJSE_INVALID_PTR ((void*)(intptr_t)-1) | 442 #define FXJSE_INVALID_PTR ((void*)(intptr_t)-1) |
470 FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, | 443 FX_BOOL CFXJSE_Value::Call(CFXJSE_Value* lpReceiver, |
471 CFXJSE_Value* lpRetValue, | 444 CFXJSE_Value* lpRetValue, |
472 uint32_t nArgCount, | 445 uint32_t nArgCount, |
473 FXJSE_HVALUE* lpArgs) { | 446 CFXJSE_Value** lpArgs) { |
474 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); | 447 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(m_pIsolate); |
475 v8::Local<v8::Value> hFunctionValue = | 448 v8::Local<v8::Value> hFunctionValue = |
476 v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue()); | 449 v8::Local<v8::Value>::New(m_pIsolate, DirectGetValue()); |
477 v8::Local<v8::Object> hFunctionObject = | 450 v8::Local<v8::Object> hFunctionObject = |
478 !hFunctionValue.IsEmpty() && hFunctionValue->IsObject() | 451 !hFunctionValue.IsEmpty() && hFunctionValue->IsObject() |
479 ? hFunctionValue.As<v8::Object>() | 452 ? hFunctionValue.As<v8::Object>() |
480 : v8::Local<v8::Object>(); | 453 : v8::Local<v8::Object>(); |
481 | 454 |
482 v8::TryCatch trycatch(m_pIsolate); | 455 v8::TryCatch trycatch(m_pIsolate); |
483 if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) { | 456 if (hFunctionObject.IsEmpty() || !hFunctionObject->IsCallable()) { |
484 if (lpRetValue) | 457 if (lpRetValue) |
485 lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch)); | 458 lpRetValue->ForceSetValue(FXJSE_CreateReturnValue(m_pIsolate, trycatch)); |
486 return FALSE; | 459 return FALSE; |
487 } | 460 } |
488 | 461 |
489 v8::Local<v8::Value> hReturnValue; | 462 v8::Local<v8::Value> hReturnValue; |
490 v8::Local<v8::Value>* lpLocalArgs = NULL; | 463 v8::Local<v8::Value>* lpLocalArgs = NULL; |
491 if (nArgCount) { | 464 if (nArgCount) { |
492 lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount); | 465 lpLocalArgs = FX_Alloc(v8::Local<v8::Value>, nArgCount); |
493 for (uint32_t i = 0; i < nArgCount; i++) { | 466 for (uint32_t i = 0; i < nArgCount; i++) { |
494 new (lpLocalArgs + i) v8::Local<v8::Value>; | 467 new (lpLocalArgs + i) v8::Local<v8::Value>; |
495 CFXJSE_Value* lpArg = (CFXJSE_Value*)lpArgs[i]; | 468 CFXJSE_Value* lpArg = lpArgs[i]; |
496 if (lpArg) { | 469 if (lpArg) { |
497 lpLocalArgs[i] = | 470 lpLocalArgs[i] = |
498 v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue()); | 471 v8::Local<v8::Value>::New(m_pIsolate, lpArg->DirectGetValue()); |
499 } | 472 } |
500 if (lpLocalArgs[i].IsEmpty()) { | 473 if (lpLocalArgs[i].IsEmpty()) { |
501 lpLocalArgs[i] = v8::Undefined(m_pIsolate); | 474 lpLocalArgs[i] = v8::Undefined(m_pIsolate); |
502 } | 475 } |
503 } | 476 } |
504 } | 477 } |
505 | 478 |
(...skipping 25 matching lines...) Expand all Loading... |
531 if (lpRetValue) | 504 if (lpRetValue) |
532 lpRetValue->ForceSetValue(hReturnValue); | 505 lpRetValue->ForceSetValue(hReturnValue); |
533 | 506 |
534 if (lpLocalArgs) { | 507 if (lpLocalArgs) { |
535 for (uint32_t i = 0; i < nArgCount; i++) | 508 for (uint32_t i = 0; i < nArgCount; i++) |
536 lpLocalArgs[i].~Local(); | 509 lpLocalArgs[i].~Local(); |
537 FX_Free(lpLocalArgs); | 510 FX_Free(lpLocalArgs); |
538 } | 511 } |
539 return bRetValue; | 512 return bRetValue; |
540 } | 513 } |
OLD | NEW |