| 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" |
| 11 #include "xfa/fxjse/scope_inline.h" | 11 #include "xfa/fxjse/scope_inline.h" |
| 12 #include "xfa/fxjse/util_inline.h" | 12 #include "xfa/fxjse/util_inline.h" |
| 13 #include "xfa/fxjse/value.h" | 13 #include "xfa/fxjse/value.h" |
| 14 | 14 |
| 15 static void FXJSE_V8ConstructorCallback_Wrapper( | 15 static void FXJSE_V8ConstructorCallback_Wrapper( |
| 16 const v8::FunctionCallbackInfo<v8::Value>& info); | 16 const v8::FunctionCallbackInfo<v8::Value>& info); |
| 17 static void FXJSE_V8FunctionCallback_Wrapper( | 17 static void FXJSE_V8FunctionCallback_Wrapper( |
| 18 const v8::FunctionCallbackInfo<v8::Value>& info); | 18 const v8::FunctionCallbackInfo<v8::Value>& info); |
| 19 static void FXJSE_V8GetterCallback_Wrapper( | 19 static void FXJSE_V8GetterCallback_Wrapper( |
| 20 v8::Local<v8::String> property, | 20 v8::Local<v8::String> property, |
| 21 const v8::PropertyCallbackInfo<v8::Value>& info); | 21 const v8::PropertyCallbackInfo<v8::Value>& info); |
| 22 static void FXJSE_V8SetterCallback_Wrapper( | 22 static void FXJSE_V8SetterCallback_Wrapper( |
| 23 v8::Local<v8::String> property, | 23 v8::Local<v8::String> property, |
| 24 v8::Local<v8::Value> value, | 24 v8::Local<v8::Value> value, |
| 25 const v8::PropertyCallbackInfo<void>& info); | 25 const v8::PropertyCallbackInfo<void>& info); |
| 26 | 26 |
| 27 CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext, | 27 CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext, |
| 28 const FXJSE_CLASS* lpClass) { | 28 const FXJSE_CLASS_DESCRIPTOR* lpClass) { |
| 29 ASSERT(pContext); | 29 ASSERT(pContext); |
| 30 return CFXJSE_Class::Create(pContext, lpClass, FALSE); | 30 return CFXJSE_Class::Create(pContext, lpClass, FALSE); |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void FXJSE_V8FunctionCallback_Wrapper( | 33 static void FXJSE_V8FunctionCallback_Wrapper( |
| 34 const v8::FunctionCallbackInfo<v8::Value>& info) { | 34 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 35 const FXJSE_FUNCTION* lpFunctionInfo = | 35 const FXJSE_FUNCTION_DESCRIPTOR* lpFunctionInfo = |
| 36 static_cast<FXJSE_FUNCTION*>(info.Data().As<v8::External>()->Value()); | 36 static_cast<FXJSE_FUNCTION_DESCRIPTOR*>( |
| 37 info.Data().As<v8::External>()->Value()); |
| 37 if (!lpFunctionInfo) { | 38 if (!lpFunctionInfo) { |
| 38 return; | 39 return; |
| 39 } | 40 } |
| 40 CFX_ByteStringC szFunctionName(lpFunctionInfo->name); | 41 CFX_ByteStringC szFunctionName(lpFunctionInfo->name); |
| 41 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 42 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 42 lpThisValue->ForceSetValue(info.This()); | 43 lpThisValue->ForceSetValue(info.This()); |
| 43 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); | 44 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 44 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; | 45 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; |
| 45 lpFunctionInfo->callbackProc(lpThisValue, szFunctionName, | 46 lpFunctionInfo->callbackProc(lpThisValue, szFunctionName, |
| 46 reinterpret_cast<CFXJSE_Arguments&>(impl)); | 47 reinterpret_cast<CFXJSE_Arguments&>(impl)); |
| 47 if (!lpRetValue->DirectGetValue().IsEmpty()) { | 48 if (!lpRetValue->DirectGetValue().IsEmpty()) { |
| 48 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); | 49 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); |
| 49 } | 50 } |
| 50 delete lpRetValue; | 51 delete lpRetValue; |
| 51 lpRetValue = NULL; | 52 lpRetValue = NULL; |
| 52 delete lpThisValue; | 53 delete lpThisValue; |
| 53 lpThisValue = NULL; | 54 lpThisValue = NULL; |
| 54 } | 55 } |
| 55 | 56 |
| 56 static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( | 57 static void FXJSE_V8ClassGlobalConstructorCallback_Wrapper( |
| 57 const v8::FunctionCallbackInfo<v8::Value>& info) { | 58 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 58 const FXJSE_CLASS* lpClassDefinition = | 59 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = |
| 59 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 60 static_cast<FXJSE_CLASS_DESCRIPTOR*>( |
| 61 info.Data().As<v8::External>()->Value()); |
| 60 if (!lpClassDefinition) { | 62 if (!lpClassDefinition) { |
| 61 return; | 63 return; |
| 62 } | 64 } |
| 63 CFX_ByteStringC szFunctionName(lpClassDefinition->name); | 65 CFX_ByteStringC szFunctionName(lpClassDefinition->name); |
| 64 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 66 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 65 lpThisValue->ForceSetValue(info.This()); | 67 lpThisValue->ForceSetValue(info.This()); |
| 66 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); | 68 CFXJSE_Value* lpRetValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 67 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; | 69 CFXJSE_ArgumentsImpl impl = {&info, lpRetValue}; |
| 68 lpClassDefinition->constructor(lpThisValue, szFunctionName, | 70 lpClassDefinition->constructor(lpThisValue, szFunctionName, |
| 69 reinterpret_cast<CFXJSE_Arguments&>(impl)); | 71 reinterpret_cast<CFXJSE_Arguments&>(impl)); |
| 70 if (!lpRetValue->DirectGetValue().IsEmpty()) { | 72 if (!lpRetValue->DirectGetValue().IsEmpty()) { |
| 71 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); | 73 info.GetReturnValue().Set(lpRetValue->DirectGetValue()); |
| 72 } | 74 } |
| 73 delete lpRetValue; | 75 delete lpRetValue; |
| 74 lpRetValue = NULL; | 76 lpRetValue = NULL; |
| 75 delete lpThisValue; | 77 delete lpThisValue; |
| 76 lpThisValue = NULL; | 78 lpThisValue = NULL; |
| 77 } | 79 } |
| 78 | 80 |
| 79 static void FXJSE_V8GetterCallback_Wrapper( | 81 static void FXJSE_V8GetterCallback_Wrapper( |
| 80 v8::Local<v8::String> property, | 82 v8::Local<v8::String> property, |
| 81 const v8::PropertyCallbackInfo<v8::Value>& info) { | 83 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 82 const FXJSE_PROPERTY* lpPropertyInfo = | 84 const FXJSE_PROPERTY_DESCRIPTOR* lpPropertyInfo = |
| 83 static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value()); | 85 static_cast<FXJSE_PROPERTY_DESCRIPTOR*>( |
| 86 info.Data().As<v8::External>()->Value()); |
| 84 if (!lpPropertyInfo) { | 87 if (!lpPropertyInfo) { |
| 85 return; | 88 return; |
| 86 } | 89 } |
| 87 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); | 90 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); |
| 88 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 91 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 89 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); | 92 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 90 lpThisValue->ForceSetValue(info.This()); | 93 lpThisValue->ForceSetValue(info.This()); |
| 91 lpPropertyInfo->getProc(lpThisValue, szPropertyName, lpPropValue); | 94 lpPropertyInfo->getProc(lpThisValue, szPropertyName, lpPropValue); |
| 92 info.GetReturnValue().Set(lpPropValue->DirectGetValue()); | 95 info.GetReturnValue().Set(lpPropValue->DirectGetValue()); |
| 93 delete lpThisValue; | 96 delete lpThisValue; |
| 94 lpThisValue = NULL; | 97 lpThisValue = NULL; |
| 95 delete lpPropValue; | 98 delete lpPropValue; |
| 96 lpPropValue = NULL; | 99 lpPropValue = NULL; |
| 97 } | 100 } |
| 98 | 101 |
| 99 static void FXJSE_V8SetterCallback_Wrapper( | 102 static void FXJSE_V8SetterCallback_Wrapper( |
| 100 v8::Local<v8::String> property, | 103 v8::Local<v8::String> property, |
| 101 v8::Local<v8::Value> value, | 104 v8::Local<v8::Value> value, |
| 102 const v8::PropertyCallbackInfo<void>& info) { | 105 const v8::PropertyCallbackInfo<void>& info) { |
| 103 const FXJSE_PROPERTY* lpPropertyInfo = | 106 const FXJSE_PROPERTY_DESCRIPTOR* lpPropertyInfo = |
| 104 static_cast<FXJSE_PROPERTY*>(info.Data().As<v8::External>()->Value()); | 107 static_cast<FXJSE_PROPERTY_DESCRIPTOR*>( |
| 108 info.Data().As<v8::External>()->Value()); |
| 105 if (!lpPropertyInfo) { | 109 if (!lpPropertyInfo) { |
| 106 return; | 110 return; |
| 107 } | 111 } |
| 108 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); | 112 CFX_ByteStringC szPropertyName(lpPropertyInfo->name); |
| 109 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); | 113 CFXJSE_Value* lpThisValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 110 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); | 114 CFXJSE_Value* lpPropValue = CFXJSE_Value::Create(info.GetIsolate()); |
| 111 lpThisValue->ForceSetValue(info.This()); | 115 lpThisValue->ForceSetValue(info.This()); |
| 112 lpPropValue->ForceSetValue(value); | 116 lpPropValue->ForceSetValue(value); |
| 113 lpPropertyInfo->setProc(lpThisValue, szPropertyName, lpPropValue); | 117 lpPropertyInfo->setProc(lpThisValue, szPropertyName, lpPropValue); |
| 114 delete lpThisValue; | 118 delete lpThisValue; |
| 115 lpThisValue = NULL; | 119 lpThisValue = NULL; |
| 116 delete lpPropValue; | 120 delete lpPropValue; |
| 117 lpPropValue = NULL; | 121 lpPropValue = NULL; |
| 118 } | 122 } |
| 119 | 123 |
| 120 static void FXJSE_V8ConstructorCallback_Wrapper( | 124 static void FXJSE_V8ConstructorCallback_Wrapper( |
| 121 const v8::FunctionCallbackInfo<v8::Value>& info) { | 125 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 122 const FXJSE_CLASS* lpClassDefinition = | 126 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = |
| 123 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 127 static_cast<FXJSE_CLASS_DESCRIPTOR*>( |
| 128 info.Data().As<v8::External>()->Value()); |
| 124 if (!lpClassDefinition) { | 129 if (!lpClassDefinition) { |
| 125 return; | 130 return; |
| 126 } | 131 } |
| 127 ASSERT(info.This()->InternalFieldCount()); | 132 ASSERT(info.This()->InternalFieldCount()); |
| 128 info.This()->SetAlignedPointerInInternalField(0, NULL); | 133 info.This()->SetAlignedPointerInInternalField(0, NULL); |
| 129 } | 134 } |
| 130 | 135 |
| 131 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { | 136 v8::Isolate* CFXJSE_Arguments::GetRuntime() const { |
| 132 const CFXJSE_ArgumentsImpl* lpArguments = | 137 const CFXJSE_ArgumentsImpl* lpArguments = |
| 133 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 138 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); | 191 return FXJSE_RetrieveObjectBinding(hValue.As<v8::Object>(), pClass); |
| 187 } | 192 } |
| 188 | 193 |
| 189 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() { | 194 CFXJSE_Value* CFXJSE_Arguments::GetReturnValue() { |
| 190 const CFXJSE_ArgumentsImpl* lpArguments = | 195 const CFXJSE_ArgumentsImpl* lpArguments = |
| 191 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); | 196 reinterpret_cast<const CFXJSE_ArgumentsImpl* const>(this); |
| 192 return lpArguments->m_pRetValue; | 197 return lpArguments->m_pRetValue; |
| 193 } | 198 } |
| 194 static void FXJSE_Context_GlobalObjToString( | 199 static void FXJSE_Context_GlobalObjToString( |
| 195 const v8::FunctionCallbackInfo<v8::Value>& info) { | 200 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 196 const FXJSE_CLASS* lpClass = | 201 const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( |
| 197 static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value()); | 202 info.Data().As<v8::External>()->Value()); |
| 198 if (!lpClass) { | 203 if (!lpClass) { |
| 199 return; | 204 return; |
| 200 } | 205 } |
| 201 if (info.This() == info.Holder() && lpClass->name) { | 206 if (info.This() == info.Holder() && lpClass->name) { |
| 202 CFX_ByteString szStringVal; | 207 CFX_ByteString szStringVal; |
| 203 szStringVal.Format("[object %s]", lpClass->name); | 208 szStringVal.Format("[object %s]", lpClass->name); |
| 204 info.GetReturnValue().Set(v8::String::NewFromUtf8( | 209 info.GetReturnValue().Set(v8::String::NewFromUtf8( |
| 205 info.GetIsolate(), szStringVal.c_str(), v8::String::kNormalString, | 210 info.GetIsolate(), szStringVal.c_str(), v8::String::kNormalString, |
| 206 szStringVal.GetLength())); | 211 szStringVal.GetLength())); |
| 207 } else { | 212 } else { |
| 208 v8::Local<v8::String> local_str = | 213 v8::Local<v8::String> local_str = |
| 209 info.This() | 214 info.This() |
| 210 ->ObjectProtoToString(info.GetIsolate()->GetCurrentContext()) | 215 ->ObjectProtoToString(info.GetIsolate()->GetCurrentContext()) |
| 211 .FromMaybe(v8::Local<v8::String>()); | 216 .FromMaybe(v8::Local<v8::String>()); |
| 212 info.GetReturnValue().Set(local_str); | 217 info.GetReturnValue().Set(local_str); |
| 213 } | 218 } |
| 214 } | 219 } |
| 215 | 220 |
| 216 CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext, | 221 CFXJSE_Class* CFXJSE_Class::Create( |
| 217 const FXJSE_CLASS* lpClassDefinition, | 222 CFXJSE_Context* lpContext, |
| 218 FX_BOOL bIsJSGlobal) { | 223 const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition, |
| 224 FX_BOOL bIsJSGlobal) { |
| 219 if (!lpContext || !lpClassDefinition) { | 225 if (!lpContext || !lpClassDefinition) { |
| 220 return NULL; | 226 return NULL; |
| 221 } | 227 } |
| 222 CFXJSE_Class* pClass = | 228 CFXJSE_Class* pClass = |
| 223 GetClassFromContext(lpContext, lpClassDefinition->name); | 229 GetClassFromContext(lpContext, lpClassDefinition->name); |
| 224 if (pClass) { | 230 if (pClass) { |
| 225 return pClass; | 231 return pClass; |
| 226 } | 232 } |
| 227 v8::Isolate* pIsolate = lpContext->m_pIsolate; | 233 v8::Isolate* pIsolate = lpContext->m_pIsolate; |
| 228 pClass = new CFXJSE_Class(lpContext); | 234 pClass = new CFXJSE_Class(lpContext); |
| 229 pClass->m_szClassName = lpClassDefinition->name; | 235 pClass->m_szClassName = lpClassDefinition->name; |
| 230 pClass->m_lpClassDefinition = lpClassDefinition; | 236 pClass->m_lpClassDefinition = lpClassDefinition; |
| 231 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); | 237 CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); |
| 232 v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::FunctionTemplate::New( | 238 v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::FunctionTemplate::New( |
| 233 pIsolate, bIsJSGlobal ? 0 : FXJSE_V8ConstructorCallback_Wrapper, | 239 pIsolate, bIsJSGlobal ? 0 : FXJSE_V8ConstructorCallback_Wrapper, |
| 234 v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>(lpClassDefinition))); | 240 v8::External::New( |
| 241 pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition))); |
| 235 hFunctionTemplate->SetClassName( | 242 hFunctionTemplate->SetClassName( |
| 236 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name)); | 243 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name)); |
| 237 hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(1); | 244 hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(1); |
| 238 v8::Local<v8::ObjectTemplate> hObjectTemplate = | 245 v8::Local<v8::ObjectTemplate> hObjectTemplate = |
| 239 hFunctionTemplate->InstanceTemplate(); | 246 hFunctionTemplate->InstanceTemplate(); |
| 240 SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition); | 247 SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition); |
| 241 | 248 |
| 242 if (lpClassDefinition->propNum) { | 249 if (lpClassDefinition->propNum) { |
| 243 for (int32_t i = 0; i < lpClassDefinition->propNum; i++) { | 250 for (int32_t i = 0; i < lpClassDefinition->propNum; i++) { |
| 244 hObjectTemplate->SetNativeDataProperty( | 251 hObjectTemplate->SetNativeDataProperty( |
| 245 v8::String::NewFromUtf8(pIsolate, | 252 v8::String::NewFromUtf8(pIsolate, |
| 246 lpClassDefinition->properties[i].name), | 253 lpClassDefinition->properties[i].name), |
| 247 lpClassDefinition->properties[i].getProc | 254 lpClassDefinition->properties[i].getProc |
| 248 ? FXJSE_V8GetterCallback_Wrapper | 255 ? FXJSE_V8GetterCallback_Wrapper |
| 249 : NULL, | 256 : NULL, |
| 250 lpClassDefinition->properties[i].setProc | 257 lpClassDefinition->properties[i].setProc |
| 251 ? FXJSE_V8SetterCallback_Wrapper | 258 ? FXJSE_V8SetterCallback_Wrapper |
| 252 : NULL, | 259 : NULL, |
| 253 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY*>( | 260 v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY_DESCRIPTOR*>( |
| 254 lpClassDefinition->properties + i)), | 261 lpClassDefinition->properties + i)), |
| 255 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 262 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
| 256 } | 263 } |
| 257 } | 264 } |
| 258 if (lpClassDefinition->methNum) { | 265 if (lpClassDefinition->methNum) { |
| 259 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { | 266 for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { |
| 260 hObjectTemplate->Set( | 267 hObjectTemplate->Set( |
| 261 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), | 268 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name), |
| 262 v8::FunctionTemplate::New( | 269 v8::FunctionTemplate::New( |
| 263 pIsolate, FXJSE_V8FunctionCallback_Wrapper, | 270 pIsolate, FXJSE_V8FunctionCallback_Wrapper, |
| 264 v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>( | 271 v8::External::New(pIsolate, |
| 265 lpClassDefinition->methods + i))), | 272 const_cast<FXJSE_FUNCTION_DESCRIPTOR*>( |
| 273 lpClassDefinition->methods + i))), |
| 266 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 274 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
| 267 } | 275 } |
| 268 } | 276 } |
| 269 if (lpClassDefinition->constructor) { | 277 if (lpClassDefinition->constructor) { |
| 270 if (bIsJSGlobal) { | 278 if (bIsJSGlobal) { |
| 271 hObjectTemplate->Set( | 279 hObjectTemplate->Set( |
| 272 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), | 280 v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), |
| 273 v8::FunctionTemplate::New( | 281 v8::FunctionTemplate::New( |
| 274 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, | 282 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, |
| 275 v8::External::New(pIsolate, | 283 v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>( |
| 276 const_cast<FXJSE_CLASS*>(lpClassDefinition))), | 284 lpClassDefinition))), |
| 277 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); | 285 static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); |
| 278 } else { | 286 } else { |
| 279 v8::Local<v8::Context> hLocalContext = | 287 v8::Local<v8::Context> hLocalContext = |
| 280 v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); | 288 v8::Local<v8::Context>::New(pIsolate, lpContext->m_hContext); |
| 281 FXJSE_GetGlobalObjectFromContext(hLocalContext) | 289 FXJSE_GetGlobalObjectFromContext(hLocalContext) |
| 282 ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), | 290 ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), |
| 283 v8::Function::New( | 291 v8::Function::New( |
| 284 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, | 292 pIsolate, FXJSE_V8ClassGlobalConstructorCallback_Wrapper, |
| 285 v8::External::New(pIsolate, const_cast<FXJSE_CLASS*>( | 293 v8::External::New(pIsolate, |
| 286 lpClassDefinition)))); | 294 const_cast<FXJSE_CLASS_DESCRIPTOR*>( |
| 295 lpClassDefinition)))); |
| 287 } | 296 } |
| 288 } | 297 } |
| 289 if (bIsJSGlobal) { | 298 if (bIsJSGlobal) { |
| 290 hObjectTemplate->Set( | 299 hObjectTemplate->Set( |
| 291 v8::String::NewFromUtf8(pIsolate, "toString"), | 300 v8::String::NewFromUtf8(pIsolate, "toString"), |
| 292 v8::FunctionTemplate::New( | 301 v8::FunctionTemplate::New( |
| 293 pIsolate, FXJSE_Context_GlobalObjToString, | 302 pIsolate, FXJSE_Context_GlobalObjToString, |
| 294 v8::External::New(pIsolate, | 303 v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>( |
| 295 const_cast<FXJSE_CLASS*>(lpClassDefinition)))); | 304 lpClassDefinition)))); |
| 296 } | 305 } |
| 297 pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); | 306 pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate); |
| 298 lpContext->m_rgClasses.push_back(std::unique_ptr<CFXJSE_Class>(pClass)); | 307 lpContext->m_rgClasses.push_back(std::unique_ptr<CFXJSE_Class>(pClass)); |
| 299 return pClass; | 308 return pClass; |
| 300 } | 309 } |
| 301 | 310 |
| 302 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, | 311 CFXJSE_Class* CFXJSE_Class::GetClassFromContext(CFXJSE_Context* pContext, |
| 303 const CFX_ByteStringC& szName) { | 312 const CFX_ByteStringC& szName) { |
| 304 for (const auto& pClass : pContext->m_rgClasses) { | 313 for (const auto& pClass : pContext->m_rgClasses) { |
| 305 if (pClass->m_szClassName == szName) | 314 if (pClass->m_szClassName == szName) |
| 306 return pClass.get(); | 315 return pClass.get(); |
| 307 } | 316 } |
| 308 return nullptr; | 317 return nullptr; |
| 309 } | 318 } |
| OLD | NEW |