mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibJS: Change error message for non-objects in GetIteratorFlattenable
Matches other usages in e.g. Temporal now.
This commit is contained in:
parent
92fa1efc76
commit
705e96568c
3 changed files with 5 additions and 5 deletions
|
@ -46,7 +46,7 @@ ThrowCompletionOr<IteratorRecord> get_iterator_flattenable(VM& vm, Value object,
|
||||||
if (!object.is_object()) {
|
if (!object.is_object()) {
|
||||||
// a. If stringHandling is reject-strings or obj is not a String, throw a TypeError exception.
|
// a. If stringHandling is reject-strings or obj is not a String, throw a TypeError exception.
|
||||||
if (string_handling == StringHandling::RejectStrings || !object.is_string())
|
if (string_handling == StringHandling::RejectStrings || !object.is_string())
|
||||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, "obj"sv);
|
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, object.to_string_without_side_effects()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Let method be ? GetMethod(obj, @@iterator).
|
// 2. Let method be ? GetMethod(obj, @@iterator).
|
||||||
|
@ -67,7 +67,7 @@ ThrowCompletionOr<IteratorRecord> get_iterator_flattenable(VM& vm, Value object,
|
||||||
|
|
||||||
// 5. If iterator is not an Object, throw a TypeError exception.
|
// 5. If iterator is not an Object, throw a TypeError exception.
|
||||||
if (!iterator.is_object())
|
if (!iterator.is_object())
|
||||||
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, "iterator"sv);
|
return vm.throw_completion<TypeError>(ErrorType::NotAnObject, TRY_OR_THROW_OOM(vm, iterator.to_string_without_side_effects()));
|
||||||
|
|
||||||
// 6. Return ? GetIteratorDirect(iterator).
|
// 6. Return ? GetIteratorDirect(iterator).
|
||||||
return TRY(get_iterator_direct(vm, iterator.as_object()));
|
return TRY(get_iterator_direct(vm, iterator.as_object()));
|
||||||
|
|
|
@ -2,7 +2,7 @@ describe("errors", () => {
|
||||||
test("called with non-Object", () => {
|
test("called with non-Object", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Iterator.from(Symbol.hasInstance);
|
Iterator.from(Symbol.hasInstance);
|
||||||
}).toThrowWithMessage(TypeError, "obj is not an object");
|
}).toThrowWithMessage(TypeError, "Symbol(Symbol.hasInstance) is not an object");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("@@iterator is not callable", () => {
|
test("@@iterator is not callable", () => {
|
||||||
|
@ -35,7 +35,7 @@ describe("errors", () => {
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
Iterator.from(iterable);
|
Iterator.from(iterable);
|
||||||
}).toThrowWithMessage(TypeError, "iterator is not an object");
|
}).toThrowWithMessage(TypeError, "Symbol(Symbol.hasInstance) is not an object");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ describe("errors", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const iterator = generator().flatMap(() => Symbol.hasInstance);
|
const iterator = generator().flatMap(() => Symbol.hasInstance);
|
||||||
iterator.next();
|
iterator.next();
|
||||||
}).toThrowWithMessage(TypeError, "obj is not an object");
|
}).toThrowWithMessage(TypeError, "Symbol(Symbol.hasInstance) is not an object");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue