Exemple #1
0
template<> void ScriptInterface::ToJSVal<u8>(JSContext* UNUSED(cx), JS::MutableHandleValue ret, const u8& val)
{
	ret.set(JS::NumberValue(val));
}
Exemple #2
0
void CStdDeserializer::ScriptVal(const char* name, JS::MutableHandleValue out)
{
	out.set(ReadScriptVal(name, JS::NullPtr()));
}
static bool js_is_native_obj(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
{
	vp.set(BOOLEAN_TO_JSVAL(true));
	return true;	
}
void
WebGL2Context::GetQueryParameter(JSContext*, WebGLQuery* query, GLenum pname,
                                 JS::MutableHandleValue retval)
{
    retval.set(JS::NullValue());

    if (IsContextLost())
        return;

    if (!ValidateQueryEnum(this, pname, "getQueryParameter"))
        return;

    if (!query) {
        /* OpenGL ES 3.0 spec 6.1.7 (spec getQueryObject 1):
         *    If id is not the name of a query object, or if the query object
         *    named by id is currently active, then an INVALID_OPERATION error
         *    is generated. pname must be QUERY_RESULT or
         *    QUERY_RESULT_AVAILABLE.
         */
        ErrorInvalidOperation("getQueryObject: `query` should not be null.");
        return;
    }

    if (query->IsDeleted()) {
        // See (spec getQueryObject 1)
        ErrorInvalidOperation("getQueryObject: `query` has been deleted.");
        return;
    }

    if (query->IsActive()) {
        // See (spec getQueryObject 1)
        ErrorInvalidOperation("getQueryObject: `query` is active.");
        return;
    }

    if (!query->HasEverBeenActive()) {
        /* See (spec getQueryObject 1)
         *     If this instance of WebGLQuery has never been active before, that
         *     mean that query->mGLName is not a query object yet.
         */
        ErrorInvalidOperation("getQueryObject: `query` has never been active.");
        return;
    }

    // We must wait for an event loop before the query can be available
    if (!query->mCanBeAvailable && !gfxPrefs::WebGLImmediateQueries()) {
        if (pname == LOCAL_GL_QUERY_RESULT_AVAILABLE) {
            retval.set(JS::BooleanValue(false));
        }
        return;
    }

    MakeContextCurrent();
    GLuint returned = 0;
    switch (pname) {
    case LOCAL_GL_QUERY_RESULT_AVAILABLE:
        gl->fGetQueryObjectuiv(query->mGLName, LOCAL_GL_QUERY_RESULT_AVAILABLE, &returned);
        retval.set(JS::BooleanValue(returned != 0));
        return;

    case LOCAL_GL_QUERY_RESULT:
        gl->fGetQueryObjectuiv(query->mGLName, LOCAL_GL_QUERY_RESULT, &returned);

        if (query->mType == LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN) {
            retval.set(JS::NumberValue(returned));
            return;
        }

        /*
         * test (returned != 0) is important because ARB_occlusion_query on desktop drivers
         * return the number of samples drawed when the OpenGL ES extension
         * ARB_occlusion_query_boolean return only a boolean if a sample has been drawed.
         */
        retval.set(JS::BooleanValue(returned != 0));
        return;

    default:
        break;
    }

    ErrorInvalidEnum("getQueryObject: `pname` must be QUERY_RESULT{_AVAILABLE}.");
}
Exemple #5
0
static JSBool
AfxGlobal_inRDrawViewModel_get(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
{
	vp.set(g_In_R_DrawViewModel ? JSVAL_TRUE : JSVAL_FALSE);
    return JS_TRUE;
}
Exemple #6
0
static JSBool
AfxGlobal_hasGlArbMultiTexture_get(JSContext *cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp)
{
	vp.set(g_Has_GL_ARB_multitexture ? JSVAL_TRUE : JSVAL_FALSE);
    return JS_TRUE;
}
nsresult
xptiInterfaceEntry::GetConstant(uint16_t index, JS::MutableHandleValue constant,
                                char** name)
{
    if(!EnsureResolved())
        return NS_ERROR_UNEXPECTED;

    if(index < mConstantBaseIndex)
        return mParent->GetConstant(index, constant, name);

    if(index >= mConstantBaseIndex + 
                mDescriptor->num_constants)
    {
        NS_PRECONDITION(0, "bad param");
        return NS_ERROR_INVALID_ARG;
    }

    const auto& c = mDescriptor->const_descriptors[index - mConstantBaseIndex];
    AutoJSContext cx;
    JS::Rooted<JS::Value> v(cx);
    v.setUndefined();

    switch (c.type.prefix.flags) {
      case nsXPTType::T_I8:
      {
        v.setInt32(c.value.i8);
        break;
      }
      case nsXPTType::T_U8:
      {
        v.setInt32(c.value.ui8);
        break;
      }
      case nsXPTType::T_I16:
      {
        v.setInt32(c.value.i16);
        break;
      }
      case nsXPTType::T_U16:
      {
        v.setInt32(c.value.ui16);
        break;
      }
      case nsXPTType::T_I32:
      {
        v = JS_NumberValue(c.value.i32);
        break;
      }
      case nsXPTType::T_U32:
      {
        v = JS_NumberValue(c.value.ui32);
        break;
      }
      default:
      {
#ifdef DEBUG
        NS_ERROR("Non-numeric constant found in interface.");
#endif
      }
    }

    constant.set(v);
    *name = ToNewCString(nsDependentCString(c.name));

    return NS_OK;
}
Exemple #8
0
void DBInfo::getProperty(JSContext* cx,
                         JS::HandleObject obj,
                         JS::HandleId id,
                         JS::MutableHandleValue vp) {
    // 2nd look into real values, may be cached collection object
    if (!vp.isUndefined()) {
        auto scope = getScope(cx);
        auto opContext = scope->getOpContext();

        if (opContext && vp.isObject()) {
            ObjectWrapper o(cx, vp);

            if (o.hasOwnField(InternedString::_fullName)) {
                // need to check every time that the collection did not get sharded
                if (haveLocalShardingInfo(opContext->getClient(),
                                          o.getString(InternedString::_fullName)))
                    uasserted(ErrorCodes::BadValue, "can't use sharded collection from db.eval");
            }
        }

        return;
    }

    JS::RootedObject parent(cx);
    if (!JS_GetPrototype(cx, obj, &parent))
        uasserted(ErrorCodes::JSInterpreterFailure, "Couldn't get prototype");

    ObjectWrapper parentWrapper(cx, parent);

    if (parentWrapper.hasOwnField(id)) {
        parentWrapper.getValue(id, vp);
        return;
    }

    IdWrapper idw(cx, id);

    // if starts with '_' we dont return collection, one must use getCollection()
    if (idw.isString()) {
        JSStringWrapper jsstr;
        auto sname = idw.toStringData(&jsstr);
        if (sname.size() == 0 || sname[0] == '_') {
            return;
        }
    }

    // no hit, create new collection
    JS::RootedValue getCollection(cx);
    parentWrapper.getValue(InternedString::getCollection, &getCollection);

    if (!(getCollection.isObject() && JS_ObjectIsFunction(cx, getCollection.toObjectOrNull()))) {
        uasserted(ErrorCodes::BadValue, "getCollection is not a function");
    }

    JS::AutoValueArray<1> args(cx);

    idw.toValue(args[0]);

    JS::RootedValue coll(cx);
    ObjectWrapper(cx, obj).callMethod(getCollection, args, &coll);

    uassert(16861,
            "getCollection returned something other than a collection",
            getScope(cx)->getProto<DBCollectionInfo>().instanceOf(coll));

    // cache collection for reuse, don't enumerate
    ObjectWrapper(cx, obj).defineProperty(id, coll, 0);

    vp.set(coll);
}