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

Refactor to simplify public API #69

Merged
merged 17 commits into from
Sep 17, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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 v8 >= 6.3.2 required.
You will need a recent v8 Google JavaScript engine version installed. At this time v8 >= 6.3.163 required.

#### PHP
This extension is PHP7-only. It works and tested with both PHP 7.0 and PHP 7.1.
Expand Down
4 changes: 2 additions & 2 deletions 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.3.2
V8_MIN_API_VERSION_STR=6.3.163

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

Expand Down Expand Up @@ -211,11 +211,11 @@ if test "$PHP_V8" != "no"; then
src/php_v8_symbol_object.cc \
src/php_v8_template.cc \
src/php_v8_return_value.cc \
src/php_v8_callback_info.cc \
src/php_v8_function_callback_info.cc \
src/php_v8_property_callback_info.cc \
src/php_v8_named_property_handler_configuration.cc \
src/php_v8_indexed_property_handler_configuration.cc \
src/php_v8_json.cc \
], $ext_shared, , -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)

PHP_ADD_BUILD_DIR($ext_builddir/src)
Expand Down
128 changes: 0 additions & 128 deletions src/php_v8_callback_info.cc

This file was deleted.

1 change: 0 additions & 1 deletion src/php_v8_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#endif

#include "php_v8_callbacks.h"
#include "php_v8_callback_info.h"
#include "php_v8_property_callback_info.h"
#include "php_v8_function_callback_info.h"
#include "php_v8_return_value.h"
Expand Down
13 changes: 13 additions & 0 deletions src/php_v8_enums.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ zend_class_entry* php_v8_property_handler_flags_class_entry;
zend_class_entry *php_v8_property_filter_class_entry;
zend_class_entry *php_v8_key_collection_mode_class_entry;
zend_class_entry *php_v8_index_filter_class_entry;
zend_class_entry *php_v8_rail_mode_class_entry;


static const zend_function_entry php_v8_enum_methods[] = {
Expand Down Expand Up @@ -126,5 +127,17 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
zend_declare_class_constant_long(this_ce, ZEND_STRL("SKIP_INDICES"), static_cast<zend_long>(v8::IndexFilter::kSkipIndices));
#undef this_ce

// v8::RAILMode
#define this_ce php_v8_index_filter_class_entry
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "RAILMode", php_v8_enum_methods);
this_ce = zend_register_internal_class(&ce);
this_ce->ce_flags |= ZEND_ACC_FINAL;

zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_RESPONSE"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_RESPONSE));
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_ANIMATION"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_ANIMATION));
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_IDLE"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_IDLE));
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_LOAD"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_LOAD));
#undef this_ce

return SUCCESS;
}
8 changes: 4 additions & 4 deletions src/php_v8_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern zend_class_entry* php_v8_property_handler_flags_class_entry;
extern zend_class_entry* php_v8_property_filter_class_entry;
extern zend_class_entry* php_v8_key_collection_mode_class_entry;
extern zend_class_entry* php_v8_index_filter_class_entry;
extern zend_class_entry *php_v8_rail_mode_class_entry;


#define PHP_V8_ACCESS_CONTROL_FLAGS ( 0 \
Expand Down Expand Up @@ -77,12 +78,11 @@ extern zend_class_entry* php_v8_index_filter_class_entry;
| static_cast<long>(v8::KeyCollectionMode::kIncludePrototypes) \
)

#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \
| static_cast<long>(v8::IndexFilter::kIncludeIndices) \
| static_cast<long>(v8::IndexFilter::kSkipIndices) \
#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \
| static_cast<long>(v8::IndexFilter::kIncludeIndices) \
| static_cast<long>(v8::IndexFilter::kSkipIndices) \
)


PHP_MINIT_FUNCTION (php_v8_enums);

#endif //PHP_V8_ENUMS_H
98 changes: 91 additions & 7 deletions src/php_v8_function_callback_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "php_v8_function_callback_info.h"
#include "php_v8_exceptions.h"
#include "php_v8_callback_info.h"
#include "php_v8_return_value.h"
#include "php_v8_value.h"
#include "php_v8.h"
Expand Down Expand Up @@ -46,21 +45,21 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value
// common to both callback structures:
// isolate
ZVAL_OBJ(&tmp, &php_v8_isolate->std);
zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("isolate"), &tmp);
zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("isolate"), &tmp);
// context
ZVAL_OBJ(&tmp, &php_v8_context->std);
zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("context"), &tmp);
zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("context"), &tmp);
// this
php_v8_get_or_create_value(&tmp, args.This(), php_v8_isolate);
zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("this"), &tmp);
zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("this"), &tmp);
Z_DELREF(tmp);
// holder
php_v8_get_or_create_value(&tmp, args.Holder(), php_v8_isolate);
zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("holder"), &tmp);
zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("holder"), &tmp);
Z_DELREF(tmp);
// return value
php_v8_return_value = php_v8_return_value_create_from_return_value(&tmp, php_v8_context, PHP_V8_RETVAL_ACCEPTS_ANY);
zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("return_value"), &tmp);
zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("return_value"), &tmp);
Z_DELREF(tmp);

// specific to function callback structure:
Expand All @@ -86,6 +85,66 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value
return php_v8_return_value;
}

static PHP_METHOD(CallbackInfo, getIsolate) {
zval rv;
zval *tmp;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("isolate"), 0, &rv);
ZVAL_COPY(return_value, tmp);
}

static PHP_METHOD(CallbackInfo, getContext) {
zval rv;
zval *tmp;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("context"), 0, &rv);
ZVAL_COPY(return_value, tmp);
}

static PHP_METHOD(CallbackInfo, this) {
zval rv;
zval *tmp;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("this"), 0, &rv);
ZVAL_COPY(return_value, tmp);
}

static PHP_METHOD(CallbackInfo, holder) {
zval rv;
zval *tmp;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("holder"), 0, &rv);
ZVAL_COPY(return_value, tmp);
}

static PHP_METHOD(CallbackInfo, getReturnValue) {
zval rv;
zval *tmp;

if (zend_parse_parameters_none() == FAILURE) {
return;
}

tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("return_value"), 0, &rv);
ZVAL_COPY(return_value, tmp);
}

static PHP_METHOD(FunctionCallbackInfo, length) {
zval rv;
zval *tmp;
Expand Down Expand Up @@ -136,6 +195,21 @@ static PHP_METHOD(FunctionCallbackInfo, isConstructCall) {
}


PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIsolate, ZEND_RETURN_VALUE, 0, V8\\Isolate, 0)
ZEND_END_ARG_INFO()

PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0)
ZEND_END_ARG_INFO()

PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_this, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0)
ZEND_END_ARG_INFO()

PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_holder, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0)
ZEND_END_ARG_INFO()

PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getReturnValue, ZEND_RETURN_VALUE, 0, V8\\ReturnValue, 0)
ZEND_END_ARG_INFO()

PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_length, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

Expand All @@ -150,6 +224,11 @@ ZEND_END_ARG_INFO()


static const zend_function_entry php_v8_function_callback_info_methods[] = {
PHP_V8_ME(CallbackInfo, this, ZEND_ACC_PUBLIC)
PHP_V8_ME(CallbackInfo, holder, ZEND_ACC_PUBLIC)
PHP_V8_ME(CallbackInfo, getIsolate, ZEND_ACC_PUBLIC)
PHP_V8_ME(CallbackInfo, getContext, ZEND_ACC_PUBLIC)
PHP_V8_ME(CallbackInfo, getReturnValue, ZEND_ACC_PUBLIC)
PHP_V8_ME(FunctionCallbackInfo, length, ZEND_ACC_PUBLIC)
PHP_V8_ME(FunctionCallbackInfo, arguments, ZEND_ACC_PUBLIC)
PHP_V8_ME(FunctionCallbackInfo, newTarget, ZEND_ACC_PUBLIC)
Expand All @@ -161,8 +240,13 @@ PHP_MINIT_FUNCTION(php_v8_function_callback_info) {
zend_class_entry ce;

INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "FunctionCallbackInfo", php_v8_function_callback_info_methods);
this_ce = zend_register_internal_class_ex(&ce, php_v8_callback_info_class_entry);
this_ce = zend_register_internal_class(&ce);

zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("context"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("this"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("holder"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("return_value"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("new_target"), ZEND_ACC_PRIVATE);
zend_declare_property_null(this_ce, ZEND_STRL("is_constructor_call"), ZEND_ACC_PRIVATE);
Expand Down
1 change: 0 additions & 1 deletion src/php_v8_function_callback_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define PHP_V8_FUNCTION_CALLBACK_INFO_H

#include "php_v8_return_value.h"
#include "php_v8_callback_info.h"
#include <v8.h>

extern "C" {
Expand Down
Loading