Debian Codegraph @

js/src/jsapi-tests/testForOfIterator.cpp

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 #include "js/ForOfIterator.h"
9 #include "jsapi-tests/tests.h"
10
11 BEGIN_TEST(testForOfIterator_basicNonIterable) {
12 JS::RootedValue v(cx);
13 // Hack to make it simple to produce an object that has a property
14 // named Symbol.iterator.
15 EVAL("({[Symbol.iterator]: 5})", &v);
16 JS::ForOfIterator iter(cx);
17 bool ok = iter.init(v);
18 CHECK(!ok);
19 JS_ClearPendingException(cx);
20 return true;
21 }
22 END_TEST(testForOfIterator_basicNonIterable)
23
24 BEGIN_TEST(testForOfIterator_bug515273_part1) {
25 JS::RootedValue v(cx);
26
27 // Hack to make it simple to produce an object that has a property
28 // named Symbol.iterator.
29 EVAL("({[Symbol.iterator]: 5})", &v);
30
31 JS::ForOfIterator iter(cx);
32 bool ok = iter.init(v, JS::ForOfIterator::AllowNonIterable);
33 CHECK(!ok);
34 JS_ClearPendingException(cx);
35 return true;
36 }
37 END_TEST(testForOfIterator_bug515273_part1)
38
39 BEGIN_TEST(testForOfIterator_bug515273_part2) {
40 JS::RootedObject obj(cx, JS_NewPlainObject(cx));
41 CHECK(obj);
42 JS::RootedValue v(cx, JS::ObjectValue(*obj));
43
44 JS::ForOfIterator iter(cx);
45 bool ok = iter.init(v, JS::ForOfIterator::AllowNonIterable);
46 CHECK(ok);
47 CHECK(!iter.valueIsIterable());
48 return true;
49 }
50 END_TEST(testForOfIterator_bug515273_part2)