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

Commit 3bb76f8

Browse files
committed
Remove no-data constants and use NULL instead, closes #40
1 parent fb3482c commit 3bb76f8

18 files changed

+267
-233
lines changed

src/php_v8_message.cc

+48-35
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph
7070
if (!message->GetLineNumber(context).IsNothing()) {
7171
line_number = message->GetLineNumber(context).FromJust();
7272
}
73-
zend_update_property_long(this_ce, return_value, ZEND_STRL("line_number"), static_cast<zend_long>(line_number));
73+
74+
if (v8::Message::kNoLineNumberInfo != line_number) {
75+
zend_update_property_long(this_ce, return_value, ZEND_STRL("line_number"), static_cast<zend_long>(line_number));
76+
}
7477

7578
/* v8::Message::GetStartPosition */
7679
zend_update_property_long(this_ce, return_value, ZEND_STRL("start_position"), static_cast<zend_long>(message->GetStartPosition()));
@@ -85,15 +88,19 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph
8588
start_column = message->GetStartColumn(context).FromJust();
8689
}
8790

88-
zend_update_property_long(this_ce, return_value, ZEND_STRL("start_column"), static_cast<zend_long>(start_column));
91+
if (v8::Message::kNoColumnInfo != start_column) {
92+
zend_update_property_long(this_ce, return_value, ZEND_STRL("start_column"), static_cast<zend_long>(start_column));
93+
}
8994

9095
/* v8::Message::GetEndColumn */
9196
/* NOTE: we don't use FromMaybe(v8::Message::kNoColumnInfo) due to static const (https://gcc.gnu.org/wiki/VerboseDiagnostics#missing_static_const_definition)*/
9297
int end_column = v8::Message::kNoColumnInfo;
9398
if (!message->GetEndColumn(context).IsNothing()) {
9499
end_column = message->GetEndColumn(context).FromJust();
95100
}
96-
zend_update_property_long(this_ce, return_value, ZEND_STRL("end_column"), static_cast<zend_long>(end_column));
101+
if (v8::Message::kNoColumnInfo != end_column) {
102+
zend_update_property_long(this_ce, return_value, ZEND_STRL("end_column"), static_cast<zend_long>(end_column));
103+
}
97104

98105
/* v8::Message::IsSharedCrossOrigin */
99106
zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_shared_cross_origin"), static_cast<zend_bool>(message->IsSharedCrossOrigin()));
@@ -110,11 +117,11 @@ static PHP_METHOD(Message, __construct) {
110117
zend_string *resource_name = NULL;
111118
zval *stack_trace = NULL;
112119

113-
zend_long line_number = static_cast<zend_long>(v8::Message::kNoLineNumberInfo);
120+
zend_long line_number = -1;
114121
zend_long start_position = -1;
115-
zend_long end_position = -1;
116-
zend_long start_column = static_cast<zend_long>(v8::Message::kNoColumnInfo);
117-
zend_long end_column = static_cast<zend_long>(v8::Message::kNoColumnInfo);
122+
zend_long end_position = -1;
123+
zend_long start_column = -1;
124+
zend_long end_column = -1;
118125

119126
zend_bool is_shared_cross_origin = '\0';
120127
zend_bool is_opaque = '\0';
@@ -132,11 +139,21 @@ static PHP_METHOD(Message, __construct) {
132139
zend_update_property_str(this_ce, getThis(), ZEND_STRL("resource_name"), resource_name);
133140
zend_update_property(this_ce, getThis(), ZEND_STRL("stack_trace"), stack_trace);
134141

135-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("line_number"), line_number);
136-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("start_position"), start_position);
137-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("end_position"), end_position);
138-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("start_column"), start_column);
139-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("end_column"), end_column);
142+
if (line_number > 0) {
143+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("line_number"), line_number);
144+
}
145+
if (start_position >= 0) {
146+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("start_position"), start_position);
147+
}
148+
if (end_position >= 0) {
149+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("end_position"), end_position);
150+
}
151+
if (start_column > 0) {
152+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("start_column"), start_column);
153+
}
154+
if (end_column > 0) {
155+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("end_column"), end_column);
156+
}
140157

141158
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_shared_cross_origin"), is_shared_cross_origin);
142159
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_opaque"), is_opaque);
@@ -280,11 +297,11 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 5)
280297
ZEND_ARG_OBJ_INFO(0, script_origin, V8\\ScriptOrigin, 0)
281298
ZEND_ARG_TYPE_INFO(0, resource_name, IS_STRING, 0)
282299
ZEND_ARG_OBJ_INFO(0, stack_trace, V8\\StackTrace, 0)
283-
ZEND_ARG_TYPE_INFO(0, line_number, IS_LONG, 0)
284-
ZEND_ARG_TYPE_INFO(0, start_position, IS_LONG, 0)
285-
ZEND_ARG_TYPE_INFO(0, end_position, IS_LONG, 0)
286-
ZEND_ARG_TYPE_INFO(0, start_column, IS_LONG, 0)
287-
ZEND_ARG_TYPE_INFO(0, end_column, IS_LONG, 0)
300+
ZEND_ARG_TYPE_INFO(0, line_number, IS_LONG, 1)
301+
ZEND_ARG_TYPE_INFO(0, start_position, IS_LONG, 1)
302+
ZEND_ARG_TYPE_INFO(0, end_position, IS_LONG, 1)
303+
ZEND_ARG_TYPE_INFO(0, start_column, IS_LONG, 1)
304+
ZEND_ARG_TYPE_INFO(0, end_column, IS_LONG, 1)
288305
ZEND_ARG_TYPE_INFO(0, is_shared_cross_origin, _IS_BOOL, 0)
289306
ZEND_ARG_TYPE_INFO(0, is_opaque, _IS_BOOL, 0)
290307
ZEND_END_ARG_INFO()
@@ -304,19 +321,19 @@ ZEND_END_ARG_INFO()
304321
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getStackTrace, ZEND_RETURN_VALUE, 0, V8\\StackTrace, 1)
305322
ZEND_END_ARG_INFO()
306323

307-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getLineNumber, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
324+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getLineNumber, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
308325
ZEND_END_ARG_INFO()
309326

310-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getStartPosition, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
327+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getStartPosition, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
311328
ZEND_END_ARG_INFO()
312329

313-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getEndPosition, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
330+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getEndPosition, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
314331
ZEND_END_ARG_INFO()
315332

316-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getStartColumn, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
333+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getStartColumn, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
317334
ZEND_END_ARG_INFO()
318335

319-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getEndColumn, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
336+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getEndColumn, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
320337
ZEND_END_ARG_INFO()
321338

322339
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_isSharedCrossOrigin, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0)
@@ -349,22 +366,18 @@ PHP_MINIT_FUNCTION (php_v8_message) {
349366
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "Message", php_v8_message_methods);
350367
this_ce = zend_register_internal_class(&ce);
351368

352-
zend_declare_class_constant_long(this_ce, ZEND_STRL("kNoLineNumberInfo"), static_cast<zend_long>(v8::Message::kNoLineNumberInfo));
353-
zend_declare_class_constant_long(this_ce, ZEND_STRL("kNoColumnInfo"), static_cast<zend_long>(v8::Message::kNoColumnInfo));
354-
zend_declare_class_constant_long(this_ce, ZEND_STRL("kNoScriptIdInfo"), static_cast<zend_long>(v8::Message::kNoLineNumberInfo));
355-
356-
zend_declare_property_string(this_ce, ZEND_STRL("message"), "", ZEND_ACC_PRIVATE);
357-
zend_declare_property_null(this_ce, ZEND_STRL("script_origin"), ZEND_ACC_PRIVATE);
358-
zend_declare_property_string(this_ce, ZEND_STRL("source_line"), "", ZEND_ACC_PRIVATE);
369+
zend_declare_property_string(this_ce, ZEND_STRL("message"), "", ZEND_ACC_PRIVATE);
370+
zend_declare_property_null(this_ce, ZEND_STRL("script_origin"), ZEND_ACC_PRIVATE);
371+
zend_declare_property_string(this_ce, ZEND_STRL("source_line"), "", ZEND_ACC_PRIVATE);
359372
zend_declare_property_string(this_ce, ZEND_STRL("resource_name"), "", ZEND_ACC_PRIVATE);
360-
zend_declare_property_null(this_ce, ZEND_STRL("stack_trace"), ZEND_ACC_PRIVATE);
373+
zend_declare_property_null(this_ce, ZEND_STRL("stack_trace"), ZEND_ACC_PRIVATE);
361374

362-
zend_declare_property_long(this_ce, ZEND_STRL("line_number"), static_cast<zend_long>(v8::Message::kNoLineNumberInfo), ZEND_ACC_PRIVATE);
363-
zend_declare_property_long(this_ce, ZEND_STRL("start_position"), -1, ZEND_ACC_PRIVATE);
364-
zend_declare_property_long(this_ce, ZEND_STRL("end_position"), -1, ZEND_ACC_PRIVATE);
375+
zend_declare_property_null(this_ce, ZEND_STRL("line_number"), ZEND_ACC_PRIVATE);
376+
zend_declare_property_null(this_ce, ZEND_STRL("start_position"), ZEND_ACC_PRIVATE);
377+
zend_declare_property_null(this_ce, ZEND_STRL("end_position"), ZEND_ACC_PRIVATE);
365378

366-
zend_declare_property_long(this_ce, ZEND_STRL("start_column"), static_cast<zend_long>(v8::Message::kNoColumnInfo), ZEND_ACC_PRIVATE);
367-
zend_declare_property_long(this_ce, ZEND_STRL("end_column"), static_cast<zend_long>(v8::Message::kNoColumnInfo), ZEND_ACC_PRIVATE);
379+
zend_declare_property_null(this_ce, ZEND_STRL("start_column"), ZEND_ACC_PRIVATE);
380+
zend_declare_property_null(this_ce, ZEND_STRL("end_column"), ZEND_ACC_PRIVATE);
368381

369382
zend_declare_property_bool(this_ce, ZEND_STRL("is_shared_cross_origin"), static_cast<zend_bool>(false), ZEND_ACC_PRIVATE);
370383
zend_declare_property_bool(this_ce, ZEND_STRL("is_opaque"), static_cast<zend_bool>(false), ZEND_ACC_PRIVATE);

src/php_v8_script_origin.cc

+39-24
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ extern void php_v8_create_script_origin(zval *return_value, v8::Local<v8::Contex
3737

3838
/* v8::SourceMapUrl::ResourceLineOffset */
3939
if (!origin.ResourceLineOffset().IsEmpty() && origin.ResourceLineOffset()->NumberValue(context).IsJust()) {
40-
zend_update_property_long(this_ce, return_value, ZEND_STRL("resource_line_offset"), static_cast<zend_long>(origin.ResourceLineOffset()->NumberValue(context).FromJust()));
40+
zend_long resource_line_offset = static_cast<zend_long>(origin.ResourceLineOffset()->NumberValue(context).FromJust());
41+
if (v8::Message::kNoLineNumberInfo != resource_line_offset) {
42+
zend_update_property_long(this_ce, return_value, ZEND_STRL("resource_line_offset"), resource_line_offset);
43+
}
4144
}
4245

4346
/* v8::SourceMapUrl::ResourceColumnOffset */
4447
if (!origin.ResourceColumnOffset().IsEmpty() && origin.ResourceColumnOffset()->NumberValue(context).IsJust()) {
45-
zend_update_property_long(this_ce, return_value, ZEND_STRL("resource_column_offset"), static_cast<zend_long>(origin.ResourceColumnOffset()->NumberValue(context).FromJust()));
48+
zend_long resource_column_offset = static_cast<zend_long>(origin.ResourceColumnOffset()->NumberValue(context).FromJust());
49+
if (v8::Message::kNoColumnInfo != resource_column_offset) {
50+
zend_update_property_long(this_ce, return_value, ZEND_STRL("resource_column_offset"), resource_column_offset);
51+
}
4652
}
4753

4854
/* v8::SourceMapUrl::Options */
@@ -52,7 +58,10 @@ extern void php_v8_create_script_origin(zval *return_value, v8::Local<v8::Contex
5258

5359
/* v8::SourceMapUrl::ScriptID */
5460
if (!origin.ScriptID().IsEmpty() && origin.ScriptID()->NumberValue(context).IsJust()) {
55-
zend_update_property_long(this_ce, return_value, ZEND_STRL("script_id"), static_cast<zend_long>(origin.ScriptID()->NumberValue(context).FromJust()));
61+
zend_long script_id = static_cast<zend_long>(origin.ScriptID()->NumberValue(context).FromJust());
62+
if (v8::Message::kNoScriptIdInfo != script_id) {
63+
zend_update_property_long(this_ce, return_value, ZEND_STRL("script_id"), script_id);
64+
}
5665
}
5766

5867
/* v8::SourceMapUrl::ResourceName */
@@ -146,23 +155,23 @@ v8::ScriptOrigin *php_v8_create_script_origin_from_zval(zval *value, v8::Isolate
146155

147156
static PHP_METHOD(ScriptOrigin, __construct) {
148157
zend_string *resource_name = NULL;
149-
zend_long resource_line_offset = static_cast<zend_long>(v8::Message::kNoLineNumberInfo);
150-
zend_long resource_column_offset = static_cast<zend_long>(v8::Message::kNoColumnInfo);
158+
zend_long resource_line_offset = -1;
159+
zend_long resource_column_offset = -1;
151160
zend_bool resource_is_shared_cross_origin = '\0';
152-
zend_long script_id = static_cast<zend_long>(v8::Message::kNoScriptIdInfo);
161+
zend_long script_id = -1;
153162
zend_string *source_map_url = NULL;
154163
zend_bool resource_is_opaque = '\0';
155164
zend_bool is_wasm = '\0';
156165
zend_bool is_module = '\0';
157166

158167
zval options_zv;
159168

160-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SllblSbbb",
169+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlllbSbbb",
161170
&resource_name,
162171
&resource_line_offset,
163172
&resource_column_offset,
164-
&resource_is_shared_cross_origin,
165173
&script_id,
174+
&resource_is_shared_cross_origin,
166175
&source_map_url,
167176
&resource_is_opaque,
168177
&is_wasm,
@@ -179,12 +188,18 @@ static PHP_METHOD(ScriptOrigin, __construct) {
179188

180189
zend_update_property_str(this_ce, getThis(), ZEND_STRL("resource_name"), resource_name);
181190

182-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("resource_line_offset"), resource_line_offset);
183-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("resource_column_offset"), resource_column_offset);
191+
if (resource_line_offset > 0) {
192+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("resource_line_offset"), resource_line_offset);
193+
}
194+
if (resource_column_offset > 0) {
195+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("resource_column_offset"), resource_column_offset);
196+
}
184197

185-
zend_update_property(this_ce, getThis(), ZEND_STRL("options"), &options_zv);
198+
if (script_id > 0) {
199+
zend_update_property_long(this_ce, getThis(), ZEND_STRL("script_id"), script_id);
200+
}
186201

187-
zend_update_property_long(this_ce, getThis(), ZEND_STRL("script_id"), script_id);
202+
zend_update_property(this_ce, getThis(), ZEND_STRL("options"), &options_zv);
188203

189204
if (source_map_url != NULL) {
190205
zend_update_property_str(this_ce, getThis(), ZEND_STRL("source_map_url"), source_map_url);
@@ -256,24 +271,24 @@ static PHP_METHOD(ScriptOrigin, options) {
256271

257272
PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 1)
258273
ZEND_ARG_TYPE_INFO(0, resource_name, IS_STRING, 0)
259-
ZEND_ARG_TYPE_INFO(0, resource_line_offset, IS_LONG, 0)
260-
ZEND_ARG_TYPE_INFO(0, resource_column_offset, IS_LONG, 0)
274+
ZEND_ARG_TYPE_INFO(0, resource_line_offset, IS_LONG, 1)
275+
ZEND_ARG_TYPE_INFO(0, resource_column_offset, IS_LONG, 1)
276+
ZEND_ARG_TYPE_INFO(0, script_id, IS_LONG, 1)
261277
ZEND_ARG_TYPE_INFO(0, resource_is_shared_cross_origin, _IS_BOOL, 0)
262-
ZEND_ARG_TYPE_INFO(0, script_id, IS_LONG, 0)
263278
ZEND_ARG_TYPE_INFO(0, source_map_url, IS_STRING, 0)
264279
ZEND_ARG_TYPE_INFO(0, resource_is_opaque, _IS_BOOL, 0)
265280
ZEND_END_ARG_INFO()
266281

267282
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourceName, ZEND_RETURN_VALUE, 0, IS_STRING, 0)
268283
ZEND_END_ARG_INFO()
269284

270-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourceLineOffset, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
285+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourceLineOffset, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
271286
ZEND_END_ARG_INFO()
272287

273-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourceColumnOffset, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
288+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourceColumnOffset, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
274289
ZEND_END_ARG_INFO()
275290

276-
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scriptId, ZEND_RETURN_VALUE, 0, IS_LONG, 0)
291+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scriptId, ZEND_RETURN_VALUE, 0, IS_LONG, 1)
277292
ZEND_END_ARG_INFO()
278293

279294
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sourceMapUrl, ZEND_RETURN_VALUE, 0, IS_STRING, 0)
@@ -301,12 +316,12 @@ PHP_MINIT_FUNCTION (php_v8_script_origin) {
301316
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "ScriptOrigin", php_v8_script_origin_methods);
302317
this_ce = zend_register_internal_class(&ce);
303318

304-
zend_declare_property_string(this_ce, ZEND_STRL("resource_name"), "", ZEND_ACC_PRIVATE);
305-
zend_declare_property_long(this_ce, ZEND_STRL("resource_line_offset"), static_cast<zend_long>(v8::Message::kNoLineNumberInfo), ZEND_ACC_PRIVATE);
306-
zend_declare_property_long(this_ce, ZEND_STRL("resource_column_offset"), static_cast<zend_long>(v8::Message::kNoColumnInfo), ZEND_ACC_PRIVATE);
307-
zend_declare_property_null(this_ce, ZEND_STRL("options"), ZEND_ACC_PRIVATE);
308-
zend_declare_property_long(this_ce, ZEND_STRL("script_id"), static_cast<zend_long>(v8::Message::kNoScriptIdInfo), ZEND_ACC_PRIVATE);
309-
zend_declare_property_string(this_ce, ZEND_STRL("source_map_url"), "", ZEND_ACC_PRIVATE);
319+
zend_declare_property_string(this_ce, ZEND_STRL("resource_name"), "", ZEND_ACC_PRIVATE);
320+
zend_declare_property_null(this_ce, ZEND_STRL("resource_line_offset"), ZEND_ACC_PRIVATE);
321+
zend_declare_property_null(this_ce, ZEND_STRL("resource_column_offset"), ZEND_ACC_PRIVATE);
322+
zend_declare_property_null(this_ce, ZEND_STRL("options"), ZEND_ACC_PRIVATE);
323+
zend_declare_property_null(this_ce, ZEND_STRL("script_id"), ZEND_ACC_PRIVATE);
324+
zend_declare_property_string(this_ce, ZEND_STRL("source_map_url"), "", ZEND_ACC_PRIVATE);
310325

311326
return SUCCESS;
312327
}

0 commit comments

Comments
 (0)