diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2019-12-13 19:57:31 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2019-12-17 06:25:22 -0500 |
commit | f589ef816682918dddaf13f9dc06aae5253cd56a (patch) | |
tree | 5b62f711eefd333a6c8e1c529972fd89ce3d4c3d /js/src/builtin | |
parent | e23b013adfffbb33804eef572ff1ebf48923ef26 (diff) | |
download | UXP-f589ef816682918dddaf13f9dc06aae5253cd56a.tar UXP-f589ef816682918dddaf13f9dc06aae5253cd56a.tar.gz UXP-f589ef816682918dddaf13f9dc06aae5253cd56a.tar.lz UXP-f589ef816682918dddaf13f9dc06aae5253cd56a.tar.xz UXP-f589ef816682918dddaf13f9dc06aae5253cd56a.zip |
Bug 1317376 - Part 2: Detect Promise self-resolution when resolving through the Promise resolving fast path.
Tag #1287
Diffstat (limited to 'js/src/builtin')
-rw-r--r-- | js/src/builtin/Promise.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/js/src/builtin/Promise.cpp b/js/src/builtin/Promise.cpp index 18a20ccab..2e4529140 100644 --- a/js/src/builtin/Promise.cpp +++ b/js/src/builtin/Promise.cpp @@ -346,16 +346,28 @@ static MOZ_MUST_USE bool EnqueuePromiseResolveThenableJob(JSContext* cx, HandleValue thenable, HandleValue thenVal); -// ES2016, 25.4.1.3.2, steps 7-13. +// ES2016, 25.4.1.3.2, steps 6-13. static MOZ_MUST_USE bool ResolvePromiseInternal(JSContext* cx, HandleObject promise, HandleValue resolutionVal) { - // Step 7. + // Step 7 (reordered). if (!resolutionVal.isObject()) return FulfillMaybeWrappedPromise(cx, promise, resolutionVal); RootedObject resolution(cx, &resolutionVal.toObject()); + // Step 6. + if (resolution == promise) { + // Step 6.a. + JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, + JSMSG_CANNOT_RESOLVE_PROMISE_WITH_ITSELF); + RootedValue selfResolutionError(cx); + MOZ_ALWAYS_TRUE(GetAndClearException(cx, &selfResolutionError)); + + // Step 6.b. + return RejectMaybeWrappedPromise(cx, promise, selfResolutionError); + } + // Step 8. RootedValue thenVal(cx); bool status = GetProperty(cx, resolution, resolution, cx->names().then, &thenVal); @@ -421,22 +433,6 @@ ResolvePromiseFunction(JSContext* cx, unsigned argc, Value* vp) // functions. Actually marking it as fulfilled/rejected happens later. ClearResolutionFunctionSlots(resolve); - // Step 6. - if (resolutionVal == promiseVal) { - // Step 6.a. - JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, - JSMSG_CANNOT_RESOLVE_PROMISE_WITH_ITSELF); - RootedValue selfResolutionError(cx); - bool status = GetAndClearException(cx, &selfResolutionError); - MOZ_ASSERT(status); - - // Step 6.b. - status = RejectMaybeWrappedPromise(cx, promise, selfResolutionError); - if (status) - args.rval().setUndefined(); - return status; - } - bool status = ResolvePromiseInternal(cx, promise, resolutionVal); if (status) args.rval().setUndefined(); |