This repository was archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathIsolate_throwException_with_external.phpt
78 lines (57 loc) · 2.75 KB
/
Isolate_throwException_with_external.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
--TEST--
V8\Isolate::throwException() - exception object is still the same
--SKIPIF--
<?php if (!extension_loaded("v8")) print "skip"; ?>
--FILE--
<?php
/** @var \Phpv8Testsuite $helper */
$helper = require '.testsuite.php';
require '.v8-helpers.php';
$v8_helper = new PhpV8Helpers($helper);
$isolate = new \V8\Isolate();
$context = new \V8\Context($isolate);
$v8_helper->injectConsoleLog($context);
$global = $context->globalObject();
try {
// associating external exception with non-object v8 values is not possible
$isolate->throwException($context, new \V8\StringValue($isolate, 'test'), new RuntimeException('test'));
} catch (\V8\Exceptions\ValueException $e) {
$helper->exception_export($e);
}
$v8_exception = \V8\ExceptionManager::createError($context, new \V8\StringValue($isolate, 'test'));
$func_tpl = new \V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use (&$v8_exception) {
$info->getIsolate()->throwException($info->getContext(), $v8_exception, new RuntimeException('test'));
});
$global->set($context, new \V8\StringValue($isolate, 'e'), $func_tpl);
try {
$v8_helper->CompileRun($context, 'e()');
} catch (\V8\Exceptions\TryCatchException $e) {
$helper->exception_export($e);
$helper->assert('Thrown exception object is the same', $e->getTryCatch()->getException(), $v8_exception);
$helper->exception_export($e->getTryCatch()->getExternalException());
}
$v8_helper->CompileRun($context, 'try {e()} catch(e) {}');
try {
// when we catch thrown exception within v8 runtime, we can't un-wire association, so it becomes illegal to reuse
// the same v8 object exception to throw with external exception again
$isolate->throwException($context, $v8_exception, new RuntimeException('test'));
} catch (\V8\Exceptions\ValueException $e) {
$helper->exception_export($e);
}
$v8_exception = \V8\ExceptionManager::createError($context, new \V8\StringValue($isolate, 'test'));
// re-throw the same v8 object after it was propagated through TryCatch mechanism is OK
$isolate->throwException($context, $v8_exception, new RuntimeException('test'));
try {
// re-throw v8 object while it has not been propagated through TryCatch mechanism is NOT OK
$isolate->throwException($context, $v8_exception, new RuntimeException('test'));
} catch (\V8\Exceptions\ValueException $e) {
$helper->exception_export($e);
}
?>
--EXPECT--
V8\Exceptions\ValueException: Unable to associate external exception with non-object value
V8\Exceptions\TryCatchException: Error: test
Thrown exception object is the same: ok
RuntimeException: test
V8\Exceptions\ValueException: Another external exception is already associated with a given value
V8\Exceptions\ValueException: Another external exception is already associated with a given value