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


C++ JS_GetStringLength函数代码示例

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


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

示例1: Print

static JSBool
Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  nsJSSh* shell;
  if (!GetJSShGlobal(cx, obj, &shell)) return JS_FALSE;

  JSAutoRequest ar(cx);

  PRUint32 bytesWritten;

#ifdef DEBUG
//     nsCOMPtr<nsIThread> thread;
//     nsIThread::GetCurrent(getter_AddRefs(thread));
//     printf("printing on thread %p, shell %p, output %p, cx=%p, obj=%p\n", thread.get(), shell, shell->mOutput, cx, obj);
#endif

    for (unsigned int i=0; i<argc; ++i) {
     JSString *str = JS_ValueToString(cx, argv[i]);
     if (!str) return JS_FALSE;
     if (shell->mOutput) {
       if (shell->mEmitHeader) {
         char buf[80];
         sprintf(buf, "[%d]", JS_GetStringLength(str));
         shell->mOutput->Write(buf, strlen(buf), &bytesWritten);
       }
       shell->mOutput->Write(JS_GetStringBytes(str), JS_GetStringLength(str), &bytesWritten);
     }
     else
       printf("%s", JS_GetStringBytes(str)); // use cout if no output stream given.
#ifdef DEBUG
//        printf("%s", JS_GetStringBytes(str));
#endif
   }
  return JS_TRUE;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:35,代码来源:nsJSSh.cpp

示例2: NS_ENSURE_ARG_POINTER

/* PRBool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in JSVal id, in PRUint32 flags, out JSObjectPtr objp); */
NS_IMETHODIMP
calDateTime::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
                        JSObject * obj, jsval id, PRUint32 flags,
                        JSObject * *objp, PRBool *_retval)
{
    NS_ENSURE_ARG_POINTER(objp);
    NS_ENSURE_ARG_POINTER(_retval);

    if (JSVAL_IS_STRING(id)) {
        JSString *str = JSVAL_TO_STRING(id);
        nsDependentString const name(
            reinterpret_cast<PRUnichar const*>(JS_GetStringChars(str)),
            JS_GetStringLength(str));
        if (name.EqualsLiteral("jsDate")) {
            *_retval = JS_DefineUCProperty(cx, obj, JS_GetStringChars(str),
                                           JS_GetStringLength(str),
                                           JSVAL_VOID,
                                           nsnull, nsnull, 0);
            *objp = obj;
            return *_retval ? NS_OK : NS_ERROR_FAILURE;
        }
    }

    *_retval = PR_TRUE;
    return NS_OK;
}
开发者ID:SecareLupus,项目名称:Drood,代码行数:27,代码来源:calDateTime.cpp

示例3: mapFromJSObject

/**
 * Convert a JavaScript Object to a map
 *
 * @param cx the JavaScript context
 * @param t the JavaScript Object to convert
 * @return a new map containing the JavaScript Object
 */
map* mapFromJSObject(JSContext *cx,jsval t){
  map *res=NULL;
  JSIdArray *idp=JS_Enumerate(cx,JSVAL_TO_OBJECT(t));
#ifdef JS_DEBUG
  fprintf(stderr,"Properties %p\n",(void*)t);
#endif
  if(idp!=NULL) {
    int index;
    jsdouble argNum;
#ifdef JS_DEBUG
    fprintf(stderr,"Properties length :  %d \n",idp->length);
#endif
    for (index=0,argNum=idp->length;index<argNum;index++) { 
      jsval id = idp->vector[index];
      jsval vp;
      JS_IdToValue(cx,id,&vp);
      char *tmp, *tmp1;
      JSString *jsmsg,*jsmsg1;
      size_t len,len1;
      jsmsg = JS_ValueToString(cx,vp);
      len = JS_GetStringLength(jsmsg);
      jsval nvp;
      tmp=JS_EncodeString(cx,jsmsg);
      JS_GetProperty(cx, JSVAL_TO_OBJECT(t), tmp, &nvp);
      jsmsg1 = JS_ValueToString(cx,nvp);
      len1 = JS_GetStringLength(jsmsg1);
      tmp1=JS_EncodeString(cx,jsmsg1);
#ifdef JS_DEBUG
      fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,tmp,tmp1);
#endif
      if(strcasecmp(tmp,"child")!=0){
	if(res!=NULL){
#ifdef JS_DEBUG
	  fprintf(stderr,"%s - %s\n",tmp,tmp1);
#endif
	  addToMap(res,tmp,tmp1);
	}
	else{
	  res=createMap(tmp,tmp1);
	  res->next=NULL;
	}
      }
      free(tmp);
      free(tmp1);
#ifdef JS_DEBUG
      dumpMap(res);
#endif
    }
    JS_DestroyIdArray(cx,idp);
  }
#ifdef JS_DEBUG
  dumpMap(res);
#endif
  return res;
}
开发者ID:OSGeo,项目名称:zoo-project,代码行数:62,代码来源:service_internal_js.c

示例4: to_erl_object

int
to_erl_object(emonk_buf_t* buf, JSContext* cx, JSObject* obj)
{
    JSObject* iter;
    JSString* key;
    jsid idp;
    jsval val;
    jschar* keyname;
    size_t keylen;
    int count = 0;
    int lengthpos;
    
    REQUEST(7);

    BUFPTR[0] = SMALL_TUPLE;
    BUFPTR[1] = (char) 1;
    BUFPTR[2] = LIST;
    
    // Remember the byte offset where length goes so we can write it
    // after enumerating the properties.
    lengthpos = buf->used + 3;
    buf->used += 7;
    
    iter = JS_NewPropertyIterator(cx, obj);
    if(iter == NULL) return ERROR;
    
    while(JS_NextProperty(cx, iter, &idp))
    {
        // Done iterating, write length and bail.
        if(idp == JSVAL_VOID)
        {
            count = htonl(count);
            memcpy(buf->buf+lengthpos, &count, 4);

            REQUEST(1);
            BUFPTR[0] = NIL;
            buf->used += 1;
            
            return OK;
        }

        REQUEST(2);
        BUFPTR[0] = SMALL_TUPLE;
        BUFPTR[1] = 2;
        buf->used += 2;

        if(!JS_IdToValue(cx, idp, &val)) return ERROR;
        if(!to_erl_string(buf, cx, val)) return ERROR;
        
        key = JS_ValueToString(cx, val);
        keyname = JS_GetStringChars(key);
        keylen = JS_GetStringLength(key);
        
        if(!JS_GetUCProperty(cx, obj, keyname, keylen, &val)) return ERROR;
        if(!to_erl_intern(buf, cx, val)) return ERROR;
        count += 1;
    }

    return ERROR;
}
开发者ID:kocolosk,项目名称:emonk,代码行数:60,代码来源:emonk_to_erl.c

示例5: Btoa

Btoa(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSString *str;
    if (!argc)
        return JS_TRUE;

    str = JS_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;

    char *bin_data = JS_GetStringBytes(str);
    size_t bin_dataLength = JS_GetStringLength(str);

    char *base64 = PL_Base64Encode(bin_data, bin_dataLength, nsnull);
    if (!base64)
        return JS_FALSE;

    PRUint32 base64Length = ((bin_dataLength + 2) / 3) * 4;
    str = JS_NewStringCopyN(cx, base64, base64Length);
    PR_Free(base64);
    if (!str)
        return JS_FALSE;

    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:26,代码来源:mozJSComponentLoader.cpp

示例6: Atob

Atob(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSString *str;
    if (!argc)
        return JS_TRUE;

    str = JS_ValueToString(cx, argv[0]);
    if (!str)
        return JS_FALSE;

    size_t base64StrLength = JS_GetStringLength(str);
    char *base64Str = JS_GetStringBytes(str);

    PRUint32 bin_dataLength = (PRUint32)base64StrLength;
    if (base64Str[base64StrLength - 1] == '=') {
        if (base64Str[base64StrLength - 2] == '=')
            bin_dataLength -= 2;
        else  
            --bin_dataLength;
    }
    bin_dataLength = (PRUint32)((PRUint64)bin_dataLength * 3) / 4;

    char *bin_data = PL_Base64Decode(base64Str, base64StrLength, nsnull);
    if (!bin_data)
        return JS_FALSE;

    str = JS_NewStringCopyN(cx, bin_data, bin_dataLength);
    PR_Free(bin_data);
    if (!str)
        return JS_FALSE;

    *rval = STRING_TO_JSVAL(str);
    return JS_TRUE;
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:34,代码来源:mozJSComponentLoader.cpp

示例7: wimg_image_info_setter

JSBool wimg_image_info_setter(JSContext * cx, JSObject * obj, jsval idval, jsval * vp)
{
    JS_BeginRequest(cx);
    HANDLE hImage = JS_GetPrivate(cx, obj);

    JSString * newInfo = JS_ValueToString(cx, *vp);
    *vp = STRING_TO_JSVAL(newInfo);

    DWORD length = JS_GetStringLength(newInfo);
    LPWSTR chars = (LPWSTR)JS_GetStringChars(newInfo);
    if(*chars != 0xfeff)
    {
        length++;
        LPWSTR back = chars;
        chars = (LPWSTR)JS_malloc(cx, sizeof(WCHAR) * (length + 1));
        memset(chars, 0, sizeof(WCHAR) * (length + 1));
        *chars = 0xfeff;
        wcscat(chars, back);
        newInfo = JS_NewUCString(cx, (jschar*)chars, sizeof(WCHAR) * length);
        *vp = STRING_TO_JSVAL(newInfo);
    }

    DWORD errorCode = 0;
    if(!WIMSetImageInformation(hImage, (LPVOID)chars, length * sizeof(WCHAR)))
        errorCode = GetLastError();
    JS_EndRequest(cx);
    return JS_TRUE;

}
开发者ID:z4y4,项目名称:njord,代码行数:29,代码来源:js_wimg.cpp

示例8: wimg_image_info_getter

JSBool wimg_image_info_getter(JSContext * cx, JSObject * obj, jsval idval, jsval * vp)
{
    JS_BeginRequest(cx);
    HANDLE hImage = JS_GetPrivate(cx, obj);
    LPVOID rawImageInfo;
    DWORD rawImageInfoSize;

    if(!WIMGetImageInformation(hImage, &rawImageInfo, &rawImageInfoSize))
        *vp = JSVAL_NULL;

    JSString * xmlStr = JS_NewUCStringCopyN(cx, (jschar*)rawImageInfo, rawImageInfoSize / sizeof(WCHAR));
    if(xmlStr == NULL)
    {
        JS_ReportError(cx, "Error creating xml string from raw image information");
        JS_EndRequest(cx);
        return JS_FALSE;
    }
    jsval xmlStrVal = STRING_TO_JSVAL(xmlStr);
    *vp = xmlStrVal;
    LocalFree(rawImageInfo);

    WIMSetImageInformation(hImage, JS_GetStringChars(xmlStr), JS_GetStringLength(xmlStr) * sizeof(jschar));
    JS_EndRequest(cx);
    return JS_TRUE;
}
开发者ID:z4y4,项目名称:njord,代码行数:25,代码来源:js_wimg.cpp

示例9: JSVAL_TO_STRING

xpc_qsACString::xpc_qsACString(JSContext *cx, jsval *pval)
{
    // From the T_CSTRING case in XPCConvert::JSData2Native.
    jsval v;
    JSString *s;

    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())->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.
    }

    const char *bytes = JS_GetStringBytes(s);
    size_t len = JS_GetStringLength(s);
    new(mBuf) implementation_type(bytes, len);
    mValid = JS_TRUE;
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:34,代码来源:xpcquickstubs.cpp

示例10: jsWrite

static JSBool
jsWrite( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
    *rval = JSVAL_FALSE ;
    jsUsblpPoll_t *dev = (jsUsblpPoll_t *)JS_GetInstancePrivate( cx, obj, &jsUsblpClass_, NULL );
    if( dev )
    {
        unsigned totalLength = 0 ;
        for( uintN arg = 0 ; arg < argc ; arg++ )
        {
            JSString *str = JS_ValueToString(cx, argv[arg]);
            if( str ) {
                unsigned const segLength = JS_GetStringLength( str );
                char const *outData = JS_GetStringBytes( str );
                int numWritten = dev->write( outData, segLength );
                if( 0 < numWritten ) {
                    totalLength += numWritten ;
                }
                else if( 0 > numWritten ) {
                    JS_ReportError( cx, "usblp: short write %d of %u\n", numWritten, segLength );
                }
            }
            else
                JS_ReportError( cx, "usblp.write() - error converting to string\n" );
        }
        *rval = INT_TO_JSVAL(totalLength);
    }
    else
        JS_ReportError( cx, "Invalid usblp object\n" );

    return JS_TRUE ;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:32,代码来源:jsUsblp.cpp

示例11: PJS_JSString2SV

SV *
PJS_JSString2SV(
    pTHX_
    JSString *jstr
) {
    SV *ret;
#if PJS_UTF8_NATIVE
    char *str = JS_GetStringBytes(jstr);
    ret = newSVpv(str, 0);
    SvUTF8_on(ret);
#else
    dSP;
    jschar *chars = JS_GetStringChars(jstr);
    SV *esv = newSVpv((char *)chars, JS_GetStringLength(jstr) * sizeof(jschar));

    ENTER; SAVETMPS;
    PUSHMARK(SP);
    XPUSHs(sv_2mortal(newSVpv(PJS_STR_ENCODING, 0)));
    XPUSHs(sv_2mortal(esv));
    PUTBACK;
    call_pv("Encode::decode", G_SCALAR);
    SPAGAIN;
    ret = newSVsv(POPs);
    PUTBACK;
    FREETMPS; LEAVE;
    // sv_utf8_downgrade(ret, 1); Its safe, but pays the cost? 
#endif
    return ret;
}
开发者ID:gitpan,项目名称:JSP,代码行数:29,代码来源:PJS_Reflection.c

示例12: JS_GetGlobalObject

nsresult
nsDOMWorkerTimeout::ExpressionCallback::Run(nsDOMWorkerTimeout* aTimeout,
                                            JSContext* aCx)
{
  JSObject* global = JS_GetGlobalObject(aCx);
  NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);

  JSPrincipals* principal = nsDOMWorkerSecurityManager::WorkerPrincipal();
  NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);

  JSString* expression = JS_ValueToString(aCx, mExpression);
  NS_ENSURE_TRUE(expression, NS_ERROR_FAILURE);

  jschar* string = JS_GetStringChars(expression);
  NS_ENSURE_TRUE(string, NS_ERROR_FAILURE);

  size_t stringLength = JS_GetStringLength(expression);

  jsval rval;
  PRBool success = JS_EvaluateUCScriptForPrincipals(aCx, global, principal,
                                                    string, stringLength,
                                                    mFileName.get(),
                                                    mLineNumber, &rval);
  if (!success) {
    return NS_ERROR_FAILURE;
  }

  return NS_OK;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:29,代码来源:nsDOMWorkerTimeout.cpp

示例13: jsSend

static JSBool
jsSend( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   *rval = JSVAL_FALSE ;
   jsPort_t *params = (jsPort_t *)JS_GetInstancePrivate( cx, obj, &jsSerialPortClass_, NULL );
   if( params )
   {
      if( 1 == argc )
      {
         JSString *jsMsg = JSVAL_TO_STRING( argv[0] );
         char * p = JS_GetStringBytes( jsMsg );
         int len = JS_GetStringLength( jsMsg );
         int numWritten;
         if (params->outputDelay()==0)
            numWritten = write( params->getFd(), p, len );
         else {
            numWritten=0;
            while (len) {
               usleep(params->outputDelay() );
               numWritten += write( params->getFd(), p, 1 );
               p++;
               len--;
            }
         }
         *rval = INT_TO_JSVAL( numWritten );
      }
      else
         JS_ReportError( cx, "Usage: sendToScanner( \'string\' );" );
   }

   return JS_TRUE ;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:32,代码来源:jsSerial.cpp

示例14: js_json_parse

static JSBool
js_json_parse(JSContext *cx, JSObject* pThis, uintN argc, jsval *vp, jsval* rval)
{
    JSString *s = NULL;
    jsval *argv = vp;
 
    // Must throw an Error if there isn't a first arg
    if (!JS_ConvertArguments(cx, argc, argv, "S", &s))
        return JS_FALSE;
 
    JSBool ok = JS_TRUE;  
    JSONParser *jp = js_BeginJSONParse(cx, rval);
    if (!jp)
        ok = JS_FALSE;
 
    if (ok) {
        ok = js_ConsumeJSONText(cx, jp, JS_GetStringChars(s), JS_GetStringLength(s));
        ok &= js_FinishJSONParse(cx, jp);
    }
 
    if (!ok)
        JS_ReportError(cx, "Error parsing JSON.");
 
    return ok;
}
开发者ID:artyyouth,项目名称:SpiderMonkey_JSON,代码行数:25,代码来源:json.cpp

示例15: Context_execute

PyObject*
Context_execute(Context* self, PyObject* args, PyObject* kwargs)
{
    PyObject* obj = NULL;
    PyObject* ret = NULL;
    JSContext* cx = NULL;
    JSObject* root = NULL;
    JSString* script = NULL;
    jschar* schars = NULL;
    JSBool started_counter = JS_FALSE;
    size_t slen;
    jsval rval;

    JS_BeginRequest(self->cx);
    if(!PyArg_ParseTuple(args, "O", &obj)) goto error;
    
    script = py2js_string_obj(self, obj);
    if(script == NULL) goto error;

    schars = JS_GetStringChars(script);
    slen = JS_GetStringLength(script);
    
    cx = self->cx;
    root = self->root;

    // Mark us for time consumption
    if(self->start_time == 0)
    {
        started_counter = JS_TRUE;
        self->start_time = time(NULL);
    }

    if(!JS_EvaluateUCScript(cx, root, schars, slen, "<JavaScript>", 1, &rval))
    {
        if(!PyErr_Occurred())
        {
            PyErr_SetString(PyExc_RuntimeError, "Failed to execute script.");
        }
        goto error;
    }

    if(PyErr_Occurred()) goto error;

    ret = js2py(self, rval);

    JS_EndRequest(self->cx);
    JS_MaybeGC(self->cx);
    goto success;

error:
    JS_EndRequest(self->cx);
success:

    if(started_counter)
    {
        self->start_time = 0;
    }

    return ret;
}
开发者ID:Jonnyliu,项目名称:phoneyc,代码行数:60,代码来源:context.c


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