mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
LibJS: Don't coerce this value to object in Promise.resolve()
This commit is contained in:
parent
cd391aa8ef
commit
53ec432e8d
2 changed files with 13 additions and 3 deletions
|
@ -519,12 +519,14 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::resolve)
|
||||||
auto value = vm.argument(0);
|
auto value = vm.argument(0);
|
||||||
|
|
||||||
// 1. Let C be the this value.
|
// 1. Let C be the this value.
|
||||||
|
auto constructor = vm.this_value(global_object);
|
||||||
|
|
||||||
// 2. If Type(C) is not Object, throw a TypeError exception.
|
// 2. If Type(C) is not Object, throw a TypeError exception.
|
||||||
// FIXME: Don't coerce to object!
|
if (!constructor.is_object())
|
||||||
auto* constructor = TRY(vm.this_value(global_object).to_object(global_object));
|
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, constructor.to_string_without_side_effects());
|
||||||
|
|
||||||
// 3. Return ? PromiseResolve(C, x).
|
// 3. Return ? PromiseResolve(C, x).
|
||||||
return TRY(promise_resolve(global_object, *constructor, value));
|
return TRY(promise_resolve(global_object, constructor.as_object(), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 27.2.4.8 get Promise [ @@species ], https://tc39.es/ecma262/#sec-get-promise-@@species
|
// 27.2.4.8 get Promise [ @@species ], https://tc39.es/ecma262/#sec-get-promise-@@species
|
||||||
|
|
|
@ -31,3 +31,11 @@ describe("normal behavior", () => {
|
||||||
expect(fulfillmentValue).toBe("Some value");
|
expect(fulfillmentValue).toBe("Some value");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("errors", () => {
|
||||||
|
test("this value must be an object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Promise.resolve.call("foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "foo is not an object");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue