File tree Expand file tree Collapse file tree 3 files changed +66
-12
lines changed Expand file tree Collapse file tree 3 files changed +66
-12
lines changed Original file line number Diff line number Diff line change @@ -13,20 +13,23 @@ if (getenv("SKIP_SLOW_TESTS")) {
1313
1414$ JS = <<< EOT
1515var jsfunc = function() {
16- var text = "abcdefghijklmnopqrstuvwyxz0123456789";
16+ var text = "abcdefghijklmnopqrstuvwyxz0123456789"; // 36 bytes
1717 var memory = "";
18- for (var i = 0; i < 100; ++i) {
19- for (var j = 0; j < 10000; ++j) {
18+ // should generate 360 MB
19+ for (var i = 0; i < 10_000; ++i) {
20+ for (var j = 0; j < 1000; ++j) {
2021 memory += text;
21- }
22- sleep(0);
22+ }
23+ sleep(0);
2324 }
25+
26+ return memory;
2427};
2528jsfunc;
2629EOT ;
2730
2831$ v8 = new V8Js ();
29- $ v8 ->setMemoryLimit (10000000 );
32+ $ v8 ->setMemoryLimit (10_000_000 );
3033
3134$ func = $ v8 ->executeString ($ JS );
3235var_dump ($ func );
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Test V8::setMemoryLimit() : Memory limit can be set but does not trigger when not exceeded
3+ --SKIPIF--
4+ <?php
5+ require_once (dirname (__FILE__ ) . '/skipif.inc ' );
6+
7+ if (getenv ("SKIP_SLOW_TESTS " )) {
8+ die ("skip slow test " );
9+ }
10+ ?>
11+ --FILE--
12+ <?php
13+
14+ $ JS = <<< EOT
15+ var jsfunc = function() {
16+ var text = "abcdefghijklmnopqrstuvwyxz0123456789"; // 36 bytes
17+ var memory = "";
18+ // should generate ~ 800 kB
19+ for (var i = 0; i < 22; ++i) {
20+ for (var j = 0; j < 1000; ++j) {
21+ memory += text;
22+ }
23+ sleep(0);
24+ }
25+
26+ return memory;
27+ };
28+ jsfunc;
29+ EOT ;
30+
31+ $ v8 = new V8Js ();
32+ $ v8 ->setMemoryLimit (10_000_000 );
33+
34+ $ func = $ v8 ->executeString ($ JS );
35+ var_dump ($ func );
36+
37+ try {
38+ $ func ();
39+ } catch (V8JsMemoryLimitException $ e ) {
40+ print get_class ($ e ); print PHP_EOL ;
41+ print $ e ->getMessage (); print PHP_EOL ;
42+ }
43+ ?>
44+ ===EOF===
45+ --EXPECTF--
46+ object(V8Function)#%d (0) {
47+ }
48+ ===EOF===
Original file line number Diff line number Diff line change @@ -14,22 +14,25 @@ if (getenv("SKIP_SLOW_TESTS")) {
1414$ JS = <<< EOT
1515var jsfunc = function() {
1616 PHP.imposeMemoryLimit();
17- var text = "abcdefghijklmnopqrstuvwyxz0123456789";
17+ var text = "abcdefghijklmnopqrstuvwyxz0123456789"; // 36 bytes
1818 var memory = "";
19- for (var i = 0; i < 100; ++i) {
20- for (var j = 0; j < 10000; ++j) {
19+ // should generate 360 MB
20+ for (var i = 0; i < 10_000; ++i) {
21+ for (var j = 0; j < 1000; ++j) {
2122 memory += text;
22- }
23- sleep(0);
23+ }
24+ sleep(0);
2425 }
26+
27+ return memory;
2528};
2629jsfunc;
2730EOT ;
2831
2932$ v8 = new V8Js ();
3033
3134$ v8 ->imposeMemoryLimit = function () use ($ v8 ) {
32- $ v8 ->setMemoryLimit (10000000 );
35+ $ v8 ->setMemoryLimit (10_000_000 );
3336};
3437
3538$ func = $ v8 ->executeString ($ JS );
You can’t perform that action at this time.
0 commit comments