mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Refinement of completion status codes and fatal error handlers.
This commit is contained in:
parent
398501afeb
commit
17f51e0ba6
25
src/config.h
25
src/config.h
@ -19,34 +19,34 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
#define CONFIG_MEM_STACK_LIMIT 4096
|
||||
#define CONFIG_MEM_STACK_LIMIT (4096)
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#define CONFIG_MEM_LEAST_CHUNK_NUMBER_IN_POOL 32
|
||||
#define CONFIG_MEM_LEAST_CHUNK_NUMBER_IN_POOL (32)
|
||||
|
||||
/**
|
||||
* Size of heap chunk
|
||||
*/
|
||||
#define CONFIG_MEM_HEAP_CHUNK_SIZE 64
|
||||
#define CONFIG_MEM_HEAP_CHUNK_SIZE (64)
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
#define CONFIG_MEM_HEAP_OFFSET_LOG 16
|
||||
#define CONFIG_MEM_HEAP_OFFSET_LOG (16)
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -83,7 +83,7 @@
|
||||
* 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.
|
||||
*/
|
||||
#define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH 10
|
||||
#define CONFIG_ECMA_REFERENCE_COUNTER_WIDTH (10)
|
||||
|
||||
/**
|
||||
* Maximum length of strings' concatenation
|
||||
@ -125,7 +125,7 @@
|
||||
/**
|
||||
* 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
|
||||
@ -150,9 +150,4 @@
|
||||
// #define CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
|
||||
#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 */
|
||||
|
||||
@ -555,7 +555,7 @@ ecma_concat_ecma_strings (ecma_string_t *string1_p, /**< first ecma-string */
|
||||
|
||||
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 ();
|
||||
@ -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);
|
||||
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,
|
||||
@ -1091,7 +1091,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri
|
||||
if (string1_buf == NULL
|
||||
|| string2_buf == NULL)
|
||||
{
|
||||
jerry_exit (ERR_OUT_OF_MEMORY);
|
||||
jerry_fatal (ERR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
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);
|
||||
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,
|
||||
@ -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);
|
||||
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,
|
||||
@ -1372,7 +1372,7 @@ ecma_string_get_char_at_pos (const ecma_string_t *string_p, /**< ecma-string */
|
||||
|
||||
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);
|
||||
|
||||
@ -20,6 +20,21 @@
|
||||
#include "serializer.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
|
||||
*/
|
||||
@ -122,37 +137,31 @@ jerry_parse (jerry_ctx_t* ctx_p, /**< run context */
|
||||
/**
|
||||
* Run Jerry in specified run context
|
||||
*/
|
||||
jerry_err_t
|
||||
jerry_completion_code_t
|
||||
jerry_run (jerry_ctx_t* ctx_p) /**< run context */
|
||||
{
|
||||
/* FIXME: Remove after implementation of run contexts */
|
||||
(void) ctx_p;
|
||||
|
||||
if (run_int())
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERR_FAILED_ASSERTION_IN_SCRIPT;
|
||||
}
|
||||
return run_int();
|
||||
} /* jerry_run */
|
||||
|
||||
/**
|
||||
* Simple jerry runner
|
||||
*/
|
||||
jerry_err_t
|
||||
jerry_completion_code_t
|
||||
jerry_run_simple (const char *script_source, /**< script source */
|
||||
size_t script_source_size, /**< script source size */
|
||||
jerry_flag_t flags) /**< combination of Jerry 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))
|
||||
{
|
||||
ret_code = ERR_PARSER;
|
||||
/* unhandled SyntaxError */
|
||||
ret_code = JERRY_COMPLETION_CODE_UNHANDLED_EXCEPTION;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
49
src/jerry.h
49
src/jerry.h
@ -18,9 +18,6 @@
|
||||
|
||||
#include "jrt_types.h"
|
||||
|
||||
/* FIXME: Remove when jerry_err_t will be in this header */
|
||||
#include "jrt.h"
|
||||
|
||||
/** \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
|
||||
* (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)
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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_cleanup (void);
|
||||
@ -58,9 +91,9 @@ extern jerry_ctx_t* jerry_new_ctx (void);
|
||||
extern void jerry_cleanup_ctx (jerry_ctx_t*);
|
||||
|
||||
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,
|
||||
size_t script_source_size,
|
||||
jerry_flag_t flags);
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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_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
|
||||
*/
|
||||
@ -35,7 +84,7 @@ jerry_assert_fail (const char *assertion, /**< assertion condition string */
|
||||
(void) line;
|
||||
#endif /* JERRY_NDEBUG */
|
||||
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_assert_fail */
|
||||
|
||||
/**
|
||||
@ -62,7 +111,7 @@ jerry_unreachable (const char *comment, /**< comment to unreachable mark if exis
|
||||
}
|
||||
__printf (".\n");
|
||||
|
||||
__exit (-ERR_FAILED_INTERNAL_ASSERTION);
|
||||
jerry_fatal (ERR_FAILED_INTERNAL_ASSERTION);
|
||||
} /* jerry_unreachable */
|
||||
|
||||
/**
|
||||
@ -89,5 +138,5 @@ jerry_unimplemented (const char *comment, /**< comment to unimplemented mark if
|
||||
}
|
||||
__printf (".\n");
|
||||
|
||||
__exit (-ERR_UNIMPLEMENTED_CASE);
|
||||
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
|
||||
} /* jerry_unimplemented */
|
||||
@ -16,6 +16,7 @@
|
||||
#ifndef JERRY_GLOBALS_H
|
||||
#define JERRY_GLOBALS_H
|
||||
|
||||
#include "jerry.h"
|
||||
#include "jrt_types.h"
|
||||
|
||||
/**
|
||||
@ -43,29 +44,10 @@
|
||||
#define JERRY_BITSINBYTE 8
|
||||
|
||||
/**
|
||||
* Error codes
|
||||
*
|
||||
* TODO: Move to jerry.h
|
||||
* Standalone Jerry exit codes
|
||||
*/
|
||||
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_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;
|
||||
#define JERRY_STANDALONE_EXIT_CODE_OK (0)
|
||||
#define JERRY_STANDALONE_EXIT_CODE_FAIL (1)
|
||||
|
||||
/**
|
||||
* Asserts
|
||||
@ -175,7 +157,7 @@ template<typename... values> extern void jerry_ref_unused_variables (const value
|
||||
/**
|
||||
* Exit
|
||||
*/
|
||||
extern void __noreturn jerry_exit (jerry_err_t code);
|
||||
extern void __noreturn jerry_fatal (jerry_fatal_code_t code);
|
||||
|
||||
/**
|
||||
* sizeof, offsetof, ...
|
||||
|
||||
@ -53,7 +53,7 @@ FIXME (/* Include linux/fs.h */)
|
||||
#define LIBC_EXIT_ON_ERROR(syscall_ret_val) \
|
||||
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);
|
||||
|
||||
@ -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 */
|
||||
@ -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 */
|
||||
@ -13,10 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "jerry.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 const char*
|
||||
@ -24,6 +28,8 @@ read_sources (const char *script_file_names[],
|
||||
size_t files_count,
|
||||
size_t *out_source_size_p)
|
||||
{
|
||||
JERRY_ASSERT (files_count > 0);
|
||||
|
||||
size_t i;
|
||||
uint8_t *source_buffer_tail = source_buffer;
|
||||
|
||||
@ -35,21 +41,21 @@ read_sources (const char *script_file_names[],
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
jerry_exit (ERR_IO);
|
||||
break;
|
||||
}
|
||||
|
||||
int fseek_status = __fseek (file, 0, __SEEK_END);
|
||||
|
||||
if (fseek_status != 0)
|
||||
{
|
||||
jerry_exit (ERR_IO);
|
||||
break;
|
||||
}
|
||||
|
||||
long script_len = __ftell (file);
|
||||
|
||||
if (script_len < 0)
|
||||
{
|
||||
jerry_exit (ERR_IO);
|
||||
break;
|
||||
}
|
||||
|
||||
__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))
|
||||
{
|
||||
jerry_exit (ERR_OUT_OF_MEMORY);
|
||||
break;
|
||||
}
|
||||
|
||||
size_t bytes_read = __fread (source_buffer_tail, 1, current_source_size, file);
|
||||
if (bytes_read < current_source_size)
|
||||
{
|
||||
jerry_exit (ERR_IO);
|
||||
break;
|
||||
}
|
||||
|
||||
__fclose (file);
|
||||
@ -72,29 +78,42 @@ read_sources (const char *script_file_names[],
|
||||
source_buffer_tail += current_source_size;
|
||||
}
|
||||
|
||||
const size_t source_size = (size_t) (source_buffer_tail - source_buffer);
|
||||
JERRY_ASSERT(source_size < sizeof (source_buffer));
|
||||
if (i < files_count)
|
||||
{
|
||||
__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
|
||||
main (int argc __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;
|
||||
size_t files_counter = 0;
|
||||
|
||||
jrt_set_mem_limits (CONFIG_MEM_HEAP_AREA_SIZE + CONFIG_MEM_DATA_LIMIT_MINUS_HEAP_SIZE,
|
||||
CONFIG_MEM_STACK_LIMIT);
|
||||
size_t max_data_bss_size, max_stack_size;
|
||||
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;
|
||||
|
||||
@ -102,9 +121,9 @@ main (int argc __unused,
|
||||
{
|
||||
if (!__strcmp ("-v", argv[i]))
|
||||
{
|
||||
__printf ("Build date: \t%s\n", JERRY_BUILD_DATE);
|
||||
__printf ("Commit hash:\t%s\n", JERRY_COMMIT_HASH);
|
||||
__printf ("Branch name:\t%s\n", JERRY_BRANCH_NAME);
|
||||
__printf ("Build date: \t%s\n", jerry_build_date);
|
||||
__printf ("Commit hash:\t%s\n", jerry_commit_hash);
|
||||
__printf ("Branch name:\t%s\n", jerry_branch_name);
|
||||
__printf ("\n");
|
||||
}
|
||||
if (!__strcmp ("--mem-stats", argv[i]))
|
||||
@ -131,13 +150,29 @@ main (int argc __unused,
|
||||
|
||||
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;
|
||||
const char *source_p = read_sources (file_names, files_counter, &source_size);
|
||||
if (source_p == NULL)
|
||||
{
|
||||
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);
|
||||
|
||||
jerry_exit (ret_code);
|
||||
if (ret_code == JERRY_COMPLETION_CODE_OK)
|
||||
{
|
||||
return JERRY_STANDALONE_EXIT_CODE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return JERRY_STANDALONE_EXIT_CODE_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,17 @@ main (void)
|
||||
|
||||
set_sys_tick_counter ((uint32_t) - 1);
|
||||
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;
|
||||
|
||||
if (ret_code == JERRY_COMPLETION_CODE_OK)
|
||||
{
|
||||
return JERRY_STANDALONE_EXIT_CODE_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return JERRY_STANDALONE_EXIT_CODE_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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_exit (ERR_OUT_OF_MEMORY);
|
||||
jerry_fatal (ERR_OUT_OF_MEMORY);
|
||||
}
|
||||
} /* mem_heap_alloc_block */
|
||||
|
||||
|
||||
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -31,7 +31,7 @@
|
||||
} \
|
||||
__printf ("^\n"); \
|
||||
__printf ("ERROR: Ln %d, Col %d: %s\n", line + 1, column + 1, MESSAGE); \
|
||||
__exit (-1); \
|
||||
jerry_fatal (ERR_PARSER); \
|
||||
} while (0)
|
||||
#define PARSE_WARN(MESSAGE, LOCUS) do { \
|
||||
size_t line, column; \
|
||||
@ -50,7 +50,7 @@
|
||||
__printf ("ERROR: Ln %d, Col %d: ", line + 1, column + 1); \
|
||||
__printf (MESSAGE, __VA_ARGS__); \
|
||||
__printf ("\n"); \
|
||||
__exit (-1); \
|
||||
jerry_fatal (ERR_PARSER); \
|
||||
} while (0)
|
||||
#define PARSE_SORRY(MESSAGE, LOCUS) do { \
|
||||
size_t line, column; \
|
||||
@ -62,19 +62,19 @@
|
||||
} \
|
||||
__printf ("^\n"); \
|
||||
__printf ("SORRY, Unimplemented: Ln %d, Col %d: %s\n", line + 1, column + 1, MESSAGE); \
|
||||
__exit (-1); \
|
||||
JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \
|
||||
} while (0)
|
||||
#else /* JERRY_NDEBUG */
|
||||
#define PARSE_ERROR(MESSAGE, LOCUS) do { \
|
||||
__exit (-1); \
|
||||
jerry_fatal (ERR_PARSER); \
|
||||
} while (0)
|
||||
#define PARSE_WARN(MESSAGE, LOCUS) do { \
|
||||
} while (0)
|
||||
#define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \
|
||||
__exit (-1); \
|
||||
jerry_fatal (ERR_PARSER); \
|
||||
} while (0)
|
||||
#define PARSE_SORRY(MESSAGE, LOCUS) do { \
|
||||
__exit (-1); \
|
||||
JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \
|
||||
} while (0)
|
||||
#endif /* JERRY_NDEBUG */
|
||||
|
||||
|
||||
@ -128,7 +128,7 @@ opfunc_native_call (opcode_t opdata, /**< operation data */
|
||||
MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
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);
|
||||
|
||||
@ -345,7 +345,7 @@ init_int (const opcode_t *program_p, /**< pointer to byte-code program */
|
||||
__program = program_p;
|
||||
} /* init_int */
|
||||
|
||||
bool
|
||||
jerry_completion_code_t
|
||||
run_int (void)
|
||||
{
|
||||
JERRY_ASSERT (__program != NULL);
|
||||
@ -378,20 +378,31 @@ run_int (void)
|
||||
is_strict,
|
||||
false);
|
||||
|
||||
jerry_completion_code_t ret_code;
|
||||
|
||||
if (ecma_is_completion_value_exit (completion))
|
||||
{
|
||||
ecma_deref_object (glob_obj_p);
|
||||
ecma_deref_object (lex_env_p);
|
||||
ecma_finalize ();
|
||||
|
||||
return ecma_is_value_true (ecma_get_completion_value_value (completion));
|
||||
if (ecma_is_value_true (ecma_get_completion_value_value (completion)))
|
||||
{
|
||||
ret_code = JERRY_COMPLETION_CODE_OK;
|
||||
}
|
||||
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
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
#include "opcodes.h"
|
||||
|
||||
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_from_pos (opcode_counter_t start_pos,
|
||||
const ecma_value_t& this_binding_value,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user