summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-03-29 23:48:25 +0100
committerLinus Groh <mail@linusgroh.de>2022-03-29 23:48:25 +0100
commit68ee193464a2f98cee1d889aaa47cd45decc312f (patch)
tree6aa23e604102a07bd3fb565332c2e0cbf9605248 /Userland
parentf1d744e11a7995aec13274c43901c162c1f6af43 (diff)
downloadserenity-68ee193464a2f98cee1d889aaa47cd45decc312f.zip
LibJS: Check type of ShadowRealm.prototype.importValue() 2nd argument
This is a normative change in the ShadowRealm spec. See: https://github.com/tc39/proposal-shadowrealm/commit/2b45a15
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp7
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js7
2 files changed, 11 insertions, 3 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp
index 074739396c..b20113f421 100644
--- a/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ShadowRealmPrototype.cpp
@@ -65,8 +65,9 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
// 3. Let specifierString be ? ToString(specifier).
auto specifier_string = TRY(specifier.to_string(global_object));
- // 4. Let exportNameString be ? ToString(exportName).
- auto export_name_string = TRY(export_name.to_string(global_object));
+ // 4. If Type(exportName) is not String, throw a TypeError exception.
+ if (!export_name.is_string())
+ return vm.throw_completion<TypeError>(global_object, ErrorType::NotAString, export_name.to_string_without_side_effects());
// 5. Let callerRealm be the current Realm Record.
auto* caller_realm = vm.current_realm();
@@ -78,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
auto& eval_context = object->execution_context();
// 8. Return ? ShadowRealmImportValue(specifierString, exportNameString, callerRealm, evalRealm, evalContext).
- return shadow_realm_import_value(global_object, move(specifier_string), move(export_name_string), *caller_realm, eval_realm, eval_context);
+ return shadow_realm_import_value(global_object, move(specifier_string), export_name.as_string().string(), *caller_realm, eval_realm, eval_context);
}
}
diff --git a/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js b/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js
index 8b1efef9f2..9b7ab9677a 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/ShadowRealm/ShadowRealm.prototype.importValue.js
@@ -70,4 +70,11 @@ describe("errors", () => {
ShadowRealm.prototype.importValue.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type ShadowRealm");
});
+
+ test("export name must be string", () => {
+ const shadowRealm = new ShadowRealm();
+ expect(() => {
+ shadowRealm.importValue("./whatever.mjs", 123);
+ }).toThrowWithMessage(TypeError, "123 is not a string");
+ });
});