LibJS: Convert the CreateHTML AO to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-23 03:08:25 +03:00 committed by Andreas Kling
parent 0948bd8c1e
commit 38c4693c70
Notes: sideshowbarker 2024-07-18 02:00:34 +09:00

View file

@ -955,16 +955,16 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::search)
}
// B.2.2.2.1 CreateHTML ( string, tag, attribute, value ), https://tc39.es/ecma262/#sec-createhtml
static Value create_html(GlobalObject& global_object, Value string, const String& tag, const String& attribute, Value value)
static ThrowCompletionOr<Value> create_html(GlobalObject& global_object, Value string, const String& tag, const String& attribute, Value value)
{
auto& vm = global_object.vm();
TRY_OR_DISCARD(require_object_coercible(global_object, string));
auto str = TRY_OR_DISCARD(string.to_string(global_object));
TRY(require_object_coercible(global_object, string));
auto str = TRY(string.to_string(global_object));
StringBuilder builder;
builder.append('<');
builder.append(tag);
if (!attribute.is_empty()) {
auto value_string = TRY_OR_DISCARD(value.to_string(global_object));
auto value_string = TRY(value.to_string(global_object));
builder.append(' ');
builder.append(attribute);
builder.append("=\"");
@ -982,79 +982,79 @@ static Value create_html(GlobalObject& global_object, Value string, const String
// B.2.2.2 String.prototype.anchor ( name ), https://tc39.es/ecma262/#sec-string.prototype.anchor
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::anchor)
{
return create_html(global_object, vm.this_value(global_object), "a", "name", vm.argument(0));
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "a", "name", vm.argument(0)));
}
// B.2.2.3 String.prototype.big ( ), https://tc39.es/ecma262/#sec-string.prototype.big
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::big)
{
return create_html(global_object, vm.this_value(global_object), "big", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "big", String::empty(), Value()));
}
// B.2.2.4 String.prototype.blink ( ), https://tc39.es/ecma262/#sec-string.prototype.blink
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::blink)
{
return create_html(global_object, vm.this_value(global_object), "blink", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "blink", String::empty(), Value()));
}
// B.2.2.5 String.prototype.bold ( ), https://tc39.es/ecma262/#sec-string.prototype.bold
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::bold)
{
return create_html(global_object, vm.this_value(global_object), "b", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "b", String::empty(), Value()));
}
// B.2.2.6 String.prototype.fixed ( ), https://tc39.es/ecma262/#sec-string.prototype.fixed
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::fixed)
{
return create_html(global_object, vm.this_value(global_object), "tt", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "tt", String::empty(), Value()));
}
// B.2.2.7 String.prototype.fontcolor ( color ), https://tc39.es/ecma262/#sec-string.prototype.fontcolor
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::fontcolor)
{
return create_html(global_object, vm.this_value(global_object), "font", "color", vm.argument(0));
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "font", "color", vm.argument(0)));
}
// B.2.2.8 String.prototype.fontsize ( size ), https://tc39.es/ecma262/#sec-string.prototype.fontsize
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::fontsize)
{
return create_html(global_object, vm.this_value(global_object), "font", "size", vm.argument(0));
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "font", "size", vm.argument(0)));
}
// B.2.2.9 String.prototype.italics ( ), https://tc39.es/ecma262/#sec-string.prototype.italics
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::italics)
{
return create_html(global_object, vm.this_value(global_object), "i", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "i", String::empty(), Value()));
}
// B.2.2.10 String.prototype.link ( url ), https://tc39.es/ecma262/#sec-string.prototype.link
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::link)
{
return create_html(global_object, vm.this_value(global_object), "a", "href", vm.argument(0));
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "a", "href", vm.argument(0)));
}
// B.2.2.11 String.prototype.small ( ), https://tc39.es/ecma262/#sec-string.prototype.small
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::small)
{
return create_html(global_object, vm.this_value(global_object), "small", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "small", String::empty(), Value()));
}
// B.2.2.12 String.prototype.strike ( ), https://tc39.es/ecma262/#sec-string.prototype.strike
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::strike)
{
return create_html(global_object, vm.this_value(global_object), "strike", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "strike", String::empty(), Value()));
}
// B.2.2.13 String.prototype.sub ( ), https://tc39.es/ecma262/#sec-string.prototype.sub
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::sub)
{
return create_html(global_object, vm.this_value(global_object), "sub", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "sub", String::empty(), Value()));
}
// B.2.2.14 String.prototype.sup ( ), https://tc39.es/ecma262/#sec-string.prototype.sup
JS_DEFINE_OLD_NATIVE_FUNCTION(StringPrototype::sup)
{
return create_html(global_object, vm.this_value(global_object), "sup", String::empty(), Value());
return TRY_OR_DISCARD(create_html(global_object, vm.this_value(global_object), "sup", String::empty(), Value()));
}
// 22.1.3.11 String.prototype.localeCompare ( that [ , reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-string.prototype.localecompare