Add || and && tests.

This commit is contained in:
Brendan Eich 2008-08-01 20:13:11 -07:00
parent b5e4c9bea4
commit 3dad101a7c
3 changed files with 58 additions and 9 deletions

View File

@ -732,11 +732,16 @@ js_ValueToNumber(JSContext *cx, jsval *vp)
/*
* Note that ECMA doesn't treat a string beginning with a '0' as
* an octal number here.
* an octal number here. This works because all such numbers will
* be interpreted as decimal by js_strtod and will never get
* passed to js_strtointeger (which would interpret them as
* octal).
*/
JSSTRING_CHARS_AND_END(str, bp, end);
if (!js_strtointeger(cx, bp, end, &ep, -1, &d) ||
js_SkipWhiteSpace(ep, end) != end) {
if ((!js_strtod(cx, bp, end, &ep, &d) ||
js_SkipWhiteSpace(ep, end) != end) &&
(!js_strtointeger(cx, bp, end, &ep, 0, &d) ||
js_SkipWhiteSpace(ep, end) != end)) {
break;
}
@ -1081,7 +1086,7 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar *send,
goto no_digits;
}
if (base <= 0) {
if (base == 0) {
/* No base supplied, or some base that evaluated to 0. */
if (*s1 == '0') {
/* It's either hex or octal; only increment char if str isn't '0' */
@ -1090,8 +1095,6 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar *send,
s1 += 2;
if (s1 == send)
goto no_digits;
} else if (base == -1) {
base = 10; /* Caller doesn't ever want octal. */
} else {
base = 8;
}

View File

@ -881,6 +881,7 @@ TraceRecorder::import(LIns* base, ptrdiff_t offset, jsval* p, uint8& t,
nativeFrameTracker.set(p, ins);
}
tracker.set(p, ins);
#ifdef DEBUG
char name[64];
JS_ASSERT(strlen(prefix) < 10);
@ -1662,7 +1663,7 @@ TraceRecorder::ifop()
lir->ins_eq0(lir->ins2(LIR_eq, get(&v), lir->insImm(1))),
BRANCH_EXIT);
} else if (JSVAL_IS_OBJECT(v)) {
guard(!JSVAL_IS_NULL(v), lir->ins_eq0(get(&v)), BRANCH_EXIT);
guard(!JSVAL_IS_NULL(v), lir->ins_eq0(lir->ins_eq0(get(&v))), BRANCH_EXIT);
} else if (isNumber(v)) {
jsdouble d = asNumber(v);
jsdpun u;

View File

@ -401,6 +401,51 @@ function stringConvert()
stringConvert.expected = "1,8.7,75,37,,,,5";
test(stringConvert);
function orTestHelper(a, b, n)
{
var k = 0;
for (var i = 0; i < n; i++) {
if (a || b)
k += i;
}
return k;
}
function andTestHelper(a, b, n)
{
var k = 0;
for (var i = 0; i < n; i++) {
if (a && b)
k += i;
}
return k;
}
(function () {
var opsies = ["||", "&&"];
var falsies = [null, undefined, false, NaN, 0, /*""*/];
var truthies = [{}, true, 1, 42, 1/0, -1/0, /*"blah"*/];
var boolies = [falsies, truthies];
for each (var op in opsies) {
for (var i in boolies) {
for (var j in boolies[i]) {
var x = uneval(boolies[i][j]);
for (var k in boolies) {
for (var l in boolies[k]) {
var y = uneval(boolies[k][l]);
var prefix = (op == "||") ? "or" : "and";
var f = new Function("return " + prefix + "TestHelper(" + x + "," + y + ",10)");
f.name = prefix + "Test(" + x + "," + y + ")";
f.expected = eval(x + op + y) ? 45 : 0;
test(f);
}
}
}
}
}
})();
/* Keep these at the end so that we can see the summary after the trace-debug spew. */
print("pass:", passes.length ? passes.join(",") : "<none>");
print("FAIL:", fails.length ? fails.join(",") : "<none>");
print("pass:\n", passes.length ? passes.join("\n") : "<none>");
print("\nFAIL:\n", fails.length ? fails.join("\n") : "<none>");