@@ -783,15 +783,14 @@ jerry_run_simple (const jerry_char_t *script_source_p,
783
783
[doctest]: # ()
784
784
785
785
```c
786
- #include <string.h>
787
786
#include "jerryscript.h"
788
787
789
788
int
790
789
main (void)
791
790
{
792
- const jerry_char_t * script = (const jerry_char_t *) "print ('Hello, World!');";
791
+ const jerry_char_t script[] = "print ('Hello, World!');";
793
792
794
- jerry_run_simple (script, strlen ((const char *) script), JERRY_INIT_EMPTY);
793
+ jerry_run_simple (script, sizeof ( script) - 1 , JERRY_INIT_EMPTY);
795
794
}
796
795
```
797
796
@@ -839,7 +838,6 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
839
838
[doctest]: # ()
840
839
841
840
```c
842
- #include <string.h>
843
841
#include "jerryscript.h"
844
842
845
843
int
@@ -848,9 +846,8 @@ main (void)
848
846
jerry_init (JERRY_INIT_EMPTY);
849
847
850
848
const jerry_char_t script[] = "print ('Hello, World!');";
851
- size_t script_size = strlen ((const char *) script);
852
849
853
- jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size , JERRY_PARSE_NO_OPTS);
850
+ jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1 , JERRY_PARSE_NO_OPTS);
854
851
jerry_release_value (parsed_code);
855
852
856
853
jerry_cleanup ();
@@ -924,20 +921,18 @@ jerry_run (const jerry_value_t func_val);
924
921
[doctest]: # ()
925
922
926
923
```c
927
- #include <string.h>
928
924
#include "jerryscript.h"
929
925
930
926
int
931
927
main (void)
932
928
{
933
929
const jerry_char_t script[] = "print ('Hello, World!');";
934
- size_t script_size = strlen ((const char *) script);
935
930
936
931
/* Initialize engine */
937
932
jerry_init (JERRY_INIT_EMPTY);
938
933
939
934
/* Setup Global scope code */
940
- jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size , JERRY_PARSE_NO_OPTS);
935
+ jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1 , JERRY_PARSE_NO_OPTS);
941
936
942
937
if (!jerry_value_is_error (parsed_code))
943
938
{
@@ -1016,7 +1011,6 @@ jerry_run_all_enqueued_jobs (void)
1016
1011
[doctest]: # ()
1017
1012
1018
1013
```c
1019
- #include <string.h>
1020
1014
#include "jerryscript.h"
1021
1015
1022
1016
int
@@ -1025,9 +1019,8 @@ main (void)
1025
1019
jerry_init (JERRY_INIT_EMPTY);
1026
1020
1027
1021
const jerry_char_t script[] = "new Promise(function(f,r) { f('Hello, World!'); }).then(function(x) { print(x); });";
1028
- size_t script_size = strlen ((const char *) script);
1029
1022
1030
- jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size , JERRY_PARSE_NO_OPTS);
1023
+ jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1 , JERRY_PARSE_NO_OPTS);
1031
1024
jerry_value_t script_value = jerry_run (parsed_code);
1032
1025
jerry_value_t job_value = jerry_run_all_enqueued_jobs ();
1033
1026
@@ -2989,10 +2982,10 @@ jerry_create_error_sz (jerry_error_t error_type,
2989
2982
2990
2983
```c
2991
2984
{
2992
- const jerry_char_t * message = "error";
2985
+ const jerry_char_t message[] = "error";
2993
2986
jerry_value_t error_obj = jerry_create_error_sz (JERRY_ERROR_COMMON,
2994
2987
message,
2995
- strlen ((const char *) message));
2988
+ sizeof ( message) - 1 );
2996
2989
2997
2990
... // usage of error_obj
2998
2991
@@ -3320,7 +3313,7 @@ jerry_create_string_sz (const jerry_char_t *str_p,
3320
3313
{
3321
3314
const jerry_char_t char_array[] = "a string";
3322
3315
jerry_value_t string_value = jerry_create_string_sz (char_array,
3323
- strlen ((const char *) char_array));
3316
+ sizeof ( char_array) - 1 );
3324
3317
3325
3318
... // usage of string_value
3326
3319
@@ -3398,7 +3391,7 @@ jerry_create_string_sz (const jerry_char_t *str_p,
3398
3391
{
3399
3392
const jerry_char_t char_array[] = "a string";
3400
3393
jerry_value_t string_value = jerry_create_string_sz_from_utf8 (char_array,
3401
- strlen ((const char *) char_array));
3394
+ sizeof ( char_array) - 1 );
3402
3395
3403
3396
... // usage of string_value
3404
3397
@@ -4792,16 +4785,15 @@ jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */
4792
4785
[doctest]: # ()
4793
4786
4794
4787
```c
4795
- #include <string.h>
4796
4788
#include "jerryscript.h"
4797
4789
4798
4790
int
4799
4791
main (void)
4800
4792
{
4801
4793
const jerry_char_t script[] = "print ('Hello, World!');";
4802
- size_t script_size = strlen ((const char *) script);
4794
+ const jerry_size_t script_size = sizeof ( script) - 1 ;
4803
4795
4804
- if (jerry_is_valid_utf8_string (script, (jerry_size_t) script_size))
4796
+ if (jerry_is_valid_utf8_string (script, script_size))
4805
4797
{
4806
4798
jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
4807
4799
}
@@ -4840,7 +4832,6 @@ jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string
4840
4832
[doctest]: # ()
4841
4833
4842
4834
```c
4843
- #include <string.h>
4844
4835
#include "jerryscript.h"
4845
4836
4846
4837
int
@@ -4849,12 +4840,12 @@ main (void)
4849
4840
jerry_init (JERRY_INIT_EMPTY);
4850
4841
4851
4842
const jerry_char_t script[] = "Hello, World!";
4852
- size_t script_size = strlen ((const char *) script);
4843
+ const jerry_size_t script_size = sizeof ( script) - 1 ;
4853
4844
4854
- if (jerry_is_valid_cesu8_string (script, (jerry_size_t) script_size))
4845
+ if (jerry_is_valid_cesu8_string (script, script_size))
4855
4846
{
4856
4847
jerry_value_t string_value = jerry_create_string_sz (script,
4857
- (jerry_size_t) script_size);
4848
+ script_size);
4858
4849
4859
4850
// usage of string_value
4860
4851
@@ -5059,7 +5050,6 @@ jerry_generate_snapshot (const jerry_char_t *resource_name_p,
5059
5050
[doctest]: # ()
5060
5051
5061
5052
```c
5062
- #include <string.h>
5063
5053
#include "jerryscript.h"
5064
5054
5065
5055
int
@@ -5068,13 +5058,13 @@ main (void)
5068
5058
jerry_init (JERRY_INIT_EMPTY);
5069
5059
5070
5060
static uint32_t global_mode_snapshot_buffer[256];
5071
- const jerry_char_t *code_to_snapshot_p = (const jerry_char_t *) "(function () { return 'string from snapshot'; }) ();";
5061
+ const jerry_char_t script_to_snapshot[] = "(function () { return 'string from snapshot'; }) ();";
5072
5062
5073
5063
jerry_value_t generate_result;
5074
5064
generate_result = jerry_generate_snapshot (NULL,
5075
5065
0,
5076
- code_to_snapshot_p ,
5077
- strlen ((const char *) code_to_snapshot_p) ,
5066
+ script_to_snapshot ,
5067
+ sizeof (script_to_snapshot) - 1 ,
5078
5068
0,
5079
5069
global_mode_snapshot_buffer,
5080
5070
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
@@ -5139,7 +5129,6 @@ jerry_generate_function_snapshot (const jerry_char_t *resource_name_p,
5139
5129
[doctest]: # ()
5140
5130
5141
5131
```c
5142
- #include <string.h>
5143
5132
#include "jerryscript.h"
5144
5133
5145
5134
int
@@ -5148,16 +5137,16 @@ main (void)
5148
5137
jerry_init (JERRY_INIT_EMPTY);
5149
5138
5150
5139
static uint32_t func_snapshot_buffer[256];
5151
- const jerry_char_t *args_p = (const jerry_char_t *) "a, b";
5152
- const jerry_char_t *src_p = (const jerry_char_t *) "return a + b;";
5140
+ const jerry_char_t args[] = "a, b";
5141
+ const jerry_char_t src[] = "return a + b;";
5153
5142
5154
5143
jerry_value_t generate_result;
5155
5144
generate_result = jerry_generate_function_snapshot (NULL,
5156
5145
0,
5157
- src_p ,
5158
- strlen ((const char *) src_p) ,
5159
- args_p ,
5160
- strlen ((const char *) args_p) ,
5146
+ src ,
5147
+ sizeof (src) - 1 ,
5148
+ args ,
5149
+ sizeof (args) - 1 ,
5161
5150
0,
5162
5151
func_snapshot_buffer,
5163
5152
sizeof (func_snapshot_buffer) / sizeof (uint32_t));
@@ -5209,22 +5198,21 @@ jerry_exec_snapshot (const uint32_t *snapshot_p,
5209
5198
[doctest]: # ()
5210
5199
5211
5200
```c
5212
- #include <string.h>
5213
5201
#include "jerryscript.h"
5214
5202
5215
5203
int
5216
5204
main (void)
5217
5205
{
5218
5206
static uint32_t global_mode_snapshot_buffer[256];
5219
- const jerry_char_t *code_to_snapshot_p = (const jerry_char_t *) "(function () { return 'string from snapshot'; }) ();";
5207
+ const jerry_char_t script_to_snapshot[] = "(function () { return 'string from snapshot'; }) ();";
5220
5208
5221
5209
jerry_init (JERRY_INIT_EMPTY);
5222
5210
5223
5211
jerry_value_t generate_result;
5224
5212
generate_result = jerry_generate_snapshot (NULL,
5225
5213
0,
5226
- code_to_snapshot_p ,
5227
- strlen ((const char *) code_to_snapshot_p) ,
5214
+ script_to_snapshot ,
5215
+ sizeof (script_to_snapshot) - 1 ,
5228
5216
0,
5229
5217
global_mode_snapshot_buffer,
5230
5218
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
@@ -5287,25 +5275,24 @@ jerry_load_function_snapshot (const uint32_t *snapshot_p,
5287
5275
[doctest]: # ()
5288
5276
5289
5277
```c
5290
- #include <string.h>
5291
5278
#include "jerryscript.h"
5292
5279
5293
5280
int
5294
5281
main (void)
5295
5282
{
5296
5283
static uint32_t snapshot_buffer[256];
5297
- const jerry_char_t *args_p = (const jerry_char_t *) "a, b";
5298
- const jerry_char_t *src_p = (const jerry_char_t *) "return a + b;";
5284
+ const jerry_char_t func_args[] = "a, b";
5285
+ const jerry_char_t func_src[] = "return a + b;";
5299
5286
5300
5287
jerry_init (JERRY_INIT_EMPTY);
5301
5288
5302
5289
jerry_value_t generate_result;
5303
5290
generate_result = jerry_generate_function_snapshot (NULL,
5304
5291
0,
5305
- src_p ,
5306
- strlen ((const char *) src_p) ,
5307
- args_p ,
5308
- strlen ((const char *) args_p) ,
5292
+ func_src ,
5293
+ sizeof (func_src) - 1 ,
5294
+ func_args ,
5295
+ sizeof (func_args) - 1 ,
5309
5296
false,
5310
5297
snapshot_buffer,
5311
5298
sizeof (snapshot_buffer) / sizeof (uint32_t));
@@ -5383,7 +5370,6 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p,
5383
5370
5384
5371
```c
5385
5372
#include <stdio.h>
5386
- #include <string.h>
5387
5373
#include "jerryscript.h"
5388
5374
5389
5375
int
@@ -5393,13 +5379,12 @@ main (void)
5393
5379
5394
5380
static jerry_char_t literal_buffer[256];
5395
5381
static uint32_t snapshot_buffer[256];
5396
- const jerry_char_t *code_for_literal_save_p = (const jerry_char_t *) "var obj = { a:'aa', bb:'Bb' }";
5397
- size_t code_for_literal_save_size = strlen ((const char *) code_for_literal_save_p);
5382
+ const jerry_char_t script_for_literal_save[] = "var obj = { a:'aa', bb:'Bb' }";
5398
5383
5399
5384
jerry_value_t generate_result = jerry_generate_snapshot (NULL,
5400
5385
0,
5401
- code_for_literal_save_p ,
5402
- code_for_literal_save_size ,
5386
+ script_for_literal_save ,
5387
+ sizeof (script_for_literal_save) - 1 ,
5403
5388
0,
5404
5389
snapshot_buffer,
5405
5390
256);
@@ -5471,7 +5456,6 @@ jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb,
5471
5456
[doctest]: # (test="link")
5472
5457
5473
5458
```c
5474
- #include <string.h>
5475
5459
#include "jerryscript.h"
5476
5460
5477
5461
static int countdown = 10;
@@ -5497,11 +5481,11 @@ main (void)
5497
5481
jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);
5498
5482
5499
5483
// Inifinte loop.
5500
- const char *src_p = "while(true) {}";
5484
+ const jerry_char_t script[] = "while(true) {}";
5501
5485
5502
- jerry_value_t src = jerry_parse (NULL, 0, (jerry_char_t *) src_p, strlen (src_p) , JERRY_PARSE_NO_OPTS);
5503
- jerry_release_value (jerry_run (src ));
5504
- jerry_release_value (src );
5486
+ jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1 , JERRY_PARSE_NO_OPTS);
5487
+ jerry_release_value (jerry_run (parsed_code ));
5488
+ jerry_release_value (parsed_code );
5505
5489
jerry_cleanup ();
5506
5490
}
5507
5491
```
@@ -5920,9 +5904,8 @@ jerry_value_t jerry_json_parse (const jerry_char_t *string_p, jerry_size_t strin
5920
5904
5921
5905
```c
5922
5906
{
5923
- const char *data = "{\"name\": \"John\", \"age\": 5}";
5924
- jerry_size_t str_length = (jerry_size_t)strlen (data);
5925
- jerry_value_t parsed_json = jerry_json_parse ((jerry_char_t*)data, str_length);
5907
+ const jerry_char_t data[] = "{\"name\": \"John\", \"age\": 5}";
5908
+ jerry_value_t parsed_json = jerry_json_parse (data, sizeof (data) - 1);
5926
5909
5927
5910
// parsed_json now conatins all data stored in data_in_json
5928
5911
0 commit comments