mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
LibJS: Convert RegExpStringIteratorPrototype to ThrowCompletionOr
This commit is contained in:
parent
063ce946b7
commit
2ab089fa21
2 changed files with 11 additions and 11 deletions
|
@ -23,21 +23,21 @@ void RegExpStringIteratorPrototype::initialize(GlobalObject& global_object)
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
|
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
define_old_native_function(vm.names.next, next, 0, attr);
|
define_native_function(vm.names.next, next, 0, attr);
|
||||||
|
|
||||||
// 22.2.7.2.2 %RegExpStringIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%-@@tostringtag
|
// 22.2.7.2.2 %RegExpStringIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%-@@tostringtag
|
||||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "RegExp String Iterator"), Attribute::Configurable);
|
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "RegExp String Iterator"), Attribute::Configurable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 22.2.7.2.1 %RegExpStringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%.next
|
// 22.2.7.2.1 %RegExpStringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%.next
|
||||||
JS_DEFINE_OLD_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next)
|
JS_DEFINE_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next)
|
||||||
{
|
{
|
||||||
// For details, see the 'closure' of: https://tc39.es/ecma262/#sec-createregexpstringiterator
|
// For details, see the 'closure' of: https://tc39.es/ecma262/#sec-createregexpstringiterator
|
||||||
auto* iterator = TRY_OR_DISCARD(typed_this_value(global_object));
|
auto* iterator = TRY(typed_this_value(global_object));
|
||||||
if (iterator->done())
|
if (iterator->done())
|
||||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||||
|
|
||||||
auto match = TRY_OR_DISCARD(regexp_exec(global_object, iterator->regexp_object(), iterator->string()));
|
auto match = TRY(regexp_exec(global_object, iterator->regexp_object(), iterator->string()));
|
||||||
|
|
||||||
if (match.is_null()) {
|
if (match.is_null()) {
|
||||||
iterator->set_done();
|
iterator->set_done();
|
||||||
|
@ -49,16 +49,16 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next)
|
||||||
return create_iterator_result_object(global_object, match, false);
|
return create_iterator_result_object(global_object, match, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* match_object = TRY_OR_DISCARD(match.to_object(global_object));
|
auto* match_object = TRY(match.to_object(global_object));
|
||||||
auto match_string_value = TRY_OR_DISCARD(match_object->get(0));
|
auto match_string_value = TRY(match_object->get(0));
|
||||||
auto match_string = TRY_OR_DISCARD(match_string_value.to_string(global_object));
|
auto match_string = TRY(match_string_value.to_string(global_object));
|
||||||
if (match_string.is_empty()) {
|
if (match_string.is_empty()) {
|
||||||
auto last_index_value = TRY_OR_DISCARD(iterator->regexp_object().get(vm.names.lastIndex));
|
auto last_index_value = TRY(iterator->regexp_object().get(vm.names.lastIndex));
|
||||||
auto last_index = TRY_OR_DISCARD(last_index_value.to_length(global_object));
|
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||||
|
|
||||||
last_index = advance_string_index(iterator->string().view(), last_index, iterator->unicode());
|
last_index = advance_string_index(iterator->string().view(), last_index, iterator->unicode());
|
||||||
|
|
||||||
TRY_OR_DISCARD(iterator->regexp_object().set(vm.names.lastIndex, Value(last_index), Object::ShouldThrowExceptions::Yes));
|
TRY(iterator->regexp_object().set(vm.names.lastIndex, Value(last_index), Object::ShouldThrowExceptions::Yes));
|
||||||
}
|
}
|
||||||
|
|
||||||
return create_iterator_result_object(global_object, match, false);
|
return create_iterator_result_object(global_object, match, false);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
virtual void initialize(GlobalObject&) override;
|
virtual void initialize(GlobalObject&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(next);
|
JS_DECLARE_NATIVE_FUNCTION(next);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue