0
0
mirror of https://github.com/phpv8/v8js.git synced 2025-01-03 15:41:55 +00:00

Allow snapshot creation & use with V8 > 4.3.7

This does *not* seem to depend on whether V8 itself was compiled
with support for snapshots or not.

Therefore use PHP_V8_USE_EXTERNAL_STARTUP_DATA only to mark
whether we need to provide external snapshot data to V8.
This commit is contained in:
Stefan Siegl 2016-03-05 14:22:48 +01:00
parent 4df6e80be9
commit d0e78019aa
2 changed files with 12 additions and 12 deletions

View File

@ -207,7 +207,7 @@ static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
c->modules_stack.~vector(); c->modules_stack.~vector();
c->modules_base.~vector(); c->modules_base.~vector();
#if defined(PHP_V8_USE_EXTERNAL_STARTUP_DATA) && PHP_V8_API_VERSION >= 4004044 #if PHP_V8_API_VERSION >= 4003007
if (c->snapshot_blob.data) { if (c->snapshot_blob.data) {
efree((void*)c->snapshot_blob.data); efree((void*)c->snapshot_blob.data);
} }
@ -364,22 +364,23 @@ static PHP_METHOD(V8Js, __construct)
c->pending_exception = NULL; c->pending_exception = NULL;
c->in_execution = 0; c->in_execution = 0;
#if PHP_V8_API_VERSION >= 4003007
new (&c->create_params) v8::Isolate::CreateParams();
#if PHP_V8_API_VERSION >= 4004044 #if PHP_V8_API_VERSION >= 4004044
static ArrayBufferAllocator array_buffer_allocator; static ArrayBufferAllocator array_buffer_allocator;
new (&c->create_params) v8::Isolate::CreateParams();
c->create_params.array_buffer_allocator = &array_buffer_allocator; c->create_params.array_buffer_allocator = &array_buffer_allocator;
#endif
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
new (&c->snapshot_blob) v8::StartupData(); new (&c->snapshot_blob) v8::StartupData();
if (snapshot_blob && snapshot_blob_len) { if (snapshot_blob && snapshot_blob_len) {
c->snapshot_blob.data = snapshot_blob; c->snapshot_blob.data = snapshot_blob;
c->snapshot_blob.raw_size = snapshot_blob_len; c->snapshot_blob.raw_size = snapshot_blob_len;
c->create_params.snapshot_blob = &c->snapshot_blob; c->create_params.snapshot_blob = &c->snapshot_blob;
} }
#endif /* PHP_V8_USE_EXTERNAL_STARTUP_DATA */
c->isolate = v8::Isolate::New(c->create_params); c->isolate = v8::Isolate::New(c->create_params);
#else /* PHP_V8_API_VERSION < 4004044 */ #else /* PHP_V8_API_VERSION < 4003007 */
c->isolate = v8::Isolate::New(); c->isolate = v8::Isolate::New();
#endif #endif
@ -1081,7 +1082,7 @@ static PHP_METHOD(V8Js, getExtensions)
} }
/* }}} */ /* }}} */
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA #if PHP_V8_API_VERSION >= 4003007
/* {{{ proto string|bool V8Js::createSnapshot(string embed_source) /* {{{ proto string|bool V8Js::createSnapshot(string embed_source)
*/ */
static PHP_METHOD(V8Js, createSnapshot) static PHP_METHOD(V8Js, createSnapshot)
@ -1112,7 +1113,7 @@ static PHP_METHOD(V8Js, createSnapshot)
delete[] snapshot_blob.data; delete[] snapshot_blob.data;
} }
/* }}} */ /* }}} */
#endif /* PHP_V8_USE_EXTERNAL_STARTUP_DATA */ #endif /* PHP_V8_API_VERSION >= 4003007 */
/* {{{ arginfo */ /* {{{ arginfo */
@ -1178,7 +1179,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0) ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA #if PHP_V8_API_VERSION >= 4003007
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_createsnapshot, 0, 0, 1) ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_createsnapshot, 0, 0, 1)
ZEND_ARG_INFO(0, script) ZEND_ARG_INFO(0, script)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
@ -1209,7 +1210,8 @@ const zend_function_entry v8js_methods[] = { /* {{{ */
PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC) PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
#if PHP_V8_API_VERSION >= 4003007
PHP_ME(V8Js, createSnapshot, arginfo_v8js_createsnapshot, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(V8Js, createSnapshot, arginfo_v8js_createsnapshot, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
#endif #endif
{NULL, NULL, NULL} {NULL, NULL, NULL}

View File

@ -69,12 +69,10 @@ struct v8js_ctx {
std::vector<struct _v8js_script *> script_objects; std::vector<struct _v8js_script *> script_objects;
char *tz; char *tz;
#if PHP_V8_API_VERSION >= 4004044 #if PHP_V8_API_VERSION >= 4003007
v8::Isolate::CreateParams create_params; v8::Isolate::CreateParams create_params;
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
v8::StartupData snapshot_blob; v8::StartupData snapshot_blob;
#endif #endif
#endif
#ifdef ZTS #ifdef ZTS
void ***zts_ctx; void ***zts_ctx;