diff --git a/jerry-core/api/jerry-module.c b/jerry-core/api/jerry-module.c index 782f001d2..c0443866a 100644 --- a/jerry-core/api/jerry-module.c +++ b/jerry-core/api/jerry-module.c @@ -13,14 +13,14 @@ * limitations under the License. */ -#include "lit-magic-strings.h" -#include "lit-strings.h" - #include "jerryscript-core.h" #include "jerryscript-port.h" #include "ecma-errors.h" +#include "lit-magic-strings.h" +#include "lit-strings.h" + #if JERRY_MODULE_SYSTEM /** diff --git a/jerry-core/ecma/base/ecma-module.c b/jerry-core/ecma/base/ecma-module.c index f6413df07..21fc52fd7 100644 --- a/jerry-core/ecma/base/ecma-module.c +++ b/jerry-core/ecma/base/ecma-module.c @@ -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; + JERRY_ASSERT (local_env_p->type_flags_refs & ECMA_OBJECT_FLAG_BLOCK); + while (import_names_p != NULL) { - ecma_object_t *lex_env_p = local_env_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); - } + ecma_property_t *binding_p = ecma_find_named_property (local_env_p, import_names_p->local_name_p); if (binding_p != NULL) { 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; } diff --git a/tests/jerry/module-import-global.mjs b/tests/jerry/module-import-global.mjs new file mode 100644 index 000000000..cdb4c539b --- /dev/null +++ b/tests/jerry/module-import-global.mjs @@ -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") diff --git a/tests/snapshot-tests-skiplist.txt b/tests/snapshot-tests-skiplist.txt index 687808ea5..2952f1235 100644 --- a/tests/snapshot-tests-skiplist.txt +++ b/tests/snapshot-tests-skiplist.txt @@ -43,6 +43,7 @@ tests/jerry/module-import-04.mjs tests/jerry/module-import-05.mjs tests/jerry/module-import-06.mjs tests/jerry/module-import-07.mjs +tests/jerry/module-import-global.mjs tests/jerry/module-namespace-01.mjs tests/jerry/module-namespace-02.mjs tests/jerry/module-namespace-03.mjs