Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 87fd600

Browse files
committed
Replace Isolate::GetCurrentContext() with Isolate::GetEnteredContext()
1 parent af359b4 commit 87fd600

10 files changed

+20
-16
lines changed

src/php_v8_context.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ static void php_v8_context_free(zend_object *object)
3030
{
3131
php_v8_context_t *php_v8_context = php_v8_context_fetch_object(object);
3232

33-
// TODO: if we become weak, don't forget to remove stored `zval* this_ptr` to Context object
34-
3533
if (php_v8_context->context) {
3634
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_context)) {
35+
{
36+
PHP_V8_ENTER_STORED_ISOLATE(php_v8_context);
37+
PHP_V8_DECLARE_CONTEXT(php_v8_context);
38+
php_v8_context_store_reference(isolate, context, nullptr);
39+
}
40+
3741
php_v8_context->context->Reset();
3842
}
3943

src/php_v8_function_callback_info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value
3232
v8::Local<v8::Value> local_value;
3333

3434
v8::Isolate *isolate = args.GetIsolate();
35-
v8::Local<v8::Context> context = isolate->GetCurrentContext();
35+
v8::Local<v8::Context> context = isolate->GetEnteredContext();
3636

3737
if (context.IsEmpty()) {
3838
PHP_V8_THROW_EXCEPTION("Internal exception: no calling context found");

src/php_v8_isolate.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static PHP_METHOD(V8Isolate, InContext) {
360360
RETURN_BOOL(php_v8_isolate->isolate->InContext())
361361
}
362362

363-
static PHP_METHOD(V8Isolate, GetCurrentContext) {
363+
static PHP_METHOD(V8Isolate, GetEnteredContext) {
364364
if (zend_parse_parameters_none() == FAILURE) {
365365
return;
366366
}
@@ -370,8 +370,8 @@ static PHP_METHOD(V8Isolate, GetCurrentContext) {
370370

371371
PHP_V8_ISOLATE_REQUIRE_IN_CONTEXT(isolate);
372372

373-
v8::Local<v8::Context> local_context = php_v8_isolate->isolate->GetCurrentContext();
374-
373+
v8::Local<v8::Context> local_context = php_v8_isolate->isolate->GetEnteredContext();
374+
375375
php_v8_context_t *php_v8_context = php_v8_context_get_reference(local_context);
376376

377377
ZVAL_OBJ(return_value, &php_v8_context->std);
@@ -551,7 +551,7 @@ ZEND_END_ARG_INFO()
551551
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_isolate_InContext, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0)
552552
ZEND_END_ARG_INFO()
553553

554-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_isolate_GetCurrentContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0)
554+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_isolate_GetEnteredContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0)
555555
ZEND_END_ARG_INFO()
556556

557557
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_isolate_ThrowException, ZEND_RETURN_VALUE, 1, V8\\Value, 0)
@@ -610,7 +610,7 @@ static const zend_function_entry php_v8_isolate_methods[] = {
610610
PHP_ME(V8Isolate, GetHeapStatistics, arginfo_v8_isolate_GetHeapStatistics, ZEND_ACC_PUBLIC)
611611

612612
PHP_ME(V8Isolate, InContext, arginfo_v8_isolate_InContext, ZEND_ACC_PUBLIC)
613-
PHP_ME(V8Isolate, GetCurrentContext, arginfo_v8_isolate_GetCurrentContext, ZEND_ACC_PUBLIC)
613+
PHP_ME(V8Isolate, GetEnteredContext, arginfo_v8_isolate_GetEnteredContext, ZEND_ACC_PUBLIC)
614614

615615
PHP_ME(V8Isolate, ThrowException, arginfo_v8_isolate_ThrowException, ZEND_ACC_PUBLIC)
616616
PHP_ME(V8Isolate, IdleNotificationDeadline, arginfo_v8_isolate_IdleNotificationDeadline, ZEND_ACC_PUBLIC)

src/php_v8_message.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph
3030
object_init_ex(return_value, this_ce);
3131

3232
v8::Isolate *isolate = php_v8_isolate->isolate;
33-
v8::Local<v8::Context> context = isolate->GetCurrentContext();
33+
v8::Local<v8::Context> context = isolate->GetEnteredContext();
3434

3535
/* v8::Message::Get */
3636
if (!message->Get().IsEmpty()) {

src/php_v8_property_callback_info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ php_v8_return_value_t *php_v8_callback_info_create_from_info_meta(zval *return_v
5454
php_v8_return_value_t *php_v8_return_value;
5555

5656
v8::Isolate *isolate = args.GetIsolate();
57-
v8::Local<v8::Context> context = isolate->GetCurrentContext();
57+
v8::Local<v8::Context> context = isolate->GetEnteredContext();
5858

5959
if (context.IsEmpty()) {
6060
PHP_V8_THROW_EXCEPTION("Internal exception: no calling context found");

src/php_v8_try_catch.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void php_v8_try_catch_create_from_try_catch(zval *return_value, php_v8_isolate_t
3030
object_init_ex(return_value, this_ce);
3131

3232
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
33-
v8::Local<v8::Context> context = isolate->GetCurrentContext();
33+
v8::Local<v8::Context> context = isolate->GetEnteredContext();
3434

3535
ZVAL_OBJ(&isolate_zv, &php_v8_isolate->std);
3636
ZVAL_OBJ(&context_zv, &php_v8_context->std);

stubs/src/Isolate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ public function InContext() : bool
8282
}
8383

8484
/**
85-
* Returns the context that is on the top of the stack.
85+
* Returns the last entered context.
8686
*
8787
* @return \V8\Context
8888
*/
89-
public function GetCurrentContext() : Context
89+
public function GetEnteredContext() : Context
9090
{
9191
}
9292

stubs/src/Script.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function GetContext(): Context
5151
*
5252
* @param \V8\Context $context
5353
*
54-
* @return BooleanValue|FunctionObject|NumberValue|ObjectValue|StringValue|Value
54+
* @return BooleanValue | FunctionObject | NumberValue | ObjectValue | StringValue | Value
5555
*/
5656
public function Run(Context $context): Value
5757
{

tests/V8Isolate.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $helper->dump($isolate);
1717
$helper->line();
1818

1919
try {
20-
$isolate->GetCurrentContext();
20+
$isolate->GetEnteredContext();
2121
} catch (Exception $e) {
2222
$helper->exception_export($e);
2323
}

tests/V8ObjectTemplate_SetAccessCheckCallback.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ $AccessBlocker = function (\V8\Context $context, \V8\ObjectValue $object) use (&
4848
echo 'AccessBlocker called', PHP_EOL;
4949
// echo ' access ', ($allowed_access ? 'allowed' : 'denied'), PHP_EOL;
5050

51-
//return $isolate->GetCurrentContext()->GlobalObject()->Equals($isolate->GetCurrentContext(), $object) || $allowed_access;
51+
//return $isolate->GetEnteredContext()->GlobalObject()->Equals($isolate->GetCurrentContext(), $object) || $allowed_access;
5252
return true;
5353
};
5454

0 commit comments

Comments
 (0)