mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
LibJS: Don't coerce this value to object in Promise.prototype.finally()
This commit is contained in:
parent
53ec432e8d
commit
194d90dc72
2 changed files with 14 additions and 4 deletions
|
@ -73,12 +73,14 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
auto on_finally = vm.argument(0);
|
auto on_finally = vm.argument(0);
|
||||||
|
|
||||||
// 1. Let promise be the this value.
|
// 1. Let promise be the this value.
|
||||||
|
auto promise = vm.this_value(global_object);
|
||||||
|
|
||||||
// 2. If Type(promise) is not Object, throw a TypeError exception.
|
// 2. If Type(promise) is not Object, throw a TypeError exception.
|
||||||
// FIXME: Don't coerce to object!
|
if (!promise.is_object())
|
||||||
auto* promise = TRY(vm.this_value(global_object).to_object(global_object));
|
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, promise.to_string_without_side_effects());
|
||||||
|
|
||||||
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
|
// 3. Let C be ? SpeciesConstructor(promise, %Promise%).
|
||||||
auto* constructor = TRY(species_constructor(global_object, *promise, *global_object.promise_constructor()));
|
auto* constructor = TRY(species_constructor(global_object, promise.as_object(), *global_object.promise_constructor()));
|
||||||
|
|
||||||
// 4. Assert: IsConstructor(C) is true.
|
// 4. Assert: IsConstructor(C) is true.
|
||||||
VERIFY(constructor);
|
VERIFY(constructor);
|
||||||
|
@ -150,7 +152,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Return ? Invoke(promise, "then", « thenFinally, catchFinally »).
|
// 7. Return ? Invoke(promise, "then", « thenFinally, catchFinally »).
|
||||||
return TRY(Value(promise).invoke(global_object, vm.names.then, then_finally, catch_finally));
|
return TRY(promise.invoke(global_object, vm.names.then, then_finally, catch_finally));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,3 +52,11 @@ describe("normal behavior", () => {
|
||||||
expect(thenFinallyArg).not.toBe(catchFinallyArg);
|
expect(thenFinallyArg).not.toBe(catchFinallyArg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("errors", () => {
|
||||||
|
test("this value must be an object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Promise.prototype.finally.call("foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "foo is not an object");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue