diff --git a/.gitignore b/.gitignore index fc3e1faa9..9f6957077 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ nbproject *.swp *~ js.files +js.fail.files jerry.error jerry.passed core diff --git a/Makefile.mk b/Makefile.mk index 6decebe58..383c8ae09 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -88,6 +88,9 @@ else OPTION_TODO := disable endif +# Parser error code +PARSER_ERROR_CODE := 255 + ifeq ($(fixme),1) OPTION_FIXME := enable else @@ -514,6 +517,21 @@ $(CHECK_TARGETS): fi; \ \ exit $$status_code; \ + fi; \ + if [ -d $(TESTS_DIR)/fail/ ]; \ + then \ + VALGRIND=$(VALGRIND_CMD) TIMEOUT=$(VALGRIND_TIMEOUT) ./tools/jerry_test_fail.sh $(TARGET_DIR)/$(ENGINE_NAME) $(TARGET_DIR)/check $(PARSER_ERROR_CODE) $(TESTS_DIR) $(TESTS_OPTS) $$ADD_OPTS; \ + status_code=$$?; \ + if [ $$status_code -ne 0 ]; \ + then \ + echo $(TARGET) failed; \ + if [ "$(OUTPUT_TO_LOG)" = "enable" ]; \ + then \ + echo See log in $(TARGET_DIR)/check directory for details.; \ + fi; \ + \ + exit $$status_code; \ + fi; \ fi; diff --git a/src/libjsparser/parser.c b/src/libjsparser/parser.c index aeb665365..c2b44b379 100644 --- a/src/libjsparser/parser.c +++ b/src/libjsparser/parser.c @@ -878,22 +878,47 @@ cleanup: STACK_CHECK_USAGE (IDX); } +static void +emit_error_on_eval_and_arguments (idx_t id) +{ + if (id < lexer_get_strings_count ()) + { + if (lp_string_equal_zt (lexer_get_string_by_id (id), + ecma_get_magic_string_zt (ECMA_MAGIC_STRING_ARGUMENTS)) + || lp_string_equal_zt (lexer_get_string_by_id (id), + ecma_get_magic_string_zt (ECMA_MAGIC_STRING_EVAL))) + { + EMIT_ERROR ("'eval' and 'arguments' are not allowed here in strict mode"); + } + } +} + static void check_for_eval_and_arguments_in_strict_mode (idx_t id) { if (parser_strict_mode ()) { - if (id < lexer_get_strings_count ()) + emit_error_on_eval_and_arguments (id); + } +} + +static bool +find_assignment_to (opcode_counter_t from, idx_t tmp_id, opcode_t *res) +{ + JERRY_ASSERT (res != NULL); + JERRY_ASSERT (tmp_id >= lexer_get_reserved_ids_count ()); + for (opcode_counter_t oc = from; oc > 0; oc = (opcode_counter_t) (oc - 1)) + { + *res = deserialize_opcode (oc); + if (OPCODE_IS ((*res), assignment)) { - if (lp_string_equal_zt (lexer_get_string_by_id (id), - ecma_get_magic_string_zt (ECMA_MAGIC_STRING_ARGUMENTS)) - || lp_string_equal_zt (lexer_get_string_by_id (id), - ecma_get_magic_string_zt (ECMA_MAGIC_STRING_EVAL))) + if (res->data.assignment.var_left == tmp_id) { - EMIT_ERROR ("'eval' and 'arguments' are not allowed here in strict mode"); + return true; } } } + return false; } static void @@ -908,9 +933,9 @@ check_for_duplication_of_param (opcode_counter_t from, uint8_t metas_num) STACK_DECLARE_USAGE (U8); STACK_DECLARE_USAGE (ops); + STACK_PUSH (U8, 0); // seen metas STACK_PUSH (U8, STACK_SIZE (IDX)); - uint8_t seen_metas = 0; for (opcode_counter_t oc = from; oc < OPCODE_COUNTER (); oc = (opcode_counter_t) (oc + 1)) { STACK_PUSH (ops, deserialize_opcode (oc)); @@ -919,41 +944,58 @@ check_for_duplication_of_param (opcode_counter_t from, uint8_t metas_num) switch (STACK_TOP (ops).data.meta.type) { case OPCODE_META_TYPE_VARG: - case OPCODE_META_TYPE_VARG_PROP_DATA: { for (uint8_t i = STACK_TOP (U8); i < STACK_SIZE (IDX); i = (uint8_t) (i + 1)) { - if (i == STACK_TOP (ops).data.meta.data_1) + if (STACK_ELEMENT (IDX, i) == STACK_TOP (ops).data.meta.data_1) { - JERRY_ASSERT (i < lexer_get_strings_count ()); - EMIT_ERROR_VARG ("Duplication of identifier '%s' as parameter is not allowed in strict mode.", - lexer_get_string_by_id (i)); + JERRY_ASSERT (STACK_ELEMENT (IDX, i) < lexer_get_strings_count ()); + EMIT_ERROR ("Duplication of identifier as parameter is not allowed in strict mode."); } } - /* FALLTHRU. */ + STACK_PUSH (IDX, STACK_TOP (ops).data.meta.data_1); + STACK_INCR_HEAD (U8, 2); + break; + } + case OPCODE_META_TYPE_VARG_PROP_DATA: + { + opcode_t res; + if (find_assignment_to (oc, STACK_TOP (ops).data.meta.data_1, &res)) + { + for (uint8_t i = STACK_TOP (U8); i < STACK_SIZE (IDX); i = (uint8_t) (i + 1)) + { + if (STACK_ELEMENT (IDX, i) == res.data.assignment.value_right) + { + JERRY_ASSERT (STACK_ELEMENT (IDX, i) < lexer_get_strings_count ()); + EMIT_ERROR ("Duplication of identifier as parameter is not allowed in strict mode."); + } + } + STACK_PUSH (IDX, res.data.assignment.value_right); + } + /* FALLTHRU. */ } case OPCODE_META_TYPE_THIS_ARG: case OPCODE_META_TYPE_VARG_PROP_GETTER: case OPCODE_META_TYPE_VARG_PROP_SETTER: { - seen_metas = (uint8_t) (seen_metas + 1); + STACK_INCR_HEAD (U8, 2); break; } default: { - JERRY_UNREACHABLE (); + break; } } } STACK_DROP (ops, 1); - if (seen_metas == metas_num) + if (STACK_HEAD (U8, 2) == metas_num) { break; } } STACK_DROP (IDX, STACK_SIZE (IDX) - STACK_TOP (U8)); - STACK_DROP (U8, 1); + STACK_DROP (U8, 2); STACK_CHECK_USAGE (ops); STACK_CHECK_USAGE (U8); @@ -1181,6 +1223,7 @@ next: } case AL_OBJ_DECL: { + check_for_duplication_of_param (STACK_TOP (U16), STACK_TOP (U8)); REWRITE_OPCODE_2 (STACK_TOP (U16), obj_decl, ID(1), STACK_TOP (U8)); break; } @@ -1231,10 +1274,6 @@ parse_function_declaration (void) STACK_DECLARE_USAGE (scopes) STACK_DECLARE_USAGE (U8) - SET_OPCODE_COUNTER (0); - STACK_PUSH (scopes, scopes_tree_init (STACK_TOP (scopes))); - serializer_set_scope (STACK_TOP (scopes)); - assert_keyword (KW_FUNCTION); token_after_newlines_must_be (TOK_NAME); @@ -1242,7 +1281,12 @@ parse_function_declaration (void) STACK_PUSH (IDX, token_data ()); skip_newlines (); + SET_OPCODE_COUNTER (0); + STACK_PUSH (scopes, scopes_tree_init (STACK_TOP (scopes))); + serializer_set_scope (STACK_TOP (scopes)); + scopes_tree_set_strict_mode (STACK_TOP (scopes), scopes_tree_strict_mode (STACK_HEAD (scopes, 2))); STACK_PUSH (U8, parse_argument_list (AL_FUNC_DECL, ID(1))); + scopes_tree_set_strict_mode (STACK_TOP (scopes), false); STACK_PUSH (U16, OPCODE_COUNTER ()); DUMP_OPCODE_3 (meta, OPCODE_META_TYPE_UNDEFINED, INVALID_VALUE, INVALID_VALUE); @@ -3778,16 +3822,16 @@ preparse_scope (bool is_global) STACK_PUSH (U8, is_global ? TOK_EOF : TOK_CLOSE_BRACE); STACK_PUSH (U16, OPCODE_COUNTER ()); - DUMP_VOID_OPCODE (nop); /* use strict. */ + + if (token_is (TOK_STRING) && lp_string_equal_s (lexer_get_string_by_id (token_data ()), "use strict")) + { + scopes_tree_set_strict_mode (STACK_TOP (scopes), true); + DUMP_OPCODE_3 (meta, OPCODE_META_TYPE_STRICT_CODE, INVALID_VALUE, INVALID_VALUE); + } while (!token_is (STACK_TOP (U8))) { - if (token_is (TOK_STRING) && lp_string_equal_s (lexer_get_string_by_id (token_data ()), "use strict")) - { - scopes_tree_set_strict_mode (STACK_TOP (scopes), true); - REWRITE_OPCODE_3 (STACK_TOP (U16), meta, OPCODE_META_TYPE_STRICT_CODE, INVALID_VALUE, INVALID_VALUE); - } - else if (is_keyword (KW_VAR)) + if (is_keyword (KW_VAR)) { preparse_var_decls (); } diff --git a/tests/jerry/fail/255/arguments_assignment_strict.js b/tests/jerry/fail/255/arguments_assignment_strict.js new file mode 100644 index 000000000..b581932d8 --- /dev/null +++ b/tests/jerry/fail/255/arguments_assignment_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +arguments = 1; diff --git a/tests/jerry/fail/255/arguments_catch_strict.js b/tests/jerry/fail/255/arguments_catch_strict.js new file mode 100644 index 000000000..80b3fa1d4 --- /dev/null +++ b/tests/jerry/fail/255/arguments_catch_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +try{}catch(arguments){}; diff --git a/tests/jerry/fail/255/arguments_in_prop_set_param_list_strict.js b/tests/jerry/fail/255/arguments_in_prop_set_param_list_strict.js new file mode 100644 index 000000000..ea4383bb4 --- /dev/null +++ b/tests/jerry/fail/255/arguments_in_prop_set_param_list_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var a = { set a(arguments) {} }; diff --git a/tests/jerry/fail/255/arguments_in_var_decl_strict.js b/tests/jerry/fail/255/arguments_in_var_decl_strict.js new file mode 100644 index 000000000..7bd81940b --- /dev/null +++ b/tests/jerry/fail/255/arguments_in_var_decl_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var arguments; diff --git a/tests/jerry/fail/255/arguments_param_strict.js b/tests/jerry/fail/255/arguments_param_strict.js new file mode 100644 index 000000000..6aecb72d0 --- /dev/null +++ b/tests/jerry/fail/255/arguments_param_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +function f(arguments) {} diff --git a/tests/jerry/fail/255/arguments_postfix_strict.js b/tests/jerry/fail/255/arguments_postfix_strict.js new file mode 100644 index 000000000..bc319d524 --- /dev/null +++ b/tests/jerry/fail/255/arguments_postfix_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +arguments++; diff --git a/tests/jerry/fail/255/arguments_prefix_strict.js b/tests/jerry/fail/255/arguments_prefix_strict.js new file mode 100644 index 000000000..217fa508e --- /dev/null +++ b/tests/jerry/fail/255/arguments_prefix_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +++arguments; diff --git a/tests/jerry/fail/255/delete_strict.js b/tests/jerry/fail/255/delete_strict.js new file mode 100644 index 000000000..fa82d732a --- /dev/null +++ b/tests/jerry/fail/255/delete_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +delete a; diff --git a/tests/jerry/fail/255/eval_assignment_strict.js b/tests/jerry/fail/255/eval_assignment_strict.js new file mode 100644 index 000000000..aa28ff6d4 --- /dev/null +++ b/tests/jerry/fail/255/eval_assignment_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +eval = 1; diff --git a/tests/jerry/fail/255/eval_catch_strict.js b/tests/jerry/fail/255/eval_catch_strict.js new file mode 100644 index 000000000..c48f0a8f6 --- /dev/null +++ b/tests/jerry/fail/255/eval_catch_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +try{}catch(eval){}; diff --git a/tests/jerry/fail/255/eval_in_prop_set_param_list_strict.js b/tests/jerry/fail/255/eval_in_prop_set_param_list_strict.js new file mode 100644 index 000000000..da21ecd8f --- /dev/null +++ b/tests/jerry/fail/255/eval_in_prop_set_param_list_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var a = { set a(eval) {} }; diff --git a/tests/jerry/fail/255/eval_in_var_decl_strict.js b/tests/jerry/fail/255/eval_in_var_decl_strict.js new file mode 100644 index 000000000..753197c5a --- /dev/null +++ b/tests/jerry/fail/255/eval_in_var_decl_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var eval; diff --git a/tests/jerry/fail/255/eval_param_strict.js b/tests/jerry/fail/255/eval_param_strict.js new file mode 100644 index 000000000..689f4f58d --- /dev/null +++ b/tests/jerry/fail/255/eval_param_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +function f(eval) {} diff --git a/tests/jerry/fail/255/eval_postfix_strict.js b/tests/jerry/fail/255/eval_postfix_strict.js new file mode 100644 index 000000000..e908b5f71 --- /dev/null +++ b/tests/jerry/fail/255/eval_postfix_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +eval++; diff --git a/tests/jerry/fail/255/eval_prefix_strict.js b/tests/jerry/fail/255/eval_prefix_strict.js new file mode 100644 index 000000000..55a0202e1 --- /dev/null +++ b/tests/jerry/fail/255/eval_prefix_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +++eval; diff --git a/tests/jerry/fail/255/let_strict.js b/tests/jerry/fail/255/let_strict.js new file mode 100644 index 000000000..e39810412 --- /dev/null +++ b/tests/jerry/fail/255/let_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var let = 1; diff --git a/tests/jerry/fail/255/object_several_prop_names_strict.js b/tests/jerry/fail/255/object_several_prop_names_strict.js new file mode 100644 index 000000000..1426f3ef6 --- /dev/null +++ b/tests/jerry/fail/255/object_several_prop_names_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var a = {a:1, a:2}; diff --git a/tests/jerry/fail/255/octal_strict.js b/tests/jerry/fail/255/octal_strict.js new file mode 100644 index 000000000..7e51a8129 --- /dev/null +++ b/tests/jerry/fail/255/octal_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +var a = 07; diff --git a/tests/jerry/fail/255/param_duplication_strict.js b/tests/jerry/fail/255/param_duplication_strict.js new file mode 100644 index 000000000..ce645650d --- /dev/null +++ b/tests/jerry/fail/255/param_duplication_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +function f(a, a) {} diff --git a/tests/jerry/fail/255/with_strict.js b/tests/jerry/fail/255/with_strict.js new file mode 100644 index 000000000..34aa856d2 --- /dev/null +++ b/tests/jerry/fail/255/with_strict.js @@ -0,0 +1,17 @@ +// Copyright 2014 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. + +"use strict" + +with (Array) {} diff --git a/tests/unit/test_preparser.c b/tests/unit/test_preparser.c index c8f1a4d7c..658d27b8c 100644 --- a/tests/unit/test_preparser.c +++ b/tests/unit/test_preparser.c @@ -39,12 +39,11 @@ main( int __unused argc, if (!opcodes_equal(deserialize_bytecode (), (opcode_t[]) { [0] = getop_reg_var_decl (1, 2), // var tmp1 .. tmp2; - [1] = getop_nop (), // ; - [2] = getop_var_decl (0), // var a; - [3] = getop_assignment (1, 1, 1), // tmp1 = 1: SMALLINT; - [4] = getop_assignment (0, 4, 1), // a = tmp1: TYPEOF(tmp1); - [5] = getop_exitval (0) // exit 0; - }, 6)) + [1] = getop_var_decl (0), // var a; + [2] = getop_assignment (1, 1, 1), // tmp1 = 1: SMALLINT; + [3] = getop_assignment (0, 4, 1), // a = tmp1: TYPEOF(tmp1); + [4] = getop_exitval (0) // exit 0; + }, 5)) { is_ok = false; } diff --git a/tools/jerry_test_fail.sh b/tools/jerry_test_fail.sh new file mode 100755 index 000000000..410c25fef --- /dev/null +++ b/tools/jerry_test_fail.sh @@ -0,0 +1,138 @@ +# Copyright 2014 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. + +#!/bin/bash + +TIMEOUT=${TIMEOUT:=5} + +START_DIR=`pwd` + +ENGINE=$START_DIR/$1 +shift + +OUT_DIR=$1 +shift + +ERROR_CODE=$1 +shift + +TESTS=$START_DIR/$1/fail/$ERROR_CODE +shift + +ECHO_PROGRESS=1 +JERRY_ARGS= +while (( "$#" )) +do + if [ "$1" = "--parse-only" ] + then + JERRY_ARGS="$JERRY_ARGS $1" + fi + if [ "$1" = "--output-to-log" ] + then + exec 1>$OUT_DIR/jerry_test.log + ECHO_PROGRESS=0 + fi + shift +done + +if [ ! -x $ENGINE ] +then + echo \"$ENGINE\" is not an executable file +fi + +if [ ! -d $OUT_DIR ] +then + mkdir -p $OUT_DIR +fi +cd $OUT_DIR + +JS_FILES=js.fail.files +JERRY_ERROR=jerry.error +JERRY_OK=jerry.passed + +rm -f $JS_FILES $JERRY_ERROR + +if [ -d $TESTS ]; +then + find $TESTS -name [^N]*.js -print | sort > $JS_FILES +else + if [ -f $TESTS ]; + then + cp $TESTS $JS_FILES + else + exit 1 + fi; +fi; +total=$(cat $JS_FILES | wc -l) + +tested=0 +failed=0 +passed=0 + +JERRY_TEMP=jerry.tmp + +exec 2>/dev/null + +echo " Passed / Failed / Tested / Total / Percent" + +for test in `cat $JS_FILES` +do + percent=$(echo $tested*100/$total | bc) + + ( ulimit -t $TIMEOUT; $VALGRIND ${ENGINE} ${test} ${JERRY_ARGS} >&$JERRY_TEMP; exit $? ); + status_code=$? + + if [ $ECHO_PROGRESS -eq 1 ] + then + printf "\r\e[2K[ %6d / %6d / %6d / %5d / %3d%% ]" ${passed} ${failed} ${tested} ${total} ${percent} + fi + + if [ $status_code -ne $ERROR_CODE ] + then + echo "$status_code: ${test}" >> $JERRY_ERROR + echo "============================================" >> $JERRY_ERROR + cat $JERRY_TEMP >> $JERRY_ERROR + echo "============================================" >> $JERRY_ERROR + echo >> $JERRY_ERROR + echo >> $JERRY_ERROR + + failed=$((failed+1)) + else + echo "${test}" >> $JERRY_OK + passed=$((passed+1)) + fi + + tested=$((tested+1)) +done + +rm $JERRY_TEMP + +printf "\r\e[2K[ %6d / %6d / %6d / %5d / %3d%% ]\n" ${passed} ${failed} ${tested} ${total} ${percent} + +ratio=$(echo $passed*100/$total | bc) + +echo ========================== +echo "Number of tests passed: ${passed}" +echo "Number of tests failed: ${failed}" +echo -------------------------- +echo "Total number of tests: ${total}" +echo "Passed: ${ratio}%" + +if [ ${failed} -ne 0 ] +then + echo "See $JERRY_ERROR for details about failures" + exit 1; +fi + +exit 0