mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-08 13:48:40 +00:00
Move types from php_v8js_macros.h to new headers
This commit is contained in:
parent
6869d318b3
commit
d269809d8b
@ -42,6 +42,10 @@ extern "C" {
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
#include "v8js_class.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_timer.h"
|
||||
|
||||
#ifndef PATH_MAX
|
||||
/* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
|
||||
* just assume an arbitrary upper bound of 4096 chars.
|
||||
@ -53,27 +57,6 @@ extern "C" {
|
||||
/* V8Js Version */
|
||||
#define V8JS_VERSION "0.1.5"
|
||||
|
||||
/* Helper macros */
|
||||
#define V8JS_SYM(v) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, sizeof(v) - 1)
|
||||
#define V8JS_SYML(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, l)
|
||||
#define V8JS_STR(v) v8::String::NewFromUtf8(isolate, v)
|
||||
#define V8JS_STRL(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kNormalString, l)
|
||||
#define V8JS_INT(v) v8::Integer::New(isolate, v)
|
||||
#define V8JS_UINT(v) v8::Integer::NewFromUnsigned(isolate, v)
|
||||
#define V8JS_FLOAT(v) v8::Number::New(isolate, v)
|
||||
#define V8JS_BOOL(v) ((v)?v8::True(isolate):v8::False(isolate))
|
||||
#define V8JS_DATE(v) v8::Date::New(isolate, v)
|
||||
#define V8JS_NULL v8::Null(isolate)
|
||||
#define V8JS_UNDEFINED v8::Undefined(isolate)
|
||||
#define V8JS_MN(name) v8js_method_##name
|
||||
#define V8JS_METHOD(name) void V8JS_MN(name)(const v8::FunctionCallbackInfo<v8::Value>& info)
|
||||
#define V8JS_THROW(isolate, type, message, message_len) (isolate)->ThrowException(v8::Exception::type(V8JS_STRL(message, message_len)))
|
||||
#define V8JS_GLOBAL(isolate) ((isolate)->GetCurrentContext()->Global())
|
||||
|
||||
/* Abbreviate long type names */
|
||||
typedef v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::FunctionTemplate> > v8js_tmpl_t;
|
||||
typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > v8js_persistent_obj_t;
|
||||
|
||||
/* Hidden field name used to link JS wrappers with underlying PHP object */
|
||||
#define PHPJS_OBJECT_KEY "phpjs::object"
|
||||
|
||||
@ -111,13 +94,6 @@ typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > v8
|
||||
#define V8JS_DEBUG_AUTO_BREAK_ONCE 1
|
||||
#define V8JS_DEBUG_AUTO_BREAK_ALWAYS 2
|
||||
|
||||
/* Extracts a C string from a V8 Utf8Value. */
|
||||
static inline const char * ToCString(const v8::String::Utf8Value &value) /* {{{ */
|
||||
{
|
||||
return *value ? *value : "<string conversion failed>";
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* Create PHP V8 object */
|
||||
void php_v8js_create_v8(zval *, v8::Handle<v8::Value>, int, v8::Isolate * TSRMLS_DC);
|
||||
|
||||
@ -139,70 +115,6 @@ void php_v8js_accessor_ctx_dtor(php_v8js_accessor_ctx * TSRMLS_DC);
|
||||
/* Register accessors into passed object */
|
||||
void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_list, v8::Local<v8::FunctionTemplate>, zval *, v8::Isolate * TSRMLS_DC);
|
||||
|
||||
struct v8js_v8object;
|
||||
|
||||
/* {{{ Context container */
|
||||
struct php_v8js_ctx {
|
||||
zend_object std;
|
||||
v8::Persistent<v8::String> object_name;
|
||||
v8::Persistent<v8::Context> context;
|
||||
zend_bool report_uncaught;
|
||||
zval *pending_exception;
|
||||
int in_execution;
|
||||
v8::Isolate *isolate;
|
||||
|
||||
long time_limit;
|
||||
bool time_limit_hit;
|
||||
long memory_limit;
|
||||
bool memory_limit_hit;
|
||||
|
||||
v8::Persistent<v8::FunctionTemplate> global_template;
|
||||
|
||||
zval *module_loader;
|
||||
std::vector<char *> modules_stack;
|
||||
std::vector<char *> modules_base;
|
||||
std::map<char *, v8js_persistent_obj_t> modules_loaded;
|
||||
std::map<const char *,v8js_tmpl_t> template_cache;
|
||||
|
||||
std::map<zval *, v8js_persistent_obj_t> weak_objects;
|
||||
std::map<v8js_tmpl_t *, v8js_persistent_obj_t> weak_closures;
|
||||
|
||||
std::list<v8js_v8object *> v8js_v8objects;
|
||||
|
||||
std::vector<php_v8js_accessor_ctx *> accessor_list;
|
||||
char *tz;
|
||||
#ifdef ZTS
|
||||
void ***zts_ctx;
|
||||
#endif
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
#ifdef ZTS
|
||||
# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData(0))->zts_ctx);
|
||||
#else
|
||||
# define V8JS_TSRMLS_FETCH()
|
||||
#endif
|
||||
|
||||
// Timer context
|
||||
struct php_v8js_timer_ctx
|
||||
{
|
||||
long time_limit;
|
||||
long memory_limit;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> time_point;
|
||||
php_v8js_ctx *v8js_ctx;
|
||||
bool killed;
|
||||
};
|
||||
|
||||
/* {{{ Object container */
|
||||
struct v8js_v8object {
|
||||
zend_object std;
|
||||
v8::Persistent<v8::Value> v8obj;
|
||||
int flags;
|
||||
struct php_v8js_ctx *ctx;
|
||||
HashTable *properties;
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* Resource declaration */
|
||||
|
||||
/* Module globals */
|
||||
|
@ -28,6 +28,7 @@ extern "C" {
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_exceptions.h"
|
||||
#include "v8js_v8object_class.h"
|
||||
#include "v8js_timer.h"
|
||||
|
||||
#include <functional>
|
||||
|
52
v8js_class.h
52
v8js_class.h
@ -14,6 +14,58 @@
|
||||
#ifndef V8JS_CLASS_H
|
||||
#define V8JS_CLASS_H
|
||||
|
||||
|
||||
/* Abbreviate long type names */
|
||||
typedef v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::FunctionTemplate> > v8js_tmpl_t;
|
||||
typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> > v8js_persistent_obj_t;
|
||||
|
||||
/* Forward declarations */
|
||||
struct v8js_v8object;
|
||||
struct php_v8js_accessor_ctx;
|
||||
|
||||
/* {{{ Context container */
|
||||
struct php_v8js_ctx {
|
||||
zend_object std;
|
||||
v8::Persistent<v8::String> object_name;
|
||||
v8::Persistent<v8::Context> context;
|
||||
zend_bool report_uncaught;
|
||||
zval *pending_exception;
|
||||
int in_execution;
|
||||
v8::Isolate *isolate;
|
||||
|
||||
long time_limit;
|
||||
bool time_limit_hit;
|
||||
long memory_limit;
|
||||
bool memory_limit_hit;
|
||||
|
||||
v8::Persistent<v8::FunctionTemplate> global_template;
|
||||
|
||||
zval *module_loader;
|
||||
std::vector<char *> modules_stack;
|
||||
std::vector<char *> modules_base;
|
||||
std::map<char *, v8js_persistent_obj_t> modules_loaded;
|
||||
std::map<const char *,v8js_tmpl_t> template_cache;
|
||||
|
||||
std::map<zval *, v8js_persistent_obj_t> weak_objects;
|
||||
std::map<v8js_tmpl_t *, v8js_persistent_obj_t> weak_closures;
|
||||
|
||||
std::list<v8js_v8object *> v8js_v8objects;
|
||||
|
||||
std::vector<php_v8js_accessor_ctx *> accessor_list;
|
||||
char *tz;
|
||||
#ifdef ZTS
|
||||
void ***zts_ctx;
|
||||
#endif
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
#ifdef ZTS
|
||||
# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData(0))->zts_ctx);
|
||||
#else
|
||||
# define V8JS_TSRMLS_FETCH()
|
||||
#endif
|
||||
|
||||
|
||||
PHP_MINIT_FUNCTION(v8js_class);
|
||||
|
||||
#endif /* V8JS_CLASS_H */
|
||||
|
10
v8js_timer.h
10
v8js_timer.h
@ -14,6 +14,16 @@
|
||||
#ifndef V8JS_TIMER_H
|
||||
#define V8JS_TIMER_H
|
||||
|
||||
// Timer context
|
||||
struct php_v8js_timer_ctx
|
||||
{
|
||||
long time_limit;
|
||||
long memory_limit;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> time_point;
|
||||
php_v8js_ctx *v8js_ctx;
|
||||
bool killed;
|
||||
};
|
||||
|
||||
void v8js_timer_thread(TSRMLS_D);
|
||||
void v8js_timer_push(long time_limit, long memory_limit, php_v8js_ctx *c TSRMLS_DC);
|
||||
|
||||
|
27
v8js_v8.h
27
v8js_v8.h
@ -14,6 +14,33 @@
|
||||
#ifndef V8JS_V8_H
|
||||
#define V8JS_V8_H
|
||||
|
||||
/* Helper macros */
|
||||
#define V8JS_SYM(v) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, sizeof(v) - 1)
|
||||
#define V8JS_SYML(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kInternalizedString, l)
|
||||
#define V8JS_STR(v) v8::String::NewFromUtf8(isolate, v)
|
||||
#define V8JS_STRL(v, l) v8::String::NewFromUtf8(isolate, v, v8::String::kNormalString, l)
|
||||
#define V8JS_INT(v) v8::Integer::New(isolate, v)
|
||||
#define V8JS_UINT(v) v8::Integer::NewFromUnsigned(isolate, v)
|
||||
#define V8JS_FLOAT(v) v8::Number::New(isolate, v)
|
||||
#define V8JS_BOOL(v) ((v)?v8::True(isolate):v8::False(isolate))
|
||||
#define V8JS_DATE(v) v8::Date::New(isolate, v)
|
||||
#define V8JS_NULL v8::Null(isolate)
|
||||
#define V8JS_UNDEFINED v8::Undefined(isolate)
|
||||
#define V8JS_MN(name) v8js_method_##name
|
||||
#define V8JS_METHOD(name) void V8JS_MN(name)(const v8::FunctionCallbackInfo<v8::Value>& info)
|
||||
#define V8JS_THROW(isolate, type, message, message_len) (isolate)->ThrowException(v8::Exception::type(V8JS_STRL(message, message_len)))
|
||||
#define V8JS_GLOBAL(isolate) ((isolate)->GetCurrentContext()->Global())
|
||||
|
||||
|
||||
/* Extracts a C string from a V8 Utf8Value. */
|
||||
static inline const char * ToCString(const v8::String::Utf8Value &value) /* {{{ */
|
||||
{
|
||||
return *value ? *value : "<string conversion failed>";
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
|
||||
void v8js_v8_init(TSRMLS_D);
|
||||
void v8js_v8_call(php_v8js_ctx *c, zval **return_value,
|
||||
long flags, long time_limit, long memory_limit,
|
||||
|
@ -28,6 +28,7 @@ extern "C" {
|
||||
#include "php_v8js_macros.h"
|
||||
#include "v8js_exceptions.h"
|
||||
#include "v8js_v8.h"
|
||||
#include "v8js_v8object_class.h"
|
||||
|
||||
/* {{{ Class Entries */
|
||||
zend_class_entry *php_ce_v8object;
|
||||
|
@ -14,6 +14,16 @@
|
||||
#ifndef V8JS_V8OBJECT_CLASS_H
|
||||
#define V8JS_V8OBJECT_CLASS_H
|
||||
|
||||
/* {{{ Object container */
|
||||
struct v8js_v8object {
|
||||
zend_object std;
|
||||
v8::Persistent<v8::Value> v8obj;
|
||||
int flags;
|
||||
struct php_v8js_ctx *ctx;
|
||||
HashTable *properties;
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
extern zend_class_entry *php_ce_v8object;
|
||||
extern zend_class_entry *php_ce_v8function;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user