diff --git a/jerry-core/jerry.h b/jerry-core/jerry.h index a2252a9c2..b60e1d70c 100644 --- a/jerry-core/jerry.h +++ b/jerry-core/jerry.h @@ -49,7 +49,6 @@ 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; diff --git a/jerry-core/jrt/jrt-fatals.cpp b/jerry-core/jrt/jrt-fatals.cpp index 2dcc761ba..cfae74892 100644 --- a/jerry-core/jrt/jrt-fatals.cpp +++ b/jerry-core/jrt/jrt-fatals.cpp @@ -47,11 +47,6 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */ /* 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"); diff --git a/jerry-core/jrt/jrt-libc-includes.h b/jerry-core/jrt/jrt-libc-includes.h index f694b52c3..41684e1aa 100644 --- a/jerry-core/jrt/jrt-libc-includes.h +++ b/jerry-core/jrt/jrt-libc-includes.h @@ -17,6 +17,8 @@ #define JRT_LIBC_INCLUDES_H #include +#include +#include #include #include #include diff --git a/jerry-core/parser/js/collections/array-list.cpp b/jerry-core/parser/js/collections/array-list.cpp index f964aed6e..51422bb4c 100644 --- a/jerry-core/parser/js/collections/array-list.cpp +++ b/jerry-core/parser/js/collections/array-list.cpp @@ -14,8 +14,8 @@ */ #include "array-list.h" -#include "mem-heap.h" #include "jrt-libc-includes.h" +#include "jsp-mm.h" typedef struct { @@ -44,14 +44,14 @@ array_list_append (array_list al, void *element) array_list_header *h = extract_header (al); if ((h->len + 1) * h->element_size + sizeof (array_list_header) > h->size) { - size_t size = mem_heap_recommend_allocation_size (h->size + h->element_size); + size_t size = jsp_mm_recommend_size (h->size + h->element_size); JERRY_ASSERT (size > h->size); - uint8_t* new_block_p = (uint8_t*) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM); + uint8_t *new_block_p = (uint8_t *) jsp_mm_alloc (size); memcpy (new_block_p, h, h->size); memset (new_block_p + h->size, 0, size - h->size); - mem_heap_free_block ((uint8_t *) h); + jsp_mm_free (h); h = (array_list_header *) new_block_p; h->size = size; @@ -111,8 +111,8 @@ array_list_set_last_element (array_list al, size_t index, void *elem) array_list array_list_init (uint8_t element_size) { - size_t size = mem_heap_recommend_allocation_size (sizeof (array_list_header)); - array_list_header *header = (array_list_header *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM); + size_t size = jsp_mm_recommend_size (sizeof (array_list_header)); + array_list_header *header = (array_list_header *) jsp_mm_alloc (size); memset (header, 0, size); header->element_size = element_size; header->len = 0; @@ -131,5 +131,5 @@ void array_list_free (array_list al) { array_list_header *h = extract_header (al); - mem_heap_free_block ((uint8_t *) h); + jsp_mm_free (h); } diff --git a/jerry-core/parser/js/collections/hash-table.cpp b/jerry-core/parser/js/collections/hash-table.cpp index ac5abe6a3..5b0948335 100644 --- a/jerry-core/parser/js/collections/hash-table.cpp +++ b/jerry-core/parser/js/collections/hash-table.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "hash-table.h" #include "array-list.h" -#include "mem-heap.h" +#include "hash-table.h" #include "jrt-libc-includes.h" +#include "jsp-mm.h" typedef struct { @@ -25,7 +25,6 @@ typedef struct uint16_t size; uint8_t key_size; uint8_t value_size; - mem_heap_alloc_term_t alloc_term; } hash_table_int; static hash_table_int * @@ -65,12 +64,12 @@ hash_table_insert (hash_table ht, void *key, void *value) { list = array_list_init (bucket_size (hti)); } - uint8_t *bucket = (uint8_t*) mem_heap_alloc_block (bucket_size (hti), hti->alloc_term); + uint8_t *bucket = (uint8_t *) jsp_mm_alloc (bucket_size (hti)); memcpy (bucket, key, hti->key_size); memcpy (bucket + hti->key_size, value, hti->value_size); list = array_list_append (list, bucket); hti->data[index] = list; - mem_heap_free_block (bucket); + jsp_mm_free (bucket); } void * @@ -98,15 +97,14 @@ hash_table_lookup (hash_table ht, void *key) hash_table hash_table_init (uint8_t key_size, uint8_t value_size, uint16_t size, - uint16_t (*hash) (void *), mem_heap_alloc_term_t alloc_term) + uint16_t (*hash) (void *)) { - hash_table_int *res = (hash_table_int *) mem_heap_alloc_block (sizeof (hash_table_int), alloc_term); + hash_table_int *res = (hash_table_int *) jsp_mm_alloc (sizeof (hash_table_int)); memset (res, 0, sizeof (hash_table_int)); res->key_size = key_size; res->value_size = value_size; res->size = size; - res->alloc_term = alloc_term; - res->data = (array_list *) mem_heap_alloc_block (size * sizeof (array_list), alloc_term); + res->data = (array_list *) jsp_mm_alloc (size * sizeof (array_list)); memset (res->data, 0, size * sizeof (array_list)); res->hash = hash; return res; @@ -125,6 +123,6 @@ hash_table_free (hash_table ht) set_list (h, i, null_list); } } - mem_heap_free_block ((uint8_t *) h->data); - mem_heap_free_block ((uint8_t *) h); + jsp_mm_free (h->data); + jsp_mm_free (h); } diff --git a/jerry-core/parser/js/collections/hash-table.h b/jerry-core/parser/js/collections/hash-table.h index 2e47bf9a4..f284a7eeb 100644 --- a/jerry-core/parser/js/collections/hash-table.h +++ b/jerry-core/parser/js/collections/hash-table.h @@ -30,7 +30,7 @@ typedef void* hash_table; #define null_hash NULL -hash_table hash_table_init (uint8_t, uint8_t, uint16_t, uint16_t (*hash) (void *), mem_heap_alloc_term_t); +hash_table hash_table_init (uint8_t, uint8_t, uint16_t, uint16_t (*hash) (void *)); void hash_table_free (hash_table); void hash_table_insert (hash_table, void *, void *); void *hash_table_lookup (hash_table, void *); diff --git a/jerry-core/parser/js/collections/linked-list.cpp b/jerry-core/parser/js/collections/linked-list.cpp index f9b6c2cfd..a4329c3f5 100644 --- a/jerry-core/parser/js/collections/linked-list.cpp +++ b/jerry-core/parser/js/collections/linked-list.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ -#include "linked-list.h" #include "jrt-libc-includes.h" -#include "mem-heap.h" +#include "jsp-mm.h" +#include "linked-list.h" typedef struct linked_list_header { @@ -31,14 +31,14 @@ do { \ static size_t linked_list_block_size (uint16_t element_size) { - return mem_heap_recommend_allocation_size (sizeof (linked_list_header) + element_size) - sizeof (linked_list_header); + return jsp_mm_recommend_size (sizeof (linked_list_header) + element_size) - sizeof (linked_list_header); } linked_list linked_list_init (uint16_t element_size) { size_t size = sizeof (linked_list_header) + linked_list_block_size (element_size); - linked_list list = (linked_list) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM); + linked_list list = (linked_list) jsp_mm_alloc (size); if (list == null_list) { printf ("Out of memory"); @@ -60,7 +60,7 @@ linked_list_free (linked_list list) { linked_list_free ((linked_list) header->next); } - mem_heap_free_block (list); + jsp_mm_free (list); } void * diff --git a/jerry-core/parser/js/jsp-mm.cpp b/jerry-core/parser/js/jsp-mm.cpp index 2fc242c23..6fc7b1293 100644 --- a/jerry-core/parser/js/jsp-mm.cpp +++ b/jerry-core/parser/js/jsp-mm.cpp @@ -92,7 +92,7 @@ jsp_mm_recommend_size (size_t minimum_size) /**< minimum required size */ void* jsp_mm_alloc (size_t size) /**< size of block to allocate */ { - void *ptr_p = mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM); + void *ptr_p = mem_heap_alloc_block (size + sizeof (jsp_mm_header_t), MEM_HEAP_ALLOC_SHORT_TERM); jsp_mm_header_t *tmem_header_p = (jsp_mm_header_t*) ptr_p; diff --git a/jerry-core/parser/js/lexer.cpp b/jerry-core/parser/js/lexer.cpp index 2cafb0ae0..369cdb1c3 100644 --- a/jerry-core/parser/js/lexer.cpp +++ b/jerry-core/parser/js/lexer.cpp @@ -13,11 +13,11 @@ * limitations under the License. */ -#include "mem-allocator.h" +#include "ecma-helpers.h" #include "jrt-libc-includes.h" +#include "jsp-mm.h" #include "lexer.h" #include "syntax-errors.h" -#include "ecma-helpers.h" static token saved_token, prev_token, sent_token, empty_token; @@ -474,9 +474,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of JERRY_ASSERT (source_str_p != NULL); } - MEM_DEFINE_LOCAL_ARRAY (str_buf_p, - source_str_size, - ecma_char_t); + ecma_char_t *str_buf_p = (ecma_char_t*) jsp_mm_alloc (source_str_size * sizeof (ecma_char_t)); const char *source_str_iter_p = source_str_p; ecma_char_t *str_buf_iter_p = str_buf_p; @@ -632,7 +630,7 @@ convert_string_to_token_transform_escape_seq (token_type tok_type, /**< type of PARSE_ERROR ("Malformed escape sequence", source_str_p - buffer_start); } - MEM_FINALIZE_LOCAL_ARRAY (str_buf_p); + jsp_mm_free (str_buf_p); return ret; } /* convert_string_to_token_transform_escape_seq */ @@ -860,13 +858,12 @@ parse_number (void) tok_length = (size_t) (buffer - token_start);; if (is_fp || is_exp) { - ecma_char_t *temp = (ecma_char_t*) mem_heap_alloc_block ((size_t) (tok_length + 1), - MEM_HEAP_ALLOC_SHORT_TERM); + ecma_char_t *temp = (ecma_char_t*) jsp_mm_alloc ((size_t) (tok_length + 1) * sizeof (ecma_char_t)); strncpy ((char *) temp, token_start, (size_t) (tok_length)); temp[tok_length] = '\0'; ecma_number_t res = ecma_zt_string_to_number (temp); JERRY_ASSERT (!ecma_number_is_nan (res)); - mem_heap_free_block (temp); + jsp_mm_free (temp); known_token = convert_seen_num_to_token (res); token_start = NULL; return known_token; @@ -1467,28 +1464,22 @@ lexer_are_tokens_with_same_identifier (token id1, /**< identifier token (TOK_NAM } /* lexer_are_tokens_with_same_identifier */ /** - * Initialize lexer to start parsing of a new source + * Intitialize lexer */ void -lexer_init_source (const char *source, /**< script source */ - size_t source_size) /**< script source size in bytes */ +lexer_init (const char *source, /**< script source */ + size_t source_size /**< script source size in bytes */, + bool show_opcodes) /**< flag indicating if to dump opcodes */ { + empty_token.type = TOK_EMPTY; + empty_token.uid = 0; + empty_token.loc = 0; + saved_token = prev_token = sent_token = empty_token; buffer_size = source_size; lexer_set_source (source); lexer_set_strict_mode (false); -} /* lexer_init_source */ - -/** - * Intitialize lexer - */ -void -lexer_init (bool show_opcodes) /**< flag indicating if to dump opcodes */ -{ - empty_token.type = TOK_EMPTY; - empty_token.uid = 0; - empty_token.loc = 0; #ifndef JERRY_NDEBUG allow_dump_lines = show_opcodes; @@ -1497,8 +1488,3 @@ lexer_init (bool show_opcodes) /**< flag indicating if to dump opcodes */ allow_dump_lines = false; #endif /* JERRY_NDEBUG */ } /* lexer_init */ - -void -lexer_free (void) -{ -} diff --git a/jerry-core/parser/js/lexer.h b/jerry-core/parser/js/lexer.h index 914ad9639..f67b6a991 100644 --- a/jerry-core/parser/js/lexer.h +++ b/jerry-core/parser/js/lexer.h @@ -169,9 +169,7 @@ typedef struct */ #define TOKEN_EMPTY_INITIALIZER {0, TOK_EMPTY, 0} -void lexer_init (bool); -void lexer_init_source (const char *, size_t); -void lexer_free (void); +void lexer_init (const char *, size_t, bool); token lexer_next_token (void); void lexer_save_token (token); diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 3fcb0c0a7..2c2179e46 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -13,22 +13,20 @@ * limitations under the License. */ -#include - +#include "ecma-helpers.h" +#include "hash-table.h" #include "jrt-libc-includes.h" #include "jsp-label.h" -#include "parser.h" +#include "jsp-mm.h" #include "opcodes.h" -#include "serializer.h" -#include "vm.h" -#include "stack.h" -#include "hash-table.h" -#include "opcodes-native-call.h" -#include "scopes-tree.h" -#include "ecma-helpers.h" -#include "syntax-errors.h" #include "opcodes-dumper.h" +#include "opcodes-native-call.h" +#include "parser.h" +#include "scopes-tree.h" #include "serializer.h" +#include "stack.h" +#include "syntax-errors.h" +#include "vm.h" /** * Flag, indicating whether result of expression @@ -2895,8 +2893,16 @@ parser_parse_program (const char *source_p, /**< source code buffer */ inside_function = in_function; inside_eval = in_eval; - lexer_init (parser_show_opcodes); - lexer_init_source (source_p, source_size); +#ifndef JERRY_NDEBUG + volatile bool is_parse_finished = false; +#endif /* !JERRY_NDEBUG */ + + bool is_syntax_correct; + + jsp_mm_init (); + jsp_label_init (); + + lexer_init (source_p, source_size, parser_show_opcodes); serializer_set_show_opcodes (parser_show_opcodes); dumper_init (); @@ -2907,41 +2913,67 @@ parser_parse_program (const char *source_p, /**< source code buffer */ serializer_set_scope (STACK_TOP (scopes)); lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes))); - jsp_label_init (); + jmp_buf *syntax_error_label_p = syntax_get_syntax_error_longjmp_label (); + int r = setjmp (*syntax_error_label_p); - skip_newlines (); - parse_source_element_list (true); - - skip_newlines (); - JERRY_ASSERT (token_is (TOK_EOF)); - - if (in_function) + if (r == 0) { - dump_ret (); - } - else if (inside_eval) - { - dump_retval (eval_ret_operand ()); + skip_newlines (); + parse_source_element_list (true); + + skip_newlines (); + JERRY_ASSERT (token_is (TOK_EOF)); + + if (in_function) + { + dump_ret (); + } + else if (inside_eval) + { + dump_retval (eval_ret_operand ()); + } + else + { + dump_exit (); + } + +#ifndef JERRY_NDEBUG + is_parse_finished = true; +#endif /* !JERRY_NDEBUG */ + + syntax_free (); + + *out_opcodes_p = serializer_merge_scopes_into_bytecode (); + + dumper_free (); + + serializer_set_scope (NULL); + scopes_tree_free (STACK_TOP (scopes)); + STACK_DROP (scopes, 1); + STACK_FREE (scopes); + + is_syntax_correct = true; } else { - dump_exit (); + /* SyntaxError handling */ + +#ifndef JERRY_NDEBUG + JERRY_ASSERT (!is_parse_finished); +#endif /* !JERRY_NDEBUG */ + + *out_opcodes_p = NULL; + + jsp_label_remove_all_labels (); + jsp_mm_free_all (); + + is_syntax_correct = false; } jsp_label_finalize (); - syntax_free (); - lexer_free (); + jsp_mm_finalize (); - *out_opcodes_p = serializer_merge_scopes_into_bytecode (); - - dumper_free (); - - serializer_set_scope (NULL); - scopes_tree_free (STACK_TOP (scopes)); - STACK_DROP (scopes, 1); - STACK_FREE (scopes); - - return true; + return is_syntax_correct; } /* parser_parse_program */ /** diff --git a/jerry-core/parser/js/scopes-tree.cpp b/jerry-core/parser/js/scopes-tree.cpp index 3bf84afa9..ce083e868 100644 --- a/jerry-core/parser/js/scopes-tree.cpp +++ b/jerry-core/parser/js/scopes-tree.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -#include "scopes-tree.h" #include "bytecode-data.h" +#include "jsp-mm.h" +#include "scopes-tree.h" #define OPCODE(op) (__op__idx_##op) #define HASH_SIZE 128 @@ -114,8 +115,7 @@ start_new_block_if_necessary (void) hash_table_free (lit_id_to_uid); lit_id_to_uid = null_hash; } - lit_id_to_uid = hash_table_init (sizeof (lit_cpointer_t), sizeof (idx_t), HASH_SIZE, lit_id_hash, - MEM_HEAP_ALLOC_SHORT_TERM); + lit_id_to_uid = hash_table_init (sizeof (lit_cpointer_t), sizeof (idx_t), HASH_SIZE, lit_id_hash); } } @@ -652,7 +652,7 @@ scopes_tree_strict_mode (scopes_tree tree) scopes_tree scopes_tree_init (scopes_tree parent) { - scopes_tree tree = (scopes_tree) mem_heap_alloc_block (sizeof (scopes_tree_int), MEM_HEAP_ALLOC_SHORT_TERM); + scopes_tree tree = (scopes_tree) jsp_mm_alloc (sizeof (scopes_tree_int)); memset (tree, 0, sizeof (scopes_tree_int)); tree->t.parent = (tree_header *) parent; tree->t.children = null_list; @@ -687,5 +687,5 @@ scopes_tree_free (scopes_tree tree) linked_list_free (tree->t.children); } linked_list_free (tree->opcodes); - mem_heap_free_block ((uint8_t *) tree); + jsp_mm_free (tree); } diff --git a/jerry-core/parser/js/syntax-errors.cpp b/jerry-core/parser/js/syntax-errors.cpp index 481aef350..508916883 100644 --- a/jerry-core/parser/js/syntax-errors.cpp +++ b/jerry-core/parser/js/syntax-errors.cpp @@ -20,6 +20,15 @@ #include "jrt-libc-includes.h" #include "ecma-helpers.h" +/** + * SyntaxError longjmp label, used to finish parse upon a SyntaxError is raised + * + * See also: + * syntax_get_syntax_error_longjmp_label + * syntax_raise_error + */ +static jmp_buf jsp_syntax_error_label; + typedef struct { prop_type type; @@ -38,6 +47,26 @@ enum }; STATIC_STACK (U8, uint8_t) +/** + * Get buffer for SyntaxError longjmp label + * + * @return pointer to jmp_buf + */ +jmp_buf * +syntax_get_syntax_error_longjmp_label (void) +{ + return &jsp_syntax_error_label; +} /* syntax_get_syntax_error_longjmp_label */ + +/** + * Raise SyntaxError, i.e. perform longjmp to SyntaxError longjmp label + */ +void __attribute__((noreturn)) +syntax_raise_error (void) +{ + longjmp (jsp_syntax_error_label, 1); +} /* syntax_raise_error */ + static prop_literal create_prop_literal (literal_t lit, prop_type type) { diff --git a/jerry-core/parser/js/syntax-errors.h b/jerry-core/parser/js/syntax-errors.h index 62dc228cc..c075252d9 100644 --- a/jerry-core/parser/js/syntax-errors.h +++ b/jerry-core/parser/js/syntax-errors.h @@ -16,11 +16,12 @@ #ifndef SYNTAX_ERRORS_H #define SYNTAX_ERRORS_H +#include "jrt-libc-includes.h" #include "opcodes-dumper.h" #include "lexer.h" #ifndef JERRY_NDEBUG -#define PARSE_ERROR(MESSAGE, LOCUS) do { \ +#define PARSE_ERROR_PRINT_PLACE(TYPE, LOCUS) do { \ size_t line, column; \ lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \ lexer_dump_line (line); \ @@ -29,49 +30,30 @@ putchar (' '); \ } \ printf ("^\n"); \ - printf ("ERROR: Ln %lu, Col %lu: %s\n", (unsigned long) (line + 1), (unsigned long) (column + 1), MESSAGE); \ - jerry_fatal (ERR_PARSER); \ + printf ("%s: Ln %lu, Col %lu: ", TYPE, (unsigned long) (line + 1), (unsigned long) (column + 1)); \ } while (0) -#define PARSE_WARN(MESSAGE, LOCUS) do { \ - size_t line, column; \ - lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \ - printf ("WARNING: Ln %lu, Col %lu: %s\n", (unsigned long) (line + 1), (unsigned long) (column + 1), MESSAGE); \ +#define PARSE_ERROR(MESSAGE, LOCUS) do { \ + PARSE_ERROR_PRINT_PLACE ("ERROR", LOCUS); \ + printf ("%s\n", MESSAGE); \ + syntax_raise_error (); \ } while (0) #define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \ - size_t line, column; \ - lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \ - lexer_dump_line (line); \ - printf ("\n"); \ - for (size_t i = 0; i < column; i++) { \ - putchar (' '); \ - } \ - printf ("^\n"); \ - printf ("ERROR: Ln %lu, Col %lu: ", (unsigned long) (line + 1), (unsigned long) (column + 1)); \ + PARSE_ERROR_PRINT_PLACE ("ERROR", LOCUS); \ printf (MESSAGE, __VA_ARGS__); \ printf ("\n"); \ - jerry_fatal (ERR_PARSER); \ + syntax_raise_error (); \ } while (0) #define PARSE_SORRY(MESSAGE, LOCUS) do { \ - size_t line, column; \ - lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \ - lexer_dump_line (line); \ - printf ("\n"); \ - for (size_t i = 0; i < column; i++) { \ - putchar (' '); \ - } \ - printf ("^\n"); \ - printf ("SORRY, Unimplemented: Ln %lu, Col %lu: %s\n", \ - (unsigned long) (line + 1), (unsigned long) (column + 1), MESSAGE); \ + PARSE_ERROR_PRINT_PLACE ("SORRY, Unimplemented", LOCUS); \ + printf ("%s\n", MESSAGE); \ JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \ } while (0) #else /* JERRY_NDEBUG */ #define PARSE_ERROR(MESSAGE, LOCUS) do { \ - jerry_fatal (ERR_PARSER); \ -} while (0) -#define PARSE_WARN(MESSAGE, LOCUS) do { \ + syntax_raise_error (); \ } while (0) #define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \ - jerry_fatal (ERR_PARSER); \ + syntax_raise_error (); \ } while (0) #define PARSE_SORRY(MESSAGE, LOCUS) do { \ JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \ @@ -100,4 +82,7 @@ void syntax_check_for_syntax_errors_in_formal_param_list (bool, locus); void syntax_check_delete (bool, locus); +jmp_buf * syntax_get_syntax_error_longjmp_label (void); +void __attribute__((noreturn)) syntax_raise_error (void); + #endif /* SYNTAX_ERRORS_H */ diff --git a/jerry-libc/include/setjmp.h b/jerry-libc/include/setjmp.h index 89071eb9e..35ae5ae59 100644 --- a/jerry-libc/include/setjmp.h +++ b/jerry-libc/include/setjmp.h @@ -16,6 +16,8 @@ #ifndef JERRY_LIBC_SETJMP_H #define JERRY_LIBC_SETJMP_H +#include + #ifdef __cplusplus # define EXTERN_C "C" #else /* !__cplusplus */ diff --git a/tests/jerry/eval.js b/tests/jerry/eval.js index 22eb187fd..f3e6bfb51 100644 --- a/tests/jerry/eval.js +++ b/tests/jerry/eval.js @@ -86,3 +86,14 @@ for (var i = 0; i < 100; i++) r = eval ('if (true) 3; else 5;'); assert (r === 3); } + +// Check SyntaxError handling +try +{ + eval ('var var;'); + assert (false); +} +catch (e) +{ + assert (e instanceof SyntaxError); +} diff --git a/tests/jerry/fail/12/arguments-assignment-strict.js b/tests/jerry/fail/1/arguments-assignment-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-assignment-strict.js rename to tests/jerry/fail/1/arguments-assignment-strict.js index b581932d8..c39b16eb5 100644 --- a/tests/jerry/fail/12/arguments-assignment-strict.js +++ b/tests/jerry/fail/1/arguments-assignment-strict.js @@ -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. diff --git a/tests/jerry/fail/12/arguments-catch-strict.js b/tests/jerry/fail/1/arguments-catch-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-catch-strict.js rename to tests/jerry/fail/1/arguments-catch-strict.js index 80b3fa1d4..433e5a7fa 100644 --- a/tests/jerry/fail/12/arguments-catch-strict.js +++ b/tests/jerry/fail/1/arguments-catch-strict.js @@ -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. diff --git a/tests/jerry/fail/12/arguments-in-prop-set-param-list-strict.js b/tests/jerry/fail/1/arguments-in-prop-set-param-list-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-in-prop-set-param-list-strict.js rename to tests/jerry/fail/1/arguments-in-prop-set-param-list-strict.js index ea4383bb4..4ba512f04 100644 --- a/tests/jerry/fail/12/arguments-in-prop-set-param-list-strict.js +++ b/tests/jerry/fail/1/arguments-in-prop-set-param-list-strict.js @@ -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. diff --git a/tests/jerry/fail/12/arguments-in-var-decl-strict.js b/tests/jerry/fail/1/arguments-in-var-decl-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-in-var-decl-strict.js rename to tests/jerry/fail/1/arguments-in-var-decl-strict.js index 7bd81940b..276c9b7d0 100644 --- a/tests/jerry/fail/12/arguments-in-var-decl-strict.js +++ b/tests/jerry/fail/1/arguments-in-var-decl-strict.js @@ -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. diff --git a/tests/jerry/fail/12/arguments-param-strict.js b/tests/jerry/fail/1/arguments-param-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-param-strict.js rename to tests/jerry/fail/1/arguments-param-strict.js index 6aecb72d0..10e44ba0d 100644 --- a/tests/jerry/fail/12/arguments-param-strict.js +++ b/tests/jerry/fail/1/arguments-param-strict.js @@ -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. diff --git a/tests/jerry/fail/12/arguments-postfix-strict.js b/tests/jerry/fail/1/arguments-postfix-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-postfix-strict.js rename to tests/jerry/fail/1/arguments-postfix-strict.js index bc319d524..2498f79c9 100644 --- a/tests/jerry/fail/12/arguments-postfix-strict.js +++ b/tests/jerry/fail/1/arguments-postfix-strict.js @@ -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. diff --git a/tests/jerry/fail/12/arguments-prefix-strict.js b/tests/jerry/fail/1/arguments-prefix-strict.js similarity index 91% rename from tests/jerry/fail/12/arguments-prefix-strict.js rename to tests/jerry/fail/1/arguments-prefix-strict.js index 217fa508e..c011369b9 100644 --- a/tests/jerry/fail/12/arguments-prefix-strict.js +++ b/tests/jerry/fail/1/arguments-prefix-strict.js @@ -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. diff --git a/tests/jerry/fail/12/delete-strict.js b/tests/jerry/fail/1/delete-strict.js similarity index 91% rename from tests/jerry/fail/12/delete-strict.js rename to tests/jerry/fail/1/delete-strict.js index fa82d732a..1b525aa4e 100644 --- a/tests/jerry/fail/12/delete-strict.js +++ b/tests/jerry/fail/1/delete-strict.js @@ -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. diff --git a/tests/jerry/fail/12/escape-sequences-invalid-hex.js b/tests/jerry/fail/1/escape-sequences-invalid-hex.js similarity index 100% rename from tests/jerry/fail/12/escape-sequences-invalid-hex.js rename to tests/jerry/fail/1/escape-sequences-invalid-hex.js diff --git a/tests/jerry/fail/12/escape-sequences-invalid-unicode.js b/tests/jerry/fail/1/escape-sequences-invalid-unicode.js similarity index 100% rename from tests/jerry/fail/12/escape-sequences-invalid-unicode.js rename to tests/jerry/fail/1/escape-sequences-invalid-unicode.js diff --git a/tests/jerry/fail/12/escape-sequences-invalid-variable.js b/tests/jerry/fail/1/escape-sequences-invalid-variable.js similarity index 100% rename from tests/jerry/fail/12/escape-sequences-invalid-variable.js rename to tests/jerry/fail/1/escape-sequences-invalid-variable.js diff --git a/tests/jerry/fail/12/eval-assignment-strict.js b/tests/jerry/fail/1/eval-assignment-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-assignment-strict.js rename to tests/jerry/fail/1/eval-assignment-strict.js index aa28ff6d4..b59b5d3f0 100644 --- a/tests/jerry/fail/12/eval-assignment-strict.js +++ b/tests/jerry/fail/1/eval-assignment-strict.js @@ -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. diff --git a/tests/jerry/fail/12/eval-catch-strict.js b/tests/jerry/fail/1/eval-catch-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-catch-strict.js rename to tests/jerry/fail/1/eval-catch-strict.js index c48f0a8f6..80d2996bb 100644 --- a/tests/jerry/fail/12/eval-catch-strict.js +++ b/tests/jerry/fail/1/eval-catch-strict.js @@ -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. diff --git a/tests/jerry/fail/12/eval-in-prop-set-param-list-strict.js b/tests/jerry/fail/1/eval-in-prop-set-param-list-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-in-prop-set-param-list-strict.js rename to tests/jerry/fail/1/eval-in-prop-set-param-list-strict.js index da21ecd8f..3cd28bad0 100644 --- a/tests/jerry/fail/12/eval-in-prop-set-param-list-strict.js +++ b/tests/jerry/fail/1/eval-in-prop-set-param-list-strict.js @@ -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. diff --git a/tests/jerry/fail/12/eval-in-var-decl-strict.js b/tests/jerry/fail/1/eval-in-var-decl-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-in-var-decl-strict.js rename to tests/jerry/fail/1/eval-in-var-decl-strict.js index 753197c5a..319635e91 100644 --- a/tests/jerry/fail/12/eval-in-var-decl-strict.js +++ b/tests/jerry/fail/1/eval-in-var-decl-strict.js @@ -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. diff --git a/tests/jerry/fail/12/eval-param-strict.js b/tests/jerry/fail/1/eval-param-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-param-strict.js rename to tests/jerry/fail/1/eval-param-strict.js index 689f4f58d..893efb539 100644 --- a/tests/jerry/fail/12/eval-param-strict.js +++ b/tests/jerry/fail/1/eval-param-strict.js @@ -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. diff --git a/tests/jerry/fail/12/eval-postfix-strict.js b/tests/jerry/fail/1/eval-postfix-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-postfix-strict.js rename to tests/jerry/fail/1/eval-postfix-strict.js index e908b5f71..da7d49f30 100644 --- a/tests/jerry/fail/12/eval-postfix-strict.js +++ b/tests/jerry/fail/1/eval-postfix-strict.js @@ -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. diff --git a/tests/jerry/fail/12/eval-prefix-strict.js b/tests/jerry/fail/1/eval-prefix-strict.js similarity index 91% rename from tests/jerry/fail/12/eval-prefix-strict.js rename to tests/jerry/fail/1/eval-prefix-strict.js index 55a0202e1..d36f8b950 100644 --- a/tests/jerry/fail/12/eval-prefix-strict.js +++ b/tests/jerry/fail/1/eval-prefix-strict.js @@ -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. diff --git a/tests/jerry/fail/12/labelled-statements-break-across-function.js b/tests/jerry/fail/1/labelled-statements-break-across-function.js similarity index 100% rename from tests/jerry/fail/12/labelled-statements-break-across-function.js rename to tests/jerry/fail/1/labelled-statements-break-across-function.js diff --git a/tests/jerry/fail/12/labelled-statements-duplicate-label.js b/tests/jerry/fail/1/labelled-statements-duplicate-label.js similarity index 100% rename from tests/jerry/fail/12/labelled-statements-duplicate-label.js rename to tests/jerry/fail/1/labelled-statements-duplicate-label.js diff --git a/tests/jerry/fail/12/labelled-statements-no-label.js b/tests/jerry/fail/1/labelled-statements-no-label.js similarity index 100% rename from tests/jerry/fail/12/labelled-statements-no-label.js rename to tests/jerry/fail/1/labelled-statements-no-label.js diff --git a/tests/jerry/fail/12/let-strict.js b/tests/jerry/fail/1/let-strict.js similarity index 91% rename from tests/jerry/fail/12/let-strict.js rename to tests/jerry/fail/1/let-strict.js index e39810412..4f40cc0fc 100644 --- a/tests/jerry/fail/12/let-strict.js +++ b/tests/jerry/fail/1/let-strict.js @@ -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. diff --git a/tests/jerry/fail/12/object-get-data.js b/tests/jerry/fail/1/object-get-data.js similarity index 91% rename from tests/jerry/fail/12/object-get-data.js rename to tests/jerry/fail/1/object-get-data.js index 5a2184af0..f69c4c826 100644 --- a/tests/jerry/fail/12/object-get-data.js +++ b/tests/jerry/fail/1/object-get-data.js @@ -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. diff --git a/tests/jerry/fail/12/object-get-get.js b/tests/jerry/fail/1/object-get-get.js similarity index 92% rename from tests/jerry/fail/12/object-get-get.js rename to tests/jerry/fail/1/object-get-get.js index fb429f78c..324ea3187 100644 --- a/tests/jerry/fail/12/object-get-get.js +++ b/tests/jerry/fail/1/object-get-get.js @@ -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. diff --git a/tests/jerry/fail/12/object-several-prop-names-strict.js b/tests/jerry/fail/1/object-several-prop-names-strict.js similarity index 91% rename from tests/jerry/fail/12/object-several-prop-names-strict.js rename to tests/jerry/fail/1/object-several-prop-names-strict.js index 1426f3ef6..366bad987 100644 --- a/tests/jerry/fail/12/object-several-prop-names-strict.js +++ b/tests/jerry/fail/1/object-several-prop-names-strict.js @@ -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. diff --git a/tests/jerry/fail/12/octal-strict.js b/tests/jerry/fail/1/octal-strict.js similarity index 91% rename from tests/jerry/fail/12/octal-strict.js rename to tests/jerry/fail/1/octal-strict.js index 7e51a8129..e271e3721 100644 --- a/tests/jerry/fail/12/octal-strict.js +++ b/tests/jerry/fail/1/octal-strict.js @@ -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. diff --git a/tests/jerry/fail/12/param-duplication-strict.js b/tests/jerry/fail/1/param-duplication-strict.js similarity index 91% rename from tests/jerry/fail/12/param-duplication-strict.js rename to tests/jerry/fail/1/param-duplication-strict.js index ce645650d..388b2a24a 100644 --- a/tests/jerry/fail/12/param-duplication-strict.js +++ b/tests/jerry/fail/1/param-duplication-strict.js @@ -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. diff --git a/tests/jerry/fail/12/with-strict.js b/tests/jerry/fail/1/with-strict.js similarity index 91% rename from tests/jerry/fail/12/with-strict.js rename to tests/jerry/fail/1/with-strict.js index 34aa856d2..7d51fcc7c 100644 --- a/tests/jerry/fail/12/with-strict.js +++ b/tests/jerry/fail/1/with-strict.js @@ -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. diff --git a/tests/jerry/function-construct.js b/tests/jerry/function-construct.js index 0a2d70364..8f221c216 100644 --- a/tests/jerry/function-construct.js +++ b/tests/jerry/function-construct.js @@ -79,3 +79,14 @@ catch (e) { assert (e instanceof TypeError); } + +// Check SyntaxError handling +try +{ + new Function ('var var;'); + assert (false); +} +catch (e) +{ + assert (e instanceof SyntaxError); +} diff --git a/tests/unit/test-parser.cpp b/tests/unit/test-parser.cpp index 5e83bfefc..e1b1604c6 100644 --- a/tests/unit/test-parser.cpp +++ b/tests/unit/test-parser.cpp @@ -71,18 +71,19 @@ main (int __attr_unused___ argc, { TEST_INIT (); - char program[] = "a=1;var a;"; - bool is_ok; - const opcode_t *opcodes_p; bool is_syntax_correct; mem_init (); + + // #1 + char program1[] = "a=1;var a;"; + serializer_init (); parser_set_show_opcodes (true); - is_syntax_correct = parser_parse_script (program, strlen (program), &opcodes_p); + is_syntax_correct = parser_parse_script (program1, strlen (program1), &opcodes_p); - JERRY_ASSERT (is_syntax_correct); + JERRY_ASSERT (is_syntax_correct && opcodes_p != NULL); opcode_t opcodes[] = { @@ -97,17 +98,22 @@ main (int __attr_unused___ argc, getop_exitval (0) // exit 0; }; - if (!opcodes_equal (opcodes_p, opcodes, 5)) - { - is_ok = false; - } - else - { - is_ok = true; - } + JERRY_ASSERT (opcodes_equal (opcodes_p, opcodes, 5)); serializer_free (); + + // #2 + char program2[] = "var var;"; + + serializer_init (); + parser_set_show_opcodes (true); + is_syntax_correct = parser_parse_script (program2, strlen (program2), &opcodes_p); + + JERRY_ASSERT (!is_syntax_correct && opcodes_p == NULL); + + serializer_free (); + mem_finalize (false); - return (is_ok ? 0 : 1); + return 0; } /* main */