Skip to content

Initialize ICU as (meanwhile) needed #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: >-
Expand All @@ -57,15 +58,15 @@ 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:
- cd c:\projects\php-sdk\v8js-ci\vc14\%Platform%\php-%PHP_VERSION%
- 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%
Expand Down
4 changes: 3 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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_SUFFIX_NAME"

if test -r $PHP_V8JS/$SEARCH_FOR; then
case $host_os in
Expand All @@ -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])
Expand Down
2 changes: 2 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions php_v8js_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
28 changes: 28 additions & 0 deletions tests/issue_306_basic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test V8::executeString() : Issue #306 V8 crashing on toLocaleString()
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php

$v8 = new V8Js();

$expr = 'new Date("10/11/2009").toLocaleString("en-us", { month: "long" });';
$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--
bool(true)
===EOF===
28 changes: 22 additions & 6 deletions v8js_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) /* {{{ */
{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions v8js_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ void v8js_v8_init() /* {{{ */
}
}

#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();

Expand Down