本文整理汇总了C++中JS::ToNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ JS::ToNumber方法的具体用法?C++ JS::ToNumber怎么用?C++ JS::ToNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JS
的用法示例。
在下文中一共展示了JS::ToNumber方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
js::minmax_impl(JSContext *cx, bool max, HandleValue a, HandleValue b, MutableHandleValue res)
{
double x, y;
if (!ToNumber(cx, a, &x))
return false;
if (!ToNumber(cx, b, &y))
return false;
if (max)
res.setNumber(max_double(x, y));
else
res.setNumber(min_double(x, y));
return true;
}
示例2: CallArgsFromVp
bool
js::math_atan2(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
double y;
if (!ToNumber(cx, args.get(0), &y))
return false;
double x;
if (!ToNumber(cx, args.get(1), &x))
return false;
double z = ecmaAtan2(y, x);
args.rval().setDouble(z);
return true;
}
示例3: ecmaHypot
bool
js::math_hypot_handle(JSContext* cx, HandleValueArray args, MutableHandleValue res)
{
// IonMonkey calls the system hypot function directly if two arguments are
// given. Do that here as well to get the same results.
if (args.length() == 2) {
double x, y;
if (!ToNumber(cx, args[0], &x))
return false;
if (!ToNumber(cx, args[1], &y))
return false;
double result = ecmaHypot(x, y);
res.setNumber(result);
return true;
}
bool isInfinite = false;
bool isNaN = false;
double scale = 0;
double sumsq = 1;
for (unsigned i = 0; i < args.length(); i++) {
double x;
if (!ToNumber(cx, args[i], &x))
return false;
isInfinite |= mozilla::IsInfinite(x);
isNaN |= mozilla::IsNaN(x);
if (isInfinite || isNaN)
continue;
hypot_step(scale, sumsq, x);
}
double result = isInfinite ? PositiveInfinity<double>() :
isNaN ? GenericNaN() :
scale * sqrt(sumsq);
res.setNumber(result);
return true;
}
示例4:
bool
js::math_ceil_handle(JSContext* cx, HandleValue v, MutableHandleValue res)
{
double d;
if(!ToNumber(cx, v, &d))
return false;
double result = math_ceil_impl(d);
res.setNumber(result);
return true;
}
示例5: CallArgsFromVp
bool
js::math_fround(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() == 0) {
args.rval().setNaN();
return true;
}
double x;
if (!ToNumber(cx, args[0], &x))
return false;
float f = x;
args.rval().setDouble(static_cast<double>(f));
return true;
}