0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-19 00:25:18 +00:00

Require V8 4.6.76 or higher

... and hence remove all #ifdef hell.  Those versions didn't have
security support by Google anyhow, and it helps to drastically
shrink the test matrix.
This commit is contained in:
Stefan Siegl 2016-05-11 16:50:37 +02:00
parent 1f54fac62d
commit 4fea8f4fb9
7 changed files with 96 additions and 177 deletions

View File

@ -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).

195
config.m4
View File

@ -121,8 +121,8 @@ 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", [ ])
@ -130,129 +130,116 @@ int main ()
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
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])
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
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
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
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"
fi
# modify flags for (possibly) succeeding V8 startup check
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
LIBS="$LIBS $LDFLAGS_libplatform"
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>
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();
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;
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])
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"
SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"
AC_MSG_CHECKING([for natives_blob.bin])
SEARCH_FOR="natives_blob.bin"
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
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
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"
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
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
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

View File

@ -167,9 +167,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;

View File

@ -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) {

View File

@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
| Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| http://www.opensource.org/licenses/mit-license.php MIT License |
+----------------------------------------------------------------------+
@ -71,7 +71,6 @@ struct v8js_jsext {
};
/* }}} */
#if PHP_V8_API_VERSION >= 4004010
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
public:
virtual void* Allocate(size_t length) {
@ -81,7 +80,6 @@ public:
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
virtual void Free(void* data, size_t) { free(data); }
};
#endif
static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
{
@ -207,11 +205,9 @@ static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
c->modules_stack.~vector();
c->modules_base.~vector();
#if PHP_V8_API_VERSION >= 4003007
if (c->zval_snapshot_blob) {
zval_ptr_dtor(&c->zval_snapshot_blob);
}
#endif
efree(object);
}
@ -367,13 +363,10 @@ static PHP_METHOD(V8Js, __construct)
c->pending_exception = NULL;
c->in_execution = 0;
#if PHP_V8_API_VERSION >= 4003007
new (&c->create_params) v8::Isolate::CreateParams();
#if PHP_V8_API_VERSION >= 4004044
static ArrayBufferAllocator array_buffer_allocator;
c->create_params.array_buffer_allocator = &array_buffer_allocator;
#endif
new (&c->snapshot_blob) v8::StartupData();
if (snapshot_blob) {
@ -390,10 +383,6 @@ static PHP_METHOD(V8Js, __construct)
}
c->isolate = v8::Isolate::New(c->create_params);
#else /* PHP_V8_API_VERSION < 4003007 */
c->isolate = v8::Isolate::New();
#endif
c->isolate->SetData(0, c);
c->time_limit = 0;
@ -1108,7 +1097,7 @@ static PHP_METHOD(V8Js, getExtensions)
}
/* }}} */
#if PHP_V8_API_VERSION >= 4003007
/* {{{ proto string|bool V8Js::createSnapshot(string embed_source)
*/
static PHP_METHOD(V8Js, createSnapshot)
@ -1139,7 +1128,6 @@ static PHP_METHOD(V8Js, createSnapshot)
delete[] snapshot_blob.data;
}
/* }}} */
#endif /* PHP_V8_API_VERSION >= 4003007 */
/* {{{ arginfo */
@ -1210,11 +1198,9 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
ZEND_END_ARG_INFO()
#if PHP_V8_API_VERSION >= 4003007
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_createsnapshot, 0, 0, 1)
ZEND_ARG_INFO(0, script)
ZEND_END_ARG_INFO()
#endif
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
ZEND_ARG_INFO(0, time_limit)
@ -1242,10 +1228,7 @@ const zend_function_entry v8js_methods[] = { /* {{{ */
PHP_ME(V8Js, setAverageObjectSize, arginfo_v8js_setaverageobjectsize, ZEND_ACC_PUBLIC)
PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
#if PHP_V8_API_VERSION >= 4003007
PHP_ME(V8Js, createSnapshot, arginfo_v8js_createsnapshot, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
#endif
{NULL, NULL, NULL}
};
/* }}} */
@ -1314,10 +1297,8 @@ PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
#if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
static ArrayBufferAllocator array_buffer_allocator;
v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
#endif
return SUCCESS;
} /* }}} */

View File

@ -70,11 +70,9 @@ struct v8js_ctx {
std::vector<struct _v8js_script *> script_objects;
char *tz;
#if PHP_V8_API_VERSION >= 4003007
v8::Isolate::CreateParams create_params;
zval *zval_snapshot_blob;
v8::StartupData snapshot_blob;
#endif
#ifdef ZTS
void ***zts_ctx;

View File

@ -25,7 +25,7 @@ extern "C" {
#include "zend_exceptions.h"
}
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
#if !defined(_WIN32)
#include <libplatform/libplatform.h>
#endif
@ -34,43 +34,6 @@ extern "C" {
#include "v8js_timer.h"
#include "v8js_exceptions.h"
#if defined(PHP_V8_USE_EXTERNAL_STARTUP_DATA) && PHP_V8_API_VERSION < 4006076
/* Old V8 version, requires startup data but has no
* (internal/API) means to let it be loaded. */
static v8::StartupData natives_;
static v8::StartupData snapshot_;
static void v8js_v8_load_startup_data(const char* blob_file,
v8::StartupData* startup_data,
void (*setter_fn)(v8::StartupData*)) {
startup_data->data = NULL;
startup_data->raw_size = 0;
if (!blob_file) {
return;
}
FILE* file = fopen(blob_file, "rb");
if (!file) {
return;
}
fseek(file, 0, SEEK_END);
startup_data->raw_size = static_cast<int>(ftell(file));
rewind(file);
startup_data->data = new char[startup_data->raw_size];
int read_size = static_cast<int>(fread(const_cast<char*>(startup_data->data),
1, startup_data->raw_size, file));
fclose(file);
if (startup_data->raw_size == read_size) {
(*setter_fn)(startup_data);
}
}
#endif
void v8js_v8_init(TSRMLS_D) /* {{{ */
{
/* Run only once; thread-local test first */
@ -93,21 +56,14 @@ void v8js_v8_init(TSRMLS_D) /* {{{ */
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
/* V8 doesn't work without startup data, load it. */
#if PHP_V8_API_VERSION >= 4006076
v8::V8::InitializeExternalStartupData(
PHP_V8_NATIVES_BLOB_PATH,
PHP_V8_SNAPSHOT_BLOB_PATH
);
#else
v8js_v8_load_startup_data(PHP_V8_NATIVES_BLOB_PATH, &natives_, v8::V8::SetNativesDataBlob);
v8js_v8_load_startup_data(PHP_V8_SNAPSHOT_BLOB_PATH, &snapshot_, v8::V8::SetSnapshotDataBlob);
#endif
#endif
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
v8js_process_globals.v8_platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(v8js_process_globals.v8_platform);
#endif
/* Set V8 command line flags (must be done before V8::Initialize()!) */
if (v8js_process_globals.v8_flags) {