0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 19:51:51 +00:00

Merge pull request #82 from stesie/fix-ftbfs-v8-3.24.5

Fix build against V8 >= 3.24.4
This commit is contained in:
Patrick Reilly 2013-12-29 00:21:38 -08:00
commit 98d535b8b1
6 changed files with 78 additions and 56 deletions

View File

@ -1,8 +1,6 @@
V8Js
====
[![Build Status](http://jenkins.brokenpipe.de/job/v8js/badge/icon)](http://jenkins.brokenpipe.de/job/v8js/)
V8Js is a PHP extension for Google's V8 Javascript engine.
The extension allows you to execute Javascript code in a secure sandbox from PHP. The executed code can be restricted using a time limit and/or memory limit. This provides the possibility to execute untrusted code with confidence.
@ -16,9 +14,9 @@ Minimum requirements
V8 is Google's open source Javascript engine.
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 implements ECMAScript as specified in ECMA-262, 5th edition.
This extension makes use of V8 isolates to ensure separation between multiple V8Js instances and already uses the new persistence API, hence the need for 3.21.12 or above.
This extension makes use of V8 isolates to ensure separation between multiple V8Js instances and uses the new isolate-based mechanism to throw exceptions, hence the need for 3.22.3 or above.
For a detailed overview of which V8 version V8Js can be successfully build against, see the [Jenkins V8Js job list](http://jenkins.brokenpipe.de/view/v8js-with-v8-versions/).
For a detailed overview of which V8 version V8Js can be successfully built against, see the [Jenkins V8Js job list](http://jenkins.brokenpipe.de/view/v8js-with-v8-versions/).
- PHP 5.3.3+

View File

@ -34,6 +34,14 @@ extern "C" {
/* V8Js Version */
#define V8JS_VERSION "0.1.3"
/* V8 from 3.23.12 has most v8::Anything::New constructors expect isolates
as their first argument. Older versions don't provide these. */
#if PHP_V8_API_VERSION < 3023012
#define V8JS_NEW(t, i, v...) t::New(v)
#else
#define V8JS_NEW(t, i, v...) t::New(i, v)
#endif
/* 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)
@ -46,8 +54,8 @@ extern "C" {
#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(type, message, message_len) v8::ThrowException(v8::Exception::type(V8JS_STRL(message, message_len)))
#define V8JS_GLOBAL v8::Context::GetCurrent()->Global()
#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())
#if PHP_V8_API_VERSION < 3022000
/* CopyablePersistentTraits is only part of V8 from 3.22.0 on,
@ -108,8 +116,8 @@ typedef v8::Persistent<v8::FunctionTemplate, v8::CopyablePersistentTraits<v8::Fu
#endif
/* Global flags */
#define V8JS_GLOBAL_SET_FLAGS(flags) V8JS_GLOBAL->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
#define V8JS_GLOBAL_GET_FLAGS() V8JS_GLOBAL->GetHiddenValue(V8JS_SYM("__php_flags__"))->IntegerValue();
#define V8JS_GLOBAL_SET_FLAGS(isolate,flags) V8JS_GLOBAL(isolate)->SetHiddenValue(V8JS_SYM("__php_flags__"), V8JS_INT(flags))
#define V8JS_GLOBAL_GET_FLAGS(isolate) V8JS_GLOBAL(isolate)->GetHiddenValue(V8JS_SYM("__php_flags__"))->IntegerValue();
/* Options */
#define V8JS_FLAG_NONE (1<<0)
@ -179,7 +187,12 @@ struct php_v8js_ctx {
/* }}} */
#ifdef ZTS
# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData())->zts_ctx);
# if PHP_V8_API_VERSION <= 3023008
/* Until V8 3.23.8 Isolate could only take one external pointer. */
# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData())->zts_ctx);
# else
# define V8JS_TSRMLS_FETCH() TSRMLS_FETCH_FROM_CTX(((php_v8js_ctx *) isolate->GetData(0))->zts_ctx);
# endif
#else
# define V8JS_TSRMLS_FETCH()
#endif

24
v8js.cc
View File

@ -418,7 +418,7 @@ static int php_v8js_v8_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) /
jsArgv[i] = v8::Local<v8::Value>::New(isolate, zval_to_v8js(*argv[i], isolate TSRMLS_CC));
}
js_retval = cb->Call(V8JS_GLOBAL, argc, jsArgv);
js_retval = cb->Call(V8JS_GLOBAL(isolate), argc, jsArgv);
zval_ptr_dtor(&object);
@ -566,10 +566,10 @@ static void php_v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
v8::Locker locker(c->isolate);
v8::Isolate::Scope isolate_scope(c->isolate);
v8::HandleScope handle_scope(c->isolate);
v8::Context::Scope context_scope(c->isolate, c->context);
v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(c->isolate, c->context);
v8::Context::Scope context_scope(v8_context);
v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(c->isolate, c->object_name);
V8JS_GLOBAL->Delete(object_name_js);
V8JS_GLOBAL(c->isolate)->Delete(object_name_js);
}
c->object_name.Reset();
@ -779,7 +779,12 @@ static PHP_METHOD(V8Js, __construct)
c->pending_exception = NULL;
c->in_execution = 0;
c->isolate = v8::Isolate::New();
#if PHP_V8_API_VERSION <= 3023008
/* Until V8 3.23.8 Isolate could only take one external pointer. */
c->isolate->SetData(c);
#else
c->isolate->SetData(0, c);
#endif
c->time_limit_hit = false;
c->memory_limit_hit = false;
c->module_loader = NULL;
@ -865,7 +870,7 @@ static PHP_METHOD(V8Js, __construct)
/* Add the PHP object into global object */
v8::Local<v8::Object> php_obj = php_obj_t->InstanceTemplate()->NewInstance();
V8JS_GLOBAL->Set(object_name_js, php_obj, v8::ReadOnly);
V8JS_GLOBAL(isolate)->Set(object_name_js, php_obj, v8::ReadOnly);
/* Export public property values */
HashTable *properties = zend_std_get_properties(getThis() TSRMLS_CC);
@ -909,7 +914,8 @@ static PHP_METHOD(V8Js, __construct)
v8::Locker locker(isolate); \
v8::Isolate::Scope isolate_scope(isolate); \
v8::HandleScope handle_scope(isolate); \
v8::Context::Scope context_scope(isolate, (ctx)->context);
v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(isolate, (ctx)->context); \
v8::Context::Scope context_scope(v8_context);
static void php_v8js_timer_push(long time_limit, long memory_limit, php_v8js_ctx *c TSRMLS_DC)
{
@ -1032,7 +1038,7 @@ static PHP_METHOD(V8Js, executeString)
}
/* Set flags for runtime use */
V8JS_GLOBAL_SET_FLAGS(flags);
V8JS_GLOBAL_SET_FLAGS(isolate, flags);
if (time_limit > 0 || memory_limit > 0) {
// If timer thread is not running then start it
@ -1447,7 +1453,7 @@ static void php_v8js_write_property(zval *object, zval *member, zval *value ZEND
if(property_info->flags & ZEND_ACC_PUBLIC) {
/* Global PHP JS object */
v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
v8::Local<v8::Object> jsobj = V8JS_GLOBAL->Get(object_name_js)->ToObject();
v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
/* Write value to PHP JS object */
jsobj->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
@ -1464,7 +1470,7 @@ static void php_v8js_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC
/* Global PHP JS object */
v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
v8::Local<v8::Object> jsobj = V8JS_GLOBAL->Get(object_name_js)->ToObject();
v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
/* Delete value from PHP JS object */
jsobj->ForceDelete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));

View File

@ -70,7 +70,7 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct
(argc < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
argc);
return_value = V8JS_THROW(TypeError, error, error_len);
return_value = V8JS_THROW(isolate, TypeError, error, error_len);
if (ce == zend_ce_closure) {
efree(const_cast<char*>(method_ptr->internal_function.function_name));
efree(method_ptr);
@ -82,7 +82,7 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct
/* Convert parameters passed from V8 */
if (argc) {
flags = V8JS_GLOBAL_GET_FLAGS();
flags = V8JS_GLOBAL_GET_FLAGS(isolate);
fci.params = (zval ***) safe_emalloc(argc, sizeof(zval **), 0);
argv = (zval **) safe_emalloc(argc, sizeof(zval *), 0);
for (i = 0; i < argc; i++) {
@ -99,7 +99,7 @@ static void php_v8js_call_php_func(zval *value, zend_class_entry *ce, zend_funct
if (v8js_to_zval(info[i], argv[i], flags, isolate TSRMLS_CC) == FAILURE) {
fci.param_count++;
error_len = spprintf(&error, 0, "converting parameter #%d passed to %s() failed", i + 1, method_ptr->common.function_name);
return_value = V8JS_THROW(Error, error, error_len);
return_value = V8JS_THROW(isolate, Error, error, error_len);
efree(error);
goto failure;
}
@ -205,7 +205,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
// Check access on __construct function, if any
if (ctor_ptr != NULL && (ctor_ptr->common.fn_flags & ZEND_ACC_PUBLIC) == 0) {
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Call to protected __construct() not allowed")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Call to protected __construct() not allowed")));
return;
}
@ -216,7 +216,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
if (ctor_ptr != NULL) {
php_v8js_call_php_func(value, ce, ctor_ptr, isolate, info TSRMLS_CC);
}
php_object = v8::External::New(value);
php_object = V8JS_NEW(v8::External, isolate, value);
}
newobj->SetAlignedPointerInInternalField(0, ext_tmpl->Value());
@ -230,7 +230,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
// Just tell v8 that we're allocating some external memory
// (for the moment we just always tell 1k instead of trying to find out actual values)
v8::V8::AdjustAmountOfExternalAllocatedMemory(1024);
isolate->AdjustAmountOfExternalAllocatedMemory(1024);
}
/* }}} */
@ -260,7 +260,7 @@ static void php_v8js_weak_object_callback(const v8::WeakCallbackData<v8::Object,
zval *value = data.GetParameter();
zval_ptr_dtor(&value);
v8::V8::AdjustAmountOfExternalAllocatedMemory(-1024);
data.GetIsolate()->AdjustAmountOfExternalAllocatedMemory(-1024);
}
static void php_v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object, v8js_tmpl_t> &data) {
@ -278,8 +278,8 @@ static void php_v8js_weak_closure_callback(const v8::WeakCallbackData<v8::Object
((key_len == sizeof(mname)) && \
!strncasecmp(key, mname, key_len - 1))
#define PHP_V8JS_CALLBACK(mptr, tmpl) \
v8::FunctionTemplate::New(php_v8js_php_callback, v8::External::New(mptr), v8::Signature::New(tmpl))->GetFunction()
#define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \
v8::FunctionTemplate::New(php_v8js_php_callback, V8JS_NEW(v8::External, (isolate), mptr), V8JS_NEW(v8::Signature, (isolate), tmpl))->GetFunction()
static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */
@ -287,7 +287,7 @@ static void php_v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8
// note: 'special' properties like 'constructor' are not enumerated.
v8::Isolate *isolate = info.GetIsolate();
v8::Local<v8::Object> self = info.Holder();
v8::Local<v8::Array> result = v8::Array::New(0);
v8::Local<v8::Array> result = V8JS_NEW(v8::Array, isolate, 0);
uint32_t result_len = 0;
V8JS_TSRMLS_FETCH();
@ -423,7 +423,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
error_len = spprintf(&error, 0,
"%s::__call expects 2 parameters, %d given",
ce->name, (int) info.Length());
return_value = V8JS_THROW(TypeError, error, error_len);
return_value = V8JS_THROW(isolate, TypeError, error, error_len);
efree(error);
info.GetReturnValue().Set(return_value);
return;
@ -432,7 +432,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
error_len = spprintf(&error, 0,
"%s::__call expects 2nd parameter to be an array",
ce->name);
return_value = V8JS_THROW(TypeError, error, error_len);
return_value = V8JS_THROW(isolate, TypeError, error, error_len);
efree(error);
info.GetReturnValue().Set(return_value);
return;
@ -447,7 +447,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
error_len = spprintf(&error, 0,
"%s::__call expects fewer than a million arguments",
ce->name);
return_value = V8JS_THROW(TypeError, error, error_len);
return_value = V8JS_THROW(isolate, TypeError, error, error_len);
efree(error);
info.GetReturnValue().Set(return_value);
return;
@ -463,7 +463,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
error_len = spprintf(&error, 0,
"%s::__call to %s method %s", ce->name,
(method_ptr == NULL) ? "undefined" : "non-public", method_name);
return_value = V8JS_THROW(TypeError, error, error_len);
return_value = V8JS_THROW(isolate, TypeError, error, error_len);
efree(error);
info.GetReturnValue().Set(return_value);
return;
@ -473,7 +473,7 @@ static void php_v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& i
v8::Local<v8::FunctionTemplate>::New
(isolate, *reinterpret_cast<v8js_tmpl_t *>(self->GetAlignedPointerFromInternalField(0)));
// use php_v8js_php_callback to actually execute the method
v8::Local<v8::Function> cb = PHP_V8JS_CALLBACK(method_ptr, tmpl);
v8::Local<v8::Function> cb = PHP_V8JS_CALLBACK(isolate, method_ptr, tmpl);
uint32_t i, argc = args->Length();
v8::Local<v8::Value> argv[argc];
for (i=0; i<argc; i++) {
@ -547,11 +547,11 @@ static inline v8::Local<v8::Value> php_v8js_named_property_callback(v8::Local<v8
v8::Local<v8::Function> cb =
v8::FunctionTemplate::New(
php_v8js_fake_call_impl, V8JS_NULL,
v8::Signature::New(tmpl))->GetFunction();
V8JS_NEW(v8::Signature, isolate, tmpl))->GetFunction();
cb->SetName(property);
ret_value = cb;
} else {
ret_value = PHP_V8JS_CALLBACK(method_ptr, tmpl);
ret_value = PHP_V8JS_CALLBACK(isolate, method_ptr, tmpl);
}
}
} else if (callback_type == V8JS_PROP_QUERY) {
@ -686,7 +686,12 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
return v8obj;
} else if (ce) {
#if PHP_V8_API_VERSION <= 3023008
/* Until V8 3.23.8 Isolate could only take one external pointer. */
php_v8js_ctx *ctx = (php_v8js_ctx *) isolate->GetData();
#else
php_v8js_ctx *ctx = (php_v8js_ctx *) isolate->GetData(0);
#endif
v8::Local<v8::FunctionTemplate> new_tpl;
v8js_tmpl_t *persist_tpl_;
@ -726,17 +731,17 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value, v8::Isolate *is
sizeof(ZEND_INVOKE_FUNC_NAME),
(void**)&invoke_method_ptr) == SUCCESS &&
invoke_method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) {
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_invoke_callback, PHP_V8JS_CALLBACK(invoke_method_ptr, new_tpl));
new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl));
}
}
v8::Local<v8::Array> call_handler_data = v8::Array::New(2);
call_handler_data->Set(0, v8::External::New(persist_tpl_));
call_handler_data->Set(1, v8::External::New(ce));
v8::Local<v8::Array> call_handler_data = V8JS_NEW(v8::Array, isolate, 2);
call_handler_data->Set(0, V8JS_NEW(v8::External, isolate, persist_tpl_));
call_handler_data->Set(1, V8JS_NEW(v8::External, isolate, ce));
new_tpl->SetCallHandler(php_v8js_construct_callback, call_handler_data);
}
// Create v8 wrapper object
v8::Handle<v8::Value> external = v8::External::New(value);
v8::Handle<v8::Value> external = V8JS_NEW(v8::External, isolate, value);
newobj = new_tpl->GetFunction()->NewInstance(1, &external);
if (ce == zend_ce_closure) {
@ -814,7 +819,7 @@ static v8::Handle<v8::Value> php_v8js_hash_to_jsarr(zval *value, v8::Isolate *is
return V8JS_NULL;
}
newarr = v8::Array::New(i);
newarr = V8JS_NEW(v8::Array, isolate, i);
if (i > 0)
{

View File

@ -205,7 +205,7 @@ V8JS_METHOD(require)
// Check that we have a module loader
if (c->module_loader == NULL) {
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("No module loader")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("No module loader")));
return;
}
@ -237,7 +237,7 @@ V8JS_METHOD(require)
efree(normalised_module_id);
efree(normalised_path);
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Module cyclic dependency")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module cyclic dependency")));
return;
}
}
@ -265,7 +265,7 @@ V8JS_METHOD(require)
efree(normalised_module_id);
efree(normalised_path);
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Module loader callback failed")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
return;
}
zval_ptr_dtor(&normalised_path_zend);
@ -277,7 +277,7 @@ V8JS_METHOD(require)
// Clear the PHP exception and throw it in V8 instead
zend_clear_exception(TSRMLS_C);
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Module loader callback exception")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback exception")));
return;
}
@ -292,7 +292,7 @@ V8JS_METHOD(require)
efree(normalised_module_id);
efree(normalised_path);
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Module loader callback did not return code")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback did not return code")));
return;
}
@ -300,11 +300,11 @@ V8JS_METHOD(require)
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(V8JS_MN(print)), v8::ReadOnly);
global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(V8JS_MN(sleep)), v8::ReadOnly);
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(V8JS_MN(require), v8::External::New(c)), v8::ReadOnly);
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
// Add the exports object in which the module can return its API
v8::Handle<v8::ObjectTemplate> exports_template = v8::ObjectTemplate::New();
v8::Handle<v8::Object> exports = exports_template->NewInstance();
v8::Local<v8::ObjectTemplate> exports_template = v8::ObjectTemplate::New();
v8::Local<v8::Object> exports = exports_template->NewInstance();
global->Set(V8JS_SYM("exports"), exports);
// Add the module object in which the module can have more fine-grained control over what it can return
@ -322,7 +322,7 @@ V8JS_METHOD(require)
v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::EscapableHandleScope handle_scope(isolate);
// Enter the module context
v8::Context::Scope scope(context);
@ -339,7 +339,7 @@ V8JS_METHOD(require)
if (script.IsEmpty()) {
efree(normalised_module_id);
efree(normalised_path);
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Module script compile failed")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module script compile failed")));
return;
}
@ -360,7 +360,7 @@ V8JS_METHOD(require)
// Script possibly terminated, return immediately
if (!try_catch.CanContinue()) {
info.GetReturnValue().Set(v8::ThrowException(V8JS_SYM("Module script compile failed")));
info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module script compile failed")));
return;
}
@ -375,10 +375,10 @@ V8JS_METHOD(require)
// Ensure compatibility with CommonJS implementations such as NodeJS by playing nicely with module.exports and exports
if (module->Has(V8JS_SYM("exports")) && !module->Get(V8JS_SYM("exports"))->IsUndefined()) {
// If module.exports has been set then we cache this arbitrary value...
V8JSG(modules_loaded)[normalised_module_id] = handle_scope.Close(module->Get(V8JS_SYM("exports"))->ToObject());
V8JSG(modules_loaded)[normalised_module_id] = handle_scope.Escape(module->Get(V8JS_SYM("exports"))->ToObject());
} else {
// ...otherwise we cache the exports object itself
V8JSG(modules_loaded)[normalised_module_id] = handle_scope.Close(exports);
V8JSG(modules_loaded)[normalised_module_id] = handle_scope.Escape(exports);
}
info.GetReturnValue().Set(V8JSG(modules_loaded)[normalised_module_id]);
@ -393,7 +393,7 @@ void php_v8js_register_methods(v8::Handle<v8::ObjectTemplate> global, php_v8js_c
global->Set(V8JS_SYM("var_dump"), v8::FunctionTemplate::New(V8JS_MN(var_dump)), v8::ReadOnly);
c->modules_base.push_back("");
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(V8JS_MN(require), v8::External::New(c)), v8::ReadOnly);
global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(V8JS_MN(require), V8JS_NEW(v8::External, isolate, c)), v8::ReadOnly);
}
/* }}} */

View File

@ -86,7 +86,7 @@ void php_v8js_register_accessors(std::vector<php_v8js_accessor_ctx*> *accessor_l
ctx->isolate = isolate;
/* Set the variable fetch callback for given symbol on named property */
php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, v8::External::New(ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, v8::AccessorSignature::New(php_obj_t));
php_obj->SetAccessor(V8JS_STRL(property_name, property_name_len - 1), php_v8js_fetch_php_variable, NULL, V8JS_NEW(v8::External, isolate, ctx), v8::PROHIBITS_OVERWRITING, v8::ReadOnly, V8JS_NEW(v8::AccessorSignature, isolate, php_obj_t));
/* record the context so we can free it later */
accessor_list->push_back(ctx);