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:
Akos Kiss
2018-09-04 13:56:49 +02:00
committed by GitHub
parent d3d42f7685
commit 30b7a72344
9 changed files with 145 additions and 140 deletions
+30 -30
View File
@@ -238,32 +238,32 @@ typedef struct
} jerry_context_data_manager_t;
```
## jerry_instance_alloc_t
## jerry_context_alloc_t
**Summary**
Function type for allocating buffer for JerryScript instance.
Function type for allocating buffer for JerryScript context.
**Prototype**
```c
typedef void *(*jerry_instance_alloc_t) (size_t size, void *cb_data_p);
typedef void *(*jerry_context_alloc_t) (size_t size, void *cb_data_p);
```
- `size` - allocation size
- `cb_data_p` - pointer to user data
## jerry_instance_t
## jerry_context_t
**Summary**
An opaque declaration of the JerryScript instance structure which is the header of the context space.
An opaque declaration of the JerryScript context structure.
**Prototype**
```c
typedef struct jerry_instance_t jerry_instance_t;
typedef struct jerry_context_t jerry_context_t;
```
## jerry_property_descriptor_t
@@ -4877,26 +4877,26 @@ main (void)
# External context functions
## jerry_create_instance
## jerry_create_context
**Summary**
Creates a JerryScript instance for external context.
Create an external JerryScript engine context.
**Prototype**
```c
jerry_instance_t *
jerry_create_instance (uint32_t heap_size,
jerry_instance_alloc_t alloc,
void *cb_data_p);
jerry_context_t *
jerry_create_context (uint32_t heap_size,
jerry_context_alloc_t alloc,
void *cb_data_p);
```
- `heap_size` - requested heap size of the JerryScript instance
- `heap_size` - requested heap size of the JerryScript context
- `alloc` - function for allocation
- `cb_data_p` - user data
- return value
- pointer to the newly created JerryScript instance if success
- pointer to the newly created JerryScript context if success
- NULL otherwise.
**Example**
@@ -4910,19 +4910,19 @@ jerry_create_instance (uint32_t heap_size,
#include "jerryscript.h"
#include "jerryscript-port.h"
/* A different Thread Local Storage variable for each jerry instance. */
__thread jerry_instance_t *tls_instance;
/* A different Thread Local Storage variable for each jerry context. */
__thread jerry_context_t *tls_context;
jerry_instance_t *
jerry_port_get_current_instance (void)
jerry_context_t *
jerry_port_get_current_context (void)
{
/* Returns the instance assigned to the thread. */
return tls_instance;
/* Returns the context assigned to the thread. */
return tls_context;
}
/* Allocate JerryScript heap for each thread. */
static void *
instance_alloc_fn (size_t size, void *cb_data)
context_alloc_fn (size_t size, void *cb_data)
{
(void) cb_data;
return malloc (size);
@@ -4931,15 +4931,15 @@ instance_alloc_fn (size_t size, void *cb_data)
static void *
thread_function (void *param)
{
tls_instance = jerry_create_instance (512 * 1024,
instance_alloc_fn,
NULL);
tls_context = jerry_create_context (512 * 1024,
context_alloc_fn,
NULL);
jerry_init (JERRY_INIT_EMPTY);
/* Run the JerryScript instance (e.g.: jerry_parse & jerry_run) */
/* Run JerryScript in the context (e.g.: jerry_parse & jerry_run) */
jerry_cleanup ();
/* Deallocate JerryScript instance */
free (tls_instance);
/* Deallocate JerryScript context */
free (tls_context);
return NULL;
}
@@ -4969,9 +4969,9 @@ main (void)
**See also**
- [jerry_instance_t](#jerry_instance_t)
- [jerry_instance_alloc_t](#jerry_instance_alloc_t)
- [jerry_port_get_current_instance](05.PORT-API.md#jerry_port_get_current_instance)
- [jerry_context_t](#jerry_context_t)
- [jerry_context_alloc_t](#jerry_context_alloc_t)
- [jerry_port_get_current_context](05.PORT-API.md#jerry_port_get_current_context)
# Snapshot functions