summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Eisinger <jochen@chromium.org>2016-07-15 13:30:58 +0200
committerJochen Eisinger <jochen@chromium.org>2016-07-15 13:30:58 +0200
commite5effaf2556046b01265484922e0b8681790323b (patch)
treeeb710ea53a2294165fcb21096305c241f15d0b5f
parent4707a8f8ab98e3091e109cab71dea69a27c217db (diff)
downloadpdfium-e5effaf2556046b01265484922e0b8681790323b.tar.xz
Remove prototypes from v8 functions that aren't constructors
BUG=chromium:625823 TBR=haraken@chromium.org,thestig@chromium.org Review-Url: https://codereview.chromium.org/2123153002 (cherry picked from commit c4dedf32b1f5c71740df5be2a9b1446a01df304c) Review URL: https://codereview.chromium.org/2144333003 .
-rw-r--r--fpdfsdk/jsapi/fxjs_v8.cpp33
-rw-r--r--xfa/fxjse/class.cpp25
2 files changed, 35 insertions, 23 deletions
diff --git a/fpdfsdk/jsapi/fxjs_v8.cpp b/fpdfsdk/jsapi/fxjs_v8.cpp
index a471d5613d..badabd1d5e 100644
--- a/fpdfsdk/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/jsapi/fxjs_v8.cpp
@@ -225,13 +225,14 @@ void FXJS_DefineObjMethod(v8::Isolate* pIsolate,
CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode();
CFXJS_ObjDefinition* pObjDef =
CFXJS_ObjDefinition::ForID(pIsolate, nObjDefnID);
+ v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(
+ pIsolate, pMethodCall, v8::Local<v8::Value>(), pObjDef->GetSignature());
+ fun->RemovePrototype();
pObjDef->GetInstanceTemplate()->Set(
v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(),
v8::NewStringType::kNormal)
.ToLocalChecked(),
- v8::FunctionTemplate::New(pIsolate, pMethodCall, v8::Local<v8::Value>(),
- pObjDef->GetSignature()),
- v8::ReadOnly);
+ fun, v8::ReadOnly);
}
void FXJS_DefineObjProperty(v8::Isolate* pIsolate,
@@ -283,11 +284,14 @@ void FXJS_DefineGlobalMethod(v8::Isolate* pIsolate,
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFX_ByteString bsMethodName = CFX_WideString(sMethodName).UTF8Encode();
- GetGlobalObjectTemplate(pIsolate)
- ->Set(v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(),
- v8::NewStringType::kNormal)
- .ToLocalChecked(),
- v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly);
+ v8::Local<v8::FunctionTemplate> fun =
+ v8::FunctionTemplate::New(pIsolate, pMethodCall);
+ fun->RemovePrototype();
+ GetGlobalObjectTemplate(pIsolate)->Set(
+ v8::String::NewFromUtf8(pIsolate, bsMethodName.c_str(),
+ v8::NewStringType::kNormal)
+ .ToLocalChecked(),
+ fun, v8::ReadOnly);
}
void FXJS_DefineGlobalConst(v8::Isolate* pIsolate,
@@ -296,11 +300,14 @@ void FXJS_DefineGlobalConst(v8::Isolate* pIsolate,
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode();
- GetGlobalObjectTemplate(pIsolate)
- ->SetAccessorProperty(v8::String::NewFromUtf8(pIsolate, bsConst.c_str(),
- v8::NewStringType::kNormal)
- .ToLocalChecked(),
- v8::FunctionTemplate::New(pIsolate, pConstGetter));
+ v8::Local<v8::FunctionTemplate> fun =
+ v8::FunctionTemplate::New(pIsolate, pConstGetter);
+ fun->RemovePrototype();
+ GetGlobalObjectTemplate(pIsolate)->SetAccessorProperty(
+ v8::String::NewFromUtf8(pIsolate, bsConst.c_str(),
+ v8::NewStringType::kNormal)
+ .ToLocalChecked(),
+ fun);
}
void FXJS_InitializeRuntime(
diff --git a/xfa/fxjse/class.cpp b/xfa/fxjse/class.cpp
index d6744a6112..b3862076c8 100644
--- a/xfa/fxjse/class.cpp
+++ b/xfa/fxjse/class.cpp
@@ -127,6 +127,9 @@ static void FXJSE_V8SetterCallback_Wrapper(
static void FXJSE_V8ConstructorCallback_Wrapper(
const v8::FunctionCallbackInfo<v8::Value>& info) {
+ if (!info.IsConstructCall()) {
+ return;
+ }
const FXJSE_CLASS* lpClassDefinition =
static_cast<FXJSE_CLASS*>(info.Data().As<v8::External>()->Value());
if (!lpClassDefinition) {
@@ -267,12 +270,14 @@ CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext,
}
if (lpClassDefinition->methNum) {
for (int32_t i = 0; i < lpClassDefinition->methNum; i++) {
+ v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(
+ pIsolate, FXJSE_V8FunctionCallback_Wrapper,
+ v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>(
+ lpClassDefinition->methods + i)));
+ fun->RemovePrototype();
hObjectTemplate->Set(
v8::String::NewFromUtf8(pIsolate, lpClassDefinition->methods[i].name),
- v8::FunctionTemplate::New(
- pIsolate, FXJSE_V8FunctionCallback_Wrapper,
- v8::External::New(pIsolate, const_cast<FXJSE_FUNCTION*>(
- lpClassDefinition->methods + i))),
+ fun,
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
}
}
@@ -297,12 +302,12 @@ CFXJSE_Class* CFXJSE_Class::Create(CFXJSE_Context* lpContext,
}
}
if (bIsJSGlobal) {
- hObjectTemplate->Set(
- v8::String::NewFromUtf8(pIsolate, "toString"),
- v8::FunctionTemplate::New(
- pIsolate, FXJSE_Context_GlobalObjToString,
- v8::External::New(pIsolate,
- const_cast<FXJSE_CLASS*>(lpClassDefinition))));
+ v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(
+ pIsolate, FXJSE_Context_GlobalObjToString,
+ v8::External::New(pIsolate,
+ const_cast<FXJSE_CLASS*>(lpClassDefinition)));
+ fun->RemovePrototype();
+ hObjectTemplate->Set(v8::String::NewFromUtf8(pIsolate, "toString"), fun);
}
pClass->m_hTemplate.Reset(lpContext->m_pIsolate, hFunctionTemplate);
lpContext->m_rgClasses.Add(pClass);