Skip to content

Commit f5003a7

Browse files
committed
Improve the jerry port api documents.
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 b3fa5e0 commit f5003a7

File tree

17 files changed

+23
-236
lines changed

17 files changed

+23
-236
lines changed

docs/05.PORT-API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ void jerry_port_context_free (void);
112112
*
113113
* The implementation can decide whether error and debug messages are logged to
114114
* the console, or saved to a database or to a file.
115+
*
116+
* @param message_p: the message to log.
115117
*/
116118
void jerry_port_log (const char *message_p);
117119
```

jerry-core/include/jerryscript-port.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ void jerry_port_context_free (void);
139139
*
140140
* The implementation can decide whether error and debug messages are logged to
141141
* the console, or saved to a database or to a file.
142+
*
143+
* @param message_p: the message to log.
142144
*/
143145
void jerry_port_log (const char *message_p);
144146

@@ -233,7 +235,7 @@ void jerry_port_path_free (jerry_char_t *path_p);
233235
jerry_size_t jerry_port_path_base (const jerry_char_t *path_p);
234236

235237
/**
236-
* Open a source file and read the content into a buffer.
238+
* Open a source file and read its contents into a buffer.
237239
*
238240
* When the source file is no longer needed by the caller, the returned pointer will be passed to
239241
* `jerry_port_source_free`, which can be used to finalize the buffer.

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

Lines changed: 0 additions & 15 deletions
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

Lines changed: 5 additions & 30 deletions
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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919

2020
#include "jerryscript-port.h"
2121

22-
/**
23-
* Default implementation of jerry_port_log. Prints log messages to stderr.
24-
*/
2522
void JERRY_ATTR_WEAK
26-
jerry_port_log (const char *message_p) /**< message */
23+
jerry_port_log (const char *message_p)
2724
{
2825
fputs (message_p, stderr);
2926
} /* jerry_port_log */
@@ -34,14 +31,6 @@ jerry_port_print_buffer (const jerry_char_t *buffer_p, jerry_size_t buffer_size)
3431
fwrite (buffer_p, 1, buffer_size, stdout);
3532
} /* jerry_port_print_buffer */
3633

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-
*/
4534
jerry_char_t *JERRY_ATTR_WEAK
4635
jerry_port_line_read (jerry_size_t *out_size_p)
4736
{
@@ -80,11 +69,6 @@ jerry_port_line_read (jerry_size_t *out_size_p)
8069
}
8170
} /* jerry_port_line_read */
8271

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-
*/
8872
void JERRY_ATTR_WEAK
8973
jerry_port_line_free (jerry_char_t *buffer_p)
9074
{

jerry-port/common/jerry-port-process.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717

1818
#include "jerryscript-port.h"
1919

20-
/**
21-
* Default implementation of jerry_port_fatal. Calls 'abort' if exit code is
22-
* non-zero, 'exit' otherwise.
23-
*/
2420
void JERRY_ATTR_WEAK
25-
jerry_port_fatal (jerry_fatal_code_t code) /**< cause of error */
21+
jerry_port_fatal (jerry_fatal_code_t code)
2622
{
2723
if (code != 0 && code != JERRY_FATAL_OUT_OF_MEMORY)
2824
{

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

Lines changed: 0 additions & 11 deletions
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

Lines changed: 3 additions & 21 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 0 additions & 11 deletions
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

Lines changed: 1 addition & 18 deletions
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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818

1919
#include <windows.h>
2020

21-
/**
22-
* Default implementation of jerry_port_sleep, uses 'Sleep'.
23-
*/
2421
void
25-
jerry_port_sleep (uint32_t sleep_time) /**< milliseconds to sleep */
22+
jerry_port_sleep (uint32_t sleep_time)
2623
{
2724
Sleep (sleep_time);
2825
} /* jerry_port_sleep */

0 commit comments

Comments
 (0)