Skip to content

Commit e617ba2

Browse files
author
bors-servo
authored
Auto merge of #150 - CYBAI:getpromiseishandled, r=jdm
Support to get PromiseIsHandled internal slot in Promise When trying to implement unhandled rejection in servo/servo#20755, I'd need to check the internal slot of Promise which is the step 4.1.1 for the spec of [notify about rejected promises](https://html.spec.whatwg.org/multipage/webappapis.html#notify-about-rejected-promises). So, this PR will add the API to add the `GetPromiseIsHandled` method. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/mozjs/150) <!-- Reviewable:end -->
2 parents 4a31b2e + e181437 commit e617ba2

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository = "https://github.com/servo/mozjs/"
5-
version = "0.61.0"
5+
version = "0.61.1"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
build = "build.rs"

etc/patches/is_handled.patch

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
diff --git a/mozjs/js/src/jsapi.cpp b/mozjs/js/src/jsapi.cpp
2+
index 94ef1b3ed..06be95062 100644
3+
--- a/mozjs/js/src/jsapi.cpp
4+
+++ b/mozjs/js/src/jsapi.cpp
5+
@@ -5162,6 +5162,14 @@ JS::GetPromiseResult(JS::HandleObject promiseObj)
6+
return promise->state() == JS::PromiseState::Fulfilled ? promise->value() : promise->reason();
7+
}
8+
9+
+JS_PUBLIC_API(bool)
10+
+JS::GetPromiseIsHandled(JS::HandleObject promiseObj)
11+
+{
12+
+ PromiseObject* promise = &promiseObj->as<PromiseObject>();
13+
+ MOZ_ASSERT(promise->state() == JS::PromiseState::Rejected);
14+
+ return !promise->isUnhandled();
15+
+}
16+
+
17+
JS_PUBLIC_API(JSObject*)
18+
JS::GetPromiseAllocationSite(JS::HandleObject promise)
19+
{
20+
diff --git a/mozjs/js/src/jsapi.h b/mozjs/js/src/jsapi.h
21+
index c7f92e273..5c5e9abc5 100644
22+
--- a/mozjs/js/src/jsapi.h
23+
+++ b/mozjs/js/src/jsapi.h
24+
@@ -4390,6 +4390,12 @@ GetPromiseID(JS::HandleObject promise);
25+
extern JS_PUBLIC_API(JS::Value)
26+
GetPromiseResult(JS::HandleObject promise);
27+
28+
+/**
29+
+ * Returns thhe given Promise's internal slot of `isHandled`.
30+
+ */
31+
+extern JS_PUBLIC_API(bool)
32+
+GetPromiseIsHandled(JS::HandleObject promise);
33+
+
34+
/**
35+
* Returns a js::SavedFrame linked list of the stack that lead to the given
36+
* Promise's allocation.

mozjs/js/src/jsapi.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -5162,6 +5162,14 @@ JS::GetPromiseResult(JS::HandleObject promiseObj)
51625162
return promise->state() == JS::PromiseState::Fulfilled ? promise->value() : promise->reason();
51635163
}
51645164

5165+
JS_PUBLIC_API(bool)
5166+
JS::GetPromiseIsHandled(JS::HandleObject promiseObj)
5167+
{
5168+
PromiseObject* promise = &promiseObj->as<PromiseObject>();
5169+
MOZ_ASSERT(promise->state() == JS::PromiseState::Rejected);
5170+
return !promise->isUnhandled();
5171+
}
5172+
51655173
JS_PUBLIC_API(JSObject*)
51665174
JS::GetPromiseAllocationSite(JS::HandleObject promise)
51675175
{

mozjs/js/src/jsapi.h

+6
Original file line numberDiff line numberDiff line change
@@ -4390,6 +4390,12 @@ GetPromiseID(JS::HandleObject promise);
43904390
extern JS_PUBLIC_API(JS::Value)
43914391
GetPromiseResult(JS::HandleObject promise);
43924392

4393+
/**
4394+
* Returns thhe given Promise's internal slot of `isHandled`.
4395+
*/
4396+
extern JS_PUBLIC_API(bool)
4397+
GetPromiseIsHandled(JS::HandleObject promise);
4398+
43934399
/**
43944400
* Returns a js::SavedFrame linked list of the stack that lead to the given
43954401
* Promise's allocation.

0 commit comments

Comments
 (0)