|
| 1 | +/// <reference path="../../../../../types/index.d.ts" /> |
| 2 | +/* eslint-env serviceworker */ |
| 3 | + |
| 4 | +import { routes } from "../../../test-harness.js"; |
| 5 | +import { pass, assert, assertThrows } from "../../../assertions.js"; |
| 6 | + |
| 7 | +let error; |
| 8 | +routes.set("/Performance/interface", () => { |
| 9 | + let actual = Reflect.ownKeys(Performance) |
| 10 | + let expected = ["prototype","length","name"] |
| 11 | + error = assert(actual, expected, `Reflect.ownKeys(Performance)`) |
| 12 | + if (error) { return error } |
| 13 | + |
| 14 | + // Check the prototype descriptors are correct |
| 15 | + { |
| 16 | + actual = Reflect.getOwnPropertyDescriptor(Performance, 'prototype') |
| 17 | + expected = { |
| 18 | + "value": Performance.prototype, |
| 19 | + "writable": false, |
| 20 | + "enumerable": false, |
| 21 | + "configurable": false |
| 22 | + } |
| 23 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance, 'prototype')`) |
| 24 | + if (error) { return error } |
| 25 | + } |
| 26 | + |
| 27 | + // Check the constructor function's defined parameter length is correct |
| 28 | + { |
| 29 | + actual = Reflect.getOwnPropertyDescriptor(Performance, 'length') |
| 30 | + expected = { |
| 31 | + "value": 0, |
| 32 | + "writable": false, |
| 33 | + "enumerable": false, |
| 34 | + "configurable": true |
| 35 | + } |
| 36 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance, 'length')`) |
| 37 | + if (error) { return error } |
| 38 | + } |
| 39 | + |
| 40 | + // Check the constructor function's name is correct |
| 41 | + { |
| 42 | + actual = Reflect.getOwnPropertyDescriptor(Performance, 'name') |
| 43 | + expected = { |
| 44 | + "value": "Performance", |
| 45 | + "writable": false, |
| 46 | + "enumerable": false, |
| 47 | + "configurable": true |
| 48 | + } |
| 49 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance, 'name')`) |
| 50 | + if (error) { return error } |
| 51 | + } |
| 52 | + |
| 53 | + // Check the prototype has the correct keys |
| 54 | + { |
| 55 | + actual = Reflect.ownKeys(Performance.prototype) |
| 56 | + expected = ["constructor","timeOrigin","now", Symbol.toStringTag] |
| 57 | + error = assert(actual, expected, `Reflect.ownKeys(Performance.prototype)`) |
| 58 | + if (error) { return error } |
| 59 | + } |
| 60 | + |
| 61 | + // Check the constructor on the prototype is correct |
| 62 | + { |
| 63 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype, 'constructor') |
| 64 | + expected = { "writable": true, "enumerable": false, "configurable": true, value: Performance.prototype.constructor } |
| 65 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance.prototype, 'constructor')`) |
| 66 | + if (error) { return error } |
| 67 | + |
| 68 | + error = assert(typeof Performance.prototype.constructor, 'function', `typeof Performance.prototype.constructor`) |
| 69 | + if (error) { return error } |
| 70 | + |
| 71 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype.constructor, 'length') |
| 72 | + expected = { |
| 73 | + "value": 0, |
| 74 | + "writable": false, |
| 75 | + "enumerable": false, |
| 76 | + "configurable": true |
| 77 | + } |
| 78 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance.prototype.constructor, 'length')`) |
| 79 | + if (error) { return error } |
| 80 | + |
| 81 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype.constructor, 'name') |
| 82 | + expected = { |
| 83 | + "value": "Performance", |
| 84 | + "writable": false, |
| 85 | + "enumerable": false, |
| 86 | + "configurable": true |
| 87 | + } |
| 88 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance.prototype.constructor, 'name')`) |
| 89 | + if (error) { return error } |
| 90 | + } |
| 91 | + |
| 92 | + // Check the Symbol.toStringTag on the prototype is correct |
| 93 | + { |
| 94 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype, Symbol.toStringTag) |
| 95 | + expected = {"value":"performance","writable":false,"enumerable":false,"configurable":true} |
| 96 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance.prototype, [Symbol.toStringTag])`) |
| 97 | + if (error) { return error } |
| 98 | + |
| 99 | + error = assert(typeof Performance.prototype[Symbol.toStringTag], 'string', `typeof Performance.prototype[Symbol.toStringTag]`) |
| 100 | + if (error) { return error } |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + // Check the timeOrigin property is correct |
| 105 | + { |
| 106 | + const descriptors = Reflect.getOwnPropertyDescriptor(Performance.prototype, 'timeOrigin') |
| 107 | + expected = { "enumerable": true, "configurable": true } |
| 108 | + error = assert(descriptors.enumerable, true, `Reflect.getOwnPropertyDescriptor(Performance, 'timeOrigin').enumerable`) |
| 109 | + error = assert(descriptors.configurable, true, `Reflect.getOwnPropertyDescriptor(Performance, 'timeOrigin').configurable`) |
| 110 | + error = assert(descriptors.value, undefined, `Reflect.getOwnPropertyDescriptor(Performance, 'timeOrigin').value`) |
| 111 | + error = assert(descriptors.set, undefined, `Reflect.getOwnPropertyDescriptor(Performance, 'timeOrigin').set`) |
| 112 | + error = assert(typeof descriptors.get, 'function', `typeof Reflect.getOwnPropertyDescriptor(Performance, 'timeOrigin').get`) |
| 113 | + if (error) { return error } |
| 114 | + |
| 115 | + error = assert(typeof Performance.prototype.timeOrigin, 'number', `typeof Performance.prototype.timeOrigin`) |
| 116 | + if (error) { return error } |
| 117 | + } |
| 118 | + |
| 119 | + // Check the now property is correct |
| 120 | + { |
| 121 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype, 'now') |
| 122 | + expected = { "writable": true, "enumerable": true, "configurable": true, value: Performance.prototype.now } |
| 123 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance, 'now')`) |
| 124 | + if (error) { return error } |
| 125 | + |
| 126 | + error = assert(typeof Performance.prototype.now, 'function', `typeof Performance.prototype.now`) |
| 127 | + if (error) { return error } |
| 128 | + |
| 129 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype.now, 'length') |
| 130 | + expected = { |
| 131 | + "value": 0, |
| 132 | + "writable": false, |
| 133 | + "enumerable": false, |
| 134 | + "configurable": true |
| 135 | + } |
| 136 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance.prototype.now, 'length')`) |
| 137 | + if (error) { return error } |
| 138 | + |
| 139 | + actual = Reflect.getOwnPropertyDescriptor(Performance.prototype.now, 'name') |
| 140 | + expected = { |
| 141 | + "value": "now", |
| 142 | + "writable": false, |
| 143 | + "enumerable": false, |
| 144 | + "configurable": true |
| 145 | + } |
| 146 | + error = assert(actual, expected, `Reflect.getOwnPropertyDescriptor(Performance.prototype.now, 'name')`) |
| 147 | + if (error) { return error } |
| 148 | + } |
| 149 | + |
| 150 | + return pass('ok') |
| 151 | +}); |
| 152 | + |
| 153 | +routes.set("/globalThis.performance", () => { |
| 154 | + error = assert(globalThis.performance instanceof Performance, true, `globalThis.performance instanceof Performance`) |
| 155 | + if (error) { return error } |
| 156 | + |
| 157 | + return pass('ok') |
| 158 | +}); |
| 159 | + |
| 160 | +routes.set("/globalThis.performance/now", () => { |
| 161 | + error = assertThrows(() => new performance.now()) |
| 162 | + if (error) { return error } |
| 163 | + |
| 164 | + error = assert(typeof performance.now(), 'number') |
| 165 | + if (error) { return error } |
| 166 | + |
| 167 | + error = assert(performance.now() > 0, true) |
| 168 | + if (error) { return error } |
| 169 | + |
| 170 | + error = assert(Number.isNaN(performance.now()), false) |
| 171 | + if (error) { return error } |
| 172 | + |
| 173 | + error = assert(Number.isFinite(performance.now()), true) |
| 174 | + if (error) { return error } |
| 175 | + |
| 176 | + error = assert(performance.now() < Date.now(), true) |
| 177 | + if (error) { return error } |
| 178 | + |
| 179 | + return pass('ok') |
| 180 | +}); |
| 181 | + |
| 182 | +routes.set("/globalThis.performance/timeOrigin", () => { |
| 183 | + error = assert(typeof performance.timeOrigin, 'number') |
| 184 | + if (error) { return error } |
| 185 | + |
| 186 | + error = assert(performance.timeOrigin > 0, true) |
| 187 | + if (error) { return error } |
| 188 | + |
| 189 | + error = assert(Number.isNaN(performance.timeOrigin), false) |
| 190 | + if (error) { return error } |
| 191 | + |
| 192 | + error = assert(Number.isFinite(performance.timeOrigin), true) |
| 193 | + if (error) { return error } |
| 194 | + |
| 195 | + |
| 196 | + error = assert(performance.timeOrigin < Date.now(), true) |
| 197 | + if (error) { return error } |
| 198 | + |
| 199 | + return pass('ok') |
| 200 | +}); |
0 commit comments