Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | var BUGNUMBER = 465199; |
michael@0 | 7 | var summary = "RegExp lastIndex property set should not coerce type to number"; |
michael@0 | 8 | |
michael@0 | 9 | print(BUGNUMBER + ": " + summary); |
michael@0 | 10 | |
michael@0 | 11 | /************** |
michael@0 | 12 | * BEGIN TEST * |
michael@0 | 13 | **************/ |
michael@0 | 14 | |
michael@0 | 15 | var called = false; |
michael@0 | 16 | var o = { valueOf: function() { called = true; return 1; } }; |
michael@0 | 17 | var r = /a/g; |
michael@0 | 18 | var desc, m; |
michael@0 | 19 | |
michael@0 | 20 | assertEq(r.lastIndex, 0); |
michael@0 | 21 | |
michael@0 | 22 | desc = Object.getOwnPropertyDescriptor(r, "lastIndex"); |
michael@0 | 23 | assertEq(desc.enumerable, false); |
michael@0 | 24 | assertEq(desc.configurable, false); |
michael@0 | 25 | assertEq(desc.value, 0); |
michael@0 | 26 | assertEq(desc.writable, true); |
michael@0 | 27 | |
michael@0 | 28 | r.lastIndex = o; |
michael@0 | 29 | |
michael@0 | 30 | assertEq(r.lastIndex, o); |
michael@0 | 31 | |
michael@0 | 32 | desc = Object.getOwnPropertyDescriptor(r, "lastIndex"); |
michael@0 | 33 | assertEq(desc.enumerable, false); |
michael@0 | 34 | assertEq(desc.configurable, false); |
michael@0 | 35 | assertEq(desc.value, o); |
michael@0 | 36 | assertEq(desc.writable, true); |
michael@0 | 37 | |
michael@0 | 38 | assertEq(called, false); |
michael@0 | 39 | assertEq(r.exec("aaaa").length, 1); |
michael@0 | 40 | assertEq(called, true); |
michael@0 | 41 | assertEq(r.lastIndex, 2); |
michael@0 | 42 | |
michael@0 | 43 | desc = Object.getOwnPropertyDescriptor(r, "lastIndex"); |
michael@0 | 44 | assertEq(desc.enumerable, false); |
michael@0 | 45 | assertEq(desc.configurable, false); |
michael@0 | 46 | assertEq(desc.value, 2); |
michael@0 | 47 | assertEq(desc.writable, true); |
michael@0 | 48 | |
michael@0 | 49 | |
michael@0 | 50 | r.lastIndex = -0.2; |
michael@0 | 51 | assertEq(r.lastIndex, -0.2); |
michael@0 | 52 | |
michael@0 | 53 | m = r.exec("aaaa"); |
michael@0 | 54 | assertEq(Array.isArray(m), true); |
michael@0 | 55 | assertEq(m.length, 1); |
michael@0 | 56 | assertEq(m[0], "a"); |
michael@0 | 57 | assertEq(r.lastIndex, 1); |
michael@0 | 58 | |
michael@0 | 59 | m = r.exec("aaaa"); |
michael@0 | 60 | assertEq(Array.isArray(m), true); |
michael@0 | 61 | assertEq(m.length, 1); |
michael@0 | 62 | assertEq(m[0], "a"); |
michael@0 | 63 | assertEq(r.lastIndex, 2); |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | /******************************************************************************/ |
michael@0 | 67 | |
michael@0 | 68 | if (typeof reportCompare === "function") |
michael@0 | 69 | reportCompare(true, true); |
michael@0 | 70 | |
michael@0 | 71 | print("All tests passed!"); |