|
|
|
@ -12,12 +12,9 @@
|
|
|
|
|
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
|
|
|
|
|
|
|
|
|
|
use crate::{ |
|
|
|
|
builtins::{ |
|
|
|
|
function::make_builtin_fn, |
|
|
|
|
value::{ResultValue, Value}, |
|
|
|
|
}, |
|
|
|
|
builtins::{function::make_builtin_fn, value::Value}, |
|
|
|
|
exec::Interpreter, |
|
|
|
|
BoaProfiler, |
|
|
|
|
BoaProfiler, Result, |
|
|
|
|
}; |
|
|
|
|
use std::f64; |
|
|
|
|
|
|
|
|
@ -40,7 +37,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.abs
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
|
|
|
|
|
pub(crate) fn abs(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn abs(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -57,7 +54,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.acos
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos
|
|
|
|
|
pub(crate) fn acos(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn acos(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -74,7 +71,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.acosh
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh
|
|
|
|
|
pub(crate) fn acosh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn acosh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -91,7 +88,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.asin
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin
|
|
|
|
|
pub(crate) fn asin(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn asin(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -108,7 +105,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.asinh
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh
|
|
|
|
|
pub(crate) fn asinh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn asinh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -125,7 +122,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.atan
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan
|
|
|
|
|
pub(crate) fn atan(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn atan(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -142,7 +139,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.atanh
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh
|
|
|
|
|
pub(crate) fn atanh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn atanh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -159,7 +156,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.atan2
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2
|
|
|
|
|
pub(crate) fn atan2(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn atan2(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(match ( |
|
|
|
|
args.get(0).map(|x| x.to_number(ctx)).transpose()?, |
|
|
|
|
args.get(1).map(|x| x.to_number(ctx)).transpose()?, |
|
|
|
@ -178,7 +175,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.cbrt
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt
|
|
|
|
|
pub(crate) fn cbrt(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn cbrt(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -195,7 +192,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.ceil
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil
|
|
|
|
|
pub(crate) fn ceil(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn ceil(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -212,7 +209,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.clz32
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
|
|
|
|
|
pub(crate) fn clz32(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn clz32(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_u32(ctx)) |
|
|
|
@ -230,7 +227,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.cos
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos
|
|
|
|
|
pub(crate) fn cos(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn cos(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -247,7 +244,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.cosh
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh
|
|
|
|
|
pub(crate) fn cosh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn cosh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -264,7 +261,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.exp
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp
|
|
|
|
|
pub(crate) fn exp(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn exp(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -283,7 +280,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.expm1
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1
|
|
|
|
|
pub(crate) fn expm1(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn expm1(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -300,7 +297,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.floor
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor
|
|
|
|
|
pub(crate) fn floor(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn floor(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -317,7 +314,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.fround
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
|
|
|
|
|
pub(crate) fn fround(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn fround(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -334,7 +331,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.hypot
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot
|
|
|
|
|
pub(crate) fn hypot(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn hypot(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
let mut result = 0f64; |
|
|
|
|
for arg in args { |
|
|
|
|
let x = arg.to_number(ctx)?; |
|
|
|
@ -351,7 +348,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.imul
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
|
|
|
|
|
pub(crate) fn imul(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn imul(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(match ( |
|
|
|
|
args.get(0).map(|x| x.to_u32(ctx)).transpose()?, |
|
|
|
|
args.get(1).map(|x| x.to_u32(ctx)).transpose()?, |
|
|
|
@ -370,7 +367,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.log
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log
|
|
|
|
|
pub(crate) fn log(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn log(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -387,7 +384,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.log1p
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p
|
|
|
|
|
pub(crate) fn log1p(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn log1p(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -404,7 +401,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.log10
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10
|
|
|
|
|
pub(crate) fn log10(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn log10(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -421,7 +418,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.log2
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2
|
|
|
|
|
pub(crate) fn log2(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn log2(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -438,7 +435,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.max
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max
|
|
|
|
|
pub(crate) fn max(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn max(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
let mut max = f64::NEG_INFINITY; |
|
|
|
|
for arg in args { |
|
|
|
|
let num = arg.to_number(ctx)?; |
|
|
|
@ -455,7 +452,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.min
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min
|
|
|
|
|
pub(crate) fn min(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn min(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
let mut min = f64::INFINITY; |
|
|
|
|
for arg in args { |
|
|
|
|
let num = arg.to_number(ctx)?; |
|
|
|
@ -472,7 +469,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.pow
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
|
|
|
|
|
pub(crate) fn pow(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn pow(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(match ( |
|
|
|
|
args.get(0).map(|x| x.to_number(ctx)).transpose()?, |
|
|
|
|
args.get(1).map(|x| x.to_number(ctx)).transpose()?, |
|
|
|
@ -491,7 +488,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.random
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
|
|
|
|
|
pub(crate) fn random(_: &Value, _: &[Value], _: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn random(_: &Value, _: &[Value], _: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(rand::random::<f64>().into()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -503,7 +500,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.round
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
|
|
|
|
|
pub(crate) fn round(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn round(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -520,7 +517,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.sign
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
|
|
|
|
|
pub(crate) fn sign(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn sign(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -546,7 +543,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.sin
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin
|
|
|
|
|
pub(crate) fn sin(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn sin(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -563,7 +560,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.sinh
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh
|
|
|
|
|
pub(crate) fn sinh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn sinh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -580,7 +577,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.sqrt
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt
|
|
|
|
|
pub(crate) fn sqrt(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn sqrt(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -597,7 +594,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.tan
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan
|
|
|
|
|
pub(crate) fn tan(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn tan(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -614,7 +611,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.tanh
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh
|
|
|
|
|
pub(crate) fn tanh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn tanh(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
@ -631,7 +628,7 @@ impl Math {
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-math.trunc
|
|
|
|
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
|
|
|
|
|
pub(crate) fn trunc(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultValue { |
|
|
|
|
pub(crate) fn trunc(_: &Value, args: &[Value], ctx: &mut Interpreter) -> Result<Value> { |
|
|
|
|
Ok(args |
|
|
|
|
.get(0) |
|
|
|
|
.map(|x| x.to_number(ctx)) |
|
|
|
|