Skip to content
Draft
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
4 changes: 2 additions & 2 deletions core/engine/src/vm/opcode/binary_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{IndexOperand, RegisterOperand};
use crate::{Context, JsResult, error::JsNativeError, vm::opcode::Operation};
use crate::{Context, JsExpect, JsResult, error::JsNativeError, vm::opcode::Operation};

pub(crate) mod logical;
pub(crate) mod macro_defined;
Expand Down Expand Up @@ -129,7 +129,7 @@ impl InPrivate {
.frame()
.environments
.resolve_private_identifier(name)
.expect("private name must be in environment");
.js_expect("private name must be in environment")?;

let value = rhs.private_element_find(&name, true, true).is_some();

Expand Down
14 changes: 7 additions & 7 deletions core/engine/src/vm/opcode/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dynify::Dynify;

use super::{IndexOperand, RegisterOperand};
use crate::{
Context, JsError, JsObject, JsResult, JsValue, NativeFunction,
Context, JsError, JsExpect, JsObject, JsResult, JsValue, NativeFunction,
builtins::{Promise, promise::PromiseCapability},
error::JsNativeError,
job::NativeAsyncJob,
Expand Down Expand Up @@ -107,12 +107,12 @@ impl CallEvalSpread {
let arguments_array = context.vm.stack.pop();
let arguments_array_object = arguments_array
.as_object()
.expect("arguments array in call spread function must be an object");
.js_expect("arguments array in call spread function must be an object")?;
let arguments = arguments_array_object
.borrow()
.properties()
.to_dense_indexed_properties()
.expect("arguments array in call spread function must be dense");
.js_expect("arguments array in call spread function must be dense")?;

let func = context.vm.stack.calling_convention_get_function(0);

Expand Down Expand Up @@ -223,12 +223,12 @@ impl CallSpread {
let arguments_array = context.vm.stack.pop();
let arguments_array_object = arguments_array
.as_object()
.expect("arguments array in call spread function must be an object");
.js_expect("arguments array in call spread function must be an object")?;
let arguments = arguments_array_object
.borrow()
.properties()
.to_dense_indexed_properties()
.expect("arguments array in call spread function must be dense");
.js_expect("arguments array in call spread function must be dense")?;

let argument_count = arguments.len();
context
Expand Down Expand Up @@ -303,13 +303,13 @@ fn parse_import_attributes(
for entry in entries {
let entry = entry
.as_object()
.expect("entry from EnumerableOwnProperties must be an object");
.js_expect("entry from EnumerableOwnProperties must be an object")?;

// 1. Let key be entry.[[Key]].
let key = entry.get(0, context)?;
let key_str = key
.as_string()
.expect("key from EnumerableOwnProperties must be a string")
.js_expect("key from EnumerableOwnProperties must be a string")?
.clone();

// 2. Let value be entry.[[Value]].
Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/vm/opcode/copy/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::RegisterOperand;
use crate::{Context, JsResult, vm::opcode::Operation};
use crate::{Context, JsExpect, JsResult, vm::opcode::Operation};
use thin_vec::ThinVec;

/// `CopyDataProperties` implements the Opcode Operation for `Opcode::CopyDataProperties`
Expand All @@ -22,10 +22,10 @@ impl CopyDataProperties {
let key = context.vm.get_register(key.into()).clone();
excluded_keys.push(
key.to_property_key(context)
.expect("key must be property key"),
.js_expect("key must be property key")?,
);
}
let object = object.as_object().expect("not an object");
let object = object.as_object().js_expect("not an object")?;
object.copy_data_properties(&source, excluded_keys, context)?;
Ok(())
}
Expand Down
13 changes: 6 additions & 7 deletions core/engine/src/vm/opcode/get/name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
Context, JsResult, JsValue,
Context, JsExpect, JsResult, JsValue,
error::JsNativeError,
object::{internal_methods::InternalMethodPropertyContext, shape::slot::SlotAttributes},
property::PropertyKey,
Expand Down Expand Up @@ -62,7 +62,7 @@ impl GetNameGlobal {
let object_borrowed = object.borrow();
if let Some((shape, slot)) = ic.get(object_borrowed.shape()) {
let mut result = if slot.attributes.contains(SlotAttributes::PROTOTYPE) {
let prototype = shape.prototype().expect("prototype should have value");
let prototype = shape.prototype().js_expect("prototype should have value")?;
let prototype = prototype.borrow();
prototype.properties().storage[slot.index as usize].clone()
} else {
Expand All @@ -71,11 +71,10 @@ impl GetNameGlobal {

drop(object_borrowed);
if slot.attributes.has_get() && result.is_object() {
result = result.as_object().expect("should contain getter").call(
&object.clone().into(),
&[],
context,
)?;
result = result
.as_object()
.js_expect("should contain getter")?
.call(&object.clone().into(), &[], context)?;
}
context.vm.set_register(dst.into(), result);
return Ok(());
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/vm/opcode/get/private.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
Context, JsResult,
Context, JsExpect, JsResult,
vm::opcode::{IndexOperand, Operation, RegisterOperand},
};

Expand Down Expand Up @@ -28,7 +28,7 @@ impl GetPrivateField {
.frame()
.environments
.resolve_private_identifier(name)
.expect("private name must be in environment");
.js_expect("private name must be in environment")?;

let result = object.private_get(&name, context)?;
context.vm.set_register(dst.into(), result);
Expand Down
13 changes: 6 additions & 7 deletions core/engine/src/vm/opcode/get/property.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use boa_string::StaticJsStrings;

use crate::{
Context, JsResult, JsValue, js_string,
Context, JsExpect, JsResult, JsValue, js_string,
object::{internal_methods::InternalMethodPropertyContext, shape::slot::SlotAttributes},
property::PropertyKey,
vm::opcode::{IndexOperand, Operation, RegisterOperand},
Expand Down Expand Up @@ -41,7 +41,7 @@ fn get_by_name<const LENGTH: bool>(
let object_borrowed = object.borrow();
if let Some((shape, slot)) = ic.get(object_borrowed.shape()) {
let mut result = if slot.attributes.contains(SlotAttributes::PROTOTYPE) {
let prototype = shape.prototype().expect("prototype should have value");
let prototype = shape.prototype().js_expect("prototype should have value")?;
let prototype = prototype.borrow();
prototype.properties().storage[slot.index as usize].clone()
} else {
Expand All @@ -50,11 +50,10 @@ fn get_by_name<const LENGTH: bool>(

drop(object_borrowed);
if slot.attributes.has_get() && result.is_object() {
result =
result
.as_object()
.expect("should contain getter")
.call(receiver, &[], context)?;
result = result
.as_object()
.js_expect("should contain getter")?
.call(receiver, &[], context)?;
}
context.vm.set_register(dst.into(), result);
return Ok(());
Expand Down
8 changes: 4 additions & 4 deletions core/engine/src/vm/opcode/iteration/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl IteratorNext {
.frame_mut()
.iterators
.pop()
.expect("iterator stack should have at least an iterator");
.js_expect("iterator stack should have at least an iterator")?;

iterator.step(context)?;

Expand Down Expand Up @@ -178,7 +178,7 @@ impl IteratorFinishAsyncNext {
.frame_mut()
.iterators
.pop()
.expect("iterator on the call frame must exist");
.js_expect("iterator on the call frame must exist")?;

let resume_kind = context
.vm
Expand Down Expand Up @@ -249,7 +249,7 @@ impl IteratorValue {
.frame_mut()
.iterators
.pop()
.expect("iterator on the call frame must exist");
.js_expect("iterator on the call frame must exist")?;

let iter_value = iterator.value(context)?;
context.vm.set_register(value.into(), iter_value);
Expand Down Expand Up @@ -358,7 +358,7 @@ impl IteratorToArray {
.frame_mut()
.iterators
.pop()
.expect("iterator on the call frame must exist");
.js_expect("iterator on the call frame must exist")?;

let mut values = Vec::new();

Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/vm/opcode/set/private.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
Context, JsResult, js_str, js_string,
Context, JsExpect, JsResult, js_str, js_string,
object::PrivateElement,
property::PropertyDescriptor,
vm::opcode::{IndexOperand, Operation, RegisterOperand},
Expand Down Expand Up @@ -31,7 +31,7 @@ impl SetPrivateField {
.frame()
.environments
.resolve_private_identifier(name)
.expect("private name must be in environment");
.js_expect("private name must be in environment")?;

base_obj.private_set(&name, value.clone(), context)?;
Ok(())
Expand Down Expand Up @@ -67,7 +67,7 @@ impl DefinePrivateField {

let object = object
.as_object()
.expect("class prototype must be an object");
.js_expect("class prototype must be an object")?;

let name = object.private_name(name);
object.private_field_add(&name, value, context)?;
Expand Down
Loading