Skip to content

Syntax error feedback support #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions jerry-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ project (JerryCore CXX C ASM)
${CMAKE_SOURCE_DIR}/jerry-core/ecma/builtin-objects
${CMAKE_SOURCE_DIR}/jerry-core/ecma/base
${CMAKE_SOURCE_DIR}/jerry-core/ecma/operations
${CMAKE_SOURCE_DIR}/jerry-core/parser/collections
${CMAKE_SOURCE_DIR}/jerry-core/parser/js
${CMAKE_SOURCE_DIR}/jerry-core/parser/js/collections
${CMAKE_SOURCE_DIR}/jerry-core/jrt)

# Third-party
Expand All @@ -110,17 +110,17 @@ project (JerryCore CXX C ASM)

# Sources
# Jerry core
file(GLOB SOURCE_CORE_API *.cpp)
file(GLOB SOURCE_CORE_LIT lit/*.cpp)
file(GLOB SOURCE_CORE_RCS rcs/*.cpp)
file(GLOB SOURCE_CORE_MEM mem/*.cpp)
file(GLOB SOURCE_CORE_VM vm/*.cpp)
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.cpp)
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.cpp)
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.cpp)
file(GLOB SOURCE_CORE_PARSER_COLLECTIONS parser/collections/*.cpp)
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.cpp)
file(GLOB SOURCE_CORE_JRT jrt/*.cpp)
file(GLOB SOURCE_CORE_API *.cpp)
file(GLOB SOURCE_CORE_LIT lit/*.cpp)
file(GLOB SOURCE_CORE_RCS rcs/*.cpp)
file(GLOB SOURCE_CORE_MEM mem/*.cpp)
file(GLOB SOURCE_CORE_VM vm/*.cpp)
file(GLOB SOURCE_CORE_ECMA_BUILTINS ecma/builtin-objects/*.cpp)
file(GLOB SOURCE_CORE_ECMA_BASE ecma/base/*.cpp)
file(GLOB SOURCE_CORE_ECMA_OPERATIONS ecma/operations/*.cpp)
file(GLOB SOURCE_CORE_PARSER_JS parser/js/*.cpp)
file(GLOB SOURCE_CORE_PARSER_JS_COLLECTIONS parser/js/collections/*.cpp)
file(GLOB SOURCE_CORE_JRT jrt/*.cpp)

set(SOURCE_CORE
jerry.cpp
Expand All @@ -132,8 +132,8 @@ project (JerryCore CXX C ASM)
${SOURCE_CORE_ECMA_BUILTINS}
${SOURCE_CORE_ECMA_BASE}
${SOURCE_CORE_ECMA_OPERATIONS}
${SOURCE_CORE_PARSER_COLLECTIONS}
${SOURCE_CORE_PARSER_JS}
${SOURCE_CORE_PARSER_JS_COLLECTIONS}
${SOURCE_CORE_JRT})

# Per-option configuration
Expand Down
82 changes: 43 additions & 39 deletions jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "ecma-alloc.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "ecma-gc.h"
#include "ecma-function-object.h"
#include "ecma-lex-env.h"
Expand Down Expand Up @@ -130,52 +131,55 @@ ecma_builtin_function_dispatch_construct (const ecma_value_t *arguments_list_p,
zt_string_buffer_pos += sz;
}

parser_init ();
const opcode_t* opcodes_p;
bool is_syntax_correct;

/*
* FIXME:
* Handle syntax errors
*/
parser_parse_new_function ((const char **) zt_string_params_p, params_count);
const opcode_t* opcodes_p = (const opcode_t*) serializer_get_bytecode ();
serializer_print_opcodes ();
parser_free ();
is_syntax_correct = parser_parse_new_function ((const char **) zt_string_params_p,
params_count,
&opcodes_p);

bool is_strict = false;
bool do_instantiate_arguments_object = true;

opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (opcodes_p,
0);

if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
if (!is_syntax_correct)
{
is_strict = true;
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_SYNTAX));
}

if ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER)
&& (scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER))
else
{
/* the code doesn't use 'arguments' identifier
* and doesn't perform direct call to eval,
* so Arguments object can't be referenced */
do_instantiate_arguments_object = false;
bool is_strict = false;
bool do_instantiate_arguments_object = true;

opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (opcodes_p,
0);

if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
is_strict = true;
}

if ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER)
&& (scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER))
{
/* the code doesn't use 'arguments' identifier
* and doesn't perform direct call to eval,
* so Arguments object can't be referenced */
do_instantiate_arguments_object = false;
}

/* 11. */
ecma_object_t *glob_lex_env_p = ecma_get_global_environment ();

ecma_object_t *func_obj_p = ecma_op_create_function_object (params_count > 1u ? string_params_p : NULL,
(ecma_length_t) (params_count - 1u),
glob_lex_env_p,
is_strict,
do_instantiate_arguments_object,
opcodes_p,
1);

ecma_deref_object (glob_lex_env_p);

ret_value = ecma_make_normal_completion_value (ecma_make_object_value (func_obj_p));
}

/* 11. */
ecma_object_t *glob_lex_env_p = ecma_get_global_environment ();

ecma_object_t *func_obj_p = ecma_op_create_function_object (params_count > 1u ? string_params_p : NULL,
(ecma_length_t) (params_count - 1u),
glob_lex_env_p,
is_strict,
do_instantiate_arguments_object,
opcodes_p,
1);

ecma_deref_object (glob_lex_env_p);

ret_value = ecma_make_normal_completion_value (ecma_make_object_value (func_obj_p));

MEM_FINALIZE_LOCAL_ARRAY (zt_string_buffer_p);
MEM_FINALIZE_LOCAL_ARRAY (zt_string_params_p);
}
Expand Down
31 changes: 16 additions & 15 deletions jerry-core/ecma/operations/ecma-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,30 @@ ecma_op_eval_chars_buffer (const ecma_char_t *code_p, /**< code characters buffe

ecma_completion_value_t completion;

parser_init ();
bool is_syntax_correct = parser_parse_eval ((const char *) code_p, code_buffer_size);
const opcode_t* opcodes_p = (const opcode_t*) serializer_get_bytecode ();
serializer_print_opcodes ();
parser_free ();

opcode_counter_t first_opcode_index = 0u;
bool is_strict_prologue = false;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (opcodes_p,
first_opcode_index++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
is_strict_prologue = true;
}
const opcode_t *opcodes_p;
bool is_syntax_correct;

bool is_strict = (is_strict_prologue || (is_direct && is_called_from_strict_mode_code));
is_syntax_correct = parser_parse_eval ((const char *) code_p,
code_buffer_size,
&opcodes_p);

if (!is_syntax_correct)
{
completion = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_SYNTAX));
}
else
{
opcode_counter_t first_opcode_index = 0u;
bool is_strict_prologue = false;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (opcodes_p,
first_opcode_index++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
is_strict_prologue = true;
}

bool is_strict = (is_strict_prologue || (is_direct && is_called_from_strict_mode_code));

ecma_value_t this_binding;
ecma_object_t *lex_env_p;

Expand Down
20 changes: 14 additions & 6 deletions jerry-core/jerry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,9 @@ jerry_reg_err_callback (jerry_error_callback_t callback) /**< pointer to callbac

/**
* Parse script for specified context
*
* @return true - if script was parsed successfully,
* false - otherwise (SyntaxError was raised).
*/
bool
jerry_parse (const char* source_p, /**< script source */
Expand All @@ -1254,13 +1257,18 @@ jerry_parse (const char* source_p, /**< script source */
bool is_show_opcodes = ((jerry_flags & JERRY_FLAG_SHOW_OPCODES) != 0);

parser_set_show_opcodes (is_show_opcodes);
parser_init ();
parser_parse_script (source_p, source_size);

const opcode_t* opcodes = (const opcode_t*) serializer_get_bytecode ();
const opcode_t *opcodes_p;
bool is_syntax_correct;

is_syntax_correct = parser_parse_script (source_p,
source_size,
&opcodes_p);

serializer_print_opcodes ();
parser_free ();
if (!is_syntax_correct)
{
return false;
}

#ifdef MEM_STATS
if (jerry_flags & JERRY_FLAG_MEM_STATS_SEPARATE)
Expand All @@ -1272,7 +1280,7 @@ jerry_parse (const char* source_p, /**< script source */

bool is_show_mem_stats_per_opcode = ((jerry_flags & JERRY_FLAG_MEM_STATS_PER_OPCODE) != 0);

vm_init (opcodes, is_show_mem_stats_per_opcode);
vm_init (opcodes_p, is_show_mem_stats_per_opcode);

return true;
} /* jerry_parse */
Expand Down
1 change: 0 additions & 1 deletion jerry-core/jerry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions jerry-core/jrt/jrt-fatals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions jerry-core/jrt/jrt-libc-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define JRT_LIBC_INCLUDES_H

#include <ctype.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
64 changes: 0 additions & 64 deletions jerry-core/parser/collections/lit-id-hash-table.cpp

This file was deleted.

18 changes: 11 additions & 7 deletions jerry-core/parser/js/bytecode-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "opcodes.h"
#include "lit-id-hash-table.h"
#include "mem-allocator.h"

/*
* All literals are kept in the 'literals' array.
Expand All @@ -35,11 +36,13 @@
#define BLOCK_SIZE 64

/**
* Pointer to lit_id_hash_table precedes every independent bytecode region
* Header of byte-code memory region, containing byte-code array and literal identifiers hash table
*/
typedef struct __attribute__ ((aligned (MEM_ALIGNMENT)))
{
lit_id_hash_table *lit_id_hash;
mem_cpointer_t lit_id_hash_cp; /**< pointer to literal identifiers hash table
* See also: lit_id_hash_table_init */
mem_cpointer_t next_opcodes_cp; /**< pointer to next byte-code memory region */
} opcodes_header_t;

typedef struct
Expand All @@ -50,14 +53,15 @@ typedef struct
} bytecode_data_t;

/**
* Macros to get a hash table corresponding to a bytecode region
* Macros to get a pointer to bytecode header by pointer to opcodes start
*/
#define GET_HASH_TABLE_FOR_BYTECODE(opcodes) (((opcodes_header_t *) (((uint8_t *) (opcodes)) - \
sizeof (opcodes_header_t)))->lit_id_hash)
#define GET_BYTECODE_HEADER(opcodes) ((opcodes_header_t *) (((uint8_t *) (opcodes)) - sizeof (opcodes_header_t)))

/**
* Macros to get a pointer to bytecode header by pointer to opcodes start
* Macros to get a hash table corresponding to a bytecode region
*/
#define GET_BYTECODE_HEADER(opcodes) ((opcodes_header_t *) (((uint8_t *) (opcodes)) - sizeof (opcodes_header_t)))
#define GET_HASH_TABLE_FOR_BYTECODE(opcodes) (MEM_CP_GET_POINTER (lit_id_hash_table, \
GET_BYTECODE_HEADER (opcodes)->lit_id_hash_cp))


#endif // BYTECODE_DATA_H
Loading