Skip to content

Commit d0e7801

Browse files
committed
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.
1 parent 4df6e80 commit d0e7801

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

v8js_class.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
207207
c->modules_stack.~vector();
208208
c->modules_base.~vector();
209209

210-
#if defined(PHP_V8_USE_EXTERNAL_STARTUP_DATA) && PHP_V8_API_VERSION >= 4004044
210+
#if PHP_V8_API_VERSION >= 4003007
211211
if (c->snapshot_blob.data) {
212212
efree((void*)c->snapshot_blob.data);
213213
}
@@ -364,22 +364,23 @@ static PHP_METHOD(V8Js, __construct)
364364
c->pending_exception = NULL;
365365
c->in_execution = 0;
366366

367+
#if PHP_V8_API_VERSION >= 4003007
368+
new (&c->create_params) v8::Isolate::CreateParams();
369+
367370
#if PHP_V8_API_VERSION >= 4004044
368371
static ArrayBufferAllocator array_buffer_allocator;
369-
new (&c->create_params) v8::Isolate::CreateParams();
370372
c->create_params.array_buffer_allocator = &array_buffer_allocator;
373+
#endif
371374

372-
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
373375
new (&c->snapshot_blob) v8::StartupData();
374376
if (snapshot_blob && snapshot_blob_len) {
375377
c->snapshot_blob.data = snapshot_blob;
376378
c->snapshot_blob.raw_size = snapshot_blob_len;
377379
c->create_params.snapshot_blob = &c->snapshot_blob;
378380
}
379-
#endif /* PHP_V8_USE_EXTERNAL_STARTUP_DATA */
380381

381382
c->isolate = v8::Isolate::New(c->create_params);
382-
#else /* PHP_V8_API_VERSION < 4004044 */
383+
#else /* PHP_V8_API_VERSION < 4003007 */
383384
c->isolate = v8::Isolate::New();
384385
#endif
385386

@@ -1081,7 +1082,7 @@ static PHP_METHOD(V8Js, getExtensions)
10811082
}
10821083
/* }}} */
10831084

1084-
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
1085+
#if PHP_V8_API_VERSION >= 4003007
10851086
/* {{{ proto string|bool V8Js::createSnapshot(string embed_source)
10861087
*/
10871088
static PHP_METHOD(V8Js, createSnapshot)
@@ -1112,7 +1113,7 @@ static PHP_METHOD(V8Js, createSnapshot)
11121113
delete[] snapshot_blob.data;
11131114
}
11141115
/* }}} */
1115-
#endif /* PHP_V8_USE_EXTERNAL_STARTUP_DATA */
1116+
#endif /* PHP_V8_API_VERSION >= 4003007 */
11161117

11171118

11181119
/* {{{ arginfo */
@@ -1178,7 +1179,7 @@ ZEND_END_ARG_INFO()
11781179
ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
11791180
ZEND_END_ARG_INFO()
11801181

1181-
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
1182+
#if PHP_V8_API_VERSION >= 4003007
11821183
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_createsnapshot, 0, 0, 1)
11831184
ZEND_ARG_INFO(0, script)
11841185
ZEND_END_ARG_INFO()
@@ -1209,7 +1210,8 @@ const zend_function_entry v8js_methods[] = { /* {{{ */
12091210
PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
12101211
PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12111212
PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1212-
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
1213+
1214+
#if PHP_V8_API_VERSION >= 4003007
12131215
PHP_ME(V8Js, createSnapshot, arginfo_v8js_createsnapshot, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12141216
#endif
12151217
{NULL, NULL, NULL}

v8js_class.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ struct v8js_ctx {
6969
std::vector<struct _v8js_script *> script_objects;
7070
char *tz;
7171

72-
#if PHP_V8_API_VERSION >= 4004044
72+
#if PHP_V8_API_VERSION >= 4003007
7373
v8::Isolate::CreateParams create_params;
74-
#ifdef PHP_V8_USE_EXTERNAL_STARTUP_DATA
7574
v8::StartupData snapshot_blob;
7675
#endif
77-
#endif
7876

7977
#ifdef ZTS
8078
void ***zts_ctx;

0 commit comments

Comments
 (0)