Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 9b57c93

Browse files
committed
Add test case for v8 string length range error
1 parent c93acbd commit 9b57c93

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
v8\String - RangeError: Invalid string length
3+
--SKIPIF--
4+
<?php if (!extension_loaded("v8")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
/** @var \Phpv8Testsuite $helper */
9+
$helper = require '.testsuite.php';
10+
11+
require '.v8-helpers.php';
12+
$v8_helper = new PhpV8Helpers($helper);
13+
14+
// Tests:
15+
16+
$isolate = new v8\Isolate();
17+
$extensions = [];
18+
$global_template = new v8\ObjectTemplate($isolate);
19+
$global_template->Set(new \v8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \v8\PropertyAttribute::DontDelete);
20+
21+
$context = new v8\Context($isolate, $extensions, $global_template);
22+
23+
24+
$source = '
25+
var str = " ".repeat(1024); // 1kb
26+
var blob = "";
27+
while(true) {
28+
blob += str;
29+
//print(blob.length, "\n");
30+
}
31+
';
32+
$file_name = 'test.js';
33+
34+
$script = new v8\Script($context, new \v8\StringValue($isolate, $source), new \v8\ScriptOrigin($file_name));
35+
36+
$t = microtime(true);
37+
try {
38+
$res = $script->Run();
39+
} catch(\v8\Exceptions\TryCatchException $e) {
40+
$helper->exception_export($e);
41+
}
42+
?>
43+
--EXPECT--
44+
v8\Exceptions\TryCatchException: RangeError: Invalid string length

0 commit comments

Comments
 (0)