LibJS: Convert RegExpStringIteratorPrototype to ThrowCompletionOr
This commit is contained in:
parent
063ce946b7
commit
2ab089fa21
Notes:
sideshowbarker
2024-07-18 01:59:18 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/2ab089fa218 Pull-request: https://github.com/SerenityOS/serenity/pull/10586
2 changed files with 11 additions and 11 deletions
|
@ -23,21 +23,21 @@ void RegExpStringIteratorPrototype::initialize(GlobalObject& global_object)
|
|||
auto& vm = this->vm();
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
auto* iterator = TRY_OR_DISCARD(typed_this_value(global_object));
|
||||
auto* iterator = TRY(typed_this_value(global_object));
|
||||
if (iterator->done())
|
||||
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()) {
|
||||
iterator->set_done();
|
||||
|
@ -49,16 +49,16 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(RegExpStringIteratorPrototype::next)
|
|||
return create_iterator_result_object(global_object, match, false);
|
||||
}
|
||||
|
||||
auto* match_object = TRY_OR_DISCARD(match.to_object(global_object));
|
||||
auto match_string_value = TRY_OR_DISCARD(match_object->get(0));
|
||||
auto match_string = TRY_OR_DISCARD(match_string_value.to_string(global_object));
|
||||
auto* match_object = TRY(match.to_object(global_object));
|
||||
auto match_string_value = TRY(match_object->get(0));
|
||||
auto match_string = TRY(match_string_value.to_string(global_object));
|
||||
if (match_string.is_empty()) {
|
||||
auto last_index_value = TRY_OR_DISCARD(iterator->regexp_object().get(vm.names.lastIndex));
|
||||
auto last_index = TRY_OR_DISCARD(last_index_value.to_length(global_object));
|
||||
auto last_index_value = TRY(iterator->regexp_object().get(vm.names.lastIndex));
|
||||
auto last_index = TRY(last_index_value.to_length(global_object));
|
||||
|
||||
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);
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual void initialize(GlobalObject&) override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(next);
|
||||
JS_DECLARE_NATIVE_FUNCTION(next);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue