Skip to content

joehoyle/php-v8js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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