mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibJS: Remove support for the "assert" keyword for import attributes
This was removed from the spec some time ago. See:
14286bb
This commit is contained in:
parent
47ba231a9b
commit
b64a355a30
Notes:
github-actions[bot]
2025-01-21 13:59:26 +00:00
Author: https://github.com/trflynn89
Commit: b64a355a30
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3324
7 changed files with 14 additions and 31 deletions
|
@ -4544,13 +4544,6 @@ void Parser::check_identifier_name_for_assignment_validity(DeprecatedFlyString c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Parser::match_with_clause() const
|
|
||||||
{
|
|
||||||
if (m_state.current_token.original_value() == "with"sv)
|
|
||||||
return true;
|
|
||||||
return !m_state.current_token.trivia_contains_line_terminator() && m_state.current_token.original_value() == "assert"sv;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeprecatedFlyString Parser::consume_string_value()
|
DeprecatedFlyString Parser::consume_string_value()
|
||||||
{
|
{
|
||||||
VERIFY(match(TokenType::StringLiteral));
|
VERIFY(match(TokenType::StringLiteral));
|
||||||
|
@ -4585,11 +4578,10 @@ ModuleRequest Parser::parse_module_request()
|
||||||
|
|
||||||
ModuleRequest request { consume_string_value() };
|
ModuleRequest request { consume_string_value() };
|
||||||
|
|
||||||
if (!match_with_clause())
|
if (!match(TokenType::With))
|
||||||
return request;
|
return request;
|
||||||
|
|
||||||
VERIFY(m_state.current_token.original_value().is_one_of("with"sv, "assert"sv));
|
consume(TokenType::With);
|
||||||
consume();
|
|
||||||
consume(TokenType::CurlyOpen);
|
consume(TokenType::CurlyOpen);
|
||||||
|
|
||||||
while (!done() && !match(TokenType::CurlyClose)) {
|
while (!done() && !match(TokenType::CurlyClose)) {
|
||||||
|
|
|
@ -225,7 +225,6 @@ private:
|
||||||
bool match_secondary_expression(ForbiddenTokens forbidden = {}) const;
|
bool match_secondary_expression(ForbiddenTokens forbidden = {}) const;
|
||||||
bool match_statement() const;
|
bool match_statement() const;
|
||||||
bool match_export_or_import() const;
|
bool match_export_or_import() const;
|
||||||
bool match_with_clause() const;
|
|
||||||
|
|
||||||
enum class AllowUsingDeclaration {
|
enum class AllowUsingDeclaration {
|
||||||
No,
|
No,
|
||||||
|
|
|
@ -1699,11 +1699,11 @@ static bool all_import_attributes_supported(VM& vm, Vector<ImportAttribute> cons
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 13.3.10.2 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-attributes/#sec-evaluate-import-call
|
||||||
ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value options_value)
|
ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value options_value)
|
||||||
{
|
{
|
||||||
auto& realm = *vm.current_realm();
|
auto& realm = *vm.current_realm();
|
||||||
|
|
||||||
// 13.3.10.2 EvaluateImportCall ( specifierExpression [ , optionsExpression ] ), https://tc39.es/proposal-import-attributes/#sec-evaluate-import-call
|
|
||||||
// 1. Let referrer be GetActiveScriptOrModule().
|
// 1. Let referrer be GetActiveScriptOrModule().
|
||||||
auto referrer = [&]() -> ImportedModuleReferrer {
|
auto referrer = [&]() -> ImportedModuleReferrer {
|
||||||
auto active_script_or_module = vm.get_active_script_or_module();
|
auto active_script_or_module = vm.get_active_script_or_module();
|
||||||
|
@ -1744,17 +1744,9 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
|
||||||
// c. IfAbruptRejectPromise(attributesObj, promiseCapability).
|
// c. IfAbruptRejectPromise(attributesObj, promiseCapability).
|
||||||
auto attributes_obj = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, options_value.get(vm, vm.names.with));
|
auto attributes_obj = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, options_value.get(vm, vm.names.with));
|
||||||
|
|
||||||
// d. Normative Optional, Deprecated
|
// d. If attributesObj is not undefined, then
|
||||||
// 11. If the host supports the deprecated assert keyword for import attributes and attributesObj is undefined, then
|
|
||||||
if (attributes_obj.is_undefined()) {
|
|
||||||
// i. Set attributesObj to Completion(Get(options, "assert")).
|
|
||||||
// ii. IfAbruptRejectPromise(attributesObj, promiseCapability).
|
|
||||||
attributes_obj = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, options_value.get(vm, vm.names.assert));
|
|
||||||
}
|
|
||||||
|
|
||||||
// e. If attributesObj is not undefined,
|
|
||||||
if (!attributes_obj.is_undefined()) {
|
if (!attributes_obj.is_undefined()) {
|
||||||
// i. If Type(attributesObj) is not Object,
|
// i. If Type(attributesObj) is not Object, then
|
||||||
if (!attributes_obj.is_object()) {
|
if (!attributes_obj.is_object()) {
|
||||||
auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions")));
|
auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions")));
|
||||||
// 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
// 1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
|
@ -1791,7 +1783,7 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// f. If AllImportAttributesSupported(attributes) is false, then
|
// e. If AllImportAttributesSupported(attributes) is false, then
|
||||||
if (!all_import_attributes_supported(vm, attributes)) {
|
if (!all_import_attributes_supported(vm, attributes)) {
|
||||||
auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions")));
|
auto error = TypeError::create(realm, TRY_OR_THROW_OOM(vm, String::formatted(ErrorType::NotAnObject.message(), "ImportOptionsAssertions")));
|
||||||
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
// i. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
|
||||||
|
@ -1801,7 +1793,7 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
|
||||||
return Value { promise_capability->promise() };
|
return Value { promise_capability->promise() };
|
||||||
}
|
}
|
||||||
|
|
||||||
// g. Sort attributes according to the lexicographic order of their [[Key]] fields,
|
// f. Sort attributes according to the lexicographic order of their [[Key]] fields,
|
||||||
// treating the value of each such field as a sequence of UTF-16 code unit values.
|
// treating the value of each such field as a sequence of UTF-16 code unit values.
|
||||||
// NOTE: This sorting is observable only in that hosts are prohibited from
|
// NOTE: This sorting is observable only in that hosts are prohibited from
|
||||||
// distinguishing among attributes by the order they occur in.
|
// distinguishing among attributes by the order they occur in.
|
||||||
|
|
|
@ -179,8 +179,8 @@ describe("in- and exports", () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("can import with (useless) assertions", () => {
|
test("can import with (useless) attributes", () => {
|
||||||
expectModulePassed("./import-with-assertions.mjs");
|
expectModulePassed("./import-with-attributes.mjs");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("namespace has expected ordering", () => {
|
test("namespace has expected ordering", () => {
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
import * as self from "./import-with-assertions.mjs" assert { key: "value", key2: "value2", default: "shouldwork" };
|
|
||||||
import "./import-with-assertions.mjs" assert { key: "value", key2: "value2", default: "shouldwork" };
|
|
||||||
|
|
||||||
export { passed } from "./module-with-default.mjs" assert { key: "value", key2: "value2", default: "shouldwork" };
|
|
4
Libraries/LibJS/Tests/modules/import-with-attributes.mjs
Normal file
4
Libraries/LibJS/Tests/modules/import-with-attributes.mjs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
import * as self from "./import-with-attributes.mjs" with { key: "value", key2: "value2", default: "shouldwork" };
|
||||||
|
import "./import-with-attributes.mjs" with { key: "value", key2: "value2", default: "shouldwork" };
|
||||||
|
|
||||||
|
export { passed } from "./module-with-default.mjs" with { key: "value", key2: "value2", default: "shouldwork" };
|
|
@ -4,7 +4,7 @@ describe("basic behavior", () => {
|
||||||
let error = null;
|
let error = null;
|
||||||
let result = null;
|
let result = null;
|
||||||
|
|
||||||
import("./json-module.json", { assert: { type: "json" } })
|
import("./json-module.json", { with: { type: "json" } })
|
||||||
.then(jsonObj => {
|
.then(jsonObj => {
|
||||||
passed = true;
|
passed = true;
|
||||||
result = jsonObj;
|
result = jsonObj;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue