Skip to content

Commit 1773ef2

Browse files
committed
LibWeb: Redefine WebIDL types in terms of Infra spec
Corresponds to whatwg/webidl#1452
1 parent 39c500e commit 1773ef2

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

Libraries/LibWeb/Infra/Types.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#include <AK/Types.h>
10+
#include <AK/UFixedBigInt.h>
11+
12+
namespace Web::Infra {
13+
14+
// https://infra.spec.whatwg.org/#booleans
15+
// A boolean is either true or false.
16+
using Boolean = bool;
17+
18+
// https://infra.spec.whatwg.org/#8-bit-unsigned-integer
19+
// An 8-bit unsigned integer is an integer in the range 0 to 255 (0 to 2^8 − 1), inclusive.
20+
using Unsigned8BitInteger = u8;
21+
22+
// https://infra.spec.whatwg.org/#16-bit-unsigned-integer
23+
// A 16-bit unsigned integer is an integer in the range 0 to 65535 (0 to 2^16 − 1), inclusive.
24+
using Unsigned16BitInteger = u16;
25+
26+
// https://infra.spec.whatwg.org/#32-bit-unsigned-integer
27+
// A 32-bit unsigned integer is an integer in the range 0 to 4294967295 (0 to 2^32 − 1), inclusive.
28+
using Unsigned32BitInteger = u32;
29+
30+
// https://infra.spec.whatwg.org/#64-bit-unsigned-integer
31+
// A 64-bit unsigned integer is an integer in the range 0 to 18446744073709551615 (0 to 2^64 − 1), inclusive.
32+
using Unsigned64BitInteger = u64;
33+
34+
// https://infra.spec.whatwg.org/#128-bit-unsigned-integer
35+
// A 128-bit unsigned integer is an integer in the range 0 to 340282366920938463463374607431768211455 (0 to 2^128 − 1), inclusive.
36+
using Unsigned128BitInteger = u128;
37+
38+
// https://infra.spec.whatwg.org/#8-bit-signed-integer
39+
// An 8-bit signed integer is an integer in the range −128 to 127 (−2^7 to 2^7 − 1), inclusive.
40+
using Signed8BitInteger = i8;
41+
42+
// https://infra.spec.whatwg.org/#16-bit-signed-integer
43+
// A 16-bit signed integer is an integer in the range −32768 to 32767 (−2^15 to 2^15 − 1), inclusive.
44+
using Signed16BitInteger = i16;
45+
46+
// https://infra.spec.whatwg.org/#32-bit-signed-integer
47+
// A 32-bit signed integer is an integer in the range −2147483648 to 2147483647 (−2^31 to 2^31 − 1), inclusive.
48+
using Signed32BitInteger = i32;
49+
50+
// https://infra.spec.whatwg.org/#64-bit-signed-integer
51+
// A 64-bit signed integer is an integer in the range −9223372036854775808 to 9223372036854775807 (−2^63 to 2^63 − 1), inclusive.
52+
using Signed64BitInteger = i64;
53+
54+
}

Libraries/LibWeb/WebIDL/Types.h

+21-17
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,45 @@
66

77
#pragma once
88

9-
#include <AK/Types.h>
9+
#include <LibWeb/Infra/Types.h>
1010

1111
namespace Web::WebIDL {
1212

13+
// https://webidl.spec.whatwg.org/#idl-boolean
14+
// The boolean type corresponds to booleans.
15+
using Boolean = Infra::Boolean;
16+
1317
// https://webidl.spec.whatwg.org/#idl-byte
14-
// The byte type is a signed integer type that has values in the range [−128, 127].
15-
using Byte = i8;
18+
// The byte type corresponds to 8-bit signed integers.
19+
using Byte = Infra::Signed8BitInteger;
1620

1721
// https://webidl.spec.whatwg.org/#idl-octet
18-
// The octet type is an unsigned integer type that has values in the range [0, 255].
19-
using Octet = u8;
22+
// The octet type corresponds to 8-bit unsigned integers.
23+
using Octet = Infra::Unsigned8BitInteger;
2024

2125
// https://webidl.spec.whatwg.org/#idl-short
22-
// The short type is a signed integer type that has values in the range [−32768, 32767].
23-
using Short = i16;
26+
// The short type corresponds to 16-bit signed integers.
27+
using Short = Infra::Signed16BitInteger;
2428

2529
// https://webidl.spec.whatwg.org/#idl-unsigned-short
26-
// The unsigned short type is an unsigned integer type that has values in the range [0, 65535].
27-
using UnsignedShort = u16;
30+
// The unsigned short type corresponds to 16-bit unsigned integers.
31+
using UnsignedShort = Infra::Unsigned16BitInteger;
2832

2933
// https://webidl.spec.whatwg.org/#idl-long
30-
// The long type is a signed integer type that has values in the range [−2147483648, 2147483647].
31-
using Long = i32;
34+
// The long type corresponds to 32-bit signed integers.
35+
using Long = Infra::Signed32BitInteger;
3236

3337
// https://webidl.spec.whatwg.org/#idl-unsigned-long
34-
// The unsigned long type is an unsigned integer type that has values in the range [0, 4294967295].
35-
using UnsignedLong = u32;
38+
// The unsigned long type corresponds to 32-bit unsigned integers.
39+
using UnsignedLong = Infra::Unsigned32BitInteger;
3640

3741
// https://webidl.spec.whatwg.org/#idl-long-long
38-
// The long long type is a signed integer type that has values in the range [−9223372036854775808, 9223372036854775807].
39-
using LongLong = i64;
42+
// The long long type corresponds to 64-bit signed integers.
43+
using LongLong = Infra::Signed64BitInteger;
4044

4145
// https://webidl.spec.whatwg.org/#idl-unsigned-long-long
42-
// The unsigned long long type is an unsigned integer type that has values in the range [0, 18446744073709551615].
43-
using UnsignedLongLong = u64;
46+
// The unsigned long long type corresponds to 64-bit unsigned integers.
47+
using UnsignedLongLong = Infra::Unsigned64BitInteger;
4448

4549
// https://webidl.spec.whatwg.org/#idl-double
4650
// The double type is a floating point numeric type that corresponds to the set of finite

0 commit comments

Comments
 (0)