@@ -1462,6 +1462,30 @@ typedef struct
1462
1462
- [jerry_source_info_enabled_fields_t](#jerry_source_info_enabled_fields_t)
1463
1463
- [jerry_get_source_info](#jerry_get_source_info)
1464
1464
1465
+ ## jerry_syntax_error_location_t
1466
+
1467
+ **Summary**
1468
+
1469
+ Detailed location info for SyntaxErrors. It contains the
1470
+ start and end location of the token which caused the SyntaxError.
1471
+
1472
+ **Prototype**
1473
+
1474
+ ```c
1475
+ typedef struct
1476
+ {
1477
+ uint32_t line; /**< start line of the invalid token */
1478
+ uint32_t column_start; /**< start column of the invalid token */
1479
+ uint32_t column_end; /**< end column of the invalid token */
1480
+ } jerry_syntax_error_location_t;
1481
+ ```
1482
+
1483
+ *New in version [[NEXT_RELEASE]]*.
1484
+
1485
+ **See also**
1486
+
1487
+ - [jerry_get_syntax_error_location](#jerry_get_syntax_error_location)
1488
+
1465
1489
## jerry_arraybuffer_type_t
1466
1490
1467
1491
**Summary**
@@ -12236,8 +12260,8 @@ Returns a newly created source info structure corresponding to the passed script
12236
12260
The function is lower level than `toString()` operation, but provides more contextual information.
12237
12261
12238
12262
*Notes*:
12239
- - Returned value must be freed with [jerry_free_source_info](#jerry_free_source_info) when it
12240
- is no longer needed.
12263
+ - Returned value must be freed with [jerry_free_source_info](#jerry_free_source_info)
12264
+ when it is no longer needed.
12241
12265
- This API depends on a build option (`JERRY_FUNCTION_TO_STRING`) and can be checked
12242
12266
in runtime with the `JERRY_FEATURE_FUNCTION_TO_STRING` feature enum value,
12243
12267
see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
@@ -12320,6 +12344,69 @@ See [jerry_get_source_info](#jerry_get_source_info)
12320
12344
- [jerry_get_source_info](#jerry_get_source_info)
12321
12345
- [jerry_source_info_t](#jerry_source_info_t)
12322
12346
12347
+ ## jerry_get_syntax_error_location
12348
+
12349
+ **Summary**
12350
+
12351
+ Gets the resource name and location info assigned to a SyntaxError object generated by the parser.
12352
+
12353
+ *Notes*:
12354
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
12355
+ when it is no longer needed.
12356
+ - This API depends on a build option (`JERRY_ERROR_MESSAGES`) and can be checked
12357
+ in runtime with the `JERRY_FEATURE_ERROR_MESSAGES` feature enum value,
12358
+ see: [jerry_is_feature_enabled](#jerry_is_feature_enabled).
12359
+
12360
+ **Prototype**
12361
+
12362
+ ```c
12363
+ jerry_value_t jerry_get_syntax_error_location (jerry_value_t value,
12364
+ jerry_syntax_error_location_t *error_location_p);
12365
+ ```
12366
+ - `value` - SyntaxError object
12367
+ - `error_location_p` - output location info
12368
+ - return
12369
+ - resource name - if the `value` object has a location info data
12370
+ - error - otherwise
12371
+
12372
+ *New in version [[NEXT_RELEASE]]*.
12373
+
12374
+ **Example**
12375
+
12376
+ [doctest]: # ()
12377
+
12378
+ ```c
12379
+ #include "jerryscript.h"
12380
+
12381
+ int
12382
+ main (void)
12383
+ {
12384
+ jerry_init (JERRY_INIT_EMPTY);
12385
+
12386
+ const jerry_char_t script[] = "aa bb";
12387
+
12388
+ jerry_value_t result_value = jerry_parse (script, sizeof (script) - 1, NULL);
12389
+
12390
+ jerry_syntax_error_location_t error_location;
12391
+ jerry_value_t resource_value = jerry_get_syntax_error_location (result_value, &error_location);
12392
+
12393
+ if (jerry_value_is_string (resource_value))
12394
+ {
12395
+ /* Prints the location of the error. */
12396
+ }
12397
+
12398
+ jerry_release_value (resource_value);
12399
+ jerry_release_value (result_value);
12400
+
12401
+ jerry_cleanup ();
12402
+ return 0;
12403
+ }
12404
+ ```
12405
+
12406
+ **See also**
12407
+
12408
+ - [jerry_syntax_error_location_t](#jerry_syntax_error_location_t)
12409
+
12323
12410
12324
12411
# Functions for realm objects
12325
12412
0 commit comments