当前位置: 首页>>代码示例>>C++>>正文


C++ JSVAL_IS_PRIMITIVE函数代码示例

本文整理汇总了C++中JSVAL_IS_PRIMITIVE函数的典型用法代码示例。如果您正苦于以下问题:C++ JSVAL_IS_PRIMITIVE函数的具体用法?C++ JSVAL_IS_PRIMITIVE怎么用?C++ JSVAL_IS_PRIMITIVE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JSVAL_IS_PRIMITIVE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: jsd_GetValueClassName

const char*
jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval)
{
    jsval val = jsdval->val;
    JSCompartment* oldCompartment = NULL;

    if(!jsdval->className && !JSVAL_IS_PRIMITIVE(val))
    {
        JSContext* cx = jsdc->dumbContext;

        JS::RootedObject obj(cx, JSVAL_TO_OBJECT(val));
        JS_BeginRequest(cx);
        oldCompartment = JS_EnterCompartment(cx, obj);
        jsdval->className = JS_GetDebugClassName(obj);
        JS_LeaveCompartment(cx, oldCompartment);
        JS_EndRequest(cx);
    }
    return jsdval->className;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:19,代码来源:jsd_val.cpp

示例2: ScriptEvent_OnSwapBuffers

bool ScriptEvent_OnSwapBuffers(HDC hDC, BOOL & bSwapRes)
{
	JSAutoCompartment ac(g_JsCx, g_JsGlobal);

	jsval f;

	if(!JS_GetProperty(g_JsCx, g_JsGlobal, "onSwapBuffers", &f) || JSVAL_IS_PRIMITIVE(f))
		return false;

	jsval y;
	jsval x[1] = { JS_NumberValue((unsigned int)hDC) };

	if(!JS_CallFunctionValue(g_JsCx, g_JsGlobal, f, 1, x, &y))
		return false;

	bSwapRes = JS::ToBoolean(y);

	return true;
}
开发者ID:YaLTeR,项目名称:advancedfx,代码行数:19,代码来源:scripting.cpp

示例3: jsd_GetValueFunction

/*
 * Retrieve a JSFunction* from a JSDValue*. This differs from
 * JS_ValueToFunction by fully unwrapping the object first.
 */
JSFunction*
jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
{
    JSContext* cx = jsdc->dumbContext;

    JS::RootedObject obj(cx);
    JS::RootedFunction fun(cx);

    JSCompartment* oldCompartment = NULL;
    if (JSVAL_IS_PRIMITIVE(jsdval->val))
        return NULL;

    obj = js::UncheckedUnwrap(JSVAL_TO_OBJECT(jsdval->val));
    oldCompartment = JS_EnterCompartment(cx, obj);
    fun = JS_ValueToFunction(cx, OBJECT_TO_JSVAL(obj));
    JS_LeaveCompartment(cx, oldCompartment);

    return fun;
}
开发者ID:mvarie,项目名称:Spidermonkey,代码行数:23,代码来源:jsd_val.cpp

示例4: if

// static
nsresult
IDBKeyRange::FromJSVal(JSContext* aCx,
                       const jsval& aVal,
                       IDBKeyRange** aKeyRange)
{
  nsresult rv;
  nsRefPtr<IDBKeyRange> keyRange;

  if (JSVAL_IS_VOID(aVal) || JSVAL_IS_NULL(aVal)) {
    // undefined and null returns no IDBKeyRange.
  }
  else if (JSVAL_IS_PRIMITIVE(aVal)) {
    // A valid key returns an 'only' IDBKeyRange.
    keyRange = new IDBKeyRange(false, false, true);

    rv = GetKeyFromJSVal(aCx, aVal, keyRange->Lower());
    if (NS_FAILED(rv)) {
      return rv;
    }
  }
  else {
    // An object is not permitted unless it's another IDBKeyRange.
    nsIXPConnect* xpc = nsContentUtils::XPConnect();
    NS_ASSERTION(xpc, "This should never be null!");

    nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
    rv = xpc->GetWrappedNativeOfJSObject(aCx, JSVAL_TO_OBJECT(aVal),
                                         getter_AddRefs(wrapper));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);

    nsCOMPtr<nsIIDBKeyRange> iface;
    if (!wrapper || !(iface = do_QueryInterface(wrapper->Native()))) {
      // Some random JS object?
      return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
    }

    keyRange = static_cast<IDBKeyRange*>(iface.get());
  }

  keyRange.forget(aKeyRange);
  return NS_OK;
}
开发者ID:krad-radio,项目名称:mozilla-krad,代码行数:43,代码来源:IDBKeyRange.cpp

示例5: JS_WrapValue

// Call WaiveXrayAndWrap when you have a JS object that you don't want to be
// wrapped in an Xray wrapper. cx->compartment is the compartment that will be
// using the returned object. If the object to be wrapped is already in the
// correct compartment, then this returns the unwrapped object.
bool
WrapperFactory::WaiveXrayAndWrap(JSContext *cx, jsval *vp)
{
    if (JSVAL_IS_PRIMITIVE(*vp))
        return JS_WrapValue(cx, vp);

    JSObject *obj = js::UnwrapObject(JSVAL_TO_OBJECT(*vp));
    obj = GetCurrentOuter(cx, obj);
    if (js::IsObjectInContextCompartment(obj, cx)) {
        *vp = OBJECT_TO_JSVAL(obj);
        return true;
    }

    obj = WaiveXray(cx, obj);
    if (!obj)
        return false;

    *vp = OBJECT_TO_JSVAL(obj);
    return JS_WrapValue(cx, vp);
}
开发者ID:jrmuizel,项目名称:mozilla-central-1,代码行数:24,代码来源:WrapperFactory.cpp

示例6: JS_WrapValue

// Call WaiveXrayAndWrap when you have a JS object that you don't want to be
// wrapped in an Xray wrapper. cx->compartment is the compartment that will be
// using the returned object. If the object to be wrapped is already in the
// correct compartment, then this returns the unwrapped object.
bool
WrapperFactory::WaiveXrayAndWrap(JSContext *cx, jsval *vp)
{
    if (JSVAL_IS_PRIMITIVE(*vp))
        return JS_WrapValue(cx, vp);

    JSObject *obj = JSVAL_TO_OBJECT(*vp)->unwrap();
    obj = GetCurrentOuter(cx, obj);
    if (obj->compartment() == cx->compartment) {
        *vp = OBJECT_TO_JSVAL(obj);
        return true;
    }

    obj = WaiveXray(cx, obj);
    if (!obj)
        return false;

    *vp = OBJECT_TO_JSVAL(obj);
    return JS_WrapValue(cx, vp);
}
开发者ID:mkedwards,项目名称:mozilla-central,代码行数:24,代码来源:WrapperFactory.cpp

示例7: jsd_GetValueWrappedJSVal

jsval
jsd_GetValueWrappedJSVal(JSDContext* jsdc, JSDValue* jsdval)
{
    JSObject* obj;
    JSContext* cx;
    jsval val = jsdval->val;
    if (!JSVAL_IS_PRIMITIVE(val)) {
        cx = JSD_GetDefaultJSContext(jsdc);
        obj = JS_ObjectToOuterObject(cx, JSVAL_TO_OBJECT(val));
        if (!obj)
        {
            JS_ClearPendingException(cx);
            val = JSVAL_NULL;
        }
        else
            val = OBJECT_TO_JSVAL(obj);
    }
    
    return val;
}
开发者ID:moussa1,项目名称:mozilla-central,代码行数:20,代码来源:jsd_val.c

示例8: jsd_GetValuePrototype

JSDValue*
jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval)
{
    if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PROTO)))
    {
        JSObject* obj;
        JSObject* proto;
        JS_ASSERT(!jsdval->proto);
        SET_BIT_FLAG(jsdval->flags, GOT_PROTO);
        if(JSVAL_IS_PRIMITIVE(jsdval->val))
            return NULL;
        obj = JSVAL_TO_OBJECT(jsdval->val);
        proto = JS_GetPrototype(obj);
        if(!proto)
            return NULL;
        jsdval->proto = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(proto));
    }
    if(jsdval->proto)
        jsdval->proto->nref++;
    return jsdval->proto;
}
开发者ID:Lynart,项目名称:mozilla-central,代码行数:21,代码来源:jsd_val.cpp

示例9: XPC_COW_RewrapForContent

JSBool
XPC_COW_RewrapForContent(JSContext *cx, JSObject *wrapperObj, jsval *vp)
{
  jsval v = *vp;
  if (JSVAL_IS_PRIMITIVE(v)) {
    return JS_TRUE;
  }

  JSObject *obj = GetWrappedJSObject(cx, JSVAL_TO_OBJECT(v));
  if (!obj) {
    *vp = JSVAL_NULL;
    return JS_TRUE;
  }

  if (JS_ObjectIsFunction(cx, obj)) {
    return XPC_COW_WrapFunction(cx, wrapperObj, obj, vp);
  }

  return XPC_COW_WrapObject(cx, JS_GetScopeChain(cx), OBJECT_TO_JSVAL(obj),
                            vp);
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:21,代码来源:XPCChromeObjectWrapper.cpp

示例10: mJSVal

XPCVariant::XPCVariant(XPCCallContext& ccx, jsval aJSVal)
    : mJSVal(aJSVal)
{
    nsVariant::Initialize(&mData);
    if(!JSVAL_IS_PRIMITIVE(mJSVal))
    {
        // If the incoming object is an XPCWrappedNative, then it could be a
        // double-wrapped object, and we should return the double-wrapped
        // object back out to script.

        JSObject* proto;
        XPCWrappedNative* wn =
            XPCWrappedNative::GetWrappedNativeOfJSObject(ccx,
                                                         JSVAL_TO_OBJECT(mJSVal),
                                                         nsnull,
                                                         &proto);
        mReturnRawObject = !wn && !proto;
    }
    else
        mReturnRawObject = JS_FALSE;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:21,代码来源:xpcvariant.cpp

示例11: JS_FRIEND_API

JS_FRIEND_API(bool) JS_FASTCALL
js_CloseIterator(JSContext *cx, jsval v)
{
    JSObject *obj;
    JSClass *clasp;

    JS_ASSERT(!JSVAL_IS_PRIMITIVE(v));
    obj = JSVAL_TO_OBJECT(v);
    clasp = OBJ_GET_CLASS(cx, obj);

    if (clasp == &js_IteratorClass) {
        js_CloseNativeIterator(cx, obj);
    }
#if JS_HAS_GENERATORS
    else if (clasp == &js_GeneratorClass) {
        if (!CloseGenerator(cx, obj))
            return JS_FALSE;
    }
#endif
    return JS_TRUE;
}
开发者ID:ahadzi,项目名称:celtx,代码行数:21,代码来源:jsiter.cpp

示例12: js_CallIteratorNext

js_CallIteratorNext(JSContext *cx, JSObject *iterobj, jsval *rval)
{
    uintN flags;

    /* Fast path for native iterators */
    if (OBJ_GET_CLASS(cx, iterobj) == &js_IteratorClass) {
        flags = JSVAL_TO_INT(STOBJ_GET_SLOT(iterobj, JSSLOT_ITER_FLAGS));
        if (flags & JSITER_ENUMERATE)
            return CallEnumeratorNext(cx, iterobj, flags, rval);

        /*
         * Call next directly as all the methods of the native iterator are
         * read-only and permanent.
         */
        if (!IteratorNextImpl(cx, iterobj, rval))
            return JS_FALSE;
    } else {
        jsid id = ATOM_TO_JSID(cx->runtime->atomState.nextAtom);

        if (!JS_GetMethodById(cx, iterobj, id, &iterobj, rval))
            return JS_FALSE;
        if (!js_InternalCall(cx, iterobj, *rval, 0, NULL, rval)) {
            /* Check for StopIteration. */
            if (!cx->throwing ||
                JSVAL_IS_PRIMITIVE(cx->exception) ||
                OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(cx->exception))
                    != &js_StopIterationClass) {
                return JS_FALSE;
            }

            /* Inline JS_ClearPendingException(cx). */
            cx->throwing = JS_FALSE;
            cx->exception = JSVAL_VOID;
            *rval = JSVAL_HOLE;
            return JS_TRUE;
        }
    }

    return JS_TRUE;
}
开发者ID:ahadzi,项目名称:celtx,代码行数:40,代码来源:jsiter.cpp

示例13: XrayWrapperConstructor

static JSBool
XrayWrapperConstructor(JSContext *cx, uintN argc, jsval *vp)
{
  if (argc == 0) {
    return ThrowException(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx);
  }

  if (JSVAL_IS_PRIMITIVE(vp[2])) {
    return ThrowException(NS_ERROR_ILLEGAL_VALUE, cx);
  }

  JSObject *obj = JSVAL_TO_OBJECT(vp[2]);
  if (!obj->isWrapper()) {
    *vp = OBJECT_TO_JSVAL(obj);
    return JS_TRUE;
  }

  obj = obj->unwrap();

  *vp = OBJECT_TO_JSVAL(obj);
  return JS_WrapValue(cx, vp);
}
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:22,代码来源:XPCWrapper.cpp

示例14: mJSVal

XPCVariant::XPCVariant(JSContext* cx, jsval aJSVal)
    : mJSVal(aJSVal), mCCGeneration(0)
{
    nsVariant::Initialize(&mData);
    if (!JSVAL_IS_PRIMITIVE(mJSVal)) {
        // XXXbholley - The innerization here was from bug 638026. Blake says
        // the basic problem was that we were storing the C++ inner but the JS
        // outer, which meant that, after navigation, the JS inner could be
        // collected, which would cause us to try to recreate the JS inner at
        // some later point after teardown, which would crash. This is shouldn't
        // be a problem anymore because SetParentToWindow will do the right
        // thing, but I'm saving the cleanup here for another day. Blake thinks
        // that we should just not store the WN if we're creating a variant for
        // an outer window.
        JSObject *obj = JS_ObjectToInnerObject(cx, JSVAL_TO_OBJECT(mJSVal));
        mJSVal = OBJECT_TO_JSVAL(obj);

        JSObject *unwrapped = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false);
        mReturnRawObject = !(unwrapped && IS_WN_WRAPPER(unwrapped));
    } else
        mReturnRawObject = false;
}
开发者ID:petemoore,项目名称:mozilla-central,代码行数:22,代码来源:XPCVariant.cpp

示例15: DEBUG_CheckForComponentsInScope

void DEBUG_CheckForComponentsInScope(JSContext* cx, JSObject* obj,
                                     JSObject* startingObj,
                                     JSBool OKIfNotInitialized,
                                     XPCJSRuntime* runtime)
{
    if(OKIfNotInitialized)
        return;

    if(!(JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS))
        return;

    const char* name = runtime->GetStringName(XPCJSRuntime::IDX_COMPONENTS);
    jsval prop;
    if(JS_LookupProperty(cx, obj, name, &prop) && !JSVAL_IS_PRIMITIVE(prop))
        return;

    // This is pretty much always bad. It usually means that native code is
    // making a callback to an interface implemented in JavaScript, but the
    // document where the JS object was created has already been cleared and the
    // global properties of that document's window are *gone*. Generally this
    // indicates a problem that should be addressed in the design and use of the
    // callback code.
    NS_ERROR("XPConnect is being called on a scope without a 'Components' property!  (stack and details follow)");
    printf("The current JS stack is:\n");
    xpc_DumpJSStack(cx, JS_TRUE, JS_TRUE, JS_TRUE);

    printf("And the object whose scope lacks a 'Components' property is:\n");
    js_DumpObject(startingObj);

    JSObject *p = startingObj;
    while(p->isWrapper())
    {
        p = p->getProxyPrivate().toObjectOrNull();
        if(!p)
            break;
        printf("which is a wrapper for:\n");
        js_DumpObject(p);
    }
}
开发者ID:mbrubeck,项目名称:mozilla-central,代码行数:39,代码来源:xpcwrappednativescope.cpp


注:本文中的JSVAL_IS_PRIMITIVE函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。