summaryrefslogtreecommitdiff
path: root/fxjs
AgeCommit message (Collapse)Author
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>
2018-07-12Use JSGetObject() in even more places.Lei Zhang
BUG=chromium:862059 Change-Id: Id354a5e6dbc037dbb76f901de8311a4f4a4d8940 Reviewed-on: https://pdfium-review.googlesource.com/37670 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-11Use JSGetObject() in more places.chromium/3489Lei Zhang
Change-Id: I7f26709bdad56cc2712f21e8e644be7c53ec5ec4 Reviewed-on: https://pdfium-review.googlesource.com/37513 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
2018-07-11Check GetObjDefnID() in various JS functions.Lei Zhang
Consolidate all the checks into JSGetObject(), and add GetObjDefnID() methods for classes that are missing it. BUG=chromium:862059 Change-Id: I2c2b725a01dcd259ef712d2513fcf740cc410b15 Reviewed-on: https://pdfium-review.googlesource.com/37510 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-11Fix some nits in fxjs code.Lei Zhang
Change-Id: I533a702947ba371cbc7971d88a3b7dabbc81a298 Reviewed-on: https://pdfium-review.googlesource.com/37511 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-07-03Use unowned ptr to Node from outside XFA node tree.chromium/3481Tom Sepez
Change-Id: Idcd992224fc5411c97f3001293af83a6c581e695 Reviewed-on: https://pdfium-review.googlesource.com/36991 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-07-02Kill a malloc/memcpy in cjs_document.cppTom Sepez
Change-Id: Icdbdd1c0e5052490c251009b5b2b31b2c46fb580 Reviewed-on: https://pdfium-review.googlesource.com/36833 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-07-02Virtualize Observable<T>::ObservedPtr::OnDestroy() for CPDF_Avail cleanupTom Sepez
This enables more complicated cleanup when an observed object is destroyed. Use it to make documents observable and to allow the CPDF_Avail to cleanup without the need for intermediate class. Change-Id: I3a8e758b7ff542e0a58710eff1ac8017205cbd45 Reviewed-on: https://pdfium-review.googlesource.com/36373 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-29Use UnownedPtr<CXFA_Node> or comment raw pointers as tree nodes.chromium/3479chromium/3478Tom Sepez
Part 2. Change-Id: I26fe434dac3c3f5186414440acc2a495a5f14091 Reviewed-on: https://pdfium-review.googlesource.com/36670 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-06-29Use UnownedPtr to CXFA_Node from outside the treechromium/3477Tom Sepez
Comment raw pointers subject to nondeterministic tree destruction order as such to avoid re-attempting to convert to the unowned mechanism. Change-Id: Ia9fe3c8a2729dc1e2b1de4a8c62ae3d2c3d7ec0a Reviewed-on: https://pdfium-review.googlesource.com/36635 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-06-28Fix logic error in CJX_InstanceManager::count()chromium/3476Tom Sepez
Calling the Setter when the Getter was intended results in a segv when accessing the empty return value. Bug: 353450 Change-Id: If3d35de1c5e2a24d11690fd323253f1103ee9ab5 Reviewed-on: https://pdfium-review.googlesource.com/36431 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-28Replace DCHECKs with ASSERTs.Lei Zhang
Change-Id: I0f2bf1cb44b4cba872a719f0a75d8776f413812c Reviewed-on: https://pdfium-review.googlesource.com/36250 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-26Use ObservedPtr for CJS_Field::m_pJSFieldTom Sepez
Bug: 856354 Change-Id: Ic0ac4d189dff6f4688a6c5feb745fe8c5a5ed4bb Reviewed-on: https://pdfium-review.googlesource.com/36150 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-22Avoid some duplicate const/non-const getters.Tom Sepez
Getters should nearly always be const when they return a non-const pointer to an unowned object. Saves a bit of code along the way. Grep for similar occurrences and add "const". Change-Id: I492bf962a7d62452fa40310146226dc0c8ebb753 Reviewed-on: https://pdfium-review.googlesource.com/35890 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2018-06-21Clean up constant values for JS alert and beepRyan Harrison
Define constant values in the public API for the valid values of alert button type, alert icon type, and beep type. Replace various magic numbers through out the code base using these values. Also replace the XFA specific versions with an enum class that is guaranteed to have the same values, instead of #defines that just happen to. This CL does not attempt to add error checking on these values, since it currently doesn't exist so adding it may cause regressions. Change-Id: Ief3aee2a4ad419691c18fc1dba8b984ad222141b Reviewed-on: https://pdfium-review.googlesource.com/35730 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-21Use the length of calculated string instead of sourceRyan Harrison
In this function a string is converted to UTF8, if there are non-printing characters in the original string, the generated string will be shorter. Thus using the original string length for iteration range will cause an OOB read. BUG=chromium:854623 Change-Id: I338005476c3de529709f3eae6892d27a6c7f2263 Reviewed-on: https://pdfium-review.googlesource.com/35810 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2018-06-21Pass output parameters as pointers in ijs_event_contextTom Sepez
It is hard to tell if there is some unsavory stuff going on with references otherwise. Avoids some const_casts in the process. Add some UnownedPtrs along the way to check caller's storage duration. Change-Id: Ic8d85802083f0b27e07993ea25f8f1c15fca1712 Reviewed-on: https://pdfium-review.googlesource.com/35750 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-21Remove WideString::c_str() calls where possible.Tom Sepez
Many of these cause a string duplication as we go from Widestring => c_str => Widestring Change-Id: I0dfa952e66f89138e719ff9200db3d9397839e28 Reviewed-on: https://pdfium-review.googlesource.com/35790 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-06-21Avoid const-refs to implicitly constructed strings.Tom Sepez
Because the invisible temporary goes out of scope at the next semicolon. Also avoid returning const string references since the cost is low to properly keep the string alive. Change-Id: Id283e4fd99f79a02d79d739a533a4ce05e831e2a Reviewed-on: https://pdfium-review.googlesource.com/35710 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-20Avoid more .c_str() usage, part 3Tom Sepez
Change-Id: I5dfadcb68e640235be6e3eb7c8d57ae3b8013d26 Reviewed-on: https://pdfium-review.googlesource.com/35691 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-20Re-work some more c_str() usage.Tom Sepez
Many of these are converting ByteString => c_str => ByteStringView, since the ByteStringView ctor is implicit. This is unfortunate, since that involves a strlen() which the ByteString already knows if we use AsStringView() instead. This changed one test result where we can now return the string "\0" instead of "" -- since strlen no longer eats the NUL. This seems consistent, say, with String.fromCharCode(). Change-Id: I17f68d1a1f4b352960208f9148e68ab4c4d78bd2 Reviewed-on: https://pdfium-review.googlesource.com/35590 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-20c_str() calls not needed when writing to ostreamTom Sepez
c_str() is a bit of a code smell, esp. since Byte/Wide strings know how to do this all by themselves. Change-Id: I9c86cee42c12a3f72ddb1d410a91cf25647d0ce6 Reviewed-on: https://pdfium-review.googlesource.com/35530 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-19Move fxcrt::{Byte,Wide}Strings with std::move().chromium/3466Tom Sepez
Remove some string copies in barcode that were noticed whilst looking for moves. Change-Id: Ieda34d00f633576ba1f0dca283dcdabfb36f236c Reviewed-on: https://pdfium-review.googlesource.com/35410 Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-14Move definition of XFA_SCRIPTATTRIBUTEINFO into cjx_object.h.Peter Collingbourne
This allows compilers targeting the MS ABI to select the correct inheritance model for the member function pointer type XFA_ATTRIBUTE_CALLBACK using the complete type of CJX_Object. It will allow us to enable the new Clang flag -fcomplete-member-pointers globally. Bug: chromium:847724 Change-Id: I90cedde8c5355e5eb896a93f0e43e6a1e1d09dbc Reviewed-on: https://pdfium-review.googlesource.com/35190 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2018-06-12Rework "Make common page base class."Tom Sepez
Re-landing of https://pdfium-review.googlesource.com/c/pdfium/+/32892 This time, however, we do not build on the previous CL which cached pages. This CL by itself should be OK but was reverted only because it was blocking earlier reverts. Change-Id: I067d5f07373eeac6cced5d0c113ea40e5f8dcd15 Reviewed-on: https://pdfium-review.googlesource.com/34910 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-11Move some CFXJS_Engine methods to CFXJS_ObjDefinition.Tom Sepez
Partial move, we'll clean up the engine side later. Change-Id: I07fdae150de9e834d11ed242a7f9a007aae266ac Reviewed-on: https://pdfium-review.googlesource.com/34810 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-11Move some FXJS methods onto the per-isolate object.Tom Sepez
This more clearly shows how information is flowing out of V8 and into our C++ callbacks. Change-Id: I5c37d2c28c166443eb9983076fbb0e944bebbf47 Reviewed-on: https://pdfium-review.googlesource.com/34790 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-11Use spans in CJX_Object.Tom Sepez
Avoid explicitly finding array sizes. Change-Id: Id51e3d10ea4db0a6375807a53309ce8d68b3b413 Reviewed-on: https://pdfium-review.googlesource.com/34750 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-11Use spans in CJS_Object.Tom Sepez
Avoid explicitly having to count items in arrays. Change-Id: I24a91db45e8a8530f38afcc273e824ffb70a6cb9 Reviewed-on: https://pdfium-review.googlesource.com/34710 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-06-08Remove CJS_Object::InitInstance().Tom Sepez
Because constructors can do all this. Change-Id: I4f7ff6c26b17d9bddd326333a66e1bd38b2ea377 Reviewed-on: https://pdfium-review.googlesource.com/34693 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-08Ensure CJS_Return() with error always includes a message.Tom Sepez
Change the signature of the constructors to make it impossible to do this otherwise. Change-Id: I14e88d98a1128f2d599459ce9337cd6d079469fe Reviewed-on: https://pdfium-review.googlesource.com/34531 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-08Fix issue with resolveNodes() not found off global proxy object.Tom Sepez
We used to assume that a global proxy object could be distinguished by it not having two internal fields, but that invariant isn't correct. Instead, flag it as such so the block of code at line 126 will check the prototype to find an actual object. Squeeze some bytes out of the tags while were at it, no reason for them to be wide. Also remove GetGlobalObjectFromContext() helper, for transparency into what's really going on in v8. This then shows a needless retrieval of an object we already have in one case. Bug: pdfium:1097 Change-Id: Iafc356373166fe5fda76ea7d64193826ee69a6c3 Reviewed-on: https://pdfium-review.googlesource.com/34630 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-08Update fxjs/README now that context data slots are goneTom Sepez
TBR=dsinclair@chromium.org Change-Id: I2665f616d451ff7075b63457a91ef264bbde84c9 Reviewed-on: https://pdfium-review.googlesource.com/34610 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-07Remove friending in CFXJSE_Context.Tom Sepez
Change-Id: I6a634cb3fb9acdd78ae29017987e5e41865a0d4b Reviewed-on: https://pdfium-review.googlesource.com/34490 Commit-Queue: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-07Remove v8::Context slot usage entierly from fxjsTom Sepez
Its no longer required. Change-Id: I180ca99817352a91b6d9d7c9b45985cd96dc730e Reviewed-on: https://pdfium-review.googlesource.com/34290 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-07Simplify cfxjs_engine_embeddertest.cppTom Sepez
In a world without context slots, we don't need to test getting an engine from a content slot. Change-Id: If572c364d663d1f20af659392bda3b96348fd4d4 Reviewed-on: https://pdfium-review.googlesource.com/34270 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-06Remove still more v8::Context slot usage.chromium/3452Tom Sepez
Removes CJS_Runtime::RuntimeFromIsolateCurrentContext() Change-Id: I51abcf32aaafac522e1595edf663507c26781357 Reviewed-on: https://pdfium-review.googlesource.com/34230 Commit-Queue: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-06Get global consts without use of v8::Context slotTom Sepez
Another step in the move away from v8::Context slots. Change-Id: I302d1b3305755088c663214120e582b783cc5fbb Reviewed-on: https://pdfium-review.googlesource.com/34211 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-06Stop using some v8::Context slot to find runtime.Tom Sepez
Instead, use the object binding's pointer. Puts the cart back behind the horse. Change-Id: I4c06ae991b871c6e90b0e6c70b69886addca2354 Reviewed-on: https://pdfium-review.googlesource.com/33630 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-06[xfa] Make class error description betterDan Sinclair
This CL changes the JS error produced by the CFXJSE_Class when a method call returns with error. Instead of outputing something like: JS Error: resolveNode.: we will now get: JS Error: Root.resolveNode: which at least lets us know we're looking at the Root class. Bug: pdfium:1097 Change-Id: I4982109398e290d9ebc2763fcc2421a642c581a5 Reviewed-on: https://pdfium-review.googlesource.com/34090 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-06Better error reporting on XFA JS errorsTom Sepez
Change-Id: I773ff83b45ffbd736f064daedb1010c8d01a99d5 Reviewed-on: https://pdfium-review.googlesource.com/34050 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-05Introduce IJS_Runtime::ScopedEventContext helper class.chromium/3451Tom Sepez
This proves that m_EventContextArray is, in fact, a stack. Tidy one function by using AutoRestorer while at it. Change-Id: I319538b4eadcd9ce83319aa73861635dd5eb8c36 Reviewed-on: https://pdfium-review.googlesource.com/33970 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-05Tidy parser lifecycle state machine in CPDF_PageObjectHolder.Tom Sepez
Only update state in CPDF_PageObjectHolder itself. Make more data private. Remove CPDF_Page::GetPageBBox() as exact duplicate of CPDF_PageObjectHolder::GetBBox(). Change-Id: I083ec33f61a1490e7a5e673c9787751af15a6cd1 Reviewed-on: https://pdfium-review.googlesource.com/33810 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-05[xfa] Make the event context available when calling back in XFADan Sinclair
When calling into the XFA JS engine with a request for a non-XFA JS call which accesses the EventContext we would get a crash in XFA as we never set the context. This CL changes the XFA code to accept the CJS_Runtime instead of the CFXJS_Engine and then calls NewEventContext before executing JS scripts. This will correctly setup the event context as needed for any JS callbacks. Bug: pdfium:1003 Change-Id: Icf202252b2e6e56afdf0d1766a32a893935a2fd3 Reviewed-on: https://pdfium-review.googlesource.com/33930 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-06-04Lowercase JS_Define.{h,cpp} and CJS_Define.hTom Sepez
Consistency with file naming conventions. No functional change. Change-Id: I596c4be5bbf0510950c44a7d9d80f59537739c3b Reviewed-on: https://pdfium-review.googlesource.com/33593 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>