aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZsolt Borbély <zsborbely.u-szeged@partner.samsung.com>2017-10-25 09:44:56 +0200
committeryichoi <duddlf.choi@samsung.com>2017-10-25 17:50:23 +0900
commit196c4cb17e79b29d5181d492bf63c05c20f0bb93 (patch)
tree9a283e73b350f6f1826ebb7a1161033a7cfdcb81
parent962807a13f905c4184aea15bb69943c151d96614 (diff)
Update the webpage
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
-rw-r--r--02.API-REFERENCE.md242
1 files changed, 242 insertions, 0 deletions
diff --git a/02.API-REFERENCE.md b/02.API-REFERENCE.md
index c44ddaff..373ff6eb 100644
--- a/02.API-REFERENCE.md
+++ b/02.API-REFERENCE.md
@@ -4180,6 +4180,78 @@ main (void)
- [jerry_exec_snapshot](#jerry_exec_snapshot)
+## jerry_parse_and_save_function_snapshot
+
+**Summary**
+
+Generate function snapshot from the specified source code
+with the given arguments.
+
+The function arguments and function body are
+passed as separated arguments.
+
+**Prototype**
+
+```c
+size_t
+jerry_parse_and_save_function_snapshot (const jerry_char_t *source_p,
+ size_t source_size,
+ const jerry_char_t *args_p,
+ size_t args_size,
+ bool is_strict,
+ uint32_t *buffer_p,
+ size_t buffer_size)
+```
+
+- `source_p` - script source, it must be a valid utf8 string.
+- `source_size` - script source size, in bytes.
+- `args_p` - function arguments, it must be a valid utf8 string.
+- `args_size` - function argument size, in bytes.
+- `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_SAVE)
+ - 0 otherwise.
+
+**Example**
+
+[doctest]: # ()
+
+```c
+#include <string.h>
+#include "jerryscript.h"
+
+int
+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;";
+
+ size_t func_snapshot_size = jerry_parse_and_save_function_snapshot (src_p,
+ strlen ((const char *) src_p),
+ args_p,
+ strlen ((const char *) args_p),
+ false,
+ func_snapshot_buffer,
+ sizeof (func_snapshot_buffer) / sizeof (uint32_t));
+
+ jerry_cleanup ();
+}
+```
+
+**See also**
+
+- [jerry_init](#jerry_init)
+- [jerry_cleanup](#jerry_cleanup)
+- [jerry_load_function_snapshot_at](#jerry_load_function_snapshot_at)
+
+
## jerry_exec_snapshot
**Summary**
@@ -4246,9 +4318,179 @@ main (void)
- [jerry_init](#jerry_init)
- [jerry_cleanup](#jerry_cleanup)
+- [jerry_exec_snapshot_at](#jerry_exec_snapshot_at)
+- [jerry_parse_and_save_snapshot](#jerry_parse_and_save_snapshot)
+
+
+## jerry_exec_snapshot_at
+
+**Summary**
+
+Execute the selected snapshot function from the specified buffer.
+
+Same function as [jerry_exec_snapshot](#jerry_exec_snapshot) except
+the executed function index can be specified.
+
+*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_exec_snapshot_at (const uint32_t *snapshot_p,
+ size_t snapshot_size,
+ size_t func_index,
+ bool copy_bytecode);
+```
+
+- `snapshot_p` - pointer to snapshot
+- `snapshot_size` - size of snapshot
+- `func_index` - index of executed function
+- `copy_bytecode` - flag, indicating whether the passed snapshot buffer should be copied to the
+ engine's memory. If set the engine should not reference the buffer after the function returns
+ (in this case, the passed buffer could be freed after the call). Otherwise (if the flag is not
+ set) - the buffer could only be freed after the engine stops (i.e. after call to jerry_cleanup).
+- return value
+ - result of bytecode, if run was successful
+ - thrown error, otherwise
+
+**Example**
+
+[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'; }) ();";
+
+ jerry_init (JERRY_INIT_EMPTY);
+ 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,
+ sizeof (global_mode_snapshot_buffer) / sizeof (uint32_t));
+ jerry_cleanup ();
+
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t res = jerry_exec_snapshot_at (global_mode_snapshot_buffer,
+ global_mode_snapshot_size,
+ 0,
+ false);
+
+ jerry_release_value (res);
+
+ jerry_cleanup ();
+ return 0;
+}
+```
+
+**See also**
+
+- [jerry_init](#jerry_init)
+- [jerry_cleanup](#jerry_cleanup)
+- [jerry_exec_snapshot](#jerry_exec_snapshot)
- [jerry_parse_and_save_snapshot](#jerry_parse_and_save_snapshot)
+## jerry_load_function_snapshot_at
+
+**Summary**
+
+Load the selected snapshot function from the specified buffer as a function object.
+
+The lexical environment of the loaded function is always the global lexical environment.
+
+*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_load_function_snapshot_at (const uint32_t *snapshot_p,
+ size_t snapshot_size,
+ size_t func_index,
+ bool copy_bytecode);
+```
+
+- `snapshot_p` - pointer to snapshot
+- `snapshot_size` - size of snapshot
+- `func_index` - index of function to load
+- `copy_bytecode` - flag, indicating whether the passed snapshot buffer should be copied to the
+ engine's memory. If set the engine should not reference the buffer after the function returns
+ (in this case, the passed buffer could be freed after the call). Otherwise (if the flag is not
+ set) - the buffer could only be freed after the engine stops (i.e. after call to jerry_cleanup).
+- return value
+ - function object built from the snapshot
+ - thrown error, otherwise
+
+**Example**
+
+[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;";
+
+ jerry_init (JERRY_INIT_EMPTY);
+ size_t snapshot_size = jerry_parse_and_save_function_snapshot (src_p,
+ strlen ((const char *) src_p),
+ args_p,
+ strlen ((const char *) args_p),
+ false,
+ snapshot_buffer,
+ sizeof (snapshot_buffer) / sizeof (uint32_t));
+ jerry_cleanup ();
+
+ jerry_init (JERRY_INIT_EMPTY);
+
+ jerry_value_t func = jerry_load_function_snapshot_at (snapshot_buffer,
+ snapshot_size,
+ 0,
+ false);
+ /* 'func' can be used now as a function object */
+
+ jerry_value_t this_value = jerry_create_undefined ();
+ jerry_value_t args[2];
+ args[0] = jerry_create_number (1.0);
+ args[1] = jerry_create_number (2.0);
+
+ jerry_value_t res = jerry_call_function (func, this_value, args, 2);
+
+ /* 'res' now contains the value 3 as a jerry_value_t */
+
+ jerry_release_value (args[0]);
+ jerry_release_value (args[1]);
+ jerry_release_value (this_value);
+ jerry_release_value (func);
+
+ jerry_cleanup ();
+ return 0;
+}
+```
+
+**See also**
+
+- [jerry_init](#jerry_init)
+- [jerry_cleanup](#jerry_cleanup)
+- [jerry_parse_and_save_function_snapshot](#jerry_parse_and_save_function_snapshot)
+
+
## jerry_parse_and_save_literals
**Summary**