0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-11-14 08:18:41 +00:00
Commit Graph

1056 Commits

Author SHA1 Message Date
C. Scott Ananian
1976e35b9a Fix leak in v8 named property setter; clean up v8 named property getter.
zend_update_property does not own the value after the call; we need to
do the deref ourself.  Tweaks to the getter based on a better understanding
of the zend_read_property API.
2013-10-27 12:36:54 -04:00
Patrick Reilly
a730ddeb67 Merge pull request #70 from cscott/travis-fix-3
More memory leak and safety fixes; fix travis configuration.
2013-10-27 04:18:34 -07:00
C. Scott Ananian
99a1d54e9e Travis config update: compile against minimum supported v8 and most recent v8. 2013-10-27 02:49:24 -04:00
C. Scott Ananian
673d178ce7 Travis config update: fix for issue #56.
Test against php 5.3, 5.4, and 5.5 -- which incidentally works around
the 'make test always succeeds' bug in php 5.3 and 5.4
(https://bugs.php.net/bug.php?id=60285).

('make test' may always succeed, but we still test against 5.3 and 5.4 to
ensure that we build correctly w/o errors on these php versions.)
2013-10-27 02:49:24 -04:00
C. Scott Ananian
24257b54af Free php_v8js_accessor_ctx when we are done with it. 2013-10-27 02:49:24 -04:00
C. Scott Ananian
3f77a5a356 Make PHP object accessors typesafe using V8::AccessorSignature.
This ensures that if you copy the accessor to another object you can't
trigger a segfault.
2013-10-27 02:49:24 -04:00
C. Scott Ananian
879d1d54a2 Fix memory leak in zend_read_property; also pass correct scope object. 2013-10-27 02:49:24 -04:00
C. Scott Ananian
1c3a919ae8 Don't leak if PHP constructor is called from JavaScript.
Register the weak reference callback to deref and do memory limit
accounting for wrapped PHP objects created from within JavaScript.
2013-10-27 02:49:23 -04:00
C. Scott Ananian
57348c5f7d Fix double-pop of timer_ctx (and efree from wrong thread).
The timer_ctx was being popped & freed in terminate_execution, from the
timer thread (not the main thread), and then popped again in the main
thread when execution was aborted.  Do all pop/free work in main thread.
Also, remember to pop the timer_ctx when just a memory limit is set.
2013-10-27 02:48:52 -04:00
C. Scott Ananian
dba6322812 Fix memory leak: The get_properties handler owns the returned hashtable. 2013-10-26 23:14:39 -04:00
C. Scott Ananian
b4d560dd52 Fix a bunch of memory leaks.
Found by compiling PHP with --enable-debug.
2013-10-26 23:14:39 -04:00
C. Scott Ananian
7cdcb5f45e Document rules for initialization/cleanup of ZTS globals.
Transfer stesie's comment from the c3512587ac
commit message so that future additions to v8js_globals maintain the
proper ZTS behavior.
2013-10-26 23:14:39 -04:00
Patrick Reilly
ae2ad9967d Merge pull request #69 from stesie/fix-global-zts-init
Initialize v8js_globals manually only if ZTS is enabled.
2013-10-26 18:21:25 -07:00
Patrick Reilly
8a51e0bc81 Merge pull request #67 from stesie/fix-garbage-collection
Fix garbage collection
2013-10-26 18:21:14 -07:00
Stefan Siegl
68a579f3ae Delete global PHP object on shutdown
Deleting the global object implicitly deletes all the properties,
i.e. PHP objects we previously attached to it (and for which we
increased the reference counter).

Since the following idle notifications trigger the weak callbacks,
the references on the PHP objects are finally decreased.
2013-10-27 00:41:47 +02:00
Stefan Siegl
18b129b128 Trigger garbage collection within Isolate::Scope
Before the idle notifications to V8 were sent without a special
Isolate entered, which results in V8 using it's default isolate
(which we don't use at all).  Hence those were pretty useless
anyways (if they were called, which was unlikely).

Besides V8 seems to not trigger the weak object callbacks if
the isolate is destroyed, hence the PHP objects we add-ref'ed
before will leak.

Therefore this removes the previous idle notification logic
and forces garbage collection from the V8Js object destructor.
2013-10-27 00:41:47 +02:00
Stefan Siegl
c3512587ac Initialize v8js_globals manually only if ZTS is enabled.
If ZTS is disabled, the v8js_globals instance is declared right
in the BSS and hence automatically initialized by C++ compiler.
Most of the variables are just zeroed.

If ZTS is enabled however, v8js_globals just points to a freshly
allocated, unitialized piece of memory, hence we need to
initialize all fields on our own.  Likewise on shutdown we have to
run the destructors manually.
2013-10-27 00:29:50 +02:00
Stefan Siegl
5c1c68b045 Merge pull request #68 from stesie/fix-double-free
Don't manually call destructors on v8js_globals.
2013-10-26 14:59:33 -07:00
Stefan Siegl
16934c2254 Don't manually call destructors on v8js_globals.
v8js_globals is declared at the beginning of v8js.cc and hence
it's constructors and destructors are run automatically.
2013-10-26 23:57:49 +02:00
Patrick Reilly
1906a8e6b6 Merge pull request #66 from cscott/mem-leaks
Fix init/shutdown of v8js_globals.
2013-10-26 14:26:34 -07:00
Patrick Reilly
b2a92e5be1 Merge pull request #65 from cscott/zts-fix
ZTS fixes
2013-10-26 14:25:30 -07:00
C. Scott Ananian
39cc821f91 Store tsrm_ls in php_v8js_ctx.
This avoids the need to ever do a (slow) TSRMLS_FETCH().
2013-10-26 02:07:12 -04:00
C. Scott Ananian
011e517cfe Fix ZTS errors in v8js_convert.cc. 2013-10-26 02:07:00 -04:00
C. Scott Ananian
527e636b25 Fix init/shutdown of v8js_globals.
The mutex/map/stack constructor/destructors weren't being properly called.
2013-10-26 02:04:57 -04:00
Patrick Reilly
e2a8186ad6 Merge pull request #63 from cscott/travis-fix
Travis config update: Partial fix for issue #56.
2013-10-25 14:49:43 -07:00
C. Scott Ananian
0948795d36 Travis config update: Partial fix for issue #56. 2013-10-25 17:43:36 -04:00
Patrick Reilly
e73a9434db Merge pull request #62 from cscott/issue-25
Fix property and method calls on PHP native objects.
2013-10-25 14:42:22 -07:00
Patrick Reilly
ed8fd24f69 Merge pull request #61 from cscott/misc-cleanup
A week's worth of cleanup
2013-10-25 14:41:33 -07:00
C. Scott Ananian
303f3f52b5 Refactor template cache into php_v8js_ctx.
Reduce map lookups by adding internal object field pointing to function
template.  Use hidden field to allow easy unwrapping of PHP objects.
2013-10-25 17:40:51 -04:00
C. Scott Ananian
c341511b36 PHP 5.3 compatibility fixes. 2013-10-25 17:40:51 -04:00
C. Scott Ananian
f6a6d1e4b5 Rework JavaScript wrapper for PHP objects.
Use the NamedPropertyHandler feature of v8 to wrap accesses to PHP properties
and methods from JavaScript.  This enables us to support property
set/delete/query.

The `in` and `delete` operators in JavaScript work like the `isset()` and
`unset()` functions in PHP.  In particular, a PHP property with a null
value will not be `in` the JavaScript object. (This holds when enumerating
all properties of an object as well.)

Because JavaScript has a single namespace for both properties and methods,
we allow the use of the `__call` method on a PHP object (even if the
PHP class does not natively define the `__call` magic function) in order
to unambiguously invoke a method.  Similarly, you can prefix a property
name with `$` to unambiguously access the property. (When enumerating all
properties, properties are `$`-prefixed in order to ensure they are not
conflated with method names.)
2013-10-25 16:47:15 -04:00
C. Scott Ananian
0adefa5048 Add a test for issue 25 (native properties) 2013-10-25 16:47:15 -04:00
C. Scott Ananian
44c329b953 Add a test of PHP magic functions. 2013-10-25 16:47:15 -04:00
C. Scott Ananian
52d8946b89 Add isolate parameter to V8JS_* macros.
This avoids unnecessary calls to Isolate::GetCurrent() in the implementation.
By standardizing on the V8JS_SYM and V8JS_STR macros we also standardize on
UTF-8 encoding for v8 strings.
2013-10-25 16:46:07 -04:00
C. Scott Ananian
27a140c9fb Bug fixes for JavaScript var_dump implementation (make it match PHP). 2013-10-25 14:18:56 -04:00
C. Scott Ananian
c725a80674 Handle NULL in global.var_dump(). 2013-10-25 14:18:56 -04:00
C. Scott Ananian
0e1c6ef5e9 Clean up allocation/deallocation of php_v8js_ctx.
Use the constructor and destructor functions (don't just cross our fingers
and hope that zeroing out memory will work).
2013-10-25 14:18:50 -04:00
C. Scott Ananian
49632054a4 Cleanup: remove some warnings when compiled with -Wunused 2013-10-25 14:17:40 -04:00
C. Scott Ananian
abadda147c Don't rethrow outer exception if report_uncaught is false.
This would cause the exception to stick around and the next time JavaScript
is executed, this exception would be (anomalously) thrown.
2013-10-25 14:17:40 -04:00
C. Scott Ananian
2516e76ff8 Unwrap PHP objects when passing them back from JavaScript to PHP. 2013-10-25 14:17:40 -04:00
Patrick Reilly
6de3e901fa Merge pull request #60 from stesie/fix-v8object-rewrap
Don't re-wrap PHP objects from V8 to V8Object
2013-10-22 10:51:56 -07:00
Stefan Siegl
bd9483080d Don't re-wrap PHP objects from V8 to V8Object 2013-10-21 20:00:58 +02:00
Patrick Reilly
0051c77700 Merge pull request #58 from stesie/fix-tsrm
TSRM/ZTS fixes.
2013-10-21 03:21:41 -07:00
Stefan Siegl
61eee4cbd6 TSRM/ZTS fixes. 2013-10-19 23:04:35 +00:00
Patrick Reilly
f31c44e524 Merge pull request #57 from stesie/call-object_properties_init
More fixes on handling of derived V8Js objects and property export
2013-10-18 23:37:43 -07:00
Stefan Siegl
8eb5721c35 Copy default_properties to new object (PHP 5.3) 2013-10-19 02:52:19 +02:00
Stefan Siegl
683ac347c7 Test export of undeclared properties in derived classes 2013-10-19 02:36:19 +02:00
Stefan Siegl
c77cdf4b6f Export initially initialized public properties to V8
Before a property was exported to V8 if it was assigned a value
during normal code execution.  However if the value was assigned
(hard coded) on class level it wasn't exported.
2013-10-19 02:36:19 +02:00
Stefan Siegl
257233be51 Make php_v8js_write_property export only public properties
Before a property would have been exported, even if a derived
class declared it either private or protected.
2013-10-19 02:22:13 +02:00
Stefan Siegl
b888cfce0d Add test on protected & private properties on derived classes 2013-10-19 02:17:10 +02:00