Skip to content

Commit e9e90ba

Browse files
committed
Merge remote-tracking branch 'origin/master' into php7
Conflicts: config.w32 package.xml php_v8js_macros.h v8js.cc v8js_array_access.cc v8js_class.cc v8js_convert.cc v8js_exceptions.cc v8js_object_export.cc v8js_timer.cc v8js_v8.cc v8js_v8object_class.cc
2 parents 99c23fa + c34fc46 commit e9e90ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+586
-2080
lines changed

Makefile.frag

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,3 @@ endif
77
ifneq (,$(realpath $(EXTENSION_DIR)/pthreads.so))
88
PHP_TEST_SHARED_EXTENSIONS+=-d extension=$(EXTENSION_DIR)/pthreads.so
99
endif
10-
11-
testv8: all
12-
$(PHP_EXECUTABLE) -n -d extension_dir=./modules -d extension=v8js.so test.php
13-
14-
debugv8: all
15-
gdb --arg $(PHP_EXECUTABLE) -n -d extension_dir=./modules -d extension=v8js.so test.php
16-
17-
valgrindv8: all
18-
USE_ZEND_ALLOC=0 valgrind --leak-check=full --show-reachable=yes --track-origins=yes $(PHP_EXECUTABLE) -n -d extension_dir=./modules -d extension=v8js.so test.php 2> valgrind.dump
19-
20-

README.Linux.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ make native library=shared snapshot=on -j8
6363
sudo mkdir -p /usr/lib /usr/include
6464
sudo cp out/native/lib.target/lib*.so /usr/lib/
6565
sudo cp -R include/* /usr/include
66+
67+
# Install libv8_libplatform.a (V8 >= 5.2.51)
68+
echo -e "create /usr/lib/libv8_libplatform.a\naddlib out/native/obj.target/src/libv8_libplatform.a\nsave\nend" | sudo ar -M
69+
70+
# ... same for V8 < 5.2.51, libv8_libplatform.a is built in tools/gyp directory
6671
echo -e "create /usr/lib/libv8_libplatform.a\naddlib out/native/obj.target/tools/gyp/libv8_libplatform.a\nsave\nend" | sudo ar -M
6772
```
6873

69-
Then add `extension=v8js.so` to your php.ini file. If you have a separate configuration for CLI, add it there also.
70-
7174
* If you don't want to overwrite the system copy of v8, replace `/usr` in
7275
the above commands with some other path like `/opt/v8` and then add
7376
`--with-v8js=/opt/v8` to the php-v8js `./configure` command below.
@@ -91,3 +94,5 @@ make
9194
make test
9295
sudo make install
9396
```
97+
98+
Then add `extension=v8js.so` to your php.ini file. If you have a separate configuration for CLI, add it there also.

README.md

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

2829
V8 releases are published rather quickly and the V8 team usually provides security support
2930
for the version line shipped with the Chrome browser (stable channel) and newer (only).
@@ -163,6 +164,14 @@ class V8Js
163164
public function setMemoryLimit($limit)
164165
{}
165166

167+
/**
168+
* Set the average object size (in bytes) for this V8Js object.
169+
* V8's "amount of external memory" is adjusted by this value for every exported object. V8 triggers a garbage collection once this totals to 192 MB.
170+
* @param int $average_object_size
171+
*/
172+
public function setAverageObjectSize($average_object_size)
173+
{}
174+
166175
/**
167176
* Returns uncaught pending exception or null if there is no pending exception.
168177
* @return V8JsScriptException|null

TODO

Lines changed: 0 additions & 6 deletions
This file was deleted.

config.m4

Lines changed: 105 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -121,137 +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-
for static_link_extra_file in $static_link_extra; do
149-
AC_MSG_CHECKING([for $static_link_extra_file])
150-
151-
for i in $PHP_V8JS $SEARCH_PATH ; do
152-
if test -r $i/lib64/$static_link_extra_file; then
153-
static_link_dir=$i/lib64
154-
AC_MSG_RESULT(found in $i)
155-
fi
156-
if test -r $i/lib/$static_link_extra_file; then
157-
static_link_dir=$i/lib
158-
AC_MSG_RESULT(found in $i)
159-
fi
160-
done
161-
162-
if test -z "$static_link_dir"; then
163-
AC_MSG_RESULT([not found])
164-
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
165-
fi
166-
167-
LDFLAGS_libplatform="$static_link_dir/$static_link_extra_file"
168-
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
169143

170-
# modify flags for (possibly) succeeding V8 startup check
171-
CPPFLAGS="$CPPFLAGS -I$V8_DIR"
172-
LIBS="$LIBS $LDFLAGS_libplatform"
173-
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>
174178
175-
if test "$V8_API_VERSION" -ge 4004010 ; then
176-
dnl building for v8 4.4.10 or later, which requires us to
177-
dnl provide startup data, if V8 wasn't compiled with snapshot=off.
178-
AC_MSG_CHECKING([whether V8 requires startup data])
179-
AC_TRY_RUN([
180-
#include <v8.h>
181-
#include <libplatform/libplatform.h>
182-
#include <stdlib.h>
183-
#include <string.h>
184-
185-
#if PHP_V8_API_VERSION >= 4004010
186179
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
187180
public:
188-
virtual void* Allocate(size_t length) {
189-
void* data = AllocateUninitialized(length);
190-
return data == NULL ? data : memset(data, 0, length);
191-
}
192-
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
193-
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); }
194187
};
195-
#endif
196-
197-
int main ()
198-
{
199-
v8::Platform *v8_platform = v8::platform::CreateDefaultPlatform();
200-
v8::V8::InitializePlatform(v8_platform);
201-
v8::V8::Initialize();
202-
203-
#if PHP_V8_API_VERSION >= 4004044
204-
static ArrayBufferAllocator array_buffer_allocator;
205-
v8::Isolate::CreateParams create_params;
206-
create_params.array_buffer_allocator = &array_buffer_allocator;
207-
208-
v8::Isolate::New(create_params);
209-
#else /* PHP_V8_API_VERSION < 4004044 */
210-
v8::Isolate::New();
211-
#endif
212-
return 0;
213-
}
214-
], [
215-
AC_MSG_RESULT([no])
216-
], [
217-
AC_MSG_RESULT([yes])
218-
AC_DEFINE([PHP_V8_USE_EXTERNAL_STARTUP_DATA], [1], [Whether V8 requires (and can be provided with custom versions of) external startup data])
219-
220-
SEARCH_PATH="$V8_DIR/lib $V8_DIR/share/v8"
221-
222-
AC_MSG_CHECKING([for natives_blob.bin])
223-
SEARCH_FOR="natives_blob.bin"
224-
225-
for i in $SEARCH_PATH ; do
226-
if test -r $i/$SEARCH_FOR; then
227-
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
228-
AC_DEFINE_UNQUOTED([PHP_V8_NATIVES_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to natives_blob.bin file])
229-
native_blob_found=1
230-
fi
231-
done
232-
233-
if test -z "$native_blob_found"; then
234-
AC_MSG_RESULT([not found])
235-
AC_MSG_ERROR([Please provide V8 native blob as needed])
236-
fi
237-
238-
AC_MSG_CHECKING([for snapshot_blob.bin])
239-
SEARCH_FOR="snapshot_blob.bin"
240-
241-
for i in $SEARCH_PATH ; do
242-
if test -r $i/$SEARCH_FOR; then
243-
AC_MSG_RESULT([found ($i/$SEARCH_FOR)])
244-
AC_DEFINE_UNQUOTED([PHP_V8_SNAPSHOT_BLOB_PATH], "$i/$SEARCH_FOR", [Full path to snapshot_blob.bin file])
245-
snapshot_blob_found=1
246-
fi
247-
done
248-
249-
if test -z "$snapshot_blob_found"; then
250-
AC_MSG_RESULT([not found])
251-
AC_MSG_ERROR([Please provide V8 snapshot blob as needed])
252-
fi
253-
])
254-
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+
])
255242

256243
AC_LANG_RESTORE
257244
LIBS=$old_LIBS

config.w32

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ if (PHP_V8JS != "no") {
4242
} else {
4343
WARNING("Could not parse v8-version.h");
4444
}
45-
var v8api = v8major + v8js_zeroPad(v8minor,2) + v8js_zeroPad(v8build,2) + v8js_zeroPad(v8patch,2);
46-
var v8ver = v8major+"."+v8minor+"."+v8build+"."+v8patch;
47-
//WARNING("v8api = " + v8api + ", v8ver = " + v8ver);
45+
46+
var v8api = v8major + v8js_zeroPad(v8minor, 3) + v8js_zeroPad(v8build, 3);
47+
var v8ver = v8major + "." + v8minor + "." + v8build + "." + v8patch;
48+
4849
AC_DEFINE("PHP_V8_API_VERSION", v8api, "", false);
4950
AC_DEFINE("PHP_V8_VERSION", v8ver, "", true);
50-
//AC_DEFINE("PHP_V8_API_VERSION", "4007075", "", false);
51-
//AC_DEFINE("PHP_V8_VERSION", "4.7.75", "", true);
5251

5352
EXTENSION("v8js", "v8js_array_access.cc v8js.cc v8js_class.cc v8js_commonjs.cc v8js_convert.cc v8js_exceptions.cc v8js_generator_export.cc v8js_methods.cc v8js_object_export.cc v8js_timer.cc v8js_v8.cc v8js_v8object_class.cc v8js_variables.cc", "yes");
5453

0 commit comments

Comments
 (0)