Skip to content

Commit 3d8ca6a

Browse files
authored
fix(jspromise): convert panics to EngineError::Panic using js_expect (boa-dev#4875)
Part of boa-dev#3241 Converts all 23 panics in jspromise.rs to EngineError::Panic using js_expect introduced in boa-dev#4828. Patterns converted: - `.js_expect()` on internal promise operations that cannot fail - `.js_expect().map_err(Into::into)` for methods returning `JsResult<JsPromise>` Signature changes: - `resolve()`, `reject()`, `from_result()` → `JsResult<Self>` - `then()`, `catch()`, `finally()` → `JsResult<JsPromise>` - `all()`, `all_settled()`, `any()`, `race()` → `JsResult<JsPromise>` - `into_js_future()` → `JsResult<JsFuture>` Files modified: 6
1 parent faaf64d commit 3d8ca6a

6 files changed

Lines changed: 132 additions & 97 deletions

File tree

core/engine/src/builtins/array/from_async.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Array {
116116
from_array_like(Ok(JsValue::undefined()), &coroutine_state, context)?
117117
{
118118
// Coroutine yielded. We need to allocate it for a future execution.
119-
JsPromise::resolve(value, context).await_native(
119+
JsPromise::resolve(value, context)?.await_native(
120120
NativeCoroutine::from_copy_closure_with_captures(
121121
from_array_like,
122122
coroutine_state,
@@ -161,7 +161,7 @@ impl Array {
161161
if let CoroutineState::Yielded(value) =
162162
from_async_iterator(Ok(JsValue::undefined()), &coroutine_state, context)?
163163
{
164-
JsPromise::resolve(value, context).await_native(
164+
JsPromise::resolve(value, context)?.await_native(
165165
NativeCoroutine::from_copy_closure_with_captures(
166166
from_async_iterator,
167167
coroutine_state,
@@ -449,7 +449,7 @@ fn from_async_iterator(
449449

450450
// i. Assert: result is a throw completion.
451451
Err(err) => {
452-
// ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
452+
// ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
453453
global_state
454454
.resolvers
455455
.reject
@@ -610,7 +610,7 @@ fn from_array_like(
610610
Ok(cont) => Ok(cont),
611611
// i. Assert: result is a throw completion.
612612
Err(err) => {
613-
// ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
613+
// ii. Perform ! Call(promiseCapability.[[Reject]], undefined, « result.[[Value]] »).
614614
global_state
615615
.resolvers
616616
.reject

core/engine/src/module/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ impl Module {
658658
None,
659659
context,
660660
)
661+
.expect("`then` cannot fail for a native `JsPromise`")
661662
.then(
662663
Some(
663664
NativeFunction::from_copy_closure_with_captures(
@@ -669,6 +670,7 @@ impl Module {
669670
None,
670671
context,
671672
)
673+
.expect("`then` cannot fail for a native `JsPromise`")
672674
}
673675

674676
/// Abstract operation [`GetModuleNamespace ( module )`][spec].

core/engine/src/module/synthetic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ impl SyntheticModule {
257257
///
258258
/// [spec]: https://tc39.es/proposal-json-modules/#sec-smr-LoadRequestedModules
259259
pub(super) fn load(context: &mut Context) -> JsPromise {
260-
// 1. Return ! PromiseResolve(%Promise%, undefined).
261260
JsPromise::resolve(JsValue::undefined(), context)
261+
.expect("default resolve functions cannot throw and must return a promise")
262262
}
263263

264264
/// Concrete method [`GetExportedNames ( [ exportStarSet ] )`][spec].

0 commit comments

Comments
 (0)