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

Commit babba44

Browse files
committed
Rename TryCatch methods, #41
1 parent 3c84fe2 commit babba44

6 files changed

+34
-49
lines changed

src/php_v8_try_catch.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static PHP_METHOD(TryCatch, getContext)
151151
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("context"), 0, &rv), 1, 0);
152152
}
153153

154-
static PHP_METHOD(TryCatch, exception)
154+
static PHP_METHOD(TryCatch, getException)
155155
{
156156
zval rv;
157157
zval *prop;
@@ -165,7 +165,7 @@ static PHP_METHOD(TryCatch, exception)
165165
RETVAL_ZVAL(prop, 1, 0);
166166
}
167167

168-
static PHP_METHOD(TryCatch, stackTrace)
168+
static PHP_METHOD(TryCatch, getStackTrace)
169169
{
170170
zval rv;
171171
zval *prop;
@@ -179,7 +179,7 @@ static PHP_METHOD(TryCatch, stackTrace)
179179
RETVAL_ZVAL(prop, 1, 0);
180180
}
181181

182-
static PHP_METHOD(TryCatch, message)
182+
static PHP_METHOD(TryCatch, getMessage)
183183
{
184184
zval rv;
185185
zval *prop;
@@ -245,13 +245,13 @@ ZEND_END_ARG_INFO()
245245
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0)
246246
ZEND_END_ARG_INFO()
247247

248-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_exception, ZEND_RETURN_VALUE, 0, V8\\Value, 1)
248+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getException, ZEND_RETURN_VALUE, 0, V8\\Value, 1)
249249
ZEND_END_ARG_INFO()
250250

251-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_stackTrace, ZEND_RETURN_VALUE, 0, V8\\Value, 1)
251+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getStackTrace, ZEND_RETURN_VALUE, 0, V8\\Value, 1)
252252
ZEND_END_ARG_INFO()
253253

254-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_message, ZEND_RETURN_VALUE, 0, V8\\Message, 1)
254+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getMessage, ZEND_RETURN_VALUE, 0, V8\\Message, 1)
255255
ZEND_END_ARG_INFO()
256256

257257
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_canContinue, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0)
@@ -268,9 +268,9 @@ static const zend_function_entry php_v8_try_catch_methods[] = {
268268
PHP_V8_ME(TryCatch, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
269269
PHP_V8_ME(TryCatch, getIsolate, ZEND_ACC_PUBLIC)
270270
PHP_V8_ME(TryCatch, getContext, ZEND_ACC_PUBLIC)
271-
PHP_V8_ME(TryCatch, exception, ZEND_ACC_PUBLIC)
272-
PHP_V8_ME(TryCatch, stackTrace, ZEND_ACC_PUBLIC)
273-
PHP_V8_ME(TryCatch, message, ZEND_ACC_PUBLIC)
271+
PHP_V8_ME(TryCatch, getException, ZEND_ACC_PUBLIC)
272+
PHP_V8_ME(TryCatch, getStackTrace, ZEND_ACC_PUBLIC)
273+
PHP_V8_ME(TryCatch, getMessage, ZEND_ACC_PUBLIC)
274274
PHP_V8_ME(TryCatch, canContinue, ZEND_ACC_PUBLIC)
275275
PHP_V8_ME(TryCatch, hasTerminated, ZEND_ACC_PUBLIC)
276276

stubs/src/TryCatch.php

+3-18
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,20 @@ public function __construct(
7979
bool $has_terminated = false,
8080
Throwable $external_exception = null
8181
) {
82-
$this->isolate = $isolate;
83-
$this->exception = $exception;
84-
$this->stack_trace = $stack_trace;
85-
$this->message = $message;
86-
$this->can_continue = $can_continue;
87-
$this->has_terminated = $has_terminated;
88-
$this->external_exception = $external_exception;
8982
}
9083

9184
/**
9285
* @return Isolate
9386
*/
9487
public function getIsolate(): Isolate
9588
{
96-
return $this->isolate;
9789
}
9890

9991
/**
10092
* @return Context
10193
*/
10294
public function getContext(): Context
10395
{
104-
return $this->context;
10596
}
10697

10798
/**
@@ -113,9 +104,8 @@ public function getContext(): Context
113104
* @return Value|null
114105
*
115106
*/
116-
public function exception(): ?Value
107+
public function getException(): ?Value
117108
{
118-
return $this->exception;
119109
}
120110

121111
/**
@@ -124,9 +114,8 @@ public function exception(): ?Value
124114
*
125115
* @return Value|null
126116
*/
127-
public function stackTrace(): ?Value
117+
public function getStackTrace(): ?Value
128118
{
129-
return $this->stack_trace;
130119
}
131120

132121
/**
@@ -138,9 +127,8 @@ public function stackTrace(): ?Value
138127
*
139128
* @return Message|null
140129
*/
141-
public function message(): ?Message
130+
public function getMessage(): ?Message
142131
{
143-
return $this->message;
144132
}
145133

146134
/**
@@ -155,7 +143,6 @@ public function message(): ?Message
155143
*/
156144
public function canContinue(): bool
157145
{
158-
return $this->can_continue;
159146
}
160147

161148
/**
@@ -174,14 +161,12 @@ public function canContinue(): bool
174161
*/
175162
public function hasTerminated(): bool
176163
{
177-
return $this->has_terminated;
178164
}
179165

180166
/**
181167
* @return null|Throwable
182168
*/
183169
public function getExternalException(): ?Throwable
184170
{
185-
return $this->external_exception;
186171
}
187172
}

tests/001-verify_extension_entities.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ class V8\TryCatch
432432
public function __construct(V8\Isolate $isolate, V8\Context $context, ?V8\Value $exception, ?V8\Value $stack_trace, ?V8\Message $message, bool $can_continue, bool $has_terminated, ?Throwable $external_exception)
433433
public function getIsolate(): V8\Isolate
434434
public function getContext(): V8\Context
435-
public function exception(): ?V8\Value
436-
public function stackTrace(): ?V8\Value
437-
public function message(): ?V8\Message
435+
public function getException(): ?V8\Value
436+
public function getStackTrace(): ?V8\Value
437+
public function getMessage(): ?V8\Message
438438
public function canContinue(): bool
439439
public function hasTerminated(): bool
440440
public function getExternalException(): ?Throwable

tests/Isolate_throwException_with_external.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ try {
4141
} catch (\V8\Exceptions\TryCatchException $e) {
4242
$helper->exception_export($e);
4343

44-
$helper->assert('Thrown exception object is the same', $e->getTryCatch()->exception(), $v8_exception);
44+
$helper->assert('Thrown exception object is the same', $e->getTryCatch()->getException(), $v8_exception);
4545

4646
$helper->exception_export($e->getTryCatch()->getExternalException());
4747
}

tests/TryCatch.phpt

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ $helper->space();
2626
$helper->header('Test getters (default)');
2727
$helper->method_matches($obj, 'getIsolate', $isolate);
2828
$helper->method_matches($obj, 'getContext', $context);
29-
$helper->method_matches($obj, 'exception', null);
30-
$helper->method_matches($obj, 'message', null);
31-
$helper->method_matches($obj, 'stackTrace', null);
29+
$helper->method_matches($obj, 'getException', null);
30+
$helper->method_matches($obj, 'getMessage', null);
31+
$helper->method_matches($obj, 'getStackTrace', null);
3232

3333
$helper->method_matches($obj, 'canContinue', false);
3434
$helper->method_matches($obj, 'hasTerminated', false);
@@ -49,9 +49,9 @@ $helper->space();
4949
$helper->header('Test getters');
5050
$helper->method_matches($obj, 'getIsolate', $isolate);
5151
$helper->method_matches($obj, 'getContext', $context);
52-
$helper->method_matches($obj, 'exception', $exception);
53-
$helper->method_matches($obj, 'message', $message);
54-
$helper->method_matches($obj, 'stackTrace', $trace);
52+
$helper->method_matches($obj, 'getException', $exception);
53+
$helper->method_matches($obj, 'getMessage', $message);
54+
$helper->method_matches($obj, 'getStackTrace', $trace);
5555

5656
$helper->method_matches($obj, 'canContinue', true);
5757
$helper->method_matches($obj, 'hasTerminated', true);
@@ -104,9 +104,9 @@ Test getters (default):
104104
-----------------------
105105
V8\TryCatch::getIsolate() matches expected value
106106
V8\TryCatch::getContext() matches expected value
107-
V8\TryCatch::exception() matches expected value
108-
V8\TryCatch::message() matches expected value
109-
V8\TryCatch::stackTrace() matches expected value
107+
V8\TryCatch::getException() matches expected value
108+
V8\TryCatch::getMessage() matches expected value
109+
V8\TryCatch::getStackTrace() matches expected value
110110
V8\TryCatch::canContinue() matches expected value
111111
V8\TryCatch::hasTerminated() matches expected value
112112

@@ -215,9 +215,9 @@ Test getters:
215215
-------------
216216
V8\TryCatch::getIsolate() matches expected value
217217
V8\TryCatch::getContext() matches expected value
218-
V8\TryCatch::exception() matches expected value
219-
V8\TryCatch::message() matches expected value
220-
V8\TryCatch::stackTrace() matches expected value
218+
V8\TryCatch::getException() matches expected value
219+
V8\TryCatch::getMessage() matches expected value
220+
V8\TryCatch::getStackTrace() matches expected value
221221
V8\TryCatch::canContinue() matches expected value
222222
V8\TryCatch::hasTerminated() matches expected value
223223
V8\TryCatch::getExternalException() matches expected value

tests/TryCatch_from_script.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ $nested_try_catch_func_tpl = new \v8Tests\TrackingDtors\FunctionTemplate($isolat
4444
$helper->assert('TryCatch holds the same isolate it was thrown', $try_catch->getIsolate(), $isolate);
4545
$helper->assert('TryCatch holds the same context it was thrown', $try_catch->getContext(), $nested_context);
4646

47-
$helper->dump($e->getTryCatch()->message()->get());
47+
$helper->dump($e->getTryCatch()->getMessage()->get());
4848
$helper->line();
4949
}
5050
});
@@ -72,10 +72,10 @@ try {
7272
$helper->assert('TryCatch holds the same isolate it was thrown', $try_catch->getIsolate(), $script->getIsolate());
7373
$helper->assert('TryCatch holds the same context it was thrown', $try_catch->getContext(), $script->getContext());
7474

75-
$helper->dump($e->getTryCatch()->message()->get());
75+
$helper->dump($e->getTryCatch()->getMessage()->get());
7676

7777
$helper->line();
78-
$helper->assert('TryCatchException message has not stack trace', $e->getTryCatch()->message()->getStackTrace() === null);
78+
$helper->assert('TryCatchException message has not stack trace', $e->getTryCatch()->getMessage()->getStackTrace() === null);
7979
$helper->line();
8080
}
8181

@@ -87,7 +87,7 @@ try {
8787
$helper->exception_export($e);
8888
$helper->line();
8989

90-
$helper->assert('TryCatchException message has stack trace', $e->getTryCatch()->message()->getStackTrace() instanceof \V8\StackTrace);
90+
$helper->assert('TryCatchException message has stack trace', $e->getTryCatch()->getMessage()->getStackTrace() instanceof \V8\StackTrace);
9191
$helper->line();
9292
}
9393

@@ -115,7 +115,7 @@ try {
115115
$helper->assert('TryCatch holds the same isolate it was thrown', $try_catch->getIsolate(), $script->getIsolate());
116116
$helper->assert('TryCatch holds the same context it was thrown', $try_catch->getContext(), $script->getContext());
117117

118-
$helper->dump($e->getTryCatch()->message()->get());
118+
$helper->dump($e->getTryCatch()->getMessage()->get());
119119
$helper->line();
120120
}
121121

@@ -129,7 +129,7 @@ try {
129129
$helper->assert('TryCatchException holds the same context it was thrown', $e->getContext(), $context);
130130
$helper->assert('TryCatchException holds the same isolate it was thrown', $e->getIsolate(), $isolate);
131131

132-
$helper->dump($e->getTryCatch()->message()->get());
132+
$helper->dump($e->getTryCatch()->getMessage()->get());
133133
$helper->line();
134134
}
135135

0 commit comments

Comments
 (0)