dongnanyanhai / php-v8js

A fork of V8Js re-implemented in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  • Memory / time limits
  • Snapshop creating and loading
  • Default global functions var_dump, sleep, exit
  • Default global function print
  • CommonJS / require support
  • setModuleLoader
  • setModuleNormaliser
  • Subclassing V8Js
  • Custom exceptions for V8JsScriptException, V8JsMemoryLimitException and V8JsTimeLimitException
  • Support for V8JsScriptException::getJsLineNumber etc.
  • Support for FLAG_PROPAGATE_PHP_EXCEPTIONS, V8Js::FLAG_FORCE_ARRAY
  • PHP INI settings v8js.flags
  • V8Js::V8_VERSION constant

Not planned compatibility

  • Support for ArrayAccess objects 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

About

A fork of V8Js re-implemented in Rust


Languages

Language:PHP 81.7%Language:Rust 18.1%Language:Dockerfile 0.2%