array-length.js revision 44f0eee88ff00398ff7f715fab053374d808c90d
1d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Copyright 2010 the V8 project authors. All rights reserved.
2d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Redistribution and use in source and binary forms, with or without
3d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// modification, are permitted provided that the following conditions are
4d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// met:
5d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//
6d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//     * Redistributions of source code must retain the above copyright
7d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//       notice, this list of conditions and the following disclaimer.
8d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//     * Redistributions in binary form must reproduce the above
9d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//       copyright notice, this list of conditions and the following
10d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//       disclaimer in the documentation and/or other materials provided
11d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//       with the distribution.
12d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//     * Neither the name of Google Inc. nor the names of its
13d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch//       contributors may be used to endorse or promote products derived
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)//       from this software without specific prior written permission.
153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)//
16d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
28d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochfunction ArrayLength(a) { return a.length; }
293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
30d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochfunction Test(a0, a2, a5) {
313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  assertEquals(0, ArrayLength(a0));
3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  assertEquals(2, ArrayLength(a2));
3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  assertEquals(5, ArrayLength(a5));
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)var a0 = [];
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)var a2 = [1,2];
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)var a5 = [1,2,3,4,5];
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)for (var i = 0; i < 100000; i++) Test(a0, a2, a5);
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)assertEquals("undefined", typeof(ArrayLength(0)));
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)for (var i = 0; i < 100000; i++) Test(a0, a2, a5);
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)assertEquals(4, ArrayLength("hest"));
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)