|
@@ -42,6 +42,10 @@ extern "C" {
|
|
#include <vector>
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include <mutex>
|
|
|
|
|
|
|
|
+#include "v8js_class.h"
|
|
|
|
+#include "v8js_v8.h"
|
|
|
|
+#include "v8js_timer.h"
|
|
|
|
+
|
|
#ifndef PATH_MAX
|
|
#ifndef PATH_MAX
|
|
/* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
|
|
/* Some platforms (Windows among others) don't have a PATH_MAX, for the moment
|
|
* just assume an arbitrary upper bound of 4096 chars.
|
|
* just assume an arbitrary upper bound of 4096 chars.
|
|
@@ -53,27 +57,6 @@ extern "C" {
|
|
/* V8Js Version */
|
|
/* V8Js Version */
|
|
#define V8JS_VERSION "0.1.5"
|
|
#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 */
|
|
/* Hidden field name used to link JS wrappers with underlying PHP object */
|
|
#define PHPJS_OBJECT_KEY "phpjs::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_ONCE 1
|
|
#define V8JS_DEBUG_AUTO_BREAK_ALWAYS 2
|
|
#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 */
|
|
/* Create PHP V8 object */
|
|
void php_v8js_create_v8(zval *, v8::Handle<v8::Value>, int, v8::Isolate * TSRMLS_DC);
|
|
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 */
|
|
/* 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);
|
|
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 */
|
|
/* Resource declaration */
|
|
|
|
|
|
/* Module globals */
|
|
/* Module globals */
|