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:
+20
-11
@@ -48,18 +48,22 @@ typedef enum {
|
|||||||
#define JERRY_BITSINBYTE 8
|
#define JERRY_BITSINBYTE 8
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Errors
|
* Error codes
|
||||||
*/
|
*/
|
||||||
#define ERR_IO (-1)
|
typedef enum
|
||||||
#define ERR_BUFFER_SIZE (-2)
|
{
|
||||||
#define ERR_SEVERAL_FILES (-3)
|
ERR_OK = 0,
|
||||||
#define ERR_NO_FILES (-4)
|
ERR_IO = -1,
|
||||||
#define ERR_NON_CHAR (-5)
|
ERR_BUFFER_SIZE = -2,
|
||||||
#define ERR_UNCLOSED (-6)
|
ERR_SEVERAL_FILES = -3,
|
||||||
#define ERR_INT_LITERAL (-7)
|
ERR_NO_FILES = -4,
|
||||||
#define ERR_STRING (-8)
|
ERR_NON_CHAR = -5,
|
||||||
#define ERR_PARSER (-9)
|
ERR_UNCLOSED = -6,
|
||||||
#define ERR_GENERAL (-255)
|
ERR_INT_LITERAL = -7,
|
||||||
|
ERR_STRING = -8,
|
||||||
|
ERR_PARSER = -9,
|
||||||
|
ERR_GENERAL = -255
|
||||||
|
} jerry_Status_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts
|
* 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_UNREACHABLE() do { JERRY_ASSERT( false); __builtin_trap(); } while (0)
|
||||||
#define JERRY_UNIMPLEMENTED() JERRY_UNREACHABLE()
|
#define JERRY_UNIMPLEMENTED() JERRY_UNREACHABLE()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit
|
||||||
|
*/
|
||||||
|
extern void __noreturn jerry_Exit( jerry_Status_t code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sizeof, offsetof, ...
|
* sizeof, offsetof, ...
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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 */
|
||||||
|
|
||||||
Reference in New Issue
Block a user