diff options
author | dan sinclair <dsinclair@chromium.org> | 2017-12-04 15:14:05 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-04 15:14:05 +0000 |
commit | 85caeb903c239d0c80aec86241885eabc1de71fb (patch) | |
tree | 43f1175aab8c758a722641005725ba41deba05c0 /fxjs | |
parent | 703b6f08a23a1e1d87c41266f92827ae28bf994d (diff) | |
download | pdfium-85caeb903c239d0c80aec86241885eabc1de71fb.tar.xz |
Remove unused XFA code
Change-Id: Iea75ce6b3a7e06b7977491a89e7a31755f038312
Reviewed-on: https://pdfium-review.googlesource.com/20191
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cfxjse_class.cpp | 131 | ||||
-rw-r--r-- | fxjs/cfxjse_context.cpp | 5 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 12 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context.cpp | 4 | ||||
-rw-r--r-- | fxjs/cfxjse_runtimedata.cpp | 29 | ||||
-rw-r--r-- | fxjs/fxjse.h | 15 |
6 files changed, 10 insertions, 186 deletions
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index b2e747b4fd..09976d1aa5 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -34,57 +34,6 @@ void V8FunctionCallback_Wrapper( info.GetReturnValue().Set(lpRetValue->DirectGetValue()); } -void V8ClassGlobalConstructorCallback_Wrapper( - const v8::FunctionCallbackInfo<v8::Value>& info) { - const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = - static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); - if (!lpClassDefinition) - return; - - ByteStringView szFunctionName(lpClassDefinition->name); - auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - lpThisValue->ForceSetValue(info.Holder()); - auto lpRetValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - CFXJSE_Arguments impl(&info, lpRetValue.get()); - lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, impl); - if (!lpRetValue->DirectGetValue().IsEmpty()) - info.GetReturnValue().Set(lpRetValue->DirectGetValue()); -} - -void V8GetterCallback_Wrapper(v8::Local<v8::String> property, - const v8::PropertyCallbackInfo<v8::Value>& info) { - const FXJSE_PROPERTY_DESCRIPTOR* lpPropertyInfo = - static_cast<FXJSE_PROPERTY_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); - if (!lpPropertyInfo) - return; - - ByteStringView szPropertyName(lpPropertyInfo->name); - auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - auto lpPropValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - lpThisValue->ForceSetValue(info.Holder()); - lpPropertyInfo->getProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); - info.GetReturnValue().Set(lpPropValue->DirectGetValue()); -} - -void V8SetterCallback_Wrapper(v8::Local<v8::String> property, - v8::Local<v8::Value> value, - const v8::PropertyCallbackInfo<void>& info) { - const FXJSE_PROPERTY_DESCRIPTOR* lpPropertyInfo = - static_cast<FXJSE_PROPERTY_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); - if (!lpPropertyInfo) - return; - - ByteStringView szPropertyName(lpPropertyInfo->name); - auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - auto lpPropValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - lpThisValue->ForceSetValue(info.Holder()); - lpPropValue->ForceSetValue(value); - lpPropertyInfo->setProc(lpThisValue.get(), szPropertyName, lpPropValue.get()); -} - void V8ConstructorCallback_Wrapper( const v8::FunctionCallbackInfo<v8::Value>& info) { if (!info.IsConstructCall()) @@ -202,22 +151,6 @@ bool DynPropQueryAdapter(const FXJSE_CLASS_DESCRIPTOR* lpClass, return nPropType != FXJSE_ClassPropType_None; } -bool DynPropDeleterAdapter(const FXJSE_CLASS_DESCRIPTOR* lpClass, - CFXJSE_Value* pObject, - const ByteStringView& szPropName) { - ASSERT(lpClass); - int32_t nPropType = - lpClass->dynPropTypeGetter == nullptr - ? FXJSE_ClassPropType_Property - : lpClass->dynPropTypeGetter(pObject, szPropName, false); - if (nPropType != FXJSE_ClassPropType_Method) { - if (lpClass->dynPropDeleter) - return lpClass->dynPropDeleter(pObject, szPropName); - return nPropType != FXJSE_ClassPropType_Property; - } - return false; -} - void NamedPropertyQueryCallback( v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { @@ -238,22 +171,6 @@ void NamedPropertyQueryCallback( info.GetReturnValue().Set(iV8Absent); } -void NamedPropertyDeleterCallback( - v8::Local<v8::Name> property, - const v8::PropertyCallbackInfo<v8::Boolean>& info) { - v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); - v8::Isolate* pIsolate = info.GetIsolate(); - v8::HandleScope scope(pIsolate); - v8::String::Utf8Value szPropName(property); - ByteStringView szFxPropName(*szPropName, szPropName.length()); - auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); - lpThisValue->ForceSetValue(thisObject); - info.GetReturnValue().Set( - !!DynPropDeleterAdapter(lpClass, lpThisValue.get(), szFxPropName)); -} - void NamedPropertyGetterCallback( v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { @@ -291,15 +208,7 @@ void NamedPropertySetterCallback( void NamedPropertyEnumeratorCallback( const v8::PropertyCallbackInfo<v8::Array>& info) { - const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); - v8::Isolate* pIsolate = info.GetIsolate(); - v8::Local<v8::Array> newArray = v8::Array::New(pIsolate, lpClass->propNum); - for (int i = 0; i < lpClass->propNum; i++) { - newArray->Set( - i, v8::String::NewFromUtf8(pIsolate, lpClass->properties[i].name)); - } - info.GetReturnValue().Set(newArray); + info.GetReturnValue().Set(v8::Array::New(info.GetIsolate())); } } // namespace @@ -333,20 +242,6 @@ CFXJSE_Class* CFXJSE_Class::Create( hFunctionTemplate->InstanceTemplate(); SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition); - if (lpClassDefinition->propNum) { - for (int32_t i = 0; i < lpClassDefinition->propNum; i++) { - hObjectTemplate->SetNativeDataProperty( - v8::String::NewFromUtf8(pIsolate, - lpClassDefinition->properties[i].name), - lpClassDefinition->properties[i].getProc ? V8GetterCallback_Wrapper - : nullptr, - lpClassDefinition->properties[i].setProc ? V8SetterCallback_Wrapper - : nullptr, - v8::External::New(pIsolate, const_cast<FXJSE_PROPERTY_DESCRIPTOR*>( - lpClassDefinition->properties + i)), - static_cast<v8::PropertyAttribute>(v8::DontDelete)); - } - } if (lpClassDefinition->methNum) { for (int32_t i = 0; i < lpClassDefinition->methNum; i++) { v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( @@ -360,26 +255,7 @@ CFXJSE_Class* CFXJSE_Class::Create( static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); } } - if (lpClassDefinition->constructor) { - if (bIsJSGlobal) { - hObjectTemplate->Set( - v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), - v8::FunctionTemplate::New( - pIsolate, V8ClassGlobalConstructorCallback_Wrapper, - v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>( - lpClassDefinition))), - static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete)); - } else { - v8::Local<v8::Context> hLocalContext = lpContext->GetContext(); - FXJSE_GetGlobalObjectFromContext(hLocalContext) - ->Set(v8::String::NewFromUtf8(pIsolate, lpClassDefinition->name), - v8::Function::New( - pIsolate, V8ClassGlobalConstructorCallback_Wrapper, - v8::External::New(pIsolate, - const_cast<FXJSE_CLASS_DESCRIPTOR*>( - lpClassDefinition)))); - } - } + if (bIsJSGlobal) { v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New( pIsolate, Context_GlobalObjToString, @@ -402,8 +278,7 @@ void CFXJSE_Class::SetUpNamedPropHandler( v8::NamedPropertyHandlerConfiguration configuration( lpClassDefinition->dynPropGetter ? NamedPropertyGetterCallback : 0, lpClassDefinition->dynPropSetter ? NamedPropertySetterCallback : 0, - lpClassDefinition->dynPropTypeGetter ? NamedPropertyQueryCallback : 0, - lpClassDefinition->dynPropDeleter ? NamedPropertyDeleterCallback : 0, + lpClassDefinition->dynPropTypeGetter ? NamedPropertyQueryCallback : 0, 0, NamedPropertyEnumeratorCallback, v8::External::New(pIsolate, const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition)), diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp index 0af2d361dd..ad37ca2c0a 100644 --- a/fxjs/cfxjse_context.cpp +++ b/fxjs/cfxjse_context.cpp @@ -159,10 +159,10 @@ std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create( CFXJSE_HostObject* pGlobalObject) { CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); auto pContext = pdfium::MakeUnique<CFXJSE_Context>(pIsolate); - CFXJSE_Class* pGlobalClassObj = nullptr; v8::Local<v8::ObjectTemplate> hObjectTemplate; if (pGlobalClass) { - pGlobalClassObj = CFXJSE_Class::Create(pContext.get(), pGlobalClass, true); + CFXJSE_Class* pGlobalClassObj = + CFXJSE_Class::Create(pContext.get(), pGlobalClass, true); ASSERT(pGlobalClassObj); v8::Local<v8::FunctionTemplate> hFunctionTemplate = v8::Local<v8::FunctionTemplate>::New(pIsolate, @@ -172,6 +172,7 @@ std::unique_ptr<CFXJSE_Context> CFXJSE_Context::Create( hObjectTemplate = v8::ObjectTemplate::New(pIsolate); hObjectTemplate->SetInternalFieldCount(2); } + hObjectTemplate->Set( v8::Symbol::GetToStringTag(pIsolate), v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal) diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index cd0a3f3c93..3ba6a3699f 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -34,43 +34,31 @@ namespace { const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { "Root", // name - nullptr, // constructor - nullptr, // properties nullptr, // methods - 0, // property count 0, // method count CFXJSE_Engine::GlobalPropTypeGetter, CFXJSE_Engine::GlobalPropertyGetter, CFXJSE_Engine::GlobalPropertySetter, - nullptr, // property deleter CFXJSE_Engine::NormalMethodCall, }; const FXJSE_CLASS_DESCRIPTOR NormalClassDescriptor = { "XFAObject", // name - nullptr, // constructor - nullptr, // properties nullptr, // methods - 0, // property count 0, // method count CFXJSE_Engine::NormalPropTypeGetter, CFXJSE_Engine::NormalPropertyGetter, CFXJSE_Engine::NormalPropertySetter, - nullptr, // property deleter CFXJSE_Engine::NormalMethodCall, }; const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor = { "XFAScriptObject", // name - nullptr, // constructor - nullptr, // properties nullptr, // methods - 0, // property count 0, // method count CFXJSE_Engine::NormalPropTypeGetter, CFXJSE_Engine::GlobalPropertyGetter, CFXJSE_Engine::GlobalPropertySetter, - nullptr, // property deleter CFXJSE_Engine::NormalMethodCall, }; diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index ca75008b84..b396db39b1 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -311,15 +311,11 @@ const FXJSE_FUNCTION_DESCRIPTOR formcalc_fm2js_functions[] = { const FXJSE_CLASS_DESCRIPTOR formcalc_fm2js_descriptor = { "XFA_FM2JS_FormCalcClass", // name - nullptr, // constructor - nullptr, // properties formcalc_fm2js_functions, // methods - 0, // number of properties FX_ArraySize(formcalc_fm2js_functions), // number of methods nullptr, // dynamic prop type nullptr, // dynamic prop getter nullptr, // dynamic prop setter - nullptr, // dynamic prop deleter nullptr, // dynamic prop method call }; diff --git a/fxjs/cfxjse_runtimedata.cpp b/fxjs/cfxjse_runtimedata.cpp index b8df9ce0b3..be6938e762 100644 --- a/fxjs/cfxjse_runtimedata.cpp +++ b/fxjs/cfxjse_runtimedata.cpp @@ -13,14 +13,6 @@ namespace { -// Duplicates fpdfsdk's cjs_runtime.h, but keeps XFA from depending on it. -// TODO(tsepez): make a single version of this. -class FXJSE_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - void* Allocate(size_t length) override { return calloc(1, length); } - void* AllocateUninitialized(size_t length) override { return malloc(length); } - void Free(void* data, size_t length) override { free(data); } -}; - void Runtime_DisposeCallback(v8::Isolate* pIsolate, bool bOwned) { if (FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate)) delete pData; @@ -55,23 +47,6 @@ void FXJSE_Finalize() { CFXJSE_IsolateTracker::g_pInstance = nullptr; } -v8::Isolate* FXJSE_Runtime_Create_Own() { - std::unique_ptr<v8::ArrayBuffer::Allocator> allocator( - new FXJSE_ArrayBufferAllocator()); - v8::Isolate::CreateParams params; - params.array_buffer_allocator = allocator.get(); - v8::Isolate* pIsolate = v8::Isolate::New(params); - ASSERT(pIsolate && CFXJSE_IsolateTracker::g_pInstance); - CFXJSE_IsolateTracker::g_pInstance->Append(pIsolate, std::move(allocator)); - return pIsolate; -} - -void FXJSE_Runtime_Release(v8::Isolate* pIsolate) { - if (!pIsolate) - return; - CFXJSE_IsolateTracker::g_pInstance->Remove(pIsolate, Runtime_DisposeCallback); -} - CFXJSE_RuntimeData::CFXJSE_RuntimeData(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} @@ -82,6 +57,7 @@ std::unique_ptr<CFXJSE_RuntimeData> CFXJSE_RuntimeData::Create( std::unique_ptr<CFXJSE_RuntimeData> pRuntimeData( new CFXJSE_RuntimeData(pIsolate)); CFXJSE_ScopeUtil_IsolateHandle scope(pIsolate); + v8::Local<v8::FunctionTemplate> hFuncTemplate = v8::FunctionTemplate::New(pIsolate); v8::Local<v8::ObjectTemplate> hGlobalTemplate = @@ -90,9 +66,11 @@ std::unique_ptr<CFXJSE_RuntimeData> CFXJSE_RuntimeData::Create( v8::Symbol::GetToStringTag(pIsolate), v8::String::NewFromUtf8(pIsolate, "global", v8::NewStringType::kNormal) .ToLocalChecked()); + v8::Local<v8::Context> hContext = v8::Context::New(pIsolate, 0, hGlobalTemplate); hContext->SetSecurityToken(v8::External::New(pIsolate, pIsolate)); + pRuntimeData->m_hRootContextGlobalTemplate.Reset(pIsolate, hFuncTemplate); pRuntimeData->m_hRootContext.Reset(pIsolate, hContext); return pRuntimeData; @@ -100,6 +78,7 @@ std::unique_ptr<CFXJSE_RuntimeData> CFXJSE_RuntimeData::Create( CFXJSE_RuntimeData* CFXJSE_RuntimeData::Get(v8::Isolate* pIsolate) { FXJS_PerIsolateData::SetUp(pIsolate); + FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); if (!pData->m_pFXJSERuntimeData) pData->m_pFXJSERuntimeData = CFXJSE_RuntimeData::Create(pIsolate); diff --git a/fxjs/fxjse.h b/fxjs/fxjse.h index 48648130ab..9a38d20ddf 100644 --- a/fxjs/fxjse.h +++ b/fxjs/fxjse.h @@ -39,8 +39,6 @@ typedef void (*FXJSE_PropAccessor)(CFXJSE_Value* pObject, typedef int32_t (*FXJSE_PropTypeGetter)(CFXJSE_Value* pObject, const ByteStringView& szPropName, bool bQueryIn); -typedef bool (*FXJSE_PropDeleter)(CFXJSE_Value* pObject, - const ByteStringView& szPropName); enum FXJSE_ClassPropTypes { FXJSE_ClassPropType_None, @@ -53,32 +51,19 @@ struct FXJSE_FUNCTION_DESCRIPTOR { FXJSE_FuncCallback callbackProc; }; -struct FXJSE_PROPERTY_DESCRIPTOR { - const char* name; - FXJSE_PropAccessor getProc; - FXJSE_PropAccessor setProc; -}; - struct FXJSE_CLASS_DESCRIPTOR { const char* name; - FXJSE_FuncCallback constructor; - const FXJSE_PROPERTY_DESCRIPTOR* properties; const FXJSE_FUNCTION_DESCRIPTOR* methods; - int32_t propNum; int32_t methNum; FXJSE_PropTypeGetter dynPropTypeGetter; FXJSE_PropAccessor dynPropGetter; FXJSE_PropAccessor dynPropSetter; - FXJSE_PropDeleter dynPropDeleter; FXJSE_FuncCallback dynMethodCall; }; void FXJSE_Initialize(); void FXJSE_Finalize(); -v8::Isolate* FXJSE_Runtime_Create_Own(); -void FXJSE_Runtime_Release(v8::Isolate* pIsolate); - void FXJSE_ThrowMessage(const ByteStringView& utf8Message); #endif // FXJS_FXJSE_H_ |