mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
jerry_Exit - exit function that under !JERRY_NDEBUG, in case status code is non-zero, prints exit status as string and calls handler of failed assertion.
This commit is contained in:
parent
f9ee8960c7
commit
e6b3be5dfc
@ -48,18 +48,22 @@ typedef enum {
|
||||
#define JERRY_BITSINBYTE 8
|
||||
|
||||
/**
|
||||
* Errors
|
||||
* Error codes
|
||||
*/
|
||||
#define ERR_IO (-1)
|
||||
#define ERR_BUFFER_SIZE (-2)
|
||||
#define ERR_SEVERAL_FILES (-3)
|
||||
#define ERR_NO_FILES (-4)
|
||||
#define ERR_NON_CHAR (-5)
|
||||
#define ERR_UNCLOSED (-6)
|
||||
#define ERR_INT_LITERAL (-7)
|
||||
#define ERR_STRING (-8)
|
||||
#define ERR_PARSER (-9)
|
||||
#define ERR_GENERAL (-255)
|
||||
typedef enum
|
||||
{
|
||||
ERR_OK = 0,
|
||||
ERR_IO = -1,
|
||||
ERR_BUFFER_SIZE = -2,
|
||||
ERR_SEVERAL_FILES = -3,
|
||||
ERR_NO_FILES = -4,
|
||||
ERR_NON_CHAR = -5,
|
||||
ERR_UNCLOSED = -6,
|
||||
ERR_INT_LITERAL = -7,
|
||||
ERR_STRING = -8,
|
||||
ERR_PARSER = -9,
|
||||
ERR_GENERAL = -255
|
||||
} jerry_Status_t;
|
||||
|
||||
/**
|
||||
* Asserts
|
||||
@ -98,6 +102,11 @@ extern void __noreturn jerry_AssertFail( const char *assertion, const char *file
|
||||
#define JERRY_UNREACHABLE() do { JERRY_ASSERT( false); __builtin_trap(); } while (0)
|
||||
#define JERRY_UNIMPLEMENTED() JERRY_UNREACHABLE()
|
||||
|
||||
/**
|
||||
* Exit
|
||||
*/
|
||||
extern void __noreturn jerry_Exit( jerry_Status_t code);
|
||||
|
||||
/**
|
||||
* sizeof, offsetof, ...
|
||||
*/
|
||||
|
||||
80
src/libruntime/jerry-exit.c
Normal file
80
src/libruntime/jerry-exit.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of exit with specified status code.
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
/*
|
||||
* Exit with specified status code.
|
||||
*
|
||||
* If !JERRY_NDEBUG and code != 0, print status code with description
|
||||
* and call assertion fail handler.
|
||||
*/
|
||||
void __noreturn
|
||||
jerry_Exit( jerry_Status_t code) /**< status code */
|
||||
{
|
||||
#ifndef JERRY_NDEBUG
|
||||
if ( code != ERR_OK )
|
||||
{
|
||||
__printf("Error: ");
|
||||
|
||||
switch ( code )
|
||||
{
|
||||
case ERR_OK:
|
||||
JERRY_UNREACHABLE();
|
||||
break;
|
||||
case ERR_IO:
|
||||
__printf("ERR_IO\n");
|
||||
break;
|
||||
case ERR_BUFFER_SIZE:
|
||||
__printf("ERR_BUFFER_SIZE\n");
|
||||
break;
|
||||
case ERR_SEVERAL_FILES:
|
||||
__printf("ERR_SEVERAL_FILES\n");
|
||||
break;
|
||||
case ERR_NO_FILES:
|
||||
__printf("ERR_NO_FILES\n");
|
||||
break;
|
||||
case ERR_NON_CHAR:
|
||||
__printf("ERR_NON_CHAR\n");
|
||||
break;
|
||||
case ERR_UNCLOSED:
|
||||
__printf("ERR_UNCLOSED\n");
|
||||
break;
|
||||
case ERR_INT_LITERAL:
|
||||
__printf("ERR_INT_LITERAL\n");
|
||||
break;
|
||||
case ERR_STRING:
|
||||
__printf("ERR_STRING\n");
|
||||
break;
|
||||
case ERR_PARSER:
|
||||
__printf("ERR_PARSER\n");
|
||||
break;
|
||||
case ERR_GENERAL:
|
||||
__printf("ERR_GENERAL\n");
|
||||
break;
|
||||
}
|
||||
|
||||
jerry_AssertFail( "Return code is zero", __FILE__, __LINE__);
|
||||
}
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
__exit( -code );
|
||||
} /* jerry_Exit */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user