benjamin@webkit.org | e324d43 | 2015-04-26 19:55:18 +0000 | [diff] [blame] | 1 | description("Test the basic behaviors of Math.clz32()"); |
| 2 | |
| 3 | shouldBeTrue('Math.hasOwnProperty("clz32")'); |
| 4 | shouldBeEqualToString('typeof Math.clz32', 'function'); |
| 5 | shouldBe('Object.getPrototypeOf(Math).clz32', 'undefined'); |
| 6 | |
| 7 | // Function properties. |
| 8 | shouldBe('Math.clz32.length', '1'); |
commit-queue@webkit.org | d8eebe5 | 2016-06-04 18:58:08 +0000 | [diff] [blame] | 9 | shouldBeEqualToString('Math.clz32.name', 'clz32'); |
benjamin@webkit.org | e324d43 | 2015-04-26 19:55:18 +0000 | [diff] [blame] | 10 | shouldBe('Object.getOwnPropertyDescriptor(Math, "clz32").configurable', 'true'); |
| 11 | shouldBe('Object.getOwnPropertyDescriptor(Math, "clz32").enumerable', 'false'); |
| 12 | shouldBe('Object.getOwnPropertyDescriptor(Math, "clz32").writable', 'true'); |
| 13 | |
| 14 | // Some simple cases. |
| 15 | shouldBe('Math.clz32(0)', '32'); |
| 16 | shouldBe('Math.clz32(-0)', '32'); |
| 17 | shouldBe('Math.clz32(1)', '31'); |
| 18 | shouldBe('Math.clz32(-1)', '0'); |
| 19 | shouldBe('Math.clz32(42)', '26'); |
| 20 | shouldBe('Math.clz32(-2147483648)', '0'); |
| 21 | shouldBe('Math.clz32(2147483647)', '1'); |
| 22 | |
| 23 | shouldBe('Math.clz32(Number.MAX_VALUE)', '32'); |
| 24 | shouldBe('Math.clz32(Number.MIN_VALUE)', '32'); |
| 25 | shouldBe('Math.clz32(Number.MAX_SAFE_INTEGER)', '0'); |
| 26 | shouldBe('Math.clz32(Number.MIN_SAFE_INTEGER)', '31'); |
| 27 | |
| 28 | shouldBe('Math.clz32(Math.PI)', '30'); |
| 29 | shouldBe('Math.clz32(Math.E)', '30'); |
| 30 | shouldBe('Math.clz32(NaN)', '32'); |
benjamin@webkit.org | 5a33d80 | 2016-06-03 02:54:05 +0000 | [diff] [blame] | 31 | shouldBe('Math.clz32(Number.POSITIVE_INFINITY)', '32'); |
| 32 | shouldBe('Math.clz32(Number.NEGATIVE_INFINITY)', '32'); |
benjamin@webkit.org | e324d43 | 2015-04-26 19:55:18 +0000 | [diff] [blame] | 33 | |
| 34 | shouldBe('Math.clz32()', '32'); |
| 35 | shouldBe('Math.clz32(undefined)', '32'); |
| 36 | shouldBe('Math.clz32(null)', '32'); |
| 37 | shouldBe('Math.clz32("WebKit")', '32'); |
| 38 | shouldThrow('Math.clz32(Symbol("WebKit"))'); |
| 39 | shouldBe('Math.clz32({ webkit: "awesome" })', '32'); |
| 40 | |
| 41 | // Type conversion. |
| 42 | var objectConvertToString = { toString: function() { return "66"; } }; |
| 43 | shouldBe('Math.clz32(objectConvertToString)', '25'); |
| 44 | |
| 45 | var objectRecordToStringCall = { toStringCallCount: 0, toString: function() { this.toStringCallCount += 1; return "9"; } }; |
| 46 | shouldBe('Math.clz32(objectRecordToStringCall)', '28'); |
| 47 | shouldBe('objectRecordToStringCall.toStringCallCount', '1'); |
| 48 | |
| 49 | var objectThrowOnToString = { toString: function() { throw "No!"; } }; |
| 50 | shouldThrow('Math.clz32(objectThrowOnToString)'); |
| 51 | |
| 52 | var objectWithValueOf = { valueOf: function() { return 95014; } }; |
| 53 | shouldBe('Math.clz32(objectWithValueOf)', '15'); |
| 54 | |
| 55 | var objectThrowOnValueOf = { valueOf: function() { throw "Nope!" }, toString: function() { return 5; } }; |
| 56 | shouldThrow('Math.clz32(objectThrowOnValueOf)'); |
| 57 | |
| 58 | |
| 59 | var objectRecordValueOfCall = { valueOfCallCount: 0, valueOf: function() { ++this.valueOfCallCount; return 436; } } |
| 60 | shouldBe('Math.clz32(objectRecordValueOfCall)', '23'); |
| 61 | shouldBe('objectRecordValueOfCall.valueOfCallCount', '1'); |
| 62 | |
| 63 | var 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 | }; |
| 74 | shouldBe('Math.clz32(objectRecordConversionCalls)', '15'); |
benjamin@webkit.org | 5a33d80 | 2016-06-03 02:54:05 +0000 | [diff] [blame] | 75 | shouldBe('objectRecordConversionCalls.callList.toString()', '"valueOf"'); |