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

Commit 37ad9e3

Browse files
committed
Add StackFrame::isWasm(), closes #53
1 parent f4a84c5 commit 37ad9e3

6 files changed

+63
-26
lines changed

src/php_v8_stack_frame.cc

+24-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ void php_v8_stack_frame_create_from_stack_frame(v8::Isolate *isolate, zval *retu
6060

6161
/* v8::StackFrame::IsConstructor */
6262
zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_constructor"), static_cast<zend_bool >(frame->IsConstructor()));
63+
64+
/* v8::StackFrame::IsWasm */
65+
zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_wasm"), static_cast<zend_bool >(frame->IsWasm()));
6366
}
6467

6568
static PHP_METHOD(StackFrame, __construct) {
@@ -73,11 +76,12 @@ static PHP_METHOD(StackFrame, __construct) {
7376

7477
zend_bool is_eval = '\0';
7578
zend_bool is_constructor = '\0';
79+
zend_bool is_wasm = '\0';
7680

77-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lllSSSbb",
81+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lllSSSbbb",
7882
&line_number, &column, &script_id,
7983
&script_name, &script_name_or_source_url, &function_name,
80-
&is_eval, &is_constructor) == FAILURE) {
84+
&is_eval, &is_constructor, &is_wasm) == FAILURE) {
8185
return;
8286
}
8387

@@ -105,6 +109,7 @@ static PHP_METHOD(StackFrame, __construct) {
105109

106110
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_eval"), is_eval);
107111
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_constructor"), is_constructor);
112+
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_wasm"), is_wasm);
108113
}
109114

110115
static PHP_METHOD(StackFrame, getLineNumber) {
@@ -187,6 +192,17 @@ static PHP_METHOD(StackFrame, isConstructor) {
187192
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("is_constructor"), 0, &rv), 1, 0);
188193
}
189194

195+
static PHP_METHOD(StackFrame, isWasm) {
196+
zval rv;
197+
198+
if (zend_parse_parameters_none() == FAILURE) {
199+
return;
200+
}
201+
202+
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("is_wasm"), 0, &rv), 1, 0);
203+
}
204+
205+
190206
PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 0)
191207
ZEND_ARG_TYPE_INFO(0, line_number, IS_LONG, 1)
192208
ZEND_ARG_TYPE_INFO(0, column, IS_LONG, 1)
@@ -196,6 +212,7 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 0)
196212
ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0)
197213
ZEND_ARG_TYPE_INFO(0, is_eval, _IS_BOOL, 0)
198214
ZEND_ARG_TYPE_INFO(0, is_constructor, _IS_BOOL, 0)
215+
ZEND_ARG_TYPE_INFO(0, is_wasm, _IS_BOOL, 0)
199216
ZEND_END_ARG_INFO()
200217

201218
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getLineNumber, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
@@ -222,6 +239,9 @@ ZEND_END_ARG_INFO()
222239
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_isConstructor, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0)
223240
ZEND_END_ARG_INFO()
224241

242+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_isWasm, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0)
243+
ZEND_END_ARG_INFO()
244+
225245

226246
static const zend_function_entry php_v8_stack_frame_methods[] = {
227247
PHP_V8_ME(StackFrame, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
@@ -233,6 +253,7 @@ static const zend_function_entry php_v8_stack_frame_methods[] = {
233253
PHP_V8_ME(StackFrame, getFunctionName, ZEND_ACC_PUBLIC)
234254
PHP_V8_ME(StackFrame, isEval, ZEND_ACC_PUBLIC)
235255
PHP_V8_ME(StackFrame, isConstructor, ZEND_ACC_PUBLIC)
256+
PHP_V8_ME(StackFrame, isWasm, ZEND_ACC_PUBLIC)
236257

237258
PHP_FE_END
238259
};
@@ -253,6 +274,7 @@ PHP_MINIT_FUNCTION (php_v8_stack_frame) {
253274

254275
zend_declare_property_bool(this_ce, ZEND_STRL("is_eval"), static_cast<zend_bool>(false), ZEND_ACC_PRIVATE);
255276
zend_declare_property_bool(this_ce, ZEND_STRL("is_constructor"), static_cast<zend_bool>(false), ZEND_ACC_PRIVATE);
277+
zend_declare_property_bool(this_ce, ZEND_STRL("is_wasm"), static_cast<zend_bool>(false), ZEND_ACC_PRIVATE);
256278

257279
return SUCCESS;
258280
}

stubs/src/StackFrame.php

+16-17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class StackFrame
5252
* @var bool
5353
*/
5454
private $is_constructor;
55+
/**
56+
* @var bool
57+
*/
58+
private $is_wasm;
5559

5660
/**
5761
* @param int|null $line_number
@@ -62,6 +66,7 @@ class StackFrame
6266
* @param string $function_name
6367
* @param bool $is_eval
6468
* @param bool $is_constructor
69+
* @param bool $is_wasm
6570
*/
6671
public function __construct(
6772
?int $line_number = null,
@@ -71,16 +76,9 @@ public function __construct(
7176
string $script_name_or_source_url = '',
7277
string $function_name = '',
7378
bool $is_eval = false,
74-
bool $is_constructor = false
79+
bool $is_constructor = false,
80+
bool $is_wasm = false
7581
) {
76-
$this->line_number = $line_number;
77-
$this->column = $column;
78-
$this->script_id = $script_id;
79-
$this->script_name = $script_name;
80-
$this->script_name_or_source_url = $script_name_or_source_url;
81-
$this->function_name = $function_name;
82-
$this->is_eval = $is_eval;
83-
$this->is_constructor = $is_constructor;
8482
}
8583

8684
/**
@@ -93,7 +91,6 @@ public function __construct(
9391
*/
9492
public function getLineNumber(): ?int
9593
{
96-
return $this->line_number;
9794
}
9895

9996
/**
@@ -107,7 +104,6 @@ public function getLineNumber(): ?int
107104
*/
108105
public function getColumn(): ?int
109106
{
110-
return $this->column;
111107
}
112108

113109
/**
@@ -120,7 +116,6 @@ public function getColumn(): ?int
120116
*/
121117
public function getScriptId(): ?int
122118
{
123-
return $this->script_id;
124119
}
125120

126121
/**
@@ -131,7 +126,6 @@ public function getScriptId(): ?int
131126
*/
132127
public function getScriptName(): string
133128
{
134-
return $this->script_name;
135129
}
136130

137131
/**
@@ -144,7 +138,6 @@ public function getScriptName(): string
144138
*/
145139
public function getScriptNameOrSourceURL(): string
146140
{
147-
return $this->script_name_or_source_url;
148141
}
149142

150143
/**
@@ -154,7 +147,6 @@ public function getScriptNameOrSourceURL(): string
154147
*/
155148
public function getFunctionName(): string
156149
{
157-
return $this->function_name;
158150
}
159151

160152
/**
@@ -165,7 +157,6 @@ public function getFunctionName(): string
165157
*/
166158
public function isEval(): bool
167159
{
168-
return $this->is_eval;
169160
}
170161

171162
/**
@@ -176,6 +167,14 @@ public function isEval(): bool
176167
*/
177168
public function isConstructor(): bool
178169
{
179-
return $this->is_constructor;
170+
}
171+
172+
/**
173+
* Returns whether or not the associated functions is defined in wasm.
174+
*
175+
* @return bool
176+
*/
177+
public function isWasm(): bool
178+
{
180179
}
181180
}

tests/001-verify_extension_entities.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ class V8\StackFrame
470470
private $function_name
471471
private $is_eval
472472
private $is_constructor
473-
public function __construct(?int $line_number, ?int $column, ?int $script_id, string $script_name, string $script_name_or_source_url, string $function_name, bool $is_eval, bool $is_constructor)
473+
private $is_wasm
474+
public function __construct(?int $line_number, ?int $column, ?int $script_id, string $script_name, string $script_name_or_source_url, string $function_name, bool $is_eval, bool $is_constructor, bool $is_wasm)
474475
public function getLineNumber(): ?int
475476
public function getColumn(): ?int
476477
public function getScriptId(): ?int
@@ -479,6 +480,7 @@ class V8\StackFrame
479480
public function getFunctionName(): string
480481
public function isEval(): bool
481482
public function isConstructor(): bool
483+
public function isWasm(): bool
482484

483485
class V8\StackTrace
484486
const MIN_FRAME_LIMIT = 0

tests/ExceptionManager_createGetStackTrace.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Stack trace created from thrown value:
116116
V8\StackTrace->getFrames():
117117
array(1) {
118118
[0]=>
119-
object(V8\StackFrame)#14 (8) {
119+
object(V8\StackFrame)#14 (9) {
120120
["line_number":"V8\StackFrame":private]=>
121121
int(5)
122122
["column":"V8\StackFrame":private]=>
@@ -133,6 +133,8 @@ V8\StackTrace->getFrames():
133133
bool(false)
134134
["is_constructor":"V8\StackFrame":private]=>
135135
bool(false)
136+
["is_wasm":"V8\StackFrame":private]=>
137+
bool(false)
136138
}
137139
}
138140
V8\StackTrace->getFrameCount(): int(1)

tests/StackFrame.phpt

+11-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ $helper->method_matches_with_output($obj, 'getScriptNameOrSourceURL', '');
2525
$helper->method_matches_with_output($obj, 'getFunctionName', '');
2626
$helper->method_matches_with_output($obj, 'isEval', false);
2727
$helper->method_matches_with_output($obj, 'isConstructor', false);
28+
$helper->method_matches_with_output($obj, 'isWasm', false);
2829
$helper->space();
2930

3031

31-
$obj = new V8\StackFrame(1, 2, 3, 'script_name', 'script_name_or_source_url', 'function_name', true, true);
32+
$obj = new V8\StackFrame(1, 2, 3, 'script_name', 'script_name_or_source_url', 'function_name', true, true, true);
3233

3334

3435
$helper->header('Object representation');
@@ -44,13 +45,14 @@ $helper->method_matches_with_output($obj, 'getScriptNameOrSourceURL', 'script_na
4445
$helper->method_matches_with_output($obj, 'getFunctionName', 'function_name');
4546
$helper->method_matches_with_output($obj, 'isEval', true);
4647
$helper->method_matches_with_output($obj, 'isConstructor', true);
48+
$helper->method_matches_with_output($obj, 'isWasm', true);
4749
$helper->space();
4850

4951
?>
5052
--EXPECT--
5153
Object representation (default):
5254
--------------------------------
53-
object(V8\StackFrame)#2 (8) {
55+
object(V8\StackFrame)#2 (9) {
5456
["line_number":"V8\StackFrame":private]=>
5557
NULL
5658
["column":"V8\StackFrame":private]=>
@@ -67,6 +69,8 @@ object(V8\StackFrame)#2 (8) {
6769
bool(false)
6870
["is_constructor":"V8\StackFrame":private]=>
6971
bool(false)
72+
["is_wasm":"V8\StackFrame":private]=>
73+
bool(false)
7074
}
7175

7276

@@ -80,11 +84,12 @@ V8\StackFrame::getScriptNameOrSourceURL() matches expected ''
8084
V8\StackFrame::getFunctionName() matches expected ''
8185
V8\StackFrame::isEval() matches expected false
8286
V8\StackFrame::isConstructor() matches expected false
87+
V8\StackFrame::isWasm() matches expected false
8388

8489

8590
Object representation:
8691
----------------------
87-
object(V8\StackFrame)#3 (8) {
92+
object(V8\StackFrame)#3 (9) {
8893
["line_number":"V8\StackFrame":private]=>
8994
int(1)
9095
["column":"V8\StackFrame":private]=>
@@ -101,6 +106,8 @@ object(V8\StackFrame)#3 (8) {
101106
bool(true)
102107
["is_constructor":"V8\StackFrame":private]=>
103108
bool(true)
109+
["is_wasm":"V8\StackFrame":private]=>
110+
bool(true)
104111
}
105112

106113

@@ -114,3 +121,4 @@ V8\StackFrame::getScriptNameOrSourceURL() matches expected 'script_name_or_sourc
114121
V8\StackFrame::getFunctionName() matches expected 'function_name'
115122
V8\StackFrame::isEval() matches expected true
116123
V8\StackFrame::isConstructor() matches expected true
124+
V8\StackFrame::isWasm() matches expected true

tests/StackTrace.phpt

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object(V8\StackTrace)#7 (1) {
5454
["frames":"V8\StackTrace":private]=>
5555
array(2) {
5656
[0]=>
57-
object(V8\StackFrame)#5 (8) {
57+
object(V8\StackFrame)#5 (9) {
5858
["line_number":"V8\StackFrame":private]=>
5959
int(1)
6060
["column":"V8\StackFrame":private]=>
@@ -71,9 +71,11 @@ object(V8\StackTrace)#7 (1) {
7171
bool(false)
7272
["is_constructor":"V8\StackFrame":private]=>
7373
bool(false)
74+
["is_wasm":"V8\StackFrame":private]=>
75+
bool(false)
7476
}
7577
[1]=>
76-
object(V8\StackFrame)#6 (8) {
78+
object(V8\StackFrame)#6 (9) {
7779
["line_number":"V8\StackFrame":private]=>
7880
int(2)
7981
["column":"V8\StackFrame":private]=>
@@ -90,6 +92,8 @@ object(V8\StackTrace)#7 (1) {
9092
bool(false)
9193
["is_constructor":"V8\StackFrame":private]=>
9294
bool(false)
95+
["is_wasm":"V8\StackFrame":private]=>
96+
bool(false)
9397
}
9498
}
9599
}

0 commit comments

Comments
 (0)