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

Upgrade to libv8-6.3 #50

Merged
merged 6 commits into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 12 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
sudo: required
dist: trusty
sudo: required

language: php

php:
- 7.1
- nightly

matrix:
allow_failures:
- php: nightly
services:
- docker

env:
global:
- NO_INTERACTION=1
- TEST_TIMEOUT=120
- V8=6.3
matrix:
- V8=6.2
- V8=6.2 TEST_PHP_ARGS=-m
- TAG=xenial-v8-63-php-71
- TAG=xenial-v8-63-php-71 TEST_PHP_ARGS=-m
- TAG=xenial-v8-63-php-72
- TAG=xenial-v8-63-php-72 TEST_PHP_ARGS=-m

before_install:
- sudo add-apt-repository ppa:pinepain/libv8-${V8} -y
- sudo apt-get update -q
- sudo apt-get install -y libv8-${V8}-dev
- php -i
- php-config || true

before_script:
- echo 'variables_order = "EGPCS"' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- phpize && ./configure && make
# docker on travis doesn't allow anything before FROM, let's fix that
- sed -i -e "s/\${TAG}/$TAG/g" Dockerfile && sed -i -e '1,2d' Dockerfile
- docker build -t ${TRAVIS_REPO_SLUG}:${V8}-${PHP} --build-arg TAG=${TAG} .

script:
- sh -c "make test | tee result.txt"
- sh test-report.sh

addons:
apt:
packages:
- valgrind
- docker run -e TEST_PHP_ARGS ${TRAVIS_REPO_SLUG}:${V8}-${PHP} bash -c "make test | tee result.txt; ./test-report.sh"
11 changes: 11 additions & 0 deletions .valgrind-docker.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
<docker_specific_report>
Memcheck:Free
fun:free
fun:deallocate
fun:deallocate
fun:_M_destroy
fun:_M_dispose
fun:~basic_string
...
}
6 changes: 6 additions & 0 deletions .valgrind-v8.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
<suppress_false_positive_warning_see_v8_issue_6566>
Memcheck:Cond
fun:_ZN2v88internal20MarkCompactCollector20EmptyMarkingWorklistEv
...
}
3 changes: 3 additions & 0 deletions .valgrindrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--gen-suppressions=all
--suppressions=./.valgrind-v8.supp
--suppressions=./.valgrind-docker.supp
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ project(php-v8)

# NOTE: This CMake file is just for syntax highlighting in CLion

include_directories(/usr/local/opt/v8@6.2/include)
include_directories(/usr/local/opt/v8@6.2/include/libplatform)
include_directories(/usr/local/opt/v8@6.3/include)
include_directories(/usr/local/opt/v8@6.3/include/libplatform)

include_directories(/usr/local/include/php)
include_directories(/usr/local/include/php/TSRM)
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ARG TAG=xenial-v8-63-php-72

FROM pinepain/php-v8-docker:${TAG}

COPY . /root/php-v8
COPY ./scripts/provision/.bashrc /root/.bashrc

WORKDIR /root/php-v8

RUN php -i && php-config || true

RUN phpize && ./configure && make
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $source = new \V8\StringValue($isolate, "'Hello' + ', World!'");
$script = new \V8\Script($context, $source);
$result = $script->run($context);

echo $result->toString($context)->value(), PHP_EOL;
echo $result->value(), PHP_EOL;
```

which will output `Hello, World!`. See how it's shorter and more readable than [that C++ version][v8-hello-world]?
Expand All @@ -69,7 +69,7 @@ in your IDE and other code-analysis tools.
### Requirements

#### V8
You will need a recent v8 Google JavaScript engine version installed. At this time the extension is tested on 6.2.2.
You will need a recent v8 Google JavaScript engine version installed. At this time v8 >= 6.3.2 required.

#### PHP
This extension is PHP7-only. It works and tested with both PHP 7.0 and PHP 7.1.
Expand All @@ -92,7 +92,7 @@ $ php --ri v8

While [pinepain/php](https://launchpad.net/~pinepain/+archive/ubuntu/php) PPA targets to contain all necessary
extensions with dependencies, you may find
[pinepain/libv8-6.2](https://launchpad.net/~pinepain/+archive/ubuntu/libv8-6.2),
[pinepain/libv8-6.3](https://launchpad.net/~pinepain/+archive/ubuntu/libv8-6.3),
[pinepain/libv8-experimental](https://launchpad.net/~pinepain/+archive/ubuntu/libv8-experimental) and
[pinepain/php-v8](https://launchpad.net/~pinepain/+archive/ubuntu/php-v8) standalone PPAs useful.

Expand Down
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if test "$PHP_V8" != "no"; then
SEARCH_PATH="/usr/local /usr"
SEARCH_FOR="include/v8.h"

V8_MIN_API_VERSION_STR=6.2.2
V8_MIN_API_VERSION_STR=6.3.2

DESIRED_V8_VERSION=`echo "${V8_MIN_API_VERSION_STR}" | $AWK 'BEGIN { FS = "."; } { printf "%s.%s", [$]1, [$]2;}'`

Expand Down
4 changes: 2 additions & 2 deletions scripts/provision/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ echo Provisioning...
# Add Ondřej Surý's PPA with co-installable PHP versions:
sudo add-apt-repository -y ppa:ondrej/php
# Add libv8 PPA:
sudo add-apt-repository ppa:pinepain/libv8-6.2
sudo add-apt-repository ppa:pinepain/libv8-6.3

# Let's update packages list:
sudo apt-get update
Expand All @@ -19,7 +19,7 @@ sudo apt-get install -y git htop curl pkgconf


# Build and development requirements
sudo apt-get install -y libv8-6.2 libv8-6.2-dev libv8-6.2-dbg
sudo apt-get install -y libv8-6.3 libv8-6.3-dev libv8-6.3-dbg
sudo apt-get install -y dh-make valgrind
sudo apt-get install -y libssl-dev openssl
sudo apt-get install -y php7.1 php7.1-cli php7.1-dev php7.1-fpm
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_v8/hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main(int argc, char* argv[]) {
Local<Value> result = script->Run();

// Convert the result to an UTF8 string and print it.
String::Utf8Value utf8(result);
String::Utf8Value utf8(isolate, result);
printf("%s\n", *utf8);
}

Expand Down
6 changes: 3 additions & 3 deletions src/php_v8_exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void php_v8_create_try_catch_exception(zval *return_value, php_v8_isolate_t *php
const char *message = NULL;

PHP_V8_DECLARE_LIMITS(php_v8_isolate);
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);

if ((try_catch == NULL) || (try_catch->Exception()->IsNull() && try_catch->Message().IsEmpty() && !try_catch->CanContinue() && try_catch->HasTerminated())) {
if (limits->time_limit_hit) {
Expand All @@ -68,10 +69,9 @@ void php_v8_create_try_catch_exception(zval *return_value, php_v8_isolate_t *php
object_init_ex(return_value, ce);
zend_update_property_string(php_v8_try_catch_exception_class_entry, return_value, ZEND_STRL("message"), message);
} else {
v8::String::Utf8Value exception(try_catch->Exception());

ce = php_v8_try_catch_exception_class_entry;
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK_NODECL(exception, message);

PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING_NODECL(isolate, message, try_catch->Exception());

object_init_ex(return_value, ce);
zend_update_property_string(php_v8_try_catch_exception_class_entry, return_value, ZEND_STRL("message"), message);
Expand Down
11 changes: 4 additions & 7 deletions src/php_v8_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph

object_init_ex(return_value, this_ce);

v8::Isolate *isolate = php_v8_isolate->isolate;
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
v8::Local<v8::Context> context = isolate->GetEnteredContext();

/* v8::Message::Get */
if (!message->Get().IsEmpty()) {
v8::String::Utf8Value message_utf8(message->Get());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(message_utf8, message_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, message_chars, message->Get());
zend_update_property_string(this_ce, return_value, ZEND_STRL("message"), message_chars);
}

/* v8::Message::GetSourceLine */
if (!message->GetSourceLine(context).IsEmpty()) {
v8::String::Utf8Value source_line_utf8(message->GetSourceLine(context).ToLocalChecked());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(source_line_utf8, source_line_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, source_line_chars, message->GetSourceLine(context).ToLocalChecked());
zend_update_property_string(this_ce, return_value, ZEND_STRL("source_line"), source_line_chars);
}

Expand All @@ -54,8 +52,7 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph

/* v8::Message::GetScriptResourceName */
if (!message->GetScriptResourceName().IsEmpty() && !message->GetScriptResourceName()->IsUndefined()) {
v8::String::Utf8Value script_resource_name_utf8(message->GetScriptResourceName());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(script_resource_name_utf8, script_resource_name_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, script_resource_name_chars, message->GetScriptResourceName());
zend_update_property_string(this_ce, return_value, ZEND_STRL("resource_name"), script_resource_name_chars);
}

Expand Down
4 changes: 2 additions & 2 deletions src/php_v8_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ static PHP_METHOD(Object, setAccessor) {
v8::Local<v8::Object> local_object = php_v8_value_get_local_as<v8::Object>(php_v8_value);
v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);

PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);

attributes = attributes ? attributes & PHP_V8_PROPERTY_ATTRIBUTE_FLAGS : attributes;
settings = settings ? settings & PHP_V8_ACCESS_CONTROL_FLAGS : settings;
Expand Down Expand Up @@ -574,7 +574,7 @@ static PHP_METHOD(Object, setNativeDataProperty) {
v8::Local<v8::Object> local_object = php_v8_value_get_local_as<v8::Object>(php_v8_value);
v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);

PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);

attributes = attributes ? attributes & PHP_V8_PROPERTY_ATTRIBUTE_FLAGS : attributes;

Expand Down
2 changes: 1 addition & 1 deletion src/php_v8_object_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static PHP_METHOD(ObjectTemplate, setAccessor) {

v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);

PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);

v8::AccessorNameGetterCallback getter;
v8::AccessorNameSetterCallback setter = 0;
Expand Down
7 changes: 3 additions & 4 deletions src/php_v8_script_origin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ extern void php_v8_create_script_origin(zval *return_value, v8::Local<v8::Contex
zval options_zv;

object_init_ex(return_value, this_ce);
v8::Isolate *isolate= context->GetIsolate();

/* v8::ScriptOrigin::ResourceName */
if (!origin.ResourceName().IsEmpty() && !origin.ResourceName()->IsUndefined()) {
v8::String::Utf8Value resource_name_utf8(origin.ResourceName());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(resource_name_utf8, resource_name_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, resource_name_chars, origin.ResourceName());
zend_update_property_string(this_ce, return_value, ZEND_STRL("resource_name"), resource_name_chars);
}

Expand All @@ -57,8 +57,7 @@ extern void php_v8_create_script_origin(zval *return_value, v8::Local<v8::Contex

/* v8::SourceMapUrl::ResourceName */
if (!origin.SourceMapUrl().IsEmpty() && !origin.SourceMapUrl()->IsUndefined()) {
v8::String::Utf8Value source_map_url_utf8(origin.SourceMapUrl());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(source_map_url_utf8, source_map_url_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, source_map_url_chars, origin.SourceMapUrl());
zend_update_property_string(this_ce, return_value, ZEND_STRL("source_map_url"), source_map_url_chars);
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/php_v8_stack_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ zend_class_entry *php_v8_stack_frame_class_entry;
#define this_ce php_v8_stack_frame_class_entry


void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local<v8::StackFrame> frame) {
void php_v8_stack_frame_create_from_stack_frame(v8::Isolate *isolate, zval *return_value, v8::Local<v8::StackFrame> frame) {

assert(!frame.IsEmpty());

Expand All @@ -41,23 +41,19 @@ void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local<v8

/* v8::StackFrame::GetScriptName */
if (!frame->GetScriptName().IsEmpty()) {
v8::String::Utf8Value script_name_utf8(frame->GetScriptName());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(script_name_utf8, script_name_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, script_name_chars, frame->GetScriptName());
zend_update_property_string(this_ce, return_value, ZEND_STRL("script_name"), script_name_chars);
}

/* v8::StackFrame::GetScriptNameOrSourceURL */
if (!frame->GetScriptNameOrSourceURL().IsEmpty()) {
v8::String::Utf8Value script_name_or_source_url_utf8(frame->GetScriptNameOrSourceURL());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(script_name_or_source_url_utf8, script_name_or_source_url_chars);
zend_update_property_string(this_ce, return_value, ZEND_STRL("script_name_or_source_url"),
script_name_or_source_url_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, script_name_or_source_url_chars, frame->GetScriptNameOrSourceURL());
zend_update_property_string(this_ce, return_value, ZEND_STRL("script_name_or_source_url"), script_name_or_source_url_chars);
}

/* v8::StackFrame::GetFunctionName */
if (!frame->GetFunctionName().IsEmpty()) {
v8::String::Utf8Value function_name_utf8(frame->GetFunctionName());
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(function_name_utf8, function_name_chars);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, function_name_chars, frame->GetFunctionName());
zend_update_property_string(this_ce, return_value, ZEND_STRL("function_name"), function_name_chars);
}

Expand Down
2 changes: 1 addition & 1 deletion src/php_v8_stack_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {

extern zend_class_entry* php_v8_stack_frame_class_entry;

extern void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local<v8::StackFrame> frame);
extern void php_v8_stack_frame_create_from_stack_frame(v8::Isolate *isolate, zval *return_value, v8::Local<v8::StackFrame> frame);


PHP_MINIT_FUNCTION(php_v8_stack_frame);
Expand Down
4 changes: 2 additions & 2 deletions src/php_v8_stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void php_v8_stack_trace_create_from_stack_trace(zval *return_value, php_v8_isola

object_init_ex(return_value, this_ce);

v8::Isolate *isolate = php_v8_isolate->isolate;
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);

/* v8::StackTrace::GetFrames */
/* v8::StackTrace::GetFrame */
Expand All @@ -42,7 +42,7 @@ void php_v8_stack_trace_create_from_stack_trace(zval *return_value, php_v8_isola
zval frame_zv;

for (uint32_t i = 0; i < frames_cnt; i++) {
php_v8_stack_frame_create_from_stack_frame(&frame_zv, trace->GetFrame(i));
php_v8_stack_frame_create_from_stack_frame(isolate, &frame_zv, trace->GetFrame(i));
add_index_zval(&frames_array_zv, i, &frame_zv);
}

Expand Down
2 changes: 1 addition & 1 deletion src/php_v8_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static PHP_METHOD(String, value)

v8::Local<v8::Value> str_tpl = php_v8_value_get_local(php_v8_value);

v8::String::Utf8Value str(str_tpl);
v8::String::Utf8Value str(isolate, str_tpl);

PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(str, cstr);

Expand Down
2 changes: 1 addition & 1 deletion src/php_v8_symbol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static PHP_METHOD(Symbol, value)
RETURN_EMPTY_STRING();
}

v8::String::Utf8Value str(local_name);
v8::String::Utf8Value str(isolate, local_name);

PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(str, cstr);

Expand Down
2 changes: 1 addition & 1 deletion src/php_v8_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void php_v8_template_SetNativeDataProperty(v8::Isolate *isolate, v8::Local<T> lo

v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);

PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);

phpv8::CallbacksBucket *bucket = php_v8_template->persistent_data->bucket("native_data_property_", local_name->IsSymbol(), name);
data = v8::External::New(isolate, bucket);
Expand Down
19 changes: 6 additions & 13 deletions src/php_v8_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,13 @@ extern php_v8_value_t *php_v8_get_or_create_value(zval *return_value, v8::Local<
return; \
}

#define PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(cstr, v8_local_string_from) \
v8::String::Utf8Value _v8_utf8_str_##cstr((v8_local_string_from)); \
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(_v8_utf8_str_##cstr, cstr); \
#define PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, cstr, v8_local_string_from) \
v8::String::Utf8Value _v8_utf8_str_##cstr((isolate), (v8_local_string_from)); \
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(_v8_utf8_str_##cstr, cstr); \

#define PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING_NODECL(cstr, v8_local_string_from) { \
v8::String::Utf8Value _v8_utf8_str_##cstr((v8_local_string_from)); \
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK_NODECL(_v8_utf8_str_##cstr, cstr); \
}

#define PHP_V8_SET_ZVAL_STRING_FROM_V8_STRING(zval_to, v8_local_string_from) { \
v8::String::Utf8Value _v8_utf8_str((v8_local_string_from)); \
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(_v8_utf8_str, _v8_utf8_cstr); \
ZVAL_STRINGL((zval_to), _v8_utf8_cstr, _v8_utf8_str.length()); \
}
#define PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING_NODECL(isolate, cstr, v8_local_string_from) \
v8::String::Utf8Value _v8_utf8_str_##cstr((isolate), (v8_local_string_from)); \
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK_NODECL(_v8_utf8_str_##cstr, cstr); \

struct _php_v8_value_t {
php_v8_isolate_t *php_v8_isolate;
Expand Down
2 changes: 1 addition & 1 deletion stubs/src/StringValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class StringValue extends NameValue
{
const MAX_LENGTH = (1 << 28) - 16;
const MAX_LENGTH = (1 << 30) - 25; // It's (1 << 28) - 16 on x32 platform, but we don't run on x32.

/**
* @param Isolate $isolate
Expand Down
Loading