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


C++ JSVAL_TO_STRING函数代码示例

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


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

示例1: JS_GetStringBytes

JSBool ADM_JSAvidemuxAudio::mixer(JSContext *cx, JSObject *obj, uintN argc, 
                                      jsval *argv, jsval *rval)
{
uint32_t nb=0,nw=0;
uint32_t *infos=NULL;
        // default return value
        ADM_JSAvidemuxAudio *p = (ADM_JSAvidemuxAudio *)JS_GetPrivate(cx, obj);

        // default return value
      if(argc != 1)
                return JS_FALSE;
        char *pArg0 = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
        enterLock();

        if(setCurrentMixerFromString(pArg0))
                *rval=BOOLEAN_TO_JSVAL(true);
        else
                *rval=BOOLEAN_TO_JSVAL(false);
        leaveLock()
        return JS_TRUE;

}// end Codec
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:22,代码来源:ADM_JSAvidemuxAudio.cpp

示例2: JSVAL_TO_STRING

xpc_qsAString::xpc_qsAString(JSContext *cx, jsval *pval)
{
    // From the T_ASTRING case in XPCConvert::JSData2Native.
    typedef implementation_type::char_traits traits;
    jsval v;
    JSString *s;
    const PRUnichar *chars;
    size_t len;

    v = *pval;
    if(JSVAL_IS_STRING(v))
    {
        s = JSVAL_TO_STRING(v);
    }
    else
    {
        if(JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
        {
            (new(mBuf) implementation_type(
                traits::sEmptyBuffer, PRUint32(0)))->SetIsVoid(PR_TRUE);
            mValid = JS_TRUE;
            return;
        }

        s = JS_ValueToString(cx, v);
        if(!s)
        {
            mValid = JS_FALSE;
            return;
        }
        *pval = STRING_TO_JSVAL(s);  // Root the new string.
    }

    len = JS_GetStringLength(s);
    chars = (len == 0 ? traits::sEmptyBuffer : (const PRUnichar*)JS_GetStringChars(s));
    new(mBuf) implementation_type(chars, len);
    mValid = JS_TRUE;
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:38,代码来源:xpcquickstubs.cpp

示例3: PrimJSVALToSV

SV *
PrimJSVALToSV(
    pTHX_
    JSContext *cx,
    jsval v
) {
    SV *sv = NULL;
    if(JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v))
	sv = newSV(0);
    else if(JSVAL_IS_BOOLEAN(v)) {
	sv = newSV(0);
	sv_setref_iv(sv, PJS_BOOLEAN, (IV)JSVAL_TO_BOOLEAN(v));
    }
    else if(JSVAL_IS_INT(v)) 
	sv = newSViv((IV)JSVAL_TO_INT(v));
    else if(JSVAL_IS_DOUBLE(v))
	sv = newSVnv(*JSVAL_TO_DOUBLE(v));
    else if(JSVAL_IS_STRING(v)) 
	sv = PJS_JSString2SV(aTHX_ JSVAL_TO_STRING(v));
    else croak("PJS_Assert: Unknown primitive type");
    
    return sv;
}
开发者ID:gitpan,项目名称:JSP,代码行数:23,代码来源:PJS_Reflection.c

示例4: lwqq_js_enc_pwd

LWQQ_EXPORT
char* lwqq_js_enc_pwd(const char* pwd, const char* salt, const char* vcode,
                      lwqq_js_t* js)
{
   JSObject* global = JS_GetGlobalObject(js->context);
   jsval res;
   jsval argv[3];
   char* res_;

   JSString* pwd_ = JS_NewStringCopyZ(js->context, pwd);
   JSString* salt_ = JS_NewStringCopyZ(js->context, salt);
   JSString* vcode_ = JS_NewStringCopyZ(js->context, vcode);
   argv[0] = STRING_TO_JSVAL(pwd_);
   argv[1] = STRING_TO_JSVAL(salt_);
   argv[2] = STRING_TO_JSVAL(vcode_);
   JS_CallFunctionName(js->context, global, "encryption", 3, argv, &res);

   res_ = JS_EncodeString(js->context, JSVAL_TO_STRING(res));
   char* ret = strdup(res_);
   JS_free(js->context, res_);

   return ret;
}
开发者ID:HenryHu,项目名称:lwqq,代码行数:23,代码来源:lwjs.c

示例5: getUTF8StringArgument

static void
getUTF8StringArgument(JSContext *cx, JSObject *obj, PRUint16 argNum,
                      uintN argc, jsval *argv, nsCString& aRetval)
{
    if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) {
        JS_ReportError(cx, "String argument expected");
        aRetval.Truncate();
        return;
    }

    /*
     * We don't want to use JS_ValueToString because we want to be able
     * to have an object to represent a target in subsequent versions.
     */
    JSString *str = JSVAL_TO_STRING(argv[argNum]);
    if (!str) {
        aRetval.Truncate();
        return;
    }

    PRUnichar *data = (PRUnichar*)JS_GetStringChars(str);
    CopyUTF16toUTF8(data, aRetval);
}
开发者ID:AllenDou,项目名称:firefox,代码行数:23,代码来源:nsSecurityManagerFactory.cpp

示例6: JSID_TO_INT

JSBool S_SimpleNativeClass::jsPropertySet(JSContext *cx, JSObject *obj, jsid _id, JSBool strict, jsval *val)
{
	int32_t propId = JSID_TO_INT(_id);
	S_SimpleNativeClass *cobj; JSGET_PTRSHELL(S_SimpleNativeClass, cobj, obj);
	if (!cobj) return JS_FALSE;
	switch(propId) {
	case kSomeField:
		do { uint32_t tmp; JS_ValueToECMAUint32(cx, *val, &tmp); cobj->setSomeField(tmp); } while (0);
		break;
	case kSomeOtherField:
		do { uint32_t tmp; JS_ValueToECMAUint32(cx, *val, &tmp); cobj->setSomeOtherField(tmp); } while (0);
		break;
	case kAnotherMoreComplexField:
		do {
			char *tmp = JS_EncodeString(cx, JSVAL_TO_STRING(*val));
			if (tmp) { cobj->setAnotherMoreComplexField(tmp); }
		} while (0);
		break;
	default:
		break;
	}
	return JS_TRUE;
}
开发者ID:funkaster,项目名称:testjs,代码行数:23,代码来源:simple_native_generated.cpp

示例7: jsval_to_std_vector_string

    JSBool jsval_to_std_vector_string(JSContext* cx, jsval v, std::vector<std::string>* ret) {
        JSObject *jsobj;
        JSBool ok = JS_ValueToObject( cx, v, &jsobj );
        JSB_PRECONDITION2( ok, cx, JS_FALSE, "Error converting value to object");
        JSB_PRECONDITION2( jsobj && JS_IsArrayObject( cx, jsobj),  cx, JS_FALSE, "Object must be an array");

        uint32_t len = 0;
        JS_GetArrayLength(cx, jsobj, &len);

        for (uint32_t i=0; i < len; i++) {
            jsval elt;
            if (JS_GetElement(cx, jsobj, i, &elt)) {

                if (JSVAL_IS_STRING(elt))
                {
                    JSStringWrapper str(JSVAL_TO_STRING(elt));
                    ret->push_back(str.get());
                }
            }
        }

        return JS_TRUE;
    }
开发者ID:sdkbox,项目名称:sdkbox-sample-appnext,代码行数:23,代码来源:SDKBoxJSHelper.cpp

示例8: JS_TO_CONCEPT

//---------------------------------------------------------------------------
void JS_TO_CONCEPT(void *member, jsval rval) {
    INVOKE_CALL            InvokePtr   = 0;
    CALL_BACK_VARIABLE_SET SetVariable = _SetVariable;
    void *HANDLER = CONCEPT_HANDLER;

    if (JSVAL_IS_DOUBLE(rval)) {
        SET_NUMBER_VARIABLE(member, *JSVAL_TO_DOUBLE(rval));
    } else
    if (JSVAL_IS_INT(rval)) {
        SET_NUMBER_VARIABLE(member, JSVAL_TO_INT(rval));
    } else
    if (JSVAL_IS_STRING(rval)) {
        struct JSString *str = JSVAL_TO_STRING(rval);
        SET_BUFFER_VARIABLE(member, JS_GetStringBytes(str), str->length);
    } else
    if (JSVAL_IS_BOOLEAN(rval)) {
        SET_NUMBER_VARIABLE(member, (NUMBER)JSVAL_TO_BOOLEAN(rval));
    } else
    if ((JSVAL_IS_NULL(rval)) || (JSVAL_IS_VOID(rval))) {
        SET_NUMBER_VARIABLE(member, 0);
    } else
        SET_NUMBER_VARIABLE(member, 1);
}
开发者ID:Devronium,项目名称:ConceptApplicationServer,代码行数:24,代码来源:main.cpp

示例9: getVar

JSBool getVar(JSContext *cx, JSObject *obj, uintN argc, 
                                       jsval *argv, jsval *rval)
{// begin getVar
        int out=0;
        char *dupe=NULL;

        // default return value
        if(argc != 1)
                return JS_FALSE;
	if(JSVAL_IS_STRING(argv[0]) == false)
		return JS_FALSE;
	char  *stringa = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
	dupe=script_getVar(stringa ,&out);

	if(!dupe)
		return JS_FALSE;
	// if out=1 it is a string else a number
	if(out)
		*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,dupe));
	else
		*rval = INT_TO_JSVAL(atoi(dupe));
	return JS_TRUE;
}// end getVar
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:23,代码来源:ADM_JSFunctions.cpp

示例10: js_prop_from_object

int
js_prop_from_object(JSContext *cx, JSObject *obj, prop_t *p)
{
  JSIdArray *ida;
  int i, r = 0;
  const char *n;

  if((ida = JS_Enumerate(cx, obj)) == NULL)
    return -1;
  
  for(i = 0; i < ida->length; i++) {
    jsval name, value;

    if(!JS_IdToValue(cx, ida->vector[i], &name))
      continue;

    if(JSVAL_IS_STRING(name)) {
      n = JS_GetStringBytes(JSVAL_TO_STRING(name));
      if(!JS_GetProperty(cx, obj, n, &value))
	continue;
    } else if(JSVAL_IS_INT(name)) {
      if(!JS_GetElement(cx, obj, JSVAL_TO_INT(name), &value) ||
	 JSVAL_IS_VOID(value))
	continue;
      n = NULL;
    } else {
      continue;
    }

    if(JSVAL_TO_OBJECT(value) == obj)
      continue;

    js_prop_set_from_jsval(cx, prop_create(p, n), value);
  }
  JS_DestroyIdArray(cx, ida);
  return r;
}
开发者ID:stallman,项目名称:showtime,代码行数:37,代码来源:js.c

示例11: JSB_IOSiAP_requestProducts

static JSBool JSB_IOSiAP_requestProducts(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
    jsval *argv = JS_ARGV(cx,vp);
    
    JSObject *obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
    IOSiAP_Bridge *bridge = (IOSiAP_Bridge *)JS_GetPrivate(obj);
    
    // parse array param
    // JSObject like a array which hold jsval
    JSObject *arrayObj = JSVAL_TO_OBJECT(argv[0]);
    // safety check for type
    if (JS_FALSE == JS_IsArrayObject(cx, arrayObj)) {
        JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(JS_FALSE));
        return JS_TRUE;
    }
    
    std::vector <std::string> productIdentifiers;
    uint32_t length = 0;
    JS_GetArrayLength(cx, arrayObj, &length);
    for(int index = 0; index < length; index++)
    {
        // jsval ==> JSString ==> char *
        jsval argVal;
        JS_GetElement(cx, arrayObj, index, &argVal);
        JSString *jsIdentifier = JSVAL_TO_STRING(argVal);
        JSStringWrapper wrapper(jsIdentifier);
        // fill into C++ vector
        productIdentifiers.push_back(std::string(wrapper.get()));
    }
    // now safe to call native function.
    bridge->iap->requestProducts(productIdentifiers);

    JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(JS_TRUE));
    return JS_TRUE;
}
开发者ID:1007650105,项目名称:cocos-docs,代码行数:36,代码来源:IOSiAP_JSB.cpp

示例12: JSB_IOSiAP_iOSProductByIdentifier

static JSBool JSB_IOSiAP_iOSProductByIdentifier(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2(argc==1, cx, JS_FALSE, "Invalid number of arguments");
    jsval *argv = JS_ARGV(cx,vp);
    
    JSObject *obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
    IOSiAP_Bridge *bridge = (IOSiAP_Bridge *)JS_GetPrivate(obj);
    
    // safety check for type
    if (JS_FALSE == JSVAL_IS_STRING(argv[0])) {
        JS_SET_RVAL(cx, vp, JSVAL_VOID);
        return JS_TRUE;
    }
    
    JSString *jsIdentifier = JSVAL_TO_STRING(argv[0]);
    JSStringWrapper wrapper(jsIdentifier);
    std::string identifier = wrapper.get();
    IOSProduct *product = bridge->iap->iOSProductByIdentifier(identifier);
    // return a js object
    JSObject *productObj = JS_NewObject(cx, JSB_Product_class, JSB_Product_object, NULL);
    JS_SetPrivate(productObj, product);
    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(productObj));
    return JS_TRUE;
}
开发者ID:1007650105,项目名称:cocos-docs,代码行数:24,代码来源:IOSiAP_JSB.cpp

示例13: jsj_ConvertJSValueToJavaValue

/*
 * Convert a JS value to a Java value of the given type signature.  The cost
 * variable is incremented if coercion is required, e.g. the source value is
 * a string, but the target type is a boolean.
 *
 * Returns JS_FALSE if no conversion is possible, either because the jsval has
 * a type that is wholly incompatible with the Java value, or because a scalar
 * jsval can't be represented in a variable of the target type without loss of
 * precision, e.g. the source value is "4.2" but the destination type is byte.
 * If conversion is not possible and java_value is non-NULL, the JS error
 * reporter is called with an appropriate message.
 */  
JSBool
jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v_arg,
                              JavaSignature *signature,
                              int *cost, jvalue *java_value, JSBool *is_local_refp)
{
    JavaSignatureChar type;
    jsval v;
    JSBool success = JS_FALSE;

    /* Initialize to default case, in which no new Java object is
       synthesized to perform the conversion and, therefore, no JNI local
       references are being held. */
    *is_local_refp = JS_FALSE;   
    
    type = signature->type;
    v = v_arg;
    switch (type) {
    case JAVA_SIGNATURE_BOOLEAN:
        if (!JSVAL_IS_BOOLEAN(v)) {
            if (!JS_ConvertValue(cx, v, JSTYPE_BOOLEAN, &v))
                goto conversion_error;
            if (JSVAL_IS_VOID(v))
                goto conversion_error;
            (*cost)++;
        }
        if (java_value)
            java_value->z = (jboolean)(JSVAL_TO_BOOLEAN(v) == JS_TRUE);
        break;

    case JAVA_SIGNATURE_SHORT:
        JSVAL_TO_INTEGRAL_JVALUE(short, s, jshort, v, java_value);
        break;

    case JAVA_SIGNATURE_BYTE:
        JSVAL_TO_INTEGRAL_JVALUE(byte, b, jbyte, v, java_value);
        break;

    case JAVA_SIGNATURE_CHAR:
        /* A one-character string can be converted into a character */
        if (JSVAL_IS_STRING(v) && (JS_GetStringLength(JSVAL_TO_STRING(v)) == 1)) {
            v = INT_TO_JSVAL(*JS_GetStringChars(JSVAL_TO_STRING(v)));
        }
        JSVAL_TO_INTEGRAL_JVALUE(char, c, jchar, v, java_value);
        break;

    case JAVA_SIGNATURE_INT:
        JSVAL_TO_INTEGRAL_JVALUE(int, i, jint, v, java_value);
        break;

    case JAVA_SIGNATURE_LONG:
#if defined(XP_MAC) || (defined(XP_OS2) && !defined(HAVE_LONG_LONG))
        JSVAL_TO_JLONG_JVALUE(j, jlong, v, java_value);
#else
        JSVAL_TO_INTEGRAL_JVALUE(long, j, jlong, v, java_value);
#endif
        break;
    
    case JAVA_SIGNATURE_FLOAT:
        if (!JSVAL_IS_NUMBER(v)) {
            if (!JS_ConvertValue(cx, v, JSTYPE_NUMBER, &v))
                goto conversion_error;
            (*cost)++;
        }
        if (java_value) {
            if (JSVAL_IS_INT(v))
                java_value->f = (jfloat) JSVAL_TO_INT(v);
            else
                java_value->f = (jfloat) *JSVAL_TO_DOUBLE(v);
        }
        break;

    case JAVA_SIGNATURE_DOUBLE:
        if (!JSVAL_IS_NUMBER(v)) {
            if (!JS_ConvertValue(cx, v, JSTYPE_NUMBER, &v))
                goto conversion_error;
            (*cost)++;
        }
        if (java_value) {
            if (JSVAL_IS_INT(v))
                java_value->d = (jdouble) JSVAL_TO_INT(v);
            else
                java_value->d = (jdouble) *JSVAL_TO_DOUBLE(v);
        }
        break;

    /* Non-primitive (reference) type */
    default:
        JS_ASSERT(IS_REFERENCE_TYPE(type));
//.........这里部分代码省略.........
开发者ID:bluecherrydvr,项目名称:omv,代码行数:101,代码来源:jsj_convert.c

示例14: JS_NewObject

JSObject*
Library::Create(JSContext* cx, jsval path, JSCTypesCallbacks* callbacks)
{
  JSObject* libraryObj = JS_NewObject(cx, &sLibraryClass, NULL, NULL);
  if (!libraryObj)
    return NULL;
  js::AutoObjectRooter root(cx, libraryObj);

  // initialize the library
  if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL)))
    return NULL;

  // attach API functions
  if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions))
    return NULL;

  if (!JSVAL_IS_STRING(path)) {
    JS_ReportError(cx, "open takes a string argument");
    return NULL;
  }

  PRLibSpec libSpec;
  JSFlatString* pathStr = JS_FlattenString(cx, JSVAL_TO_STRING(path));
  if (!pathStr)
    return NULL;
#ifdef XP_WIN
  // On Windows, converting to native charset may corrupt path string.
  // So, we have to use Unicode path directly.
  const PRUnichar* pathChars = JS_GetFlatStringChars(pathStr);
  if (!pathChars)
    return NULL;

  libSpec.value.pathname_u = pathChars;
  libSpec.type = PR_LibSpec_PathnameU;
#else
  // Convert to platform native charset if the appropriate callback has been
  // provided.
  char* pathBytes;
  if (callbacks && callbacks->unicodeToNative) {
    pathBytes = 
      callbacks->unicodeToNative(cx, pathStr->chars(), pathStr->length());
    if (!pathBytes)
      return NULL;

  } else {
    // Fallback: assume the platform native charset is UTF-8. This is true
    // for Mac OS X, Android, and probably Linux.
    size_t nbytes =
      js_GetDeflatedUTF8StringLength(cx, pathStr->chars(), pathStr->length());
    if (nbytes == (size_t) -1)
      return NULL;

    pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1));
    if (!pathBytes)
      return NULL;

    ASSERT_OK(js_DeflateStringToUTF8Buffer(cx, pathStr->chars(),
                pathStr->length(), pathBytes, &nbytes));
    pathBytes[nbytes] = 0;
  }

  libSpec.value.pathname = pathBytes;
  libSpec.type = PR_LibSpec_Pathname;
#endif

  PRLibrary* library = PR_LoadLibraryWithFlags(libSpec, 0);
#ifndef XP_WIN
  JS_free(cx, pathBytes);
#endif
  if (!library) {
    JS_ReportError(cx, "couldn't open library");
    return NULL;
  }

  // stash the library
  if (!JS_SetReservedSlot(cx, libraryObj, SLOT_LIBRARY,
         PRIVATE_TO_JSVAL(library)))
    return NULL;

  return libraryObj;
}
开发者ID:GCRC,项目名称:build-couchdb,代码行数:81,代码来源:Library.cpp

示例15: global_resolve

static JSBool
global_resolve(JSContext *cx, JSHandleObject obj, JSHandleId id, unsigned flags,
	       MutableHandleObject objp)
{
#ifdef LAZY_STANDARD_CLASSES
    if ((flags & JSRESOLVE_ASSIGNING) == 0) {
        JSBool resolved;

        if (!JS_ResolveStandardClass(cx, obj, id, &resolved))
            return JS_FALSE;
        if (resolved) {
            objp.set(obj);
            return JS_TRUE;
        }
    }
#endif

#if defined(SHELL_HACK) && defined(DEBUG) && defined(XP_UNIX)
    if ((flags & (JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING)) == 0) {
        /*
         * Do this expensive hack only for unoptimized Unix builds, which are
         * not used for benchmarking.
         */
        char *path, *comp, *full;
        const char *name;
        JSBool ok, found;
        JSFunction *fun;

        if (!JSVAL_IS_STRING(id))
            return JS_TRUE;
        path = getenv("PATH");
        if (!path)
            return JS_TRUE;
        path = JS_strdup(cx, path);
        if (!path)
            return JS_FALSE;
        name = JS_GetStringBytes(JSVAL_TO_STRING(id));
        ok = JS_TRUE;
        for (comp = strtok(path, ":"); comp; comp = strtok(NULL, ":")) {
            if (*comp != '\0') {
                full = JS_smprintf("%s/%s", comp, name);
                if (!full) {
                    JS_ReportOutOfMemory(cx);
                    ok = JS_FALSE;
                    break;
                }
            } else {
                full = (char *)name;
            }
            found = (access(full, X_OK) == 0);
            if (*comp != '\0')
                free(full);
            if (found) {
                fun = JS_DefineFunction(cx, obj, name, Exec, 0, JSPROP_ENUMERATE);
                ok = (fun != NULL);
                if (ok)
                    objp.set(obj);
                break;
            }
        }
        JS_free(cx, path);
        return ok;
    }
#else
    return JS_TRUE;
#endif
}
开发者ID:FunkyVerb,项目名称:devtools-window,代码行数:67,代码来源:SkJS.cpp


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