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

Commit b85e1ed

Browse files
committed
Cleanup tests
1 parent f660ef7 commit b85e1ed

File tree

65 files changed

+685
-755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+685
-755
lines changed

scripts/replace_expect.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
*/
1414

1515
$tests_dir = realpath(__DIR__ . '/../tests');
16-
$iterator = new GlobIterator($tests_dir . '/*.out', FilesystemIterator::KEY_AS_FILENAME);
16+
17+
18+
if ($argc == 2) {
19+
$mask = str_replace(['tests/', '.phpt', '.diff'], '', $argv[1]);
20+
} else {
21+
$mask = '*';
22+
}
23+
24+
$iterator = new GlobIterator($tests_dir . "/{$mask}.out", FilesystemIterator::KEY_AS_FILENAME);
1725

1826
foreach ($iterator as $item) {
1927
//var_dump($item);

tests/.v8-helpers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function injectConsoleLog(\V8\Context $context) {
8686

8787
$console_obj = $obj_tpl->NewInstance($context);
8888
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'console'), $console_obj);
89+
90+
return $context;
8991
}
9092

9193
/**

tests/004-ICU-Intl_NumberFormat.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ console.log(new Intl.NumberFormat(['ban', 'id']).format(number));
4343
// → 123.456,789
4444
HEREDOC;
4545

46-
(new \V8\Script($context, new \V8\StringValue($isolate, $source)))->Run($context);
46+
$v8_helper->CompileRun($context, $source);
4747

4848
$helper->line();
4949

@@ -66,8 +66,7 @@ console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).form
6666
// → 1,23,000
6767
HEREDOC;
6868

69-
(new \V8\Script($context, new \V8\StringValue($isolate, $source)))->Run($context);
70-
69+
$v8_helper->CompileRun($context, $source)
7170

7271
?>
7372
--EXPECT--

tests/V8ArrayObject.phpt

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ require '.v8-helpers.php';
1212
$v8_helper = new PhpV8Helpers($helper);
1313

1414
$isolate = new \V8\Isolate();
15-
$global_template1 = new V8\ObjectTemplate($isolate);
16-
17-
$global_template1->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete);
18-
$context = new V8\Context($isolate, $global_template1);
15+
$context = new V8\Context($isolate);
16+
$v8_helper->injectConsoleLog($context);
1917

2018
$value = new V8\ArrayObject($context);
2119

@@ -48,18 +46,16 @@ $value->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\StringValue
4846

4947
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'arr'), $value);
5048

51-
$source1 = '
52-
print("typeof arr: ", typeof arr, "\n");
53-
print("arr: ", arr, "\n");
54-
print("arr.length: ", arr.length, "\n");
55-
print("arr[0]: ", arr[0], "\n");
56-
print("arr.test: ", arr.test, "\n");
57-
print("arr.slice(1): ", arr.slice(1), "\n");
49+
$source = '
50+
console.log("typeof arr: ", typeof arr);
51+
console.log("arr: ", arr);
52+
console.log("arr.length: ", arr.length);
53+
console.log("arr[0]: ", arr[0]);
54+
console.log("arr.test: ", arr.test);
55+
console.log("arr.slice(1): ", arr.slice(1));
5856
';
59-
$file_name1 = 'test.js';
6057

61-
$script1 = new V8\Script($context, new \V8\StringValue($isolate, $source1), new \V8\ScriptOrigin($file_name1));
62-
$res1 = $script1->Run($context);
58+
$v8_helper->CompileRun($context, $source);
6359

6460
?>
6561
--EXPECT--
@@ -80,7 +76,7 @@ object(V8\ArrayObject)#6 (2) {
8076
bool(false)
8177
}
8278
["context":"V8\ObjectValue":private]=>
83-
object(V8\Context)#5 (1) {
79+
object(V8\Context)#4 (1) {
8480
["isolate":"V8\Context":private]=>
8581
object(V8\Isolate)#3 (5) {
8682
["snapshot":"V8\Isolate":private]=>
@@ -166,7 +162,7 @@ V8\ArrayObject(V8\Value)->IsProxy(): bool(false)
166162
Converters:
167163
-----------
168164
V8\ArrayObject(V8\Value)->ToBoolean():
169-
object(V8\BooleanValue)#119 (1) {
165+
object(V8\BooleanValue)#118 (1) {
170166
["isolate":"V8\Value":private]=>
171167
object(V8\Isolate)#3 (5) {
172168
["snapshot":"V8\Isolate":private]=>
@@ -182,7 +178,7 @@ V8\ArrayObject(V8\Value)->ToBoolean():
182178
}
183179
}
184180
V8\ArrayObject(V8\Value)->ToNumber():
185-
object(V8\Int32Value)#119 (1) {
181+
object(V8\Int32Value)#118 (1) {
186182
["isolate":"V8\Value":private]=>
187183
object(V8\Isolate)#3 (5) {
188184
["snapshot":"V8\Isolate":private]=>
@@ -198,7 +194,7 @@ V8\ArrayObject(V8\Value)->ToNumber():
198194
}
199195
}
200196
V8\ArrayObject(V8\Value)->ToString():
201-
object(V8\StringValue)#119 (1) {
197+
object(V8\StringValue)#118 (1) {
202198
["isolate":"V8\Value":private]=>
203199
object(V8\Isolate)#3 (5) {
204200
["snapshot":"V8\Isolate":private]=>
@@ -214,7 +210,7 @@ V8\ArrayObject(V8\Value)->ToString():
214210
}
215211
}
216212
V8\ArrayObject(V8\Value)->ToDetailString():
217-
object(V8\StringValue)#119 (1) {
213+
object(V8\StringValue)#118 (1) {
218214
["isolate":"V8\Value":private]=>
219215
object(V8\Isolate)#3 (5) {
220216
["snapshot":"V8\Isolate":private]=>
@@ -245,7 +241,7 @@ V8\ArrayObject(V8\Value)->ToObject():
245241
bool(false)
246242
}
247243
["context":"V8\ObjectValue":private]=>
248-
object(V8\Context)#5 (1) {
244+
object(V8\Context)#4 (1) {
249245
["isolate":"V8\Context":private]=>
250246
object(V8\Isolate)#3 (5) {
251247
["snapshot":"V8\Isolate":private]=>
@@ -262,7 +258,7 @@ V8\ArrayObject(V8\Value)->ToObject():
262258
}
263259
}
264260
V8\ArrayObject(V8\Value)->ToInteger():
265-
object(V8\Int32Value)#119 (1) {
261+
object(V8\Int32Value)#118 (1) {
266262
["isolate":"V8\Value":private]=>
267263
object(V8\Isolate)#3 (5) {
268264
["snapshot":"V8\Isolate":private]=>
@@ -278,7 +274,7 @@ V8\ArrayObject(V8\Value)->ToInteger():
278274
}
279275
}
280276
V8\ArrayObject(V8\Value)->ToUint32():
281-
object(V8\Int32Value)#119 (1) {
277+
object(V8\Int32Value)#118 (1) {
282278
["isolate":"V8\Value":private]=>
283279
object(V8\Isolate)#3 (5) {
284280
["snapshot":"V8\Isolate":private]=>
@@ -294,7 +290,7 @@ V8\ArrayObject(V8\Value)->ToUint32():
294290
}
295291
}
296292
V8\ArrayObject(V8\Value)->ToInt32():
297-
object(V8\Int32Value)#119 (1) {
293+
object(V8\Int32Value)#118 (1) {
298294
["isolate":"V8\Value":private]=>
299295
object(V8\Isolate)#3 (5) {
300296
["snapshot":"V8\Isolate":private]=>

tests/V8ArrayObject_Length.phpt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,22 @@ V8\ArrayObject::Length
77

88
/** @var \Phpv8Testsuite $helper */
99
$helper = require '.testsuite.php';
10+
require '.v8-helpers.php';
11+
$v8_helper = new PhpV8Helpers($helper);
1012

11-
$isolate1 = new \V8\Isolate();
12-
$global_template1 = new V8\ObjectTemplate($isolate1);
13+
$isolate = new \V8\Isolate();
14+
$context = new V8\Context($isolate);
1315

14-
$context1 = new V8\Context($isolate1, $global_template1);
16+
$res = $v8_helper->CompileRun($context, '[1,2,3]');
1517

16-
$source1 = '
17-
[1,2,3]
18-
';
19-
$file_name1 = 'test.js';
18+
echo $res->Length(), PHP_EOL;
2019

21-
$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
22-
$res1 = $script1->Run($context1);
2320

24-
echo $res1->Length(), PHP_EOL;
25-
26-
27-
$arr = new \V8\ArrayObject($context1, 5);
21+
$arr = new \V8\ArrayObject($context, 5);
2822
echo $arr->Length(), PHP_EOL;
2923

3024
for ($i =0; $i < 7; $i++) {
31-
$arr->Set($context1, new \V8\Uint32Value($isolate1, $i), new \V8\StringValue($isolate1, 'test-'.$i));
25+
$arr->Set($context, new \V8\Uint32Value($isolate, $i), new \V8\StringValue($isolate, 'test-'.$i));
3226
}
3327

3428
echo $arr->Length(), PHP_EOL;

tests/V8BooleanObject.phpt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@ $helper = require '.testsuite.php';
1111
require '.v8-helpers.php';
1212
$v8_helper = new PhpV8Helpers($helper);
1313

14-
$isolate1 = new \V8\Isolate();
15-
$global_template1 = new V8\ObjectTemplate($isolate1);
14+
$isolate = new \V8\Isolate();
15+
$context = new V8\Context($isolate);
16+
$v8_helper->injectConsoleLog($context);
1617

17-
// TODO: fix it, this cause segfault due to FunctionTemplate object destruction and all it internal structures cleanup
18-
//$global_template1->Set('print', $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete);
19-
$print_func_tpl = $v8_helper->getPrintFunctionTemplate($isolate1);
20-
$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete);
21-
22-
$context1 = new V8\Context($isolate1, $global_template1);
23-
24-
$value = new V8\BooleanObject($context1, true);
18+
$value = new V8\BooleanObject($context, true);
2519

2620
$helper->header('Object representation');
2721
$helper->dump($value);
@@ -37,27 +31,25 @@ $helper->space();
3731

3832
$v8_helper->run_checks($value, 'Checkers');
3933

40-
$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value);
34+
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value);
4135

42-
$source1 = '
43-
print("val: ", val, "\n");
44-
print("typeof val: ", typeof val, "\n");
36+
$source = '
37+
console.log("val: ", val);
38+
console.log("typeof val: ", typeof val);
4539
4640
new Boolean(false);
4741
';
48-
$file_name1 = 'test.js';
4942

50-
$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
51-
$res1 = $script1->Run($context1);
43+
$res = $v8_helper->CompileRun($context, $source);
5244
$helper->space();
5345

54-
$v8_helper->run_checks($res1, 'Checkers on boxed from script');
46+
$v8_helper->run_checks($res, 'Checkers on boxed from script');
5547

5648
?>
5749
--EXPECT--
5850
Object representation:
5951
----------------------
60-
object(V8\BooleanObject)#8 (2) {
52+
object(V8\BooleanObject)#6 (2) {
6153
["isolate":"V8\Value":private]=>
6254
object(V8\Isolate)#3 (5) {
6355
["snapshot":"V8\Isolate":private]=>
@@ -72,7 +64,7 @@ object(V8\BooleanObject)#8 (2) {
7264
bool(false)
7365
}
7466
["context":"V8\ObjectValue":private]=>
75-
object(V8\Context)#7 (1) {
67+
object(V8\Context)#4 (1) {
7668
["isolate":"V8\Context":private]=>
7769
object(V8\Isolate)#3 (5) {
7870
["snapshot":"V8\Isolate":private]=>

tests/V8Context.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ $helper = require '.testsuite.php';
1111
require '.v8-helpers.php';
1212
$v8_helper = new PhpV8Helpers($helper);
1313

14-
$isolate1 = new \V8\Isolate();
14+
$isolate = new \V8\Isolate();
1515

16-
$context = new \V8\Context($isolate1);
16+
$context = new \V8\Context($isolate);
1717

1818
$helper->method_matches_instanceof($context, 'GlobalObject', \V8\ObjectValue::class);
1919

@@ -33,7 +33,7 @@ $helper->assert('Code generation is not allowed', $context->IsCodeGenerationFrom
3333
$helper->method_matches_with_output($context, 'IsCodeGenerationFromStringsAllowed', false);
3434
$res = $v8_helper->CompileTryRun($context, 'eval("1+1")');
3535

36-
$context->SetErrorMessageForCodeGenerationFromStrings(new \V8\StringValue($isolate1, 'Whoa! Nope. No eval this time, sorry.'));
36+
$context->SetErrorMessageForCodeGenerationFromStrings(new \V8\StringValue($isolate, 'Whoa! Nope. No eval this time, sorry.'));
3737
$res = $v8_helper->CompileTryRun($context, 'eval("2+2")');
3838

3939

tests/V8Context_GlobalObject.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ $v8_helper = new PhpV8Helpers($helper);
1414

1515
require '.tracking_dtors.php';
1616

17-
$isolate1 = new \V8\Isolate();
18-
$context = new \V8\Context($isolate1);
17+
$isolate = new \V8\Isolate();
18+
$context = new \V8\Context($isolate);
1919

2020
$helper->method_matches_instanceof($context, 'GlobalObject', \V8\ObjectValue::class);
2121

@@ -29,7 +29,7 @@ $helper->assert('Global object on repeatable calls holds extra props', $global1-
2929

3030
$context->DetachGlobal();
3131

32-
$context2 = new \V8\Context($isolate1, null, $global2);
32+
$context2 = new \V8\Context($isolate, null, $global2);
3333
$helper->method_matches_instanceof($context2, 'GlobalObject', \V8\ObjectValue::class);
3434

3535
echo 'Global object passed from one context to another is ', ($global1 === $global2 ? 'the same' : 'not the same'), PHP_EOL;

tests/V8Context_SetSecurityToken.phpt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,60 @@ require '.v8-helpers.php';
1111
$v8_helper = new PhpV8Helpers($helper);
1212

1313

14-
$isolate1 = new \V8\Isolate();
14+
$isolate = new \V8\Isolate();
1515

16-
$context = new \V8\Context($isolate1);
16+
$context = new \V8\Context($isolate);
1717
$v8_helper->injectConsoleLog($context);
1818

19-
$other = new \V8\Context($isolate1);
19+
$other = new \V8\Context($isolate);
2020
$v8_helper->injectConsoleLog($other);
2121

2222
$obj_own = new \V8\ObjectValue($context);
23-
$obj_own->Set($context, new \V8\StringValue($isolate1, 'test'), new \V8\StringValue($isolate1, 'own'));
23+
$obj_own->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\StringValue($isolate, 'own'));
2424

2525
$obj_other = new \V8\ObjectValue($context);
26-
$obj_other->Set($context, new \V8\StringValue($isolate1, 'test'), new \V8\StringValue($isolate1, 'other'));
26+
$obj_other->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\StringValue($isolate, 'other'));
2727

2828

2929
try {
30-
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate1, 'own'), $obj_own);
31-
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate1, 'other'), $obj_other);
30+
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own);
31+
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other);
3232
$helper->assert('There is no cross-context access by default', false);
3333
} catch (\V8\Exceptions\TryCatchException $e) {
3434
$helper->exception_export($e);
3535
}
3636

37-
$context->SetSecurityToken(new \V8\StringValue($isolate1, 'secret 1'));
38-
$other->SetSecurityToken(new \V8\StringValue($isolate1, 'secret 2'));
37+
$context->SetSecurityToken(new \V8\StringValue($isolate, 'secret 1'));
38+
$other->SetSecurityToken(new \V8\StringValue($isolate, 'secret 2'));
3939

4040
try {
41-
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate1, 'own'), $obj_own);
42-
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate1, 'other'), $obj_other);
41+
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own);
42+
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other);
4343
$helper->assert('Different security tokens should not grant cross-context access', false);
4444
} catch (\V8\Exceptions\TryCatchException $e) {
4545
$helper->exception_export($e);
4646
}
4747

4848

49-
$context->SetSecurityToken(new \V8\StringValue($isolate1, 'secret'));
50-
$other->SetSecurityToken(new \V8\StringValue($isolate1, 'secret'));
49+
$context->SetSecurityToken(new \V8\StringValue($isolate, 'secret'));
50+
$other->SetSecurityToken(new \V8\StringValue($isolate, 'secret'));
5151

5252
try {
53-
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate1, 'own'), $obj_own);
54-
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate1, 'other'), $obj_other);
53+
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own);
54+
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other);
5555
$helper->assert('Different security tokens with the same value should not grant cross-context access', false);
5656
} catch (\V8\Exceptions\TryCatchException $e) {
5757
$helper->exception_export($e);
5858
}
5959

6060

61-
$secret = new \V8\StringValue($isolate1, 'secret');
61+
$secret = new \V8\StringValue($isolate, 'secret');
6262

6363
$context->SetSecurityToken($secret);
6464
$other->SetSecurityToken($secret);
6565

66-
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate1, 'own'), $obj_own);
67-
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate1, 'other'), $obj_other);
66+
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own);
67+
$context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other);
6868

6969
$helper->line();
7070

0 commit comments

Comments
 (0)