aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Langó <llango.u-szeged@partner.samsung.com>2019-04-24 10:35:44 +0200
committerGitHub <noreply@github.com>2019-04-24 10:35:44 +0200
commit887d06b7a36cec50ce4f082bd9caea08f6678bfb (patch)
tree14e812f0bf782151b0b3241809b31ac890cc2b12
parent9ca5e323bd26bb61105bc4590e00920299eb6a54 (diff)
Update the webpage (#2835)
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
-rw-r--r--01.GETTING-STARTED.md6
-rw-r--r--02.API-REFERENCE.md614
-rw-r--r--03.API-EXAMPLE.md10
-rw-r--r--05.PORT-API.md49
-rw-r--r--07.DEBUGGER.md7
-rw-r--r--10.EXT-REFERENCE-HANDLER.md41
-rw-r--r--14.EXT-REFERENCE-HANDLE-SCOPE.md122
-rw-r--r--15.MODULE-SYSTEM.md142
8 files changed, 855 insertions, 136 deletions
diff --git a/01.GETTING-STARTED.md b/01.GETTING-STARTED.md
index e60f06e6..daf87c04 100644
--- a/01.GETTING-STARTED.md
+++ b/01.GETTING-STARTED.md
@@ -49,6 +49,12 @@ python tools/build.py --debug
python tools/build.py --debug --lto=off
```
+**To enable more verbose outputs for debugging**
+
+```bash
+tools/build.py --debug --logging=on --error-messages=on --line-info=on
+```
+
**Add custom arguments to CMake**
```bash
diff --git a/02.API-REFERENCE.md b/02.API-REFERENCE.md
index 12582d90..9617e33c 100644
--- a/02.API-REFERENCE.md
+++ b/02.API-REFERENCE.md
@@ -73,6 +73,7 @@ Possible compile time enabled feature types:
- JERRY_FEATURE_LINE_INFO - line info available
- JERRY_FEATURE_LOGGING - logging
- JERRY_FEATURE_SYMBOL - symbol support
+ - JERRY_FEATURE_DATAVIEW - DataView support
## jerry_regexp_flags_t
@@ -198,6 +199,9 @@ that indicates whether is an error or not. Every type has an error flag not only
be cleared before the value is passed as an argument, otherwise it can lead to a type error. The error objects
created by API functions has the error flag set.
+Returned and created values by the API functions must be freed with
+[jerry_release_value](#jerry_release_value) when they are no longer needed.
+
**Prototype**
```c
@@ -664,6 +668,8 @@ someplace_in_the_code (void)
Registers an external magic string array.
*Note*: The strings in the array must be sorted by size at first, then lexicographically.
+*Note*: The maximum number of external magic strings is limited to 2147483648 (UINT32_MAX / 2).
+ If there are more than 2147483648 external magic strings the extra is cropped.
**Prototype**
@@ -937,7 +943,10 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u
Run an EcmaScript function created by `jerry_parse`.
-*Note*: The code should be previously parsed with `jerry_parse`.
+*Note*:
+ - The code should be previously parsed with `jerry_parse`.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
**Prototype**
@@ -995,7 +1004,10 @@ main (void)
**Summary**
-Perform JavaScript `eval`.
+Perform JavaScript `eval` function call (ECMA-262 v5.1 sec-15.1.2.1).
+
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
**Prototype**
@@ -1032,6 +1044,9 @@ jerry_eval (const jerry_char_t *source_p,
Run enqueued Promise jobs until the first thrown error or until all get executed.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -1193,6 +1208,8 @@ jerry_value_is_array (const jerry_value_t value)
Returns whether the given `jerry_value_t` is an ArrayBuffer object.
+*Note*: This API depends on the ES2015-subset profile.
+
**Prototype**
```c
@@ -1304,6 +1321,58 @@ jerry_value_is_constructor (const jerry_value_t value)
- [jerry_release_value](#jerry_release_value)
+## jerry_value_is_dataview
+
+**Summary**
+
+Returns whether the given `jerry_value_t` is a DataView object value.
+
+*Note*: This API depends on the ES2015-subset profile.
+
+**Prototype**
+
+```c
+bool
+jerry_value_is_dataview (const jerry_value_t value)
+```
+
+- `value` - API value
+- return value
+ - true, if the given `jerry_value_t` is a DataView object
+ - false, otherwise
+
+**Example**
+
+[doctest]: # ()
+
+```c
+#include "jerryscript.h"
+
+int
+main (void)
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t arraybuffer = jerry_create_arraybuffer (16);
+ jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 16);
+
+ if (jerry_value_is_dataview (dataview))
+ {
+ // usage of dataview
+ }
+
+ jerry_release_value (dataview);
+ jerry_release_value (arraybuffer);
+
+ jerry_cleanup ();
+}
+```
+
+**See also**
+
+- [jerry_release_value](#jerry_release_value)
+
+
## jerry_value_is_error
**Summary**
@@ -1392,7 +1461,7 @@ Returns whether the given `jerry_value_t` is a number.
```c
bool
-jerry_value_is_function (const jerry_value_t value)
+jerry_value_is_number (const jerry_value_t value)
```
- `value` - api value
@@ -1585,6 +1654,8 @@ jerry_value_is_string (const jerry_value_t value)
Returns whether the given `jerry_value_t` is a symbol value.
+*Note*: This API depends on the ES2015-subset profile.
+
**Prototype**
```c
@@ -1790,6 +1861,9 @@ jerry_is_feature_enabled (const jerry_feature_t feature);
Perform binary operation on the given operands (==, ===, <, >, etc.).
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -2829,7 +2903,7 @@ jerry_value_to_string (const jerry_value_t value);
# Functions for promise objects
-These APIs all depends on the ES2015-subset profile.
+These APIs all depend on the ES2015-subset profile.
## jerry_resolve_or_reject_promise
@@ -2837,6 +2911,9 @@ These APIs all depends on the ES2015-subset profile.
Resolve or reject the promise with an argument.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3023,6 +3100,9 @@ is no longer needed.
Create an array object value.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3057,6 +3137,11 @@ jerry_create_array (uint32_t size);
Create a jerry_value_t representing an ArrayBuffer object.
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
**Prototype**
```c
@@ -3098,6 +3183,11 @@ User must pass a buffer pointer which is at least `size` big.
After the object is not needed the GC will call the `free_cb`
so the user can release the buffer which was provided.
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
**Prototype**
```c
@@ -3176,10 +3266,11 @@ jerry_create_boolean (bool value);
Create new JavaScript error object.
-Important! The `error_type` argument *must not be*
-`JERRY_ERROR_NONE`.
+Important! The `error_type` argument *must not be* `JERRY_ERROR_NONE`.
Creating an error with no error type is not valid.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
**Prototype**
@@ -3220,6 +3311,9 @@ jerry_create_error (jerry_error_t error_type,
Create new JavaScript error object.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3254,12 +3348,72 @@ jerry_create_error_sz (jerry_error_t error_type,
- [jerry_create_error](#jerry_create_error)
+## jerry_create_dataview
+
+**Summary**
+
+Create new JavaScript DataView object.
+
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
+**Prototype**
+
+```c
+jerry_value_t
+jerry_create_dataview (const jerry_value_t array_buffer,
+ const jerry_length_t byte_offset,
+ const jerry_length_t byte_length)
+```
+
+- `array_buffer` - arrayBuffer to create DataView from
+- `byte_offset` - offset in bytes, to the first byte in the buffer
+- `byte_length` - number of elements in the byte array
+- return value
+ - value of the constructed DataView object - if success
+ - created error - otherwise
+
+**Example**
+
+[doctest]: # ()
+
+```c
+#include "jerryscript.h"
+
+int
+main (void)
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t arraybuffer = jerry_create_arraybuffer (16);
+ jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 16);
+
+ // usage of dataview
+
+ jerry_release_value (dataview);
+ jerry_release_value (arraybuffer);
+
+ jerry_cleanup ();
+}
+```
+
+**See also**
+
+- [jerry_value_is_dataview](#jerry_value_is_dataview)
+- [jerry_create_arraybuffer](#jerry_create_arraybuffer)
+
+
## jerry_create_external_function
**Summary**
Create an external function object.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3312,6 +3466,9 @@ handler (const jerry_value_t function_obj,
Creates a `jerry_value_t` representing a number value.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3347,6 +3504,9 @@ jerry_create_number (double value);
Creates a `jerry_value_t` representing a positive or negative infinity value.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3382,6 +3542,9 @@ jerry_create_number_infinity (bool sign);
Creates a `jerry_value_t` representing a not-a-number value.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3448,6 +3611,9 @@ jerry_create_null (void);
Create new JavaScript object, like with new Object().
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3481,7 +3647,10 @@ jerry_create_object (void);
Create an empty promise object which can be resolved or rejected later
by calling jerry_resolve_or_reject_promise.
-*Note*: This API depends on the ES2015-subset profile.
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
**Prototype**
@@ -3516,6 +3685,9 @@ jerry_create_promise (void)
Create string from a valid CESU8 string.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3551,6 +3723,9 @@ jerry_create_string (const jerry_char_t *str_p);
Create string from a valid CESU8 string.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -3591,6 +3766,8 @@ jerry_create_string_sz (const jerry_char_t *str_p,
Create string from a valid UTF8 string.
*Note*: The difference from [jerry_create_string](#jerry_create_string) is that it accepts utf-8 string instead of cesu-8 string.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
**Prototype**
@@ -3628,6 +3805,8 @@ jerry_create_string_from_utf8 (const jerry_char_t *str_p);
Create string from a valid UTF8 string.
*Note*: The difference from [jerry_create_string_sz](#jerry_create_string_sz) is that it accepts utf-8 string instead of cesu-8 string.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
**Prototype**
@@ -3668,7 +3847,11 @@ jerry_create_string_sz (const jerry_char_t *str_p,
Create symbol from an API value.
-*Note*: The given argument is converted to string. This operation can throw an error.
+*Note*:
+ - The given argument is converted to string. This operation can throw an error.
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
**Prototype**
@@ -3718,10 +3901,13 @@ main (void)
**Summary**
-Returns a jerry_value_t RegExp object or an error, if the construction of the object fails.
+Returns a `jerry_value_t` RegExp object or an error, if the construction of the object fails.
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t).
These flags can be combined together with the binary OR operator or used on their own as enum values.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
jerry_value_t
@@ -3752,10 +3938,13 @@ jerry_create_regexp (const jerry_char_t *pattern_p, uint16_t flags);
**Summary**
-Returns a jerry_value_t RegExp object or an error, if the construction of the object fails.
+Returns a `jerry_value_t` RegExp object or an error, if the construction of the object fails.
Optional flags can be set using [jerry_regexp_flags_t](#jerry_regexp_flags_t).
These flags can be combined together with the binary OR operator or used on their own as enum values.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
jerry_value_t
@@ -3793,6 +3982,11 @@ Create a jerry_value_t representing an TypedArray object.
For the new object the type of the TypedArray (see: [jerry_typedarray_type_t](#jerry_typedarray_type_t))
and element count can be specified.
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
**Prototype**
```c
@@ -3839,6 +4033,11 @@ type of TypedArray otherwise an error is generated.
The JavaScript equivalent of this function is: `new %TypedArray%(arraybuffer)` where `%TypedArray%` is
one of the allowed TypedArray functions.
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
**Prototype**
```c
@@ -3890,6 +4089,11 @@ type of TypedArray otherwise an error is generated.
The JavaScript equivalent of this function is: `new %TypedArray%(arraybuffer, byteOffset, length)` where `%TypedArray%` is
one of the allowed TypedArray functions.
+*Note*:
+ - This API depends on the ES2015-subset profile.
+ - Returned value must be freed with [jerry_release_value](#jerry_release_value)
+ when it is no longer needed.
+
**Prototype**
```c
@@ -4646,6 +4850,9 @@ jerry_construct_object (const jerry_value_t func_obj_val,
Get keys of the specified object value.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -4685,6 +4892,9 @@ jerry_get_object_keys (const jerry_value_t obj_val);
Get the prototype of the specified object.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -4724,6 +4934,9 @@ jerry_get_prototype (const jerry_value_t obj_val);
Set the prototype of the specified object.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -4764,23 +4977,11 @@ jerry_set_prototype (const jerry_value_t obj_val,
**Summary**
-Get native pointer and its type information.
+Get native pointer by the given type information.
The pointer and the type information are previously associated with the object by jerry_set_object_native_pointer.
-*Note*: It is recommended to ensure that the `out_native_info_p` value pointer
- is equal to the native info pointer that is expected, before casting
- and accessing the `out_native_pointer_p`.
- An example of when this is important: external functions that expect
- `this` to have a native pointer of a certain C type.
- It is possible in JavaScript to change `this` at will – using `call()`,
- `apply()` or `bind()`. Therefore, it is possible that the native pointer
- of `this` is not of the expected C type. To handle this safely and
- securely, one must always add type checks to make sure that the
- `out_native_pointer_p` is of the expected type, before casting
- and dereferencing `out_native_pointer_p`.
-
-*Note*: `out_native_pointer_p` and `out_native_info_p` can be NULL, and it means the
- caller doesn't want to get the native_pointer or type information.
+*Note*: `out_native_pointer_p` can be NULL, and it means the
+ caller doesn't want to get the native_pointer.
**Prototype**
@@ -4788,73 +4989,185 @@ The pointer and the type information are previously associated with the object b
bool
jerry_get_object_native_pointer (const jerry_value_t obj_val,
void **out_native_pointer_p,
- const jerry_object_native_info_t **out_native_info_p)
+ const jerry_object_native_info_t *native_info_p)
```
- `obj_val` - object value to get native pointer from.
- `out_native_pointer_p` - native pointer (output parameter).
-- `out_native_info_p` - native pointer's type information (output parameter).
+- `native_info_p` - native pointer's type information.
- return value
- - true, if there is native pointer associated with the object
+ - true, if there is native pointer associated of the specified object with the given native type info
- false, otherwise
**Example**
+[doctest]: # ()
+
```c
-typedef struct {
- int foo;
- bool bar;
-} native_obj_t;
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "jerryscript.h"
-static void native_freecb (void *native_p)
+typedef struct
{
- ... // free the native pointer
+ char *data_p;
+ unsigned int length;
+} buffer_native_object_t;
+
+typedef struct
+{
+ int area;
+ int perimeter;
+} shape_native_object_t;
+
+#define SECRET_INFO ((void *) 42)
+
+static void
+buffer_native_freecb (void *native_p)
+{
+ char *data_p = ((buffer_native_object_t*)native_p)->data_p;
+
+ if (data_p != NULL)
+ {
+ free (data_p);
+ }
+
+ free (native_p);
+}
+
+static void
+shape_native_freecb (void *native_p)
+{
+ free (native_p);
+}
+
+static void
+destructor_freecb (void *native_p)
+{
+ printf("Note: the object has been freed\n");
}
// NOTE: The address (!) of type_info acts as a way to uniquely "identify" the
-// C type `native_obj_t *`.
-static const jerry_object_native_info_t native_obj_type_info =
+// C type `buffer_native_object_t *`.
+static const jerry_object_native_info_t buffer_obj_type_info =
{
- .free_cb = native_freecb
+ .free_cb = buffer_native_freecb
};
-// Function creating JS object that is "backed" by a native_obj_t *:
+// NOTE: The address (!) of type_info acts as a way to uniquely "identify" the
+// C type `shape_native_object_t *`.
+static const jerry_object_native_info_t shape_obj_type_info =
{
- ...
+ .free_cb = shape_native_freecb
+};
- // construct object and native_set value:
- jerry_value_t object = ...;
- native_obj_t *native_obj = malloc(sizeof(*native_obj));
- jerry_set_object_native_pointer (object, native_obj, &native_obj_type_info);
+// NOTE: The address (!) of type_info is the unique "identifier"
+static const jerry_object_native_info_t destructor_obj_type_info =
+{
+ .free_cb = destructor_freecb
+};
- ...
+static void
+print_buffer (char *data_p,
+ unsigned int length)
+{
+ for (unsigned int i = 0; i < length; ++i)
+ {
+ printf("%c", data_p[i]);
+ }
+
+ printf("\n");
}
-// Native method, `this` is expected to be "backed" by a native_obj_t *:
+static void
+do_stuff (jerry_value_t object)
{
void *native_p;
- const jerry_object_native_info_t *type_p;
- bool has_p = jerry_get_object_native_pointer (this_val, &native_p, &type_p);
+ bool has_p = jerry_get_object_native_pointer (object, &native_p, &buffer_obj_type_info);
+
+ if (!has_p)
+ {
+ // Process the error
+ return;
+ }
+
+ // It is safe to cast to buffer_native_object_t * and dereference the pointer:
+ buffer_native_object_t *buffer_p = (buffer_native_object_t *) native_p;
+ print_buffer (buffer_p->data_p, buffer_p->length); // Usage of buffer_p
+
+ bool need_shape_info = true; // implementation dependent
- if (has_p)
+ if (need_shape_info)
{
- // The type_p pointer address itself is used to identify the type:
- if (type_p == &native_obj_type_info)
+ has_p = jerry_get_object_native_pointer (object, &native_p, &shape_obj_type_info);
+
+ if (!has_p)
{
- // The type of this's native pointer matches what is expected.
- // Only now is it safe to cast to native_obj_t * and dereference the
- // pointer:
- native_obj_t *native_obj = native_p;
- native_obj->bar = ...; // Safe to access now!
+ // Process the error
+ return;
}
- else
+
+ // It is safe to cast to shape_native_object_t * and dereference the pointer:
+ shape_native_object_t *shape_p = (shape_native_object_t *) native_p;
+
+ printf("Area: %d\tPerimeter: %d\n", shape_p->area, shape_p->perimeter); // Usage of shape_p
+ }
+
+ bool need_secret_info = true; // implementation dependent
+
+ if (need_secret_info)
+ {
+ has_p = jerry_get_object_native_pointer (object, &native_p, NULL);
+
+ if (!has_p)
{
- // The type of this's native pointer is NOT what we expected!
- // We should not cast to native_obj_t * and dereference because it's unsafe.
- // Handle the error here, for example throw an error.
+ // Process the error
+ return;
+ }
+
+ printf("Secret: %d\n", (int)((uintptr_t) native_p)); // Usage of native_p
+
+ bool deleted = jerry_delete_object_native_pointer (object, NULL);
+
+ if (deleted)
+ {
+ printf("The secret is no longer available\n");
}
}
- ...
+}
+
+int
+main (void)
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t object = jerry_create_object ();
+ buffer_native_object_t *buffer_p = (buffer_native_object_t *) malloc (sizeof (buffer_native_object_t));
+ buffer_p->length = 14;
+ buffer_p->data_p = (char *) malloc (buffer_p->length * sizeof (char));
+ memcpy (buffer_p->data_p, "My buffer data", buffer_p->length);
+ jerry_set_object_native_pointer (object, buffer_p, &buffer_obj_type_info);
+
+ shape_native_object_t *shape_p = (shape_native_object_t *) malloc (sizeof (shape_native_object_t));
+ shape_p->area = 6;
+ shape_p->perimeter = 12;
+ jerry_set_object_native_pointer (object, shape_p, &shape_obj_type_info);
+
+ // The native pointer can be NULL. This gives possibily to get notified via the native type info's
+ // free callback when the object has been freed by the GC.
+ jerry_set_object_native_pointer (object, NULL, &destructor_obj_type_info);
+
+ // The native type info can be NULL as well. In this case the registered property is simply freed
+ // when the object is freed by te GC.
+ jerry_set_object_native_pointer (object, SECRET_INFO, NULL);
+
+ do_stuff (object);
+
+ jerry_release_value (object);
+ jerry_cleanup ();
+
+ return 0;
}
```
@@ -4882,7 +5195,7 @@ You can get them by calling jerry_get_object_native_pointer later.
**Prototype**
```c
-bool
+void
jerry_set_object_native_pointer (const jerry_value_t obj_val,
void *native_p,
const jerry_object_native_info_t *info_p)
@@ -4905,6 +5218,40 @@ best-practice example.
- [jerry_get_object_native_pointer](#jerry_get_object_native_pointer)
- [jerry_object_native_info_t](#jerry_object_native_info_t)
+## jerry_delete_object_native_pointer
+
+**Summary**
+
+Delete the native pointer of the specified object associated with the given native type info.
+You can get them by calling jerry_get_object_native_pointer later.
+
+*Note*:
+ - If the specified object has no matching native pointer for the given native type info the operation has no effect.
+ - This operation cannot throw an exception.
+
+**Prototype**
+
+```c
+bool
+jerry_delete_object_native_pointer (const jerry_value_t obj_val,
+ const jerry_object_native_info_t *info_p)
+```
+
+- `obj_val` - object to delete native pointer from.
+- `info_p` - native pointer's type information.
+
+**Example**
+
+See [jerry_get_object_native_pointer](#jerry_get_object_native_pointer) for a
+best-practice example.
+
+**See also**
+
+- [jerry_create_object](#jerry_create_object)
+- [jerry_get_object_native_pointer](#jerry_get_object_native_pointer)
+- [jerry_get_object_native_pointer](#jerry_set_object_native_pointer)
+- [jerry_object_native_info_t](#jerry_object_native_info_t)
+
## jerry_foreach_object_property
@@ -4933,9 +5280,10 @@ jerry_foreach_object_property (jerry_value_t obj_val,
**Example**
```c
-bool foreach_function (const jerry_value_t prop_name,
- const jerry_value_t prop_value,
- void *user_data_p)
+bool
+foreach_function (const jerry_value_t prop_name,
+ const jerry_value_t prop_value,
+ void *user_data_p)
{
... // implementation of the foreach function
@@ -4968,8 +5316,9 @@ Iterate over objects.
**Prototype**
```c
-bool jerry_objects_foreach (jerry_objects_foreach_t foreach_p,
- void *user_data_p);
+bool
+jerry_objects_foreach (jerry_objects_foreach_t foreach_p,
+ void *user_data_p);
```
- `foreach_p` - function that will be invoked for each object.
@@ -5043,9 +5392,10 @@ Iterate over objects matching a certain native data type.
**Prototype**
```c
-bool jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_info_p,
- jerry_objects_foreach_by_native_info_t foreach_p,
- void *user_data_p);
+bool
+jerry_objects_foreach_by_native_info (const jerry_object_native_info_t *native_info_p,
+ jerry_objects_foreach_by_native_info_t foreach_p,
+ void *user_data_p);
```
- `native_info_p` - native pointer's type information.
@@ -5397,6 +5747,9 @@ main (void)
Generate snapshot from the specified source code.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -5415,12 +5768,12 @@ jerry_generate_snapshot (const jerry_char_t *resource_name_p,
- `source_p` - script source, it must be a valid utf8 string.
- `source_size` - script source size, in bytes.
- `generate_snapshot_opts` - any combination of [jerry_generate_snapshot_opts_t](#jerry_generate_snapshot_opts_t) flags.
-- `buffer_p` - buffer to save snapshot to.
+- `buffer_p` - buffer (aligned to 4 bytes) to save snapshot to.
- `buffer_size` - the buffer's size.
- return value
- - the size of the snapshot as a number value, if it was generated succesfully (i.e. there are no syntax
- errors in source code, buffer size is sufficient, and snapshot support is enabled in current configuration
- through JERRY_ENABLE_SNAPSHOT_SAVE)
+ - the size of the generated snapshot in bytes as number value, if it was generated succesfully (i.e. there
+ are no syntax errors in source code, buffer size is sufficient, and snapshot support is enabled in
+ current configuration through JERRY_ENABLE_SNAPSHOT_SAVE)
- thrown error, otherwise.
**Example**
@@ -5472,6 +5825,9 @@ with the given arguments.
The function arguments and function body are
passed as separated arguments.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -5494,12 +5850,12 @@ jerry_generate_function_snapshot (const jerry_char_t *resource_name_p,
- `args_p` - function arguments, it must be a valid utf8 string.
- `args_size` - function argument size, in bytes.
- `generate_snapshot_opts` - any combination of [jerry_generate_snapshot_opts_t](#jerry_generate_snapshot_opts_t) flags.
-- `buffer_p` - buffer to save snapshot to.
+- `buffer_p` - buffer (aligned to 4 bytes) to save snapshot to.
- `buffer_size` - the buffer's size.
- return value
- - the size of the snapshot as a number value, if it was generated succesfully (i.e. there are no syntax
- errors in source code, buffer size is sufficient, and snapshot support is enabled in current configuration
- through JERRY_ENABLE_SNAPSHOT_SAVE)
+ - the size of the generated snapshot in bytes as number value, if it was generated succesfully (i.e. there
+ are no syntax errors in source code, buffer size is sufficient, and snapshot support is enabled in
+ current configuration through JERRY_ENABLE_SNAPSHOT_SAVE)
- thrown error, otherwise.
**Example**
@@ -5564,7 +5920,7 @@ jerry_exec_snapshot (const uint32_t *snapshot_p,
```
- `snapshot_p` - pointer to snapshot
-- `snapshot_size` - size of snapshot
+- `snapshot_size` - size of snapshot in bytes
- `func_index` - index of executed function
- `exec_snapshot_opts` - any combination of [jerry_exec_snapshot_opts_t](#jerry_exec_snapshot_opts_t) flags.
- return value
@@ -5641,7 +5997,7 @@ jerry_load_function_snapshot (const uint32_t *snapshot_p,
```
- `snapshot_p` - pointer to snapshot
-- `snapshot_size` - size of snapshot
+- `snapshot_size` - size of snapshot in bytes
- `func_index` - index of function to load
- `exec_snapshot_opts` - any combination of [jerry_exec_snapshot_opts_t](#jerry_exec_snapshot_opts_t) flags.
- return value
@@ -5733,7 +6089,7 @@ jerry_get_literals_from_snapshot (const uint32_t *snapshot_p,
```
- `snapshot_p` - input snapshot buffer.
-- `snapshot_size` - snapshot size, in bytes.
+- `snapshot_size` - size of snapshot 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).
@@ -5886,6 +6242,9 @@ The array length is zero if the backtrace is not available.
This function is typically called from native callbacks.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
@@ -5895,7 +6254,7 @@ jerry_get_backtrace (uint32_t max_depth);
- `max_depth` - backtrace collection stops after reaching this value, 0 = unlimited
- return value
- - a new array
+ - a newly constructed JS array
**See also**
@@ -5904,6 +6263,8 @@ jerry_get_backtrace (uint32_t max_depth);
# ArrayBuffer and TypedArray functions
+These APIs all depend on the ES2015-subset profile.
+
## jerry_get_arraybuffer_byte_length
**Summary**
@@ -6128,6 +6489,70 @@ jerry_get_arraybuffer_pointer (const jerry_value_t value);
- [jerry_create_arraybuffer_external](#jerry_create_arraybuffer_external)
+## jerry_get_dataview_buffer
+
+**Summary**
+
+Get the ArrayBuffer object used by a DataView object.
+Additionally returns the byteLength and byteOffset properties
+of the DataView object.
+
+For the returned ArrayBuffer the [jerry_release_value](#jerry_release_value)
+must be called when it is no longer needed.
+
+**Prototype**
+
+```c
+jerry_value_t
+jerry_get_dataview_buffer (const jerry_value_t value,
+ jerry_length_t *byteOffset,
+ jerry_length_t *byteLength);
+```
+
+- `value` - DataView to get the ArrayBuffer from
+- `byteOffset` - (Optional) returns the start offset of the ArrayBuffer for the DataView
+- `byteLength` - (Optional) returns the number of bytes used from the ArrayBuffer for the DataView
+- return
+ - DataView object's underlying ArrayBuffer object
+ - TypeError if the `value` is not a DataView object
+
+**Example**
+
+[doctest]: # ()
+
+```c
+#include "jerryscript.h"
+
+int
+main (void)
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t arraybuffer = jerry_create_arraybuffer (16);
+ jerry_value_t dataview = jerry_create_dataview (arraybuffer, 0, 16);
+ jerry_length_t byteOffset = 0;
+ jerry_length_t byteLength = 0;
+ jerry_value_t buffer = jerry_get_dataview_buffer (dataview, &byteOffset, &byteLength);
+
+ // buffer is an ArrayBuffer object and ArrayBuffer operations can be performed on it
+ // byteOffset is 0
+ // byteLength is 16
+
+ // usage of buffer
+
+ jerry_release_value (buffer);
+ jerry_release_value (dataview);
+ jerry_release_value (arraybuffer);
+
+ jerry_cleanup ();
+}
+```
+
+**See also**
+
+- [jerry_create_dataview](#jerry_create_dataview)
+
+
## jerry_get_typedarray_type
**Summary**
@@ -6220,12 +6645,16 @@ of the TypedArray object.
For the returned ArrayBuffer the [jerry_release_value](#jerry_release_value)
must be called.
+*Note*: Returned value must be freed with [jerry_release_value](#jerry_release_value) when it
+is no longer needed.
+
**Prototype**
```c
-jerry_value_t jerry_get_typedarray_buffer (jerry_value_t value,
- jerry_length_t *byteOffset,
- jerry_length_t *byteLength);
+jerry_value_t
+jerry_get_typedarray_buffer (jerry_value_t value,
+ jerry_length_t *byteOffset,
+ jerry_length_t *byteLength);
```
- `value` - TypedArray to get the ArrayBuffer from
@@ -6264,12 +6693,14 @@ jerry_value_t jerry_get_typedarray_buffer (jerry_value_t value,
**Summary**
-Returns the same result as JSON.parse ecmascript function.
+Returns the same result as `JSON.parse` ecmascript function.
**Prototype**
```c
-jerry_value_t jerry_json_parse (const jerry_char_t *string_p, jerry_size_t string_size)
+jerry_value_t
+jerry_json_parse (const jerry_char_t *string_p,
+ jerry_size_t string_size);
```
- `string_p` - a JSON string
@@ -6293,14 +6724,15 @@ jerry_value_t jerry_json_parse (const jerry_char_t *string_p, jerry_size_t strin
## jerry_json_stringify
- **Summary**
+**Summary**
- Returns the same value as JSON.stringify() ecmascript function.
+Returns the same value as `JSON.stringify` ecmascript function.
- **Prototype**
+**Prototype**
```c
-jerry_value_t jerry_json_stringify (const jerry_value_t object_to_stringify)
+jerry_value_t
+jerry_json_stringify (const jerry_value_t object_to_stringify);
```
- `object_to_stringify` - a jerry_value_t object to stringify
@@ -6315,7 +6747,7 @@ jerry_value_t jerry_json_stringify (const jerry_value_t object_to_stringify)
jerry_value_t obj = jerry_create_object ();
jerry_value_t key = jerry_create_string ((const jerry_char_t *) "name");
jerry_value_t value = jerry_create_string ((const jerry_char_t *) "John");
- jerry_set_property (obj, key, value);
+ jerry_release_value (jerry_set_property (obj, key, value));
jerry_value_t stringified = jerry_json_stringify (obj);
//stringified now contains a json formated string
diff --git a/03.API-EXAMPLE.md b/03.API-EXAMPLE.md
index 65fb95b0..25761497 100644
--- a/03.API-EXAMPLE.md
+++ b/03.API-EXAMPLE.md
@@ -161,7 +161,7 @@ main (void)
jerry_value_t prop_value = jerry_create_string (str);
/* Setting the string value as a property of the Global object */
- jerry_set_property (global_object, prop_name, prop_value);
+ jerry_release_value (jerry_set_property (global_object, prop_name, prop_value));
/* Releasing string values, as it is no longer necessary outside of engine */
jerry_release_value (prop_name);
@@ -396,7 +396,7 @@ main (void)
/* Set the native function as a property of the empty JS object */
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "myFunc");
- jerry_set_property (object, prop_name, func_obj);
+ jerry_release_value (jerry_set_property (object, prop_name, func_obj));
jerry_release_value (prop_name);
jerry_release_value (func_obj);
@@ -405,7 +405,7 @@ main (void)
/* Add the JS object to the global context */
prop_name = jerry_create_string ((const jerry_char_t *) "MyObject");
- jerry_set_property (global_object, prop_name, object);
+ jerry_release_value (jerry_set_property (global_object, prop_name, object));
jerry_release_value (prop_name);
jerry_release_value (object);
jerry_release_value (global_object);
@@ -472,7 +472,7 @@ add_handler (const jerry_value_t func_value, /**< function object */
jerry_value_t res_val = jerry_create_number (x + d);
/* Set the new value of 'this.x' */
- jerry_set_property (this_val, prop_name, res_val);
+ jerry_release_value (jerry_set_property (this_val, prop_name, res_val));
jerry_release_value (res_val);
}
@@ -516,7 +516,7 @@ main (void)
/* Set the native function as a property of previously created MyObject */
jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "add2x");
- jerry_set_property (my_js_obj_val, prop_name, add_func_obj);
+ jerry_release_value (jerry_set_property (my_js_obj_val, prop_name, add_func_obj));
jerry_release_value (add_func_obj);
jerry_release_value (prop_name);
diff --git a/05.PORT-API.md b/05.PORT-API.md
index e57922de..4468da9e 100644
--- a/05.PORT-API.md
+++ b/05.PORT-API.md
@@ -82,6 +82,44 @@ typedef enum
void jerry_port_log (jerry_log_level_t level, const char *fmt, ...);
```
+The `jerry_port_print_char` is currenlty not used by the jerry-core directly.
+However, it provides a port specifc way for `jerry-ext` components to print
+information.
+
+```c
+/**
+ * Print a character to stdout.
+ */
+void jerry_port_print_char (char c);
+```
+
+### ES2015 Module system helper functions
+
+The import statement requires two specific functions for opening and closing files (the modules) port specific.
+
+```c
+/**
+ * Opens file with the given path and reads its source.
+ * @return the source of the file
+ */
+uint8_t *
+jerry_port_read_source (const char *file_name_p, /**< file name */
+ size_t *out_size_p) /**< [out] read bytes */
+{
+ // open file from given path
+ // return its source
+} /* jerry_port_read_source */
+
+/**
+ * Release the previously opened file's content.
+ */
+void
+jerry_port_release_source (uint8_t *buffer_p) /**< buffer to free */
+{
+ free (buffer_p);
+} /* jerry_port_release_source */
+```
+
## Date
```c
@@ -211,6 +249,17 @@ jerry_port_log (jerry_log_level_t level, /**< log level */
} /* jerry_port_log */
```
+```c
+/**
+ * Print a character to stdout with putchar.
+ */
+void
+jerry_port_print_char (char c)
+{
+ putchar (c);
+} /* jerr_port_print_char */
+```
+
## Date
```c
diff --git a/07.DEBUGGER.md b/07.DEBUGGER.md
index c8d2a4b1..fb36224e 100644
--- a/07.DEBUGGER.md
+++ b/07.DEBUGGER.md
@@ -78,8 +78,11 @@ When using the extension-provided WebSocket transport layer, the
debugger can be enabled by calling `jerryx_debugger_after_connect
(jerryx_debugger_tcp_create (debug_port) && jerryx_debugger_ws_create ())`
after the `jerry_init ()` function. It initializes the debugger and
-blocks until a client connects. (Custom transport layers may be
-implemented and initialized similarly.)
+blocks until a client connects.
+(Custom transport layers may be implemented and initialized similarly.
+Currently, `jerryx_debugger_rp_create ()` for raw packet transport layer and
+`jerryx_debugger_serial_create (const char* config)` for serial protocol
+are also available.)
The resource name provided to `jerry_parse ()` is used by the client
to identify the resource name of the source code. This resource name
diff --git a/10.EXT-REFERENCE-HANDLER.md b/10.EXT-REFERENCE-HANDLER.md
index f0020008..efee4c5e 100644
--- a/10.EXT-REFERENCE-HANDLER.md
+++ b/10.EXT-REFERENCE-HANDLER.md
@@ -107,14 +107,14 @@ jerryx_handler_gc (const jerry_value_t func_obj_val, const jerry_value_t this_p,
Provide a `print` implementation for scripts. The routine converts all of its
arguments to strings and outputs them char-by-char using
-`jerryx_port_handler_print_char`. The NUL character is output as "\u0000",
+`jerry_port_print_char`. The NUL character is output as "\u0000",
other characters are output bytewise.
*Note*: This implementation does not use standard C `printf` to print its
output. This allows more flexibility but also extends the core JerryScript
engine port API. Applications that want to use `jerryx_handler_print` must
ensure that their port implementation also provides
-`jerryx_port_handler_print_char`.
+`jerry_port_print_char`.
**Prototype**
@@ -134,7 +134,7 @@ jerryx_handler_print (const jerry_value_t func_obj_val, const jerry_value_t this
**See also**
- [jerryx_handler_register_global](#jerryx_handler_register_global)
-- [jerryx_port_handler_print_char](#jerryx_port_handler_print_char)
+- [jerry_port_print_char](05.PORT-API.md#jerry_port_print_char)
# Handler registration helper
@@ -194,38 +194,3 @@ register_common_functions (void)
jerry_release_value (ret);
}
```
-
-
-# Port API extension
-
-## jerryx_port_handler_print_char
-
-**Summary**
-
-Print a single character.
-
-**Prototype**
-
-```c
-void
-jerryx_port_handler_print_char (char c);
-```
-
-- `c` - the character to print.
-
-**Example**
-
-```c
-/**
- * Print a character to stdout with printf.
- */
-void
-jerryx_port_handler_print_char (char c)
-{
- printf ("%c", c);
-} /* jerryx_port_handler_print_char */
-```
-
-**See also**
-
-- [jerryx_handler_print](#jerryx_handler_print)
diff --git a/14.EXT-REFERENCE-HANDLE-SCOPE.md b/14.EXT-REFERENCE-HANDLE-SCOPE.md
new file mode 100644
index 00000000..34977c0a
--- /dev/null
+++ b/14.EXT-REFERENCE-HANDLE-SCOPE.md
@@ -0,0 +1,122 @@
+---
+layout: page
+title: 'Extension API: Handle Scope'
+category: documents
+permalink: /ext-reference-handle-scope/
+---
+
+* toc
+{:toc}
+
+# Handle Scope
+
+## jerryx_handle_scope
+
+**Summary**
+It is often necessary to make the lifespan of handles shorter than the lifespan of a native method. Even though the native code could only use the most recent handle, all of the associated objects would also be kept alive since they all share the same scope.
+
+To handle this case, JerryScript HandleScope extension provides the ability to establish a new 'scope' to which newly created handles will be associated. Once those handles are no longer required, the scope can be 'closed' and any handles associated with the scope are invalidated. The methods available to open/close scopes are `jerryx_open_handle_scope` and `jerryx_close_handle_scope`.
+
+JerryScript only supports a single nested hierarchy of scopes. There is only one active scope at any time, and all new handles will be associated with that scope while it is active. Scopes must be closed in the reverse order from which they are opened. In addition, all scopes created within a native method must be closed before returning from that method.
+
+**Example**
+
+[doctest]: # (test="compile")
+
+```c
+#include "jerryscript.h"
+#include "jerryscript-ext/handle-scope.h"
+
+static jerry_value_t
+create_object (void)
+{
+ jerry_value_t obj = jerry_create_object ();
+ return obj;
+} /* create_object */
+
+static void
+test_handle_scope_val (void)
+{
+ jerryx_handle_scope scope;
+ jerryx_open_handle_scope (&scope);
+ jerry_value_t obj = jerryx_create_handle (create_object ());
+
+ jerryx_close_handle_scope (scope);
+ // now obj has been released
+} /* test_handle_scope_val */
+
+int
+main (void)
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ test_handle_scope_val ();
+ jerry_gc (JERRY_GC_SEVERITY_LOW);
+
+ jerry_cleanup ();
+} /* main */
+```
+
+## jerryx_escapable_handle_scope
+
+**Summary**
+
+It is necessary in common cases that a handle has to be promote to outer scope and prevent from been garbage collected. To handle this case, a escapable handle scope has been proposed from which one object can be promoted to the outer scope. The method available to escape an object from been release at current scope is `jerryx_escape_handle`.
+
+**Example**
+
+[doctest]: # (test="compile")
+
+```c
+#include "jerryscript.h"
+#include "jerryscript-ext/handle-scope.h"
+
+static jerry_value_t
+create_object (void)
+{
+ jerryx_escapable_handle_scope scope;
+ jerryx_open_escapable_handle_scope (&scope);
+ jerry_value_t obj = jerryx_create_handle (jerry_create_object ());
+
+ jerry_value_t escaped_obj;
+ jerryx_escape_handle(scope, obj, &escaped_obj);
+ jerryx_close_handle_scope (scope);
+ // escaped_obj has now been escaped to outer scope, thus not released at this point
+
+ return escaped_obj;
+} /* create_object */
+
+static void
+test_handle_scope_val (void)
+{
+ jerryx_handle_scope scope;
+ jerryx_open_handle_scope (&scope);
+ jerry_value_t obj = create_object ();
+
+ jerryx_close_handle_scope (scope);
+ // now obj has been released
+} /* test_handle_scope_val */
+
+int
+main (void)
+{
+ jerry_init (JERRY_INIT_EMPTY);
+
+ test_handle_scope_val ();
+ jerry_gc (JERRY_GC_SEVERITY_LOW);
+
+ jerry_cleanup ();
+} /* main */
+```
+
+**See also**
+
+- [jerry_value_t](../api-reference#jerry_value_t)
+- [jerry_acquire_value](../api-reference#jerry_acquire_value)
+- [jerry_release_value](../api-reference#jerry_release_value)
+
+## Pre-allocated list of handle scopes and handles
+
+To prevent trapping into system calls frequently, a pre-allocated dedicated list mechanism has been introduced to the implementation of JerryX handle scope.
+
+To change the size of pre-allocation list, use build definition `JERRYX_HANDLE_PRELIST_SIZE` and `JERRYX_SCOPE_PRELIST_SIZE` to alter the default value of 20.
diff --git a/15.MODULE-SYSTEM.md b/15.MODULE-SYSTEM.md
new file mode 100644
index 00000000..a680626a
--- /dev/null
+++ b/15.MODULE-SYSTEM.md
@@ -0,0 +1,142 @@
+---
+layout: page
+title: 'Module System (EcmaScript2015)'
+category: documents
+permalink: /module-system/
+---
+
+* toc
+{:toc}
+
+# ES6 module support for JerryScript
+
+The module system allows users to write import and export statements in scripts. Therefore the logic of the application could be separated in custom modules.
+The standard's relevant part can be found [here](https://www.ecma-international.org/ecma-262/6.0/#sec-modules).
+
+## General
+
+If the main script contains import statements, then Jerry opens and runs the appropriate scripts before the main script (as the standard says). The script's and the module's extension is `.js`, custom extensions are unnecessary.
+
+main.js
+
+```js
+import { secret_number } from "./module.js"
+
+print (secret_number);
+```
+
+module.js
+
+```js
+var secret_number = 42;
+
+export secret_number;
+```
+
+## Supported features
+
+* import variable or function
+ * add alias name to the imported variable (function)
+* export variable or function
+ * add alias name to the exported variable (function)
+
+### Example
+
+```js
+import {
+ engine,
+ version as v
+} from "./module.js"
+
+import { getFeatureDetails } from "./module_2.js"
+
+var version = "v3.1415";
+
+print("> main.js");
+
+print(">> Engine: " + engine);
+print(">> Version: " + v);
+
+print (">> " + getFeatureDetails());
+print (">> Script version: " + version);
+```
+
+```js
+// module.js
+var _engine = "JerryScript";
+export _engine as engine;
+
+export var version = "1.0 (e92ae0fb)";
+```
+
+```js
+// module_2.js
+var featureName = "EcmaScript 2015 modules";
+var year = 2018;
+
+export function getFeatureDetails() {
+ return "Feature name: " + featureName + " | developed in " + year;
+}
+```
+
+## Unsupported features
+
+* **snapshot**
+* errors from the imported scripts
+* redirection ( `export { a, b } from 'module.js'` )
+* default import and export
+ * `import b from 'module.js'`
+ * `export default b`,
+* whole module import statements
+ * `import * from 'module.js`
+ * `import { * as module } from 'module.js`
+* object freezing ( `Object.freeze (this)` )
+
+### Redirection
+
+An export statement can import variables from a custom module and export it directly from the current script. This statement is called redirection. In this case the `export { b } from 'module2.js'` works as the `b` was imported before then exported as a local variable.
+
+```js
+import { a, b } from 'module.js'
+
+print (a + b);
+```
+
+```js
+// module.js
+export var a = 2;
+export { b } from 'module2.js'
+```
+
+```js
+// module2.js
+export var b = 40;
+```
+
+### Default imports and exports
+
+TODO: This part is going to be written in the next part of the patch.
+
+### Import the whole module
+
+The whole module can be imported. In this case the `m` object would contain the exported parts of the module. If the import is not aliased, the `global object` would contain the exports.
+
+```js
+import { * as m } from "./module.js"
+
+print (m.secret_number);
+print (m.getPrettifiedNumber());
+print (m.api.version);
+```
+
+```js
+// module.js
+var secret_number = 42;
+export secret_number;
+
+export function getPrettifiedNumber() {
+ return "*** " + secret_number + " ***";
+}
+
+export { ble as api } from "./ble.js";
+```