summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/jsapi/fxjs_v8.cpp
AgeCommit message (Collapse)Author
2015-11-25CFXJS_ObjDefinition's lifetime must match isolate.chromium/2585chromium/2584chromium/2583chromium/2582chromium/2581chromium/2580chromium/2579chromium/2578chromium/2577chromium/2576Tom Sepez
Introduced at https://codereview.chromium.org/1424933013/ The v8 objects are 1:1 with the context being destroyed in FXJS_ReleaseRuntime, but the CFXJS_ObjDefinitions are still 1:1 with the isolate, so they can't be destroyed until the refcounts hit zero. BUG=561184 R=jochen@chromium.org Review URL: https://codereview.chromium.org/1468423004 .
2015-11-12Remove relative includes.Lei Zhang
That refer to parent directories. R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1434223002 .
2015-11-10Keep "static" objects per-context rather than per isolate.Tom Sepez
Every time we initialize a new v8::Context, we make a new set of pre-existing native objects, and overwrite the v8::Global handles to those in the previous set. Thus, we may be theoretically releasing some v8::Globals early. R=jochen@chromium.org Review URL: https://codereview.chromium.org/1424933013 .
2015-11-09Remove CFX_PtrArray usage in fpdfsdk.Lei Zhang
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1430213002 .
2015-11-06Fix all relative includes to core.Lei Zhang
Do some IWYU to fix build errors due to files that have no #includes but just happened to work previously because the #includes were in the right order. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1407423004 .
2015-11-06Rename CFXJS_PrivateData to CFXJS_PerObjectData.Tom Sepez
Use m_ naming convention for its members. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1424933012 .
2015-11-06Remove FXJS_GetRuntimeTom Sepez
Its pointless to have a function that gets the isolate given a v8::object, since v8 gives us that directly. Also remove some CreationContext() calls, since they are only used to get the isolate, and we can do so directly. R=jochen@chromium.org Review URL: https://codereview.chromium.org/1413733004 .
2015-10-27Fix memory leak in FXJS_ReleaseRuntime.Oliver Chang
Should fix a bunch of JS related memory leaks reported by LSan/DrMemory. R=jochen@chromium.org, thestig@chromium.org, tsepez@chromium.org BUG=pdfium:242 Review URL: https://codereview.chromium.org/1417973009 .
2015-10-09Pass IJS_Runtime, not IJS_Context, to native object constructors.Tom Sepez
This better separates the two IJS_ classes, with the IJS_Context taking on its proper role of describing an event. There's no need for the event details for object creation, so this gets much cleaner. Move some JS error reporting code from CJS_Context to CJS_Runtime. Make InitInstance() and ExitInstance() voids, they always return TRUE and we never check the result anyways. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1389163007 .
2015-10-07Rename IFXJS_Runtime and IFXJS_Context to IJS_.Tom Sepez
Nothing but sed. FXJS is a layer that makes it easier to define objects in V8, but has no knowledge of PDF-specific native objects. It could in theory be used to implement other sets of native objects. JS is the layer that implements PDF-specific native objects on top of FXJS. Therefore, the classes used to interface to JS should be named using IJS_. IFXJS_ is reserved for someday adding better API for FXJS iteslf. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1386173002 .
2015-10-06Remove unused global argument from FXJS_CONSTRUCTOR.Tom Sepez
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1389003003 .
2015-10-06Store object definition ID in each js_class.Tom Sepez
Avoids doing a lookup via FXJS_V8 for something already known in CJS layer. Also: Consolidate repeated code in JS macros. Remove knowledge that Document is global from FXJS layer R=thestig@chromium.org Review URL: https://codereview.chromium.org/1382263002 .
2015-10-04Fix a leak with g_DefaultGlobalObjectTemplate.chromium/2528Lei Zhang
As seen when running FXJSV8Embeddertest.Getters. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1380993003 .
2015-10-04Only call DefineJSObjects() once for the global V8 isolate.Lei Zhang
BUG=539106 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1386823002 .
2015-10-03Refcount external V8 isolate initialization / release.chromium/2527Lei Zhang
BUG=531339 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1377463005 .
2015-10-02Pass v8::Isolate to PDFium at init time.Tom Sepez
Move the external isolate and embedder slot from the IPDF_JSPlatforms struct supplied at the FPDFDOC_InitFormFillEnvironment() call time to arguments to the FPDF_InitLibraryWithConfig() call. This has several benefits: -- Avoids the crash that could happen if multiple FPDFDOC_InitFormFillEnvironmen() calls should happen to be made by an embedder with different slot values. -- Down the road, for XFA, there may be XFA but no FormFill environment. We support both forms for the time being, until the chrome side catches up, at which point we will deprecate the old way. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1367033002 .
2015-10-01Fix static initializer in fxjs_v8.cppTom Sepez
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1372103004 .
2015-09-30Add signatures to FXJS_V8.Tom Sepez
BUG=chromium:529012 R=jochen@chromium.org, krasin@google.com Review URL: https://codereview.chromium.org/1353193004 .
2015-09-28Introduce kPerIsolateDataIndex and tidy JS_Define.hTom Sepez
Follow-up from https://codereview.chromium.org/1366053003/ - use kPerIsolateDataIndex rather than magic constant 1. - make a helper function for common code in JS_Define.h - remove dead prototypes missed in earlier CL. - fxjs_v8 can't include generic fpdfsdk includes (layering). R=jochen@chromium.org Review URL: https://codereview.chromium.org/1367813003 .
2015-09-25Revert "Revert "Merge to master: contention over isolate data slots""Tom Sepez
This reverts commit 3b4382a847b5a7439a3107512dbe54c317108579. The difference between this CL and the one that failed is fxjs_v8.cpp:271. In master, we pass the runtime information as: v8::isolate -> v8::Context -> FXJS Runtime, but in XFA: V8::Isolate -> PerIsolate struct -> FXJS Runtime. The master way is more correct, in that FXJS_Runtime is 1:1 with v8 contexts and many:1 (in theory) with isolates. It looks like the XFA branch missed a patch along the way. I'll do that next. Having made this change, the only data in the per-isolate struct will be the ptr array (on master); it will also include the XFA context (on XFA). I've kept the struct on master for the sake of similarity. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1365733003 .
2015-09-22Revert "Merge to master: contention over isolate data slots"Tom Sepez
Reason for revert: embeddertests failed. This reverts commit 70bc04b16646c92f221c5aa56831b01d6ec7c1ca. TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1358263004 .
2015-09-22Merge to master: contention over isolate data slotsTom Sepez
Work on this was first performed on the XFA branch, since it has additional requirements (FXJSE layer) that needed to be accomodated by the solution. (cherry picked from commit ed7b2b50aa1744e0bc5a60bef12c61fa91d863b7) Original Review URL: https://codereview.chromium.org/1351173002 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1354593004 .
2015-09-17Don't pass null isolates to FXJS_ when we have a real isolate.Tom Sepez
Kill some now unused functions as a result. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1350703003 .
2015-09-16Remove several dead functions from fxjs_v8.{cpp,h}.Tom Sepez
Re-arrange things in the header so function overloads are next to each other, and related things are near each other. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1348693003 .
2015-09-16Fix build broken at 506df426d5d6.Tom Sepez
Move header file includes when usage moved. Windows-only section missing a ")". TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1349783003 .
2015-09-16Ensure functions in FXJS_V8 are prefixed by FXJS_.Tom Sepez
Currently, its hard to tell which functions come from the JS_ layer at fpdfsdk/include/javascript vs. which functions come from the FXJS_V8 layer at fpdfsdk/include/jsapi. Until we take up the task of using namespaces, at least make the prefix consistent. Move objects out of FXJS_V8 that are really part of JS_. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1347833002 .
2015-09-15Refactor fxjs_v8 and add embeddertests for it.Tom Sepez
This forces the layer defined by fxjs_v8.h to be (more) self-contained, so that it can be tested apart from the CJS_* objects (in fpdfsdk/{src,include}/javascript. This implies the array buffer allocator must be part of fxjs_v8. One wrinkle is that we'd like to be able to test an isolate upon which no native objects have been added, so some initialization that would have occurred as part of object definition must be made explicit. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1338073002 .
2015-09-11Fix strings, remove stringify macros, void return types for Consts.h.Tom Sepez
Replace multiple #defines of the same strings with externs. Fix strings mangled by interaction of # and clang-format. Remove macros as possible. Make more JS_ functions void and simplify. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1342433002 .
2015-09-10Remove some abstractions in fxjs_v8.h.Tom Sepez
It's too hard to keep mapping between v8 and fx abstractions; the lack of transparency prevents those skilled in v8 only from working on this code. Apparently, the original intention was to confine v8 types to fpdfsdk/{include,src}/jsapi, but fpdfsdk/{include,src}/javascript is already well-polluted with v8 types. Also remove no-op JS_SetThisObj(). Also remove unused ParserParams() [noticed because it was incorrectly passing handles as pointers]. Also remove cast operator from CJS_Runtime and call GetIsolate() explicitly. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1332973002 .
2015-09-10Fix JS_GetArrayElement to not return an empty handle on successchromium/2507Jochen Eisinger
BUG=chromium:528376 R=ulan@chromium.org, tsepez@chromium.org Review URL: https://codereview.chromium.org/1337433002 .
2015-08-31CJS_Context::compile unusedTom Sepez
This, in turn, allows us to get rid of the DoJob method and its clumsy mode parameter conditional. Add explicit and consts, and remove pointless asserts along the way. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1318543012 .
2015-08-04clang-format all pdfium code.Nico Weber
No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163' | \ xargs ../../buildtools/mac/clang-format -i See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1265503005 .
2015-07-27Revert "FX Bool considered harmful, part 3"Tom Sepez
This reverts commit ff46aaf499edcf153ee2f57c7016587aa96dcfa0. TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1255293002 .
2015-07-27FX Bool considered harmful, part 3Tom Sepez
Try to reland this patch after fixing underlying issues that caused it to be reverted. fx_system.h is the only manual edit. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1258093002 .
2015-07-23Revert "FX_BOOL considered harmful, part 2."Tom Sepez
This reverts commit 320b2313d19869333ed453af546e61a9fc2b81c9. Reason for revert: build failure. TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1255693002 .
2015-07-23FX_BOOL considered harmful, part 2.Tom Sepez
Fully automatic change, execpt for cleanup in fx_system.h R=thestig@chromium.org Review URL: https://codereview.chromium.org/1254703002 .
2015-07-22Remove dead code found by Scythe.Lei Zhang
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1249643003 .
2015-07-16Make v8 embedder data slot configurablechromium/2460chromium/2459chromium/2458Jochen Eisinger
Chrome already uses 0 and 1. BUG=none R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1235303003 .
2015-06-11Remove trailing whitespaces in fpdfsdk.Lei Zhang
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1173343004.
2015-06-10Remove typdefs for pointer types in fx_system.h.Tom Sepez
This involves fixing some multiple variable per line declarations, as the textually-substituted "*" applies only to the first one. This involves moving some consts around following the substitution. This involves replacing some typedefs used as constructors with better code. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1171733003
2015-05-19Replace v8::Handle with v8::Local and v8::Persistent with v8::GlobalJochen Eisinger
those types are just aliases, and we should consistently use the new version R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1138823004
2015-05-17Replace deprecated with non-deprecated V8 APIsJochen Eisinger
In most cases, we just CHECK() that no exception was thrown. Previously, we'd just crash. Ideally, this should all be fixed and the system should cope with those exceptions, but that's beyond this CL. R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1126203010
2015-05-14Use phantom handles instead of weak handlesJochen Eisinger
Phantom handles allow for freeing objects with one pass of GC. However, this means that by the time the callback is invoked, the v8 object already does no longer exist. To avoid accidential access to the dead object, there are now two callbacks, where the first must only reset the handle, and the second does the clean-up work. R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1129253004
2015-05-13Set pointers in internal fields directly instead of wrapping themJochen Eisinger
The internal fields are scanned by the garbage collector, so they can't contain arbitrary data. However, aligned pointers are supported by the V8 GC, so the V8 API allows for setting a pointer directly instead of wrapping it in an External container. Not only is this faster, but it's also required for the new v8::Global API which I'm going to update to in a follow-up patch. R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1139853003
2015-04-23Remove unused nParamNum values from JS method tables.Tom Sepez
The code to validate the number of parameters happens inside each particular method, rather than prior to method dispatch. As such, there's no point in having this number take up space in the table. Add some test to cover at least some of the per-method validations, and update error messages to be more useful. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1084183008
2015-04-17Replace FX_NEW with new, remove tests from fpdfsdkTom Sepez
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1089823004
2015-04-14Kill CFX_Object.Tom Sepez
CFX_Object is a type that implements its own new operators that return NULL on error. There's no need for this given the |new (std::nothrow)| syntax; in fact, the current code can only work if there is no activity in the constructors. This may explain the pervasive lack of constructors and reliance on Init() methods throughout the codebase. The activity takes place in fx_memory.h, where FX_NEW is mapped onto the std::nothrow syntax. The rest is just cleanup. Down the road, we will simply throw and remove all the error-checking paths for new objects. Landing this patch first will at least show a simple path back to the old behaviour without having to re-introduce CFX_Object should someone want to do so in their own fork. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1088733002
2015-04-09Fix reference to timezone variable - removed in VS 2015Bruce Dawson
It turns out that 'timezone' has been deprecated for a while. If deprecation messages are enabled then VS 2013 says this when 'timezone' is referenced: warning C4996: 'timezone': This function or variable may be unsafe. Consider using _get_timezone instead. Sometimes features stay deprecated for decades, but in this case 'timezone' is now gone. R=tsepez@chromium.org BUG=440500 Review URL: https://codereview.chromium.org/1075673002
2015-03-02Return error information from pdfium to JS.Tom Sepez
This implements the previously unimplemented JS_Error() function. Along the way: - fix some IWYU when the include order in global.cpp was perturbed. - remove some uses of JS_ErrorString, to increase transparency. - use vp.IsSetting() in place of !vp.IsGetting() for clarity. - specify an error string on several error return paths. - add an error string for writing readonly properties. - rename an error string constant to reflect the actual message. - replace calls to variadic Format() with a function doing string appends. - remove unused JS_GetClassName() R=thestig@chromium.org Review URL: https://codereview.chromium.org/963193003
2015-01-02Remove g_NaN global variable and its constructor.Bruce Dawson
Doing the type conversion on demand is just as efficient as doing it at startup time, and makes for more efficient startup. Also mark g_nan as const, to reduce .data section size and enforce desired semantics. BUG=441899 R=bo_xu@foxitsoftware.com Review URL: https://codereview.chromium.org/788143009