1 | /* Copyright JS Foundation and other contributors, http://js.foundation |
2 | * |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | * you may not use this file except in compliance with the License. |
5 | * You may obtain a copy of the License at |
6 | * |
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | * |
9 | * Unless required by applicable law or agreed to in writing, software |
10 | * distributed under the License is distributed on an "AS IS" BASIS |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | * See the License for the specific language governing permissions and |
13 | * limitations under the License. |
14 | */ |
15 | |
16 | /** |
17 | * Implementation of exit with specified status code. |
18 | */ |
19 | |
20 | #include "jrt.h" |
21 | #include "jrt-libc-includes.h" |
22 | |
23 | /* |
24 | * Exit with specified status code. |
25 | * |
26 | * If !JERRY_NDEBUG and code != 0, print status code with description |
27 | * and call assertion fail handler. |
28 | */ |
29 | void JERRY_ATTR_NORETURN |
30 | jerry_fatal (jerry_fatal_code_t code) /**< status code */ |
31 | { |
32 | #ifndef JERRY_NDEBUG |
33 | switch (code) |
34 | { |
35 | case ERR_OUT_OF_MEMORY: |
36 | { |
37 | JERRY_ERROR_MSG ("Error: ERR_OUT_OF_MEMORY\n" ); |
38 | break; |
39 | } |
40 | case ERR_REF_COUNT_LIMIT: |
41 | { |
42 | JERRY_ERROR_MSG ("Error: ERR_REF_COUNT_LIMIT\n" ); |
43 | break; |
44 | } |
45 | case ERR_UNTERMINATED_GC_LOOPS: |
46 | { |
47 | JERRY_ERROR_MSG ("Error: ERR_UNTERMINATED_GC_LOOPS\n" ); |
48 | break; |
49 | } |
50 | case ERR_DISABLED_BYTE_CODE: |
51 | { |
52 | JERRY_ERROR_MSG ("Error: ERR_DISABLED_BYTE_CODE\n" ); |
53 | break; |
54 | } |
55 | case ERR_FAILED_INTERNAL_ASSERTION: |
56 | { |
57 | JERRY_ERROR_MSG ("Error: ERR_FAILED_INTERNAL_ASSERTION\n" ); |
58 | break; |
59 | } |
60 | } |
61 | #endif /* !JERRY_NDEBUG */ |
62 | |
63 | jerry_port_fatal (code); |
64 | |
65 | /* to make compiler happy for some RTOS: 'control reaches end of non-void function' */ |
66 | while (true) |
67 | { |
68 | } |
69 | } /* jerry_fatal */ |
70 | |
71 | #ifndef JERRY_NDEBUG |
72 | /** |
73 | * Handle failed assertion |
74 | */ |
75 | void JERRY_ATTR_NORETURN |
76 | jerry_assert_fail (const char *assertion, /**< assertion condition string */ |
77 | const char *file, /**< file name */ |
78 | const char *function, /**< function name */ |
79 | const uint32_t line) /**< line */ |
80 | { |
81 | JERRY_ERROR_MSG ("ICE: Assertion '%s' failed at %s(%s):%lu.\n" , |
82 | assertion, |
83 | file, |
84 | function, |
85 | (unsigned long) line); |
86 | |
87 | jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION); |
88 | } /* jerry_assert_fail */ |
89 | |
90 | /** |
91 | * Handle execution of control path that should be unreachable |
92 | */ |
93 | void JERRY_ATTR_NORETURN |
94 | jerry_unreachable (const char *file, /**< file name */ |
95 | const char *function, /**< function name */ |
96 | const uint32_t line) /**< line */ |
97 | { |
98 | JERRY_ERROR_MSG ("ICE: Unreachable control path at %s(%s):%lu was executed.\n" , |
99 | file, |
100 | function, |
101 | (unsigned long) line); |
102 | |
103 | jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION); |
104 | } /* jerry_unreachable */ |
105 | #endif /* !JERRY_NDEBUG */ |
106 | |