Bug 752226 - Remove any use of JSVAL_IS_OBJECT. r=luke,Ms2ger

This commit is contained in:
Tom Schuster 2012-05-11 17:46:26 +02:00
parent 0f7357a542
commit 448c19e69b
34 changed files with 305 additions and 332 deletions

View File

@ -164,19 +164,20 @@ nsSecurityNameSet::InitializeNameSet(nsIScriptContext* aScriptContext)
obj = proto;
JSClass *objectClass = JS_GetClass(obj);
jsval v;
JS::Value v;
if (!JS_GetProperty(cx, global, "netscape", &v))
return NS_ERROR_FAILURE;
JSObject *securityObj;
if (JSVAL_IS_OBJECT(v)) {
if (v.isObject()) {
/*
* "netscape" property of window object exists; get the
* "security" property.
*/
obj = JSVAL_TO_OBJECT(v);
if (!JS_GetProperty(cx, obj, "security", &v) || !JSVAL_IS_OBJECT(v))
obj = &v.toObject();
if (!JS_GetProperty(cx, obj, "security", &v) || !v.isObject())
return NS_ERROR_FAILURE;
securityObj = JSVAL_TO_OBJECT(v);
securityObj = &v.toObject();
} else {
/* define netscape.security object */
obj = JS_DefineObject(cx, global, "netscape", objectClass, nsnull, 0);

View File

@ -404,18 +404,18 @@ nsDOMBlobBuilder::GetFile(const nsAString& aName,
/* [implicit_jscontext] void append (in jsval data,
[optional] in DOMString endings); */
NS_IMETHODIMP
nsDOMBlobBuilder::Append(const jsval& aData,
nsDOMBlobBuilder::Append(const JS::Value& aData,
const nsAString& aEndings, JSContext* aCx)
{
// We need to figure out what our jsval is
// Just return for null
if (aData.isNull())
return NS_OK;
// Is it an object?
if (JSVAL_IS_OBJECT(aData)) {
JSObject* obj = JSVAL_TO_OBJECT(aData);
if (!obj) {
// We got passed null. Just do nothing.
return NS_OK;
}
if (aData.isObject()) {
JSObject* obj = &aData.toObject();
// Is it a Blob?
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(

View File

@ -517,7 +517,7 @@ nsDOMFileFile::Initialize(nsISupports* aOwner,
JSContext* aCx,
JSObject* aObj,
PRUint32 aArgc,
jsval* aArgv)
JS::Value* aArgv)
{
nsresult rv;
@ -533,14 +533,13 @@ nsDOMFileFile::Initialize(nsISupports* aOwner,
// We expect to get a path to represent as a File object,
// or an nsIFile
nsCOMPtr<nsIFile> file;
if (!JSVAL_IS_STRING(aArgv[0])) {
if (!aArgv[0].isString()) {
// Lets see if it's an nsIFile
if (!JSVAL_IS_OBJECT(aArgv[0])) {
if (!aArgv[0].isObject()) {
return NS_ERROR_UNEXPECTED; // We're not interested
}
JSObject* obj = JSVAL_TO_OBJECT(aArgv[0]);
NS_ASSERTION(obj, "This is a bit odd");
JSObject* obj = &aArgv[0].toObject();
// Is it an nsIFile
file = do_QueryInterface(

View File

@ -326,16 +326,16 @@ nsDOMParser::Init(nsIPrincipal* principal, nsIURI* documentURI,
}
static nsQueryInterface
JSvalToInterface(JSContext* cx, jsval val, nsIXPConnect* xpc, bool* wasNull)
JSvalToInterface(JSContext* cx, JS::Value val, nsIXPConnect* xpc, bool* wasNull)
{
if (val == JSVAL_NULL) {
if (val.isNull()) {
*wasNull = true;
return nsQueryInterface(nsnull);
}
*wasNull = false;
if (JSVAL_IS_OBJECT(val)) {
JSObject* arg = JSVAL_TO_OBJECT(val);
if (val.isObject()) {
JSObject* arg = &val.toObject();
nsCOMPtr<nsIXPConnectWrappedNative> native;
xpc->GetWrappedNativeOfJSObject(cx, arg, getter_AddRefs(native));

View File

@ -453,10 +453,10 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
jsval thisValue = JSVAL_VOID;
jsval funval = JSVAL_VOID;
JS::Value funval;
if (JS_ObjectIsCallable(ctx, object)) {
// If the listener is a JS function:
funval = OBJECT_TO_JSVAL(object);
funval.setObject(*object);
// A small hack to get 'this' value right on content side where
// messageManager is wrapped in TabChildGlobal.
@ -471,13 +471,13 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
defaultThisValue, &thisValue, nsnull, true);
} else {
// If the listener is a JS object which has receiveMessage function:
NS_ENSURE_STATE(JS_GetProperty(ctx, object, "receiveMessage",
&funval) &&
JSVAL_IS_OBJECT(funval) &&
!JSVAL_IS_NULL(funval));
JSObject* funobject = JSVAL_TO_OBJECT(funval);
NS_ENSURE_STATE(JS_ObjectIsCallable(ctx, funobject));
thisValue = OBJECT_TO_JSVAL(object);
if (!JS_GetProperty(ctx, object, "receiveMessage", &funval) ||
!funval.isObject())
return NS_ERROR_UNEXPECTED;
// Check if the object is even callable.
NS_ENSURE_STATE(JS_ObjectIsCallable(ctx, &funval.toObject()));
thisValue.setObject(*object);
}
jsval rval = JSVAL_VOID;

View File

@ -562,7 +562,7 @@ nsWebSocket::Initialize(nsISupports* aOwner,
JSContext* aContext,
JSObject* aObject,
PRUint32 aArgc,
jsval* aArgv)
JS::Value* aArgv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsAutoString urlParam;
@ -608,11 +608,10 @@ nsWebSocket::Initialize(nsISupports* aOwner,
nsTArray<nsString> protocolArray;
if (aArgc == 2) {
JSObject *jsobj;
if (aArgv[1].isObject() &&
JS_IsArrayObject(aContext, &aArgv[1].toObject())) {
JSObject* jsobj = &aArgv[1].toObject();
if (JSVAL_IS_OBJECT(aArgv[1]) &&
(jsobj = JSVAL_TO_OBJECT(aArgv[1])) &&
JS_IsArrayObject(aContext, jsobj)) {
uint32_t len;
JS_GetArrayLength(aContext, jsobj, &len);

View File

@ -193,14 +193,14 @@ nsIDOMWebGLRenderingContext_TexImage2D(JSContext *cx, unsigned argc, jsval *vp)
if (argc < 6 || argc == 7 || argc == 8)
return xpc_qsThrow(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS);
jsval *argv = JS_ARGV(cx, vp);
JS::Value* argv = JS_ARGV(cx, vp);
// arguments common to all cases
GET_UINT32_ARG(argv0, 0);
GET_INT32_ARG(argv1, 1);
GET_UINT32_ARG(argv2, 2);
if (argc > 5 && !JSVAL_IS_PRIMITIVE(argv[5])) {
if (argc > 5 && argv[5].isObject()) {
// implement the variants taking a DOMElement as argv[5]
GET_UINT32_ARG(argv3, 3);
GET_UINT32_ARG(argv4, 4);
@ -210,7 +210,7 @@ nsIDOMWebGLRenderingContext_TexImage2D(JSContext *cx, unsigned argc, jsval *vp)
return false;
}
rv = NS_OK;
} else if (argc > 8 && JSVAL_IS_OBJECT(argv[8])) {
} else if (argc > 8 && argv[8].isObjectOrNull()) {
// here, we allow null !
// implement the variants taking a buffer/array as argv[8]
GET_INT32_ARG(argv3, 3);
@ -219,7 +219,7 @@ nsIDOMWebGLRenderingContext_TexImage2D(JSContext *cx, unsigned argc, jsval *vp)
GET_UINT32_ARG(argv6, 6);
GET_UINT32_ARG(argv7, 7);
JSObject *argv8 = JSVAL_TO_OBJECT(argv[8]);
JSObject* argv8 = argv[8].toObjectOrNull();
// then try to grab either a js::TypedArray, or null
if (argv8 == nsnull) {

View File

@ -498,7 +498,7 @@ nsHTMLCanvasElement::GetContextHelper(const nsAString& aContextId,
NS_IMETHODIMP
nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
const jsval& aContextOptions,
const JS::Value& aContextOptions,
nsISupports **aContext)
{
nsresult rv;
@ -521,52 +521,51 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId,
return NS_ERROR_FAILURE;
}
// note: if any contexts end up supporting something other
// than objects, e.g. plain strings, then we'll need to expand
// this to know how to create nsISupportsStrings etc.
nsCOMPtr<nsIWritablePropertyBag2> contextProps;
if (!JSVAL_IS_NULL(aContextOptions) &&
!JSVAL_IS_VOID(aContextOptions))
if (aContextOptions.isObject())
{
JSContext *cx = nsContentUtils::GetCurrentJSContext();
// note: if any contexts end up supporting something other
// than objects, e.g. plain strings, then we'll need to expand
// this to know how to create nsISupportsStrings etc.
if (JSVAL_IS_OBJECT(aContextOptions)) {
contextProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
contextProps = do_CreateInstance("@mozilla.org/hash-property-bag;1");
JSObject *opts = JSVAL_TO_OBJECT(aContextOptions);
JS::AutoIdArray props(cx, JS_Enumerate(cx, opts));
for (size_t i = 0; !!props && i < props.length(); ++i) {
jsid propid = props[i];
jsval propname, propval;
if (!JS_IdToValue(cx, propid, &propname) ||
!JS_GetPropertyById(cx, opts, propid, &propval)) {
continue;
}
JSObject *opts = &aContextOptions.toObject();
JS::AutoIdArray props(cx, JS_Enumerate(cx, opts));
for (size_t i = 0; !!props && i < props.length(); ++i) {
jsid propid = props[i];
jsval propname, propval;
if (!JS_IdToValue(cx, propid, &propname) ||
!JS_GetPropertyById(cx, opts, propid, &propval)) {
continue;
}
JSString *propnameString = JS_ValueToString(cx, propname);
nsDependentJSString pstr;
if (!propnameString || !pstr.init(cx, propnameString)) {
JSString *propnameString = JS_ValueToString(cx, propname);
nsDependentJSString pstr;
if (!propnameString || !pstr.init(cx, propnameString)) {
mCurrentContext = nsnull;
return NS_ERROR_FAILURE;
}
if (JSVAL_IS_BOOLEAN(propval)) {
contextProps->SetPropertyAsBool(pstr, JSVAL_TO_BOOLEAN(propval));
} else if (JSVAL_IS_INT(propval)) {
contextProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
} else if (JSVAL_IS_DOUBLE(propval)) {
contextProps->SetPropertyAsDouble(pstr, JSVAL_TO_DOUBLE(propval));
} else if (JSVAL_IS_STRING(propval)) {
JSString *propvalString = JS_ValueToString(cx, propval);
nsDependentJSString vstr;
if (!propvalString || !vstr.init(cx, propvalString)) {
mCurrentContext = nsnull;
return NS_ERROR_FAILURE;
}
if (JSVAL_IS_BOOLEAN(propval)) {
contextProps->SetPropertyAsBool(pstr, JSVAL_TO_BOOLEAN(propval));
} else if (JSVAL_IS_INT(propval)) {
contextProps->SetPropertyAsInt32(pstr, JSVAL_TO_INT(propval));
} else if (JSVAL_IS_DOUBLE(propval)) {
contextProps->SetPropertyAsDouble(pstr, JSVAL_TO_DOUBLE(propval));
} else if (JSVAL_IS_STRING(propval)) {
JSString *propvalString = JS_ValueToString(cx, propval);
nsDependentJSString vstr;
if (!propvalString || !vstr.init(cx, propvalString)) {
mCurrentContext = nsnull;
return NS_ERROR_FAILURE;
}
contextProps->SetPropertyAsAString(pstr, vstr);
}
contextProps->SetPropertyAsAString(pstr, vstr);
}
}
}

View File

@ -2087,19 +2087,19 @@ CreateExceptionFromResult(JSContext *cx, nsresult aResult)
return NS_ERROR_FAILURE;
}
jsval jv;
JS::Value jv;
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, ::JS_GetGlobalObject(cx), exception,
&NS_GET_IID(nsIException), false, &jv,
getter_AddRefs(holder));
if (NS_FAILED(rv) || JSVAL_IS_NULL(jv)) {
if (NS_FAILED(rv) || jv.isNull()) {
return NS_ERROR_FAILURE;
}
JSAutoEnterCompartment ac;
if (JSVAL_IS_OBJECT(jv)) {
if (!ac.enter(cx, JSVAL_TO_OBJECT(jv))) {
if (jv.isObject()) {
if (!ac.enter(cx, &jv.toObject())) {
return NS_ERROR_UNEXPECTED;
}
}
@ -6492,26 +6492,23 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx,
JSObject *proto = nsnull;
if (class_parent_name) {
jsval val;
JSAutoEnterCompartment ac;
if (!ac.enter(cx, winobj)) {
return NS_ERROR_UNEXPECTED;
}
if (!::JS_LookupProperty(cx, winobj, CutPrefix(class_parent_name), &val)) {
JS::Value val;
if (!JS_LookupProperty(cx, winobj, CutPrefix(class_parent_name), &val)) {
return NS_ERROR_UNEXPECTED;
}
JSObject *tmp = JSVAL_IS_OBJECT(val) ? JSVAL_TO_OBJECT(val) : nsnull;
if (tmp) {
if (!::JS_LookupProperty(cx, tmp, "prototype", &val)) {
if (val.isObject()) {
if (!JS_LookupProperty(cx, &val.toObject(), "prototype", &val)) {
return NS_ERROR_UNEXPECTED;
}
if (JSVAL_IS_OBJECT(val)) {
proto = JSVAL_TO_OBJECT(val);
if (val.isObject()) {
proto = &val.toObject();
}
}
}
@ -8956,8 +8953,9 @@ nsHTMLDocumentSH::CallToGetPropMapper(JSContext *cx, unsigned argc, jsval *vp)
// If we are called via document.all(id) instead of document.all.item(i) or
// another method, use the document.all callee object as self.
JSObject *self;
if (JSVAL_IS_OBJECT(JS_CALLEE(cx, vp)) &&
::JS_GetClass(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))) == &sHTMLDocumentAllClass) {
JS::Value callee = JS_CALLEE(cx, vp);
if (callee.isObject() &&
JS_GetClass(&callee.toObject()) == &sHTMLDocumentAllClass) {
self = JSVAL_TO_OBJECT(JS_CALLEE(cx, vp));
} else {
self = JS_THIS_OBJECT(cx, vp);
@ -9001,7 +8999,7 @@ PrivateToFlags(void *priv)
JSBool
nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp)
jsid id, JS::Value *vp)
{
if (id != nsDOMClassInfo::sAll_id) {
return JS_TRUE;
@ -9024,12 +9022,12 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
// or it was not being resolved with a qualified name. Claim that
// document.all is undefined.
*vp = JSVAL_VOID;
vp->setUndefined();
} else {
// document.all is not being detected, and it resolved with a
// qualified name. Expose the document.all collection.
if (!JSVAL_IS_OBJECT(*vp)) {
if (!vp->isObjectOrNull()) {
// First time through, create the collection, and set the
// document as its private nsISupports data.
nsresult rv;
@ -9051,7 +9049,7 @@ nsHTMLDocumentSH::DocumentAllHelperGetProperty(JSContext *cx, JSObject *obj,
doc.forget();
*vp = OBJECT_TO_JSVAL(all);
vp->setObject(*all);
}
}
@ -9495,25 +9493,20 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
// static
nsresult
nsHTMLSelectElementSH::SetOption(JSContext *cx, jsval *vp, PRUint32 aIndex,
nsHTMLSelectElementSH::SetOption(JSContext *cx, JS::Value *vp, PRUint32 aIndex,
nsIDOMHTMLOptionsCollection *aOptCollection)
{
JSAutoRequest ar(cx);
// vp must refer to an object
if (!JSVAL_IS_OBJECT(*vp) && !::JS_ConvertValue(cx, *vp, JSTYPE_OBJECT, vp)) {
if (!vp->isObject()) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIDOMHTMLOptionElement> new_option;
if (!JSVAL_IS_NULL(*vp)) {
new_option = do_QueryWrapper(cx, JSVAL_TO_OBJECT(*vp));
if (!new_option) {
// Someone is trying to set an option to a non-option object.
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIDOMHTMLOptionElement> new_option = do_QueryWrapper(cx, &vp->toObject());
if (!new_option) {
// Someone is trying to set an option to a non-option object.
return NS_ERROR_UNEXPECTED;
}
return aOptCollection->SetOption(aIndex, new_option);

View File

@ -204,7 +204,7 @@ WriteCallback(const jschar *buf, uint32_t len, void *data)
}
NS_IMETHODIMP
nsJSON::EncodeFromJSVal(jsval *value, JSContext *cx, nsAString &result)
nsJSON::EncodeFromJSVal(JS::Value *value, JSContext *cx, nsAString &result)
{
result.Truncate();
@ -212,9 +212,9 @@ nsJSON::EncodeFromJSVal(jsval *value, JSContext *cx, nsAString &result)
JSAutoRequest ar(cx);
JSAutoEnterCompartment ac;
JSObject *obj;
nsIScriptSecurityManager *ssm = nsnull;
if (JSVAL_IS_OBJECT(*value) && (obj = JSVAL_TO_OBJECT(*value))) {
if (value->isObject()) {
JSObject *obj = &value->toObject();
if (!ac.enter(cx, obj)) {
return NS_ERROR_FAILURE;
}
@ -254,14 +254,11 @@ nsJSON::EncodeInternal(JSContext* cx, const JS::Value& aValue, nsJSONWriter* wri
// Backward compatibility:
// nsIJSON does not allow to serialize anything other than objects
if (!JSVAL_IS_OBJECT(aValue)) {
if (!aValue.isObject()) {
return NS_ERROR_INVALID_ARG;
}
JSObject* obj = JSVAL_TO_OBJECT(aValue);
if (!obj) {
return NS_ERROR_INVALID_ARG;
}
JSObject* obj = &aValue.toObject();
JS::Value val = aValue;

View File

@ -1846,7 +1846,7 @@ WorkerRunnable::NotifyScriptExecutedIfNeeded() const
struct WorkerPrivate::TimeoutInfo
{
TimeoutInfo()
: mTimeoutVal(JSVAL_VOID), mLineNumber(0), mId(0), mIsInterval(false),
: mTimeoutVal(JS::UndefinedValue()), mLineNumber(0), mId(0), mIsInterval(false),
mCanceled(false)
{
MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo);
@ -1867,7 +1867,7 @@ struct WorkerPrivate::TimeoutInfo
return mTargetTime < aOther.mTargetTime;
}
jsval mTimeoutVal;
JS::Value mTimeoutVal;
nsTArray<jsval> mExtraArgVals;
mozilla::TimeStamp mTargetTime;
mozilla::TimeDuration mInterval;
@ -3619,11 +3619,11 @@ WorkerPrivate::SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp,
mNextTimeoutId = 1;
}
jsval* argv = JS_ARGV(aCx, aVp);
JS::Value* argv = JS_ARGV(aCx, aVp);
// Take care of the main argument.
if (JSVAL_IS_OBJECT(argv[0])) {
if (JS_ObjectIsCallable(aCx, JSVAL_TO_OBJECT(argv[0]))) {
if (argv[0].isObject()) {
if (JS_ObjectIsCallable(aCx, &argv[0].toObject())) {
newInfo->mTimeoutVal = argv[0];
}
else {
@ -3631,10 +3631,10 @@ WorkerPrivate::SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp,
if (!timeoutStr) {
return false;
}
newInfo->mTimeoutVal = STRING_TO_JSVAL(timeoutStr);
newInfo->mTimeoutVal.setString(timeoutStr);
}
}
else if (JSVAL_IS_STRING(argv[0])) {
else if (argv[0].isString()) {
newInfo->mTimeoutVal = argv[0];
}
else {
@ -3651,7 +3651,7 @@ WorkerPrivate::SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp,
}
newInfo->mInterval = TimeDuration::FromMilliseconds(intervalMS);
if (aArgc > 2 && JSVAL_IS_OBJECT(newInfo->mTimeoutVal)) {
if (aArgc > 2 && newInfo->mTimeoutVal.isObject()) {
nsTArray<jsval> extraArgVals(aArgc - 2);
for (unsigned index = 2; index < aArgc; index++) {
extraArgVals.AppendElement(argv[index]);
@ -3662,7 +3662,7 @@ WorkerPrivate::SetTimeout(JSContext* aCx, unsigned aArgc, jsval* aVp,
newInfo->mTargetTime = TimeStamp::Now() + newInfo->mInterval;
if (JSVAL_IS_STRING(newInfo->mTimeoutVal)) {
if (newInfo->mTimeoutVal.isString()) {
const char* filenameChars;
PRUint32 lineNumber;
if (nsJSUtils::GetCallingLocation(aCx, &filenameChars, &lineNumber)) {
@ -3786,8 +3786,8 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
// JS_ReportPendingException returns false (i.e. uncatchable exception) then
// break out of the loop.
if (JSVAL_IS_STRING(info->mTimeoutVal)) {
JSString* expression = JSVAL_TO_STRING(info->mTimeoutVal);
if (info->mTimeoutVal.isString()) {
JSString* expression = info->mTimeoutVal.toString();
size_t stringLength;
const jschar* string = JS_GetStringCharsAndLength(aCx, expression,

View File

@ -297,19 +297,18 @@ private:
static JSBool
UnwrapErrorEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JS_ASSERT(JSVAL_IS_OBJECT(JS_CALLEE(aCx, aVp)));
JS_ASSERT(aArgc == 1);
JS_ASSERT(JSVAL_IS_OBJECT(JS_ARGV(aCx, aVp)[0]));
JS_ASSERT((JS_ARGV(aCx, aVp)[0]).isObject());
JSObject* wrapper = JSVAL_TO_OBJECT(JS_CALLEE(aCx, aVp));
JSObject* wrapper = &JS_CALLEE(aCx, aVp).toObject();
JS_ASSERT(JS_ObjectIsFunction(aCx, wrapper));
jsval scope = js::GetFunctionNativeReserved(wrapper, SLOT_wrappedScope);
jsval listener = js::GetFunctionNativeReserved(wrapper, SLOT_wrappedFunction);
JS_ASSERT(JSVAL_IS_OBJECT(scope));
JS_ASSERT(scope.isObject());
JSObject* event = JSVAL_TO_OBJECT(JS_ARGV(aCx, aVp)[0]);
JSObject* event = &JS_ARGV(aCx, aVp)[0].toObject();
jsval argv[3] = { JSVAL_VOID, JSVAL_VOID, JSVAL_VOID };
if (!JS_GetProperty(aCx, event, "message", &argv[0]) ||

View File

@ -51,7 +51,7 @@ void JSD_ASSERT_VALID_VALUE(JSDValue* jsdval)
if(!JS_CLIST_IS_EMPTY(&jsdval->props))
{
JS_ASSERT(CHECK_BIT_FLAG(jsdval->flags, GOT_PROPS));
JS_ASSERT(JSVAL_IS_OBJECT(jsdval->val));
JS_ASSERT(!JSVAL_IS_PRIMITIVE(jsdval->val));
}
if(jsdval->proto)
@ -87,7 +87,7 @@ void JSD_ASSERT_VALID_PROPERTY(JSDProperty* jsdprop)
JSBool
jsd_IsValueObject(JSDContext* jsdc, JSDValue* jsdval)
{
return JSVAL_IS_OBJECT(jsdval->val);
return !JSVAL_IS_PRIMITIVE(jsdval->val) || JSVAL_IS_NULL(jsdval->val);
}
JSBool
@ -449,7 +449,7 @@ static JSBool _buildProps(JSDContext* jsdc, JSDValue* jsdval)
JS_ASSERT(JS_CLIST_IS_EMPTY(&jsdval->props));
JS_ASSERT(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PROPS)));
JS_ASSERT(JSVAL_IS_OBJECT(jsdval->val));
JS_ASSERT(!JSVAL_IS_PRIMITIVE(jsdval->val));
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return JS_FALSE;
@ -675,16 +675,16 @@ jsd_GetValueFunction(JSDContext* jsdc, JSDValue* jsdval)
{
JSObject *obj;
JSFunction *fun;
JSCrossCompartmentCall *call = NULL;
if (!JSVAL_IS_OBJECT(jsdval->val))
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
return NULL;
obj = JS_UnwrapObject(obj);
JSCrossCompartmentCall *call = NULL;
if (JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JS_UnwrapObject(JSVAL_TO_OBJECT(jsdval->val));
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
if (!call)
return NULL;
fun = JS_ValueToFunction(jsdc->dumbContext, OBJECT_TO_JSVAL(obj));
JS_LeaveCrossCompartmentCall(call);
@ -702,10 +702,9 @@ jsd_GetValuePrototype(JSDContext* jsdc, JSDValue* jsdval)
JSObject* proto;
JS_ASSERT(!jsdval->proto);
SET_BIT_FLAG(jsdval->flags, GOT_PROTO);
if(!JSVAL_IS_OBJECT(jsdval->val))
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JSVAL_TO_OBJECT(jsdval->val);
proto = JS_GetPrototype(obj);
if(!proto)
return NULL;
@ -727,10 +726,9 @@ jsd_GetValueParent(JSDContext* jsdc, JSDValue* jsdval)
JSObject* parent;
JS_ASSERT(!jsdval->parent);
SET_BIT_FLAG(jsdval->flags, GOT_PARENT);
if(!JSVAL_IS_OBJECT(jsdval->val))
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JSVAL_TO_OBJECT(jsdval->val);
JS_BeginRequest(jsdc->dumbContext);
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
if(!call) {
@ -762,10 +760,9 @@ jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
JSObject* ctor;
JS_ASSERT(!jsdval->ctor);
SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
if(!JSVAL_IS_OBJECT(jsdval->val))
return NULL;
if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
if(JSVAL_IS_PRIMITIVE(jsdval->val))
return NULL;
obj = JSVAL_TO_OBJECT(jsdval->val);
proto = JS_GetPrototype(obj);
if(!proto)
return NULL;
@ -794,11 +791,9 @@ jsd_GetValueClassName(JSDContext* jsdc, JSDValue* jsdval)
jsval val = jsdval->val;
JSCrossCompartmentCall *call = NULL;
if(!jsdval->className && JSVAL_IS_OBJECT(val))
if(!jsdval->className && !JSVAL_IS_PRIMITIVE(val))
{
JSObject* obj;
if(!(obj = JSVAL_TO_OBJECT(val)))
return NULL;
JSObject* obj = JSVAL_TO_OBJECT(val);
JS_BeginRequest(jsdc->dumbContext);
call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
if(!call) {

View File

@ -2240,7 +2240,7 @@ jsdValue::GetJsType (PRUint32 *_rval)
*_rval = TYPE_VOID;
else if (JSD_IsValueFunction (mCx, mValue))
*_rval = TYPE_FUNCTION;
else if (JSVAL_IS_OBJECT(val))
else if (!JSVAL_IS_PRIMITIVE(val))
*_rval = TYPE_OBJECT;
else
NS_ASSERTION (0, "Value has no discernible type.");

View File

@ -3633,8 +3633,8 @@ PointerType::ConstructData(JSContext* cx,
jsval* argv = JS_ARGV(cx, vp);
JSObject* baseObj = PointerType::GetBaseType(obj);
bool looksLikeClosure = CType::GetTypeCode(baseObj) == TYPE_function &&
JSVAL_IS_OBJECT(argv[0]) &&
JS_ObjectIsCallable(cx, JSVAL_TO_OBJECT(argv[0]));
argv[0].isObject() &&
JS_ObjectIsCallable(cx, &argv[0].toObject());
//
// Case 2 - Initialized pointer
@ -3656,7 +3656,9 @@ PointerType::ConstructData(JSContext* cx,
// wish to pass the third argument.
JSObject* thisObj = NULL;
if (argc >= 2) {
if (JSVAL_IS_OBJECT(argv[1])) {
if (JSVAL_IS_NULL(argv[1])) {
thisObj = NULL;
} else if (!JSVAL_IS_PRIMITIVE(argv[1])) {
thisObj = JSVAL_TO_OBJECT(argv[1]);
} else if (!JS_ValueToObject(cx, argv[1], &thisObj)) {
return JS_FALSE;
@ -3696,7 +3698,7 @@ PointerType::TargetTypeGetter(JSContext* cx,
}
*vp = JS_GetReservedSlot(obj, SLOT_TARGET_T);
JS_ASSERT(JSVAL_IS_OBJECT(*vp));
JS_ASSERT(vp->isObject());
return JS_TRUE;
}
@ -6530,12 +6532,12 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval *vp)
}
jsval* argv = JS_ARGV(cx, vp);
jsval valCodePtr = argv[1];
if (!JSVAL_IS_OBJECT(valCodePtr) || JSVAL_IS_NULL(valCodePtr)) {
JS::Value valCodePtr = argv[1];
if (!valCodePtr.isObject()) {
return TypeError(cx, "_a CData object_ of a function pointer type",
valCodePtr);
}
JSObject *objCodePtr = JSVAL_TO_OBJECT(valCodePtr);
JSObject *objCodePtr = &valCodePtr.toObject();
//Note: Using a custom argument formatter here would be awkward (requires
//a destructor just to uninstall the formatter).

View File

@ -4,19 +4,19 @@ BEGIN_TEST(test_BindCallable)
{
jsval v;
EVAL("({ somename : 1717 })", &v);
CHECK(JSVAL_IS_OBJECT(v));
CHECK(v.isObject());
jsval func;
EVAL("(function() { return this.somename; })", &func);
CHECK(JSVAL_IS_OBJECT(func));
CHECK(func.isObject());
JSObject* newCallable = JS_BindCallable(cx, JSVAL_TO_OBJECT(func),
JSVAL_TO_OBJECT(v));
JSVAL_TO_OBJECT(v));
CHECK(newCallable);
jsval retval;
bool called = JS_CallFunctionValue(cx, NULL, OBJECT_TO_JSVAL(newCallable),
0, NULL, &retval);
0, NULL, &retval);
CHECK(called);
CHECK(JSVAL_IS_INT(retval));

View File

@ -6,7 +6,7 @@ BEGIN_TEST(testConservativeGC)
{
jsval v2;
EVAL("({foo: 'bar'});", &v2);
CHECK(JSVAL_IS_OBJECT(v2));
CHECK(v2.isObject());
char objCopy[sizeof(JSObject)];
js_memcpy(&objCopy, JSVAL_TO_OBJECT(v2), sizeof(JSObject));
@ -18,7 +18,7 @@ BEGIN_TEST(testConservativeGC)
jsval tmp;
EVAL("({foo2: 'bar2'});", &tmp);
CHECK(JSVAL_IS_OBJECT(tmp));
CHECK(tmp.isObject());
JSObject *obj2 = JSVAL_TO_OBJECT(tmp);
char obj2Copy[sizeof(JSObject)];
js_memcpy(&obj2Copy, obj2, sizeof(JSObject));

View File

@ -24,8 +24,8 @@ BEGIN_TEST(testLookup_bug522590)
// This lookup must not return an internal function object.
jsvalRoot r(cx);
CHECK(JS_LookupProperty(cx, xobj, "f", r.addr()));
CHECK(JSVAL_IS_OBJECT(r));
JSObject *funobj = JSVAL_TO_OBJECT(r);
CHECK(r.value().isObject());
JSObject *funobj = &r.value().toObject();
CHECK(funobj->isFunction());
CHECK(!js::IsInternalFunctionObject(funobj));

View File

@ -36,7 +36,7 @@ BEGIN_TEST(testTrap_gc)
// execute
jsvalRoot v2(cx);
CHECK(JS_ExecuteScript(cx, global, script, v2.addr()));
CHECK(JSVAL_IS_OBJECT(v2));
CHECK(v2.value().isObject());
CHECK_EQUAL(emptyTrapCallCount, 0);
// Enable debug mode

View File

@ -2696,18 +2696,14 @@ EvalInFrame(JSContext *cx, unsigned argc, jsval *vp)
}
static JSBool
ShapeOf(JSContext *cx, unsigned argc, jsval *vp)
ShapeOf(JSContext *cx, unsigned argc, JS::Value *vp)
{
jsval v;
if (argc < 1 || !JSVAL_IS_OBJECT(v = JS_ARGV(cx, vp)[0])) {
JS::Value v;
if (argc < 1 || !((v = JS_ARGV(cx, vp)[0]).isObject())) {
JS_ReportError(cx, "shapeOf: object expected");
return JS_FALSE;
}
JSObject *obj = JSVAL_TO_OBJECT(v);
if (!obj) {
*vp = JSVAL_ZERO;
return JS_TRUE;
}
JSObject *obj = &v.toObject();
return JS_NewNumberValue(cx, (double) ((uintptr_t)obj->lastProperty() >> 3), vp);
}
@ -3856,13 +3852,13 @@ Help(JSContext *cx, unsigned argc, jsval *vp)
jsval v;
if (!JS_LookupPropertyById(cx, global, ida[i], &v))
return false;
if (JSVAL_IS_OBJECT(v) && !PrintHelp(cx, JSVAL_TO_OBJECT(v)))
if (!JSVAL_IS_PRIMITIVE(v) && !PrintHelp(cx, JSVAL_TO_OBJECT(v)))
return false;
}
} else {
jsval *argv = JS_ARGV(cx, vp);
for (unsigned i = 0; i < argc; i++) {
if (JSVAL_IS_OBJECT(argv[i]) && !PrintHelp(cx, JSVAL_TO_OBJECT(argv[i])))
if (!JSVAL_IS_PRIMITIVE(argv[i]) && !PrintHelp(cx, JSVAL_TO_OBJECT(argv[i])))
return false;
}
}

View File

@ -516,21 +516,20 @@ ReferenceFinder::addReferrer(jsval referrer, Path *path)
Root<jsval> referrerRoot(context, &referrer);
/* Find the property of the results object named |pathName|. */
jsval v;
JS::Value v;
if (!JS_GetProperty(context, result, pathName, &v))
return false;
if (JSVAL_IS_VOID(v)) {
if (v.isUndefined()) {
/* Create an array to accumulate referents under this path. */
JSObject *array = JS_NewArrayObject(context, 1, &referrer);
if (!array)
return false;
v = OBJECT_TO_JSVAL(array);
v.setObject(*array);
return !!JS_SetProperty(context, result, pathName, &v);
}
/* The property's value had better be an array. */
JS_ASSERT(JSVAL_IS_OBJECT(v) && !JSVAL_IS_NULL(v));
RootedVarObject array(context, JSVAL_TO_OBJECT(v));
RootedVarObject array(context, &v.toObject());
JS_ASSERT(JS_IsArrayObject(context, array));
/* Append our referrer to this array. */
@ -561,8 +560,8 @@ FindReferences(JSContext *cx, unsigned argc, jsval *vp)
return false;
}
jsval target = JS_ARGV(cx, vp)[0];
if (!JSVAL_IS_OBJECT(target) || JSVAL_IS_NULL(target)) {
JS::Value target = JS_ARGV(cx, vp)[0];
if (!target.isObject()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_UNEXPECTED_TYPE,
"argument", "not an object");
return false;
@ -575,7 +574,7 @@ FindReferences(JSContext *cx, unsigned argc, jsval *vp)
/* Given the reversed map, find the referents of target. */
ReferenceFinder finder(cx, reverser);
JSObject *references = finder.findReferences(RootedVarObject(cx, JSVAL_TO_OBJECT(target)));
JSObject *references = finder.findReferences(RootedVarObject(cx, &target.toObject()));
if (!references)
return false;

View File

@ -971,7 +971,7 @@ class ErrorEvent : public Event
public:
static ErrorEvent *create(JSContext *cx, Worker *child) {
JSString *data = NULL;
jsval exc;
JS::Value exc;
if (JS_GetPendingException(cx, &exc)) {
AutoValueRooter tvr(cx, exc);
JS_ClearPendingException(cx);
@ -979,12 +979,12 @@ class ErrorEvent : public Event
// Determine what error message to put in the error event.
// If exc.message is a string, use that; otherwise use String(exc).
// (This is a little different from what web workers do.)
if (JSVAL_IS_OBJECT(exc)) {
jsval msg;
if (!JS_GetProperty(cx, JSVAL_TO_OBJECT(exc), "message", &msg))
if (exc.isObject()) {
JS::Value msg;
if (!JS_GetProperty(cx, &exc.toObject(), "message", &msg))
JS_ClearPendingException(cx);
else if (JSVAL_IS_STRING(msg))
data = JSVAL_TO_STRING(msg);
else if (msg.isString())
data = msg.toString();
}
if (!data) {
data = JS_ValueToString(cx, exc);

View File

@ -1013,11 +1013,12 @@ mozJSComponentLoader::Import(const nsACString& registryLocation,
if (optionalArgc) {
// The caller passed in the optional second argument. Get it.
if (!JSVAL_IS_OBJECT(targetObj)) {
if (targetObj.isObjectOrNull()) {
targetObject = targetObj.toObjectOrNull();
} else {
return ReportOnCaller(cx, ERROR_SCOPE_OBJ,
PromiseFlatCString(registryLocation).get());
PromiseFlatCString(registryLocation).get());
}
targetObject = JSVAL_TO_OBJECT(targetObj);
} else {
// Our targetObject is the caller's global object. Find it by
// walking the calling object's parent chain.
@ -1171,7 +1172,6 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
NS_ASSERTION(mod->global, "Import table contains entry with no global");
*_retval = mod->global;
jsval symbols;
if (targetObj) {
JSCLContextHelper cxhelper(this);
@ -1179,20 +1179,21 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
if (!ac.enter(mContext, mod->global))
return NS_ERROR_FAILURE;
JS::Value symbols;
if (!JS_GetProperty(mContext, mod->global,
"EXPORTED_SYMBOLS", &symbols)) {
return ReportOnCaller(cxhelper, ERROR_NOT_PRESENT,
PromiseFlatCString(aLocation).get());
}
JSObject *symbolsObj = nsnull;
if (!JSVAL_IS_OBJECT(symbols) ||
!(symbolsObj = JSVAL_TO_OBJECT(symbols)) ||
!JS_IsArrayObject(mContext, symbolsObj)) {
if (!symbols.isObject() ||
!JS_IsArrayObject(mContext, &symbols.toObject())) {
return ReportOnCaller(cxhelper, ERROR_NOT_AN_ARRAY,
PromiseFlatCString(aLocation).get());
}
JSObject *symbolsObj = &symbols.toObject();
// Iterate over symbols array, installing symbols on targetObj:
uint32_t symbolCount = 0;

View File

@ -135,8 +135,8 @@ public:
* Explicit JSObject* conversion.
*/
JSObject* ToJSObject() const {
return JSVAL_IS_OBJECT(mVal)
? JSVAL_TO_OBJECT(mVal)
return mVal.isObject()
? &mVal.toObject()
: nsnull;
}

View File

@ -3315,7 +3315,7 @@ nsXPCComponents_utils_Sandbox::Construct(nsIXPConnectWrappedNative *wrapper,
nsresult
nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrapper,
JSContext * cx, JSObject * obj,
PRUint32 argc, jsval * argv,
PRUint32 argc, JS::Value * argv,
jsval * vp, bool *_retval)
{
if (argc < 1)
@ -3327,8 +3327,8 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
nsCOMPtr<nsIScriptObjectPrincipal> sop;
nsCOMPtr<nsIPrincipal> principal;
nsISupports *prinOrSop = nsnull;
if (JSVAL_IS_STRING(argv[0])) {
JSString *codebaseStr = JSVAL_TO_STRING(argv[0]);
if (argv[0].isString()) {
JSString *codebaseStr = argv[0].toString();
size_t codebaseLength;
const jschar *codebaseChars = JS_GetStringCharsAndLength(cx, codebaseStr,
&codebaseLength);
@ -3356,12 +3356,12 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
prinOrSop = principal;
} else {
if (!JSVAL_IS_PRIMITIVE(argv[0])) {
if (argv[0].isObject()) {
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
if (!xpc)
return NS_ERROR_XPC_UNEXPECTED;
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
xpc->GetWrappedNativeOfJSObject(cx, JSVAL_TO_OBJECT(argv[0]),
xpc->GetWrappedNativeOfJSObject(cx, &argv[0].toObject(),
getter_AddRefs(wrapper));
if (wrapper) {
@ -3384,10 +3384,10 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
nsCString sandboxName;
if (argc > 1) {
if (!JSVAL_IS_OBJECT(argv[1]))
if (!argv[1].isObject())
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
JSObject *optionsObject = JSVAL_TO_OBJECT(argv[1]);
JSObject *optionsObject = &argv[1].toObject();
jsval option;
JSBool found;
@ -3396,11 +3396,11 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
if (found) {
if (!JS_GetProperty(cx, optionsObject, "sandboxPrototype", &option) ||
!JSVAL_IS_OBJECT(option)) {
!option.isObject()) {
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
proto = JSVAL_TO_OBJECT(option);
proto = &option.toObject();
}
if (!JS_HasProperty(cx, optionsObject, "wantXrays", &found))
@ -3408,11 +3408,11 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
if (found) {
if (!JS_GetProperty(cx, optionsObject, "wantXrays", &option) ||
!JSVAL_IS_BOOLEAN(option)) {
!option.isBoolean()) {
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
wantXrays = JSVAL_TO_BOOLEAN(option);
wantXrays = option.toBoolean();
}
if (!JS_HasProperty(cx, optionsObject, "sandboxName", &found))
@ -3420,11 +3420,11 @@ nsXPCComponents_utils_Sandbox::CallOrConstruct(nsIXPConnectWrappedNative *wrappe
if (found) {
if (!JS_GetProperty(cx, optionsObject, "sandboxName", &option) ||
!JSVAL_IS_STRING(option)) {
!option.isString()) {
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
char *tmp = JS_EncodeString(cx, JSVAL_TO_STRING(option));
char *tmp = JS_EncodeString(cx, option.toString());
if (!tmp) {
return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
}
@ -3869,18 +3869,18 @@ nsXPCComponents_Utils::SchedulePreciseShrinkingGC(ScheduledGCCallback* aCallback
/* [implicit_jscontext] jsval nondeterministicGetWeakMapKeys(in jsval aMap); */
NS_IMETHODIMP
nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(const jsval &aMap,
nsXPCComponents_Utils::NondeterministicGetWeakMapKeys(const JS::Value &aMap,
JSContext *aCx,
jsval *aKeys)
JS::Value *aKeys)
{
if (!JSVAL_IS_OBJECT(aMap)) {
*aKeys = JSVAL_VOID;
if (!aMap.isObject()) {
aKeys->setUndefined();
return NS_OK;
}
JSObject *objRet;
if (!JS_NondeterministicGetWeakMapKeys(aCx, JSVAL_TO_OBJECT(aMap), &objRet))
if (!JS_NondeterministicGetWeakMapKeys(aCx, &aMap.toObject(), &objRet))
return NS_ERROR_OUT_OF_MEMORY;
*aKeys = objRet ? OBJECT_TO_JSVAL(objRet) : JSVAL_VOID;
*aKeys = objRet ? ObjectValue(*objRet) : UndefinedValue();
return NS_OK;
}
@ -3961,8 +3961,9 @@ nsXPCComponents_Utils::CreateObjectIn(const jsval &vobj, JSContext *cx, jsval *r
JSBool
FunctionWrapper(JSContext *cx, unsigned argc, jsval *vp)
{
jsval v = js::GetFunctionNativeReserved(JSVAL_TO_OBJECT(JS_CALLEE(cx, vp)), 0);
NS_ASSERTION(JSVAL_IS_OBJECT(v), "weird function");
JSObject *callee = &JS_CALLEE(cx, vp).toObject();
JS::Value v = js::GetFunctionNativeReserved(callee, 0);
NS_ASSERTION(v.isObject(), "weird function");
JSObject *obj = JS_THIS_OBJECT(cx, vp);
if (!obj) {

View File

@ -529,19 +529,17 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
return false;
case nsXPTType::T_IID:
{
JSObject* obj;
const nsID* pid=nsnull;
const nsID* pid = nsnull;
// There's no good reason to pass a null IID.
if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) {
if (s.isNullOrUndefined()) {
if (pErr)
*pErr = NS_ERROR_XPC_BAD_CONVERT_JS;
*pErr = NS_ERROR_XPC_BAD_CONVERT_JS;
return false;
}
if (!JSVAL_IS_OBJECT(s) ||
(!(obj = JSVAL_TO_OBJECT(s))) ||
(!(pid = xpc_JSObjectToID(cx, obj))) ||
if (!s.isObject() ||
(!(pid = xpc_JSObjectToID(cx, &s.toObject()))) ||
(!(pid = (const nsID*) nsMemory::Clone(pid, sizeof(nsID))))) {
return false;
}
@ -796,7 +794,6 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
case nsXPTType::T_INTERFACE:
case nsXPTType::T_INTERFACE_IS:
{
JSObject* obj;
NS_ASSERTION(iid,"can't do interface conversions without iid");
if (iid->Equals(NS_GET_IID(nsIVariant))) {
@ -825,19 +822,19 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
}
//else ...
if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) {
if (s.isNullOrUndefined()) {
*((nsISupports**)d) = nsnull;
return true;
}
// only wrap JSObjects
if (!JSVAL_IS_OBJECT(s) || !(obj = JSVAL_TO_OBJECT(s))) {
if (pErr && JSVAL_IS_INT(s) && 0 == JSVAL_TO_INT(s))
if (!s.isObject()) {
if (pErr && s.isInt32() && 0 == s.toInt32())
*pErr = NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL;
return false;
}
return JSObject2NativeInterface(ccx, (void**)d, obj, iid,
return JSObject2NativeInterface(ccx, (void**)d, &s.toObject(), iid,
nsnull, pErr);
}
default:
@ -1743,7 +1740,7 @@ XPCConvert::JSTypedArray2Native(XPCCallContext& ccx,
// static
JSBool
XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, jsval s,
XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, JS::Value s,
uint32_t count, const nsXPTType& type,
const nsID* iid, nsresult* pErr)
{
@ -1751,21 +1748,11 @@ XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, jsval s,
JSContext* cx = ccx.GetJSContext();
// No Action, FRee memory, RElease object
enum CleanupMode {na, fr, re};
CleanupMode cleanupMode;
JSObject* jsarray = nsnull;
void* array = nsnull;
uint32_t initedCount;
jsval current;
// XXX add support for getting chars from strings
// XXX add support to indicate *which* array element was not convertable
if (JSVAL_IS_VOID(s) || JSVAL_IS_NULL(s)) {
if (s.isNullOrUndefined()) {
if (0 != count) {
if (pErr)
*pErr = NS_ERROR_XPC_NOT_ENOUGH_ELEMENTS_IN_ARRAY;
@ -1776,13 +1763,13 @@ XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, jsval s,
return true;
}
if (!JSVAL_IS_OBJECT(s)) {
if (!s.isObject()) {
if (pErr)
*pErr = NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY;
return false;
}
jsarray = JSVAL_TO_OBJECT(s);
JSObject* jsarray = &s.toObject();
// If this is a typed array, then try a fast conversion with memcpy.
if (JS_IsTypedArrayObject(jsarray, cx)) {
@ -1823,9 +1810,16 @@ XPCConvert::JSArray2Native(XPCCallContext& ccx, void** d, jsval s,
} \
PR_END_MACRO
// No Action, FRee memory, RElease object
enum CleanupMode {na, fr, re};
CleanupMode cleanupMode;
void *array = nsnull;
uint32_t initedCount;
jsval current;
// XXX check IsPtr - esp. to handle array of nsID (as opposed to nsID*)
// XXX make extra space at end of char* and wchar* and null termintate
switch (type.TagPart()) {

View File

@ -79,7 +79,6 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
PRInt32 lineno = 0;
JSFunction* fun = nsnull;
uint32_t namedArgCount = 0;
jsval val;
JSBool isString;
// get the info for this stack frame
@ -152,11 +151,11 @@ static char* FormatJSFrame(JSContext* cx, JSStackFrame* fp,
}
// print any unnamed trailing args (found in 'arguments' object)
JS::Value val;
if (JS_GetProperty(cx, callObj, "arguments", &val) &&
JSVAL_IS_OBJECT(val)) {
val.isObject()) {
uint32_t argCount;
JSObject* argsObj = JSVAL_TO_OBJECT(val);
JSObject* argsObj = &val.toObject();
if (JS_GetProperty(cx, argsObj, "length", &val) &&
JS_ValueToECMAUint32(cx, val, &argCount) &&
argCount > namedArgCount) {

View File

@ -821,24 +821,24 @@ xpc_qsUnwrapThisFromCcxImpl(XPCCallContext &ccx,
}
JSObject*
xpc_qsUnwrapObj(jsval v, nsISupports **ppArgRef, nsresult *rv)
xpc_qsUnwrapObj(JS::Value v, nsISupports **ppArgRef, nsresult *rv)
{
if (JSVAL_IS_VOID(v) || JSVAL_IS_NULL(v)) {
if (v.isNullOrUndefined()) {
*ppArgRef = nsnull;
*rv = NS_OK;
return nsnull;
}
if (!JSVAL_IS_OBJECT(v)) {
if (!v.isObject()) {
*ppArgRef = nsnull;
*rv = ((JSVAL_IS_INT(v) && JSVAL_TO_INT(v) == 0)
*rv = ((v.isInt32() && v.toInt32() == 0)
? NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL
: NS_ERROR_XPC_BAD_CONVERT_JS);
return nsnull;
}
*rv = NS_OK;
return JSVAL_TO_OBJECT(v);
return &v.toObject();
}
nsresult

View File

@ -117,8 +117,8 @@ XPCTraceableVariant::PrintTraceName(JSTracer* trc, char *buf, size_t bufsize)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
jsval val = tmp->GetJSValPreserveColor();
if (JSVAL_IS_OBJECT(val)) {
JS::Value val = tmp->GetJSValPreserveColor();
if (val.isObjectOrNull()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSVal");
cb.NoteJSChild(JSVAL_TO_OBJECT(val));
}
@ -127,19 +127,19 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
jsval val = tmp->GetJSValPreserveColor();
JS::Value val = tmp->GetJSValPreserveColor();
// We're sharing val's buffer, clear the pointer to it so Cleanup() won't
// try to delete it
if (JSVAL_IS_STRING(val))
if (val.isString())
tmp->mData.u.wstr.mWStringValue = nsnull;
nsVariant::Cleanup(&tmp->mData);
if (JSVAL_IS_TRACEABLE(val)) {
if (val.isMarkable()) {
XPCTraceableVariant *v = static_cast<XPCTraceableVariant*>(tmp);
v->RemoveFromRootSet(nsXPConnect::GetRuntimeInstance()->GetMapLock());
}
tmp->mJSVal = JSVAL_NULL;
tmp->mJSVal = JS::NullValue();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
// static
@ -221,26 +221,26 @@ XPCArrayHomogenizer::GetTypeForArray(XPCCallContext& ccx, JSObject* array,
Type type;
for (uint32_t i = 0; i < length; i++) {
jsval val;
JS::Value val;
if (!JS_GetElement(ccx, array, i, &val))
return false;
if (JSVAL_IS_INT(val))
if (val.isInt32()) {
type = tInt;
else if (JSVAL_IS_DOUBLE(val))
} else if (val.isDouble()) {
type = tDbl;
else if (JSVAL_IS_BOOLEAN(val))
} else if (val.isBoolean()) {
type = tBool;
else if (JSVAL_IS_VOID(val)) {
} else if (val.isUndefined()) {
state = tVar;
break;
} else if (JSVAL_IS_NULL(val))
} else if (val.isNull()) {
type = tNull;
else if (JSVAL_IS_STRING(val))
} else if (val.isString()) {
type = tStr;
else {
NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
JSObject* jsobj = JSVAL_TO_OBJECT(val);
} else {
NS_ASSERTION(val.isObject(), "invalid type of jsval!");
JSObject* jsobj = &val.toObject();
if (JS_IsArrayObject(ccx, jsobj))
type = tArr;
else if (xpc_JSObjectIsID(ccx, jsobj))
@ -306,24 +306,22 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
{
JS_CHECK_RECURSION(ccx.GetJSContext(), return false);
jsval val = GetJSVal();
JS::Value val = GetJSVal();
if (JSVAL_IS_INT(val))
return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData, JSVAL_TO_INT(val)));
if (JSVAL_IS_DOUBLE(val))
return NS_SUCCEEDED(nsVariant::SetFromDouble(&mData,
JSVAL_TO_DOUBLE(val)));
if (JSVAL_IS_BOOLEAN(val))
return NS_SUCCEEDED(nsVariant::SetFromBool(&mData,
JSVAL_TO_BOOLEAN(val)));
if (JSVAL_IS_VOID(val))
if (val.isInt32())
return NS_SUCCEEDED(nsVariant::SetFromInt32(&mData, val.toInt32()));
if (val.isDouble())
return NS_SUCCEEDED(nsVariant::SetFromDouble(&mData, val.toDouble()));
if (val.isBoolean())
return NS_SUCCEEDED(nsVariant::SetFromBool(&mData, val.toBoolean()));
if (val.isUndefined())
return NS_SUCCEEDED(nsVariant::SetToVoid(&mData));
if (JSVAL_IS_NULL(val))
if (val.isNull())
return NS_SUCCEEDED(nsVariant::SetToEmpty(&mData));
if (JSVAL_IS_STRING(val)) {
if (val.isString()) {
// Make our string immutable. This will also ensure null-termination,
// which nsVariant assumes for its PRUnichar* stuff.
JSString* str = JSVAL_TO_STRING(val);
JSString* str = val.toString();
if (!JS_MakeStringImmutable(ccx, str))
return false;
@ -350,9 +348,9 @@ JSBool XPCVariant::InitializeData(XPCCallContext& ccx)
}
// leaving only JSObject...
NS_ASSERTION(JSVAL_IS_OBJECT(val), "invalid type of jsval!");
NS_ASSERTION(val.isObject(), "invalid type of jsval!");
JSObject* jsobj = JSVAL_TO_OBJECT(val);
JSObject* jsobj = &val.toObject();
// Let's see if it is a xpcJSID.

View File

@ -308,14 +308,14 @@ nsXPCWrappedJSClass::CallQueryInterfaceOnJSObject(XPCCallContext& ccx,
if (JS_GetPendingException(cx, &jsexception)) {
nsresult rv;
if (JSVAL_IS_OBJECT(jsexception)) {
if (jsexception.isObject()) {
// XPConnect may have constructed an object to represent a
// C++ QI failure. See if that is the case.
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
nsXPConnect::GetXPConnect()->
GetWrappedNativeOfJSObject(ccx,
JSVAL_TO_OBJECT(jsexception),
&jsexception.toObject(),
getter_AddRefs(wrapper));
if (wrapper) {

View File

@ -2644,9 +2644,9 @@ CallMethodHelper::GatherAndConvertResults()
mCallContext.SetRetVal(v);
} else if (i < mArgc) {
// we actually assured this before doing the invoke
NS_ASSERTION(JSVAL_IS_OBJECT(mArgv[i]), "out var is not object");
NS_ASSERTION(mArgv[i].isObject(), "out var is not object");
if (!JS_SetPropertyById(mCallContext,
JSVAL_TO_OBJECT(mArgv[i]),
&mArgv[i].toObject(),
mIdxValueId, &v)) {
ThrowBadParam(NS_ERROR_XPC_CANT_SET_OUT_VAL, i, mCallContext);
return false;
@ -2670,11 +2670,14 @@ CallMethodHelper::QueryInterfaceFastPath() const
Throw(NS_ERROR_XPC_NOT_ENOUGH_ARGS, mCallContext);
return false;
}
const nsID* iid;
JSObject* obj;
if (!JSVAL_IS_OBJECT(mArgv[0]) ||
(!(obj = JSVAL_TO_OBJECT(mArgv[0]))) ||
(!(iid = xpc_JSObjectToID(mCallContext, obj)))) {
if (!mArgv[0].isObject()) {
ThrowBadParam(NS_ERROR_XPC_BAD_CONVERT_JS, 0, mCallContext);
return false;
}
const nsID* iid = xpc_JSObjectToID(mCallContext, &mArgv[0].toObject());
if (!iid) {
ThrowBadParam(NS_ERROR_XPC_BAD_CONVERT_JS, 0, mCallContext);
return false;
}

View File

@ -2890,30 +2890,29 @@ JS_EXPORT_API(void) DumpJSObject(JSObject* obj)
xpc_DumpJSObject(obj);
}
JS_EXPORT_API(void) DumpJSValue(jsval val)
JS_EXPORT_API(void) DumpJSValue(JS::Value val)
{
printf("Dumping 0x%llu.\n", (long long) JSVAL_TO_IMPL(val).asBits);
if (JSVAL_IS_NULL(val)) {
printf("Dumping 0x%llu.\n", (long long) val.asRawBits());
if (val.isNull()) {
printf("Value is null\n");
} else if (JSVAL_IS_OBJECT(val) || JSVAL_IS_NULL(val)) {
} else if (val.isObject()) {
printf("Value is an object\n");
JSObject* obj = JSVAL_TO_OBJECT(val);
DumpJSObject(obj);
} else if (JSVAL_IS_NUMBER(val)) {
DumpJSObject(&val.toObject());
} else if (val.isNumber()) {
printf("Value is a number: ");
if (JSVAL_IS_INT(val))
printf("Integer %i\n", JSVAL_TO_INT(val));
else if (JSVAL_IS_DOUBLE(val))
printf("Floating-point value %f\n", JSVAL_TO_DOUBLE(val));
} else if (JSVAL_IS_STRING(val)) {
if (val.isInt32())
printf("Integer %i\n", val.toInt32());
else if (val.isDouble())
printf("Floating-point value %f\n", val.toDouble());
} else if (val.isString()) {
printf("Value is a string: ");
putc('<', stdout);
JS_FileEscapedString(stdout, JSVAL_TO_STRING(val), 0);
JS_FileEscapedString(stdout, val.toString(), 0);
fputs(">\n", stdout);
} else if (JSVAL_IS_BOOLEAN(val)) {
} else if (val.isBoolean()) {
printf("Value is boolean: ");
printf(JSVAL_TO_BOOLEAN(val) ? "true" : "false");
} else if (JSVAL_IS_VOID(val)) {
printf(val.isTrue() ? "true" : "false");
} else if (val.isUndefined()) {
printf("Value is undefined\n");
} else {
printf("No idea what this value is.\n");

View File

@ -533,20 +533,20 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapper, jsid id, Wrapper:
return true;
}
jsval exposedProps;
JS::Value exposedProps;
if (!JS_LookupPropertyById(cx, wrappedObject, exposedPropsId, &exposedProps))
return false;
if (JSVAL_IS_VOID(exposedProps) || JSVAL_IS_NULL(exposedProps)) {
if (exposedProps.isNullOrUndefined()) {
return PermitIfUniversalXPConnect(cx, id, act, perm); // Deny
}
if (!JSVAL_IS_OBJECT(exposedProps)) {
if (!exposedProps.isObject()) {
JS_ReportError(cx, "__exposedProps__ must be undefined, null, or an Object");
return false;
}
JSObject *hallpass = JSVAL_TO_OBJECT(exposedProps);
JSObject *hallpass = &exposedProps.toObject();
Access access = NO_ACCESS;

View File

@ -147,30 +147,29 @@ checkAndLogStatementPerformance(sqlite3_stmt *aStatement)
nsIVariant *
convertJSValToVariant(
JSContext *aCtx,
jsval aValue)
JS::Value aValue)
{
if (JSVAL_IS_INT(aValue))
return new IntegerVariant(JSVAL_TO_INT(aValue));
if (aValue.isInt32())
return new IntegerVariant(aValue.toInt32());
if (JSVAL_IS_DOUBLE(aValue))
return new FloatVariant(JSVAL_TO_DOUBLE(aValue));
if (aValue.isDouble())
return new FloatVariant(aValue.toDouble());
if (JSVAL_IS_STRING(aValue)) {
JSString *str = JSVAL_TO_STRING(aValue);
if (aValue.isString()) {
nsDependentJSString value;
if (!value.init(aCtx, str))
if (!value.init(aCtx, aValue))
return nsnull;
return new TextVariant(value);
}
if (JSVAL_IS_BOOLEAN(aValue))
return new IntegerVariant((aValue == JSVAL_TRUE) ? 1 : 0);
if (aValue.isBoolean())
return new IntegerVariant(aValue.isTrue() ? 1 : 0);
if (JSVAL_IS_NULL(aValue))
if (aValue.isNull())
return new NullVariant();
if (JSVAL_IS_OBJECT(aValue)) {
JSObject *obj = JSVAL_TO_OBJECT(aValue);
if (aValue.isObject()) {
JSObject* obj = &aValue.toObject();
// We only support Date instances, all others fail.
if (!::js_DateIsValid(aCtx, obj))
return nsnull;