Skip to content

Commit 627b7dd

Browse files
shannonboothtcl3
authored andcommitted
LibWeb/Bindings: Define constructor properties in the correct order
1 parent 3261f87 commit 627b7dd

File tree

8 files changed

+56
-9
lines changed

8 files changed

+56
-9
lines changed

Libraries/LibWeb/Bindings/AudioConstructor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ void AudioConstructor::initialize(JS::Realm& realm)
2626
auto& vm = this->vm();
2727
Base::initialize(realm);
2828

29-
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLAudioElementPrototype>(realm, "HTMLAudioElement"_fly_string), 0);
3029
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
30+
define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "Audio"_string), JS::Attribute::Configurable);
31+
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLAudioElementPrototype>(realm, "HTMLAudioElement"_fly_string), 0);
3132
}
3233

3334
JS::ThrowCompletionOr<JS::Value> AudioConstructor::call()

Libraries/LibWeb/Bindings/ImageConstructor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ void ImageConstructor::initialize(JS::Realm& realm)
2626
auto& vm = this->vm();
2727
Base::initialize(realm);
2828

29-
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLImageElementPrototype>(realm, "HTMLImageElement"_fly_string), 0);
3029
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
30+
define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "Image"_string), JS::Attribute::Configurable);
31+
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLImageElementPrototype>(realm, "HTMLImageElement"_fly_string), 0);
3132
}
3233

3334
JS::ThrowCompletionOr<JS::Value> ImageConstructor::call()

Libraries/LibWeb/Bindings/OptionConstructor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ void OptionConstructor::initialize(JS::Realm& realm)
2929
auto& vm = this->vm();
3030
Base::initialize(realm);
3131

32-
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLOptionElementPrototype>(realm, "HTMLOptionElement"_fly_string), 0);
3332
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
33+
define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "Option"_string), JS::Attribute::Configurable);
34+
define_direct_property(vm.names.prototype, &ensure_web_prototype<Bindings::HTMLOptionElementPrototype>(realm, "HTMLOptionElement"_fly_string), 0);
3435
}
3536

3637
JS::ThrowCompletionOr<JS::Value> OptionConstructor::call()

Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2021-2023, Luke Wilde <[email protected]>
55
* Copyright (c) 2022, Ali Mohammad Pur <[email protected]>
66
* Copyright (c) 2023-2024, Kenneth Myhra <[email protected]>
7-
* Copyright (c) 2023-2024, Shannon Booth <[email protected]>
7+
* Copyright (c) 2023-2025, Shannon Booth <[email protected]>
88
* Copyright (c) 2023-2024, Matthew Olsson <[email protected]>
99
*
1010
* SPDX-License-Identifier: BSD-2-Clause
@@ -4753,8 +4753,9 @@ void @constructor_class@::initialize(JS::Realm& realm)
47534753
}
47544754

47554755
generator.append(R"~~~(
4756-
define_direct_property(vm.names.prototype, &ensure_web_prototype<@prototype_class@>(realm, "@namespaced_name@"_fly_string), 0);
47574756
define_direct_property(vm.names.length, JS::Value(@constructor.length@), JS::Attribute::Configurable);
4757+
define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "@namespaced_name@"_string), JS::Attribute::Configurable);
4758+
define_direct_property(vm.names.prototype, &ensure_web_prototype<@prototype_class@>(realm, "@namespaced_name@"_fly_string), 0);
47584759
47594760
)~~~");
47604761

Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWindowOrWorkerInterfaces.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,14 @@ void Intrinsics::create_web_prototype_and_constructor<@prototype_class@>(JS::Rea
152152
m_constructors.set("@interface_name@"_fly_string, constructor);
153153
154154
prototype->define_direct_property(vm.names.constructor, constructor.ptr(), JS::Attribute::Writable | JS::Attribute::Configurable);
155-
constructor->define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "@interface_name@"_string), JS::Attribute::Configurable);
156155
)~~~");
157156

158157
if (legacy_constructor.has_value()) {
159158
gen.set("legacy_interface_name", legacy_constructor->name);
160159
gen.set("legacy_constructor_class", legacy_constructor->constructor_class);
161160
gen.append(R"~~~(
162161
auto legacy_constructor = realm.create<@legacy_constructor_class@>(realm);
163-
m_constructors.set("@legacy_interface_name@"_fly_string, legacy_constructor);
164-
165-
legacy_constructor->define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "@legacy_interface_name@"_string), JS::Attribute::Configurable);)~~~");
162+
m_constructors.set("@legacy_interface_name@"_fly_string, legacy_constructor);)~~~");
166163
}
167164

168165
gen.append(R"~~~(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Harness status: OK
2+
3+
Found 3 tests
4+
5+
3 Pass
6+
Pass Constructor property enumeration order of "length", "name", and "prototype"
7+
Pass Method property enumeration order of "length" and "name"
8+
Pass Getter property enumeration order of "length" and "name"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
4+
<script>
5+
self.GLOBAL = {
6+
isWindow: function() { return true; },
7+
isWorker: function() { return false; },
8+
isShadowRealm: function() { return false; },
9+
};
10+
</script>
11+
<script src="../../resources/testharness.js"></script>
12+
<script src="../../resources/testharnessreport.js"></script>
13+
14+
<div id=log></div>
15+
<script src="../../webidl/ecmascript-binding/builtin-function-properties.any.js"></script>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
test(() => {
4+
const ownPropKeys = Reflect.ownKeys(Blob).slice(0, 3);
5+
assert_array_equals(ownPropKeys, ["length", "name", "prototype"]);
6+
}, 'Constructor property enumeration order of "length", "name", and "prototype"');
7+
8+
test(() => {
9+
assert_own_property(Blob.prototype, "slice");
10+
11+
const ownPropKeys = Reflect.ownKeys(Blob.prototype.slice).slice(0, 2);
12+
assert_array_equals(ownPropKeys, ["length", "name"]);
13+
}, 'Method property enumeration order of "length" and "name"');
14+
15+
test(() => {
16+
assert_own_property(Blob.prototype, "size");
17+
18+
const desc = Reflect.getOwnPropertyDescriptor(Blob.prototype, "size");
19+
assert_equals(typeof desc.get, "function");
20+
21+
const ownPropKeys = Reflect.ownKeys(desc.get).slice(0, 2);
22+
assert_array_equals(ownPropKeys, ["length", "name"]);
23+
}, 'Getter property enumeration order of "length" and "name"');

0 commit comments

Comments
 (0)