mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-15 00:18:06 -05:00
Make native functions const aware
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::native_function::ThisWrapper;
|
||||
use crate::stack_frame::FrameStepResult;
|
||||
use crate::stack_frame::{CallResult, FrameStepOk, StackFrameTrait};
|
||||
use crate::vs_array::VsArray;
|
||||
@@ -86,7 +87,7 @@ impl StackFrameTrait for ArrayMappingFrame {
|
||||
array_i,
|
||||
el,
|
||||
native_fn(
|
||||
&mut self.this_arg.clone(),
|
||||
ThisWrapper::new(false, &mut self.this_arg.clone()),
|
||||
vec![
|
||||
el.clone(),
|
||||
Val::Number(array_i as f64),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::native_frame_function::NativeFrameFunction;
|
||||
use crate::native_function::ThisWrapper;
|
||||
use crate::stack_frame::{CallResult, FrameStepOk, FrameStepResult, StackFrameTrait};
|
||||
use crate::vs_array::VsArray;
|
||||
use crate::vs_value::{LoadFunctionResult, Val, ValTrait};
|
||||
@@ -67,7 +68,7 @@ impl StackFrameTrait for ReduceFrame {
|
||||
LoadFunctionResult::NotAFunction => return type_error!("reduce fn is not a function"),
|
||||
LoadFunctionResult::NativeFunction(native_fn) => {
|
||||
self.value = Some(native_fn(
|
||||
&mut Val::Undefined,
|
||||
ThisWrapper::new(true, &mut Val::Undefined),
|
||||
vec![
|
||||
value.clone(),
|
||||
el.clone(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::native_frame_function::NativeFrameFunction;
|
||||
use crate::native_function::ThisWrapper;
|
||||
use crate::stack_frame::{CallResult, FrameStepOk, FrameStepResult, StackFrameTrait};
|
||||
use crate::vs_array::VsArray;
|
||||
use crate::vs_value::{LoadFunctionResult, Val, ValTrait};
|
||||
@@ -89,7 +90,7 @@ impl StackFrameTrait for ReduceRightFrame {
|
||||
}
|
||||
LoadFunctionResult::NativeFunction(native_fn) => {
|
||||
self.value = Some(native_fn(
|
||||
&mut Val::Undefined,
|
||||
ThisWrapper::new(true, &mut Val::Undefined),
|
||||
vec![
|
||||
value.clone(),
|
||||
el.clone(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::native_frame_function::NativeFrameFunction;
|
||||
use crate::native_function::ThisWrapper;
|
||||
use crate::stack_frame::FrameStepResult;
|
||||
use crate::stack_frame::{CallResult, FrameStepOk, StackFrameTrait};
|
||||
use crate::vs_array::VsArray;
|
||||
@@ -271,7 +272,11 @@ impl StackFrameTrait for SortFrame {
|
||||
return type_error!("comparator is not a function");
|
||||
}
|
||||
LoadFunctionResult::NativeFunction(native_fn) => {
|
||||
let res = native_fn(&mut Val::Undefined, vec![left, right])?.to_number();
|
||||
let res = native_fn(
|
||||
ThisWrapper::new(true, &mut Val::Undefined),
|
||||
vec![left, right],
|
||||
)?
|
||||
.to_number();
|
||||
|
||||
let should_swap = match res.is_nan() {
|
||||
true => false,
|
||||
|
||||
Reference in New Issue
Block a user