Skip to content

Commit ac1c48e

Browse files
authored
Update jerry-port and jerry-ext (jerryscript-project#4907)
Notable changes: - Updated and the port API interface, new functions have been added and some have been changed. The port library is now cleaned up to not have any dependency on jerry-core, as it should be. The port library is now strictly a collection of functions that implement embedding/platform specific behavior. - The default port implementation has been split for windows and unix. Implemented port functions have been categorized and reorganized, and marked with attribute((weak)) for better reusability. - External context allocation has been moved to the port API instead of a core API callback. The iterface has also been extended with a function to free the allocated context. When external context is enabled, jerry_init now automatically calls the port implementation to allocate the context and jerry_cleanup automatically calls the port to free the context. - jerry_port_log has been changed to no longer require formatting to be implemented by the port. The reason beind this is that it was vague what format specifiers were used by the engine, and in what manner. The port function now takes a zero-terminated string, and should only implement how the string should be logged. - Logging and log message formatting is now handled by the core jerry library where it can be implemented as necessary. Logging can be done through a new core API function, which uses the port to output the final log message. - Log level has been moved into jerry-core, and an API function has been added to set the log level. It should be the library that filters log messages based on the requested log level, instead of logging everything and requiring the user to do so. - Module resolving logic has been moved into jerry-core. There's no reason to have it in the port library and requiring embedders to duplicate the code. It also added an unnecessary dependency on jerry-core to the port. Platform specific behavior is still used through the port API, like resolving module specifiers, and reading source file contents. If necessary, the resolving logic can still be overridden as previously. - The jerry-ext library has also been cleaned up, and many utility functions have been added that previously were implemented in jerry-main. This allows easier reusability for some common operations, like printing unhandled exceptions or providing a repl console. - Debugger interaction with logged/printed messages has been fixed, so that it's no longer the port implementations responsibility to send the output to the debugger, as the port should have no notion of what a debugger is. The printing and logging functions will now pass the result message to the debugger, if connected. - Cleaned up TZA handling in the date port implementation, and simplified the API function prototype. - Moved property access helper functions that use ASCII strings as keys from jerry-ext to the core API. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
1 parent 79fd540 commit ac1c48e

File tree

170 files changed

+4115
-5612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+4115
-5612
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ IncludeBlocks: Regroup
4444
IncludeCategories:
4545
- Regex: '<windows.h>'
4646
Priority: 0
47-
- Regex: '<[-.a-z]*>'
47+
- Regex: '<[-./a-z]*>'
4848
Priority: 1
4949
- Regex: '"jerryscript[-.a-z]*"'
5050
Priority: 2

CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ set(JERRY_CMDLINE ON CACHE BOOL "Build jerry command line tool?")
5454
set(JERRY_CMDLINE_TEST OFF CACHE BOOL "Build jerry test command line tool?")
5555
set(JERRY_CMDLINE_SNAPSHOT OFF CACHE BOOL "Build jerry snapshot command line tool?")
5656
set(JERRY_LIBFUZZER OFF CACHE BOOL "Build jerry with libfuzzer support?")
57-
set(JERRY_PORT_DEFAULT ON CACHE BOOL "Build default jerry port implementation?")
57+
set(JERRY_PORT ON CACHE BOOL "Build default jerry port implementation?")
5858
set(JERRY_EXT ON CACHE BOOL "Build jerry-ext?")
5959
set(JERRY_MATH OFF CACHE BOOL "Build and use jerry-math?")
6060
set(UNITTESTS OFF CACHE BOOL "Build unit tests?")
@@ -75,9 +75,9 @@ if(NOT USING_CLANG)
7575
endif()
7676

7777
if(JERRY_CMDLINE OR JERRY_CMDLINE_TEST OR JERRY_CMDLINE_SNAPSHOT OR JERRY_LIBFUZZER OR UNITTESTS OR DOCTESTS)
78-
set(JERRY_PORT_DEFAULT ON)
78+
set(JERRY_PORT ON)
7979

80-
set(JERRY_PORT_DEFAULT_MESSAGE " (FORCED BY CMDLINE OR LIBFUZZER OR TESTS)")
80+
set(JERRY_PORT_MESSAGE " (FORCED BY CMDLINE OR LIBFUZZER OR TESTS)")
8181
endif()
8282

8383
if(JERRY_CMDLINE OR DOCTESTS)
@@ -138,7 +138,7 @@ message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE} ${JERRY_CMDLIN
138138
message(STATUS "JERRY_CMDLINE_TEST " ${JERRY_CMDLINE_TEST} ${JERRY_CMDLINE_TEST_MESSAGE})
139139
message(STATUS "JERRY_CMDLINE_SNAPSHOT " ${JERRY_CMDLINE_SNAPSHOT} ${JERRY_CMDLINE_SNAPSHOT_MESSAGE})
140140
message(STATUS "JERRY_LIBFUZZER " ${JERRY_LIBFUZZER} ${JERRY_LIBFUZZER_MESSAGE})
141-
message(STATUS "JERRY_PORT_DEFAULT " ${JERRY_PORT_DEFAULT} ${JERRY_PORT_DEFAULT_MESSAGE})
141+
message(STATUS "JERRY_PORT " ${JERRY_PORT} ${JERRY_PORT_MESSAGE})
142142
message(STATUS "JERRY_EXT " ${JERRY_EXT} ${JERRY_EXT_MESSAGE})
143143
message(STATUS "JERRY_MATH " ${JERRY_MATH} ${JERRY_MATH_MESSAGE})
144144
message(STATUS "UNITTESTS " ${UNITTESTS})
@@ -278,8 +278,8 @@ if(JERRY_EXT)
278278
endif()
279279

280280
# Jerry's default port implementation
281-
if(JERRY_PORT_DEFAULT)
282-
add_subdirectory(jerry-port/default)
281+
if(JERRY_PORT)
282+
add_subdirectory(jerry-port)
283283
endif()
284284

285285
# Jerry command line tool

docs/01.CONFIGURATION.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ in other projects. To achieve this, the following command can be executed to cre
299299
into the `amalgam` directory:
300300

301301
```sh
302-
$ python tools/amalgam.py --output-dir amalgam --jerry-core --jerry-port-default --jerry-math
302+
$ python tools/amalgam.py --output-dir amalgam --jerry-core --jerry-port --jerry-math
303303
```
304304

305305
(Note: In the example above, the command is executed from the project's root directory, but that is
@@ -310,8 +310,7 @@ The command creates the following files in the `amalgam` dir:
310310
* `jerryscript.c`
311311
* `jerryscript.h`
312312
* `jerryscript-config.h`
313-
* `jerryscript-port-default.c`
314-
* `jerryscript-port-default.h`
313+
* `jerryscript-port.c`
315314
* `jerryscript-math.c`
316315
* `math.h`
317316

@@ -323,7 +322,7 @@ These files can be directly compiled with an application using the JerryScript A
323322
E.g., using a command similar to the one below:
324323

325324
```sh
326-
$ gcc -Wall -o demo_app demo_app.c amalgam/jerryscript.c amalgam/jerryscript-port-default.c amalgam/jerryscript-math.c -Iamalgam/
325+
$ gcc -Wall -o demo_app demo_app.c amalgam/jerryscript.c amalgam/jerryscript-port.c amalgam/jerryscript-math.c -Iamalgam/
327326
```
328327

329328
(Note: The headers must be available on the include path.)

docs/02.API-REFERENCE.md

+2-100
Original file line numberDiff line numberDiff line change
@@ -6385,6 +6385,8 @@ jerry_bigint_digit_count (jerry_value_t value)
63856385
[doctest]: # ()
63866386

63876387
```c
6388+
#include <stdio.h>
6389+
63886390
#include "jerryscript.h"
63896391

63906392
int
@@ -10527,106 +10529,6 @@ void jerry_heap_free (void *mem_p, size_t size);
1052710529
- [jerry_heap_alloc](#jerry_heap_alloc)
1052810530

1052910531

10530-
# External context functions
10531-
10532-
## jerry_context_alloc
10533-
10534-
**Summary**
10535-
10536-
Create an external JerryScript engine context.
10537-
10538-
**Prototype**
10539-
10540-
```c
10541-
jerry_context_t *
10542-
jerry_context_alloc (uint32_t heap_size,
10543-
jerry_context_alloc_t alloc,
10544-
void *cb_data_p);
10545-
```
10546-
10547-
- `heap_size` - requested heap size of the JerryScript context
10548-
- `alloc` - function for allocation
10549-
- `cb_data_p` - user data
10550-
- return value
10551-
- pointer to the newly created JerryScript context if success
10552-
- NULL otherwise.
10553-
10554-
*New in version 2.0*.
10555-
10556-
**Example**
10557-
10558-
[doctest]: # (test="compile", name="02.API-REFERENCE-create-context.c")
10559-
10560-
```c
10561-
#include <stdlib.h>
10562-
#include <pthread.h>
10563-
10564-
#include "jerryscript.h"
10565-
#include "jerryscript-port.h"
10566-
10567-
/* A different Thread Local Storage variable for each jerry context. */
10568-
__thread jerry_context_t *tls_context;
10569-
10570-
jerry_context_t *
10571-
jerry_port_get_current_context (void)
10572-
{
10573-
/* Returns the context assigned to the thread. */
10574-
return tls_context;
10575-
}
10576-
10577-
/* Allocate JerryScript heap for each thread. */
10578-
static void *
10579-
context_alloc_fn (size_t size, void *cb_data)
10580-
{
10581-
(void) cb_data;
10582-
return malloc (size);
10583-
}
10584-
10585-
static void *
10586-
thread_function (void *param)
10587-
{
10588-
tls_context = jerry_context_alloc (512 * 1024, context_alloc_fn, NULL);
10589-
10590-
jerry_init (JERRY_INIT_EMPTY);
10591-
/* Run JerryScript in the context (e.g.: jerry_parse & jerry_run) */
10592-
jerry_cleanup ();
10593-
10594-
/* Deallocate JerryScript context */
10595-
free (tls_context);
10596-
10597-
return NULL;
10598-
}
10599-
10600-
#define NUM_OF_THREADS 8
10601-
10602-
int
10603-
main (void)
10604-
{
10605-
pthread_t threads[NUM_OF_THREADS];
10606-
10607-
/* Create the threads. */
10608-
for (int i = 0; i < NUM_OF_THREADS; i++)
10609-
{
10610-
pthread_create (&threads[i], NULL, thread_function, (void *) (intptr_t) i);
10611-
}
10612-
10613-
/* Wait for the threads to complete, and release their resources. */
10614-
for (int i = 0; i < NUM_OF_THREADS; i++)
10615-
{
10616-
pthread_join (threads[i], NULL);
10617-
}
10618-
10619-
return 0;
10620-
}
10621-
```
10622-
10623-
**See also**
10624-
10625-
- [jerry_context_t](#jerry_context_t)
10626-
- [jerry_context_alloc_t](#jerry_context_alloc_t)
10627-
- [jerry_port_get_current_context](05.PORT-API.md#jerry_port_get_current_context)
10628-
10629-
1063010532
# Snapshot functions
1063110533

1063210534
## jerry_generate_snapshot

0 commit comments

Comments
 (0)