Skip to content

Commit ce260ab

Browse files
committed
Make jerryx_port_handler_print_char truly a port function
In the previous approach `jerryx_port_handler_print_char` was implemented in by the jerry-default-port. This implementation however required the jerry-ext handler header file which created a requirement in the jerry-default-port for the jerry-ext headers. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
1 parent 85e0509 commit ce260ab

File tree

10 files changed

+82
-109
lines changed

10 files changed

+82
-109
lines changed

docs/05.PORT-API.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ typedef enum
7272
void jerry_port_log (jerry_log_level_t level, const char *fmt, ...);
7373
```
7474
75+
The `jerry_port_print_char` is currenlty not used by the jerry-core directly.
76+
However, it provides a port specifc way for `jerry-ext` components to print
77+
information.
78+
79+
```c
80+
/**
81+
* Print a character to stdout with printf.
82+
*/
83+
void jerry_port_print_char (char c);
84+
```
85+
86+
7587
## Date
7688

7789
```c
@@ -201,6 +213,17 @@ jerry_port_log (jerry_log_level_t level, /**< log level */
201213
} /* jerry_port_log */
202214
```
203215
216+
```c
217+
/**
218+
* Print a character to stdout with printf.
219+
*/
220+
void
221+
jerry_port_print_char (char c)
222+
{
223+
printf ("%c", c);
224+
} /* jerr_port_print_char */
225+
```
226+
204227
## Date
205228

206229
```c

docs/10.EXT-REFERENCE-HANDLER.md

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ jerryx_handler_gc (const jerry_value_t func_obj_val, const jerry_value_t this_p,
9797
9898
Provide a `print` implementation for scripts. The routine converts all of its
9999
arguments to strings and outputs them char-by-char using
100-
`jerryx_port_handler_print_char`. The NUL character is output as "\u0000",
100+
`jerry_port_print_char`. The NUL character is output as "\u0000",
101101
other characters are output bytewise.
102102
103103
*Note*: This implementation does not use standard C `printf` to print its
104104
output. This allows more flexibility but also extends the core JerryScript
105105
engine port API. Applications that want to use `jerryx_handler_print` must
106106
ensure that their port implementation also provides
107-
`jerryx_port_handler_print_char`.
107+
`jerry_port_print_char`.
108108
109109
**Prototype**
110110
@@ -124,7 +124,7 @@ jerryx_handler_print (const jerry_value_t func_obj_val, const jerry_value_t this
124124
**See also**
125125

126126
- [jerryx_handler_register_global](#jerryx_handler_register_global)
127-
- [jerryx_port_handler_print_char](#jerryx_port_handler_print_char)
127+
- [jerry_port_print_char](05.PORT-API.md#jerry_port_print_char)
128128

129129

130130
# Handler registration helper
@@ -184,38 +184,3 @@ register_common_functions (void)
184184
jerry_release_value (ret);
185185
}
186186
```
187-
188-
189-
# Port API extension
190-
191-
## jerryx_port_handler_print_char
192-
193-
**Summary**
194-
195-
Print a single character.
196-
197-
**Prototype**
198-
199-
```c
200-
void
201-
jerryx_port_handler_print_char (char c);
202-
```
203-
204-
- `c` - the character to print.
205-
206-
**Example**
207-
208-
```c
209-
/**
210-
* Print a character to stdout with printf.
211-
*/
212-
void
213-
jerryx_port_handler_print_char (char c)
214-
{
215-
printf ("%c", c);
216-
} /* jerryx_port_handler_print_char */
217-
```
218-
219-
**See also**
220-
221-
- [jerryx_handler_print](#jerryx_handler_print)

jerry-core/include/jerryscript-port.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ struct jerry_context_t *jerry_port_get_current_context (void);
179179
*/
180180
void jerry_port_sleep (uint32_t sleep_time);
181181

182+
/**
183+
* Print a single character.
184+
*
185+
* Note:
186+
* This port function is here so the jerry-ext components would have
187+
* a common way to print out information.
188+
* If possible do not use from the jerry-core.
189+
*
190+
* @param c the character to print.
191+
*/
192+
void jerry_port_print_char (char c);
193+
182194
/**
183195
* @}
184196
*/

jerry-ext/handler/handler-print.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
*/
1515

1616
#include "jerryscript-ext/handler.h"
17+
#include "jerryscript-port.h"
1718
#include "jerryscript-debugger.h"
1819

1920
/**
2021
* Provide a 'print' implementation for scripts.
2122
*
2223
* The routine converts all of its arguments to strings and outputs them
23-
* char-by-char using jerryx_port_handler_print_char.
24+
* char-by-char using jerry_port_print_char.
2425
*
2526
* The NUL character is output as "\u0000", other characters are output
2627
* bytewise.
@@ -30,7 +31,7 @@
3031
* output. This allows more flexibility but also extends the core
3132
* JerryScript engine port API. Applications that want to use
3233
* `jerryx_handler_print` must ensure that their port implementation also
33-
* provides `jerryx_port_handler_print_char`.
34+
* provides `jerry_port_print_char`.
3435
*
3536
* @return undefined - if all arguments could be converted to strings,
3637
* error - otherwise.
@@ -103,13 +104,13 @@ jerryx_handler_print (const jerry_value_t func_obj_val, /**< function object */
103104

104105
if (chr != '\0')
105106
{
106-
jerryx_port_handler_print_char (chr);
107+
jerry_port_print_char (chr);
107108
continue;
108109
}
109110

110111
for (jerry_size_t null_index = 0; null_str[null_index] != '\0'; null_index++)
111112
{
112-
jerryx_port_handler_print_char (null_str[null_index]);
113+
jerry_port_print_char (null_str[null_index]);
113114
}
114115
}
115116
}
@@ -120,7 +121,7 @@ jerryx_handler_print (const jerry_value_t func_obj_val, /**< function object */
120121

121122
if (args_cnt == 0 || jerry_value_is_error (ret_val))
122123
{
123-
jerryx_port_handler_print_char ('\n');
124+
jerry_port_print_char ('\n');
124125
}
125126

126127
return ret_val;

jerry-ext/include/jerryscript-ext/handler.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ jerry_value_t jerryx_handler_gc (const jerry_value_t func_obj_val, const jerry_v
4545
jerry_value_t jerryx_handler_print (const jerry_value_t func_obj_val, const jerry_value_t this_p,
4646
const jerry_value_t args_p[], const jerry_length_t args_cnt);
4747

48-
/*
49-
* Port API extension
50-
*/
51-
52-
/**
53-
* Print a single character.
54-
*
55-
* @param c the character to print.
56-
*/
57-
void jerryx_port_handler_print_char (char c);
58-
5948
#ifdef __cplusplus
6049
}
6150
#endif /* __cplusplus */

jerry-port/default/default-io.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,32 @@ jerry_port_log (jerry_log_level_t level, /**< message log level */
9898
va_end (args);
9999
}
100100
} /* jerry_port_log */
101+
102+
103+
#ifdef JERRY_DEBUGGER
104+
105+
#define DEBUG_BUFFER_SIZE (256)
106+
static char debug_buffer[DEBUG_BUFFER_SIZE];
107+
static int debug_buffer_index = 0;
108+
109+
#endif /* JERRY_DEBUGGER */
110+
111+
/**
112+
* Default implementation of jerry_port_print_char. Uses 'printf' to
113+
* print a single character to standard output.
114+
*/
115+
void
116+
jerry_port_print_char (char c) /**< the character to print */
117+
{
118+
printf ("%c", c);
119+
120+
#ifdef JERRY_DEBUGGER
121+
debug_buffer[debug_buffer_index++] = c;
122+
123+
if ((debug_buffer_index == DEBUG_BUFFER_SIZE) || (c == '\n'))
124+
{
125+
jerry_debugger_send_output ((jerry_char_t *) debug_buffer, (jerry_size_t) debug_buffer_index);
126+
debug_buffer_index = 0;
127+
}
128+
#endif /* JERRY_DEBUGGER */
129+
} /* jerry_port_print_char */

jerry-port/default/defaultx-handler.c

Lines changed: 0 additions & 46 deletions
This file was deleted.

targets/nuttx-stm32f4/jerry_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ jerry_port_get_current_time (void)
515515
} /* jerry_port_get_current_time */
516516

517517
/**
518-
* Provide the implementation of jerryx_port_handler_print_char.
518+
* Provide the implementation of jerry_port_print_char.
519519
* Uses 'printf' to print a single character to standard output.
520520
*/
521521
void
522-
jerryx_port_handler_print_char (char c) /**< the character to print */
522+
jerry_port_print_char (char c) /**< the character to print */
523523
{
524524
printf ("%c", c);
525-
} /* jerryx_port_handler_print_char */
525+
} /* jerry_port_print_char */

targets/tizenrt-artik053/apps/jerryscript/jerry_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,14 @@ jerry_port_get_current_time (void)
497497
} /* jerry_port_get_current_time */
498498

499499
/**
500-
* Provide the implementation of jerryx_port_handler_print_char.
500+
* Provide the implementation of jerry_port_print_char.
501501
* Uses 'printf' to print a single character to standard output.
502502
*/
503503
void
504-
jerryx_port_handler_print_char (char c) /**< the character to print */
504+
jerry_port_print_char (char c) /**< the character to print */
505505
{
506506
printf ("%c", c);
507-
} /* jerryx_port_handler_print_char */
507+
} /* jerry_port_print_char */
508508

509509
/**
510510
* Main program.

targets/zephyr/src/jerry-port.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ jerry_port_get_local_time_zone_adjustment (double unix_ms, bool is_utc)
7171
} /* jerry_port_get_local_time_zone_adjustment */
7272

7373
/**
74-
* Provide the implementation of jerryx_port_handler_print_char.
74+
* Provide the implementation of jerry_port_print_char.
7575
* Uses 'printf' to print a single character to standard output.
7676
*/
7777
void
78-
jerryx_port_handler_print_char (char c) /**< the character to print */
78+
jerry_port_print_char (char c) /**< the character to print */
7979
{
8080
printf ("%c", c);
81-
} /* jerryx_port_handler_print_char */
81+
} /* jerry_port_print_char */

0 commit comments

Comments
 (0)