php-v8js
php-v8js copied to clipboard
A fork of V8Js re-implemented in Rust
PHP-V8Js
PHP-V8Js is a PHP extension for the V8 JavaScript engine. It is a re-implementation of the fantastic (though unmaintained) V8Js PHP extension.
The extension allows you to execute JavaScript code in a secure sandbox from PHP. The executed code can be restricted using a time limit and/or memory limit. This provides the possibility to execute untrusted code with confidence.
Requirements
- PHP 8.0+
The extension includes builds of libv8, via the v8 crate. This makes installing the extension very simple.
Mapping Rules
| PHP -> JavaScript | JavaScript -> PHP |
|---|---|
| String -> string | string -> String |
| Bool -> bool | bool -> Bool |
| Array (numeric) -> Array | array -> Array |
| Array (string keys) -> Object | Object -> V8Object |
| Int -> Number | Number -> Float |
Todo:
V8Js Compatibility
- [x] Memory / time limits
- [x] Snapshop creating and loading
- [x] Default global functions
var_dump,sleep,exit - [x] Default global function
print - [x] CommonJS /
requiresupport - [x]
setModuleLoader - [ ]
setModuleNormaliser - [ ] Subclassing V8Js
- [x] Custom exceptions for
V8JsScriptException,V8JsMemoryLimitExceptionandV8JsTimeLimitException - [ ] Support for
V8JsScriptException::getJsLineNumberetc. - [ ] Support for
FLAG_PROPAGATE_PHP_EXCEPTIONS,V8Js::FLAG_FORCE_ARRAY - [ ] PHP INI settings
v8js.flags - [x]
V8Js::V8_VERSIONconstant
Not planned compatibility
- Support for
ArrayAccessobjects mapped into JavaScript - PHP INI settings
v8js.use_array_access,v8js.use_date,v8js.icudtl_dat_path V8Js::registerExtension
New features
- [ ] Support for native ES modules
Credits
- Stefan Siegl of course for creating v8js, and the 37 contributors.
- David Cole for creating ext-php-rs and helping me use the library.