FunctionExpression name binding should be immutable

JerryScript-DCO-1.0-Signed-off-by: Youngil Choi duddlf.choi@samsung.com
This commit is contained in:
Youngil Choi
2016-08-29 18:02:34 +09:00
parent 260b967853
commit 2c78ee7f54
2 changed files with 53 additions and 9 deletions
+21 -9
View File
@@ -530,6 +530,8 @@ vm_init_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
uint16_t register_end;
jmem_cpointer_t *literal_start_p = frame_ctx_p->literal_start_p;
bool is_strict = ((frame_ctx_p->bytecode_header_p->status_flags & CBC_CODE_FLAGS_STRICT_MODE) != 0);
jmem_cpointer_t self_reference;
ECMA_SET_NON_NULL_POINTER (self_reference, bytecode_header_p);
/* Prepare. */
if (!(bytecode_header_p->status_flags & CBC_CODE_FLAGS_FULL_LITERAL_ENCODING))
@@ -602,12 +604,8 @@ vm_init_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
ecma_string_t *name_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_string_t,
literal_start_p[literal_index]);
vm_var_decl (frame_ctx_p, name_p);
READ_LITERAL_INDEX (value_index);
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (frame_ctx_p->lex_env_p, name_p);
if (value_index < register_end)
{
lit_value = frame_ctx_p->registers_p[value_index];
@@ -618,11 +616,25 @@ vm_init_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
literal_start_p[value_index]);
}
/* TODO: check the return value */
ecma_op_put_value_lex_env_base (ref_base_lex_env_p,
name_p,
is_strict,
lit_value);
if (self_reference == literal_start_p[value_index])
{
ecma_op_create_immutable_binding (frame_ctx_p->lex_env_p, name_p);
ecma_op_initialize_immutable_binding (frame_ctx_p->lex_env_p,
name_p,
lit_value);
}
else
{
vm_var_decl (frame_ctx_p, name_p);
ecma_object_t *ref_base_lex_env_p = ecma_op_resolve_reference_base (frame_ctx_p->lex_env_p, name_p);
/* TODO: check the return value */
ecma_op_put_value_lex_env_base (ref_base_lex_env_p,
name_p,
is_strict,
lit_value);
}
if (value_index >= register_end)
{
+32
View File
@@ -0,0 +1,32 @@
// Copyright 2016 Samsung Electronics Co., Ltd.
// Copyright 2016 University of Szeged.
//
// 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.
(function nonStrictFuncExpr() {
assert(typeof nonStrictFuncExpr == "function");
nonStrictFuncExpr = 123;
assert(typeof nonStrictFuncExpr == "function");
})();
(function strictFuncExpr() {
"use strict";
assert(typeof strictFuncExpr == "function");
try {
strictFuncExpr = 123;
assert(false);
} catch (e) {
assert(e instanceof TypeError);
}
assert(typeof strictFuncExpr == "function");
})();