File tree Expand file tree Collapse file tree 3 files changed +12
-22
lines changed Expand file tree Collapse file tree 3 files changed +12
-22
lines changed Original file line number Diff line number Diff line change @@ -13,20 +13,22 @@ if (getenv("SKIP_SLOW_TESTS")) {
1313
1414$ JS = <<< EOT
1515var jsfunc = function() {
16- var text = "abcdefghijklmnopqrstuvwyxz0123456789";
16+ var text = "abcdefghijklmnopqrstuvwyxz0123456789"; // 36 bytes fits 277777 times in 10 MB
1717 var memory = "";
18- for (var i = 0; i < 100; ++i) {
19- for (var j = 0; j < 10000; ++j) {
18+
19+ // this should exceed the memory limit as it tries to generate 500_000 * 36 bytes = 18 MB
20+ for (var i = 0; i < 50; ++i) {
21+ for (var j = 0; j < 10_000; ++j) {
2022 memory += text;
21- }
22- sleep(0);
23+ }
24+ sleep(0);
2325 }
2426};
2527jsfunc;
2628EOT ;
2729
2830$ v8 = new V8Js ();
29- $ v8 ->setMemoryLimit (10000000 );
31+ $ v8 ->setMemoryLimit (10_000_000 );
3032
3133$ func = $ v8 ->executeString ($ JS );
3234var_dump ($ func );
Original file line number Diff line number Diff line change @@ -14,14 +14,8 @@ if (getenv("SKIP_SLOW_TESTS")) {
1414$ JS = <<< EOT
1515var jsfunc = function() {
1616 PHP.imposeMemoryLimit();
17- var text = "abcdefghijklmnopqrstuvwyxz0123456789";
18- var memory = "";
19- for (var i = 0; i < 100; ++i) {
20- for (var j = 0; j < 10000; ++j) {
21- memory += text;
22- }
23- sleep(0);
24- }
17+ // Allocate a single large string to deterministically exceed the limit
18+ var memory = new Array(12 * 1024 * 1024).join("x"); // ~12MB
2519};
2620jsfunc;
2721EOT ;
Original file line number Diff line number Diff line change @@ -11,14 +11,8 @@ if (getenv("SKIP_SLOW_TESTS")) {
1111--FILE--
1212<?php
1313$ JS = <<< EOT
14- var text = "abcdefghijklmnopqrstuvwyxz0123456789";
15- var memory = "";
16- for (var i = 0; i < 100; ++i) {
17- for (var j = 0; j < 10000; ++j) {
18- memory += text;
19- }
20- sleep(0);
21- }
14+ // Allocate a single large string to deterministically exceed the limit
15+ var memory = new Array(12 * 1024 * 1024).join("x"); // ~12 MB
2216EOT ;
2317
2418$ v8 = new V8Js ();
You can’t perform that action at this time.
0 commit comments