From c957be8b2a0048e0bd384f4156de5ab4d2f129e0 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 14 Apr 2017 14:27:01 +0200 Subject: [PATCH 1/7] Initialize ICU as (meanwhile) needed --- config.m4 | 4 +++- tests/issue_306_basic.phpt | 18 ++++++++++++++++++ v8js_v8.cc | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/issue_306_basic.phpt diff --git a/config.m4 b/config.m4 index f012482f..9da20e4a 100644 --- a/config.m4 +++ b/config.m4 @@ -3,7 +3,7 @@ PHP_ARG_WITH(v8js, for V8 Javascript Engine, if test "$PHP_V8JS" != "no"; then SEARCH_PATH="/usr/local /usr" - SEARCH_FOR="include/v8.h" + SEARCH_FOR="$PHP_LIBDIR/libv8.$SHLIB_DL_SUFFIX_NAME" if test -r $PHP_V8JS/$SEARCH_FOR; then case $host_os in @@ -25,6 +25,8 @@ if test "$PHP_V8JS" != "no"; then done fi + AC_DEFINE_UNQUOTED([PHP_V8_EXEC_PATH], "$V8_DIR/$SEARCH_FOR", [Full path to libv8 library file]) + if test -z "$V8_DIR"; then AC_MSG_RESULT([not found]) AC_MSG_ERROR([Please reinstall the v8 distribution]) diff --git a/tests/issue_306_basic.phpt b/tests/issue_306_basic.phpt new file mode 100644 index 00000000..c3d02446 --- /dev/null +++ b/tests/issue_306_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test V8::executeString() : Issue #306 V8 crashing on toLocaleString() +--SKIPIF-- + +--FILE-- +executeString($expr, null, V8Js::FLAG_FORCE_ARRAY) ); + +?> +===EOF=== +--EXPECT-- +string(7) "October" +===EOF=== diff --git a/v8js_v8.cc b/v8js_v8.cc index 2114d381..ab432e5c 100644 --- a/v8js_v8.cc +++ b/v8js_v8.cc @@ -76,6 +76,11 @@ void v8js_v8_init() /* {{{ */ } } +#ifdef PHP_V8_EXEC_PATH + /* Initialize ICU */ + v8::V8::InitializeICUDefaultLocation(PHP_V8_EXEC_PATH, nullptr); +#endif + /* Initialize V8 */ v8::V8::Initialize(); From 5f08db8a499ef1617236a2576f8c8ad59a5ab66b Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 14 Apr 2017 19:36:21 +0200 Subject: [PATCH 2/7] Don't initialize ICU on V8 < 5.3.178 --- v8js_v8.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v8js_v8.cc b/v8js_v8.cc index ab432e5c..ecd6a99b 100644 --- a/v8js_v8.cc +++ b/v8js_v8.cc @@ -76,8 +76,8 @@ void v8js_v8_init() /* {{{ */ } } -#ifdef PHP_V8_EXEC_PATH - /* Initialize ICU */ +#if defined(PHP_V8_EXEC_PATH) && PHP_V8_API_VERSION >= 5003178 + /* Initialize ICU, call introduced in V8 5.3.178 */ v8::V8::InitializeICUDefaultLocation(PHP_V8_EXEC_PATH, nullptr); #endif From 6723ff2d34c505c7019db0f0a3c4e035dac2da2a Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 14 Apr 2017 20:59:25 +0200 Subject: [PATCH 3/7] fix check for libv8.dylib (on macOS) --- config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.m4 b/config.m4 index 9da20e4a..69127eae 100644 --- a/config.m4 +++ b/config.m4 @@ -3,7 +3,7 @@ PHP_ARG_WITH(v8js, for V8 Javascript Engine, if test "$PHP_V8JS" != "no"; then SEARCH_PATH="/usr/local /usr" - SEARCH_FOR="$PHP_LIBDIR/libv8.$SHLIB_DL_SUFFIX_NAME" + SEARCH_FOR="$PHP_LIBDIR/libv8.$SHLIB_SUFFIX_NAME" if test -r $PHP_V8JS/$SEARCH_FOR; then case $host_os in From 09f69caf64201ae5f95e5cc2650c21e171027203 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 14 Apr 2017 22:48:39 +0200 Subject: [PATCH 4/7] Relax test to work on V8 without i18n support --- tests/issue_306_basic.phpt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/issue_306_basic.phpt b/tests/issue_306_basic.phpt index c3d02446..8b6f8e7f 100644 --- a/tests/issue_306_basic.phpt +++ b/tests/issue_306_basic.phpt @@ -7,12 +7,22 @@ Test V8::executeString() : Issue #306 V8 crashing on toLocaleString() $v8 = new V8Js(); -$v8 = new V8Js; $expr = 'new Date("10/11/2009").toLocaleString("en-us", { month: "long" });'; -var_dump( $v8->executeString($expr, null, V8Js::FLAG_FORCE_ARRAY) ); +$result = $v8->executeString($expr); + +// V8 can be compiled with i18n support and without; +// without i18n support however toLocaleString doesn't really work, +// it just returns the date string... + +if ($result === 'October') { + var_dump(true); +} else { + $expr = 'new Date("10/11/2009").toString();'; + var_dump($v8->executeString($expr) === $result); +} ?> ===EOF=== --EXPECT-- -string(7) "October" -===EOF=== +bool(true) +===EOF=== \ No newline at end of file From 73e1f3c9a223191480d8ddadce704ffc8b30580d Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 14 Apr 2017 22:54:42 +0200 Subject: [PATCH 5/7] appveyor gah ... --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index a6f9db6a..fea0873a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -69,6 +69,7 @@ test_script: on_finish: - cd c:\projects\php-sdk\v8js-ci\vc14\%Platform%\php-%PHP_VERSION% + - type ext\v8js\tests\issue_306_basic.out - ps: | # upload results to AppVeyor $wc = New-Object 'System.Net.WebClient' From 989f0ae82c8e2e52df400966eefa9df7cbdac95d Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 21 Apr 2017 18:20:12 +0200 Subject: [PATCH 6/7] Add php.ini setting v8js.icudtl_dat_path --- php_v8js_macros.h | 3 +++ v8js_main.cc | 28 ++++++++++++++++++++++------ v8js_v8.cc | 13 ++++++++++--- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index 7fca6db8..b3071010 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -156,6 +156,9 @@ struct _v8js_process_globals { /* V8 command line flags */ char *v8_flags; + /* Path to icudtl.dat file */ + char *icudtl_dat_path; + v8::Platform *v8_platform; }; diff --git a/v8js_main.cc b/v8js_main.cc index b9acd51c..bc60ba9d 100644 --- a/v8js_main.cc +++ b/v8js_main.cc @@ -33,7 +33,7 @@ struct _v8js_process_globals v8js_process_globals; /* {{{ INI Settings */ -static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */ +static bool v8js_ini_string(char **field, const zend_string *new_value)/* {{{ */ { bool immutable = false; @@ -56,18 +56,33 @@ static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */ } if (new_value) { - if (v8js_process_globals.v8_flags) { - free(v8js_process_globals.v8_flags); - v8js_process_globals.v8_flags = NULL; + if (*field) { + free(*field); + *field = NULL; } + if (!ZSTR_VAL(new_value)[0]) { - return FAILURE; + return SUCCESS; } - v8js_process_globals.v8_flags = zend_strndup(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); + + *field = zend_strndup(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); } return SUCCESS; } +/* }}} */ + +static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */ +{ + return v8js_ini_string(&v8js_process_globals.v8_flags, new_value); +} +/* }}} */ + +static ZEND_INI_MH(v8js_OnUpdateIcudatPath) /* {{{ */ +{ + return v8js_ini_string(&v8js_process_globals.icudtl_dat_path, new_value); +} +/* }}} */ static bool v8js_ini_to_bool(const zend_string *new_value) /* {{{ */ { @@ -106,6 +121,7 @@ static ZEND_INI_MH(v8js_OnUpdateCompatExceptions) /* {{{ */ ZEND_INI_BEGIN() /* {{{ */ ZEND_INI_ENTRY("v8js.flags", NULL, ZEND_INI_ALL, v8js_OnUpdateV8Flags) + ZEND_INI_ENTRY("v8js.icudtl_dat_path", NULL, ZEND_INI_ALL, v8js_OnUpdateIcudatPath) ZEND_INI_ENTRY("v8js.use_date", "0", ZEND_INI_ALL, v8js_OnUpdateUseDate) ZEND_INI_ENTRY("v8js.use_array_access", "0", ZEND_INI_ALL, v8js_OnUpdateUseArrayAccess) ZEND_INI_ENTRY("v8js.compat_php_exceptions", "0", ZEND_INI_ALL, v8js_OnUpdateCompatExceptions) diff --git a/v8js_v8.cc b/v8js_v8.cc index ecd6a99b..f886f0c0 100644 --- a/v8js_v8.cc +++ b/v8js_v8.cc @@ -76,10 +76,17 @@ void v8js_v8_init() /* {{{ */ } } -#if defined(PHP_V8_EXEC_PATH) && PHP_V8_API_VERSION >= 5003178 - /* Initialize ICU, call introduced in V8 5.3.178 */ - v8::V8::InitializeICUDefaultLocation(PHP_V8_EXEC_PATH, nullptr); +#if PHP_V8_API_VERSION >= 5003178 + /* Initialize ICU, call introduced in V8 5.3.178 */ + if (v8js_process_globals.icudtl_dat_path != NULL && v8js_process_globals.icudtl_dat_path[0] != 0) { + v8::V8::InitializeICUDefaultLocation(nullptr, v8js_process_globals.icudtl_dat_path); + } +#ifdef PHP_V8_EXEC_PATH + else { + v8::V8::InitializeICUDefaultLocation(PHP_V8_EXEC_PATH, nullptr); + } #endif +#endif /* PHP_V8_API_VERSION >= 5003178 */ /* Initialize V8 */ v8::V8::Initialize(); From ba3f74f45cab4eebe78ee6895b5cd2da24ce24f6 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 22 Apr 2017 11:37:34 +0200 Subject: [PATCH 7/7] Fix PHP_V8_EXEC_PATH for Windows build also --- appveyor.yml | 12 ++++++------ config.w32 | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index fea0873a..59baea1a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,13 +2,13 @@ environment: matrix: - ARTIFACT_NAME: v8js_vc14_php7_%Platform%_ts.zip OUTDIR: Release_TS - V8_ASSETS: V8-5.8.301.0-%Platform%.zip + V8_ASSETS: V8-5.8.283.31-%Platform%.zip - ARTIFACT_NAME: v8js_vc14_php7_%Platform%_nts.zip OUTDIR: Release CONFIGURE_EXTRA: --disable-zts - V8_ASSETS: V8-5.8.301.0-%Platform%.zip + V8_ASSETS: V8-5.8.283.31-%Platform%.zip - PHP_VERSION: 7.0.16 + PHP_VERSION: 7.0.18 PHP_SDK: c:\projects\php-sdk os: Windows Server 2012 @@ -38,6 +38,7 @@ install: - IF "%Platform%" == "x64" SET OUTDIR=x64\%OUTDIR% - mkdir %OUTDIR% - move ..\deps\bin\*.dll %OUTDIR%\ + - move ..\deps\bin\icudtl.dat %OUTDIR%\ build_script: - ps: >- @@ -57,7 +58,7 @@ build_script: after_build: - cd %OUTDIR% - - 7z a %ARTIFACT_NAME% icu*.dll v8.dll php_v8js.dll + - 7z a %ARTIFACT_NAME% icudtl.dat icu*.dll v8.dll php_v8js.dll - ps: Push-AppveyorArtifact $env:ARTIFACT_NAME test_script: @@ -65,11 +66,10 @@ test_script: - set NO_INTERACTION=1 - set TEST_PHP_JUNIT=junit.xml - set REPORT_EXIT_STATUS=1 - - "%OUTDIR%\\php.exe run-tests.php -p %OUTDIR%\\php.exe ext/v8js/tests/ -d extension=php_v8js.dll -d extension_dir=%OUTDIR%\\" + - "%OUTDIR%\\php.exe run-tests.php -p %OUTDIR%\\php.exe ext/v8js/tests/ -d v8js.icudtl_dat_path=%OUTDIR%/icudtl.dat -d extension=php_v8js.dll -d extension_dir=%OUTDIR%\\" on_finish: - cd c:\projects\php-sdk\v8js-ci\vc14\%Platform%\php-%PHP_VERSION% - - type ext\v8js\tests\issue_306_basic.out - ps: | # upload results to AppVeyor $wc = New-Object 'System.Net.WebClient' diff --git a/config.w32 b/config.w32 index d5ef2a4a..efc93497 100644 --- a/config.w32 +++ b/config.w32 @@ -77,6 +77,8 @@ if (PHP_V8JS != "no") { AC_DEFINE("PHP_V8_API_VERSION", v8api, "", false); AC_DEFINE("PHP_V8_VERSION", v8ver, "", true); + // AC_DEFINE("PHP_V8_EXEC_PATH", "C:\\php\\bin\\v8.dll", "", true); + EXTENSION("v8js", "v8js_array_access.cc v8js_class.cc v8js_commonjs.cc v8js_convert.cc v8js_exceptions.cc v8js_generator_export.cc v8js_main.cc v8js_methods.cc v8js_object_export.cc v8js_timer.cc v8js_v8.cc v8js_v8object_class.cc v8js_variables.cc", "yes"); } else {