0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-23 00:51:51 +00:00

Make time limit tests pass more safely

This commit is contained in:
Stefan Siegl 2014-12-08 22:43:04 +00:00
parent b6fb9acc65
commit 0004626015
2 changed files with 16 additions and 5 deletions

View File

@ -8,8 +8,12 @@ Test V8::setTimeLimit() : Time limit can be changed
$JS = <<< EOT
var jsfunc = function() {
PHP.incrTimeLimit();
var start = (new Date()).getTime();
var text = "abcdefghijklmnopqrstuvwyxz0123456789";
for (var i = 0; i < 10000000; ++i) {
while ((new Date()).getTime() - start < 150) {
/* pass at least 150ms in the loop so the timer loop has plenty of
* time to trigger. */
var encoded = encodeURI(text);
}
};
@ -17,7 +21,8 @@ jsfunc;
EOT;
$v8 = new V8Js();
$v8->setTimeLimit(10);
/* Set very short time limit, but enough so v8 can start up safely. */
$v8->setTimeLimit(20);
$v8->incrTimeLimit = function() use ($v8) {
$v8->setTimeLimit(100);

View File

@ -7,10 +7,16 @@ Test V8::setTimeLimit() : Time limit can be prolonged
$JS = <<< EOT
var text = "abcdefghijklmnopqrstuvwyxz0123456789";
for (var j = 0; j < 100; ++j) {
/* Spend 20 * >10ms in the loop, i.e. at least 200ms; hence
* it should be killed if prolonging doesn't work. */
for (var j = 0; j < 20; ++j) {
PHP.prolongTimeLimit();
for (var i = 0; i < 3000; ++i) {
var encoded = encodeURI(text);
var start = (new Date()).getTime();
var encoded = encodeURI(text);
while ((new Date()).getTime() - start < 10) {
/* pass about 10ms in the loop, then prolong */
var encoded = encodeURI(text);
}
}
EOT;