diff --git a/CMakeLists.txt b/CMakeLists.txt index 9de91a0..ceb42c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ project(php_v8) # NOTE: This CMake file is just for syntax highlighting in CLion -include_directories(/usr/local/opt/v8@5.9/include) -include_directories(/usr/local/opt/v8@5.9/include/libplatform) +include_directories(/usr/local/opt/v8@6.0/include) +include_directories(/usr/local/opt/v8@6.0/include/libplatform) include_directories(/usr/local/include/php) include_directories(/usr/local/include/php/TSRM) diff --git a/config.m4 b/config.m4 index c40fb57..c23dc92 100644 --- a/config.m4 +++ b/config.m4 @@ -149,6 +149,7 @@ if test "$PHP_V8" != "no"; then PHP_NEW_EXTENSION(v8, [ \ v8.cc \ src/php_v8_a.cc \ + src/php_v8_enums.cc \ src/php_v8_exception.cc \ src/php_v8_ext_mem_interface.cc \ src/php_v8_try_catch.cc \ @@ -169,7 +170,6 @@ if test "$PHP_V8" != "no"; then src/php_v8_script.cc \ src/php_v8_unbound_script.cc \ src/php_v8_cached_data.cc \ - src/php_v8_compile_options.cc \ src/php_v8_script_compiler.cc \ src/php_v8_source.cc \ src/php_v8_data.cc \ @@ -184,7 +184,6 @@ if test "$PHP_V8" != "no"; then src/php_v8_integer.cc \ src/php_v8_int32.cc \ src/php_v8_uint32.cc \ - src/php_v8_integrity_level.cc \ src/php_v8_object.cc \ src/php_v8_function.cc \ src/php_v8_array.cc \ @@ -196,17 +195,13 @@ if test "$PHP_V8" != "no"; then src/php_v8_boolean_object.cc \ src/php_v8_string_object.cc \ src/php_v8_symbol_object.cc \ - src/php_v8_property_attribute.cc \ src/php_v8_template.cc \ src/php_v8_return_value.cc \ src/php_v8_callback_info.cc \ src/php_v8_function_callback_info.cc \ src/php_v8_property_callback_info.cc \ - src/php_v8_access_control.cc \ - src/php_v8_property_handler_flags.cc \ src/php_v8_named_property_handler_configuration.cc \ src/php_v8_indexed_property_handler_configuration.cc \ - src/php_v8_access_type.cc \ ], $ext_shared, , -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_ADD_BUILD_DIR($ext_builddir/src) diff --git a/scripts/provision/.bashrc b/scripts/provision/.bashrc index 3ed5783..30e1997 100644 --- a/scripts/provision/.bashrc +++ b/scripts/provision/.bashrc @@ -127,4 +127,7 @@ if [[ -e ~/.phpbrew/bashrc ]]; then fi fi -EDITOR=vim +export EDITOR=vim + +# To prevent a PHP test suite from asking to send results to the PHP QA team: +export NO_INTERACTION=1 diff --git a/scripts/provision/provision.sh b/scripts/provision/provision.sh index 86504e5..4c65880 100644 --- a/scripts/provision/provision.sh +++ b/scripts/provision/provision.sh @@ -10,6 +10,10 @@ sudo add-apt-repository ppa:pinepain/libv8-6.0 # Let's update packages list: sudo apt-get update +# Remove unused +sudo apt-get remove -y liblxc1 lxc-common lxd lxcfs + + # Make sure this system tools installed: sudo apt-get install -y git htop curl pkgconf diff --git a/scripts/replace_expect.php b/scripts/replace_expect.php index d3c76ff..a39e436 100755 --- a/scripts/replace_expect.php +++ b/scripts/replace_expect.php @@ -13,7 +13,15 @@ */ $tests_dir = realpath(__DIR__ . '/../tests'); -$iterator = new GlobIterator($tests_dir . '/*.out', FilesystemIterator::KEY_AS_FILENAME); + + +if ($argc == 2) { + $mask = str_replace(['tests/', '.phpt', '.diff'], '', $argv[1]); +} else { + $mask = '*'; +} + +$iterator = new GlobIterator($tests_dir . "/{$mask}.out", FilesystemIterator::KEY_AS_FILENAME); foreach ($iterator as $item) { //var_dump($item); @@ -35,7 +43,42 @@ foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) { @unlink($tests_dir. '/'.$base_name . $ext); } - } else { - printf("please, edit manually [%s]".PHP_EOL, $iterator->key()); + + continue; + } elseif (false !== ($pos = strpos($test_content, '--EXPECTF--'))) { + + printf("--EXPECTF-- [%s]".PHP_EOL, $iterator->key()); + + // get replacements + + $tests = substr($test_content, 0, $pos); + $result = file_get_contents($tests_dir . '/' . $out_file); + + preg_match_all('#// EXPECTF: \-\-\-(.+)#', $tests, $expectf_search); + preg_match_all('#// EXPECTF: \+\+\+(.+)#', $tests, $expectf_replace); + + if (count($expectf_search) != count($expectf_replace)) { + printf("please, edit manually [%s]: searches and replaces count doesn't match".PHP_EOL, $iterator->key()); + continue; + } + + foreach (array_combine($expectf_search[1], $expectf_replace[1]) as $search => $replace) { + $result = preg_replace($search, $replace, $result); + } + + $test_content = $tests; + $test_content .= '--EXPECTF--'.PHP_EOL; + $test_content .= $result; + $test_content .= PHP_EOL; + + file_put_contents($tests_dir . '/' . $test_file, $test_content); + + foreach (['.diff', '.exp', '.log', '.mem', '.out', '.php', '.sh'] as $ext) { + @unlink($tests_dir. '/'.$base_name . $ext); + } + + continue; } + + printf("please, edit manually [%s]".PHP_EOL, $iterator->key()); } diff --git a/src/php_v8_access_control.cc b/src/php_v8_access_control.cc deleted file mode 100644 index b7e49da..0000000 --- a/src/php_v8_access_control.cc +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_access_control.h" -#include "php_v8.h" - -zend_class_entry* php_v8_access_control_class_entry; -#define this_ce php_v8_access_control_class_entry - - -static const zend_function_entry php_v8_access_control_methods[] = { - PHP_FE_END -}; - -PHP_MINIT_FUNCTION(php_v8_access_control) { - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "AccessControl", php_v8_access_control_methods); - this_ce = zend_register_internal_class(&ce); - - zend_declare_class_constant_long(this_ce, ZEND_STRL("DEFAULT_ACCESS"), v8::AccessControl::DEFAULT); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_CAN_READ"), v8::AccessControl::ALL_CAN_READ); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_CAN_WRITE"), v8::AccessControl::ALL_CAN_WRITE); - - return SUCCESS; -} diff --git a/src/php_v8_access_control.h b/src/php_v8_access_control.h deleted file mode 100644 index cc425e8..0000000 --- a/src/php_v8_access_control.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_ACCESS_CONTROL_H -#define PHP_V8_ACCESS_CONTROL_H - -#include - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_access_control_class_entry; - -PHP_MINIT_FUNCTION (php_v8_access_control); - -#define PHP_V8_ACCESS_CONTROL_FLAGS ( 0 \ - | v8::AccessControl::DEFAULT \ - | v8::AccessControl::ALL_CAN_READ \ - | v8::AccessControl::ALL_CAN_WRITE \ -) - - -#endif //PHP_V8_ACCESS_CONTROL_H diff --git a/src/php_v8_access_type.cc b/src/php_v8_access_type.cc deleted file mode 100644 index 40b6a64..0000000 --- a/src/php_v8_access_type.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_access_type.h" -#include "php_v8.h" -#include - -zend_class_entry* php_v8_access_type_class_entry; -#define this_ce php_v8_access_type_class_entry - - -static const zend_function_entry php_v8_access_type_methods[] = { - PHP_FE_END -}; - -PHP_MINIT_FUNCTION(php_v8_access_type) { - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "AccessType", php_v8_access_type_methods); - this_ce = zend_register_internal_class(&ce); - - zend_declare_class_constant_long(this_ce, ZEND_STRL("ACCESS_GET"), v8::AccessType::ACCESS_GET); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ACCESS_SET"), v8::AccessType::ACCESS_SET); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ACCESS_HAS"), v8::AccessType::ACCESS_HAS); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ACCESS_DELETE"), v8::AccessType::ACCESS_DELETE); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ACCESS_KEYS"), v8::AccessType::ACCESS_KEYS); - - return SUCCESS; -} diff --git a/src/php_v8_access_type.h b/src/php_v8_access_type.h deleted file mode 100644 index 916a323..0000000 --- a/src/php_v8_access_type.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_ACCESS_TYPE_H -#define PHP_V8_ACCESS_TYPE_H - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_access_type_class_entry; - -#define PHP_V8_ACCESS_TYPE_FLAGS ( 0 \ - | v8::AccessType::ACCESS_GET \ - | v8::AccessType::ACCESS_SET \ - | v8::AccessType::ACCESS_HAS \ - | v8::AccessType::ACCESS_DELETE \ - | v8::AccessType::ACCESS_KEYS \ -) - -PHP_MINIT_FUNCTION(php_v8_access_type); - -#endif //PHP_V8_ACCESS_TYPE_H diff --git a/src/php_v8_callbacks.cc b/src/php_v8_callbacks.cc index ea0f1ad..fa1331d 100644 --- a/src/php_v8_callbacks.cc +++ b/src/php_v8_callbacks.cc @@ -89,7 +89,7 @@ namespace phpv8 { } } - phpv8::Callback *CallbacksBucket::get(size_t index) { + phpv8::Callback *CallbacksBucket::get(Index index) { auto it = callbacks.find(index); if (it != callbacks.end()) { @@ -99,7 +99,7 @@ namespace phpv8 { return NULL; } - void CallbacksBucket::add(size_t index, zend_fcall_info fci, zend_fcall_info_cache fci_cache) { + void CallbacksBucket::add(Index index, zend_fcall_info fci, zend_fcall_info_cache fci_cache) { callbacks[index] = std::make_shared(fci, fci_cache); } @@ -235,7 +235,7 @@ static inline void php_v8_callback_set_retval_from_callback_info(v8::ReturnValue } -void php_v8_callback_call_from_bucket_with_zargs(size_t index, v8::Local data, zval *args, zval *retval) { +void php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index index, v8::Local data, zval *args, zval *retval) { phpv8::CallbacksBucket *bucket; if (data.IsEmpty() || !data->IsExternal()) { @@ -275,7 +275,7 @@ void php_v8_callback_call_from_bucket_with_zargs(size_t index, v8::Local -void php_v8_callback_call_from_bucket_with_zargs(size_t index, const T &info, M rv, zval *args) { +void php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index index, const T &info, M rv, zval *args) { zval callback_info; php_v8_return_value_t *php_v8_return_value; // Wrap callback info @@ -304,7 +304,7 @@ void php_v8_callback_function(const v8::FunctionCallbackInfo &info) { /* Build the parameter array */ array_init_size(&args, 1); - php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Callback, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -322,7 +322,7 @@ void php_v8_callback_accessor_name_getter(v8::Local property, const v8 php_v8_get_or_create_value(&property_name, property, php_v8_isolate); add_index_zval(&args, 0, &property_name); - php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Getter, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -344,7 +344,7 @@ void php_v8_callback_accessor_name_setter(v8::Local property, v8::Loca add_index_zval(&args, 0, &property_name); add_index_zval(&args, 1, &property_value); - php_v8_callback_call_from_bucket_with_zargs(1, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Setter, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -363,7 +363,7 @@ void php_v8_callback_generic_named_property_getter(v8::Local property, php_v8_get_or_create_value(&property_name, property, php_v8_isolate); add_index_zval(&args, 0, &property_name); - php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Getter, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -385,7 +385,7 @@ void php_v8_callback_generic_named_property_setter(v8::Local property, add_index_zval(&args, 0, &property_name); add_index_zval(&args, 1, &property_value); - php_v8_callback_call_from_bucket_with_zargs(1, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Setter, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -403,7 +403,7 @@ void php_v8_callback_generic_named_property_query(v8::Local property, php_v8_get_or_create_value(&property_name, property, php_v8_isolate); add_index_zval(&args, 0, &property_name); - php_v8_callback_call_from_bucket_with_zargs(2, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Query, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -421,7 +421,7 @@ void php_v8_callback_generic_named_property_deleter(v8::Local property php_v8_get_or_create_value(&property_name, property, php_v8_isolate); add_index_zval(&args, 0, &property_name); - php_v8_callback_call_from_bucket_with_zargs(3, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Deleter, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -434,7 +434,7 @@ void php_v8_callback_generic_named_property_enumerator(const v8::PropertyCallbac /* Build the parameter array */ array_init_size(&args, 1); - php_v8_callback_call_from_bucket_with_zargs(4, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Enumerator, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -453,7 +453,7 @@ void php_v8_callback_indexed_property_getter(uint32_t index, const v8::PropertyC ZVAL_LONG(&property_name, index); add_index_zval(&args, 0, &property_name); - php_v8_callback_call_from_bucket_with_zargs(0, info, info.GetReturnValue(), &args); + php_v8_callback_call_from_bucket_with_zargs(phpv8::CallbacksBucket::Index::Getter, info, info.GetReturnValue(), &args); zval_ptr_dtor(&args); } @@ -475,7 +475,7 @@ void php_v8_callback_indexed_property_setter(uint32_t index, v8::Local accessing_context, v8::Local accessed_object, v8::Local data) { - PHP_V8_THROW_EXCEPTION("Broken due to problem (see https://groups.google.com/forum/?fromgroups#!topic/v8-dev/c7LhW2bNabY)"); - return false; - - PHP_V8_DECLARE_ISOLATE_LOCAL_ALIAS(v8::Isolate::GetCurrent()); - php_v8_isolate_t *php_v8_isolate = PHP_V8_ISOLATE_FETCH_REFERENCE(isolate); - - - zval args; - zval accessed_object_zv; - zval retval; - zval context_zv; - - bool security_retval = false; - - ZVAL_BOOL(&retval, false); - - array_init_size(&args, 2); - - php_v8_context_t *php_v8_context = php_v8_context_get_reference(accessing_context); - - assert(NULL != php_v8_context); - - php_v8_get_or_create_value(&accessed_object_zv, accessed_object, php_v8_isolate); - - ZVAL_OBJ(&context_zv, &php_v8_context->std); - add_index_zval(&args, 0, &context_zv); - add_index_zval(&args, 1, &accessed_object_zv); - - php_v8_callback_call_from_bucket_with_zargs(0, data, &args, &retval); - - if (Z_TYPE(retval) == IS_TRUE) { - security_retval = true; - } - - zval_ptr_dtor(&args); - zval_ptr_dtor(&retval); - - return security_retval; -} diff --git a/src/php_v8_callbacks.h b/src/php_v8_callbacks.h index 2d34b6b..e90fa6c 100644 --- a/src/php_v8_callbacks.h +++ b/src/php_v8_callbacks.h @@ -56,8 +56,6 @@ extern void php_v8_callback_indexed_property_query(uint32_t index, const v8::Pro extern void php_v8_callback_indexed_property_deleter(uint32_t index, const v8::PropertyCallbackInfo& info); extern void php_v8_callback_indexed_property_enumerator(const v8::PropertyCallbackInfo& info); -extern bool php_v8_callback_access_check(v8::Local accessing_context, v8::Local accessed_object, v8::Local data); - //#define PHP_V8_DEBUG_EXTERNAL_MEM 1 #ifdef PHP_V8_DEBUG_EXTERNAL_MEM @@ -92,10 +90,18 @@ namespace phpv8 { class CallbacksBucket { public: - phpv8::Callback *get(size_t index); + enum class Index { + Callback = 0, + Getter = 0, + Setter = 1, + Query = 2, + Deleter = 3, + Enumerator = 4, + }; + phpv8::Callback *get(Index index); void reset(CallbacksBucket *bucket); - void add(size_t index, zend_fcall_info fci, zend_fcall_info_cache fci_cache); + void add(Index index, zend_fcall_info fci, zend_fcall_info_cache fci_cache); int getGcCount(); void collectGcZvals(zval *& zv); @@ -109,7 +115,7 @@ namespace phpv8 { } private: - std::map> callbacks; + std::map> callbacks; }; diff --git a/src/php_v8_compile_options.cc b/src/php_v8_compile_options.cc deleted file mode 100644 index aad6177..0000000 --- a/src/php_v8_compile_options.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_compile_options.h" -#include "php_v8.h" - -zend_class_entry* php_v8_compile_options_class_entry; -#define this_ce php_v8_compile_options_class_entry - - -static const zend_function_entry php_v8_compile_options_methods[] = { - PHP_FE_END -}; - -PHP_MINIT_FUNCTION(php_v8_compile_options) { - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, "V8\\ScriptCompiler", "CompileOptions", php_v8_compile_options_methods); - this_ce = zend_register_internal_class(&ce); - - zend_declare_class_constant_long(this_ce, ZEND_STRL("kNoCompileOptions"), v8::ScriptCompiler::CompileOptions::kNoCompileOptions); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kProduceParserCache"), v8::ScriptCompiler::CompileOptions::kProduceParserCache); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kConsumeParserCache"), v8::ScriptCompiler::CompileOptions::kConsumeParserCache); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kProduceCodeCache"), v8::ScriptCompiler::CompileOptions::kProduceCodeCache); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kConsumeCodeCache"), v8::ScriptCompiler::CompileOptions::kConsumeCodeCache); - - return SUCCESS; -} diff --git a/src/php_v8_compile_options.h b/src/php_v8_compile_options.h deleted file mode 100644 index c169729..0000000 --- a/src/php_v8_compile_options.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_COMPILE_OPTIONS_H -#define PHP_V8_COMPILE_OPTIONS_H - -#include "php_v8_exceptions.h" -#include - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_compile_options_class_entry; - -#define PHP_V8_CHECK_COMPILER_OPTIONS_RANGE(options, message) \ - if (options < static_cast(v8::ScriptCompiler::CompileOptions::kNoCompileOptions) \ - || options > static_cast(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache)) { \ - PHP_V8_THROW_VALUE_EXCEPTION(message); \ - return; \ - } - -PHP_MINIT_FUNCTION (php_v8_compile_options); - - -#endif //PHP_V8_COMPILE_OPTIONS_H diff --git a/src/php_v8_context.cc b/src/php_v8_context.cc index ae1a51b..4a6c08c 100644 --- a/src/php_v8_context.cc +++ b/src/php_v8_context.cc @@ -262,20 +262,6 @@ static PHP_METHOD(V8Context, SetErrorMessageForCodeGenerationFromStrings) context->SetErrorMessageForCodeGenerationFromStrings(local_string); } -static PHP_METHOD(V8Context, EstimatedSize) -{ - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - PHP_V8_CONTEXT_FETCH_WITH_CHECK(getThis(), php_v8_context); - - PHP_V8_ENTER_STORED_ISOLATE(php_v8_context); - PHP_V8_ENTER_CONTEXT(php_v8_context); - - RETURN_LONG(context->EstimatedSize()); -} - ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_context___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) ZEND_ARG_OBJ_INFO(0, global_template, V8\\ObjectTemplate, 1) @@ -318,9 +304,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_context_SetErrorMessageForCodeGenerationFromSt ZEND_ARG_OBJ_INFO(0, message, V8\\StringValue, 0) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_context_EstimatedSize, ZEND_RETURN_VALUE, 0, IS_LONG, 0) -ZEND_END_ARG_INFO() - static const zend_function_entry php_v8_context_methods[] = { PHP_ME(V8Context, __construct, arginfo_v8_context___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) @@ -337,8 +320,6 @@ static const zend_function_entry php_v8_context_methods[] = { PHP_ME(V8Context, IsCodeGenerationFromStringsAllowed, arginfo_v8_context_IsCodeGenerationFromStringsAllowed, ZEND_ACC_PUBLIC) PHP_ME(V8Context, SetErrorMessageForCodeGenerationFromStrings, arginfo_v8_context_SetErrorMessageForCodeGenerationFromStrings, ZEND_ACC_PUBLIC) - PHP_ME(V8Context, EstimatedSize, arginfo_v8_context_EstimatedSize, ZEND_ACC_PUBLIC) - PHP_FE_END }; diff --git a/src/php_v8_enums.cc b/src/php_v8_enums.cc new file mode 100644 index 0000000..f79eb93 --- /dev/null +++ b/src/php_v8_enums.cc @@ -0,0 +1,122 @@ +/* + * This file is part of the pinepain/php-v8 PHP extension. + * + * Copyright (c) 2015-2017 Bogdan Padalko + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php_v8_enums.h" +#include "php_v8.h" + +zend_class_entry *php_v8_access_control_class_entry; +zend_class_entry* php_v8_constructor_behavior_class_entry; +zend_class_entry* php_v8_integrity_level_class_entry; +zend_class_entry* php_v8_property_attribute_class_entry; +zend_class_entry* php_v8_property_handler_flags_class_entry; +zend_class_entry *php_v8_property_filter_class_entry; +zend_class_entry *php_v8_key_collection_mode_class_entry; +zend_class_entry *php_v8_index_filter_class_entry; + + +static const zend_function_entry php_v8_enum_methods[] = { + PHP_FE_END +}; + + +PHP_MINIT_FUNCTION (php_v8_enums) { + zend_class_entry ce; + + // v8::AccessControl + #define this_ce php_v8_access_control_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "AccessControl", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("DEFAULT_ACCESS"), v8::AccessControl::DEFAULT); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_CAN_READ"), v8::AccessControl::ALL_CAN_READ); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_CAN_WRITE"), v8::AccessControl::ALL_CAN_WRITE); + #undef this_ce + + //v8::ConstructorBehavior + #define this_ce php_v8_constructor_behavior_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "ConstructorBehavior", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("kThrow"), static_cast(v8::ConstructorBehavior::kThrow)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kAllow"), static_cast(v8::ConstructorBehavior::kAllow)); + + #undef this_ce + + // v8::IntegrityLevel + #define this_ce php_v8_integrity_level_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "IntegrityLevel", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("kFrozen"), static_cast(v8::IntegrityLevel::kFrozen)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kSealed"), static_cast(v8::IntegrityLevel::kSealed)); + #undef this_ce + + // v8::PropertyAttribute + #define this_ce php_v8_property_attribute_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyAttribute", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("None"), v8::PropertyAttribute::None); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ReadOnly"), v8::PropertyAttribute::ReadOnly); + zend_declare_class_constant_long(this_ce, ZEND_STRL("DontEnum"), v8::PropertyAttribute::DontEnum); + zend_declare_class_constant_long(this_ce, ZEND_STRL("DontDelete"), v8::PropertyAttribute::DontDelete); + + #undef this_ce + + // v8::PropertyHandlerFlags + #define this_ce php_v8_property_handler_flags_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyHandlerFlags", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("kNone"), static_cast(v8::PropertyHandlerFlags::kNone)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kAllCanRead"), static_cast(v8::PropertyHandlerFlags::kAllCanRead)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kNonMasking"), static_cast(v8::PropertyHandlerFlags::kNonMasking)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kOnlyInterceptStrings"), static_cast(v8::PropertyHandlerFlags::kOnlyInterceptStrings)); + #undef this_ce + + // v8::PropertyFilter + #define this_ce php_v8_property_filter_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyFilter", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_PROPERTIES"), v8::PropertyFilter::ALL_PROPERTIES); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ONLY_WRITABLE"), v8::PropertyFilter::ONLY_WRITABLE); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ONLY_ENUMERABLE"), v8::PropertyFilter::ONLY_ENUMERABLE); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ONLY_CONFIGURABLE"), v8::PropertyFilter::ONLY_CONFIGURABLE); + zend_declare_class_constant_long(this_ce, ZEND_STRL("SKIP_STRINGS"), v8::PropertyFilter::SKIP_STRINGS); + zend_declare_class_constant_long(this_ce, ZEND_STRL("SKIP_SYMBOLS"), v8::PropertyFilter::SKIP_SYMBOLS); + #undef this_ce + + // v8::KeyCollectionMode + #define this_ce php_v8_key_collection_mode_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "KeyCollectionMode", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("kOwnOnly"), static_cast(v8::KeyCollectionMode::kOwnOnly)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kIncludePrototypes"), static_cast(v8::KeyCollectionMode::kIncludePrototypes)); + #undef this_ce + + // v8::IndexFilter + #define this_ce php_v8_index_filter_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "IndexFilter", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("kIncludeIndices"), static_cast(v8::IndexFilter::kIncludeIndices)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kSkipIndices"), static_cast(v8::IndexFilter::kSkipIndices)); + #undef this_ce + + return SUCCESS; +} diff --git a/src/php_v8_enums.h b/src/php_v8_enums.h new file mode 100644 index 0000000..c3922b1 --- /dev/null +++ b/src/php_v8_enums.h @@ -0,0 +1,88 @@ +/* + * This file is part of the pinepain/php-v8 PHP extension. + * + * Copyright (c) 2015-2017 Bogdan Padalko + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + +#ifndef PHP_V8_ENUMS_H +#define PHP_V8_ENUMS_H + +#include + +extern "C" { +#include "php.h" + +#ifdef ZTS +#include "TSRM.h" +#endif +} + +extern zend_class_entry* php_v8_access_control_class_entry; +extern zend_class_entry* php_v8_constructor_behavior_class_entry; +extern zend_class_entry* php_v8_integrity_level_class_entry; +extern zend_class_entry* php_v8_property_attribute_class_entry; +extern zend_class_entry* php_v8_property_handler_flags_class_entry; +extern zend_class_entry* php_v8_property_filter_class_entry; +extern zend_class_entry* php_v8_key_collection_mode_class_entry; +extern zend_class_entry* php_v8_index_filter_class_entry; + + +#define PHP_V8_ACCESS_CONTROL_FLAGS ( 0 \ + | v8::AccessControl::DEFAULT \ + | v8::AccessControl::ALL_CAN_READ \ + | v8::AccessControl::ALL_CAN_WRITE \ +) + +#define PHP_V8_CONSTRUCTOR_BEHAVIOR_FLAGS ( 0 \ + | static_cast(v8::ConstructorBehavior::kAllow) \ + | static_cast(v8::ConstructorBehavior::kThrow) \ +) + +#define PHP_V8_INTEGRITY_LEVEL_FLAGS ( 0 \ + | static_cast(v8::IntegrityLevel::kFrozen) \ + | static_cast(v8::IntegrityLevel::kSealed) \ +) + +#define PHP_V8_PROPERTY_ATTRIBUTE_FLAGS ( 0 \ + | v8::PropertyAttribute::None \ + | v8::PropertyAttribute::ReadOnly \ + | v8::PropertyAttribute::DontEnum \ + | v8::PropertyAttribute::DontDelete \ +) + +#define PHP_V8_PROPERTY_HANDLER_FLAGS ( 0 \ + | static_cast(v8::PropertyHandlerFlags::kNone) \ + | static_cast(v8::PropertyHandlerFlags::kAllCanRead) \ + | static_cast(v8::PropertyHandlerFlags::kNonMasking) \ + | static_cast(v8::PropertyHandlerFlags::kOnlyInterceptStrings) \ +) + +#define PHP_V8_PROPERTY_FILTER_FLAGS ( 0 \ + | v8::PropertyFilter::ALL_PROPERTIES \ + | v8::PropertyFilter::ONLY_WRITABLE \ + | v8::PropertyFilter::ONLY_ENUMERABLE \ + | v8::PropertyFilter::ONLY_CONFIGURABLE \ + | v8::PropertyFilter::SKIP_STRINGS \ + | v8::PropertyFilter::SKIP_SYMBOLS \ +) + +#define PHP_V8_KEY_COLLECTION_MODE_FLAGS ( 0 \ + | static_cast(v8::KeyCollectionMode::kOwnOnly) \ + | static_cast(v8::KeyCollectionMode::kIncludePrototypes) \ +) + +#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \ + | static_cast(v8::IndexFilter::kIncludeIndices) \ + | static_cast(v8::IndexFilter::kSkipIndices) \ +) + + +PHP_MINIT_FUNCTION (php_v8_enums); + +#endif //PHP_V8_ENUMS_H diff --git a/src/php_v8_function.cc b/src/php_v8_function.cc index d1a15d4..51f6fc9 100644 --- a/src/php_v8_function.cc +++ b/src/php_v8_function.cc @@ -20,6 +20,7 @@ #include "php_v8_string.h" #include "php_v8_object.h" #include "php_v8_context.h" +#include "php_v8_enums.h" #include "php_v8.h" zend_class_entry *php_v8_function_class_entry; @@ -302,14 +303,17 @@ static PHP_METHOD(V8Function, __construct) { zend_fcall_info_cache fci_cache = empty_fcall_info_cache; zend_long length = 0; + zend_long behavior = static_cast(v8::ConstructorBehavior::kAllow); v8::FunctionCallback callback = 0; v8::Local data; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "of|l", &php_v8_context_zv, &fci, &fci_cache, &length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "of|ll", &php_v8_context_zv, &fci, &fci_cache, &length, &behavior) == FAILURE) { return; } + behavior = behavior ? behavior & PHP_V8_CONSTRUCTOR_BEHAVIOR_FLAGS : behavior; + PHP_V8_CHECK_FUNCTION_LENGTH_RANGE(length, "Length is out of range"); PHP_V8_VALUE_FETCH_INTO(getThis(), php_v8_value); @@ -328,12 +332,16 @@ static PHP_METHOD(V8Function, __construct) { phpv8::CallbacksBucket *bucket = php_v8_value->persistent_data->bucket("callback"); data = v8::External::New(isolate, bucket); - bucket->add(0, fci, fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Getter, fci, fci_cache); callback = php_v8_callback_function; } - v8::MaybeLocal maybe_local_function = v8::Function::New(context, callback, data, static_cast(length)); + v8::MaybeLocal maybe_local_function = v8::Function::New(context, + callback, + data, + static_cast(length), + static_cast(behavior)); if (maybe_local_function.IsEmpty()) { PHP_V8_THROW_EXCEPTION("Failed to create Function value"); diff --git a/src/php_v8_function_template.cc b/src/php_v8_function_template.cc index 862884d..0ca948d 100644 --- a/src/php_v8_function_template.cc +++ b/src/php_v8_function_template.cc @@ -22,6 +22,7 @@ #include "php_v8_value.h" #include "php_v8_context.h" #include "php_v8_ext_mem_interface.h" +#include "php_v8_enums.h" #include "php_v8.h" zend_class_entry *php_v8_function_template_class_entry; @@ -130,17 +131,21 @@ static PHP_METHOD(V8FunctionTemplate, __construct) { zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; + zval *php_v8_receiver_zv = NULL; + zend_long length = 0; + zend_long behavior = static_cast(v8::ConstructorBehavior::kAllow); v8::FunctionCallback callback = 0; v8::Local data; v8::Local signature; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|f!l", &php_v8_isolate_zv, &fci, &fci_cache, &length) == - FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|f!o!ll", &php_v8_isolate_zv, &fci, &fci_cache, &php_v8_receiver_zv, &length, &behavior) == FAILURE) { return; } + behavior = behavior ? behavior & PHP_V8_CONSTRUCTOR_BEHAVIOR_FLAGS : behavior; + PHP_V8_CHECK_FUNCTION_LENGTH_RANGE(length, "Length is out of range"); PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); @@ -151,16 +156,28 @@ static PHP_METHOD(V8FunctionTemplate, __construct) { PHP_V8_ENTER_ISOLATE(php_v8_isolate); + if (php_v8_receiver_zv) { + PHP_V8_FETCH_FUNCTION_TEMPLATE_WITH_CHECK(php_v8_receiver_zv, php_v8_receiver); + PHP_V8_DATA_ISOLATES_CHECK(php_v8_function_template, php_v8_receiver); + + signature = v8::Signature::New(isolate, php_v8_function_template_get_local(php_v8_receiver)); + } + if (fci.size) { phpv8::CallbacksBucket *bucket= php_v8_function_template->persistent_data->bucket("callback"); data = v8::External::New(isolate, bucket); - bucket->add(0, fci, fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Callback, fci, fci_cache); callback = php_v8_callback_function; } - v8::Local local_template = v8::FunctionTemplate::New(isolate, callback, data, signature, static_cast(length)); + v8::Local local_template = v8::FunctionTemplate::New(isolate, + callback, + data, + signature, + static_cast(length), + static_cast(behavior)); PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_template, "Failed to create FunctionTemplate value"); @@ -237,7 +254,7 @@ static PHP_METHOD(V8FunctionTemplate, SetCallHandler) { PHP_V8_ENTER_STORED_ISOLATE(php_v8_function_template); phpv8::CallbacksBucket *bucket= php_v8_function_template->persistent_data->bucket("callback"); - bucket->add(0, fci, fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Callback, fci, fci_cache); v8::Local local_template = php_v8_function_template_get_local(php_v8_function_template); @@ -436,7 +453,9 @@ static PHP_METHOD(V8FunctionTemplate, GetExternalAllocatedMemory) { ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_function_template___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) ZEND_ARG_CALLABLE_INFO(0, callback, 1) + ZEND_ARG_OBJ_INFO(0, receiver, V8\\FunctionTemplate, 1) ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, behavior, IS_LONG, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_function_template_GetIsolate, ZEND_RETURN_VALUE, 0, V8\\Isolate, 0) @@ -463,6 +482,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_function_template_SetNativeDataProperty, Z ZEND_ARG_CALLABLE_INFO(0, getter, 0) ZEND_ARG_CALLABLE_INFO(0, setter, 1) ZEND_ARG_TYPE_INFO(0, attributes, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, receiver, V8\\FunctionTemplate, 1) ZEND_ARG_TYPE_INFO(0, settings, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/src/php_v8_indexed_property_handler_configuration.cc b/src/php_v8_indexed_property_handler_configuration.cc index 9bcdc38..f6e0459 100644 --- a/src/php_v8_indexed_property_handler_configuration.cc +++ b/src/php_v8_indexed_property_handler_configuration.cc @@ -16,7 +16,7 @@ #include "php_v8_indexed_property_handler_configuration.h" #include "php_v8_named_property_handler_configuration.h" -#include "php_v8_property_handler_flags.h" +#include "php_v8_enums.h" #include "php_v8.h" zend_class_entry* php_v8_indexed_property_handler_configuration_class_entry; @@ -96,26 +96,26 @@ static PHP_METHOD (V8IndexedPropertyHandlerConfiguration, __construct) { PHP_V8_INDEXED_PROPERTY_HANDLER_FETCH_INTO(getThis(), php_v8_handlers); - php_v8_handlers->bucket->add(0, fci_getter, fci_cache_getter); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Getter, fci_getter, fci_cache_getter); php_v8_handlers->getter = php_v8_callback_indexed_property_getter; if (fci_setter.size) { - php_v8_handlers->bucket->add(1, fci_setter, fci_cache_setter); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Setter, fci_setter, fci_cache_setter); php_v8_handlers->setter = php_v8_callback_indexed_property_setter; } if (fci_query.size) { - php_v8_handlers->bucket->add(2, fci_query, fci_cache_query); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Query, fci_query, fci_cache_query); php_v8_handlers->query = php_v8_callback_indexed_property_query; } if (fci_deleter.size) { - php_v8_handlers->bucket->add(3, fci_deleter, fci_cache_deleter); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Deleter, fci_deleter, fci_cache_deleter); php_v8_handlers->deleter = php_v8_callback_indexed_property_deleter; } if (fci_enumerator.size) { - php_v8_handlers->bucket->add(4, fci_enumerator, fci_cache_enumerator); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Enumerator, fci_enumerator, fci_cache_enumerator); php_v8_handlers->enumerator = php_v8_callback_indexed_property_enumerator; } diff --git a/src/php_v8_integrity_level.cc b/src/php_v8_integrity_level.cc deleted file mode 100644 index caf14e4..0000000 --- a/src/php_v8_integrity_level.cc +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_integrity_level.h" -#include "php_v8.h" - -zend_class_entry* php_v8_integrity_level_class_entry; -#define this_ce php_v8_integrity_level_class_entry - - -static const zend_function_entry php_v8_integrity_level_methods[] = { - PHP_FE_END -}; - - -PHP_MINIT_FUNCTION(php_v8_integrity_level) { - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "IntegrityLevel", php_v8_integrity_level_methods); - this_ce = zend_register_internal_class(&ce); - - zend_declare_class_constant_long(this_ce, ZEND_STRL("kFrozen"), static_cast(v8::IntegrityLevel::kFrozen)); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kSealed"), static_cast(v8::IntegrityLevel::kSealed)); - - return SUCCESS; -} diff --git a/src/php_v8_integrity_level.h b/src/php_v8_integrity_level.h deleted file mode 100644 index 8a92f1f..0000000 --- a/src/php_v8_integrity_level.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_INTEGRITY_LEVEL_H -#define PHP_V8_INTEGRITY_LEVEL_H - -#include - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_integrity_level_class_entry; - -PHP_MINIT_FUNCTION (php_v8_integrity_level); - -#define PHP_V8_INTEGRITY_LEVEL_FLAGS ( 0 \ - | static_cast(v8::IntegrityLevel::kFrozen) \ - | static_cast(v8::IntegrityLevel::kSealed) \ -) - - -#endif //PHP_V8_INTEGRITY_LEVEL_H diff --git a/src/php_v8_isolate.cc b/src/php_v8_isolate.cc index 8cb492f..1af73ff 100644 --- a/src/php_v8_isolate.cc +++ b/src/php_v8_isolate.cc @@ -480,9 +480,8 @@ static PHP_METHOD(V8Isolate, CancelTerminateExecution) { static PHP_METHOD(V8Isolate, SetCaptureStackTraceForUncaughtExceptions) { zend_bool capture; zend_long frame_limit = 10; - zend_long options = static_cast(v8::StackTrace::StackTraceOptions::kOverview); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "b|ll", &capture, &frame_limit, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b|ll", &capture, &frame_limit) == FAILURE) { return; } @@ -491,9 +490,7 @@ static PHP_METHOD(V8Isolate, SetCaptureStackTraceForUncaughtExceptions) { PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate); PHP_V8_ENTER_ISOLATE(php_v8_isolate); - isolate->SetCaptureStackTraceForUncaughtExceptions(static_cast(capture), - static_cast(frame_limit), - static_cast(options & PHP_V8_STACK_TRACE_OPTIONS)); + isolate->SetCaptureStackTraceForUncaughtExceptions(static_cast(capture), static_cast(frame_limit)); } static PHP_METHOD(V8Isolate, IsDead) { @@ -586,7 +583,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_isolate_SetCaptureStackTraceForUncaughtExceptions, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_TYPE_INFO(0, capture, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, frame_limit, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_isolate_IsDead, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) diff --git a/src/php_v8_named_property_handler_configuration.cc b/src/php_v8_named_property_handler_configuration.cc index dc392e9..56b2e22 100644 --- a/src/php_v8_named_property_handler_configuration.cc +++ b/src/php_v8_named_property_handler_configuration.cc @@ -15,7 +15,7 @@ #endif #include "php_v8_named_property_handler_configuration.h" -#include "php_v8_property_handler_flags.h" +#include "php_v8_enums.h" #include "php_v8.h" zend_class_entry* php_v8_named_property_handler_configuration_class_entry; @@ -96,26 +96,26 @@ static PHP_METHOD (V8NamedPropertyHandlerConfiguration, __construct) { PHP_V8_NAMED_PROPERTY_HANDLER_FETCH_INTO(getThis(), php_v8_handlers); - php_v8_handlers->bucket->add(0, fci_getter, fci_cache_getter); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Getter, fci_getter, fci_cache_getter); php_v8_handlers->getter = php_v8_callback_generic_named_property_getter; if (fci_setter.size) { - php_v8_handlers->bucket->add(1, fci_setter, fci_cache_setter); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Setter, fci_setter, fci_cache_setter); php_v8_handlers->setter = php_v8_callback_generic_named_property_setter; } if (fci_query.size) { - php_v8_handlers->bucket->add(2, fci_query, fci_cache_query); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Query, fci_query, fci_cache_query); php_v8_handlers->query = php_v8_callback_generic_named_property_query; } if (fci_deleter.size) { - php_v8_handlers->bucket->add(3, fci_deleter, fci_cache_deleter); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Deleter, fci_deleter, fci_cache_deleter); php_v8_handlers->deleter = php_v8_callback_generic_named_property_deleter; } if (fci_enumerator.size) { - php_v8_handlers->bucket->add(4, fci_enumerator, fci_cache_enumerator); + php_v8_handlers->bucket->add(phpv8::CallbacksBucket::Index::Enumerator, fci_enumerator, fci_cache_enumerator); php_v8_handlers->enumerator = php_v8_callback_generic_named_property_enumerator; } diff --git a/src/php_v8_object.cc b/src/php_v8_object.cc index 2cee700..09ec3b4 100644 --- a/src/php_v8_object.cc +++ b/src/php_v8_object.cc @@ -15,18 +15,16 @@ #endif #include "php_v8_object.h" -#include "php_v8_integrity_level.h" #include "php_v8_exceptions.h" #include "php_v8_function_template.h" #include "php_v8_function.h" -#include "php_v8_property_attribute.h" -#include "php_v8_access_control.h" #include "php_v8_string.h" #include "php_v8_uint32.h" #include "php_v8_name.h" #include "php_v8_value.h" #include "php_v8_context.h" #include "php_v8_ext_mem_interface.h" +#include "php_v8_enums.h" #include "php_v8.h" @@ -463,11 +461,11 @@ static PHP_METHOD(V8Object, SetAccessor) { phpv8::CallbacksBucket *bucket = php_v8_value->persistent_data->bucket("accessor_", local_name->IsSymbol(), name); data = v8::External::New(isolate, bucket); - bucket->add(0, getter_fci, getter_fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache); getter = php_v8_callback_accessor_name_getter; if (setter_fci.size) { - bucket->add(1, setter_fci, setter_fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache); setter = php_v8_callback_accessor_name_setter; } @@ -530,15 +528,101 @@ static PHP_METHOD(V8Object, SetAccessorProperty) { local_object->SetAccessorProperty(local_name, getter, setter, static_cast(attributes), static_cast(settings)); } + +///** +// * Sets a native data property like Template::SetNativeDataProperty, but +// * this method sets on this object directly. +// */ +//V8_WARN_UNUSED_RESULT Maybe SetNativeDataProperty( +// Local context, Local name, +// AccessorNameGetterCallback getter, +// AccessorNameSetterCallback setter = nullptr, +// Local data = Local(), PropertyAttribute attributes = None); + +static PHP_METHOD(V8Object, SetNativeDataProperty) { + zval *context_zv; + zval *php_v8_name_zv; + + zend_long attributes = 0; + + zend_fcall_info getter_fci = empty_fcall_info; + zend_fcall_info_cache getter_fci_cache = empty_fcall_info_cache; + + zend_fcall_info setter_fci = empty_fcall_info; + zend_fcall_info_cache setter_fci_cache = empty_fcall_info_cache; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "oof|f!l", + &context_zv, + &php_v8_name_zv, + &getter_fci, &getter_fci_cache, + &setter_fci, &setter_fci_cache, + &attributes + ) == FAILURE) { + return; + } + + PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value); + PHP_V8_VALUE_FETCH_WITH_CHECK(php_v8_name_zv, php_v8_name); + PHP_V8_CONTEXT_FETCH_WITH_CHECK(context_zv, php_v8_context); + + PHP_V8_DATA_ISOLATES_CHECK(php_v8_value, php_v8_context) + PHP_V8_DATA_ISOLATES_CHECK(php_v8_value, php_v8_name) + + PHP_V8_ENTER_STORED_ISOLATE(php_v8_context); + PHP_V8_ENTER_CONTEXT(php_v8_context); + + v8::Local local_object = php_v8_value_get_local_as(php_v8_value); + v8::Local local_name = php_v8_value_get_local_as(php_v8_name); + + PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name); + + attributes = attributes ? attributes & PHP_V8_PROPERTY_ATTRIBUTE_FLAGS : attributes; + + v8::AccessorNameGetterCallback getter; + v8::AccessorNameSetterCallback setter = 0; + v8::Local data; + + phpv8::CallbacksBucket *bucket = php_v8_value->persistent_data->bucket("native_data_property_", local_name->IsSymbol(), name); + data = v8::External::New(isolate, bucket); + + bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache); + getter = php_v8_callback_accessor_name_getter; + + if (setter_fci.size) { + bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache); + setter = php_v8_callback_accessor_name_setter; + } + + v8::Maybe maybe_res = local_object->SetNativeDataProperty(context, + local_name, + getter, + setter, + data, + static_cast(attributes) + ); + + PHP_V8_THROW_EXCEPTION_WHEN_NOTHING(maybe_res, "Failed to set native data property"); + + RETURN_BOOL(maybe_res.FromJust()); +} + + /* NOTE: we skip functionality for private properties for now */ static PHP_METHOD(V8Object, GetPropertyNames) { zval *context_zv; + zend_long mode = static_cast(v8::KeyCollectionMode::kOwnOnly); + zend_long property_filter = static_cast(v8::PropertyFilter::ALL_PROPERTIES); + zend_long index_filter = static_cast(v8::IndexFilter::kIncludeIndices); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &context_zv) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|lll", &context_zv, &mode, &property_filter, &index_filter) == FAILURE) { return; } + mode = mode ? mode & PHP_V8_KEY_COLLECTION_MODE_FLAGS : mode; + property_filter = property_filter ? property_filter & PHP_V8_PROPERTY_FILTER_FLAGS : property_filter; + index_filter = index_filter ? index_filter & PHP_V8_INDEX_FILTER_FLAGS : index_filter; + PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value); PHP_V8_CONTEXT_FETCH_WITH_CHECK(context_zv, php_v8_context); @@ -552,7 +636,10 @@ static PHP_METHOD(V8Object, GetPropertyNames) { PHP_V8_TRY_CATCH(isolate); PHP_V8_INIT_ISOLATE_LIMITS_ON_OBJECT_VALUE(php_v8_value); - v8::MaybeLocal maybe_local_array = local_object->GetPropertyNames(context); + v8::MaybeLocal maybe_local_array = local_object->GetPropertyNames(context, + static_cast(mode), + static_cast(property_filter), + static_cast(index_filter)); PHP_V8_MAYBE_CATCH(php_v8_context, try_catch); PHP_V8_THROW_EXCEPTION_WHEN_EMPTY(maybe_local_array, "Failed to get property names") @@ -564,10 +651,12 @@ static PHP_METHOD(V8Object, GetPropertyNames) { static PHP_METHOD(V8Object, GetOwnPropertyNames) { zval *context_zv; + zend_long filter = static_cast(v8::PropertyFilter::ALL_PROPERTIES); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &context_zv) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|l", &context_zv, &filter) == FAILURE) { return; } + filter = filter ? filter & PHP_V8_PROPERTY_FILTER_FLAGS : filter; PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value); PHP_V8_CONTEXT_FETCH_WITH_CHECK(context_zv, php_v8_context); @@ -582,7 +671,7 @@ static PHP_METHOD(V8Object, GetOwnPropertyNames) { PHP_V8_TRY_CATCH(isolate); PHP_V8_INIT_ISOLATE_LIMITS_ON_OBJECT_VALUE(php_v8_value); - v8::MaybeLocal maybe_local_array = local_object->GetOwnPropertyNames(context); + v8::MaybeLocal maybe_local_array = local_object->GetOwnPropertyNames(context, static_cast(filter)); PHP_V8_MAYBE_CATCH(php_v8_context, try_catch); PHP_V8_THROW_EXCEPTION_WHEN_EMPTY(maybe_local_array, "Failed to get own property names") @@ -1270,12 +1359,24 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_object_SetAccessorProperty, ZEND_SEND_BY_V ZEND_ARG_TYPE_INFO(0, settings, IS_LONG, 0) ZEND_END_ARG_INFO() +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_php_v8_object_SetNativeDataProperty, ZEND_RETURN_VALUE, 3, _IS_BOOL, 0) + ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) + ZEND_ARG_OBJ_INFO(0, name, V8\\NameValue, 0) + ZEND_ARG_CALLABLE_INFO(0, getter, 0) + ZEND_ARG_CALLABLE_INFO(0, setter, 1) + ZEND_ARG_TYPE_INFO(0, attributes, IS_LONG, 0) +ZEND_END_ARG_INFO() + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_php_v8_object_GetPropertyNames, ZEND_RETURN_VALUE, 1, V8\\ArrayObject, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) + ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, property_filter, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, index_filter, IS_LONG, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_php_v8_object_GetOwnPropertyNames, ZEND_RETURN_VALUE, 1, V8\\ArrayObject, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) + ZEND_ARG_TYPE_INFO(0, filter, IS_LONG, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_php_v8_object_GetPrototype, ZEND_RETURN_VALUE, 0, V8\\Value, 0) @@ -1395,6 +1496,7 @@ static const zend_function_entry php_v8_object_methods[] = { PHP_ME(V8Object, Delete, arginfo_v8_object_Delete, ZEND_ACC_PUBLIC) PHP_ME(V8Object, SetAccessor, arginfo_v8_object_SetAccessor, ZEND_ACC_PUBLIC) PHP_ME(V8Object, SetAccessorProperty, arginfo_php_v8_object_SetAccessorProperty, ZEND_ACC_PUBLIC) + PHP_ME(V8Object, SetNativeDataProperty, arginfo_php_v8_object_SetNativeDataProperty, ZEND_ACC_PUBLIC) PHP_ME(V8Object, GetPropertyNames, arginfo_php_v8_object_GetPropertyNames, ZEND_ACC_PUBLIC) PHP_ME(V8Object, GetOwnPropertyNames, arginfo_php_v8_object_GetOwnPropertyNames, ZEND_ACC_PUBLIC) PHP_ME(V8Object, GetPrototype, arginfo_php_v8_object_GetPrototype, ZEND_ACC_PUBLIC) diff --git a/src/php_v8_object_template.cc b/src/php_v8_object_template.cc index 37282be..59c1e28 100644 --- a/src/php_v8_object_template.cc +++ b/src/php_v8_object_template.cc @@ -18,12 +18,11 @@ #include "php_v8_function_template.h" #include "php_v8_named_property_handler_configuration.h" #include "php_v8_indexed_property_handler_configuration.h" -#include "php_v8_property_attribute.h" -#include "php_v8_access_control.h" #include "php_v8_name.h" #include "php_v8_context.h" #include "php_v8_value.h" #include "php_v8_ext_mem_interface.h" +#include "php_v8_enums.h" #include "php_v8.h" zend_class_entry *php_v8_object_template_class_entry; @@ -209,8 +208,11 @@ static PHP_METHOD(V8ObjectTemplate, NewInstance) { static PHP_METHOD(V8ObjectTemplate, SetAccessor) { zval *php_v8_name_zv; + zval *php_v8_receiver_zv = NULL; + zend_long attributes = 0; zend_long settings = 0; + v8::Local signature; zend_fcall_info getter_fci = empty_fcall_info; zend_fcall_info_cache getter_fci_cache = empty_fcall_info_cache; @@ -218,12 +220,13 @@ static PHP_METHOD(V8ObjectTemplate, SetAccessor) { zend_fcall_info setter_fci = empty_fcall_info; zend_fcall_info_cache setter_fci_cache = empty_fcall_info_cache; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "of|f!ll", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "of|f!llo!", &php_v8_name_zv, &getter_fci, &getter_fci_cache, &setter_fci, &setter_fci_cache, &settings, - &attributes + &attributes, + &php_v8_receiver_zv ) == FAILURE) { return; } @@ -247,20 +250,26 @@ static PHP_METHOD(V8ObjectTemplate, SetAccessor) { v8::AccessorNameGetterCallback getter; v8::AccessorNameSetterCallback setter = 0; v8::Local data; - v8::Local signature; // TODO: add AccessorSignature support phpv8::CallbacksBucket *bucket = php_v8_object_template->persistent_data->bucket("accessor_", local_name->IsSymbol(), name); data = v8::External::New(isolate, bucket); - bucket->add(0, getter_fci, getter_fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache); getter = php_v8_callback_accessor_name_getter; if (setter_fci.size) { - bucket->add(1, setter_fci, setter_fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache); setter = php_v8_callback_accessor_name_setter; } + if (php_v8_receiver_zv) { + PHP_V8_FETCH_FUNCTION_TEMPLATE_WITH_CHECK(php_v8_receiver_zv, php_v8_receiver); + PHP_V8_DATA_ISOLATES_CHECK(php_v8_object_template, php_v8_receiver); + + signature = v8::AccessorSignature::New(isolate, php_v8_function_template_get_local(php_v8_receiver)); + } + local_obj_tpl->SetAccessor(local_name, getter, setter, @@ -353,7 +362,7 @@ static PHP_METHOD(V8ObjectTemplate, SetCallAsFunctionHandler) { phpv8::CallbacksBucket *bucket = php_v8_object_template->persistent_data->bucket("callback"); data = v8::External::New(isolate, bucket); - bucket->add(0, fci, fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Callback, fci, fci_cache); callback = php_v8_callback_function; } @@ -362,41 +371,6 @@ static PHP_METHOD(V8ObjectTemplate, SetCallAsFunctionHandler) { local_template->SetCallAsFunctionHandler(callback, data); } -// NOTE: Method is not supported anymore due to a limited use and a way it implemented (causes segfault under certain conditions) -/* -static PHP_METHOD(V8ObjectTemplate, MarkAsUndetectable) { - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - PHP_V8_FETCH_OBJECT_TEMPLATE_WITH_CHECK(getThis(), php_v8_object_template); - PHP_V8_ENTER_STORED_ISOLATE(php_v8_object_template); - - v8::Local local_template = php_v8_object_template_get_local(isolate, php_v8_object_template); - - local_template->MarkAsUndetectable(); -} -*/ - -// not used currently -static PHP_METHOD(V8ObjectTemplate, SetAccessCheckCallback) { - zend_fcall_info fci_callback = empty_fcall_info; - zend_fcall_info_cache fci_cache_callback = empty_fcall_info_cache; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "f", &fci_callback, &fci_cache_callback) == FAILURE) { - return; - } - - PHP_V8_FETCH_OBJECT_TEMPLATE_WITH_CHECK(getThis(), php_v8_object_template); - PHP_V8_ENTER_STORED_ISOLATE(php_v8_object_template); - - phpv8::CallbacksBucket *bucket = php_v8_object_template->persistent_data->bucket("access_check"); - bucket->add(0, fci_callback, fci_cache_callback); - - v8::Local local_template = php_v8_object_template_get_local(php_v8_object_template); - - local_template->SetAccessCheckCallback(php_v8_callback_access_check, v8::External::New(isolate, bucket)); -} /* Non-standard, implementations of AdjustableExternalMemoryInterface::AdjustExternalAllocatedMemory */ static PHP_METHOD(V8ObjectTemplate, AdjustExternalAllocatedMemory) { @@ -439,6 +413,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_object_template_SetNativeDataProperty, ZEN ZEND_ARG_CALLABLE_INFO(0, getter, 0) ZEND_ARG_CALLABLE_INFO(0, setter, 1) ZEND_ARG_TYPE_INFO(0, attributes, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, receiver, V8\\FunctionTemplate, 1) ZEND_ARG_TYPE_INFO(0, settings, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -455,6 +430,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_object_template_SetAccessor, ZEND_SEND_BY_ ZEND_ARG_CALLABLE_INFO(0, setter, 1) ZEND_ARG_TYPE_INFO(0, settings, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, attributes, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, receiver, V8\\FunctionTemplate, 1) ZEND_END_ARG_INFO() // void method @@ -472,21 +448,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_object_template_SetCallAsFunctionHandler, ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO() -// not used -// void method -/* -ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_object_template_MarkAsUndetectable, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -ZEND_END_ARG_INFO() -*/ - -// not used -// void method -/* -ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_object_template_SetAccessCheckCallback, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_CALLABLE_INFO(0, callback, 1) -ZEND_END_ARG_INFO() -*/ - PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_object_template_AdjustExternalAllocatedMemory, ZEND_RETURN_VALUE, 1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, change_in_bytes, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -511,8 +472,6 @@ static const zend_function_entry php_v8_object_template_methods[] = { PHP_ME(V8ObjectTemplate, SetHandlerForNamedProperty, arginfo_php_v8_object_template_SetHandlerForNamedProperty, ZEND_ACC_PUBLIC) PHP_ME(V8ObjectTemplate, SetHandlerForIndexedProperty, arginfo_php_v8_object_template_SetHandlerForIndexedProperty, ZEND_ACC_PUBLIC) PHP_ME(V8ObjectTemplate, SetCallAsFunctionHandler, arginfo_php_v8_object_template_SetCallAsFunctionHandler, ZEND_ACC_PUBLIC) -// PHP_ME(V8ObjectTemplate, MarkAsUndetectable, arginfo_php_v8_object_template_MarkAsUndetectable, ZEND_ACC_PUBLIC) -// PHP_ME(V8ObjectTemplate, SetAccessCheckCallback, arginfo_php_v8_object_template_SetAccessCheckCallback, ZEND_ACC_PUBLIC) PHP_ME(V8ObjectTemplate, AdjustExternalAllocatedMemory, arginfo_v8_object_template_AdjustExternalAllocatedMemory, ZEND_ACC_PUBLIC) PHP_ME(V8ObjectTemplate, GetExternalAllocatedMemory, arginfo_v8_object_template_GetExternalAllocatedMemory, ZEND_ACC_PUBLIC) diff --git a/src/php_v8_property_attribute.cc b/src/php_v8_property_attribute.cc deleted file mode 100644 index 1edaa26..0000000 --- a/src/php_v8_property_attribute.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_property_attribute.h" -#include "php_v8.h" - -zend_class_entry* php_v8_property_attribute_class_entry; -#define this_ce php_v8_property_attribute_class_entry - - -static const zend_function_entry php_v8_property_attribute_methods[] = { - PHP_FE_END -}; - -PHP_MINIT_FUNCTION(php_v8_property_attribute) { - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyAttribute", php_v8_property_attribute_methods); - this_ce = zend_register_internal_class(&ce); - - zend_declare_class_constant_long(this_ce, ZEND_STRL("None"), v8::PropertyAttribute::None); - zend_declare_class_constant_long(this_ce, ZEND_STRL("ReadOnly"), v8::PropertyAttribute::ReadOnly); - zend_declare_class_constant_long(this_ce, ZEND_STRL("DontEnum"), v8::PropertyAttribute::DontEnum); - zend_declare_class_constant_long(this_ce, ZEND_STRL("DontDelete"), v8::PropertyAttribute::DontDelete); - - return SUCCESS; -} diff --git a/src/php_v8_property_attribute.h b/src/php_v8_property_attribute.h deleted file mode 100644 index 9c8f1bf..0000000 --- a/src/php_v8_property_attribute.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_PROPERTY_ATTRIBUTE_H -#define PHP_V8_PROPERTY_ATTRIBUTE_H - -#include - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_property_attribute_class_entry; - -PHP_MINIT_FUNCTION (php_v8_property_attribute); - -#define PHP_V8_PROPERTY_ATTRIBUTE_FLAGS ( 0 \ - | v8::PropertyAttribute::None \ - | v8::PropertyAttribute::ReadOnly \ - | v8::PropertyAttribute::DontEnum \ - | v8::PropertyAttribute::DontDelete \ -) - - -#endif //PHP_V8_PROPERTY_ATTRIBUTE_H diff --git a/src/php_v8_property_handler_flags.cc b/src/php_v8_property_handler_flags.cc deleted file mode 100644 index 0a21d00..0000000 --- a/src/php_v8_property_handler_flags.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_property_handler_flags.h" -#include "php_v8.h" - -zend_class_entry* php_v8_property_handler_flags_class_entry; -#define this_ce php_v8_property_handler_flags_class_entry - - -static const zend_function_entry php_v8_property_handler_flags_methods[] = { - PHP_FE_END -}; - -PHP_MINIT_FUNCTION(php_v8_property_handler_flags) { - zend_class_entry ce; - INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyHandlerFlags", php_v8_property_handler_flags_methods); - this_ce = zend_register_internal_class(&ce); - - zend_declare_class_constant_long(this_ce, ZEND_STRL("kNone"), static_cast(v8::PropertyHandlerFlags::kNone)); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kAllCanRead"), static_cast(v8::PropertyHandlerFlags::kAllCanRead)); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kNonMasking"), static_cast(v8::PropertyHandlerFlags::kNonMasking)); - zend_declare_class_constant_long(this_ce, ZEND_STRL("kOnlyInterceptStrings"), static_cast(v8::PropertyHandlerFlags::kOnlyInterceptStrings)); - - return SUCCESS; -} diff --git a/src/php_v8_property_handler_flags.h b/src/php_v8_property_handler_flags.h deleted file mode 100644 index 961536d..0000000 --- a/src/php_v8_property_handler_flags.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_PROPERTY_HANDLER_FLAGS_H -#define PHP_V8_PROPERTY_HANDLER_FLAGS_H - -#include - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_property_handler_flags_class_entry; - -#define PHP_V8_PROPERTY_HANDLER_FLAGS ( 0 \ - | static_cast(v8::PropertyHandlerFlags::kNone) \ - | static_cast(v8::PropertyHandlerFlags::kAllCanRead) \ - | static_cast(v8::PropertyHandlerFlags::kNonMasking) \ - | static_cast(v8::PropertyHandlerFlags::kOnlyInterceptStrings) \ -) - -PHP_MINIT_FUNCTION (php_v8_property_handler_flags); - -#endif //PHP_V8_PROPERTY_HANDLER_FLAGS_H diff --git a/src/php_v8_script_compiler.cc b/src/php_v8_script_compiler.cc index 0f28a16..6066a35 100644 --- a/src/php_v8_script_compiler.cc +++ b/src/php_v8_script_compiler.cc @@ -15,7 +15,6 @@ #endif #include "php_v8_script_compiler.h" -#include "php_v8_compile_options.h" #include "php_v8_cached_data.h" #include "php_v8_script.h" #include "php_v8_script_origin.h" @@ -28,6 +27,7 @@ #include "php_v8.h" zend_class_entry* php_v8_script_compiler_class_entry; +zend_class_entry* php_v8_compile_options_class_entry; #define this_ce php_v8_script_compiler_class_entry @@ -285,6 +285,10 @@ static const zend_function_entry php_v8_script_compiler_methods[] = { PHP_FE_END }; +static const zend_function_entry php_v8_compile_options_methods[] = { + PHP_FE_END +}; + PHP_MINIT_FUNCTION(php_v8_script_compiler) { @@ -293,5 +297,17 @@ PHP_MINIT_FUNCTION(php_v8_script_compiler) INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "ScriptCompiler", php_v8_script_compiler_methods); this_ce = zend_register_internal_class(&ce); + #undef this_ce + #define this_ce php_v8_compile_options_class_entry + + INIT_NS_CLASS_ENTRY(ce, "V8\\ScriptCompiler", "CompileOptions", php_v8_compile_options_methods); + php_v8_compile_options_class_entry = zend_register_internal_class(&ce); + + zend_declare_class_constant_long(this_ce, ZEND_STRL("kNoCompileOptions"), v8::ScriptCompiler::CompileOptions::kNoCompileOptions); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kProduceParserCache"), v8::ScriptCompiler::CompileOptions::kProduceParserCache); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kConsumeParserCache"), v8::ScriptCompiler::CompileOptions::kConsumeParserCache); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kProduceCodeCache"), v8::ScriptCompiler::CompileOptions::kProduceCodeCache); + zend_declare_class_constant_long(this_ce, ZEND_STRL("kConsumeCodeCache"), v8::ScriptCompiler::CompileOptions::kConsumeCodeCache); + return SUCCESS; } diff --git a/src/php_v8_script_compiler.h b/src/php_v8_script_compiler.h index 4f98b04..0892bbc 100644 --- a/src/php_v8_script_compiler.h +++ b/src/php_v8_script_compiler.h @@ -22,6 +22,15 @@ extern "C" { } extern zend_class_entry *php_v8_script_compiler_class_entry; +extern zend_class_entry* php_v8_compile_options_class_entry; + +#define PHP_V8_CHECK_COMPILER_OPTIONS_RANGE(options, message) \ + if (options < static_cast(v8::ScriptCompiler::CompileOptions::kNoCompileOptions) \ + || options > static_cast(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache)) { \ + PHP_V8_THROW_VALUE_EXCEPTION(message); \ + return; \ + } + PHP_MINIT_FUNCTION(php_v8_script_compiler); diff --git a/src/php_v8_stack_frame.cc b/src/php_v8_stack_frame.cc index ab5e7a0..f964476 100644 --- a/src/php_v8_stack_frame.cc +++ b/src/php_v8_stack_frame.cc @@ -62,11 +62,10 @@ void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local(frame->IsEval())); + zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_eval"), static_cast(frame->IsEval())); /* v8::StackFrame::IsConstructor */ - zend_update_property_long(this_ce, return_value, ZEND_STRL("is_constructor"), - static_cast(frame->IsConstructor())); + zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_constructor"), static_cast(frame->IsConstructor())); } static PHP_METHOD(V8StackFrame, __construct) { diff --git a/src/php_v8_stack_trace.cc b/src/php_v8_stack_trace.cc index baa88fe..920dfd4 100644 --- a/src/php_v8_stack_trace.cc +++ b/src/php_v8_stack_trace.cc @@ -20,7 +20,6 @@ #include "php_v8.h" zend_class_entry* php_v8_stack_trace_class_entry; -zend_class_entry* php_v8_stack_trace_options_class_entry; #define this_ce php_v8_stack_trace_class_entry @@ -49,28 +48,19 @@ void php_v8_stack_trace_create_from_stack_trace(zval *return_value, php_v8_isola zend_update_property(this_ce, return_value, ZEND_STRL("frames"), &frames_array_zv); zval_ptr_dtor(&frames_array_zv); - - /* v8::StackTrace::AsArray */ - zval as_array_zv; - v8::Local local_frames_array_v8 = trace->AsArray(); - php_v8_get_or_create_value(&as_array_zv, local_frames_array_v8, php_v8_isolate); - zend_update_property(this_ce, return_value, ZEND_STRL("as_array"), &as_array_zv); - zval_ptr_dtor(&as_array_zv); } static PHP_METHOD(V8StackTrace, __construct) { zval *frames_zv = NULL; - zval *as_array_zv = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ao", &frames_zv, &as_array_zv) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &frames_zv) == FAILURE) { return; } // TODO: check that all frame items are instance of StackFrame zend_update_property(this_ce, getThis(), ZEND_STRL("frames"), frames_zv); - zend_update_property(this_ce, getThis(), ZEND_STRL("as_array"), as_array_zv); } static PHP_METHOD(V8StackTrace, getFrames) @@ -131,24 +121,12 @@ static PHP_METHOD(V8StackTrace, GetFrameCount) RETURN_LONG(cnt); } -static PHP_METHOD(V8StackTrace, AsArray) -{ - zval rv; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("as_array"), 0, &rv), 1, 0); -} - static PHP_METHOD(V8StackTrace, CurrentStackTrace) { zval *isolate_zv; zend_long frame_limit = 0; - zend_long options = static_cast(v8::StackTrace::StackTraceOptions::kOverview); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ol|l", &isolate_zv, &frame_limit, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ol", &isolate_zv, &frame_limit) == FAILURE) { return; } @@ -157,20 +135,15 @@ static PHP_METHOD(V8StackTrace, CurrentStackTrace) PHP_V8_ISOLATE_FETCH_WITH_CHECK(isolate_zv, php_v8_isolate); PHP_V8_DECLARE_ISOLATE(php_v8_isolate); - v8::Local trace = v8::StackTrace::CurrentStackTrace( - isolate, - static_cast(frame_limit), - static_cast(options & PHP_V8_STACK_TRACE_OPTIONS) - ); + v8::Local trace = v8::StackTrace::CurrentStackTrace(isolate, static_cast(frame_limit)); PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(trace, "Failed to get current stack trace"); php_v8_stack_trace_create_from_stack_trace(return_value, php_v8_isolate, trace); } -ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_stack_trace___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) +ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_stack_trace___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_TYPE_INFO(0, frames, IS_ARRAY, 0) - ZEND_ARG_OBJ_INFO(0, frames, V8\\ArrayObject, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_stack_trace_getFrames, ZEND_RETURN_VALUE, 0, IS_ARRAY, 0) @@ -183,16 +156,12 @@ ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_stack_trace_GetFrameCount, ZEND_RETURN_VALUE, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_stack_trace_AsArray, ZEND_RETURN_VALUE, 0, V8\\ArrayObject, 0) -ZEND_END_ARG_INFO() - - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_stack_trace_CurrentStackTrace, ZEND_RETURN_VALUE, 2, V8\\StackTrace, 1) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_stack_trace_CurrentStackTrace, ZEND_RETURN_VALUE, 2, V8\\StackTrace, 0) ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) ZEND_ARG_TYPE_INFO(0, frame_limit, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0) ZEND_END_ARG_INFO() + static const zend_function_entry php_v8_stack_trace_methods[] = { PHP_ME(V8StackTrace, __construct, arginfo_v8_stack_trace___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) @@ -201,16 +170,11 @@ static const zend_function_entry php_v8_stack_trace_methods[] = { PHP_ME(V8StackTrace, GetFrame, arginfo_v8_stack_trace_GetFrame, ZEND_ACC_PUBLIC) PHP_ME(V8StackTrace, GetFrameCount, arginfo_v8_stack_trace_GetFrameCount, ZEND_ACC_PUBLIC) - PHP_ME(V8StackTrace, AsArray, arginfo_v8_stack_trace_AsArray, ZEND_ACC_PUBLIC) PHP_ME(V8StackTrace, CurrentStackTrace, arginfo_v8_stack_trace_CurrentStackTrace, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END }; -static const zend_function_entry php_v8_stack_trace_options_methods[] = { - PHP_FE_END -}; - PHP_MINIT_FUNCTION (php_v8_stack_trace) { zend_class_entry ce; @@ -221,23 +185,6 @@ PHP_MINIT_FUNCTION (php_v8_stack_trace) { zend_declare_class_constant_long(this_ce, ZEND_STRL("MAX_FRAME_LIMIT"), PHP_V8_STACK_TRACE_MAX_FRAME_LIMIT); zend_declare_property_null(this_ce, ZEND_STRL("frames"), ZEND_ACC_PRIVATE); - zend_declare_property_null(this_ce, ZEND_STRL("as_array"), ZEND_ACC_PRIVATE); - - INIT_NS_CLASS_ENTRY(ce, "V8\\StackTrace", "StackTraceOptions", php_v8_stack_trace_options_methods); - php_v8_stack_trace_options_class_entry = zend_register_internal_class(&ce); - - - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kLineNumber"), v8::StackTrace::StackTraceOptions::kLineNumber); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kColumnOffset"), v8::StackTrace::StackTraceOptions::kColumnOffset); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kScriptName"), v8::StackTrace::StackTraceOptions::kScriptName); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kFunctionName"), v8::StackTrace::StackTraceOptions::kFunctionName); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kIsEval"), v8::StackTrace::StackTraceOptions::kIsEval); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kIsConstructor"), v8::StackTrace::StackTraceOptions::kIsConstructor); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kScriptNameOrSourceURL"), v8::StackTrace::StackTraceOptions::kScriptNameOrSourceURL); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kScriptId"), v8::StackTrace::StackTraceOptions::kScriptId); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kExposeFramesAcrossSecurityOrigins"), v8::StackTrace::StackTraceOptions::kExposeFramesAcrossSecurityOrigins); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kOverview"), v8::StackTrace::StackTraceOptions::kOverview); - zend_declare_class_constant_long(php_v8_stack_trace_options_class_entry, ZEND_STRL("kDetailed"), v8::StackTrace::StackTraceOptions::kDetailed); return SUCCESS; } diff --git a/src/php_v8_stack_trace.h b/src/php_v8_stack_trace.h index f3ff1c7..53d98f7 100644 --- a/src/php_v8_stack_trace.h +++ b/src/php_v8_stack_trace.h @@ -25,26 +25,12 @@ extern "C" { } extern zend_class_entry* php_v8_stack_trace_class_entry; -extern zend_class_entry* php_v8_stack_trace_options_class_entry; extern void php_v8_stack_trace_create_from_stack_trace(zval *return_value, php_v8_isolate_t *php_v8_isolate, v8::Local trace); #define PHP_V8_STACK_TRACE_MIN_FRAME_LIMIT 0 #define PHP_V8_STACK_TRACE_MAX_FRAME_LIMIT 1000 -#define PHP_V8_STACK_TRACE_OPTIONS ( 0 \ - | v8::StackTrace::StackTraceOptions::kLineNumber \ - | v8::StackTrace::StackTraceOptions::kColumnOffset \ - | v8::StackTrace::StackTraceOptions::kScriptName \ - | v8::StackTrace::StackTraceOptions::kFunctionName \ - | v8::StackTrace::StackTraceOptions::kIsEval \ - | v8::StackTrace::StackTraceOptions::kIsConstructor \ - | v8::StackTrace::StackTraceOptions::kScriptNameOrSourceURL \ - | v8::StackTrace::StackTraceOptions::kScriptId \ - | v8::StackTrace::StackTraceOptions::kExposeFramesAcrossSecurityOrigins \ - | v8::StackTrace::StackTraceOptions::kOverview \ - | v8::StackTrace::StackTraceOptions::kDetailed ) - #define PHP_V8_CHECK_STACK_TRACE_RANGE(val, message) \ if ((val) > PHP_V8_STACK_TRACE_MAX_FRAME_LIMIT || (val) < PHP_V8_STACK_TRACE_MIN_FRAME_LIMIT) { \ PHP_V8_THROW_VALUE_EXCEPTION(message); \ diff --git a/src/php_v8_symbol.cc b/src/php_v8_symbol.cc index be9d315..c68730c 100644 --- a/src/php_v8_symbol.cc +++ b/src/php_v8_symbol.cc @@ -116,95 +116,37 @@ static PHP_METHOD(V8Symbol, ForApi) php_v8_get_or_create_value(return_value, local_symbol, php_v8_context->php_v8_isolate); } -static PHP_METHOD(V8Symbol, GetIterator) -{ - zval *php_v8_isolate_zv; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { - return; - } - - PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); - PHP_V8_ENTER_ISOLATE(php_v8_isolate); - - v8::Local local_symbol = v8::Symbol::GetIterator(isolate); - - PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value"); - - php_v8_get_or_create_value(return_value, local_symbol, php_v8_isolate); -} - -static PHP_METHOD(V8Symbol, GetUnscopables) -{ - zval *php_v8_isolate_zv; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { - return; - } - - PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); - PHP_V8_ENTER_ISOLATE(php_v8_isolate); - - v8::Local local_symbol = v8::Symbol::GetUnscopables(isolate); - - PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value"); - - php_v8_get_or_create_value(return_value, local_symbol, php_v8_isolate); -} - -static PHP_METHOD(V8Symbol, GetToPrimitive) -{ - zval *php_v8_isolate_zv; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { - return; - } - - PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); - PHP_V8_ENTER_ISOLATE(php_v8_isolate); - - v8::Local local_symbol = v8::Symbol::GetToPrimitive(isolate); - - PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value"); - - php_v8_get_or_create_value(return_value, local_symbol, php_v8_isolate); -} - -static PHP_METHOD(V8Symbol, GetToStringTag) -{ - zval *php_v8_isolate_zv; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { - return; - } - - PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); - PHP_V8_ENTER_ISOLATE(php_v8_isolate); - - v8::Local local_symbol = v8::Symbol::GetToStringTag(isolate); - - PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value"); - - php_v8_get_or_create_value(return_value, local_symbol, php_v8_isolate); -} - -static PHP_METHOD(V8Symbol, GetIsConcatSpreadable) -{ - zval *php_v8_isolate_zv; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { - return; - } - - PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); - PHP_V8_ENTER_ISOLATE(php_v8_isolate); - - v8::Local local_symbol = v8::Symbol::GetIsConcatSpreadable(isolate); - - PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value"); - - php_v8_get_or_create_value(return_value, local_symbol, php_v8_isolate); -} +// Well-known symbols + +#define PHP_V8_SYMBOL_WELL_KNOWN_METHOD(classname, name) \ + PHP_METHOD(classname, name) \ + { \ + zval *php_v8_isolate_zv; \ + \ + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { \ + return; \ + } \ + \ + PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); \ + PHP_V8_ENTER_ISOLATE(php_v8_isolate); \ + \ + v8::Local local_symbol = v8::Symbol::name(isolate); \ + \ + PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value"); \ + \ + php_v8_get_or_create_value(return_value, local_symbol, php_v8_isolate); \ + } \ + +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetHasInstance); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetIsConcatSpreadable); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetIterator); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetMatch); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetReplace); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetSearch); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetSplit); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetToPrimitive); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetToStringTag); +static PHP_V8_SYMBOL_WELL_KNOWN_METHOD(V8Symbol, GetUnscopables); ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_symbol___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) @@ -225,25 +167,22 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_ForApi, ZEND_RET ZEND_ARG_OBJ_INFO(0, name, V8\\StringValue, 0) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetIterator, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) - ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetUnscopables, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) - ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetToPrimitive, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) - ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetToStringTag, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) - ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) -ZEND_END_ARG_INFO() +#define PHP_V8_SYMBOL_WELL_KNOWN_ARGS(name) \ + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) \ + ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) \ + ZEND_END_ARG_INFO() \ -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetIsConcatSpreadable, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) - ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) -ZEND_END_ARG_INFO() +// Well-known symbols +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetHasInstance); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetIsConcatSpreadable); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetIterator); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetMatch); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetReplace); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetSearch); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetSplit); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetToPrimitive); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetToStringTag); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_v8_symbol_GetUnscopables); static const zend_function_entry php_v8_symbol_methods[] = { @@ -254,11 +193,17 @@ static const zend_function_entry php_v8_symbol_methods[] = { PHP_ME(V8Symbol, For, arginfo_v8_symbol_For, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(V8Symbol, ForApi, arginfo_v8_symbol_ForApi, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(V8Symbol, GetIterator, arginfo_v8_symbol_GetIterator, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(V8Symbol, GetUnscopables, arginfo_v8_symbol_GetUnscopables, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(V8Symbol, GetToPrimitive, arginfo_v8_symbol_GetToPrimitive, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(V8Symbol, GetToStringTag, arginfo_v8_symbol_GetToStringTag, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(V8Symbol, GetIsConcatSpreadable, arginfo_v8_symbol_GetIsConcatSpreadable, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + // Well-known symbols + PHP_ME(V8Symbol, GetHasInstance, arginfo_v8_symbol_GetHasInstance, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetIsConcatSpreadable, arginfo_v8_symbol_GetIsConcatSpreadable, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetIterator, arginfo_v8_symbol_GetIterator, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetMatch, arginfo_v8_symbol_GetMatch, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetReplace, arginfo_v8_symbol_GetReplace, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetSearch, arginfo_v8_symbol_GetSearch, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetSplit, arginfo_v8_symbol_GetSplit, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetToPrimitive, arginfo_v8_symbol_GetToPrimitive, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetToStringTag, arginfo_v8_symbol_GetToStringTag, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(V8Symbol, GetUnscopables, arginfo_v8_symbol_GetUnscopables, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END }; diff --git a/src/php_v8_template.cc b/src/php_v8_template.cc index d2d1503..219c344 100644 --- a/src/php_v8_template.cc +++ b/src/php_v8_template.cc @@ -17,11 +17,10 @@ #include "php_v8_template.h" #include "php_v8_object_template.h" #include "php_v8_function_template.h" -#include "php_v8_property_attribute.h" -#include "php_v8_access_control.h" #include "php_v8_name.h" #include "php_v8_data.h" #include "php_v8_value.h" +#include "php_v8_enums.h" #include "php_v8.h" zend_class_entry *php_v8_template_ce; @@ -217,9 +216,7 @@ void php_v8_template_SetAccessorProperty(v8::Isolate *isolate, v8::Local loca template void php_v8_template_SetNativeDataProperty(v8::Isolate *isolate, v8::Local local_template, N* php_v8_template, INTERNAL_FUNCTION_PARAMETERS) { zval *php_v8_name_zv; - - zend_long attributes = v8::PropertyAttribute::None; - zend_long settings = v8::AccessControl::DEFAULT; + zval *php_v8_receiver_zv = NULL; zend_fcall_info getter_fci = empty_fcall_info; zend_fcall_info_cache getter_fci_cache = empty_fcall_info_cache; @@ -227,8 +224,20 @@ void php_v8_template_SetNativeDataProperty(v8::Isolate *isolate, v8::Local lo zend_fcall_info setter_fci = empty_fcall_info; zend_fcall_info_cache setter_fci_cache = empty_fcall_info_cache; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "of|f!ll", &php_v8_name_zv, &getter_fci, &getter_fci_cache, &setter_fci, &setter_fci_cache, &attributes, &settings) == - FAILURE) { + v8::AccessorNameGetterCallback getter; + v8::AccessorNameSetterCallback setter = 0; + + zend_long attributes = v8::PropertyAttribute::None; + v8::Local signature; + zend_long settings = v8::AccessControl::DEFAULT; + + v8::Local data; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), + "of|f!lo!l", + &php_v8_name_zv, &getter_fci, &getter_fci_cache, &setter_fci, &setter_fci_cache, + &attributes, &php_v8_receiver_zv, &settings + ) == FAILURE) { return; } @@ -240,24 +249,26 @@ void php_v8_template_SetNativeDataProperty(v8::Isolate *isolate, v8::Local lo v8::Local local_name = php_v8_value_get_local_as(php_v8_name); - v8::AccessorNameGetterCallback getter; - v8::AccessorNameSetterCallback setter = 0; - v8::Local data; - v8::Local signature; // TODO: add AccessorSignature support - PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name); phpv8::CallbacksBucket *bucket = php_v8_template->persistent_data->bucket("native_data_property_", local_name->IsSymbol(), name); data = v8::External::New(isolate, bucket); - bucket->add(0, getter_fci, getter_fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Getter, getter_fci, getter_fci_cache); getter = php_v8_callback_accessor_name_getter; if (setter_fci.size) { - bucket->add(1, setter_fci, setter_fci_cache); + bucket->add(phpv8::CallbacksBucket::Index::Setter, setter_fci, setter_fci_cache); setter = php_v8_callback_accessor_name_setter; } + if (php_v8_receiver_zv) { + PHP_V8_FETCH_FUNCTION_TEMPLATE_WITH_CHECK(php_v8_receiver_zv, php_v8_receiver); + PHP_V8_DATA_ISOLATES_CHECK(php_v8_template, php_v8_receiver); + + signature = v8::AccessorSignature::New(isolate, php_v8_function_template_get_local(php_v8_receiver)); + } + local_template->SetNativeDataProperty(local_name, getter, setter, @@ -290,6 +301,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_php_v8_template_SetNativeDataProperty, ZEND_SEND_ ZEND_ARG_CALLABLE_INFO(0, getter, 0) ZEND_ARG_CALLABLE_INFO(0, setter, 1) ZEND_ARG_TYPE_INFO(0, attributes, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, receiver, V8\\FunctionTemplate, 1) ZEND_ARG_TYPE_INFO(0, settings, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/src/php_v8_value.cc b/src/php_v8_value.cc index cbf730d..7c63312 100644 --- a/src/php_v8_value.cc +++ b/src/php_v8_value.cc @@ -874,24 +874,48 @@ static PHP_METHOD(V8Value, SameValue) { } static PHP_METHOD(V8Value, TypeOf) { - zval *php_v8_isolate_zv; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) { + if (zend_parse_parameters_none() == FAILURE) { return; } - PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate); PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value); - PHP_V8_DATA_ISOLATES_CHECK_USING(php_v8_value, php_v8_isolate); - PHP_V8_ENTER_STORED_ISOLATE(php_v8_value); v8::Local local_string = php_v8_value_get_local(php_v8_value)->TypeOf(isolate); PHP_V8_THROW_EXCEPTION_WHEN_EMPTY(local_string, "Failed to get type of value"); - php_v8_get_or_create_value(return_value, local_string, php_v8_isolate); + php_v8_get_or_create_value(return_value, local_string, php_v8_value->php_v8_isolate); +} + +static PHP_METHOD(V8Value, InstanceOf) { + zval *php_v8_context_zv; + zval *php_v8_value_object_zv; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "oo", &php_v8_context_zv, &php_v8_value_object_zv) == FAILURE) { + return; + } + + PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context); + PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value); + PHP_V8_VALUE_FETCH_WITH_CHECK(php_v8_value_object_zv, php_v8_value_object); + + PHP_V8_DATA_ISOLATES_CHECK(php_v8_value, php_v8_context); + PHP_V8_DATA_ISOLATES_CHECK(php_v8_value, php_v8_value_object); + + PHP_V8_ENTER_STORED_ISOLATE(php_v8_context); + PHP_V8_ENTER_CONTEXT(php_v8_context); + + PHP_V8_TRY_CATCH(isolate); + PHP_V8_INIT_ISOLATE_LIMITS_ON_CONTEXT(php_v8_context); + + v8::Maybe maybe_res = php_v8_value_get_local(php_v8_value)->InstanceOf(context, php_v8_value_get_local_as(php_v8_value_object)); + + PHP_V8_MAYBE_CATCH(php_v8_context, try_catch); + PHP_V8_THROW_EXCEPTION_WHEN_NOTHING(maybe_res, "Failed to check"); + + RETURN_BOOL(maybe_res.FromJust()); } @@ -1015,21 +1039,25 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_value_Uint32Value, ZEND_SEND_BY_VAL, ZEND_RETU ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_value_Equals, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_value_Equals, ZEND_RETURN_VALUE, 2, _IS_BOOL, 2) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) ZEND_ARG_OBJ_INFO(0, that, V8\\Value, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_value_StrictEquals, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_value_StrictEquals, ZEND_RETURN_VALUE, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, that, V8\\Value, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_value_SameValue, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_value_SameValue, ZEND_RETURN_VALUE, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, that, V8\\Value, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_value_TypeOf, ZEND_RETURN_VALUE, 0, V8\\StringValue, 0) - ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_value_InstanceOf, ZEND_RETURN_VALUE, 2, _IS_BOOL, 0) + ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) + ZEND_ARG_OBJ_INFO(0, object, V8\\ObjectValue, 0) ZEND_END_ARG_INFO() @@ -1107,6 +1135,7 @@ static const zend_function_entry php_v8_value_methods[] = { PHP_ME(V8Value, StrictEquals, arginfo_v8_value_StrictEquals, ZEND_ACC_PUBLIC) PHP_ME(V8Value, SameValue, arginfo_v8_value_SameValue, ZEND_ACC_PUBLIC) PHP_ME(V8Value, TypeOf, arginfo_v8_value_TypeOf, ZEND_ACC_PUBLIC) + PHP_ME(V8Value, InstanceOf, arginfo_v8_value_InstanceOf, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/stubs/src/AccessControl.php b/stubs/src/AccessControl.php index 408f17b..08c18aa 100644 --- a/stubs/src/AccessControl.php +++ b/stubs/src/AccessControl.php @@ -15,10 +15,10 @@ namespace V8; - class AccessControl { - const DEFAULT_ACCESS = 0; - const ALL_CAN_READ = 1; - const ALL_CAN_WRITE = 2; + const DEFAULT_ACCESS = 0; // do not allow cross-context access + const ALL_CAN_READ = 1; // all cross-context reads are allowed + const ALL_CAN_WRITE = 2; // all cross-context writes are allowed + // ALL_CAN_READ | ALL_CAN_WRITE could be use allow all cross-context access } diff --git a/stubs/src/AdjustableExternalMemoryInterface.php b/stubs/src/AdjustableExternalMemoryInterface.php index 3f14d6c..48dafaa 100644 --- a/stubs/src/AdjustableExternalMemoryInterface.php +++ b/stubs/src/AdjustableExternalMemoryInterface.php @@ -44,12 +44,12 @@ interface AdjustableExternalMemoryInterface * * NOTE: returned adjusted value can't be less then zero. */ - public function AdjustExternalAllocatedMemory(int $change_in_bytes) : int; + public function AdjustExternalAllocatedMemory(int $change_in_bytes): int; /** * Get external allocated memory hint value. * * @return int */ - public function GetExternalAllocatedMemory() : int; + public function GetExternalAllocatedMemory(): int; } diff --git a/stubs/src/ArrayObject.php b/stubs/src/ArrayObject.php index 2b6e9e3..e83e297 100644 --- a/stubs/src/ArrayObject.php +++ b/stubs/src/ArrayObject.php @@ -36,7 +36,7 @@ public function __construct(Context $context, int $length = 0) /** * @return int */ - public function Length() : int + public function Length(): int { } } diff --git a/stubs/src/BooleanObject.php b/stubs/src/BooleanObject.php index 3aa7b17..4b87dd7 100644 --- a/stubs/src/BooleanObject.php +++ b/stubs/src/BooleanObject.php @@ -33,7 +33,7 @@ public function __construct(Context $context, bool $value) /** * @return bool */ - public function ValueOf() : bool + public function ValueOf(): bool { } } diff --git a/stubs/src/BooleanValue.php b/stubs/src/BooleanValue.php index a4e2e1c..78311a4 100644 --- a/stubs/src/BooleanValue.php +++ b/stubs/src/BooleanValue.php @@ -33,7 +33,7 @@ public function __construct(Isolate $isolate, bool $value) /** * @return bool */ - public function Value() : bool + public function Value(): bool { } } diff --git a/stubs/src/CallbackInfo.php b/stubs/src/CallbackInfo.php index 66b8e8c..485852c 100644 --- a/stubs/src/CallbackInfo.php +++ b/stubs/src/CallbackInfo.php @@ -20,35 +20,35 @@ class CallbackInfo /** * @return \V8\Isolate */ - public function GetIsolate() : Isolate + public function GetIsolate(): Isolate { } /** * @return \V8\Context */ - public function GetContext() : Context + public function GetContext(): Context { } /** * @return \V8\ObjectValue */ - public function This() : ObjectValue + public function This(): ObjectValue { } /** * @return \V8\ObjectValue */ - public function Holder() : ObjectValue + public function Holder(): ObjectValue { } /** * @return \V8\ReturnValue */ - public function GetReturnValue() : ReturnValue + public function GetReturnValue(): ReturnValue { } } diff --git a/stubs/src/ConstructorBehavior.php b/stubs/src/ConstructorBehavior.php new file mode 100644 index 0000000..1914410 --- /dev/null +++ b/stubs/src/ConstructorBehavior.php @@ -0,0 +1,23 @@ + + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + +namespace V8; + + +class ConstructorBehavior +{ + const kThrow = 0; + const kAllow = 1; +} diff --git a/stubs/src/Context.php b/stubs/src/Context.php index b99cb5b..8d9796d 100644 --- a/stubs/src/Context.php +++ b/stubs/src/Context.php @@ -55,7 +55,7 @@ public function __construct( /** * @return \V8\Isolate */ - public function GetIsolate() : Isolate + public function GetIsolate(): Isolate { return $this->isolate; } @@ -74,7 +74,7 @@ public function GetIsolate() : Isolate * * @return \V8\ObjectValue */ - public function GlobalObject() : ObjectValue + public function GlobalObject(): ObjectValue { } @@ -87,7 +87,6 @@ public function DetachGlobal() { } - /** * Sets the security token for the context. To access an object in * another context, the security tokens must match. @@ -110,7 +109,7 @@ public function UseDefaultSecurityToken() * * @return \V8\Value */ - public function GetSecurityToken() : Value + public function GetSecurityToken(): Value { } @@ -139,7 +138,7 @@ public function AllowCodeGenerationFromStrings(bool $allow) * * @return bool */ - public function IsCodeGenerationFromStringsAllowed() : bool + public function IsCodeGenerationFromStringsAllowed(): bool { } @@ -153,11 +152,4 @@ public function IsCodeGenerationFromStringsAllowed() : bool public function SetErrorMessageForCodeGenerationFromStrings(StringValue $message) { } - - /** - * Estimate the memory in bytes retained by this context. - */ - public function EstimatedSize() : int - { - } } diff --git a/stubs/src/DateObject.php b/stubs/src/DateObject.php index 4ba91de..60d3624 100644 --- a/stubs/src/DateObject.php +++ b/stubs/src/DateObject.php @@ -33,7 +33,7 @@ public function __construct(Context $context, double $value) /** * @return double */ - public function ValueOf() : double + public function ValueOf(): double { } @@ -51,5 +51,7 @@ public function ValueOf() : double * * @param \V8\Isolate $isolate */ - public static function DateTimeConfigurationChangeNotification(Isolate $isolate){} + public static function DateTimeConfigurationChangeNotification(Isolate $isolate) + { + } } diff --git a/stubs/src/Exception.php b/stubs/src/Exception.php index 9deb8d8..bcb6cb2 100644 --- a/stubs/src/Exception.php +++ b/stubs/src/Exception.php @@ -28,7 +28,7 @@ class Exception * * @return Value */ - public static function RangeError(Context $context, StringValue $message) : Value + public static function RangeError(Context $context, StringValue $message): Value { } @@ -38,7 +38,7 @@ public static function RangeError(Context $context, StringValue $message) : Valu * * @return Value */ - public static function ReferenceError(Context $context, StringValue $message) : Value + public static function ReferenceError(Context $context, StringValue $message): Value { } @@ -48,7 +48,7 @@ public static function ReferenceError(Context $context, StringValue $message) : * * @return Value */ - public static function SyntaxError(Context $context, StringValue $message) : Value + public static function SyntaxError(Context $context, StringValue $message): Value { } @@ -58,7 +58,7 @@ public static function SyntaxError(Context $context, StringValue $message) : Val * * @return Value */ - public static function TypeError(Context $context, StringValue $message) : Value + public static function TypeError(Context $context, StringValue $message): Value { } @@ -68,7 +68,7 @@ public static function TypeError(Context $context, StringValue $message) : Value * * @return Value */ - public static function Error(Context $context, StringValue $message) : Value + public static function Error(Context $context, StringValue $message): Value { } @@ -82,7 +82,7 @@ public static function Error(Context $context, StringValue $message) : Value * * @return Message */ - static function CreateMessage(Context $context, Value $exception) : Message + static function CreateMessage(Context $context, Value $exception): Message { } diff --git a/stubs/src/Exceptions/TryCatchException.php b/stubs/src/Exceptions/TryCatchException.php index 27e29ab..f5a01ac 100644 --- a/stubs/src/Exceptions/TryCatchException.php +++ b/stubs/src/Exceptions/TryCatchException.php @@ -37,15 +37,15 @@ class TryCatchException extends Exception public function __construct(Isolate $isolate, Context $context, TryCatch $try_catch) { - $this->isolate = $isolate; - $this->context = $context; + $this->isolate = $isolate; + $this->context = $context; $this->try_catch = $try_catch; } /** * @return Isolate */ - public function GetIsolate() : Isolate + public function GetIsolate(): Isolate { return $this->isolate; } @@ -53,7 +53,7 @@ public function GetIsolate() : Isolate /** * @return Context */ - public function GetContext() : Context + public function GetContext(): Context { return $this->context; } @@ -61,7 +61,7 @@ public function GetContext() : Context /** * @return TryCatch */ - public function GetTryCatch() : TryCatch + public function GetTryCatch(): TryCatch { return $this->try_catch; } diff --git a/stubs/src/FunctionCallbackInfo.php b/stubs/src/FunctionCallbackInfo.php index e2676ec..64150c2 100644 --- a/stubs/src/FunctionCallbackInfo.php +++ b/stubs/src/FunctionCallbackInfo.php @@ -27,25 +27,25 @@ class FunctionCallbackInfo extends CallbackInfo /** * @return int */ - public function Length() : int + public function Length(): int { } /** * @return Value[] | StringValue[] | SymbolValue[] | NumberValue[] | ObjectValue[] | ArrayObject[] | FunctionObject[] | StringObject[] | SymbolObject[] */ - public function Arguments() : array + public function Arguments(): array { } - public function NewTarget() : Value + public function NewTarget(): Value { } /** * @return bool */ - public function IsConstructCall() : bool + public function IsConstructCall(): bool { } } diff --git a/stubs/src/FunctionObject.php b/stubs/src/FunctionObject.php index 2e111a7..fbe5b07 100644 --- a/stubs/src/FunctionObject.php +++ b/stubs/src/FunctionObject.php @@ -28,8 +28,9 @@ class FunctionObject extends ObjectValue * @param \V8\Context $context * @param callable $callback * @param int $length + * @param int $behavior */ - public function __construct(Context $context, callable $callback, int $length = 0) + public function __construct(Context $context, callable $callback, int $length = 0, int $behavior = ConstructorBehavior::kAllow) { parent::__construct($context); } @@ -40,7 +41,7 @@ public function __construct(Context $context, callable $callback, int $length = * * @return \V8\ObjectValue */ - public function NewInstance(Context $context, array $arguments = []) : ObjectValue + public function NewInstance(Context $context, array $arguments = []): ObjectValue { } @@ -51,7 +52,7 @@ public function NewInstance(Context $context, array $arguments = []) : ObjectVal * * @return \V8\Value */ - public function Call(Context $context, Value $recv, array $arguments = []) : Value + public function Call(Context $context, Value $recv, array $arguments = []): Value { } @@ -65,7 +66,7 @@ public function SetName(StringValue $name) /** * @return \V8\Value | StringValue */ - public function GetName() : Value + public function GetName(): Value { } @@ -77,7 +78,7 @@ public function GetName() : Value * * @return \V8\Value | StringValue */ - public function GetInferredName() : Value + public function GetInferredName(): Value { } @@ -87,7 +88,7 @@ public function GetInferredName() : Value * * @return \V8\Value | StringValue */ - public function GetDisplayName() : Value + public function GetDisplayName(): Value { } @@ -126,14 +127,14 @@ public function GetScriptColumnNumber() * * @return Value */ - public function GetBoundFunction() : Value + public function GetBoundFunction(): Value { } /** * @return ScriptOrigin */ - public function GetScriptOrigin() : ScriptOrigin + public function GetScriptOrigin(): ScriptOrigin { } } diff --git a/stubs/src/FunctionTemplate.php b/stubs/src/FunctionTemplate.php index efb7bb1..025d493 100644 --- a/stubs/src/FunctionTemplate.php +++ b/stubs/src/FunctionTemplate.php @@ -25,7 +25,7 @@ * preferred. * * Any modification of a FunctionTemplate after first instantiation will trigger - *a crash. + * a crash. * * A FunctionTemplate can have properties, these properties are added to the * function object when it is created. @@ -41,17 +41,21 @@ * The following example shows how to use a FunctionTemplate: * * \code - * v8::Local t = v8::FunctionTemplate::New(); - * t->Set("func_property", v8::Number::New(1)); + * v8::Local t = v8::FunctionTemplate::New(isolate); + * t->Set(isolate, "func_property", v8::Number::New(isolate, 1)); * * v8::Local proto_t = t->PrototypeTemplate(); - * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); - * proto_t->Set("proto_const", v8::Number::New(2)); + * proto_t->Set(isolate, + * "proto_method", + * v8::FunctionTemplate::New(isolate, InvokeCallback)); + * proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2)); * * v8::Local instance_t = t->InstanceTemplate(); - * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); - * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); - * instance_t->Set("instance_property", Number::New(3)); + * instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"), + * InstanceAccessorCallback); + * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback); + * instance_t->Set(String::NewFromUtf8(isolate, "instance_property"), + * Number::New(isolate, 3)); * * v8::Local function = t->GetFunction(); * v8::Local instance = function->NewInstance(); @@ -111,27 +115,25 @@ * child_instance.instance_property == 3; * \endcode */ -//class FunctionTemplateInterface extends TemplateInterface class FunctionTemplate extends Template implements AdjustableExternalMemoryInterface { - private $isolate; - - //static Local New( - // Isolate* isolate, - // FunctionCallback callback = 0, - // Handle data = Handle(), - // Handle signature = Handle(), - // int length = 0); - public function __construct(Isolate $isolate, callable $callback = null, int $length=0) - { + /** + * @param Isolate $isolate + * @param callable|null $callback + * @param FunctionTemplate|null $receiver Specifies which receiver is valid for a function + * @param int $length + * @param int $behavior + */ + public function __construct( + Isolate $isolate, + callable $callback = null, + FunctionTemplate $receiver = null, + int $length = 0, + int $behavior = ConstructorBehavior::kAllow + ) { parent::__construct($isolate); } - public function GetIsolate() - { - return $this->isolate; - } - /** * Returns the unique function instance in the current execution context. * @@ -139,7 +141,7 @@ public function GetIsolate() * * @return FunctionObject */ - public function GetFunction(Context $context) : FunctionObject + public function GetFunction(Context $context): FunctionObject { } @@ -164,7 +166,7 @@ public function SetLength(int $length) * * @return \V8\ObjectTemplate */ - public function InstanceTemplate() : ObjectTemplate + public function InstanceTemplate(): ObjectTemplate { } @@ -183,7 +185,7 @@ public function Inherit(FunctionTemplate $parent) * * @return \V8\ObjectTemplate */ - public function PrototypeTemplate() : ObjectTemplate + public function PrototypeTemplate(): ObjectTemplate { } @@ -245,21 +247,21 @@ public function RemovePrototype() * * @return bool */ - public function HasInstance(Value $object) : bool + public function HasInstance(Value $object): bool { } /** * {@inheritdoc} */ - public function AdjustExternalAllocatedMemory(int $change_in_bytes) : int + public function AdjustExternalAllocatedMemory(int $change_in_bytes): int { } /** * {@inheritdoc} */ - public function GetExternalAllocatedMemory() : int + public function GetExternalAllocatedMemory(): int { } } diff --git a/stubs/src/HeapStatistics.php b/stubs/src/HeapStatistics.php index f34d4b0..7dd3abb 100644 --- a/stubs/src/HeapStatistics.php +++ b/stubs/src/HeapStatistics.php @@ -82,58 +82,58 @@ public function __construct( float $peak_malloced_memory, bool $does_zap_garbage ) { - $this->total_heap_size = $total_heap_size; + $this->total_heap_size = $total_heap_size; $this->total_heap_size_executable = $total_heap_size_executable; - $this->total_physical_size = $total_physical_size; - $this->total_available_size = $total_available_size; - $this->used_heap_size = $used_heap_size; - $this->heap_size_limit = $heap_size_limit; - $this->malloced_memory = $malloced_memory; - $this->peak_malloced_memory = $peak_malloced_memory; - $this->does_zap_garbage = $does_zap_garbage; + $this->total_physical_size = $total_physical_size; + $this->total_available_size = $total_available_size; + $this->used_heap_size = $used_heap_size; + $this->heap_size_limit = $heap_size_limit; + $this->malloced_memory = $malloced_memory; + $this->peak_malloced_memory = $peak_malloced_memory; + $this->does_zap_garbage = $does_zap_garbage; } - public function total_heap_size() : float + public function total_heap_size(): float { return $this->total_heap_size; } - public function total_heap_size_executable() : float + public function total_heap_size_executable(): float { return $this->total_heap_size_executable; } - public function total_physical_size() : float + public function total_physical_size(): float { return $this->total_physical_size; } - public function total_available_size() : float + public function total_available_size(): float { return $this->total_available_size; } - public function used_heap_size() : float + public function used_heap_size(): float { return $this->used_heap_size; } - public function heap_size_limit() : float + public function heap_size_limit(): float { return $this->heap_size_limit; } - public function malloced_memory() : float + public function malloced_memory(): float { return $this->malloced_memory; } - public function peak_malloced_memory() : float + public function peak_malloced_memory(): float { return $this->peak_malloced_memory; } - public function does_zap_garbage() : bool + public function does_zap_garbage(): bool { return $this->does_zap_garbage; } diff --git a/stubs/src/IndexFilter.php b/stubs/src/IndexFilter.php new file mode 100644 index 0000000..4ee7c9d --- /dev/null +++ b/stubs/src/IndexFilter.php @@ -0,0 +1,22 @@ + + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + +namespace V8; + +class IndexFilter +{ + const kIncludeIndices = 0; // allows for integer indices to be collected, while + const kSkipIndices = 1; // will exclude integer indicies from being collected. +} diff --git a/stubs/src/IndexedPropertyHandlerConfiguration.php b/stubs/src/IndexedPropertyHandlerConfiguration.php index 77ce0be..37bf03a 100644 --- a/stubs/src/IndexedPropertyHandlerConfiguration.php +++ b/stubs/src/IndexedPropertyHandlerConfiguration.php @@ -19,20 +19,20 @@ class IndexedPropertyHandlerConfiguration { /** - * @param callable $getter The callback to invoke when getting a property. - * @param callable $setter The callback to invoke when setting a property. - * @param callable $query The callback to invoke to check if an object has a property. - * @param callable $deleter The callback to invoke when deleting a property. + * @param callable $getter The callback to invoke when getting a property. + * @param callable $setter The callback to invoke when setting a property. + * @param callable $query The callback to invoke to check if an object has a property. + * @param callable $deleter The callback to invoke when deleting a property. * @param callable $enumerator The callback to invoke to enumerate all the indexed properties of an object. - * @param int $flags One of \v8\PropertyHandlerFlags constants + * @param int $flags One of \v8\PropertyHandlerFlags constants */ - public function __construct(callable $getter, - callable $setter = null, - callable $query = null, - callable $deleter = null, - callable $enumerator = null, - $flags = PropertyHandlerFlags::kNone - ) - { + public function __construct( + callable $getter, + callable $setter = null, + callable $query = null, + callable $deleter = null, + callable $enumerator = null, + $flags = PropertyHandlerFlags::kNone + ) { } } diff --git a/stubs/src/Int32Value.php b/stubs/src/Int32Value.php index 23a9121..28ce204 100644 --- a/stubs/src/Int32Value.php +++ b/stubs/src/Int32Value.php @@ -18,7 +18,8 @@ /** * A JavaScript value representing a 32-bit signed integer. */ -class Int32Value extends IntegerValue { +class Int32Value extends IntegerValue +{ /** * @param Isolate $isolate * @param int $value Should be valid int32 value @@ -31,7 +32,7 @@ public function __construct(Isolate $isolate, int $value) /** * @return int int32 value */ - public function Value() : int + public function Value(): int { } } diff --git a/stubs/src/IntegerValue.php b/stubs/src/IntegerValue.php index 29a3bb5..b4d61d8 100644 --- a/stubs/src/IntegerValue.php +++ b/stubs/src/IntegerValue.php @@ -32,7 +32,7 @@ public function __construct(Isolate $isolate, int $value) /** * @return int int64 value */ - public function Value() : int + public function Value(): int { } } diff --git a/stubs/src/Isolate.php b/stubs/src/Isolate.php index 097ad62..7ca9ef7 100644 --- a/stubs/src/Isolate.php +++ b/stubs/src/Isolate.php @@ -15,8 +15,6 @@ namespace V8; -use V8\StackTrace\StackTraceOptions; - class Isolate { /** @@ -37,11 +35,11 @@ public function SetMemoryLimit(int $memory_limit_in_bytes) { } - public function GetMemoryLimit() : int + public function GetMemoryLimit(): int { } - public function IsMemoryLimitHit() : bool + public function IsMemoryLimitHit(): bool { } @@ -49,13 +47,14 @@ public function SetTimeLimit(float $time_limit_in_seconds) { } - public function GetTimeLimit() : float + public function GetTimeLimit(): float { } - public function IsTimeLimitHit() : bool + public function IsTimeLimitHit(): bool { } + /** * @return StartupData | null */ @@ -68,7 +67,7 @@ public function GetSnapshot() * * @return HeapStatistics */ - public function GetHeapStatistics() : HeapStatistics + public function GetHeapStatistics(): HeapStatistics { } @@ -77,7 +76,7 @@ public function GetHeapStatistics() : HeapStatistics * * @return bool */ - public function InContext() : bool + public function InContext(): bool { } @@ -86,7 +85,7 @@ public function InContext() : bool * * @return \V8\Context */ - public function GetEnteredContext() : Context + public function GetEnteredContext(): Context { } @@ -97,11 +96,11 @@ public function GetEnteredContext() : Context * has been handled does it become legal to invoke JavaScript operations. * * @param Context $context - * @param Value $value + * @param Value $value * * @return Value */ - public function ThrowException(Context $context, Value $value) : Value + public function ThrowException(Context $context, Value $value): Value { } @@ -126,7 +125,7 @@ public function TerminateExecution() * * @return bool */ - public function IsExecutionTerminating() : bool + public function IsExecutionTerminating(): bool { } @@ -180,7 +179,7 @@ public function CancelTerminateExecution() * * @return bool */ - public function IdleNotificationDeadline($deadline_in_seconds) : bool + public function IdleNotificationDeadline($deadline_in_seconds): bool { } @@ -198,7 +197,7 @@ public function LowMemoryNotification() * * @return bool */ - public function IsDead() : bool + public function IsDead(): bool { } @@ -208,7 +207,7 @@ public function IsDead() : bool * * @return bool */ - public function IsInUse() : bool + public function IsInUse(): bool { } @@ -218,13 +217,8 @@ public function IsInUse() : bool * * @param bool $capture * @param int $frame_limit - * @param int $options */ - public function SetCaptureStackTraceForUncaughtExceptions( - bool $capture, - int $frame_limit = 10, - int $options = StackTraceOptions::kOverview - ) + public function SetCaptureStackTraceForUncaughtExceptions(bool $capture, int $frame_limit = 10) { } } diff --git a/stubs/src/KeyCollectionMode.php b/stubs/src/KeyCollectionMode.php new file mode 100644 index 0000000..66ffa63 --- /dev/null +++ b/stubs/src/KeyCollectionMode.php @@ -0,0 +1,25 @@ + + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + +namespace V8; + +/** + * Keys/Properties filter to limits the range of collected properties + */ +class KeyCollectionMode +{ + const kOwnOnly = 0; // limits the collected properties to the given Object only. kIncludesPrototypes + const kIncludesPrototypes = 1; // will include all keys of the objects's prototype chain as well. +} diff --git a/stubs/src/MapObject.php b/stubs/src/MapObject.php index 3046c33..74c2432 100644 --- a/stubs/src/MapObject.php +++ b/stubs/src/MapObject.php @@ -31,7 +31,7 @@ public function Clear() /** * @param Context $context - * @param Value $key + * @param Value $key * * //TODO: add throws * @@ -43,8 +43,8 @@ public function Get(Context $context, Value $key): Value /** * @param Context $context - * @param Value $key - * @param Value $value + * @param Value $key + * @param Value $value * * //TODO: add throws * @@ -56,7 +56,7 @@ public function Set(Context $context, Value $key, Value $value): MapObject /** * @param Context $context - * @param Value $key + * @param Value $key * * @return bool */ @@ -66,7 +66,7 @@ public function Has(Context $context, Value $key): bool /** * @param Context $context - * @param Value $key + * @param Value $key * * @return bool */ diff --git a/stubs/src/Message.php b/stubs/src/Message.php index 80218a5..d4024c0 100644 --- a/stubs/src/Message.php +++ b/stubs/src/Message.php @@ -87,38 +87,39 @@ class Message * @param bool $is_shared_cross_origin * @param bool $is_opaque */ - public function __construct(string $message, - string $source_line, - ScriptOrigin $script_origin, - string $resource_name, - StackTrace $stack_trace, - int $line_number = self::kNoLineNumberInfo, - int $start_position = -1, - int $end_position = -1, - int $start_column = self::kNoColumnInfo, - int $end_column = self::kNoColumnInfo, - bool $is_shared_cross_origin = false, - bool $is_opaque = false) - { - $this->message = $message; - $this->source_line = $source_line; - $this->script_origin = $script_origin; - $this->resource_name = $resource_name; - $this->stack_trace = $stack_trace; - $this->line_number = $line_number; - $this->start_position = $start_position; - $this->end_position = $end_position; - $this->start_column = $start_column; - $this->end_column = $end_column; + public function __construct( + string $message, + string $source_line, + ScriptOrigin $script_origin, + string $resource_name, + StackTrace $stack_trace, + int $line_number = self::kNoLineNumberInfo, + int $start_position = -1, + int $end_position = -1, + int $start_column = self::kNoColumnInfo, + int $end_column = self::kNoColumnInfo, + bool $is_shared_cross_origin = false, + bool $is_opaque = false + ) { + $this->message = $message; + $this->source_line = $source_line; + $this->script_origin = $script_origin; + $this->resource_name = $resource_name; + $this->stack_trace = $stack_trace; + $this->line_number = $line_number; + $this->start_position = $start_position; + $this->end_position = $end_position; + $this->start_column = $start_column; + $this->end_column = $end_column; $this->is_shared_cross_origin = $is_shared_cross_origin; - $this->is_opaque = $is_opaque; + $this->is_opaque = $is_opaque; } /** * @return string */ - public function Get() : string + public function Get(): string { } @@ -127,7 +128,7 @@ public function Get() : string * * @return string */ - public function GetSourceLine() : string + public function GetSourceLine(): string { } @@ -137,7 +138,7 @@ public function GetSourceLine() : string * * @return ScriptOrigin */ - public function GetScriptOrigin() : ScriptOrigin + public function GetScriptOrigin(): ScriptOrigin { } @@ -147,7 +148,7 @@ public function GetScriptOrigin() : ScriptOrigin * * @return string */ - public function GetScriptResourceName() : string + public function GetScriptResourceName(): string { } @@ -158,7 +159,7 @@ public function GetScriptResourceName() : string * * @return StackTrace */ - public function GetStackTrace() : StackTrace + public function GetStackTrace(): StackTrace { } @@ -167,7 +168,7 @@ public function GetStackTrace() : StackTrace * * @return int */ - public function GetLineNumber() : int + public function GetLineNumber(): int { } @@ -177,7 +178,7 @@ public function GetLineNumber() : int * * @return int */ - public function GetStartPosition() : int + public function GetStartPosition(): int { } @@ -187,7 +188,7 @@ public function GetStartPosition() : int * * @return int */ - public function GetEndPosition() : int + public function GetEndPosition(): int { } @@ -197,7 +198,7 @@ public function GetEndPosition() : int * * @return int */ - public function GetStartColumn() : int + public function GetStartColumn(): int { } @@ -207,7 +208,7 @@ public function GetStartColumn() : int * * @return int */ - public function GetEndColumn() : int + public function GetEndColumn(): int { } @@ -217,14 +218,14 @@ public function GetEndColumn() : int * * @return bool */ - public function IsSharedCrossOrigin() : bool + public function IsSharedCrossOrigin(): bool { } /** * @return bool */ - public function IsOpaque() : bool + public function IsOpaque(): bool { } } diff --git a/stubs/src/NameValue.php b/stubs/src/NameValue.php index bb4e153..10f5ac3 100644 --- a/stubs/src/NameValue.php +++ b/stubs/src/NameValue.php @@ -28,7 +28,7 @@ class NameValue extends PrimitiveValue * The return value will never be 0. Also, it is not guaranteed to be * unique. */ - public function GetIdentityHash() : int + public function GetIdentityHash(): int { } } diff --git a/stubs/src/NamedPropertyHandlerConfiguration.php b/stubs/src/NamedPropertyHandlerConfiguration.php index c7edd22..c3af63d 100644 --- a/stubs/src/NamedPropertyHandlerConfiguration.php +++ b/stubs/src/NamedPropertyHandlerConfiguration.php @@ -19,20 +19,20 @@ class NamedPropertyHandlerConfiguration { /** - * @param callable $getter The callback to invoke when getting a property. - * @param callable $setter The callback to invoke when setting a property. - * @param callable $query The callback to invoke to check if a property is present, and if present, get its attributes. - * @param callable $deleter The callback to invoke when deleting a property. + * @param callable $getter The callback to invoke when getting a property. + * @param callable $setter The callback to invoke when setting a property. + * @param callable $query The callback to invoke to check if a property is present, and if present, get its attributes. + * @param callable $deleter The callback to invoke when deleting a property. * @param callable $enumerator The callback to invoke to enumerate all the named properties of an object. - * @param int $flags One of \v8\PropertyHandlerFlags constants + * @param int $flags One of \v8\PropertyHandlerFlags constants */ - public function __construct(callable $getter, - callable $setter = null, - callable $query = null, - callable $deleter = null, - callable $enumerator = null, - $flags = PropertyHandlerFlags::kNone - ) - { + public function __construct( + callable $getter, + callable $setter = null, + callable $query = null, + callable $deleter = null, + callable $enumerator = null, + $flags = PropertyHandlerFlags::kNone + ) { } } diff --git a/stubs/src/NumberValue.php b/stubs/src/NumberValue.php index 3e7cd68..781cc39 100644 --- a/stubs/src/NumberValue.php +++ b/stubs/src/NumberValue.php @@ -22,7 +22,7 @@ class NumberValue extends PrimitiveValue { /** * @param Isolate $isolate - * @param float $value + * @param float $value */ public function __construct(Isolate $isolate, float $value) { diff --git a/stubs/src/ObjectTemplate.php b/stubs/src/ObjectTemplate.php index 70b1c39..7fe8c79 100644 --- a/stubs/src/ObjectTemplate.php +++ b/stubs/src/ObjectTemplate.php @@ -35,7 +35,7 @@ public function __construct(Isolate $isolate, FunctionTemplate $constructor = nu * * @return \V8\ObjectValue */ - public function NewInstance(Context $context) : ObjectValue + public function NewInstance(Context $context): ObjectValue { } @@ -47,56 +47,36 @@ public function NewInstance(Context $context) : ObjectValue * are called instead of getting and setting the property directly * on the JavaScript object. * - * \param name The name of the property for which an accessor is added. - * \param getter The callback to invoke when getting the property. - * \param setter The callback to invoke when setting the property. - * \param data A piece of data that will be passed to the getter and setter - * callbacks whenever they are invoked. - * \param settings Access control settings for the accessor. This is a bit - * field consisting of one of more of - * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. - * The default is to not allow cross-context access. - * ALL_CAN_READ means that all cross-context reads are allowed. - * ALL_CAN_WRITE means that all cross-context writes are allowed. - * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all - * cross-context access. - * \param attribute The attributes of the property for which an accessor - * is added. - * \param signature The signature describes valid receivers for the accessor - * and is used to perform implicit instance checks against them. If the - * receiver is incompatible (i.e. is not an instance of the constructor as - * defined by FunctionTemplate::HasInstance()), an implicit TypeError is - * thrown and no callback is invoked. - * - * @param NameValue $name - * @param callable $getter - * @param callable $setter - * @param int $settings \v8\AccessControl constants (one or many) - * @param int $attribute \v8\PropertyAttribute constants (one or many) - * - * TODO: add signature support + * @param NameValue $name + * @param NameValue $name The name of the property for which an accessor is added. + * + * @param callable $getter The callback to invoke when getting the property. + * Callback signature should be (NameValue $property, PropertyCallbackInfo $info) + * + * @param callable $setter The callback to invoke when setting the property. + * Callback signature should be (NameValue $property, PropertyCallbackInfo $info) + * + * @param int $settings Access control settings for the accessor. + * + * @param int $attributes The attributes of the property for which an accessor is added. + * + * @param FunctionTemplate $receiver The signature describes valid receivers for the accessor + * and is used to perform implicit instance checks against them. If the + * receiver is incompatible (i.e. is not an instance of the constructor as + * defined by FunctionTemplate::HasInstance()), an implicit TypeError is + * thrown and no callback is invoked. */ + public function SetAccessor( NameValue $name, callable $getter, callable $setter, $settings = AccessControl::DEFAULT_ACCESS, - $attribute = PropertyAttribute::None + $attributes = PropertyAttribute::None, + FunctionTemplate $receiver ) { } - ///** - // * Sets a named or indexed property handler on the object template. - // * - // * See \v8\NamedPropertyHandlerConfiguration and \v8\IndexedPropertyHandlerConfiguration constructor argument - // * description for details - // * - // * @param \v8\NamedPropertyHandlerConfiguration | \v8\IndexedPropertyHandlerConfiguration $configuration - // */ - //public function SetHandler(NamedPropertyHandlerConfiguration $configuration) - //{ - //} - /** * Sets a named property handler on the object template. * @@ -140,57 +120,17 @@ public function SetCallAsFunctionHandler(callable $callback) { } - // Method is not supported anymore due to a limited use and a way it implemented (causes segfault under certain conditions) - // see v8/src/api-natives.cc:677 - // // Mark as undetectable if needed. - // if (obj->undetectable()) { - // // We only allow callable undetectable receivers here, since this whole - // // undetectable business is only to support document.all, which is both - // // undetectable and callable. If we ever see the need to have an object - // // that is undetectable but not callable, we need to update the types.h - // // to allow encoding this. - // CHECK(!obj->instance_call_handler()->IsUndefined(isolate)); - // map->set_is_undetectable(); - // } - - - ///** - // * Mark object instances of the template as undetectable. - // * - // * In many ways, undetectable objects behave as though they are not - // * there. They behave like 'undefined' in conditionals and when - // * printed. However, properties can be accessed and called as on - // * normal objects. - // */ - //public function MarkAsUndetectable() - //{ - //} - - // Disabled due to https://groups.google.com/forum/#!topic/v8-dev/c7LhW2bNabY and it should be not necessary to use - // it in other then browser setup in most cases, though It would be nice to have it for API consistency reason. - ///** - // * Sets access check callback on the object template and enables access - // * checks. - // * - // * When accessing properties on instances of this object template, - // * the access check callback will be called to determine whether or - // * not to allow cross-context access to the properties. - // */ - //public function SetAccessCheckCallback(callable $callback) - //{ - //} - /** * {@inheritdoc} */ - public function AdjustExternalAllocatedMemory(int $change_in_bytes) : int + public function AdjustExternalAllocatedMemory(int $change_in_bytes): int { } /** * {@inheritdoc} */ - public function GetExternalAllocatedMemory() : int + public function GetExternalAllocatedMemory(): int { } } diff --git a/stubs/src/ObjectValue.php b/stubs/src/ObjectValue.php index b2379e6..5f79ae4 100644 --- a/stubs/src/ObjectValue.php +++ b/stubs/src/ObjectValue.php @@ -40,7 +40,7 @@ public function GetContext() * * @return bool */ - public function Set(Context $context, Value $key, Value $value) : bool + public function Set(Context $context, Value $key, Value $value): bool { } @@ -58,7 +58,7 @@ public function Set(Context $context, Value $key, Value $value) : bool * * @return bool */ - public function CreateDataProperty(Context $context, NameValue $key, Value $value) : bool + public function CreateDataProperty(Context $context, NameValue $key, Value $value): bool { } @@ -88,7 +88,7 @@ public function DefineOwnProperty( * * @return \V8\Value | \V8\ObjectValue | \V8\FunctionObject | ArrayObject | StringValue | NumberValue */ - public function Get(Context $context, Value $key) : Value + public function Get(Context $context, Value $key): Value { } @@ -124,7 +124,7 @@ public function GetOwnPropertyDescriptor(Context $context, NameValue $key): Valu * * @return bool */ - public function Has(Context $context, Value $key) : bool + public function Has(Context $context, Value $key): bool { } @@ -134,7 +134,7 @@ public function Has(Context $context, Value $key) : bool * * @return bool */ - public function Delete(Context $context, Value $key) : bool + public function Delete(Context $context, Value $key): bool { } @@ -174,6 +174,27 @@ public function SetAccessorProperty( ) { } + /** + * Sets a native data property like Template::SetNativeDataProperty, but + * this method sets on this object directly. + * + * @param Context $context + * @param NameValue $name + * @param callable $getter + * @param callable $setter + * @param int $attributes + * + * @return bool + */ + public function SetNativeDataProperty( + Context $context, + NameValue $name, + callable $getter, + callable $setter = null, + int $attributes = PropertyAttribute::None + ): bool { + } + /** * Returns an array containing the names of the enumerable properties * of this object, including properties from prototype objects. The @@ -181,12 +202,18 @@ public function SetAccessorProperty( * be enumerated by a for-in statement over this object. * * @param Context $context + * @param int $mode One of KeyCollectionMode options + * @param int $property_filter One or multiple PropertyFilter options + * @param int $index_filter One or multiple IndexFilter options * - * - * @return \V8\ArrayObject + * @return ArrayObject */ - public function GetPropertyNames(Context $context): ArrayObject - { + public function GetPropertyNames( + Context $context, + int $mode = KeyCollectionMode::kOwnOnly, + int $property_filter = PropertyFilter::ALL_PROPERTIES, + int $index_filter = IndexFilter::kIncludeIndices + ): ArrayObject { } /** @@ -195,11 +222,11 @@ public function GetPropertyNames(Context $context): ArrayObject * prototype objects. * * @param Context $context + * @param int $filter One or multiple PropertyFilter options * - * - * @return \V8\ArrayObject + * @return ArrayObject */ - public function GetOwnPropertyNames(Context $context): ArrayObject + public function GetOwnPropertyNames(Context $context, int $filter = PropertyFilter::ALL_PROPERTIES): ArrayObject { } diff --git a/stubs/src/PropertyFilter.php b/stubs/src/PropertyFilter.php new file mode 100644 index 0000000..f17b0ff --- /dev/null +++ b/stubs/src/PropertyFilter.php @@ -0,0 +1,29 @@ + + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + +namespace V8; + +/** + * Property filter bits. They can be or'ed to build a composite filter. + */ +class PropertyFilter +{ + const ALL_PROPERTIES = 0; + const ONLY_WRITABLE = 1; + const ONLY_ENUMERABLE = 2; + const ONLY_CONFIGURABLE = 4; + const SKIP_STRINGS = 8; + const SKIP_SYMBOLS = 16; +} diff --git a/stubs/src/RegExpObject.php b/stubs/src/RegExpObject.php index a52fb89..d2019c4 100644 --- a/stubs/src/RegExpObject.php +++ b/stubs/src/RegExpObject.php @@ -32,14 +32,14 @@ public function __construct(Context $context, StringValue $pattern, int $flags = /** * @return StringValue */ - public function GetSource() : StringValue + public function GetSource(): StringValue { } /** * @return int */ - public function GetFlags() : int + public function GetFlags(): int { } } diff --git a/stubs/src/ReturnValue.php b/stubs/src/ReturnValue.php index 4c9e0a9..fb40ac0 100644 --- a/stubs/src/ReturnValue.php +++ b/stubs/src/ReturnValue.php @@ -32,7 +32,7 @@ public function Set(Value $value) * * @return Value | StringValue | NumberValue | ObjectValue | ArrayObject | FunctionObject */ - public function Get() : Value + public function Get(): Value { } @@ -72,14 +72,14 @@ public function SetFloat(float $i) /** * @return \V8\Isolate */ - public function GetIsolate() : Isolate + public function GetIsolate(): Isolate { } /** * @return \V8\Context */ - public function GetContext() : Context + public function GetContext(): Context { } @@ -88,7 +88,7 @@ public function GetContext() : Context * * @return bool */ - public function InContext() : bool + public function InContext(): bool { } } diff --git a/stubs/src/StackFrame.php b/stubs/src/StackFrame.php index 00b0f6a..4789586 100644 --- a/stubs/src/StackFrame.php +++ b/stubs/src/StackFrame.php @@ -73,14 +73,14 @@ public function __construct( bool $is_eval = false, bool $is_constructor = false ) { - $this->line_number = $line_number; - $this->column = $column; - $this->script_id = $script_id; - $this->script_name = $script_name; + $this->line_number = $line_number; + $this->column = $column; + $this->script_id = $script_id; + $this->script_name = $script_name; $this->script_name_or_source_url = $script_name_or_source_url; - $this->function_name = $function_name; - $this->is_eval = $is_eval; - $this->is_constructor = $is_constructor; + $this->function_name = $function_name; + $this->is_eval = $is_eval; + $this->is_constructor = $is_constructor; } /** @@ -91,7 +91,7 @@ public function __construct( * * @return int */ - public function GetLineNumber() : int + public function GetLineNumber(): int { return $this->line_number; } @@ -105,7 +105,7 @@ public function GetLineNumber() : int * * @return int */ - public function GetColumn() : int + public function GetColumn(): int { return $this->column; } @@ -118,7 +118,7 @@ public function GetColumn() : int * * @return int */ - public function GetScriptId() : int + public function GetScriptId(): int { return $this->script_id; } @@ -129,7 +129,7 @@ public function GetScriptId() : int * * @return string */ - public function GetScriptName() : string + public function GetScriptName(): string { return $this->script_name; } @@ -142,7 +142,7 @@ public function GetScriptName() : string * * @return string */ - public function GetScriptNameOrSourceURL() : string + public function GetScriptNameOrSourceURL(): string { return $this->script_name_or_source_url; } @@ -152,7 +152,7 @@ public function GetScriptNameOrSourceURL() : string * * @return string */ - public function GetFunctionName() : string + public function GetFunctionName(): string { return $this->function_name; } @@ -163,7 +163,7 @@ public function GetFunctionName() : string * * @return bool */ - public function IsEval() : bool + public function IsEval(): bool { return $this->is_eval; } @@ -174,7 +174,7 @@ public function IsEval() : bool * * @return bool */ - public function IsConstructor() : bool + public function IsConstructor(): bool { return $this->is_constructor; } diff --git a/stubs/src/StackTrace.php b/stubs/src/StackTrace.php index b788d82..7794235 100644 --- a/stubs/src/StackTrace.php +++ b/stubs/src/StackTrace.php @@ -17,7 +17,6 @@ use V8\Exceptions\Exception; -use V8\StackTrace\StackTraceOptions; /** @@ -34,19 +33,13 @@ class StackTrace * @var array|StackFrame[] */ private $frames; - /** - * @var ArrayObject - */ - private $as_array; /** * @param StackFrame[] $frames - * @param ArrayObject $as_array */ - public function __construct(array $frames, ArrayObject $as_array) + public function __construct(array $frames) { - $this->frames = $frames; - $this->as_array = $as_array; + $this->frames = $frames; } @@ -55,7 +48,7 @@ public function __construct(array $frames, ArrayObject $as_array) * * @return StackFrame[] */ - public function GetFrames() : array + public function GetFrames(): array { return $this->frames; } @@ -69,7 +62,7 @@ public function GetFrames() : array * * @throws Exception When index is out of range */ - public function GetFrame(int $index) : StackFrame + public function GetFrame(int $index): StackFrame { if ($index < 0 || !isset($this->frames[$index])) { throw new Exception('Frame index is out of range'); @@ -83,21 +76,11 @@ public function GetFrame(int $index) : StackFrame * * @return int */ - public function GetFrameCount() : int + public function GetFrameCount(): int { return count($this->frames); } - /** - * Returns StackTrace as a v8::Array that contains StackFrame objects. - * - * @return ArrayObject | null - */ - public function AsArray() : ArrayObject - { - return $this->as_array; - } - /** * Grab a snapshot of the current JavaScript execution stack. * @@ -107,7 +90,6 @@ public function AsArray() : ArrayObject * * @param Isolate $isolate * @param int $frame_limit - * @param int $options One or more \v8\StackTrace\StackTraceOptions const flags * * TODO: try to minimize effect of invalid args * Note, that having large (or negative) $frame_limit number may cause OutOfMemory error. @@ -115,11 +97,7 @@ public function AsArray() : ArrayObject * * @return StackTrace */ - public static function CurrentStackTrace( - Isolate $isolate, - int $frame_limit, - int $options = StackTraceOptions::kOverview - ) : StackTrace + public static function CurrentStackTrace(Isolate $isolate, int $frame_limit): StackTrace { } } diff --git a/stubs/src/StackTrace/StackTraceOptions.php b/stubs/src/StackTrace/StackTraceOptions.php deleted file mode 100644 index 07a6020..0000000 --- a/stubs/src/StackTrace/StackTraceOptions.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - - -namespace V8\StackTrace; - -/** - * Flags that determine what information is placed captured for each - * StackFrame when grabbing the current stack trace. - */ -class StackTraceOptions -{ - const kLineNumber = 1; - const kColumnOffset = 1 << 1 | self::kLineNumber; - const kScriptName = 1 << 2; - const kFunctionName = 1 << 3; - const kIsEval = 1 << 4; - const kIsConstructor = 1 << 5; - const kScriptNameOrSourceURL = 1 << 6; - const kScriptId = 1 << 7; - const kExposeFramesAcrossSecurityOrigins = 1 << 8; - const kOverview = self::kLineNumber | self::kColumnOffset | self::kScriptName | self::kFunctionName; - const kDetailed = self::kOverview | self::kIsEval | self::kIsConstructor | self::kScriptNameOrSourceURL; -} diff --git a/stubs/src/StartupData.php b/stubs/src/StartupData.php index 1ce2cd2..b235e15 100644 --- a/stubs/src/StartupData.php +++ b/stubs/src/StartupData.php @@ -25,11 +25,11 @@ public function __construct(string $blob) { } - public function GetData() : string + public function GetData(): string { } - public function GetRawSize() : int + public function GetRawSize(): int { } @@ -40,7 +40,7 @@ public function GetRawSize() : int * * @return StartupData */ - public static function CreateFromSource(string $source) : StartupData + public static function CreateFromSource(string $source): StartupData { $blob = '/* convert source to blob*/'; diff --git a/stubs/src/StringValue.php b/stubs/src/StringValue.php index da773d0..b98b86a 100644 --- a/stubs/src/StringValue.php +++ b/stubs/src/StringValue.php @@ -23,7 +23,11 @@ class StringValue extends NameValue { const kMaxLength = (1 << 28) - 16; - public function __construct(Isolate $isolate, $data = '', $attributes = null) + /** + * @param Isolate $isolate + * @param string $data + */ + public function __construct(Isolate $isolate, $data = '') { parent::__construct($isolate); } diff --git a/stubs/src/SymbolObject.php b/stubs/src/SymbolObject.php index 7266868..1c5cc1f 100644 --- a/stubs/src/SymbolObject.php +++ b/stubs/src/SymbolObject.php @@ -33,7 +33,7 @@ public function __construct(Context $context, SymbolValue $value) /** * @return SymbolValue */ - public function ValueOf() : SymbolValue + public function ValueOf(): SymbolValue { } } diff --git a/stubs/src/SymbolValue.php b/stubs/src/SymbolValue.php index 05751f8..adc9e3a 100644 --- a/stubs/src/SymbolValue.php +++ b/stubs/src/SymbolValue.php @@ -39,7 +39,7 @@ public function __construct(Isolate $isolate, StringValue $name = null) * * @return StringValue | Value */ - public function Name() : Value + public function Name(): Value { } @@ -57,7 +57,7 @@ public function Name() : Value * * @return SymbolValue */ - public static function For(Context $context, StringValue $name) : SymbolValue + public static function For (Context $context, StringValue $name): SymbolValue { } @@ -72,7 +72,54 @@ public static function For(Context $context, StringValue $name) : SymbolValue * * @return SymbolValue */ - public static function ForApi(Context $context, StringValue $name) : SymbolValue + public static function ForApi(Context $context, StringValue $name): SymbolValue + { + } + + // Well-known symbols + + /** + * @param Isolate $isolate + * + * @return SymbolValue + */ + public static function GetHasInstance(Isolate $isolate): SymbolValue + { + } + + /** + * @param Isolate $isolate + * + * @return SymbolValue + */ + public static function GetIsConcatSpreadable(Isolate $isolate): SymbolValue + { + } + + /** + * @param Isolate $isolate + * + * @return SymbolValue + */ + public static function GetIterator(Isolate $isolate): SymbolValue + { + } + + /** + * @param Isolate $isolate + * + * @return SymbolValue + */ + public static function GetMatch(Isolate $isolate): SymbolValue + { + } + + /** + * @param Isolate $isolate + * + * @return SymbolValue + */ + public static function GetReplace(Isolate $isolate): SymbolValue { } @@ -81,7 +128,7 @@ public static function ForApi(Context $context, StringValue $name) : SymbolValue * * @return SymbolValue */ - public static function GetIterator(Isolate $isolate) : SymbolValue + public static function GetSearch(Isolate $isolate): SymbolValue { } @@ -90,7 +137,7 @@ public static function GetIterator(Isolate $isolate) : SymbolValue * * @return SymbolValue */ - public static function GetUnscopables(Isolate $isolate) : SymbolValue + public static function GetSplit(Isolate $isolate): SymbolValue { } @@ -99,7 +146,7 @@ public static function GetUnscopables(Isolate $isolate) : SymbolValue * * @return SymbolValue */ - public static function GetToPrimitive(Isolate $isolate) : SymbolValue + public static function GetToPrimitive(Isolate $isolate): SymbolValue { } @@ -108,7 +155,7 @@ public static function GetToPrimitive(Isolate $isolate) : SymbolValue * * @return SymbolValue */ - public static function GetToStringTag(Isolate $isolate) : SymbolValue + public static function GetToStringTag(Isolate $isolate): SymbolValue { } @@ -117,7 +164,7 @@ public static function GetToStringTag(Isolate $isolate) : SymbolValue * * @return SymbolValue */ - public static function GetIsConcatSpreadable(Isolate $isolate) : SymbolValue + public static function GetUnscopables(Isolate $isolate): SymbolValue { } } diff --git a/stubs/src/Template.php b/stubs/src/Template.php index 09f3109..9704add 100644 --- a/stubs/src/Template.php +++ b/stubs/src/Template.php @@ -34,7 +34,7 @@ public function __construct(\V8\Isolate $isolate) /** * @return \V8\Isolate */ - public function GetIsolate() : Isolate + public function GetIsolate(): Isolate { return $this->isolate; } @@ -78,49 +78,30 @@ public function SetAccessorProperty( * are called instead of getting and setting the property directly * on the JavaScript object. * - * \param name The name of the property for which an accessor is added. - * \param getter The callback to invoke when getting the property. - * \param setter The callback to invoke when setting the property. - * \param data A piece of data that will be passed to the getter and setter - * callbacks whenever they are invoked. - * \param settings Access control settings for the accessor. This is a bit - * field consisting of one of more of - * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. - * The default is to not allow cross-context access. - * ALL_CAN_READ means that all cross-context reads are allowed. - * ALL_CAN_WRITE means that all cross-context writes are allowed. - * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all - * cross-context access. - * \param attribute The attributes of the property for which an accessor - * is added. - * \param signature The signature describes valid receivers for the accessor - * and is used to perform implicit instance checks against them. If the - * receiver is incompatible (i.e. is not an instance of the constructor as - * defined by FunctionTemplate::HasInstance()), an implicit TypeError is - * thrown and no callback is invoked. - */ - //public function void SetNativeDataProperty(Local name, - // AccessorGetterCallback getter, - // AccessorSetterCallback setter = 0, - // // TODO(dcarney): gcc can't handle Local below - // Handle data = Handle(), - // PropertyAttribute attribute = None, - // Local signature = - // Local(), - // AccessControl settings = DEFAULT); - - /** - * @param NameValue $name - * @param callable $getter Callable that will accept (string $property, PropertyCallbackInfo $info) - * @param callable $setter Callable that will accept (string $property, PropertyCallbackInfo $info) - * @param int $attribute - * @param int $settings + * @param NameValue $name The name of the property for which an accessor is added. + * + * @param callable $getter The callback to invoke when getting the property. + * + * Callback signature should be (NameValue $property, PropertyCallbackInfo $info) + * @param callable $setter The callback to invoke when setting the property. + * Callback signature should be (NameValue $property, PropertyCallbackInfo $info) + * + * @param int $attribute The attributes of the property for which an accessor is added. + * + * @param FunctionTemplate $receiver The signature describes valid receivers for the accessor + * and is used to perform implicit instance checks against them. If the + * receiver is incompatible (i.e. is not an instance of the constructor as + * defined by FunctionTemplate::HasInstance()), an implicit TypeError is + * thrown and no callback is invoked. + * + * @param int $settings Access control settings for the accessor. */ public function SetNativeDataProperty( NameValue $name, callable $getter, callable $setter = null, $attribute = PropertyAttribute::None, + FunctionTemplate $receiver, $settings = AccessControl::DEFAULT_ACCESS ) { } diff --git a/stubs/src/TryCatch.php b/stubs/src/TryCatch.php index 080b33c..880a1b1 100644 --- a/stubs/src/TryCatch.php +++ b/stubs/src/TryCatch.php @@ -61,28 +61,29 @@ class TryCatch * @param bool $can_continue * @param bool $has_terminated */ - public function __construct(Isolate $isolate, - Context $context, - Value $exception = null, - Value $stack_trace = null, - Message $message = null, - bool $can_continue = false, - bool $has_terminated = false) - { - $this->isolate = $isolate; - $this->exception = $exception; - $this->stack_trace = $stack_trace; - $this->message = $message; - $this->can_continue = $can_continue; + public function __construct( + Isolate $isolate, + Context $context, + Value $exception = null, + Value $stack_trace = null, + Message $message = null, + bool $can_continue = false, + bool $has_terminated = false + ) { + $this->isolate = $isolate; + $this->exception = $exception; + $this->stack_trace = $stack_trace; + $this->message = $message; + $this->can_continue = $can_continue; $this->has_terminated = $has_terminated; } - public function GetIsolate() : Isolate + public function GetIsolate(): Isolate { return $this->isolate; } - public function GetContext() : Context + public function GetContext(): Context { return $this->context; } @@ -136,7 +137,7 @@ public function Message() * * @return bool */ - public function CanContinue() : bool + public function CanContinue(): bool { return $this->can_continue; } @@ -155,7 +156,7 @@ public function CanContinue() : bool * * @return bool */ - public function HasTerminated() : bool + public function HasTerminated(): bool { return $this->has_terminated; } diff --git a/stubs/src/Uint32Value.php b/stubs/src/Uint32Value.php index 15e6583..473c22c 100644 --- a/stubs/src/Uint32Value.php +++ b/stubs/src/Uint32Value.php @@ -18,7 +18,8 @@ /** * A JavaScript value representing a 32-bit unsigned integer. */ -class Uint32Value extends IntegerValue { +class Uint32Value extends IntegerValue +{ /** * @param Isolate $isolate * @param int $value Should be valid uint32 value @@ -31,7 +32,7 @@ public function __construct(Isolate $isolate, int $value) /** * @return int uint32 value */ - public function Value() : int + public function Value(): int { } } diff --git a/stubs/src/Value.php b/stubs/src/Value.php index 6fac760..79abd76 100644 --- a/stubs/src/Value.php +++ b/stubs/src/Value.php @@ -47,7 +47,7 @@ public function GetIsolate() * * @return bool */ - public function IsUndefined() : bool + public function IsUndefined(): bool { } @@ -56,7 +56,7 @@ public function IsUndefined() : bool * * @return bool */ - public function IsNull() : bool + public function IsNull(): bool { } @@ -65,7 +65,7 @@ public function IsNull() : bool * * @return bool */ - public function IsTrue() : bool + public function IsTrue(): bool { } @@ -74,7 +74,7 @@ public function IsTrue() : bool * * @return bool */ - public function IsFalse() : bool + public function IsFalse(): bool { } @@ -84,7 +84,7 @@ public function IsFalse() : bool * * @return bool */ - public function IsName() : bool + public function IsName(): bool { } @@ -93,7 +93,7 @@ public function IsName() : bool * * @return bool */ - public function IsString() : bool + public function IsString(): bool { } @@ -102,7 +102,7 @@ public function IsString() : bool * * @return bool */ - public function IsSymbol() : bool + public function IsSymbol(): bool { } @@ -111,7 +111,7 @@ public function IsSymbol() : bool * * @return bool */ - public function IsFunction() : bool + public function IsFunction(): bool { } @@ -120,7 +120,7 @@ public function IsFunction() : bool * * @return bool */ - public function IsArray() : bool + public function IsArray(): bool { } @@ -129,7 +129,7 @@ public function IsArray() : bool * * @return bool */ - public function IsObject() : bool + public function IsObject(): bool { } @@ -138,7 +138,7 @@ public function IsObject() : bool * * @return bool */ - public function IsBoolean() : bool + public function IsBoolean(): bool { } @@ -147,7 +147,7 @@ public function IsBoolean() : bool * * @return bool */ - public function IsNumber() : bool + public function IsNumber(): bool { } @@ -156,7 +156,7 @@ public function IsNumber() : bool * * @return bool */ - public function IsInt32() : bool + public function IsInt32(): bool { } @@ -165,7 +165,7 @@ public function IsInt32() : bool * * @return bool */ - public function IsUint32() : bool + public function IsUint32(): bool { } @@ -174,7 +174,7 @@ public function IsUint32() : bool * * @return bool */ - public function IsDate() : bool + public function IsDate(): bool { } @@ -183,7 +183,7 @@ public function IsDate() : bool * * @return bool */ - public function IsArgumentsObject() : bool + public function IsArgumentsObject(): bool { } @@ -192,7 +192,7 @@ public function IsArgumentsObject() : bool * * @return bool */ - public function IsBooleanObject() : bool + public function IsBooleanObject(): bool { } @@ -201,7 +201,7 @@ public function IsBooleanObject() : bool * * @return bool */ - public function IsNumberObject() : bool + public function IsNumberObject(): bool { } @@ -210,14 +210,14 @@ public function IsNumberObject() : bool * * @return bool */ - public function IsStringObject() : bool + public function IsStringObject(): bool { } /** * Returns true if this value is a Symbol object. */ - public function IsSymbolObject() : bool + public function IsSymbolObject(): bool { } @@ -226,7 +226,7 @@ public function IsSymbolObject() : bool * * @return bool */ - public function IsNativeError() : bool + public function IsNativeError(): bool { } @@ -235,7 +235,7 @@ public function IsNativeError() : bool * * @return bool */ - public function IsRegExp() : bool + public function IsRegExp(): bool { } @@ -382,7 +382,7 @@ public function Int32Value(Context $context) * * @return bool */ - public function Equals(Context $context, Value $that) + public function Equals(Context $context, Value $that): bool { } @@ -391,7 +391,7 @@ public function Equals(Context $context, Value $that) * * @return bool */ - public function StrictEquals(Value $that) + public function StrictEquals(Value $that): bool { } @@ -400,25 +400,24 @@ public function StrictEquals(Value $that) * * @return bool */ - public function SameValue(Value $that) + public function SameValue(Value $that): bool { } - -// /** -// * @param Value $value -// * @return Value -// */ -////template V8_INLINE static Value* Cast(T* value); -// public static function Cast(Value $value) {} -// Local TypeOf(v8::Isolate*); + /** + * @return StringValue + */ + public function TypeOf(): StringValue + { + } /** - * @param Isolate $isolate + * @param Context $context + * @param ObjectValue $object * - * @return StringValue + * @return bool */ - public function TypeOf(Isolate $isolate) : StringValue + public function InstanceOf (Context $context, ObjectValue $object): bool { } } diff --git a/tests/.testsuite.php b/tests/.testsuite.php index 3d3b093..f0814f9 100644 --- a/tests/.testsuite.php +++ b/tests/.testsuite.php @@ -128,6 +128,10 @@ public function assert($message, $actual, $expected = true, $identical = true) } } + public function fail($message = null) { + echo $message ?: 'Should fail', PHP_EOL; + } + public function value_matches($expected, $actual, $identical = true) { if ($identical) { diff --git a/tests/.v8-helpers.php b/tests/.v8-helpers.php index da9673c..2fc9f72 100644 --- a/tests/.v8-helpers.php +++ b/tests/.v8-helpers.php @@ -31,6 +31,36 @@ public function __construct(PhpV8Testsuite $testsuite) { $this->testsuite = $testsuite; } + /** + * @param \V8\Context $context + * @param \V8\StackFrame[] $frames + * + * @return \V8\ArrayObject + */ + public function getStackTraceFramesAsArray(\V8\Context $context, array $frames) + { + $isolate = $context->GetIsolate(); + + $arr = new \V8\ArrayObject($context); + + foreach ($frames as $i => $frame) { + $f = new \V8\ObjectValue($context); + + $f->Set($context, new \V8\StringValue($isolate, 'line'), new \V8\NumberValue($isolate, $frame->GetLineNumber())); + $f->Set($context, new \V8\StringValue($isolate, 'column'), new \V8\NumberValue($isolate, $frame->GetColumn())); + $f->Set($context, new \V8\StringValue($isolate, 'scriptId'), new \V8\NumberValue($isolate, $frame->GetScriptId())); + $f->Set($context, new \V8\StringValue($isolate, 'scriptName'), new \V8\StringValue($isolate, $frame->GetScriptName())); + $f->Set($context, new \V8\StringValue($isolate, 'scriptNameOrSourceURL'), new \V8\StringValue($isolate, $frame->GetScriptNameOrSourceURL())); + $f->Set($context, new \V8\StringValue($isolate, 'functionName'), new \V8\StringValue($isolate, $frame->GetFunctionName())); + $f->Set($context, new \V8\StringValue($isolate, 'isEval'), new \V8\BooleanValue($isolate, $frame->IsEval())); + $f->Set($context, new \V8\StringValue($isolate, 'isConstructor'), new \V8\BooleanValue($isolate, $frame->IsConstructor())); + + $arr->Set($context, new \V8\IntegerValue($isolate, $i), $f); + } + + return $arr; + } + public function getPrintFunctionTemplate(\V8\Isolate $isolate, $newline = false) { $print_func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $args) use ($newline) { @@ -56,6 +86,8 @@ public function injectConsoleLog(\V8\Context $context) { $console_obj = $obj_tpl->NewInstance($context); $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'console'), $console_obj); + + return $context; } /** @@ -115,7 +147,7 @@ public function run_checks(\V8\Value $value, $title=null) { $filter = new ArrayListFilter(['TypeOf'], false); $finalizer = new CallChainFinalizer([\V8\StringValue::class => 'Value'], [], false); - $this->testsuite->dump_object_methods($value, ['@@default' => [$value->GetIsolate()]], $filter, $finalizer); + $this->testsuite->dump_object_methods($value, [], $filter, $finalizer); $this->testsuite->line(); $filter = new RegexpFilter('/^Is/'); diff --git a/tests/002-enums.phpt b/tests/002-enums.phpt new file mode 100644 index 0000000..c8436bd --- /dev/null +++ b/tests/002-enums.phpt @@ -0,0 +1,173 @@ +--TEST-- +Built-in enum classes +--SKIPIF-- + +--FILE-- +header('Object representation'); + $helper->dump($enum); + $helper->space(); + + + $helper->header('Class constants'); + $helper->dump_object_constants($enum); + $helper->space(); +} + + +?> +--EXPECT-- +Object representation: +---------------------- +object(V8\AccessControl)#2 (0) { +} + + +Class constants: +---------------- +V8\AccessControl::DEFAULT_ACCESS = 0 +V8\AccessControl::ALL_CAN_READ = 1 +V8\AccessControl::ALL_CAN_WRITE = 2 + + +Object representation: +---------------------- +object(V8\ConstructorBehavior)#3 (0) { +} + + +Class constants: +---------------- +V8\ConstructorBehavior::kThrow = 0 +V8\ConstructorBehavior::kAllow = 1 + + +Object representation: +---------------------- +object(V8\IntegrityLevel)#4 (0) { +} + + +Class constants: +---------------- +V8\IntegrityLevel::kFrozen = 0 +V8\IntegrityLevel::kSealed = 1 + + +Object representation: +---------------------- +object(V8\PropertyAttribute)#5 (0) { +} + + +Class constants: +---------------- +V8\PropertyAttribute::None = 0 +V8\PropertyAttribute::ReadOnly = 1 +V8\PropertyAttribute::DontEnum = 2 +V8\PropertyAttribute::DontDelete = 4 + + +Object representation: +---------------------- +object(V8\PropertyHandlerFlags)#6 (0) { +} + + +Class constants: +---------------- +V8\PropertyHandlerFlags::kNone = 0 +V8\PropertyHandlerFlags::kAllCanRead = 1 +V8\PropertyHandlerFlags::kNonMasking = 2 +V8\PropertyHandlerFlags::kOnlyInterceptStrings = 4 + + +Object representation: +---------------------- +object(V8\PropertyFilter)#7 (0) { +} + + +Class constants: +---------------- +V8\PropertyFilter::ALL_PROPERTIES = 0 +V8\PropertyFilter::ONLY_WRITABLE = 1 +V8\PropertyFilter::ONLY_ENUMERABLE = 2 +V8\PropertyFilter::ONLY_CONFIGURABLE = 4 +V8\PropertyFilter::SKIP_STRINGS = 8 +V8\PropertyFilter::SKIP_SYMBOLS = 16 + + +Object representation: +---------------------- +object(V8\KeyCollectionMode)#8 (0) { +} + + +Class constants: +---------------- +V8\KeyCollectionMode::kOwnOnly = 0 +V8\KeyCollectionMode::kIncludePrototypes = 1 + + +Object representation: +---------------------- +object(V8\IndexFilter)#9 (0) { +} + + +Class constants: +---------------- +V8\IndexFilter::kIncludeIndices = 0 +V8\IndexFilter::kSkipIndices = 1 + + +Object representation: +---------------------- +object(V8\RegExpObject\Flags)#10 (0) { +} + + +Class constants: +---------------- +V8\RegExpObject\Flags::kNone = 0 +V8\RegExpObject\Flags::kGlobal = 1 +V8\RegExpObject\Flags::kIgnoreCase = 2 +V8\RegExpObject\Flags::kMultiline = 4 +V8\RegExpObject\Flags::kSticky = 8 +V8\RegExpObject\Flags::kUnicode = 16 + + +Object representation: +---------------------- +object(V8\ScriptCompiler\CompileOptions)#11 (0) { +} + + +Class constants: +---------------- +V8\ScriptCompiler\CompileOptions::kNoCompileOptions = 0 +V8\ScriptCompiler\CompileOptions::kProduceParserCache = 1 +V8\ScriptCompiler\CompileOptions::kConsumeParserCache = 2 +V8\ScriptCompiler\CompileOptions::kProduceCodeCache = 3 +V8\ScriptCompiler\CompileOptions::kConsumeCodeCache = 4 diff --git a/tests/004-ICU-Intl_NumberFormat.phpt b/tests/004-ICU-Intl_NumberFormat.phpt index 1959c5d..9601b78 100644 --- a/tests/004-ICU-Intl_NumberFormat.phpt +++ b/tests/004-ICU-Intl_NumberFormat.phpt @@ -43,7 +43,7 @@ console.log(new Intl.NumberFormat(['ban', 'id']).format(number)); // → 123.456,789 HEREDOC; -(new \V8\Script($context, new \V8\StringValue($isolate, $source)))->Run($context); +$v8_helper->CompileRun($context, $source); $helper->line(); @@ -66,8 +66,7 @@ console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).form // → 1,23,000 HEREDOC; -(new \V8\Script($context, new \V8\StringValue($isolate, $source)))->Run($context); - +$v8_helper->CompileRun($context, $source) ?> --EXPECT-- diff --git a/tests/V8AccessControl.phpt b/tests/V8AccessControl.phpt deleted file mode 100644 index 89ed9df..0000000 --- a/tests/V8AccessControl.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -V8\AccessControl ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\AccessControl)#1 (0) { -} - - -Class constants: ----------------- -V8\AccessControl::DEFAULT_ACCESS = 0 -V8\AccessControl::ALL_CAN_READ = 1 -V8\AccessControl::ALL_CAN_WRITE = 2 diff --git a/tests/V8ArrayObject.phpt b/tests/V8ArrayObject.phpt index 6883e52..ab4b18b 100644 --- a/tests/V8ArrayObject.phpt +++ b/tests/V8ArrayObject.phpt @@ -12,10 +12,8 @@ require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); $isolate = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate); - -$global_template1->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); -$context = new V8\Context($isolate, $global_template1); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $value = new V8\ArrayObject($context); @@ -24,6 +22,7 @@ $helper->dump($value); $helper->space(); $helper->assert('ArrayObject extends ObjectValue', $value instanceof \V8\ObjectValue); +$helper->assert('ArrayObject is instanceof Array', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Array')))); $helper->line(); $helper->header('Accessors'); @@ -47,18 +46,16 @@ $value->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\StringValue $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'arr'), $value); -$source1 = ' -print("typeof arr: ", typeof arr, "\n"); -print("arr: ", arr, "\n"); -print("arr.length: ", arr.length, "\n"); -print("arr[0]: ", arr[0], "\n"); -print("arr.test: ", arr.test, "\n"); -print("arr.slice(1): ", arr.slice(1), "\n"); +$source = ' +console.log("typeof arr: ", typeof arr); +console.log("arr: ", arr); +console.log("arr.length: ", arr.length); +console.log("arr[0]: ", arr[0]); +console.log("arr.test: ", arr.test); +console.log("arr.slice(1): ", arr.slice(1)); '; -$file_name1 = 'test.js'; -$script1 = new V8\Script($context, new \V8\StringValue($isolate, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context); +$v8_helper->CompileRun($context, $source); ?> --EXPECT-- @@ -79,7 +76,7 @@ object(V8\ArrayObject)#6 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#5 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -98,6 +95,7 @@ object(V8\ArrayObject)#6 (2) { ArrayObject extends ObjectValue: ok +ArrayObject is instanceof Array: ok Accessors: ---------- @@ -164,7 +162,7 @@ V8\ArrayObject(V8\Value)->IsProxy(): bool(false) Converters: ----------- V8\ArrayObject(V8\Value)->ToBoolean(): - object(V8\BooleanValue)#117 (1) { + object(V8\BooleanValue)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -180,7 +178,7 @@ V8\ArrayObject(V8\Value)->ToBoolean(): } } V8\ArrayObject(V8\Value)->ToNumber(): - object(V8\Int32Value)#117 (1) { + object(V8\Int32Value)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -196,7 +194,7 @@ V8\ArrayObject(V8\Value)->ToNumber(): } } V8\ArrayObject(V8\Value)->ToString(): - object(V8\StringValue)#117 (1) { + object(V8\StringValue)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -212,7 +210,7 @@ V8\ArrayObject(V8\Value)->ToString(): } } V8\ArrayObject(V8\Value)->ToDetailString(): - object(V8\StringValue)#117 (1) { + object(V8\StringValue)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -243,7 +241,7 @@ V8\ArrayObject(V8\Value)->ToObject(): bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#5 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -260,7 +258,7 @@ V8\ArrayObject(V8\Value)->ToObject(): } } V8\ArrayObject(V8\Value)->ToInteger(): - object(V8\Int32Value)#117 (1) { + object(V8\Int32Value)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -276,7 +274,7 @@ V8\ArrayObject(V8\Value)->ToInteger(): } } V8\ArrayObject(V8\Value)->ToUint32(): - object(V8\Int32Value)#117 (1) { + object(V8\Int32Value)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -292,7 +290,7 @@ V8\ArrayObject(V8\Value)->ToUint32(): } } V8\ArrayObject(V8\Value)->ToInt32(): - object(V8\Int32Value)#117 (1) { + object(V8\Int32Value)#118 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8ArrayObject_Length.phpt b/tests/V8ArrayObject_Length.phpt index 6e36857..91f0cda 100644 --- a/tests/V8ArrayObject_Length.phpt +++ b/tests/V8ArrayObject_Length.phpt @@ -7,28 +7,22 @@ V8\ArrayObject::Length /** @var \Phpv8Testsuite $helper */ $helper = require '.testsuite.php'; +require '.v8-helpers.php'; +$v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$context = new V8\Context($isolate); -$context1 = new V8\Context($isolate1, $global_template1); +$res = $v8_helper->CompileRun($context, '[1,2,3]'); -$source1 = ' -[1,2,3] -'; -$file_name1 = 'test.js'; +echo $res->Length(), PHP_EOL; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); -echo $res1->Length(), PHP_EOL; - - -$arr = new \V8\ArrayObject($context1, 5); +$arr = new \V8\ArrayObject($context, 5); echo $arr->Length(), PHP_EOL; for ($i =0; $i < 7; $i++) { - $arr->Set($context1, new \V8\Uint32Value($isolate1, $i), new \V8\StringValue($isolate1, 'test-'.$i)); + $arr->Set($context, new \V8\Uint32Value($isolate, $i), new \V8\StringValue($isolate, 'test-'.$i)); } echo $arr->Length(), PHP_EOL; diff --git a/tests/V8BooleanObject.phpt b/tests/V8BooleanObject.phpt index 5de9fae..4af5181 100644 --- a/tests/V8BooleanObject.phpt +++ b/tests/V8BooleanObject.phpt @@ -11,17 +11,11 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); -// TODO: fix it, this cause segfault due to FunctionTemplate object destruction and all it internal structures cleanup -//$global_template1->Set('print', $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$print_func_tpl = $v8_helper->getPrintFunctionTemplate($isolate1); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete); - -$context1 = new V8\Context($isolate1, $global_template1); - -$value = new V8\BooleanObject($context1, true); +$value = new V8\BooleanObject($context, true); $helper->header('Object representation'); $helper->dump($value); @@ -37,27 +31,25 @@ $helper->space(); $v8_helper->run_checks($value, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); new Boolean(false); '; -$file_name1 = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$res = $v8_helper->CompileRun($context, $source); $helper->space(); -$v8_helper->run_checks($res1, 'Checkers on boxed from script'); +$v8_helper->run_checks($res, 'Checkers on boxed from script'); ?> --EXPECT-- Object representation: ---------------------- -object(V8\BooleanObject)#8 (2) { +object(V8\BooleanObject)#6 (2) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -72,7 +64,7 @@ object(V8\BooleanObject)#8 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#7 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8CompileOptions.phpt b/tests/V8CompileOptions.phpt deleted file mode 100644 index 6c92e97..0000000 --- a/tests/V8CompileOptions.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -V8\ScriptCompiler\CompileOptions ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\ScriptCompiler\CompileOptions)#1 (0) { -} - - -Class constants: ----------------- -V8\ScriptCompiler\CompileOptions::kNoCompileOptions = 0 -V8\ScriptCompiler\CompileOptions::kProduceParserCache = 1 -V8\ScriptCompiler\CompileOptions::kConsumeParserCache = 2 -V8\ScriptCompiler\CompileOptions::kProduceCodeCache = 3 -V8\ScriptCompiler\CompileOptions::kConsumeCodeCache = 4 diff --git a/tests/V8Context.phpt b/tests/V8Context.phpt index 8b7a260..80785cd 100644 --- a/tests/V8Context.phpt +++ b/tests/V8Context.phpt @@ -11,10 +11,9 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); +$isolate = new \V8\Isolate(); -$context = new \V8\Context($isolate1); -$helper->pretty_dump('Estimated memory usage size by this context', $context->EstimatedSize()); +$context = new \V8\Context($isolate); $helper->method_matches_instanceof($context, 'GlobalObject', \V8\ObjectValue::class); @@ -34,14 +33,12 @@ $helper->assert('Code generation is not allowed', $context->IsCodeGenerationFrom $helper->method_matches_with_output($context, 'IsCodeGenerationFromStringsAllowed', false); $res = $v8_helper->CompileTryRun($context, 'eval("1+1")'); -$context->SetErrorMessageForCodeGenerationFromStrings(new \V8\StringValue($isolate1, 'Whoa! Nope. No eval this time, sorry.')); +$context->SetErrorMessageForCodeGenerationFromStrings(new \V8\StringValue($isolate, 'Whoa! Nope. No eval this time, sorry.')); $res = $v8_helper->CompileTryRun($context, 'eval("2+2")'); -$helper->pretty_dump('Estimated memory usage size by this context', $context->EstimatedSize()); ?> ---EXPECTF-- -Estimated memory usage size by this context: int(%d) +--EXPECT-- V8\Context::GlobalObject() result is instance of V8\ObjectValue CHECK $global->SameValue($context->GlobalObject()): OK V8\Context::IsCodeGenerationFromStringsAllowed() matches expected value @@ -50,4 +47,3 @@ Code generation is not allowed: ok V8\Context::IsCodeGenerationFromStringsAllowed() matches expected false eval("1+1"): V8\Exceptions\TryCatchException: EvalError: Code generation from strings disallowed for this context eval("2+2"): V8\Exceptions\TryCatchException: EvalError: Whoa! Nope. No eval this time, sorry. -Estimated memory usage size by this context: int(%d) diff --git a/tests/V8Context_GlobalObject.phpt b/tests/V8Context_GlobalObject.phpt index c35525e..b68652d 100644 --- a/tests/V8Context_GlobalObject.phpt +++ b/tests/V8Context_GlobalObject.phpt @@ -14,8 +14,8 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new \V8\Isolate(); -$context = new \V8\Context($isolate1); +$isolate = new \V8\Isolate(); +$context = new \V8\Context($isolate); $helper->method_matches_instanceof($context, 'GlobalObject', \V8\ObjectValue::class); @@ -29,7 +29,7 @@ $helper->assert('Global object on repeatable calls holds extra props', $global1- $context->DetachGlobal(); -$context2 = new \V8\Context($isolate1, null, $global2); +$context2 = new \V8\Context($isolate, null, $global2); $helper->method_matches_instanceof($context2, 'GlobalObject', \V8\ObjectValue::class); echo 'Global object passed from one context to another is ', ($global1 === $global2 ? 'the same' : 'not the same'), PHP_EOL; diff --git a/tests/V8Context_SetSecurityToken.phpt b/tests/V8Context_SetSecurityToken.phpt new file mode 100644 index 0000000..b313eef --- /dev/null +++ b/tests/V8Context_SetSecurityToken.phpt @@ -0,0 +1,89 @@ +--TEST-- +V8\Context::SetSecurityToken() +--SKIPIF-- + +--FILE-- +injectConsoleLog($context); + +$other = new \V8\Context($isolate); +$v8_helper->injectConsoleLog($other); + +$obj_own = new \V8\ObjectValue($context); +$obj_own->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\StringValue($isolate, 'own')); + +$obj_other = new \V8\ObjectValue($context); +$obj_other->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\StringValue($isolate, 'other')); + + +try { + $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own); + $context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other); + $helper->assert('There is no cross-context access by default', false); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +$context->SetSecurityToken(new \V8\StringValue($isolate, 'secret 1')); +$other->SetSecurityToken(new \V8\StringValue($isolate, 'secret 2')); + +try { + $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own); + $context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other); + $helper->assert('Different security tokens should not grant cross-context access', false); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + + +$context->SetSecurityToken(new \V8\StringValue($isolate, 'secret')); +$other->SetSecurityToken(new \V8\StringValue($isolate, 'secret')); + +try { + $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own); + $context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other); + $helper->assert('Different security tokens with the same value should not grant cross-context access', false); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + + +$secret = new \V8\StringValue($isolate, 'secret'); + +$context->SetSecurityToken($secret); +$other->SetSecurityToken($secret); + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'own'), $obj_own); +$context->GlobalObject()->Set($other, new \V8\StringValue($isolate, 'other'), $obj_other); + +$helper->line(); + + +$v8_helper->CompileRun($context, <<<'SCRIPT' +console.log('own.test: ', own.test); +console.log('other.test: ', other.test); +SCRIPT +); + +echo 'We are done for now', PHP_EOL; +?> +EOF +--EXPECT-- +V8\Exceptions\TryCatchException: TypeError: no access +V8\Exceptions\TryCatchException: TypeError: no access +V8\Exceptions\TryCatchException: TypeError: no access + +own.test: own +other.test: other +We are done for now +EOF diff --git a/tests/V8Context_reference_lifecycle.phpt b/tests/V8Context_reference_lifecycle.phpt index d6c5ee5..cfc9dd4 100644 --- a/tests/V8Context_reference_lifecycle.phpt +++ b/tests/V8Context_reference_lifecycle.phpt @@ -13,22 +13,18 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -class Context extends V8\Context { - public function __destruct() { - echo 'Context dies now', PHP_EOL; - } -} +require '.tracking_dtors.php'; $isolate = new \V8\Isolate(); -$obj = $v8_helper->CompileRun(new Context($isolate), 'var obj = {}; obj'); +$obj = $v8_helper->CompileRun(new \v8Tests\TrackingDtors\Context($isolate), 'var obj = {}; obj'); //$helper->dump($obj); $helper->dump($obj->GetContext()); -$context = new Context($isolate); +$context = new \v8Tests\TrackingDtors\Context($isolate); $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj'), $obj); $helper->line(); @@ -45,7 +41,7 @@ $helper->dump($obj->GetContext()); $obj = null; ?> --EXPECT-- -object(Context)#4 (1) { +object(v8Tests\TrackingDtors\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -61,11 +57,11 @@ object(Context)#4 (1) { } } -Context dies now +Context dies now! Previous context should be dead, creating zval for object from old context -object(Context)#6 (1) { +object(v8Tests\TrackingDtors\Context)#6 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -80,4 +76,4 @@ object(Context)#6 (1) { bool(false) } } -Context dies now +Context dies now! diff --git a/tests/V8Context_weakness.phpt b/tests/V8Context_weakness.phpt index 976d2aa..33a66b4 100644 --- a/tests/V8Context_weakness.phpt +++ b/tests/V8Context_weakness.phpt @@ -10,29 +10,26 @@ V8\Context weakness /** @var \Phpv8Testsuite $helper */ $helper = require '.testsuite.php'; -class Context extends V8\Context { - public function __destruct() { - echo 'Context dies now', PHP_EOL; - } -} +require '.tracking_dtors.php'; -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); -$source1 = 'var obj = {}; obj'; -$file_name1 = 'test.js'; +$global_template = new V8\ObjectTemplate($isolate); -$script1 = new \V8\Script( - new Context($isolate1, $global_template1), - new \V8\StringValue($isolate1, $source1), - new \V8\ScriptOrigin($file_name1) +$source = 'var obj = {}; obj'; +$file_name = 'test.js'; + +$script = new \V8\Script( + new \v8Tests\TrackingDtors\Context($isolate, $global_template), + new \V8\StringValue($isolate, $source), + new \V8\ScriptOrigin($file_name) ); -$obj = $script1->Run($script1->GetContext())->ToObject($script1->GetContext()); // contest should be stored in object +$obj = $script->Run($script->GetContext())->ToObject($script->GetContext()); // contest should be stored in object -$script1 = null; +$script = null; echo 'We are done for now', PHP_EOL; ?> @@ -40,4 +37,4 @@ EOF --EXPECT-- We are done for now EOF -Context dies now +Context dies now! diff --git a/tests/V8DateObject.phpt b/tests/V8DateObject.phpt index e06285b..c2d31fd 100644 --- a/tests/V8DateObject.phpt +++ b/tests/V8DateObject.phpt @@ -17,25 +17,19 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); - -// TODO: fix it, this cause segfault due to FunctionTemplate object destruction and all it internal structures cleanup -//$global_template1->Set('print', $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$print_func_tpl = $v8_helper->getPrintFunctionTemplate($isolate1); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete); - -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new \V8\Isolate(); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $test_time = 1445444940000.0; -$value = new V8\DateObject($context1, $test_time); +$value = new V8\DateObject($context, $test_time); $helper->header('Object representation'); $helper->dump($value); $helper->space(); $helper->assert('DateObject extends ObjectValue', $value instanceof \V8\ObjectValue); -$helper->line(); +$helper->assert('ObjectValue is instanceof Date', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Date'))));$helper->line(); $helper->header('Getters'); $helper->method_export($value, 'ValueOf'); @@ -43,22 +37,22 @@ $helper->space(); $v8_helper->run_checks($value, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' +$source = ' var orig = val; -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +console.log("val: ", val); +console.log("typeof val: ", typeof val); orig '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); $helper->space(); $helper->header('Returned value should be the same'); -$helper->value_matches_with_no_output($res1, $value); +$helper->value_matches_with_no_output($res, $value); $helper->space(); $helper->header('Timezone change (with notification to v8)'); @@ -68,21 +62,21 @@ $helper->header('Timezone change (with notification to v8)'); $old_tz = getenv('TZ'); putenv('TZ=America/Los_Angeles'); // UTC offset DST (ISO 8601)‎: ‎−07:00, UTC offset (ISO 8601)‎: ‎−08:00 -\V8\DateObject::DateTimeConfigurationChangeNotification($isolate1); -$value = new V8\DateObject($context1, $test_time); +\V8\DateObject::DateTimeConfigurationChangeNotification($isolate); +$value = new V8\DateObject($context, $test_time); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); val '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); $helper->value_matches($test_time, $value->ValueOf()); $helper->space(); @@ -91,20 +85,20 @@ $helper->header('Timezone change (without notification to v8)'); putenv('TZ=America/New_York'); // UTC offset DST (ISO 8601)‎: ‎−05:00, UTC offset (ISO 8601)‎: ‎−04:00 -$value = new V8\DateObject($context1, $test_time); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$value = new V8\DateObject($context, $test_time); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); val '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; // TODO: for some reason v8 still be notified about TZ changes, see https://groups.google.com/forum/?fromgroups#!topic/v8-users/f249jR67ANk // TODO: we temporary set EDT instead of PDT which was before -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); $helper->value_matches($test_time, $value->ValueOf()); $helper->space(); @@ -115,7 +109,7 @@ putenv("TZ={$old_tz}"); // Go back --EXPECT-- Object representation: ---------------------- -object(V8\DateObject)#8 (2) { +object(V8\DateObject)#6 (2) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -130,7 +124,7 @@ object(V8\DateObject)#8 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#7 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -149,6 +143,7 @@ object(V8\DateObject)#8 (2) { DateObject extends ObjectValue: ok +ObjectValue is instanceof Date: ok Getters: -------- diff --git a/tests/V8Exception_CreateMessage.phpt b/tests/V8Exception_CreateMessage.phpt index 15945ad..2f11ad4 100644 --- a/tests/V8Exception_CreateMessage.phpt +++ b/tests/V8Exception_CreateMessage.phpt @@ -42,10 +42,10 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba }); $global_tpl = new \V8\ObjectTemplate($isolate); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $source = ' @@ -54,9 +54,9 @@ $source = ' try { throw {test: "error"}; } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); - print("\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); + console.log(""); test(exception); @@ -85,7 +85,7 @@ Message created from thrown value: V8\Message->Get(): string(18) "Uncaught #" V8\Message->GetSourceLine(): string(24) " test(exception);" V8\Message->GetScriptOrigin(): - object(V8\ScriptOrigin)#21 (6) { + object(V8\ScriptOrigin)#15 (6) { ["resource_name":"V8\ScriptOrigin":private]=> string(7) "test.js" ["resource_line_offset":"V8\ScriptOrigin":private]=> @@ -93,7 +93,7 @@ V8\Message->GetScriptOrigin(): ["resource_column_offset":"V8\ScriptOrigin":private]=> int(0) ["options":"V8\ScriptOrigin":private]=> - object(V8\ScriptOriginOptions)#15 (4) { + object(V8\ScriptOriginOptions)#13 (4) { ["is_shared_cross_origin":"V8\ScriptOriginOptions":private]=> bool(false) ["is_opaque":"V8\ScriptOriginOptions":private]=> @@ -104,15 +104,15 @@ V8\Message->GetScriptOrigin(): bool(false) } ["script_id":"V8\ScriptOrigin":private]=> - int(%d) + int(19) ["source_map_url":"V8\ScriptOrigin":private]=> string(0) "" } V8\Message->GetScriptResourceName(): string(7) "test.js" V8\Message->GetStackTrace(): NULL V8\Message->GetLineNumber(): int(11) -V8\Message->GetStartPosition(): int(227) -V8\Message->GetEndPosition(): int(228) +V8\Message->GetStartPosition(): int(231) +V8\Message->GetEndPosition(): int(232) V8\Message->GetStartColumn(): int(8) V8\Message->GetEndColumn(): int(9) V8\Message->IsSharedCrossOrigin(): bool(false) @@ -142,15 +142,15 @@ V8\Message->GetScriptOrigin(): bool(false) } ["script_id":"V8\ScriptOrigin":private]=> - int(%d) + int(19) ["source_map_url":"V8\ScriptOrigin":private]=> string(0) "" } V8\Message->GetScriptResourceName(): string(7) "test.js" V8\Message->GetStackTrace(): NULL V8\Message->GetLineNumber(): int(11) -V8\Message->GetStartPosition(): int(227) -V8\Message->GetEndPosition(): int(228) +V8\Message->GetStartPosition(): int(231) +V8\Message->GetEndPosition(): int(232) V8\Message->GetStartColumn(): int(8) V8\Message->GetEndColumn(): int(9) V8\Message->IsSharedCrossOrigin(): bool(false) diff --git a/tests/V8Exception_Error.phpt b/tests/V8Exception_Error.phpt index 2622272..aefcaa6 100644 --- a/tests/V8Exception_Error.phpt +++ b/tests/V8Exception_Error.phpt @@ -52,10 +52,11 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba $global_tpl = new \V8\ObjectTemplate($isolate); $global_tpl->Set(new \V8\StringValue($isolate, 'e'), $func_tpl); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); + $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $v8_helper->CompileTryRun($context, 'test()'); $v8_helper->CompileTryRun($context, 'e()'); @@ -67,8 +68,8 @@ $source = ' try { e("foo"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } diff --git a/tests/V8Exception_GetStackTrace.phpt b/tests/V8Exception_GetStackTrace.phpt index 5176deb..a3e8dc3 100644 --- a/tests/V8Exception_GetStackTrace.phpt +++ b/tests/V8Exception_GetStackTrace.phpt @@ -55,10 +55,10 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba }); $global_tpl = new \V8\ObjectTemplate($isolate); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $source = ' @@ -67,9 +67,9 @@ $source = ' try { throw new Error("test"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); - print("\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); + console.log(); test(exception); @@ -112,7 +112,7 @@ Stack trace created from thrown value: V8\StackTrace->getFrames(): array(1) { [0]=> - object(V8\StackFrame)#19 (8) { + object(V8\StackFrame)#14 (8) { ["line_number":"V8\StackFrame":private]=> int(5) ["column":"V8\StackFrame":private]=> @@ -126,43 +126,11 @@ V8\StackTrace->getFrames(): ["function_name":"V8\StackFrame":private]=> string(0) "" ["is_eval":"V8\StackFrame":private]=> - int(0) - ["is_constructor":"V8\StackFrame":private]=> - int(0) - } - } -V8\StackTrace->GetFrameCount(): int(1) -V8\StackTrace->AsArray(): - object(V8\ArrayObject)#15 (2) { - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#3 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> + ["is_constructor":"V8\StackFrame":private]=> bool(false) } - ["context":"V8\ObjectValue":private]=> - object(V8\Context)#8 (1) { - ["isolate":"V8\Context":private]=> - object(V8\Isolate)#3 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - } } +V8\StackTrace->GetFrameCount(): int(1) Stack trace created from manually created value is null: ok diff --git a/tests/V8Exception_RangeError.phpt b/tests/V8Exception_RangeError.phpt index 62df2f9..32685ee 100644 --- a/tests/V8Exception_RangeError.phpt +++ b/tests/V8Exception_RangeError.phpt @@ -53,10 +53,10 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba $global_tpl = new \V8\ObjectTemplate($isolate); $global_tpl->Set(new \V8\StringValue($isolate, 'e'), $func_tpl); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $v8_helper->CompileTryRun($context, 'test()'); $v8_helper->CompileTryRun($context, 'e()'); @@ -68,8 +68,8 @@ $source = ' try { e("foo"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } diff --git a/tests/V8Exception_ReferenceError.phpt b/tests/V8Exception_ReferenceError.phpt index b503e77..8bdb136 100644 --- a/tests/V8Exception_ReferenceError.phpt +++ b/tests/V8Exception_ReferenceError.phpt @@ -53,10 +53,10 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba $global_tpl = new \V8\ObjectTemplate($isolate); $global_tpl->Set(new \V8\StringValue($isolate, 'e'), $func_tpl); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $v8_helper->CompileTryRun($context, 'test()'); $v8_helper->CompileTryRun($context, 'e()'); @@ -68,8 +68,8 @@ $source = ' try { e("foo"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } diff --git a/tests/V8Exception_SyntaxError.phpt b/tests/V8Exception_SyntaxError.phpt index dc67515..9c67754 100644 --- a/tests/V8Exception_SyntaxError.phpt +++ b/tests/V8Exception_SyntaxError.phpt @@ -53,10 +53,10 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba $global_tpl = new \V8\ObjectTemplate($isolate); $global_tpl->Set(new \V8\StringValue($isolate, 'e'), $func_tpl); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $v8_helper->CompileTryRun($context, 'test()'); $v8_helper->CompileTryRun($context, 'e()'); @@ -68,8 +68,8 @@ $source = ' try { e("foo"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } diff --git a/tests/V8Exception_TypeError.phpt b/tests/V8Exception_TypeError.phpt index cd69db5..407acb9 100644 --- a/tests/V8Exception_TypeError.phpt +++ b/tests/V8Exception_TypeError.phpt @@ -53,10 +53,10 @@ $func_test_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallba $global_tpl = new \V8\ObjectTemplate($isolate); $global_tpl->Set(new \V8\StringValue($isolate, 'e'), $func_tpl); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $global_tpl->Set(new \V8\StringValue($isolate, 'test'), $func_test_tpl); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $v8_helper->CompileTryRun($context, 'test()'); $v8_helper->CompileTryRun($context, 'e()'); @@ -68,8 +68,8 @@ $source = ' try { e("foo"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } diff --git a/tests/V8FunctionCallbackInfo.phpt b/tests/V8FunctionCallbackInfo.phpt index 0e1436a..4274b23 100644 --- a/tests/V8FunctionCallbackInfo.phpt +++ b/tests/V8FunctionCallbackInfo.phpt @@ -12,19 +12,19 @@ $helper = require '.testsuite.php'; require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new v8Tests\TrackingDtors\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new V8\Context($isolate, $global_template); // TEST: Pass context instead of isolate to FunctionTemplate -$scalar = new \V8\StringValue($isolate1, "test"); -$object = new \V8\ObjectValue($context1); +$scalar = new \V8\StringValue($isolate, "test"); +$object = new \V8\ObjectValue($context); /** @var V8\FunctionCallbackInfo $callback_info */ $callback_info = null; -$func = new v8Tests\TrackingDtors\FunctionObject($context1, function (V8\FunctionCallbackInfo $info) use ($helper, &$callback_info, $scalar, $object, $isolate1, $context1) { +$func = new v8Tests\TrackingDtors\FunctionObject($context, function (V8\FunctionCallbackInfo $info) use ($helper, &$callback_info, $scalar, $object, $isolate, $context) { echo 'Function called', PHP_EOL; $helper->header('Object representation'); @@ -35,24 +35,24 @@ $func = new v8Tests\TrackingDtors\FunctionObject($context1, function (V8\Functio $helper->assert('Original arguments number passed', count($info->Arguments()) == 2); $helper->assert('Arguments number matches Length() method output', count($info->Arguments()) == $info->Length()); - $helper->assert('Callback info holds original isolate object', $info->GetIsolate(), $isolate1); - $helper->assert('Callback info holds original isolate object', $info->GetContext(), $context1); + $helper->assert('Callback info holds original isolate object', $info->GetIsolate(), $isolate); + $helper->assert('Callback info holds original isolate object', $info->GetContext(), $context); $helper->assert('Scalars hold no info about their zval, so that their zvals are recreated on each access', $scalar !== $info->Arguments()[0]); $helper->assert("Objects can hold info about their zval and keep it until zval's get free() ", $object === $info->Arguments()[1]); }); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'print'), $func); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'scalar'), $scalar); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'obj'), $object); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'print'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'scalar'), $scalar); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj'), $object); -$source1 = 'print(scalar, obj); "Script done";'; -$file_name1 = 'test.js'; +$source = 'print(scalar, obj); "Script done";'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$helper->dump($script1->Run($context1)->ToString($context1)->Value()); +$helper->dump($script->Run($context)->ToString($context)->Value()); $helper->space(); diff --git a/tests/V8FunctionObject.phpt b/tests/V8FunctionObject.phpt index f82c6f8..a6f0cc4 100644 --- a/tests/V8FunctionObject.phpt +++ b/tests/V8FunctionObject.phpt @@ -15,16 +15,16 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new v8Tests\TrackingDtors\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new V8\Context($isolate, $global_template); -$func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) { +$func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) { echo 'Should output Hello World string', PHP_EOL; }); -$func->SetName(new \V8\StringValue($isolate1, 'custom_name')); +$func->SetName(new \V8\StringValue($isolate, 'custom_name')); $helper->header('Object representation'); $helper->dump($func); @@ -32,19 +32,20 @@ $helper->space(); $helper->assert('FunctionObject extends ObjectValue', $func instanceof \V8\ObjectValue); $helper->assert('FunctionObject implements AdjustableExternalMemoryInterface', $func instanceof \V8\AdjustableExternalMemoryInterface); +$helper->assert('FunctionObject is instanceof Function', $func->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Function')))); $helper->line(); $v8_helper->run_checks($func, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'print'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'print'), $func); -$source1 = 'print("Hello, world\n"); delete print; "Script done"'; -$file_name1 = 'test.js'; +$source = 'print("Hello, world"); delete print; "Script done"'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$helper->dump($script1->Run($context1)->ToString($context1)->Value()); +$helper->dump($script->Run($context)->ToString($context)->Value()); $helper->line(); $helper->dump_object_methods($func, [], new ArrayMapFilter(['GetScriptOrigin' => true])); @@ -91,6 +92,7 @@ object(v8Tests\TrackingDtors\FunctionObject)#6 (2) { FunctionObject extends ObjectValue: ok FunctionObject implements AdjustableExternalMemoryInterface: ok +FunctionObject is instanceof Function: ok Checkers: --------- @@ -152,7 +154,7 @@ Should output Hello World string string(11) "Script done" v8Tests\TrackingDtors\FunctionObject(V8\FunctionObject)->GetScriptOrigin(): - object(V8\ScriptOrigin)#126 (6) { + object(V8\ScriptOrigin)#128 (6) { ["resource_name":"V8\ScriptOrigin":private]=> string(0) "" ["resource_line_offset":"V8\ScriptOrigin":private]=> @@ -160,7 +162,7 @@ v8Tests\TrackingDtors\FunctionObject(V8\FunctionObject)->GetScriptOrigin(): ["resource_column_offset":"V8\ScriptOrigin":private]=> int(0) ["options":"V8\ScriptOrigin":private]=> - object(V8\ScriptOriginOptions)#130 (4) { + object(V8\ScriptOriginOptions)#132 (4) { ["is_shared_cross_origin":"V8\ScriptOriginOptions":private]=> bool(false) ["is_opaque":"V8\ScriptOriginOptions":private]=> diff --git a/tests/V8FunctionObject_constructor_behavior.phpt b/tests/V8FunctionObject_constructor_behavior.phpt new file mode 100644 index 0000000..6aa6d1f --- /dev/null +++ b/tests/V8FunctionObject_constructor_behavior.phpt @@ -0,0 +1,46 @@ +--TEST-- +V8\FunctionObject - constructor behavior +--SKIPIF-- + +--FILE-- +injectConsoleLog($context); + +$f_allow = new \V8\FunctionObject($context, function () { + echo 'Allow', PHP_EOL; +}); + +$f_throw = new \V8\FunctionObject($context, function () { + echo 'Throw', PHP_EOL; +}, 0, \V8\ConstructorBehavior::kThrow); + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'f_allow'), $f_allow); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'f_throw'), $f_throw); + + +$v8_helper->CompileRun($context, 'f_allow(); new f_allow();'); +try { + $v8_helper->CompileRun($context, 'f_throw(); new f_throw();'); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +?> +--EXPECT-- +Allow +Allow +Throw +V8\Exceptions\TryCatchException: TypeError: f_throw is not a constructor diff --git a/tests/V8FunctionObject_die.phpt b/tests/V8FunctionObject_die.phpt index 137de64..e8dcbea 100644 --- a/tests/V8FunctionObject_die.phpt +++ b/tests/V8FunctionObject_die.phpt @@ -12,26 +12,26 @@ $helper = require '.testsuite.php'; require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new v8Tests\TrackingDtors\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new V8\Context($isolate, $global_template); -$func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) { +$func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) { echo 'going to die...', PHP_EOL; die(); }); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'test'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $func); -$source1 = 'test(); "Script done"'; -$file_name1 = 'test.js'; +$source = 'test(); "Script done"'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$res = $script1->Run($context1)->ToString($context1)->Value(); +$res = $script->Run($context)->ToString($context)->Value(); $helper->pretty_dump('Script result', $res); echo 'We are done for now', PHP_EOL; diff --git a/tests/V8FunctionObject_die_nested.phpt b/tests/V8FunctionObject_die_nested.phpt index eeb93c5..2b7e285 100644 --- a/tests/V8FunctionObject_die_nested.phpt +++ b/tests/V8FunctionObject_die_nested.phpt @@ -13,19 +13,19 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new v8Tests\TrackingDtors\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new V8\Context($isolate, $global_template); -$die_func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) { +$die_func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) { echo 'going to die...', PHP_EOL; die(); }); $die_func->destructor_test_message = 'die() function dtored'; -$teste_nested_func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) { +$teste_nested_func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) { echo 'calling nested...', PHP_EOL; $context = $info->GetContext(); @@ -35,13 +35,13 @@ $teste_nested_func = new v8Tests\TrackingDtors\FunctionObject($context1, functio $teste_nested_func->destructor_test_message = 'test_nested() function dtored'; -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'die'), $die_func); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'test_nested'), $teste_nested_func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'die'), $die_func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test_nested'), $teste_nested_func); -$res = $v8_helper->CompileRun($context1, 'test_nested(); "Script done"'); +$res = $v8_helper->CompileRun($context, 'test_nested(); "Script done"'); -$helper->pretty_dump('Script result', $res->ToString($context1)->Value()); +$helper->pretty_dump('Script result', $res->ToString($context)->Value()); echo 'We are done for now', PHP_EOL; diff --git a/tests/V8FunctionObject_weakness_multiple.phpt b/tests/V8FunctionObject_weakness_multiple.phpt index 8971ca7..3aeb80b 100644 --- a/tests/V8FunctionObject_weakness_multiple.phpt +++ b/tests/V8FunctionObject_weakness_multiple.phpt @@ -15,51 +15,51 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new v8Tests\TrackingDtors\Context($isolate1, $global_template1); -$global_template1 = null; +$isolate = new v8Tests\TrackingDtors\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new v8Tests\TrackingDtors\Context($isolate, $global_template); +$global_template = null; -$func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) { +$func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) { echo 'Should output Hello World string', PHP_EOL; }); -$func->SetAccessor($context1, new \V8\StringValue($isolate1, 'nonexistent'), function () { echo 'get nonexistent 1', PHP_EOL; } ); +$func->SetAccessor($context, new \V8\StringValue($isolate, 'nonexistent'), function () { echo 'get nonexistent 1', PHP_EOL; } ); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'print'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'print'), $func); $func = null; -$v8_helper->CompileRun($context1, 'print("test"); print.nonexistent; '); +$v8_helper->CompileRun($context, 'print("test"); print.nonexistent; '); -$fnc1 = $context1->GlobalObject()->Get($context1, new \V8\StringValue($isolate1, 'print')); +$fnc1 = $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'print')); /** @var $fnc1 \V8\FunctionObject */ -$fnc1->SetAccessor($context1, new \V8\StringValue($isolate1, 'nonexistent'), function () { echo 'get nonexistent 2', PHP_EOL; } ); -$v8_helper->CompileRun($context1, 'print("test"); print.nonexistent; '); +$fnc1->SetAccessor($context, new \V8\StringValue($isolate, 'nonexistent'), function () { echo 'get nonexistent 2', PHP_EOL; } ); +$v8_helper->CompileRun($context, 'print("test"); print.nonexistent; '); $fnc1 = null; -$fnc2 = $context1->GlobalObject()->Get($context1, new \V8\StringValue($isolate1, 'print')); +$fnc2 = $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'print')); /** @var $fnc1 \V8\FunctionObject */ -$fnc2->SetAccessor($context1, new \V8\StringValue($isolate1, 'nonexistent'), function () { echo 'get nonexistent 3', PHP_EOL; } ); -$v8_helper->CompileRun($context1, 'print("test"); print.nonexistent; '); +$fnc2->SetAccessor($context, new \V8\StringValue($isolate, 'nonexistent'), function () { echo 'get nonexistent 3', PHP_EOL; } ); +$v8_helper->CompileRun($context, 'print("test"); print.nonexistent; '); $fnc2 = null; echo 'Persistent should be removed', PHP_EOL; -$isolate1->LowMemoryNotification(); +$isolate->LowMemoryNotification(); // Here newly create object internally linked to specific callback and persistent, but as it has no own callback, free'ing // it shouldn't affect functionality -$fnc3 = $context1->GlobalObject()->Get($context1, new \V8\StringValue($isolate1, 'print')); -$v8_helper->CompileRun($context1, 'print("test"); print.nonexistent;'); +$fnc3 = $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'print')); +$v8_helper->CompileRun($context, 'print("test"); print.nonexistent;'); $fnc3 = null; -$v8_helper->CompileRun($context1, 'print("test"); print.nonexistent;'); +$v8_helper->CompileRun($context, 'print("test"); print.nonexistent;'); -$context1 = null; +$context = null; echo 'Context should be removed', PHP_EOL; -$isolate1->LowMemoryNotification(); +$isolate->LowMemoryNotification(); echo 'We are done for now', PHP_EOL; diff --git a/tests/V8FunctionTemplate.phpt b/tests/V8FunctionTemplate.phpt index d1877d0..7c17ffb 100644 --- a/tests/V8FunctionTemplate.phpt +++ b/tests/V8FunctionTemplate.phpt @@ -50,7 +50,7 @@ $print_func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallb } } - echo implode('', $out); + echo implode('', $out), PHP_EOL; }); @@ -73,10 +73,6 @@ $helper->dump($instance_template); $helper->method_matches($function_template, 'InstanceTemplate', $instance_template); $helper->space(); -$instance_template_1 = $function_template->InstanceTemplate(); - -$instance_template_2 = $function_template->InstanceTemplate(); - $global_template = new V8\ObjectTemplate($isolate); $value = new V8\StringValue($isolate, 'TEST VALUE 111'); @@ -90,8 +86,8 @@ $context = new V8\Context($isolate, $global_template); $source = ' -print("Hello, world!\n"); -print(s, " ", o,"\n"); +print("Hello, world!"); +print(s, " ", o); typeof func() '; //$source = 'func(); func(); func(); func()'; @@ -138,9 +134,6 @@ if ($res->IsFunction()) { $helper->dump($res->ToString($context)->Value()); - - - ?> --EXPECT-- Object representation: diff --git a/tests/V8FunctionTemplate_GetFunction.phpt b/tests/V8FunctionTemplate_GetFunction.phpt index 78a5d00..df6eb45 100644 --- a/tests/V8FunctionTemplate_GetFunction.phpt +++ b/tests/V8FunctionTemplate_GetFunction.phpt @@ -10,23 +10,23 @@ V8\FunctionTemplate::GetFunction /** @var \Phpv8Testsuite $helper */ $helper = require '.testsuite.php'; -$isolate1 = new \V8\Isolate(); +$isolate = new \V8\Isolate(); -$print_func_tpl = new \V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackInfo $info) { +$print_func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) { echo 'Should output Hello World string', PHP_EOL; }); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new \V8\Context($isolate1, $global_template1); -$context2 = new \V8\Context($isolate1, $global_template1); +$global_template = new V8\ObjectTemplate($isolate); +$context = new \V8\Context($isolate, $global_template); +$context2 = new \V8\Context($isolate, $global_template); -$func_1 = $print_func_tpl->GetFunction($context1); +$func_1 = $print_func_tpl->GetFunction($context); $helper->object_type($func_1); -$func_2 = $print_func_tpl->GetFunction($context1); +$func_2 = $print_func_tpl->GetFunction($context); if ($func_1 === $func_2) { echo 'Function instance is the same within single context', PHP_EOL; @@ -41,16 +41,16 @@ if ($func_1 === $func_3) { echo 'Function instance is NOT the same between different contexts', PHP_EOL; } -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'print'), $func_1); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'print'), $func_1); -$source1 = 'print("Hello, world\n"); "Script done"'; -$file_name1 = 'test.js'; +$source = 'print("Hello, world"); "Script done"'; +$file_name = 'test.js'; -$script1 = new \V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new \V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$helper->dump($script1->Run($context1)->ToString($context1)->Value()); +$helper->dump($script->Run($context)->ToString($context)->Value()); echo 'We are done for now', PHP_EOL; diff --git a/tests/V8FunctionTemplate_SetCallHandler.phpt b/tests/V8FunctionTemplate_SetCallHandler.phpt index 8117663..9cf8d48 100644 --- a/tests/V8FunctionTemplate_SetCallHandler.phpt +++ b/tests/V8FunctionTemplate_SetCallHandler.phpt @@ -10,10 +10,10 @@ V8\FunctionTemplate::SetCallHandler /** @var \Phpv8Testsuite $helper */ $helper = require '.testsuite.php'; -$isolate1 = new \V8\Isolate(); +$isolate = new \V8\Isolate(); -$test_func_tpl = new \V8\FunctionTemplate($isolate1, function () {echo 'callback 1', PHP_EOL;}); +$test_func_tpl = new \V8\FunctionTemplate($isolate, function () {echo 'callback 1', PHP_EOL;}); $test_func_tpl->SetCallHandler(function () {echo 'callback test()', PHP_EOL;}); try { @@ -23,26 +23,26 @@ try { $helper->line(); } -$change_func_tpl = new \V8\FunctionTemplate($isolate1, function () use ($test_func_tpl){ +$change_func_tpl = new \V8\FunctionTemplate($isolate, function () use ($test_func_tpl){ $test_func_tpl->SetCallHandler(function () {echo 'callback change()', PHP_EOL;}); }); -$global_template1 = new \V8\ObjectTemplate($isolate1); +$global_template = new \V8\ObjectTemplate($isolate); -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_func_tpl); -$global_template1->Set(new \V8\StringValue($isolate1, 'change'), $change_func_tpl); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_func_tpl); +$global_template->Set(new \V8\StringValue($isolate, 'change'), $change_func_tpl); -$context1 = new \V8\Context($isolate1, $global_template1); +$context = new \V8\Context($isolate, $global_template); -$source1 = 'test(); change(); test(); "Script done"'; -$file_name1 = 'test.js'; +$source = 'test(); change(); test(); "Script done"'; +$file_name = 'test.js'; -$script1 = new \V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new \V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); try { - $helper->dump($script1->Run($context1)->ToString($context1)->Value()); + $helper->dump($script->Run($context)->ToString($context)->Value()); } catch (Exception $e) { $helper->exception_export($e); } diff --git a/tests/V8FunctionTemplate_constructor_behavior.phpt b/tests/V8FunctionTemplate_constructor_behavior.phpt new file mode 100644 index 0000000..9310815 --- /dev/null +++ b/tests/V8FunctionTemplate_constructor_behavior.phpt @@ -0,0 +1,46 @@ +--TEST-- +V8\FunctionTemplate - constructor behavior +--SKIPIF-- + +--FILE-- +injectConsoleLog($context); + +$ftpl_allow = new \V8\FunctionTemplate($isolate, function () { + echo 'Allow', PHP_EOL; +}); + +$ftpl_throw = new \V8\FunctionTemplate($isolate, function () { + echo 'Throw', PHP_EOL; +}, null, 0, \V8\ConstructorBehavior::kThrow); + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'f_allow'), $ftpl_allow->GetFunction($context)); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'f_throw'), $ftpl_throw->GetFunction($context)); + + +$v8_helper->CompileRun($context, 'f_allow(); new f_allow();'); +try { + $v8_helper->CompileRun($context, 'f_throw(); new f_throw();'); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +?> +--EXPECT-- +Allow +Allow +Throw +V8\Exceptions\TryCatchException: TypeError: f_throw is not a constructor diff --git a/tests/V8FunctionTemplate_constructor_receiver.phpt b/tests/V8FunctionTemplate_constructor_receiver.phpt new file mode 100644 index 0000000..03e8e2f --- /dev/null +++ b/tests/V8FunctionTemplate_constructor_receiver.phpt @@ -0,0 +1,65 @@ +--TEST-- +V8\FunctionTemplate::__construct() - with receiver +--SKIPIF-- + +--FILE-- +injectConsoleLog($context); + + +$cb = function (\V8\FunctionCallbackInfo $args) { + echo 'Callback', PHP_EOL; + $args->GetReturnValue()->Set(new \V8\IntegerValue($args->GetIsolate(), 42)); +}; + +$sig_obj = new \V8\FunctionTemplate($isolate); + +$x = new \V8\FunctionTemplate($isolate, $cb, $sig_obj); + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'sig_obj'), $sig_obj->GetFunction($context)); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'x'), $x->GetFunction($context)); + +$v8_helper->CompileRun($context, "var s = new sig_obj();"); + +try { + $v8_helper->CompileRun($context, "x()"); + $helper->fail(); +}catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +try { + $v8_helper->CompileRun($context, "x.call(1)"); + $helper->fail(); +}catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +$res = $v8_helper->CompileRun($context, "s.x = x; s.x()"); +$v8_helper->CHECK_EQ(42, $res->Value()); + +$res = $v8_helper->CompileRun($context, "x.call(s)"); +$v8_helper->CHECK_EQ(42, $res->Value()); + + +?> +--EXPECT-- +V8\Exceptions\TryCatchException: TypeError: Illegal invocation +V8\Exceptions\TryCatchException: TypeError: Illegal invocation +Callback +CHECK_EQ: OK +Callback +CHECK_EQ: OK diff --git a/tests/V8FunctionTemplate_exception_in_php.phpt b/tests/V8FunctionTemplate_exception_in_php.phpt index 27522aa..567c776 100644 --- a/tests/V8FunctionTemplate_exception_in_php.phpt +++ b/tests/V8FunctionTemplate_exception_in_php.phpt @@ -10,25 +10,25 @@ V8\FunctionTemplate: exception in php thrown /** @var \Phpv8Testsuite $helper */ $helper = require '.testsuite.php'; -$isolate1 = new \V8\Isolate(); +$isolate = new \V8\Isolate(); -$test_func_tpl = new \V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackInfo $info) { +$test_func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) { throw new Exception('Unexpected exception'); }); -$global_template1 = new V8\ObjectTemplate($isolate1); -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_func_tpl, \V8\PropertyAttribute::DontDelete); +$global_template = new V8\ObjectTemplate($isolate); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_func_tpl, \V8\PropertyAttribute::DontDelete); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); -$source1 = 'test(); "Script done"'; -$file_name1 = 'test.js'; +$source = 'test(); "Script done"'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); try { - $helper->dump($script1->Run($context1)->ToString($context1)->Value()); + $helper->dump($script->Run($context)->ToString($context)->Value()); } catch (Exception $e) { $helper->exception_export($e); } diff --git a/tests/V8FunctionTemplate_require_implementation.phpt b/tests/V8FunctionTemplate_require_implementation.phpt index 71fed55..9665502 100644 --- a/tests/V8FunctionTemplate_require_implementation.phpt +++ b/tests/V8FunctionTemplate_require_implementation.phpt @@ -11,7 +11,7 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); +$isolate = new \V8\Isolate(); $code = []; @@ -23,7 +23,7 @@ $code['test.js'] = 'var out = {"foo" : "unchanged"}; out'; /** @var \V8\Value[] $loaded */ $loaded_cache = []; -$require_func_tpl_cache = new \V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackInfo $info) use (&$loaded_cache, &$code) { +$require_func_tpl_cache = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) use (&$loaded_cache, &$code) { $isolate = $info->GetIsolate(); $context = $info->GetContext(); @@ -39,27 +39,27 @@ $require_func_tpl_cache = new \V8\FunctionTemplate($isolate1, function (\V8\Func $info->GetReturnValue()->Set($loaded_cache[$module]); }); -$global_template = new V8\ObjectTemplate($isolate1); -$global_template->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$global_template->Set(new \V8\StringValue($isolate1, 'require'), $require_func_tpl_cache, \V8\PropertyAttribute::DontDelete); -$context = new V8\Context($isolate1, $global_template); +$global_template = new V8\ObjectTemplate($isolate); +$global_template->Set(new \V8\StringValue($isolate, 'require'), $require_func_tpl_cache, \V8\PropertyAttribute::DontDelete); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); $JS = ' var test = require("test.js"); -print(test.foo, "\n"); +console.log(test.foo); test.foo = "changed"; -print(test.foo, "\n"); +console.log(test.foo); var test2 = require("test.js"); -print(test2.foo, "\n"); +console.log(test2.foo); '; $file_name2 = 'experiment.js'; $helper->header('Test require() (with cache)'); -$script2 = new V8\Script($context, new \V8\StringValue($isolate1, $JS), new \V8\ScriptOrigin($file_name2)); +$script2 = new V8\Script($context, new \V8\StringValue($isolate, $JS), new \V8\ScriptOrigin($file_name2)); $res2 = $script2->Run($context); $helper->space(); @@ -71,7 +71,7 @@ $helper->space(); /** @var \V8\Script[] $loaded */ $loaded_no_cache = []; -$require_func_tpl_nocache = new \V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackInfo $info) use (&$loaded_no_cache, &$code) { +$require_func_tpl_nocache = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) use (&$loaded_no_cache, &$code) { $isolate = $info->GetIsolate(); $context = $info->GetContext(); @@ -89,27 +89,27 @@ $require_func_tpl_nocache = new \V8\FunctionTemplate($isolate1, function (\V8\Fu }); -$global_template = new V8\ObjectTemplate($isolate1); -$global_template->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$global_template->Set(new \V8\StringValue($isolate1, 'require'), $require_func_tpl_nocache, \V8\PropertyAttribute::DontDelete); -$context = new V8\Context($isolate1, $global_template); +$global_template = new V8\ObjectTemplate($isolate); +$global_template->Set(new \V8\StringValue($isolate, 'require'), $require_func_tpl_nocache, \V8\PropertyAttribute::DontDelete); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); $JS = ' var test = require("test.js"); -print(test.foo, "\n"); +console.log(test.foo); test.foo = "changed"; -print(test.foo, "\n"); +console.log(test.foo); var test2 = require("test.js"); -print(test2.foo, "\n"); +console.log(test2.foo); '; $file_name2 = 'experiment.js'; $helper->header('Test require() (no cache)'); -$script2 = new V8\Script($context, new \V8\StringValue($isolate1, $JS), new \V8\ScriptOrigin($file_name2)); +$script2 = new V8\Script($context, new \V8\StringValue($isolate, $JS), new \V8\ScriptOrigin($file_name2)); $res2 = $script2->Run($context); ?> diff --git a/tests/V8FunctionTemplate_weakness.phpt b/tests/V8FunctionTemplate_weakness.phpt index 3111bf2..a23402f 100644 --- a/tests/V8FunctionTemplate_weakness.phpt +++ b/tests/V8FunctionTemplate_weakness.phpt @@ -50,7 +50,7 @@ class MyObjectTemplate extends \V8\ObjectTemplate } } -$isolate1 = new Isolate(); +$isolate = new Isolate(); class MyCallaback @@ -66,28 +66,28 @@ class MyCallaback } } -$print_func_tpl = new MyFunctionTemplate($isolate1, new MyCallaback()); +$print_func_tpl = new MyFunctionTemplate($isolate, new MyCallaback()); -$global_template1 = new MyObjectTemplate($isolate1); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl); +$global_template = new MyObjectTemplate($isolate); +$global_template->Set(new \V8\StringValue($isolate, 'print'), $print_func_tpl); $print_func_tpl = null; -$context1 = new Context($isolate1, $global_template1); -$global_template1 = null; +$context = new Context($isolate, $global_template); +$global_template = null; -$source1 = 'print("Hello, world\n"); delete print; "Script done"'; -$file_name1 = 'test.js'; +$source = 'print("Hello, world"); delete print; "Script done"'; +$file_name = 'test.js'; try { - $script1 = new Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); + $script = new Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); - $script1->Run($context1)->Value(); + $script->Run($context)->Value(); } catch (Exception $e) { $helper->exception_export($e); } -$script1 = null; -$context1 = null; -$isolate1 = null; +$script = null; +$context = null; +$isolate = null; echo 'We are done for now', PHP_EOL; diff --git a/tests/V8Int32Value.phpt b/tests/V8Int32Value.phpt index 386ef46..df66d61 100644 --- a/tests/V8Int32Value.phpt +++ b/tests/V8Int32Value.phpt @@ -161,7 +161,7 @@ V8\Int32Value(V8\Value)->IsProxy(): bool(false) V8\Int32Value::ToString() converting: ------------------------------------- -object(V8\StringValue)#78 (1) { +object(V8\StringValue)#79 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#1 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8IntegerValue.phpt b/tests/V8IntegerValue.phpt index b4d4af3..faad629 100644 --- a/tests/V8IntegerValue.phpt +++ b/tests/V8IntegerValue.phpt @@ -161,7 +161,7 @@ V8\IntegerValue(V8\Value)->IsProxy(): bool(false) V8\IntegerValue::ToString() converting: --------------------------------------- -object(V8\StringValue)#78 (1) { +object(V8\StringValue)#79 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#1 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8IntegrityLevel.phpt b/tests/V8IntegrityLevel.phpt deleted file mode 100644 index 4b8ae6e..0000000 --- a/tests/V8IntegrityLevel.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -V8\PropertyAttribute ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\IntegrityLevel)#1 (0) { -} - - -Class constants: ----------------- -V8\IntegrityLevel::kFrozen = 0 -V8\IntegrityLevel::kSealed = 1 diff --git a/tests/V8Isolate_ThrowException.phpt b/tests/V8Isolate_ThrowException.phpt index 390a881..e575bee 100644 --- a/tests/V8Isolate_ThrowException.phpt +++ b/tests/V8Isolate_ThrowException.phpt @@ -24,9 +24,9 @@ $func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInf $global_tpl = new \V8\ObjectTemplate($isolate); $global_tpl->Set(new \V8\StringValue($isolate, 'e'), $func_tpl); -$global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $context = new \V8\Context($isolate, $global_tpl); +$v8_helper->injectConsoleLog($context); $v8_helper->CompileTryRun($context, 'e()'); @@ -39,8 +39,8 @@ $source = ' try { e("foo"); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } @@ -63,8 +63,8 @@ $source = ' try { e({}); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } @@ -82,8 +82,8 @@ $source = ' try { throw new Error(); } catch (exception) { - print("exception: ", "\'", exception, "\'", "\n"); - print("exception.stack: ", exception.stack, "\n"); + console.log("exception: ", "\'", exception, "\'"); + console.log("exception.stack: ", exception.stack); ex = exception; } diff --git a/tests/V8Isolate_gc_cyclic_ref_memleak.phpt b/tests/V8Isolate_gc_cyclic_ref_memleak.phpt index c71aab5..96a4e85 100644 --- a/tests/V8Isolate_gc_cyclic_ref_memleak.phpt +++ b/tests/V8Isolate_gc_cyclic_ref_memleak.phpt @@ -13,14 +13,14 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); -$func_tpl = new \V8\FunctionTemplate($isolate1, function () {}); -$global_template1->Set(new \V8\StringValue($isolate1, 'func'), $func_tpl, \V8\PropertyAttribute::DontDelete); +$func_tpl = new \V8\FunctionTemplate($isolate, function () {}); +$global_template->Set(new \V8\StringValue($isolate, 'func'), $func_tpl, \V8\PropertyAttribute::DontDelete); -$foo = new V8\ObjectTemplate($isolate1);; -$name = new V8\StringValue($isolate1, 'test'); +$foo = new V8\ObjectTemplate($isolate);; +$name = new V8\StringValue($isolate, 'test'); $getter = function ($index) use (&$foo, &$name, $helper) { echo 'I am getter for ' . $index . ' !', PHP_EOL; @@ -31,17 +31,17 @@ $getter = function ($index) use (&$foo, &$name, $helper) { $handlers = new \V8\IndexedPropertyHandlerConfiguration($getter); $getter = null; -$test_obj_tpl = new \V8\ObjectTemplate($isolate1); +$test_obj_tpl = new \V8\ObjectTemplate($isolate); $test_obj_tpl->SetHandlerForIndexedProperty($handlers); -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_obj_tpl); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_obj_tpl); $handlers = null; -$context1 = new \V8\Context($isolate1, $global_template1); +$context = new \V8\Context($isolate, $global_template); -$obj = new V8\ObjectValue($context1); -$obj->SetAccessor($context1, new \V8\StringValue($isolate1, 'test'), function () use (&$isolate1, &$foo, &$name) {}); +$obj = new V8\ObjectValue($context); +$obj->SetAccessor($context, new \V8\StringValue($isolate, 'test'), function () use (&$isolate, &$foo, &$name) {}); echo 'Done here for now', PHP_EOL; ?> diff --git a/tests/V8Isolate_limit_memory.phpt b/tests/V8Isolate_limit_memory.phpt index 1c0990b..c8bf86c 100644 --- a/tests/V8Isolate_limit_memory.phpt +++ b/tests/V8Isolate_limit_memory.phpt @@ -22,18 +22,15 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: $isolate = new V8\Isolate(); -$global_template = new V8\ObjectTemplate($isolate); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); - -$context = new V8\Context($isolate, $global_template); - +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $source = ' var str = " ".repeat(1024); // 1kb var blob = []; while(true) { blob.push(str); - //print(blob.length, "\n"); + //console.log(blob.length); } '; $file_name = 'test.js'; @@ -98,23 +95,23 @@ object(V8\Isolate)#3 (5) { ["memory_limit_hit":"V8\Isolate":private]=> bool(true) } -object(V8\HeapStatistics)#11 (9) { +object(V8\HeapStatistics)#10 (9) { ["total_heap_size":"V8\HeapStatistics":private]=> - float(%d) + float(14737408) ["total_heap_size_executable":"V8\HeapStatistics":private]=> - float(%d) + float(3670016) ["total_physical_size":"V8\HeapStatistics":private]=> - float(%d) + float(12383272) ["total_available_size":"V8\HeapStatistics":private]=> - float(%d) + float(1486132752) ["used_heap_size":"V8\HeapStatistics":private]=> - float(%d) + float(12226176) ["heap_size_limit":"V8\HeapStatistics":private]=> - float(%d) + float(1501560832) ["malloced_memory":"V8\HeapStatistics":private]=> - float(%d) + float(8192) ["peak_malloced_memory":"V8\HeapStatistics":private]=> - float(%d) + float(187880) ["does_zap_garbage":"V8\HeapStatistics":private]=> bool(false) } diff --git a/tests/V8Isolate_limit_memory_nested.phpt b/tests/V8Isolate_limit_memory_nested.phpt index 7bd3be4..ef31143 100644 --- a/tests/V8Isolate_limit_memory_nested.phpt +++ b/tests/V8Isolate_limit_memory_nested.phpt @@ -24,10 +24,8 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: $isolate = new V8\Isolate(); -$global_template = new V8\ObjectTemplate($isolate); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); - -$context = new V8\Context($isolate, $global_template); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use (&$helper) { if (!$info->Arguments()) { @@ -38,7 +36,7 @@ $func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info var blob = []; while(true) { blob.push(str); - //print(blob.length, "\n"); + //console.log(blob.length); } '; diff --git a/tests/V8Isolate_limit_memory_not_hit.phpt b/tests/V8Isolate_limit_memory_not_hit.phpt index f0b6581..3f46e8a 100644 --- a/tests/V8Isolate_limit_memory_not_hit.phpt +++ b/tests/V8Isolate_limit_memory_not_hit.phpt @@ -12,19 +12,17 @@ require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); $isolate = new V8\Isolate(); -$global_template = new V8\ObjectTemplate($isolate); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); - -$context = new V8\Context($isolate, $global_template); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $source = ' -print("start\n"); -print("end\n"); +console.log("start"); +console.log("end"); "Script done"'; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); $memory_limit = 1024 * 1024 * 10; $helper->assert('Memory limit accessor report no hit', false === $isolate->IsMemoryLimitHit()); diff --git a/tests/V8Isolate_limit_time_nested.phpt b/tests/V8Isolate_limit_time_nested.phpt index ee7bba8..dd369ae 100644 --- a/tests/V8Isolate_limit_time_nested.phpt +++ b/tests/V8Isolate_limit_time_nested.phpt @@ -10,13 +10,13 @@ $helper = require '.testsuite.php'; require '.tracking_dtors.php'; -$isolate1 = new V8\Isolate(); +$isolate = new V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$global_template = new V8\ObjectTemplate($isolate); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); -$func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) use (&$helper) { +$func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use (&$helper) { if (!$info->Arguments()) { $isolate = $info->GetIsolate(); @@ -45,16 +45,16 @@ $func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $inf }); -$func->SetName(new \V8\StringValue($isolate1, 'custom_name')); +$func->SetName(new \V8\StringValue($isolate, 'custom_name')); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'test'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $func); -$source1 = 'test(test); delete print; "Script done"'; -$file_name1 = 'test.js'; +$source = 'test(test); delete print; "Script done"'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); if ($helper->need_more_time()) { // On travis when valgrind active it takes more time to complete all operations so we just increase initial limits @@ -67,13 +67,13 @@ if ($helper->need_more_time()) { $high_range = 1.65; } -$isolate1->SetTimeLimit($time_limit); -$helper->dump($isolate1); +$isolate->SetTimeLimit($time_limit); +$helper->dump($isolate); $helper->line(); $t = microtime(true); try { - $script1->Run($context1); + $script->Run($context); } catch(\V8\Exceptions\TimeLimitException $e) { $helper->exception_export($e); echo 'script execution terminated', PHP_EOL; @@ -85,7 +85,7 @@ try { } $helper->line(); -$helper->dump($isolate1); +$helper->dump($isolate); ?> --EXPECTF-- object(V8\Isolate)#2 (5) { diff --git a/tests/V8Isolate_limit_time_not_hit.phpt b/tests/V8Isolate_limit_time_not_hit.phpt index b6b3af9..c98d55a 100644 --- a/tests/V8Isolate_limit_time_not_hit.phpt +++ b/tests/V8Isolate_limit_time_not_hit.phpt @@ -12,19 +12,17 @@ require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); $isolate = new V8\Isolate(); -$global_template = new V8\ObjectTemplate($isolate); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); - -$context = new V8\Context($isolate, $global_template); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $source = ' -print("start\n"); -print("end\n"); +console.log("start"); +console.log("end"); "Script done"'; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); $time_limit = 1.5; $helper->assert('Time limit accessor report no hit', false === $isolate->IsTimeLimitHit()); diff --git a/tests/V8Isolate_limit_time_set_during_execution.phpt b/tests/V8Isolate_limit_time_set_during_execution.phpt index 8be9da9..a01de9e 100644 --- a/tests/V8Isolate_limit_time_set_during_execution.phpt +++ b/tests/V8Isolate_limit_time_set_during_execution.phpt @@ -10,10 +10,10 @@ $helper = require '.testsuite.php'; require '.tracking_dtors.php'; -$isolate1 = new V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); if ($helper->need_more_time()) { // On travis when valgrind active it takes more time to complete all operations so we just increase initial limits @@ -26,28 +26,28 @@ if ($helper->need_more_time()) { $high_range = 1.65; } -$func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) use (&$helper, $time_limit) { +$func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use (&$helper, $time_limit) { $isolate = $info->GetIsolate(); $isolate->SetTimeLimit($time_limit); }); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'test'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $func); -$source1 = ' +$source = ' test(); for(;;); "Script done"'; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$helper->dump($isolate1); +$helper->dump($isolate); $helper->line(); $t = microtime(true); try { - $script1->Run($context1); + $script->Run($context); } catch(\V8\Exceptions\TimeLimitException $e) { $helper->exception_export($e); echo 'script execution terminated', PHP_EOL; @@ -59,7 +59,7 @@ try { } $helper->line(); -$helper->dump($isolate1); +$helper->dump($isolate); ?> --EXPECTF-- diff --git a/tests/V8Isolate_nested_termination_exceptions.phpt b/tests/V8Isolate_nested_termination_exceptions.phpt index d85b956..f08d4f4 100644 --- a/tests/V8Isolate_nested_termination_exceptions.phpt +++ b/tests/V8Isolate_nested_termination_exceptions.phpt @@ -10,12 +10,12 @@ $helper = require '.testsuite.php'; require '.tracking_dtors.php'; -$isolate1 = new V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); -$func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) { +$func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) { if (!$info->Arguments()) { $isolate = $info->GetIsolate(); @@ -41,19 +41,19 @@ $func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $inf }); -$func->SetName(new \V8\StringValue($isolate1, 'custom_name')); +$func->SetName(new \V8\StringValue($isolate, 'custom_name')); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'test'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $func); -$source1 = 'test(test); delete print; "Script done"'; -$file_name1 = 'test.js'; +$source = 'test(test); delete print; "Script done"'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); try { - $script1->Run($context1); + $script->Run($context); } catch (\V8\Exceptions\TerminationException $e) { echo 'script execution terminated', PHP_EOL; } diff --git a/tests/V8Isolate_snapshot_support.phpt b/tests/V8Isolate_snapshot_support.phpt index 1284e6a..47f92b9 100644 --- a/tests/V8Isolate_snapshot_support.phpt +++ b/tests/V8Isolate_snapshot_support.phpt @@ -56,8 +56,8 @@ $context = new \V8\Context($isolate); $helper->assert('Context should have test function', $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'test_snapshot'))->IsFunction()); $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test_snapshot'), new \V8\StringValue($isolate, 'garbage')); -$context1 = new \V8\Context($isolate); -$helper->assert('Contexts from the same snapshot doesn\'t affected by each other', $context1->GlobalObject()->Get($context1, new \V8\StringValue($isolate, 'test_snapshot'))->IsFunction()); +$context = new \V8\Context($isolate); +$helper->assert('Contexts from the same snapshot doesn\'t affected by each other', $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'test_snapshot'))->IsFunction()); $isolate2 = new \v8Tests\TrackingDtors\Isolate($data); $context2 = new \V8\Context($isolate2); @@ -71,7 +71,7 @@ $helper->assert('Deleting reference to snapshot is OK after creating Isolate ins $helper->line(); $context = null; -$context1 = null; +$context = null; $context2 = null; $context3 = null; $isolate = null; diff --git a/tests/V8MapObject.phpt b/tests/V8MapObject.phpt index f176654..845dcb1 100644 --- a/tests/V8MapObject.phpt +++ b/tests/V8MapObject.phpt @@ -23,9 +23,10 @@ $helper->header('Object representation'); $helper->dump($value); $helper->space(); -$helper->assert('ObjectValue extends Value', $value instanceof \V8\Value); -$helper->assert('ObjectValue does not extend PrimitiveValue', !($value instanceof \V8\PrimitiveValue)); -$helper->assert('ObjectValue implements AdjustableExternalMemoryInterface', $value instanceof \V8\AdjustableExternalMemoryInterface); +$helper->assert('MapObject extends Value', $value instanceof \V8\Value); +$helper->assert('MapObject does not extend PrimitiveValue', !($value instanceof \V8\PrimitiveValue)); +$helper->assert('MapObject implements AdjustableExternalMemoryInterface', $value instanceof \V8\AdjustableExternalMemoryInterface); +$helper->assert('MapObject is instanceof Map', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Map')))); $helper->line(); $helper->header('Accessors'); @@ -132,9 +133,10 @@ object(V8\MapObject)#6 (2) { } -ObjectValue extends Value: ok -ObjectValue does not extend PrimitiveValue: ok -ObjectValue implements AdjustableExternalMemoryInterface: ok +MapObject extends Value: ok +MapObject does not extend PrimitiveValue: ok +MapObject implements AdjustableExternalMemoryInterface: ok +MapObject is instanceof Map: ok Accessors: ---------- @@ -206,7 +208,7 @@ V8\MapObject(V8\Value)->IsProxy(): bool(false) Converters: ----------- V8\MapObject(V8\Value)->ToBoolean(): - object(V8\BooleanValue)#118 (1) { + object(V8\BooleanValue)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -222,7 +224,7 @@ V8\MapObject(V8\Value)->ToBoolean(): } } V8\MapObject(V8\Value)->ToNumber(): - object(V8\NumberValue)#118 (1) { + object(V8\NumberValue)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -238,7 +240,7 @@ V8\MapObject(V8\Value)->ToNumber(): } } V8\MapObject(V8\Value)->ToString(): - object(V8\StringValue)#118 (1) { + object(V8\StringValue)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -254,7 +256,7 @@ V8\MapObject(V8\Value)->ToString(): } } V8\MapObject(V8\Value)->ToDetailString(): - object(V8\StringValue)#118 (1) { + object(V8\StringValue)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -302,7 +304,7 @@ V8\MapObject(V8\Value)->ToObject(): } } V8\MapObject(V8\Value)->ToInteger(): - object(V8\Int32Value)#118 (1) { + object(V8\Int32Value)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -318,7 +320,7 @@ V8\MapObject(V8\Value)->ToInteger(): } } V8\MapObject(V8\Value)->ToUint32(): - object(V8\Int32Value)#118 (1) { + object(V8\Int32Value)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -334,7 +336,7 @@ V8\MapObject(V8\Value)->ToUint32(): } } V8\MapObject(V8\Value)->ToInt32(): - object(V8\Int32Value)#118 (1) { + object(V8\Int32Value)#120 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8Message.phpt b/tests/V8Message.phpt index d8fd7ed..97ed228 100644 --- a/tests/V8Message.phpt +++ b/tests/V8Message.phpt @@ -12,7 +12,7 @@ $isolate = new \V8\Isolate(); $context = new \V8\Context($isolate); $origin = new \V8\ScriptOrigin('resource_name'); -$trace = new \V8\StackTrace([], new \V8\ArrayObject($context)); +$trace = new \V8\StackTrace([]); $obj = new V8\Message('message', 'source_line', $origin, 'resource_name', $trace); @@ -61,7 +61,7 @@ $helper->space(); --EXPECT-- Object representation (default): -------------------------------- -object(V8\Message)#8 (12) { +object(V8\Message)#7 (12) { ["message":"V8\Message":private]=> string(7) "message" ["script_origin":"V8\Message":private]=> @@ -93,42 +93,10 @@ object(V8\Message)#8 (12) { ["resource_name":"V8\Message":private]=> string(13) "resource_name" ["stack_trace":"V8\Message":private]=> - object(V8\StackTrace)#6 (2) { + object(V8\StackTrace)#6 (1) { ["frames":"V8\StackTrace":private]=> array(0) { } - ["as_array":"V8\StackTrace":private]=> - object(V8\ArrayObject)#7 (2) { - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#2 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - ["context":"V8\ObjectValue":private]=> - object(V8\Context)#3 (1) { - ["isolate":"V8\Context":private]=> - object(V8\Isolate)#2 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - } - } } ["line_number":"V8\Message":private]=> int(0) @@ -165,7 +133,7 @@ V8\Message::IsOpaque() matches expected false Object representation: ---------------------- -object(V8\Message)#9 (12) { +object(V8\Message)#8 (12) { ["message":"V8\Message":private]=> string(7) "message" ["script_origin":"V8\Message":private]=> @@ -197,42 +165,10 @@ object(V8\Message)#9 (12) { ["resource_name":"V8\Message":private]=> string(13) "resource_name" ["stack_trace":"V8\Message":private]=> - object(V8\StackTrace)#6 (2) { + object(V8\StackTrace)#6 (1) { ["frames":"V8\StackTrace":private]=> array(0) { } - ["as_array":"V8\StackTrace":private]=> - object(V8\ArrayObject)#7 (2) { - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#2 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - ["context":"V8\ObjectValue":private]=> - object(V8\Context)#3 (1) { - ["isolate":"V8\Context":private]=> - object(V8\Isolate)#2 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - } - } } ["line_number":"V8\Message":private]=> int(1) diff --git a/tests/V8NameValue.phpt b/tests/V8NameValue.phpt index e5b9398..561dab2 100644 --- a/tests/V8NameValue.phpt +++ b/tests/V8NameValue.phpt @@ -159,7 +159,7 @@ V8\NameValue(V8\Value)->NumberValue(): float(NAN) V8\NameValue::ToString() converting: ------------------------------------ -object(V8\StringValue)#78 (1) { +object(V8\StringValue)#79 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8NullValue.phpt b/tests/V8NullValue.phpt index 38777ce..85938ea 100644 --- a/tests/V8NullValue.phpt +++ b/tests/V8NullValue.phpt @@ -139,7 +139,7 @@ V8\NullValue(V8\Value)->NumberValue(): float(0) V8\NullValue::ToString() converting: ------------------------------------ -object(V8\StringValue)#78 (1) { +object(V8\StringValue)#79 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#1 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8NumberObject.phpt b/tests/V8NumberObject.phpt index 082e911..0125559 100644 --- a/tests/V8NumberObject.phpt +++ b/tests/V8NumberObject.phpt @@ -13,23 +13,18 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); -// TODO: fix it, this cause segfault due to FunctionTemplate object destruction and all it internal structures cleanup -//$global_template1->Set('print', $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$print_func_tpl = $v8_helper->getPrintFunctionTemplate($isolate1); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete); - -$context1 = new V8\Context($isolate1, $global_template1); - -$value = new V8\NumberObject($context1, 42.12); +$value = new V8\NumberObject($context, 42.12); $helper->header('Object representation'); $helper->dump($value); $helper->space(); $helper->assert('NumberObject extends ObjectValue', $value instanceof \V8\ObjectValue); +$helper->assert('NumberObject is instanceof Number', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Number')))); $helper->line(); $helper->header('Getters'); @@ -38,37 +33,37 @@ $helper->space(); $v8_helper->run_checks($value, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); val'; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); $helper->space(); $helper->header('Returned value should be the same'); -$helper->value_matches_with_no_output($res1, $value); +$helper->value_matches_with_no_output($res, $value); $helper->space(); -$source1 = 'new Number(11.22);'; -$file_name1 = 'test.js'; +$source = 'new Number(11.22);'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); -$v8_helper->run_checks($res1, 'Checkers on boxed from script'); +$v8_helper->run_checks($res, 'Checkers on boxed from script'); ?> --EXPECT-- Object representation: ---------------------- -object(V8\NumberObject)#8 (2) { +object(V8\NumberObject)#6 (2) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -83,7 +78,7 @@ object(V8\NumberObject)#8 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#7 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -102,6 +97,7 @@ object(V8\NumberObject)#8 (2) { NumberObject extends ObjectValue: ok +NumberObject is instanceof Number: ok Getters: -------- diff --git a/tests/V8NumberValue.phpt b/tests/V8NumberValue.phpt index a83a67d..cf826e1 100644 --- a/tests/V8NumberValue.phpt +++ b/tests/V8NumberValue.phpt @@ -158,7 +158,7 @@ V8\NumberValue(V8\Value)->IsProxy(): bool(false) V8\NumberValue::ToString() converting: -------------------------------------- -object(V8\StringValue)#78 (1) { +object(V8\StringValue)#79 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8ObjectTemplate_MarkAsUndetectable.phpt b/tests/V8ObjectTemplate_MarkAsUndetectable.phpt deleted file mode 100644 index f56774c..0000000 --- a/tests/V8ObjectTemplate_MarkAsUndetectable.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -V8\ObjectTemplate::MarkAsUndetectable ---SKIPIF-- - - ---FILE-- -Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); - -$test_obj_tpl = new \V8\ObjectTemplate($isolate1); -$test_obj_tpl->MarkAsUndetectable(); - -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_obj_tpl); -$global_template1->Set(new \V8\StringValue($isolate1, 'test2'), new \V8\ObjectTemplate($isolate1)); - -$context1 = new V8\Context($isolate1, $global_template1); - - -$source1 = ' -print("typeof test: ", typeof test, "\n"); -print("test: ", test, "\n"); -print("!test: ", !test, "\n"); - - -print("\n"); -print("typeof test2: ", typeof test2, "\n"); -print("test2: ", test2, "\n"); -print("!test2: ", !test2, "\n"); -'; - -$file_name1 = 'test.js'; - -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); - -?> ---EXPECT-- -typeof test: undefined -test: [object Object] -!test: true - -typeof test2: object -test2: [object Object] -!test2: false diff --git a/tests/V8ObjectTemplate_Set.phpt b/tests/V8ObjectTemplate_Set.phpt index 6d8e7ef..bee8e11 100644 --- a/tests/V8ObjectTemplate_Set.phpt +++ b/tests/V8ObjectTemplate_Set.phpt @@ -5,19 +5,19 @@ V8\ObjectTemplate::Set() - FunctionTemplate --FILE-- Set(new \V8\StringValue($isolate1, 'test'), $test); -$global_template1->Set(new \V8\StringValue($isolate1, 'test2'), $test2); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test); +$global_template->Set(new \V8\StringValue($isolate, 'test2'), $test2); echo 'Done here for now', PHP_EOL; ?> diff --git a/tests/V8ObjectTemplate_SetAccessCheckCallback.phpt b/tests/V8ObjectTemplate_SetAccessCheckCallback.phpt deleted file mode 100644 index 622af2b..0000000 --- a/tests/V8ObjectTemplate_SetAccessCheckCallback.phpt +++ /dev/null @@ -1,325 +0,0 @@ ---TEST-- -V8\ObjectTemplate::SetAccessCheckCallback() ---SKIPIF-- - ---FILE-- - global_template = v8::ObjectTemplate::New(isolate); - -$global_template = new \V8\ObjectTemplate($isolate); - - -$g_echo_value = -1; - -$EchoGetter = function ($name, \V8\PropertyCallbackInfo $info) use (&$g_echo_value) { -// echo 'EchoGetter for ', $name, PHP_EOL; - $info->GetReturnValue()->Set(new \V8\NumberValue($info->GetIsolate(), $g_echo_value)); -}; - -$EchoSetter = function ($name, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (&$g_echo_value) { -// echo 'EchoSetter for ', $name, PHP_EOL; - $g_echo_value = $value->Int32Value($info->GetContext()); -}; - -$UnreachableGetter = function () {throw new \Exception('Unreachable Getter');}; -$UnreachableSetter = function () {throw new \Exception('Unreachable Setter');}; - -$allowed_access = false; - -$AccessBlocker = function (\V8\Context $context, \V8\ObjectValue $object) use (&$isolate, &$allowed_access, $v8_helper, $helper) { - echo 'AccessBlocker called', PHP_EOL; -// echo ' access ', ($allowed_access ? 'allowed' : 'denied'), PHP_EOL; - - //return $isolate->GetEnteredContext()->GlobalObject()->Equals($isolate->GetCurrentContext(), $object) || $allowed_access; - return true; -}; - -$UnreachableFunction = new \V8\FunctionTemplate($isolate, function () {throw new \Exception('Unreachable function');}); - -// global_template->SetAccessCheckCallbacks(AccessBlocker, NULL); -$global_template->SetAccessCheckCallback($AccessBlocker); - -// // Add an accessor accessible by cross-domain JS code. -// global_template->SetAccessor(v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Handle(), v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); -$global_template->SetAccessor(new \V8\StringValue($isolate, 'accessible_prop'), $EchoGetter, $EchoSetter, \V8\AccessControl::ALL_CAN_READ | \V8\AccessControl::ALL_CAN_WRITE); - - -// // Add an accessor that is not accessible by cross-domain JS code. -// global_template->SetAccessor(v8_str("blocked_prop"), UnreachableGetter, UnreachableSetter, v8::Handle(), v8::DEFAULT); -$global_template->SetAccessor(new \V8\StringValue($isolate, 'blocked_prop'), $UnreachableGetter, $UnreachableSetter, \V8\AccessControl::DEFAULT_ACCESS); - - -// global_template->SetAccessorProperty(v8_str("blocked_js_prop"), v8::FunctionTemplate::New(isolate, UnreachableFunction), v8::FunctionTemplate::New(isolate, UnreachableFunction), v8::None, v8::DEFAULT); -$global_template->SetAccessorProperty(new \V8\StringValue($isolate, 'blocked_js_prop'), $UnreachableFunction, $UnreachableFunction, \V8\PropertyAttribute::None, \V8\AccessControl::DEFAULT_ACCESS); - - -// // Create an environment -// v8::Local context0 = Context::New(isolate, NULL, global_template); -// context0->Enter(); -$context0 = new \V8\Context($isolate, $global_template); - -// v8::Handle global0 = context0->Global(); -$global0 = $context0->GlobalObject(); - - -// // Define a property with JS getter and setter. -// CompileRun( -// "function getter() { return 'getter'; };\n" -// "function setter() { return 'setter'; }\n" -// "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})"); - -$v8_helper->CompileRun($context0, - "function getter() { return 'getter'; };\n" . - "function setter() { return 'setter'; }\n" . - "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})"); - -$getter = $global0->Get($context0, new \V8\StringValue($isolate, 'getter')); -$setter = $global0->Get($context0, new \V8\StringValue($isolate, 'setter')); - -// // And define normal element. -// global0->Set(239, v8_str("239")); -$global0->Set($context0, 239, new \V8\StringValue($isolate, '239')); - -// // Define an element with JS getter and setter. -// CompileRun( -// "function el_getter() { return 'el_getter'; };\n" -// "function el_setter() { return 'el_setter'; };\n" -// "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); - -$v8_helper->CompileRun($context0, - "function el_getter() { return 'el_getter'; };\n" . - "function el_setter() { return 'el_setter'; };\n" . - "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); - - -// Local el_getter = global0->Get(v8_str("el_getter")); -// Local el_setter = global0->Get(v8_str("el_setter")); - -$el_getter = $global0->Get($context0, new \V8\StringValue($isolate, 'el_getter')); -$el_setter = $global0->Get($context0, new \V8\StringValue($isolate, 'el_setter')); - - -// v8::HandleScope scope1(isolate); -// -// v8::Local context1 = Context::New(isolate); -// context1->Enter(); -$context1 = new \V8\Context($isolate); - - -// v8::Handle global1 = context1->Global(); -$global1 = $context1->GlobalObject(); - - -// global1->Set(v8_str("other"), global0); -$global1->Set($context1, new \V8\StringValue($isolate, 'other'), $global0); - -// // Access blocked property. -// CompileRun("other.blocked_prop = 1"); -$v8_helper->CompileTryRun($context1, 'other.blocked_prop = 1'); - -// CHECK(CompileRun("other.blocked_prop").IsEmpty()); -$v8_helper->CompileTryRun($context1, 'other.blocked_prop'); - -// CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')").IsEmpty()); -$v8_helper->CompileTryRun($context1, "Object.getOwnPropertyDescriptor(other, 'blocked_prop')"); - -// CHECK(CompileRun("propertyIsEnumerable.call(other, 'blocked_prop')").IsEmpty()); -$v8_helper->CompileTryRun($context1, "propertyIsEnumerable.call(other, 'blocked_prop')"); - -// // Access blocked element. -// CHECK(CompileRun("other[239] = 1").IsEmpty()); -$v8_helper->CompileTryRun($context1, "other[239] = 1"); - -// CHECK(CompileRun("other[239]").IsEmpty()); -$v8_helper->CompileTryRun($context1, "other[239]"); - -// CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, '239')").IsEmpty()); -$v8_helper->CompileTryRun($context1, "Object.getOwnPropertyDescriptor(other, '239')"); - -// CHECK(CompileRun("propertyIsEnumerable.call(other, '239')").IsEmpty()); -$v8_helper->CompileTryRun($context1, "propertyIsEnumerable.call(other, '239')"); - -// allowed_access = true; -$allowed_access = true; - -// // Now we can enumerate the property. -// ExpectTrue("propertyIsEnumerable.call(other, '239')"); -$v8_helper->ExpectTrue($context1, "propertyIsEnumerable.call(other, '239')"); - - -// allowed_access = false; -$allowed_access = false; - -// // Access a property with JS accessor. -// CHECK(CompileRun("other.js_accessor_p = 2").IsEmpty()); -$v8_helper->CompileTryRun($context1, "other.js_accessor_p = 2"); - -// CHECK(CompileRun("other.js_accessor_p").IsEmpty()); -$v8_helper->CompileTryRun($context1, "other.js_accessor_p"); - -// CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'js_accessor_p')").IsEmpty()); -$v8_helper->CompileTryRun($context1, "Object.getOwnPropertyDescriptor(other, 'js_accessor_p')"); - -// allowed_access = true; -$allowed_access = true; - -// ExpectString("other.js_accessor_p", "getter"); -$v8_helper->ExpectString($context1, "other.js_accessor_p", "getter"); - - -// ExpectObject("Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", getter); -$v8_helper->ExpectObject($context1, "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').get", $getter); - -// ExpectObject("Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", setter); -$v8_helper->ExpectObject($context1, "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').set", $setter); - -// ExpectUndefined("Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value"); -$v8_helper->ExpectUndefined($context1, "Object.getOwnPropertyDescriptor(other, 'js_accessor_p').value"); - -// allowed_access = false; -$allowed_access = false; - -// // Access an element with JS accessor. -// CHECK(CompileRun("other[42] = 2").IsEmpty()); -$v8_helper->CompileTryRun($context1, "other[42] = 2"); - -// CHECK(CompileRun("other[42]").IsEmpty()); -$v8_helper->CompileTryRun($context1, "other[42]"); - -// CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, '42')").IsEmpty()); -$v8_helper->CompileTryRun($context1, "Object.getOwnPropertyDescriptor(other, '42')"); - -// allowed_access = true; -$allowed_access = true; - -// ExpectString("other[42]", "el_getter"); -$v8_helper->ExpectString($context1, "other[42]", "el_getter"); - -// ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter); -$v8_helper->ExpectObject($context1, "Object.getOwnPropertyDescriptor(other, '42').get", $el_getter); - -// ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter); -$v8_helper->ExpectObject($context1, "Object.getOwnPropertyDescriptor(other, '42').set", $el_setter); - -// ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value"); -$v8_helper->ExpectUndefined($context1, "Object.getOwnPropertyDescriptor(other, '42').value"); - - -// allowed_access = false; -$allowed_access = false; - -// // Access accessible property -// value = CompileRun("other.accessible_prop = 3"); -// CHECK(value->IsNumber()); -// CHECK_EQ(3, value->Int32Value()); -$v8_helper->ExpectNumber($context1, "other.accessible_prop = 3", 3); -// CHECK_EQ(3, g_echo_value); -$helper->value_matches(3, $g_echo_value); - - -// value = CompileRun("other.accessible_prop"); -// CHECK(value->IsNumber()); -// CHECK_EQ(3, value->Int32Value()); -$v8_helper->ExpectNumber($context1, "other.accessible_prop", 3); - -// value = CompileRun("Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); -// CHECK(value->IsNumber()); -// CHECK_EQ(3, value->Int32Value()); -$v8_helper->ExpectNumber($context1, "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value", 3); - -// value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); -// CHECK(value->IsTrue()); -$v8_helper->ExpectTrue($context1, "propertyIsEnumerable.call(other, 'accessible_prop')"); - -// // Enumeration doesn't enumerate accessors from inaccessible objects in -// // the prototype chain even if the accessors are in themselves accessible. -// // Enumeration doesn't throw, it silently ignores what it can't access. -// value = CompileRun( -// "(function() {" -// " var obj = { '__proto__': other };" -// " try {" -// " for (var p in obj) {" -// " if (p == 'accessible_prop' ||" -// " p == 'blocked_js_prop' ||" -// " p == 'blocked_js_prop') {" -// " return false;" -// " }" -// " }" -// " return true;" -// " } catch (e) {" -// " return false;" -// " }" -// "})()"); -// CHECK(value->IsTrue()); -//} - -$v8_helper->ExpectTrue($context1, - "(function() {" . - " var obj = { '__proto__': other };" . - " try {" . - " for (var p in obj) {" . - " if (p == 'accessible_prop' ||" . - " p == 'blocked_js_prop' ||" . - " p == 'blocked_js_prop') {" . - " return false;" . - " }" . - " }" . - " return true;" . - " } catch (e) {" . - " return false;" . - " }" . - "})()"); - - -?> ---XFAIL-- -Waiting for data parameter to be added to AccessCheck callback, https://groups.google.com/d/msg/v8-dev/c7LhW2bNabY/2p8U7KtgDQAJ -TODO: test null-callback ---EXPECT-- -other.blocked_prop = 1: V8\Exceptions\TryCatchException: TypeError: no access -other.blocked_prop: V8\Exceptions\TryCatchException: TypeError: no access -Object.getOwnPropertyDescriptor(other, 'blocked_prop'): V8\Exceptions\TryCatchException: TypeError: no access -propertyIsEnumerable.call(other, 'blocked_prop'): V8\Exceptions\TryCatchException: TypeError: no access -other[239] = 1: V8\Exceptions\TryCatchException: TypeError: no access -other[239]: V8\Exceptions\TryCatchException: TypeError: no access -Object.getOwnPropertyDescriptor(other, '239'): V8\Exceptions\TryCatchException: TypeError: no access -propertyIsEnumerable.call(other, '239'): V8\Exceptions\TryCatchException: TypeError: no access -Expected true value is identical to actual value true -other.js_accessor_p = 2: V8\Exceptions\TryCatchException: TypeError: no access -other.js_accessor_p: V8\Exceptions\TryCatchException: TypeError: no access -Object.getOwnPropertyDescriptor(other, 'js_accessor_p'): V8\Exceptions\TryCatchException: TypeError: no access -Expected 'getter' value is identical to actual value 'getter' -Actual and expected objects are the same -Actual and expected objects are the same -Actual result for expected value is undefined -other[42] = 2: V8\Exceptions\TryCatchException: TypeError: no access -other[42]: V8\Exceptions\TryCatchException: TypeError: no access -Object.getOwnPropertyDescriptor(other, '42'): V8\Exceptions\TryCatchException: TypeError: no access -Expected 'el_getter' value is identical to actual value 'el_getter' -Actual and expected objects are the same -Actual and expected objects are the same -Actual result for expected value is undefined -Expected 3 value is identical to actual value 3 -Expected 3 value is identical to actual value 3 -Expected 3 value is identical to actual value 3 -Expected 3 value is identical to actual value 3 -Expected true value is identical to actual value true -Expected true value is identical to actual value true diff --git a/tests/V8ObjectTemplate_SetAccessCheckCallback_func_args.phpt b/tests/V8ObjectTemplate_SetAccessCheckCallback_func_args.phpt deleted file mode 100644 index aea90cb..0000000 --- a/tests/V8ObjectTemplate_SetAccessCheckCallback_func_args.phpt +++ /dev/null @@ -1,157 +0,0 @@ ---TEST-- -V8\ObjectTemplate::SetAccessCheckCallbacks() - test access check callback function arguments ---SKIPIF-- - ---FILE-- - - // NOTE: type is never used and always v8::AccessType::ACCESS_HAS used - - $helper->dump(func_get_args(), 1); - return true; -}; - -$g_echo_value = -1; - -$EchoGetter = function ($name, \V8\PropertyCallbackInfo $info) use (&$g_echo_value) { - echo 'EchoGetter for ', $name, PHP_EOL; - $info->GetReturnValue()->Set(new \V8\NumberValue($info->GetIsolate(), $g_echo_value)); -}; - -$EchoSetter = function ($name, $value, \V8\PropertyCallbackInfo $info) use (&$g_echo_value) { - echo 'EchoSetter for ', $name, PHP_EOL; -}; - -$test_obj_tpl = new \V8\ObjectTemplate($isolate); -$test_obj_tpl->SetHandler(new \V8\IndexedPropertyHandlerConfiguration($EchoGetter, $EchoSetter)); -$test_obj_tpl->SetHandler(new \V8\NamedPropertyHandlerConfiguration($EchoGetter, $EchoSetter)); -$test_obj_tpl->SetAccessCheckCallback($access_check_callback); - - -$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_obj_tpl); - -$context0 = new \V8\Context($isolate, $global_template); - -$other = $context0->GlobalObject()->Get($context0, new \V8\StringValue($isolate, 'test')); - -$context1 = new \V8\Context($isolate); - -$global1 = $context1->GlobalObject(); - -$global1->Set($context1, new \V8\StringValue($isolate, 'other'), $other); - - -echo 'Property accessor:'; -$v8_helper->CompileTryRun($context1, 'other.foo'); -echo PHP_EOL; -echo 'Index accessor:'; -$v8_helper->CompileTryRun($context1, 'other[1]'); -echo PHP_EOL; - -?> ---XFAIL-- -Waiting for data parameter to be added to AccessCheck callback, https://groups.google.com/d/msg/v8-dev/c7LhW2bNabY/2p8U7KtgDQAJ -TODO: test null-callback ---EXPECT-- -Property accessor: - array(3) refcount(3){ - [0]=> - object(V8\ObjectValue)#13 (2) refcount(5){ - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - ["context":"V8\ObjectValue":private]=> - object(V8\Context)#10 (4) refcount(2){ - ["isolate":"V8\Context":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - ["extensions":"V8\Context":private]=> - array(0) refcount(2){ - } - ["global_template":"V8\Context":private]=> - object(V8\ObjectTemplate)#4 (1) refcount(2){ - ["isolate":"V8\Template":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - } - ["global_object":"V8\Context":private]=> - NULL - } - } - [1]=> - object(V8\Value)#17 (1) refcount(4){ - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - } - [2]=> - int(2) - } -EchoGetter for foo - -Index accessor: - array(3) refcount(3){ - [0]=> - object(V8\ObjectValue)#13 (2) refcount(5){ - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - ["context":"V8\ObjectValue":private]=> - object(V8\Context)#10 (4) refcount(2){ - ["isolate":"V8\Context":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - ["extensions":"V8\Context":private]=> - array(0) refcount(2){ - } - ["global_template":"V8\Context":private]=> - object(V8\ObjectTemplate)#4 (1) refcount(2){ - ["isolate":"V8\Template":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - } - ["global_object":"V8\Context":private]=> - NULL - } - } - [1]=> - object(V8\Value)#16 (1) refcount(4){ - ["isolate":"V8\Value":private]=> - object(V8\Isolate)#3 (1) refcount(11){ - ["snapshot":"V8\Isolate":private]=> - NULL - } - } - [2]=> - int(2) - } -EchoGetter for 1 diff --git a/tests/V8ObjectTemplate_SetAccessor_receiver.phpt b/tests/V8ObjectTemplate_SetAccessor_receiver.phpt new file mode 100644 index 0000000..3ea99af --- /dev/null +++ b/tests/V8ObjectTemplate_SetAccessor_receiver.phpt @@ -0,0 +1,86 @@ +--TEST-- +V8\ObjectTemplate::SetAccessor() - with receiver +--SKIPIF-- + +--FILE-- +injectConsoleLog($context); + +$getter_checks = 0; + +$getter = function (\V8\NameValue $prop, \V8\PropertyCallbackInfo $info) use (&$getter_checks) { + echo 'Getter callback', PHP_EOL; + $getter_checks++; +}; + +$setter_checks = 0; + +$setter = function (\V8\NameValue $prop, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (&$setter_checks) { + echo 'Setter callback', PHP_EOL; + $setter_checks++; +}; + + +$templ = new \V8\FunctionTemplate($isolate); + +$inst = $templ->InstanceTemplate(); +$inst->SetAccessor(new \V8\StringValue($isolate, 'foo'), $getter, $setter, \V8\AccessControl::DEFAULT_ACCESS, \V8\PropertyAttribute::None, $templ); + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'f'), $templ->GetFunction($context)); + +$helper->header('Testing positive'); +$obj = $v8_helper->CompileRun($context, "var obj = new f(); obj"); +$v8_helper->CHECK($templ->HasInstance($obj), '$obj instance of $templ'); + +// Test path through generic runtime code. +$v8_helper->CompileRun($context, "obj.foo"); +$v8_helper->CompileRun($context, "obj.foo = 23"); + +$helper->line(); + +$helper->header('Testing negative'); + +$obj = $v8_helper->CompileRun($context, "var obj = {}; obj.__proto__ = new f(); obj"); +$v8_helper->CHECK(!$templ->HasInstance($obj), '$obj is not an instance of $templ'); + +// Test path through generic runtime code. +try { + $v8_helper->CompileRun($context, "obj.foo"); + $helper->fail(); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +try { + $v8_helper->CompileRun($context, "obj.foo = 23"); + $helper->fail(); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} + +$helper->line(); +echo 'Done here for now', PHP_EOL; +?> +--EXPECT-- +Testing positive: +----------------- +CHECK $obj instance of $templ: OK +Getter callback +Setter callback + +Testing negative: +----------------- +CHECK $obj is not an instance of $templ: OK +V8\Exceptions\TryCatchException: TypeError: Method foo called on incompatible receiver [object Object] +V8\Exceptions\TryCatchException: TypeError: Method foo called on incompatible receiver [object Object] + +Done here for now diff --git a/tests/V8ObjectTemplate_SetCallAsFunctionHandler.phpt b/tests/V8ObjectTemplate_SetCallAsFunctionHandler.phpt index 54ca0e1..28b3e89 100644 --- a/tests/V8ObjectTemplate_SetCallAsFunctionHandler.phpt +++ b/tests/V8ObjectTemplate_SetCallAsFunctionHandler.phpt @@ -11,10 +11,8 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); - -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); $callback = function (\V8\FunctionCallbackInfo $info) { $out = []; @@ -30,41 +28,41 @@ $callback = function (\V8\FunctionCallbackInfo $info) { $info->GetReturnValue()->Set(new \V8\StringValue($info->GetIsolate(), 'done')); }; -$test_obj_tpl = new \V8\ObjectTemplate($isolate1); +$test_obj_tpl = new \V8\ObjectTemplate($isolate); $test_obj_tpl->SetCallAsFunctionHandler($callback); -$global_template1->Set(new \V8\StringValue($isolate1, 'func'), new \V8\FunctionTemplate($isolate1)); -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_obj_tpl); -$global_template1->Set(new \V8\StringValue($isolate1, 'test2'), new \V8\ObjectTemplate($isolate1)); - -$context1 = new V8\Context($isolate1, $global_template1); +$global_template->Set(new \V8\StringValue($isolate, 'func'), new \V8\FunctionTemplate($isolate)); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_obj_tpl); +$global_template->Set(new \V8\StringValue($isolate, 'test2'), new \V8\ObjectTemplate($isolate)); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$source1 = ' -print("typeof func: ", typeof func, "\n"); -print("func: ", func, "\n"); -print("func(): ", func("should", "pass"), "\n"); +$source = ' +console.log("typeof func: ", typeof func); +console.log("func: ", func); +console.log("func(): ", func("should", "pass")); -print("\n"); -print("typeof test: ", typeof test, "\n"); -print("test: ", test, "\n"); -print("test(): ", test("should", "pass"), "\n"); +console.log(); +console.log("typeof test: ", typeof test); +console.log("test: ", test); +console.log("test(): ", test("should", "pass")); -print("\n"); -print("typeof test2: ", typeof test2, "\n"); -print("test2: ", test2, "\n"); +console.log(); +console.log("typeof test2: ", typeof test2); +console.log("test2: ", test2); try { - print("test2(): ", test2("will", "fail"), "\n"); + console.log("test2(): ", test2("will", "fail")); } catch (e) { - print(e, "\n"); + console.log(e); } '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); ?> --EXPECT-- diff --git a/tests/V8ObjectTemplate_SetHandlerForIndexedProperty.phpt b/tests/V8ObjectTemplate_SetHandlerForIndexedProperty.phpt index 7e12bdb..aa59f96 100644 --- a/tests/V8ObjectTemplate_SetHandlerForIndexedProperty.phpt +++ b/tests/V8ObjectTemplate_SetHandlerForIndexedProperty.phpt @@ -11,10 +11,8 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); - -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); $foo = 100; @@ -71,36 +69,37 @@ $test = function () { }; -$test_obj_tpl = new \V8\ObjectTemplate($isolate1); +$test_obj_tpl = new \V8\ObjectTemplate($isolate); $test_obj_tpl->SetHandlerForIndexedProperty(new \V8\IndexedPropertyHandlerConfiguration($getter, $setter, $query, $deleter, $enumerator)); -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_obj_tpl); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_obj_tpl); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$source1 = ' +$source = ' -print("\"0\" in test: ", "0" in test, "\n"); -print("0 in test: ", 0 in test, "\n"); +console.log("\"0\" in test: ", "0" in test); +console.log("0 in test: ", 0 in test); -print("\"1\" in test: ", "1" in test, "\n"); -print("1 in test: ", 1 in test, "\n"); +console.log("\"1\" in test: ", "1" in test); +console.log("1 in test: ", 1 in test); -print("test[0] = 42: ", test[0] = 42, "\n"); -print("test[0]: ", test[0], "\n"); +console.log("test[0] = 42: ", test[0] = 42); +console.log("test[0]: ", test[0]); -print("delete test[0]: ", delete test[0], "\n"); -print("test[0]: ", test[0], "\n"); +console.log("delete test[0]: ", delete test[0]); +console.log("test[0]: ", test[0]); for (i in test) { - print("test["+i+"]: ", test[i], "\n"); + console.log("test["+i+"]: ", test[i]); } '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); ?> --EXPECT-- diff --git a/tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt b/tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt index 51cd198..24f9848 100644 --- a/tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt +++ b/tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt @@ -11,10 +11,8 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); - -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); $foo = 100; @@ -58,33 +56,34 @@ $enumerator = function (\V8\PropertyCallbackInfo $info) use (&$foo) { }; -$test_obj_tpl = new \V8\ObjectTemplate($isolate1); +$test_obj_tpl = new \V8\ObjectTemplate($isolate); $test_obj_tpl->SetHandlerForNamedProperty(new \V8\NamedPropertyHandlerConfiguration($getter, $setter, $query, $deleter, $enumerator)); -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_obj_tpl); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_obj_tpl); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$source1 = ' -print("\"foo\" in test: ", "foo" in test, "\n"); -print("\"bar\" in test: ", "bar" in test, "\n"); +$source = ' +console.log("\"foo\" in test: ", "foo" in test); +console.log("\"bar\" in test: ", "bar" in test); -print("test.foo: ", test.foo, "\n"); -print("test.foo = 42: ", test.foo = 42, "\n"); -print("test.foo: ", test.foo, "\n"); +console.log("test.foo: ", test.foo); +console.log("test.foo = 42: ", test.foo = 42); +console.log("test.foo: ", test.foo); -print("delete test.foo: ", delete test.foo, "\n"); -print("\"foo\" in test: ", "foo" in test, "\n"); +console.log("delete test.foo: ", delete test.foo); +console.log("\"foo\" in test: ", "foo" in test); for (i in test) { - print("test["+i+"]: ", test[i], "\n"); + console.log("test["+i+"]: ", test[i]); } '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); ?> --EXPECT-- diff --git a/tests/V8ObjectTemplate_SetHandler_both.phpt b/tests/V8ObjectTemplate_SetHandler_both.phpt index 1a62f28..fec3260 100644 --- a/tests/V8ObjectTemplate_SetHandler_both.phpt +++ b/tests/V8ObjectTemplate_SetHandler_both.phpt @@ -11,10 +11,8 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); - -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); $allow_named = false; $allow_indexed = false; @@ -63,7 +61,7 @@ $enumerator = function (\V8\PropertyCallbackInfo $info) use (&$foo, &$allow_name }; -$test_obj_tpl = new \V8\ObjectTemplate($isolate1); +$test_obj_tpl = new \V8\ObjectTemplate($isolate); $test_obj_tpl->SetHandlerForNamedProperty(new \V8\NamedPropertyHandlerConfiguration($getter, $setter, $query, $deleter, $enumerator)); @@ -117,62 +115,62 @@ $test_obj_tpl->SetHandlerForIndexedProperty(new \V8\IndexedPropertyHandlerConfig -$global_template1->Set(new \V8\StringValue($isolate1, 'test'), $test_obj_tpl); - -$context1 = new V8\Context($isolate1, $global_template1); +$global_template->Set(new \V8\StringValue($isolate, 'test'), $test_obj_tpl); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$source1 = ' -print("\"foo\" in test: ", "foo" in test, "\n"); -print("\"bar\" in test: ", "bar" in test, "\n"); +$source = ' +console.log("\"foo\" in test: ", "foo" in test); +console.log("\"bar\" in test: ", "bar" in test); -print("test.foo: ", test.foo, "\n"); -print("test.foo = 42: ", test.foo = 42, "\n"); -print("test.foo: ", test.foo, "\n"); +console.log("test.foo: ", test.foo); +console.log("test.foo = 42: ", test.foo = 42); +console.log("test.foo: ", test.foo); -print("delete test.foo: ", delete test.foo, "\n"); -print("\"foo\" in test: ", "foo" in test, "\n"); +console.log("delete test.foo: ", delete test.foo); +console.log("\"foo\" in test: ", "foo" in test); for (i in test) { - print("test["+i+"]: ", test[i], "\n"); + console.log("test["+i+"]: ", test[i]); } '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; $allow_named = true; $allow_indexed = false; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); $helper->space(); -$source1 = ' +$source = ' -print("\"0\" in test: ", "0" in test, "\n"); -print("0 in test: ", 0 in test, "\n"); +console.log("\"0\" in test: ", "0" in test); +console.log("0 in test: ", 0 in test); -print("\"1\" in test: ", "1" in test, "\n"); -print("1 in test: ", 1 in test, "\n"); +console.log("\"1\" in test: ", "1" in test); +console.log("1 in test: ", 1 in test); -print("test[0] = 42: ", test[0] = 42, "\n"); -print("test[0]: ", test[0], "\n"); +console.log("test[0] = 42: ", test[0] = 42); +console.log("test[0]: ", test[0]); -print("delete test[0]: ", delete test[0], "\n"); -print("test[0]: ", test[0], "\n"); +console.log("delete test[0]: ", delete test[0]); +console.log("test[0]: ", test[0]); for (i in test) { - print("test["+i+"]: ", test[i], "\n"); + console.log("test["+i+"]: ", test[i]); } '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; $allow_named = false; $allow_indexed = true; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); ?> --EXPECT-- diff --git a/tests/V8ObjectTemplate_SetNativeDataProperty.phpt b/tests/V8ObjectTemplate_SetNativeDataProperty.phpt new file mode 100644 index 0000000..99d92f4 --- /dev/null +++ b/tests/V8ObjectTemplate_SetNativeDataProperty.phpt @@ -0,0 +1,64 @@ +--TEST-- +V8\ObjectTemplate::SetNativeDataProperty +--SKIPIF-- + +--FILE-- +ToString($info->GetContext())->Value(), ' called, value is ', $prop_value, PHP_EOL; + + $info->GetReturnValue()->Set(new \V8\StringValue($info->GetIsolate(), $prop_value)); +}; + +$setter = function (\V8\NameValue $property, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (& $prop_value) { + $val = $value->ToString($info->GetContext())->Value(); + echo 'Userland native setter on property ', $property->ToString($info->GetContext())->Value(), ' called with ', $val, ', value is ', $prop_value, PHP_EOL; + + $prop_value = $val; +}; + +$tpl = new V8\ObjectTemplate($isolate); +$tpl->SetNativeDataProperty(new \V8\StringValue($isolate, 'test'), $getter, $setter); + + +$context = new V8\Context($isolate); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj'), $tpl->NewInstance($context)); + +$v8_helper->injectConsoleLog($context); + +$source = ' +console.log(obj.test, "\n"); +obj.test = "bar"; +console.log(obj.test, "\n"); + +"Script done"; +'; +$file_name = 'test.js'; + + +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); + +$v8_helper->CompileRun($context, $source); + +?> +--EXPECT-- +Userland native getter on property test called, value is foo +foo + +Userland native setter on property test called with bar, value is foo +Userland native getter on property test called, value is bar +bar diff --git a/tests/V8ObjectValue.phpt b/tests/V8ObjectValue.phpt index 099935e..9fcc52c 100644 --- a/tests/V8ObjectValue.phpt +++ b/tests/V8ObjectValue.phpt @@ -26,6 +26,7 @@ $helper->space(); $helper->assert('ObjectValue extends Value', $value instanceof \V8\Value); $helper->assert('ObjectValue does not extend PrimitiveValue', !($value instanceof \V8\PrimitiveValue)); $helper->assert('ObjectValue implements AdjustableExternalMemoryInterface', $value instanceof \V8\AdjustableExternalMemoryInterface); +$helper->assert('ObjectValue is instanceof Object', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Object')))); $helper->line(); $helper->header('Accessors'); @@ -82,6 +83,7 @@ object(V8\ObjectValue)#6 (2) { ObjectValue extends Value: ok ObjectValue does not extend PrimitiveValue: ok ObjectValue implements AdjustableExternalMemoryInterface: ok +ObjectValue is instanceof Object: ok Accessors: ---------- @@ -153,7 +155,7 @@ V8\ObjectValue(V8\Value)->IsProxy(): bool(false) Converters: ----------- V8\ObjectValue(V8\Value)->ToBoolean(): - object(V8\BooleanValue)#115 (1) { + object(V8\BooleanValue)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -169,7 +171,7 @@ V8\ObjectValue(V8\Value)->ToBoolean(): } } V8\ObjectValue(V8\Value)->ToNumber(): - object(V8\NumberValue)#115 (1) { + object(V8\NumberValue)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -185,7 +187,7 @@ V8\ObjectValue(V8\Value)->ToNumber(): } } V8\ObjectValue(V8\Value)->ToString(): - object(V8\StringValue)#115 (1) { + object(V8\StringValue)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -201,7 +203,7 @@ V8\ObjectValue(V8\Value)->ToString(): } } V8\ObjectValue(V8\Value)->ToDetailString(): - object(V8\StringValue)#115 (1) { + object(V8\StringValue)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -249,7 +251,7 @@ V8\ObjectValue(V8\Value)->ToObject(): } } V8\ObjectValue(V8\Value)->ToInteger(): - object(V8\Int32Value)#115 (1) { + object(V8\Int32Value)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -265,7 +267,7 @@ V8\ObjectValue(V8\Value)->ToInteger(): } } V8\ObjectValue(V8\Value)->ToUint32(): - object(V8\Int32Value)#115 (1) { + object(V8\Int32Value)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -281,7 +283,7 @@ V8\ObjectValue(V8\Value)->ToUint32(): } } V8\ObjectValue(V8\Value)->ToInt32(): - object(V8\Int32Value)#115 (1) { + object(V8\Int32Value)#117 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8ObjectValue_IsArgumentsObject.phpt b/tests/V8ObjectValue_IsArgumentsObject.phpt index d9f071a..c31940d 100644 --- a/tests/V8ObjectValue_IsArgumentsObject.phpt +++ b/tests/V8ObjectValue_IsArgumentsObject.phpt @@ -13,26 +13,26 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new V8\Context($isolate, $global_template); //THREADED_TEST(ArgumentsObject) // v8::Handle arguments_object = CompileRun("var out = 0; (function(){ out = arguments; })(1,2,3); out;"); -$arguments_object = $v8_helper->CompileRun($context1, "var out = 0; (function(){ out = arguments; })(1,2,3); out;"); +$arguments_object = $v8_helper->CompileRun($context, "var out = 0; (function(){ out = arguments; })(1,2,3); out;"); // CHECK(arguments_object->IsArgumentsObject()); $v8_helper->CHECK($arguments_object->IsArgumentsObject(), '$arguments_object->IsArgumentsObject()'); // v8::Handle array = CompileRun("[1,2,3]"); -$array = $v8_helper->CompileRun($context1, "[1,2,3]"); +$array = $v8_helper->CompileRun($context, "[1,2,3]"); // CHECK(!array->IsArgumentsObject()); $v8_helper->CHECK(!$array->IsArgumentsObject(), '!$array->IsArgumentsObject()'); // v8::Handle object = CompileRun("{a:42}"); -$object = $v8_helper->CompileRun($context1, "{a:42}"); +$object = $v8_helper->CompileRun($context, "{a:42}"); // CHECK(!object->IsArgumentsObject()); $v8_helper->CHECK(!$object->IsArgumentsObject(), '!$object->IsArgumentsObject()'); diff --git a/tests/V8ObjectValue_IsNativeError.phpt b/tests/V8ObjectValue_IsNativeError.phpt index 974232a..9456701 100644 --- a/tests/V8ObjectValue_IsNativeError.phpt +++ b/tests/V8ObjectValue_IsNativeError.phpt @@ -13,27 +13,27 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); -$context1 = new V8\Context($isolate1, $global_template1); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); +$context = new V8\Context($isolate, $global_template); // THREADED_TEST(IsNativeError) //v8::Handle syntax_error = CompileRun("var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); -$syntax_error = $v8_helper->CompileRun($context1, "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); +$syntax_error = $v8_helper->CompileRun($context, "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); // CHECK(syntax_error->IsNativeError()); $v8_helper->CHECK($syntax_error->IsNativeError(), '$syntax_error->IsNativeError()'); // v8::Handle not_error = CompileRun("{a:42}"); -$not_error = $v8_helper->CompileRun($context1, "{a:42}"); +$not_error = $v8_helper->CompileRun($context, "{a:42}"); // CHECK(!not_error->IsNativeError()); $v8_helper->CHECK(!$not_error->IsNativeError(), '!$not_error->IsNativeError()'); // v8::Handle not_object = CompileRun("42"); -$not_object = $v8_helper->CompileRun($context1, "42"); +$not_object = $v8_helper->CompileRun($context, "42"); // CHECK(!not_object->IsNativeError()); $v8_helper->CHECK(!$not_object->IsNativeError(), '!$not_object->IsNativeError()'); diff --git a/tests/V8ObjectValue_SetAccessor.phpt b/tests/V8ObjectValue_SetAccessor.phpt index ea3193c..7c46ce1 100644 --- a/tests/V8ObjectValue_SetAccessor.phpt +++ b/tests/V8ObjectValue_SetAccessor.phpt @@ -11,12 +11,14 @@ V8\ObjectValue::SetAccessor /** @var \Phpv8Testsuite $helper */ $helper = require '.testsuite.php'; +require '.v8-helpers.php'; +$v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); -$print_func_tpl = new \V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackInfo $info) { +$print_func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) { $context = $info->GetContext(); $out = []; @@ -33,12 +35,12 @@ $print_func_tpl = new \V8\FunctionTemplate($isolate1, function (\V8\FunctionCall } } - echo implode('', $out); + echo implode('', $out), PHP_EOL; }); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete); +$global_template->Set(new \V8\StringValue($isolate, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); $prop_value = 'foo'; @@ -57,25 +59,25 @@ $setter = function (\V8\NameValue $property, \V8\Value $value, \V8\PropertyCallb }; -$obj = new \V8\ObjectValue($context1); +$obj = new \V8\ObjectValue($context); -$obj->SetAccessor($context1, new \V8\StringValue($isolate1, 'test'), $getter, $setter); +$obj->SetAccessor($context, new \V8\StringValue($isolate, 'test'), $getter, $setter); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'obj'), $obj); -$source1 = ' -print(obj.test, "\n"); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj'), $obj); +$source = ' +print(obj.test); obj.test = "bar"; -print(obj.test, "\n"); +print(obj.test); "Script done"; '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$helper->dump($script1->Run($context1)->ToString($context1)->Value()); +$helper->dump($script->Run($context)->ToString($context)->Value()); ?> --EXPECT-- diff --git a/tests/V8ObjectValue_SetIntegrityLevel.phpt b/tests/V8ObjectValue_SetIntegrityLevel.phpt index 0befa00..097c6ec 100644 --- a/tests/V8ObjectValue_SetIntegrityLevel.phpt +++ b/tests/V8ObjectValue_SetIntegrityLevel.phpt @@ -11,28 +11,28 @@ $helper = require '.testsuite.php'; require '.v8-helpers.php'; $v8_helper = new PhpV8Helpers($helper); -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$global_template = new V8\ObjectTemplate($isolate); -$context1 = new V8\Context($isolate1, $global_template1); -$v8_helper->injectConsoleLog($context1); +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$obj0 = new \V8\ObjectValue($context1); -$obj0->Set($context1, new \V8\StringValue($isolate1, 'test'), new \V8\IntegerValue($isolate1, 42)); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'obj0'), $obj0); +$obj0 = new \V8\ObjectValue($context); +$obj0->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\IntegerValue($isolate, 42)); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj0'), $obj0); -$obj1 = new \V8\ObjectValue($context1); -$obj1->Set($context1, new \V8\StringValue($isolate1, 'test'), new \V8\IntegerValue($isolate1, 42)); -$obj1->SetIntegrityLevel($context1, \V8\IntegrityLevel::kFrozen); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'obj1'), $obj1); +$obj1 = new \V8\ObjectValue($context); +$obj1->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\IntegerValue($isolate, 42)); +$obj1->SetIntegrityLevel($context, \V8\IntegrityLevel::kFrozen); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj1'), $obj1); -$obj2 = new \V8\ObjectValue($context1); -$obj2->Set($context1, new \V8\StringValue($isolate1, 'test'), new \V8\IntegerValue($isolate1, 42)); -$obj2->SetIntegrityLevel($context1, \V8\IntegrityLevel::kSealed); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'obj2'), $obj2); +$obj2 = new \V8\ObjectValue($context); +$obj2->Set($context, new \V8\StringValue($isolate, 'test'), new \V8\IntegerValue($isolate, 42)); +$obj2->SetIntegrityLevel($context, \V8\IntegrityLevel::kSealed); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj2'), $obj2); -$source1 = ' +$source = ' console.log(Object.isFrozen(obj0)); console.log(Object.isSealed(obj0)); console.log(obj0.test); @@ -67,11 +67,11 @@ console.log(); '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$script1->Run($context1); +$script->Run($context); ?> --EXPECT-- diff --git a/tests/V8ObjectValue_SetNativeDataProperty.phpt b/tests/V8ObjectValue_SetNativeDataProperty.phpt new file mode 100644 index 0000000..529b278 --- /dev/null +++ b/tests/V8ObjectValue_SetNativeDataProperty.phpt @@ -0,0 +1,66 @@ +--TEST-- +V8\ObjectValue::SetNativeDataProperty +--SKIPIF-- + +--FILE-- +ToString($info->GetContext())->Value(), ' called, value is ', $prop_value, PHP_EOL; + + $info->GetReturnValue()->Set(new \V8\StringValue($info->GetIsolate(), $prop_value)); +}; + +$setter = function (\V8\NameValue $property, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (& $prop_value) { + $val = $value->ToString($info->GetContext())->Value(); + echo 'Userland native setter on property ', $property->ToString($info->GetContext())->Value(), ' called with ', $val, ', value is ', $prop_value, PHP_EOL; + + $prop_value = $val; +}; + + + +$context = new V8\Context($isolate); + +$obj = new V8\ObjectValue($context); +$obj->SetNativeDataProperty($context, new \V8\StringValue($isolate, 'test'), $getter, $setter); + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj'), $obj); + +$v8_helper->injectConsoleLog($context); + +$source = ' +console.log(obj.test, "\n"); +obj.test = "bar"; +console.log(obj.test, "\n"); + +"Script done"; +'; +$file_name = 'test.js'; + + +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); + +$v8_helper->CompileRun($context, $source); + +?> +--EXPECT-- +Userland native getter on property test called, value is foo +foo + +Userland native setter on property test called with bar, value is foo +Userland native getter on property test called, value is bar +bar diff --git a/tests/V8ObjectValue_SetNativeDataProperty_from_template.phpt b/tests/V8ObjectValue_SetNativeDataProperty_from_template.phpt new file mode 100644 index 0000000..ba7008c --- /dev/null +++ b/tests/V8ObjectValue_SetNativeDataProperty_from_template.phpt @@ -0,0 +1,109 @@ +--TEST-- +V8\ObjectValue::SetNativeDataProperty - when object created from template +--SKIPIF-- + +--FILE-- +ToString($info->GetContext())->Value(), ' called, value is ', $prop_value, PHP_EOL; + + $info->GetReturnValue()->Set(new \V8\StringValue($info->GetIsolate(), $prop_value)); +}; + +$setter_obj = function (\V8\NameValue $property, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (& $prop_value) { + $val = $value->ToString($info->GetContext())->Value(); + echo 'Userland native setter on property (obj) ', $property->ToString($info->GetContext())->Value(), ' called with ', $val, ', value is ', $prop_value, PHP_EOL; + + $prop_value = $val; +}; + +$getter_tpl = function (\V8\NameValue $property, \V8\PropertyCallbackInfo $info) use (&$prop_value) { + echo 'Userland native getter on property (tpl) ', $property->ToString($info->GetContext())->Value(), ' called, value is ', $prop_value, PHP_EOL; + + $info->GetReturnValue()->Set(new \V8\StringValue($info->GetIsolate(), $prop_value)); +}; + +$setter_tpl = function (\V8\NameValue $property, \V8\Value $value, \V8\PropertyCallbackInfo $info) use (& $prop_value) { + $val = $value->ToString($info->GetContext())->Value(); + echo 'Userland native setter on property (tpl) ', $property->ToString($info->GetContext())->Value(), ' called with ', $val, ', value is ', $prop_value, PHP_EOL; + + $prop_value = $val; +}; +$context = new V8\Context($isolate); + +$tpl = new V8\ObjectTemplate($isolate); +$tpl->SetNativeDataProperty(new \V8\StringValue($isolate, 'test'), $getter_tpl, $setter_tpl); + +$obj = new V8\ObjectValue($context); +$obj->SetNativeDataProperty($context, new \V8\StringValue($isolate, 'test'), $getter_obj, $setter_obj); + +$obj1 = $tpl->NewInstance($context); +$obj1->SetNativeDataProperty($context, new \V8\StringValue($isolate, 'test'), $getter_obj, $setter_obj); + +$obj2 = $tpl->NewInstance($context); + + +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj'), $obj); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj1'), $obj1); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'obj2'), $obj2); + +$v8_helper->injectConsoleLog($context); + +$source = ' +console.log(obj.test, "\n"); +obj.test = "bar"; +console.log(obj.test, "\n"); + +console.log(obj1.test, "\n"); +obj1.test = "foo"; +console.log(obj1.test, "\n"); + +console.log(obj2.test, "\n"); +obj2.test = "bar"; +console.log(obj2.test, "\n"); + +"Script done"; +'; +$file_name = 'test.js'; + + +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); + +$v8_helper->CompileRun($context, $source); + +?> +--EXPECT-- +Userland native getter on property (obj) test called, value is foo +foo + +Userland native setter on property (obj) test called with bar, value is foo +Userland native getter on property (obj) test called, value is bar +bar + +Userland native getter on property (obj) test called, value is bar +bar + +Userland native setter on property (obj) test called with foo, value is bar +Userland native getter on property (obj) test called, value is foo +foo + +Userland native getter on property (tpl) test called, value is foo +foo + +Userland native setter on property (tpl) test called with bar, value is foo +Userland native getter on property (tpl) test called, value is bar +bar diff --git a/tests/V8PrimitiveValue.phpt b/tests/V8PrimitiveValue.phpt index 1eacf56..42223f7 100644 --- a/tests/V8PrimitiveValue.phpt +++ b/tests/V8PrimitiveValue.phpt @@ -149,7 +149,7 @@ V8\PrimitiveValue(V8\Value)->NumberValue(): float(NAN) V8\PrimitiveValue::ToString() converting: ----------------------------------------- -object(V8\StringValue)#77 (1) { +object(V8\StringValue)#78 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8PropertyAttribute.phpt b/tests/V8PropertyAttribute.phpt deleted file mode 100644 index 48486dd..0000000 --- a/tests/V8PropertyAttribute.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -V8\PropertyAttribute ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\PropertyAttribute)#1 (0) { -} - - -Class constants: ----------------- -V8\PropertyAttribute::None = 0 -V8\PropertyAttribute::ReadOnly = 1 -V8\PropertyAttribute::DontEnum = 2 -V8\PropertyAttribute::DontDelete = 4 diff --git a/tests/V8PropertyCallbackInfo.phpt b/tests/V8PropertyCallbackInfo.phpt index 44c3ddb..a608d2c 100644 --- a/tests/V8PropertyCallbackInfo.phpt +++ b/tests/V8PropertyCallbackInfo.phpt @@ -46,10 +46,10 @@ $obj->SetAccessor($context, new StringValue($isolate, 'test'), $getter); $context->GlobalObject()->Set($context, new StringValue($isolate, 'obj'), $obj); -$script1 = new Script($context, new StringValue($isolate, 'obj.test')); +$script = new Script($context, new StringValue($isolate, 'obj.test')); -$helper->dump($script1->Run($context)->ToString($context)->Value()); +$helper->dump($script->Run($context)->ToString($context)->Value()); ?> --EXPECT-- diff --git a/tests/V8PropertyHandlerFlags.phpt b/tests/V8PropertyHandlerFlags.phpt deleted file mode 100644 index 620d05c..0000000 --- a/tests/V8PropertyHandlerFlags.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -V8\PropertyHandlerFlags ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\PropertyHandlerFlags)#1 (0) { -} - - -Class constants: ----------------- -V8\PropertyHandlerFlags::kNone = 0 -V8\PropertyHandlerFlags::kAllCanRead = 1 -V8\PropertyHandlerFlags::kNonMasking = 2 -V8\PropertyHandlerFlags::kOnlyInterceptStrings = 4 diff --git a/tests/V8RegExpFlags.phpt b/tests/V8RegExpFlags.phpt deleted file mode 100644 index fd95fd0..0000000 --- a/tests/V8RegExpFlags.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -V8\RegExpObject\Flags ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\RegExpObject\Flags)#1 (0) { -} - - -Class constants: ----------------- -V8\RegExpObject\Flags::kNone = 0 -V8\RegExpObject\Flags::kGlobal = 1 -V8\RegExpObject\Flags::kIgnoreCase = 2 -V8\RegExpObject\Flags::kMultiline = 4 -V8\RegExpObject\Flags::kSticky = 8 -V8\RegExpObject\Flags::kUnicode = 16 diff --git a/tests/V8RegExpObject.phpt b/tests/V8RegExpObject.phpt index 47505c3..9c46b70 100644 --- a/tests/V8RegExpObject.phpt +++ b/tests/V8RegExpObject.phpt @@ -13,17 +13,11 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); -// TODO: fix it, this cause segfault due to FunctionTemplate object destruction and all it internal structures cleanup -//$global_template1->Set('print', $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$print_func_tpl = $v8_helper->getPrintFunctionTemplate($isolate1); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $print_func_tpl, \V8\PropertyAttribute::DontDelete); - -$context1 = new V8\Context($isolate1, $global_template1); - -$value = new V8\RegExpObject($context1, new \V8\StringValue($isolate1, '([a-z]{1,4})-([0-9]+)'), \V8\RegExpObject\Flags::kIgnoreCase); +$value = new V8\RegExpObject($context, new \V8\StringValue($isolate, '([a-z]{1,4})-([0-9]+)'), \V8\RegExpObject\Flags::kIgnoreCase); $helper->header('Object representation'); $helper->dump($value); @@ -39,24 +33,24 @@ $helper->space(); $v8_helper->run_checks($value, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); -print("\"test-1\".replace(val, \"$2-$1\"): ", "test-1".replace(val, "$2-$1"), "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); +console.log("\"test-1\".replace(val, \"$2-$1\"): ", "test-1".replace(val, "$2-$1")); val '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); +$res = $script->Run($context); $helper->space(); $helper->header('Returned value should be the same'); -$helper->value_matches_with_no_output($res1, $value); +$helper->value_matches_with_no_output($res, $value); $helper->space(); @@ -64,7 +58,7 @@ $helper->space(); --EXPECT-- Object representation: ---------------------- -object(V8\RegExpObject)#8 (2) { +object(V8\RegExpObject)#6 (2) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -79,7 +73,7 @@ object(V8\RegExpObject)#8 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#7 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8ReturnValue.phpt b/tests/V8ReturnValue.phpt index c3aaee4..aaaf12c 100644 --- a/tests/V8ReturnValue.phpt +++ b/tests/V8ReturnValue.phpt @@ -15,31 +15,31 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); +$isolate = new v8Tests\TrackingDtors\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$global_template = new V8\ObjectTemplate($isolate); -//$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); +//$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); -$context1 = new V8\Context($isolate1, $global_template1); +$context = new V8\Context($isolate, $global_template); -$scalar = new \V8\StringValue($isolate1, "test"); -$object = new \V8\ObjectValue($context1); +$scalar = new \V8\StringValue($isolate, "test"); +$object = new \V8\ObjectValue($context); $method = null; $checker = null; $args = []; -$func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\FunctionCallbackInfo $info) use ($helper, $scalar, $object, $isolate1, $context1, &$method, &$checker, &$args) { +$func = new v8Tests\TrackingDtors\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use ($helper, $scalar, $object, $isolate, $context, &$method, &$checker, &$args) { $retval = $info->GetReturnValue(); if (!$method) { echo 'Function called', PHP_EOL; - $helper->assert('Return value holds original isolate object', $retval->GetIsolate(), $isolate1); - $helper->assert('Return value holds original context object', $retval->GetContext(), $context1); + $helper->assert('Return value holds original isolate object', $retval->GetIsolate(), $isolate); + $helper->assert('Return value holds original context object', $retval->GetContext(), $context); } $helper->assert('Return value holds no value', $retval->Get()->IsUndefined()); @@ -51,46 +51,46 @@ $func = new v8Tests\TrackingDtors\FunctionObject($context1, function (\V8\Functi } }); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'test'), $func); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $func); -$source1 = 'test(); "Script done";'; -$file_name1 = 'test.js'; +$source = 'test(); "Script done";'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$helper->dump($script1->Run($context1)->ToString($context1)->Value()); +$helper->dump($script->Run($context)->ToString($context)->Value()); $helper->space(); $method = 'SetUndefined'; $checker = 'IsUndefined'; $args = []; -$res = $v8_helper->CompileRun($context1, "test()"); +$res = $v8_helper->CompileRun($context, "test()"); $helper->assert('Returns undefined', $res->IsUndefined()); $method = 'SetNull'; $checker = 'IsNull'; $args = []; -$res = $v8_helper->CompileRun($context1, "test()"); +$res = $v8_helper->CompileRun($context, "test()"); $helper->assert('Returns null', $res->IsNull()); $method = 'SetBool'; $checker = 'IsBoolean'; $args = [true]; -$res = $v8_helper->CompileRun($context1, "test()"); +$res = $v8_helper->CompileRun($context, "test()"); $helper->assert('Returns boolean', $res->IsBoolean() && $res->IsTrue()); $method = 'SetInteger'; $checker = 'IsInt32'; $args = [42]; -$res = $v8_helper->CompileRun($context1, "test()"); +$res = $v8_helper->CompileRun($context, "test()"); $helper->assert('Returns integer', $res->IsNumber() && $res->IsInt32()); $method = 'SetFloat'; $checker = 'IsNumber'; $args = [PHP_INT_MAX + 0.22]; -$res = $v8_helper->CompileRun($context1, "test()"); +$res = $v8_helper->CompileRun($context, "test()"); $helper->assert('Returns float', $res->IsNumber() && !$res->IsInt32() && !$res->IsUint32()); $helper->pretty_dump('Returns float', $res->Value()); diff --git a/tests/V8ReturnValue_context.phpt b/tests/V8ReturnValue_context.phpt index f63f44f..653fa69 100644 --- a/tests/V8ReturnValue_context.phpt +++ b/tests/V8ReturnValue_context.phpt @@ -44,13 +44,13 @@ $func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test'), $func); -$source1 = 'test(); "Script done";'; -$file_name1 = 'test.js'; +$source = 'test(); "Script done";'; +$file_name = 'test.js'; -$script1 = new V8\Script($context, new \V8\StringValue($isolate, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$script1->Run($context); +$script->Run($context); $helper->space(); $helper->assert('Return value object is out of context', false === $retval->InContext()); diff --git a/tests/V8ScriptCompiler_CompileFunctionInContext.phpt b/tests/V8ScriptCompiler_CompileFunctionInContext.phpt index d059c6f..818296a 100644 --- a/tests/V8ScriptCompiler_CompileFunctionInContext.phpt +++ b/tests/V8ScriptCompiler_CompileFunctionInContext.phpt @@ -94,10 +94,7 @@ $function = V8\ScriptCompiler::CompileFunctionInContext($context, $source); $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test_simple'), $function); -$script = new \V8\Script($context, new \V8\StringValue($isolate, 'test_simple()')); - -$helper->dump($script->Run($context)->Value()); - +$helper->dump($v8_helper->CompileRun($context, 'test_simple("passed")')->Value()); $source_string = new V8\StringValue($isolate, 'return "test " + status;'); @@ -106,9 +103,7 @@ $function = V8\ScriptCompiler::CompileFunctionInContext($context, $source, [new $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test_with_parameter'), $function); -$script = new \V8\Script($context, new \V8\StringValue($isolate, 'test_with_parameter("passed")')); - -$helper->dump($script->Run($context)->Value()); +$helper->dump($v8_helper->CompileRun($context, 'test_with_parameter("passed")')->Value()); $ctx_a = new \V8\ObjectValue($context); @@ -125,10 +120,7 @@ $source = new \V8\ScriptCompiler\Source($source_string); $function = V8\ScriptCompiler::CompileFunctionInContext($context, $source, [new \V8\StringValue($isolate, 'status')], [$ctx_a, $ctx_b]); $context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'test_with_parameter_and_contexts'), $function); - -$script = new \V8\Script($context, new \V8\StringValue($isolate, 'test_with_parameter_and_contexts("passed")')); - -$helper->dump($script->Run($context)->Value()); +$helper->dump($v8_helper->CompileRun($context, 'test_with_parameter_and_contexts("passed")')->Value()); ?> --EXPECT-- diff --git a/tests/V8Script_Run_out_of_memory.phpt b/tests/V8Script_Run_out_of_memory.phpt index 19b4d45..be3c514 100644 --- a/tests/V8Script_Run_out_of_memory.phpt +++ b/tests/V8Script_Run_out_of_memory.phpt @@ -18,8 +18,8 @@ $global_template = new V8\ObjectTemplate($isolate); $value = new V8\StringValue($isolate, 'TEST VALUE 111'); $global_template->Set(new \V8\StringValue($isolate, 'test'), $value); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); // This causes segfault $source = ' @@ -28,17 +28,17 @@ var multiply = 25; while (multiply-- > 0){ x = x+x; - print(x.length, "\n"); + console.log(x.length); } var arr = []; -print("\n\n"); +console.log("\n"); while (1) { arr.push(x); //if (!(arr.length % 10000)) { - // print(arr.length, "\n"); + // console.log(arr.length); //} } '; diff --git a/tests/V8Script_exit_during_script_execution.phpt b/tests/V8Script_exit_during_script_execution.phpt index 0373574..f01a7c8 100644 --- a/tests/V8Script_exit_during_script_execution.phpt +++ b/tests/V8Script_exit_during_script_execution.phpt @@ -13,40 +13,39 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); +$isolate = new v8Tests\TrackingDtors\Isolate(); register_shutdown_function(function () { echo 'Doing shutdown', PHP_EOL; }); -$global_template1 = new v8Tests\TrackingDtors\ObjectTemplate($isolate1); +$global_template = new v8Tests\TrackingDtors\ObjectTemplate($isolate); -$exit = new v8Tests\TrackingDtors\FunctionTemplate($isolate1, function () { +$exit = new v8Tests\TrackingDtors\FunctionTemplate($isolate, function () { echo 'Going to exit', PHP_EOL; exit(); }); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$global_template1->Set(new \V8\StringValue($isolate1, 'exit'), $exit, \V8\PropertyAttribute::DontDelete); +$global_template->Set(new \V8\StringValue($isolate, 'exit'), $exit, \V8\PropertyAttribute::DontDelete); -$context1 = new v8Tests\TrackingDtors\Context($isolate1, $global_template1); +$context = new v8Tests\TrackingDtors\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); - -$source1 = ' -print("before exit\n"); +$source = ' +console.log("before exit"); exit(); -print("after exit\n"); +console.log("after exit"); '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script = new v8Tests\TrackingDtors\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); +$script = new v8Tests\TrackingDtors\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$isolate1 = null; -$global_template1 = null; +$isolate = null; +$global_template = null; $exit = null; -$script->Run($context1); +$script->Run($context); -$context1 = null; +$context = null; echo 'Done here', PHP_EOL; ?> diff --git a/tests/V8Script_terminate_script_execution.phpt b/tests/V8Script_terminate_script_execution.phpt index d777207..db1bde4 100644 --- a/tests/V8Script_terminate_script_execution.phpt +++ b/tests/V8Script_terminate_script_execution.phpt @@ -13,14 +13,14 @@ $v8_helper = new PhpV8Helpers($helper); require '.tracking_dtors.php'; -$isolate1 = new v8Tests\TrackingDtors\Isolate(); +$isolate = new v8Tests\TrackingDtors\Isolate(); -//$isolate1->SetCaptureStackTraceForUncaughtExceptions(true); +//$isolate->SetCaptureStackTraceForUncaughtExceptions(true); -$global_template1 = new V8\ObjectTemplate($isolate1); +$global_template = new V8\ObjectTemplate($isolate); $timer = 0; -$terminate = new V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackInfo $info) use (&$timer) { +$terminate = new V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) use (&$timer) { echo 'Going to terminate', PHP_EOL; $isolate = $info->GetIsolate(); @@ -38,26 +38,26 @@ $terminate = new V8\FunctionTemplate($isolate1, function (\V8\FunctionCallbackIn $e = null; }); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$global_template1->Set(new \V8\StringValue($isolate1, 'terminate'), $terminate, \V8\PropertyAttribute::DontDelete); +$global_template->Set(new \V8\StringValue($isolate, 'terminate'), $terminate, \V8\PropertyAttribute::DontDelete); -$context1 = new V8\Context($isolate1, $global_template1); -$global_template1 = null; +$context = new V8\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$source1 = ' +$global_template = null; + +$source = ' cnt = 0; -print("before terminate\n"); +console.log("before terminate"); terminate(); while (true) { - print("after terminate ", cnt, "\n"); + console.log("after terminate ", cnt); cnt++; } '; -$file_name1 = 'test.js'; +$file_name = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); try { -$res1 = $script1->Run($context1); + $res = $v8_helper->CompileRun($context, $source); } catch (\V8\Exceptions\TerminationException $e) { $helper->exception_export($e); } finally { @@ -70,10 +70,9 @@ $res1 = $script1->Run($context1); $e = null; $terminate = null; -$res1 = null; -$script1 = null; -$context1 = null; -$isolate1 = null; +$res = null; +$context = null; +$isolate = null; echo 'Done here', PHP_EOL; ?> diff --git a/tests/V8SetObject.phpt b/tests/V8SetObject.phpt index 0e4677e..2229b88 100644 --- a/tests/V8SetObject.phpt +++ b/tests/V8SetObject.phpt @@ -23,9 +23,10 @@ $helper->header('Object representation'); $helper->dump($value); $helper->space(); -$helper->assert('ObjectValue extends Value', $value instanceof \V8\Value); -$helper->assert('ObjectValue does not extend PrimitiveValue', !($value instanceof \V8\PrimitiveValue)); -$helper->assert('ObjectValue implements AdjustableExternalMemoryInterface', $value instanceof \V8\AdjustableExternalMemoryInterface); +$helper->assert('SetObject extends Value', $value instanceof \V8\Value); +$helper->assert('SetObject does not extend PrimitiveValue', !($value instanceof \V8\PrimitiveValue)); +$helper->assert('SetObject implements AdjustableExternalMemoryInterface', $value instanceof \V8\AdjustableExternalMemoryInterface); +$helper->assert('SetObject is instanceof Set', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Set')))); $helper->line(); $helper->header('Accessors'); @@ -139,9 +140,10 @@ object(V8\SetObject)#6 (2) { } -ObjectValue extends Value: ok -ObjectValue does not extend PrimitiveValue: ok -ObjectValue implements AdjustableExternalMemoryInterface: ok +SetObject extends Value: ok +SetObject does not extend PrimitiveValue: ok +SetObject implements AdjustableExternalMemoryInterface: ok +SetObject is instanceof Set: ok Accessors: ---------- @@ -213,7 +215,7 @@ V8\SetObject(V8\Value)->IsProxy(): bool(false) Converters: ----------- V8\SetObject(V8\Value)->ToBoolean(): - object(V8\BooleanValue)#119 (1) { + object(V8\BooleanValue)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -229,7 +231,7 @@ V8\SetObject(V8\Value)->ToBoolean(): } } V8\SetObject(V8\Value)->ToNumber(): - object(V8\NumberValue)#119 (1) { + object(V8\NumberValue)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -245,7 +247,7 @@ V8\SetObject(V8\Value)->ToNumber(): } } V8\SetObject(V8\Value)->ToString(): - object(V8\StringValue)#119 (1) { + object(V8\StringValue)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -261,7 +263,7 @@ V8\SetObject(V8\Value)->ToString(): } } V8\SetObject(V8\Value)->ToDetailString(): - object(V8\StringValue)#119 (1) { + object(V8\StringValue)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -309,7 +311,7 @@ V8\SetObject(V8\Value)->ToObject(): } } V8\SetObject(V8\Value)->ToInteger(): - object(V8\Int32Value)#119 (1) { + object(V8\Int32Value)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -325,7 +327,7 @@ V8\SetObject(V8\Value)->ToInteger(): } } V8\SetObject(V8\Value)->ToUint32(): - object(V8\Int32Value)#119 (1) { + object(V8\Int32Value)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -341,7 +343,7 @@ V8\SetObject(V8\Value)->ToUint32(): } } V8\SetObject(V8\Value)->ToInt32(): - object(V8\Int32Value)#119 (1) { + object(V8\Int32Value)#121 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8StackTrace.phpt b/tests/V8StackTrace.phpt index 0fc2084..f9c1575 100644 --- a/tests/V8StackTrace.phpt +++ b/tests/V8StackTrace.phpt @@ -16,13 +16,11 @@ $v8_helper = new PhpV8Helpers($helper); $isolate = new \v8Tests\TrackingDtors\Isolate(); $context = new \v8Tests\TrackingDtors\Context($isolate); -$array = new \V8\ArrayObject($context); - $frame_1 = new \V8\StackFrame(1); $frame_2 = new \V8\StackFrame(2); $frames = [$frame_1, $frame_2]; -$obj = new \V8\StackTrace($frames, $array); +$obj = new \V8\StackTrace($frames); $helper->header('Object representation'); @@ -38,7 +36,6 @@ $helper->header('Test getters'); $helper->method_matches($obj, 'GetFrames', $frames); $helper->method_matches($obj, 'GetFrame', $frame_1, [0]); $helper->method_matches_with_output($obj, 'GetFrameCount', 2); -$helper->method_matches_instanceof($obj, 'AsArray', V8\ArrayObject::class); $helper->space(); $obj = null; @@ -51,11 +48,11 @@ echo "END", PHP_EOL --EXPECT-- Object representation: ---------------------- -object(V8\StackTrace)#8 (2) { +object(V8\StackTrace)#7 (1) { ["frames":"V8\StackTrace":private]=> array(2) { [0]=> - object(V8\StackFrame)#6 (8) { + object(V8\StackFrame)#5 (8) { ["line_number":"V8\StackFrame":private]=> int(1) ["column":"V8\StackFrame":private]=> @@ -74,7 +71,7 @@ object(V8\StackTrace)#8 (2) { bool(false) } [1]=> - object(V8\StackFrame)#7 (8) { + object(V8\StackFrame)#6 (8) { ["line_number":"V8\StackFrame":private]=> int(2) ["column":"V8\StackFrame":private]=> @@ -93,38 +90,6 @@ object(V8\StackTrace)#8 (2) { bool(false) } } - ["as_array":"V8\StackTrace":private]=> - object(V8\ArrayObject)#5 (2) { - ["isolate":"V8\Value":private]=> - object(v8Tests\TrackingDtors\Isolate)#3 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - ["context":"V8\ObjectValue":private]=> - object(v8Tests\TrackingDtors\Context)#4 (1) { - ["isolate":"V8\Context":private]=> - object(v8Tests\TrackingDtors\Isolate)#3 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - } - } } @@ -139,7 +104,6 @@ Test getters: V8\StackTrace::GetFrames() matches expected value V8\StackTrace::GetFrame() matches expected value V8\StackTrace::GetFrameCount() matches expected 2 -V8\StackTrace::AsArray() result is instance of V8\ArrayObject Context dies now! diff --git a/tests/V8StackTraceOptions.phpt b/tests/V8StackTraceOptions.phpt deleted file mode 100644 index b4838cf..0000000 --- a/tests/V8StackTraceOptions.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -V8\StackTrace\StackTraceOptions ---SKIPIF-- - ---FILE-- -header('Object representation'); -$helper->dump($obj); -$helper->space(); - - -$helper->header('Class constants'); -$helper->dump_object_constants($obj); -$helper->space(); - -?> ---EXPECT-- -Object representation: ----------------------- -object(V8\StackTrace\StackTraceOptions)#1 (0) { -} - - -Class constants: ----------------- -V8\StackTrace\StackTraceOptions::kLineNumber = 1 -V8\StackTrace\StackTraceOptions::kColumnOffset = 3 -V8\StackTrace\StackTraceOptions::kScriptName = 4 -V8\StackTrace\StackTraceOptions::kFunctionName = 8 -V8\StackTrace\StackTraceOptions::kIsEval = 16 -V8\StackTrace\StackTraceOptions::kIsConstructor = 32 -V8\StackTrace\StackTraceOptions::kScriptNameOrSourceURL = 64 -V8\StackTrace\StackTraceOptions::kScriptId = 128 -V8\StackTrace\StackTraceOptions::kExposeFramesAcrossSecurityOrigins = 256 -V8\StackTrace\StackTraceOptions::kOverview = 15 -V8\StackTrace\StackTraceOptions::kDetailed = 127 diff --git a/tests/V8StackTrace_CurrentStackTrace.phpt b/tests/V8StackTrace_CurrentStackTrace.phpt index e056197..fc4f0f4 100644 --- a/tests/V8StackTrace_CurrentStackTrace.phpt +++ b/tests/V8StackTrace_CurrentStackTrace.phpt @@ -18,7 +18,7 @@ $global_template = new v8Tests\TrackingDtors\ObjectTemplate($isolate); $stack_trace = null; -$current_stack_trace_func_tpl = new \v8Tests\TrackingDtors\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $args) use (&$stack_trace) { +$current_stack_trace_func_tpl = new \v8Tests\TrackingDtors\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $args) use ($v8_helper, &$stack_trace) { $isolate = $args->GetIsolate(); $context = $args->GetContext(); @@ -28,40 +28,35 @@ $current_stack_trace_func_tpl = new \v8Tests\TrackingDtors\FunctionTemplate($iso $frame_limit = 10; } - if (count($args->Arguments()) > 1) { - $options = $args->Arguments()[1]->NumberValue($context); - } else { - $options = \V8\StackTrace\StackTraceOptions::kOverview; - } - - $stack_trace = \V8\StackTrace::CurrentStackTrace($isolate, $frame_limit, $options); + $stack_trace = \V8\StackTrace::CurrentStackTrace($isolate, $frame_limit); echo 'totally ', $stack_trace->GetFrameCount(), ' frames:', PHP_EOL; - $args->GetReturnValue()->Set($stack_trace->AsArray()); + $arr = $v8_helper->getStackTraceFramesAsArray($context, $stack_trace->GetFrames()); + + $args->GetReturnValue()->Set($arr); }); $global_template->Set(new \V8\StringValue($isolate, 'current_stack_trace'), $current_stack_trace_func_tpl); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate)); $context = new v8Tests\TrackingDtors\Context($isolate, $global_template); +$v8_helper->injectConsoleLog($context); -$source = /** @lang JavaScript */ +$source = ' "use strict"; function print_trace(trace) { - print("[\\n"); + console.log("["); for (var frame in trace) { - print(" ", JSON.stringify(trace[frame])); - print("\\n"); + console.log(" ", JSON.stringify(trace[frame])); } - print("]\\n"); + console.log("]"); } function get_trace(frame_limit, options) { var trace = current_stack_trace(frame_limit, options); print_trace(trace); - print("\\n"); + console.log(); } function TestWithConstructor (frame_limit, options) { @@ -76,27 +71,14 @@ function recursive_get_trace(depth, frame_limit, options) { return get_trace(frame_limit, options); } - -var kLineNumber = 1; -var kColumnOffset = 3; -var kScriptName = 4; -var kFunctionName = 8; -var kIsEval = 16; -var kIsConstructor = 32; -var kScriptNameOrSourceURL = 64; -var kScriptId = 128; -var kExposeFramesAcrossSecurityOrigins = 256; -var kOverview = 15; -var kDetailed = 127; - -get_trace(0, kDetailed); // zero trace is fine, though, makes no sense -get_trace(1, kDetailed); -get_trace(2, kColumnOffset | kScriptId); +get_trace(0); // zero trace is fine, though, makes no sense +get_trace(1); +get_trace(2); new TestWithConstructor(1, -1); -recursive_get_trace(100, 10, kOverview); +recursive_get_trace(100, 10); get_trace(2, -1); // as option are bit flags, -1 will lead to all options set @@ -108,10 +90,10 @@ function stackTrace() { return err.stack; } -print("JS-land stack trace:\\n"); -print(stackTrace()); -print("\\n"); -print("\\n"); +console.log("JS-land stack trace:"); +console.log(stackTrace()); +console.log(); +console.log(); '; $file_name = 'test.js'; @@ -131,6 +113,9 @@ $isolate = null; echo 'END', PHP_EOL; + +// EXPECTF: ---/"scriptId"\:\d+/ +// EXPECTF: +++"scriptId":%d ?> --EXPECTF-- totally 0 frames: @@ -139,44 +124,45 @@ totally 0 frames: totally 1 frames: [ - {"line":15,"column":18,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} + {"line":13,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} ] totally 2 frames: [ - {"line":15,"column":18,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} - {"line":47,"column":2,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"","isEval":false,"isConstructor":false} + {"line":13,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} + {"line":32,"column":1,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"","isEval":false,"isConstructor":false} ] totally 1 frames: [ - {"line":15,"column":18,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} + {"line":13,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} ] totally 10 frames: [ - {"line":15,"column":18,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} - {"line":29,"column":13,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} - {"line":26,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":13,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} + {"line":27,"column":12,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} + {"line":24,"column":16,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"recursive_get_trace","isEval":false,"isConstructor":false} ] totally 2 frames: [ - {"line":15,"column":18,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} - {"line":54,"column":2,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"","isEval":false,"isConstructor":false} + {"line":13,"column":17,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"get_trace","isEval":false,"isConstructor":false} + {"line":39,"column":1,"scriptId":%d,"scriptName":"test.js","scriptNameOrSourceURL":"test.js","functionName":"","isEval":false,"isConstructor":false} ] JS-land stack trace: Error - at stackTrace (test.js:58:15) - at test.js:64:7 + at stackTrace (test.js:44:15) + at test.js:50:13 + Script dies now! ObjectTemplate dies now! diff --git a/tests/V8StringObject.phpt b/tests/V8StringObject.phpt index 3cd3017..63ac106 100644 --- a/tests/V8StringObject.phpt +++ b/tests/V8StringObject.phpt @@ -14,20 +14,18 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: -$isolate1 = new \V8\Isolate(); -$global_template1 = new V8\ObjectTemplate($isolate1); +$isolate = new \V8\Isolate(); +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); - -$context1 = new V8\Context($isolate1, $global_template1); - -$value = new V8\StringObject($context1, new \V8\StringValue($isolate1, 'test string')); +$value = new V8\StringObject($context, new \V8\StringValue($isolate, 'test string')); $helper->header('Object representation'); $helper->dump($value); $helper->space(); $helper->assert('StringObject extends ObjectValue', $value instanceof \V8\ObjectValue); +$helper->assert('StringObject is instanceof String', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'String')))); $helper->line(); $helper->header('Getters'); @@ -37,31 +35,25 @@ $helper->space(); $v8_helper->run_checks($value, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); val '; -$file_name1 = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$res = $v8_helper->CompileRun($context, $source); $helper->space(); $helper->header('Returned value should be the same'); -$helper->value_matches_with_no_output($res1, $value); +$helper->value_matches_with_no_output($res, $value); $helper->space(); -$source1 = 'new String("boxed test string from script");'; -$file_name1 = 'test.js'; - -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); - -$v8_helper->run_checks($res1, 'Checkers on boxed from script') +$res = $v8_helper->CompileRun($context, 'new String("boxed test string from script");'); + +$v8_helper->run_checks($res, 'Checkers on boxed from script') ?> --EXPECT-- @@ -82,7 +74,7 @@ object(V8\StringObject)#6 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#5 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -101,11 +93,12 @@ object(V8\StringObject)#6 (2) { StringObject extends ObjectValue: ok +StringObject is instanceof String: ok Getters: -------- V8\StringObject->ValueOf(): - object(V8\StringValue)#118 (1) { + object(V8\StringValue)#119 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8String_range_error_length.phpt b/tests/V8String_range_error_length.phpt index 034a3db..bc2eaf6 100644 --- a/tests/V8String_range_error_length.phpt +++ b/tests/V8String_range_error_length.phpt @@ -14,27 +14,21 @@ $v8_helper = new PhpV8Helpers($helper); // Tests: $isolate = new V8\Isolate(); -$global_template = new V8\ObjectTemplate($isolate); -$global_template->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFunctionTemplate($isolate), \V8\PropertyAttribute::DontDelete); - -$context = new V8\Context($isolate, $global_template); - +$context = new V8\Context($isolate); +$v8_helper->injectConsoleLog($context); $source = ' var str = " ".repeat(1024); // 1kb var blob = ""; while(true) { blob += str; - //print(blob.length, "\n"); + //console.log(blob.length, "\n"); } '; -$file_name = 'test.js'; - -$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); $t = microtime(true); try { - $res = $script->Run($context); + $res = $v8_helper->CompileRun($context, $source); } catch(\V8\Exceptions\TryCatchException $e) { $helper->exception_export($e); } diff --git a/tests/V8SymbolObject.phpt b/tests/V8SymbolObject.phpt index 95dbbc6..7b36d96 100644 --- a/tests/V8SymbolObject.phpt +++ b/tests/V8SymbolObject.phpt @@ -1,7 +1,9 @@ --TEST-- V8\SymbolObject --SKIPIF-- - + --FILE-- injectConsoleLog($context); -$global_template1->Set(new \V8\StringValue($isolate1, 'print'), $v8_helper->getPrintFunctionTemplate($isolate1), \V8\PropertyAttribute::DontDelete); -$context1 = new V8\Context($isolate1, $global_template1); - -$value = new V8\SymbolObject($context1, new \V8\SymbolValue($isolate1, new \V8\StringValue($isolate1, 'test'))); +$value = new V8\SymbolObject($context, new \V8\SymbolValue($isolate, new \V8\StringValue($isolate, 'test'))); $helper->header('Object representation'); $helper->dump($value); $helper->space(); $helper->assert('SymbolObject extends ObjectValue', $value instanceof \V8\ObjectValue); +$helper->assert('SymbolObject is instanceof Symbol', $value->InstanceOf($context, $context->GlobalObject()->Get($context, new \V8\StringValue($isolate, 'Symbol')))); $helper->line(); $helper->header('Getters'); @@ -37,33 +38,28 @@ $helper->space(); $v8_helper->run_checks($value, 'Checkers'); -$context1->GlobalObject()->Set($context1, new \V8\StringValue($isolate1, 'val'), $value); +$context->GlobalObject()->Set($context, new \V8\StringValue($isolate, 'val'), $value); -$source1 = ' -print("val: ", val, "\n"); -print("typeof val: ", typeof val, "\n"); +$source = ' +console.log("val: ", val); +console.log("typeof val: ", typeof val); val '; -$file_name1 = 'test.js'; -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); -$res1 = $script1->Run($context1); +$res = $v8_helper->CompileRun($context, $source); + $helper->space(); $helper->header('Returned value should be the same'); -$helper->value_matches_with_no_output($res1, $value); +$helper->value_matches_with_no_output($res, $value); $helper->space(); -// This now not allowed, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol -$source1 = 'new Symbol("boxed")'; -$file_name1 = 'test.js'; - -$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1)); try { - $res1 = $script1->Run($context1); -} catch(Exception $e) { - $helper->exception_export($e); + // This now not allowed, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol + $res = $v8_helper->CompileRun($context, 'new Symbol("boxed")'); +} catch (Exception $e) { + $helper->exception_export($e); } ?> @@ -85,7 +81,7 @@ object(V8\SymbolObject)#6 (2) { bool(false) } ["context":"V8\ObjectValue":private]=> - object(V8\Context)#5 (1) { + object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -104,11 +100,12 @@ object(V8\SymbolObject)#6 (2) { SymbolObject extends ObjectValue: ok +SymbolObject is instanceof Symbol: ok Getters: -------- V8\SymbolObject->ValueOf(): - object(V8\SymbolValue)#118 (1) { + object(V8\SymbolValue)#119 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8SymbolValue.phpt b/tests/V8SymbolValue.phpt index e7931b8..5ee65a2 100644 --- a/tests/V8SymbolValue.phpt +++ b/tests/V8SymbolValue.phpt @@ -109,8 +109,7 @@ $source = 'Symbol("foo")'; $file_name = 'test.js'; $context = new V8\Context($isolate); -$script = new V8\Script($context, new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin($file_name)); -$res = $script->Run($context); +$res = $v8_helper->CompileRun($context, $source); $v8_helper->run_checks($res, 'Checkers on Symbol value from script'); @@ -145,35 +144,26 @@ $helper->assert('Symbol ForApi(string) returned', $value instanceof \V8\SymbolVa $helper->pretty_dump('Symbol ForApi(string) name', $value->Name()->Value()); $helper->line(); -$helper->assert('Isolate not in context', !$isolate->InContext()); -$value = V8\SymbolValue::GetIterator($isolate); -$helper->assert('Symbol GetIterator() returned', $value instanceof \V8\SymbolValue); -$helper->pretty_dump('Symbol GetIterator() name', $value->Name()->Value()); -$helper->line(); - -$helper->assert('Isolate not in context', !$isolate->InContext()); -$value = V8\SymbolValue::GetUnscopables($isolate); -$helper->assert('Symbol GetUnscopables() returned', $value instanceof \V8\SymbolValue); -$helper->pretty_dump('Symbol GetUnscopables() name', $value->Name()->Value()); -$helper->line(); - -$helper->assert('Isolate not in context', !$isolate->InContext()); -$value = V8\SymbolValue::GetToPrimitive($isolate); -$helper->assert('Symbol GetToPrimitive() returned', $value instanceof \V8\SymbolValue); -$helper->pretty_dump('Symbol GetToPrimitive() name', $value->Name()->Value()); -$helper->line(); - -$helper->assert('Isolate not in context', !$isolate->InContext()); -$value = V8\SymbolValue::GetToStringTag($isolate); -$helper->assert('Symbol GetToStringTag() returned', $value instanceof \V8\SymbolValue); -$helper->pretty_dump('Symbol GetToStringTag() name', $value->Name()->Value()); -$helper->line(); - -$helper->assert('Isolate not in context', !$isolate->InContext()); -$value = V8\SymbolValue::GetIsConcatSpreadable($isolate); -$helper->assert('Symbol GetIsConcatSpreadable() returned', $value instanceof \V8\SymbolValue); -$helper->pretty_dump('Symbol GetIsConcatSpreadable() name', $value->Name()->Value()); -$helper->line(); +$static_getters = [ + 'GetHasInstance', + 'GetIsConcatSpreadable', + 'GetIterator', + 'GetMatch', + 'GetReplace', + 'GetSearch', + 'GetSplit', + 'GetToPrimitive', + 'GetToStringTag', + 'GetUnscopables', +]; + +foreach ($static_getters as $static_getter) { + $helper->assert('Isolate not in context', !$isolate->InContext()); + $value = V8\SymbolValue::$static_getter($isolate); + $helper->assert("Symbol {$static_getter}() returned", $value instanceof \V8\SymbolValue); + $helper->pretty_dump("Symbol {$static_getter}() name", $value->Name()->Value()); + $helper->line(); +} ?> --EXPECT-- @@ -205,7 +195,7 @@ Accessors: ---------- V8\SymbolValue::GetIsolate() matches expected value V8\SymbolValue->Name(): - object(V8\Value)#86 (1) { + object(V8\Value)#92 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -282,7 +272,7 @@ Null constructor: Object representation: ---------------------- -object(V8\SymbolValue)#86 (1) { +object(V8\SymbolValue)#92 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -509,7 +499,7 @@ Accessors: ---------- V8\SymbolValue::GetIsolate() matches expected value V8\SymbolValue->Name(): - object(V8\StringValue)#87 (1) { + object(V8\StringValue)#93 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -704,13 +694,33 @@ Isolate not in context: ok Symbol ForApi(string) returned: ok Symbol ForApi(string) name: string(4) "test" +Isolate not in context: ok +Symbol GetHasInstance() returned: ok +Symbol GetHasInstance() name: string(18) "Symbol.hasInstance" + +Isolate not in context: ok +Symbol GetIsConcatSpreadable() returned: ok +Symbol GetIsConcatSpreadable() name: string(25) "Symbol.isConcatSpreadable" + Isolate not in context: ok Symbol GetIterator() returned: ok Symbol GetIterator() name: string(15) "Symbol.iterator" Isolate not in context: ok -Symbol GetUnscopables() returned: ok -Symbol GetUnscopables() name: string(18) "Symbol.unscopables" +Symbol GetMatch() returned: ok +Symbol GetMatch() name: string(12) "Symbol.match" + +Isolate not in context: ok +Symbol GetReplace() returned: ok +Symbol GetReplace() name: string(14) "Symbol.replace" + +Isolate not in context: ok +Symbol GetSearch() returned: ok +Symbol GetSearch() name: string(13) "Symbol.search" + +Isolate not in context: ok +Symbol GetSplit() returned: ok +Symbol GetSplit() name: string(12) "Symbol.split" Isolate not in context: ok Symbol GetToPrimitive() returned: ok @@ -721,5 +731,5 @@ Symbol GetToStringTag() returned: ok Symbol GetToStringTag() name: string(18) "Symbol.toStringTag" Isolate not in context: ok -Symbol GetIsConcatSpreadable() returned: ok -Symbol GetIsConcatSpreadable() name: string(25) "Symbol.isConcatSpreadable" +Symbol GetUnscopables() returned: ok +Symbol GetUnscopables() name: string(18) "Symbol.unscopables" diff --git a/tests/V8TryCatch.phpt b/tests/V8TryCatch.phpt index 61891a7..527d0b8 100644 --- a/tests/V8TryCatch.phpt +++ b/tests/V8TryCatch.phpt @@ -35,7 +35,7 @@ $helper->space(); $exception = new \V8\ObjectValue($context); -$message = new \V8\Message('message', 'line', new \V8\ScriptOrigin('resource_name'), 'resource_name', new \V8\StackTrace([], new \V8\ArrayObject($context))); +$message = new \V8\Message('message', 'line', new \V8\ScriptOrigin('resource_name'), 'resource_name', new \V8\StackTrace([])); $trace = new \V8\StringValue($isolate, 'trace'); $obj = new \V8\TryCatch($isolate, $context, $exception, $trace, $message, true, true); @@ -125,7 +125,7 @@ V8\TryCatch::HasTerminated() matches expected value Object representation: ---------------------- -object(V8\TryCatch)#12 (7) { +object(V8\TryCatch)#11 (7) { ["isolate":"V8\TryCatch":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (5) { ["snapshot":"V8\Isolate":private]=> @@ -188,7 +188,7 @@ object(V8\TryCatch)#12 (7) { } } ["stack_trace":"V8\TryCatch":private]=> - object(V8\StringValue)#11 (1) { + object(V8\StringValue)#10 (1) { ["isolate":"V8\Value":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (5) { ["snapshot":"V8\Isolate":private]=> @@ -236,42 +236,10 @@ object(V8\TryCatch)#12 (7) { ["resource_name":"V8\Message":private]=> string(13) "resource_name" ["stack_trace":"V8\Message":private]=> - object(V8\StackTrace)#9 (2) { + object(V8\StackTrace)#9 (1) { ["frames":"V8\StackTrace":private]=> array(0) { } - ["as_array":"V8\StackTrace":private]=> - object(V8\ArrayObject)#10 (2) { - ["isolate":"V8\Value":private]=> - object(v8Tests\TrackingDtors\Isolate)#2 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - ["context":"V8\ObjectValue":private]=> - object(v8Tests\TrackingDtors\Context)#3 (1) { - ["isolate":"V8\Context":private]=> - object(v8Tests\TrackingDtors\Isolate)#2 (5) { - ["snapshot":"V8\Isolate":private]=> - NULL - ["time_limit":"V8\Isolate":private]=> - float(0) - ["time_limit_hit":"V8\Isolate":private]=> - bool(false) - ["memory_limit":"V8\Isolate":private]=> - int(0) - ["memory_limit_hit":"V8\Isolate":private]=> - bool(false) - } - } - } } ["line_number":"V8\Message":private]=> int(0) diff --git a/tests/V8Uint32Value.phpt b/tests/V8Uint32Value.phpt index 9509114..415dcc3 100644 --- a/tests/V8Uint32Value.phpt +++ b/tests/V8Uint32Value.phpt @@ -151,7 +151,7 @@ V8\Uint32Value(V8\Value)->IsProxy(): bool(false) V8\Uint32Value::ToString() converting: -------------------------------------- -object(V8\StringValue)#78 (1) { +object(V8\StringValue)#79 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/tests/V8Value.phpt b/tests/V8Value.phpt index 966d904..e22757b 100644 --- a/tests/V8Value.phpt +++ b/tests/V8Value.phpt @@ -15,6 +15,7 @@ $v8_helper = new PhpV8Helpers($helper); $isolate = new V8\Isolate(); +$context = new V8\Context($isolate); $value = new V8\Value($isolate); @@ -23,7 +24,16 @@ $helper->dump($value); $helper->space(); $helper->assert('Value extends Data', $value instanceof \V8\Data); -$helper->assert('TypeOf returns StringValue', $value->TypeOf($isolate) instanceof \V8\StringValue); +$helper->assert('TypeOf returns StringValue', $value->TypeOf() instanceof \V8\StringValue); +$helper->line(); + +$helper->header('InstanceOf'); +try { + $value->InstanceOf($context, new \V8\ObjectValue($context)); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); +} +$helper->assert('Default Value is not an instance of Function', !$value->InstanceOf($context, new \V8\FunctionObject($context, function(){}))); $helper->line(); $helper->header('Accessors'); @@ -64,7 +74,7 @@ $helper->space(); --EXPECT-- Object representation: ---------------------- -object(V8\Value)#4 (1) { +object(V8\Value)#5 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> @@ -84,6 +94,11 @@ object(V8\Value)#4 (1) { Value extends Data: ok TypeOf returns StringValue: ok +InstanceOf: +----------- +V8\Exceptions\TryCatchException: TypeError: Right-hand side of 'instanceof' is not callable +Default Value is not an instance of Function: ok + Accessors: ---------- V8\Value::GetIsolate() matches expected value @@ -151,7 +166,7 @@ V8\Value->NumberValue(): float(NAN) V8\Value::ToString() converting: -------------------------------- -object(V8\StringValue)#77 (1) { +object(V8\StringValue)#88 (1) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#3 (5) { ["snapshot":"V8\Isolate":private]=> diff --git a/v8.cc b/v8.cc index a3effb5..66603f8 100644 --- a/v8.cc +++ b/v8.cc @@ -34,7 +34,6 @@ #include "php_v8_script.h" #include "php_v8_unbound_script.h" #include "php_v8_cached_data.h" -#include "php_v8_compile_options.h" #include "php_v8_source.h" #include "php_v8_script_compiler.h" #include "php_v8_null.h" @@ -47,7 +46,6 @@ #include "php_v8_int32.h" #include "php_v8_uint32.h" #include "php_v8_primitive.h" -#include "php_v8_integrity_level.h" #include "php_v8_function.h" #include "php_v8_array.h" #include "php_v8_map.h" @@ -59,20 +57,17 @@ #include "php_v8_string_object.h" #include "php_v8_symbol_object.h" #include "php_v8_object.h" -#include "php_v8_property_attribute.h" #include "php_v8_template.h" #include "php_v8_return_value.h" #include "php_v8_callback_info.h" #include "php_v8_property_callback_info.h" #include "php_v8_function_callback_info.h" -#include "php_v8_access_control.h" -#include "php_v8_property_handler_flags.h" #include "php_v8_named_property_handler_configuration.h" #include "php_v8_indexed_property_handler_configuration.h" -#include "php_v8_access_type.h" #include "php_v8_value.h" #include "php_v8_data.h" +#include "php_v8_enums.h" #include "php_v8_ext_mem_interface.h" #include @@ -104,6 +99,8 @@ PHP_INI_END() */ PHP_MINIT_FUNCTION(v8) { + PHP_MINIT(php_v8_enums)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(php_v8_exceptions)(INIT_FUNC_ARGS_PASSTHRU); /* Exceptions */ PHP_MINIT(php_v8_ext_mem_interface)(INIT_FUNC_ARGS_PASSTHRU); /* AdjustableExternalMemoryInterface */ @@ -115,7 +112,6 @@ PHP_MINIT_FUNCTION(v8) PHP_MINIT(php_v8_script)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_unbound_script)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_cached_data)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(php_v8_compile_options)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_source)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_script_compiler)(INIT_FUNC_ARGS_PASSTHRU); @@ -139,7 +135,6 @@ PHP_MINIT_FUNCTION(v8) PHP_MINIT(php_v8_integer)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_int32)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_uint32)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(php_v8_integrity_level)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_object)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_function)(INIT_FUNC_ARGS_PASSTHRU); @@ -159,20 +154,15 @@ PHP_MINIT_FUNCTION(v8) PHP_MINIT(php_v8_function_template)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(php_v8_property_attribute)(INIT_FUNC_ARGS_PASSTHRU); /* Helper class, holds constants for v8 internals similarity/compatibility */ - PHP_MINIT(php_v8_access_control)(INIT_FUNC_ARGS_PASSTHRU); /* Helper class, holds constants */ PHP_MINIT(php_v8_return_value)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_callback_info)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_property_callback_info)(INIT_FUNC_ARGS_PASSTHRU); /* PropertyCallbackInfo inherits CallbackInfo */ PHP_MINIT(php_v8_function_callback_info)(INIT_FUNC_ARGS_PASSTHRU); /* FunctionCallbackInfo inherits CallbackInfo */ - PHP_MINIT(php_v8_property_handler_flags)(INIT_FUNC_ARGS_PASSTHRU); /* Helper class, holds constants */ PHP_MINIT(php_v8_named_property_handler_configuration)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_indexed_property_handler_configuration)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(php_v8_access_type)(INIT_FUNC_ARGS_PASSTHRU); /* Helper class, holds constants */ - /* If you have INI entries, uncomment these lines REGISTER_INI_ENTRIES(); */