use crate::runner::ds::error::JErrorType;
use crate::runner::ds::value::JsValue;
use crate::runner::plugin::registry::BuiltInRegistry;
use crate::runner::plugin::types::{BuiltInObject, EvalContext};
pub fn register(registry: &mut BuiltInRegistry) {
let array = BuiltInObject::new("Array")
.with_constructor(array_constructor)
.add_method("push", array_push)
.add_method("pop", array_pop)
.add_method("shift", array_shift)
.add_method("unshift", array_unshift)
.add_method("slice", array_slice)
.add_method("splice", array_splice)
.add_method("indexOf", array_index_of)
.add_method("includes", array_includes)
.add_method("forEach", array_for_each)
.add_method("map", array_map)
.add_method("filter", array_filter)
.add_method("reduce", array_reduce)
.add_method("find", array_find)
.add_method("every", array_every)
.add_method("some", array_some)
.add_method("join", array_join)
.add_method("concat", array_concat)
.add_method("reverse", array_reverse)
.add_method("sort", array_sort)
.add_method("isArray", is_array);
registry.register_object(array);
}
fn array_constructor(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array constructor not yet implemented".to_string()))
}
fn array_push(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.push not yet implemented".to_string()))
}
fn array_pop(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.pop not yet implemented".to_string()))
}
fn array_shift(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.shift not yet implemented".to_string()))
}
fn array_unshift(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.unshift not yet implemented".to_string()))
}
fn array_slice(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.slice not yet implemented".to_string()))
}
fn array_splice(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.splice not yet implemented".to_string()))
}
fn array_index_of(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.indexOf not yet implemented".to_string()))
}
fn array_includes(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.includes not yet implemented".to_string()))
}
fn array_for_each(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.forEach not yet implemented".to_string()))
}
fn array_map(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.map not yet implemented".to_string()))
}
fn array_filter(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.filter not yet implemented".to_string()))
}
fn array_reduce(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.reduce not yet implemented".to_string()))
}
fn array_find(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.find not yet implemented".to_string()))
}
fn array_every(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.every not yet implemented".to_string()))
}
fn array_some(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.some not yet implemented".to_string()))
}
fn array_join(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.join not yet implemented".to_string()))
}
fn array_concat(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.concat not yet implemented".to_string()))
}
fn array_reverse(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.reverse not yet implemented".to_string()))
}
fn array_sort(
_ctx: &mut EvalContext,
_this: JsValue,
_args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
Err(JErrorType::TypeError("Array.sort not yet implemented".to_string()))
}
fn is_array(
_ctx: &mut EvalContext,
_this: JsValue,
args: Vec<JsValue>,
) -> Result<JsValue, JErrorType> {
if args.is_empty() {
return Ok(JsValue::Boolean(false));
}
Ok(JsValue::Boolean(false))
}