Skip to content

Commit fe2e188

Browse files
authored
Merge pull request #307 from stesie/issue-306
Initialize ICU as (meanwhile) needed
2 parents 12c6b53 + ba3f74f commit fe2e188

File tree

7 files changed

+76
-12
lines changed

7 files changed

+76
-12
lines changed

appveyor.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ environment:
22
matrix:
33
- ARTIFACT_NAME: v8js_vc14_php7_%Platform%_ts.zip
44
OUTDIR: Release_TS
5-
V8_ASSETS: V8-5.8.301.0-%Platform%.zip
5+
V8_ASSETS: V8-5.8.283.31-%Platform%.zip
66
- ARTIFACT_NAME: v8js_vc14_php7_%Platform%_nts.zip
77
OUTDIR: Release
88
CONFIGURE_EXTRA: --disable-zts
9-
V8_ASSETS: V8-5.8.301.0-%Platform%.zip
9+
V8_ASSETS: V8-5.8.283.31-%Platform%.zip
1010

11-
PHP_VERSION: 7.0.16
11+
PHP_VERSION: 7.0.18
1212
PHP_SDK: c:\projects\php-sdk
1313

1414
os: Windows Server 2012
@@ -38,6 +38,7 @@ install:
3838
- IF "%Platform%" == "x64" SET OUTDIR=x64\%OUTDIR%
3939
- mkdir %OUTDIR%
4040
- move ..\deps\bin\*.dll %OUTDIR%\
41+
- move ..\deps\bin\icudtl.dat %OUTDIR%\
4142

4243
build_script:
4344
- ps: >-
@@ -57,15 +58,15 @@ build_script:
5758

5859
after_build:
5960
- cd %OUTDIR%
60-
- 7z a %ARTIFACT_NAME% icu*.dll v8.dll php_v8js.dll
61+
- 7z a %ARTIFACT_NAME% icudtl.dat icu*.dll v8.dll php_v8js.dll
6162
- ps: Push-AppveyorArtifact $env:ARTIFACT_NAME
6263

6364
test_script:
6465
- cd c:\projects\php-sdk\v8js-ci\vc14\%Platform%\php-%PHP_VERSION%
6566
- set NO_INTERACTION=1
6667
- set TEST_PHP_JUNIT=junit.xml
6768
- set REPORT_EXIT_STATUS=1
68-
- "%OUTDIR%\\php.exe run-tests.php -p %OUTDIR%\\php.exe ext/v8js/tests/ -d extension=php_v8js.dll -d extension_dir=%OUTDIR%\\"
69+
- "%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%\\"
6970

7071
on_finish:
7172
- cd c:\projects\php-sdk\v8js-ci\vc14\%Platform%\php-%PHP_VERSION%

config.m4

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PHP_ARG_WITH(v8js, for V8 Javascript Engine,
33

44
if test "$PHP_V8JS" != "no"; then
55
SEARCH_PATH="/usr/local /usr"
6-
SEARCH_FOR="include/v8.h"
6+
SEARCH_FOR="$PHP_LIBDIR/libv8.$SHLIB_SUFFIX_NAME"
77

88
if test -r $PHP_V8JS/$SEARCH_FOR; then
99
case $host_os in
@@ -25,6 +25,8 @@ if test "$PHP_V8JS" != "no"; then
2525
done
2626
fi
2727

28+
AC_DEFINE_UNQUOTED([PHP_V8_EXEC_PATH], "$V8_DIR/$SEARCH_FOR", [Full path to libv8 library file])
29+
2830
if test -z "$V8_DIR"; then
2931
AC_MSG_RESULT([not found])
3032
AC_MSG_ERROR([Please reinstall the v8 distribution])

config.w32

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ if (PHP_V8JS != "no") {
7777
AC_DEFINE("PHP_V8_API_VERSION", v8api, "", false);
7878
AC_DEFINE("PHP_V8_VERSION", v8ver, "", true);
7979

80+
// AC_DEFINE("PHP_V8_EXEC_PATH", "C:\\php\\bin\\v8.dll", "", true);
81+
8082
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");
8183

8284
} else {

php_v8js_macros.h

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ struct _v8js_process_globals {
156156
/* V8 command line flags */
157157
char *v8_flags;
158158

159+
/* Path to icudtl.dat file */
160+
char *icudtl_dat_path;
161+
159162
v8::Platform *v8_platform;
160163
};
161164

tests/issue_306_basic.phpt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test V8::executeString() : Issue #306 V8 crashing on toLocaleString()
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$v8 = new V8Js();
9+
10+
$expr = 'new Date("10/11/2009").toLocaleString("en-us", { month: "long" });';
11+
$result = $v8->executeString($expr);
12+
13+
// V8 can be compiled with i18n support and without;
14+
// without i18n support however toLocaleString doesn't really work,
15+
// it just returns the date string...
16+
17+
if ($result === 'October') {
18+
var_dump(true);
19+
} else {
20+
$expr = 'new Date("10/11/2009").toString();';
21+
var_dump($v8->executeString($expr) === $result);
22+
}
23+
24+
?>
25+
===EOF===
26+
--EXPECT--
27+
bool(true)
28+
===EOF===

v8js_main.cc

+22-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct _v8js_process_globals v8js_process_globals;
3333

3434
/* {{{ INI Settings */
3535

36-
static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */
36+
static bool v8js_ini_string(char **field, const zend_string *new_value)/* {{{ */
3737
{
3838
bool immutable = false;
3939

@@ -56,18 +56,33 @@ static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */
5656
}
5757

5858
if (new_value) {
59-
if (v8js_process_globals.v8_flags) {
60-
free(v8js_process_globals.v8_flags);
61-
v8js_process_globals.v8_flags = NULL;
59+
if (*field) {
60+
free(*field);
61+
*field = NULL;
6262
}
63+
6364
if (!ZSTR_VAL(new_value)[0]) {
64-
return FAILURE;
65+
return SUCCESS;
6566
}
66-
v8js_process_globals.v8_flags = zend_strndup(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
67+
68+
*field = zend_strndup(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
6769
}
6870

6971
return SUCCESS;
7072
}
73+
/* }}} */
74+
75+
static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */
76+
{
77+
return v8js_ini_string(&v8js_process_globals.v8_flags, new_value);
78+
}
79+
/* }}} */
80+
81+
static ZEND_INI_MH(v8js_OnUpdateIcudatPath) /* {{{ */
82+
{
83+
return v8js_ini_string(&v8js_process_globals.icudtl_dat_path, new_value);
84+
}
85+
/* }}} */
7186

7287
static bool v8js_ini_to_bool(const zend_string *new_value) /* {{{ */
7388
{
@@ -106,6 +121,7 @@ static ZEND_INI_MH(v8js_OnUpdateCompatExceptions) /* {{{ */
106121

107122
ZEND_INI_BEGIN() /* {{{ */
108123
ZEND_INI_ENTRY("v8js.flags", NULL, ZEND_INI_ALL, v8js_OnUpdateV8Flags)
124+
ZEND_INI_ENTRY("v8js.icudtl_dat_path", NULL, ZEND_INI_ALL, v8js_OnUpdateIcudatPath)
109125
ZEND_INI_ENTRY("v8js.use_date", "0", ZEND_INI_ALL, v8js_OnUpdateUseDate)
110126
ZEND_INI_ENTRY("v8js.use_array_access", "0", ZEND_INI_ALL, v8js_OnUpdateUseArrayAccess)
111127
ZEND_INI_ENTRY("v8js.compat_php_exceptions", "0", ZEND_INI_ALL, v8js_OnUpdateCompatExceptions)

v8js_v8.cc

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ void v8js_v8_init() /* {{{ */
7676
}
7777
}
7878

79+
#if PHP_V8_API_VERSION >= 5003178
80+
/* Initialize ICU, call introduced in V8 5.3.178 */
81+
if (v8js_process_globals.icudtl_dat_path != NULL && v8js_process_globals.icudtl_dat_path[0] != 0) {
82+
v8::V8::InitializeICUDefaultLocation(nullptr, v8js_process_globals.icudtl_dat_path);
83+
}
84+
#ifdef PHP_V8_EXEC_PATH
85+
else {
86+
v8::V8::InitializeICUDefaultLocation(PHP_V8_EXEC_PATH, nullptr);
87+
}
88+
#endif
89+
#endif /* PHP_V8_API_VERSION >= 5003178 */
90+
7991
/* Initialize V8 */
8092
v8::V8::Initialize();
8193

0 commit comments

Comments
 (0)