summaryrefslogtreecommitdiff
path: root/fxjs
AgeCommit message (Collapse)Author
2017-08-16Check for possible empty object returns from NewFxDynamicObj()Tom Sepez
Avoid some potential crashiness. TBR=jochen@chromium.org Bug: 754610 Change-Id: Ie8143c1909df7ba5783b7d20b61e31f093d04b34 Reviewed-on: https://pdfium-review.googlesource.com/10970 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-07-26Use method to get global objectDan Sinclair
This CL switches the CFXJSE_Context::GetGlobalObject method to call FXJSE_GetGlobalObjectFromContext() instead of getting the global object directly. Bug: pdfium:832 Change-Id: I6c04adb0a9775926d3a0708cefb8bba85c60fd21 Reviewed-on: https://pdfium-review.googlesource.com/9111 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-07-19Rename StringCs c_str() to unterminated_c_str().Tom Sepez
Since there is no guarantee of termination if the StringC was extracted from a snippet of another string. Make it more obvious that things like strlen(str.unterminated_c_str()) might be a bad idea. Change-Id: I7832248ed89ebbddf5c0bcd402aac7d40ec2adc2 Reviewed-on: https://pdfium-review.googlesource.com/8170 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
2017-06-01Document bindings implementaionTom Sepez
Change-Id: Ic2690fa09f35284fcb96050e8d6ce16b724e45dc Reviewed-on: https://pdfium-review.googlesource.com/6212 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-06-01Tag CFXJSE_HostObject sub-classes.Tom Sepez
CXFA_FM2JSContext and CXFA_Object both subclass CFXJSE_HostObject. When a CFXJSE_HostObject is obtained from an opaque pointer inside a V8 object internal slot, there is no way to distinguish one from the other. Bug: 728158 Change-Id: Iabc648e8b7226e2819d8795227442c3f6c61a793 Reviewed-on: https://pdfium-review.googlesource.com/6211 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-06-01Replace some repeated code with existing CFXJS_Engine::NewString() helper.Tom Sepez
In turn, fix type information for New*() return values. In turn, resolve some ambiguity in a ? operator expression. Change-Id: I45c31d81f815b11590b46dacc8060d8e489dde5c Reviewed-on: https://pdfium-review.googlesource.com/6131 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-06-01Be less trusting of MaybeLocal<> return types from V8 To* methods.Tom Sepez
Calling ToLocalChecked() will crash otherwise. Bug: 707673 Change-Id: I66a5b36d8cf1710a725e30c2d14a195d08ef25a4 Reviewed-on: https://pdfium-review.googlesource.com/6130 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-05-31CFXJS_Engine::GetObjDefnID is a static methodTom Sepez
So call it as such. Fix two places where we're invoking it off of an intance. Change-Id: I08712fa27dbdf85c9195cedcc62d7d741b0ad091 Reviewed-on: https://pdfium-review.googlesource.com/6110 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-05-25Mass conversion of remaining class members (non-xfa)Tom Sepez
Change-Id: I8365ba80e3395d59a3cf35dbd9d9162e86e712e3 Reviewed-on: https://pdfium-review.googlesource.com/5970 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
2017-05-02Tag FXJSE's V8 objects as such.Tom Sepez
There are two APIs to V8 from pdfium: FXJS and FXJSE (for XFA). Previously, we put tags in internal fields for FXJS's objects. Now do the same for FXJSE. Bug: 713998 Change-Id: Ife4f616df3768db566b996dedc1da104f8d3fb93 Reviewed-on: https://pdfium-review.googlesource.com/4475 Reviewed-by: Jochen Eisinger <jochen@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-04-25Use unique_ptr in CXFA_ScriptContext::m_mapVariableToContext.Tom Sepez
Remove unused CFXJSE_Arguments::GetRuntime(). Remove some default argument values. Make members of CFXJSE_Context private. Change-Id: Id21951f7d8d68929b2799a9d6a2cdd7a3677f52a Reviewed-on: https://pdfium-review.googlesource.com/4493 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-03-31Use PartitionFreeGeneric, not PartitionFree, for JS ArrayBuffers.Chris Palmer
BUG=pdfium:681 Change-Id: Ide52764c7c7e8833c581dbc9d41ed875faa2c2bc Reviewed-on: https://pdfium-review.googlesource.com/3555 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-03-30Add some calls to MakeUniqueDan Sinclair
This CL replaces some new's with pdfium::MakeUnique. Change-Id: I50faf3ed55e7730b094c14a7989a9dd51cf33cbb Reviewed-on: https://pdfium-review.googlesource.com/3430 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-03-26Use PartitionAlloc for JavaScript ArrayBuffers and strings.Chris Palmer
BUG=pdfium:681 Change-Id: I5073d80d9bd623b73e578d5ba2226c39c371bab0 Reviewed-on: https://pdfium-review.googlesource.com/3097 Commit-Queue: Chris Palmer <palmer@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-03-22Convert to use info.Holder instead of info.ThisDan Sinclair
The definition of info.This is changing in v8. We want to work with the Holder and not what info.This will be returning in the future. Change-Id: Ic988f62d225569398cfde84ab51c72ae620a991a Reviewed-on: https://pdfium-review.googlesource.com/3147 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-03-15Add array_buffer JS test.Tom Sepez
JS Array Buffers are the first candidate to be allocated from PartitionAlloc when it becomes available, so add test first. Presently, we will return as large an array buffer as the system can handle; this is generally a bad idea so limit them to 256MB and test that we handle failure. Change-Id: I205745a7938d69eb32ac883b90824f2f9e584ec7 Reviewed-on: https://pdfium-review.googlesource.com/3065 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-03-14Replace FX_FLOAT with underlying float type.Dan Sinclair
Change-Id: I158b7d80b0ec28b742a9f2d5a96f3dde7fb3ab56 Reviewed-on: https://pdfium-review.googlesource.com/3031 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Nicolás Peña <npm@chromium.org>
2017-03-14Replace FX_CHAR and FX_WCHAR with underlying types.Dan Sinclair
Change-Id: I96e0a20d66b9184d22f64d8e4ce0dadd5a78c1e8 Reviewed-on: https://pdfium-review.googlesource.com/2967 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2017-02-27Explicitly tag fxjs native objects.Tom Sepez
Native object callbacks have to distinguish whether the object they have been given is actually a native object and not some ordinary JS object. For method/property calls, this happens via v8's signature mechanism, but signature checks aren't applied to method arguments themselves. Currently, we do this by treating any object with an internal field count of 2 as being such, but this is fragile, and it has been pointed out that other objects with two internal fields are present. Additionally, that the first field points to a structure with a small zero-based object definition ID doesn't really have enough entropy to trust that it isn't some other entity. So add a pointer to an internal address in the second slot to make this safer. Note that we'll also get the same release_assert in the majority of cases as described in the bug. This is great from a security standpoint, but not great from a functional standpoint, except this likely only occurs in the wild if they are trying to mess with us. This just guards the theoretical cases that might pass the existing release_assert. BUG=695830 Change-Id: I42db27d6ed1143269a852805e4e4d862a8ab8773 Reviewed-on: https://pdfium-review.googlesource.com/2847 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-02-27Fix uninitialized memory read in CJS_Object::GetEmbedObject()Tom Sepez
The expected way to create native PDFium objects for JS is via the NewFxDynamicObject() call in C++, but that doesn't mean that the corresponding constructors won't be called from JS. In that case, the internal fields will be uninitialized, and subsequent method calls may try to use them. Add a constructor callback for all PDFium objects that nulls out these fields (shame that v8 doesn't do this by default, but probably saves some cycles). Then ensure that we check for this possibility in all the places it might turn up. Conversely, if we've just gotten a successful return from NewFxDynamicObject(), we know the CJS_Object/EmbedObj are good, so avoid checking there. BUG=695826 Change-Id: Iadad644c4af937def967ddc83daac1dad7544d69 Reviewed-on: https://pdfium-review.googlesource.com/2839 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
2017-02-23Store JS string constants as single-byte strings.Tom Sepez
Save some space since none contain non-ascii characters. Avoid allocating C++ WideStrings just to convert back to UTF8 when defining properties. Change-Id: Id94db21b32ee7a96856c35a09f7550b54599ae13 Reviewed-on: https://pdfium-review.googlesource.com/2826 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
2017-02-22Move JS constant tables to single-byte namesTom Sepez
none are non-ascii characters, so save space. Change-Id: I5e81e8847a2ce4a5ffa3422d2103ffe453036e7c Reviewed-on: https://pdfium-review.googlesource.com/2819 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-02-22Convert JS property tables to single-byte.Tom Sepez
Change-Id: I4daec9e05a63c55caa01402a594c3553073c439e Reviewed-on: https://pdfium-review.googlesource.com/2818 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-02-22Convert native method names to single-byte.Tom Sepez
There are no non-ascii characters, so save space. Change-Id: Ib9efb9386b6fc83bf3bb1810c791aadeeeebc259 Reviewed-on: https://pdfium-review.googlesource.com/2817 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-02-21Avoid some widestring to bytestring conversions in fxjs.Tom Sepez
None of the names have non-ascii characters. Change-Id: I83a52d6276edf2f442fca33221f38f6a53c3ffe3 Reviewed-on: https://pdfium-review.googlesource.com/2816 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-02-16Rename IJS_Context to IJS_EventContext.Tom Sepez
Prevents confusion with v8::Context, which is wrapped by a different IJS_ class. Change-Id: Iff75809e65015c0f810294de1f0d8ecf963150a3 Reviewed-on: https://pdfium-review.googlesource.com/2751 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-02-13Simplify FX_UTF8Encode variants.chromium/3012Tom Sepez
Doing so reveals places where there are needless copies and conversions. Change-Id: I24a868d40aa63836f4167eaf4541964049df7916 Reviewed-on: https://pdfium-review.googlesource.com/2555 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
2017-01-18Tidy FXJS_V8, backfill tests.chromium/2986tsepez
Move checks performed as part of JS_Value's object and array handling back into FXJS, to ease removal of JS_Value in the future. Remove some convenience routines in FXJS for objects, to shrink API to be covered during testing. Change some naming (number => double, string => widestring) to make it clearer when there is a C++ type involved. BUG= Review-Url: https://codereview.chromium.org/2637503002
2017-01-11Cleaning up memory allocation in CXFA_FM2JSContext - IVDan Sinclair
This CL removes the use of FX_Alloc and any remaining new'd CFXJSE_Value objects from CXFA_FM2JSContext and replaces them with unique_ptrs and vectors. Change-Id: I30ba697d65ee326d2faa895c3217bdc407419298 Reviewed-on: https://pdfium-review.googlesource.com/2157 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
2016-11-21Fixup lint flags.Dan Sinclair
The -build/include setting was masking out build/include_what_you_use. This CL restores them, fixes any build errors, and adds NOLINT as needed. As well, the runtime/explicit and runtime/printf flags are aslo enabled and NOLINT'd. lint cleanups Change-Id: Ib013b3eb29c8d0e48cad74c5df9028684130719f Reviewed-on: https://pdfium-review.googlesource.com/2030 Reviewed-by: Tom Sepez <tsepez@chromium.org>
2016-11-03Remove FX_BOOL entirely.tsepez
FX_BOOL was a type just like a regular C++ bool, except that it took 4x the space and frequently was used to hold values besides true or false. Review-Url: https://codereview.chromium.org/2471353002
2016-11-01Reland: Make the CPDFXFA_App non-globalchromium/2907dsinclair
This reverts commit a282c7380f3964de41ea93c9980b12c4513d3473. This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2421603002
2016-10-13Revert of Reland: Make the CPDFXFA_App non-global (patchset #2 id:20001 of ↵dsinclair
https://codereview.chromium.org/2418653003/ ) Reason for revert: https://build.chromium.org/p/client.pdfium/builders/linux_xfa_asan_lsan/builds/117/steps/corpus%20tests/logs/stdio Original issue's description: > Reland: Make the CPDFXFA_App non-global > > This reverts commit b685e6471075bebd26711bc183de3128f54932e3. > > This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. > > BUG=pdfium:623 > > Committed: https://pdfium.googlesource.com/pdfium/+/f3736bca5f874b0889c5906ffbd74a405089f671 TBR=tsepez@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2414883006
2016-10-13Reland: Make the CPDFXFA_App non-globaldsinclair
This reverts commit b685e6471075bebd26711bc183de3128f54932e3. This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2418653003
2016-10-13Revert of Make the CPDFXFA_App non-global (patchset #3 id:80001 of ↵dsinclair
https://codereview.chromium.org/2416753002/ ) Reason for revert: https://build.chromium.org/p/client.pdfium/builders/linux_xfa_asan_lsan/builds/112/steps/embeddertests/logs/stdio msan is sad. Original issue's description: > Make the CPDFXFA_App non-global > > This CL changes CPDFXFA_App from a global object to a child of the > CPDFXFA_Document objects. > > BUG=pdfium:623 > > Committed: https://pdfium.googlesource.com/pdfium/+/abefb79577b32d291d14d7e01a70f6f8cf213bd3 TBR=tsepez@chromium.org,thestig@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2412903004
2016-10-13Make the CPDFXFA_App non-globaldsinclair
This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2416753002
2016-09-29Move fxjs/include to fxjsdsinclair
BUG=pdfium:611 Review-Url: https://codereview.chromium.org/2380713005
2016-09-29Move core/fxcrt/include to core/fxcrtdsinclair
BUG=pdfium:611 Review-Url: https://codereview.chromium.org/2382723003
2016-09-22Simplify memory management for per isolate dataweili
Use smart pointers for FXJS_PerIsolateData owned member variables. Also move creation and deletion of dynamic object map into FXJS_PerIsolateData's constructor and destructor. Overall, the interfaces and memory management should be simpler. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2358343002
2016-09-21Set up isolate in CFXJS_Engine's constructorweili
CFXJS_Engine class should always be constructed with an isolate, except for its subclasses which may need to create an isolate by themselves. Move SetIsolate() function to be protected so that only subclasses can access it. Review-Url: https://codereview.chromium.org/2354353002
2016-09-21Fix leaks related to the usage of JSE runtime dataweili
Per isolate runtime data should be deleted when the associated isolate's destructed. Also, the internal of per isolate runtime data is obscure to the JS engine. So XFA or this class itself has to be in charge of the memory management. Use smart pointer for it so that the resource could be released properly. BUG=pdfium:242 Review-Url: https://codereview.chromium.org/2354923003
2016-09-12Fix leaked value object in NamedPropertySetterCallback()weili
When setting a new value for a V8 object property, the passed along pointer of CFXJSE_Value is only used, but needs to be released by the original owner. Use unique_ptr to have the pointer released automatically. BUG=pdfium:242 Review-Url: https://codereview.chromium.org/2328273004
2016-08-19Fix leaked array buffer allocators of isolatesweili
The array buffer allocators are allocated and owned by pdfium code, they should be deleted properly after the corresponding isolates are disposed. BUG=pdfium:242 Review-Url: https://codereview.chromium.org/2254123004
2016-08-15Push v8::Isolate into CFXJS_Engine classchromium/2831tsepez
Nearly all the "loose" functions in FXJS become methods on the CFJXS_Engine. This is the "missing link" wrt some layering violatons that have been around forever. We can stop passing &m_ variables from CJS_ down into FXJS Initialization as a result. Review-Url: https://codereview.chromium.org/2245863002
2016-08-15Move some v8 objects from CJS back into FXJStsepez
Create a new class to hold these, CFXJS_Engine (could have been called Runtime, but there are too many "Runtimes" already). In a subsequent patch, all the FXJS_*() functions that take an isolate as the first argument can become methods on the engine. CJS_ must still manage the isolates; this happens outside the engine. The IJS_Runtime abstraction moves up to fpdfsdk/javascript; it remains to allow for either a real JS library or a stubb one to be linked (for non-js builds). Review-Url: https://codereview.chromium.org/2241483004
2016-08-11Make FXJS_GetObjectElement return std::vector<CFX_WideString>.chromium/2829chromium/2828tsepez
Analogous to getting the length of JS array, this result should be a C++-side object only. Also rename to FXJS_GetObjectProperty to match JS nomenclature. Review-Url: https://codereview.chromium.org/2242593002
2016-08-05Return v8::Date specialization not v8::Value where possiblechromium/2824chromium/2823chromium/2822chromium/2821tsepez
Also get rid of FXJS_ValueCopy() while we're at it. BUG=pdfium:556 Review-Url: https://codereview.chromium.org/2215093002
2016-07-15Remove type info from CJS_Value, interrogate v8 insteadtsepez
Review-Url: https://codereview.chromium.org/2154503002
2016-07-14Do not try to v8::Object::Clone() any objectstsepez
v8::Object::Clone() is deprecated, and gets us into trouble with some corner cases. Create a new handle to the same object instead. Remove FXJS_NewObject() and FXJS_NewObject2(), and replace with direct assignments. Pass isolate to FXJS_NewNull() while were at it, even though not needed, for consistency with all remaining FXJS_New*() calls. BUG=628106 R=jochen@chromium.org Review-Url: https://codereview.chromium.org/2151023002
2016-07-12Move fpdfsdk/jsapi into fxjs/dsinclair
This CL moves the fpdfsdk/sjapi code info fxjs/. The "fxjs" library is moved from being XFA specific to being compiled if V8 is enabled. The fxjs_v8 files are required when building for XFA (they have XFA defines in them) and are used in CFXJS_RuntimeData. The cfxjse_* files are only added if XFA is also enabled. Review-Url: https://codereview.chromium.org/2144603003