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

Commit a706a95

Browse files
committed
Add mechanism to escape from js runtime
1 parent 8101fac commit a706a95

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the pinepain/js-sandbox PHP library.
5+
*
6+
* Copyright (c) 2016-2017 Bogdan Padalko <pinepain@gmail.com>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace Pinepain\JsSandbox\Exceptions;
17+
18+
19+
use Throwable;
20+
21+
22+
class EscapableException extends Exception
23+
{
24+
/**
25+
* @var Throwable
26+
*/
27+
private $original;
28+
29+
30+
public function __construct(Throwable $original)
31+
{
32+
$this->original = $original;
33+
}
34+
35+
/**
36+
* @return Throwable
37+
*/
38+
public function getOriginal(): Throwable
39+
{
40+
return $this->original;
41+
}
42+
}

src/Wrappers/CallbackGuards/CallbackGuard.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Pinepain\JsSandbox\Wrappers\CallbackGuards;
1717

1818

19+
use Pinepain\JsSandbox\Exceptions\EscapableException;
1920
use Pinepain\JsSandbox\Exceptions\NativeException;
2021
use Throwable;
2122
use V8\CallbackInfoInterface;
@@ -57,6 +58,8 @@ public function guard(callable $callback): callable
5758
}
5859
} catch (NativeException $e) {
5960
$isolate->throwException($context, ExceptionManager::createError($context, new StringValue($isolate, $e->getMessage())), $e);
61+
} catch (EscapableException $e) {
62+
throw $e->getOriginal();
6063
} catch (Throwable $e) {
6164
// UNEXPECTED
6265
$message = $this->getMessageFromException($e);

0 commit comments

Comments
 (0)