Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/engine/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

use crate::{
Context, JsArgs, JsBigInt, JsResult, JsString, JsValue,
Context, JsArgs, JsBigInt, JsExpect, JsResult, JsString, JsValue,
builtins::BuiltInObject,
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError,
Expand Down Expand Up @@ -122,7 +122,12 @@ impl BigInt {
}

// 2. Return the BigInt value that represents ℝ(number).
Ok(JsBigInt::from(number.to_bigint().expect("This conversion must be safe")).into())
Ok(JsBigInt::from(
number
.to_bigint()
.js_expect("This conversion must be safe")?,
)
.into())
}

/// The abstract operation `thisBigIntValue` takes argument value.
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/error/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError

use crate::{
Context, JsArgs, JsResult, JsString, JsValue,
Context, JsArgs, JsExpect, JsResult, JsString, JsValue,
builtins::{
Array, BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject,
iterable::IteratorHint,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl BuiltInConstructor for AggregateError {
.build(),
context,
)
.expect("should not fail according to spec");
.js_expect("should not fail according to spec")?;

// 5. Return O.
Ok(o.into())
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

use crate::{
Context, JsArgs, JsResult, JsString, JsValue, SpannedSourceText,
Context, JsArgs, JsExpect, JsResult, JsString, JsValue, SpannedSourceText,
builtins::{BuiltInObject, function::OrdinaryFunction},
bytecompiler::{ByteCompiler, prepare_eval_declaration_instantiation},
context::intrinsics::Intrinsics,
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Eval {
.slots()
.function_object()
.downcast_ref::<OrdinaryFunction>()
.expect("must be function object");
.js_expect("must be function object")?;

// ii. Set inFunction to true.
let mut flags = Flags::IN_FUNCTION;
Expand Down
26 changes: 17 additions & 9 deletions core/engine/src/builtins/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator

use crate::{
Context, JsArgs, JsData, JsError, JsResult, JsString,
Context, JsArgs, JsData, JsError, JsExpect, JsResult, JsString,
builtins::iterable::create_iter_result_object,
context::intrinsics::Intrinsics,
error::JsNativeError,
error::PanicError,
js_string,
object::{CONSTRUCTOR, JsObject},
property::Attribute,
Expand Down Expand Up @@ -101,7 +102,9 @@ impl GeneratorContext {
context: &mut Context,
) -> CompletionRecord {
std::mem::swap(&mut context.vm.stack, &mut self.stack);
let frame = self.call_frame.take().expect("should have a call frame");
let Some(frame) = self.call_frame.take() else {
return CompletionRecord::Throw(PanicError::new("should have a call frame").into());
};
let fp = frame.fp;
let rp = frame.rp;
context.vm.push_frame(frame);
Expand All @@ -125,16 +128,21 @@ impl GeneratorContext {
}

/// Returns the async generator object, if the function that this [`GeneratorContext`] is from an async generator, [`None`] otherwise.
pub(crate) fn async_generator_object(&self) -> Option<JsObject> {
let frame = self.call_frame.as_ref()?;
pub(crate) fn async_generator_object(&self) -> JsResult<Option<JsObject>> {
let Some(frame) = self.call_frame.as_ref() else {
return Ok(None);
};

if !frame.code_block().is_async_generator() {
return None;
return Ok(None);
}

self.stack
let val = self
.stack
.get_register(frame, CallFrame::ASYNC_GENERATOR_OBJECT_REGISTER_INDEX)
.expect("registers must have an async generator object")
.as_object()
.js_expect("registers must have an async generator object")?;

Ok(val.as_object())
}
}

Expand Down Expand Up @@ -306,7 +314,7 @@ impl Generator {

let mut r#gen = generator_obj
.downcast_mut::<Self>()
.expect("already checked this object type");
.js_expect("already checked this object type")?;

// 8. Push genContext onto the execution context stack; genContext is now the running execution context.
// 9. Resume the suspended evaluation of genContext using NormalCompletion(value) as the result of the operation that suspended it. Let result be the value returned by the resumed computation.
Expand Down
18 changes: 9 additions & 9 deletions core/engine/src/builtins/iterable/async_from_sync_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
Context, JsArgs, JsData, JsError, JsNativeError, JsResult, JsValue,
Context, JsArgs, JsData, JsError, JsExpect, JsNativeError, JsResult, JsValue,
builtins::{
BuiltInBuilder, IntrinsicObject, Promise,
iterable::{IteratorRecord, IteratorResult, create_iter_result_object},
Expand Down Expand Up @@ -99,7 +99,7 @@ impl AsyncFromSyncIterator {
let mut sync_iterator_record = object
.as_ref()
.and_then(JsObject::downcast_ref::<Self>)
.expect("async from sync iterator prototype must be object")
.js_expect("async from sync iterator prototype must be object")?
.sync_iterator_record
.clone();

Expand All @@ -108,7 +108,7 @@ impl AsyncFromSyncIterator {
&context.intrinsics().constructors().promise().constructor(),
context,
)
.expect("cannot fail with promise constructor");
.js_expect("cannot fail with promise constructor")?;

// 5. If value is present, then
// a. Let result be Completion(IteratorNext(syncIteratorRecord, value)).
Expand Down Expand Up @@ -143,7 +143,7 @@ impl AsyncFromSyncIterator {
let sync_iterator_record = object
.as_ref()
.and_then(JsObject::downcast_ref::<Self>)
.expect("async from sync iterator prototype must be object")
.js_expect("async from sync iterator prototype must be object")?
.sync_iterator_record
.clone();
// 5. Let syncIterator be syncIteratorRecord.[[Iterator]].
Expand All @@ -154,7 +154,7 @@ impl AsyncFromSyncIterator {
&context.intrinsics().constructors().promise().constructor(),
context,
)
.expect("cannot fail with promise constructor");
.js_expect("cannot fail with promise constructor")?;

// 6. Let return be Completion(GetMethod(syncIterator, "return")).
let r#return = sync_iterator.get_method(js_string!("return"), context);
Expand All @@ -173,7 +173,7 @@ impl AsyncFromSyncIterator {
promise_capability
.resolve()
.call(&JsValue::undefined(), &[iter_result], context)
.expect("cannot fail according to spec");
.js_expect("cannot fail according to spec")?;

// c. Return promiseCapability.[[Promise]].
return Ok(promise_capability.promise().clone().into());
Expand Down Expand Up @@ -225,7 +225,7 @@ impl AsyncFromSyncIterator {
let sync_iterator_record = object
.as_ref()
.and_then(JsObject::downcast_ref::<Self>)
.expect("async from sync iterator prototype must be object")
.js_expect("async from sync iterator prototype must be object")?
.sync_iterator_record
.clone();
// 5. Let syncIterator be syncIteratorRecord.[[Iterator]].
Expand All @@ -236,7 +236,7 @@ impl AsyncFromSyncIterator {
&context.intrinsics().constructors().promise().constructor(),
context,
)
.expect("cannot fail with promise constructor");
.js_expect("cannot fail with promise constructor")?;

// 6. Let throw be Completion(GetMethod(syncIterator, "throw")).
let throw = sync_iterator.get_method(js_string!("throw"), context);
Expand Down Expand Up @@ -267,7 +267,7 @@ impl AsyncFromSyncIterator {
.into()],
context,
)
.expect("cannot fail according to spec");
.js_expect("cannot fail according to spec")?;

// h. Return promiseCapability.[[Promise]].
return Ok(promise_capability.promise().clone().into());
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ impl Json {

// 5. Perform ! CreateDataPropertyOrThrow(obj, "rawJSON", jsonString).
obj.create_data_property_or_throw(js_string!("rawJSON"), json_string, context)
.expect("CreateDataPropertyOrThrow should never throw here");
.js_expect("CreateDataPropertyOrThrow should never throw here")?;

// 6. Perform ! SetIntegrityLevel(obj, frozen).
obj.set_integrity_level(IntegrityLevel::Frozen, context)
.expect("SetIntegrityLevel should never throw here");
.js_expect("SetIntegrityLevel should never throw here")?;

// 7. Return obj.
Ok(obj.into())
Expand Down
8 changes: 4 additions & 4 deletions core/engine/src/builtins/promise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,10 @@ impl Promise {
js_string!("fulfilled"),
context,
)
.expect("cannot fail per spec");
.js_expect("cannot fail per spec")?;
// c. Perform ! CreateDataPropertyOrThrow(obj, "value", x).
obj.create_data_property_or_throw(js_string!("value"), x, context)
.expect("cannot fail per spec");
.js_expect("cannot fail per spec")?;
// d. Set values[index] to obj.
captures.values.borrow_mut()[captures.index] = obj.into();
}
Expand Down Expand Up @@ -1374,10 +1374,10 @@ impl Promise {
js_string!("rejected"),
context,
)
.expect("cannot fail per spec");
.js_expect("cannot fail per spec")?;
// 5. Perform ! CreateDataPropertyOrThrow(obj, "reason", x).
obj.create_data_property_or_throw(js_string!("reason"), x, context)
.expect("cannot fail per spec");
.js_expect("cannot fail per spec")?;
// 6. Set values[index] to obj.
captures.values.borrow_mut()[captures.index] = obj.into();

Expand Down
Loading
Loading