Refinement of completion status codes and fatal error handlers.

This commit is contained in:
Ruben Ayrapetyan
2015-02-11 20:53:14 +03:00
parent 398501afeb
commit 17f51e0ba6
17 changed files with 237 additions and 347 deletions
+10 -15
View File
@@ -19,34 +19,34 @@
/** /**
* Limit of data (system heap, engine's data except engine's own heap) * Limit of data (system heap, engine's data except engine's own heap)
*/ */
#define CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE 1024 #define CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE (1024)
/** /**
* Limit of stack size * Limit of stack size
*/ */
#define CONFIG_MEM_STACK_LIMIT 4096 #define CONFIG_MEM_STACK_LIMIT (4096)
/** /**
* Log2 of maximum number of chunks in a pool * Log2 of maximum number of chunks in a pool
*/ */
#define CONFIG_MEM_POOL_MAX_CHUNKS_NUMBER_LOG 8 #define CONFIG_MEM_POOL_MAX_CHUNKS_NUMBER_LOG (8)
/** /**
* Size of pool chunk * Size of pool chunk
* *
* Should not be less than size of any of ECMA Object Model's data types. * Should not be less than size of any of ECMA Object Model's data types.
*/ */
#define CONFIG_MEM_POOL_CHUNK_SIZE 8 #define CONFIG_MEM_POOL_CHUNK_SIZE (8)
/** /**
* Minimum number of chunks in a pool allocated by pools' manager. * Minimum number of chunks in a pool allocated by pools' manager.
*/ */
#define CONFIG_MEM_LEAST_CHUNK_NUMBER_IN_POOL 32 #define CONFIG_MEM_LEAST_CHUNK_NUMBER_IN_POOL (32)
/** /**
* Size of heap chunk * Size of heap chunk
*/ */
#define CONFIG_MEM_HEAP_CHUNK_SIZE 64 #define CONFIG_MEM_HEAP_CHUNK_SIZE (64)
/** /**
* Size of heap * Size of heap
@@ -65,12 +65,12 @@
* *
* On the other hand, value 2 ^ CONFIG_MEM_HEAP_OFFSET_LOG should not be less than CONFIG_MEM_HEAP_AREA_SIZE. * On the other hand, value 2 ^ CONFIG_MEM_HEAP_OFFSET_LOG should not be less than CONFIG_MEM_HEAP_AREA_SIZE.
*/ */
#define CONFIG_MEM_HEAP_OFFSET_LOG 16 #define CONFIG_MEM_HEAP_OFFSET_LOG (16)
/** /**
* Number of lower bits in key of literal hash table. * Number of lower bits in key of literal hash table.
*/ */
#define CONFIG_LITERAL_HASH_TABLE_KEY_BITS 7 #define CONFIG_LITERAL_HASH_TABLE_KEY_BITS (7)
/** /**
* Width of fields used for holding counter of references to ecma-strings and ecma-objects * Width of fields used for holding counter of references to ecma-strings and ecma-objects
@@ -83,7 +83,7 @@
* Also the option affects size of ECMA Object Model's data types. * Also the option affects size of ECMA Object Model's data types.
* In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE. * In any case size of any of the types should not exceed CONFIG_MEM_POOL_CHUNK_SIZE.
*/ */
#define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH 10 #define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH (10)
/** /**
* Maximum length of strings' concatenation * Maximum length of strings' concatenation
@@ -125,7 +125,7 @@
/** /**
* Number of ecma-values inlined into stack frame * Number of ecma-values inlined into stack frame
*/ */
#define CONFIG_ECMA_STACK_FRAME_INLINED_VALUES_NUMBER 16 #define CONFIG_ECMA_STACK_FRAME_INLINED_VALUES_NUMBER (16)
/** /**
* Link Global Environment to an empty declarative lexical environment * Link Global Environment to an empty declarative lexical environment
@@ -150,9 +150,4 @@
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN // #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
#endif /* CONFIG_ECMA_COMPACT_PROFILE */ #endif /* CONFIG_ECMA_COMPACT_PROFILE */
/**
* Maximum number of arguments in the engine's command line (i.e. maximum argc value)
*/
#define CONFIG_JERRY_MAX_COMMAND_LINE_ARGS 64
#endif /* !CONFIG_H */ #endif /* !CONFIG_H */
+6 -6
View File
@@ -555,7 +555,7 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
if (length > ECMA_STRING_MAX_CONCATENATION_LENGTH) if (length > ECMA_STRING_MAX_CONCATENATION_LENGTH)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ecma_string_t* string_desc_p = ecma_alloc_string (); ecma_string_t* string_desc_p = ecma_alloc_string ();
@@ -846,7 +846,7 @@ ecma_string_to_number (const ecma_string_t *str_p) /**< ecma-string */
ecma_char_t *str_buffer_p = (ecma_char_t*) mem_heap_alloc_block (string_buf_size, MEM_HEAP_ALLOC_SHORT_TERM); ecma_char_t *str_buffer_p = (ecma_char_t*) mem_heap_alloc_block (string_buf_size, MEM_HEAP_ALLOC_SHORT_TERM);
if (str_buffer_p == NULL) if (str_buffer_p == NULL)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ssize_t bytes_copied = ecma_string_to_zt_string (str_p, ssize_t bytes_copied = ecma_string_to_zt_string (str_p,
@@ -1091,7 +1091,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
if (string1_buf == NULL if (string1_buf == NULL
|| string2_buf == NULL) || string2_buf == NULL)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ssize_t req_size; ssize_t req_size;
@@ -1205,7 +1205,7 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM); ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
if (heap_buffer_p == NULL) if (heap_buffer_p == NULL)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p, ssize_t bytes_copied = ecma_string_to_zt_string (string1_p,
@@ -1240,7 +1240,7 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma-
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM); ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM);
if (heap_buffer_p == NULL) if (heap_buffer_p == NULL)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p, ssize_t bytes_copied = ecma_string_to_zt_string (string2_p,
@@ -1372,7 +1372,7 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
if (zt_str_p == NULL) if (zt_str_p == NULL)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ecma_string_to_zt_string (string_p, zt_str_p, (ssize_t) buffer_size); ecma_string_to_zt_string (string_p, zt_str_p, (ssize_t) buffer_size);
+21 -12
View File
@@ -20,6 +20,21 @@
#include "serializer.h" #include "serializer.h"
#include "vm.h" #include "vm.h"
/**
* Jerry engine build date
*/
const char *jerry_build_date = JERRY_BUILD_DATE;
/**
* Jerry engine build commit hash
*/
const char *jerry_commit_hash = JERRY_COMMIT_HASH;
/**
* Jerry engine build branch name
*/
const char *jerry_branch_name = JERRY_BRANCH_NAME;
/** /**
* Jerry run-time configuration flags * Jerry run-time configuration flags
*/ */
@@ -122,37 +137,31 @@ jerry_parse (jerry_ctx_t* ctx_p, /**< run context */
/** /**
* Run Jerry in specified run context * Run Jerry in specified run context
*/ */
jerry_err_t jerry_completion_code_t
jerry_run (jerry_ctx_t* ctx_p) /**< run context */ jerry_run (jerry_ctx_t* ctx_p) /**< run context */
{ {
/* FIXME: Remove after implementation of run contexts */ /* FIXME: Remove after implementation of run contexts */
(void) ctx_p; (void) ctx_p;
if (run_int()) return run_int();
{
return ERR_OK;
}
else
{
return ERR_FAILED_ASSERTION_IN_SCRIPT;
}
} /* jerry_run */ } /* jerry_run */
/** /**
* Simple jerry runner * Simple jerry runner
*/ */
jerry_err_t jerry_completion_code_t
jerry_run_simple (const char *script_source, /**< script source */ jerry_run_simple (const char *script_source, /**< script source */
size_t script_source_size, /**< script source size */ size_t script_source_size, /**< script source size */
jerry_flag_t flags) /**< combination of Jerry flags */ jerry_flag_t flags) /**< combination of Jerry flags */
{ {
jerry_init (flags); jerry_init (flags);
jerry_err_t ret_code = ERR_OK; jerry_completion_code_t ret_code = JERRY_COMPLETION_CODE_OK;
if (!jerry_parse (NULL, script_source, script_source_size)) if (!jerry_parse (NULL, script_source, script_source_size))
{ {
ret_code = ERR_PARSER; /* unhandled SyntaxError */
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
} }
else else
{ {
+41 -8
View File
@@ -18,9 +18,6 @@
#include "jrt_types.h" #include "jrt_types.h"
/* FIXME: Remove when jerry_err_t will be in this header */
#include "jrt.h"
/** \addtogroup jerry Jerry engine interface /** \addtogroup jerry Jerry engine interface
* @{ * @{
*/ */
@@ -35,18 +32,54 @@ typedef uint32_t jerry_flag_t;
#define JERRY_FLAG_MEM_STATS (1 << 1) /**< dump per-opcode memory statistics during execution #define JERRY_FLAG_MEM_STATS (1 << 1) /**< dump per-opcode memory statistics during execution
* (in the mode full GC is performed after each opcode handler) */ * (in the mode full GC is performed after each opcode handler) */
#define JERRY_FLAG_PARSE_ONLY (1 << 2) /**< parse only, prevents script execution (only for testing) #define JERRY_FLAG_PARSE_ONLY (1 << 2) /**< parse only, prevents script execution (only for testing)
* FIXME: Remove. * FIXME: Remove. */
*/
/**
* Jerry completion codes
*/
typedef enum
{
JERRY_COMPLETION_CODE_OK = 0, /**< successful completion */
JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION = 1, /**< exception occured and it was not handled */
JERRY_COMPLETION_CODE_FAILED_ASSERTION_IN_SCRIPT = 2 /**< assertion, performed by script, failed */
} jerry_completion_code_t;
/**
* Error codes
*/
typedef enum
{
ERR_OUT_OF_MEMORY = 10,
ERR_SYSCALL = 11,
ERR_PARSER = 12,
ERR_UNIMPLEMENTED_CASE = 118,
ERR_FAILED_INTERNAL_ASSERTION = 120
} jerry_fatal_code_t;
/** /**
* Jerry run context * Jerry run context
*/ */
typedef struct jerry_ctx_t jerry_ctx_t; typedef struct jerry_ctx_t jerry_ctx_t;
/**
* Jerry engine build date
*/
extern const char *jerry_build_date;
/**
* Jerry engine build commit hash
*/
extern const char *jerry_commit_hash;
/**
* Jerry engine build branch name
*/
extern const char *jerry_branch_name;
/** /**
* Jerry error callback type * Jerry error callback type
*/ */
typedef void (*jerry_error_callback_t) (jerry_err_t); typedef void (*jerry_error_callback_t) (jerry_fatal_code_t);
extern void jerry_init (jerry_flag_t flags); extern void jerry_init (jerry_flag_t flags);
extern void jerry_cleanup (void); extern void jerry_cleanup (void);
@@ -58,9 +91,9 @@ extern jerry_ctx_t* jerry_new_ctx (void);
extern void jerry_cleanup_ctx (jerry_ctx_t*); extern void jerry_cleanup_ctx (jerry_ctx_t*);
extern bool jerry_parse (jerry_ctx_t*, const char* source_p, size_t source_size); extern bool jerry_parse (jerry_ctx_t*, const char* source_p, size_t source_size);
extern jerry_err_t jerry_run (jerry_ctx_t *); extern jerry_completion_code_t jerry_run (jerry_ctx_t *);
extern jerry_err_t extern jerry_completion_code_t
jerry_run_simple (const char *script_source, jerry_run_simple (const char *script_source,
size_t script_source_size, size_t script_source_size,
jerry_flag_t flags); jerry_flag_t flags);
-125
View File
@@ -1,125 +0,0 @@
/* Copyright 2014-2015 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 "jrt.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_err_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_OUT_OF_MEMORY:
{
__printf ("ERR_OUT_OF_MEMORY\n");
break;
}
case ERR_SYSCALL:
{
JERRY_UNREACHABLE();
break;
}
case ERR_UNHANDLED_EXCEPTION:
{
__printf ("ERR_UNHANDLED_EXCEPTION\n");
break;
}
case ERR_UNIMPLEMENTED_CASE:
{
__printf ("ERR_UNIMPLEMENTED_CASE\n");
break;
}
case ERR_FAILED_ASSERTION_IN_SCRIPT:
{
__printf ("ERR_FAILED_ASSERTION_IN_SCRIPT\n");
break;
}
case ERR_FAILED_INTERNAL_ASSERTION:
{
__printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
break;
}
}
}
#endif /* !JERRY_NDEBUG */
__exit (-code);
} /* jerry_exit */
@@ -13,9 +13,58 @@
* limitations under the License. * limitations under the License.
*/ */
/**
* Implementation of exit with specified status code.
*/
#include "jrt.h" #include "jrt.h"
#include "jerry-libc.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_fatal (jerry_fatal_code_t code) /**< status code */
{
#ifndef JERRY_NDEBUG
__printf ("Error: ");
switch (code)
{
case ERR_OUT_OF_MEMORY:
{
__printf ("ERR_OUT_OF_MEMORY\n");
break;
}
case ERR_SYSCALL:
{
/* print nothing as it may invoke syscall recursively */
break;
}
case ERR_PARSER:
{
__printf ("ERR_PARSER\n");
break;
}
case ERR_UNIMPLEMENTED_CASE:
{
__printf ("ERR_UNIMPLEMENTED_CASE\n");
break;
}
case ERR_FAILED_INTERNAL_ASSERTION:
{
__printf ("ERR_FAILED_INTERNAL_ASSERTION\n");
break;
}
}
#endif /* !JERRY_NDEBUG */
__exit (code);
} /* jerry_fatal */
/** /**
* Handle failed assertion * Handle failed assertion
*/ */
@@ -35,7 +84,7 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
(void) line; (void) line;
#endif /* JERRY_NDEBUG */ #endif /* JERRY_NDEBUG */
__exit (-ERR_FAILED_INTERNAL_ASSERTION); jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */ } /* jerry_assert_fail */
/** /**
@@ -62,7 +111,7 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
} }
__printf (".\n"); __printf (".\n");
__exit (-ERR_FAILED_INTERNAL_ASSERTION); jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */ } /* jerry_unreachable */
/** /**
@@ -89,5 +138,5 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
} }
__printf (".\n"); __printf (".\n");
__exit (-ERR_UNIMPLEMENTED_CASE); jerry_fatal (ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */ } /* jerry_unimplemented */
+5 -23
View File
@@ -16,6 +16,7 @@
#ifndef JERRY_GLOBALS_H #ifndef JERRY_GLOBALS_H
#define JERRY_GLOBALS_H #define JERRY_GLOBALS_H
#include "jerry.h"
#include "jrt_types.h" #include "jrt_types.h"
/** /**
@@ -43,29 +44,10 @@
#define JERRY_BITSINBYTE 8 #define JERRY_BITSINBYTE 8
/** /**
* Error codes * Standalone Jerry exit codes
*
* TODO: Move to jerry.h
*/ */
typedef enum #define JERRY_STANDALONE_EXIT_CODE_OK (0)
{ #define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
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_OUT_OF_MEMORY = -10,
ERR_SYSCALL = -11,
ERR_UNHANDLED_EXCEPTION = -12,
ERR_UNIMPLEMENTED_CASE = -118,
ERR_FAILED_ASSERTION_IN_SCRIPT = -119,
ERR_FAILED_INTERNAL_ASSERTION = -120,
} jerry_err_t;
/** /**
* Asserts * Asserts
@@ -175,7 +157,7 @@ template<typename... values> extern void jerry_ref_unused_variables (const value
/** /**
* Exit * Exit
*/ */
extern void __noreturn jerry_exit (jerry_err_t code); extern void __noreturn jerry_fatal (jerry_fatal_code_t code);
/** /**
* sizeof, offsetof, ... * sizeof, offsetof, ...
+1 -1
View File
@@ -53,7 +53,7 @@ FIXME (/* Include linux/fs.h */)
#define LIBC_EXIT_ON_ERROR(syscall_ret_val) \ #define LIBC_EXIT_ON_ERROR(syscall_ret_val) \
if (unlikely ((syscall_ret_val) < 0)) \ if (unlikely ((syscall_ret_val) < 0)) \
{ \ { \
__exit (-ERR_SYSCALL); \ jerry_fatal (ERR_SYSCALL); \
} }
static long int syscall_1 (long int syscall_no, long int arg1); static long int syscall_1 (long int syscall_no, long int arg1);
-55
View File
@@ -1,55 +0,0 @@
/* Copyright 2014-2015 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.
*/
#include "jrt.h"
#include "jerry-libc.h"
/**
* Handle failed assertion
*/
void __noreturn
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /** line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
-55
View File
@@ -1,55 +0,0 @@
/* Copyright 2014-2015 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.
*/
#include "jrt.h"
#include "jerry-libc.h"
/**
* Handle failed assertion
*/
void __noreturn
jerry_assert_fail (const char *assertion __unused, /**< assertion condition string */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /** line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_assert_fail */
/**
* Handle execution of control path that should be unreachable
*/
void __noreturn
jerry_unreachable (const char *comment __unused, /**< comment to unreachable mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
} /* jerry_unreachable */
/**
* Handle unimplemented case execution
*/
void __noreturn
jerry_unimplemented (const char *comment __unused, /**< comment to unimplemented mark if exists,
NULL - otherwise */
const char *file __unused, /**< file name */
const char *function __unused, /**< function name */
const uint32_t line __unused) /**< line */
{
__exit (-ERR_UNIMPLEMENTED_CASE);
} /* jerry_unimplemented */
+59 -24
View File
@@ -13,10 +13,14 @@
* limitations under the License. * limitations under the License.
*/ */
#include "config.h"
#include "jerry.h" #include "jerry.h"
#include "jerry-libc.h" #include "jerry-libc.h"
/**
* Maximum command line arguments number
*/
#define JERRY_MAX_COMMAND_LINE_ARGS (64)
static uint8_t source_buffer[ JERRY_SOURCE_BUFFER_SIZE ]; static uint8_t source_buffer[ JERRY_SOURCE_BUFFER_SIZE ];
static const char* static const char*
@@ -24,6 +28,8 @@ read_sources (const char *script_file_names[],
size_t files_count, size_t files_count,
size_t *out_source_size_p) size_t *out_source_size_p)
{ {
JERRY_ASSERT (files_count > 0);
size_t i; size_t i;
uint8_t *source_buffer_tail = source_buffer; uint8_t *source_buffer_tail = source_buffer;
@@ -35,21 +41,21 @@ read_sources (const char *script_file_names[],
if (file == NULL) if (file == NULL)
{ {
jerry_exit (ERR_IO); break;
} }
int fseek_status = __fseek (file, 0, __SEEK_END); int fseek_status = __fseek (file, 0, __SEEK_END);
if (fseek_status != 0) if (fseek_status != 0)
{ {
jerry_exit (ERR_IO); break;
} }
long script_len = __ftell (file); long script_len = __ftell (file);
if (script_len < 0) if (script_len < 0)
{ {
jerry_exit (ERR_IO); break;
} }
__rewind (file); __rewind (file);
@@ -58,13 +64,13 @@ read_sources (const char *script_file_names[],
if (source_buffer_tail + current_source_size >= source_buffer + sizeof (source_buffer)) if (source_buffer_tail + current_source_size >= source_buffer + sizeof (source_buffer))
{ {
jerry_exit (ERR_OUT_OF_MEMORY); break;
} }
size_t bytes_read = __fread (source_buffer_tail, 1, current_source_size, file); size_t bytes_read = __fread (source_buffer_tail, 1, current_source_size, file);
if (bytes_read < current_source_size) if (bytes_read < current_source_size)
{ {
jerry_exit (ERR_IO); break;
} }
__fclose (file); __fclose (file);
@@ -72,29 +78,42 @@ read_sources (const char *script_file_names[],
source_buffer_tail += current_source_size; source_buffer_tail += current_source_size;
} }
const size_t source_size = (size_t) (source_buffer_tail - source_buffer); if (i < files_count)
JERRY_ASSERT(source_size < sizeof (source_buffer)); {
__printf ("Failed to read script N%d\n", i + 1);
*out_source_size_p = source_size; return NULL;
}
else
{
const size_t source_size = (size_t) (source_buffer_tail - source_buffer);
JERRY_ASSERT(source_size < sizeof (source_buffer));
return (const char*)source_buffer; *out_source_size_p = source_size;
return (const char*)source_buffer;
}
} }
int int
main (int argc __unused, main (int argc __unused,
char **argv __unused) char **argv __unused)
{ {
if (argc > CONFIG_JERRY_MAX_COMMAND_LINE_ARGS) if (argc >= JERRY_MAX_COMMAND_LINE_ARGS)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); __printf ("Too many command line arguments. Current maximum is %d (JERRY_MAX_COMMAND_LINE_ARGS)\n", argc);
return JERRY_STANDALONE_EXIT_CODE_FAIL;
} }
const char *file_names[CONFIG_JERRY_MAX_COMMAND_LINE_ARGS]; const char *file_names[JERRY_MAX_COMMAND_LINE_ARGS];
int i; int i;
size_t files_counter = 0; size_t files_counter = 0;
jrt_set_mem_limits (CONFIG_MEM_HEAP_AREA_SIZE + CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE, size_t max_data_bss_size, max_stack_size;
CONFIG_MEM_STACK_LIMIT); jerry_get_memory_limits (&max_data_bss_size, &max_stack_size);
jrt_set_mem_limits (max_data_bss_size, max_stack_size);
jerry_flag_t flags = JERRY_FLAG_EMPTY; jerry_flag_t flags = JERRY_FLAG_EMPTY;
@@ -102,9 +121,9 @@ main (int argc __unused,
{ {
if (!__strcmp ("-v", argv[i])) if (!__strcmp ("-v", argv[i]))
{ {
__printf ("Build date: \t%s\n", JERRY_BUILD_DATE); __printf ("Build date: \t%s\n", jerry_build_date);
__printf ("Commit hash:\t%s\n", JERRY_COMMIT_HASH); __printf ("Commit hash:\t%s\n", jerry_commit_hash);
__printf ("Branch name:\t%s\n", JERRY_BRANCH_NAME); __printf ("Branch name:\t%s\n", jerry_branch_name);
__printf ("\n"); __printf ("\n");
} }
if (!__strcmp ("--mem-stats", argv[i])) if (!__strcmp ("--mem-stats", argv[i]))
@@ -131,13 +150,29 @@ main (int argc __unused,
if (files_counter == 0) if (files_counter == 0)
{ {
jerry_exit (ERR_NO_FILES); return JERRY_STANDALONE_EXIT_CODE_OK;
} }
else
{
size_t source_size;
const char *source_p = read_sources (file_names, files_counter, &source_size);
size_t source_size; if (source_p == NULL)
const char *source_p = read_sources (file_names, files_counter, &source_size); {
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
else
{
jerry_completion_code_t ret_code = jerry_run_simple (source_p, source_size, flags);
jerry_err_t ret_code = jerry_run_simple (source_p, source_size, flags); if (ret_code == JERRY_COMPLETION_CODE_OK)
{
jerry_exit (ret_code); return JERRY_STANDALONE_EXIT_CODE_OK;
}
else
{
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
}
}
} }
+12 -1
View File
@@ -39,6 +39,17 @@ main (void)
set_sys_tick_counter ((uint32_t) - 1); set_sys_tick_counter ((uint32_t) - 1);
start = get_sys_tick_counter (); start = get_sys_tick_counter ();
jerry_run_simple (source_p, source_size, JERRY_FLAG_EMPTY);
jerry_completion_code_t ret_code = jerry_run_simple (source_p, source_size, JERRY_FLAG_EMPTY);
finish_parse_ms = (start - get_sys_tick_counter ()) / 1000; finish_parse_ms = (start - get_sys_tick_counter ()) / 1000;
if (ret_code == JERRY_COMPLETION_CODE_OK)
{
return JERRY_STANDALONE_EXIT_CODE_OK;
}
else
{
return JERRY_STANDALONE_EXIT_CODE_FAIL;
}
} }
+1 -1
View File
@@ -607,7 +607,7 @@ mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to a
JERRY_ASSERT (data_space_p == NULL); JERRY_ASSERT (data_space_p == NULL);
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
} /* mem_heap_alloc_block */ } /* mem_heap_alloc_block */
+7 -7
View File
@@ -1,4 +1,4 @@
/* Copyright 2014 Samsung Electronics Co., Ltd. /* Copyright 2014-2015 Samsung Electronics Co., Ltd.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
} \ } \
__printf ("^\n"); \ __printf ("^\n"); \
__printf ("ERROR: Ln %d, Col %d: %s\n", line + 1, column + 1, MESSAGE); \ __printf ("ERROR: Ln %d, Col %d: %s\n", line + 1, column + 1, MESSAGE); \
__exit (-1); \ jerry_fatal (ERR_PARSER); \
} while (0) } while (0)
#define PARSE_WARN(MESSAGE, LOCUS) do { \ #define PARSE_WARN(MESSAGE, LOCUS) do { \
size_t line, column; \ size_t line, column; \
@@ -50,7 +50,7 @@
__printf ("ERROR: Ln %d, Col %d: ", line + 1, column + 1); \ __printf ("ERROR: Ln %d, Col %d: ", line + 1, column + 1); \
__printf (MESSAGE, __VA_ARGS__); \ __printf (MESSAGE, __VA_ARGS__); \
__printf ("\n"); \ __printf ("\n"); \
__exit (-1); \ jerry_fatal (ERR_PARSER); \
} while (0) } while (0)
#define PARSE_SORRY(MESSAGE, LOCUS) do { \ #define PARSE_SORRY(MESSAGE, LOCUS) do { \
size_t line, column; \ size_t line, column; \
@@ -62,19 +62,19 @@
} \ } \
__printf ("^\n"); \ __printf ("^\n"); \
__printf ("SORRY, Unimplemented: Ln %d, Col %d: %s\n", line + 1, column + 1, MESSAGE); \ __printf ("SORRY, Unimplemented: Ln %d, Col %d: %s\n", line + 1, column + 1, MESSAGE); \
__exit (-1); \ JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \
} while (0) } while (0)
#else /* JERRY_NDEBUG */ #else /* JERRY_NDEBUG */
#define PARSE_ERROR(MESSAGE, LOCUS) do { \ #define PARSE_ERROR(MESSAGE, LOCUS) do { \
__exit (-1); \ jerry_fatal (ERR_PARSER); \
} while (0) } while (0)
#define PARSE_WARN(MESSAGE, LOCUS) do { \ #define PARSE_WARN(MESSAGE, LOCUS) do { \
} while (0) } while (0)
#define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \ #define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \
__exit (-1); \ jerry_fatal (ERR_PARSER); \
} while (0) } while (0)
#define PARSE_SORRY(MESSAGE, LOCUS) do { \ #define PARSE_SORRY(MESSAGE, LOCUS) do { \
__exit (-1); \ JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \
} while (0) } while (0)
#endif /* JERRY_NDEBUG */ #endif /* JERRY_NDEBUG */
+1 -1
View File
@@ -128,7 +128,7 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
MEM_HEAP_ALLOC_SHORT_TERM); MEM_HEAP_ALLOC_SHORT_TERM);
if (zt_str_p == NULL) if (zt_str_p == NULL)
{ {
jerry_exit (ERR_OUT_OF_MEMORY); jerry_fatal (ERR_OUT_OF_MEMORY);
} }
ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size); ecma_string_to_zt_string (str_p, zt_str_p, zt_str_size);
+20 -9
View File
@@ -345,7 +345,7 @@ init_int (const opcode_t *program_p, /**< pointer to byte-code program */
__program = program_p; __program = program_p;
} /* init_int */ } /* init_int */
bool jerry_completion_code_t
run_int (void) run_int (void)
{ {
JERRY_ASSERT (__program != NULL); JERRY_ASSERT (__program != NULL);
@@ -378,20 +378,31 @@ run_int (void)
is_strict, is_strict,
false); false);
jerry_completion_code_t ret_code;
if (ecma_is_completion_value_exit (completion)) if (ecma_is_completion_value_exit (completion))
{ {
ecma_deref_object (glob_obj_p); if (ecma_is_value_true (ecma_get_completion_value_value (completion)))
ecma_deref_object (lex_env_p); {
ecma_finalize (); ret_code = JERRY_COMPLETION_CODE_OK;
}
return ecma_is_value_true (ecma_get_completion_value_value (completion)); else
{
ret_code = JERRY_COMPLETION_CODE_FAILED_ASSERTION_IN_SCRIPT;
}
} }
else if (ecma_is_completion_value_throw (completion)) else
{ {
jerry_exit (ERR_UNHANDLED_EXCEPTION); JERRY_ASSERT (ecma_is_completion_value_throw (completion));
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
} }
JERRY_UNREACHABLE (); ecma_deref_object (glob_obj_p);
ecma_deref_object (lex_env_p);
ecma_finalize ();
return ret_code;
} }
ecma_completion_value_t ecma_completion_value_t
+1 -1
View File
@@ -21,7 +21,7 @@
#include "opcodes.h" #include "opcodes.h"
void init_int (const opcode_t* program_p, bool dump_mem_stats); void init_int (const opcode_t* program_p, bool dump_mem_stats);
bool run_int (void); jerry_completion_code_t run_int (void);
ecma_completion_value_t run_int_loop (int_data_t *int_data); ecma_completion_value_t run_int_loop (int_data_t *int_data);
ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos, ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos,
const ecma_value_t& this_binding_value, const ecma_value_t& this_binding_value,