OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 if (self.importScripts) { | 3 if (self.importScripts) { |
4 self.importScripts('/resources/testharness.js'); | 4 self.importScripts('/resources/testharness.js'); |
5 } | 5 } |
6 | 6 |
7 test(() => { | 7 test(() => { |
8 const ws = new WritableStream({}); | 8 const ws = new WritableStream({}); |
9 const writer = ws.getWriter(); | 9 const writer = ws.getWriter(); |
10 writer.releaseLock(); | 10 writer.releaseLock(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return promises.start | 145 return promises.start |
146 .then(thisValue => assert_equals(thisValue, theSink, 'start should be call
ed as a method')) | 146 .then(thisValue => assert_equals(thisValue, theSink, 'start should be call
ed as a method')) |
147 .then(() => promises.write) | 147 .then(() => promises.write) |
148 .then(thisValue => assert_equals(thisValue, theSink, 'write should be call
ed as a method')) | 148 .then(thisValue => assert_equals(thisValue, theSink, 'write should be call
ed as a method')) |
149 .then(() => promises.close) | 149 .then(() => promises.close) |
150 .then(thisValue => assert_equals(thisValue, theSink, 'close should be call
ed as a method')) | 150 .then(thisValue => assert_equals(thisValue, theSink, 'close should be call
ed as a method')) |
151 .then(() => promises.abort) | 151 .then(() => promises.abort) |
152 .then(thisValue => assert_equals(thisValue, theSink, 'abort should be call
ed as a method')); | 152 .then(thisValue => assert_equals(thisValue, theSink, 'abort should be call
ed as a method')); |
153 }, 'WritableStream should call underlying sink methods as methods'); | 153 }, 'WritableStream should call underlying sink methods as methods'); |
154 | 154 |
| 155 promise_test(t => { |
| 156 function functionWithOverloads() {} |
| 157 functionWithOverloads.apply = () => assert_unreached('apply() should not be ca
lled'); |
| 158 functionWithOverloads.call = () => assert_unreached('call() should not be call
ed'); |
| 159 const underlyingSink = { |
| 160 start: functionWithOverloads, |
| 161 write: functionWithOverloads, |
| 162 close: functionWithOverloads, |
| 163 abort: functionWithOverloads |
| 164 }; |
| 165 // Test start(), write(), close(). |
| 166 const ws1 = new WritableStream(underlyingSink); |
| 167 const writer1 = ws1.getWriter(); |
| 168 writer1.write('a'); |
| 169 writer1.close(); |
| 170 |
| 171 // Test abort(). |
| 172 const ws2 = new WritableStream(underlyingSink); |
| 173 const writer2 = ws2.getWriter(); |
| 174 writer2.abort(); |
| 175 |
| 176 // Test PromiseInvokeOrFallbackOrNoop. |
| 177 const ws3 = new WritableStream({ |
| 178 start: functionWithOverloads, |
| 179 write: functionWithOverloads, |
| 180 close: functionWithOverloads |
| 181 }); |
| 182 const writer3 = ws3.getWriter(); |
| 183 writer3.abort(); |
| 184 |
| 185 return writer1.closed |
| 186 .then(() => promise_rejects(t, new TypeError(), writer2.closed, 'writer2.c
losed should be rejected')) |
| 187 .then(() => promise_rejects(t, new TypeError(), writer3.closed, 'writer3.c
losed should be rejected')); |
| 188 }, 'methods should not not have .apply() or .call() called'); |
| 189 |
| 190 promise_test(() => { |
| 191 const strategy = { |
| 192 size() { |
| 193 if (this !== undefined) { |
| 194 throw new Error('size called as a method'); |
| 195 } |
| 196 return 1; |
| 197 } |
| 198 }; |
| 199 |
| 200 const ws = new WritableStream({}, strategy); |
| 201 const writer = ws.getWriter(); |
| 202 return writer.write('a'); |
| 203 }, 'WritableStream\'s strategy.size should not be called as a method'); |
| 204 |
155 promise_test(() => { | 205 promise_test(() => { |
156 const ws = new WritableStream(); | 206 const ws = new WritableStream(); |
157 const writer1 = ws.getWriter(); | 207 const writer1 = ws.getWriter(); |
158 assert_equals(undefined, writer1.releaseLock(), 'releaseLock() should return u
ndefined'); | 208 assert_equals(undefined, writer1.releaseLock(), 'releaseLock() should return u
ndefined'); |
159 const writer2 = ws.getWriter(); | 209 const writer2 = ws.getWriter(); |
160 assert_equals(undefined, writer1.releaseLock(), 'no-op releaseLock() should re
turn undefined'); | 210 assert_equals(undefined, writer1.releaseLock(), 'no-op releaseLock() should re
turn undefined'); |
161 // Calling releaseLock() on writer1 should not interfere with writer2. If it d
id, then the ready promise would be | 211 // Calling releaseLock() on writer1 should not interfere with writer2. If it d
id, then the ready promise would be |
162 // rejected. | 212 // rejected. |
163 return writer2.ready; | 213 return writer2.ready; |
164 }, 'redundant releaseLock() is no-op'); | 214 }, 'redundant releaseLock() is no-op'); |
165 | 215 |
166 done(); | 216 done(); |
OLD | NEW |