mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00
LibJS: Stop using Interpreter& in the iterator operations helpers
This commit is contained in:
parent
2bc5bc64fb
commit
340d6b0ef7
1 changed files with 16 additions and 17 deletions
|
@ -24,7 +24,6 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/IteratorOperations.h>
|
||||
|
@ -33,7 +32,7 @@ namespace JS {
|
|||
|
||||
Object* get_iterator(GlobalObject& global_object, Value value, String hint, Value method)
|
||||
{
|
||||
auto& interpreter = global_object.interpreter();
|
||||
auto& vm = global_object.vm();
|
||||
ASSERT(hint == "sync" || hint == "async");
|
||||
if (method.is_empty()) {
|
||||
if (hint == "async")
|
||||
|
@ -42,18 +41,18 @@ Object* get_iterator(GlobalObject& global_object, Value value, String hint, Valu
|
|||
if (!object)
|
||||
return {};
|
||||
method = object->get(global_object.vm().well_known_symbol_iterator());
|
||||
if (interpreter.exception())
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
if (!method.is_function()) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::NotIterable, value.to_string_without_side_effects().characters());
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotIterable, value.to_string_without_side_effects().characters());
|
||||
return nullptr;
|
||||
}
|
||||
auto iterator = interpreter.call(method.as_function(), value);
|
||||
if (interpreter.exception())
|
||||
auto iterator = vm.call(method.as_function(), value);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (!iterator.is_object()) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::NotIterable, value.to_string_without_side_effects().characters());
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotIterable, value.to_string_without_side_effects().characters());
|
||||
return nullptr;
|
||||
}
|
||||
return &iterator.as_object();
|
||||
|
@ -61,27 +60,27 @@ Object* get_iterator(GlobalObject& global_object, Value value, String hint, Valu
|
|||
|
||||
Object* iterator_next(Object& iterator, Value value)
|
||||
{
|
||||
auto& interpreter = iterator.interpreter();
|
||||
auto& vm = iterator.vm();
|
||||
auto& global_object = iterator.global_object();
|
||||
auto next_method = iterator.get("next");
|
||||
if (interpreter.exception())
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
if (!next_method.is_function()) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::IterableNextNotAFunction);
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::IterableNextNotAFunction);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Value result;
|
||||
if (value.is_empty())
|
||||
result = interpreter.call(next_method.as_function(), &iterator);
|
||||
result = vm.call(next_method.as_function(), &iterator);
|
||||
else
|
||||
result = interpreter.call(next_method.as_function(), &iterator, value);
|
||||
result = vm.call(next_method.as_function(), &iterator, value);
|
||||
|
||||
if (interpreter.exception())
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (!result.is_object()) {
|
||||
interpreter.vm().throw_exception<TypeError>(global_object, ErrorType::IterableNextBadReturn);
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::IterableNextBadReturn);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -104,7 +103,7 @@ Value create_iterator_result_object(GlobalObject& global_object, Value value, bo
|
|||
|
||||
void get_iterator_values(GlobalObject& global_object, Value value, AK::Function<IterationDecision(Value)> callback)
|
||||
{
|
||||
auto& interpreter = global_object.interpreter();
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
auto iterator = get_iterator(global_object, value);
|
||||
if (!iterator)
|
||||
|
@ -116,14 +115,14 @@ void get_iterator_values(GlobalObject& global_object, Value value, AK::Function<
|
|||
return;
|
||||
|
||||
auto done_property = next_object->get("done");
|
||||
if (interpreter.exception())
|
||||
if (vm.exception())
|
||||
return;
|
||||
|
||||
if (!done_property.is_empty() && done_property.to_boolean())
|
||||
return;
|
||||
|
||||
auto next_value = next_object->get("value");
|
||||
if (interpreter.exception())
|
||||
if (vm.exception())
|
||||
return;
|
||||
|
||||
auto result = callback(next_value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue