Bug 604864 - Optimize undefined, NaN and Infinity in methodjit. r=dmandelin

This commit is contained in:
Jan de Mooij 2010-11-01 21:47:45 +01:00
parent 5cce2a3041
commit c402f81ebb
7 changed files with 58 additions and 4 deletions

View File

@ -0,0 +1,9 @@
function testLocalNames() {
var NaN = 4;
var undefined = 5;
var Infinity = 6;
return NaN + undefined + Infinity;
}
assertEq(testLocalNames(), 15);

View File

@ -0,0 +1,20 @@
function testNaN(x) {
var x = NaN;
assertEq(isNaN(x), true);
}
testNaN();
function testInfinity(x) {
return (x === Infinity);
}
assertEq(testInfinity(Infinity), true);
assertEq(testInfinity(6), false);
assertEq(testInfinity(-Infinity), false);
function testUndefined(x) {
return (x === undefined);
}
assertEq(testUndefined(undefined), true);
assertEq(testUndefined(), true);
assertEq(testUndefined(5), false);

View File

@ -0,0 +1,9 @@
NaN = 4;
undefined = 5;
Infinity = 6;
assertEq(isNaN(NaN), true);
assertEq(Infinity > 100, true);
assertEq(undefined != 5, true);

View File

@ -1525,8 +1525,8 @@ static JSStdName standard_class_names[] = {
{js_InitObjectClass, EAGER_ATOM(eval), CLASP(Object)},
/* Global properties and functions defined by the Number class. */
{js_InitNumberClass, LAZY_ATOM(NaN), CLASP(Number)},
{js_InitNumberClass, LAZY_ATOM(Infinity), CLASP(Number)},
{js_InitNumberClass, EAGER_ATOM(NaN), CLASP(Number)},
{js_InitNumberClass, EAGER_ATOM(Infinity), CLASP(Number)},
{js_InitNumberClass, LAZY_ATOM(isNaN), CLASP(Number)},
{js_InitNumberClass, LAZY_ATOM(isFinite), CLASP(Number)},
{js_InitNumberClass, LAZY_ATOM(parseFloat), CLASP(Number)},

View File

@ -181,6 +181,8 @@ const char *const js_common_atom_names[] = {
"use strict", /* useStrictAtom */
"loc", /* locAtom */
"line", /* lineAtom */
"Infinity", /* InfinityAtom */
"NaN", /* NaNAtom */
#if JS_HAS_XML_SUPPORT
js_etago_str, /* etagoAtom */

View File

@ -373,6 +373,8 @@ struct JSAtomState
JSAtom *useStrictAtom;
JSAtom *locAtom;
JSAtom *lineAtom;
JSAtom *InfinityAtom;
JSAtom *NaNAtom;
#if JS_HAS_XML_SUPPORT
JSAtom *etagoAtom;
@ -407,8 +409,6 @@ struct JSAtomState
/* Less frequently used atoms, pinned lazily by JS_ResolveStandardClass. */
struct {
JSAtom *InfinityAtom;
JSAtom *NaNAtom;
JSAtom *XMLListAtom;
JSAtom *decodeURIAtom;
JSAtom *decodeURIComponentAtom;

View File

@ -4336,6 +4336,20 @@ mjit::Compiler::jsop_bindgname()
void
mjit::Compiler::jsop_getgname(uint32 index)
{
/* Optimize undefined, NaN and Infinity. */
JSAtom *atom = script->getAtom(index);
if (atom == cx->runtime->atomState.typeAtoms[JSTYPE_VOID]) {
frame.push(UndefinedValue());
return;
}
if (atom == cx->runtime->atomState.NaNAtom) {
frame.push(cx->runtime->NaNValue);
return;
}
if (atom == cx->runtime->atomState.InfinityAtom) {
frame.push(cx->runtime->positiveInfinityValue);
return;
}
#if defined JS_MONOIC
jsop_bindgname();