Support syntax error feedback in parser.
Now, parser correctly finishes parse procedure if syntax of source code is incorrect (syntax correctness is indicated using return value): - parser-internal memory management is performed using jsp_mm_alloc / jsp_mm_free; - upon detection of incorrect syntax, all parser-allocated memory regions are deallocated using jsp_mm_free_all and parse finishes with corresponding return value. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -49,7 +49,6 @@ typedef enum
|
|||||||
{
|
{
|
||||||
ERR_OUT_OF_MEMORY = 10,
|
ERR_OUT_OF_MEMORY = 10,
|
||||||
ERR_SYSCALL = 11,
|
ERR_SYSCALL = 11,
|
||||||
ERR_PARSER = 12,
|
|
||||||
ERR_UNIMPLEMENTED_CASE = 118,
|
ERR_UNIMPLEMENTED_CASE = 118,
|
||||||
ERR_FAILED_INTERNAL_ASSERTION = 120
|
ERR_FAILED_INTERNAL_ASSERTION = 120
|
||||||
} jerry_fatal_code_t;
|
} jerry_fatal_code_t;
|
||||||
|
|||||||
@@ -47,11 +47,6 @@ jerry_fatal (jerry_fatal_code_t code) /**< status code */
|
|||||||
/* print nothing as it may invoke syscall recursively */
|
/* print nothing as it may invoke syscall recursively */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ERR_PARSER:
|
|
||||||
{
|
|
||||||
printf ("ERR_PARSER\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ERR_UNIMPLEMENTED_CASE:
|
case ERR_UNIMPLEMENTED_CASE:
|
||||||
{
|
{
|
||||||
printf ("ERR_UNIMPLEMENTED_CASE\n");
|
printf ("ERR_UNIMPLEMENTED_CASE\n");
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#define JRT_LIBC_INCLUDES_H
|
#define JRT_LIBC_INCLUDES_H
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "array-list.h"
|
#include "array-list.h"
|
||||||
#include "mem-heap.h"
|
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
|
#include "jsp-mm.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -44,14 +44,14 @@ array_list_append (array_list al, void *element)
|
|||||||
array_list_header *h = extract_header (al);
|
array_list_header *h = extract_header (al);
|
||||||
if ((h->len + 1) * h->element_size + sizeof (array_list_header) > h->size)
|
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);
|
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);
|
memcpy (new_block_p, h, h->size);
|
||||||
memset (new_block_p + h->size, 0, size - 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 = (array_list_header *) new_block_p;
|
||||||
h->size = size;
|
h->size = size;
|
||||||
@@ -111,8 +111,8 @@ array_list_set_last_element (array_list al, size_t index, void *elem)
|
|||||||
array_list
|
array_list
|
||||||
array_list_init (uint8_t element_size)
|
array_list_init (uint8_t element_size)
|
||||||
{
|
{
|
||||||
size_t size = mem_heap_recommend_allocation_size (sizeof (array_list_header));
|
size_t size = jsp_mm_recommend_size (sizeof (array_list_header));
|
||||||
array_list_header *header = (array_list_header *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
array_list_header *header = (array_list_header *) jsp_mm_alloc (size);
|
||||||
memset (header, 0, size);
|
memset (header, 0, size);
|
||||||
header->element_size = element_size;
|
header->element_size = element_size;
|
||||||
header->len = 0;
|
header->len = 0;
|
||||||
@@ -131,5 +131,5 @@ void
|
|||||||
array_list_free (array_list al)
|
array_list_free (array_list al)
|
||||||
{
|
{
|
||||||
array_list_header *h = extract_header (al);
|
array_list_header *h = extract_header (al);
|
||||||
mem_heap_free_block ((uint8_t *) h);
|
jsp_mm_free (h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hash-table.h"
|
|
||||||
#include "array-list.h"
|
#include "array-list.h"
|
||||||
#include "mem-heap.h"
|
#include "hash-table.h"
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
|
#include "jsp-mm.h"
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,6 @@ typedef struct
|
|||||||
uint16_t size;
|
uint16_t size;
|
||||||
uint8_t key_size;
|
uint8_t key_size;
|
||||||
uint8_t value_size;
|
uint8_t value_size;
|
||||||
mem_heap_alloc_term_t alloc_term;
|
|
||||||
} hash_table_int;
|
} hash_table_int;
|
||||||
|
|
||||||
static 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));
|
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, key, hti->key_size);
|
||||||
memcpy (bucket + hti->key_size, value, hti->value_size);
|
memcpy (bucket + hti->key_size, value, hti->value_size);
|
||||||
list = array_list_append (list, bucket);
|
list = array_list_append (list, bucket);
|
||||||
hti->data[index] = list;
|
hti->data[index] = list;
|
||||||
mem_heap_free_block (bucket);
|
jsp_mm_free (bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
@@ -98,15 +97,14 @@ hash_table_lookup (hash_table ht, void *key)
|
|||||||
|
|
||||||
hash_table
|
hash_table
|
||||||
hash_table_init (uint8_t key_size, uint8_t value_size, uint16_t size,
|
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));
|
memset (res, 0, sizeof (hash_table_int));
|
||||||
res->key_size = key_size;
|
res->key_size = key_size;
|
||||||
res->value_size = value_size;
|
res->value_size = value_size;
|
||||||
res->size = size;
|
res->size = size;
|
||||||
res->alloc_term = alloc_term;
|
res->data = (array_list *) jsp_mm_alloc (size * sizeof (array_list));
|
||||||
res->data = (array_list *) mem_heap_alloc_block (size * sizeof (array_list), alloc_term);
|
|
||||||
memset (res->data, 0, size * sizeof (array_list));
|
memset (res->data, 0, size * sizeof (array_list));
|
||||||
res->hash = hash;
|
res->hash = hash;
|
||||||
return res;
|
return res;
|
||||||
@@ -125,6 +123,6 @@ hash_table_free (hash_table ht)
|
|||||||
set_list (h, i, null_list);
|
set_list (h, i, null_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mem_heap_free_block ((uint8_t *) h->data);
|
jsp_mm_free (h->data);
|
||||||
mem_heap_free_block ((uint8_t *) h);
|
jsp_mm_free (h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
typedef void* hash_table;
|
typedef void* hash_table;
|
||||||
#define null_hash NULL
|
#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_free (hash_table);
|
||||||
void hash_table_insert (hash_table, void *, void *);
|
void hash_table_insert (hash_table, void *, void *);
|
||||||
void *hash_table_lookup (hash_table, void *);
|
void *hash_table_lookup (hash_table, void *);
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "linked-list.h"
|
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
#include "mem-heap.h"
|
#include "jsp-mm.h"
|
||||||
|
#include "linked-list.h"
|
||||||
|
|
||||||
typedef struct linked_list_header
|
typedef struct linked_list_header
|
||||||
{
|
{
|
||||||
@@ -31,14 +31,14 @@ do { \
|
|||||||
|
|
||||||
static size_t linked_list_block_size (uint16_t element_size)
|
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
|
||||||
linked_list_init (uint16_t element_size)
|
linked_list_init (uint16_t element_size)
|
||||||
{
|
{
|
||||||
size_t size = sizeof (linked_list_header) + linked_list_block_size (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)
|
if (list == null_list)
|
||||||
{
|
{
|
||||||
printf ("Out of memory");
|
printf ("Out of memory");
|
||||||
@@ -60,7 +60,7 @@ linked_list_free (linked_list list)
|
|||||||
{
|
{
|
||||||
linked_list_free ((linked_list) header->next);
|
linked_list_free ((linked_list) header->next);
|
||||||
}
|
}
|
||||||
mem_heap_free_block (list);
|
jsp_mm_free (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ jsp_mm_recommend_size (size_t minimum_size) /**< minimum required size */
|
|||||||
void*
|
void*
|
||||||
jsp_mm_alloc (size_t size) /**< size of block to allocate */
|
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;
|
jsp_mm_header_t *tmem_header_p = (jsp_mm_header_t*) ptr_p;
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mem-allocator.h"
|
#include "ecma-helpers.h"
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
|
#include "jsp-mm.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
#include "syntax-errors.h"
|
#include "syntax-errors.h"
|
||||||
#include "ecma-helpers.h"
|
|
||||||
|
|
||||||
static token saved_token, prev_token, sent_token, empty_token;
|
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);
|
JERRY_ASSERT (source_str_p != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_DEFINE_LOCAL_ARRAY (str_buf_p,
|
ecma_char_t *str_buf_p = (ecma_char_t*) jsp_mm_alloc (source_str_size * sizeof (ecma_char_t));
|
||||||
source_str_size,
|
|
||||||
ecma_char_t);
|
|
||||||
|
|
||||||
const char *source_str_iter_p = source_str_p;
|
const char *source_str_iter_p = source_str_p;
|
||||||
ecma_char_t *str_buf_iter_p = str_buf_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);
|
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;
|
return ret;
|
||||||
} /* convert_string_to_token_transform_escape_seq */
|
} /* convert_string_to_token_transform_escape_seq */
|
||||||
@@ -860,13 +858,12 @@ parse_number (void)
|
|||||||
tok_length = (size_t) (buffer - token_start);;
|
tok_length = (size_t) (buffer - token_start);;
|
||||||
if (is_fp || is_exp)
|
if (is_fp || is_exp)
|
||||||
{
|
{
|
||||||
ecma_char_t *temp = (ecma_char_t*) mem_heap_alloc_block ((size_t) (tok_length + 1),
|
ecma_char_t *temp = (ecma_char_t*) jsp_mm_alloc ((size_t) (tok_length + 1) * sizeof (ecma_char_t));
|
||||||
MEM_HEAP_ALLOC_SHORT_TERM);
|
|
||||||
strncpy ((char *) temp, token_start, (size_t) (tok_length));
|
strncpy ((char *) temp, token_start, (size_t) (tok_length));
|
||||||
temp[tok_length] = '\0';
|
temp[tok_length] = '\0';
|
||||||
ecma_number_t res = ecma_zt_string_to_number (temp);
|
ecma_number_t res = ecma_zt_string_to_number (temp);
|
||||||
JERRY_ASSERT (!ecma_number_is_nan (res));
|
JERRY_ASSERT (!ecma_number_is_nan (res));
|
||||||
mem_heap_free_block (temp);
|
jsp_mm_free (temp);
|
||||||
known_token = convert_seen_num_to_token (res);
|
known_token = convert_seen_num_to_token (res);
|
||||||
token_start = NULL;
|
token_start = NULL;
|
||||||
return known_token;
|
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 */
|
} /* lexer_are_tokens_with_same_identifier */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize lexer to start parsing of a new source
|
* Intitialize lexer
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
lexer_init_source (const char *source, /**< script source */
|
lexer_init (const char *source, /**< script source */
|
||||||
size_t source_size) /**< script source size in bytes */
|
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;
|
saved_token = prev_token = sent_token = empty_token;
|
||||||
|
|
||||||
buffer_size = source_size;
|
buffer_size = source_size;
|
||||||
lexer_set_source (source);
|
lexer_set_source (source);
|
||||||
lexer_set_strict_mode (false);
|
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
|
#ifndef JERRY_NDEBUG
|
||||||
allow_dump_lines = show_opcodes;
|
allow_dump_lines = show_opcodes;
|
||||||
@@ -1497,8 +1488,3 @@ lexer_init (bool show_opcodes) /**< flag indicating if to dump opcodes */
|
|||||||
allow_dump_lines = false;
|
allow_dump_lines = false;
|
||||||
#endif /* JERRY_NDEBUG */
|
#endif /* JERRY_NDEBUG */
|
||||||
} /* lexer_init */
|
} /* lexer_init */
|
||||||
|
|
||||||
void
|
|
||||||
lexer_free (void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -169,9 +169,7 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
#define TOKEN_EMPTY_INITIALIZER {0, TOK_EMPTY, 0}
|
#define TOKEN_EMPTY_INITIALIZER {0, TOK_EMPTY, 0}
|
||||||
|
|
||||||
void lexer_init (bool);
|
void lexer_init (const char *, size_t, bool);
|
||||||
void lexer_init_source (const char *, size_t);
|
|
||||||
void lexer_free (void);
|
|
||||||
|
|
||||||
token lexer_next_token (void);
|
token lexer_next_token (void);
|
||||||
void lexer_save_token (token);
|
void lexer_save_token (token);
|
||||||
|
|||||||
@@ -13,22 +13,20 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include "ecma-helpers.h"
|
||||||
|
#include "hash-table.h"
|
||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
#include "jsp-label.h"
|
#include "jsp-label.h"
|
||||||
#include "parser.h"
|
#include "jsp-mm.h"
|
||||||
#include "opcodes.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-dumper.h"
|
||||||
|
#include "opcodes-native-call.h"
|
||||||
|
#include "parser.h"
|
||||||
|
#include "scopes-tree.h"
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
|
#include "stack.h"
|
||||||
|
#include "syntax-errors.h"
|
||||||
|
#include "vm.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag, indicating whether result of expression
|
* 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_function = in_function;
|
||||||
inside_eval = in_eval;
|
inside_eval = in_eval;
|
||||||
|
|
||||||
lexer_init (parser_show_opcodes);
|
#ifndef JERRY_NDEBUG
|
||||||
lexer_init_source (source_p, source_size);
|
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);
|
serializer_set_show_opcodes (parser_show_opcodes);
|
||||||
dumper_init ();
|
dumper_init ();
|
||||||
@@ -2907,41 +2913,67 @@ parser_parse_program (const char *source_p, /**< source code buffer */
|
|||||||
serializer_set_scope (STACK_TOP (scopes));
|
serializer_set_scope (STACK_TOP (scopes));
|
||||||
lexer_set_strict_mode (scopes_tree_strict_mode (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 ();
|
if (r == 0)
|
||||||
parse_source_element_list (true);
|
|
||||||
|
|
||||||
skip_newlines ();
|
|
||||||
JERRY_ASSERT (token_is (TOK_EOF));
|
|
||||||
|
|
||||||
if (in_function)
|
|
||||||
{
|
{
|
||||||
dump_ret ();
|
skip_newlines ();
|
||||||
}
|
parse_source_element_list (true);
|
||||||
else if (inside_eval)
|
|
||||||
{
|
skip_newlines ();
|
||||||
dump_retval (eval_ret_operand ());
|
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
|
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 ();
|
jsp_label_finalize ();
|
||||||
syntax_free ();
|
jsp_mm_finalize ();
|
||||||
lexer_free ();
|
|
||||||
|
|
||||||
*out_opcodes_p = serializer_merge_scopes_into_bytecode ();
|
return is_syntax_correct;
|
||||||
|
|
||||||
dumper_free ();
|
|
||||||
|
|
||||||
serializer_set_scope (NULL);
|
|
||||||
scopes_tree_free (STACK_TOP (scopes));
|
|
||||||
STACK_DROP (scopes, 1);
|
|
||||||
STACK_FREE (scopes);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} /* parser_parse_program */
|
} /* parser_parse_program */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,8 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scopes-tree.h"
|
|
||||||
#include "bytecode-data.h"
|
#include "bytecode-data.h"
|
||||||
|
#include "jsp-mm.h"
|
||||||
|
#include "scopes-tree.h"
|
||||||
|
|
||||||
#define OPCODE(op) (__op__idx_##op)
|
#define OPCODE(op) (__op__idx_##op)
|
||||||
#define HASH_SIZE 128
|
#define HASH_SIZE 128
|
||||||
@@ -114,8 +115,7 @@ start_new_block_if_necessary (void)
|
|||||||
hash_table_free (lit_id_to_uid);
|
hash_table_free (lit_id_to_uid);
|
||||||
lit_id_to_uid = null_hash;
|
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,
|
lit_id_to_uid = hash_table_init (sizeof (lit_cpointer_t), sizeof (idx_t), HASH_SIZE, lit_id_hash);
|
||||||
MEM_HEAP_ALLOC_SHORT_TERM);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,7 +652,7 @@ scopes_tree_strict_mode (scopes_tree tree)
|
|||||||
scopes_tree
|
scopes_tree
|
||||||
scopes_tree_init (scopes_tree parent)
|
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));
|
memset (tree, 0, sizeof (scopes_tree_int));
|
||||||
tree->t.parent = (tree_header *) parent;
|
tree->t.parent = (tree_header *) parent;
|
||||||
tree->t.children = null_list;
|
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->t.children);
|
||||||
}
|
}
|
||||||
linked_list_free (tree->opcodes);
|
linked_list_free (tree->opcodes);
|
||||||
mem_heap_free_block ((uint8_t *) tree);
|
jsp_mm_free (tree);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,15 @@
|
|||||||
#include "jrt-libc-includes.h"
|
#include "jrt-libc-includes.h"
|
||||||
#include "ecma-helpers.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
|
typedef struct
|
||||||
{
|
{
|
||||||
prop_type type;
|
prop_type type;
|
||||||
@@ -38,6 +47,26 @@ enum
|
|||||||
};
|
};
|
||||||
STATIC_STACK (U8, uint8_t)
|
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
|
static prop_literal
|
||||||
create_prop_literal (literal_t lit, prop_type type)
|
create_prop_literal (literal_t lit, prop_type type)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,11 +16,12 @@
|
|||||||
#ifndef SYNTAX_ERRORS_H
|
#ifndef SYNTAX_ERRORS_H
|
||||||
#define SYNTAX_ERRORS_H
|
#define SYNTAX_ERRORS_H
|
||||||
|
|
||||||
|
#include "jrt-libc-includes.h"
|
||||||
#include "opcodes-dumper.h"
|
#include "opcodes-dumper.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
#ifndef JERRY_NDEBUG
|
||||||
#define PARSE_ERROR(MESSAGE, LOCUS) do { \
|
#define PARSE_ERROR_PRINT_PLACE(TYPE, LOCUS) do { \
|
||||||
size_t line, column; \
|
size_t line, column; \
|
||||||
lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \
|
lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \
|
||||||
lexer_dump_line (line); \
|
lexer_dump_line (line); \
|
||||||
@@ -29,49 +30,30 @@
|
|||||||
putchar (' '); \
|
putchar (' '); \
|
||||||
} \
|
} \
|
||||||
printf ("^\n"); \
|
printf ("^\n"); \
|
||||||
printf ("ERROR: Ln %lu, Col %lu: %s\n", (unsigned long) (line + 1), (unsigned long) (column + 1), MESSAGE); \
|
printf ("%s: Ln %lu, Col %lu: ", TYPE, (unsigned long) (line + 1), (unsigned long) (column + 1)); \
|
||||||
jerry_fatal (ERR_PARSER); \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
#define PARSE_WARN(MESSAGE, LOCUS) do { \
|
#define PARSE_ERROR(MESSAGE, LOCUS) do { \
|
||||||
size_t line, column; \
|
PARSE_ERROR_PRINT_PLACE ("ERROR", LOCUS); \
|
||||||
lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \
|
printf ("%s\n", MESSAGE); \
|
||||||
printf ("WARNING: Ln %lu, Col %lu: %s\n", (unsigned long) (line + 1), (unsigned long) (column + 1), MESSAGE); \
|
syntax_raise_error (); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \
|
#define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \
|
||||||
size_t line, column; \
|
PARSE_ERROR_PRINT_PLACE ("ERROR", LOCUS); \
|
||||||
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)); \
|
|
||||||
printf (MESSAGE, __VA_ARGS__); \
|
printf (MESSAGE, __VA_ARGS__); \
|
||||||
printf ("\n"); \
|
printf ("\n"); \
|
||||||
jerry_fatal (ERR_PARSER); \
|
syntax_raise_error (); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define PARSE_SORRY(MESSAGE, LOCUS) do { \
|
#define PARSE_SORRY(MESSAGE, LOCUS) do { \
|
||||||
size_t line, column; \
|
PARSE_ERROR_PRINT_PLACE ("SORRY, Unimplemented", LOCUS); \
|
||||||
lexer_locus_to_line_and_column ((locus) (LOCUS), &line, &column); \
|
printf ("%s\n", MESSAGE); \
|
||||||
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); \
|
|
||||||
JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \
|
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 { \
|
||||||
jerry_fatal (ERR_PARSER); \
|
syntax_raise_error (); \
|
||||||
} while (0)
|
|
||||||
#define PARSE_WARN(MESSAGE, LOCUS) do { \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
#define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \
|
#define PARSE_ERROR_VARG(MESSAGE, LOCUS, ...) do { \
|
||||||
jerry_fatal (ERR_PARSER); \
|
syntax_raise_error (); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define PARSE_SORRY(MESSAGE, LOCUS) do { \
|
#define PARSE_SORRY(MESSAGE, LOCUS) do { \
|
||||||
JERRY_UNIMPLEMENTED ("Unimplemented parser feature."); \
|
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);
|
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 */
|
#endif /* SYNTAX_ERRORS_H */
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
#ifndef JERRY_LIBC_SETJMP_H
|
#ifndef JERRY_LIBC_SETJMP_H
|
||||||
#define JERRY_LIBC_SETJMP_H
|
#define JERRY_LIBC_SETJMP_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
# define EXTERN_C "C"
|
# define EXTERN_C "C"
|
||||||
#else /* !__cplusplus */
|
#else /* !__cplusplus */
|
||||||
|
|||||||
@@ -86,3 +86,14 @@ for (var i = 0; i < 100; i++)
|
|||||||
r = eval ('if (true) 3; else 5;');
|
r = eval ('if (true) 3; else 5;');
|
||||||
assert (r === 3);
|
assert (r === 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check SyntaxError handling
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eval ('var var;');
|
||||||
|
assert (false);
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
assert (e instanceof SyntaxError);
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
@@ -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.
|
||||||
@@ -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.
|
||||||
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
@@ -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.
|
||||||
+1
-1
@@ -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.
|
||||||
@@ -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.
|
||||||
@@ -79,3 +79,14 @@ catch (e)
|
|||||||
{
|
{
|
||||||
assert (e instanceof TypeError);
|
assert (e instanceof TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check SyntaxError handling
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new Function ('var var;');
|
||||||
|
assert (false);
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
assert (e instanceof SyntaxError);
|
||||||
|
}
|
||||||
|
|||||||
+20
-14
@@ -71,18 +71,19 @@ main (int __attr_unused___ argc,
|
|||||||
{
|
{
|
||||||
TEST_INIT ();
|
TEST_INIT ();
|
||||||
|
|
||||||
char program[] = "a=1;var a;";
|
|
||||||
bool is_ok;
|
|
||||||
|
|
||||||
const opcode_t *opcodes_p;
|
const opcode_t *opcodes_p;
|
||||||
bool is_syntax_correct;
|
bool is_syntax_correct;
|
||||||
|
|
||||||
mem_init ();
|
mem_init ();
|
||||||
|
|
||||||
|
// #1
|
||||||
|
char program1[] = "a=1;var a;";
|
||||||
|
|
||||||
serializer_init ();
|
serializer_init ();
|
||||||
parser_set_show_opcodes (true);
|
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[] =
|
opcode_t opcodes[] =
|
||||||
{
|
{
|
||||||
@@ -97,17 +98,22 @@ main (int __attr_unused___ argc,
|
|||||||
getop_exitval (0) // exit 0;
|
getop_exitval (0) // exit 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!opcodes_equal (opcodes_p, opcodes, 5))
|
JERRY_ASSERT (opcodes_equal (opcodes_p, opcodes, 5));
|
||||||
{
|
|
||||||
is_ok = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
is_ok = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
serializer_free ();
|
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);
|
mem_finalize (false);
|
||||||
|
|
||||||
return (is_ok ? 0 : 1);
|
return 0;
|
||||||
} /* main */
|
} /* main */
|
||||||
|
|||||||
Reference in New Issue
Block a user