Skip to content

Commit 48cb242

Browse files
committed
Merge branch 'remove-api-ifdef'
2 parents 4fbdb7d + d4d8ccc commit 48cb242

File tree

7 files changed

+110
-195
lines changed

7 files changed

+110
-195
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ struct _v8js_process_globals {
167167
/* V8 command line flags */
168168
char *v8_flags;
169169

170-
#if !defined(_WIN32) && PHP_V8_API_VERSION >= 3029036
171170
v8::Platform *v8_platform;
172-
#endif
173171
};
174172

175173
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_class.cc

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
+----------------------------------------------------------------------+
33
| PHP Version 5 |
44
+----------------------------------------------------------------------+
5-
| Copyright (c) 1997-2015 The PHP Group |
5+
| Copyright (c) 1997-2016 The PHP Group |
66
+----------------------------------------------------------------------+
77
| http://www.opensource.org/licenses/mit-license.php MIT License |
88
+----------------------------------------------------------------------+
@@ -71,7 +71,6 @@ struct v8js_jsext {
7171
};
7272
/* }}} */
7373

74-
#if PHP_V8_API_VERSION >= 4004010
7574
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
7675
public:
7776
virtual void* Allocate(size_t length) {
@@ -81,7 +80,6 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
8180
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
8281
virtual void Free(void* data, size_t) { free(data); }
8382
};
84-
#endif
8583

8684
static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
8785
{
@@ -207,11 +205,9 @@ static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
207205
c->modules_stack.~vector();
208206
c->modules_base.~vector();
209207

210-
#if PHP_V8_API_VERSION >= 4003007
211208
if (c->zval_snapshot_blob) {
212209
zval_ptr_dtor(&c->zval_snapshot_blob);
213210
}
214-
#endif
215211

216212
efree(object);
217213
}
@@ -367,13 +363,10 @@ static PHP_METHOD(V8Js, __construct)
367363
c->pending_exception = NULL;
368364
c->in_execution = 0;
369365

370-
#if PHP_V8_API_VERSION >= 4003007
371366
new (&c->create_params) v8::Isolate::CreateParams();
372367

373-
#if PHP_V8_API_VERSION >= 4004044
374368
static ArrayBufferAllocator array_buffer_allocator;
375369
c->create_params.array_buffer_allocator = &array_buffer_allocator;
376-
#endif
377370

378371
new (&c->snapshot_blob) v8::StartupData();
379372
if (snapshot_blob) {
@@ -390,10 +383,6 @@ static PHP_METHOD(V8Js, __construct)
390383
}
391384

392385
c->isolate = v8::Isolate::New(c->create_params);
393-
#else /* PHP_V8_API_VERSION < 4003007 */
394-
c->isolate = v8::Isolate::New();
395-
#endif
396-
397386
c->isolate->SetData(0, c);
398387

399388
c->time_limit = 0;
@@ -1108,7 +1097,7 @@ static PHP_METHOD(V8Js, getExtensions)
11081097
}
11091098
/* }}} */
11101099

1111-
#if PHP_V8_API_VERSION >= 4003007
1100+
11121101
/* {{{ proto string|bool V8Js::createSnapshot(string embed_source)
11131102
*/
11141103
static PHP_METHOD(V8Js, createSnapshot)
@@ -1139,7 +1128,6 @@ static PHP_METHOD(V8Js, createSnapshot)
11391128
delete[] snapshot_blob.data;
11401129
}
11411130
/* }}} */
1142-
#endif /* PHP_V8_API_VERSION >= 4003007 */
11431131

11441132

11451133
/* {{{ arginfo */
@@ -1210,11 +1198,9 @@ ZEND_END_ARG_INFO()
12101198
ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
12111199
ZEND_END_ARG_INFO()
12121200

1213-
#if PHP_V8_API_VERSION >= 4003007
12141201
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_createsnapshot, 0, 0, 1)
12151202
ZEND_ARG_INFO(0, script)
12161203
ZEND_END_ARG_INFO()
1217-
#endif
12181204

12191205
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
12201206
ZEND_ARG_INFO(0, time_limit)
@@ -1242,10 +1228,7 @@ const zend_function_entry v8js_methods[] = { /* {{{ */
12421228
PHP_ME(V8Js, setAverageObjectSize, arginfo_v8js_setaverageobjectsize, ZEND_ACC_PUBLIC)
12431229
PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12441230
PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1245-
1246-
#if PHP_V8_API_VERSION >= 4003007
12471231
PHP_ME(V8Js, createSnapshot, arginfo_v8js_createsnapshot, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1248-
#endif
12491232
{NULL, NULL, NULL}
12501233
};
12511234
/* }}} */
@@ -1314,11 +1297,6 @@ PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
13141297

13151298
le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
13161299

1317-
#if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
1318-
static ArrayBufferAllocator array_buffer_allocator;
1319-
v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
1320-
#endif
1321-
13221300
return SUCCESS;
13231301
} /* }}} */
13241302

0 commit comments

Comments
 (0)