Chromium Code Reviews| 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/value.h" | 11 #include "xfa/fxjse/value.h" |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 const FX_CHAR szCompatibleModeScript[] = | |
|
Tom Sepez
2016/06/01 22:05:49
note: not CHAR* anymore.
| |
| 16 "(function(global, list) {\n" | |
| 17 " 'use strict';\n" | |
| 18 " var objname;\n" | |
| 19 " for (objname in list) {\n" | |
| 20 " var globalobj = global[objname];\n" | |
| 21 " if (globalobj) {\n" | |
| 22 " list[objname].forEach(function(name) {\n" | |
| 23 " if (!globalobj[name]) {\n" | |
| 24 " Object.defineProperty(globalobj, name, {\n" | |
| 25 " writable: true,\n" | |
| 26 " enumerable: false,\n" | |
| 27 " value: (function(obj) {\n" | |
| 28 " if (arguments.length === 0) {\n" | |
| 29 " throw new TypeError('missing argument 0 when calling " | |
| 30 " function ' + objname + '.' + name);\n" | |
| 31 " }\n" | |
| 32 " return globalobj.prototype[name].apply(obj, " | |
| 33 " Array.prototype.slice.call(arguments, 1));\n" | |
| 34 " })\n" | |
| 35 " });\n" | |
| 36 " }\n" | |
| 37 " });\n" | |
| 38 " }\n" | |
| 39 " }\n" | |
| 40 "}(this, {String: ['substr', 'toUpperCase']}));"; | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 13 v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext( | 44 v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext( |
| 14 const v8::Local<v8::Context>& hContext) { | 45 const v8::Local<v8::Context>& hContext) { |
| 15 return hContext->Global()->GetPrototype().As<v8::Object>(); | 46 return hContext->Global()->GetPrototype().As<v8::Object>(); |
| 16 } | 47 } |
| 17 | 48 |
| 18 void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject, | 49 void FXJSE_UpdateObjectBinding(v8::Local<v8::Object>& hObject, |
| 19 CFXJSE_HostObject* lpNewBinding) { | 50 CFXJSE_HostObject* lpNewBinding) { |
| 20 ASSERT(!hObject.IsEmpty()); | 51 ASSERT(!hObject.IsEmpty()); |
| 21 ASSERT(hObject->InternalFieldCount() > 0); | 52 ASSERT(hObject->InternalFieldCount() > 0); |
| 22 hObject->SetAlignedPointerInInternalField(0, | 53 hObject->SetAlignedPointerInInternalField(0, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 97 |
| 67 CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { | 98 CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) { |
| 68 if (!pContext) | 99 if (!pContext) |
| 69 return nullptr; | 100 return nullptr; |
| 70 | 101 |
| 71 CFXJSE_Value* lpValue = new CFXJSE_Value(pContext->GetRuntime()); | 102 CFXJSE_Value* lpValue = new CFXJSE_Value(pContext->GetRuntime()); |
| 72 pContext->GetGlobalObject(lpValue); | 103 pContext->GetGlobalObject(lpValue); |
| 73 return lpValue; | 104 return lpValue; |
| 74 } | 105 } |
| 75 | 106 |
| 76 static const FX_CHAR* szCompatibleModeScripts[] = { | 107 void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext) { |
| 77 "(function(global, list) {\n" | 108 FXJSE_ExecuteScript(pContext, szCompatibleModeScript, nullptr, nullptr); |
| 78 " 'use strict';\n" | |
| 79 " var objname;\n" | |
| 80 " for (objname in list) {\n" | |
| 81 " var globalobj = global[objname];\n" | |
| 82 " if (globalobj) {\n" | |
| 83 " list[objname].forEach(function(name) {\n" | |
| 84 " if (!globalobj[name]) {\n" | |
| 85 " Object.defineProperty(globalobj, name, {\n" | |
| 86 " writable: true,\n" | |
| 87 " enumerable: false,\n" | |
| 88 " value: (function(obj) {\n" | |
| 89 " if (arguments.length === 0) {\n" | |
| 90 " throw new TypeError('missing argument 0 when calling " | |
| 91 " function ' + objname + '.' + name);\n" | |
| 92 " }\n" | |
| 93 " return globalobj.prototype[name].apply(obj, " | |
| 94 " Array.prototype.slice.call(arguments, 1));\n" | |
| 95 " })\n" | |
| 96 " });\n" | |
| 97 " }\n" | |
| 98 " });\n" | |
| 99 " }\n" | |
| 100 " }\n" | |
| 101 "}(this, {String: ['substr', 'toUpperCase']}));"}; | |
| 102 void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext, | |
| 103 uint32_t dwCompatibleFlags) { | |
| 104 for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) { | |
| 105 if (dwCompatibleFlags & (1 << i)) { | |
| 106 FXJSE_ExecuteScript(pContext, szCompatibleModeScripts[i], NULL, NULL); | |
| 107 } | |
| 108 } | |
| 109 } | 109 } |
| 110 | 110 |
| 111 FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, | 111 FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext, |
| 112 const FX_CHAR* szScript, | 112 const FX_CHAR* szScript, |
| 113 CFXJSE_Value* pRetValue, | 113 CFXJSE_Value* pRetValue, |
| 114 CFXJSE_Value* pNewThisObject) { | 114 CFXJSE_Value* pNewThisObject) { |
| 115 return pContext->ExecuteScript(szScript, pRetValue, pNewThisObject); | 115 return pContext->ExecuteScript(szScript, pRetValue, pNewThisObject); |
| 116 } | 116 } |
| 117 | 117 |
| 118 v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, | 118 v8::Local<v8::Object> FXJSE_CreateReturnValue(v8::Isolate* pIsolate, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 return TRUE; | 240 return TRUE; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 if (lpRetValue) { | 243 if (lpRetValue) { |
| 244 lpRetValue->m_hValue.Reset(m_pIsolate, | 244 lpRetValue->m_hValue.Reset(m_pIsolate, |
| 245 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); | 245 FXJSE_CreateReturnValue(m_pIsolate, trycatch)); |
| 246 } | 246 } |
| 247 return FALSE; | 247 return FALSE; |
| 248 } | 248 } |
| 249 } | 249 } |
| OLD | NEW |