mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 23:08:41 +00:00
Make time limit tests pass more safely
This commit is contained in:
parent
b6fb9acc65
commit
0004626015
@ -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);
|
||||
|
@ -7,9 +7,15 @@ 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 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user