From 13e0b77015755b988aa0d80130facc7e04bd8ae6 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Mon, 24 Apr 2017 20:43:52 +0200 Subject: [PATCH] Fix left-over deprecated API calls. --- v8js_object_export.cc | 27 +++++++++++++++++++-------- v8js_timer.cc | 4 ++-- v8js_v8.cc | 10 ++++++---- v8js_v8object_class.cc | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/v8js_object_export.cc b/v8js_object_export.cc index 5bf36ad..254e0ed 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -438,10 +438,17 @@ static void v8js_invoke_callback(const v8::FunctionCallbackInfo& info new_tpl = v8::Local::New (isolate, ctx->template_cache.at(ce->name)); - result = new_tpl->GetFunction()->NewInstance(argc, argv); + v8::MaybeLocal maybeResult = new_tpl->GetFunction()->NewInstance(isolate->GetEnteredContext(), argc, argv); + + if (!maybeResult.IsEmpty()) { + result = maybeResult.ToLocalChecked(); + } else { + result = V8JS_UNDEFINED; + } } else { result = cb->Call(self, argc, argv); } + info.GetReturnValue().Set(result); } /* }}} */ @@ -804,7 +811,7 @@ static void v8js_named_property_deleter(v8::Local property, const v8 -static v8::Local v8js_wrap_object(v8::Isolate *isolate, zend_class_entry *ce, zval *value) /* {{{ */ +static v8::MaybeLocal v8js_wrap_object(v8::Isolate *isolate, zend_class_entry *ce, zval *value) /* {{{ */ { v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0); v8::Local new_tpl; @@ -903,11 +910,11 @@ static v8::Local v8js_wrap_object(v8::Isolate *isolate, zend_class_e // Create v8 wrapper object v8::Local external = v8::External::New(isolate, Z_OBJ_P(value)); - v8::Local newobj = new_tpl->GetFunction()->NewInstance(1, &external); + v8::MaybeLocal newobj = new_tpl->GetFunction()->NewInstance(isolate->GetEnteredContext(), 1, &external); - if (ce == zend_ce_closure) { + if (ce == zend_ce_closure && !newobj.IsEmpty()) { // free uncached function template when object is freed - ctx->weak_closures[persist_tpl_].Reset(isolate, newobj); + ctx->weak_closures[persist_tpl_].Reset(isolate, newobj.ToLocalChecked()); ctx->weak_closures[persist_tpl_].SetWeak(persist_tpl_, v8js_weak_closure_callback, v8::WeakCallbackType::kParameter); } @@ -1025,15 +1032,19 @@ v8::Local v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate) /* {{ /* If it's a PHP object, wrap it */ if (ce) { - v8::Local wrapped_object = v8js_wrap_object(isolate, ce, value); + v8::MaybeLocal wrapped_object = v8js_wrap_object(isolate, ce, value); + + if (wrapped_object.IsEmpty()) { + return V8JS_UNDEFINED; + } if (ce == zend_ce_generator) { /* Wrap PHP Generator object in a wrapper function that provides * ES6 style behaviour. */ - wrapped_object = v8js_wrap_generator(isolate, wrapped_object); + return v8js_wrap_generator(isolate, wrapped_object.ToLocalChecked()); } - return wrapped_object; + return wrapped_object.ToLocalChecked(); } /* Associative PHP arrays cannot be wrapped to JS arrays, convert them to diff --git a/v8js_timer.cc b/v8js_timer.cc index 965d865..185907f 100644 --- a/v8js_timer.cc +++ b/v8js_timer.cc @@ -67,7 +67,7 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /* if (timer_ctx->memory_limit > 0 && hs.used_heap_size() > timer_ctx->memory_limit) { if (has_sent_notification) { timer_ctx->killed = true; - v8::V8::TerminateExecution(c->isolate); + c->isolate->TerminateExecution(); c->memory_limit_hit = true; } else { // force garbage collection, then check again @@ -98,7 +98,7 @@ void v8js_timer_thread(zend_v8js_globals *globals) /* {{{ */ } else if(timer_ctx->time_limit > 0 && now > timer_ctx->time_point) { timer_ctx->killed = true; - v8::V8::TerminateExecution(c->isolate); + c->isolate->TerminateExecution(); c->time_limit_hit = true; } else if (timer_ctx->memory_limit > 0) { diff --git a/v8js_v8.cc b/v8js_v8.cc index f886f0c..607fb42 100644 --- a/v8js_v8.cc +++ b/v8js_v8.cc @@ -120,7 +120,7 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value, V8JSG(timer_mutex).unlock(); /* Catch JS exceptions */ - v8::TryCatch try_catch; + v8::TryCatch try_catch(isolate); /* Set flags for runtime use */ c->flags = flags; @@ -246,7 +246,7 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value, void v8js_terminate_execution(v8::Isolate *isolate) /* {{{ */ { - if(v8::V8::IsExecutionTerminating(isolate)) { + if(isolate->IsExecutionTerminating()) { /* Execution already terminating, needn't trigger it again and * especially must not execute the spinning loop (which would cause * crashes in V8 itself, at least with 4.2 and 4.3 version lines). */ @@ -264,7 +264,7 @@ void v8js_terminate_execution(v8::Isolate *isolate) /* {{{ */ v8::Local source = V8JS_STR("for(;;);"); v8::Local script = v8::Script::Compile(source); - v8::V8::TerminateExecution(isolate); + isolate->TerminateExecution(); script->Run(); } /* }}} */ @@ -282,7 +282,9 @@ int v8js_get_properties_hash(v8::Local jsValue, HashTable *retval, in v8::Local jsKey = jsKeys->Get(i)->ToString(); /* Skip any prototype properties */ - if (!jsObj->HasOwnProperty(jsKey) && !jsObj->HasRealNamedProperty(jsKey) && !jsObj->HasRealNamedCallbackProperty(jsKey)) { + if (!jsObj->HasOwnProperty(isolate->GetEnteredContext(), jsKey).FromMaybe(false) + && !jsObj->HasRealNamedProperty(jsKey) + && !jsObj->HasRealNamedCallbackProperty(jsKey)) { continue; } diff --git a/v8js_v8object_class.cc b/v8js_v8object_class.cc index 8814bc8..dcfc384 100644 --- a/v8js_v8object_class.cc +++ b/v8js_v8object_class.cc @@ -175,7 +175,7 @@ static void v8js_v8object_write_property(zval *object, zval *member, zval *value } if (v8obj->IsObject()) { - v8obj->ToObject()->ForceSet(V8JS_SYML(Z_STRVAL_P(member), static_cast(Z_STRLEN_P(member))), zval_to_v8js(value, isolate)); + v8obj->ToObject()->CreateDataProperty(v8_context, V8JS_SYML(Z_STRVAL_P(member), static_cast(Z_STRLEN_P(member))), zval_to_v8js(value, isolate)); } } /* }}} */