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/class.h" | 7 #include "xfa/fxjse/class.h" |
8 | 8 |
9 #include "xfa/fxjse/cfxjse_arguments.h" | 9 #include "xfa/fxjse/cfxjse_arguments.h" |
10 #include "xfa/fxjse/context.h" | 10 #include "xfa/fxjse/context.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 const FXJSE_FUNCTION* lpFunctionInfo = | 35 const FXJSE_FUNCTION* lpFunctionInfo = |
36 static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value()); | 36 static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value()); |
37 if (!lpFunctionInfo) { | 37 if (!lpFunctionInfo) { |
38 return; | 38 return; |
39 } | 39 } |
40 CFX_ByteStringC szFunctionName(lpFunctionInfo->name); | 40 CFX_ByteStringC szFunctionName(lpFunctionInfo->name); |
41 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 41 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
42 lpThisValue->ForceSetValue(info.This()); | 42 lpThisValue->ForceSetValue(info.This()); |
43 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); | 43 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); |
44 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; | 44 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; |
45 lpFunctionInfo->callbackProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), | 45 lpFunctionInfo->callbackProc(lpThisValue, szFunctionName, |
46 szFunctionName, | |
47 reinterpret_cast<CFXJSE_Arguments&>(impl)); | 46 reinterpret_cast<CFXJSE_Arguments&>(impl)); |
48 if (!lpRetValue->DirectGetValue().IsEmpty()) { | 47 if (!lpRetValue->DirectGetValue().IsEmpty()) { |
49 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); | 48 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); |
50 } | 49 } |
51 delete lpRetValue; | 50 delete lpRetValue; |
52 lpRetValue = NULL; | 51 lpRetValue = NULL; |
53 delete lpThisValue; | 52 delete lpThisValue; |
54 lpThisValue = NULL; | 53 lpThisValue = NULL; |
55 } | 54 } |
56 | 55 |
57 static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( | 56 static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( |
58 const v8::FunctionCallbackInfo<v8::Value>& info) { | 57 const v8::FunctionCallbackInfo<v8::Value>& info) { |
59 const FXJSE_CLASS* lpClassDefinition = | 58 const FXJSE_CLASS* lpClassDefinition = |
60 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 59 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); |
61 if (!lpClassDefinition) { | 60 if (!lpClassDefinition) { |
62 return; | 61 return; |
63 } | 62 } |
64 CFX_ByteStringC szFunctionName(lpClassDefinition->name); | 63 CFX_ByteStringC szFunctionName(lpClassDefinition->name); |
65 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 64 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
66 lpThisValue->ForceSetValue(info.This()); | 65 lpThisValue->ForceSetValue(info.This()); |
67 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); | 66 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); |
68 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; | 67 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; |
69 lpClassDefinition->constructor(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), | 68 lpClassDefinition->constructor(lpThisValue, szFunctionName, |
70 szFunctionName, | |
71 reinterpret_cast<CFXJSE_Arguments&>(impl)); | 69 reinterpret_cast<CFXJSE_Arguments&>(impl)); |
72 if (!lpRetValue->DirectGetValue().IsEmpty()) { | 70 if (!lpRetValue->DirectGetValue().IsEmpty()) { |
73 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); | 71 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); |
74 } | 72 } |
75 delete lpRetValue; | 73 delete lpRetValue; |
76 lpRetValue = NULL; | 74 lpRetValue = NULL; |
77 delete lpThisValue; | 75 delete lpThisValue; |
78 lpThisValue = NULL; | 76 lpThisValue = NULL; |
79 } | 77 } |
80 | 78 |
81 static void FXJSE_V8GetterCallback_Wrapper( | 79 static void FXJSE_V8GetterCallback_Wrapper( |
82 v8::Local<v8::String> property, | 80 v8::Local<v8::String> property, |
83 const v8::PropertyCallbackInfo<v8::Value>& info) { | 81 const v8::PropertyCallbackInfo<v8::Value>& info) { |
84 const FXJSE_PROPERTY* lpPropertyInfo = | 82 const FXJSE_PROPERTY* lpPropertyInfo = |
85 static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value()); | 83 static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value()); |
86 if (!lpPropertyInfo) { | 84 if (!lpPropertyInfo) { |
87 return; | 85 return; |
88 } | 86 } |
89 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); | 87 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); |
90 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 88 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
91 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); | 89 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); |
92 lpThisValue->ForceSetValue(info.This()); | 90 lpThisValue->ForceSetValue(info.This()); |
93 lpPropertyInfo->getProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), | 91 lpPropertyInfo->getProc(lpThisValue, szPropertyName, lpPropValue); |
94 szPropertyName, | |
95 reinterpret_cast<FXJSE_HVALUE>(lpPropValue)); | |
96 info.GetReturnValue().Set(lpPropValue->DirectGetValue()); | 92 info.GetReturnValue().Set(lpPropValue->DirectGetValue()); |
97 delete lpThisValue; | 93 delete lpThisValue; |
98 lpThisValue = NULL; | 94 lpThisValue = NULL; |
99 delete lpPropValue; | 95 delete lpPropValue; |
100 lpPropValue = NULL; | 96 lpPropValue = NULL; |
101 } | 97 } |
102 | 98 |
103 static void FXJSE_V8SetterCallback_Wrapper( | 99 static void FXJSE_V8SetterCallback_Wrapper( |
104 v8::Local<v8::String> property, | 100 v8::Local<v8::String> property, |
105 v8::Local<v8::Value> value, | 101 v8::Local<v8::Value> value, |
106 const v8::PropertyCallbackInfo<void>& info) { | 102 const v8::PropertyCallbackInfo<void>& info) { |
107 const FXJSE_PROPERTY* lpPropertyInfo = | 103 const FXJSE_PROPERTY* lpPropertyInfo = |
108 static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value()); | 104 static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value()); |
109 if (!lpPropertyInfo) { | 105 if (!lpPropertyInfo) { |
110 return; | 106 return; |
111 } | 107 } |
112 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); | 108 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); |
113 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 109 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
114 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); | 110 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); |
115 lpThisValue->ForceSetValue(info.This()); | 111 lpThisValue->ForceSetValue(info.This()); |
116 lpPropValue->ForceSetValue(value); | 112 lpPropValue->ForceSetValue(value); |
117 lpPropertyInfo->setProc(reinterpret_cast<FXJSE_HOBJECT>(lpThisValue), | 113 lpPropertyInfo->setProc(lpThisValue, szPropertyName, lpPropValue); |
118 szPropertyName, | |
119 reinterpret_cast<FXJSE_HVALUE>(lpPropValue)); | |
120 delete lpThisValue; | 114 delete lpThisValue; |
121 lpThisValue = NULL; | 115 lpThisValue = NULL; |
122 delete lpPropValue; | 116 delete lpPropValue; |
123 lpPropValue = NULL; | 117 lpPropValue = NULL; |
124 } | 118 } |
125 | 119 |
126 static void FXJSE_V8ConstructorCallback_Wrapper( | 120 static void FXJSE_V8ConstructorCallback_Wrapper( |
127 const v8::FunctionCallbackInfo<v8::Value>& info) { | 121 const v8::FunctionCallbackInfo<v8::Value>& info) { |
128 const FXJSE_CLASS* lpClassDefinition = | 122 const FXJSE_CLASS* lpClassDefinition = |
129 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 123 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); |
130 if (!lpClassDefinition) { | 124 if (!lpClassDefinition) { |
131 return; | 125 return; |
132 } | 126 } |
133 ASSERT(info.This()->InternalFieldCount()); | 127 ASSERT(info.This()->InternalFieldCount()); |
134 info.This()->SetAlignedPointerInInternalField(0, NULL); | 128 info.This()->SetAlignedPointerInInternalField(0, NULL); |
135 } | 129 } |
136 | 130 |
137 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { | 131 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { |
138 const CFXJSE_ArgumentsImpl* lpArguments = | 132 const CFXJSE_ArgumentsImpl* lpArguments = |
139 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 133 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
140 return lpArguments->m_pRetValue->GetIsolate(); | 134 return lpArguments->m_pRetValue->GetIsolate(); |
141 } | 135 } |
142 | 136 |
143 int32_t CFXJSE_Arguments::GetLength() const { | 137 int32_t CFXJSE_Arguments::GetLength() const { |
144 const CFXJSE_ArgumentsImpl* lpArguments = | 138 const CFXJSE_ArgumentsImpl* lpArguments = |
145 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 139 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
146 return lpArguments->m_pInfo->Length(); | 140 return lpArguments->m_pInfo->Length(); |
147 } | 141 } |
148 | 142 |
149 FXJSE_HVALUE CFXJSE_Arguments::GetValue(int32_t index) const { | 143 CFXJSE_Value* CFXJSE_Arguments::GetValue(int32_t index) const { |
150 const CFXJSE_ArgumentsImpl* lpArguments = | 144 const CFXJSE_ArgumentsImpl* lpArguments = |
151 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 145 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
152 CFXJSE_Value* lpArgValue = CFXJSE_Value::Create(v8::Isolate::GetCurrent()); | 146 CFXJSE_Value* lpArgValue = CFXJSE_Value::Create(v8::Isolate::GetCurrent()); |
153 ASSERT(lpArgValue); | 147 ASSERT(lpArgValue); |
154 lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]); | 148 lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]); |
155 return reinterpret_cast<FXJSE_HVALUE>(lpArgValue); | 149 return lpArgValue; |
156 } | 150 } |
157 | 151 |
158 FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const { | 152 FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const { |
159 const CFXJSE_ArgumentsImpl* lpArguments = | 153 const CFXJSE_ArgumentsImpl* lpArguments = |
160 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 154 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
161 return (*lpArguments->m_pInfo)[index]->BooleanValue(); | 155 return (*lpArguments->m_pInfo)[index]->BooleanValue(); |
162 } | 156 } |
163 | 157 |
164 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const { | 158 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const { |
165 const CFXJSE_ArgumentsImpl* lpArguments = | 159 const CFXJSE_ArgumentsImpl* lpArguments = |
(...skipping 19 matching lines...) Expand all Loading... |
185 const CFXJSE_ArgumentsImpl* lpArguments = | 179 const CFXJSE_ArgumentsImpl* lpArguments = |
186 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 180 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
187 v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index]; | 181 v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index]; |
188 ASSERT(!hValue.IsEmpty()); | 182 ASSERT(!hValue.IsEmpty()); |
189 if (!hValue->IsObject()) { | 183 if (!hValue->IsObject()) { |
190 return NULL; | 184 return NULL; |
191 } | 185 } |
192 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); | 186 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); |
193 } | 187 } |
194 | 188 |
195 FXJSE_HVALUE CFXJSE_Arguments::GetReturnValue() { | 189 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() { |
196 const CFXJSE_ArgumentsImpl* lpArguments = | 190 const CFXJSE_ArgumentsImpl* lpArguments = |
197 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 191 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
198 return reinterpret_cast<FXJSE_HVALUE>(lpArguments->m_pRetValue); | 192 return lpArguments->m_pRetValue; |
199 } | 193 } |
200 static void FXJSE_Context_GlobalObjToString( | 194 static void FXJSE_Context_GlobalObjToString( |
201 const v8::FunctionCallbackInfo<v8::Value>& info) { | 195 const v8::FunctionCallbackInfo<v8::Value>& info) { |
202 const FXJSE_CLASS* lpClass = | 196 const FXJSE_CLASS* lpClass = |
203 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 197 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); |
204 if (!lpClass) { | 198 if (!lpClass) { |
205 return; | 199 return; |
206 } | 200 } |
207 if (info.This() == info.Holder() && lpClass->name) { | 201 if (info.This() == info.Holder() && lpClass->name) { |
208 CFX_ByteString szStringVal; | 202 CFX_ByteString szStringVal; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 300 } |
307 | 301 |
308 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, | 302 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, |
309 const CFX_ByteStringC& szName) { | 303 const CFX_ByteStringC& szName) { |
310 for (const auto& pClass : pContext->m_rgClasses) { | 304 for (const auto& pClass : pContext->m_rgClasses) { |
311 if (pClass->m_szClassName == szName) | 305 if (pClass->m_szClassName == szName) |
312 return pClass.get(); | 306 return pClass.get(); |
313 } | 307 } |
314 return nullptr; | 308 return nullptr; |
315 } | 309 } |
OLD | NEW |