Bug 952650 (part 6) - Remove JSVAL_IS_STRING. r=njn.

--HG--
extra : rebase_source : ebd55749447f9feea04a78ff7cc17ba2dd2c5cd0
This commit is contained in:
Rodrigo Rodriguez Jr. 2014-04-27 19:41:01 -07:00
parent 017da05366
commit d65b5ba4e5
21 changed files with 31 additions and 38 deletions

View File

@ -240,7 +240,7 @@ TCPSocketParent::SendEvent(const nsAString& aType, JS::Handle<JS::Value> aDataVa
JS::Rooted<JS::Value> val(aCx);
if (!JS_GetProperty(aCx, obj, "name", &val)) {
NS_ERROR("No name property on supposed error object");
} else if (JSVAL_IS_STRING(val)) {
} else if (val.isString()) {
if (!name.init(aCx, JSVAL_TO_STRING(val))) {
NS_WARNING("couldn't initialize string");
}

View File

@ -398,7 +398,7 @@ JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant)
} else {
DOUBLE_TO_NPVARIANT(d, *variant);
}
} else if (JSVAL_IS_STRING(val)) {
} else if (val.isString()) {
JSString *jsstr = JSVAL_TO_STRING(val);
size_t length;
const jschar *chars = ::JS_GetStringCharsZAndLength(cx, jsstr, &length);

View File

@ -110,7 +110,7 @@ global_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **o
JSBool ok, found;
JSFunction *fun;
if (!JSVAL_IS_STRING(id))
if (!id.isString())
return JS_TRUE;
path = getenv("PATH");
if (!path)

View File

@ -90,7 +90,7 @@ PostToNFC(JSContext* aCx,
JSAutoByteString abs;
void* data;
size_t size;
if (JSVAL_IS_STRING(v)) {
if (v.isString()) {
JS::Rooted<JSString*> str(aCx, v.toString());
if (!abs.encodeUtf8(aCx, str)) {
return false;

View File

@ -95,7 +95,7 @@ PostToRIL(JSContext *aCx,
JSAutoByteString abs;
void *data;
size_t size;
if (JSVAL_IS_STRING(v)) {
if (v.isString()) {
JS::Rooted<JSString*> str(aCx, v.toString());
if (!abs.encodeUtf8(aCx, str)) {
return false;

View File

@ -84,7 +84,7 @@ jsd_IsValueDouble(JSDContext* jsdc, JSDValue* jsdval)
bool
jsd_IsValueString(JSDContext* jsdc, JSDValue* jsdval)
{
return JSVAL_IS_STRING(jsdval->val);
return jsdval->val.isString();
}
bool
@ -179,7 +179,7 @@ jsd_GetValueString(JSDContext* jsdc, JSDValue* jsdval)
return jsdval->string;
/* Reuse the string without copying or re-rooting it */
if(JSVAL_IS_STRING(jsdval->val)) {
if(jsdval->val.isString()) {
jsdval->string = JSVAL_TO_STRING(jsdval->val);
return jsdval->string;
}
@ -253,7 +253,7 @@ jsd_NewValue(JSDContext* jsdc, jsval value)
JSAutoCompartment ac(cx, jsdc->glob);
ok = JS::AddNamedValueRoot(cx, &jsdval->val, "JSDValue");
if(ok && JSVAL_IS_STRING(val)) {
if(ok && val.isString()) {
if(!JS_WrapValue(cx, &val)) {
ok = false;
}
@ -409,7 +409,7 @@ jsd_RefreshValue(JSDContext* jsdc, JSDValue* jsdval)
if(jsdval->string)
{
/* if the jsval is a string, then we didn't need to root the string */
if(!JSVAL_IS_STRING(jsdval->val))
if(!jsdval->val.isString())
{
JSAutoCompartment ac(cx, jsdc->glob);
JS::RemoveStringRoot(cx, &jsdval->string);

View File

@ -2166,7 +2166,7 @@ jsdValue::GetJsType (uint32_t *_rval)
*_rval = TYPE_DOUBLE;
else if (JSVAL_IS_INT(val))
*_rval = TYPE_INT;
else if (JSVAL_IS_STRING(val))
else if (val.isString())
*_rval = TYPE_STRING;
else if (val.isUndefined())
*_rval = TYPE_VOID;

View File

@ -1877,16 +1877,10 @@ JSVAL_IS_NUMBER(jsval v)
return JSVAL_IS_NUMBER_IMPL(JSVAL_TO_IMPL(v));
}
static inline bool
JSVAL_IS_STRING(jsval v)
{
return JSVAL_IS_STRING_IMPL(JSVAL_TO_IMPL(v));
}
static inline JSString *
JSVAL_TO_STRING(jsval v)
{
MOZ_ASSERT(JSVAL_IS_STRING(v));
MOZ_ASSERT(v.isString());
return JSVAL_TO_STRING_IMPL(JSVAL_TO_IMPL(v));
}

View File

@ -1820,7 +1820,7 @@ jsvalToBigInteger(JSContext* cx,
double d = val.toDouble();
return ConvertExact(d, result);
}
if (allowString && JSVAL_IS_STRING(val)) {
if (allowString && val.isString()) {
// Allow conversion from base-10 or base-16 strings, provided the result
// fits in IntegerType. (This allows an Int64 or UInt64 object to be passed
// to the JS array element operator, which will automatically call
@ -2312,7 +2312,7 @@ ImplicitConvert(JSContext* cx,
/* Convert from a 1-character string, regardless of encoding, */ \
/* or from an integer, provided the result fits in 'type'. */ \
type result; \
if (JSVAL_IS_STRING(val)) { \
if (val.isString()) { \
JSString* str = JSVAL_TO_STRING(val); \
if (str->length() != 1) \
return TypeError(cx, #name, val); \
@ -2356,7 +2356,7 @@ ImplicitConvert(JSContext* cx,
}
}
} else if (isArgument && JSVAL_IS_STRING(val)) {
} else if (isArgument && val.isString()) {
// Convert the string for the ffi call. This requires allocating space
// which the caller assumes ownership of.
// TODO: Extend this so we can safely convert strings at other times also.
@ -2435,7 +2435,7 @@ ImplicitConvert(JSContext* cx,
RootedObject baseType(cx, ArrayType::GetBaseType(targetType));
size_t targetLength = ArrayType::GetLength(targetType);
if (JSVAL_IS_STRING(val)) {
if (val.isString()) {
JSString* sourceString = JSVAL_TO_STRING(val);
size_t sourceLength = sourceString->length();
const jschar* sourceChars = sourceString->getChars(cx);
@ -2651,7 +2651,7 @@ ExplicitConvert(JSContext* cx, HandleValue val, HandleObject targetType, void* b
/* allow conversion from a base-10 or base-16 string. */ \
type result; \
if (!jsvalToIntegerExplicit(val, &result) && \
(!JSVAL_IS_STRING(val) || \
(!val.isString() || \
!StringToInteger(cx, JSVAL_TO_STRING(val), &result))) \
return TypeError(cx, #name, val); \
*static_cast<type*>(buffer) = result; \
@ -5410,7 +5410,7 @@ static MOZ_ALWAYS_INLINE bool
IsEllipsis(JSContext* cx, jsval v, bool* isEllipsis)
{
*isEllipsis = false;
if (!JSVAL_IS_STRING(v))
if (!v.isString())
return true;
JSString* str = JSVAL_TO_STRING(v);
if (str->length() != 3)

View File

@ -58,7 +58,7 @@ Library::Name(JSContext* cx, unsigned argc, jsval *vp)
Value arg = args[0];
JSString* str = nullptr;
if (JSVAL_IS_STRING(arg)) {
if (arg.isString()) {
str = JSVAL_TO_STRING(arg);
}
else {
@ -96,7 +96,7 @@ Library::Create(JSContext* cx, jsval path_, JSCTypesCallbacks* callbacks)
if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions))
return nullptr;
if (!JSVAL_IS_STRING(path)) {
if (!path.isString()) {
JS_ReportError(cx, "open takes a string argument");
return nullptr;
}

View File

@ -19,7 +19,7 @@ BEGIN_TEST(testConservativeGC)
JS::RootedValue v3(cx);
EVAL("String(Math.PI);", &v3);
CHECK(JSVAL_IS_STRING(v3));
CHECK(v3.isString());
char strCopy[sizeof(JSString)];
js_memcpy(&strCopy, JSVAL_TO_STRING(v3), sizeof(JSString));
@ -31,7 +31,7 @@ BEGIN_TEST(testConservativeGC)
js_memcpy(&obj2Copy, obj2, sizeof(JSObject));
EVAL("String(Math.sqrt(3));", &tmp);
CHECK(JSVAL_IS_STRING(tmp));
CHECK(tmp.isString());
JS::RootedString str2(cx, JSVAL_TO_STRING(tmp));
char str2Copy[sizeof(JSString)];
js_memcpy(&str2Copy, str2, sizeof(JSString));

View File

@ -57,7 +57,7 @@ document_resolve(JSContext *cx, JS::HandleObject obj, JS::HandleId id,
JS::RootedValue v(cx);
if (!JS_IdToValue(cx, id, &v))
return false;
if (JSVAL_IS_STRING(v)) {
if (v.isString()) {
JSString *str = JSVAL_TO_STRING(v);
JSFlatString *flatStr = JS_FlattenString(cx, str);
if (!flatStr)

View File

@ -16,7 +16,7 @@ EmptyTrapHandler(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
{
JS::RootedValue closure(cx, closureArg);
JS_GC(JS_GetRuntime(cx));
if (JSVAL_IS_STRING(closure))
if (closure.isString())
++emptyTrapCallCount;
return JSTRAP_CONTINUE;
}

View File

@ -38,7 +38,7 @@ BEGIN_TEST(testValueABI_retparam)
CHECK(equal);
v = C_GetEmptyStringValue(cx);
CHECK(JSVAL_IS_STRING(v));
CHECK(v.isString());
return true;
}

View File

@ -800,7 +800,7 @@ QuoteString(Sprinter *sp, JSString *str, uint32_t quote);
static bool
ToDisassemblySource(JSContext *cx, HandleValue v, JSAutoByteString *bytes)
{
if (JSVAL_IS_STRING(v)) {
if (v.isString()) {
Sprinter sprinter(cx);
if (!sprinter.init())
return false;

View File

@ -5,7 +5,7 @@
//-----------------------------------------------------------------------------
var BUGNUMBER = 407024;
var summary = 'Do not assert JSVAL_IS_NUMBER(pn3->pn_val) || JSVAL_IS_STRING(pn3->pn_val) || JSVAL_IS_BOOLEAN(pn3->pn_val)';
var summary = 'Do not assert JSVAL_IS_NUMBER(pn3->pn_val) || pn3->pn_val.isString() || JSVAL_IS_BOOLEAN(pn3->pn_val)';
var actual = 'No Crash';
var expect = 'No Crash';

View File

@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var summary = 'Do not assert: JSVAL_IS_STRING(v)';
var summary = 'Do not assert: v.isString()';
var BUGNUMBER = 477053;
var actual = '';
var expect = '';

View File

@ -726,8 +726,7 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
variant.forget(static_cast<nsISupports**>(d));
return true;
} else if (iid->Equals(NS_GET_IID(nsIAtom)) &&
JSVAL_IS_STRING(s)) {
} else if (iid->Equals(NS_GET_IID(nsIAtom)) && s.isString()) {
// We're trying to pass a string as an nsIAtom. Let's atomize!
JSString* str = JSVAL_TO_STRING(s);
const char16_t* chars = JS_GetStringCharsZ(cx, str);

View File

@ -233,7 +233,7 @@ protected:
StringificationBehavior nullBehavior,
StringificationBehavior undefinedBehavior) {
JSString *s;
if (JSVAL_IS_STRING(v)) {
if (v.isString()) {
s = JSVAL_TO_STRING(v);
} else {
StringificationBehavior behavior = eStringify;

View File

@ -60,7 +60,7 @@ XPCTraceableVariant::~XPCTraceableVariant()
// If val is JSVAL_STRING, we don't need to clean anything up; simply
// removing the string from the root set is good.
if (!JSVAL_IS_STRING(val))
if (!val.isString())
nsVariant::Cleanup(&mData);
if (!val.isNull())

View File

@ -316,7 +316,7 @@ GetJSValueAsString(JSContext* aCtx,
const JS::Value& aValue,
nsString& _string) {
if (aValue.isUndefined() ||
!(aValue.isNull() || JSVAL_IS_STRING(aValue))) {
!(aValue.isNull() || aValue.isString())) {
_string.SetIsVoid(true);
return;
}