| 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/context.h" | 7 #include "xfa/fxjse/context.h" |
| 8 | 8 |
| 9 #include "xfa/fxjse/class.h" | 9 #include "xfa/fxjse/class.h" |
| 10 #include "xfa/fxjse/scope_inline.h" | 10 #include "xfa/fxjse/scope_inline.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 v8::Local<v8::FunctionTemplate>::New( | 77 v8::Local<v8::FunctionTemplate>::New( |
| 78 lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate()); | 78 lpClass->GetContext()->GetRuntime(), lpClass->GetTemplate()); |
| 79 if (!hClass->HasInstance(hObject)) { | 79 if (!hClass->HasInstance(hObject)) { |
| 80 return nullptr; | 80 return nullptr; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 return static_cast<CFXJSE_HostObject*>( | 83 return static_cast<CFXJSE_HostObject*>( |
| 84 hObject->GetAlignedPointerFromInternalField(0)); | 84 hObject->GetAlignedPointerFromInternalField(0)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 CFXJSE_Context* FXJSE_Context_Create( | |
| 88 v8::Isolate* pIsolate, | |
| 89 const FXJSE_CLASS_DESCRIPTOR* lpGlobalClass, | |
| 90 CFXJSE_HostObject* lpGlobalObject) { | |
| 91 return CFXJSE_Context::Create(pIsolate, lpGlobalClass, lpGlobalObject); | |
| 92 } | |
| 93 | |
| 94 void FXJSE_Context_Release(CFXJSE_Context* pContext) { | |
| 95 delete pContext; | |
| 96 } | |
| 97 | |
| 98 CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { | |
| 99 if (!pContext) | |
| 100 return nullptr; | |
| 101 | |
| 102 CFXJSE_Value* lpValue = new CFXJSE_Value(pContext->GetRuntime()); | |
| 103 pContext->GetGlobalObject(lpValue); | |
| 104 return lpValue; | |
| 105 } | |
| 106 | |
| 107 void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext) { | |
| 108 FXJSE_ExecuteScript(pContext, szCompatibleModeScript, nullptr, nullptr); | |
| 109 } | |
| 110 | |
| 111 FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, | |
| 112 const FX_CHAR* szScript, | |
| 113 CFXJSE_Value* pRetValue, | |
| 114 CFXJSE_Value* pNewThisObject) { | |
| 115 return pContext->ExecuteScript(szScript, pRetValue, pNewThisObject); | |
| 116 } | |
| 117 | |
| 118 v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, | 87 v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, |
| 119 v8::TryCatch& trycatch) { | 88 v8::TryCatch& trycatch) { |
| 120 v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate); | 89 v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate); |
| 121 if (trycatch.HasCaught()) { | 90 if (trycatch.HasCaught()) { |
| 122 v8::Local<v8::Value> hException = trycatch.Exception(); | 91 v8::Local<v8::Value> hException = trycatch.Exception(); |
| 123 v8::Local<v8::Message> hMessage = trycatch.Message(); | 92 v8::Local<v8::Message> hMessage = trycatch.Message(); |
| 124 if (hException->IsObject()) { | 93 if (hException->IsObject()) { |
| 125 v8::Local<v8::Value> hValue; | 94 v8::Local<v8::Value> hValue; |
| 126 hValue = hException.As<v8::Object>()->Get( | 95 hValue = hException.As<v8::Object>()->Get( |
| 127 v8::String::NewFromUtf8(pIsolate, "name")); | 96 v8::String::NewFromUtf8(pIsolate, "name")); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); | 147 pIsolate, CFXJSE_RuntimeData::Get(pIsolate)->m_hRootContext); |
| 179 hNewContext->SetSecurityToken(hRootContext->GetSecurityToken()); | 148 hNewContext->SetSecurityToken(hRootContext->GetSecurityToken()); |
| 180 v8::Local<v8::Object> hGlobalObject = | 149 v8::Local<v8::Object> hGlobalObject = |
| 181 FXJSE_GetGlobalObjectFromContext(hNewContext); | 150 FXJSE_GetGlobalObjectFromContext(hNewContext); |
| 182 FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject); | 151 FXJSE_UpdateObjectBinding(hGlobalObject, lpGlobalObject); |
| 183 pContext->m_hContext.Reset(pIsolate, hNewContext); | 152 pContext->m_hContext.Reset(pIsolate, hNewContext); |
| 184 return pContext; | 153 return pContext; |
| 185 } | 154 } |
| 186 | 155 |
| 187 CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} | 156 CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} |
| 157 |
| 188 CFXJSE_Context::~CFXJSE_Context() {} | 158 CFXJSE_Context::~CFXJSE_Context() {} |
| 189 | 159 |
| 190 void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { | 160 void CFXJSE_Context::GetGlobalObject(CFXJSE_Value* pValue) { |
| 191 ASSERT(pValue); | 161 ASSERT(pValue); |
| 192 CFXJSE_ScopeUtil_IsolateHandleContext scope(this); | 162 CFXJSE_ScopeUtil_IsolateHandleContext scope(this); |
| 193 v8::Local<v8::Context> hContext = | 163 v8::Local<v8::Context> hContext = |
| 194 v8::Local<v8::Context>::New(m_pIsolate, m_hContext); | 164 v8::Local<v8::Context>::New(m_pIsolate, m_hContext); |
| 195 v8::Local<v8::Object> hGlobalObject = hContext->Global(); | 165 v8::Local<v8::Object> hGlobalObject = hContext->Global(); |
| 196 pValue->ForceSetValue(hGlobalObject); | 166 pValue->ForceSetValue(hGlobalObject); |
| 197 } | 167 } |
| 198 | 168 |
| 169 void CFXJSE_Context::EnableCompatibleMode() { |
| 170 ExecuteScript(szCompatibleModeScript, nullptr, nullptr); |
| 171 } |
| 172 |
| 199 FX_BOOL CFXJSE_Context::ExecuteScript(const FX_CHAR* szScript, | 173 FX_BOOL CFXJSE_Context::ExecuteScript(const FX_CHAR* szScript, |
| 200 CFXJSE_Value* lpRetValue, | 174 CFXJSE_Value* lpRetValue, |
| 201 CFXJSE_Value* lpNewThisObject) { | 175 CFXJSE_Value* lpNewThisObject) { |
| 202 CFXJSE_ScopeUtil_IsolateHandleContext scope(this); | 176 CFXJSE_ScopeUtil_IsolateHandleContext scope(this); |
| 203 v8::TryCatch trycatch(m_pIsolate); | 177 v8::TryCatch trycatch(m_pIsolate); |
| 204 v8::Local<v8::String> hScriptString = | 178 v8::Local<v8::String> hScriptString = |
| 205 v8::String::NewFromUtf8(m_pIsolate, szScript); | 179 v8::String::NewFromUtf8(m_pIsolate, szScript); |
| 206 if (lpNewThisObject == NULL) { | 180 if (lpNewThisObject == NULL) { |
| 207 v8::Local<v8::Script> hScript = v8::Script::Compile(hScriptString); | 181 v8::Local<v8::Script> hScript = v8::Script::Compile(hScriptString); |
| 208 if (!trycatch.HasCaught()) { | 182 if (!trycatch.HasCaught()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 return TRUE; | 214 return TRUE; |
| 241 } | 215 } |
| 242 } | 216 } |
| 243 if (lpRetValue) { | 217 if (lpRetValue) { |
| 244 lpRetValue->m_hValue.Reset(m_pIsolate, | 218 lpRetValue->m_hValue.Reset(m_pIsolate, |
| 245 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); | 219 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); |
| 246 } | 220 } |
| 247 return FALSE; | 221 return FALSE; |
| 248 } | 222 } |
| 249 } | 223 } |
| OLD | NEW |