-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
401 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : String conversion | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
class myv8 extends V8Js | ||
{ | ||
public function throwException(string $message) { | ||
throw new Exception($message); | ||
} | ||
} | ||
|
||
$v8 = new myv8(); | ||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
echo "exception filter called.\n"; | ||
return $ex->getMessage(); | ||
}); | ||
|
||
$v8->executeString(' | ||
try { | ||
PHP.throwException("Oops"); | ||
} | ||
catch (e) { | ||
var_dump(typeof e); // string | ||
var_dump(e); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
exception filter called. | ||
string(6) "string" | ||
string(4) "Oops" | ||
===EOF=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : Filter handling on exception in setModuleLoader | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
$v8 = new V8Js(); | ||
$v8->setModuleLoader(function ($path) { | ||
throw new Error('moep'); | ||
}); | ||
|
||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
echo "exception filter called.\n"; | ||
return $ex->getMessage(); | ||
}); | ||
|
||
$v8->executeString(' | ||
try { | ||
require("file"); | ||
} catch(e) { | ||
var_dump(e); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
|
||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
exception filter called. | ||
string(4) "moep" | ||
===EOF=== | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : Filter handling on exception in setModuleNormaliser | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
$v8 = new V8Js(); | ||
$v8->setModuleNormaliser(function ($path) { | ||
throw new Error('blarg'); | ||
}); | ||
$v8->setModuleLoader(function ($path) { | ||
throw new Error('moep'); | ||
}); | ||
|
||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
echo "exception filter called.\n"; | ||
return $ex->getMessage(); | ||
}); | ||
|
||
$v8->executeString(' | ||
try { | ||
require("file"); | ||
} catch(e) { | ||
var_dump(e); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
|
||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
exception filter called. | ||
string(5) "blarg" | ||
===EOF=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : Filter handling on exception in converter | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
class myv8 extends V8Js | ||
{ | ||
public function throwException(string $message) { | ||
throw new Exception($message); | ||
} | ||
} | ||
|
||
$v8 = new myv8(); | ||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
throw new Exception('moep'); | ||
}); | ||
|
||
try { | ||
$v8->executeString(' | ||
try { | ||
PHP.throwException("Oops"); | ||
print("done\\n"); | ||
} | ||
catch (e) { | ||
print("caught\\n"); | ||
var_dump(e); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
} catch (Exception $ex) { | ||
echo "caught in php: " . $ex->getMessage() . PHP_EOL; | ||
} | ||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
caught in php: moep | ||
===EOF=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : Uninstall filter on NULL | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
class myv8 extends V8Js | ||
{ | ||
public function throwException(string $message) { | ||
throw new Exception($message); | ||
} | ||
} | ||
|
||
$v8 = new myv8(); | ||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
echo "exception filter called.\n"; | ||
return "moep"; | ||
}); | ||
|
||
$v8->executeString(' | ||
try { | ||
PHP.throwException("Oops"); | ||
} | ||
catch (e) { | ||
var_dump(e); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
|
||
$v8->setExceptionFilter(null); | ||
|
||
try { | ||
$v8->executeString(' | ||
try { | ||
PHP.throwException("Oops"); | ||
print("done\\n"); | ||
} | ||
catch (e) { | ||
print("caught\\n"); | ||
var_dump(e.getMessage()); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
} catch (Exception $ex) { | ||
echo "caught in php: " . $ex->getMessage() . PHP_EOL; | ||
} | ||
|
||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
exception filter called. | ||
string(4) "moep" | ||
caught | ||
string(4) "Oops" | ||
===EOF=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : re-throw exception in exception filter | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
class myv8 extends V8Js | ||
{ | ||
public function throwException(string $message) { | ||
throw new Exception($message); | ||
} | ||
} | ||
|
||
$v8 = new myv8(); | ||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
// re-throw exception so it is not forwarded | ||
throw $ex; | ||
}); | ||
|
||
try { | ||
$v8->executeString(' | ||
try { | ||
PHP.throwException("Oops"); | ||
print("done\\n"); | ||
} | ||
catch (e) { | ||
print("caught\\n"); | ||
var_dump(e); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
} catch (Exception $ex) { | ||
echo "caught in php: " . $ex->getMessage() . PHP_EOL; | ||
} | ||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
caught in php: Oops | ||
===EOF=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--TEST-- | ||
Test V8::setExceptionFilter() : Simple test | ||
--SKIPIF-- | ||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
class myv8 extends V8Js | ||
{ | ||
public function throwException(string $message) { | ||
throw new Exception($message); | ||
} | ||
} | ||
|
||
class ExceptionFilter { | ||
private $ex; | ||
|
||
public function __construct(Throwable $ex) { | ||
echo "ExceptionFilter::__construct called!\n"; | ||
var_dump($ex->getMessage()); | ||
|
||
$this->ex = $ex; | ||
} | ||
|
||
public function getMessage() { | ||
echo "getMessage called\n"; | ||
return $this->ex->getMessage(); | ||
} | ||
} | ||
|
||
$v8 = new myv8(); | ||
$v8->setExceptionFilter(function (Throwable $ex) { | ||
echo "exception filter called.\n"; | ||
return new ExceptionFilter($ex); | ||
}); | ||
|
||
$v8->executeString(' | ||
try { | ||
PHP.throwException("Oops"); | ||
} | ||
catch (e) { | ||
var_dump(e.getMessage()); // calls ExceptionFilter::getMessage | ||
var_dump(typeof e.getTrace); | ||
} | ||
', null, V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS); | ||
?> | ||
===EOF=== | ||
--EXPECT-- | ||
exception filter called. | ||
ExceptionFilter::__construct called! | ||
string(4) "Oops" | ||
getMessage called | ||
string(4) "Oops" | ||
string(9) "undefined" | ||
===EOF=== | ||
|
Oops, something went wrong.