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

Commit 578955e

Browse files
committed
Require Context explicitly in V8\Isolate::ThrowException()
Breaks BC
1 parent d1c251a commit 578955e

File tree

8 files changed

+20
-22
lines changed

8 files changed

+20
-22
lines changed

src/php_v8_isolate.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,20 +374,23 @@ static PHP_METHOD(V8Isolate, GetEnteredContext) {
374374
}
375375

376376
static PHP_METHOD(V8Isolate, ThrowException) {
377+
zval *php_v8_context_zv;
377378
zval *php_v8_value_zv;
378379

379-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_value_zv) == FAILURE) {
380+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "oo", &php_v8_context_zv, &php_v8_value_zv) == FAILURE) {
380381
return;
381382
}
382383

383384
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
385+
386+
PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context);
384387
PHP_V8_VALUE_FETCH_WITH_CHECK(php_v8_value_zv, php_v8_value);
385388

389+
PHP_V8_DATA_ISOLATES_CHECK_USING(php_v8_context, php_v8_isolate);
386390
PHP_V8_DATA_ISOLATES_CHECK_USING(php_v8_value, php_v8_isolate);
387391

388-
PHP_V8_ENTER_ISOLATE(php_v8_isolate);
389-
390-
PHP_V8_ISOLATE_REQUIRE_IN_CONTEXT(isolate);
392+
PHP_V8_ENTER_STORED_ISOLATE(php_v8_context);
393+
PHP_V8_ENTER_CONTEXT(php_v8_context);
391394

392395
v8::Local<v8::Value> local_value = php_v8_value_get_local(php_v8_value);
393396
v8::Local<v8::Value> local_return_value = isolate->ThrowException(local_value);
@@ -549,7 +552,8 @@ ZEND_END_ARG_INFO()
549552
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_isolate_GetEnteredContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0)
550553
ZEND_END_ARG_INFO()
551554

552-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_isolate_ThrowException, ZEND_RETURN_VALUE, 1, V8\\Value, 0)
555+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_isolate_ThrowException, ZEND_RETURN_VALUE, 2, V8\\Value, 0)
556+
ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0)
553557
ZEND_ARG_OBJ_INFO(0, value, V8\\Value, 0)
554558
ZEND_END_ARG_INFO()
555559

stubs/src/Isolate.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ public function GetEnteredContext() : Context
9696
* operation; the caller must return immediately and only after the exception
9797
* has been handled does it become legal to invoke JavaScript operations.
9898
*
99-
* @param \V8\Value $value
99+
* @param Context $context
100+
* @param Value $value
100101
*
101-
* @return \V8\Value
102+
* @return Value
102103
*/
103-
public function ThrowException(Value $value) : Value
104+
public function ThrowException(Context $context, Value $value) : Value
104105
{
105106
}
106107

tests/V8Exception_Error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $helper->line();
2424
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
2525
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2626

27-
$e = $info->GetIsolate()->ThrowException(V8\Exception::Error($info->GetContext(), $value));
27+
$e = $info->GetIsolate()->ThrowException($info->GetContext(), V8\Exception::Error($info->GetContext(), $value));
2828

2929
$info->GetReturnValue()->Set($e);
3030
});

tests/V8Exception_RangeError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $helper->line();
2525
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
2626
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2727

28-
$e = $info->GetIsolate()->ThrowException(V8\Exception::RangeError($info->GetContext(), $value));
28+
$e = $info->GetIsolate()->ThrowException($info->GetContext(), V8\Exception::RangeError($info->GetContext(), $value));
2929

3030
$info->GetReturnValue()->Set($e);
3131
});

tests/V8Exception_ReferenceError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $helper->line();
2525
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
2626
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2727

28-
$e = $info->GetIsolate()->ThrowException(V8\Exception::ReferenceError($info->GetContext(), $value));
28+
$e = $info->GetIsolate()->ThrowException($info->GetContext(), V8\Exception::ReferenceError($info->GetContext(), $value));
2929

3030
$info->GetReturnValue()->Set($e);
3131
});

tests/V8Exception_SyntaxError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $helper->line();
2525
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
2626
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2727

28-
$e = $info->GetIsolate()->ThrowException(V8\Exception::SyntaxError($info->GetContext(), $value));
28+
$e = $info->GetIsolate()->ThrowException($info->GetContext(), V8\Exception::SyntaxError($info->GetContext(), $value));
2929

3030
$info->GetReturnValue()->Set($e);
3131
});

tests/V8Exception_TypeError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $helper->line();
2525
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
2626
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2727

28-
$e = $info->GetIsolate()->ThrowException(V8\Exception::TypeError($info->GetContext(), $value));
28+
$e = $info->GetIsolate()->ThrowException($info->GetContext(), V8\Exception::TypeError($info->GetContext(), $value));
2929

3030
$info->GetReturnValue()->Set($e);
3131
});

tests/V8Isolate_ThrowException.phpt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,12 @@ $v8_helper = new PhpV8Helpers($helper);
1313

1414
$isolate = new \V8\Isolate();
1515

16-
try {
17-
$isolate->ThrowException(new \V8\StringValue($isolate, 'test exception'));
18-
} catch (\Exception $e) {
19-
$helper->exception_export($e);
20-
}
21-
2216
$helper->line();
2317

2418
$func_tpl = new \V8\FunctionTemplate($isolate, function (\V8\FunctionCallbackInfo $info) {
2519
$value = count($info->Arguments()) ? $info->Arguments()[0] : new \V8\StringValue($info->GetIsolate(), "exception");
2620

27-
$e = $info->GetIsolate()->ThrowException($value);
21+
$e = $info->GetIsolate()->ThrowException($info->GetContext(), $value);
2822

2923
$info->GetReturnValue()->Set($e);
3024
});
@@ -36,6 +30,7 @@ $global_tpl->Set(new \V8\StringValue($isolate, 'print'), $v8_helper->getPrintFun
3630

3731
$context = new \V8\Context($isolate, $global_tpl);
3832

33+
3934
$v8_helper->CompileTryRun($context, 'e()');
4035
$v8_helper->CompileTryRun($context, 'e("test")');
4136

@@ -105,8 +100,6 @@ $v8_helper->run_checks($res);
105100

106101
?>
107102
--EXPECT--
108-
V8\Exceptions\GenericException: Not in context!
109-
110103
e(): V8\Exceptions\TryCatchException: exception
111104
e("test"): V8\Exceptions\TryCatchException: test
112105

0 commit comments

Comments
 (0)