Implement to_val_string on Val and avoid conversion when already string

This commit is contained in:
Andrew Morris
2023-05-26 13:53:27 +10:00
parent bc89575eae
commit 4814329eca
16 changed files with 49 additions and 50 deletions

View File

@@ -8,7 +8,7 @@ use crate::builtins::type_error_builtin::ToTypeError;
use crate::vs_array::VsArray;
use crate::vs_class::VsClass;
use crate::vs_object::VsObject;
use crate::vs_value::{LoadFunctionResult, ToVal, ToValString, Val, ValTrait, VsType};
use crate::vs_value::{LoadFunctionResult, ToVal, Val, ValTrait, VsType};
pub struct ThisWrapper<'a> {
const_: bool,
@@ -51,7 +51,7 @@ impl ValTrait for NativeFunction {
false
}
fn to_primitive(&self) -> Val {
self.to_val_string()
self.to_string().to_val()
}
fn is_truthy(&self) -> bool {
true