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 pathIsolate_limit_memory_nested.phpt
100 lines (74 loc) · 2.43 KB
/
Isolate_limit_memory_nested.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
--TEST--
V8\Isolate - nested memory limit exceptions
--SKIPIF--
<?php if (!extension_loaded("v8")) print "skip"; ?>
--FILE--
<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';
require '.tracking_dtors.php';
require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);
// Tests:
$isolate = new V8\Isolate();
$context = new V8\Context($isolate);
$v8_helper->injectConsoleLog($context);
$func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use (&$helper) {
if (!$info->arguments()) {
$isolate = $info->getIsolate();
$source = '
var str = " ".repeat(1024); // 1kb
var blob = [];
while(true) {
blob.push(str);
//console.log(blob.length);
}
';
$script = new V8\Script($info->getContext(), new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin('wait_for_termination.js'));
try {
$script->run($info->getContext());
} catch (\V8\Exceptions\MemoryLimitException $e) {
$helper->exception_export($e);
echo 'wait loop terminated', PHP_EOL;
$helper->line();
}
return;
}
$fnc= $info->arguments()[0];
try {
$fnc->call($info->getContext(), $fnc);
} catch (\V8\Exceptions\MemoryLimitException $e) {
$helper->exception_export($e);
echo 'function call terminated', PHP_EOL;
$helper->line();
}
});
$func->setName(new \V8\StringValue($isolate, 'custom_name'));
$context->globalObject()->set($context, new \V8\StringValue($isolate, 'test'), $func);
$source = 'test(test); delete print; "Script done"';
$file_name = 'test.js';
$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name));
$isolate->setMemoryLimit(1024 * 1024 * 10);
$helper->dump($isolate);
$helper->line();
$t = microtime(true);
try {
$script->run($context);
} catch(\V8\Exceptions\MemoryLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
}
$helper->line();
$helper->dump($isolate);
?>
--EXPECT--
object(V8\Isolate)#3 (0) {
}
V8\Exceptions\MemoryLimitException: Memory limit exceeded
wait loop terminated
V8\Exceptions\MemoryLimitException: Memory limit exceeded
function call terminated
V8\Exceptions\MemoryLimitException: Memory limit exceeded
script execution terminated
object(V8\Isolate)#3 (0) {
}