mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibIDL: Verify inner type of nullable type is valid
This commit is contained in:
parent
1a94241f58
commit
b081cf077e
Notes:
sideshowbarker
2024-07-17 06:45:52 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/b081cf077e Pull-request: https://github.com/SerenityOS/serenity/pull/21883
@ -187,8 +187,16 @@ NonnullRefPtr<Type const> Parser::parse_type()
|
||||
assert_specific(')');
|
||||
|
||||
bool nullable = lexer.consume_specific('?');
|
||||
auto type = adopt_ref(*new UnionType("", nullable, move(union_member_types)));
|
||||
|
||||
return adopt_ref(*new UnionType("", nullable, move(union_member_types)));
|
||||
if (nullable) {
|
||||
if (type->number_of_nullable_member_types() > 0)
|
||||
report_parsing_error("nullable union type cannot contain another nullable type"sv, filename, input, lexer.tell());
|
||||
|
||||
// FIXME: A nullable union type cannot include a dictionary type as one of its flattened member types.
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
bool unsigned_ = lexer.consume_specific("unsigned");
|
||||
@ -224,6 +232,28 @@ NonnullRefPtr<Type const> Parser::parse_type()
|
||||
builder.append("unsigned "sv);
|
||||
builder.append(name);
|
||||
|
||||
if (nullable) {
|
||||
// https://webidl.spec.whatwg.org/#dfn-nullable-type
|
||||
// The inner type must not be:
|
||||
// - any,
|
||||
if (name == "any"sv)
|
||||
report_parsing_error("'any' cannot be nullable"sv, filename, input, lexer.tell());
|
||||
|
||||
// - a promise type,
|
||||
if (name == "Promise"sv)
|
||||
report_parsing_error("'Promise' cannot be nullable"sv, filename, input, lexer.tell());
|
||||
|
||||
// - an observable array type,
|
||||
if (name == "ObservableArray")
|
||||
report_parsing_error("'ObservableArray' cannot be nullable"sv, filename, input, lexer.tell());
|
||||
|
||||
// - another nullable type, or
|
||||
|
||||
// - a union type that itself includes a nullable type or has a dictionary type as one of its flattened
|
||||
// member types
|
||||
// Note: This case is handled above
|
||||
}
|
||||
|
||||
if (is_parameterized_type)
|
||||
return adopt_ref(*new ParameterizedType(builder.to_deprecated_string(), nullable, move(parameters)));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user