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

Unified Diff: xfa/fxjse/context.cpp

Issue 2028343002: Don't use array for only one compatible mode script (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « xfa/fxfa/parser/xfa_script_imp.cpp ('k') | xfa/fxjse/include/fxjse.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fxjse/context.cpp
diff --git a/xfa/fxjse/context.cpp b/xfa/fxjse/context.cpp
index a277d4d412aa61a947361a58a1ac2596e30c3370..75be76d6730724743d0fe8d6757667840ee5e2d2 100644
--- a/xfa/fxjse/context.cpp
+++ b/xfa/fxjse/context.cpp
@@ -10,6 +10,37 @@
#include "xfa/fxjse/scope_inline.h"
#include "xfa/fxjse/value.h"
+namespace {
+
+const FX_CHAR szCompatibleModeScript[] =
Tom Sepez 2016/06/01 22:05:49 note: not CHAR* anymore.
+ "(function(global, list) {\n"
+ " 'use strict';\n"
+ " var objname;\n"
+ " for (objname in list) {\n"
+ " var globalobj = global[objname];\n"
+ " if (globalobj) {\n"
+ " list[objname].forEach(function(name) {\n"
+ " if (!globalobj[name]) {\n"
+ " Object.defineProperty(globalobj, name, {\n"
+ " writable: true,\n"
+ " enumerable: false,\n"
+ " value: (function(obj) {\n"
+ " if (arguments.length === 0) {\n"
+ " throw new TypeError('missing argument 0 when calling "
+ " function ' + objname + '.' + name);\n"
+ " }\n"
+ " return globalobj.prototype[name].apply(obj, "
+ " Array.prototype.slice.call(arguments, 1));\n"
+ " })\n"
+ " });\n"
+ " }\n"
+ " });\n"
+ " }\n"
+ " }\n"
+ "}(this, {String: ['substr', 'toUpperCase']}));";
+
+} // namespace
+
v8::Local<v8::Object> FXJSE_GetGlobalObjectFromContext(
const v8::Local<v8::Context>& hContext) {
return hContext->Global()->GetPrototype().As<v8::Object>();
@@ -73,39 +104,8 @@ CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext) {
return lpValue;
}
-static const FX_CHAR* szCompatibleModeScripts[] = {
- "(function(global, list) {\n"
- " 'use strict';\n"
- " var objname;\n"
- " for (objname in list) {\n"
- " var globalobj = global[objname];\n"
- " if (globalobj) {\n"
- " list[objname].forEach(function(name) {\n"
- " if (!globalobj[name]) {\n"
- " Object.defineProperty(globalobj, name, {\n"
- " writable: true,\n"
- " enumerable: false,\n"
- " value: (function(obj) {\n"
- " if (arguments.length === 0) {\n"
- " throw new TypeError('missing argument 0 when calling "
- " function ' + objname + '.' + name);\n"
- " }\n"
- " return globalobj.prototype[name].apply(obj, "
- " Array.prototype.slice.call(arguments, 1));\n"
- " })\n"
- " });\n"
- " }\n"
- " });\n"
- " }\n"
- " }\n"
- "}(this, {String: ['substr', 'toUpperCase']}));"};
-void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext,
- uint32_t dwCompatibleFlags) {
- for (uint32_t i = 0; i < (uint32_t)FXJSE_COMPATIBLEMODEFLAGCOUNT; i++) {
- if (dwCompatibleFlags & (1 << i)) {
- FXJSE_ExecuteScript(pContext, szCompatibleModeScripts[i], NULL, NULL);
- }
- }
+void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext) {
+ FXJSE_ExecuteScript(pContext, szCompatibleModeScript, nullptr, nullptr);
}
FX_BOOL FXJSE_ExecuteScript(CFXJSE_Context* pContext,
« no previous file with comments | « xfa/fxfa/parser/xfa_script_imp.cpp ('k') | xfa/fxjse/include/fxjse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698