本文整理匯總了C++中DOUBLE_TO_JSVAL函數的典型用法代碼示例。如果您正苦於以下問題:C++ DOUBLE_TO_JSVAL函數的具體用法?C++ DOUBLE_TO_JSVAL怎麽用?C++ DOUBLE_TO_JSVAL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DOUBLE_TO_JSVAL函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: js_math_min
JSBool
js_math_min(JSContext *cx, uintN argc, jsval *vp)
{
jsdouble x, z = *cx->runtime->jsPositiveInfinity;
jsval *argv;
uintN i;
if (argc == 0) {
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
return JS_TRUE;
}
argv = vp + 2;
for (i = 0; i < argc; i++) {
x = js_ValueToNumber(cx, &argv[i]);
if (JSVAL_IS_NULL(argv[i]))
return JS_FALSE;
if (JSDOUBLE_IS_NaN(x)) {
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
if (x == 0 && x == z) {
if (js_copysign(1.0, x) == -1)
z = x;
} else {
z = (x < z) ? x : z;
}
}
return js_NewNumberInRootedValue(cx, z, vp);
}
示例2: math_pow
static JSBool
math_pow(JSContext *cx, uintN argc, jsval *vp)
{
jsdouble x, y, z;
if (argc <= 1) {
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
x = js_ValueToNumber(cx, &vp[2]);
if (JSVAL_IS_NULL(vp[2]))
return JS_FALSE;
y = js_ValueToNumber(cx, &vp[3]);
if (JSVAL_IS_NULL(vp[3]))
return JS_FALSE;
/*
* Because C99 and ECMA specify different behavior for pow(),
* we need to wrap the libm call to make it ECMA compliant.
*/
if (!JSDOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0)) {
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
/* pow(x, +-0) is always 1, even for x = NaN. */
if (y == 0) {
*vp = JSVAL_ONE;
return JS_TRUE;
}
z = pow(x, y);
return js_NewNumberInRootedValue(cx, z, vp);
}
示例3: math_min
static JSBool
math_min(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z = *cx->runtime->jsPositiveInfinity;
uintN i;
if (argc == 0)
{
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
return JS_TRUE;
}
for (i = 0; i < argc; i++)
{
if (!js_ValueToNumber(cx, argv[i], &x))
return JS_FALSE;
if (JSDOUBLE_IS_NaN(x))
{
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
if ((x == 0) && (x == z) && (fd_copysign(1.0, x) == -1))
z = x;
else
z = (x < z) ? x : z;
}
return js_NewNumberValue(cx, z, rval);
}
示例4: js_cocos2dx_studio_ColliderBody_getCalculatedVertexList
JSBool js_cocos2dx_studio_ColliderBody_getCalculatedVertexList(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocostudio::ColliderBody* cobj = (cocostudio::ColliderBody *)(proxy ? proxy->ptr : nullptr);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const std::vector<cocos2d::Point>& ret = cobj->getCalculatedVertexList();
JSObject *jsretArr = JS_NewArrayObject(cx, 0, nullptr);
jsval jsret;
//CCObject* obj;
int i = 0;
for(std::vector<cocos2d::Point>::const_iterator it = ret.begin(); it != ret.end(); it++)
{
const cocos2d::Point& point = *it;
JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL);
if (!tmp) break;
JSBool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(point.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(point.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT);
jsval jsTmp = OBJECT_TO_JSVAL(tmp);
if(!ok || !JS_SetElement(cx, jsretArr, i, &jsTmp))
{
break;
}
++i;
}
jsret = OBJECT_TO_JSVAL(jsretArr);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
示例5: math_exp
static JSBool
math_exp(JSContext *cx, uintN argc, jsval *vp)
{
jsdouble x, z;
if (argc == 0) {
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
return JS_TRUE;
}
x = js_ValueToNumber(cx, &vp[2]);
if (JSVAL_IS_NULL(vp[2]))
return JS_FALSE;
#ifdef _WIN32
if (!JSDOUBLE_IS_NaN(x)) {
if (x == *cx->runtime->jsPositiveInfinity) {
*vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
return JS_TRUE;
}
if (x == *cx->runtime->jsNegativeInfinity) {
*vp = JSVAL_ZERO;
return JS_TRUE;
}
}
#endif
z = exp(x);
return js_NewNumberInRootedValue(cx, z, vp);
}
示例6: CGPoint_to_jsval
jsval CGPoint_to_jsval( JSContext *cx, CGPoint p)
{
#ifdef JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
JSObject *object = JS_NewObject(cx, NULL, NULL, NULL );
if (!object)
return JSVAL_VOID;
if (!JS_DefineProperty(cx, object, "x", DOUBLE_TO_JSVAL(p.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) ||
!JS_DefineProperty(cx, object, "y", DOUBLE_TO_JSVAL(p.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) )
return JSVAL_VOID;
return OBJECT_TO_JSVAL(object);
#else // JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
#ifdef __LP64__
JSObject *typedArray = JS_NewFloat64Array( cx, 2 );
#else
JSObject *typedArray = JS_NewFloat32Array( cx, 2 );
#endif
CGPoint *buffer = (CGPoint*)JS_GetArrayBufferViewData(typedArray, cx );
*buffer = p;
return OBJECT_TO_JSVAL(typedArray);
#endif // ! JSB_COMPATIBLE_WITH_COCOS2D_HTML5_BASIC_TYPES
}
示例7: def_animate_cb
void def_animate_cb(void *view, void *cb, double tt, double t) {
JSObject *js_view = (JSObject*)view;
JSObject *js_cb = (JSObject*)cb;
jsval args[2] = {DOUBLE_TO_JSVAL(tt),DOUBLE_TO_JSVAL(t)};
JSContext *cx = get_js_context();
JS_BeginRequest(cx);
jsval ret;
JS_CallFunctionValue(cx, js_view, OBJECT_TO_JSVAL(js_cb), 2, args, &ret);
JS_EndRequest(cx);
}
示例8: JS_BINDED_PROP_GET_IMPL
JS_BINDED_PROP_GET_IMPL(FakeAudio, currentTime)
{
float time;
alGetSourcef(sourceId, AL_SEC_OFFSET, &time);
vp.set(DOUBLE_TO_JSVAL(time));
return JS_TRUE;
}
示例9: add_double
static void
add_double(void *opaque, void *parent, const char *name, double v)
{
jsdouble *d = JS_NewDouble(opaque, v);
if(d != NULL)
add_item(opaque, parent, name, DOUBLE_TO_JSVAL(d));
}
示例10: FRAGMENT
FRAGMENT(jsval, simple) {
JS::Rooted<jsval> fortytwo(cx, INT_TO_JSVAL(42));
JS::Rooted<jsval> negone(cx, INT_TO_JSVAL(-1));
JS::Rooted<jsval> undefined(cx, JSVAL_VOID);
JS::Rooted<jsval> null(cx, JSVAL_NULL);
JS::Rooted<jsval> js_true(cx, JSVAL_TRUE);
JS::Rooted<jsval> js_false(cx, JSVAL_FALSE);
JS::Rooted<jsval> elements_hole(cx, js::MagicValue(JS_ELEMENTS_HOLE));
JS::Rooted<jsval> empty_string(cx);
empty_string.setString(JS_NewStringCopyZ(cx, ""));
JS::Rooted<jsval> friendly_string(cx);
friendly_string.setString(JS_NewStringCopyZ(cx, "Hello!"));
JS::Rooted<jsval> global(cx);
global.setObject(*JS_GetGlobalObject(cx));
// Some interesting value that floating-point won't munge.
JS::Rooted<jsval> onehundredthirtysevenonehundredtwentyeighths(cx, DOUBLE_TO_JSVAL(137.0 / 128.0));
breakpoint();
(void) fortytwo;
(void) negone;
(void) undefined;
(void) js_true;
(void) js_false;
(void) null;
(void) elements_hole;
(void) empty_string;
(void) friendly_string;
(void) global;
}
示例11: math_exp
static JSBool
math_exp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
jsdouble x, z;
if (!js_ValueToNumber(cx, argv[0], &x))
return JS_FALSE;
#ifdef _WIN32
if (!JSDOUBLE_IS_NaN(x))
{
if (x == *cx->runtime->jsPositiveInfinity)
{
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
return JS_TRUE;
}
if (x == *cx->runtime->jsNegativeInfinity)
{
*rval = JSVAL_ZERO;
return JS_TRUE;
}
}
#endif
z = fd_exp(x);
return js_NewNumberValue(cx, z, rval);
}
示例12: ReflectHistogramSnapshot
JSBool
ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
{
Histogram::SampleSet ss;
h->SnapshotSample(&ss);
JSObject *counts_array;
JSObject *rarray;
jsval static_histogram = h->flags() && Histogram::kUmaTargetedHistogramFlag ? JSVAL_TRUE : JSVAL_FALSE;
const size_t count = h->bucket_count();
if (!(JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), NULL, NULL, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), NULL, NULL, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "histogram_type", INT_TO_JSVAL(h->histogram_type()), NULL, NULL, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), NULL, NULL, JSPROP_ENUMERATE)
&& (rarray = JS_NewArrayObject(cx, count, NULL))
&& JS_DefineProperty(cx, obj, "ranges", OBJECT_TO_JSVAL(rarray), NULL, NULL, JSPROP_ENUMERATE)
&& FillRanges(cx, rarray, h)
&& (counts_array = JS_NewArrayObject(cx, count, NULL))
&& JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array), NULL, NULL, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "static", static_histogram, NULL, NULL, JSPROP_ENUMERATE)
)) {
return JS_FALSE;
}
for (size_t i = 0; i < count; i++) {
if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)), NULL, NULL, JSPROP_ENUMERATE)) {
return JS_FALSE;
}
}
return JS_TRUE;
}
示例13: js_set_prop_dbl
void
js_set_prop_dbl(JSContext *cx, JSObject *o, const char *prop, double v)
{
jsdouble *d = JS_NewDouble(cx, v);
if(d != NULL)
js_set_prop_jsval(cx, o, prop, DOUBLE_TO_JSVAL(d));
}
示例14: assert
void TraceMonkeyValue::setProperty(std::string propertyName, double propertyValue)
{
assert(isValid());
assert(JSVAL_IS_OBJECT(value));
jsval ret = DOUBLE_TO_JSVAL(propertyValue);
JS_SetProperty(TraceMonkeyEngine::context, JSVAL_TO_OBJECT(value), propertyName.c_str(), &ret);
}
示例15: js_time
static JSBool
js_time(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
time_t t;
time(&t);
jsdouble *d = JS_NewDouble(cx, t);
*rval = DOUBLE_TO_JSVAL(d);
return JS_TRUE;
}