summaryrefslogtreecommitdiff
path: root/fxjs
AgeCommit message (Collapse)Author
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>
2018-06-04Make CJS_Objects track CJS_Runtime (and hence the document itself)Tom Sepez
Precursor to removing some more v8::Context slot dependency. There's a cost to maintaining the set of observers, but since these objects are tied to V8 lifetimes, not C++ lifetimes, we want to be very wary of the document going away unexpectedly. Change-Id: I579f58a460aa50b88cb861227c9aca9a8a83ce12 Reviewed-on: https://pdfium-review.googlesource.com/33471 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-04cjs_globalconsts.cpp need not use v8::Context slotsTom Sepez
Small step towards deprecating FXJS's use of v8::Context slots. Reduces some string constant storage size while were at it by avoiding wide literals for ascii strings. Change-Id: Ibc651cff264302681645fde7c53bf77517b97651 Reviewed-on: https://pdfium-review.googlesource.com/33470 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2018-06-04Revert "Make CPDF_Document cache CPDF_Pages"Tom Sepez
This reverts commit f0d9d28a034fe3650c3c2d662090c1e8687ddb16. Reason for revert: avoid parsing page. Change-Id: Id3478f7e38f1cbe95d098e00158b1d7d9dc6f76e Reviewed-on: https://pdfium-review.googlesource.com/33750 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-04Revert "Make common page base class for XFA and non-XFA."Tom Sepez
This reverts commit d06cc38b76685b002c51b227ae43b8314d926ad8. Reason for revert: blocking previous revert Change-Id: I74f8b80852c671440cca5fabef30e69cde9e2063 Reviewed-on: https://pdfium-review.googlesource.com/33713 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-06-04[xfa] Get properties from the non-xfa global if possibleDan Sinclair
When script variables are used the methods are set on the non-xfa global object. This CL updates the NormalPropertyGetter to check the non-xfa global object for methods which allows the variables methods to be found. Bug: pdfium:1097 Change-Id: I13d9d49ad654cad776883aef74de6250de5e756b Reviewed-on: https://pdfium-review.googlesource.com/33433 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2018-06-01Fix XFA guardsRyan Harrison
These guards are using #if, when they should be using #ifdef. Caught using Clang's static analyzer. Change-Id: I86e99c5e4142cf84fff5f2365ad534f09ae40511 Reviewed-on: https://pdfium-review.googlesource.com/33510 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2018-05-31Update fxjs READMETom Sepez
TBR=dsinclair@chromium.org Change-Id: I6f2a4a4b39c38a1bcfcf817a5c2aa51414291ad9 Reviewed-on: https://pdfium-review.googlesource.com/33451 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-05-31Make FXJSE variable context compatible with FXJS.Tom Sepez
Allows FXJS to be entered directly from V8 when the variable context gets a reference to an FXJS object. Bug: pdfium:1066 Change-Id: I48e39ed9104cc6df31c19d94fa7e0f8c7760932f Reviewed-on: https://pdfium-review.googlesource.com/33450 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2018-05-31[xfa] Remove unused methods from CFXJSE_ScopeUtil_IsolateHandleContextDan Sinclair
Methods are not called, removed. Bug: pdfium:1097 Change-Id: I0c7bc8ded070002dd5eb980a4705eabb829fb6ec Reviewed-on: https://pdfium-review.googlesource.com/33390 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2018-05-30Make common page base class for XFA and non-XFA.Tom Sepez
Now that both are ref-counted, we can replace ifdef's with some polymorphism. Bug: pdfium:760 Change-Id: Ie22ea259c9af56fa569f0af268b8e7065789a3f2 Reviewed-on: https://pdfium-review.googlesource.com/32892 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>