blob: 32bd6c162270f3b3f26fafca42098509968169e9 [file] [log] [blame]
utatane.tea@gmail.com5fc5a2a2017-11-21 10:40:34 +00001function shouldBe(actual, expected) {
2 if (actual !== expected)
3 throw new Error('bad value: ' + actual);
4}
5
6function shouldThrow(func, errorMessage) {
7 var errorThrown = false;
8 var error = null;
9 try {
10 func();
11 } catch (e) {
12 errorThrown = true;
13 error = e;
14 }
15 if (!errorThrown)
16 throw new Error('not thrown');
17 if (String(error) !== errorMessage)
18 throw new Error(`bad error: ${String(error)}`);
19}
20
21var func = Set.prototype.add;
22function target(set)
23{
24 return func.call(set, 42);
25}
26noInline(target);
27
28for (var i = 0; i < 1e6; ++i) {
29 var set = new Set();
30 shouldBe(target(set), set);
31 shouldBe(set.has(42), true);
32}
33shouldThrow(() => {
34 target(new Map());
35}, `TypeError: Set operation called on non-Set object`);