本文整理汇总了C++中JS_GetStringBytes函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_GetStringBytes函数的具体用法?C++ JS_GetStringBytes怎么用?C++ JS_GetStringBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_GetStringBytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: xpc_DumpEvalInJSStackFrame
JSBool
xpc_DumpEvalInJSStackFrame(JSContext* cx, JSUint32 frameno, const char* text)
{
JSStackFrame* fp;
JSStackFrame* iter = nsnull;
JSUint32 num = 0;
if(!cx || !text)
{
puts("invalid params passed to xpc_DumpEvalInJSStackFrame!");
return JS_FALSE;
}
printf("js[%d]> %s\n", frameno, text);
while(nsnull != (fp = JS_FrameIterator(cx, &iter)))
{
if(num == frameno)
break;
num++;
}
if(!fp)
{
puts("invalid frame number!");
return JS_FALSE;
}
JSExceptionState* exceptionState = JS_SaveExceptionState(cx);
JSErrorReporter older = JS_SetErrorReporter(cx, xpcDumpEvalErrorReporter);
jsval rval;
JSString* str;
const char* chars;
if(JS_EvaluateInStackFrame(cx, fp, text, strlen(text), "eval", 1, &rval) &&
nsnull != (str = JS_ValueToString(cx, rval)) &&
nsnull != (chars = JS_GetStringBytes(str)))
{
printf("%s\n", chars);
}
else
puts("eval failed!");
JS_SetErrorReporter(cx, older);
JS_RestoreExceptionState(cx, exceptionState);
return JS_TRUE;
}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:46,代码来源:xpcdebug.cpp
示例2: JS_GetStringBytes
JSBool ADM_JSAvidemuxAudio::Save(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval)
{// begin Save
ADM_JSAvidemuxAudio *p = (ADM_JSAvidemuxAudio *)JS_GetPrivate(cx, obj);
// default return value
*rval = BOOLEAN_TO_JSVAL(false);
if(argc != 1)
return JS_FALSE;
if(JSVAL_IS_STRING(argv[0]) == false)
return JS_FALSE;
char *pTempStr = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
printf("Saving Audio \"%s\"\n",pTempStr);
enterLock();
*rval = INT_TO_JSVAL(A_audioSave(pTempStr));
leaveLock()
return JS_TRUE;
}// end Save
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:17,代码来源:ADM_JSAvidemuxAudio.cpp
示例3: JSVAL2String
static const char* JSVAL2String(JSContext* cx, jsval val, JSBool* isString)
{
const char* value = nsnull;
JSString* value_str = JS_ValueToString(cx, val);
if(value_str)
value = JS_GetStringBytes(value_str);
if(value)
{
const char* found = strstr(value, "function ");
if(found && (value == found || value+1 == found || value+2 == found))
value = "[function]";
}
if(isString)
*isString = JSVAL_IS_STRING(val);
return value;
}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:17,代码来源:xpcdebug.cpp
示例4: ADM_scriptDialogFactoryHelper
JSBool ADM_JSDialogFactory::JSConstructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc != 1)
return JS_FALSE;
if (JSVAL_IS_STRING(argv[0]) == false)
return JS_FALSE;
ADM_scriptDialogFactoryHelper *pObject = new ADM_scriptDialogFactoryHelper(JS_GetStringBytes(JSVAL_TO_STRING(argv[0])));
if (!JS_SetPrivate(cx, obj, pObject))
return JS_FALSE;
*rval = OBJECT_TO_JSVAL(obj);
return JS_TRUE;
}
开发者ID:AlexanderStohr,项目名称:avidemux2,代码行数:17,代码来源:ADM_JSDialogFactory.cpp
示例5: begin_request
char *sm_eval(spidermonkey_vm *vm, const char *filename, const char *code, int handle_retval) {
char *retval = NULL;
JSScript *script;
jsval result;
begin_request(vm);
script = JS_CompileScript(vm->context,
vm->global,
code, strlen(code),
filename, 1);
spidermonkey_error *error = (spidermonkey_error *) JS_GetContextPrivate(vm->context);
if (error == NULL) {
JS_ClearPendingException(vm->context);
JS_ExecuteScript(vm->context, vm->global, script, &result);
error = (spidermonkey_error *) JS_GetContextPrivate(vm->context);
if (error == NULL) {
if (handle_retval) {
if (JSVAL_IS_STRING(result)) {
JSString *str = JS_ValueToString(vm->context, result);
retval = copy_jsstring(str);
}
else if(strcmp(JS_GetStringBytes(JS_ValueToString(vm->context, result)), "undefined") == 0) {
retval = copy_string("{\"error\": \"Expression returned undefined\", \"lineno\": 0, \"source\": \"unknown\"}");
}
else {
retval = copy_string("{\"error\": \"non-JSON return value\", \"lineno\": 0, \"source\": \"unknown\"}");
}
}
JS_DestroyScript(vm->context, script);
}
else {
retval = error_to_json(error);
free_error(error);
JS_SetContextPrivate(vm->context, NULL);
}
}
else {
retval = error_to_json(error);
free_error(error);
JS_SetContextPrivate(vm->context, NULL);
}
JS_MaybeGC(vm->context);
end_request(vm);
return retval;
}
开发者ID:jamesaimonetti,项目名称:erlang_js,代码行数:45,代码来源:spidermonkey.c
示例6: jsSetCooked
static JSBool
jsSetCooked( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
*rval = JSVAL_VOID ;
if( ( 1 == argc )
&&
JSVAL_IS_STRING( argv[0] ) )
{
touchCalibration_t &cal = touchCalibration_t::get();
cal.setCalibration( JS_GetStringBytes( JSVAL_TO_STRING( argv[0] ) ) );
if( touchPoll_ )
touchPoll_->setCooked();
}
else
JS_ReportError( cx, "Usage: touchScreen.setCooked( { scale:{ x:#, y:# }, origin:{ x:#, y:# }, range:{ x:#, y:# }, swapXY=bool } )" );
return JS_TRUE ;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:18,代码来源:jsTouch.cpp
示例7: getStringArgument
static char *
getStringArgument(JSContext *cx, JSObject *obj, PRUint16 argNum, uintN argc, jsval *argv)
{
if (argc <= argNum || !JSVAL_IS_STRING(argv[argNum])) {
JS_ReportError(cx, "String argument expected");
return nsnull;
}
/*
* 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)
return nsnull;
return JS_GetStringBytes(str);
}
开发者ID:AllenDou,项目名称:firefox,代码行数:18,代码来源:nsSecurityManagerFactory.cpp
示例8: jsMD5Cram
static JSBool
jsMD5Cram( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
*rval = JSVAL_FALSE ;
if( ( 1 == argc )
&&
JSVAL_IS_STRING( argv[0] ) )
{
JSString *sArg = JSVAL_TO_STRING( argv[0] );
md5_t md5 ;
if( md5Cramfs( JS_GetStringBytes( sArg ), md5 ) )
*rval = md5ToRval( cx, md5 );
}
else
JS_ReportError( cx, "Usage: md5( string );" );
return JS_TRUE;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:18,代码来源:jsMD5.cpp
示例9: pathOnly
/********************** Extract Path from a filename **************/
JSBool pathOnly(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{// begin systemExecute
// default return value
*rval = INT_TO_JSVAL(-1);
if(argc != 1)
return JS_FALSE;
if(JSVAL_IS_STRING(argv[0]) == false )
return JS_FALSE;
char *name=NULL;
char *orgName = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
PathStripName(orgName);
/* Remove last / or last \ */
int l=strlen(orgName);
if(l) orgName[l-1]=0;
*rval=STRING_TO_JSVAL(JS_NewStringCopyZ(cx,orgName));
return JS_TRUE;
}// end systemExecute
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:19,代码来源:ADM_JSFunctions.cpp
示例10: dns_resolve_ex
// dnsResolveEx in JS context; not available in core JavaScript.
// returns javascript null if not able to resolve.
static JSBool // JS_TRUE or JS_FALSE
dns_resolve_ex(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
char* name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char* out;
char ipaddr[INET6_ADDRSTRLEN * MAX_IP_RESULTS + MAX_IP_RESULTS] = "";
out = JS_malloc(cx, strlen(ipaddr) + 1);
// Return "" on failure.
if(resolve_host(name, ipaddr, MAX_IP_RESULTS, AF_UNSPEC)) {
strcpy(out, "");
}
strcpy(out, ipaddr);
JSString *str = JS_NewString(cx, out, strlen(out));
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
开发者ID:betaY,项目名称:crawler,代码行数:20,代码来源:pacparser.c
示例11: DefineGetterOrSetter
static JSBool
DefineGetterOrSetter(JSContext *cx, uintN argc, JSBool wantGetter, jsval *vp)
{
uintN attrs;
JSBool found;
JSPropertyOp getter, setter;
JSObject *obj2;
jsval v;
jsid interned_id;
XPC_QS_ASSERT_CONTEXT_OK(cx);
JSObject *obj = JS_THIS_OBJECT(cx, vp);
if (!obj)
return JS_FALSE;
JSFastNative forward = wantGetter ? js_obj_defineGetter : js_obj_defineSetter;
jsval id = (argc >= 1) ? JS_ARGV(cx, vp)[0] : JSVAL_VOID;
if(!JSVAL_IS_STRING(id))
return forward(cx, argc, vp);
JSString *str = JSVAL_TO_STRING(id);
const char *name = JS_GetStringBytes(str);
if(!JS_ValueToId(cx, id, &interned_id) ||
!JS_LookupPropertyWithFlagsById(cx, obj, interned_id,
JSRESOLVE_QUALIFIED, &obj2, &v) ||
(obj2 &&
!JS_GetPropertyAttrsGetterAndSetterById(cx, obj2, interned_id, &attrs,
&found, &getter, &setter)))
return JS_FALSE;
// The property didn't exist, already has a getter or setter, or is not
// our property, then just forward now.
if(!obj2 ||
(attrs & (JSPROP_GETTER | JSPROP_SETTER)) ||
!(getter || setter) ||
!IS_PROTO_CLASS(STOBJ_GET_CLASS(obj2)))
return forward(cx, argc, vp);
// Reify the getter and setter...
if(!ReifyPropertyOps(cx, obj, id, interned_id, name, getter, setter,
nsnull, nsnull))
return JS_FALSE;
return forward(cx, argc, vp);
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:44,代码来源:xpcquickstubs.cpp
示例12: perlsub_as_constructor
JSBool
perlsub_as_constructor(
JSContext *cx,
JSObject *obj,
pjsid id,
DEFSTRICT_
jsval *vp
) {
// dTHX;
const char *key;
if(!PJSID_IS(STRING, id)) {
return JS_TRUE;
}
#if JS_VERSION < 185
key = JS_GetStringBytes(PJSID_TO(STRING, id));
#else
JSAutoByteString bytes(cx, PJSID_TO(STRING, id));
key = bytes.ptr();
#endif
if(strEQ(key, "constructor")) {
JSObject *constructor;
if(JSVAL_IS_OBJECT(*vp) && (constructor = JSVAL_TO_OBJECT(*vp)) &&
PJS_GET_CLASS(cx, constructor) == &perlsub_class) {
/* TODO: Change the constructor 'name' */
jsval temp;
JSObject *stash = JS_GetPrototype(cx, obj);
JS_SetPrototype(cx, stash, JS_GetPrototype(cx, constructor));
JS_SetPrototype(cx, constructor, stash);
JS_DefineProperty(cx, constructor, "prototype", OBJECT_TO_JSVAL(obj),
NULL, NULL, 0);
JS_LookupProperty(cx, obj, "__PACKAGE__", &temp);
// warn("Constructor set for %s\n", JS_GetStringBytes(JSVAL_TO_STRING(temp)));
return JS_TRUE;
} else {
JS_ReportError(cx, "Invalid constructor type");
return JS_FALSE;
}
} else
warn ("Opps: setting %s?\n", key);
return JS_TRUE;
}
开发者ID:gitpan,项目名称:JSPL,代码行数:44,代码来源:PJS_PerlSub.c
示例13: GetMemberInfo
/**
* Get the interface name and member name (for error messages).
*
* We could instead have each quick stub pass its name to the error-handling
* functions, as that name is statically known. But that would be redundant;
* the information is handy at runtime anyway. Also, this code often produces
* a more specific error message, e.g. "[nsIDOMHTMLDocument.appendChild]"
* rather than "[nsIDOMNode.appendChild]".
*/
static void
GetMemberInfo(JSObject *obj,
jsval memberId,
const char **ifaceName,
const char **memberName)
{
// Get the interface name. From DefinePropertyIfFound (in
// xpcwrappednativejsops.cpp) and XPCThrower::Verbosify.
//
// We could instead make the quick stub could pass in its interface name,
// but this code often produces a more specific error message, e.g.
*ifaceName = "Unknown";
NS_ASSERTION(IS_WRAPPER_CLASS(STOBJ_GET_CLASS(obj)) ||
STOBJ_GET_CLASS(obj) == &XPC_WN_Tearoff_JSClass ||
IS_SLIM_WRAPPER(obj),
"obj must be a wrapper");
XPCWrappedNativeProto *proto;
if(IS_SLIM_WRAPPER(obj))
{
proto = GetSlimWrapperProto(obj);
}
else
{
XPCWrappedNative *wrapper = (XPCWrappedNative *) obj->getPrivate();
proto = wrapper->GetProto();
}
if(proto)
{
XPCNativeSet *set = proto->GetSet();
if(set)
{
XPCNativeMember *member;
XPCNativeInterface *iface;
if(set->FindMember(memberId, &member, &iface))
*ifaceName = iface->GetNameString();
}
}
*memberName = (JSVAL_IS_STRING(memberId)
? JS_GetStringBytes(JSVAL_TO_STRING(memberId))
: "unknown");
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:53,代码来源:xpcquickstubs.cpp
示例14: xjse_xpnet_do_queue
/** process requests in the queue.
*/
xjse_result_t xjse_xpnet_do_queue(XPNETCTX* pxpnctx)
{
xjse_result_t xr1 = XJSE_SUCCESS;
xjse_int_t i;
for(i = 0; i < XPNETC_NMAXREQQITEMS; i++) {
XPNETREQQITEM* pitem = &(pxpnctx->xpnetreqq[i]);
//XJSE_TRACE("(X) state (%d, %p)[%d]", i, pitem, pitem->state);
switch(pitem->state) {
case XPNREQQITEMSTATE_RESPREADY:
{
// response has been loaded, exec onreadystatechange.
jsval v1;
JSBool b1 = JS_GetProperty(
pitem->pjsctx, pitem->poxhr, "onreadystatechange", &v1);
if(b1 == JS_TRUE) {
jsval rv0;
b1 = JS_CallFunctionValue(
pitem->pjsctx, pitem->poxhr, v1, 0, 0, &rv0);
if(b1 != JS_TRUE) {
XJSE_TRACE("(E) JS_CallFunctionValue() failed!");
pitem->state = XPNREQQITEMSTATE_EMPTY;
goto failed;
}
XJSE_TRACE("(X) xjse_xhr_send() JS_CallFunctionValue() returned (%s).", JS_GetStringBytes(JS_ValueToString(pitem->pjsctx, rv0)));
}
//
pitem->state = XPNREQQITEMSTATE_EMPTY;
}
break;
case XPNREQQITEMSTATE_OBSOLETED:
XJSE_TRACE("(X) xjse_xpnet_do_queue(): obs'ed req detected. "
"(idx: %d)", i);
pitem->state = XPNREQQITEMSTATE_EMPTY;
break;
}
}
return XJSE_SUCCESS;
failed:
return xr1;
}
开发者ID:odistagon,项目名称:cyeonna,代码行数:46,代码来源:xjse_xpnet.c
示例15: dns_resolve
// dnsResolve in JS context; not available in core JavaScript.
// returns javascript null if not able to resolve.
static JSBool // JS_TRUE or JS_FALSE
dns_resolve(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* name = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char* out;
char ipaddr[INET6_ADDRSTRLEN] = "";
// Return null on failure.
if(resolve_host(name, ipaddr, 1, AF_INET)) {
*rval = JSVAL_NULL;
return JS_TRUE;
}
out = JS_malloc(cx, strlen(ipaddr) + 1);
strcpy(out, ipaddr);
JSString *str = JS_NewString(cx, out, strlen(out));
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
开发者ID:betaY,项目名称:crawler,代码行数:21,代码来源:pacparser.c
示例16: Load
static JSBool
Load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsJSSh* shell;
JSAutoRequest ar(cx);
if (!GetJSShGlobal(cx, obj, &shell)) return JS_FALSE;
for (unsigned int i=0; i<argc; ++i) {
JSString *str = JS_ValueToString(cx, argv[i]);
if (!str) return JS_FALSE;
//argv[i] = STRING_TO_JSVAL(str);
const char *url = JS_GetStringBytes(str);
if (!shell->LoadURL(url, rval))
return JS_FALSE;
}
return JS_TRUE;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:19,代码来源:nsJSSh.cpp
示例17: JS_GetStringBytes
JSBool ADM_JSAvidemux::Load(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval)
{// begin Load
ADM_JSAvidemux *p = (ADM_JSAvidemux *)JS_GetPrivate(cx, obj);
// default return value
*rval = BOOLEAN_TO_JSVAL(false);
if(argc != 1)
return JS_FALSE;
if(JSVAL_IS_STRING(argv[0]) == false)
return JS_FALSE;
char *pTempStr = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
printf("Loading \"%s\"\n",pTempStr);
// Do a failure instead of returing ko
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
jsrefcount nRefCount = JS_SuspendRequest(cx);
if(!A_openAvi(pTempStr)) return JS_FALSE;
JS_ResumeRequest(cx,nRefCount);
return JS_TRUE;
}// end Load
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:19,代码来源:ADM_JSAvidemux.cpp
示例18: js_prop_set_from_jsval
void
js_prop_set_from_jsval(JSContext *cx, prop_t *p, jsval value)
{
JSBool b;
if(JSVAL_IS_INT(value)) {
prop_set_int(p, JSVAL_TO_INT(value));
} else if(JSVAL_IS_BOOLEAN(value)) {
prop_set_int(p, JSVAL_TO_BOOLEAN(value));
} else if(JSVAL_IS_NULL(value) || JSVAL_IS_VOID(value)) {
prop_set_void(p);
} else if(JSVAL_IS_DOUBLE(value)) {
double d;
if(JS_ValueToNumber(cx, value, &d))
prop_set_float(p, d);
} else if(JS_HasInstance(cx, RichText, value, &b) && b) {
JSObject *o = JSVAL_TO_OBJECT(value);
jsval v2;
if(!JS_EnterLocalRootScope(cx))
return;
if(!JS_GetProperty(cx, o, "text", &v2)) {
JS_LeaveLocalRootScope(cx);
return;
}
prop_set_string_ex(p, NULL, JS_GetStringBytes(JS_ValueToString(cx, v2)),
PROP_STR_RICH);
JS_LeaveLocalRootScope(cx);
} else if(JSVAL_IS_STRING(value)) {
js_prop_from_str(cx, p, value);
} else if(JSVAL_IS_OBJECT(value)) {
JSObject *obj = JSVAL_TO_OBJECT(value);
JSClass *c = JS_GetClass(cx, obj);
if(!strcmp(c->name, "XML")) // Treat some classes special
js_prop_from_str(cx, p, value);
else
js_prop_from_object(cx, obj, p);
} else {
prop_set_void(p);
}
}
开发者ID:stallman,项目名称:showtime,代码行数:43,代码来源:js.c
示例19: Output_flush
JSBool
Output_flush (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JS_BeginRequest(cx);
JS_EnterLocalRootScope(cx);
jsval property;
JS_GetProperty(cx, obj, "content", &property);
FCGX_PutS(JS_GetStringBytes(JS_ValueToString(cx, property)), ((LCGIData*) JS_GetContextPrivate(cx))->cgi->out);
property = JS_GetEmptyStringValue(cx);
JS_SetProperty(cx, obj, "content", &property);
JS_LeaveLocalRootScope(cx);
JS_EndRequest(cx);
return JS_TRUE;
}
开发者ID:mandrake,项目名称:lulzjs,代码行数:19,代码来源:Output.cpp
示例20: js_ungetstr
static JSBool
js_ungetstr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* p;
sbbs_t* sbbs;
JSString* js_str;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
return(JS_FALSE);
p=JS_GetStringBytes(js_str);
while(p && *p)
sbbs->ungetkey(*(p++));
return(JS_TRUE);
}
开发者ID:ftnapps,项目名称:pkg-sbbs,代码行数:19,代码来源:js_console.cpp
注:本文中的JS_GetStringBytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论