Rework resolving references and namespace creation in modules (#4695)

- Properties of namespace objects are ordered in lexical order
- The namespace object is created and imports are bound during linking phase
- Namespace imports are changed to read-only
- Reduced memory consumption

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2021-07-06 14:50:19 +02:00
committed by GitHub
parent ccc152594a
commit d1204ab1c9
14 changed files with 882 additions and 476 deletions
@@ -0,0 +1,16 @@
// 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 {a} from "./module-circular-06.mjs"
assert(a === 6.5)
@@ -0,0 +1,17 @@
// 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.
export {b as a} from "./module-circular-07.mjs";
import {b} from "./module-circular-07.mjs"
assert(b === 6.5 || b === undefined)
@@ -0,0 +1,16 @@
// 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.
export * from "./module-circular-08.mjs"
export * from "./module-circular-09.mjs"
@@ -0,0 +1,15 @@
// 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.
export {a as b} from "./module-circular-06.mjs"
@@ -0,0 +1,15 @@
// 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.
export var b = 6.5
+25
View File
@@ -0,0 +1,25 @@
/* 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.
*/
/* Test sorting order */
export let
c = 4,
bc = 3,
ddd = 6,
dddd = 7,
bb = 2,
dd = 5,
a = 1
+32
View File
@@ -0,0 +1,32 @@
/* 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 * as namespace from "module-export-09.mjs"
assert(JSON.stringify(namespace) === '{"a":1,"bb":2,"bc":3,"c":4,"dd":5,"ddd":6,"dddd":7}')
try {
namespace = 8
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
try {
namespace += 8
assert(false)
} catch (e) {
assert(e instanceof TypeError)
}
+7 -5
View File
@@ -64,16 +64,18 @@ create_module (int id) /**< module id */
if (id == 0)
{
result = jerry_parse ((jerry_char_t *) "", 0, &module_parse_options);
jerry_char_t source[] = "export var a = 7";
result = jerry_parse (source, sizeof (source) - 1, &module_parse_options);
}
else
{
jerry_char_t source[] = "import a from 'XX_module.mjs'";
jerry_char_t source[] = "export {a} from 'XX_module.mjs'";
TEST_ASSERT (id >= 1 && id <= 99 && source[15] == 'X' && source[16] == 'X');
TEST_ASSERT (id >= 1 && id <= 99 && source[17] == 'X' && source[18] == 'X');
source[15] = (jerry_char_t) ((id / 10) + '0');
source[16] = (jerry_char_t) ((id % 10) + '0');
source[17] = (jerry_char_t) ((id / 10) + '0');
source[18] = (jerry_char_t) ((id % 10) + '0');
result = jerry_parse (source, sizeof (source) - 1, &module_parse_options);
}