summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-06-01 16:10:41 -0700
committerCommit bot <commit-bot@chromium.org>2016-06-01 16:10:41 -0700
commitfb2a824f87f7096382681fd258906823ef93ebec (patch)
tree1754bc611306c55ffe02e971db11349de530f491
parent44f8faf9852a37df1edda34f99e1de4c9d222921 (diff)
downloadpdfium-fb2a824f87f7096382681fd258906823ef93ebec.tar.xz
Don't use array for only one compatible mode script
Also, don't invent an enum that has one possible value that is always set. Review-Url: https://codereview.chromium.org/2028343002
-rw-r--r--xfa/fxfa/parser/xfa_script_imp.cpp6
-rw-r--r--xfa/fxjse/context.cpp66
-rw-r--r--xfa/fxjse/include/fxjse.h9
3 files changed, 36 insertions, 45 deletions
diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp
index 8f579b5f26..357566ed9c 100644
--- a/xfa/fxfa/parser/xfa_script_imp.cpp
+++ b/xfa/fxfa/parser/xfa_script_imp.cpp
@@ -424,8 +424,7 @@ void CXFA_ScriptContext::DefineJsContext() {
m_pJsContext = FXJSE_Context_Create(m_pIsolate, &GlobalClassDescriptor,
m_pDocument->GetRoot());
RemoveBuiltInObjs(m_pJsContext);
- FXJSE_Context_EnableCompatibleMode(
- m_pJsContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS);
+ FXJSE_Context_EnableCompatibleMode(m_pJsContext);
}
CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext(
CXFA_Node* pScriptNode,
@@ -437,8 +436,7 @@ CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext(
FXJSE_Context_Create(m_pIsolate, &VariablesClassDescriptor,
new CXFA_ThisProxy(pSubform, pScriptNode));
RemoveBuiltInObjs(pVariablesContext);
- FXJSE_Context_EnableCompatibleMode(
- pVariablesContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS);
+ FXJSE_Context_EnableCompatibleMode(pVariablesContext);
m_mapVariableToContext.SetAt(pScriptNode, pVariablesContext);
return pVariablesContext;
}
diff --git a/xfa/fxjse/context.cpp b/xfa/fxjse/context.cpp
index a277d4d412..75be76d673 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[] =
+ "(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,
diff --git a/xfa/fxjse/include/fxjse.h b/xfa/fxjse/include/fxjse.h
index ab95a6d675..8a34ad0c7b 100644
--- a/xfa/fxjse/include/fxjse.h
+++ b/xfa/fxjse/include/fxjse.h
@@ -36,11 +36,6 @@ enum FXJSE_ClassPropTypes {
FXJSE_ClassPropType_Method
};
-enum FXJSE_CompatibleModeFlags {
- FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS = (1 << 0),
- FXJSE_COMPATIBLEMODEFLAGCOUNT = 1,
-};
-
struct FXJSE_FUNCTION_DESCRIPTOR {
const FX_CHAR* name;
FXJSE_FuncCallback callbackProc;
@@ -78,9 +73,7 @@ CFXJSE_Context* FXJSE_Context_Create(
CFXJSE_HostObject* lpGlobalObject);
void FXJSE_Context_Release(CFXJSE_Context* pContext);
CFXJSE_Value* FXJSE_Context_GetGlobalObject(CFXJSE_Context* pContext);
-
-void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext,
- uint32_t dwCompatibleFlags);
+void FXJSE_Context_EnableCompatibleMode(CFXJSE_Context* pContext);
CFXJSE_Class* FXJSE_DefineClass(CFXJSE_Context* pContext,
const FXJSE_CLASS_DESCRIPTOR* lpClass);