Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "jsapi-tests/tests.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "jsobjinlines.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "vm/ArgumentsObject-inl.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace js; |
michael@0 | 15 | |
michael@0 | 16 | static const char NORMAL_ZERO[] = |
michael@0 | 17 | "function f() { return arguments; }"; |
michael@0 | 18 | static const char NORMAL_ONE[] = |
michael@0 | 19 | "function f(a) { return arguments; }"; |
michael@0 | 20 | static const char NORMAL_TWO[] = |
michael@0 | 21 | "function f(a, b) { return arguments; }"; |
michael@0 | 22 | static const char NORMAL_THREE[] = |
michael@0 | 23 | "function f(a, b, c) { return arguments; }"; |
michael@0 | 24 | |
michael@0 | 25 | static const char STRICT_ZERO[] = |
michael@0 | 26 | "function f() { 'use strict'; return arguments; }"; |
michael@0 | 27 | static const char STRICT_ONE[] = |
michael@0 | 28 | "function f() { 'use strict'; return arguments; }"; |
michael@0 | 29 | static const char STRICT_TWO[] = |
michael@0 | 30 | "function f() { 'use strict'; return arguments; }"; |
michael@0 | 31 | static const char STRICT_THREE[] = |
michael@0 | 32 | "function f() { 'use strict'; return arguments; }"; |
michael@0 | 33 | |
michael@0 | 34 | static const char * const CALL_CODES[] = |
michael@0 | 35 | { "f()", "f(0)", "f(0, 1)", "f(0, 1, 2)", "f(0, 1, 2, 3)", "f(0, 1, 2, 3, 4)" }; |
michael@0 | 36 | |
michael@0 | 37 | BEGIN_TEST(testArgumentsObject) |
michael@0 | 38 | { |
michael@0 | 39 | return ExhaustiveTest<0>(NORMAL_ZERO) && |
michael@0 | 40 | ExhaustiveTest<1>(NORMAL_ZERO) && |
michael@0 | 41 | ExhaustiveTest<2>(NORMAL_ZERO) && |
michael@0 | 42 | ExhaustiveTest<0>(NORMAL_ONE) && |
michael@0 | 43 | ExhaustiveTest<1>(NORMAL_ONE) && |
michael@0 | 44 | ExhaustiveTest<2>(NORMAL_ONE) && |
michael@0 | 45 | ExhaustiveTest<3>(NORMAL_ONE) && |
michael@0 | 46 | ExhaustiveTest<0>(NORMAL_TWO) && |
michael@0 | 47 | ExhaustiveTest<1>(NORMAL_TWO) && |
michael@0 | 48 | ExhaustiveTest<2>(NORMAL_TWO) && |
michael@0 | 49 | ExhaustiveTest<3>(NORMAL_TWO) && |
michael@0 | 50 | ExhaustiveTest<4>(NORMAL_TWO) && |
michael@0 | 51 | ExhaustiveTest<0>(NORMAL_THREE) && |
michael@0 | 52 | ExhaustiveTest<1>(NORMAL_THREE) && |
michael@0 | 53 | ExhaustiveTest<2>(NORMAL_THREE) && |
michael@0 | 54 | ExhaustiveTest<3>(NORMAL_THREE) && |
michael@0 | 55 | ExhaustiveTest<4>(NORMAL_THREE) && |
michael@0 | 56 | ExhaustiveTest<5>(NORMAL_THREE) && |
michael@0 | 57 | ExhaustiveTest<0>(STRICT_ZERO) && |
michael@0 | 58 | ExhaustiveTest<1>(STRICT_ZERO) && |
michael@0 | 59 | ExhaustiveTest<2>(STRICT_ZERO) && |
michael@0 | 60 | ExhaustiveTest<0>(STRICT_ONE) && |
michael@0 | 61 | ExhaustiveTest<1>(STRICT_ONE) && |
michael@0 | 62 | ExhaustiveTest<2>(STRICT_ONE) && |
michael@0 | 63 | ExhaustiveTest<3>(STRICT_ONE) && |
michael@0 | 64 | ExhaustiveTest<0>(STRICT_TWO) && |
michael@0 | 65 | ExhaustiveTest<1>(STRICT_TWO) && |
michael@0 | 66 | ExhaustiveTest<2>(STRICT_TWO) && |
michael@0 | 67 | ExhaustiveTest<3>(STRICT_TWO) && |
michael@0 | 68 | ExhaustiveTest<4>(STRICT_TWO) && |
michael@0 | 69 | ExhaustiveTest<0>(STRICT_THREE) && |
michael@0 | 70 | ExhaustiveTest<1>(STRICT_THREE) && |
michael@0 | 71 | ExhaustiveTest<2>(STRICT_THREE) && |
michael@0 | 72 | ExhaustiveTest<3>(STRICT_THREE) && |
michael@0 | 73 | ExhaustiveTest<4>(STRICT_THREE) && |
michael@0 | 74 | ExhaustiveTest<5>(STRICT_THREE); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | static const size_t MAX_ELEMS = 6; |
michael@0 | 78 | |
michael@0 | 79 | template<size_t ArgCount> bool |
michael@0 | 80 | ExhaustiveTest(const char funcode[]) |
michael@0 | 81 | { |
michael@0 | 82 | RootedValue v(cx); |
michael@0 | 83 | EVAL(funcode, &v); |
michael@0 | 84 | |
michael@0 | 85 | EVAL(CALL_CODES[ArgCount], &v); |
michael@0 | 86 | Rooted<ArgumentsObject*> argsobj(cx, &JSVAL_TO_OBJECT(v)->as<ArgumentsObject>()); |
michael@0 | 87 | |
michael@0 | 88 | JS::AutoValueArray<MAX_ELEMS> elems(cx); |
michael@0 | 89 | |
michael@0 | 90 | for (size_t i = 0; i <= ArgCount; i++) { |
michael@0 | 91 | for (size_t j = 0; j <= ArgCount - i; j++) { |
michael@0 | 92 | ClearElements(elems); |
michael@0 | 93 | CHECK(argsobj->maybeGetElements(i, j, elems.begin())); |
michael@0 | 94 | for (size_t k = 0; k < j; k++) |
michael@0 | 95 | CHECK_SAME(elems[k], INT_TO_JSVAL(i + k)); |
michael@0 | 96 | for (size_t k = j; k < MAX_ELEMS - 1; k++) |
michael@0 | 97 | CHECK_SAME(elems[k], JSVAL_NULL); |
michael@0 | 98 | CHECK_SAME(elems[MAX_ELEMS - 1], INT_TO_JSVAL(42)); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | return true; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | template <size_t N> |
michael@0 | 106 | static void |
michael@0 | 107 | ClearElements(JS::AutoValueArray<N> &elems) |
michael@0 | 108 | { |
michael@0 | 109 | for (size_t i = 0; i < elems.length() - 1; i++) |
michael@0 | 110 | elems[i].setNull(); |
michael@0 | 111 | elems[elems.length() - 1].setInt32(42); |
michael@0 | 112 | } |
michael@0 | 113 | END_TEST(testArgumentsObject) |