summaryrefslogtreecommitdiff
path: root/fxjs
AgeCommit message (Collapse)Author
2018-08-17Introduce safer CJS_Return::Success() and Failure().Tom Sepez
Avoid the possibility of ever re-introducing the issue noticed last week. Remove some redundant JSGetStringFromID() calls. Change-Id: I56687c2191bd72e378f747083f34080e50cbe490 Reviewed-on: https://pdfium-review.googlesource.com/40490 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-16Remove optional argument from ResolveNodes_GetParent().Tom Sepez
Conformity with standards. Change-Id: Ia718700526477fd1826eb4900ab333ebf4c8a517 Reviewed-on: https://pdfium-review.googlesource.com/40353 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-08-16Replace optional bool bNotify with enum type.Tom Sepez
Adds clarity to the call sites. Change-Id: Id4deed9adda2ad79f0847d618792429044d4f7d6 Reviewed-on: https://pdfium-review.googlesource.com/40351 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-15Make CFX_MemoryStream always consecutive.chromium/3524Lei Zhang
Non-consecutive mode has questionable correctness and is not an obvious performance win. Change-Id: Idaa66e5ee5c4604628a0f55b67d5a04ab47ea5ec Reviewed-on: https://pdfium-review.googlesource.com/40050 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-08-14Remove optional argument from NewFXJSBoundObject().Tom Sepez
Additionally, we have a pre-existing enum type that is more meaningful than just a boolean. Change-Id: Ie6ad13a3c9b22e34dedf7a5a9b5b9cc2a49b1f03 Reviewed-on: https://pdfium-review.googlesource.com/40190 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-14Remove optional argument from GetVariablesThis().Tom Sepez
Change-Id: Ie0e8e83e0380c323d8d12e82e50126b85d34405c Reviewed-on: https://pdfium-review.googlesource.com/40191 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-14Remove more default arg = nullptr cases.Tom Sepez
Bring in line with standards. Remove argument entirely for mac code that is always nullptr. Change-Id: I0710bdbd51fc0bc2e1d428ef44976be39a631147 Reviewed-on: https://pdfium-review.googlesource.com/40091 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-10Remove direct calls to timechromium/3519Ryan Harrison
Replaces them with calles to the proxy function, FXSYS_time, so that tests may use a stable time value instead of the wall clock value. BUG=pdfium:1104 Change-Id: I4743c4634f56d4a6cba1f1130c4562a35cee1887 Reviewed-on: https://pdfium-review.googlesource.com/39853 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2018-08-10Add proxy for syscall timeRyan Harrison
This CL adds a proxy, FXSYS_time, for the time syscall, so that a testing mechanism can be implemented. Specically there is now a flag for pdfium_test, --time=, that allows setting the time since the epoch that will be returned. This plumbed all the way down into the proxy and allows for stable results for tests that depend on getting the current time. There are other places in the code base that will need to be patched like this, that will be dealt with in follow on CLs. BUG=pdfium:1104 Change-Id: I2de185f8d47abe46704dd579c13a54948b7f81e0 Reviewed-on: https://pdfium-review.googlesource.com/39750 Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2018-08-08Move ByteString::FromUnicode() to WideString::ToDefANSI()Tom Sepez
Turns out that "FromUnicode" is misleading in that, on linux, it simply removes any characters beyond 0xFF and passes the rest unchanged, so no unicode decoding actually takes place. On Windows, it passes it into the system function specifying FX_CODEPAGE_DefANSI, converting it into the so-called "default ANSI code plane", passing some characters, converting others to '?' and still others to 'A'. Either way, nothing resembling UTF8 comes out of this, so pick a better name. These now immediately look suspicious, so a follow-up CL will see which ones should really be WideString::UTF8Encode() instead. Making this a normal method on a widestring rather than a static method on a bytestring feels more natural; this is parallel to the UTF8Encode and UTF16LE_Encode functions. Add a test that shows these conversions. Change-Id: Ia7551b47199eba61b5c328a97bfe9176ac8e583c Reviewed-on: https://pdfium-review.googlesource.com/39690 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-07Remove WideString::Format() from ThrowException() methods.chromium/3516Tom Sepez
No need for variadic printf-like functions, since callers can cobble arguments into a string much more simply. Change-Id: I0e8d6f6a55a3715ef9d5c6940b73ce8bb2220a1a Reviewed-on: https://pdfium-review.googlesource.com/39611 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-07Speculative fix for null deref above ThrowNoDefaultPropertyExceptionTom Sepez
Avoid possibility of an unterminated string or nullptr by avoiding stringviews, since the non-view classes copy and always provide a suitable result. Always use %ls and widestrings in wprintf() variants, since that combination is consistent across our platforms (%s, %S, etc. have idiosyncracies). Bug: 870952 Change-Id: Ief62a42c3486e8298f9583b56e9333db1a74972a Reviewed-on: https://pdfium-review.googlesource.com/39551 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-08-02Mark some arrays as constant.Lei Zhang
Fix some nits as well. Change-Id: Iaef79056b68ea0dae7f76c09e7a133cc545896fd Reviewed-on: https://pdfium-review.googlesource.com/39353 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-08-02Simplify CFXJSE_FormCalcContext::unfoldArgs().Lei Zhang
Return results instead of writing them to an out parameter. Remove start index which is always 1. Change-Id: I4b969a1e27679fca56b2cde1a901a8967c7fa8ce Reviewed-on: https://pdfium-review.googlesource.com/39092 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-08-02Remove some parameters that are non-const references.Lei Zhang
Also remove a check that is always false, and simplify another check. Change-Id: I89193eebc84a6fd139b34b890a8c3003a635851b Reviewed-on: https://pdfium-review.googlesource.com/39091 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-08-01Make FPDF_FormHandle be represented as an incomplete type.chromium/3510Tom Sepez
Make consistent with other public API types. Introduce CPDFSDKFormFillEnvironmentFromFPDFFormHandle() and FPDFFormHandleFromCPDFSDKFormFillEnvironment() helper functions. Use these to kill off some casts in the process. Change-Id: I6230ecdb4cecd03076f5e24c8cc49c45ad694da7 Reviewed-on: https://pdfium-review.googlesource.com/39250 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-08-01Encapsulate some public static methods in CFXJSE_FormCalcContext.Lei Zhang
They are only used inside CFXJSE_FormCalcContext. Move into an anonymous namespace. Change-Id: Ib8a0ff9b90cf951459c04655bedada3bdb1979a4 Reviewed-on: https://pdfium-review.googlesource.com/39090 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-08-01Refactor PatternStringType().Lei Zhang
Return a std::pair instead of having a non-const ref out parameter. Use early returns / continues to simplify code. Change-Id: I093fe667d31447ed42b8d44e354405094adaf8fd Reviewed-on: https://pdfium-review.googlesource.com/39070 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-08-01Combine date/time format methods in CFXJSE_FormCalcContext.Lei Zhang
Also fix C++ style errors. Change-Id: Ia4b815c2fa8430791bb44a218ef93f8efde8c3af Reviewed-on: https://pdfium-review.googlesource.com/39050 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2018-07-30Don't static_cast<>(this) to subclass in CXFA_LayoutItem methods.chromium/3508Tom Sepez
Instead, move the methods to the subclass where they belong. Fix IWYU in CJX_Object.h to fix compilation. Change-Id: I4c71f28235b9cf5000e9ddaf33d6602baf22205f Reviewed-on: https://pdfium-review.googlesource.com/39170 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-30Fix a misspelling of "locale".Lei Zhang
Change-Id: I3fdc6d473f08835b6caeacbbd583bb651a9c5678 Reviewed-on: https://pdfium-review.googlesource.com/39111 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-07-28Remove CXFA_TraverseStrategy_ContentLayoutItem.chromium/3507chromium/3506Tom Sepez
It makes illegal casts and requires its callers to double-check the type validity of results before use. Instead, use the parent class iterator and perform checked casts. No functional difference, since it looks like the requisite checks were being made in all places. Make one "using" visible to other files to save some verbosity. Change-Id: I894ca15b4bdddd4723b787663950a58bc58b7f06 Reviewed-on: https://pdfium-review.googlesource.com/39030 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-07-28Add CPDSDK_Annot::AsBAAnnot() checked downcast methodTom Sepez
XFA introduces some additional subclasses, so it doesn't hurt to be sure in all cases before making a static cast. Change-Id: I7447ca58be0b57201b39ba40a3fc5f47505cee58 Reviewed-on: https://pdfium-review.googlesource.com/39013 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-27Tag XFA data bound to V8 Objects.Tom Sepez
Because we don't want to trust anything V8 gives us back. Use a deep namespace so we can have a short declaration in the structs, but avoid collisions. Change-Id: Ibb832a5dcd34c652159c3343dd70c9e2ee561537 Reviewed-on: https://pdfium-review.googlesource.com/38972 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-26Use moar ToXMLElement() in place of static_cast<>.Tom Sepez
Introduces checks in a few new places, but mainly just consolidates checking/casting logic. Change-Id: I634a03060d254db099972c6978249992367e146c Reviewed-on: https://pdfium-review.googlesource.com/38900 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-26Be more careful casting to widget subclasses.Tom Sepez
Part of the effort to reduce unchecked static casts. Change-Id: I1bff1c53aa7c5804660de4b65cf01523d70fcbb7 Reviewed-on: https://pdfium-review.googlesource.com/38896 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-26Fix usage of deprecated V8 Value::ToString methodDan Elphick
Value::ToString is deprecated since the Isolate is inferred from the memory address of the object being converted to a string which will soon not be reliable. As such this method will be removed in the very near future. Change-Id: I1e5a1a0464f2052cc3aa5eeb1ddbdb7b0a9222d3 Reviewed-on: https://pdfium-review.googlesource.com/38914 Commit-Queue: Jochen Eisinger <jochen@chromium.org> Reviewed-by: Jochen Eisinger <jochen@chromium.org>
2018-07-25Introduce ToXMLElement() checked downcast helper functionTom Sepez
And use it in place of ASSERT() that the type was correct. Since we can check it, doing so at runtime may help avoid type confusion, and we'll get a nice safe SEGV if the asserted condition ever fails. Change-Id: I46b65a4b70e819a670d7cad7966e0d100f0d9a63 Reviewed-on: https://pdfium-review.googlesource.com/38810 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-25Move CXFA_ThisProxy helper to CXFA_Object.Tom Sepez
Because the other helpers are declared here. Rename VariablesThis to ThisProxy in a few places; VariablesThis is a slightly different concept (see GetVariablesThis()). Then introduce helper for CXFA_List subclass as well. Remove unused const version of some helpers. Change-Id: Ia328d8cd170a8b97015e98c1c770fa8a44810455 Reviewed-on: https://pdfium-review.googlesource.com/38670 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-24Fix UAF in CPDFSDK_Widget::GetMixXFAWidget().chromium/3502Henrique Nakashima
Do not allow instanceManager methods to run in Foreground XFA forms. They are static, and their widgets should not be inserted or removed. See "XML Forms Architecture (XFA) Specification Version 3.3", page 272. Bug: chromium:860697 Change-Id: Ia96834e085ee508618ca4dcb2bd5271466369ede Reviewed-on: https://pdfium-review.googlesource.com/38751 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
2018-07-24Rename JS_{METHOD,PROP} to JSE_{METHOD,PROP}Tom Sepez
Because they are too easily confused with non-XFA JS_STATIC_PROP despite being on the XFA side. The JSE_ prefix mirrors the fxjs/fxjse split ("e" presumably standing for "extension" or some such) between the non-xfa/xfa V8 adapter layer. Rename fxjs/{cjx_define.h => jse_define.h}, since there aren't any symbols starting with |CJX| in it. Fix some IWYU for jse_define.h No functional changes. Change-Id: I6a0b2b6fe6ef1b564b0bfa2fa7ba317a0cea0953 Reviewed-on: https://pdfium-review.googlesource.com/38730 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-24Remove lpClass argument from FXJSE_RetrieveObjectBinding()Tom Sepez
In turn, it too is always nullptr. This shows that the V8 side check for hasInstance() was never being applied. We will augment this with C++ side checks down the road, since we don't want to trust V8 anyways. Change-Id: Iee38f32af9561783dbf253d798bd975029f3a4a2 Reviewed-on: https://pdfium-review.googlesource.com/38594 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-23Tighten up ThisProxy casts.Tom Sepez
Previous CLs have shown that the "lpClass" checks aren't sufficient here, so ensure we are always checking C++ enum value before downcasting this type. Change-Id: I418127c5e7131e0a3363363a60d1976719d6837c Reviewed-on: https://pdfium-review.googlesource.com/38550 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-23Remove unused CFXJSE_Arguments::GetObject()chromium/3501Tom Sepez
Insert another unowned ptr along the way. Change-Id: I953baa3448282fd4f655bb99524f131f66b7ed86 Reviewed-on: https://pdfium-review.googlesource.com/38593 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-23Remove argument from CFXJSE_Value::ToHostObject()Tom Sepez
Like the other cases, it is always nullptr. Change-Id: I280f25899ffbe5e35f4ef3342aec7896edf3e1f2 Reviewed-on: https://pdfium-review.googlesource.com/38592 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-23Remove second argument to CFXJSE_Engine::ToObject()Tom Sepez
It, too, is always passed as nullptr. Change-Id: I2573bea4cc33f48c13979026ea8ae42b368ce8a5 Reviewed-on: https://pdfium-review.googlesource.com/38590 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-23Replace CFXJSE_HostObject::type_ with polymorphic conversion methodsTom Sepez
More foolproof technique, and saves one word in every instance at a cost of two pointers in every subclass vtable. Change-Id: Ied4f91d4d203b5e6d83abe751159eb7e55489bb5 Reviewed-on: https://pdfium-review.googlesource.com/38530 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-23Remove second argument to ToJSContext().Tom Sepez
It's always passsed as nullptr. Rename function to ToFormCalcContext() for clarity while we're at it. Change-Id: I96581c6b86b7ac7b48b60429e2144f16af7e46ca Reviewed-on: https://pdfium-review.googlesource.com/38570 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-19Remove some unused default values in cfxjse_context.h.Tom Sepez
Callers already explicitly pass nullptr as needed. Change-Id: I8cf9d4951ec1b75cf90dccc1b53bfcd6fb6a42e6 Reviewed-on: https://pdfium-review.googlesource.com/38450 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-19Change some ASSERTS() to early returns in cfxjse_class.cppTom Sepez
Given the issues we've seen on the non-XFA side, be more careful about using V8-provided data on the XFA side. Change-Id: I13b7fa9ac852be74c8135410734445b2c9a23c97 Reviewed-on: https://pdfium-review.googlesource.com/38430 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-17Check for global flag on global proxy objects.Tom Sepez
Second line of defense for issue in the associated bug. Bug: chromium:862059 Change-Id: I58ba890dfe02c89dd6bcfa23e2e116e107f9adbc Reviewed-on: https://pdfium-review.googlesource.com/37991 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-16Make JSGetObject<C>() return UnownedPtr<C>.Tom Sepez
This a convenient place to assert that the callback that is about to be invoked on the object doesn't destroy the object at any point during its execution. Change-Id: Iacb9d4e01603cc6bf316b00fdd062955c903ca5c Reviewed-on: https://pdfium-review.googlesource.com/37970 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-16Use UnownedPtr<> to v8::Isolates.Tom Sepez
Isolates are long-lived, but this may catch a few things. Introduce CFX_V8IsolateDeleter for unique_ptr<v8::Isolate> usage. Fix Dispose()/SetIsolate(nullptr) ordering in cjs_runtime.cpp Remove one unused isolate member. Flip protected -> private in one place. Change-Id: I26cdd120f799192e93b0d9d04dcde8f348dc21f3 Reviewed-on: https://pdfium-review.googlesource.com/37931 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-16Alert embedder when attempting to save XFA formRyan Harrison
This CL adds an experimental callback to the form fill API that allows PDFium to signal to the embedder that an attempt call save occurred. The embedder is responsible for showing an appropriate UI when this occurs. When PDF saving is implemented the API can be removed. BUG=pdfium:953 Change-Id: Iba30f4d0547fe773b793e499995be426626092a0 Reviewed-on: https://pdfium-review.googlesource.com/35870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2018-07-12Move CJS_Field private methods into an anonymous namespace.Lei Zhang
Change-Id: Ib758cfc97a4e2bb94f58afa999608f77c0972336 Reviewed-on: https://pdfium-review.googlesource.com/37730 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-07-12Remove parameter to CJS_Field::GetFormFields().Lei Zhang
It is always the same value. Also mark ValueIsOccur() as const. Change-Id: Ifdfc33f8213ed272e7d36e1e4c2de1d2070fbcbd Reviewed-on: https://pdfium-review.googlesource.com/37712 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-12Add CJS_Field::GetFirstFormField().Lei Zhang
Its what many CJS_Field methods really want to do. Change-Id: I18cf61a15be7b783b795c61a5c26c42ef5d82127 Reviewed-on: https://pdfium-review.googlesource.com/37711 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-12Add more helper functions to check field types in CJS_Field.Lei Zhang
These types are commonly checked together. - IsComboBoxOrListBox() - IsComboBoxOrTextField() Change-Id: Ia363bd9822f8dfe61e11cf552ec516f9403a8fcc Reviewed-on: https://pdfium-review.googlesource.com/37673 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-12Add a IsCheckBoxOrRadioButton() helper for CJS_Field.Lei Zhang
Change-Id: I0e06d641d482cbcd2cf33f327d9504e55a772157 Reviewed-on: https://pdfium-review.googlesource.com/37672 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-07-12Use pdfium::Optional in CJS_Return.Lei Zhang
Change-Id: Idfe70f86fbaf341ba6b197689a65ac722e671f39 Reviewed-on: https://pdfium-review.googlesource.com/37674 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>