This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathFunctionObject_weakness_multiple.phpt
82 lines (62 loc) · 2.63 KB
/
FunctionObject_weakness_multiple.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--TEST--
V8\FunctionObject (weakness, multiple time)
--SKIPIF--
<?php if (!extension_loaded("v8")) print "skip"; ?>
--FILE--
<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';
require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);
require '.tracking_dtors.php';
$isolate = new v8Tests\TrackingDtors\Isolate();
$global_template = new V8\ObjectTemplate($isolate);
$context = new v8Tests\TrackingDtors\Context($isolate, $global_template);
$global_template = null;
$func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) {
echo 'Should output Hello World string', PHP_EOL;
});
$func->setAccessor($context, new \V8\StringValue($isolate, 'nonexistent'), function () { echo 'get nonexistent 1', PHP_EOL; } );
$context->globalObject()->set($context, new \V8\StringValue($isolate, 'print'), $func);
$func = null;
$v8_helper->CompileRun($context, 'print("test"); print.nonexistent; ');
$fnc1 = $context->globalObject()->get($context, new \V8\StringValue($isolate, 'print'));
/** @var $fnc1 \V8\FunctionObject */
$fnc1->setAccessor($context, new \V8\StringValue($isolate, 'nonexistent'), function () { echo 'get nonexistent 2', PHP_EOL; } );
$v8_helper->CompileRun($context, 'print("test"); print.nonexistent; ');
$fnc1 = null;
$fnc2 = $context->globalObject()->get($context, new \V8\StringValue($isolate, 'print'));
/** @var $fnc1 \V8\FunctionObject */
$fnc2->setAccessor($context, new \V8\StringValue($isolate, 'nonexistent'), function () { echo 'get nonexistent 3', PHP_EOL; } );
$v8_helper->CompileRun($context, 'print("test"); print.nonexistent; ');
$fnc2 = null;
echo 'Persistent should be removed', PHP_EOL;
$isolate->lowMemoryNotification();
// Here newly create object internally linked to specific callback and persistent, but as it has no own callback, free'ing
// it shouldn't affect functionality
$fnc3 = $context->globalObject()->get($context, new \V8\StringValue($isolate, 'print'));
$v8_helper->CompileRun($context, 'print("test"); print.nonexistent;');
$fnc3 = null;
$v8_helper->CompileRun($context, 'print("test"); print.nonexistent;');
$context = null;
echo 'Context should be removed', PHP_EOL;
$isolate->lowMemoryNotification();
echo 'We are done for now', PHP_EOL;
?>
--EXPECT--
FunctionObject dies now!
Should output Hello World string
get nonexistent 1
Should output Hello World string
get nonexistent 2
Should output Hello World string
get nonexistent 3
Persistent should be removed
Should output Hello World string
get nonexistent 3
Should output Hello World string
get nonexistent 3
Context dies now!
Context should be removed
We are done for now
Isolate dies now!