Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 41 additions & 58 deletions docs/02.API-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,15 +783,14 @@ jerry_run_simple (const jerry_char_t *script_source_p,
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
main (void)
{
const jerry_char_t *script = (const jerry_char_t *) "print ('Hello, World!');";
const jerry_char_t script[] = "print ('Hello, World!');";

jerry_run_simple (script, strlen ((const char *) script), JERRY_INIT_EMPTY);
jerry_run_simple (script, sizeof (script) - 1, JERRY_INIT_EMPTY);
}
```

Expand Down Expand Up @@ -839,7 +838,6 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
Expand All @@ -848,9 +846,8 @@ main (void)
jerry_init (JERRY_INIT_EMPTY);

const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);

jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
jerry_release_value (parsed_code);

jerry_cleanup ();
Expand Down Expand Up @@ -924,20 +921,18 @@ jerry_run (const jerry_value_t func_val);
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
main (void)
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);

/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);

/* Setup Global scope code */
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);

if (!jerry_value_is_error (parsed_code))
{
Expand Down Expand Up @@ -1016,7 +1011,6 @@ jerry_run_all_enqueued_jobs (void)
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
Expand All @@ -1025,9 +1019,8 @@ main (void)
jerry_init (JERRY_INIT_EMPTY);

const jerry_char_t script[] = "new Promise(function(f,r) { f('Hello, World!'); }).then(function(x) { print(x); });";
size_t script_size = strlen ((const char *) script);

jerry_value_t parsed_code = jerry_parse (NULL, 0, script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
jerry_value_t script_value = jerry_run (parsed_code);
jerry_value_t job_value = jerry_run_all_enqueued_jobs ();

Expand Down Expand Up @@ -2989,10 +2982,10 @@ jerry_create_error_sz (jerry_error_t error_type,

```c
{
const jerry_char_t *message = "error";
const jerry_char_t message[] = "error";
jerry_value_t error_obj = jerry_create_error_sz (JERRY_ERROR_COMMON,
message,
strlen ((const char *) message));
sizeof (message) - 1);

... // usage of error_obj

Expand Down Expand Up @@ -3320,7 +3313,7 @@ jerry_create_string_sz (const jerry_char_t *str_p,
{
const jerry_char_t char_array[] = "a string";
jerry_value_t string_value = jerry_create_string_sz (char_array,
strlen ((const char *) char_array));
sizeof (char_array) - 1);

... // usage of string_value

Expand Down Expand Up @@ -3398,7 +3391,7 @@ jerry_create_string_sz (const jerry_char_t *str_p,
{
const jerry_char_t char_array[] = "a string";
jerry_value_t string_value = jerry_create_string_sz_from_utf8 (char_array,
strlen ((const char *) char_array));
sizeof (char_array) - 1);

... // usage of string_value

Expand Down Expand Up @@ -4792,16 +4785,15 @@ jerry_is_valid_utf8_string (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
main (void)
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
const jerry_size_t script_size = sizeof (script) - 1;

if (jerry_is_valid_utf8_string (script, (jerry_size_t) script_size))
if (jerry_is_valid_utf8_string (script, script_size))
{
jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
}
Expand Down Expand Up @@ -4840,7 +4832,6 @@ jerry_is_valid_cesu8_string (const jerry_char_t *cesu8_buf_p, /**< CESU-8 string
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
Expand All @@ -4849,12 +4840,12 @@ main (void)
jerry_init (JERRY_INIT_EMPTY);

const jerry_char_t script[] = "Hello, World!";
size_t script_size = strlen ((const char *) script);
const jerry_size_t script_size = sizeof (script) - 1;

if (jerry_is_valid_cesu8_string (script, (jerry_size_t) script_size))
if (jerry_is_valid_cesu8_string (script, script_size))
{
jerry_value_t string_value = jerry_create_string_sz (script,
(jerry_size_t) script_size);
script_size);

// usage of string_value

Expand Down Expand Up @@ -5059,7 +5050,6 @@ jerry_generate_snapshot (const jerry_char_t *resource_name_p,
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
Expand All @@ -5068,13 +5058,13 @@ main (void)
jerry_init (JERRY_INIT_EMPTY);

static uint32_t global_mode_snapshot_buffer[256];
const jerry_char_t *code_to_snapshot_p = (const jerry_char_t *) "(function () { return 'string from snapshot'; }) ();";
const jerry_char_t script_to_snapshot[] = "(function () { return 'string from snapshot'; }) ();";

jerry_value_t generate_result;
generate_result = jerry_generate_snapshot (NULL,
0,
code_to_snapshot_p,
strlen ((const char *) code_to_snapshot_p),
script_to_snapshot,
sizeof (script_to_snapshot) - 1,
0,
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
Expand Down Expand Up @@ -5139,7 +5129,6 @@ jerry_generate_function_snapshot (const jerry_char_t *resource_name_p,
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
Expand All @@ -5148,16 +5137,16 @@ main (void)
jerry_init (JERRY_INIT_EMPTY);

static uint32_t func_snapshot_buffer[256];
const jerry_char_t *args_p = (const jerry_char_t *) "a, b";
const jerry_char_t *src_p = (const jerry_char_t *) "return a + b;";
const jerry_char_t args[] = "a, b";
const jerry_char_t src[] = "return a + b;";

jerry_value_t generate_result;
generate_result = jerry_generate_function_snapshot (NULL,
0,
src_p,
strlen ((const char *) src_p),
args_p,
strlen ((const char *) args_p),
src,
sizeof (src) - 1,
args,
sizeof (args) - 1,
0,
func_snapshot_buffer,
sizeof (func_snapshot_buffer) / sizeof (uint32_t));
Expand Down Expand Up @@ -5209,22 +5198,21 @@ jerry_exec_snapshot (const uint32_t *snapshot_p,
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
main (void)
{
static uint32_t global_mode_snapshot_buffer[256];
const jerry_char_t *code_to_snapshot_p = (const jerry_char_t *) "(function () { return 'string from snapshot'; }) ();";
const jerry_char_t script_to_snapshot[] = "(function () { return 'string from snapshot'; }) ();";

jerry_init (JERRY_INIT_EMPTY);

jerry_value_t generate_result;
generate_result = jerry_generate_snapshot (NULL,
0,
code_to_snapshot_p,
strlen ((const char *) code_to_snapshot_p),
script_to_snapshot,
sizeof (script_to_snapshot) - 1,
0,
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
Expand Down Expand Up @@ -5287,25 +5275,24 @@ jerry_load_function_snapshot (const uint32_t *snapshot_p,
[doctest]: # ()

```c
#include <string.h>
#include "jerryscript.h"

int
main (void)
{
static uint32_t snapshot_buffer[256];
const jerry_char_t *args_p = (const jerry_char_t *)"a, b";
const jerry_char_t *src_p = (const jerry_char_t *) "return a + b;";
const jerry_char_t func_args[] = "a, b";
const jerry_char_t func_src[] = "return a + b;";

jerry_init (JERRY_INIT_EMPTY);

jerry_value_t generate_result;
generate_result = jerry_generate_function_snapshot (NULL,
0,
src_p,
strlen ((const char *) src_p),
args_p,
strlen ((const char *) args_p),
func_src,
sizeof (func_src) - 1,
func_args,
sizeof (func_args) - 1,
false,
snapshot_buffer,
sizeof (snapshot_buffer) / sizeof (uint32_t));
Expand Down Expand Up @@ -5383,7 +5370,6 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p,

```c
#include <stdio.h>
#include <string.h>
#include "jerryscript.h"

int
Expand All @@ -5393,13 +5379,12 @@ main (void)

static jerry_char_t literal_buffer[256];
static uint32_t snapshot_buffer[256];
const jerry_char_t *code_for_literal_save_p = (const jerry_char_t *) "var obj = { a:'aa', bb:'Bb' }";
size_t code_for_literal_save_size = strlen ((const char *) code_for_literal_save_p);
const jerry_char_t script_for_literal_save[] = "var obj = { a:'aa', bb:'Bb' }";

jerry_value_t generate_result = jerry_generate_snapshot (NULL,
0,
code_for_literal_save_p,
code_for_literal_save_size,
script_for_literal_save,
sizeof (script_for_literal_save) - 1,
0,
snapshot_buffer,
256);
Expand Down Expand Up @@ -5471,7 +5456,6 @@ jerry_set_vm_exec_stop_callback (jerry_vm_exec_stop_callback_t stop_cb,
[doctest]: # (test="link")

```c
#include <string.h>
#include "jerryscript.h"

static int countdown = 10;
Expand All @@ -5497,11 +5481,11 @@ main (void)
jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);

// Inifinte loop.
const char *src_p = "while(true) {}";
const jerry_char_t script[] = "while(true) {}";

jerry_value_t src = jerry_parse (NULL, 0, (jerry_char_t *) src_p, strlen (src_p), JERRY_PARSE_NO_OPTS);
jerry_release_value (jerry_run (src));
jerry_release_value (src);
jerry_value_t parsed_code = jerry_parse (NULL, 0, script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
jerry_release_value (jerry_run (parsed_code));
jerry_release_value (parsed_code);
jerry_cleanup ();
}
```
Expand Down Expand Up @@ -5920,9 +5904,8 @@ jerry_value_t jerry_json_parse (const jerry_char_t *string_p, jerry_size_t strin

```c
{
const char *data = "{\"name\": \"John\", \"age\": 5}";
jerry_size_t str_length = (jerry_size_t)strlen (data);
jerry_value_t parsed_json = jerry_json_parse ((jerry_char_t*)data, str_length);
const jerry_char_t data[] = "{\"name\": \"John\", \"age\": 5}";
jerry_value_t parsed_json = jerry_json_parse (data, sizeof (data) - 1);

// parsed_json now conatins all data stored in data_in_json

Expand Down
Loading