diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-02 20:52:46 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-02 20:52:46 +0100 |
commit | 163d776df648a88c26250fa1f6a9f0f07ba66c39 (patch) | |
tree | aac2535c71b4ce7b179f3052e65431a77668becb | |
parent | a5903ac4b6c0f67cacd6d5c8ad6ab7eccf5fee10 (diff) | |
download | serenity-163d776df648a88c26250fa1f6a9f0f07ba66c39.zip |
LibJS: Replace iterator hint string argument with an enum
There's no reason at all for this to be a string or to accept arbitrary
values - just because it's displayed as strings in the spec doesn't mean
we have to do the same :^)
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/IteratorOperations.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/VM.cpp | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 5a397076d4..2087564dc1 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -10,12 +10,11 @@ namespace JS { -Object* get_iterator(GlobalObject& global_object, Value value, String hint, Value method) +Object* get_iterator(GlobalObject& global_object, Value value, IteratorHint hint, Value method) { auto& vm = global_object.vm(); - VERIFY(hint == "sync" || hint == "async"); if (method.is_empty()) { - if (hint == "async") + if (hint == IteratorHint::Async) TODO(); auto object = value.to_object(global_object); if (!object) @@ -100,7 +99,7 @@ void get_iterator_values(GlobalObject& global_object, Value value, AK::Function< { auto& vm = global_object.vm(); - auto iterator = get_iterator(global_object, value, "sync", method); + auto iterator = get_iterator(global_object, value, IteratorHint::Sync, method); if (!iterator) return; diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h index f80cd3de88..53ec962f73 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h @@ -14,7 +14,12 @@ namespace JS { // Common iterator operations defined in ECMA262 7.4 // https://tc39.es/ecma262/#sec-operations-on-iterator-objects -Object* get_iterator(GlobalObject&, Value value, String hint = "sync", Value method = {}); +enum class IteratorHint { + Sync, + Async, +}; + +Object* get_iterator(GlobalObject&, Value value, IteratorHint hint = IteratorHint::Sync, Value method = {}); bool is_iterator_complete(Object& iterator_result); Value create_iterator_result_object(GlobalObject&, Value value, bool done); diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index cb6ce81a87..53014ffe9f 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -180,7 +180,7 @@ void VM::assign(const NonnullRefPtr<BindingPattern>& target, Value value, Global switch (binding.kind) { case BindingPattern::Kind::Array: { - auto iterator = get_iterator(global_object, value, "sync"sv, {}); + auto iterator = get_iterator(global_object, value); if (!iterator) return; |