js/src/tests/ecma_5/String/match-defines-match-elements.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:aec7e5b95729
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
4 */
5
6 var BUGNUMBER = 677820;
7 var summary =
8 "String.prototype.match must define matches on the returned array, not set " +
9 "them";
10
11 print(BUGNUMBER + ": " + summary);
12
13 /**************
14 * BEGIN TEST *
15 **************/
16
17 var called = false;
18 function setterFunction(v) { called = true; }
19 function getterFunction(v) { return "getter"; }
20
21 Object.defineProperty(Array.prototype, 1,
22 { get: getterFunction, set: setterFunction });
23
24 assertEq(called, false);
25 var matches = "abcdef".match(/./g);
26 assertEq(called, false);
27 assertEq(matches.length, 6);
28 assertEq(matches[0], "a");
29 assertEq(matches[1], "b");
30 assertEq(matches[2], "c");
31 assertEq(matches[3], "d");
32 assertEq(matches[4], "e");
33 assertEq(matches[5], "f");
34
35 var desc = Object.getOwnPropertyDescriptor(Array.prototype, 1);
36 assertEq(desc.get, getterFunction);
37 assertEq(desc.set, setterFunction);
38 assertEq(desc.enumerable, false);
39 assertEq(desc.configurable, false);
40 assertEq([][1], "getter");
41
42 assertEq(called, false);
43
44 if (typeof reportCompare === "function")
45 reportCompare(true, true);
46
47 print("Tests complete");

mercurial