Allow redefining global variables as imports (#5023)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -13,14 +13,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lit-magic-strings.h"
|
|
||||||
#include "lit-strings.h"
|
|
||||||
|
|
||||||
#include "jerryscript-core.h"
|
#include "jerryscript-core.h"
|
||||||
#include "jerryscript-port.h"
|
#include "jerryscript-port.h"
|
||||||
|
|
||||||
#include "ecma-errors.h"
|
#include "ecma-errors.h"
|
||||||
|
|
||||||
|
#include "lit-magic-strings.h"
|
||||||
|
#include "lit-strings.h"
|
||||||
|
|
||||||
#if JERRY_MODULE_SYSTEM
|
#if JERRY_MODULE_SYSTEM
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -932,38 +932,17 @@ ecma_module_connect_imports (ecma_module_t *module_p)
|
|||||||
{
|
{
|
||||||
ecma_module_names_t *import_names_p = import_node_p->module_names_p;
|
ecma_module_names_t *import_names_p = import_node_p->module_names_p;
|
||||||
|
|
||||||
|
JERRY_ASSERT (local_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK);
|
||||||
|
|
||||||
while (import_names_p != NULL)
|
while (import_names_p != NULL)
|
||||||
{
|
{
|
||||||
ecma_object_t *lex_env_p = local_env_p;
|
ecma_property_t *binding_p = ecma_find_named_property (local_env_p, import_names_p->local_name_p);
|
||||||
ecma_property_t *binding_p = NULL;
|
|
||||||
|
|
||||||
if (lex_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK)
|
|
||||||
{
|
|
||||||
binding_p = ecma_find_named_property (lex_env_p, import_names_p->local_name_p);
|
|
||||||
|
|
||||||
JERRY_ASSERT (lex_env_p->u2.outer_reference_cp != JMEM_CP_NULL);
|
|
||||||
lex_env_p = ECMA_GET_NON_NULL_POINTER (ecma_object_t, lex_env_p->u2.outer_reference_cp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (binding_p != NULL)
|
if (binding_p != NULL)
|
||||||
{
|
{
|
||||||
return ecma_raise_syntax_error (ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE);
|
return ecma_raise_syntax_error (ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ecma_value_t status = ecma_op_has_binding (lex_env_p, import_names_p->local_name_p);
|
|
||||||
|
|
||||||
#if JERRY_BUILTIN_PROXY
|
|
||||||
if (ECMA_IS_VALUE_ERROR (status))
|
|
||||||
{
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
#endif /* JERRY_BUILTIN_PROXY */
|
|
||||||
|
|
||||||
if (ecma_is_value_true (status))
|
|
||||||
{
|
|
||||||
return ecma_raise_syntax_error (ECMA_ERR_IMPORTED_BINDING_SHADOWS_LOCAL_VARIABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
import_names_p = import_names_p->next_p;
|
import_names_p = import_names_p->next_p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright JS Foundation and other contributors, http://js.foundation
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
import JSON, { counter as Object } from 'module-export-default-1.mjs'
|
||||||
|
|
||||||
|
// Overwriting globals.
|
||||||
|
assert(typeof JSON === "function")
|
||||||
|
assert(Object === 1.1)
|
||||||
|
|
||||||
|
// Globals are still available.
|
||||||
|
assert(typeof globalThis.JSON === "object")
|
||||||
|
assert(typeof globalThis.Object === "function")
|
||||||
@@ -43,6 +43,7 @@ tests/jerry/module-import-04.mjs
|
|||||||
tests/jerry/module-import-05.mjs
|
tests/jerry/module-import-05.mjs
|
||||||
tests/jerry/module-import-06.mjs
|
tests/jerry/module-import-06.mjs
|
||||||
tests/jerry/module-import-07.mjs
|
tests/jerry/module-import-07.mjs
|
||||||
|
tests/jerry/module-import-global.mjs
|
||||||
tests/jerry/module-namespace-01.mjs
|
tests/jerry/module-namespace-01.mjs
|
||||||
tests/jerry/module-namespace-02.mjs
|
tests/jerry/module-namespace-02.mjs
|
||||||
tests/jerry/module-namespace-03.mjs
|
tests/jerry/module-namespace-03.mjs
|
||||||
|
|||||||
Reference in New Issue
Block a user