phpv8 / v8js

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
http://pecl.php.net/package/v8js
MIT License
1.83k stars 200 forks source link

ICU/ECMA-402 support? #182

Closed kynx closed 8 years ago

kynx commented 8 years ago

Any chance of getting this built in?

From the docs it looks as simple as adding v8::v8::InitializeICU() to v8js_v8_init(). But when I tried that it blew up. Turned out my v8 was built with i18nsupport=off and I'm not really sure how to test for that.

stesie commented 8 years ago

ICU/ECMA-402 support should be available without modifications to V8Js once you don't compile with i18nsupport=off. You actually don't have to call InitializeICU yourself, V8 does by itself.

You tried with a V8 with i18nsupport (which is the default):

stesie@hahnschaaf:~/Projekte/v8js-php7$ /opt/php-7.0.0RC3/bin/php -n -d extension_dir=./modules -d extension=v8js.so  -a
Interactive shell

php > $v8 = new V8Js();
php > $v8->blar = 3500;
php > $v8->executeString(' var_dump( new Intl.NumberFormat("en-US").format(PHP.blar));  ');
string(5) "3,500"
php > $v8->executeString(' var_dump( new Intl.NumberFormat().format(PHP.blar));  ');
string(5) "3.500"

... looks like it just works to me :-)

my box has German locale, hence the dot for digit grouping

kynx commented 8 years ago

Hey, fantastic. Serves me right for mucking about to get v8 compiled with use_system_icu - must've missed v8js doing the right thing amidst all my swearing :)