• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ JS_GetStringLength函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: enc_string

char*
enc_string(JSContext* cx, jsval arg, size_t* buflen)
{
    JSString* str = NULL;
    jschar* src = NULL;
    char* bytes = NULL;
    size_t srclen = 0;
    size_t byteslen = 0;

    str = JS_ValueToString(cx, arg);
    if(!str) goto error;

    src = JS_GetStringChars(str);
    srclen = JS_GetStringLength(str);

    if(!enc_charbuf(src, srclen, NULL, &byteslen)) goto error;

    bytes = JS_malloc(cx, (byteslen) + 1);
    bytes[byteslen] = 0;

    if(!enc_charbuf(src, srclen, bytes, &byteslen)) goto error;

    if(buflen) *buflen = byteslen;
    goto success;

error:
    if(bytes != NULL) JS_free(cx, bytes);
    bytes = NULL;

success:
    return bytes;
}
开发者ID:benoitc,项目名称:couchjs,代码行数:32,代码来源:utf8.c


示例17: JSValToChar

/**
 * Convert a JavaScript value to a char*
 *
 * @param context the JavaScript context
 * @param arg the JavaScript value
 * @return a new char*
 * @warning be sure to free the resources returned by this function
 */
char* JSValToChar(JSContext* context, jsval* arg) {
  char *c;
  char *tmp;
  JSString *jsmsg;
  size_t len;
  int i;
  if(!JSVAL_IS_STRING(*arg)) {
    return NULL;
  }
  jsmsg = JS_ValueToString(context,*arg);
  len = JS_GetStringLength(jsmsg);
  tmp = JS_EncodeString(context,jsmsg);
  c = (char*)malloc((len+1)*sizeof(char));
  c[len] = '\0';
#ifdef ULINET_DEBUG
  fprintf(stderr,"%d \n",len);
#endif
  for(i = 0;i < len;i++) {
    c[i] = tmp[i];
    c[i+1] = 0;
  }
#ifdef ULINET_DEBUG
  fprintf(stderr,"%s \n",c);
#endif
  return c;
}
开发者ID:OSGeo,项目名称:zoo-project,代码行数:34,代码来源:service_internal_js.c


示例18: convert_js_string_to_ruby

VALUE convert_js_string_to_ruby(JohnsonRuntime* runtime, JSString* str)
{
  JSContext * context = johnson_get_current_context(runtime);
  PREPARE_RUBY_JROOTS(context, 1);
  JROOT(str);
  char* bytes = JS_GetStringBytes(str);
  JCHECK(bytes);
  JRETURN_RUBY(rb_str_new(bytes, (signed long)JS_GetStringLength(str)));
}
开发者ID:JackDanger,项目名称:johnson,代码行数:9,代码来源:conversions.c


示例19: js_eval

/* Execute a string in its own context (away from Synchronet objects) */
static JSBool
js_eval(JSContext *parent_cx, JSObject *parent_obj, uintN argc, jsval *argv, jsval *rval)
{
    char*			buf;
    size_t			buflen;
    JSString*		str;
    JSScript*		script;
    JSContext*		cx;
    JSObject*		obj;
    JSErrorReporter	reporter;
#ifndef EVAL_BRANCH_CALLBACK
    JSBranchCallback callback;
#endif

    if(argc<1)
        return(JS_TRUE);

    if((str=JS_ValueToString(parent_cx, argv[0]))==NULL)
        return(JS_FALSE);
    if((buf=JS_GetStringBytes(str))==NULL)
        return(JS_FALSE);
    buflen=JS_GetStringLength(str);

    if((cx=JS_NewContext(JS_GetRuntime(parent_cx),JAVASCRIPT_CONTEXT_STACK))==NULL)
        return(JS_FALSE);

    /* Use the error reporter from the parent context */
    reporter=JS_SetErrorReporter(parent_cx,NULL);
    JS_SetErrorReporter(parent_cx,reporter);
    JS_SetErrorReporter(cx,reporter);

#ifdef EVAL_BRANCH_CALLBACK
    JS_SetContextPrivate(cx, JS_GetPrivate(parent_cx, parent_obj));
    JS_SetBranchCallback(cx, js_BranchCallback);
#else	/* Use the branch callback from the parent context */
    JS_SetContextPrivate(cx, JS_GetContextPrivate(parent_cx));
    callback=JS_SetBranchCallback(parent_cx,NULL);
    JS_SetBranchCallback(parent_cx, callback);
    JS_SetBranchCallback(cx, callback);
#endif

    if((obj=JS_NewObject(cx, NULL, NULL, NULL))==NULL
            || !JS_InitStandardClasses(cx,obj)) {
        JS_DestroyContext(cx);
        return(JS_FALSE);
    }

    if((script=JS_CompileScript(cx, obj, buf, buflen, NULL, 0))!=NULL) {
        JS_ExecuteScript(cx, obj, script, rval);
        JS_DestroyScript(cx, script);
    }

    JS_DestroyContext(cx);

    return(JS_TRUE);
}
开发者ID:ftnapps,项目名称:pkg-sbbs,代码行数:57,代码来源:js_internal.c


示例20: jsSerialPort

//
// constructor for the scanner object
//
static JSBool jsSerialPort( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
   JSString *sDevice = JSVAL_TO_STRING( argv[0] );   
   if( ( 0 != (cx->fp->flags & JSFRAME_CONSTRUCTING) )
       && 
       ( 1 <= argc )
       && 
       ( 0 != ( sDevice = JSVAL_TO_STRING( argv[0] ) ) ) )
   {
      JSObject *portObj = JS_NewObject( cx, &jsSerialPortClass_, spProto, obj );
   
      if( portObj )
      {
         *rval = OBJECT_TO_JSVAL(portObj); // root
         JS_SetPrivate( cx, portObj, 0 );

         JS_DefineProperty( cx, portObj, "deviceName", argv[0], 0, 0, JSPROP_READONLY|JSPROP_ENUMERATE );

         char terminator = '\0' ;
         unsigned inputTimeout = 0 ;

         if( 2 <= argc )
         {
            JSString *sTerminator = JSVAL_TO_STRING( argv[1] );
            if( sTerminator && ( 1 == JS_GetStringLength( sTerminator ) ) )
            {
               JS_DefineProperty( cx, portObj, "terminator", argv[1], 0, 0, JSPROP_READONLY|JSPROP_ENUMERATE );
               terminator = *JS_GetStringBytes( sTerminator );
            }
            else
               JS_ReportError( cx, "serialPort terminator must be single-character string" );
            if( 3 <= argc )
            {
               if( JSVAL_IS_INT( argv[2] ) )
               {
                  inputTimeout = (unsigned)JSVAL_TO_INT( argv[2] );
               }
               else
                  JS_ReportError( cx, "input timeout must be an integer" );
            } // input timeout property
         } // have terminator property

         (void )new jsPort_t( pollHandlers_, JS_GetStringBytes( sDevice ),
                              9600, 8, 'N', 0, terminator, inputTimeout, *rval, portObj );
      }
      else
      {
         JS_ReportError( cx, "allocating serialPort\n" );
         *rval = JSVAL_FALSE ;
      }
   }
   else
      JS_ReportError( cx, "Usage : myVar = new serialPort( '/dev/ttyS2', '\r' );" );
   
   return JS_TRUE;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:59,代码来源:jsSerial.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ JS_IdToValue函数代码示例发布时间:2022-05-30
下一篇:
C++ JS_GetStringBytes函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap