Skip to content
Open
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
16 changes: 5 additions & 11 deletions core/engine/src/builtins/date/mod.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/Date

use crate::{
Context, JsArgs, JsData, JsError, JsResult, JsString,
Context, JsArgs, JsData, JsResult, JsString,
builtins::{
BuiltInBuilder, BuiltInConstructor, BuiltInObject, IntrinsicObject,
date::utils::{
Expand All @@ -21,7 +21,7 @@ use crate::{
},
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
error::JsNativeError,
js_string,
js_error, js_string,
object::{JsObject, internal_methods::get_prototype_from_constructor},
property::Attribute,
realm::Realm,
Expand Down Expand Up @@ -1623,9 +1623,7 @@ impl Date {
_args: &[JsValue],
_context: &mut Context,
) -> JsResult<JsValue> {
Err(JsError::from_opaque(JsValue::new(js_string!(
"Function Unimplemented"
))))
Err(js_error!("Function Unimplemented"))
}

/// [`Date.prototype.toLocaleString()`][spec].
Expand All @@ -1642,9 +1640,7 @@ impl Date {
_: &[JsValue],
_context: &mut Context,
) -> JsResult<JsValue> {
Err(JsError::from_opaque(JsValue::new(js_string!(
"Function Unimplemented]"
))))
Err(js_error!("Function Unimplemented"))
}

/// [`Date.prototype.toLocaleTimeString()`][spec].
Expand All @@ -1662,9 +1658,7 @@ impl Date {
_args: &[JsValue],
_context: &mut Context,
) -> JsResult<JsValue> {
Err(JsError::from_opaque(JsValue::new(js_string!(
"Function Unimplemented]"
))))
Err(js_error!("Function Unimplemented"))
}

/// [`Date.prototype.toString()`][spec].
Expand Down
6 changes: 3 additions & 3 deletions core/engine/src/interop/into_js_function_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::private::IntoJsFunctionSealed;
use super::{IntoJsFunctionCopied, UnsafeIntoJsFunction};
use crate::interop::{JsRest, TryFromJsArgument};
use crate::{Context, JsError, NativeFunction, TryIntoJsResult, js_string};
use crate::{Context, NativeFunction, TryIntoJsResult};
use std::cell::RefCell;

/// A token to represent the context argument in the function signature.
Expand Down Expand Up @@ -59,7 +59,7 @@ macro_rules! impl_into_js_function {
match s.try_borrow_mut() {
Ok(mut r) => r( $($id,)* ).try_into_js_result(ctx),
Err(_) => {
Err(JsError::from_opaque(js_string!("recursive calls to this function not supported").into()))
Err($crate::js_error!(ReferenceError: "recursive calls to this function not supported"))
}
}
})
Expand All @@ -85,7 +85,7 @@ macro_rules! impl_into_js_function {
match s.try_borrow_mut() {
Ok(mut r) => r( $($id,)* rest.into() ).try_into_js_result(ctx),
Err(_) => {
Err(JsError::from_opaque(js_string!("recursive calls to this function not supported").into()))
Err($crate::js_error!(ReferenceError: "recursive calls to this function not supported"))
}
}
})
Expand Down
24 changes: 7 additions & 17 deletions core/engine/src/module/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@ pub fn resolve_module_specifier(
if let Some(r_path) = referrer_dir {
base_path.join(r_path).join(short_path)
} else {
return Err(JsError::from_opaque(
js_string!("relative path without referrer").into(),
));
return Err(js_error!(TypeError: "relative path without referrer"));
}
} else {
base_path.join(&specifier)
};

if long_path.is_relative() && base.is_some() {
return Err(JsError::from_opaque(
js_string!("resolved path is relative").into(),
));
return Err(js_error!(TypeError: "resolved path is relative"));
}

// Normalize the path. We cannot use `canonicalize` here because it will fail
Expand All @@ -96,9 +92,7 @@ pub fn resolve_module_specifier(
.try_fold(PathBuf::new(), |mut acc, c| {
if c == Component::ParentDir {
if acc.as_os_str().is_empty() {
return Err(JsError::from_opaque(
js_string!("path is outside the module root").into(),
));
return Err(js_error!(TypeError: "path is outside the module root"));
}
acc.pop();
} else {
Expand All @@ -110,9 +104,7 @@ pub fn resolve_module_specifier(
if path.starts_with(&base_path) {
Ok(path)
} else {
Err(JsError::from_opaque(
js_string!("path is outside the module root").into(),
))
Err(js_error!(TypeError: "path is outside the module root"))
}
}

Expand Down Expand Up @@ -320,7 +312,7 @@ impl SimpleModuleLoader {
let absolute = root.canonicalize().map_err(|e| {
JsNativeError::typ()
.with_message(format!("could not set module root `{}`", root.display()))
.with_cause(JsError::from_opaque(js_string!(e.to_string()).into()))
.with_cause(JsError::from_rust(e))
})?;
Ok(Self {
root: absolute,
Expand Down Expand Up @@ -416,9 +408,7 @@ impl ModuleLoader for SimpleModuleLoader {
let json_content = std::fs::read_to_string(&path).map_err(|err| {
JsNativeError::typ()
.with_message(format!("could not open file `{short_path}`"))
.with_cause(JsError::from_opaque(
js_string!(err.to_string()).into(),
))
.with_cause(JsError::from_rust(err))
})?;
let json_string = js_string!(json_content.as_str());
Module::parse_json(json_string, &mut context.borrow_mut()).map_err(
Expand All @@ -445,7 +435,7 @@ impl ModuleLoader for SimpleModuleLoader {
let source = Source::from_filepath(&path).map_err(|err| {
JsNativeError::typ()
.with_message(format!("could not open file `{short_path}`"))
.with_cause(JsError::from_opaque(js_string!(err.to_string()).into()))
.with_cause(JsError::from_rust(err))
})?;
Module::parse(source, None, &mut context.borrow_mut()).map_err(|err| {
JsNativeError::syntax()
Expand Down
Loading