Coder Social home page Coder Social logo

phpv8 / v8js Goto Github PK

View Code? Open in Web Editor NEW
1.8K 67.0 197.0 1.79 MB

V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine

Home Page: http://pecl.php.net/package/v8js

License: MIT License

C 2.33% C++ 52.25% PHP 43.37% M4 1.92% Makefile 0.13%
v8js javascript php php-extension v8 v8-javascript-engine php-v8

v8js's People

Contributors

alexmasterov avatar amuluowin avatar andrewtch avatar beest avatar chenos avatar chrisbckr avatar christiaan avatar cscott avatar felipensp avatar gitter-badger avatar hoffmannp avatar jalr avatar jan-e avatar k2s avatar maryo avatar petk avatar rbro avatar redbullmarky avatar remicollet avatar sameoldmadness avatar sasezaki avatar stesie avatar teameh avatar tenorviol avatar tysonandre avatar uniconstructor avatar waqasbelushi avatar weltling avatar yllierop avatar zakay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v8js's Issues

Urgent! This repo is publicly accessible!

This repository is publicly accessible. Pushing proprietary code to this repo could reveal trade secrets.

If this is intentional, please contact your lead so this repo can be whitelisted. Until that time, please refrain from pushing code to this repo.

executeFile method - feature request

Thank you for a very useful extension. Would it be possible to add an executeFile() method that works just like executeString() except it takes a filename as its first argument? This would avoid having to call file_get_contents when the javascript to execute is in an external file.

For example, rather than doing:

$v8->executeString(file_get_contents('test.js'));

executeFile would allow calls like:

$v8->executeFile('test.js');

Thanks.

Lifespan of php_v8js_ctx

I'd like to think about the cleanup of php_v8js_ctx some more. I think it might be possible for the ctx to be deallocated before all of the objects created in that context have been dereferenced -- like if you return a javascript object to PHP, store it in a property somewhere, and then the V8JS object falls out of scope. Any ideas on how best to handle that situation? Maybe we should ref the V8JS object whenever we create a new PHP wrapper of a JS object? V8 also has some "object group" features which might be relevant.

Compiling on OS X

I have had a lot of trouble compiling on OS X using the method described in the readme.

I have got it working with the following instead (requires g++-4.7).

cd /tmp
git clone https://github.com/v8/v8.git
cd v8
make dependencies

export CXX=/usr/local/bin/g++-4.7
export LINK=/usr/local/bin/g++-4.7
make native component=shared_library snapshot=off -j8

# Important to turn snapshot off

sudo mkdir -p /tmp/v8-install/lib /tmp/v8-install/include

# Copy the dylib as an "so" doesn't get built
sudo cp out/native/lib*.dylib /tmp/v8-install/lib/
sudo cp include/v8* /tmp/v8-install/include

cd /tmp
git clone https://github.com/preillyme/v8js.git
cd v8js
phpize

# Need to configure with D_GLIBCXX_USE_NANOSLEEP
./configure --with-v8js=/tmp/v8-install CXXFLAGS="-D_GLIBCXX_USE_NANOSLEEP"
make

I also needed to remove the "-Wl,-rpath" flags in the config.m4 file:

dnl $Id$

PHP_ARG_WITH(v8js, for V8 Javascript Engine,
[  --with-v8js           Include V8 JavaScript Engine])

if test "$PHP_V8JS" != "no"; then
  SEARCH_PATH="/usr/local /usr"
  SEARCH_FOR="include/v8.h"

  if test -r $PHP_V8JS/$SEARCH_FOR; then
    LDFLAGS="$LDFLAGS"
    V8_DIR=$PHP_V8JS
  else
    AC_MSG_CHECKING([for V8 files in default path])
    for i in $SEARCH_PATH ; do
      if test -r $i/$SEARCH_FOR; then
        V8_DIR=$i
        AC_MSG_RESULT(found in $i)
      fi
    done
  fi

  if test -z "$V8_DIR"; then
    AC_MSG_RESULT([not found])
    AC_MSG_ERROR([Please reinstall the v8 distribution])
  fi

  PHP_ADD_INCLUDE($V8_DIR/include)
  PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_DIR/$PHP_LIBDIR, V8JS_SHARED_LIBADD)
  PHP_SUBST(V8JS_SHARED_LIBADD)
  PHP_REQUIRE_CXX()

  old_LIBS=$LIBS
  old_LDFLAGS=$LDFLAGS
  old_CPPFLAGS=$CPPFLAGS
  LDFLAGS="-L$V8_DIR/$PHP_LIBDIR"
  LIBS=-lv8
  CPPFLAGS=-I$V8_DIR/include
  AC_LANG_SAVE
  AC_LANG_CPLUSPLUS

  AC_CACHE_CHECK(for V8 version, ac_cv_v8_version, [
AC_TRY_RUN([#include <v8.h>
#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
    ofstream testfile ("conftestval");
    if (testfile.is_open()) {
        testfile << v8::V8::GetVersion();
        testfile << "\n";
        testfile.close();
        return 0;
    }
    return 1;
}], [ac_cv_v8_version=`cat ./conftestval|awk '{print $1}'`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
])

  if test "$ac_cv_v8_version" != "NONE"; then
    ac_IFS=$IFS
    IFS=.
    set $ac_cv_v8_version
    IFS=$ac_IFS
    V8_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
    if test "$V8_API_VERSION" -lt 3021012 ; then
       AC_MSG_ERROR([libv8 must be version 3.21.12 or greater])
    fi
    AC_DEFINE_UNQUOTED([PHP_V8_API_VERSION], $V8_API_VERSION, [ ])
    AC_DEFINE_UNQUOTED([PHP_V8_VERSION], "$ac_cv_v8_version", [ ])
  else
    AC_MSG_ERROR([could not determine libv8 version])
  fi

  AC_CACHE_CHECK(for debuggersupport in v8, ac_cv_v8_debuggersupport, [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <v8-debug.h>]],
                               [[v8::Debug::DisableAgent()]])],
    [ac_cv_v8_debuggersupport=yes],
    [ac_cv_v8_debuggersupport=no])
])

  if test "$ac_cv_v8_debuggersupport" = "yes"; then
    AC_DEFINE([ENABLE_DEBUGGER_SUPPORT], [1], [Enable debugger support in V8Js])
  fi

  AC_LANG_RESTORE
  LIBS=$old_LIBS
  LDFLAGS=$old_LDFLAGS
  CPPFLAGS=$old_CPPFLAGS


  AC_CACHE_CHECK(for C standard version, ac_cv_v8_cstd, [
    ac_cv_v8_cstd="c++11"
    old_CPPFLAGS=$CPPFLAGS
    AC_LANG_PUSH([C++])
    CPPFLAGS="-std="$ac_cv_v8_cstd
    AC_TRY_RUN([int main() { return 0; }],[],[ac_cv_v8_cstd="c++0x"],[])
    AC_LANG_POP([C++])
    CPPFLAGS=$old_CPPFLAGS
  ]);

  PHP_NEW_EXTENSION(v8js, v8js.cc v8js_convert.cc v8js_methods.cc v8js_variables.cc v8js_commonjs.cc, $ext_shared, , "-std="$ac_cv_v8_cstd)

  PHP_ADD_MAKEFILE_FRAGMENT
fi

Fails to compile with v8 3.21.18.2

Starting at commit 6192319, I get the following errors when compiling against v8 3.21.18.2 (the latest 3.21 version of v8):

/bin/sh /home/cananian/Wikimedia/scribunto-js/v8js/libtool --mode=compile g++ -std=c++11 -I. -I/home/cananian/Wikimedia/scribunto-js/v8js -DPHP_ATOM_INC -I/home/cananian/Wikimedia/scribunto-js/v8js/include -I/home/cananian/Wikimedia/scribunto-js/v8js/main -I/home/cananian/Wikimedia/scribunto-js/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/home/cananian/Wikimedia/scribunto-js/v8js/v8/include  -DHAVE_CONFIG_H  -g -O2   -c /home/cananian/Wikimedia/scribunto-js/v8js/v8js_convert.cc -o v8js_convert.lo 
libtool: compile:  g++ -std=c++11 -I. -I/home/cananian/Wikimedia/scribunto-js/v8js -DPHP_ATOM_INC -I/home/cananian/Wikimedia/scribunto-js/v8js/include -I/home/cananian/Wikimedia/scribunto-js/v8js/main -I/home/cananian/Wikimedia/scribunto-js/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/home/cananian/Wikimedia/scribunto-js/v8js/v8/include -DHAVE_CONFIG_H -g -O2 -c /home/cananian/Wikimedia/scribunto-js/v8js/v8js_convert.cc  -fPIC -DPIC -o .libs/v8js_convert.o
/home/cananian/Wikimedia/scribunto-js/v8js/v8js_convert.cc:37:13: error: expected unqualified-id before 'static'
   V8_INLINE(static void Copy(const Persistent<S, M>& source,
             ^
/home/cananian/Wikimedia/scribunto-js/v8js/v8js_convert.cc:37:13: error: expected ')' before 'static'
In file included from /home/cananian/Wikimedia/scribunto-js/v8js/php_v8js_macros.h:24:0,
                 from /home/cananian/Wikimedia/scribunto-js/v8js/v8js_convert.cc:27:
/home/cananian/Wikimedia/scribunto-js/v8js/v8/include/v8.h: In instantiation of 'void v8::Persistent<T, M>::Copy(const v8::Persistent<S, M>&) [with S = v8::FunctionTemplate; M2 = v8::CopyablePersistentTraits<v8::FunctionTemplate>; T = v8::FunctionTemplate; M = v8::CopyablePersistentTraits<v8::FunctionTemplate>]':
/home/cananian/Wikimedia/scribunto-js/v8js/v8/include/v8.h:536:14:   required from 'v8::Persistent<T, M>& v8::Persistent<T, M>::operator=(const v8::Persistent<T, M>&) [with T = v8::FunctionTemplate; M = v8::CopyablePersistentTraits<v8::FunctionTemplate>]'
/home/cananian/Wikimedia/scribunto-js/v8js/v8js_convert.cc:421:44:   required from here
/home/cananian/Wikimedia/scribunto-js/v8js/v8/include/v8.h:5572:21: error: 'Copy' is not a member of 'v8::CopyablePersistentTraits<v8::FunctionTemplate>'
   M::Copy(that, this);
                     ^
make: *** [v8js_convert.lo] Error 1

We currently test against 3.21.12, so this should work...

v8js leaks memory if objects are returned to javascript

Hi there,

if I call a PHP function from JavaScript context and the PHP function returns a object, the object seems not to be correctly garbage collected even if the passed back object is not stored at all.

Code snippet to reproduce:

<?php

ini_set("v8js.flags", "--trace_gc");
$v8 = new V8Js();

class Failer {
    function call() {
        return new stdClass();
    }   
}

$v8->failer = new Failer();

$v8->executeString('
        for(;;) {
            PHP.failer.call();
        }
    ');

... after running for some twenty seconds the memory consumption hits roughly 1,5 GB, then the loop performs very poorly and v8 garbage collects on almost every instruction ... however it doesn't get rid of all those objects ...

No problem if you pass back an array or immediate values from the function though ...

I've just started using v8js the other day, neither am I a PHP "backend" developer, hence I currently have no clue on how to fix that...

cheers
stesie

Private/protected object properties are accessible from JS

Hi,

Not sure if this is intended behaviour or not, but it seems like a regression given the number of test cases that have comments saying private/protected properties shouldn't be accessible from the JS side.

Test code:

<?php

class Foo {

        private $privBar = "privBar";
        protected $protBar = "protBar";
        public $pubBar = "pubBar";

}

$js = new V8Js();

$js->foo = new Foo();

$script = <<<END

print(PHP.foo.privBar);
print(PHP.foo.protBar);
print(PHP.foo.pubBar);

END;

$js->executeString($script);

This prints all three strings instead of throwing an error or printing undefined for the non-public ones.

Ubuntu 13.10
PHP 5.5.3-1ubuntu2
phpv8js: e68d707
v8: 735e6593693921a959ca3c82037a3a918da26362

If this is the desired behaviour, would it be possible to allow configuring this? From my point of view it's not desirable to expose priv/prot properties from PHP classes to JS.

Thanks,
Chris

v8js fails to build with libv8 version 3.8.9.20

Hi there,

v8js fails to build from source with libv8 version 3.8.9.20, as currently packaged in Debian Wheezy. However the README file states it requires at least 3.2.4

Here is how the build fails ...

libtool: compile:  g++ -std=c++11 -I. -I/home/stesie/Projekte/v8js -DPHP_ATOM_INC -I/home/stesie/Projekte/v8js/include -I/home/stesie/Projekte/v8js/main -I/home/stesie/Projekte/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/stesie/Projekte/v8js/v8js.cc  -fPIC -DPIC -o .libs/v8js.o
/home/stesie/Projekte/v8js/v8js.cc:80:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/home/stesie/Projekte/v8js/v8js.cc:80:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/home/stesie/Projekte/v8js/v8js.cc:80:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/home/stesie/Projekte/v8js/v8js.cc: In function 'HashTable* php_v8js_v8_get_properties(zval*)':
/home/stesie/Projekte/v8js/v8js.cc:233:42: error: no matching function for call to 'v8::HandleScope::HandleScope(v8::Isolate*&)'
/home/stesie/Projekte/v8js/v8js.cc:233:42: note: candidates are:
In file included from /home/stesie/Projekte/v8js/php_v8js_macros.h:30:0,
                 from /home/stesie/Projekte/v8js/v8js.cc:28:
/usr/include/v8.h:463:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
/usr/include/v8.h:463:3: note:   no known conversion for argument 1 from 'v8::Isolate*' to 'const v8::HandleScope&'
/usr/include/v8.h:438:3: note: v8::HandleScope::HandleScope()
/usr/include/v8.h:438:3: note:   candidate expects 0 arguments, 1 provided
/home/stesie/Projekte/v8js/v8js.cc: In function 'void zim_V8Js___construct(int, zval*, zval**, zval*, int)':
/home/stesie/Projekte/v8js/v8js.cc:580:41: error: no matching function for call to 'v8::HandleScope::HandleScope(v8::Isolate*&)'
/home/stesie/Projekte/v8js/v8js.cc:580:41: note: candidates are:
In file included from /home/stesie/Projekte/v8js/php_v8js_macros.h:30:0,
                 from /home/stesie/Projekte/v8js/v8js.cc:28:
/usr/include/v8.h:463:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
/usr/include/v8.h:463:3: note:   no known conversion for argument 1 from 'v8::Isolate*' to 'const v8::HandleScope&'
/usr/include/v8.h:438:3: note: v8::HandleScope::HandleScope()
/usr/include/v8.h:438:3: note:   candidate expects 0 arguments, 1 provided
/home/stesie/Projekte/v8js/v8js.cc:597:14: error: 'class v8::Context' has no member named 'SetAlignedPointerInEmbedderData'
/home/stesie/Projekte/v8js/v8js.cc: In function 'void php_v8js_timer_thread()':
/home/stesie/Projekte/v8js/v8js.cc:714:16: error: 'class v8::Isolate' has no member named 'GetHeapStatistics'
/home/stesie/Projekte/v8js/v8js.cc: In function 'void zim_V8Js_executeString(int, zval*, zval**, zval*, int)':
/home/stesie/Projekte/v8js/v8js.cc:761:41: error: no matching function for call to 'v8::HandleScope::HandleScope(v8::Isolate*&)'
/home/stesie/Projekte/v8js/v8js.cc:761:41: note: candidates are:
In file included from /home/stesie/Projekte/v8js/php_v8js_macros.h:30:0,
                 from /home/stesie/Projekte/v8js/v8js.cc:28:
/usr/include/v8.h:463:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
/usr/include/v8.h:463:3: note:   no known conversion for argument 1 from 'v8::Isolate*' to 'const v8::HandleScope&'
/usr/include/v8.h:438:3: note: v8::HandleScope::HandleScope()
/usr/include/v8.h:438:3: note:   candidate expects 0 arguments, 1 provided
/home/stesie/Projekte/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/home/stesie/Projekte/v8js/v8js.cc:902:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/home/stesie/Projekte/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/home/stesie/Projekte/v8js/v8js.cc:915:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/home/stesie/Projekte/v8js/v8js.cc: At global scope:
/home/stesie/Projekte/v8js/v8js.cc:1051:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/home/stesie/Projekte/v8js/v8js.cc:1065:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/home/stesie/Projekte/v8js/v8js.cc:1068:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/home/stesie/Projekte/v8js/v8js.cc: In function 'void php_v8js_write_property(zval*, zval*, zval*, const zend_literal*)':
/home/stesie/Projekte/v8js/v8js.cc:1088:41: error: no matching function for call to 'v8::HandleScope::HandleScope(v8::Isolate*&)'
/home/stesie/Projekte/v8js/v8js.cc:1088:41: note: candidates are:
In file included from /home/stesie/Projekte/v8js/php_v8js_macros.h:30:0,
                 from /home/stesie/Projekte/v8js/v8js.cc:28:
/usr/include/v8.h:463:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
/usr/include/v8.h:463:3: note:   no known conversion for argument 1 from 'v8::Isolate*' to 'const v8::HandleScope&'
/usr/include/v8.h:438:3: note: v8::HandleScope::HandleScope()
/usr/include/v8.h:438:3: note:   candidate expects 0 arguments, 1 provided
/home/stesie/Projekte/v8js/v8js.cc: In function 'void php_v8js_unset_property(zval*, zval*, const zend_literal*)':
/home/stesie/Projekte/v8js/v8js.cc:1105:41: error: no matching function for call to 'v8::HandleScope::HandleScope(v8::Isolate*&)'
/home/stesie/Projekte/v8js/v8js.cc:1105:41: note: candidates are:
In file included from /home/stesie/Projekte/v8js/php_v8js_macros.h:30:0,
                 from /home/stesie/Projekte/v8js/v8js.cc:28:
/usr/include/v8.h:463:3: note: v8::HandleScope::HandleScope(const v8::HandleScope&)
/usr/include/v8.h:463:3: note:   no known conversion for argument 1 from 'v8::Isolate*' to 'const v8::HandleScope&'
/usr/include/v8.h:438:3: note: v8::HandleScope::HandleScope()
/usr/include/v8.h:438:3: note:   candidate expects 0 arguments, 1 provided
make: *** [v8js.lo] Error 1

... which seems to be caused by commit 8d8c671, which passes v8::Isolate to v8::HandleScope::HandleScope

From v8's ChangeLog:

2013-03-15: Version 3.17.11

        Added a version of the v8::HandleScope constructor with an v8::Isolate
        parameter and made AdjustAmountOfExternalAllocatedMemory an instance
        method of v8::Isolate.
        (issue 2487)

... hence I ask you to please update the README to reflect the requirement.

cheers
stesie

v8js Not compiling

Hello,

I built v8 with g++4.8 (accidentally), and it surprisingly went fine.

But when I tried to compile v8js, g++ displayed one of those world-famous wall of errors :

/bin/bash /home/talanor/projects/v8js/libtool --mode=compile g++ -std=c++11 -I. -I/home/talanor/projects/v8js -DPHP_ATOM_INC -I/home/talanor/projects/v8js/include -I/home/talanor/projects/v8js/main -I/home/talanor/projects/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /home/talanor/projects/v8js/v8js.cc -o v8js.lo 
libtool: compile:  g++ -std=c++11 -I. -I/home/talanor/projects/v8js -DPHP_ATOM_INC -I/home/talanor/projects/v8js/include -I/home/talanor/projects/v8js/main -I/home/talanor/projects/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/talanor/projects/v8js/v8js.cc  -fPIC -DPIC -o .libs/v8js.o
In file included from /usr/include/php5/main/php_ini.h:24:0,
                 from /usr/include/php5/main/fopen_wrappers.h:26,
                 from /usr/include/php5/main/php.h:398,
                 from /home/talanor/projects/v8js/php_v8js_macros.h:24,
                 from /home/talanor/projects/v8js/v8js.cc:24:
/usr/include/php5/Zend/zend_ini.h:115:97: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define ZEND_INI_END()  { 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, NULL } };
                                                                                                 ^
/home/talanor/projects/v8js/v8js.cc:78:1: note: in expansion of macro 'ZEND_INI_END'
 ZEND_INI_END()
 ^
/usr/include/php5/Zend/zend_ini.h:115:97: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define ZEND_INI_END()  { 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, NULL } };
                                                                                                 ^
/home/talanor/projects/v8js/v8js.cc:78:1: note: in expansion of macro 'ZEND_INI_END'
 ZEND_INI_END()
 ^
/usr/include/php5/Zend/zend_ini.h:115:97: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define ZEND_INI_END()  { 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, NULL } };
                                                                                                 ^
/home/talanor/projects/v8js/v8js.cc:78:1: note: in expansion of macro 'ZEND_INI_END'
 ZEND_INI_END()
 ^
/home/talanor/projects/v8js/v8js.cc: In function 'void zim_V8Js___construct(int, zval*, zval**, zval*, int)':
/home/talanor/projects/v8js/v8js.cc:917:65: error: no matching function for call to 'v8::Object::Set(v8::Local<v8::String>&, v8::Local<v8::Object>&, v8::PropertyAttribute)'
  V8JS_GLOBAL(isolate)->Set(object_name_js, php_obj, v8::ReadOnly);
                                                                 ^
/home/talanor/projects/v8js/v8js.cc:917:65: note: candidates are:
In file included from /usr/include/v8-debug.h:8:0,
                 from /home/talanor/projects/v8js/v8js.cc:22:
/usr/include/v8.h:2105:8: note: bool v8::Object::Set(v8::Handle<v8::Value>, v8::Handle<v8::Value>)
   bool Set(Handle<Value> key, Handle<Value> value);
        ^
/usr/include/v8.h:2105:8: note:   candidate expects 2 arguments, 3 provided
/usr/include/v8.h:2107:8: note: bool v8::Object::Set(uint32_t, v8::Handle<v8::Value>)
   bool Set(uint32_t index, Handle<Value> value);
        ^
/usr/include/v8.h:2107:8: note:   candidate expects 2 arguments, 3 provided
In file included from /usr/include/php5/main/php.h:35:0,
                 from /home/talanor/projects/v8js/php_v8js_macros.h:24,
                 from /home/talanor/projects/v8js/v8js.cc:24:
/home/talanor/projects/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/usr/include/php5/Zend/zend.h:615:57: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define zend_bailout()  _zend_bailout(__FILE__, __LINE__)
                                                         ^
/home/talanor/projects/v8js/v8js.cc:1342:4: note: in expansion of macro 'zend_bailout'
    zend_bailout();
    ^
/home/talanor/projects/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/usr/include/php5/Zend/zend.h:615:57: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define zend_bailout()  _zend_bailout(__FILE__, __LINE__)
                                                         ^
/home/talanor/projects/v8js/v8js.cc:1355:4: note: in expansion of macro 'zend_bailout'
    zend_bailout();
    ^
In file included from /usr/include/php5/main/php.h:39:0,
                 from /home/talanor/projects/v8js/php_v8js_macros.h:24,
                 from /home/talanor/projects/v8js/v8js.cc:24:
/home/talanor/projects/v8js/v8js.cc: At global scope:
/usr/include/php5/Zend/zend_API.h:111:30: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
 #define ZEND_END_ARG_INFO()  };
                              ^
/home/talanor/projects/v8js/v8js.cc:1506:1: note: in expansion of macro 'ZEND_END_ARG_INFO'
 ZEND_END_ARG_INFO()
 ^
/usr/include/php5/Zend/zend_API.h:111:30: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
 #define ZEND_END_ARG_INFO()  };
                              ^
/home/talanor/projects/v8js/v8js.cc:1520:1: note: in expansion of macro 'ZEND_END_ARG_INFO'
 ZEND_END_ARG_INFO()
 ^
/usr/include/php5/Zend/zend_API.h:111:30: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
 #define ZEND_END_ARG_INFO()  };
                              ^
/home/talanor/projects/v8js/v8js.cc:1523:1: note: in expansion of macro 'ZEND_END_ARG_INFO'
 ZEND_END_ARG_INFO()
 ^
make: *** [v8js.lo] Error 1

when searching for the error on Google, I found a link to #19 but none of the solution I found there worked.

I just stumbled across #84 which looks very much like it, but I am already building all this on bash.

Oh and if that can help : Ubuntu 14.04 LTS 64b

Doesn't compile

Hi,

v8js doesn't compile on my system. I use gcc 4.6.3 and get the following error:

$ make
/bin/bash /tmp/v8js/libtool --mode=compile g++ -std=c++0x -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/v8js/v8js.cc -o v8js.lo 
libtool: compile:  g++ -std=c++0x -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/v8js/v8js.cc  -fPIC -DPIC -o .libs/v8js.o
/tmp/v8js/v8js.cc:61:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function 'int php_v8js_v8_call_method(const char*, int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:421:23: error: 'GetCurrent' is not a member of 'v8::Context'
/tmp/v8js/v8js.cc: In function 'void zim_V8Object___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:516:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function 'void zim_V8Function___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:526:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function 'void php_v8js_free_storage(void*)':
/tmp/v8js/v8js.cc:569:58: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Isolate*&, v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:569:58: note: candidates are:
/usr/include/v8.h:5081:24: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5081:24: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(v8::Context::Scope&&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/tmp/v8js/v8js.cc:572:3: error: 'GetCurrent' is not a member of 'v8::Context'
/tmp/v8js/v8js.cc: In function 'void zim_V8Js___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:782:23: error: no matching function for call to 'v8::Isolate::SetData(php_v8js_ctx*&)'
/tmp/v8js/v8js.cc:782:23: note: candidate is:
/usr/include/v8.h:6357:6: note: void v8::Isolate::SetData(uint32_t, void*)
/usr/include/v8.h:6357:6: note:   candidate expects 2 arguments, 1 provided
/tmp/v8js/v8js.cc:868:2: error: 'GetCurrent' is not a member of 'v8::Context'
/tmp/v8js/v8js.cc: In function 'void zim_V8Js_executeString(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:1011:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Isolate*&, v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1011:2: note: candidates are:
/usr/include/v8.h:5081:24: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5081:24: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(v8::Context::Scope&&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/tmp/v8js/v8js.cc:1035:2: error: 'GetCurrent' is not a member of 'v8::Context'
/tmp/v8js/v8js.cc: In function 'void zim_V8Js___destruct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:1131:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Isolate*&, v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1131:2: note: candidates are:
/usr/include/v8.h:5081:24: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5081:24: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(v8::Context::Scope&&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/tmp/v8js/v8js.cc: In function 'void zim_V8Js_startDebugAgent(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:1156:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Isolate*&, v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1156:2: note: candidates are:
/usr/include/v8.h:5081:24: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5081:24: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(v8::Context::Scope&&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/tmp/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/tmp/v8js/v8js.cc:1232:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/tmp/v8js/v8js.cc:1245:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function 'void php_v8js_write_property(zval*, zval*, zval*, const zend_literal*)':
/tmp/v8js/v8js.cc:1443:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Isolate*&, v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1443:2: note: candidates are:
/usr/include/v8.h:5081:24: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5081:24: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(v8::Context::Scope&&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/tmp/v8js/v8js.cc:1450:33: error: 'GetCurrent' is not a member of 'v8::Context'
/tmp/v8js/v8js.cc: In function 'void php_v8js_unset_property(zval*, zval*, const zend_literal*)':
/tmp/v8js/v8js.cc:1463:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Isolate*&, v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1463:2: note: candidates are:
/usr/include/v8.h:5081:24: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5081:24: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/usr/include/v8.h:5079:9: note: constexpr v8::Context::Scope::Scope(v8::Context::Scope&&)
/usr/include/v8.h:5079:9: note:   candidate expects 1 argument, 2 provided
/tmp/v8js/v8js.cc:1467:32: error: 'GetCurrent' is not a member of 'v8::Context'
make: *** [v8js.lo] Fehler 1

What am I doing wrong?
Thanks a lot

Urgent! This repo is publicly accessible!

This repository is publicly accessible. Pushing proprietary code to this repo could reveal trade secrets.

If this is intentional, please contact your lead so this repo can be whitelisted. Until that time, please refrain from pushing code to this repo.

Properties from Objects missing

As the following code shows there seems a few properties from the object missing. PHP returns '1'. V8 returns 'undefined'.

loadXML(''); $elements=$dom->getElementsByTagName('node'); echo $elements->length, "\n"; $v8=new V8Js(); $v8->dom=$dom; $v8->executeString($script); ?>

Fails to build against v8 since 3.24.10

V8Js fails to build against the V8 version released today

/var/lib/jenkins/workspace/v8js/v8js.cc:61:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js/v8js.cc: In function 'void zim_V8Object___construct(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js/v8js.cc:516:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js/v8js.cc: In function 'void zim_V8Function___construct(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js/v8js.cc:526:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js/v8js.cc: In function 'void zim_V8Js___construct(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js/v8js.cc:821:66: error: no matching function for call to 'v8::FunctionTemplate::New()'
/var/lib/jenkins/workspace/v8js/v8js.cc:821:66: note: candidate is:
In file included from /var/lib/jenkins/workspace/v8js/v8-latest//include/v8-debug.h:31:0,
                 from /var/lib/jenkins/workspace/v8js/v8js.cc:22:
/var/lib/jenkins/workspace/v8js/v8-latest//include/v8.h:3341:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)
/var/lib/jenkins/workspace/v8js/v8-latest//include/v8.h:3341:34: note:   candidate expects 5 arguments, 0 provided
/var/lib/jenkins/workspace/v8js/v8js.cc:848:72: error: no matching function for call to 'v8::FunctionTemplate::New()'
/var/lib/jenkins/workspace/v8js/v8js.cc:848:72: note: candidate is:
In file included from /var/lib/jenkins/workspace/v8js/v8-latest//include/v8-debug.h:31:0,
                 from /var/lib/jenkins/workspace/v8js/v8js.cc:22:
/var/lib/jenkins/workspace/v8js/v8-latest//include/v8.h:3341:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)
/var/lib/jenkins/workspace/v8js/v8-latest//include/v8.h:3341:34: note:   candidate expects 5 arguments, 0 provided
/var/lib/jenkins/workspace/v8js/v8js.cc: In function 'void zim_V8Js_executeString(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js/v8js.cc:1041:2: error: invalid conversion from 'long int' to 'v8::Isolate*' [-fpermissive]
In file included from /var/lib/jenkins/workspace/v8js/v8-latest//include/v8-debug.h:31:0,
                 from /var/lib/jenkins/workspace/v8js/v8js.cc:22:
/var/lib/jenkins/workspace/v8js/v8-latest//include/v8.h:1977:25: error:   initializing argument 1 of 'static v8::Local<v8::Integer> v8::Integer::New(v8::Isolate*, int32_t)' [-fpermissive]
/var/lib/jenkins/workspace/v8js/v8js.cc:1041:2: error: invalid conversion from 'v8::Isolate*' to 'int32_t {aka int}' [-fpermissive]
In file included from /var/lib/jenkins/workspace/v8js/v8-latest//include/v8-debug.h:31:0,
                 from /var/lib/jenkins/workspace/v8js/v8js.cc:22:
/var/lib/jenkins/workspace/v8js/v8-latest//include/v8.h:1977:25: error:   initializing argument 2 of 'static v8::Local<v8::Integer> v8::Integer::New(v8::Isolate*, int32_t)' [-fpermissive]
/var/lib/jenkins/workspace/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/var/lib/jenkins/workspace/v8js/v8js.cc:1238:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/var/lib/jenkins/workspace/v8js/v8js.cc:1251:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js/v8js.cc: At global scope:
/var/lib/jenkins/workspace/v8js/v8js.cc:1398:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/var/lib/jenkins/workspace/v8js/v8js.cc:1412:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/var/lib/jenkins/workspace/v8js/v8js.cc:1415:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
make: *** [v8js.lo] Error 1

for details, see Jenkins log: http://jenkins.brokenpipe.de/job/v8js-with-v8-3.24.10/

Error - Memory Limit / Time limit

Hello,

My name is Fernando and I installed the extension v8js in my PHP 5.3.10-1ubuntu3.6
But when i try to set the memory limit e time limit it doesn't work.
I'm using the following scripts that i found in the repository at github for test:

v8js / tests / memory_limit.phpt

v8js / tests / time_limit.phpt

This is the link of my phpinfo: http://198.199.111.114/teste03.php

For Example:

executeString($JS, 'basic.js', V8Js::FLAG_NONE, 0, 10000000)); } catch (V8JsMemoryLimitException $e) { var_dump($e); } ?>

Result: Null

executeString($JS, 'basic.js', V8Js::FLAG_NONE)); } catch (V8JsMemoryLimitException $e) { var_dump($e); } ?>

Result: endint(3)

Note: I switched var_dump($v8->executeString($JS, 'basic.js', V8Js::FLAG_NONE, 0, 10000000)); to var_dump($v8->executeString($JS, 'basic.js', V8Js::FLAG_NONE));

I downloaded the files from repository on github and i tried to compile and install (phpize,./configure, make, make install) v 0.1.4.
But when i execute the command make, I get the following error:
make: *** [v8js.lo] Error 1

I also tried to download from pecl (http://pecl.php.net/get/v8js-0.1.3.tgz) and compile/install and everything worked ok.

This is the link of file with the output of the command make:
http://pastebin.com/qwxKmdyR

Short Security Question

I am looking at your v8 engine for PHP and it looks very promising, however I am not able to find any more details about your quote:

“The extension allows you to execute Javascript code in a secure sandbox from PHP. The executed code can be restricted using a time limit and/or memory limit. This provides the possibility to execute untrusted code with confidence.”.

I am mainly interested how secure this environment is. For example is it possible for the JS to include external libraries which in turn may be able to access the disk or the network? How safe would I be to expose a scripting interface in my a control panel, what is the worst types of scripts that can be ran from this. Are there any other methods of controlling the security level?

Regards Jonathan

Travis config doesn't check for test suite errors

The Travis configuration doesn't seem to check for test suite errors correctly.

See build output of https://travis-ci.org/stesie/v8js/builds/12743962 (I'm currently preparing another pull request, which broke the PHP 5.3 build however)

[...]
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test V8::executeString() : Initialized properties on derived class [tests/derived_class_properties_init.phpt]
=====================================================================
make[1]: Leaving directory `/home/travis/build/stesie/v8js'
The command "make -f Makefile.travis test" exited with 0.
Done. Your build exited with 0.

... and the build is marked with state "passed".

Fatal error inside PHP callback from JS results in segfault on cleanup

A fatal error in PHP called from JS results in a segmentation fault while cleaning up.

$v8 = new V8Js();
$v8->phpFatalError = function () {
  $foo = NULL;
  $foo->bar();
};
$v8->executeString('PHP.phpFatalError();', 'crash.js');

Output:

PHP Fatal error:  Call to a member function bar() on a non-object in fatal-error.phpt on line 5

Fatal error: Call to a member function bar() on a non-object in fatal-error.phpt on line 5
Segmentation fault (core dumped)

Stack trace:

(gdb) bt
#0  0x00007fffeeb80ae1 in v8::internal::ExitFrame::Iterate(v8::internal::ObjectVisitor*) const () from /var/v8/lib/libv8.so
#1  0x00007fffeec605b9 in v8::internal::Isolate::Iterate(v8::internal::ObjectVisitor*, v8::internal::ThreadLocalTop*) () from /var/v8/lib/libv8.so
#2  0x00007fffeebadec9 in v8::internal::Heap::IterateStrongRoots(v8::internal::ObjectVisitor*, v8::internal::VisitMode) () from /var/v8/lib/libv8.so
#3  0x00007fffeec46528 in v8::internal::IncrementalMarking::StartMarking(v8::internal::IncrementalMarking::CompactionFlag) () from /var/v8/lib/libv8.so
#4  0x00007fffeec46831 in v8::internal::IncrementalMarking::Start(v8::internal::IncrementalMarking::CompactionFlag) () from /var/v8/lib/libv8.so
#5  0x00007fffeebbb25e in v8::internal::Heap::IdleNotification(int) () from /var/v8/lib/libv8.so
#6  0x00007fffef291462 in php_v8js_free_storage (object=0x7ffff7fc7680) at /usr/share/crasman/v8js/v8js.cc:624
#7  0x0000000000800f08 in zend_objects_store_free_object_storage (objects=0x10407e0) at /usr/src/debug/php-5.4.26/Zend/zend_objects_API.c:97
#8  0x00000000007ccfb3 in shutdown_executor () at /usr/src/debug/php-5.4.26/Zend/zend_execute_API.c:295
#9  0x00000000007d9e72 in zend_deactivate () at /usr/src/debug/php-5.4.26/Zend/zend.c:934
#10 0x000000000077ce2c in php_request_shutdown (dummy=<value optimized out>) at /usr/src/debug/php-5.4.26/main/main.c:1808
#11 0x0000000000883737 in do_cli (argc=2, argv=0x7fffffffe588) at /usr/src/debug/php-5.4.26/sapi/cli/php_cli.c:1172
#12 0x0000000000884af8 in main (argc=2, argv=0x7fffffffe588) at /usr/src/debug/php-5.4.26/sapi/cli/php_cli.c:1365

I tried some workarounds to this, like removing the locking before calling IdleNotification in php_v8js_free_storage but that results in memory leaks. Adding v8::TerminateExecution before IdleNotification doesn't help either. I also tried moving the whole script->Run() into a new thread, but basically the code never returns from it.

Proposal: remove ad-hoc sync of V8Js object?

The V8Js object is treated as a special case, and has its own handlers both on the V8 and the PHP sides. Now that V8 wrapping of PHP objects works much better (since f6a6d1e) I think it makes sense to remove a bunch of this code and just expose the V8Js object using the standard zval_to_v8js wrappers.

However, there are some methods of the V8Js object which we don't want to directly expose to JS (like the executeString method), so I'm actually proposing that the V8Js object reference a separate "blank" object for user properties. Adding/removing/querying properties from the PHP side would be proxied over to the user properties object. The V8 wrapper for V8Js would be the standard zval_to_v8js of the user properies object.

I think that would end up removing a bunch of now-redundant code (like all of v8js_variables.cc) and simplifying the codebase (like php_v8js_write_property etc).

Not compiling, again )

Hi all,
pulled latest v8 from github, installed, copied all headers and libs, make fails with the following output:

/bin/bash /tmp/v8js/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/v8js/v8js.cc -o v8js.lo 
libtool: compile:  g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/v8js/v8js.cc  -fPIC -DPIC -o .libs/v8js.o
/tmp/v8js/v8js.cc:80:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc:80:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc:80:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h: In function 'zval* php_v8js_v8_read_property(zval*, zval*, int, const zend_literal*)':
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:134:49: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:134:76: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:136:43: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h: In function 'void php_v8js_v8_write_property(zval*, zval*, zval*, const zend_literal*)':
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:167:16: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:167:43: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:168:13: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h: In function 'void php_v8js_v8_unset_property(zval*, zval*, const zend_literal*)':
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:177:16: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:177:43: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:178:13: error: within this context
/tmp/v8js/v8js.cc: In function 'HashTable* php_v8js_v8_get_properties(zval*)':
/tmp/v8js/v8js.cc:234:62: warning: 'static v8::Persistent<v8::Context> v8::Context::New(v8::ExtensionConfiguration*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Value>)' is deprecated (declared at /usr/include/v8.h:4925) [-Wdeprecated-declarations]
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:751:3: error: 'v8::Persistent<T>::Persistent(const v8::Persistent<T>&) [with T = v8::Context; v8::Persistent<T> = v8::Persistent<v8::Context>]' is private
/tmp/v8js/v8js.cc:234:62: error: within this context
/tmp/v8js/v8js.cc:235:44: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:235:44: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5046:5: note: v8::Context::Scope::Scope(v8::Isolate*, v8::Persistent<v8::Context>&)
/usr/include/v8.h:5046:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/v8.h:5042:14: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5042:14: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'v8::Handle<v8::Context>'
/usr/include/v8.h:5040:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5040:9: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'const v8::Context::Scope&'
/tmp/v8js/v8js.cc:237:92: error: could not convert 'obj->php_v8js_object::v8obj' from 'v8::Persistent<v8::Value>' to 'v8::Handle<v8::Value>'
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h: In function 'zend_function* php_v8js_v8_get_method(zval**, char*, int, const zend_literal*)':
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:260:41: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:260:68: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:261:43: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h: In function 'int php_v8js_v8_call_method(const char*, int, zval*, zval**, zval*, int)':
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:298:42: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h: In function 'int php_v8js_v8_get_closure(zval*, zend_class_entry**, zend_function**, zval**)':
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Value]' is private
/tmp/v8js/v8js.cc:336:17: error: within this context
/tmp/v8js/v8js.cc: In function 'void php_v8js_create_v8(zval*, v8::Handle<v8::Value>, int, v8::Isolate*)':
/tmp/v8js/v8js.cc:394:49: error: no matching function for call to 'v8::Persistent<v8::Value>::New(v8::Handle<v8::Value>&)'
/tmp/v8js/v8js.cc:394:49: note: candidate is:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5585:4: note: static T* v8::Persistent<T>::New(v8::Isolate*, T*) [with T = v8::Value]
/usr/include/v8.h:5585:4: note:   candidate expects 2 arguments, 1 provided
/tmp/v8js/v8js.cc: In function 'void zim_V8Js___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:592:92: error: no matching function for call to 'v8::Persistent<v8::FunctionTemplate>::New(v8::Local<v8::FunctionTemplate>)'
/tmp/v8js/v8js.cc:592:92: note: candidate is:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5585:4: note: static T* v8::Persistent<T>::New(v8::Isolate*, T*) [with T = v8::FunctionTemplate]
/usr/include/v8.h:5585:4: note:   candidate expects 2 arguments, 1 provided
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::FunctionTemplate]' is private
/tmp/v8js/v8js.cc:593:20: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::FunctionTemplate]' is private
/tmp/v8js/v8js.cc:596:46: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::FunctionTemplate]' is private
/tmp/v8js/v8js.cc:599:67: error: within this context
/tmp/v8js/v8js.cc:599:87: warning: 'static v8::Persistent<v8::Context> v8::Context::New(v8::ExtensionConfiguration*, v8::Handle<v8::ObjectTemplate>, v8::Handle<v8::Value>)' is deprecated (declared at /usr/include/v8.h:4925) [-Wdeprecated-declarations]
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:753:3: error: 'v8::Persistent<T>& v8::Persistent<T>::operator=(const v8::Persistent<T>&) [with T = v8::Context; v8::Persistent<T> = v8::Persistent<v8::Context>]' is private
/tmp/v8js/v8js.cc:599:87: error: within this context
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:771:3: error: 'T* v8::Persistent<T>::operator->() const [with T = v8::Context]' is private
/tmp/v8js/v8js.cc:600:12: error: within this context
/tmp/v8js/v8js.cc:614:45: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:614:45: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5046:5: note: v8::Context::Scope::Scope(v8::Isolate*, v8::Persistent<v8::Context>&)
/usr/include/v8.h:5046:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/v8.h:5042:14: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5042:14: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'v8::Handle<v8::Context>'
/usr/include/v8.h:5040:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5040:9: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'const v8::Context::Scope&'
/tmp/v8js/v8js.cc:637:128: error: no matching function for call to 'v8::Persistent<v8::String>::New(v8::Local<v8::String>)'
/tmp/v8js/v8js.cc:637:128: note: candidate is:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5585:4: note: static T* v8::Persistent<T>::New(v8::Isolate*, T*) [with T = v8::String]
/usr/include/v8.h:5585:4: note:   candidate expects 2 arguments, 1 provided
/tmp/v8js/v8js.cc:640:93: error: no matching function for call to 'v8::Object::Set(v8::Persistent<v8::String>&, v8::Local<v8::Object>, v8::PropertyAttribute)'
/tmp/v8js/v8js.cc:640:93: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:2036:8: note: bool v8::Object::Set(v8::Handle<v8::Value>, v8::Handle<v8::Value>, v8::PropertyAttribute)
/usr/include/v8.h:2036:8: note:   no known conversion for argument 1 from 'v8::Persistent<v8::String>' to 'v8::Handle<v8::Value>'
/usr/include/v8.h:2040:8: note: bool v8::Object::Set(uint32_t, v8::Handle<v8::Value>)
/usr/include/v8.h:2040:8: note:   candidate expects 2 arguments, 3 provided
/tmp/v8js/v8js.cc: In function 'void php_v8js_timer_thread()':
/tmp/v8js/v8js.cc:706:14: warning: 'v8::Locker::Locker()' is deprecated (declared at /usr/include/v8.h:5173) [-Wdeprecated-declarations]
/tmp/v8js/v8js.cc: In function 'void zim_V8Js_executeString(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:754:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:754:2: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5046:5: note: v8::Context::Scope::Scope(v8::Isolate*, v8::Persistent<v8::Context>&)
/usr/include/v8.h:5046:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/v8.h:5042:14: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5042:14: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'v8::Handle<v8::Context>'
/usr/include/v8.h:5040:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5040:9: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'const v8::Context::Scope&'
/tmp/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/tmp/v8js/v8js.cc:905:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/tmp/v8js/v8js.cc:918:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/tmp/v8js/v8js.cc: At global scope:
/tmp/v8js/v8js.cc:1054:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/tmp/v8js/v8js.cc:1068:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/tmp/v8js/v8js.cc:1071:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/tmp/v8js/v8js.cc: In function 'void php_v8js_write_property(zval*, zval*, zval*, const zend_literal*)':
/tmp/v8js/v8js.cc:1089:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1089:2: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5046:5: note: v8::Context::Scope::Scope(v8::Isolate*, v8::Persistent<v8::Context>&)
/usr/include/v8.h:5046:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/v8.h:5042:14: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5042:14: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'v8::Handle<v8::Context>'
/usr/include/v8.h:5040:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5040:9: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'const v8::Context::Scope&'
/tmp/v8js/v8js.cc:1094:63: error: no matching function for call to 'v8::Object::Get(v8::Persistent<v8::String>&)'
/tmp/v8js/v8js.cc:1094:63: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:2054:16: note: v8::Local<v8::Value> v8::Object::Get(v8::Handle<v8::Value>)
/usr/include/v8.h:2054:16: note:   no known conversion for argument 1 from 'v8::Persistent<v8::String>' to 'v8::Handle<v8::Value>'
/usr/include/v8.h:2056:16: note: v8::Local<v8::Value> v8::Object::Get(uint32_t)
/usr/include/v8.h:2056:16: note:   no known conversion for argument 1 from 'v8::Persistent<v8::String>' to 'uint32_t {aka unsigned int}'
/tmp/v8js/v8js.cc: In function 'void php_v8js_unset_property(zval*, zval*, const zend_literal*)':
/tmp/v8js/v8js.cc:1106:2: error: no matching function for call to 'v8::Context::Scope::Scope(v8::Persistent<v8::Context>&)'
/tmp/v8js/v8js.cc:1106:2: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:5046:5: note: v8::Context::Scope::Scope(v8::Isolate*, v8::Persistent<v8::Context>&)
/usr/include/v8.h:5046:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/v8.h:5042:14: note: v8::Context::Scope::Scope(v8::Handle<v8::Context>)
/usr/include/v8.h:5042:14: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'v8::Handle<v8::Context>'
/usr/include/v8.h:5040:9: note: constexpr v8::Context::Scope::Scope(const v8::Context::Scope&)
/usr/include/v8.h:5040:9: note:   no known conversion for argument 1 from 'v8::Persistent<v8::Context>' to 'const v8::Context::Scope&'
/tmp/v8js/v8js.cc:1111:63: error: no matching function for call to 'v8::Object::Get(v8::Persistent<v8::String>&)'
/tmp/v8js/v8js.cc:1111:63: note: candidates are:
In file included from /tmp/v8js/php_v8js_macros.h:30:0,
                 from /tmp/v8js/v8js.cc:28:
/usr/include/v8.h:2054:16: note: v8::Local<v8::Value> v8::Object::Get(v8::Handle<v8::Value>)
/usr/include/v8.h:2054:16: note:   no known conversion for argument 1 from 'v8::Persistent<v8::String>' to 'v8::Handle<v8::Value>'
/usr/include/v8.h:2056:16: note: v8::Local<v8::Value> v8::Object::Get(uint32_t)
/usr/include/v8.h:2056:16: note:   no known conversion for argument 1 from 'v8::Persistent<v8::String>' to 'uint32_t {aka unsigned int}'```
any clue? )

Simulate/Emulate DOM?

I'm trying to set up a server-side LESS compiler using V8Js, but I can't load less.js because it initially attempts to interact with the DOM.

Once less.js is initialized, I can easily compile less using its built-in functions - but getting past that initialization process isn't possible without a DOM for less to interact with.

I found jsdom, but I'm at a loss to figure out how to load it in the V8Js environment as it uses require to load pieces of itself.

Fails build v8js

I'm getting error when try make php-v8js.
I'm using gcc version 4.8.1.
Versions of v8 library which I used to install: 3.20-3.24.
(Ubuntu 13.10, PHP 5.5.3-1)

Also I used gcc 4.7.3 but had same result. Install via pecl fails too.

What release and version of gcc I must use to install it correctly?

$ make

/bin/bash /tmp/v8js/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/v8js/v8js.cc -o v8js.lo 
libtool: compile:  g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/v8js/v8js.cc  -fPIC -DPIC -o .libs/v8js.o
In file included from /usr/include/php5/main/php_ini.h:24:0,
                 from /usr/include/php5/main/fopen_wrappers.h:26,
                 from /usr/include/php5/main/php.h:402,
                 from /tmp/v8js/php_v8js_macros.h:20,
                 from /tmp/v8js/v8js.cc:24:
/usr/include/php5/Zend/zend_ini.h:115:97: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define ZEND_INI_END()  { 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, NULL } };
                                                                                                 ^
/tmp/v8js/v8js.cc:61:1: note: in expansion of macro 'ZEND_INI_END'
 ZEND_INI_END()
 ^
/tmp/v8js/v8js.cc: In function 'void zim_V8Object___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:516:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   "Can't directly construct V8 objects!", 0 TSRMLS_CC);
                                                      ^
/tmp/v8js/v8js.cc: In function 'void zim_V8Function___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:526:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   "Can't directly construct V8 objects!", 0 TSRMLS_CC);
                                                      ^
/tmp/v8js/v8js.cc: In function 'void zim_V8Js___construct(int, zval*, zval**, zval*, int)':
/tmp/v8js/v8js.cc:821:66: error: no matching function for call to 'v8::FunctionTemplate::New()'
  v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New();
                                                                  ^
/tmp/v8js/v8js.cc:821:66: note: candidate is:
In file included from /usr/include/v8-debug.h:31:0,
                 from /tmp/v8js/v8js.cc:22:
/usr/include/v8.h:3341:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)
   static Local<FunctionTemplate> New(
                                  ^
/usr/include/v8.h:3341:34: note:   candidate expects 5 arguments, 0 provided
/tmp/v8js/v8js.cc:848:72: error: no matching function for call to 'v8::FunctionTemplate::New()'
  v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New();
                                                                        ^
/tmp/v8js/v8js.cc:848:72: note: candidate is:
In file included from /usr/include/v8-debug.h:31:0,
                 from /tmp/v8js/v8js.cc:22:
/usr/include/v8.h:3341:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)
   static Local<FunctionTemplate> New(
                                  ^
/usr/include/v8.h:3341:34: note:   candidate expects 5 arguments, 0 provided
In file included from /tmp/v8js/v8js.cc:24:0:
/tmp/v8js/v8js.cc: In function 'void zim_V8Js_executeString(int, zval*, zval**, zval*, int)':
/tmp/v8js/php_v8js_macros.h:50:50: error: invalid conversion from 'long int' to 'v8::Isolate*' [-fpermissive]
 #define V8JS_INT(v)   v8::Integer::New(v, isolate)
                                                  ^
/tmp/v8js/php_v8js_macros.h:119:110: note: in expansion of macro 'V8JS_INT'
 #define V8JS_GLOBAL_SET_FLAGS(isolate,flags) V8JS_GLOBAL(isolate)->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
                                                                                                              ^
/tmp/v8js/v8js.cc:1041:2: note: in expansion of macro 'V8JS_GLOBAL_SET_FLAGS'
  V8JS_GLOBAL_SET_FLAGS(isolate, flags);
  ^
In file included from /usr/include/v8-debug.h:31:0,
                 from /tmp/v8js/v8js.cc:22:
/usr/include/v8.h:1977:25: error:   initializing argument 1 of 'static v8::Local<v8::Integer> v8::Integer::New(v8::Isolate*, int32_t)' [-fpermissive]
   static Local<Integer> New(Isolate* isolate, int32_t value);
                         ^
In file included from /tmp/v8js/v8js.cc:24:0:
/tmp/v8js/php_v8js_macros.h:50:50: error: invalid conversion from 'v8::Isolate*' to 'int32_t {aka int}' [-fpermissive]
 #define V8JS_INT(v)   v8::Integer::New(v, isolate)
                                                  ^
/tmp/v8js/php_v8js_macros.h:119:110: note: in expansion of macro 'V8JS_INT'
 #define V8JS_GLOBAL_SET_FLAGS(isolate,flags) V8JS_GLOBAL(isolate)->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
                                                                                                              ^
/tmp/v8js/v8js.cc:1041:2: note: in expansion of macro 'V8JS_GLOBAL_SET_FLAGS'
  V8JS_GLOBAL_SET_FLAGS(isolate, flags);
  ^
In file included from /usr/include/v8-debug.h:31:0,
                 from /tmp/v8js/v8js.cc:22:
/usr/include/v8.h:1977:25: error:   initializing argument 2 of 'static v8::Local<v8::Integer> v8::Integer::New(v8::Isolate*, int32_t)' [-fpermissive]
   static Local<Integer> New(Isolate* isolate, int32_t value);
                         ^
In file included from /usr/include/php5/main/php.h:35:0,
                 from /tmp/v8js/php_v8js_macros.h:20,
                 from /tmp/v8js/v8js.cc:24:
/tmp/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/usr/include/php5/Zend/zend.h:615:57: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define zend_bailout()  _zend_bailout(__FILE__, __LINE__)
                                                         ^
/tmp/v8js/v8js.cc:1238:4: note: in expansion of macro 'zend_bailout'
    zend_bailout();
    ^
/tmp/v8js/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/usr/include/php5/Zend/zend.h:615:57: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
 #define zend_bailout()  _zend_bailout(__FILE__, __LINE__)
                                                         ^
/tmp/v8js/v8js.cc:1251:4: note: in expansion of macro 'zend_bailout'
    zend_bailout();
    ^
In file included from /usr/include/php5/main/php.h:39:0,
                 from /tmp/v8js/php_v8js_macros.h:20,
                 from /tmp/v8js/v8js.cc:24:
/tmp/v8js/v8js.cc: At global scope:
/usr/include/php5/Zend/zend_API.h:111:30: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
 #define ZEND_END_ARG_INFO()  };
                              ^
/tmp/v8js/v8js.cc:1398:1: note: in expansion of macro 'ZEND_END_ARG_INFO'
 ZEND_END_ARG_INFO()
 ^
/usr/include/php5/Zend/zend_API.h:111:30: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
 #define ZEND_END_ARG_INFO()  };
                              ^
/tmp/v8js/v8js.cc:1412:1: note: in expansion of macro 'ZEND_END_ARG_INFO'
 ZEND_END_ARG_INFO()
 ^
/usr/include/php5/Zend/zend_API.h:111:30: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
 #define ZEND_END_ARG_INFO()  };
                              ^
/tmp/v8js/v8js.cc:1415:1: note: in expansion of macro 'ZEND_END_ARG_INFO'
 ZEND_END_ARG_INFO()
 ^
make: *** [v8js.lo] Error 1

How to parse html page and get env variables?

I am trying to use php to retrieve a html page via curl

Is there a way to execute the whole html page & JS of the curl response via v8js so you can get access to the env variables? of the page?

Some functions doesn't work with default-parameters

Some functions doesn't work with default parameters (see result.fetchArray())

<?php

$script=<<<EOT
PHP.sql.exec('CREATE TABLE foo(bar STRING)');
PHP.sql.exec('INSERT INTO foo(bar) VALUES("test")');
var result=PHP.sql.query('SELECT bar FROM foo');
while(data=result.fetchArray()) {
    print(data.bar, "\\n");
}

EOT;

$dom=new DomDocument();
$sql=new SQLite3(':memory:');

$v8=new V8Js();
$v8->sql=$sql;
$v8->executeString($script);

?>

Memory leaks PHP5.5 apache mod_php

I am experiencing memory leaks using v8js with PHP 5.5 and mod_php.

<?php
$v = new V8Js;

With a simple php file that creates a V8Js instance, I see memory used by apache increasing on every request. I also see the thread count increasing every request.

Making 100 requests to this simple script takes the memory usage from 1.1MB to 234.5MB. I see the thread count go from 1 to 506 threads.

Crash with property declaration in class derived from V8Js class

The following code runs as expected in PHP 5.3.3 but crashes PHP 5.4.4

<?php

class V8Wrapper extends V8Js {
    public $testing;  // remove line to make it work :-)

    public function __construct() {
        parent::__construct();
        $this->testing = 23;
    }
}

$v8 = new V8Wrapper();
$v8->executeString("print('foo');");

Backtrace of crashed PHP 5.4.4 instance:

Program received signal SIGSEGV, Segmentation fault.
0x00000000006c3da1 in zend_std_write_property (object=0x7ffff7e67838, member=0x7ffff7e68a28, value=0x1ae791fcf187e3, key=0x7ffff7e68a28)
    at /tmp/buildd/php5-5.4.4/Zend/zend_object_handlers.c:527
527 /tmp/buildd/php5-5.4.4/Zend/zend_object_handlers.c: Datei oder Verzeichnis nicht gefunden.
(gdb) bt
#0  0x00000000006c3da1 in zend_std_write_property (object=0x7ffff7e67838, member=0x7ffff7e68a28, value=0x1ae791fcf187e3, key=0x7ffff7e68a28)
    at /tmp/buildd/php5-5.4.4/Zend/zend_object_handlers.c:527
#1  0x00007fffeedfdafd in php_v8js_write_property (object=0x7ffff7e65090, member=0x7ffff7e68a28, value=0x7ffff7e67838, key=0x7ffff7e68a28) at /home/sts/Projekte/v8js/v8js.cc:1182
#2  0x000000000071e3ef in zend_assign_to_object (retval=0x0, object_ptr=0xdb9720, property_name=0xdb94c0, value_type=1, value_op=0x0, Ts=0x0, opcode=7466804, key=0x7ffff7e68a28)
    at /tmp/buildd/php5-5.4.4/Zend/zend_execute.c:737
#3  0x000000000071ef34 in ZEND_ASSIGN_OBJ_SPEC_UNUSED_CONST_HANDLER (execute_data=0x7ffff7e32200) at /tmp/buildd/php5-5.4.4/Zend/zend_vm_execute.h:22253
#4  0x0000000000700927 in execute (op_array=0x7ffff7e67db0) at /tmp/buildd/php5-5.4.4/Zend/zend_vm_execute.h:410
#5  0x00000000006a076e in zend_execute_scripts (type=8, retval=0x7ffff7e65968, file_count=3) at /tmp/buildd/php5-5.4.4/Zend/zend.c:1279
#6  0x000000000063fc93 in php_execute_script (primary_file=0x7fffffff9f90) at /tmp/buildd/php5-5.4.4/main/main.c:2473
#7  0x0000000000749693 in do_cli (argc=0, argv=0x7fffffffe7d5) at /tmp/buildd/php5-5.4.4/sapi/cli/php_cli.c:988
#8  0x00000000004312aa in main (argc=32767, argv=0xdba210) at /tmp/buildd/php5-5.4.4/sapi/cli/php_cli.c:1361

If the public $testing; property declaration is removed from the code everything works well, even with PHP 5.4.4

I probably will have a go to fix this, but do we want to fix this, or do you consider it expected behaviour? (after all it shouldn't crash no matter what)

cheers
stesie

php_v8js_v8_has_property unimplemented.

Shouldn't be hard to write, but there's a // Not implemented yet comment in v8js.cc.

I ran into this while trying to use PHP's property_exists method on an object returned to PHP from JavaScript.

Calling JS function from PHP?

I'm using v8->executeString to evaluate some code like:

(function(exports) {
   // begin module code
   exports.hello = function() { return 'hello' };
   // end module code
   return exports;
})({})

That's a pretty standard wrapper for a CommonJS-style module definition. I get the exports object back in PHP land. I'd like to then call various (JavaScript) methods from it. But $exports->hello() gives me a V8 exception ("v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope"), and the other various ways I've tried to do this, like:

$v8->func = get_object_vars( $exports )['hello'];
$result = $v8->executeString("PHP.func()");

gives me complaints in JS land that func is "not a function" (it's a [object V8Function] apparently). What am I doing wrong?

unregistering extensions

Once an extension is loaded with registerExtension, is there a way to unregister an extension or overwrite it with new JS code? I was able to do it by restarting apache, but is there another way that it can be done that doesn't require restarting apache? Thanks for your help.

Memory / time limit

Hi,

I'm planning to use your library for triggers / data processing, and it would be nice to have time limiting (and probably memory limiting, which is not that important).

This can be passed to executeString as an array of options after $flags parameter. Also, I can try to pullrequest if you can point where to change, but my C knowledge is not that good )

v8js compile errors

I am new to v8js and trying it out today for the first time. I'm running CentOS 6.4 64-bit with PHP 5.5.4. I followed the instructions listed in README.md to compile the latest versions of both v8 and php-v8js, but when compiling php-v8js, I'm getting the below error. I just pasted the first few errors, but a list of them occurs. Can you please let me know what might be causing it? Please also let me know if I can supply more information. Thanks for your help.

/bin/sh /tmp/v8js/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O0 -c /tmp/v8js/v8js.cc -o v8js.lo
g++ -std=c++11 -I. -I/tmp/v8js -DPHP_ATOM_INC -I/tmp/v8js/include -I/tmp/v8js/main -I/tmp/v8js -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O0 -c /tmp/v8js/v8js.cc -fPIC -DPIC -o .libs/v8js.o
/tmp/v8js/v8js.cc:74:1: warning: deprecated conversion from string constant to âchar_â [-Wwrite-strings]
/tmp/v8js/v8js.cc:74:1: warning: deprecated conversion from string constant to âchar_â [-Wwrite-strings]
/tmp/v8js/v8js.cc:74:1: warning: deprecated conversion from string constant to âchar_â [-Wwrite-strings]
/tmp/v8js/v8js.cc: In function âzval_ php_v8js_v8_read_property(zval_, zval_, int, const zend_literal_)â:
/tmp/v8js/v8js.cc:119:49: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc:119:76: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc:121:43: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc: In function âvoid php_v8js_v8_write_property(zval_, zval_, zval_, const zend_literal_)â:
/tmp/v8js/v8js.cc:152:16: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc:152:43: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc:153:13: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc: In function âvoid php_v8js_v8_unset_property(zval_, zval_, const zend_literal_)â:
/tmp/v8js/v8js.cc:162:16: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc:162:43: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â
/tmp/v8js/v8js.cc:163:13: error: base operand of â->â has non-pointer type âv8::Persistent<v8::Value, v8::NonCopyablePersistentTraitsv8::Value >â

persisting v8 object with apc_store

Hello,

I'd need to persist the v8 object so that I do not need to instantiate
and process the javascript scripts from PHP during every http request. Is that
possible?

I have tried using apc_store to store in memory the v8 object but when I fetch
it from the cache then when I try to use it I get:

PHP Fatal error: V8 not initialized in

String with NULL-byte passback from JS to PHP fails

<?php

$v8js = new V8Js();

$foo = $v8js->executeString("String.fromCharCode(65)");
var_dump($foo);

$foo = $v8js->executeString("String.fromCharCode(0)");
var_dump($foo);

Since both JS and PHP can handle strings with NULL-bytes I would expect even the latter to return a string of one byte length, ... well but:

string(1) "A"
string(0) ""

Persisting V8 instance between requests in php-fpm

Hi!

Is it possible to persist V8 instance between requests in web server? I found old issue on this topic #4 and seems it was impossible back than. Do you have plans to implement it? I think it would be useful feature, like persistent connections in mysql extensions.

We leak variables assigned to the V8 global

The following code:

$v8 = new V8Js();
$v8->executeString("var foo='bar';");
$v8->executeString("print(foo)");

...prints bar -- that is, the variable foo is retained between invocations of executeString. Further, foo then leaks if it's a reference to a PHP object, for example:

class Bar { }
$v8 = new V8Js();
$v8->bar = new Bar;
$v8->executeString("var foo=PHP.bar;");

Somehow we're not cleaning up the v8 global object when the V8Js object is destroyed.

We should do that -- perhaps even doing that between executions of executeString, as I'm not sure that behavior in the first code example is not a bug. Maybe this is as easy as wrapping executeString's execution in a new v8 scope so it's not running in global scope? Perhaps we also want to define a globals object like node does which exposes the global scope if you want to share context between executeString calls.

v8js.so with static version of libv8

Is it possible to use a static build of the libv8 to build php-v8js. This would be very useful as the required libv8 version is not even included in recent linux distributions (like Ubuntu 14.04). Therefore a simple installation via pecl or similar is not possible.

Segfault on object construction in JS (on PHP object)

Hi again :-)

got another one, inspired by the function template thing ... the objects passed back to from PHP to JavaScript have a constructor attribute pointing to the constructor function (i.e. function template from before). If you call that one in JavaScript you get fresh extra objects, ... however if you call back to PHP everything crashes since v8js relies on the internal fields, which are not initialized however.

Example code, first showing use of constructor attribute in JavaScript, then with PHP & JavaScript in combination:

$v8 = new V8Js();

class Greeter {
    function sayHello($a) {
        echo "Hello $a\n";
    }   
}

$v8->greeter = new Greeter();
$v8->executeString('
    function JsGreeter() { };
    JsGreeter.prototype.sayHello = function(a) {
        print("Hello " + a + "\n");
    };

    jsGreeter = new JsGreeter();
    jsGreeter.sayHello("Paul");

    jsGreeterNg = new jsGreeter.constructor();
    jsGreeterNg.sayHello("George");

    // -----  now the same using v8Js  -----

    PHP.greeter.sayHello("John");       // prints "Hello John" as expected

    print(PHP.greeter);                 // prints "[object Greeter]" as expected
    print("\n");

    // What about the constructor function of greeter?
    print(PHP.greeter.constructor);
    // ... yields "function Greeter() { [native code] }"

    // ... super, so let me create more greeters
    var ngGreeter = new PHP.greeter.constructor();
    ngGreeter.sayHello("Ringo");        // well, segfaults
');

cheers,
stesie

Support for old v8 versions

Currently we require v8 version 3.22.3 or newer, however older ones aren't actively maintained by Google. I think it's a bit intransparent which versions are actively maintained, according to https://code.google.com/p/v8/wiki/Source usually the last two branches.
According to http://omahaproxy.appspot.com/ currently stable Google Chrome browser uses v8 version 3.27.34.17

So almost certainly there's no maintenance for 3.26.x and earlier and we currently have a whole lot of preprocessing macros to achieve compatibility with those rather old versions. Especially the V8JS_NEW, V8JS_INT, V8JS_UINT and V8JS_DATE ones are really ugly ... and could be dropped, if we require 3.27.0 or newer ..

I don't see any reason why to support older versions and would step up and remove that glue stuff.
Any objections? @preillyme @rosmo @cscott

(and after all, someone who needs a older v8 version could pick a slightly older v8js, i.e. current master)

Compiling v8js on windows

Hi, I'm trying to compile v8js for my php on a windows platform, but so far failed. I don't much experience of compiling from source, can a guide be created for compiling V8js on windows?

Feature suggestion: compile scripts

V8Js::executeString() now compiles and runs scripts each time it's called. It might be worth to add a V8Js::compileString() method which returns a resource for the compiled script and a V8Js::runScript() function to execute them.

Seg fault when using an object returned directly via a method

The following code sample is the minimum required to reproduce the problem. As you can see, the problem occurs via __get and via an existing method.

I'm testing with PHP-5.3.10 and libv8.so version 3.17.13.

<?php

class Service
{
    public function method()
    {
        print("method\n");
    }
}

class Container
{
    private $service = null;

    public function __get($name)
    {
        if ($name == 'crash') {
            return new Service;
        } else {
            $this->service = new Service;
            return $this->service;
        }
    }

    public function getService()
    {
        return new Service;
    }
}

$v8Js = new V8Js('PHP');
$v8Js->container = new Container;

$code = <<<EOT

var container = PHP.container;

// This works OK
//container.ok.method();

// These both cause seg fault
container.crash.method();
container.getService().method();

EOT;

$v8Js->executeString($code, 'test');

The seg fault happens during the zend_get_class_entry (via Z_OBJCE_P) call in the php_v8js_php_callback function (line 46 in v8js_convert.cc).

I have limited knowledge of Zend internals, but this looks like an object referencing issue. The pointer that is passed into Z_OBJCE_P is coming via the SetAlignedPointerInInternalField. Perhaps we need to explicitly add a reference to the object and use that in the SetAlignedPointerInInternalField call instead?

I'm willing to help fix this if anybody can provide any insights into why this might be happening.

Build unstable against v8 >= 3.25.2; broken >= 3.25.12

After fixing #83 the build is now broken for v8 version 3.25.12 and higher:

+ make
/bin/bash /var/lib/jenkins/workspace/v8js-with-v8-3.25.12/libtool --mode=compile g++ -std=c++11 -I. -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12 -DPHP_ATOM_INC -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/include -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/main -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8-3.25.12//include  -DHAVE_CONFIG_H  -g -O2   -c /var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc -o v8js.lo 
libtool: compile:  g++ -std=c++11 -I. -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12 -DPHP_ATOM_INC -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/include -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/main -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12 -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8-3.25.12//include -DHAVE_CONFIG_H -g -O2 -c /var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc  -fPIC -DPIC -o .libs/v8js.o
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:61:1: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc: In function 'void zim_V8Object___construct(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:516:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc: In function 'void zim_V8Function___construct(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:526:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc: In function 'void zim_V8Js_executeString(int, zval*, zval**, zval*, int)':
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:1033:33: error: 'New' is not a member of 'v8::Script'
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc: In function 'void php_v8js_persistent_zval_ctor(zval**)':
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:1239:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc: In function 'void php_v8js_persistent_zval_dtor(zval**)':
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:1252:4: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc: At global scope:
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:1399:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:1413:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
/var/lib/jenkins/workspace/v8js-with-v8-3.25.12/v8js.cc:1416:1: warning: narrowing conversion of '-1' from 'int' to 'zend_uint {aka unsigned int}' inside { } [-Wnarrowing]
make: *** [v8js.lo] Error 1
Build step 'Execute shell' marked build as failure
Recording test results
Sending e-mails to: [email protected]
Finished: FAILURE

However it is already unstable since 3.25.2, since they added some memory leak assertion wrt. weak refs, which "crashes" the module shutdown

#
# Fatal error in ../src/global-handles.cc, line 274
# CHECK(state() != NEAR_DEATH) failed
#

==== C stack trace ===============================

 1: v8::internal::GlobalHandles::PostGarbageCollectionProcessing(v8::internal::GarbageCollector, v8::internal::GCTracer*)
 2: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GCTracer*, v8::GCCallbackFlags)
 3: v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char const*, char const*, v8::GCCallbackFlags)
 4: v8::internal::Heap::CollectAllGarbage(int, char const*, v8::GCCallbackFlags)
 5: v8::internal::Heap::AdvanceIdleIncrementalMarking(long)
 6: v8::internal::Heap::IdleNotification(int)
 7: ??
 8: zend_objects_store_del_ref_by_handle_ex
 9: zend_objects_store_del_ref
10: _zval_ptr_dtor
11: ??
12: zend_hash_reverse_apply
13: ??
14: ??
15: php_request_shutdown
16: ??
17: ??
18: __libc_start_main
19: ??
Trace/breakpoint trap

PPA / Packages

Hi guys, for some time I've been playing with deb packaging and there's a question:

  • do you need a ppa / packaging?
  • what os do you use mostly (debian/ubuntu deb, rpm, or macos)?

Crash in zend_error

This only seems to happen in Apache (at least a simple test from command line triggering "Array to string conversion" did not crash):

#0  0x0000000000000005 in ?? ()
#1  0x00007fffecbfad7c in zend_error (type=8, format=0x7fffed0e382c "Array to string conversion") at /usr/src/debug/php-5.4.28/Zend/zend.c:1116
#2  0x00007fffecbfbcab in zend_make_printable_zval (expr=0x7ffff8d0ec98, expr_copy=0x7fffffffa770, use_copy=0x7fffffffa78c) at /usr/src/debug/php-5.4.28/Zend/zend.c:249
#3  0x00007fffecc5aa80 in ZEND_CAST_SPEC_VAR_HANDLER (execute_data=0x7ffff7ee6908) at /usr/src/debug/php-5.4.28/Zend/zend_vm_execute.h:11364
#4  0x00007fffecc64400 in execute (op_array=0x7fffd68e1a38) at /usr/src/debug/php-5.4.28/Zend/zend_vm_execute.h:410
#5  0x00007fffecbef449 in zend_call_function (fci=0x7fffffffa970, fci_cache=<value optimized out>) at /usr/src/debug/php-5.4.28/Zend/zend_execute_API.c:956
#6  0x00007fffecaf7467 in zif_call_user_func_array (ht=<value optimized out>, return_value=0x7ffff8bda0f8, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>, return_value_used=<value optimized out>)
    at /usr/src/debug/php-5.4.28/ext/standard/basic_functions.c:4754
#7  0x00007fffecc76adc in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>) at /usr/src/debug/php-5.4.28/Zend/zend_vm_execute.h:643
#8  0x00007fffecc64400 in execute (op_array=0x7ffff8ac2da8) at /usr/src/debug/php-5.4.28/Zend/zend_vm_execute.h:410
#9  0x00007fffecbef449 in zend_call_function (fci=0x7fffffffac90, fci_cache=<value optimized out>) at /usr/src/debug/php-5.4.28/Zend/zend_execute_API.c:956
#10 0x00007fffecbf0230 in call_user_function_ex (function_table=<value optimized out>, object_pp=<value optimized out>, function_name=<value optimized out>, retval_ptr_ptr=<value optimized out>,
    param_count=<value optimized out>, params=<value optimized out>, no_separation=1, symbol_table=0x0) at /usr/src/debug/php-5.4.28/Zend/zend_execute_API.c:748
#11 0x00007fffecc1c014 in zim_Closure___invoke (ht=1, return_value=0x7ffff8bce9f8, return_value_ptr=0x7fffffffb0a8, this_ptr=0x7ffff8ac1310, return_value_used=<value optimized out>)
    at /usr/src/debug/php-5.4.28/Zend/zend_closures.c:59
#12 0x00007fffecbef4fd in zend_call_function (fci=0x7fffffffaff0, fci_cache=<value optimized out>) at /usr/src/debug/php-5.4.28/Zend/zend_execute_API.c:978
#13 0x00007fffdc5685ac in php_v8js_call_php_func (value=0x7ffff8ac1310, ce=<value optimized out>, method_ptr=<value optimized out>, isolate=0x7ffff8b1f5a0, info=...)
    at /builddir/build/BUILD/v8js-0.1.6/v8js_convert.cc:176
#14 0x00007fffdbd87c44 in v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) () from /usr/lib64/libv8.so
#15 0x00007fffdbda63cc in ?? () from /usr/lib64/libv8.so

This started happening consistently right after the unwind patch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.