feat: 支持 to_string 与错误栈
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use oxide_compiler::compiler::Compiler;
|
||||
use oxide_types::value::JsValue;
|
||||
use oxide_vm::builtins::error;
|
||||
use oxide_vm::vm::Vm;
|
||||
|
||||
@@ -5,6 +7,14 @@ fn make_vm() -> Vm {
|
||||
Vm::new()
|
||||
}
|
||||
|
||||
fn eval(source: &str) -> Result<JsValue, String> {
|
||||
let allocator = oxide_parser::Allocator::default();
|
||||
let program = oxide_parser::parse(&allocator, source).map_err(|e| format!("Parse: {}", e))?;
|
||||
let module = Compiler::new().compile(&program).map_err(|e| format!("Compile: {}", e))?;
|
||||
let mut vm = make_vm();
|
||||
vm.run(&module)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_constructor_creates_object() {
|
||||
let mut vm = make_vm();
|
||||
@@ -107,3 +117,21 @@ fn error_name_is_string_property() {
|
||||
let n = obj.prop_count();
|
||||
assert!(n >= 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn error_to_string_returns_string() {
|
||||
let result = eval("new Error('test').toString()").unwrap();
|
||||
assert!(result.is_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_error_is_defined() {
|
||||
let result = eval("typeof TypeError").unwrap();
|
||||
assert!(result.is_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_error_is_defined() {
|
||||
let result = eval("typeof ReferenceError").unwrap();
|
||||
assert!(result.is_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user