Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit c9416ac

Browse files
committed
Add v8 API bindinds with stubs and tests
0 parents  commit c9416ac

File tree

253 files changed

+32367
-0
lines changed

Some content is hidden

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

253 files changed

+32367
-0
lines changed

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
tests/*
2+
!tests/*.phpt
3+
!tests/.testsuite.php
4+
!tests/.v8-helpers.php
5+
!tests/.tracking_dtors.php
6+
7+
.deps
8+
*.lo
9+
*.la
10+
*.loT
11+
.libs
12+
acinclude.m4
13+
aclocal.m4
14+
autom4te.cache
15+
build
16+
config.guess
17+
config.h
18+
config.h.in
19+
config.log
20+
config.nice
21+
config.status
22+
config.sub
23+
configure
24+
configure.in
25+
/include
26+
install-sh
27+
libtool
28+
ltmain.sh
29+
Makefile
30+
Makefile.fragments
31+
Makefile.global
32+
Makefile.objects
33+
missing
34+
mkinstalldirs
35+
modules
36+
run-tests.php
37+
tmp-php.ini
38+
39+
/conftest*

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2016 Bogdan Padalko <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

config.m4

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
PHP_ARG_WITH(v8, for V8 Javascript Engine,
2+
[ --with-v8 Include V8 JavaScript Engine])
3+
4+
if test "$PHP_V8" != "no"; then
5+
SEARCH_PATH="/usr/local /usr"
6+
SEARCH_FOR="include/v8.h"
7+
8+
if test -r $PHP_V8/$SEARCH_FOR; then
9+
case $host_os in
10+
darwin* )
11+
# MacOS does not support --rpath
12+
;;
13+
* )
14+
LDFLAGS="$LDFLAGS -Wl,--rpath=$PHP_V8/$PHP_LIBDIR"
15+
;;
16+
esac
17+
V8_DIR=$PHP_V8
18+
else
19+
AC_MSG_CHECKING([for V8 files in default path])
20+
for i in $SEARCH_PATH ; do
21+
if test -r $i/$SEARCH_FOR; then
22+
V8_DIR=$i
23+
AC_MSG_RESULT(found in $i)
24+
fi
25+
done
26+
fi
27+
28+
if test -z "$V8_DIR"; then
29+
AC_MSG_RESULT([not found])
30+
AC_MSG_ERROR([Please reinstall the v8 distribution])
31+
fi
32+
33+
PHP_ADD_INCLUDE($V8_DIR/include)
34+
PHP_ADD_LIBRARY_WITH_PATH(v8, $V8_DIR/$PHP_LIBDIR, V8_SHARED_LIBADD)
35+
PHP_SUBST(V8_SHARED_LIBADD)
36+
PHP_REQUIRE_CXX()
37+
38+
39+
AC_CACHE_CHECK(for C standard version, ac_cv_v8_cstd, [
40+
ac_cv_v8_cstd="c++11"
41+
old_CPPFLAGS=$CPPFLAGS
42+
AC_LANG_PUSH([C++])
43+
CPPFLAGS="-std="$ac_cv_v8_cstd
44+
AC_TRY_RUN([int main() { return 0; }],[],[ac_cv_v8_cstd="c++0x"],[])
45+
AC_LANG_POP([C++])
46+
CPPFLAGS=$old_CPPFLAGS
47+
]);
48+
49+
50+
old_LIBS=$LIBS
51+
old_LDFLAGS=$LDFLAGS
52+
old_CPPFLAGS=$CPPFLAGS
53+
54+
case $host_os in
55+
darwin* )
56+
# MacOS does not support --rpath
57+
LDFLAGS="-L$V8_DIR/$PHP_LIBDIR"
58+
;;
59+
* )
60+
LDFLAGS="-Wl,--rpath=$V8_DIR/$PHP_LIBDIR -L$V8_DIR/$PHP_LIBDIR"
61+
;;
62+
esac
63+
64+
PHP_ADD_INCLUDE($V8_DIR)
65+
66+
case $host_os in
67+
darwin* )
68+
static_link_extra="libv8_libplatform.a libv8_libbase.a"
69+
#static_link_extra="libv8_base.a libv8_libbase.a libv8_libplatform.a libv8_snapshot.a"
70+
;;
71+
* )
72+
static_link_extra="libv8_libplatform.a"
73+
#static_link_extra="libv8_base.a libv8_libbase.a libv8_libplatform.a libv8_snapshot.a"
74+
;;
75+
esac
76+
77+
for static_link_extra_file in $static_link_extra; do
78+
AC_MSG_CHECKING([for $static_link_extra_file])
79+
80+
for i in $PHP_V8 $SEARCH_PATH ; do
81+
if test -r $i/lib64/$static_link_extra_file; then
82+
static_link_dir=$i/lib64
83+
AC_MSG_RESULT(found in $i)
84+
fi
85+
if test -r $i/lib/$static_link_extra_file; then
86+
static_link_dir=$i/lib
87+
AC_MSG_RESULT(found in $i)
88+
fi
89+
done
90+
91+
if test -z "$static_link_dir"; then
92+
AC_MSG_RESULT([not found])
93+
AC_MSG_ERROR([Please provide $static_link_extra_file next to the libv8.so, see README.md for details])
94+
fi
95+
96+
LDFLAGS="$LDFLAGS $static_link_dir/$static_link_extra_file"
97+
done
98+
99+
LIBS=-lv8
100+
CPPFLAGS="-I$V8_DIR/include -std=$ac_cv_v8_cstd"
101+
AC_LANG_SAVE
102+
AC_LANG_CPLUSPLUS
103+
104+
105+
AC_CACHE_CHECK(for V8 version, ac_cv_v8_version, [
106+
AC_TRY_RUN([
107+
#include <v8.h>
108+
#include <iostream>
109+
#include <fstream>
110+
using namespace std;
111+
112+
int main ()
113+
{
114+
ofstream testfile ("conftestval");
115+
if (testfile.is_open()) {
116+
testfile << v8::V8::GetVersion();
117+
testfile << "\n";
118+
testfile.close();
119+
return 0;
120+
}
121+
return 1;
122+
}
123+
], [ac_cv_v8_version=`cat ./conftestval|awk '{print $1}'`], [ac_cv_v8_version=NONE], [ac_cv_v8_version=NONE])
124+
])
125+
126+
if test "$ac_cv_v8_version" != "NONE"; then
127+
ac_IFS=$IFS
128+
IFS=.
129+
set $ac_cv_v8_version
130+
IFS=$ac_IFS
131+
V8_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
132+
if test "$V8_API_VERSION" -lt 501000 ; then
133+
AC_MSG_ERROR([libv8 must be version 5.1.0 or greater])
134+
fi
135+
AC_DEFINE_UNQUOTED([PHP_LIBV8_API_VERSION], $V8_API_VERSION, [ ])
136+
AC_DEFINE_UNQUOTED([PHP_LIBV8_VERSION], "$ac_cv_v8_version", [ ])
137+
else
138+
AC_MSG_ERROR([could not determine libv8 version])
139+
fi
140+
141+
# On OS X clang reports warnings in zeng_strings.h, like
142+
# php/Zend/zend_string.h:326:2: warning: 'register' storage class specifier is deprecated [-Wdeprecated-register]
143+
# We want to make building log cleaner, so let's suppress this warning
144+
ac_cv_suppress_register_warnings_flag="-Wno-deprecated-register"
145+
146+
AC_DEFINE([V8_DEPRECATION_WARNINGS], [1], [Enable compiler warnings when using V8_DEPRECATED apis.])
147+
148+
AC_LANG_RESTORE
149+
LIBS=$old_LIBS
150+
#LDFLAGS=$old_LDFLAGS # we have to links some static libraries
151+
CPPFLAGS=$old_CPPFLAGS
152+
153+
if test -z "$TRAVIS" ; then
154+
type git &>/dev/null
155+
156+
if test $? -eq 0 ; then
157+
git describe --abbrev=0 --tags &>/dev/null
158+
159+
if test $? -eq 0 ; then
160+
AC_DEFINE_UNQUOTED([PHP_V8_VERSION], ["`git describe --abbrev=0 --tags`-`git rev-parse --abbrev-ref HEAD`-dev"], [git version])
161+
fi
162+
163+
git rev-parse --short HEAD &>/dev/null
164+
165+
if test $? -eq 0 ; then
166+
AC_DEFINE_UNQUOTED([PHP_V8_REVISION], ["`git rev-parse --short HEAD`"], [git revision])
167+
fi
168+
else
169+
AC_MSG_NOTICE([git not installed. Cannot obtain php-weak version tag. Install git.])
170+
fi
171+
fi
172+
173+
PHP_V8_SRCDIR=PHP_EXT_SRCDIR(v8)
174+
PHP_V8_BUILDDIR=PHP_EXT_BUILDDIR(v8)
175+
176+
PHP_ADD_INCLUDE($PHP_V8_SRCDIR/src)
177+
PHP_ADD_BUILD_DIR($PHP_V8_BUILDDIR/src)
178+
179+
PHP_NEW_EXTENSION(v8, [ \
180+
v8.cc \
181+
src/php_v8_a.cc \
182+
src/php_v8_exception.cc \
183+
src/php_v8_try_catch.cc \
184+
src/php_v8_message.cc \
185+
src/php_v8_stack_frame.cc \
186+
src/php_v8_stack_trace.cc \
187+
src/php_v8_script_origin_options.cc \
188+
src/php_v8_script_origin.cc \
189+
src/php_v8_exceptions.cc \
190+
src/php_v8_callbacks.cc \
191+
src/php_v8_startup_data.cc \
192+
src/php_v8_heap_statistics.cc \
193+
src/php_v8_isolate.cc \
194+
src/php_v8_context.cc \
195+
src/php_v8_object_template.cc \
196+
src/php_v8_function_template.cc \
197+
src/php_v8_script.cc \
198+
src/php_v8_data.cc \
199+
src/php_v8_value.cc \
200+
src/php_v8_primitive.cc \
201+
src/php_v8_null.cc \
202+
src/php_v8_boolean.cc \
203+
src/php_v8_name.cc \
204+
src/php_v8_string.cc \
205+
src/php_v8_symbol.cc \
206+
src/php_v8_number.cc \
207+
src/php_v8_integer.cc \
208+
src/php_v8_int32.cc \
209+
src/php_v8_uint32.cc \
210+
src/php_v8_object.cc \
211+
src/php_v8_function.cc \
212+
src/php_v8_array.cc \
213+
src/php_v8_date.cc \
214+
src/php_v8_regexp.cc \
215+
src/php_v8_number_object.cc \
216+
src/php_v8_boolean_object.cc \
217+
src/php_v8_string_object.cc \
218+
src/php_v8_symbol_object.cc \
219+
src/php_v8_property_attribute.cc \
220+
src/php_v8_template.cc \
221+
src/php_v8_return_value.cc \
222+
src/php_v8_callback_info.cc \
223+
src/php_v8_function_callback_info.cc \
224+
src/php_v8_property_callback_info.cc \
225+
src/php_v8_access_control.cc \
226+
src/php_v8_property_handler_flags.cc \
227+
src/php_v8_named_property_handler_configuration.cc \
228+
src/php_v8_indexed_property_handler_configuration.cc \
229+
src/php_v8_access_type.cc \
230+
], $ext_shared, , "$ac_cv_suppress_register_warnings_flag -std="$ac_cv_v8_cstd -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
231+
232+
PHP_ADD_BUILD_DIR($ext_builddir/src)
233+
234+
PHP_ADD_MAKEFILE_FRAGMENT
235+
fi

config.w32

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
// If your extension references something external, use ARG_WITH
5+
// ARG_WITH("v8", "for v8 support", "no");
6+
7+
// Otherwise, use ARG_ENABLE
8+
// ARG_ENABLE("v8", "enable v8 support", "no");
9+
10+
if (PHP_V8 != "no") {
11+
EXTENSION("v8", "v8.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
12+
}
13+

0 commit comments

Comments
 (0)