1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

LibJS: Check type of ShadowRealm.prototype.importValue() 2nd argument

This is a normative change in the ShadowRealm spec.

See: 2b45a15
This commit is contained in:
Linus Groh 2022-03-29 23:48:25 +01:00
parent f1d744e11a
commit 68ee193464
2 changed files with 11 additions and 3 deletions

View file

@ -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);
}
}

View file

@ -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");
});
});