зеркало из https://github.com/mozilla/pjs.git
Bug 707061 - Rename js_ValueToString to ToString. Also, consistent with ToObject, make ToString include an inline already-string fast path, and make ToStringSlow be an out-of-line slow path for the case where the value is not a string (asserting that this is the case). r=luke
This commit is contained in:
Родитель
c1aa143b02
Коммит
863c0fe811
|
@ -256,7 +256,7 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder,
|
|||
sourceStr = cx->runtime->emptyString;
|
||||
} else {
|
||||
/* Coerce to string and compile. */
|
||||
JSString *str = js_ValueToString(cx, sourceValue);
|
||||
JSString *str = ToString(cx, sourceValue);
|
||||
if (!str)
|
||||
return false;
|
||||
sourceStr = str->ensureLinear(cx);
|
||||
|
@ -266,7 +266,7 @@ CompileRegExpObject(JSContext *cx, RegExpObjectBuilder &builder,
|
|||
|
||||
RegExpFlag flags = RegExpFlag(0);
|
||||
if (argc > 1 && !argv[1].isUndefined()) {
|
||||
JSString *flagStr = js_ValueToString(cx, argv[1]);
|
||||
JSString *flagStr = ToString(cx, argv[1]);
|
||||
if (!flagStr)
|
||||
return false;
|
||||
argv[1].setString(flagStr);
|
||||
|
@ -528,7 +528,7 @@ ExecuteRegExp(JSContext *cx, Native native, uintN argc, Value *vp)
|
|||
RegExpStatics *res = cx->regExpStatics();
|
||||
|
||||
/* Step 2. */
|
||||
JSString *input = js_ValueToString(cx, (args.length() > 0) ? args[0] : UndefinedValue());
|
||||
JSString *input = ToString(cx, (args.length() > 0) ? args[0] : UndefinedValue());
|
||||
if (!input)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -316,7 +316,7 @@ JS_ConvertArgumentsVA(JSContext *cx, uintN argc, jsval *argv, const char *format
|
|||
break;
|
||||
case 'S':
|
||||
case 'W':
|
||||
str = js_ValueToString(cx, *sp);
|
||||
str = ToString(cx, *sp);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*sp = STRING_TO_JSVAL(str);
|
||||
|
@ -433,7 +433,7 @@ JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp)
|
|||
ok = (obj != NULL);
|
||||
break;
|
||||
case JSTYPE_STRING:
|
||||
str = js_ValueToString(cx, v);
|
||||
str = ToString(cx, v);
|
||||
ok = (str != NULL);
|
||||
if (ok)
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
|
@ -486,7 +486,7 @@ JS_ValueToString(JSContext *cx, jsval v)
|
|||
{
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, v);
|
||||
return js_ValueToString(cx, v);
|
||||
return ToString(cx, v);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSString *)
|
||||
|
|
|
@ -1870,7 +1870,7 @@ array_join(JSContext *cx, uintN argc, Value *vp)
|
|||
if (args.length() == 0 || args[0].isUndefined()) {
|
||||
str = NULL;
|
||||
} else {
|
||||
str = js_ValueToString(cx, args[0]);
|
||||
str = ToString(cx, args[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
args[0].setString(str);
|
||||
|
@ -2177,7 +2177,7 @@ js::array_sort(JSContext *cx, uintN argc, Value *vp)
|
|||
if (!JS_CHECK_OPERATION_LIMIT(cx))
|
||||
return false;
|
||||
const Value &v = vec[i];
|
||||
JSString *str = js_ValueToString(cx, v);
|
||||
JSString *str = ToString(cx, v);
|
||||
if (!str)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ inline bool
|
|||
js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp)
|
||||
{
|
||||
if (!v.isString()) {
|
||||
JSString *str = js_ValueToString(cx, v);
|
||||
JSString *str = js::ToStringSlow(cx, v);
|
||||
if (!str)
|
||||
return false;
|
||||
JS::Anchor<JSString *> anchor(str);
|
||||
|
@ -184,7 +184,7 @@ IdToString(JSContext *cx, jsid id)
|
|||
return JSID_TO_STRING(id);
|
||||
if (JS_LIKELY(JSID_IS_INT(id)))
|
||||
return js_IntToString(cx, JSID_TO_INT(id));
|
||||
return js_ValueToString(cx, IdToValue(id));
|
||||
return js::ToStringSlow(cx, IdToValue(id));
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
|
|
|
@ -1190,7 +1190,7 @@ date_parse(JSContext *cx, uintN argc, Value *vp)
|
|||
vp->setDouble(js_NaN);
|
||||
return true;
|
||||
}
|
||||
str = js_ValueToString(cx, vp[2]);
|
||||
str = ToString(cx, vp[2]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
vp[2].setString(str);
|
||||
|
@ -2417,7 +2417,7 @@ date_toLocaleFormat(JSContext *cx, uintN argc, Value *vp)
|
|||
if (!obj)
|
||||
return ok;
|
||||
|
||||
JSString *fmt = js_ValueToString(cx, args[0]);
|
||||
JSString *fmt = ToString(cx, args[0]);
|
||||
if (!fmt)
|
||||
return false;
|
||||
|
||||
|
@ -2511,7 +2511,7 @@ date_valueOf(JSContext *cx, uintN argc, Value *vp)
|
|||
}
|
||||
|
||||
/* Convert to number only if the hint was given, otherwise favor string. */
|
||||
JSString *str = js_ValueToString(cx, args[0]);
|
||||
JSString *str = ToString(cx, args[0]);
|
||||
if (!str)
|
||||
return false;
|
||||
JSLinearString *linear_str = str->ensureLinear(cx);
|
||||
|
@ -2606,7 +2606,7 @@ js_Date(JSContext *cx, uintN argc, Value *vp)
|
|||
d = TIMECLIP(d);
|
||||
} else {
|
||||
/* the argument is a string; parse it. */
|
||||
JSString *str = js_ValueToString(cx, args[0]);
|
||||
JSString *str = ToString(cx, args[0]);
|
||||
if (!str)
|
||||
return false;
|
||||
args[0].setString(str);
|
||||
|
|
|
@ -729,7 +729,7 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
|||
/* Set the 'message' property. */
|
||||
JSString *message;
|
||||
if (args.length() != 0 && !args[0].isUndefined()) {
|
||||
message = js_ValueToString(cx, args[0]);
|
||||
message = ToString(cx, args[0]);
|
||||
if (!message)
|
||||
return false;
|
||||
args[0].setString(message);
|
||||
|
@ -745,7 +745,7 @@ Exception(JSContext *cx, uintN argc, Value *vp)
|
|||
/* Set the 'fileName' property. */
|
||||
JSString *filename;
|
||||
if (args.length() > 1) {
|
||||
filename = js_ValueToString(cx, args[1]);
|
||||
filename = ToString(cx, args[1]);
|
||||
if (!filename)
|
||||
return false;
|
||||
args[1].setString(filename);
|
||||
|
@ -801,7 +801,7 @@ exn_toString(JSContext *cx, uintN argc, Value *vp)
|
|||
if (nameVal.isUndefined()) {
|
||||
name = CLASS_ATOM(cx, Error);
|
||||
} else {
|
||||
name = js_ValueToString(cx, nameVal);
|
||||
name = ToString(cx, nameVal);
|
||||
if (!name)
|
||||
return false;
|
||||
}
|
||||
|
@ -816,7 +816,7 @@ exn_toString(JSContext *cx, uintN argc, Value *vp)
|
|||
if (msgVal.isUndefined()) {
|
||||
message = cx->runtime->emptyString;
|
||||
} else {
|
||||
message = js_ValueToString(cx, msgVal);
|
||||
message = ToString(cx, msgVal);
|
||||
if (!message)
|
||||
return false;
|
||||
}
|
||||
|
@ -867,7 +867,8 @@ exn_toSource(JSContext *cx, uintN argc, Value *vp)
|
|||
Value nameVal;
|
||||
JSString *name;
|
||||
if (!obj->getProperty(cx, cx->runtime->atomState.nameAtom, &nameVal) ||
|
||||
!(name = js_ValueToString(cx, nameVal))) {
|
||||
!(name = ToString(cx, nameVal)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -911,7 +912,7 @@ exn_toSource(JSContext *cx, uintN argc, Value *vp)
|
|||
if (filename->empty() && !sb.append(", \"\""))
|
||||
return false;
|
||||
|
||||
JSString *linenumber = js_ValueToString(cx, linenoVal);
|
||||
JSString *linenumber = ToString(cx, linenoVal);
|
||||
if (!linenumber)
|
||||
return false;
|
||||
if (!sb.append(", ") || !sb.append(linenumber))
|
||||
|
@ -1178,10 +1179,10 @@ js_ReportUncaughtException(JSContext *cx)
|
|||
AutoArrayRooter tvr(cx, ArrayLength(roots), roots);
|
||||
|
||||
/*
|
||||
* Because js_ValueToString below could error and an exception object
|
||||
* could become unrooted, we must root exnObject. Later, if exnObject is
|
||||
* non-null, we need to root other intermediates, so allocate an operand
|
||||
* stack segment to protect all of these values.
|
||||
* Because ToString below could error and an exception object could become
|
||||
* unrooted, we must root exnObject. Later, if exnObject is non-null, we
|
||||
* need to root other intermediates, so allocate an operand stack segment
|
||||
* to protect all of these values.
|
||||
*/
|
||||
if (JSVAL_IS_PRIMITIVE(exn)) {
|
||||
exnObject = NULL;
|
||||
|
@ -1194,12 +1195,12 @@ js_ReportUncaughtException(JSContext *cx)
|
|||
reportp = js_ErrorFromException(cx, exn);
|
||||
|
||||
/* XXX L10N angels cry once again. see also everywhere else */
|
||||
str = js_ValueToString(cx, exn);
|
||||
str = ToString(cx, exn);
|
||||
JSAutoByteString bytesStorage;
|
||||
if (!str) {
|
||||
bytes = "unknown (can't convert to string)";
|
||||
} else {
|
||||
roots[1] = STRING_TO_JSVAL(str);
|
||||
roots[1] = StringValue(str);
|
||||
if (!bytesStorage.encode(cx, str))
|
||||
return false;
|
||||
bytes = bytesStorage.ptr();
|
||||
|
@ -1218,7 +1219,7 @@ js_ReportUncaughtException(JSContext *cx)
|
|||
|
||||
if (!JS_GetProperty(cx, exnObject, js_fileName_str, &roots[3]))
|
||||
return false;
|
||||
str = js_ValueToString(cx, roots[3]);
|
||||
str = ToString(cx, roots[3]);
|
||||
if (!str || !filename.encode(cx, str))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -1976,7 +1976,7 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
|||
size_t args_length = 0;
|
||||
for (uintN i = 0; i < n; i++) {
|
||||
/* Collect the lengths for all the function-argument arguments. */
|
||||
JSString *arg = js_ValueToString(cx, args[i]);
|
||||
JSString *arg = ToString(cx, args[i]);
|
||||
if (!arg)
|
||||
return false;
|
||||
args[i].setString(arg);
|
||||
|
@ -2084,7 +2084,7 @@ Function(JSContext *cx, uintN argc, Value *vp)
|
|||
size_t length;
|
||||
|
||||
if (args.length()) {
|
||||
JSString *str = js_ValueToString(cx, args[args.length() - 1]);
|
||||
JSString *str = ToString(cx, args[args.length() - 1]);
|
||||
if (!str)
|
||||
return false;
|
||||
strAnchor.set(str);
|
||||
|
|
|
@ -2685,7 +2685,7 @@ BEGIN_CASE(JSOP_ADD)
|
|||
if (lIsString) {
|
||||
lstr = lval.toString();
|
||||
} else {
|
||||
lstr = js_ValueToString(cx, lval);
|
||||
lstr = ToString(cx, lval);
|
||||
if (!lstr)
|
||||
goto error;
|
||||
regs.sp[-2].setString(lstr);
|
||||
|
@ -2693,7 +2693,7 @@ BEGIN_CASE(JSOP_ADD)
|
|||
if (rIsString) {
|
||||
rstr = rval.toString();
|
||||
} else {
|
||||
rstr = js_ValueToString(cx, rval);
|
||||
rstr = ToString(cx, rval);
|
||||
if (!rstr)
|
||||
goto error;
|
||||
regs.sp[-1].setString(rstr);
|
||||
|
@ -5124,7 +5124,7 @@ BEGIN_CASE(JSOP_XMLTAGEXPR)
|
|||
JS_ASSERT(!script->strictModeCode);
|
||||
|
||||
Value rval = regs.sp[-1];
|
||||
JSString *str = js_ValueToString(cx, rval);
|
||||
JSString *str = ToString(cx, rval);
|
||||
if (!str)
|
||||
goto error;
|
||||
regs.sp[-1].setString(str);
|
||||
|
@ -5140,7 +5140,7 @@ BEGIN_CASE(JSOP_XMLELTEXPR)
|
|||
if (IsXML(rval)) {
|
||||
str = js_ValueToXMLString(cx, rval);
|
||||
} else {
|
||||
str = js_ValueToString(cx, rval);
|
||||
str = ToString(cx, rval);
|
||||
if (str)
|
||||
str = js_EscapeElementValue(cx, str);
|
||||
}
|
||||
|
|
|
@ -1053,7 +1053,7 @@ js_IteratorNext(JSContext *cx, JSObject *iterobj, Value *rval)
|
|||
if (rval->isInt32() && StaticStrings::hasInt(i = rval->toInt32())) {
|
||||
str = cx->runtime->staticStrings.getInt(i);
|
||||
} else {
|
||||
str = js_ValueToString(cx, *rval);
|
||||
str = ToString(cx, *rval);
|
||||
if (!str)
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ num_parseFloat(JSContext *cx, uintN argc, Value *vp)
|
|||
vp->setDouble(js_NaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
str = js_ValueToString(cx, vp[2]);
|
||||
str = ToString(cx, vp[2]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
bp = str->getChars(cx);
|
||||
|
@ -438,7 +438,7 @@ num_parseInt(JSContext *cx, uintN argc, Value *vp)
|
|||
}
|
||||
|
||||
/* Step 1. */
|
||||
JSString *inputString = js_ValueToString(cx, args[0]);
|
||||
JSString *inputString = ToString(cx, args[0]);
|
||||
if (!inputString)
|
||||
return false;
|
||||
args[0].setString(inputString);
|
||||
|
|
|
@ -598,7 +598,7 @@ obj_toSource(JSContext *cx, uintN argc, Value *vp)
|
|||
* Convert id to a value and then to a string. Decide early whether we
|
||||
* prefer get/set or old getter/setter syntax.
|
||||
*/
|
||||
JSString *s = js_ValueToString(cx, IdToValue(id));
|
||||
JSString *s = ToString(cx, IdToValue(id));
|
||||
if (!s || !(idstr = s->ensureLinear(cx))) {
|
||||
ok = JS_FALSE;
|
||||
goto error;
|
||||
|
@ -2638,7 +2638,7 @@ obj_getOwnPropertyNames(JSContext *cx, uintN argc, Value *vp)
|
|||
for (size_t i = 0, len = keys.length(); i < len; i++) {
|
||||
jsid id = keys[i];
|
||||
if (JSID_IS_INT(id)) {
|
||||
JSString *str = js_ValueToString(cx, Int32Value(JSID_TO_INT(id)));
|
||||
JSString *str = js_IntToString(cx, JSID_TO_INT(id));
|
||||
if (!str)
|
||||
return false;
|
||||
vals[i].setString(str);
|
||||
|
|
|
@ -92,7 +92,7 @@ js_json_parse(JSContext *cx, uintN argc, Value *vp)
|
|||
/* Step 1. */
|
||||
JSLinearString *linear;
|
||||
if (argc >= 1) {
|
||||
JSString *str = js_ValueToString(cx, vp[2]);
|
||||
JSString *str = ToString(cx, vp[2]);
|
||||
if (!str)
|
||||
return false;
|
||||
linear = str->ensureLinear(cx);
|
||||
|
@ -367,7 +367,7 @@ PreprocessValue(JSContext *cx, JSObject *holder, KeyType key, Value *vp, Stringi
|
|||
return false;
|
||||
vp->setNumber(d);
|
||||
} else if (ObjectClassIs(obj, ESClass_String, cx)) {
|
||||
JSString *str = js_ValueToString(cx, *vp);
|
||||
JSString *str = ToStringSlow(cx, *vp);
|
||||
if (!str)
|
||||
return false;
|
||||
vp->setString(str);
|
||||
|
@ -716,7 +716,7 @@ js_Stringify(JSContext *cx, Value *vp, JSObject *replacer, Value space, StringBu
|
|||
return false;
|
||||
space = NumberValue(d);
|
||||
} else if (ObjectClassIs(spaceObj, ESClass_String, cx)) {
|
||||
JSString *str = js_ValueToString(cx, space);
|
||||
JSString *str = ToStringSlow(cx, space);
|
||||
if (!str)
|
||||
return false;
|
||||
space = StringValue(str);
|
||||
|
|
|
@ -1472,7 +1472,7 @@ DecompileSwitch(SprintStack *ss, TableEntry *table, uintN tableLength,
|
|||
return JS_FALSE;
|
||||
str = NULL;
|
||||
} else {
|
||||
str = js_ValueToString(cx, key);
|
||||
str = ToString(cx, key);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ Shape::dump(JSContext *cx, FILE *fp) const
|
|||
str = JSID_TO_ATOM(propid);
|
||||
} else {
|
||||
JS_ASSERT(JSID_IS_OBJECT(propid));
|
||||
JSString *s = js_ValueToString(cx, IdToValue(propid));
|
||||
JSString *s = ToStringSlow(cx, IdToValue(propid));
|
||||
fputs("object ", fp);
|
||||
str = s ? s->ensureLinear(cx) : NULL;
|
||||
}
|
||||
|
|
|
@ -404,7 +404,7 @@ Trap(JSContext *cx, JSObject *handler, Value fval, uintN argc, Value* argv, Valu
|
|||
static bool
|
||||
Trap1(JSContext *cx, JSObject *handler, Value fval, jsid id, Value *rval)
|
||||
{
|
||||
JSString *str = js_ValueToString(cx, IdToValue(id));
|
||||
JSString *str = ToString(cx, IdToValue(id));
|
||||
if (!str)
|
||||
return false;
|
||||
rval->setString(str);
|
||||
|
@ -414,7 +414,7 @@ Trap1(JSContext *cx, JSObject *handler, Value fval, jsid id, Value *rval)
|
|||
static bool
|
||||
Trap2(JSContext *cx, JSObject *handler, Value fval, jsid id, Value v, Value *rval)
|
||||
{
|
||||
JSString *str = js_ValueToString(cx, IdToValue(id));
|
||||
JSString *str = ToString(cx, IdToValue(id));
|
||||
if (!str)
|
||||
return false;
|
||||
rval->setString(str);
|
||||
|
@ -650,7 +650,7 @@ bool
|
|||
ScriptedProxyHandler::get(JSContext *cx, JSObject *proxy, JSObject *receiver, jsid id, Value *vp)
|
||||
{
|
||||
JSObject *handler = GetProxyHandlerObject(cx, proxy);
|
||||
JSString *str = js_ValueToString(cx, IdToValue(id));
|
||||
JSString *str = ToString(cx, IdToValue(id));
|
||||
if (!str)
|
||||
return false;
|
||||
AutoValueRooter tvr(cx, StringValue(str));
|
||||
|
@ -668,7 +668,7 @@ ScriptedProxyHandler::set(JSContext *cx, JSObject *proxy, JSObject *receiver, js
|
|||
Value *vp)
|
||||
{
|
||||
JSObject *handler = GetProxyHandlerObject(cx, proxy);
|
||||
JSString *str = js_ValueToString(cx, IdToValue(id));
|
||||
JSString *str = ToString(cx, IdToValue(id));
|
||||
if (!str)
|
||||
return false;
|
||||
AutoValueRooter tvr(cx, StringValue(str));
|
||||
|
|
|
@ -3143,7 +3143,7 @@ reflect_parse(JSContext *cx, uint32 argc, jsval *vp)
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JSString *src = js_ValueToString(cx, JS_ARGV(cx, vp)[0]);
|
||||
JSString *src = ToString(cx, JS_ARGV(cx, vp)[0]);
|
||||
if (!src)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -3183,7 +3183,7 @@ reflect_parse(JSContext *cx, uint32 argc, jsval *vp)
|
|||
}
|
||||
|
||||
if (!prop.isNullOrUndefined()) {
|
||||
JSString *str = js_ValueToString(cx, prop);
|
||||
JSString *str = ToString(cx, prop);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
|
||||
|
|
|
@ -430,7 +430,7 @@ ThisToStringForStringProto(JSContext *cx, Value *vp)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
JSString *str = js_ValueToString(cx, vp[1]);
|
||||
JSString *str = ToStringSlow(cx, vp[1]);
|
||||
if (!str)
|
||||
return NULL;
|
||||
vp[1].setString(str);
|
||||
|
@ -679,7 +679,7 @@ str_localeCompare(JSContext *cx, uintN argc, Value *vp)
|
|||
if (argc == 0) {
|
||||
vp->setInt32(0);
|
||||
} else {
|
||||
JSString *thatStr = js_ValueToString(cx, vp[2]);
|
||||
JSString *thatStr = ToString(cx, vp[2]);
|
||||
if (!thatStr)
|
||||
return false;
|
||||
if (cx->localeCallbacks && cx->localeCallbacks->localeCompare) {
|
||||
|
@ -1401,7 +1401,7 @@ class RegExpGuard
|
|||
/* Build RegExp from pattern string. */
|
||||
JSString *opt;
|
||||
if (optarg < argc) {
|
||||
opt = js_ValueToString(cx, vp[2 + optarg]);
|
||||
opt = ToString(cx, vp[2 + optarg]);
|
||||
if (!opt)
|
||||
return NULL;
|
||||
} else {
|
||||
|
@ -1789,7 +1789,7 @@ FindReplaceLength(JSContext *cx, RegExpStatics *res, ReplaceData &rdata, size_t
|
|||
return false;
|
||||
|
||||
/* root repstr: rdata is on the stack, so scanned by conservative gc. */
|
||||
JSString *repstr = ValueToString_TestForStringInline(cx, args.rval());
|
||||
JSString *repstr = ToString(cx, args.rval());
|
||||
if (!repstr)
|
||||
return false;
|
||||
rdata.repstr = repstr->ensureLinear(cx);
|
||||
|
@ -2095,7 +2095,7 @@ str_replace_flat_lambda(JSContext *cx, uintN argc, Value *vp, ReplaceData &rdata
|
|||
if (!Invoke(cx, rdata.args))
|
||||
return false;
|
||||
|
||||
JSString *repstr = js_ValueToString(cx, args.rval());
|
||||
JSString *repstr = ToString(cx, args.rval());
|
||||
if (!repstr)
|
||||
return false;
|
||||
|
||||
|
@ -2472,7 +2472,7 @@ js::str_split(JSContext *cx, uintN argc, Value *vp)
|
|||
if (!matcher.reset(reobj))
|
||||
return false;
|
||||
} else {
|
||||
JSString *sep = js_ValueToString(cx, vp[2]);
|
||||
JSString *sep = ToString(cx, vp[2]);
|
||||
if (!sep)
|
||||
return false;
|
||||
vp[2].setString(sep);
|
||||
|
@ -2587,7 +2587,7 @@ str_concat(JSContext *cx, uintN argc, Value *vp)
|
|||
|
||||
Value *argv = JS_ARGV(cx, vp);
|
||||
for (uintN i = 0; i < argc; i++) {
|
||||
JSString *str2 = js_ValueToString(cx, argv[i]);
|
||||
JSString *str2 = ToString(cx, argv[i]);
|
||||
if (!str2)
|
||||
return false;
|
||||
|
||||
|
@ -2890,7 +2890,7 @@ js_String(JSContext *cx, uintN argc, Value *vp)
|
|||
|
||||
JSString *str;
|
||||
if (argc > 0) {
|
||||
str = js_ValueToString(cx, argv[0]);
|
||||
str = ToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return false;
|
||||
} else {
|
||||
|
@ -3218,7 +3218,7 @@ js_ValueToPrintable(JSContext *cx, const Value &v, JSAutoByteString *bytes, bool
|
|||
{
|
||||
JSString *str;
|
||||
|
||||
str = (asSource ? js_ValueToSource : js_ValueToString)(cx, v);
|
||||
str = (asSource ? js_ValueToSource : ToString)(cx, v);
|
||||
if (!str)
|
||||
return NULL;
|
||||
str = js_QuoteString(cx, str, 0);
|
||||
|
@ -3228,8 +3228,11 @@ js_ValueToPrintable(JSContext *cx, const Value &v, JSAutoByteString *bytes, bool
|
|||
}
|
||||
|
||||
JSString *
|
||||
js_ValueToString(JSContext *cx, const Value &arg)
|
||||
js::ToStringSlow(JSContext *cx, const Value &arg)
|
||||
{
|
||||
/* As with ToObjectSlow, callers must verify that |arg| isn't a string. */
|
||||
JS_ASSERT(!arg.isString());
|
||||
|
||||
Value v = arg;
|
||||
if (!ToPrimitive(cx, JSTYPE_STRING, &v))
|
||||
return NULL;
|
||||
|
@ -3288,7 +3291,7 @@ js_ValueToSource(JSContext *cx, const Value &v)
|
|||
|
||||
return js_NewStringCopyN(cx, js_negzero_ucNstr, 2);
|
||||
}
|
||||
return js_ValueToString(cx, v);
|
||||
return ToString(cx, v);
|
||||
}
|
||||
|
||||
Value rval = NullValue();
|
||||
|
@ -3301,7 +3304,7 @@ js_ValueToSource(JSContext *cx, const Value &v)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return js_ValueToString(cx, rval);
|
||||
return ToString(cx, rval);
|
||||
}
|
||||
|
||||
namespace js {
|
||||
|
|
|
@ -139,26 +139,26 @@ extern const char *
|
|||
js_ValueToPrintable(JSContext *cx, const js::Value &,
|
||||
JSAutoByteString *bytes, bool asSource = false);
|
||||
|
||||
/*
|
||||
* Convert a value to a string, returning null after reporting an error,
|
||||
* otherwise returning a new string reference.
|
||||
*/
|
||||
extern JSString *
|
||||
js_ValueToString(JSContext *cx, const js::Value &v);
|
||||
|
||||
namespace js {
|
||||
|
||||
/*
|
||||
* Most code that calls js_ValueToString knows the value is (probably) not a
|
||||
* string, so it does not make sense to put this inline fast path into
|
||||
* js_ValueToString.
|
||||
* Convert a non-string value to a string, returning null after reporting an
|
||||
* error, otherwise returning a new string reference.
|
||||
*/
|
||||
extern JSString *
|
||||
ToStringSlow(JSContext *cx, const Value &v);
|
||||
|
||||
/*
|
||||
* Convert the given value to a string. This method includes an inline
|
||||
* fast-path for the case where the value is already a string; if the value is
|
||||
* known not to be a string, use ToStringSlow instead.
|
||||
*/
|
||||
static JS_ALWAYS_INLINE JSString *
|
||||
ValueToString_TestForStringInline(JSContext *cx, const Value &v)
|
||||
ToString(JSContext *cx, const js::Value &v)
|
||||
{
|
||||
if (v.isString())
|
||||
return v.toString();
|
||||
return js_ValueToString(cx, v);
|
||||
return ToStringSlow(cx, v);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -585,7 +585,7 @@ js_IsXMLName(JSContext *cx, jsval v)
|
|||
name = JSVAL_TO_OBJECT(v)->getQNameLocalName();
|
||||
} else {
|
||||
older = JS_SetErrorReporter(cx, NULL);
|
||||
JSString *str = js_ValueToString(cx, v);
|
||||
JSString *str = ToString(cx, v);
|
||||
if (str)
|
||||
name = str->ensureLinear(cx);
|
||||
JS_SetErrorReporter(cx, older);
|
||||
|
@ -659,7 +659,7 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
|
|||
obj->setNameURI(uri);
|
||||
obj->setNamePrefix(uriobj->getNamePrefix());
|
||||
} else {
|
||||
JSString *str = js_ValueToString(cx, urival);
|
||||
JSString *str = ToString(cx, urival);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
uri = str->ensureLinear(cx);
|
||||
|
@ -671,7 +671,7 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
|
|||
}
|
||||
} else if (argc == 2) {
|
||||
if (!isQName || !(uri = uriobj->getNameURI())) {
|
||||
JSString *str = js_ValueToString(cx, urival);
|
||||
JSString *str = ToString(cx, urival);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
uri = str->ensureLinear(cx);
|
||||
|
@ -683,7 +683,7 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
|
|||
prefixval = argv[0];
|
||||
if (uri->empty()) {
|
||||
if (!JSVAL_IS_VOID(prefixval)) {
|
||||
JSString *str = js_ValueToString(cx, prefixval);
|
||||
JSString *str = ToString(cx, prefixval);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
if (!str->empty()) {
|
||||
|
@ -698,7 +698,7 @@ NamespaceHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv,
|
|||
} else if (JSVAL_IS_VOID(prefixval) || !js_IsXMLName(cx, prefixval)) {
|
||||
obj->clearNamePrefix();
|
||||
} else {
|
||||
JSString *str = js_ValueToString(cx, prefixval);
|
||||
JSString *str = ToString(cx, prefixval);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
prefix = str->ensureLinear(cx);
|
||||
|
@ -821,7 +821,7 @@ QNameHelper(JSContext *cx, JSObject *obj, intN argc, jsval *argv, jsval *rval)
|
|||
prefix = obj2->getNamePrefix();
|
||||
} else {
|
||||
JS_ASSERT(argc > 1);
|
||||
JSString *str = js_ValueToString(cx, nsval);
|
||||
JSString *str = ToString(cx, nsval);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
uri = str->ensureLinear(cx);
|
||||
|
@ -1907,7 +1907,7 @@ ToXML(JSContext *cx, jsval v)
|
|||
}
|
||||
}
|
||||
|
||||
str = js_ValueToString(cx, v);
|
||||
str = ToString(cx, v);
|
||||
if (!str)
|
||||
return NULL;
|
||||
if (str->empty()) {
|
||||
|
@ -1988,7 +1988,7 @@ ToXMLList(JSContext *cx, jsval v)
|
|||
}
|
||||
}
|
||||
|
||||
str = js_ValueToString(cx, v);
|
||||
str = ToString(cx, v);
|
||||
if (!str)
|
||||
return NULL;
|
||||
if (str->empty()) {
|
||||
|
@ -2799,7 +2799,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
|
|||
}
|
||||
|
||||
if (JSVAL_IS_BOOLEAN(v) || JSVAL_IS_NUMBER(v))
|
||||
return js_ValueToString(cx, v);
|
||||
return ToString(cx, v);
|
||||
|
||||
if (JSVAL_IS_STRING(v)) {
|
||||
StringBuffer sb(cx);
|
||||
|
@ -2810,7 +2810,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
|
|||
if (!obj->isXML()) {
|
||||
if (!ToPrimitive(cx, JSTYPE_STRING, &v))
|
||||
return NULL;
|
||||
JSString *str = js_ValueToString(cx, v);
|
||||
JSString *str = ToString(cx, v);
|
||||
if (!str)
|
||||
return NULL;
|
||||
StringBuffer sb(cx);
|
||||
|
@ -2934,7 +2934,7 @@ ToXMLName(JSContext *cx, jsval v, jsid *funidp)
|
|||
name = cx->runtime->atomState.starAtom;
|
||||
goto construct;
|
||||
}
|
||||
name = js_ValueToString(cx, v);
|
||||
name = ToStringSlow(cx, v);
|
||||
if (!name)
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3535,7 +3535,7 @@ Insert(JSContext *cx, JSXML *xml, uint32 i, jsval v)
|
|||
}
|
||||
}
|
||||
if (!vxml) {
|
||||
str = js_ValueToString(cx, v);
|
||||
str = ToString(cx, v);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -3614,7 +3614,7 @@ Replace(JSContext *cx, JSXML *xml, uint32 i, jsval v)
|
|||
break;
|
||||
|
||||
default:
|
||||
str = js_ValueToString(cx, v);
|
||||
str = ToString(cx, v);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
|
||||
|
@ -3881,7 +3881,7 @@ KidToString(JSContext *cx, JSXML *xml, uint32 index)
|
|||
kidobj = js_GetXMLObject(cx, kid);
|
||||
if (!kidobj)
|
||||
return NULL;
|
||||
return js_ValueToString(cx, ObjectValue(*kidobj));
|
||||
return ToString(cx, ObjectValue(*kidobj));
|
||||
}
|
||||
|
||||
/* Forward declared -- its implementation uses other statics that call it. */
|
||||
|
@ -5288,8 +5288,8 @@ js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp)
|
|||
HasSimpleContent(xml))) {
|
||||
ok = js_EnterLocalRootScope(cx);
|
||||
if (ok) {
|
||||
ok = (str = js_ValueToString(cx, ObjectValue(*obj))) &&
|
||||
(vstr = js_ValueToString(cx, v));
|
||||
ok = (str = ToStringSlow(cx, ObjectValue(*obj))) &&
|
||||
(vstr = ToString(cx, v));
|
||||
if (ok)
|
||||
ok = EqualStrings(cx, str, vstr, bp);
|
||||
js_LeaveLocalRootScope(cx);
|
||||
|
@ -5302,12 +5302,12 @@ js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp)
|
|||
ok = js_EnterLocalRootScope(cx);
|
||||
if (ok) {
|
||||
if (HasSimpleContent(xml)) {
|
||||
ok = (str = js_ValueToString(cx, ObjectValue(*obj))) &&
|
||||
(vstr = js_ValueToString(cx, v));
|
||||
ok = (str = ToString(cx, ObjectValue(*obj))) &&
|
||||
(vstr = ToString(cx, v));
|
||||
if (ok)
|
||||
ok = EqualStrings(cx, str, vstr, bp);
|
||||
} else if (JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v)) {
|
||||
str = js_ValueToString(cx, ObjectValue(*obj));
|
||||
str = ToString(cx, ObjectValue(*obj));
|
||||
if (!str) {
|
||||
ok = JS_FALSE;
|
||||
} else if (JSVAL_IS_STRING(v)) {
|
||||
|
@ -6214,7 +6214,7 @@ xml_namespace(JSContext *cx, uintN argc, jsval *vp)
|
|||
if (argc == 0) {
|
||||
prefix = NULL;
|
||||
} else {
|
||||
JSString *str = js_ValueToString(cx, vp[2]);
|
||||
JSString *str = ToString(cx, vp[2]);
|
||||
if (!str)
|
||||
return false;
|
||||
prefix = str->ensureLinear(cx);
|
||||
|
|
|
@ -983,7 +983,7 @@ stubs::Add(VMFrame &f)
|
|||
if (lIsString) {
|
||||
lstr = lval.toString();
|
||||
} else {
|
||||
lstr = js_ValueToString(cx, lval);
|
||||
lstr = ToString(cx, lval);
|
||||
if (!lstr)
|
||||
THROW();
|
||||
regs.sp[-2].setString(lstr);
|
||||
|
@ -991,7 +991,7 @@ stubs::Add(VMFrame &f)
|
|||
if (rIsString) {
|
||||
rstr = rval.toString();
|
||||
} else {
|
||||
rstr = js_ValueToString(cx, rval);
|
||||
rstr = ToString(cx, rval);
|
||||
if (!rstr)
|
||||
THROW();
|
||||
regs.sp[-1].setString(rstr);
|
||||
|
|
|
@ -245,9 +245,9 @@ ReportException(JSContext *cx)
|
|||
}
|
||||
}
|
||||
|
||||
class ToString {
|
||||
class ToStringHelper {
|
||||
public:
|
||||
ToString(JSContext *aCx, jsval v, JSBool aThrow = JS_FALSE)
|
||||
ToStringHelper(JSContext *aCx, jsval v, JSBool aThrow = JS_FALSE)
|
||||
: cx(aCx), mThrow(aThrow)
|
||||
{
|
||||
mStr = JS_ValueToString(cx, v);
|
||||
|
@ -255,7 +255,7 @@ class ToString {
|
|||
ReportException(cx);
|
||||
JS_AddNamedStringRoot(cx, &mStr, "Value ToString helper");
|
||||
}
|
||||
~ToString() {
|
||||
~ToStringHelper() {
|
||||
JS_RemoveStringRoot(cx, &mStr);
|
||||
}
|
||||
JSBool threw() { return !mStr; }
|
||||
|
@ -272,10 +272,10 @@ class ToString {
|
|||
JSAutoByteString mBytes;
|
||||
};
|
||||
|
||||
class IdStringifier : public ToString {
|
||||
class IdStringifier : public ToStringHelper {
|
||||
public:
|
||||
IdStringifier(JSContext *cx, jsid id, JSBool aThrow = JS_FALSE)
|
||||
: ToString(cx, IdToJsval(id), aThrow)
|
||||
: ToStringHelper(cx, IdToJsval(id), aThrow)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
@ -2643,8 +2643,8 @@ ConvertArgs(JSContext *cx, uintN argc, jsval *vp)
|
|||
fprintf(gOutFile,
|
||||
"b %u, c %x (%c), i %ld, u %lu, j %ld\n",
|
||||
b, c, (char)c, i, u, j);
|
||||
ToString obj2string(cx, obj2);
|
||||
ToString valueString(cx, v);
|
||||
ToStringHelper obj2string(cx, obj2);
|
||||
ToStringHelper valueString(cx, v);
|
||||
JSAutoByteString strBytes;
|
||||
if (str)
|
||||
strBytes.encode(cx, str);
|
||||
|
@ -4357,7 +4357,7 @@ its_addProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
|||
|
||||
IdStringifier idString(cx, id);
|
||||
fprintf(gOutFile, "adding its property %s,", idString.getBytes());
|
||||
ToString valueString(cx, *vp);
|
||||
ToStringHelper valueString(cx, *vp);
|
||||
fprintf(gOutFile, " initial value %s\n", valueString.getBytes());
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -4370,7 +4370,7 @@ its_delProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
|||
|
||||
IdStringifier idString(cx, id);
|
||||
fprintf(gOutFile, "deleting its property %s,", idString.getBytes());
|
||||
ToString valueString(cx, *vp);
|
||||
ToStringHelper valueString(cx, *vp);
|
||||
fprintf(gOutFile, " initial value %s\n", valueString.getBytes());
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -4383,7 +4383,7 @@ its_getProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
|||
|
||||
IdStringifier idString(cx, id);
|
||||
fprintf(gOutFile, "getting its property %s,", idString.getBytes());
|
||||
ToString valueString(cx, *vp);
|
||||
ToStringHelper valueString(cx, *vp);
|
||||
fprintf(gOutFile, " initial value %s\n", valueString.getBytes());
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -4394,7 +4394,7 @@ its_setProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
|
|||
IdStringifier idString(cx, id);
|
||||
if (its_noisy) {
|
||||
fprintf(gOutFile, "setting its property %s,", idString.getBytes());
|
||||
ToString valueString(cx, *vp);
|
||||
ToStringHelper valueString(cx, *vp);
|
||||
fprintf(gOutFile, " new value %s\n", valueString.getBytes());
|
||||
}
|
||||
|
||||
|
@ -4809,7 +4809,7 @@ env_setProperty(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
|
|||
IdStringifier idstr(cx, id, JS_TRUE);
|
||||
if (idstr.threw())
|
||||
return JS_FALSE;
|
||||
ToString valstr(cx, *vp, JS_TRUE);
|
||||
ToStringHelper valstr(cx, *vp, JS_TRUE);
|
||||
if (valstr.threw())
|
||||
return JS_FALSE;
|
||||
#if defined XP_WIN || defined HPUX || defined OSF1
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "jsapi.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsgcmark.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsobj.h"
|
||||
#include "jswrapper.h"
|
||||
#include "jsarrayinlines.h"
|
||||
|
@ -3116,7 +3117,7 @@ DebuggerObject_getOwnPropertyNames(JSContext *cx, uintN argc, Value *vp)
|
|||
for (size_t i = 0, len = keys.length(); i < len; i++) {
|
||||
jsid id = keys[i];
|
||||
if (JSID_IS_INT(id)) {
|
||||
JSString *str = js_ValueToString(cx, Int32Value(JSID_TO_INT(id)));
|
||||
JSString *str = js_IntToString(cx, JSID_TO_INT(id));
|
||||
if (!str)
|
||||
return false;
|
||||
vals[i].setString(str);
|
||||
|
|
Загрузка…
Ссылка в новой задаче