blob: 6d195c202a8ddec9961953fad17b71acaee94a50 [file] [log] [blame]
benjamin@webkit.orge324d432015-04-26 19:55:18 +00001description("Test the basic behaviors of Math.clz32()");
2
3shouldBeTrue('Math.hasOwnProperty("clz32")');
4shouldBeEqualToString('typeof Math.clz32', 'function');
5shouldBe('Object.getPrototypeOf(Math).clz32', 'undefined');
6
7// Function properties.
8shouldBe('Math.clz32.length', '1');
commit-queue@webkit.orgd8eebe52016-06-04 18:58:08 +00009shouldBeEqualToString('Math.clz32.name', 'clz32');
benjamin@webkit.orge324d432015-04-26 19:55:18 +000010shouldBe('Object.getOwnPropertyDescriptor(Math, "clz32").configurable', 'true');
11shouldBe('Object.getOwnPropertyDescriptor(Math, "clz32").enumerable', 'false');
12shouldBe('Object.getOwnPropertyDescriptor(Math, "clz32").writable', 'true');
13
14// Some simple cases.
15shouldBe('Math.clz32(0)', '32');
16shouldBe('Math.clz32(-0)', '32');
17shouldBe('Math.clz32(1)', '31');
18shouldBe('Math.clz32(-1)', '0');
19shouldBe('Math.clz32(42)', '26');
20shouldBe('Math.clz32(-2147483648)', '0');
21shouldBe('Math.clz32(2147483647)', '1');
22
23shouldBe('Math.clz32(Number.MAX_VALUE)', '32');
24shouldBe('Math.clz32(Number.MIN_VALUE)', '32');
25shouldBe('Math.clz32(Number.MAX_SAFE_INTEGER)', '0');
26shouldBe('Math.clz32(Number.MIN_SAFE_INTEGER)', '31');
27
28shouldBe('Math.clz32(Math.PI)', '30');
29shouldBe('Math.clz32(Math.E)', '30');
30shouldBe('Math.clz32(NaN)', '32');
benjamin@webkit.org5a33d802016-06-03 02:54:05 +000031shouldBe('Math.clz32(Number.POSITIVE_INFINITY)', '32');
32shouldBe('Math.clz32(Number.NEGATIVE_INFINITY)', '32');
benjamin@webkit.orge324d432015-04-26 19:55:18 +000033
34shouldBe('Math.clz32()', '32');
35shouldBe('Math.clz32(undefined)', '32');
36shouldBe('Math.clz32(null)', '32');
37shouldBe('Math.clz32("WebKit")', '32');
38shouldThrow('Math.clz32(Symbol("WebKit"))');
39shouldBe('Math.clz32({ webkit: "awesome" })', '32');
40
41// Type conversion.
42var objectConvertToString = { toString: function() { return "66"; } };
43shouldBe('Math.clz32(objectConvertToString)', '25');
44
45var objectRecordToStringCall = { toStringCallCount: 0, toString: function() { this.toStringCallCount += 1; return "9"; } };
46shouldBe('Math.clz32(objectRecordToStringCall)', '28');
47shouldBe('objectRecordToStringCall.toStringCallCount', '1');
48
49var objectThrowOnToString = { toString: function() { throw "No!"; } };
50shouldThrow('Math.clz32(objectThrowOnToString)');
51
52var objectWithValueOf = { valueOf: function() { return 95014; } };
53shouldBe('Math.clz32(objectWithValueOf)', '15');
54
55var objectThrowOnValueOf = { valueOf: function() { throw "Nope!" }, toString: function() { return 5; } };
56shouldThrow('Math.clz32(objectThrowOnValueOf)');
57
58
59var objectRecordValueOfCall = { valueOfCallCount: 0, valueOf: function() { ++this.valueOfCallCount; return 436; } }
60shouldBe('Math.clz32(objectRecordValueOfCall)', '23');
61shouldBe('objectRecordValueOfCall.valueOfCallCount', '1');
62
63var objectRecordConversionCalls = {
64 callList: [],
65 toString: function() {
66 this.callList.push("toString");
67 return "Uh?";
68 },
69 valueOf: function() {
70 this.callList.push("valueOf");
71 return 87665;
72 }
73};
74shouldBe('Math.clz32(objectRecordConversionCalls)', '15');
benjamin@webkit.org5a33d802016-06-03 02:54:05 +000075shouldBe('objectRecordConversionCalls.callList.toString()', '"valueOf"');