Update the webpage (#2549)

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
This commit is contained in:
Zsolt Borbély 2018-10-04 11:04:17 +02:00 committed by Akos Kiss
parent cf87970ef6
commit c846c4ab73
6 changed files with 231 additions and 199 deletions

View File

@ -248,32 +248,32 @@ typedef struct
} jerry_context_data_manager_t;
```
## jerry_instance_alloc_t
## jerry_context_alloc_t
**Summary**
Function type for allocating buffer for JerryScript instance.
Function type for allocating buffer for JerryScript context.
**Prototype**
```c
typedef void *(*jerry_instance_alloc_t) (size_t size, void *cb_data_p);
typedef void *(*jerry_context_alloc_t) (size_t size, void *cb_data_p);
```
- `size` - allocation size
- `cb_data_p` - pointer to user data
## jerry_instance_t
## jerry_context_t
**Summary**
An opaque declaration of the JerryScript instance structure which is the header of the context space.
An opaque declaration of the JerryScript context structure.
**Prototype**
```c
typedef struct jerry_instance_t jerry_instance_t;
typedef struct jerry_context_t jerry_context_t;
```
## jerry_property_descriptor_t
@ -644,7 +644,7 @@ Registers an external magic string array.
```c
void
jerry_register_magic_strings (const jerry_char_t **ex_str_items_p,
jerry_register_magic_strings (const jerry_char_t * const *ex_str_items_p,
uint32_t count,
const jerry_length_t *str_lengths_p);
```
@ -667,11 +667,11 @@ main (void)
// must be static, because 'jerry_register_magic_strings' does not copy
// the items must be sorted by size at first, then lexicographically
static const jerry_char_t *magic_string_items[] = {
(const jerry_char_t *) "magicstring1",
(const jerry_char_t *) "magicstring2",
(const jerry_char_t *) "magicstring3"
};
static const jerry_char_t * const magic_string_items[] = {
(const jerry_char_t *) "magicstring1",
(const jerry_char_t *) "magicstring2",
(const jerry_char_t *) "magicstring3"
};
uint32_t num_magic_string_items = (uint32_t) (sizeof (magic_string_items) / sizeof (jerry_char_t *));
// must be static, because 'jerry_register_magic_strings' does not copy
@ -688,7 +688,7 @@ main (void)
- [jerry_init](#jerry_init)
- [jerry_cleanup](#jerry_cleanup)
- [jerry_parse_and_save_literals](#jerry_parse_and_save_literals)
- [jerry_get_literals_from_snapshot](#jerry_get_literals_from_snapshot)
## jerry_get_memory_stats
@ -793,15 +793,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);
}
```
@ -849,7 +848,6 @@ jerry_parse (const jerry_char_t *resource_name_p, /**< resource name (usually a
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
int
@ -858,9 +856,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 ();
@ -934,20 +931,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))
{
@ -1026,7 +1021,6 @@ jerry_run_all_enqueued_jobs (void)
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
int
@ -1035,9 +1029,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 ();
@ -2999,10 +2992,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
@ -3330,7 +3323,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
@ -3408,7 +3401,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
@ -4802,16 +4795,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);
}
@ -4850,7 +4842,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
@ -4859,12 +4850,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
@ -4885,28 +4876,74 @@ main (void)
- [jerry_substring_to_char_buffer](#jerry_substring_to_char_buffer)
# External context functions
# Dynamic memory management functions
## jerry_create_instance
## jerry_heap_alloc
**Summary**
Creates a JerryScript instance for external context.
Allocate memory on the engine's heap.
*Note*: This function may take away memory from the executed JavaScript code.
If any other dynamic memory allocation API is available (e.g., libc malloc), it
should be used instead.
**Prototype**
```c
jerry_instance_t *
jerry_create_instance (uint32_t heap_size,
jerry_instance_alloc_t alloc,
void *cb_data_p);
void *jerry_heap_alloc (size_t size);
```
- `heap_size` - requested heap size of the JerryScript instance
- `size`: size of the memory block.
- return value: non-NULL pointer, if the memory is successfully allocated,
NULL otherwise.
**See also**
- [jerry_heap_free](#jerry_heap_free)
## jerry_heap_free
**Summary**
Free memory allocated on the engine's heap.
**Prototype**
```c
void jerry_heap_free (void *mem_p, size_t size);
```
- `mem_p`: value returned by `jerry_heap_alloc`.
- `size`: same size as passed to `jerry_heap_alloc`.
**See also**
- [jerry_heap_alloc](#jerry_heap_alloc)
# External context functions
## jerry_create_context
**Summary**
Create an external JerryScript engine context.
**Prototype**
```c
jerry_context_t *
jerry_create_context (uint32_t heap_size,
jerry_context_alloc_t alloc,
void *cb_data_p);
```
- `heap_size` - requested heap size of the JerryScript context
- `alloc` - function for allocation
- `cb_data_p` - user data
- return value
- pointer to the newly created JerryScript instance if success
- pointer to the newly created JerryScript context if success
- NULL otherwise.
**Example**
@ -4920,19 +4957,19 @@ jerry_create_instance (uint32_t heap_size,
#include "jerryscript.h"
#include "jerryscript-port.h"
/* A different Thread Local Storage variable for each jerry instance. */
__thread jerry_instance_t *tls_instance;
/* A different Thread Local Storage variable for each jerry context. */
__thread jerry_context_t *tls_context;
jerry_instance_t *
jerry_port_get_current_instance (void)
jerry_context_t *
jerry_port_get_current_context (void)
{
/* Returns the instance assigned to the thread. */
return tls_instance;
/* Returns the context assigned to the thread. */
return tls_context;
}
/* Allocate JerryScript heap for each thread. */
static void *
instance_alloc_fn (size_t size, void *cb_data)
context_alloc_fn (size_t size, void *cb_data)
{
(void) cb_data;
return malloc (size);
@ -4941,15 +4978,15 @@ instance_alloc_fn (size_t size, void *cb_data)
static void *
thread_function (void *param)
{
tls_instance = jerry_create_instance (512 * 1024,
instance_alloc_fn,
NULL);
tls_context = jerry_create_context (512 * 1024,
context_alloc_fn,
NULL);
jerry_init (JERRY_INIT_EMPTY);
/* Run the JerryScript instance (e.g.: jerry_parse & jerry_run) */
/* Run JerryScript in the context (e.g.: jerry_parse & jerry_run) */
jerry_cleanup ();
/* Deallocate JerryScript instance */
free (tls_instance);
/* Deallocate JerryScript context */
free (tls_context);
return NULL;
}
@ -4979,9 +5016,9 @@ main (void)
**See also**
- [jerry_instance_t](#jerry_instance_t)
- [jerry_instance_alloc_t](#jerry_instance_alloc_t)
- [jerry_port_get_current_instance](05.PORT-API.md#jerry_port_get_current_instance)
- [jerry_context_t](#jerry_context_t)
- [jerry_context_alloc_t](#jerry_context_alloc_t)
- [jerry_port_get_current_context](05.PORT-API.md#jerry_port_get_current_context)
# Snapshot functions
@ -5023,7 +5060,6 @@ jerry_generate_snapshot (const jerry_char_t *resource_name_p,
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
int
@ -5032,13 +5068,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));
@ -5103,7 +5139,6 @@ jerry_generate_function_snapshot (const jerry_char_t *resource_name_p,
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
int
@ -5112,16 +5147,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));
@ -5173,22 +5208,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));
@ -5251,25 +5285,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));
@ -5313,30 +5346,28 @@ main (void)
- [jerry_parse_and_save_function_snapshot](#jerry_parse_and_save_function_snapshot)
## jerry_parse_and_save_literals
## jerry_get_literals_from_snapshot
**Summary**
Collect the used literals from the given source code and save them into a specific file in a list or C format.
These literals are generated by the parser, they are valid identifiers and none of them are magic string.
Collect the used literals from the given snapshot and save them into a buffer in list or C format.
None of these literals are magic strings. In C format only valid identifiers are collected.
**Prototype**
```c
size_t
jerry_parse_and_save_literals (const jerry_char_t *source_p,
size_t source_size,
bool is_strict,
uint32_t *buffer_p,
size_t buffer_size,
bool is_c_format);
jerry_get_literals_from_snapshot (const uint32_t *snapshot_p,
size_t snapshot_size,
jerry_char_t *lit_buf_p,
size_t lit_buf_size,
bool is_c_format);
```
- `source_p` - script source, it must be a valid utf8 string.
- `source_size` - script source size, in bytes.
- `is_strict` - strict mode.
- `buffer_p` - buffer to save literals to.
- `buffer_size` - the buffer's size.
- `snapshot_p` - input snapshot buffer.
- `snapshot_size` - snapshot size, in bytes.
- `lit_buf_p` - buffer to save literals to.
- `lit_buf_size` - the buffer's size.
- `is_c_format` - the output format would be C-style (true) or a simple list (false).
- return value
- the size of the literal-list, if it was generated succesfully (i.e. the list of literals isn't empty,
@ -5349,7 +5380,6 @@ jerry_parse_and_save_literals (const jerry_char_t *source_p,
```c
#include <stdio.h>
#include <string.h>
#include "jerryscript.h"
int
@ -5357,20 +5387,30 @@ main (void)
{
jerry_init (JERRY_INIT_EMPTY);
static uint32_t save_literal_buffer[256];
const jerry_char_t *code_for_literal_save_p = (const jerry_char_t *) "var obj = { a:'aa', bb:'Bb' }";
static jerry_char_t literal_buffer[256];
static uint32_t snapshot_buffer[256];
const jerry_char_t script_for_literal_save[] = "var obj = { a:'aa', bb:'Bb' }";
size_t literal_sizes = jerry_parse_and_save_literals (code_for_literal_save_p,
strlen ((const char *) code_for_literal_save_p),
false,
save_literal_buffer,
sizeof (save_literal_buffer) / sizeof (uint32_t),
true);
jerry_value_t generate_result = jerry_generate_snapshot (NULL,
0,
script_for_literal_save,
sizeof (script_for_literal_save) - 1,
0,
snapshot_buffer,
256);
size_t snapshot_size = (size_t) jerry_get_number_value (generate_result);
jerry_release_value (generate_result);
if (literal_sizes != 0)
const size_t literal_size = jerry_get_literals_from_snapshot (snapshot_buffer,
snapshot_size,
literal_buffer,
256,
true);
if (literal_size != 0)
{
FILE *literal_file_p = fopen ("literals.txt", "w");
fwrite (save_literal_buffer, sizeof (uint8_t), literal_sizes, literal_file_p);
FILE *literal_file_p = fopen ("literals.h", "wb");
fwrite (literal_buffer, sizeof (uint8_t), literal_size, literal_file_p);
fclose (literal_file_p);
}
@ -5426,7 +5466,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;
@ -5452,11 +5491,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 ();
}
```
@ -5875,9 +5914,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

View File

@ -17,16 +17,14 @@ This guide is intended to introduce you to JerryScript embedding API through cre
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
int
main (void)
{
const jerry_char_t script[] = "var str = 'Hello, World!';";
size_t script_size = strlen ((const char *) script);
bool ret_value = jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
bool ret_value = jerry_run_simple (script, sizeof (script) - 1, JERRY_INIT_EMPTY);
return (ret_value ? 0 : 1);
}
@ -47,7 +45,6 @@ Here we perform the same actions, as `jerry_run_simple`, while splitting into se
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@ -55,7 +52,6 @@ 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);
@ -65,7 +61,7 @@ main (void)
jerryx_handler_print);
/* 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))
{
@ -93,7 +89,6 @@ Our code is more complex now, but it introduces possibilities to interact with J
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@ -114,7 +109,7 @@ main (void)
/* Evaluate script1 */
eval_ret = jerry_eval (script_1,
strlen ((const char *) script_1),
sizeof (script_1) - 1,
JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
@ -122,7 +117,7 @@ main (void)
/* Evaluate script2 */
eval_ret = jerry_eval (script_2,
strlen ((const char *) script_2),
sizeof (script_2) - 1,
JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
@ -142,7 +137,6 @@ This way, we execute two independent script parts in one execution environment.
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@ -178,7 +172,7 @@ main (void)
/* Now starting script that would output value of just initialized field */
jerry_value_t eval_ret = jerry_eval (script,
strlen ((const char *) script),
sizeof (script) - 1,
JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
@ -207,7 +201,6 @@ The following example function will output a JavaScript value:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jerryscript.h"
static void
@ -322,7 +315,7 @@ main (void)
}
/* If the command is "quit", break the loop */
if (!strncmp (cmd, "quit\n", strlen ("quit\n")))
if (!strncmp (cmd, "quit\n", sizeof ("quit\n") - 1))
{
break;
}
@ -362,7 +355,6 @@ In this example we demonstrate how to use native function and structures in Java
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@ -427,10 +419,9 @@ main (void)
var str = MyObject.myFunc (); \
print (str); \
";
size_t script_size = strlen ((const char *) script);
/* Evaluate script */
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
jerry_release_value (eval_ret);
@ -455,7 +446,6 @@ Here we create a JS Object with `jerry_eval`, then extend it with a native funct
[doctest]: # ()
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/handler.h"
@ -518,7 +508,7 @@ main (void)
/* Evaluate script */
my_js_obj_val = jerry_eval (my_js_object,
strlen ((const char *) my_js_object),
sizeof (my_js_object) - 1,
JERRY_PARSE_NO_OPTS);
/* Create a JS function object and wrap into a jerry value */
@ -539,10 +529,9 @@ main (void)
MyObject.add2x (5); \
print (MyObject.foo ()); \
";
size_t script_size = strlen ((const char *) script);
/* Evaluate script */
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
/* Free JavaScript value, returned by eval */
jerry_release_value (eval_ret);
@ -569,7 +558,6 @@ A recommended method is using `jerry_port_get_current_time()` or something based
[doctest]: # ()
```c
#include <string.h>
#include <stdlib.h>
#include "jerryscript.h"
#include "jerryscript-port.h"
@ -583,7 +571,6 @@ main (void)
/* Generate a random number, and print it */
const jerry_char_t script[] = "var a = Math.random (); print(a)";
size_t script_size = strlen ((const char *) script);
/* Initialize the engine */
jerry_init (JERRY_INIT_EMPTY);
@ -593,7 +580,7 @@ main (void)
jerryx_handler_print);
/* Evaluate the script */
jerry_value_t eval_ret = jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_value_t eval_ret = jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
/* Free the JavaScript value returned by eval */
jerry_release_value (eval_ret);

View File

@ -122,23 +122,25 @@ bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p);
double jerry_port_get_current_time (void);
```
## External instance
## External context
Allow user to provide external buffer for jerry instance (which includes an isolated context and heap with other instances), so that user can config the heap size in runtime and run multiple JS apps simultaneously.
Allow user to provide external buffer for isolated engine contexts, so that user
can configure the heap size at runtime and run multiple JS applications
simultaneously.
```c
/**
* Get the current instance which contains the current context, heap and other
* structures. Each port should provide its own implementation of this interface.
* Get the current context of the engine. Each port should provide its own
* implementation of this interface.
*
* Note:
* This port function is called by jerry-core when
* JERRY_ENABLE_EXTERNAL_CONTEXT is defined. Otherwise this function is not
* used.
*
* @return the pointer to the jerry instance.
* @return the pointer to the engine context.
*/
struct jerry_instance_t *jerry_port_get_current_instance (void);
struct jerry_context_t *jerry_port_get_current_context (void);
```
## Sleep
@ -243,37 +245,38 @@ double jerry_port_get_current_time (void)
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
} /* jerry_port_get_current_time */
```
## External instance
## External context
```c
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
/**
* Pointer to the current instance.
* Pointer to the current context.
* Note that it is a global variable, and is not a thread safe implementation.
*/
static jerry_instance_t *current_instance_p = NULL;
static jerry_context_t *current_context_p = NULL;
/**
* Set the current_instance_p as the passed pointer.
* Set the current_context_p as the passed pointer.
*/
void
jerry_port_default_set_instance (jerry_instance_t *instance_p) /**< points to the created instance */
jerry_port_default_set_context (jerry_context_t *context_p) /**< points to the created context */
{
current_instance_p = instance_p;
} /* jerry_port_default_set_instance */
current_context_p = context_p;
} /* jerry_port_default_set_context */
/**
* Get the current instance.
* Get the current context.
*
* @return the pointer to the current instance
* @return the pointer to the current context
*/
jerry_instance_t *
jerry_port_get_current_instance (void)
jerry_context_t *
jerry_port_get_current_context (void)
{
return current_instance_p;
} /* jerry_port_get_current_instance */
return current_context_p;
} /* jerry_port_get_current_context */
```
## Sleep

View File

@ -261,7 +261,6 @@ jerry_debugger_stop_at_breakpoint (bool enable_stop_at_breakpoint)
[doctest]: # (test="link")
```c
#include <string.h>
#include "jerryscript.h"
#include "jerryscript-ext/debugger.h"
@ -276,8 +275,7 @@ main (void)
// Protected execution of JavaScript code.
const jerry_char_t script[] = "42";
size_t script_size = strlen ((const char *) script);
jerry_eval (script, script_size, JERRY_PARSE_NO_OPTS);
jerry_eval (script, sizeof (script) - 1, JERRY_PARSE_NO_OPTS);
jerry_debugger_stop_at_breakpoint (false);

View File

@ -10,18 +10,18 @@ permalink: /ext-reference-handler/
# Common external function handlers
## jerryx_handler_assert
## jerryx_handler_assert_fatal
**Summary**
Assert for scripts. The routine calls `jerry_port_fatal` on assertion failure.
Hard assert for scripts. The routine calls `jerry_port_fatal` on assertion failure.
**Prototype**
```c
jerry_value_t
jerryx_handler_assert (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
jerryx_handler_assert_fatal (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
```
- `func_obj_val` - the function object that was called (unused).
@ -37,6 +37,43 @@ jerryx_handler_assert (const jerry_value_t func_obj_val, const jerry_value_t thi
- [jerryx_handler_register_global](#jerryx_handler_register_global)
## jerryx_handler_assert_throw
**Summary**
Soft assert for scripts. The routine throws an error on assertion failure.
**Prototype**
```c
jerry_value_t
jerryx_handler_assert_throw (const jerry_value_t func_obj_val, const jerry_value_t this_p,
const jerry_value_t args_p[], const jerry_length_t args_cnt);
```
- `func_obj_val` - the function object that was called (unused).
- `this_p` - the `this` value of the call (unused).
- `args_p` - the array of function arguments.
- `args_cnt` - the number of function arguments.
- return value - `jerry_value_t` representing boolean true, if only one argument
was passed and that argument was a boolean true, an error otherwise.
**See also**
- [jerryx_handler_register_global](#jerryx_handler_register_global)
## jerryx_handler_assert_fatal
**Summary**
An alias to `jerryx_handler_assert_fatal`.
**See also**
- [jerryx_handler_assert_fatal](#jerryx_handler_assert_fatal)
## jerryx_handler_gc
**Summary**

View File

@ -1,6 +1,6 @@
---
layout: page
title: debugger transport
title: 'Debugger Transport'
category: documents
permalink: /debugger-transport/
---
@ -106,37 +106,6 @@ typedef bool (*jerry_debugger_transport_receive_t) (struct jerry_debugger_transp
# Transport interface API functions
## jerry_debugger_transport_malloc
**Summary**
Allocates memory for the transport interface.
**Prototype**
```c
void * jerry_debugger_transport_malloc (size_t size);
```
- `size`: size of the memory block.
- return value: non-NULL pointer, if the memory is successfully allocated,
NULL otherwise.
## jerry_debugger_transport_free
**Summary**
Free memory allocated by [jerry_debugger_transport_malloc](#jerry_debugger_transport_malloc)
**Prototype**
```c
void jerry_debugger_transport_free (void *mem_p, size_t size);
```
- `header_p`: header of a transporation interface.
- `size`: total size of the transportation interface.
## jerry_debugger_transport_add
**Summary**
@ -190,7 +159,7 @@ bool jerry_debugger_transport_is_connected (void);
**Summary**
Disconnect from the current debugger client. It does nothing if a client is
not connected,
not connected.
**Prototype**