This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pinepain/fix_templates_recursion
Fix templates recursion
- Loading branch information
Showing
15 changed files
with
260 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ provides an accurate native V8 C++ API implementation available from PHP. | |
- multiple isolates and contexts at the same time; | ||
- it works; | ||
|
||
With this extension almost all what native V8 C++ API provides can be used. It provides a way to pass php scalars, | ||
With this extension almost all that native V8 C++ API provides can be used. It provides a way to pass php scalars, | ||
objects and function to V8 runtime and specify interaction with passed values (objects and functions only, as scalars | ||
become js scalars too). While specific functionality will be done in PHP userland rather then in C/C++ this extension, | ||
it let get into V8 hacking faster, reduces time costs and let have more maintainable solution. And it doesn't make any | ||
assumptions for you so you are the boss, it does exactly what you ask for. | ||
it lets you get into V8 hacking faster, reduces time costs and gives you a more maintainable solution. And it doesn't | ||
make any assumptions for you, so you stay in control, it does exactly what you ask it to do. | ||
|
||
With php-v8 you can even implement nodejs in PHP. Not sure whether anyone should/will do this anyway, but it's doable. | ||
|
||
|
@@ -55,8 +55,8 @@ $result = $script->Run($context); | |
echo $result->ToString($context)->Value(), PHP_EOL; | ||
``` | ||
|
||
which will output `Hello, World!`. See how it shorter and readable from that C++ version? And it also doesn't limit you | ||
from V8 API utilizing to implement more amazing stuff. | ||
which will output `Hello, World!`. See how it's shorter and readable from that C++ version? And it also doesn't limit | ||
you from V8 API utilizing to implement more amazing stuff. | ||
|
||
|
||
## Installation | ||
|
@@ -103,25 +103,6 @@ $ sudo make install | |
- To track memory usage you may want to use `smem`, `pmem` and even `lsof` to see what shared object are loaded | ||
and `free` to display free and used memory in the system. | ||
|
||
|
||
## Edge cases: | ||
|
||
### Templates recursion: | ||
|
||
When you set property on any `Template` (`ObjectTemplate` or `FunctionTemplate`) it shouldn't lead to recursion during | ||
template instantiation while it leads to segfault and for now there are no reasonable way to avoid this on extension | ||
level (probably, some wrapper around `ObjectTemplate` and `FunctionTemplate` will solve this. | ||
|
||
Known issues demo: | ||
|
||
```php | ||
$isolate = new V8\Isolate(); | ||
|
||
$template = new V8\ObjectTemplate($isolate); | ||
|
||
$template->Set('self', $template); // leads to segfault | ||
``` | ||
|
||
## License | ||
|
||
Copyright (c) 2015-2016 Bogdan Padalko <[email protected]> | ||
|
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
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,39 @@ | ||
--TEST-- | ||
V8\ObjectTemplate - recursive 2 | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("v8")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
|
||
use V8\Exceptions\GenericException; | ||
|
||
/** @var \Phpv8Testsuite $helper */ | ||
$helper = require '.testsuite.php'; | ||
|
||
require '.v8-helpers.php'; | ||
$v8_helper = new PhpV8Helpers($helper); | ||
|
||
// Tests: | ||
|
||
$isolate = new \V8\Isolate(); | ||
|
||
$template1 = new \V8\ObjectTemplate($isolate); | ||
$template2 = new \V8\ObjectTemplate($isolate); | ||
$template3 = new \V8\ObjectTemplate($isolate); | ||
|
||
$template1->Set(new \V8\StringValue($isolate, 'that2'), $template2); | ||
$template2->Set(new \V8\StringValue($isolate, 'that3'), $template3); | ||
|
||
try { | ||
$template3->Set(new \V8\StringValue($isolate, 'that1'), $template2); | ||
} catch (GenericException $e) { | ||
$helper->exception_export($e); | ||
} | ||
|
||
|
||
$context = new \V8\Context($isolate); | ||
$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $template1->NewInstance($context)); | ||
|
||
?> | ||
--EXPECT-- | ||
V8\Exceptions\GenericException: Can't set: recursion detected |
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
Oops, something went wrong.