本文整理汇总了C++中JSVAL_IS_STRING函数的典型用法代码示例。如果您正苦于以下问题:C++ JSVAL_IS_STRING函数的具体用法?C++ JSVAL_IS_STRING怎么用?C++ JSVAL_IS_STRING使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JSVAL_IS_STRING函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CommonConstructor
static JSBool
CommonConstructor(JSContext *cx, int name, JSObject *obj, uintN argc,
jsval *argv, jsval *rval, PRBool enforceSecurity)
{
XPCCallContext ccx(JS_CALLER, cx, JS_GetGlobalObject(cx));
// Check if IDispatch is enabled, fail if not
if(!nsXPConnect::IsIDispatchEnabled())
{
XPCThrower::Throw(NS_ERROR_XPC_IDISPATCH_NOT_ENABLED, ccx);
return JS_FALSE;
}
XPCJSRuntime *rt = ccx.GetRuntime();
if(!rt)
{
XPCThrower::Throw(NS_ERROR_UNEXPECTED, ccx);
return JS_FALSE;
}
nsIXPCSecurityManager* sm = ccx.GetXPCContext()
->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CALL_METHOD);
XPCWrappedNative * wrapper = ccx.GetWrapper();
if(sm && NS_FAILED(sm->CanAccess(nsIXPCSecurityManager::ACCESS_CALL_METHOD,
&ccx, ccx, ccx.GetFlattenedJSObject(),
wrapper->GetIdentityObject(),
wrapper->GetClassInfo(),
rt->GetStringJSVal(name),
wrapper->GetSecurityInfoAddr())))
{
// Security manager will have set an exception
return JS_FALSE;
}
// Make sure we were called with one string parameter
if(argc != 1 || (argc == 1 && !JSVAL_IS_STRING(argv[0])))
{
XPCThrower::Throw(NS_ERROR_XPC_COM_INVALID_CLASS_ID, ccx);
return JS_FALSE;
}
JSString* str = JSVAL_TO_STRING(argv[0]);
PRUint32 len = JS_GetStringLength(str);
// Cap constructor argument length to keep from crashing in string
// code.
if(len > XPC_IDISPATCH_CTOR_MAX_ARG_LEN)
{
XPCThrower::Throw(NS_ERROR_XPC_COM_INVALID_CLASS_ID, ccx);
return JS_FALSE;
}
jschar * className = JS_GetStringChars(str);
CComBSTR bstrClassName(len, reinterpret_cast<const WCHAR *>(className));
if(!bstrClassName)
{
XPCThrower::Throw(NS_ERROR_XPC_COM_INVALID_CLASS_ID, ccx);
return JS_FALSE;
}
// Instantiate the desired COM object
CComPtr<IDispatch> pDispatch;
HRESULT rv = XPCDispObject::COMCreateInstance(ccx, bstrClassName,
enforceSecurity, &pDispatch);
if(FAILED(rv))
{
XPCThrower::ThrowCOMError(ccx, rv, NS_ERROR_XPC_COM_CREATE_FAILED);
return JS_FALSE;
}
// Get a wrapper for our object
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult nsrv = ccx.GetXPConnect()->WrapNative(
ccx, ccx.GetOperandJSObject(), reinterpret_cast<nsISupports*>(pDispatch.p),
NSID_IDISPATCH, getter_AddRefs(holder));
if(NS_FAILED(nsrv))
{
XPCThrower::Throw(nsrv, ccx);
return JS_FALSE;
}
// get and return the JS object wrapper
JSObject * jsobj;
nsrv = holder->GetJSObject(&jsobj);
if(NS_FAILED(nsrv))
{
XPCThrower::Throw(nsrv, ccx);
return JS_FALSE;
}
*rval = OBJECT_TO_JSVAL(jsobj);
return JS_TRUE;
}
开发者ID:miebach,项目名称:Jaxer,代码行数:85,代码来源:XPCIDispatchExtension.cpp
示例2: JavaPackage_resolve
JavaPackage_resolve(JSContext *cx, JSObject *obj, jsval id)
{
JavaPackage_Private *package;
JSBool ok = JS_TRUE;
jclass jclazz;
char *subPath, *newPath;
const char *path;
JNIEnv *jEnv;
JSJavaThreadState *jsj_env;
/* Painful hack for pre_define_java_packages() */
if (quiet_resolve_failure)
return JS_FALSE;
package = (JavaPackage_Private *)JS_GetPrivate(cx, obj);
if (!package)
return JS_TRUE;
if (!JSVAL_IS_STRING(id))
return JS_TRUE;
subPath = JS_GetStringBytes(JSVAL_TO_STRING(id));
/*
* There will be an attempt to invoke the toString() method when producing
* the string representation of a JavaPackage. When this occurs, avoid
* creating a bogus toString package. (This means that no one can ever
* create a package with the simple name "toString", but we'll live with
* that limitation.)
*/
if (!strcmp(subPath, "toString"))
return JS_FALSE;
path = package->path;
newPath = JS_smprintf("%s%s%s", path, (path[0] ? "/" : ""), subPath);
if (!newPath) {
JS_ReportOutOfMemory(cx);
return JS_FALSE;
}
jsj_env = jsj_EnterJava(cx, &jEnv);
if (!jEnv) {
ok = JS_FALSE;
goto out;
}
/*
Unfortunately, Java provides no way to find out whether a particular
name is a package or not. The only way to tell is to try to load the
name as a class file and, if that fails, assume it's a package. This
makes things work as expected for the most part, but it has three
noticeable problems that keep coming up:
- You can refer to a package like java.lang.i.buried.paul without
generating a complaint. Of course, you'll never be able to refer to
any classes through it.
- An annoying consequence of the above is that misspelling a class name
results in a cryptic error about packages.
- In a browser context, i.e. where applets are involved, figuring out
whether something is a class may require looking for it over the net
using the current classloader. This means that the first time you
refer to java.lang.System in a js context, there will be an attempt
to search for [[DOCBASE]]/java.class on the server.
A solution is to explicitly tell jsjava the names of all the (local)
packages on the CLASSPATH. (Not implemented yet.)
*/
jclazz = (*jEnv)->FindClass(jEnv, newPath);
if (jclazz) {
JSObject *newClass;
newClass = jsj_define_JavaClass(cx, jEnv, obj, subPath, jclazz);
(*jEnv)->DeleteLocalRef(jEnv, jclazz);
if (!newClass) {
ok = JS_FALSE;
goto out;
}
} else {
/* We assume that any failed attempt to load a class is because it
doesn't exist. If we wanted to do a better job, we would check
the exception type and make sure that it's NoClassDefFoundError */
(*jEnv)->ExceptionClear(jEnv);
/*
* If there's no class of the given name, then we must be referring to
* a package. However, don't allow bogus sub-packages of pre-defined
* system packages to be created.
*/
if (JS_InstanceOf(cx, obj, &JavaPackage_class, NULL)) {
JavaPackage_Private *current_package;
current_package = JS_GetPrivate(cx, obj);
if (current_package->flags & PKG_SYSTEM) {
char *msg, *cp;
msg = JS_strdup(cx, newPath);
/* Check for OOM */
//.........这里部分代码省略.........
开发者ID:Kitiara,项目名称:UOX3,代码行数:101,代码来源:jsj_JavaPackage.c
示例3: gjstest_test_func_gjs_jsapi_util_error_throw
void
gjstest_test_func_gjs_jsapi_util_error_throw(void)
{
GjsUnitTestFixture fixture;
JSContext *context;
jsval exc, value, previous;
char *s = NULL;
int strcmp_result;
_gjs_unit_test_fixture_begin(&fixture);
context = fixture.context;
/* Test that we can throw */
gjs_throw(context, "This is an exception %d", 42);
g_assert(JS_IsExceptionPending(context));
exc = JSVAL_VOID;
JS_GetPendingException(context, &exc);
g_assert(!JSVAL_IS_VOID(exc));
value = JSVAL_VOID;
JS_GetProperty(context, JSVAL_TO_OBJECT(exc), "message",
&value);
g_assert(JSVAL_IS_STRING(value));
gjs_string_get_binary_data (context, value, &s, NULL);
g_assert(s != NULL);
strcmp_result = strcmp(s, "This is an exception 42");
free(s);
if (strcmp_result != 0)
g_error("Exception has wrong message '%s'", s);
/* keep this around before we clear it */
previous = exc;
JS_AddValueRoot(context, &previous);
JS_ClearPendingException(context);
g_assert(!JS_IsExceptionPending(context));
/* Check that we don't overwrite a pending exception */
JS_SetPendingException(context, previous);
g_assert(JS_IsExceptionPending(context));
gjs_throw(context, "Second different exception %s", "foo");
g_assert(JS_IsExceptionPending(context));
exc = JSVAL_VOID;
JS_GetPendingException(context, &exc);
g_assert(!JSVAL_IS_VOID(exc));
g_assert(exc == previous);
JS_RemoveValueRoot(context, &previous);
_gjs_unit_test_fixture_finish(&fixture);
}
开发者ID:Cobinja,项目名称:cjs,代码行数:61,代码来源:jsapi-util-error.c
示例4: 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_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:Displacer,项目名称:freewrl,代码行数:101,代码来源:jsj_convert.c
示例5: if
// static
JSBool
XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
jsuint length,
nsXPTType* resultType, nsID* resultID)
{
Type state = tUnk;
Type type;
for(jsuint i = 0; i < length; i++)
{
jsval val;
if(!JS_GetElement(ccx, array, i, &val))
return JS_FALSE;
if(JSVAL_IS_INT(val))
type = tInt;
else if(JSVAL_IS_DOUBLE(val))
type = tDbl;
else if(JSVAL_IS_BOOLEAN(val))
type = tBool;
else if(JSVAL_IS_VOID(val))
{
state = tVar;
break;
}
else if(JSVAL_IS_NULL(val))
type = tNull;
else if(JSVAL_IS_STRING(val))
type = tStr;
else
{
NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
JSObject* jsobj = JSVAL_TO_OBJECT(val);
if(JS_IsArrayObject(ccx, jsobj))
type = tArr;
else if(xpc_JSObjectIsID(ccx, jsobj))
type = tID;
else
type = tISup;
}
NS_ASSERTION(state != tErr, "bad state table!");
NS_ASSERTION(type != tErr, "bad type!");
NS_ASSERTION(type != tVar, "bad type!");
NS_ASSERTION(type != tUnk, "bad type!");
state = StateTable[state][type];
NS_ASSERTION(state != tErr, "bad state table!");
NS_ASSERTION(state != tUnk, "bad state table!");
if(state == tVar)
break;
}
switch(state)
{
case tInt :
*resultType = nsXPTType((uint8)TD_INT32);
break;
case tDbl :
*resultType = nsXPTType((uint8)TD_DOUBLE);
break;
case tBool:
*resultType = nsXPTType((uint8)TD_BOOL);
break;
case tStr :
*resultType = nsXPTType((uint8)(TD_PWSTRING | XPT_TDP_POINTER));
break;
case tID :
*resultType = nsXPTType((uint8)(TD_PNSIID | XPT_TDP_POINTER));
break;
case tISup:
*resultType = nsXPTType((uint8)(TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER));
*resultID = NS_GET_IID(nsISupports);
break;
case tNull:
// FALL THROUGH
case tVar :
*resultType = nsXPTType((uint8)(TD_INTERFACE_IS_TYPE | XPT_TDP_POINTER));
*resultID = NS_GET_IID(nsIVariant);
break;
case tArr :
// FALL THROUGH
case tUnk :
// FALL THROUGH
case tErr :
// FALL THROUGH
default:
NS_ERROR("bad state");
return JS_FALSE;
}
return JS_TRUE;
}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:95,代码来源:xpcvariant.cpp
示例6: js_Stringify
JSBool
js_Stringify(JSContext *cx, jsval *vp, JSObject *replacer,
JSONWriteCallback callback, void *data, uint32 depth)
{
if (depth > JSON_MAX_DEPTH)
return JS_FALSE; /* encoding error */
JSBool ok = JS_TRUE;
JSObject *obj = JSVAL_TO_OBJECT(*vp);
JSBool isArray = JS_IsArrayObject(cx, obj);
jschar output = jschar(isArray ? '[' : '{');
if (!callback(&output, 1, data))
return JS_FALSE;
JSObject *iterObj = NULL;
jsint i = 0;
jsuint length = 0;
if (isArray) {
if (!JS_GetArrayLength(cx, obj, &length))
return JS_FALSE;
} else {
if (!js_ValueToIterator(cx, JSITER_ENUMERATE, vp))
return JS_FALSE;
iterObj = JSVAL_TO_OBJECT(*vp);
}
jsval outputValue = JSVAL_VOID;
JSAutoTempValueRooter tvr(cx, 1, &outputValue);
jsval key;
JSBool memberWritten = JS_FALSE;
do {
outputValue = JSVAL_VOID;
if (isArray) {
if ((jsuint)i >= length)
break;
ok = JS_GetElement(cx, obj, i++, &outputValue);
} else {
ok = js_CallIteratorNext(cx, iterObj, &key);
if (!ok)
break;
if (key == JSVAL_HOLE)
break;
JSString *ks;
if (JSVAL_IS_STRING(key)) {
ks = JSVAL_TO_STRING(key);
} else {
ks = JS_ValueToString(cx, key);
if (!ks) {
ok = JS_FALSE;
break;
}
}
ok = JS_GetUCProperty(cx, obj, JS_GetStringChars(ks),
JS_GetStringLength(ks), &outputValue);
}
if (!ok)
break;
// if this is an array, holes are transmitted as null
if (isArray && outputValue == JSVAL_VOID) {
outputValue = JSVAL_NULL;
} else if (JSVAL_IS_OBJECT(outputValue)) {
ok = js_TryJSON(cx, &outputValue);
if (!ok)
break;
}
// elide undefined values
if (outputValue == JSVAL_VOID)
continue;
// output a comma unless this is the first member to write
if (memberWritten) {
output = jschar(',');
ok = callback(&output, 1, data);
if (!ok)
break;
}
memberWritten = JS_TRUE;
JSType type = JS_TypeOfValue(cx, outputValue);
// Can't encode these types, so drop them
if (type == JSTYPE_FUNCTION || type == JSTYPE_XML)
break;
// Be careful below, this string is weakly rooted.
JSString *s;
// If this isn't an array, we need to output a key
if (!isArray) {
s = JS_ValueToString(cx, key);
if (!s) {
ok = JS_FALSE;
//.........这里部分代码省略.........
开发者ID:artyyouth,项目名称:SpiderMonkey_JSON,代码行数:101,代码来源:json.cpp
示例7: jsd_IsValueString
JSBool
jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval)
{
return JSVAL_IS_STRING(jsdval->val);
}
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:5,代码来源:jsd_val.c
示例8: JS_GetPrivate
JSBool ADM_JSAvidemux::JSSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
if (JSVAL_IS_INT(id))
{
ADM_JSAvidemux *priv = (ADM_JSAvidemux *) JS_GetPrivate(cx, obj);
switch(JSVAL_TO_INT(id))
{
case markerA_prop:
if(JSVAL_IS_INT(*vp) == false)
break;
{
int f=JSVAL_TO_INT(*vp);
if (!avifileinfo)
{
return JS_FALSE;
}
if(f==-1)
f=avifileinfo->nb_frames-1;
if(f<0 || f>avifileinfo->nb_frames-1)
return JS_FALSE;
frameStart=f;
}
break;
case markerB_prop:
if(JSVAL_IS_INT(*vp) == false)
break;
{
int f=JSVAL_TO_INT(*vp);
if (!avifileinfo)
{
return JS_FALSE;
}
if(f==-1)
f=avifileinfo->nb_frames-1;
if(f<0 || f>avifileinfo->nb_frames-1)
return JS_FALSE;
frameEnd=f;
}
break;
case audio_prop:
return JS_FALSE;
break;
case video_prop:
return JS_FALSE;
break;
case container_prop:
if(JSVAL_IS_STRING(*vp) == false)
break;
{
priv->getObject()->m_pContainer = JSVAL_TO_STRING(*vp);
char *pContainer = JS_GetStringBytes(priv->getObject()->m_pContainer);
aprintf("Setting container format \"%s\"\n",pContainer);
if(A_setContainer(pContainer))
return JS_TRUE;
return JS_FALSE;
return JS_FALSE;
}
break;
case currentframe_prop:
if(JSVAL_IS_INT(*vp) == false)
break;
{
int frameno;
if (!avifileinfo)
return JS_FALSE;
frameno = JSVAL_TO_INT(*vp);
if( frameno<0)
{
aviInfo info;
video_body->getVideoInfo(&info);
frameno=-frameno;
if(frameno>info.nb_frames)
return JS_FALSE;
frameno = info.nb_frames-frameno;
}
enterLock();
if(GUI_GoToFrame( frameno ))
{
leaveLock();
return JS_TRUE;
}
leaveLock();
return JS_FALSE;
}
break;
case fps_prop:
if(JSVAL_IS_DOUBLE(*vp) == false)
break;
{
priv->getObject()->m_dFPS = *JSVAL_TO_DOUBLE(*vp);
aviInfo info;
if (avifileinfo)
{
video_body->getVideoInfo(&info);
info.fps1000 = (uint32_t)floor(priv->getObject()->m_dFPS*1000.f);
video_body->updateVideoInfo (&info);
video_body->getVideoInfo (avifileinfo);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:avidemux-svn,代码行数:101,代码来源:ADM_JSAvidemux.cpp
示例9: NS_WARNING
NS_IMETHODIMP
TCPSocketParent::SendCallback(const nsAString& aType, const JS::Value& aDataVal,
const nsAString& aReadyState, uint32_t aBuffered,
JSContext* aCx)
{
if (!mIPCOpen) {
NS_WARNING("Dropping callback due to no IPC connection");
return NS_OK;
}
CallbackData data;
if (aDataVal.isString()) {
JSString* jsstr = aDataVal.toString();
nsDependentJSString str;
if (!str.init(aCx, jsstr)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
data = str;
} else if (aDataVal.isUndefined() || aDataVal.isNull()) {
data = mozilla::void_t();
} else if (aDataVal.isObject()) {
JSObject* obj = &aDataVal.toObject();
if (JS_IsTypedArrayObject(obj)) {
NS_ENSURE_TRUE(JS_IsUint8Array(obj), NS_ERROR_FAILURE);
uint32_t nbytes = JS_GetTypedArrayByteLength(obj);
uint8_t* buffer = JS_GetUint8ArrayData(obj);
if (!buffer) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
FallibleTArray<uint8_t> fallibleArr;
if (!fallibleArr.InsertElementsAt(0, buffer, nbytes)) {
FireInteralError(this, __LINE__);
return NS_ERROR_OUT_OF_MEMORY;
}
InfallibleTArray<uint8_t> arr;
arr.SwapElements(fallibleArr);
data = SendableData(arr);
} else {
nsDependentJSString message, filename;
uint32_t lineNumber = 0;
uint32_t columnNumber = 0;
jsval val;
if (!JS_GetProperty(aCx, obj, "message", &val)) {
NS_ERROR("No message property on supposed error object");
} else if (JSVAL_IS_STRING(val)) {
if (!message.init(aCx, JSVAL_TO_STRING(val))) {
NS_WARNING("couldn't initialize string");
}
}
if (!JS_GetProperty(aCx, obj, "fileName", &val)) {
NS_ERROR("No fileName property on supposed error object");
} else if (JSVAL_IS_STRING(val)) {
if (!filename.init(aCx, JSVAL_TO_STRING(val))) {
NS_WARNING("couldn't initialize string");
}
}
if (!JS_GetProperty(aCx, obj, "lineNumber", &val)) {
NS_ERROR("No lineNumber property on supposed error object");
} else if (JSVAL_IS_INT(val)) {
lineNumber = JSVAL_TO_INT(val);
}
if (!JS_GetProperty(aCx, obj, "columnNumber", &val)) {
NS_ERROR("No columnNumber property on supposed error object");
} else if (JSVAL_IS_INT(val)) {
columnNumber = JSVAL_TO_INT(val);
}
data = JSError(message, filename, lineNumber, columnNumber);
}
} else {
NS_ERROR("Unexpected JS value encountered");
FireInteralError(this, __LINE__);
return NS_ERROR_FAILURE;
}
mozilla::unused <<
PTCPSocketParent::SendCallback(nsString(aType), data,
nsString(aReadyState), aBuffered);
return NS_OK;
}
开发者ID:bjacob,项目名称:mozilla-central,代码行数:88,代码来源:TCPSocketParent.cpp
示例10: JO
static JSBool
JO(JSContext *cx, jsval *vp, StringifyContext *scx)
{
JSObject *obj = JSVAL_TO_OBJECT(*vp);
if (!scx->cb.append('{'))
return JS_FALSE;
jsval vec[3] = {JSVAL_NULL, JSVAL_NULL, JSVAL_NULL};
JSAutoTempValueRooter tvr(cx, 3, vec);
jsval& key = vec[0];
jsval& outputValue = vec[1];
JSObject *iterObj = NULL;
jsval *keySource = vp;
bool usingWhitelist = false;
// if the replacer is an array, we use the keys from it
if (scx->replacer && JS_IsArrayObject(cx, scx->replacer)) {
usingWhitelist = true;
vec[2] = OBJECT_TO_JSVAL(scx->replacer);
keySource = &vec[2];
}
if (!js_ValueToIterator(cx, JSITER_ENUMERATE, keySource))
return JS_FALSE;
iterObj = JSVAL_TO_OBJECT(*keySource);
JSBool memberWritten = JS_FALSE;
bool ok = false;
while (true) {
outputValue = JSVAL_VOID;
if (!js_CallIteratorNext(cx, iterObj, &key))
goto error_break;
if (key == JSVAL_HOLE)
break;
jsuint index = 0;
if (usingWhitelist) {
// skip non-index properties
if (!js_IdIsIndex(key, &index))
continue;
jsval newKey;
if (!scx->replacer->getProperty(cx, key, &newKey))
goto error_break;
key = newKey;
}
JSString *ks;
if (JSVAL_IS_STRING(key)) {
ks = JSVAL_TO_STRING(key);
} else {
ks = js_ValueToString(cx, key);
if (!ks)
goto error_break;
}
JSAutoTempValueRooter keyStringRoot(cx, ks);
// Don't include prototype properties, since this operation is
// supposed to be implemented as if by ES3.1 Object.keys()
jsid id;
jsval v = JS_FALSE;
if (!js_ValueToStringId(cx, STRING_TO_JSVAL(ks), &id) ||
!js_HasOwnProperty(cx, obj->map->ops->lookupProperty, obj, id, &v)) {
goto error_break;
}
if (v != JSVAL_TRUE)
continue;
if (!JS_GetPropertyById(cx, obj, id, &outputValue))
goto error_break;
if (JSVAL_IS_OBJECT(outputValue) && !js_TryJSON(cx, &outputValue))
goto error_break;
// call this here, so we don't write out keys if the replacer function
// wants to elide the value.
if (!CallReplacerFunction(cx, id, obj, scx, &outputValue))
goto error_break;
JSType type = JS_TypeOfValue(cx, outputValue);
// elide undefined values and functions and XML
if (outputValue == JSVAL_VOID || type == JSTYPE_FUNCTION || type == JSTYPE_XML)
continue;
// output a comma unless this is the first member to write
if (memberWritten && !scx->cb.append(','))
goto error_break;
memberWritten = JS_TRUE;
if (!WriteIndent(cx, scx, scx->depth))
goto error_break;
// Be careful below, this string is weakly rooted
JSString *s = js_ValueToString(cx, key);
if (!s)
//.........这里部分代码省略.........
开发者ID:Loen-ring,项目名称:jscoverage-1,代码行数:101,代码来源:json.cpp
示例11: UNUSED
//.........这里部分代码省略.........
return JS_FALSE;
}
break;
}
case GUIST_float:
{
jsdouble value;
if (JS_ValueToNumber(cx, *vp, &value) == JS_TRUE)
GUI<float>::SetSetting(e, propName, (float)value);
else
{
JS_ReportError(cx, "Cannot convert value to float");
return JS_FALSE;
}
break;
}
case GUIST_bool:
{
JSBool value;
if (JS_ValueToBoolean(cx, *vp, &value) == JS_TRUE)
GUI<bool>::SetSetting(e, propName, value||0); // ||0 to avoid int-to-bool compiler warnings
else
{
JS_ReportError(cx, "Cannot convert value to bool");
return JS_FALSE;
}
break;
}
case GUIST_CClientArea:
{
if (JSVAL_IS_STRING(*vp))
{
std::wstring value;
if (!ScriptInterface::FromJSVal(cx, *vp, value))
return JS_FALSE;
if (e->SetSetting(propName, value) != PSRETURN_OK)
{
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
return JS_FALSE;
}
}
else if (JSVAL_IS_OBJECT(*vp) && JS_InstanceOf(cx, JSVAL_TO_OBJECT(*vp), &JSI_GUISize::JSI_class, NULL))
{
CClientArea area;
GUI<CClientArea>::GetSetting(e, propName, area);
JSObject* obj = JSVAL_TO_OBJECT(*vp);
#define P(x, y, z) area.x.y = (float)g_ScriptingHost.GetObjectProperty_Double(obj, #z)
P(pixel, left, left);
P(pixel, top, top);
P(pixel, right, right);
P(pixel, bottom, bottom);
P(percent, left, rleft);
P(percent, top, rtop);
P(percent, right, rright);
P(percent, bottom, rbottom);
#undef P
GUI<CClientArea>::SetSetting(e, propName, area);
}
else
{
开发者ID:Marlinc,项目名称:0ad,代码行数:67,代码来源:JSInterface_IGUIObject.cpp
示例12: SMJS_FUNCTION
static JSBool SMJS_FUNCTION(upnp_action_send_reply)
{
SMJS_OBJ
SMJS_ARGS
GPAC_GenericDevice *device = (GPAC_GenericDevice *)SMJS_GET_PRIVATE(c, obj);
if (!device) return JS_FALSE;
if (argc && JSVAL_IS_OBJECT(argv[0]) ) {
JSObject *list = JSVAL_TO_OBJECT(argv[0]);
u32 i, count;
JS_GetArrayLength(c, list, (jsuint*) &count);
GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Calling response %s(", (char *) device->act_ref->GetActionDesc().GetName()));
i=0;
while (i+2<=count) {
jsval an_arg;
NPT_Result res;
char *param_val, *_param_val = NULL;
char szParamVal[1024];
JS_GetElement(c, list, (jsint) i, &an_arg);
char *param_name = SMJS_CHARS(c, an_arg);
JS_GetElement(c, list, (jsint) i+1, &an_arg);
param_val = (char*)"";
if (JSVAL_IS_STRING(an_arg)) {
param_val = _param_val = SMJS_CHARS(c, an_arg);
} else if (JSVAL_IS_BOOLEAN(an_arg)) {
param_val = (char *) ((JSVAL_TO_BOOLEAN(an_arg) == JS_TRUE) ? "true" : "false");
}
else if (JSVAL_IS_INT(argv[1])) {
sprintf(szParamVal, "%d", JSVAL_TO_INT(an_arg));
param_val = szParamVal;
}
else if (JSVAL_IS_NUMBER(an_arg)) {
jsdouble v;
JS_ValueToNumber(c, an_arg, &v);
sprintf(szParamVal, "%g", v);
param_val = szParamVal;
}
if (!param_name || !param_val) res = NPT_FAILURE;
else {
GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, (" %s(%s)", param_name, param_val));
res = device->act_ref->SetArgumentValue(param_name, param_val);
}
SMJS_FREE(c, param_name);
SMJS_FREE(c, _param_val);
if (res != NPT_SUCCESS) return JS_FALSE;
i+=2;
}
GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, (" )\n"));
}
//notify we are ready
if (device->m_pSema) {
gf_sema_notify(device->m_pSema, 1);
}
return JS_TRUE;
}
开发者ID:ARSekkat,项目名称:gpac,代码行数:61,代码来源:GenericDevice.cpp
示例13: do_import
static JSBool
do_import(JSContext *context,
JSObject *obj,
Importer *priv,
const char *name)
{
char *filename;
char *full_path;
char *dirname = NULL;
jsval search_path_val;
JSObject *search_path;
JSObject *module_obj = NULL;
guint32 search_path_len;
guint32 i;
JSBool result;
GPtrArray *directories;
jsid search_path_name;
GFile *gfile;
gboolean exists;
search_path_name = gjs_context_get_const_string(context, GJS_STRING_SEARCH_PATH);
if (!gjs_object_require_property(context, obj, "importer", search_path_name, &search_path_val)) {
return JS_FALSE;
}
if (!JSVAL_IS_OBJECT(search_path_val)) {
gjs_throw(context, "searchPath property on importer is not an object");
return JS_FALSE;
}
search_path = JSVAL_TO_OBJECT(search_path_val);
if (!JS_IsArrayObject(context, search_path)) {
gjs_throw(context, "searchPath property on importer is not an array");
return JS_FALSE;
}
if (!JS_GetArrayLength(context, search_path, &search_path_len)) {
gjs_throw(context, "searchPath array has no length");
return JS_FALSE;
}
result = JS_FALSE;
filename = g_strdup_printf("%s.js", name);
full_path = NULL;
directories = NULL;
/* First try importing an internal module like byteArray */
if (priv->is_root &&
gjs_is_registered_native_module(context, obj, name) &&
import_native_file(context, obj, name)) {
gjs_debug(GJS_DEBUG_IMPORTER,
"successfully imported module '%s'", name);
result = JS_TRUE;
goto out;
}
for (i = 0; i < search_path_len; ++i) {
jsval elem;
elem = JSVAL_VOID;
if (!JS_GetElement(context, search_path, i, &elem)) {
/* this means there was an exception, while elem == JSVAL_VOID
* means no element found
*/
goto out;
}
if (JSVAL_IS_VOID(elem))
continue;
if (!JSVAL_IS_STRING(elem)) {
gjs_throw(context, "importer searchPath contains non-string");
goto out;
}
g_free(dirname);
dirname = NULL;
if (!gjs_string_to_utf8(context, elem, &dirname))
goto out; /* Error message already set */
/* Ignore empty path elements */
if (dirname[0] == '\0')
continue;
/* Try importing __init__.js and loading the symbol from it */
if (full_path)
g_free(full_path);
full_path = g_build_filename(dirname, MODULE_INIT_FILENAME,
NULL);
module_obj = load_module_init(context, obj, full_path);
if (module_obj != NULL) {
jsval obj_val;
if (JS_GetProperty(context,
module_obj,
name,
//.........这里部分代码省略.........
开发者ID:brownsr,项目名称:cjs,代码行数:101,代码来源:importer.cpp
示例14: screen_setProperty
static JSBool
screen_setProperty (JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
FILE *fOut;
JSString *str;
size_t n, i;
jschar *s;
if (JSVAL_IS_INT (id))
{
switch (JSVAL_TO_INT (id))
{
case SCREEN_AVAILHEIGHT:
case SCREEN_AVAILWIDTH:
case SCREEN_COLORDEPTH:
case SCREEN_HEIGHT:
case SCREEN_WIDTH:
fOut = fopen (SETTERLOG, "a");
if (fOut == NULL)
return JS_FALSE;
if (JSVAL_IS_INT (*vp))
{
fprintf (fOut, "screen set property read-only %s = %d\n",
screen_property_str[JSVAL_TO_INT (id)],
JSVAL_TO_INT (*vp));
}
else if (JSVAL_IS_STRING (*vp))
{
str = js_ValueToString (cx, *vp);
if (!str)
return JS_FALSE;
if (JSSTRING_IS_DEPENDENT (str))
{
n = JSSTRDEP_LENGTH (str);
s = JSSTRDEP_CHARS (str);
}
else
{
n = str->length;
s = str->chars;
}
fprintf (fOut, "screen set property read-only %s = \"",
screen_property_str[JSVAL_TO_INT (id)]);
if (n != 0)
{
for (i = 0; i < n; i++)
fputc (s[i], fOut);
}
fprintf (fOut, "\"\n");
}
else
{
fprintf (fOut,
"screen set property read-only %s to value of unknown type %x\n",
screen_property_str[JSVAL_TO_INT (id)],
JSVAL_TAG (*vp));
}
fclose (fOut);
break;
}
}
return JS_TRUE;
}
开发者ID:pankajtanwar,项目名称:ponkey,代码行数:63,代码来源:jsscreen.c
示例15: importer_new_enumerate
/*
* Like JSEnumerateOp, but enum provides contextual information as follows:
*
* JSENUMERATE_INIT: allocate private enum struct in state_p, return number
* of elements in *id_p
* JSENUMERATE_NEXT: return next property id in *id_p, and if no new property
* free state_p and set to JSVAL_NULL
* JSENUMERATE_DESTROY : destroy state_p
*
* Note that in a for ... in loop, this will be called first on the object,
* then on its prototype.
*
*/
static JSBool
importer_new_enumerate(JSContext *context,
JSObject **object,
JSIterateOp enum_op,
jsval *state_p,
jsid *id_p)
{
ImporterIterator *iter;
switch (enum_op) {
case JSENUMERATE_INIT_ALL:
case JSENUMERATE_INIT: {
Importer *priv;
JSObject *search_path;
jsval search_path_val;
guint32 search_path_len;
guint32 i;
jsid search_path_name;
if (state_p)
*state_p = JSVAL_NULL;
if (id_p)
*id_p = INT_TO_JSID(0);
priv = priv_from_js(context, *object);
if (!priv)
/* we are enumerating the prototype properties */
return JS_TRUE;
search_path_name = gjs_context_get_const_string(context, GJS_STRING_SEARCH_PATH);
if (!gjs_object_require_property(context, *object, "importer", search_path_name, &search_path_val))
return JS_FALSE;
if (!JSVAL_IS_OBJECT(search_path_val)) {
gjs_throw(context, "searchPath property on importer is not an object");
return JS_FALSE;
}
search_path = JSVAL_TO_OBJECT(search_path_val);
if (!JS_IsArrayObject(context, search_path)) {
gjs_throw(context, "searchPath property on importer is not an array");
return JS_FALSE;
}
if (!JS_GetArrayLength(context, search_path, &search_path_len)) {
gjs_throw(context, "searchPath array has no length");
return JS_FALSE;
}
iter = importer_iterator_new();
for (i = 0; i < search_path_len; ++i) {
char *dirname = NULL;
char *init_path;
const char *filename;
jsval elem;
GDir *dir = NULL;
elem = JSVAL_VOID;
if (!JS_GetElement(context, search_path, i, &elem)) {
/* this means there was an exception, while elem == JSVAL_VOID
* means no element found
*/
importer_iterator_free(iter);
return JS_FALSE;
}
if (JSVAL_IS_VOID(elem))
continue;
if (!JSVAL_IS_STRING(elem)) {
gjs_throw(context, "importer searchPath contains non-string");
importer_iterator_free(iter);
return JS_FALSE;
}
if (!gjs_string_to_utf8(context, elem, &dirname)) {
importer_iterator_free(iter);
return JS_FALSE; /* Error message already set */
}
init_path = g_build_filename(dirname, MODULE_INIT_FILENAME,
NULL);
//.........这里部分代码省略.........
开发者ID:brownsr,项目名称:cjs,代码行数:101,代码来源:importer.cpp
示例16: rpmts_dbkeys
static JSBool
rpmts_dbkeys(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL);
rpmts ts = ptr;
jsval tagid = JSVAL_VOID;
jsval v = JSVAL_VOID;
rpmTag tag = RPMTAG_NVRA;
rpmMireMode _mode = RPMMIRE_PCRE;
const char * _pat = "^a.*$";
ARGV_t _av = NULL;
JSBool ok = JS_FALSE;
int xx;
_METHOD_DEBUG_ENTRY(_debug);
if (!(ok = JS_ConvertArguments(cx, argc, argv, "/vvu", &v, &tagid, &v, &_mode)))
goto exit;
if (!JSVAL_IS_VOID(tagid)) {
/* XXX TODO: make sure both tag and key were specified. */
tag = JSVAL_IS_INT(tagid)
? (rpmTag) JSVAL_TO_INT(tagid)
: tagValue(JS_GetStringBytes(JS_ValueToString(cx, tagid)));
}
if (JSVAL_IS_VOID(v))
_pat = "^.*$";
else if (JSVAL_IS_NULL(v))
_pat = NULL;
else if (JSVAL_IS_STRING(v))
_pat = JS_GetStringBytes(JS_ValueToString(cx, v));
#ifdef NOTYET
else if (JSVAL_IS_NUMBER(v)) {
uint32_t _u = 0;
if (!JS_ValueToECMAUint32(cx, v, &_u)) {
*rval = JSVAL_VOID;
goto exit;
}
} else
;
#endif
switch (_mode) {
default:
*rval = JSVAL_VOID;
goto exit;
break;
case RPMMIRE_DEFAULT:
case RPMMIRE_STRCMP:
case RPMMIRE_REGEX:
case RPMMIRE_GLOB:
case RPMMIRE_PCRE:
break;
}
if (rpmtsGetRdb(ts) == NULL)
xx = rpmtsOpenDB(ts, O_RDONLY);
if (rpmdbMireApply(rpmtsGetRdb(ts), tag, _mode, _pat, &_av))
*rval = JSVAL_VOID;
else if (_av == NULL || _av[0] == NULL)
*rval = JSVAL_NULL;
else {
int _ac = argvCount(_av);
int i;
JSObject * arr = JS_NewArrayObject(cx, 0, NULL);
*rval = OBJECT_TO_JSVAL(arr);
for (i = 0; i < _ac; i++) {
v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _av[i]));
ok = JS_SetElement(cx, arr, i, &v);
}
}
exit:
ok = JS_TRUE;
_av = argvFree(_av);
return ok;
}
开发者ID:hahnakane,项目名称:junkcode,代码行数:80,代码来源:rpmts-js.c
示例17: js_ReportUncaughtException
JSBool
js_ReportUncaughtException(JSContext *cx)
{
jsval exn;
JSObject *exnObject;
jsval roots[5];
JSTempValueRooter tvr;
JSErrorReport *reportp, report;
JSString *str;
const char *bytes;
JSBool ok;
if (!JS_IsExceptionPending(cx))
return JS_TRUE;
if (!JS_GetPendingException(cx, &exn))
return JS_FALSE;
memset(roots, 0, sizeof roots);
|
请发表评论