LibJS: Add missing CommonPropertyNamess and StringMayBeNumber::Nos

This commit is contained in:
Jonne Ransijn 2024-12-01 01:06:25 +01:00 committed by Andreas Kling
parent cfb00ba494
commit 58631e9eef
Notes: github-actions[bot] 2024-12-01 09:43:42 +00:00
9 changed files with 27 additions and 19 deletions

View file

@ -172,7 +172,7 @@ static ThrowCompletionOr<GC::Ref<Object>> create_table_row(Realm& realm, Value r
// 2. Set `row["(index)"]` to `rowIndex`
{
auto key = PropertyKey("(index)");
auto key = PropertyKey { "(index)", PropertyKey::StringMayBeNumber::No };
TRY(row->set(key, row_index, Object::ShouldThrowExceptions::No));
add_column(key);
@ -228,12 +228,11 @@ static ThrowCompletionOr<GC::Ref<Object>> create_table_row(Realm& realm, Value r
}
// 5. Otherwise,
else {
PropertyKey key("Value");
// 5.1. Set `row["Value"]` to `tabularDataItem`
TRY(row->set(key, tabular_data_item, Object::ShouldThrowExceptions::No));
TRY(row->set(vm.names.Value, tabular_data_item, Object::ShouldThrowExceptions::No));
// 5.2. If `finalColumns` does not contain "Value", append "Value" to `finalColumns`
add_column(key);
add_column(vm.names.Value);
}
// 6. Return row
@ -322,10 +321,10 @@ ThrowCompletionOr<Value> Console::table()
auto final_data = Object::create(realm(), nullptr);
// 5.2. Set `finalData["rows"]` to `finalRows`
TRY(final_data->set(PropertyKey("rows"), table_rows, Object::ShouldThrowExceptions::No));
TRY(final_data->set(vm.names.rows, table_rows, Object::ShouldThrowExceptions::No));
// 5.3. Set finalData["columns"] to finalColumns
TRY(final_data->set(PropertyKey("columns"), table_cols, Object::ShouldThrowExceptions::No));
TRY(final_data->set(vm.names.columns, table_cols, Object::ShouldThrowExceptions::No));
// 5.4. Perform `Printer("table", finalData)`
GC::MarkedVector<Value> args(vm.heap());

View file

@ -13,6 +13,7 @@
namespace JS {
#define ENUMERATE_STANDARD_PROPERTY_NAMES(P) \
P(_) \
P(__defineGetter__) \
P(__defineSetter__) \
P(__lookupGetter__) \
@ -94,6 +95,7 @@ namespace JS {
P(copyWithin) \
P(cos) \
P(cosh) \
P(columns) \
P(count) \
P(countReset) \
P(create) \
@ -123,6 +125,7 @@ namespace JS {
P(difference) \
P(dir) \
P(direction) \
P(disabledFeatures) \
P(disambiguation) \
P(disposed) \
P(done) \
@ -170,6 +173,7 @@ namespace JS {
P(fontcolor) \
P(fontsize) \
P(forEach) \
P(formAssociated) \
P(format) \
P(formatMatcher) \
P(formatRange) \
@ -366,10 +370,12 @@ namespace JS {
P(Number) \
P(numberingSystem) \
P(numeric) \
P(observedAttributes) \
P(of) \
P(offset) \
P(offsetNanoseconds) \
P(omitPadding) \
P(opener) \
P(overflow) \
P(ownKeys) \
P(padEnd) \
@ -419,6 +425,7 @@ namespace JS {
P(roundingIncrement) \
P(roundingMode) \
P(roundingPriority) \
P(rows) \
P(script) \
P(seal) \
P(second) \
@ -569,6 +576,7 @@ namespace JS {
P(use) \
P(useGrouping) \
P(UTC) \
P(Value) \
P(value) \
P(valueOf) \
P(values) \

View file

@ -156,7 +156,7 @@ static WebIDL::ExceptionOr<KeyframeType<AL>> process_a_keyframe_like_object(JS::
auto name = input_property.as_string().utf8_string();
if (name == "all"sv) {
all_value = TRY(keyframe_object.get(JS::PropertyKey { "all"sv }));
all_value = TRY(keyframe_object.get(vm.names.all));
for (auto i = to_underlying(CSS::first_longhand_property_id); i <= to_underlying(CSS::last_longhand_property_id); ++i) {
auto property = static_cast<CSS::PropertyID>(i);
if (CSS::is_animatable_property(property))
@ -183,7 +183,7 @@ static WebIDL::ExceptionOr<KeyframeType<AL>> process_a_keyframe_like_object(JS::
// 1. Let raw value be the result of calling the [[Get]] internal method on keyframe input, with property name
// as the property key and keyframe input as the receiver.
// 2. Check the completion record of raw value.
JS::PropertyKey key { property_name.to_byte_string() };
JS::PropertyKey key { property_name.to_byte_string(), JS::PropertyKey::StringMayBeNumber::No };
auto raw_value = TRY(keyframe_object.has_property(key)) ? TRY(keyframe_object.get(key)) : *all_value;
using PropertyValuesType = Conditional<AL == AllowLists::Yes, Vector<String>, String>;
@ -827,7 +827,7 @@ WebIDL::ExceptionOr<GC::MarkedVector<JS::Object*>> KeyframeEffect::get_keyframes
for (auto const& [id, value] : keyframe.parsed_properties()) {
auto value_string = JS::PrimitiveString::create(vm, value->to_string());
TRY(object->set(JS::PropertyKey(DeprecatedFlyString(CSS::camel_case_string_from_property_id(id))), value_string, ShouldThrowExceptions::Yes));
TRY(object->set(JS::PropertyKey { DeprecatedFlyString(CSS::camel_case_string_from_property_id(id)), JS::PropertyKey::StringMayBeNumber::No }, value_string, ShouldThrowExceptions::Yes));
}
m_keyframe_objects.append(object);

View file

@ -218,7 +218,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
VERIFY(attribute_changed_callback_iterator != lifecycle_callbacks.end());
if (attribute_changed_callback_iterator->value) {
// 1. Let observedAttributesIterable be ? Get(constructor, "observedAttributes").
auto observed_attributes_iterable = TRY(constructor->callback->get(JS::PropertyKey { "observedAttributes" }));
auto observed_attributes_iterable = TRY(constructor->callback->get(vm.names.observedAttributes));
// 2. If observedAttributesIterable is not undefined, then set observedAttributes to the result of converting observedAttributesIterable to a sequence<DOMString>. Rethrow any exceptions from the conversion.
if (!observed_attributes_iterable.is_undefined())
@ -229,7 +229,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
Vector<String> disabled_features;
// 7. Let disabledFeaturesIterable be ? Get(constructor, "disabledFeatures").
auto disabled_features_iterable = TRY(constructor->callback->get(JS::PropertyKey { "disabledFeatures" }));
auto disabled_features_iterable = TRY(constructor->callback->get(vm.names.disabledFeatures));
// 8. If disabledFeaturesIterable is not undefined, then set disabledFeatures to the result of converting disabledFeaturesIterable to a sequence<DOMString>. Rethrow any exceptions from the conversion.
if (!disabled_features_iterable.is_undefined())
@ -242,7 +242,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
disable_shadow = disabled_features.contains_slow("shadow"sv);
// 11. Let formAssociatedValue be ? Get( constructor, "formAssociated").
auto form_associated_value = TRY(constructor->callback->get(JS::PropertyKey { "formAssociated" }));
auto form_associated_value = TRY(constructor->callback->get(vm.names.formAssociated));
// 12. Set formAssociated to the result of converting formAssociatedValue to a boolean. Rethrow any exceptions from the conversion.
// NOTE: Converting to a boolean cannot throw with ECMAScript.

View file

@ -935,8 +935,7 @@ WebIDL::ExceptionOr<void> Window::set_opener(JS::Value value)
// 2. If the given value is non-null, then perform ? DefinePropertyOrThrow(this, "opener", { [[Value]]: the given value, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }).
if (!value.is_null()) {
static JS::PropertyKey opener_property_key { "opener", JS::PropertyKey::StringMayBeNumber::No };
TRY(define_property_or_throw(opener_property_key, { .value = value, .writable = true, .enumerable = true, .configurable = true }));
TRY(define_property_or_throw(vm().names.opener, { .value = value, .writable = true, .enumerable = true, .configurable = true }));
}
return {};

View file

@ -3954,6 +3954,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
}
} else if (auto put_forwards_identifier = attribute.extended_attributes.get("PutForwards"sv); put_forwards_identifier.has_value()) {
attribute_generator.set("put_forwards_identifier"sv, *put_forwards_identifier);
VERIFY(!put_forwards_identifier->is_empty() && !is_ascii_digit(put_forwards_identifier->byte_at(0))); // Ensure `PropertyKey`s are not Numbers.
attribute_generator.append(R"~~~(
JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
@ -3963,7 +3964,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
auto value = vm.argument(0);
auto receiver = TRY(throw_dom_exception_if_needed(vm, [&]() { return impl->@attribute.cpp_name@(); }));
TRY(receiver->set(JS::PropertyKey { "@put_forwards_identifier@" }, value, JS::Object::ShouldThrowExceptions::Yes));
TRY(receiver->set(JS::PropertyKey { "@put_forwards_identifier@", JS::PropertyKey::StringMayBeNumber::No }, value, JS::Object::ShouldThrowExceptions::Yes));
return JS::js_undefined();
}

View file

@ -573,6 +573,7 @@ bool is_animatable_property(PropertyID property_id)
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
VERIFY(!name.is_empty() && !is_ascii_digit(name[0])); // Ensure `PropertyKey`s are not Numbers.
if (is_legacy_alias(value.as_object()))
return;

View file

@ -152,8 +152,8 @@ JS::ThrowCompletionOr<JS::Value> WebContentConsoleClient::printer(JS::Console::L
auto table_args = arguments.get<GC::MarkedVector<JS::Value>>();
auto& table = table_args.at(0).as_object();
auto& columns = TRY(table.get(JS::PropertyKey("columns"))).as_array().indexed_properties();
auto& rows = TRY(table.get(JS::PropertyKey("rows"))).as_array().indexed_properties();
auto& columns = TRY(table.get(vm.names.columns)).as_array().indexed_properties();
auto& rows = TRY(table.get(vm.names.rows)).as_array().indexed_properties();
StringBuilder html;

View file

@ -344,10 +344,10 @@ void ReplObject::initialize(JS::Realm& realm)
outln("Disable writing last value to '_'");
// We must delete first otherwise this setter gets called recursively.
TRY(global_object.internal_delete(JS::PropertyKey { "_" }));
TRY(global_object.internal_delete(vm.names._));
auto value = vm.argument(0);
TRY(global_object.internal_set(JS::PropertyKey { "_" }, value, &global_object));
TRY(global_object.internal_set(vm.names._, value, &global_object));
return value;
},
attr);