Skip to content

Commit 450a7a1

Browse files
committed
Merge pull request #234 from stesie/fix-build-v8-5.2
Fix build against V8 5.2
2 parents 4fbdb7d + ec6c6d3 commit 450a7a1

11 files changed

+152
-259
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Minimum requirements
2020
V8 is Google's open source Javascript engine.
2121
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
2222
V8 implements ECMAScript as specified in ECMA-262, 5th edition.
23-
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.
23+
24+
This extension requires V8 4.6.76 or higher.
2425

2526
V8 releases are published rather quickly and the V8 team usually provides security support
2627
for the version line shipped with the Chrome browser (stable channel) and newer (only).

config.m4

Lines changed: 105 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -121,138 +121,124 @@ int main ()
121121
set $ac_cv_v8_version
122122
IFS=$ac_IFS
123123
V8_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
124-
if test "$V8_API_VERSION" -lt 3024006 ; then
125-
AC_MSG_ERROR([libv8 must be version 3.24.6 or greater])
124+
if test "$V8_API_VERSION" -lt 4006076 ; then
125+
AC_MSG_ERROR([libv8 must be version 4.6.76 or greater])
126126
fi
127127
AC_DEFINE_UNQUOTED([PHP_V8_API_VERSION], $V8_API_VERSION, [ ])
128128
AC_DEFINE_UNQUOTED([PHP_V8_VERSION], "$ac_cv_v8_version", [ ])
129129
else
130130
AC_MSG_ERROR([could not determine libv8 version])
131131
fi
132132

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

139-
case $host_os in
140-
darwin* )
141-
static_link_extra="libv8_libplatform.a libv8_libbase.a"
142-
;;
143-
* )
144-
static_link_extra="libv8_libplatform.a"
145-
;;
146-
esac
147-
148-
LDFLAGS_libplatform=""
149-
for static_link_extra_file in $static_link_extra; do
150-
AC_MSG_CHECKING([for $static_link_extra_file])
151-
152-
for i in $PHP_V8JS $SEARCH_PATH ; do
153-
if test -r $i/lib64/$static_link_extra_file; then
154-
static_link_dir=$i/lib64
155-
AC_MSG_RESULT(found in $i)
156-
fi
157-
if test -r $i/lib/$static_link_extra_file; then
158-
static_link_dir=$i/lib
159-
AC_MSG_RESULT(found in $i)
160-
fi
161-
done
162-
163-
if test -z "$static_link_dir"; then
164-
AC_MSG_RESULT([not found])
165-
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
166-
fi
167-
168-
LDFLAGS_libplatform="$LDFLAGS_libplatform $static_link_dir/$static_link_extra_file"
169-
done
135+
case $host_os in
136+
darwin* )
137+
static_link_extra="libv8_libplatform.a libv8_libbase.a"
138+
;;
139+
* )
140+
static_link_extra="libv8_libplatform.a"
141+
;;
142+
esac
170143

171-
# modify flags for (possibly) succeeding V8 startup check
172-
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
173-
LIBS="$LIBS $LDFLAGS_libplatform"
174-
fi
144+
LDFLAGS_libplatform=""
145+
for static_link_extra_file in $static_link_extra; do
146+
AC_MSG_CHECKING([for $static_link_extra_file])
147+
148+
if test -r $V8_DIR/lib64/$static_link_extra_file; then
149+
static_link_dir=$V8_DIR/lib64
150+
AC_MSG_RESULT(found in $V8_DIR/lib64)
151+
fi
152+
153+
if test -r $V8_DIR/lib/$static_link_extra_file; then
154+
static_link_dir=$V8_DIR/lib
155+
AC_MSG_RESULT(found in $V8_DIR/lib)
156+
fi
157+
158+
if test -z "$static_link_dir"; then
159+
AC_MSG_RESULT([not found])
160+
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
161+
fi
162+
163+
LDFLAGS_libplatform="$LDFLAGS_libplatform $static_link_dir/$static_link_extra_file"
164+
done
165+
166+
# modify flags for (possibly) succeeding V8 startup check
167+
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
168+
LIBS="$LIBS $LDFLAGS_libplatform"
169+
170+
dnl building for v8 4.4.10 or later, which requires us to
171+
dnl provide startup data, if V8 wasn't compiled with snapshot=off.
172+
AC_MSG_CHECKING([whether V8 requires startup data])
173+
AC_TRY_RUN([
174+
#include <v8.h>
175+
#include <libplatform/libplatform.h>
176+
#include <stdlib.h>
177+
#include <string.h>
175178
176-
if test "$V8_API_VERSION" -ge 4004010 ; then
177-
dnl building for v8 4.4.10 or later, which requires us to
178-
dnl provide startup data, if V8 wasn't compiled with snapshot=off.
179-
AC_MSG_CHECKING([whether V8 requires startup data])
180-
AC_TRY_RUN([
181-
#include <v8.h>
182-
#include <libplatform/libplatform.h>
183-
#include <stdlib.h>
184-
#include <string.h>
185-
186-
#if PHP_V8_API_VERSION >= 4004010
187179
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
188180
public:
189-
virtual void* Allocate(size_t length) {
190-
void* data = AllocateUninitialized(length);
191-
return data == NULL ? data : memset(data, 0, length);
192-
}
193-
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
194-
virtual void Free(void* data, size_t) { free(data); }
181+
virtual void* Allocate(size_t length) {
182+
void* data = AllocateUninitialized(length);
183+
return data == NULL ? data : memset(data, 0, length);
184+
}
185+
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
186+
virtual void Free(void* data, size_t) { free(data); }
195187
};
196-
#endif
197-
198-
int main ()
199-
{
200-
v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
201-
v8::V8::InitializePlatform(v8_platform);
202-
v8::V8::Initialize();
203-
204-
#if PHP_V8_API_VERSION >= 4004044
205-
static ArrayBufferAllocator array_buffer_allocator;
206-
v8::Isolate::CreateParams create_params;
207-
create_params.array_buffer_allocator = &array_buffer_allocator;
208-
209-
v8::Isolate::New(create_params);
210-
#else /* PHP_V8_API_VERSION < 4004044 */
211-
v8::Isolate::New();
212-
#endif
213-
return 0;
214-
}
215-
], [
216-
AC_MSG_RESULT([no])
217-
], [
218-
AC_MSG_RESULT([yes])
219-
AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
220-
221-
SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"
222-
223-
AC_MSG_CHECKING([for natives_blob.bin])
224-
SEARCH_FOR="natives_blob.bin"
225-
226-
for i in $SEARCH_PATH ; do
227-
if test -r $i/$SEARCH_FOR; then
228-
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
229-
AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
230-
native_blob_found=1
231-
fi
232-
done
233-
234-
if test -z "$native_blob_found"; then
235-
AC_MSG_RESULT([not found])
236-
AC_MSG_ERROR([Please provide V8 native blob as needed])
237-
fi
238-
239-
AC_MSG_CHECKING([for snapshot_blob.bin])
240-
SEARCH_FOR="snapshot_blob.bin"
241-
242-
for i in $SEARCH_PATH ; do
243-
if test -r $i/$SEARCH_FOR; then
244-
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
245-
AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
246-
snapshot_blob_found=1
247-
fi
248-
done
249-
250-
if test -z "$snapshot_blob_found"; then
251-
AC_MSG_RESULT([not found])
252-
AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
253-
fi
254-
])
255-
fi
188+
189+
int main ()
190+
{
191+
v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
192+
v8::V8::InitializePlatform(v8_platform);
193+
v8::V8::Initialize();
194+
195+
static ArrayBufferAllocator array_buffer_allocator;
196+
v8::Isolate::CreateParams create_params;
197+
create_params.array_buffer_allocator = &array_buffer_allocator;
198+
199+
v8::Isolate::New(create_params);
200+
return 0;
201+
}
202+
], [
203+
AC_MSG_RESULT([no])
204+
], [
205+
AC_MSG_RESULT([yes])
206+
AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
207+
208+
SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"
209+
210+
AC_MSG_CHECKING([for natives_blob.bin])
211+
SEARCH_FOR="natives_blob.bin"
212+
213+
for i in $SEARCH_PATH ; do
214+
if test -r $i/$SEARCH_FOR; then
215+
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
216+
AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
217+
native_blob_found=1
218+
fi
219+
done
220+
221+
if test -z "$native_blob_found"; then
222+
AC_MSG_RESULT([not found])
223+
AC_MSG_ERROR([Please provide V8 native blob as needed])
224+
fi
225+
226+
AC_MSG_CHECKING([for snapshot_blob.bin])
227+
SEARCH_FOR="snapshot_blob.bin"
228+
229+
for i in $SEARCH_PATH ; do
230+
if test -r $i/$SEARCH_FOR; then
231+
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
232+
AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
233+
snapshot_blob_found=1
234+
fi
235+
done
236+
237+
if test -z "$snapshot_blob_found"; then
238+
AC_MSG_RESULT([not found])
239+
AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
240+
fi
241+
])
256242

257243
AC_LANG_RESTORE
258244
LIBS=$old_LIBS

php_v8js_macros.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ extern "C" {
5555
/* V8Js Version */
5656
#define PHP_V8JS_VERSION "0.6.2"
5757

58-
/* Hidden field name used to link JS wrappers with underlying PHP object */
59-
#define PHPJS_OBJECT_KEY "phpjs::object"
60-
6158
/* Helper macros */
6259
#define V8JS_GET_CLASS_NAME(var, obj) \
6360
v8::String::Utf8Value var(obj->GetConstructorName());
@@ -167,9 +164,7 @@ struct _v8js_process_globals {
167164
/* V8 command line flags */
168165
char *v8_flags;
169166

170-
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
171167
v8::Platform *v8_platform;
172-
#endif
173168
};
174169

175170
extern struct _v8js_process_globals v8js_process_globals;

v8js.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,9 @@ static PHP_MSHUTDOWN_FUNCTION(v8js)
150150

151151
if(v8_initialized) {
152152
v8::V8::Dispose();
153-
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
154153
v8::V8::ShutdownPlatform();
155154
// @fixme call virtual destructor somehow
156155
//delete v8js_process_globals.v8_platform;
157-
#endif
158156
}
159157

160158
if (v8js_process_globals.v8_flags) {

v8js_array_access.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| PHP Version 5 |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 1997-2013 The PHP Group |
5+
| Copyright (c) 1997-2016 The PHP Group |
66
+----------------------------------------------------------------------+
77
| http://www.opensource.org/licenses/mit-license.php MIT License |
88
+----------------------------------------------------------------------+
@@ -73,8 +73,7 @@ void v8js_array_access_getter(uint32_t index, const v8::PropertyCallbackInfo<v8:
7373

7474
V8JS_TSRMLS_FETCH();
7575

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

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

9392
V8JS_TSRMLS_FETCH();
9493

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

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

157155
V8JS_TSRMLS_FETCH();
158156

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

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

172169
V8JS_TSRMLS_FETCH();
173170

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

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

189185
V8JS_TSRMLS_FETCH();
190186

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

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

208203
V8JS_TSRMLS_FETCH();
209204

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

213207
int length = v8js_array_access_get_count_result(object TSRMLS_CC);
214208
v8::Local<v8::Array> result = v8::Array::New(isolate, length);

0 commit comments

Comments
 (0)