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

Cleanups and optimizations #22

Merged
merged 18 commits into from
Feb 28, 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
5 changes: 4 additions & 1 deletion php_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include "config.h"
#endif

#include <v8-version.h>
#include <v8.h>

extern "C" {
#include "php.h"
#include <v8-version.h>

#ifdef ZTS
#include "TSRM.h"
Expand Down Expand Up @@ -51,6 +53,7 @@ extern zend_module_entry php_v8_module_entry;

ZEND_BEGIN_MODULE_GLOBALS(v8)
bool v8_initialized;
v8::Platform *platform;
ZEND_END_MODULE_GLOBALS(v8)

// Add zend_type support (new since PHP 7.2)
Expand Down
23 changes: 12 additions & 11 deletions src/php_v8_a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,29 @@ void php_v8_init()

v8::V8::InitializeICUDefaultLocation(PHP_V8_ICU_DATA_DIR);

// NOTE: if we use snapshot and extenal startup data then we have to initialize it (see https://codereview.chromium.org/315033002/)
// If we use snapshot and extenal startup data then we have to initialize it (see https://codereview.chromium.org/315033002/)
// v8::V8::InitializeExternalStartupData(NULL);
v8::Platform *platform = v8::platform::CreateDefaultPlatform();
v8::V8::InitializePlatform(platform);

// const char *flags = "--no-hard_abort";
// v8::V8::SetFlagsFromString(flags, strlen(flags));


// TODO: remove flags?
/* Set V8 command line flags (must be done before V8::Initialize()!) */
// if (PHP_V8_G(v8_flags)) {
// v8::V8::SetFlagsFromString(PHP_V8_G(v8_flags), strlen(PHP_V8_G(v8_flags)));
// }

/* Initialize V8 */
v8::V8::Initialize();

/* Run only once */
PHP_V8_G(v8_initialized) = true;
PHP_V8_G(platform) = platform;
}

void php_v8_shutdown() {
if (!PHP_V8_G(v8_initialized)) {
return;
}

v8::V8::Dispose();
v8::V8::ShutdownPlatform();

// TODO: probably, not necessary to call it on shutdown
// v8::V8::Dispose();
// v8::V8::ShutdownPlatform();
delete PHP_V8_G(platform);
}
9 changes: 9 additions & 0 deletions src/php_v8_a.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#ifndef PHP_V8_A_H
#define PHP_V8_A_H

extern "C" {
#include "php.h"

#ifdef ZTS
#include "TSRM.h"
#endif
};

void php_v8_init();
void php_v8_shutdown();

#endif //PHP_V8_A_H
8 changes: 2 additions & 6 deletions src/php_v8_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
zend_class_entry *php_v8_array_class_entry;
#define this_ce php_v8_array_class_entry

v8::Local<v8::Array> php_v8_value_get_array_local(v8::Isolate *isolate, php_v8_value_t *php_v8_value) {
return v8::Local<v8::Array>::Cast(php_v8_value_get_value_local(isolate, php_v8_value));
};

static PHP_METHOD(V8Array, __construct) {
zval rv;
Expand All @@ -46,8 +43,7 @@ static PHP_METHOD(V8Array, __construct) {

PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_array, "Failed to create Array value");

ZVAL_COPY_VALUE(&php_v8_value->this_ptr, getThis());
php_v8_object_store_self_ptr(isolate, local_array, php_v8_value);
php_v8_object_store_self_ptr(php_v8_value, local_array);

php_v8_value->persistent->Reset(isolate, local_array);
}
Expand All @@ -60,7 +56,7 @@ static PHP_METHOD(V8Array, Length) {
PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value);
PHP_V8_ENTER_STORED_ISOLATE(php_v8_value);

RETURN_LONG((zend_long) php_v8_value_get_array_local(isolate, php_v8_value)->Length());
RETURN_LONG(static_cast<zend_long >(php_v8_value_get_local_as<v8::Array>(php_v8_value)->Length()));
}


Expand Down
2 changes: 0 additions & 2 deletions src/php_v8_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ extern "C" {

extern zend_class_entry* php_v8_array_class_entry;

extern v8::Local<v8::Array> php_v8_value_get_array_local(v8::Isolate *isolate, php_v8_value_t *php_v8_value);


PHP_MINIT_FUNCTION(php_v8_array);

Expand Down
7 changes: 1 addition & 6 deletions src/php_v8_boolean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ zend_class_entry *php_v8_boolean_class_entry;
#define this_ce php_v8_boolean_class_entry


v8::Local<v8::Boolean> php_v8_value_get_boolean_local(v8::Isolate *isolate, php_v8_value_t *php_v8_value) {
return v8::Local<v8::Boolean>::Cast(php_v8_value_get_value_local(isolate, php_v8_value));
};

static PHP_METHOD(V8BooleanValue, __construct) {
zval *php_v8_isolate_zv;

Expand All @@ -53,8 +49,7 @@ static PHP_METHOD(V8BooleanValue, Value) {
PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value);
PHP_V8_ENTER_ISOLATE(php_v8_value->php_v8_isolate);

v8::Local<v8::Value> local_value = php_v8_value_get_value_local(isolate, php_v8_value);
v8::Local<v8::Boolean> local_boolean = v8::Local<v8::Boolean>::Cast(local_value);
v8::Local<v8::Boolean> local_boolean = php_v8_value_get_local_as<v8::Boolean>(php_v8_value);

RETVAL_BOOL(static_cast<zend_bool>(local_boolean->Value()));
}
Expand Down
2 changes: 0 additions & 2 deletions src/php_v8_boolean.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ extern "C" {

extern zend_class_entry* php_v8_boolean_class_entry;

extern v8::Local<v8::Boolean> php_v8_value_get_boolean_local(v8::Isolate *isolate, php_v8_value_t *php_v8_value);


PHP_MINIT_FUNCTION(php_v8_boolean);

Expand Down
8 changes: 2 additions & 6 deletions src/php_v8_boolean_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
zend_class_entry *php_v8_boolean_object_class_entry;
#define this_ce php_v8_boolean_object_class_entry

v8::Local<v8::BooleanObject> php_v8_value_get_boolean_object_local(v8::Isolate *isolate, php_v8_value_t *php_v8_value) {
return v8::Local<v8::BooleanObject>::Cast(php_v8_value_get_value_local(isolate, php_v8_value));
};

static PHP_METHOD(V8BooleanObject, __construct) {
zval rv;
Expand All @@ -41,8 +38,7 @@ static PHP_METHOD(V8BooleanObject, __construct) {

v8::Local<v8::BooleanObject> local_bool_obj = v8::BooleanObject::New(isolate, value).As<v8::BooleanObject>();

ZVAL_COPY_VALUE(&php_v8_value->this_ptr, getThis());
php_v8_object_store_self_ptr(isolate, local_bool_obj, php_v8_value);
php_v8_object_store_self_ptr(php_v8_value, local_bool_obj);

php_v8_value->persistent->Reset(isolate, local_bool_obj);
}
Expand All @@ -56,7 +52,7 @@ static PHP_METHOD(V8BooleanObject, ValueOf) {
PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value);
PHP_V8_ENTER_STORED_ISOLATE(php_v8_value);

v8::Local<v8::BooleanObject> local_boolean = php_v8_value_get_boolean_object_local(isolate, php_v8_value);
v8::Local<v8::BooleanObject> local_boolean = php_v8_value_get_local_as<v8::BooleanObject>(php_v8_value);

RETURN_BOOL(static_cast<zend_bool>(local_boolean->ValueOf()));
}
Expand Down
2 changes: 0 additions & 2 deletions src/php_v8_boolean_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ extern "C" {

extern zend_class_entry* php_v8_boolean_object_class_entry;

extern v8::Local<v8::BooleanObject> php_v8_value_get_boolean_object_local(v8::Isolate *isolate, php_v8_value_t *php_v8_value);


PHP_MINIT_FUNCTION(php_v8_boolean_object);

Expand Down
8 changes: 3 additions & 5 deletions src/php_v8_cached_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ zend_class_entry * php_v8_cached_data_class_entry;

static zend_object_handlers php_v8_cached_data_object_handlers;

php_v8_cached_data_t * php_v8_cached_data_fetch_object(zend_object *obj) {
return (php_v8_cached_data_t *)((char *)obj - XtOffsetOf(php_v8_cached_data_t, std));
}

php_v8_cached_data_t * php_v8_create_cached_data(zval *return_value, const v8::ScriptCompiler::CachedData *cached_data) {

Expand Down Expand Up @@ -139,8 +136,9 @@ PHP_MINIT_FUNCTION(php_v8_cached_data)

memcpy(&php_v8_cached_data_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));

php_v8_cached_data_object_handlers.offset = XtOffsetOf(php_v8_cached_data_t, std);
php_v8_cached_data_object_handlers.free_obj = php_v8_cached_data_free;
php_v8_cached_data_object_handlers.offset = XtOffsetOf(php_v8_cached_data_t, std);
php_v8_cached_data_object_handlers.free_obj = php_v8_cached_data_free;
php_v8_cached_data_object_handlers.clone_obj = NULL;

return SUCCESS;
}
6 changes: 5 additions & 1 deletion src/php_v8_cached_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {

extern zend_class_entry *php_v8_cached_data_class_entry;

extern php_v8_cached_data_t * php_v8_cached_data_fetch_object(zend_object *obj);
inline php_v8_cached_data_t * php_v8_cached_data_fetch_object(zend_object *obj);
extern php_v8_cached_data_t * php_v8_create_cached_data(zval *return_value, const v8::ScriptCompiler::CachedData *cached_data);


Expand Down Expand Up @@ -57,6 +57,10 @@ struct _php_v8_cached_data_t {
zend_object std;
};

inline php_v8_cached_data_t * php_v8_cached_data_fetch_object(zend_object *obj) {
return (php_v8_cached_data_t *)((char *)obj - XtOffsetOf(php_v8_cached_data_t, std));
}

PHP_MINIT_FUNCTION(php_v8_cached_data);

#endif //PHP_V8_CACHED_DATA_H
Loading