|
| 1 | +--TEST-- |
| 2 | +V8\FunctionTemplate - callback weakness |
| 3 | +--SKIPIF-- |
| 4 | +<?php if (!extension_loaded("v8")) { |
| 5 | + print "skip"; |
| 6 | +} ?> |
| 7 | +--FILE-- |
| 8 | +<?php |
| 9 | + |
| 10 | +/** @var \Phpv8Testsuite $helper */ |
| 11 | +$helper = require '.testsuite.php'; |
| 12 | + |
| 13 | +require '.v8-helpers.php'; |
| 14 | +$v8_helper = new PhpV8Helpers($helper); |
| 15 | + |
| 16 | + |
| 17 | +$isolate = new V8\Isolate(); |
| 18 | + |
| 19 | +$f1 = function () {}; |
| 20 | +$f2 = function () {}; |
| 21 | + |
| 22 | +$helper->header('Functions before setting as a callback'); |
| 23 | +debug_zval_dump($f1); |
| 24 | +debug_zval_dump($f2); |
| 25 | + |
| 26 | +$fnc = new \V8\FunctionTemplate($isolate, $f1); |
| 27 | + |
| 28 | +$helper->header('Functions after f1 was set as a callback'); |
| 29 | +debug_zval_dump($f1); |
| 30 | +debug_zval_dump($f2); |
| 31 | + |
| 32 | +$fnc->SetCallHandler($f2); |
| 33 | + |
| 34 | +$helper->header('Functions after f2 was set as a callback'); |
| 35 | +debug_zval_dump($f1); |
| 36 | +debug_zval_dump($f2); |
| 37 | + |
| 38 | +$fnc = null; |
| 39 | +$helper->header('Functions after function template was destroyed'); |
| 40 | + |
| 41 | +debug_zval_dump($f1); |
| 42 | +debug_zval_dump($f2); |
| 43 | + |
| 44 | +$isolate = null; |
| 45 | +//for($i = 0; $i<1000; $i++) { |
| 46 | +// $isolate->LowMemoryNotification(); |
| 47 | +//} |
| 48 | +$helper->header('Functions after isolate was destroyed'); |
| 49 | + |
| 50 | +debug_zval_dump($f1); |
| 51 | +debug_zval_dump($f2); |
| 52 | + |
| 53 | + |
| 54 | +echo 'We are done for now', PHP_EOL; |
| 55 | + |
| 56 | +?> |
| 57 | +--EXPECT-- |
| 58 | +Functions before setting as a callback: |
| 59 | +--------------------------------------- |
| 60 | +object(Closure)#4 (0) refcount(2){ |
| 61 | +} |
| 62 | +object(Closure)#5 (0) refcount(2){ |
| 63 | +} |
| 64 | +Functions after f1 was set as a callback: |
| 65 | +----------------------------------------- |
| 66 | +object(Closure)#4 (0) refcount(3){ |
| 67 | +} |
| 68 | +object(Closure)#5 (0) refcount(2){ |
| 69 | +} |
| 70 | +Functions after f2 was set as a callback: |
| 71 | +----------------------------------------- |
| 72 | +object(Closure)#4 (0) refcount(2){ |
| 73 | +} |
| 74 | +object(Closure)#5 (0) refcount(3){ |
| 75 | +} |
| 76 | +Functions after function template was destroyed: |
| 77 | +------------------------------------------------ |
| 78 | +object(Closure)#4 (0) refcount(2){ |
| 79 | +} |
| 80 | +object(Closure)#5 (0) refcount(3){ |
| 81 | +} |
| 82 | +Functions after isolate was destroyed: |
| 83 | +-------------------------------------- |
| 84 | +object(Closure)#4 (0) refcount(2){ |
| 85 | +} |
| 86 | +object(Closure)#5 (0) refcount(2){ |
| 87 | +} |
| 88 | +We are done for now |
0 commit comments