Merge instance into context (#2501)
There was quite some confusion about terminology around instances and contexts. All the docs mentioned external contexts but functions and types were referring to instances, and the relation between these two concepts were not clear. This commit keeps (external) context as the only surviving concept. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
+22
-19
@@ -112,23 +112,25 @@ bool jerry_port_get_time_zone (jerry_time_zone_t *tz_p);
|
||||
double jerry_port_get_current_time (void);
|
||||
```
|
||||
|
||||
## External instance
|
||||
## External context
|
||||
|
||||
Allow user to provide external buffer for jerry instance (which includes an isolated context and heap with other instances), so that user can config the heap size in runtime and run multiple JS apps simultaneously.
|
||||
Allow user to provide external buffer for isolated engine contexts, so that user
|
||||
can configure the heap size at runtime and run multiple JS applications
|
||||
simultaneously.
|
||||
|
||||
```c
|
||||
/**
|
||||
* Get the current instance which contains the current context, heap and other
|
||||
* structures. Each port should provide its own implementation of this interface.
|
||||
* Get the current context of the engine. Each port should provide its own
|
||||
* implementation of this interface.
|
||||
*
|
||||
* Note:
|
||||
* This port function is called by jerry-core when
|
||||
* JERRY_ENABLE_EXTERNAL_CONTEXT is defined. Otherwise this function is not
|
||||
* used.
|
||||
*
|
||||
* @return the pointer to the jerry instance.
|
||||
* @return the pointer to the engine context.
|
||||
*/
|
||||
struct jerry_instance_t *jerry_port_get_current_instance (void);
|
||||
struct jerry_context_t *jerry_port_get_current_context (void);
|
||||
```
|
||||
|
||||
## Sleep
|
||||
@@ -233,37 +235,38 @@ double jerry_port_get_current_time (void)
|
||||
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
|
||||
} /* jerry_port_get_current_time */
|
||||
```
|
||||
## External instance
|
||||
|
||||
## External context
|
||||
|
||||
```c
|
||||
#include "jerryscript-port.h"
|
||||
#include "jerryscript-port-default.h"
|
||||
|
||||
/**
|
||||
* Pointer to the current instance.
|
||||
* Pointer to the current context.
|
||||
* Note that it is a global variable, and is not a thread safe implementation.
|
||||
*/
|
||||
static jerry_instance_t *current_instance_p = NULL;
|
||||
static jerry_context_t *current_context_p = NULL;
|
||||
|
||||
/**
|
||||
* Set the current_instance_p as the passed pointer.
|
||||
* Set the current_context_p as the passed pointer.
|
||||
*/
|
||||
void
|
||||
jerry_port_default_set_instance (jerry_instance_t *instance_p) /**< points to the created instance */
|
||||
jerry_port_default_set_context (jerry_context_t *context_p) /**< points to the created context */
|
||||
{
|
||||
current_instance_p = instance_p;
|
||||
} /* jerry_port_default_set_instance */
|
||||
current_context_p = context_p;
|
||||
} /* jerry_port_default_set_context */
|
||||
|
||||
/**
|
||||
* Get the current instance.
|
||||
* Get the current context.
|
||||
*
|
||||
* @return the pointer to the current instance
|
||||
* @return the pointer to the current context
|
||||
*/
|
||||
jerry_instance_t *
|
||||
jerry_port_get_current_instance (void)
|
||||
jerry_context_t *
|
||||
jerry_port_get_current_context (void)
|
||||
{
|
||||
return current_instance_p;
|
||||
} /* jerry_port_get_current_instance */
|
||||
return current_context_p;
|
||||
} /* jerry_port_get_current_context */
|
||||
```
|
||||
|
||||
## Sleep
|
||||
|
||||
Reference in New Issue
Block a user