コード例 #1
0
ファイル: jsmath.cpp プロジェクト: pope/APE_Server
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
0
ファイル: jsmath.cpp プロジェクト: pope/APE_Server
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
0
ファイル: jsmath.c プロジェクト: nixz/covise
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
0
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
0
ファイル: jsmath.cpp プロジェクト: pope/APE_Server
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
0
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
0
ファイル: js_animate.cpp プロジェクト: rampr/native-ios
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
0
enum reflectStatus
ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
{
  Histogram::SampleSet ss;
  h->SnapshotSample(&ss);

  // We don't want to reflect corrupt histograms.
  if (h->FindCorruption(ss) != Histogram::NO_INCONSISTENCIES) {
    return REFLECT_CORRUPT;
  }

  JSObject *counts_array;
  JSObject *rarray;
  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)
        )) {
    return REFLECT_FAILURE;
  }
  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 REFLECT_FAILURE;
    }
  }
  return REFLECT_OK;
}
コード例 #9
0
ファイル: FakeAudio.cpp プロジェクト: bagobor/FakeWebGL
JS_BINDED_PROP_GET_IMPL(FakeAudio, currentTime)
{
	float time;
	alGetSourcef(sourceId, AL_SEC_OFFSET, &time);
	vp.set(DOUBLE_TO_JSVAL(time));
	return JS_TRUE;
}
コード例 #10
0
ファイル: js_json.c プロジェクト: Rautz/showtime
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));
}
コード例 #11
0
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;
}
コード例 #12
0
ファイル: jsmath.c プロジェクト: nixz/covise
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);
}
コード例 #13
0
ファイル: FakeAudio.cpp プロジェクト: bagobor/FakeWebGL
JS_BINDED_PROP_GET_IMPL(FakeAudio, volume)
{
	float vol;
	alGetSourcef(sourceId, AL_GAIN, &vol);
	vp.set(DOUBLE_TO_JSVAL(vol));
	return JS_TRUE;
}
コード例 #14
0
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;
}
コード例 #15
0
ファイル: js.c プロジェクト: dev-life/showtime
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));
}
コード例 #16
0
void
JSObjectBuilder::DefineProperty(JS::HandleObject aObject, const char *name, double value)
{
  if (!mOk)
    return;

  mOk = JS_DefineProperty(mCx, aObject, name, DOUBLE_TO_JSVAL(value), nullptr, nullptr, JSPROP_ENUMERATE);
}
コード例 #17
0
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);
}
コード例 #18
0
ファイル: js.c プロジェクト: Daisho/showtime
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;
}
コード例 #19
0
ファイル: body.cpp プロジェクト: dumganhar/sugs_spiderMonkey
static JSBool body_getVelocityLimit(JSContext* cx, uintN argc, jsval* vp)
{
  JSObject* bodyObj = JS_THIS_OBJECT(cx, vp);

  cpBody* body = (cpBody*)JS_GetPrivate(cx, bodyObj);

  jsval rVal = DOUBLE_TO_JSVAL(cpBodyGetVelLimit(body));
  JS_SET_RVAL(cx, vp, rVal);
  return JS_TRUE;
}
コード例 #20
0
void ComponentJS::update(float delta)
{
    if (_succeedLoadingScript)
    {
        mozilla::Maybe<JS::PersistentRootedObject>* jsObj = static_cast<mozilla::Maybe<JS::PersistentRootedObject>*>(_jsObj);
        jsval dataVal = DOUBLE_TO_JSVAL(delta);
        JS::RootedValue retval(ScriptingCore::getInstance()->getGlobalContext());
        ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsObj->ref().get()), ComponentJS::UPDATE.c_str(), 1, &dataVal, &retval);
    }
}
コード例 #21
0
bool js_cocos2dx_audioengine_AudioProfile_get_minDelay(JSContext *cx, uint32_t argc, jsval *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(args.thisv().toObjectOrNull());
    cocos2d::experimental::AudioProfile* cobj = (cocos2d::experimental::AudioProfile *)(proxy ? proxy->ptr : NULL);
    JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_audioengine_AudioProfile_get_minDelay : Invalid Native Object");

    jsval jsret = DOUBLE_TO_JSVAL(cobj->minDelay);
    args.rval().set(jsret);
    return true;
}
コード例 #22
0
JS_CLASS_METHOD( JsPointBinding,ToAngle) {
	if(argc == 1) {
		JSObject *objA;
		JS_ConvertArguments(context, argc, JS_ARGV(cx, vp), "o", &objA);
		CCPoint *p1 = static_cast<CCPoint*>(JS_GetPrivate(context,objA));
		CGFloat result = ccpToAngle(*p1);
		JS_SET_RVAL(cx, vp, DOUBLE_TO_JSVAL(result));
	}
	return JS_TRUE;

}
コード例 #23
0
ファイル: body.cpp プロジェクト: dumganhar/sugs_spiderMonkey
static JSBool body_getVelocity(JSContext* cx, uintN argc, jsval* vp)
{
  JSObject* bodyObj = JS_THIS_OBJECT(cx, vp);

  cpBody* body = (cpBody*)JS_GetPrivate(cx, bodyObj);

  cpVect velocity = cpBodyGetVel(body);
  jsval xVelVal = DOUBLE_TO_JSVAL(velocity.x);
  jsval yVelVal = DOUBLE_TO_JSVAL(velocity.y);
  JSObject* velocityObj = JS_NewObject(cx, NULL, NULL, NULL);
  if(!JS_SetProperty(cx, velocityObj, "x", &xVelVal)) {
    JS_ReportError(cx, "Failure to set x property of velocity for Body");
  }
  if(!JS_SetProperty(cx, velocityObj, "y", &yVelVal)) {
    JS_ReportError(cx, "Failure to set y property of velocity for Body");
  }
  jsval rVal = OBJECT_TO_JSVAL(velocityObj);
  JS_SET_RVAL(cx, vp, rVal);
  return JS_TRUE;
}
コード例 #24
0
//---------------------------------------------------------------------------
jsval CONCEPT_TO_JS(JSContext *cx, void *member) {
    INTEGER type     = 0;
    char    *szValue = 0;
    NUMBER  nValue   = 0;
    jsval   ret      = 0;

    InvokePtr(INVOKE_GET_VARIABLE, member, &type, &szValue, &nValue);
    switch (type) {
        case VARIABLE_NUMBER:
            ret = DOUBLE_TO_JSVAL(JS_NewDouble(cx, nValue));
            break;

        case VARIABLE_STRING:
            ret = STRING_TO_JSVAL(JS_NewString(cx, szValue, (int)nValue));
            break;

        default:
            ret = DOUBLE_TO_JSVAL(JS_NewDouble(cx, 1.0));
    }
    return ret;
}
コード例 #25
0
ファイル: jsmath.cpp プロジェクト: pope/APE_Server
static JSBool
math_log(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;
#if defined(SOLARIS) && defined(__GNUC__)
    if (x < 0) {
        *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
        return JS_TRUE;
    }
#endif
    z = log(x);
    return js_NewNumberInRootedValue(cx, z, vp);
}
コード例 #26
0
ファイル: jsatom.cpp プロジェクト: Web5design/meguro
JSAtom *
js_AtomizeDouble(JSContext *cx, jsdouble d)
{
    JSAtomState *state;
    JSDHashTable *table;
    JSAtomHashEntry *entry;
    uint32 gen;
    jsdouble *key;
    jsval v;

    state = &cx->runtime->atomState;
    table = &state->doubleAtoms;

    JS_LOCK(cx, &state->lock);
    entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, &d, JS_DHASH_ADD));
    if (!entry)
        goto failed_hash_add;
    if (entry->keyAndFlags == 0) {
        gen = ++table->generation;
        JS_UNLOCK(cx, &state->lock);

        key = js_NewWeaklyRootedDouble(cx, d);
        if (!key)
            return NULL;

        JS_LOCK(cx, &state->lock);
        if (table->generation == gen) {
            JS_ASSERT(entry->keyAndFlags == 0);
        } else {
            entry = TO_ATOM_ENTRY(JS_DHashTableOperate(table, key,
                                                       JS_DHASH_ADD));
            if (!entry)
                goto failed_hash_add;
            if (entry->keyAndFlags != 0)
                goto finish;
            ++table->generation;
        }
        INIT_ATOM_ENTRY(entry, key);
    }

  finish:
    v = DOUBLE_TO_JSVAL((jsdouble *)ATOM_ENTRY_KEY(entry));
    cx->weakRoots.lastAtom = v;
    JS_UNLOCK(cx, &state->lock);

    return (JSAtom *)v;

  failed_hash_add:
    JS_UNLOCK(cx, &state->lock);
    JS_ReportOutOfMemory(cx);
    return NULL;
}
コード例 #27
0
ファイル: jsatom.c プロジェクト: Kitiara/UOX3
JSAtom *
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags)
{
    jsdouble *dp;
    JSHashNumber keyHash;
    jsval key;
    JSAtomState *state;
    JSHashTable *table;
    JSHashEntry *he, **hep;
    JSAtom *atom;
    char buf[2 * ALIGNMENT(double)];

    dp = ALIGN(buf, double);
    *dp = d;
    keyHash = HASH_DOUBLE(dp);
    key = DOUBLE_TO_JSVAL(dp);
    state = &cx->runtime->atomState;
    JS_LOCK(&state->lock, cx);
    table = state->table;
    hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
    if ((he = *hep) == NULL) {
#ifdef JS_THREADSAFE
        uint32 gen = state->tablegen;
#endif
        JS_UNLOCK(&state->lock,cx);
        if (!js_NewDoubleValue(cx, d, &key))
            return NULL;
        JS_LOCK(&state->lock, cx);
#ifdef JS_THREADSAFE
        if (state->tablegen != gen) {
            hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
            if ((he = *hep) != NULL) {
                atom = (JSAtom *)he;
                goto out;
            }
        }
#endif
        he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
        if (!he) {
            JS_ReportOutOfMemory(cx);
            atom = NULL;
            goto out;
        }
    }

    atom = (JSAtom *)he;
    atom->flags |= flags;
    cx->lastAtom = atom;
out:
    JS_UNLOCK(&state->lock,cx);
    return atom;
}
コード例 #28
0
JSBool ADM_JSAvidemux::JSGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
        if (JSVAL_IS_INT(id)) 
        {
                ADM_JSAvidemux *priv = (ADM_JSAvidemux *) JS_GetPrivate(cx, obj);
                switch(JSVAL_TO_INT(id))
                {

                        case markerA_prop:
                                *vp = INT_TO_JSVAL(frameStart);
                                break;
                        case markerB_prop:
                                *vp = INT_TO_JSVAL(frameEnd);
                                break;
                        case audio_prop:
                                *vp = OBJECT_TO_JSVAL(priv->getObject()->m_pAudio);
                                break;
                        case video_prop:
                                *vp = OBJECT_TO_JSVAL(priv->getObject()->m_pVideo);
                                break;
                        case container_prop:
                                *vp = STRING_TO_JSVAL(priv->getObject()->m_pContainer);
                                break;
                        case currentframe_prop:
                                *vp = INT_TO_JSVAL(priv->getObject()->m_nCurrentFrame);
                                break;
                        case fps_prop:
                                {
                                        aviInfo info;

                                        if (avifileinfo)
                                        {
                                                enterLock();
                                                video_body->getVideoInfo(&info);
                                                priv->getObject()->m_dFPS = info.fps1000/1000.0; 
                                                video_body->updateVideoInfo (&info);
                                                video_body->getVideoInfo (avifileinfo);
                                                leaveLock();
                                        } 
                                        else 
                                        {
                                                return JS_FALSE;
                                        }
                                        *vp = DOUBLE_TO_JSVAL(priv->getObject()->m_dFPS);
                                }
                                break;
                }
        }
        return JS_TRUE;
}
コード例 #29
0
ファイル: js.c プロジェクト: dev-life/showtime
void
js_set_prop_int(JSContext *cx, JSObject *o, const char *prop, int v)
{
  jsval val;
  if(v <= INT32_MAX && v >= INT32_MIN && INT_FITS_IN_JSVAL(v))
    val = INT_TO_JSVAL(v);
  else {
    jsdouble *d = JS_NewDouble(cx, v);
    if(d == NULL)
      return;
    val = DOUBLE_TO_JSVAL(d);
  }
   js_set_prop_jsval(cx, o, prop, val);
}
コード例 #30
0
ファイル: js_settings.c プロジェクト: kshostak/showtime
static jsval
jsval_from_htsmsgfield(JSContext *cx, htsmsg_field_t *f)
{
  jsdouble *d;
  switch(f->hmf_type) {
  case HMF_STR:
    return STRING_TO_JSVAL(JS_NewStringCopyZ(cx, f->hmf_str));

  case HMF_S64:
    if(f->hmf_s64 <= INT32_MAX && f->hmf_s64 >= INT32_MIN &&
       INT_FITS_IN_JSVAL(f->hmf_s64))
      return INT_TO_JSVAL(f->hmf_s64);
    if((d = JS_NewDouble(cx, f->hmf_s64)) != NULL)
      return DOUBLE_TO_JSVAL(d);
    break;

  case HMF_DBL:
    if((d = JS_NewDouble(cx, f->hmf_dbl)) != NULL)
      return DOUBLE_TO_JSVAL(d);
    break;
  }
  return JSVAL_NULL;
}