| 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" |
| 11 #include "xfa/fxjse/util_inline.h" | 11 #include "xfa/fxjse/util_inline.h" |
| 12 #include "xfa/fxjse/value.h" | 12 #include "xfa/fxjse/value.h" |
| 13 | 13 |
| 14 CFXJSE_Context* FXJSE_Context_Create(v8::Isolate* pIsolate, | 14 CFXJSE_Context* FXJSE_Context_Create(v8::Isolate* pIsolate, |
| 15 const FXJSE_CLASS* lpGlobalClass, | 15 const FXJSE_CLASS* lpGlobalClass, |
| 16 void* lpGlobalObject) { | 16 void* lpGlobalObject) { |
| 17 return CFXJSE_Context::Create(pIsolate, lpGlobalClass, lpGlobalObject); | 17 return CFXJSE_Context::Create(pIsolate, lpGlobalClass, lpGlobalObject); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void FXJSE_Context_Release(CFXJSE_Context* pContext) { | 20 void FXJSE_Context_Release(CFXJSE_Context* pContext) { |
| 21 delete pContext; | 21 delete pContext; |
| 22 } | 22 } |
| 23 | 23 |
| 24 FXJSE_HVALUE FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { | 24 CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { |
| 25 if (!pContext) | 25 if (!pContext) |
| 26 return nullptr; | 26 return nullptr; |
| 27 | 27 |
| 28 CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime()); | 28 CFXJSE_Value* lpValue = CFXJSE_Value::Create(pContext->GetRuntime()); |
| 29 ASSERT(lpValue); | 29 ASSERT(lpValue); |
| 30 pContext->GetGlobalObject(lpValue); | 30 pContext->GetGlobalObject(lpValue); |
| 31 return reinterpret_cast<FXJSE_HVALUE>(lpValue); | 31 return lpValue; |
| 32 } | 32 } |
| 33 | 33 |
| 34 static const FX_CHAR* szCompatibleModeScripts[] = { | 34 static const FX_CHAR* szCompatibleModeScripts[] = { |
| 35 "(function(global, list) {\n" | 35 "(function(global, list) {\n" |
| 36 " 'use strict';\n" | 36 " 'use strict';\n" |
| 37 " var objname;\n" | 37 " var objname;\n" |
| 38 " for (objname in list) {\n" | 38 " for (objname in list) {\n" |
| 39 " var globalobj = global[objname];\n" | 39 " var globalobj = global[objname];\n" |
| 40 " if (globalobj) {\n" | 40 " if (globalobj) {\n" |
| 41 " list[objname].forEach(function(name) {\n" | 41 " list[objname].forEach(function(name) {\n" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 uint32_t dwCompatibleFlags) { | 61 uint32_t dwCompatibleFlags) { |
| 62 for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) { | 62 for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) { |
| 63 if (dwCompatibleFlags & (1 << i)) { | 63 if (dwCompatibleFlags & (1 << i)) { |
| 64 FXJSE_ExecuteScript(pContext, szCompatibleModeScripts[i], NULL, NULL); | 64 FXJSE_ExecuteScript(pContext, szCompatibleModeScripts[i], NULL, NULL); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, | 69 FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, |
| 70 const FX_CHAR* szScript, | 70 const FX_CHAR* szScript, |
| 71 FXJSE_HVALUE hRetValue, | 71 CFXJSE_Value* pRetValue, |
| 72 FXJSE_HVALUE hNewThisObject) { | 72 CFXJSE_Value* pNewThisObject) { |
| 73 return pContext->ExecuteScript( | 73 return pContext->ExecuteScript(szScript, pRetValue, pNewThisObject); |
| 74 szScript, reinterpret_cast<CFXJSE_Value*>(hRetValue), | |
| 75 reinterpret_cast<CFXJSE_Value*>(hNewThisObject)); | |
| 76 } | 74 } |
| 77 | 75 |
| 78 v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, | 76 v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, |
| 79 v8::TryCatch& trycatch) { | 77 v8::TryCatch& trycatch) { |
| 80 v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate); | 78 v8::Local<v8::Object> hReturnValue = v8::Object::New(pIsolate); |
| 81 if (trycatch.HasCaught()) { | 79 if (trycatch.HasCaught()) { |
| 82 v8::Local<v8::Value> hException = trycatch.Exception(); | 80 v8::Local<v8::Value> hException = trycatch.Exception(); |
| 83 v8::Local<v8::Message> hMessage = trycatch.Message(); | 81 v8::Local<v8::Message> hMessage = trycatch.Message(); |
| 84 if (hException->IsObject()) { | 82 if (hException->IsObject()) { |
| 85 v8::Local<v8::Value> hValue; | 83 v8::Local<v8::Value> hValue; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return TRUE; | 197 return TRUE; |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 if (lpRetValue) { | 200 if (lpRetValue) { |
| 203 lpRetValue->m_hValue.Reset(m_pIsolate, | 201 lpRetValue->m_hValue.Reset(m_pIsolate, |
| 204 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); | 202 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); |
| 205 } | 203 } |
| 206 return FALSE; | 204 return FALSE; |
| 207 } | 205 } |
| 208 } | 206 } |
| OLD | NEW |