Skip to content

Fix build against V8 5.2 #234

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Minimum requirements
V8 is Google's open source Javascript engine.
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 implements ECMAScript as specified in ECMA-262, 5th edition.
This extension makes use of V8 isolates to ensure separation between multiple V8Js instances and uses the new isolate-based mechanism to throw exceptions, hence the need for 3.24.6 or above.

This extension requires V8 4.6.76 or higher.

V8 releases are published rather quickly and the V8 team usually provides security support
for the version line shipped with the Chrome browser (stable channel) and newer (only).
Expand Down
224 changes: 105 additions & 119 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -121,138 +121,124 @@ int main ()
set $ac_cv_v8_version
IFS=$ac_IFS
V8_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
if test "$V8_API_VERSION" -lt 3024006 ; then
AC_MSG_ERROR([libv8 must be version 3.24.6 or greater])
if test "$V8_API_VERSION" -lt 4006076 ; then
AC_MSG_ERROR([libv8 must be version 4.6.76 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

if test "$V8_API_VERSION" -ge 3029036 ; then
dnl building for v8 3.29.36 or later, which requires us to
dnl initialize and provide a platform; hence we need to
dnl link in libplatform to make our life easier.
PHP_ADD_INCLUDE($V8_DIR)
PHP_ADD_INCLUDE($V8_DIR)

case $host_os in
darwin* )
static_link_extra="libv8_libplatform.a libv8_libbase.a"
;;
* )
static_link_extra="libv8_libplatform.a"
;;
esac

LDFLAGS_libplatform=""
for static_link_extra_file in $static_link_extra; do
AC_MSG_CHECKING([for $static_link_extra_file])

for i in $PHP_V8JS $SEARCH_PATH ; do
if test -r $i/lib64/$static_link_extra_file; then
static_link_dir=$i/lib64
AC_MSG_RESULT(found in $i)
fi
if test -r $i/lib/$static_link_extra_file; then
static_link_dir=$i/lib
AC_MSG_RESULT(found in $i)
fi
done

if test -z "$static_link_dir"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
fi

LDFLAGS_libplatform="$LDFLAGS_libplatform $static_link_dir/$static_link_extra_file"
done
case $host_os in
darwin* )
static_link_extra="libv8_libplatform.a libv8_libbase.a"
;;
* )
static_link_extra="libv8_libplatform.a"
;;
esac

# modify flags for (possibly) succeeding V8 startup check
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
LIBS="$LIBS $LDFLAGS_libplatform"
fi
LDFLAGS_libplatform=""
for static_link_extra_file in $static_link_extra; do
AC_MSG_CHECKING([for $static_link_extra_file])

if test -r $V8_DIR/lib64/$static_link_extra_file; then
static_link_dir=$V8_DIR/lib64
AC_MSG_RESULT(found in $V8_DIR/lib64)
fi

if test -r $V8_DIR/lib/$static_link_extra_file; then
static_link_dir=$V8_DIR/lib
AC_MSG_RESULT(found in $V8_DIR/lib)
fi

if test -z "$static_link_dir"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
fi

LDFLAGS_libplatform="$LDFLAGS_libplatform $static_link_dir/$static_link_extra_file"
done

# modify flags for (possibly) succeeding V8 startup check
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
LIBS="$LIBS $LDFLAGS_libplatform"

dnl building for v8 4.4.10 or later, which requires us to
dnl provide startup data, if V8 wasn't compiled with snapshot=off.
AC_MSG_CHECKING([whether V8 requires startup data])
AC_TRY_RUN([
#include <v8.h>
#include <libplatform/libplatform.h>
#include <stdlib.h>
#include <string.h>

if test "$V8_API_VERSION" -ge 4004010 ; then
dnl building for v8 4.4.10 or later, which requires us to
dnl provide startup data, if V8 wasn't compiled with snapshot=off.
AC_MSG_CHECKING([whether V8 requires startup data])
AC_TRY_RUN([
#include <v8.h>
#include <libplatform/libplatform.h>
#include <stdlib.h>
#include <string.h>

#if PHP_V8_API_VERSION >= 4004010
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
public:
virtual void* Allocate(size_t length) {
void* data = AllocateUninitialized(length);
return data == NULL ? data : memset(data, 0, length);
}
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
virtual void Free(void* data, size_t) { free(data); }
virtual void* Allocate(size_t length) {
void* data = AllocateUninitialized(length);
return data == NULL ? data : memset(data, 0, length);
}
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
virtual void Free(void* data, size_t) { free(data); }
};
#endif

int main ()
{
v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(v8_platform);
v8::V8::Initialize();

#if PHP_V8_API_VERSION >= 4004044
static ArrayBufferAllocator array_buffer_allocator;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &array_buffer_allocator;

v8::Isolate::New(create_params);
#else /* PHP_V8_API_VERSION < 4004044 */
v8::Isolate::New();
#endif
return 0;
}
], [
AC_MSG_RESULT([no])
], [
AC_MSG_RESULT([yes])
AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])

SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"

AC_MSG_CHECKING([for natives_blob.bin])
SEARCH_FOR="natives_blob.bin"

for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
native_blob_found=1
fi
done

if test -z "$native_blob_found"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide V8 native blob as needed])
fi

AC_MSG_CHECKING([for snapshot_blob.bin])
SEARCH_FOR="snapshot_blob.bin"

for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
snapshot_blob_found=1
fi
done

if test -z "$snapshot_blob_found"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
fi
])
fi

int main ()
{
v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(v8_platform);
v8::V8::Initialize();

static ArrayBufferAllocator array_buffer_allocator;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &array_buffer_allocator;

v8::Isolate::New(create_params);
return 0;
}
], [
AC_MSG_RESULT([no])
], [
AC_MSG_RESULT([yes])
AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])

SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"

AC_MSG_CHECKING([for natives_blob.bin])
SEARCH_FOR="natives_blob.bin"

for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
native_blob_found=1
fi
done

if test -z "$native_blob_found"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide V8 native blob as needed])
fi

AC_MSG_CHECKING([for snapshot_blob.bin])
SEARCH_FOR="snapshot_blob.bin"

for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
snapshot_blob_found=1
fi
done

if test -z "$snapshot_blob_found"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
fi
])

AC_LANG_RESTORE
LIBS=$old_LIBS
Expand Down
5 changes: 0 additions & 5 deletions php_v8js_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ extern "C" {
/* V8Js Version */
#define PHP_V8JS_VERSION "0.6.2"

/* Hidden field name used to link JS wrappers with underlying PHP object */
#define PHPJS_OBJECT_KEY "phpjs::object"

/* Helper macros */
#define V8JS_GET_CLASS_NAME(var, obj) \
v8::String::Utf8Value var(obj->GetConstructorName());
Expand Down Expand Up @@ -167,9 +164,7 @@ struct _v8js_process_globals {
/* V8 command line flags */
char *v8_flags;

#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
v8::Platform *v8_platform;
#endif
};

extern struct _v8js_process_globals v8js_process_globals;
Expand Down
2 changes: 0 additions & 2 deletions v8js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@ static PHP_MSHUTDOWN_FUNCTION(v8js)

if(v8_initialized) {
v8::V8::Dispose();
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
v8::V8::ShutdownPlatform();
// @fixme call virtual destructor somehow
//delete v8js_process_globals.v8_platform;
#endif
}

if (v8js_process_globals.v8_flags) {
Expand Down
20 changes: 7 additions & 13 deletions v8js_array_access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
| Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| http://www.opensource.org/licenses/mit-license.php MIT License |
+----------------------------------------------------------------------+
Expand Down Expand Up @@ -73,8 +73,7 @@ void v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8:

V8JS_TSRMLS_FETCH();

v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(1));

zval *php_value = v8js_array_access_dispatch(object, "offsetGet", 1, index, NULL TSRMLS_CC);
v8::Local<v8::Value> ret_value = zval_to_v8js(php_value, isolate TSRMLS_CC);
Expand All @@ -92,8 +91,7 @@ void v8js_array_access_setter(uint32_t index, v8::Local<v8::Value> value,

V8JS_TSRMLS_FETCH();

v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(1));

zval *zvalue_ptr;
MAKE_STD_ZVAL(zvalue_ptr);
Expand Down Expand Up @@ -156,8 +154,7 @@ static void v8js_array_access_length(v8::Local<v8::String> property, const v8::P

V8JS_TSRMLS_FETCH();

v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(1));

int length = v8js_array_access_get_count_result(object TSRMLS_CC);
info.GetReturnValue().Set(V8JS_INT(length));
Expand All @@ -171,8 +168,7 @@ void v8js_array_access_deleter(uint32_t index, const v8::PropertyCallbackInfo<v8

V8JS_TSRMLS_FETCH();

v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(1));

zval *php_value = v8js_array_access_dispatch(object, "offsetUnset", 1, index, NULL TSRMLS_CC);
zval_ptr_dtor(&php_value);
Expand All @@ -188,8 +184,7 @@ void v8js_array_access_query(uint32_t index, const v8::PropertyCallbackInfo<v8::

V8JS_TSRMLS_FETCH();

v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(1));

/* If index is set, then return an integer encoding a v8::PropertyAttribute;
* otherwise we're expected to return an empty handle. */
Expand All @@ -207,8 +202,7 @@ void v8js_array_access_enumerator(const v8::PropertyCallbackInfo<v8::Array>& inf

V8JS_TSRMLS_FETCH();

v8::Local<v8::Value> php_object = self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY));
zval *object = reinterpret_cast<zval *>(v8::External::Cast(*php_object)->Value());
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(1));

int length = v8js_array_access_get_count_result(object TSRMLS_CC);
v8::Local<v8::Array> result = v8::Array::New(isolate, length);
Expand Down
Loading