mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:27:42 +00:00
LibJS: Put exports before symbols in keys of module namespace object
This commit is contained in:
parent
fb61e9274a
commit
3b56043612
3 changed files with 27 additions and 4 deletions
|
@ -210,16 +210,19 @@ ThrowCompletionOr<bool> ModuleNamespaceObject::internal_delete(PropertyKey const
|
||||||
ThrowCompletionOr<MarkedVector<Value>> ModuleNamespaceObject::internal_own_property_keys() const
|
ThrowCompletionOr<MarkedVector<Value>> ModuleNamespaceObject::internal_own_property_keys() const
|
||||||
{
|
{
|
||||||
// 1. Let exports be O.[[Exports]].
|
// 1. Let exports be O.[[Exports]].
|
||||||
|
// NOTE: We only add the exports after we know the size of symbolKeys
|
||||||
|
MarkedVector<Value> exports { vm().heap() };
|
||||||
|
|
||||||
// 2. Let symbolKeys be OrdinaryOwnPropertyKeys(O).
|
// 2. Let symbolKeys be OrdinaryOwnPropertyKeys(O).
|
||||||
auto symbol_keys = MUST(Object::internal_own_property_keys());
|
auto symbol_keys = MUST(Object::internal_own_property_keys());
|
||||||
|
|
||||||
// 3. Return the list-concatenation of exports and symbolKeys.
|
// 3. Return the list-concatenation of exports and symbolKeys.
|
||||||
for (auto& export_name : m_exports) {
|
exports.ensure_capacity(m_exports.size() + symbol_keys.size());
|
||||||
symbol_keys.append(js_string(vm(), export_name));
|
for (auto const& export_name : m_exports)
|
||||||
}
|
exports.unchecked_append(js_string(vm(), export_name));
|
||||||
|
exports.extend(symbol_keys);
|
||||||
|
|
||||||
return symbol_keys;
|
return exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,10 @@ describe("in- and exports", () => {
|
||||||
test("can import with (useless) assertions", () => {
|
test("can import with (useless) assertions", () => {
|
||||||
expectModulePassed("./import-with-assertions.mjs");
|
expectModulePassed("./import-with-assertions.mjs");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("namespace has expected ordering", () => {
|
||||||
|
expectModulePassed("./namespace-order.mjs");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("loops", () => {
|
describe("loops", () => {
|
||||||
|
|
16
Userland/Libraries/LibJS/Tests/modules/namespace-order.mjs
Normal file
16
Userland/Libraries/LibJS/Tests/modules/namespace-order.mjs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import * as ns from "./default-and-star-export.mjs";
|
||||||
|
|
||||||
|
const keys = Reflect.ownKeys(ns);
|
||||||
|
// The keys should be in alphabetical order and @@toString at the end
|
||||||
|
if (keys.length < 4) throw new Error("Expected at least 3 keys and @@toStringTag");
|
||||||
|
|
||||||
|
if (keys[0] !== "") throw new Error('Expected keys[0] === ""');
|
||||||
|
|
||||||
|
if (keys[1] !== "*") throw new Error('Expected keys[1] === "*"');
|
||||||
|
|
||||||
|
if (keys[2] !== "default") throw new Error('Expected keys[2] === "default"');
|
||||||
|
|
||||||
|
if (keys.indexOf(Symbol.toStringTag) <= 2)
|
||||||
|
throw new Error("Expected Symbol.toStringTag to be behind string keys");
|
||||||
|
|
||||||
|
export const passed = true;
|
Loading…
Add table
Add a link
Reference in a new issue