Skip to content

Commit b4bc230

Browse files
authored
Improve the jerry port api documents. (#4977)
Notable changes: - Remove the comments in port impl, that's easily getting to in-consistence - Sync the jerryscript-port.h and 05.PORT-API.md - Fixes the invalid comment in port codes JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent 77c72d4 commit b4bc230

16 files changed

+21
-227
lines changed

docs/05.PORT-API.md

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ void jerry_port_context_free (void);
119119
*
120120
* The implementation can decide whether error and debug messages are logged to
121121
* the console, or saved to a database or to a file.
122+
*
123+
* @param message_p: the message to log.
122124
*/
123125
void jerry_port_log (const char *message_p);
124126
```

jerry-core/include/jerryscript-port.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ void jerry_port_context_free (void);
143143
*
144144
* The implementation can decide whether error and debug messages are logged to
145145
* the console, or saved to a database or to a file.
146+
*
147+
* @param message_p: the message to log.
146148
*/
147149
void jerry_port_log (const char *message_p);
148150

@@ -237,7 +239,7 @@ void jerry_port_path_free (jerry_char_t *path_p);
237239
jerry_size_t jerry_port_path_base (const jerry_char_t *path_p);
238240

239241
/**
240-
* Open a source file and read the content into a buffer.
242+
* Open a source file and read its contents into a buffer.
241243
*
242244
* When the source file is no longer needed by the caller, the returned pointer will be passed to
243245
* `jerry_port_source_free`, which can be used to finalize the buffer.

jerry-port/common/jerry-port-context.c

-15
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
*/
2828
static jerry_context_t *current_context_p = NULL;
2929

30-
/**
31-
* Allocate a new external context.
32-
*
33-
* @param context_size: requested context size
34-
*
35-
* @return total allcoated size
36-
*/
3730
size_t JERRY_ATTR_WEAK
3831
jerry_port_context_alloc (size_t context_size)
3932
{
@@ -43,20 +36,12 @@ jerry_port_context_alloc (size_t context_size)
4336
return total_size;
4437
} /* jerry_port_context_alloc */
4538

46-
/**
47-
* Get the current context.
48-
*
49-
* @return the pointer to the current context
50-
*/
5139
jerry_context_t *JERRY_ATTR_WEAK
5240
jerry_port_context_get (void)
5341
{
5442
return current_context_p;
5543
} /* jerry_port_context_get */
5644

57-
/**
58-
* Free the currently allocated external context.
59-
*/
6045
void JERRY_ATTR_WEAK
6146
jerry_port_context_free (void)
6247
{

jerry-port/common/jerry-port-fs.c

+5-30
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,8 @@ jerry_port_get_file_size (FILE *file_p) /**< opened file */
4141
return (jerry_size_t) size;
4242
} /* jerry_port_get_file_size */
4343

44-
/**
45-
* Opens file with the given path and reads its source.
46-
* @return the source of the file
47-
*/
4844
jerry_char_t *JERRY_ATTR_WEAK
49-
jerry_port_source_read (const char *file_name_p, /**< file name */
50-
jerry_size_t *out_size_p) /**< [out] read bytes */
45+
jerry_port_source_read (const char *file_name_p, jerry_size_t *out_size_p)
5146
{
5247
/* TODO(dbatyai): Temporary workaround for nuttx target
5348
* The nuttx target builds and copies the jerryscript libraries as a separate build step, which causes linking issues
@@ -92,11 +87,8 @@ jerry_port_source_read (const char *file_name_p, /**< file name */
9287
return buffer_p;
9388
} /* jerry_port_source_read */
9489

95-
/**
96-
* Release the previously opened file's content.
97-
*/
9890
void JERRY_ATTR_WEAK
99-
jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */
91+
jerry_port_source_free (uint8_t *buffer_p)
10092
{
10193
free (buffer_p);
10294
} /* jerry_port_source_free */
@@ -107,15 +99,8 @@ jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */
10799
*/
108100
#if defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32))
109101

110-
/**
111-
* Normalize a file path.
112-
*
113-
* @return a newly allocated buffer with the normalized path if the operation is successful,
114-
* NULL otherwise
115-
*/
116102
jerry_char_t *JERRY_ATTR_WEAK
117-
jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
118-
jerry_size_t path_size) /**< size of the path */
103+
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
119104
{
120105
jerry_char_t *buffer_p = (jerry_char_t *) malloc (path_size + 1);
121106

@@ -130,24 +115,14 @@ jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
130115
return buffer_p;
131116
} /* jerry_port_path_normalize */
132117

133-
/**
134-
* Free a path buffer returned by jerry_port_path_normalize.
135-
*
136-
* @param path_p: the path to free
137-
*/
138118
void JERRY_ATTR_WEAK
139119
jerry_port_path_free (jerry_char_t *path_p)
140120
{
141121
free (path_p);
142122
} /* jerry_port_path_free */
143123

144-
/**
145-
* Computes the end of the directory part of a path.
146-
*
147-
* @return end of the directory part of a path.
148-
*/
149124
jerry_size_t JERRY_ATTR_WEAK
150-
jerry_port_path_base (const jerry_char_t *path_p) /**< path */
125+
jerry_port_path_base (const jerry_char_t *path_p)
151126
{
152127
const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1;
153128

@@ -157,6 +132,6 @@ jerry_port_path_base (const jerry_char_t *path_p) /**< path */
157132
}
158133

159134
return (jerry_size_t) (basename_p - path_p);
160-
} /* jerry_port_get_directory_end */
135+
} /* jerry_port_path_base */
161136

162137
#endif /* defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */

jerry-port/common/jerry-port-io.c

-13
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ jerry_port_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size)
3434
fwrite (buffer_p, 1, buffer_size, stdout);
3535
} /* jerry_port_print_buffer */
3636

37-
/**
38-
* Read a line from standard input as a zero-terminated string.
39-
*
40-
* @param out_size_p: length of the string
41-
*
42-
* @return pointer to the buffer storing the string,
43-
* or NULL if end of input
44-
*/
4537
jerry_char_t *JERRY_ATTR_WEAK
4638
jerry_port_line_read (jerry_size_t *out_size_p)
4739
{
@@ -80,11 +72,6 @@ jerry_port_line_read (jerry_size_t *out_size_p)
8072
}
8173
} /* jerry_port_line_read */
8274

83-
/**
84-
* Free a line buffer allocated by jerry_port_line_read
85-
*
86-
* @param buffer_p: buffer that has been allocated by jerry_port_line_read
87-
*/
8875
void JERRY_ATTR_WEAK
8976
jerry_port_line_free (jerry_char_t *buffer_p)
9077
{

jerry-port/unix/jerry-port-unix-date.c

-11
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#include <sys/time.h>
2121
#include <time.h>
2222

23-
/**
24-
* Default implementation of jerry_port_local_tza.
25-
*
26-
* @return offset between UTC and local time at the given unix timestamp, if
27-
* available. Otherwise, returns 0, assuming UTC time.
28-
*/
2923
int32_t
3024
jerry_port_local_tza (double unix_ms)
3125
{
@@ -53,11 +47,6 @@ jerry_port_local_tza (double unix_ms)
5347
#endif /* HAVE_TM_GMTOFF */
5448
} /* jerry_port_local_tza */
5549

56-
/**
57-
* Default implementation of jerry_port_current_time.
58-
*
59-
* @return milliseconds since Unix epoch
60-
*/
6150
double
6251
jerry_port_current_time (void)
6352
{

jerry-port/unix/jerry-port-unix-fs.c

+3-21
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,26 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222

23-
/**
24-
* Normalize a file path using realpath.
25-
*
26-
* @param path_p: input path
27-
* @param path_size: input path size
28-
*
29-
* @return a newly allocated buffer with the normalized path if the operation is successful,
30-
* NULL otherwise
31-
*/
3223
jerry_char_t *
33-
jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
34-
jerry_size_t path_size) /**< size of the path */
24+
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
3525
{
3626
(void) path_size;
3727

3828
return (jerry_char_t *) realpath ((char *) path_p, NULL);
3929
} /* jerry_port_path_normalize */
4030

41-
/**
42-
* Free a path buffer returned by jerry_port_path_normalize.
43-
*/
4431
void
4532
jerry_port_path_free (jerry_char_t *path_p)
4633
{
4734
free (path_p);
4835
} /* jerry_port_path_free */
4936

50-
/**
51-
* Computes the end of the directory part of a path.
52-
*
53-
* @return end of the directory part of a path.
54-
*/
5537
jerry_size_t JERRY_ATTR_WEAK
56-
jerry_port_path_base (const jerry_char_t *path_p) /**< path */
38+
jerry_port_path_base (const jerry_char_t *path_p)
5739
{
5840
const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1;
5941

6042
return (jerry_size_t) (basename_p - path_p);
61-
} /* jerry_port_get_directory_end */
43+
} /* jerry_port_path_base */
6244

6345
#endif /* defined(__unix__) || defined(__APPLE__) */

jerry-port/unix/jerry-port-unix-process.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525

2626
#include <unistd.h>
2727

28-
/**
29-
* Default implementation of jerry_port_sleep, uses 'usleep'.
30-
*/
3128
void
32-
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
29+
jerry_port_sleep (uint32_t sleep_time)
3330
{
3431
usleep ((useconds_t) sleep_time * 1000);
3532
} /* jerry_port_sleep */

jerry-port/win/jerry-port-win-date.c

-11
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ filetime_to_unix_time (LPFILETIME ft_p)
7272
return (double) (((LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS) / TICKS_PER_MS);
7373
} /* filetime_to_unix_time */
7474

75-
/**
76-
* Default implementation of jerry_port_local_tza.
77-
*
78-
* @return offset between UTC and local time at the given unix timestamp, if
79-
* available. Otherwise, returns 0, assuming UTC time.
80-
*/
8175
int32_t
8276
jerry_port_local_tza (double unix_ms)
8377
{
@@ -115,11 +109,6 @@ jerry_port_local_tza (double unix_ms)
115109
return 0;
116110
} /* jerry_port_local_tza */
117111

118-
/**
119-
* Default implementation of jerry_port_current_time.
120-
*
121-
* @return milliseconds since Unix epoch
122-
*/
123112
double
124113
jerry_port_current_time (void)
125114
{

jerry-port/win/jerry-port-win-fs.c

+1-18
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,20 @@
2020
#include <stdlib.h>
2121
#include <string.h>
2222

23-
/**
24-
* Normalize a file path.
25-
*
26-
* @return a newly allocated buffer with the normalized path if the operation is successful,
27-
* NULL otherwise
28-
*/
2923
jerry_char_t *
30-
jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */
31-
jerry_size_t path_size) /**< size of the path */
24+
jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size)
3225
{
3326
(void) path_size;
3427

3528
return (jerry_char_t *) _fullpath (NULL, path_p, _MAX_PATH);
3629
} /* jerry_port_path_normalize */
3730

38-
/**
39-
* Free a path buffer returned by jerry_port_path_normalize.
40-
*/
4131
void
4232
jerry_port_path_free (jerry_char_t *path_p)
4333
{
4434
free (path_p);
4535
} /* jerry_port_path_free */
4636

47-
/**
48-
* Get the end of the directory part of the input path.
49-
*
50-
* @param path_p: input zero-terminated path string
51-
*
52-
* @return offset of the directory end in the input path string
53-
*/
5437
jerry_size_t
5538
jerry_port_path_base (const jerry_char_t *path_p)
5639
{

jerry-port/win/jerry-port-win-process.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ jerry_port_init (void)
8080
}
8181
} /* jerry_port_init */
8282

83-
/**
84-
* Default implementation of jerry_port_sleep, uses 'Sleep'.
85-
*/
8683
void
87-
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
84+
jerry_port_sleep (uint32_t sleep_time)
8885
{
8986
Sleep (sleep_time);
9087
} /* jerry_port_sleep */

targets/baremetal-sdk/espressif/main/jerry-port.c

+2-24
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,20 @@
3030

3131
static const char ESP_JS_TAG[] = "JS";
3232

33-
/**
34-
* Provide log message implementation for the engine.
35-
*/
3633
void
37-
jerry_port_log (const char *message_p) /**< message */
34+
jerry_port_log (const char *message_p)
3835
{
3936
ESP_LOGI (ESP_JS_TAG, "%s", message_p);
4037
} /* jerry_port_log */
4138

42-
/**
43-
* Implementation of jerry_port_fatal.
44-
* Calls 'abort' if exit code is non-zero, 'exit' otherwise.
45-
*/
4639
void
47-
jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
40+
jerry_port_fatal (jerry_fatal_code_t code)
4841
{
4942
ESP_LOGE (ESP_JS_TAG, "Fatal error: %d", code);
5043
vTaskSuspend (NULL);
5144
abort ();
5245
} /* jerry_port_fatal */
5346

54-
/**
55-
* Default implementation of jerry_port_local_tza. Uses the 'tm_gmtoff' field
56-
* of 'struct tm' (a GNU extension) filled by 'localtime_r' if available on the
57-
* system, does nothing otherwise.
58-
*
59-
* @return offset between UTC and local time at the given unix timestamp, if
60-
* available. Otherwise, returns 0, assuming UTC time.
61-
*/
6247
int32_t
6348
jerry_port_local_tza (double unix_ms)
6449
{
@@ -71,13 +56,6 @@ jerry_port_local_tza (double unix_ms)
7156
return -atoi (buf) * 3600 * 1000 / 100;
7257
} /* jerry_port_local_tza */
7358

74-
/**
75-
* Implementation of jerry_port_get_current_time.
76-
* Uses 'gettimeofday' if available on the system, does nothing otherwise.
77-
*
78-
* @return milliseconds since Unix epoch if 'gettimeofday' is available
79-
* 0 - otherwise.
80-
*/
8159
double
8260
jerry_port_current_time (void)
8361
{

0 commit comments

Comments
 (0)