diff options
author | Zidong Jiang <zidong.jiang@intel.com> | 2017-05-20 11:00:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-20 11:00:19 +0800 |
commit | 5e28bfc28ada61684f166deee994f1ff84c4db08 (patch) | |
tree | 17b84c2ba143f5c720126599c701f40d18fb5c32 /jerry-main | |
parent | c6d890ee135b8ba4c627a577679cee17104fe888 (diff) |
Support external context, heap and lcache (#1778)
JerryScript should support external context, heap and lcache,
so that it can have multiple instances and runtime configurable heap
size.
Related issue: 1746
JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
Diffstat (limited to 'jerry-main')
-rw-r--r-- | jerry-main/CMakeLists.txt | 4 | ||||
-rw-r--r-- | jerry-main/main-unix.c | 25 |
2 files changed, 28 insertions, 1 deletions
diff --git a/jerry-main/CMakeLists.txt b/jerry-main/CMakeLists.txt index b2cc6515..5624d984 100644 --- a/jerry-main/CMakeLists.txt +++ b/jerry-main/CMakeLists.txt @@ -55,6 +55,10 @@ macro(jerry_create_executable JERRY_NAME) install(TARGETS ${JERRY_NAME} DESTINATION bin) endmacro() +if(JERRY_LIBC AND FEATURE_EXTERNAL_CONTEXT) + MESSAGE(FATAL_ERROR "This configuration is not supported for jerry-main. Please build against your system libc to enable the external context.") +endif() + # Jerry standalones if(JERRY_CMDLINE) jerry_create_executable("jerry" "main-unix.c" "cli.c") diff --git a/jerry-main/main-unix.c b/jerry-main/main-unix.c index 6cb4af8a..7586a4eb 100644 --- a/jerry-main/main-unix.c +++ b/jerry-main/main-unix.c @@ -390,6 +390,20 @@ check_usage (bool condition, /**< the condition that must hold */ } } /* check_usage */ +#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT + +/** + * The alloc function passed to jerry_create_instance + */ +static void * +instance_alloc (size_t size, + void *cb_data_p __attribute__((unused))) +{ + return malloc (size); +} /* instance_alloc */ + +#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */ + int main (int argc, char **argv) @@ -560,6 +574,13 @@ main (int argc, is_repl_mode = true; } +#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT + + jerry_instance_t *instance_p = jerry_create_instance (512*1024, instance_alloc, NULL); + jerry_port_default_set_instance (instance_p); + +#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */ + jerry_init (flags); register_js_function ("assert", jerryx_handler_assert); @@ -764,6 +785,8 @@ main (int argc, } jerry_release_value (ret_value); jerry_cleanup (); - +#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT + free (instance_p); +#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */ return ret_code; } /* main */ |