From a85e5ca5f2dfadcf9f3812a8ef039d1f206833a4 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 1 Nov 2017 16:06:07 +0000 Subject: Split JS methods out of CXFA_Object This CL moves the javascript code from CXFA_Object to CJX_Object. The Script_* methods are proxied to CJX_Object. The ownership of the CJX_ object was removed from CXFA_Node and moved up to CXFA_Object. Change-Id: I58d286e6bb0151aa88d4f673bc7729987417bde6 Reviewed-on: https://pdfium-review.googlesource.com/17310 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fxjs/cjx_object.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 fxjs/cjx_object.cpp (limited to 'fxjs/cjx_object.cpp') diff --git a/fxjs/cjx_object.cpp b/fxjs/cjx_object.cpp new file mode 100644 index 0000000000..a3ba05f1b4 --- /dev/null +++ b/fxjs/cjx_object.cpp @@ -0,0 +1,55 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fxjs/cjx_object.h" + +#include "fxjs/cfxjse_value.h" +#include "xfa/fxfa/parser/cxfa_object.h" + +CJX_Object::CJX_Object(CXFA_Object* obj) : object_(obj) {} + +CJX_Object::~CJX_Object() {} + +void CJX_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue, + bool bSetting, + XFA_ATTRIBUTE eAttribute) { + if (bSetting) { + ThrowInvalidPropertyException(); + return; + } + pValue->SetString( + FX_UTF8Encode(GetXFAObject()->GetClassName()).AsStringView()); +} + +void CJX_Object::ThrowInvalidPropertyException() const { + ThrowException(L"Invalid property set operation."); +} + +void CJX_Object::ThrowIndexOutOfBoundsException() const { + ThrowException(L"Index value is out of bounds."); +} + +void CJX_Object::ThrowParamCountMismatchException( + const WideString& method) const { + ThrowException(L"Incorrect number of parameters calling method '%.16s'.", + method.c_str()); +} + +void CJX_Object::ThrowArgumentMismatchException() const { + ThrowException(L"Argument mismatch in property or function argument."); +} + +void CJX_Object::ThrowException(const wchar_t* str, ...) const { + WideString wsMessage; + va_list arg_ptr; + + va_start(arg_ptr, str); + wsMessage.FormatV(str, arg_ptr); + va_end(arg_ptr); + + ASSERT(!wsMessage.IsEmpty()); + FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringView()); +} -- cgit v1.2.3