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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | |
michael@0 | 3 | /* |
michael@0 | 4 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 5 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | var out = {}; |
michael@0 | 9 | |
michael@0 | 10 | function arr() { |
michael@0 | 11 | return Object.defineProperty([1, 2, 3, 4], 2, {configurable: false}); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | function nonStrict1(out) |
michael@0 | 15 | { |
michael@0 | 16 | var a = out.array = arr(); |
michael@0 | 17 | a.length = 2; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function strict1(out) |
michael@0 | 21 | { |
michael@0 | 22 | "use strict"; |
michael@0 | 23 | var a = out.array = arr(); |
michael@0 | 24 | a.length = 2; |
michael@0 | 25 | return a; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | out.array = null; |
michael@0 | 29 | nonStrict1(out); |
michael@0 | 30 | assertEq(deepEqual(out.array, [1, 2, 3]), true); |
michael@0 | 31 | |
michael@0 | 32 | out.array = null; |
michael@0 | 33 | try |
michael@0 | 34 | { |
michael@0 | 35 | strict1(out); |
michael@0 | 36 | throw "no error"; |
michael@0 | 37 | } |
michael@0 | 38 | catch (e) |
michael@0 | 39 | { |
michael@0 | 40 | assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); |
michael@0 | 41 | } |
michael@0 | 42 | assertEq(deepEqual(out.array, [1, 2, 3]), true); |
michael@0 | 43 | |
michael@0 | 44 | // Internally, SpiderMonkey has two representations for arrays: |
michael@0 | 45 | // fast-but-inflexible, and slow-but-flexible. Adding a non-index property |
michael@0 | 46 | // to an array turns it into the latter. We should test on both kinds. |
michael@0 | 47 | function addx(obj) { |
michael@0 | 48 | obj.x = 5; |
michael@0 | 49 | return obj; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function nonStrict2(out) |
michael@0 | 53 | { |
michael@0 | 54 | var a = out.array = addx(arr()); |
michael@0 | 55 | a.length = 2; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function strict2(out) |
michael@0 | 59 | { |
michael@0 | 60 | "use strict"; |
michael@0 | 61 | var a = out.array = addx(arr()); |
michael@0 | 62 | a.length = 2; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | out.array = null; |
michael@0 | 66 | nonStrict2(out); |
michael@0 | 67 | assertEq(deepEqual(out.array, addx([1, 2, 3])), true); |
michael@0 | 68 | |
michael@0 | 69 | out.array = null; |
michael@0 | 70 | try |
michael@0 | 71 | { |
michael@0 | 72 | strict2(out); |
michael@0 | 73 | throw "no error"; |
michael@0 | 74 | } |
michael@0 | 75 | catch (e) |
michael@0 | 76 | { |
michael@0 | 77 | assertEq(e instanceof TypeError, true, "expected TypeError, got " + e); |
michael@0 | 78 | } |
michael@0 | 79 | assertEq(deepEqual(out.array, addx([1, 2, 3])), true); |
michael@0 | 80 | |
michael@0 | 81 | if (typeof reportCompare === "function") |
michael@0 | 82 | reportCompare(true, true); |
michael@0 | 83 | |
michael@0 | 84 | print("Tests complete"); |