Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: xfa/fxjse/class.cpp

Issue 2036513002: Stop casting struct CFXJSE_ArgumentsImpl to unrelated class CFXJSE_Arguments (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Explicit ctor Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxjse/class.h ('k') | xfa/fxjse/dynprop.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
35 static_cast<FXJSE_FUNCTION_DESCRIPTOR*>( 35 static_cast<FXJSE_FUNCTION_DESCRIPTOR*>(
36 info.Data().As<v8::External>()->Value()); 36 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 std::unique_ptr<CFXJSE_Value> lpThisValue( 41 std::unique_ptr<CFXJSE_Value> lpThisValue(
42 new CFXJSE_Value(info.GetIsolate())); 42 new CFXJSE_Value(info.GetIsolate()));
43 lpThisValue->ForceSetValue(info.This()); 43 lpThisValue->ForceSetValue(info.This());
44 std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate())); 44 std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate()));
45 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; 45 CFXJSE_Arguments impl(&info, lpRetValue.get());
46 lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, 46 lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, impl);
47 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 } 50 }
52 51
53 static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( 52 static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper(
54 const v8::FunctionCallbackInfo<v8::Value>& info) { 53 const v8::FunctionCallbackInfo<v8::Value>& info) {
55 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = 54 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition =
56 static_cast<FXJSE_CLASS_DESCRIPTOR*>( 55 static_cast<FXJSE_CLASS_DESCRIPTOR*>(
57 info.Data().As<v8::External>()->Value()); 56 info.Data().As<v8::External>()->Value());
58 if (!lpClassDefinition) { 57 if (!lpClassDefinition) {
59 return; 58 return;
60 } 59 }
61 CFX_ByteStringC szFunctionName(lpClassDefinition->name); 60 CFX_ByteStringC szFunctionName(lpClassDefinition->name);
62 std::unique_ptr<CFXJSE_Value> lpThisValue( 61 std::unique_ptr<CFXJSE_Value> lpThisValue(
63 new CFXJSE_Value(info.GetIsolate())); 62 new CFXJSE_Value(info.GetIsolate()));
64 lpThisValue->ForceSetValue(info.This()); 63 lpThisValue->ForceSetValue(info.This());
65 std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate())); 64 std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate()));
66 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue.get()}; 65 CFXJSE_Arguments impl(&info, lpRetValue.get());
67 lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, 66 lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, impl);
68 reinterpret_cast<CFXJSE_Arguments&>(impl));
69 if (!lpRetValue->DirectGetValue().IsEmpty()) { 67 if (!lpRetValue->DirectGetValue().IsEmpty()) {
70 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); 68 info.GetReturnValue().Set(lpRetValue->DirectGetValue());
71 } 69 }
72 } 70 }
73 71
74 static void FXJSE_V8GetterCallback_Wrapper( 72 static void FXJSE_V8GetterCallback_Wrapper(
75 v8::Local<v8::String> property, 73 v8::Local<v8::String> property,
76 const v8::PropertyCallbackInfo<v8::Value>& info) { 74 const v8::PropertyCallbackInfo<v8::Value>& info) {
77 const FXJSE_PROPERTY_DESCRIPTOR* lpPropertyInfo = 75 const FXJSE_PROPERTY_DESCRIPTOR* lpPropertyInfo =
78 static_cast<FXJSE_PROPERTY_DESCRIPTOR*>( 76 static_cast<FXJSE_PROPERTY_DESCRIPTOR*>(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 static_cast<FXJSE_CLASS_DESCRIPTOR*>( 114 static_cast<FXJSE_CLASS_DESCRIPTOR*>(
117 info.Data().As<v8::External>()->Value()); 115 info.Data().As<v8::External>()->Value());
118 if (!lpClassDefinition) { 116 if (!lpClassDefinition) {
119 return; 117 return;
120 } 118 }
121 ASSERT(info.This()->InternalFieldCount()); 119 ASSERT(info.This()->InternalFieldCount());
122 info.This()->SetAlignedPointerInInternalField(0, NULL); 120 info.This()->SetAlignedPointerInInternalField(0, NULL);
123 } 121 }
124 122
125 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { 123 v8::Isolate* CFXJSE_Arguments::GetRuntime() const {
126 const CFXJSE_ArgumentsImpl* lpArguments = 124 return m_pRetValue->GetIsolate();
127 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
128 return lpArguments->m_pRetValue->GetIsolate();
129 } 125 }
130 126
131 int32_t CFXJSE_Arguments::GetLength() const { 127 int32_t CFXJSE_Arguments::GetLength() const {
132 const CFXJSE_ArgumentsImpl* lpArguments = 128 return m_pInfo->Length();
133 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
134 return lpArguments->m_pInfo->Length();
135 } 129 }
136 130
137 std::unique_ptr<CFXJSE_Value> CFXJSE_Arguments::GetValue(int32_t index) const { 131 std::unique_ptr<CFXJSE_Value> CFXJSE_Arguments::GetValue(int32_t index) const {
138 const CFXJSE_ArgumentsImpl* lpArguments =
139 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
140 std::unique_ptr<CFXJSE_Value> lpArgValue( 132 std::unique_ptr<CFXJSE_Value> lpArgValue(
141 new CFXJSE_Value(v8::Isolate::GetCurrent())); 133 new CFXJSE_Value(v8::Isolate::GetCurrent()));
142 lpArgValue->ForceSetValue((*lpArguments->m_pInfo)[index]); 134 lpArgValue->ForceSetValue((*m_pInfo)[index]);
143 return lpArgValue; 135 return lpArgValue;
144 } 136 }
145 137
146 FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const { 138 FX_BOOL CFXJSE_Arguments::GetBoolean(int32_t index) const {
147 const CFXJSE_ArgumentsImpl* lpArguments = 139 return (*m_pInfo)[index]->BooleanValue();
148 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
149 return (*lpArguments->m_pInfo)[index]->BooleanValue();
150 } 140 }
151 141
152 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const { 142 int32_t CFXJSE_Arguments::GetInt32(int32_t index) const {
153 const CFXJSE_ArgumentsImpl* lpArguments = 143 return static_cast<int32_t>((*m_pInfo)[index]->NumberValue());
154 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
155 return static_cast<int32_t>((*lpArguments->m_pInfo)[index]->NumberValue());
156 } 144 }
157 145
158 FX_FLOAT CFXJSE_Arguments::GetFloat(int32_t index) const { 146 FX_FLOAT CFXJSE_Arguments::GetFloat(int32_t index) const {
159 const CFXJSE_ArgumentsImpl* lpArguments = 147 return static_cast<FX_FLOAT>((*m_pInfo)[index]->NumberValue());
160 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
161 return static_cast<FX_FLOAT>((*lpArguments->m_pInfo)[index]->NumberValue());
162 } 148 }
163 149
164 CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const { 150 CFX_ByteString CFXJSE_Arguments::GetUTF8String(int32_t index) const {
165 const CFXJSE_ArgumentsImpl* lpArguments = 151 v8::Local<v8::String> hString = (*m_pInfo)[index]->ToString();
166 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
167 v8::Local<v8::String> hString = (*lpArguments->m_pInfo)[index]->ToString();
168 v8::String::Utf8Value szStringVal(hString); 152 v8::String::Utf8Value szStringVal(hString);
169 return CFX_ByteString(*szStringVal); 153 return CFX_ByteString(*szStringVal);
170 } 154 }
171 155
172 void* CFXJSE_Arguments::GetObject(int32_t index, CFXJSE_Class* pClass) const { 156 void* CFXJSE_Arguments::GetObject(int32_t index, CFXJSE_Class* pClass) const {
173 const CFXJSE_ArgumentsImpl* lpArguments = 157 v8::Local<v8::Value> hValue = (*m_pInfo)[index];
174 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
175 v8::Local<v8::Value> hValue = (*lpArguments->m_pInfo)[index];
176 ASSERT(!hValue.IsEmpty()); 158 ASSERT(!hValue.IsEmpty());
177 if (!hValue->IsObject()) { 159 if (!hValue->IsObject())
178 return NULL; 160 return nullptr;
179 }
180 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); 161 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass);
181 } 162 }
182 163
183 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() { 164 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() {
184 const CFXJSE_ArgumentsImpl* lpArguments = 165 return m_pRetValue;
185 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this);
186 return lpArguments->m_pRetValue;
187 } 166 }
167
188 static void FXJSE_Context_GlobalObjToString( 168 static void FXJSE_Context_GlobalObjToString(
189 const v8::FunctionCallbackInfo<v8::Value>& info) { 169 const v8::FunctionCallbackInfo<v8::Value>& info) {
190 const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( 170 const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>(
191 info.Data().As<v8::External>()->Value()); 171 info.Data().As<v8::External>()->Value());
192 if (!lpClass) { 172 if (!lpClass) {
193 return; 173 return;
194 } 174 }
195 if (info.This() == info.Holder() && lpClass->name) { 175 if (info.This() == info.Holder() && lpClass->name) {
196 CFX_ByteString szStringVal; 176 CFX_ByteString szStringVal;
197 szStringVal.Format("[object %s]", lpClass->name); 177 szStringVal.Format("[object %s]", lpClass->name);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 278 }
299 279
300 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, 280 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext,
301 const CFX_ByteStringC& szName) { 281 const CFX_ByteStringC& szName) {
302 for (const auto& pClass : pContext->m_rgClasses) { 282 for (const auto& pClass : pContext->m_rgClasses) {
303 if (pClass->m_szClassName == szName) 283 if (pClass->m_szClassName == szName)
304 return pClass.get(); 284 return pClass.get();
305 } 285 }
306 return nullptr; 286 return nullptr;
307 } 287 }
OLDNEW
« no previous file with comments | « xfa/fxjse/class.h ('k') | xfa/fxjse/dynprop.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698