/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//----------------------------------------------------------------------------- var BUGNUMBER = 290592; var summary = 'Array extras: forEach, indexOf, filter, map'; var actual = ''; var expect = '';
// throw TypeError if no every callback function specified
expect = 'TypeError'; try
{
strings.every();
actual = 'no error';
} catch(e)
{
actual = e.name;
}
reportCompare(expect, actual, 'Array.every(undefined) throws TypeError');
// test general every
try
{
expect = true;
actual = strings.every(isString);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'strings: every element is a string');
try
{
expect = false;
actual = mixed.every(isString);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'mixed: every element is a string');
try
{ // see https://bugzilla.mozilla.org/show_bug.cgi?id=311082
expect = true;
actual = sparsestrings.every(isString);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'sparsestrings: every element is a string');
// pass object method as map callback
obj = new ArrayCallback(false);
try
{
expect = true;
actual = strings.every(obj.isString, obj);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'strings: every element is a string, via object callback');
try
{
expect = false;
actual = mixed.every(obj.isString, obj);
} catch(e)
{
actual = dumpError(e) ;
}
reportCompare(expect, actual, 'mixed: every element is a string, via object callback');
try
{ // see https://bugzilla.mozilla.org/show_bug.cgi?id=311082
expect = true;
actual = sparsestrings.every(obj.isString, obj);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'sparsestrings: every element is a string, via object callback');
// throw TypeError if no some callback function specified
expect = 'TypeError'; try
{
strings.some();
actual = 'no error';
} catch(e)
{
actual = e.name;
}
reportCompare(expect, actual, 'Array.some(undefined) throws TypeError');
// test general some
try
{
expect = true;
actual = strings.some(isString);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'strings: some element is a string');
try
{
expect = true;
actual = mixed.some(isString);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'mixed: some element is a string');
try
{
expect = true;
actual = sparsestrings.some(isString);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'sparsestrings: some element is a string');
// pass object method as map callback
obj = new ArrayCallback(false);
try
{
expect = true;
actual = strings.some(obj.isString, obj);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'strings: some element is a string, via object callback');
try
{
expect = true;
actual = mixed.some(obj.isString, obj);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'mixed: some element is a string, via object callback');
try
{
expect = true;
actual = sparsestrings.some(obj.isString, obj);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'sparsestrings: some element is a string, via object callback');
try
{
expect = -1;
actual = mixed.indexOf('not found');
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'indexOf returns -1 if value not found');
try
{
expect = 0;
actual = mixed.indexOf(0);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'indexOf matches using strict equality');
try
{
expect = 1;
actual = mixed.indexOf('0');
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'indexOf matches using strict equality');
try
{
expect = 2;
actual = mixed.indexOf(0, 1);
} catch(e)
{
actual = dumpError(e);
}
reportCompare(expect, actual, 'indexOf begins searching at fromIndex');
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.