aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZsolt Borbély <zsborbely.u-szeged@partner.samsung.com>2016-08-26 16:38:24 +0200
committerZsolt Borbély <zsborbely.u-szeged@partner.samsung.com>2016-08-26 16:38:24 +0200
commit622f42e0a8ded9f549d93d404017ae20b724102d (patch)
tree42b8ab2bd0092aafb2268fa2f3fcdb3da061292d
parent0deac9f81c303767e1e3bd6684c71f92d299e390 (diff)
Update the webpage
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
-rw-r--r--01.GETTING-STARTED.md128
-rw-r--r--02.API-REFERENCE.md225
-rw-r--r--03.API-EXAMPLE.md49
-rw-r--r--04.INTERNALS.md97
-rw-r--r--img/bytecode-layout.pngbin0 -> 10553 bytes
5 files changed, 335 insertions, 164 deletions
diff --git a/01.GETTING-STARTED.md b/01.GETTING-STARTED.md
index 36f6e2db..23913b14 100644
--- a/01.GETTING-STARTED.md
+++ b/01.GETTING-STARTED.md
@@ -7,70 +7,146 @@ permalink: /getting-started/
* toc
{:toc}
-### Setting Up Prerequisites
+## Setting up prerequisites
Currently, only Ubuntu 14.04+ is officially supported as primary development environment.
There are several dependencies, that should be installed manually. The following list is required for building:
-- `gcc` higher than `4.8.2`
+- `gcc` or any C99-compliant compiler
- native
- arm-none-eabi
-- `cmake` higher than `2.8.12.2`
-- `make` higher than `3.81`
-- `bash` higher than `4.3.11`
-- `cppcheck` higher than 1.61
-- `vera++` higher than 1.2.1
+- `cmake` >= `2.8.12.2`
+- `bash` >= `4.3.11`
+- `cppcheck` >= `1.61`
+- `vera++` >= `1.2.1`
+- `python` >= `2.7.6`
```bash
-sudo apt-get install gcc g++ gcc-arm-none-eabi cmake cppcheck vera++
+sudo apt-get install gcc g++ gcc-arm-none-eabi cmake cppcheck vera++ python
```
To make our scripts run correctly, several shell utilities should be available on the system:
-- `find`
-- `bc`
- `awk`
+- `bc`
+- `find`
- `sed`
-- `sha256sum`
-- `wget`
-Upon first build, `make` would try to setup prerequisites, required for further development and pre-commit testing:
+## Building JerryScript
+
+**To build debug version for Linux**
+
+```bash
+python tools/build.py --debug
+```
+
+**To build debug version for Linux without LTO (Link Time Optimization)**
+
+```bash
+python tools/build.py --debug --lto=off
+```
+
+**Add custom arguments to CMake**
+
+```bash
+python tools/build.py --cmake-param=CMAKE_PARAM
+```
+
+**Set a profile mode (full, minimal)**
+
+```bash
+python tools/build.py --feature=full|minimal
+```
+
+**Use (jerry, compiler-default, external) libc**
-- STM32F3 and STM32F4 libraries
+The default libc is jerry-libc, but you can use compiler-default libc or an external libc:
+
+- compiler-default libc:
```bash
-make prerequisites -j
+python tools/build.py --jerry-libc=off --compiler-default-libc=on
```
-It may take time, so go grab some coffee:
+- external libc:
```bash
-Setting up prerequisites... (log file: ./build/prerequisites/prerequisites.log)
+python tools/build.py --jerry-libc=off --compiler-default-libc=off --compile-flag="-I/path/to/libc/include"
```
-### Building Debug Version
+**Add toolchain file**
-To build debug version for Linux:
+The ```cmake``` dir already contains some usable toolchain files, which you can use in the following format:
```bash
-make debug.linux -j
+python tools/build.py --toolchain=TOOLCHAIN
```
-To build debug version for Linux without LTO (Link Time Optimization):
+For example the cross-compile to RaspberryPi 2 is something like this:
```bash
-LTO=OFF make debug.linux -j
+python tools/build.py --toolchain=cmake/toolchain_linux_armv7l.cmake
```
-### Checking Patch
+**To get a list of all the available buildoptions for Linux**
```bash
-make precommit -j
+python tools/build.py --help
```
-If some style guidelines, build or test runs fail during precommit, then this is indicated with a message like this:
+## Checking patch
+
+```bash
+python tools/run-tests.py --precommit
+```
+### Running only one type of test
+
+**To run build option tests**
+
+```bash
+python tools/run-tests.py --buildoption-test
```
-Build failed. See ./build/bin/unittests/make.log for details.
+
+**To run unittests**
+
+```bash
+python tools/run-tests.py --unittests
+```
+
+**To run jerry-tests**
+
+```bash
+python tools/run-tests.py --jerry-tests
+```
+
+**To run jerry-test-suite**
+
+```bash
+python tools/run-tests.py --jerry-test-suite
+```
+
+**To run signed-off check**
+
+```bash
+python tools/run-tests.py --check-signed-off
+```
+
+**To run cppcheck**
+
+```bash
+python tools/run-tests.py --check-cppcheck
+```
+
+**To run vera check**
+
+```bash
+python tools/run-tests.py --check-vera
+```
+
+**To get a list of all the available test options**
+
+```bash
+python tools/run-tests.py --help
```
diff --git a/02.API-REFERENCE.md b/02.API-REFERENCE.md
index ef09c0ff..4ae4d89b 100644
--- a/02.API-REFERENCE.md
+++ b/02.API-REFERENCE.md
@@ -14,14 +14,15 @@ permalink: /api-reference/
Enum that contains the following elements:
- JERRY_INIT_EMPTY - empty flag set
- - JERRY_INIT_ENABLE_LOG - enable logging
- - JERRY_INIT_SHOW_OPCODES - dump byte-code to stdout after parse
+ - JERRY_INIT_SHOW_OPCODES - dump byte-code to log after parse
+ - JERRY_INIT_SHOW_REGEXP_OPCODES - dump regexp byte-code to log after compilation
- JERRY_INIT_MEM_STATS - dump memory statistics
- JERRY_INIT_MEM_STATS_SEPARATE - dump memory statistics and reset peak values after parse
## jerry_error_t
Possible types of an error:
+
- JERRY_ERROR_COMMON - common error
- JERRY_ERROR_EVAL - eval error
- JERRY_ERROR_RANGE - range error
@@ -42,6 +43,18 @@ Jerry's char value
typedef uint8_t jerry_char_t;
```
+## jerry_char_ptr_t
+
+**Summary**
+
+Pointer to an array of character values
+
+**Prototype**
+
+```c
+typedef jerry_char_t *jerry_char_ptr_t;
+```
+
## jerry_size_t
**Summary**
@@ -139,7 +152,7 @@ Type of an external function handler
**Prototype**
```c
-typedef jerry_value_t (*jerry_external_handler_t) (const jerry_value_t function_obj_p,
+typedef jerry_value_t (*jerry_external_handler_t) (const jerry_value_t function_obj,
const jerry_value_t this_val,
const jerry_value_t args_p[],
const jerry_length_t args_count);
@@ -166,7 +179,7 @@ Function type applied for each data property of an object
**Prototype**
```c
-typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name_p,
+typedef bool (*jerry_object_property_foreach_t) (const jerry_value_t property_name,
const jerry_value_t property_value,
void *user_data_p);
```
@@ -190,8 +203,8 @@ jerry_init (jerry_init_flag_t flags)
`flags` - combination of various engine configuration flags:
- `JERRY_INIT_EMPTY` - no flags, just initialize in default configuration.
-- `JERRY_INIT_ENABLE_LOG` - enable logging.
- `JERRY_INIT_SHOW_OPCODES` - print compiled byte-code.
+- `JERRY_INIT_SHOW_REGEXP_OPCODES` - print compiled regexp byte-code.
- `JERRY_INIT_MEM_STATS` - dump memory statistics.
- `JERRY_INIT_MEM_STATS_SEPARATE` - dump memory statistics and reset peak values after parse.
@@ -199,7 +212,7 @@ jerry_init (jerry_init_flag_t flags)
```c
{
- jerry_init (JERRY_INIT_SHOW_OPCODES | JERRY_INIT_ENABLE_LOG);
+ jerry_init (JERRY_INIT_SHOW_OPCODES | JERRY_INIT_SHOW_REGEXP_OPCODES);
// ...
@@ -242,14 +255,14 @@ Registers an external magic string array.
```c
void
-jerry_register_magic_strings (const jerry_char_ptr_t *ex_str_items,
+jerry_register_magic_strings (const jerry_char_ptr_t *ex_str_items_p,
uint32_t count,
- const jerry_length_t *str_lengths);
+ const jerry_length_t *str_lengths_p);
```
-- `ex_str_items` - character arrays, representing external magic strings' contents
+- `ex_str_items_p` - character arrays, representing external magic strings' contents
- `count` - number of the strings
-- `str_lengths` - lengths of the strings
+- `str_lengths_p` - lengths of the strings
**Example**
@@ -305,8 +318,8 @@ jerry_get_memory_limits (size_t *out_data_bss_brk_limit_p,
jerry_init (JERRY_INIT_EMPTY);
size_t stack_limit;
- size_t data_dss_brk_limit;
- jerry_get_memory_limits (&stack_limit, &data_dss_brk_limit);
+ size_t data_bss_brk_limit;
+ jerry_get_memory_limits (&stack_limit, &data_bss_brk_limit);
}
```
@@ -354,12 +367,12 @@ The simplest way to run JavaScript.
```c
bool
-jerry_run_simple (const jerry_char_t *script_source,
+jerry_run_simple (const jerry_char_t *script_source_p,
size_t script_source_size,
jerry_init_flag_t flags);
```
-- `script_source` - source code, it must be a valid utf8 string.
+- `script_source_p` - source code, it must be a valid utf8 string.
- `script_source_size` - size of source code buffer, in bytes.
- `jerry_init_flag_t` - combination of various engine configuration flags
- return value
@@ -388,7 +401,8 @@ jerry_run_simple (const jerry_char_t *script_source,
**Summary**
-Parse specified script to execute in Global scope.
+Parse script and construct an EcmaScript function. The
+lexical environment is set to the global lexical environment.
*Note*: Returned value must be freed with [jerry_release_value](#jerryreleasevalue) when it
is no longer needed.
@@ -415,7 +429,7 @@ jerry_parse (const jerry_char_t *source_p,
{
jerry_init (JERRY_INIT_EMPTY);
- char script [] = "print ('Hello, World!');";
+ const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
jerry_value_t parsed_code = jerry_parse (script, script_size, false);
@@ -434,7 +448,7 @@ jerry_parse (const jerry_char_t *source_p,
**Summary**
-Run code in Global scope.
+Run an EcmaScript function created by `jerry_parse`.
*Note*: The code should be previously parsed with `jerry_parse`.
@@ -442,7 +456,7 @@ Run code in Global scope.
```c
jerry_value_t
-jerry_run (jerry_value_t func_val);
+jerry_run (const jerry_value_t func_val);
```
- `func_val` - function to run
@@ -529,7 +543,7 @@ jerry_eval (const jerry_char_t *source_p,
Get the Global object.
-*Note*: Returned value must be freed with [jerry_release_object](#jerryreleaseobject) when it
+*Note*: Returned value must be freed with [jerry_release_value](#jerryreleasevalue) when it
is no longer needed.
**Prototype**
@@ -555,7 +569,7 @@ jerry_get_global_object (void);
**See also**
-- [jerry_release_object](#jerryreleaseobject)
+- [jerry_release_value](#jerryreleasevalue)
- [jerry_define_own_property](#jerrydefineownproperty)
# Checker functions
@@ -566,6 +580,8 @@ Functions to check the type of an API value ([jerry_value_t](#jerryvaluet)).
**Summary**
+Returns whether the given `jerry_value_t` is an array.
+
**Prototype**
```c
@@ -1026,7 +1042,7 @@ Get raw data from API values.
**Summary**
-Gets the raw bool value form a `jerry_value_t`.
+Gets the raw bool value from a `jerry_value_t`.
**Prototype**
@@ -1111,7 +1127,7 @@ jerry_get_number_value (const jerry_value_t value);
**Summary**
-Get the size of a string. Returns zero, if the specified string is not a value.
+Get the size of a string. Returns zero, if the value parameter is not a string.
**Prototype**
@@ -1126,7 +1142,7 @@ jerry_get_string_size (const jerry_value_t value);
```c
{
- jerry_char_t char_array[] = "a string";
+ const jerry_char_t char_array[] = "a string";
jerry_value_t string = jerry_create_string (char_array);
jerry_size_t string_size = jerry_get_string_size (string);
@@ -1147,7 +1163,7 @@ jerry_get_string_size (const jerry_value_t value);
**Summary**
-Get the length of a string. Returns zero, if the specified string is not a value.
+Get the length of a string. Returns zero, if the value parameter is not a string.
**Prototype**
@@ -1163,7 +1179,7 @@ jerry_get_string_length (const jerry_value_t value);
```c
{
- jerry_char_t char_array[] = "a string";
+ const jerry_char_t char_array[] = "a string";
jerry_value_t string = jerry_create_string (char_array);
jerry_length_t string_length = jerry_get_string_length (string);
@@ -1184,10 +1200,10 @@ jerry_get_string_length (const jerry_value_t value);
**Summary**
-Copy string characters to specified buffer. It is the caller's responsibility to make sure that
-the string fits in the buffer.
-
-*Note*: '\0' could occur in characters.
+Copy the characters of a string into a specified buffer. The
+'\0' character could occur in character buffer. Returns 0,
+if the value parameter is not a string or the buffer is
+not large enough for the whole string.
**Prototype**
@@ -1263,7 +1279,7 @@ jerry_get_array_length (const jerry_value_t value);
# Converters of 'jerry_value_t'
-Functions for convering API values to another value type.
+Functions for converting API values to another value type.
## jerry_value_to_boolean
@@ -1437,7 +1453,7 @@ jerry_value_to_string (const jerry_value_t value);
- `value` - api value
- return value
- - converted srting value, if success
+ - converted string value, if success
- thrown error, otherwise
**Example**
@@ -1459,7 +1475,7 @@ jerry_value_to_string (const jerry_value_t value);
- [jerry_value_to_primitive](#jerryvaluetoprimitive)
-# Aquire and release API values
+# Acquire and release API values
## jerry_acquire_value
@@ -1628,7 +1644,7 @@ jerry_create_error (jerry_error_t error_type,
```c
{
jerry_value_t error_obj = jerry_create_error (JERRY_ERROR_TYPE,
- (jerry_char_t * ) "error");
+ (const jerry_char_t *) "error");
... // usage of error_obj
@@ -1668,10 +1684,10 @@ jerry_create_error_sz (jerry_error_t error_type,
```c
{
- 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 ((char *) message));
+ strlen ((const char *) message));
... // usage of error_obj
@@ -1704,10 +1720,10 @@ jerry_create_external_function (jerry_external_handler_t handler_p);
```c
static jerry_value_t
-handler (const jerry_value_t function_obj_p,
- const jerry_value_t this_p,
+handler (const jerry_value_t function_obj,
+ const jerry_value_t this_val,
const jerry_value_t args_p[],
- const uint16_t args_cnt)
+ const jerry_length_t args_cnt)
{
printf ("native handler called!\n");
@@ -1719,7 +1735,7 @@ handler (const jerry_value_t function_obj_p,
jerry_value_t glob_obj = jerry_get_global_object ();
// after this, script can invoke the native handler through "handler_field (1, 2, 3);"
- jerry_value_t prop_name = jerry_create_string ((jerry_char_t *) "handler_field");
+ jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field");
jerry_set_property (glob_obj, prop_name, func_val);
jerry_release_value (prop_name);
@@ -1766,6 +1782,77 @@ jerry_create_number (double value);
**See also**
- [jerry_release_value](#jerryreleasevalue)
+- [jerry_create_number_infinity](#jerrycreatenumberinfinity)
+- [jerry_create_number_nan](#jerrycreatenumbernan)
+
+
+## jerry_create_number_infinity
+
+**Summary**
+
+Creates a `jerry_value_t` representing a positive or negative infinity value.
+
+**Prototype**
+
+```c
+jerry_value_t
+jerry_create_number_infinity (bool sign);
+```
+
+- `sign` - true for negative Infinity and false for positive Infinity
+- return value - a `jerry_value_t` representing the infinity value
+
+**Example**
+
+```c
+{
+ jerry_value_t positive_inf_value = jerry_create_number_infinity (false);
+
+ ... // usage of the positive_inf_value
+
+ jerry_release_value (positive_inf_value);
+}
+```
+
+**See also**
+
+- [jerry_release_value](#jerryreleasevalue)
+- [jerry_create_number](#jerrycreatenumber)
+- [jerry_create_number_nan](#jerrycreatenumbernan)
+
+
+## jerry_create_number_nan
+
+**Summary**
+
+Creates a `jerry_value_t` representing a not-a-number value.
+
+**Prototype**
+
+```c
+jerry_value_t
+jerry_create_number_nan (void);
+```
+
+- return value - a `jerry_value_t` representing the not-a-number value
+
+**Example**
+
+```c
+{
+ jerry_value_t nan_value = jerry_create_number_nan ();
+
+ ... // usage of the nan_value
+
+ jerry_release_value (nan_value);
+}
+```
+
+**See also**
+
+- [jerry_release_value](#jerryreleasevalue)
+- [jerry_create_number](#jerrycreatenumber)
+- [jerry_create_number_infinity](#jerrycreatenumberinfinity)
## jerry_create_null
@@ -1890,7 +1977,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 ((char *) char_array));
+ strlen ((const char *) char_array));
... // usage of string_value
@@ -1901,14 +1988,14 @@ jerry_create_string_sz (const jerry_char_t *str_p,
**See also**
-- [jerry_release_string](#jerryreleasestring)
+- [jerry_create_string](#jerrycreatestring)
## jerry_create_undefined
**Summary**
-Creates a jerry_value_t representing an undefined value.
+Creates a `jerry_value_t` representing an undefined value.
**Prototype**
@@ -1942,7 +2029,7 @@ jerry_create_undefined (void);
**Summary**
-Checks whether the object or it's prototype has the given property.
+Checks whether the object or it's prototype objects have the given property.
**Prototype**
@@ -1963,7 +2050,7 @@ jerry_has_property (const jerry_value_t obj_val,
```c
{
jerry_value_t global_object = jerry_get_global_object ();
- jerry_value_t prop_name = jerry_create_string ((jerry_char_t *) "handler_field");
+ jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field");
bool has_prop = jerry_has_property (global_object, prop_name);
@@ -2003,7 +2090,7 @@ jerry_has_own_property (const jerry_value_t obj_val,
```c
{
jerry_value_t global_object = jerry_get_global_object ();
- jerry_value_t prop_name = jerry_create_string ((jerry_char_t *) "handler_field");
+ jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "handler_field");
bool has_prop = jerry_has_own_property (global_object, prop_name);
@@ -2043,7 +2130,7 @@ jerry_delete_property (const jerry_value_t obj_val,
```c
{
jerry_value_t global_object = jerry_get_global_object ();
- jerry_value_t prop_name = jerry_create_string ((jerry_char_t *) "my_prop");
+ jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop");
jerry_delete_property (global_object, prop_name);
@@ -2124,7 +2211,7 @@ jerry_get_property_by_index (const jerry_value_t obj_val,
```
- `obj_val` - object value
-- index - index number
+- `index` - index number
- return value
- stored value on the specified index, if success
- thrown exception, otherwise.
@@ -2190,7 +2277,7 @@ jerry_set_property (const jerry_value_t obj_val,
... // create or acquire value to set
jerry_value_t glob_obj = jerry_get_global_object ();
- jerry_value_t prop_name = jerry_create_string ((jerry_char_t *) "my_prop");
+ jerry_value_t prop_name = jerry_create_string ((const jerry_char_t *) "my_prop");
jerry_set_property (glob_obj, prop_name, value_to_set);
@@ -2232,7 +2319,7 @@ jerry_set_property_by_index (const jerry_value_t obj_val,
```
- `obj_val` - object value
-- index - index number
+- `index` - index number
- `value_to_set` - value to set
- return value
- true, if field value was set successfully
@@ -2445,7 +2532,8 @@ jerry_free_property_descriptor_fields (const jerry_property_descriptor_t *prop_d
**Summary**
-Call function specified by a function value.
+Call function specified by a function value. Error flag
+must not be set for any arguments of this function.
*Note*: Returned value must be freed with [jerry_release_value](#jerryreleasevalue) when it
is no longer needed.
@@ -2501,6 +2589,7 @@ jerry_call_function (const jerry_value_t func_obj_val,
**Summary**
Construct object, invoking specified function object as constructor.
+Error flag must not be set for any arguments of this function.
*Note*: Returned value must be freed with [jerry_release_value](#jerryreleasevalue) when it
is no longer needed.
@@ -2511,7 +2600,7 @@ is no longer needed.
jerry_value_t
jerry_construct_object (const jerry_value_t func_obj_val,
const jerry_value_t args_p[],
- uint16_t args_count);
+ jerry_size_t args_count);
```
- `func_obj_val` - function object to call
@@ -2713,25 +2802,26 @@ jerry_get_object_native_handle (const jerry_value_t obj_val,
**Summary**
-Set native handle and, optionally, free callback for the specified object
+Set native handle and an optional free callback for the specified object
*Note*: If native handle was already set for the object, its value is updated.
-*Note*: If free callback is specified, it is set to be called upon specified JS-object is freed (by GC).
- Otherwise, if NULL is specified for free callback pointer, free callback is not created and, if
- a free callback was added earlier for the object, it is removed.
+*Note*: If a non-NULL free callback is specified, it will be called
+ by the garbage collector when the object is freed. The free
+ callback always overwrites the previous value, so passing
+ a NULL value deletes the current free callback.
**Prototype**
```c
void
jerry_set_object_native_handle (const jerry_value_t obj_val,
- uintptr_t handle,
+ uintptr_t handle_p,
jerry_object_free_callback_t freecb_p);
```
- `obj_val` - object value to set handle in
-- `handle` - handle value
+- `handle_p` - handle value
- `freecb_p` - pointer to "free" callback or NULL
**Example**
@@ -2774,14 +2864,13 @@ jerry_foreach_object_property (jerry_value_t obj_val,
```
- `obj_val` - object value
-- `foreach_p` - foreach function, that will be apllied for each property
+- `foreach_p` - foreach function, that will be applied for each property
- `user_data_p` - user data for foreach function
- return value
- true, if object fields traversal was performed successfully, i.e.:
- no unhandled exceptions were thrown in object fields traversal
- object fields traversal was stopped on callback that returned false
- - false, otherwise, if getter of field threw a exception or unhandled exceptions were thrown
- during traversal
+ - false, otherwise
**Example**
@@ -2834,13 +2923,13 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p,
- `source_p` - script source, it must be a valid utf8 string.
- `source_size` - script source size, in bytes.
- `is_for_global` - snapshot would be executed as global (true) or eval (false).
-- `is_strict` - stric mode
+- `is_strict` - strict mode
- `buffer_p` - buffer to save snapshot to.
- `buffer_size` - the buffer's size.
- return value
- the size of snapshot, 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)
+ JERRY_ENABLE_SNAPSHOT_SAVE)
- 0 otherwise.
**Example**
@@ -2850,10 +2939,10 @@ jerry_parse_and_save_snapshot (const jerry_char_t *source_p,
jerry_init (JERRY_INIT_EMPTY);
static uint8_t global_mode_snapshot_buffer[1024];
- const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
+ const jerry_char_t *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
- size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_char_t *) code_to_snapshot_p,
- strlen (code_to_snapshot_p),
+ size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot (code_to_snapshot_p,
+ strlen ((const char *) code_to_snapshot_p),
true,
false,
global_mode_snapshot_buffer,
@@ -2904,11 +2993,11 @@ jerry_exec_snapshot (const void *snapshot_p,
{
jerry_value_t res;
static uint8_t global_mode_snapshot_buffer[1024];
- const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
+ const jerry_char_t *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
jerry_init (JERRY_INIT_EMPTY);
- size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_char_t *) code_to_snapshot_p,
- strlen (code_to_snapshot_p),
+ size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot (code_to_snapshot_p,
+ strlen ((const char *) code_to_snapshot_p),
true,
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer));
diff --git a/03.API-EXAMPLE.md b/03.API-EXAMPLE.md
index 90c71e10..87248986 100644
--- a/03.API-EXAMPLE.md
+++ b/03.API-EXAMPLE.md
@@ -18,14 +18,14 @@ This guide is intended to introduce you to JerryScript embedding API through cre
#include "jerry-api.h"
int
-main (int argc, char * argv[])
+main (int argc, char *argv[])
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
bool ret_value = jerry_run_simple (script, script_size, JERRY_INIT_EMPTY);
- return (ret_value ? 1 : 0);
+ return (ret_value ? 0 : 1);
}
```
@@ -50,7 +50,7 @@ Here we perform the same actions, as `jerry_run_simple`, while splitting into se
#include "jerry-api.h"
int
-main (int argc, char * argv[])
+main (int argc, char *argv[])
{
const jerry_char_t script[] = "print ('Hello, World!');";
size_t script_size = strlen ((const char *) script);
@@ -89,7 +89,7 @@ Our code is more complex now, but it introduces possibilities to interact with J
#include "jerry-api.h"
int
-main (int argc, char * argv[])
+main (int argc, char *argv[])
{
const jerry_char_t script_1[] = "var s = 'Hello, World!';";
const jerry_char_t script_2[] = "print (s);";
@@ -131,7 +131,7 @@ This way, we execute two independent script parts in one execution environment.
#include "jerry-api.h"
int
-main (int argc, char * argv[]) {
+main (int argc, char *argv[]) {
const jerry_char_t str[] = "Hello, World!";
const jerry_char_t script[] = "print (s);";
@@ -193,27 +193,27 @@ print_value (const jerry_value_t value)
{
if (jerry_value_is_undefined (value))
{
- jerry_port_logmsg (stdout, "undefined");
+ jerry_port_console ("undefined");
}
else if (jerry_value_is_null (value))
{
- jerry_port_logmsg (stdout, "null");
+ jerry_port_console ("null");
}
else if (jerry_value_is_boolean (value))
{
if (jerry_get_boolean_value (value))
{
- jerry_port_logmsg (stdout, "true");
+ jerry_port_console ("true");
}
else
{
- jerry_port_logmsg (stdout, "false");
+ jerry_port_console ("false");
}
}
/* Float value */
else if (jerry_value_is_number (value))
{
- jerry_port_logmsg (stdout, "number");
+ jerry_port_console ("number");
}
/* String value */
else if (jerry_value_is_string (value))
@@ -223,16 +223,17 @@ print_value (const jerry_value_t value)
jerry_char_t str_buf_p[req_sz];
jerry_string_to_char_buffer (value, str_buf_p, req_sz);
+ str_buf_p[req_sz] = '\0';
- jerry_port_logmsg (stdout, "%s", (const char *) str_buf_p);
+ jerry_port_console ("%s", (const char *) str_buf_p);
}
/* Object reference */
else if (jerry_value_is_object (value))
{
- jerry_port_logmsg (stdout, "[JS object]");
+ jerry_port_console ("[JS object]");
}
- jerry_port_logmsg (stdout, "\n");
+ jerry_port_console ("\n");
}
```
@@ -257,10 +258,10 @@ Shell operation can be described with the following loop:
#include "jerry-api.h"
#include "jerry-port.h"
-static void print_value (const jerry_api_value_t);
+static void print_value (const jerry_value_t);
int
-main (int argc, char * argv[])
+main (int argc, char *argv[])
{
bool is_done = false;
@@ -269,11 +270,11 @@ main (int argc, char * argv[])
while (!is_done)
{
- char cmd [256];
+ char cmd[256] = {};
char *cmd_tail = cmd;
size_t len = 0;
- jerry_port_logmsg (stdout, "> ");
+ jerry_port_console ("> ");
/* Read next command */
while (true)
@@ -292,6 +293,12 @@ main (int argc, char * argv[])
len++;
}
+ /* If the command is "quit", break the loop */
+ if (!strncmp (cmd, "quit\n", strlen ("quit\n")))
+ {
+ break;
+ }
+
jerry_value_t ret_val;
/* Evaluate entered command */
@@ -304,7 +311,7 @@ main (int argc, char * argv[])
{
/* Evaluated JS code thrown an exception
* and didn't handle it with try-catch-finally */
- jerry_port_errormsg ("Unhandled JS exception occured: ");
+ jerry_port_console ("Unhandled JS exception occured: ");
}
print_value (ret_val);
@@ -346,7 +353,7 @@ get_msg_handler (const jerry_value_t func_value, /**< function object */
} /* get_msg_handler */
int
-main (int argc, char * argv[])
+main (int argc, char *argv[])
{
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
@@ -448,7 +455,7 @@ add_handler (const jerry_value_t func_value, /**< function object */
} /* add_handler */
int
-main (int argc, char * argv[])
+main (int argc, char *argv[])
{
/* Initialize engine */
jerry_init (JERRY_INIT_EMPTY);
@@ -514,4 +521,4 @@ Value of x is 17
## Further steps
-For further API description, please visit [API Reference page](https://samsung.github.io/jerryscript/API/) on [JerryScript home page](https://samsung.github.io/jerryscript/).
+For further API description, please visit [API Reference page](https://samsung.github.io/jerryscript/api-reference/) on [JerryScript home page](https://samsung.github.io/jerryscript/).
diff --git a/04.INTERNALS.md b/04.INTERNALS.md
index 52f68527..12891451 100644
--- a/04.INTERNALS.md
+++ b/04.INTERNALS.md
@@ -22,7 +22,7 @@ The lexer splits input string (ECMAScript program) into sequence of tokens. It i
## Scanner
-Scanner (`./jerry-core/parser/js/js-parser-scanner.h`) pre-scans the input string to find certain tokens. For example, scanner determines whether the keyword `for` defines a general for or a for-in loop. Reading tokens in a while loop is not enough because a slash (`/`) can indicate the start of a regular expression or can be a division operator.
+Scanner (`./jerry-core/parser/js/js-parser-scanner.c`) pre-scans the input string to find certain tokens. For example, scanner determines whether the keyword `for` defines a general for or a for-in loop. Reading tokens in a while loop is not enough because a slash (`/`) can indicate the start of a regular expression or can be a division operator.
## Expression Parser
@@ -30,9 +30,9 @@ Expression parser is responsible for parsing JavaScript expressions. It is imple
## Statement Parser
-JavaScript statements are parsed by this component. It uses the [Expression parser](#expression parser) to parse the constituent expressions. The implementation of Statement parser is located in `./jerry-core/parser/js/js-parser-statm.c`.
+JavaScript statements are parsed by this component. It uses the [Expression parser](#expression-parser) to parse the constituent expressions. The implementation of Statement parser is located in `./jerry-core/parser/js/js-parser-statm.c`.
-Function `parser_parse_source` carries out the parsing and compiling of the input EcmaScript source code. When a function appears in the source `parser_parse_source` calls `parser_parse_function` which is responsible for processing the source code of functions recursively including argument parsing and context handling. After the parsing, function `parser_post_processing` dumps the created opcodes and returns an ecma_compiled_code_t* that points to the compiled bytecode sequence.
+Function `parser_parse_source` carries out the parsing and compiling of the input EcmaScript source code. When a function appears in the source `parser_parse_source` calls `parser_parse_function` which is responsible for processing the source code of functions recursively including argument parsing and context handling. After the parsing, function `parser_post_processing` dumps the created opcodes and returns an `ecma_compiled_code_t*` that points to the compiled bytecode sequence.
The interactions between the major components shown on the following figure.
@@ -70,9 +70,9 @@ There are three types of bytecode arguments in CBC:
* __byte argument__: A value between 0 and 255, which often represents the argument count of call like opcodes (function call, new, eval, etc.).
- * __literal argument__: An integer index which is greater or equal than zero and less than the `literal_end` field of the header. For further information see next section Literals (next).
+ * __literal argument__: An integer index which is greater or equal than zero and less than the `literal_end` field of the header. For further information see next section Literals (next).
- * __relative branch__: An 1-3 byte long offset. The branch argument might also represent the end of an instruction range. For example the branch argument of `CBC_EXT_WITH_CREATE_CONTEXT` shows the end of a with statement. More precisely the position after the last instruction.
+ * __relative branch__: An 1-3 byte long offset. The branch argument might also represent the end of an instruction range. For example the branch argument of `CBC_EXT_WITH_CREATE_CONTEXT` shows the end of a `with` statement. More precisely the position after the last instruction.
Argument combinations are limited to the following seven forms:
@@ -101,30 +101,30 @@ There are two other sub-groups of identifiers. *Registers* are those identifiers
There are two types of literal encoding in CBC. Both are variable length, where the length is one or two byte long.
* __small__: maximum 511 literals can be encoded.
-
+
One byte encoding for literals 0 - 254.
-
+
```c
byte[0] = literal_index
```
Two byte encoding for literals 255 - 510.
-
+
```c
byte[0] = 0xff
byte[1] = literal_index - 0xff
```
* __full__: maximum 32767 literal can be encoded.
-
+
One byte encoding for literals 0 - 127.
-
+
```c
byte[0] = literal_index
```
Two byte encoding for literals 128 - 32767.
-
+
```c
byte[0] = (literal_index >> 8) | 0x80
byte[1] = (literal_index & 0xff)
@@ -146,12 +146,12 @@ Byte-codes of this category serve for placing objects onto the stack. As there a
<div class="CSSTableGenerator" markdown="block">
-| byte-code | description |
-| CBC_PUSH_LITERAL | Pushes the value of the given literal argument. |
-| CBC_PUSH_TWO_LITERALS | Pushes the value of the given two literal arguments. |
-| CBC_PUSH_UNDEFINED | Pushes an undefined value. |
-| CBC_PUSH_TRUE | Pushes a logical true. |
-| CBC_PUSH_PROP_LITERAL | Pushes a property whose base object is popped from the stack, and the property name is passed as a literal argument. |
+| byte-code | description |
+| CBC_PUSH_LITERAL | Pushes the value of the given literal argument. |
+| CBC_PUSH_TWO_LITERALS | Pushes the value of the given two literal arguments. |
+| CBC_PUSH_UNDEFINED | Pushes an undefined value. |
+| CBC_PUSH_TRUE | Pushes a logical true. |
+| CBC_PUSH_PROP_LITERAL | Pushes a property whose base object is popped from the stack, and the property name is passed as a literal argument. |
</div>
@@ -161,30 +161,30 @@ The byte-codes of this category perform calls in different ways.
<div class="CSSTableGenerator" markdown="block">
-| byte-code | description |
-| CBC_CALL0 | Calls a function without arguments. The return value won't be pushed onto the stack. |
-| CBC_CALL1 | Calls a function with one argument. The return value won't be pushed onto the stack. |
-| CBC_CALL | Calls a function with n arguments. n is passed as a byte argument. The return value won't be pushed onto the stack. |
-| CBC_CALL0_PUSH_RESULT | Calls a function without arguments. The return value will be pushed onto the stack. |
-| CBC_CALL1_PUSH_RESULT | Calls a function with one argument. The return value will be pushed onto the stack. |
-| CBC_CALL2_PROP | Calls a property function with two arguments. The base object, the property name, and the two arguments are on the stack. |
+| byte-code | description |
+| CBC_CALL0 | Calls a function without arguments. The return value won't be pushed onto the stack. |
+| CBC_CALL1 | Calls a function with one argument. The return value won't be pushed onto the stack. |
+| CBC_CALL | Calls a function with n arguments. n is passed as a byte argument. The return value won't be pushed onto the stack. |
+| CBC_CALL0_PUSH_RESULT | Calls a function without arguments. The return value will be pushed onto the stack. |
+| CBC_CALL1_PUSH_RESULT | Calls a function with one argument. The return value will be pushed onto the stack. |
+| CBC_CALL2_PROP | Calls a property function with two arguments. The base object, the property name, and the two arguments are on the stack. |
</div>
### Arithmetic, Logical, Bitwise and Assignment Byte-codes
-The opcodes of this category perform arithmetic, logical, bitwise and assignment operations according to the different
+The opcodes of this category perform arithmetic, logical, bitwise and assignment operations.
<div class="CSSTableGenerator" markdown="block">
-| byte-code | description |
-| CBC_LOGICAL_NOT | Negates the logical value that popped from the stack. The result is pushed onto the stack. |
-| CBC_LOGICAL_NOT_LITERAL | Negates the logical value that given in literal argument. The result is pushed onto the stack. |
-| CBC_ADD | Adds two values that are poped from the stack. The result is pushed onto the stack. |
-| CBC_ADD_RIGHT_LITERAL | Adds two values. The left one popped from the stack, the right one is given as literal argument. |
-| CBC_ADD_TWO_LITERALS | Adds two values. Both are given as literal arguments. |
-| CBC_ASSIGN | Assigns a value to a property. It has three arguments: base object, property name, value to assign. |
-| CBC_ASSIGN_PUSH_RESULT | Assigns a value to a property. It has three arguments: base object, property name, value to assign. The result will be pushed onto the stack. |
+| byte-code | description |
+| CBC_LOGICAL_NOT | Negates the logical value that popped from the stack. The result is pushed onto the stack. |
+| CBC_LOGICAL_NOT_LITERAL | Negates the logical value that given in literal argument. The result is pushed onto the stack. |
+| CBC_ADD | Adds two values that are popped from the stack. The result is pushed onto the stack. |
+| CBC_ADD_RIGHT_LITERAL | Adds two values. The left one popped from the stack, the right one is given as literal argument. |
+| CBC_ADD_TWO_LITERALS | Adds two values. Both are given as literal arguments. |
+| CBC_ASSIGN | Assigns a value to a property. It has three arguments: base object, property name, value to assign. |
+| CBC_ASSIGN_PUSH_RESULT | Assigns a value to a property. It has three arguments: base object, property name, value to assign. The result will be pushed onto the stack. |
</div>
@@ -194,14 +194,14 @@ Branch byte-codes are used to perform conditional and unconditional jumps in the
<div class="CSSTableGenerator" markdown="block">
-| byte-code | description |
-| CBC_JUMP_FORWARD | Jumps forward by the 1 byte long relative offset argument. |
-| CBC_JUMP_FORWARD_2 | Jumps forward by the 2 byte long relative offset argument. |
-| CBC_JUMP_FORWARD_3 | Jumps forward by the 3 byte long relative offset argument. |
-| CBC_JUMP_BACKWARD | Jumps backward by the 1 byte long relative offset argument. |
-| CBC_JUMP_BACKWARD_2 | Jumps backward by the 2 byte long relative offset argument. |
-| CBC_JUMP_BACKWARD_3 | Jumps backward by the 3 byte long relative offset argument. |
-| CBC_BRANCH_IF_TRUE_FORWARD | Jumps if the value on the top of the stack is true by the 1 byte long relative offset argument. |
+| byte-code | description |
+| CBC_JUMP_FORWARD | Jumps forward by the 1 byte long relative offset argument. |
+| CBC_JUMP_FORWARD_2 | Jumps forward by the 2 byte long relative offset argument. |
+| CBC_JUMP_FORWARD_3 | Jumps forward by the 3 byte long relative offset argument. |
+| CBC_JUMP_BACKWARD | Jumps backward by the 1 byte long relative offset argument. |
+| CBC_JUMP_BACKWARD_2 | Jumps backward by the 2 byte long relative offset argument. |
+| CBC_JUMP_BACKWARD_3 | Jumps backward by the 3 byte long relative offset argument. |
+| CBC_BRANCH_IF_TRUE_FORWARD | Jumps if the value on the top of the stack is true by the 1 byte long relative offset argument. |
</div>
@@ -248,7 +248,7 @@ Compressed pointers were introduced to save heap space.
![Compressed Pointer]({{ site.baseurl }}/img/ecma_compressed.png){: class="thumbnail center-block img-responsive" }
-These pointers are 8 byte alligned 16 bit long pointers which can address 512 Kb of memory which is also the maximum size of the JerryScript heap.
+These pointers are 8 byte aligned 16 bit long pointers which can address 512 Kb of memory which is also the maximum size of the JerryScript heap.
ECMA data elements are allocated in pools (pools are allocated on heap)
Chunk size of the pool is 8 bytes (reduces fragmentation).
@@ -256,9 +256,8 @@ Chunk size of the pool is 8 bytes (reduces fragmentation).
### Number
There are two possible representation of numbers according to standard IEEE 754:
-
-* 4-byte (float, compact profile)
-* 8-byte (double, full profile)
+The default is 8-byte (double),
+but the engine supports the 4-byte (single precision) representation by setting CONFIG_ECMA_NUMBER_TYPE as well.
![Number]({{ site.baseurl }}/img/number.png){: class="thumbnail center-block img-responsive" }
@@ -272,7 +271,7 @@ Strings in JerryScript are not just character sequences, but can hold numbers an
An object can be a conventional data object or a lexical environment object. Unlike other data types, object can have references (called properties) to other data types. Because of circular references, reference counting is not always enough to determine dead objects. Hence a chain list is formed from all existing objects, which can be used to find unreferenced objects during garbage collection. The `gc-next` pointer of each object shows the next allocated object in the chain list.
-Lexical environments (link) are implemented as objects in JerryScript, since lexical environments contains key-value pairs (called bindings) like objects. This simplifies the implementation and reduces code size.
+[Lexical environments](http://www.ecma-international.org/ecma-262/5.1/#sec-10.2) are implemented as objects in JerryScript, since lexical environments contains key-value pairs (called bindings) like objects. This simplifies the implementation and reduces code size.
![Object/Lexicat environment structures]({{ site.baseurl }}/img/ecma_object.png){: class="thumbnail center-block img-responsive" }
@@ -292,13 +291,13 @@ A property is 7 bit long and its type field is 2 bit long which consumes 9 bit w
#### Property Hashmap
-If the number of property pairs reach a limit (currently this limit is defined to 16), a hash map (called [Property Hashmap](#Property Hashmap)) is inserted at the first position of the property pair list, in order to find a property using it, instead of finding it by iterating linearly over the property pairs.
+If the number of property pairs reach a limit (currently this limit is defined to 16), a hash map (called [Property Hashmap](#property-hashmap)) is inserted at the first position of the property pair list, in order to find a property using it, instead of finding it by iterating linearly over the property pairs.
Property hashmap contains 2<sup>n</sup> elements, where 2<sup>n</sup> is larger than the number of properties of the object. Each element can have tree types of value:
* null, indicating an empty element
* deleted, indicating a deleted property, or
-* reference to the existing property
+* reference to the existing property
This hashmap is a must-return type cache, meaning that every property that the object have, can be found using it.
@@ -318,7 +317,7 @@ LCache is a hashmap for finding a property specified by an object and by a prope
![LCache]({{ site.baseurl }}/img/ecma_lcache.png){: class="thumbnail center-block img-responsive" }
-When a property access occurs, a hash value is extracted form the demanded property name and than this hash is used to index the LCache. After that, in the indexed row the specified object and property name will be searched.
+When a property access occurs, a hash value is extracted from the demanded property name and than this hash is used to index the LCache. After that, in the indexed row the specified object and property name will be searched.
It is important to note, that if the specified property is not found in the LCache, it does not mean that it does not exist (i.e. LCache is a may-return cache). If the property is not found, it will be searched in the property-list of the object, and if it is found there, the property will be placed into the LCache.
diff --git a/img/bytecode-layout.png b/img/bytecode-layout.png
new file mode 100644
index 00000000..3d8bbafe
--- /dev/null
+++ b/img/bytecode-layout.png
Binary files differ