1 | /* |
2 | * Copyright (c) 2015 Canon Inc. All rights reserved. |
3 | * Copyright (c) 2015 Igalia. |
4 | * Copyright (c) 2016 Apple Inc. All rights reserved. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
17 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
19 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | * THE POSSIBILITY OF SUCH DAMAGE. |
26 | * |
27 | */ |
28 | |
29 | // DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for |
30 | // builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py |
31 | |
32 | #include "config.h" |
33 | #include "ReadableStreamInternalsBuiltins.h" |
34 | |
35 | #if ENABLE(STREAMS_API) |
36 | |
37 | #include "WebCoreJSClientData.h" |
38 | #include <JavaScriptCore/HeapInlines.h> |
39 | #include <JavaScriptCore/IdentifierInlines.h> |
40 | #include <JavaScriptCore/Intrinsic.h> |
41 | #include <JavaScriptCore/JSCJSValueInlines.h> |
42 | #include <JavaScriptCore/JSCellInlines.h> |
43 | #include <JavaScriptCore/StructureInlines.h> |
44 | #include <JavaScriptCore/VM.h> |
45 | |
46 | namespace WebCore { |
47 | |
48 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
49 | const int s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeLength = 756; |
50 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamReaderGenericInitializeCodeIntrinsic = JSC::NoIntrinsic; |
51 | const char* const s_readableStreamInternalsReadableStreamReaderGenericInitializeCode = |
52 | "(function (reader, stream)\n" \ |
53 | "{\n" \ |
54 | " \"use strict\";\n" \ |
55 | "\n" \ |
56 | " @putByIdDirectPrivate(reader, \"ownerReadableStream\", stream);\n" \ |
57 | " @putByIdDirectPrivate(stream, \"reader\", reader);\n" \ |
58 | " if (@getByIdDirectPrivate(stream, \"state\") === @streamReadable)\n" \ |
59 | " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", @newPromiseCapability(@Promise));\n" \ |
60 | " else if (@getByIdDirectPrivate(stream, \"state\") === @streamClosed)\n" \ |
61 | " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", { @promise: @Promise.@resolve() });\n" \ |
62 | " else {\n" \ |
63 | " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamErrored);\n" \ |
64 | " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", { @promise: @newHandledRejectedPromise(@getByIdDirectPrivate(stream, \"storedError\")) });\n" \ |
65 | " }\n" \ |
66 | "})\n" \ |
67 | ; |
68 | |
69 | const JSC::ConstructAbility s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
70 | const int s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeLength = 1513; |
71 | static const JSC::Intrinsic s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic; |
72 | const char* const s_readableStreamInternalsPrivateInitializeReadableStreamDefaultControllerCode = |
73 | "(function (stream, underlyingSource, size, highWaterMark)\n" \ |
74 | "{\n" \ |
75 | " \"use strict\";\n" \ |
76 | "\n" \ |
77 | " if (!@isReadableStream(stream))\n" \ |
78 | " @throwTypeError(\"ReadableStreamDefaultController needs a ReadableStream\");\n" \ |
79 | "\n" \ |
80 | " //\n" \ |
81 | " if (@getByIdDirectPrivate(stream, \"readableStreamController\") !== null)\n" \ |
82 | " @throwTypeError(\"ReadableStream already has a controller\");\n" \ |
83 | "\n" \ |
84 | " @putByIdDirectPrivate(this, \"controlledReadableStream\", stream);\n" \ |
85 | " @putByIdDirectPrivate(this, \"underlyingSource\", underlyingSource);\n" \ |
86 | " @putByIdDirectPrivate(this, \"queue\", @newQueue());\n" \ |
87 | " @putByIdDirectPrivate(this, \"started\", false);\n" \ |
88 | " @putByIdDirectPrivate(this, \"closeRequested\", false);\n" \ |
89 | " @putByIdDirectPrivate(this, \"pullAgain\", false);\n" \ |
90 | " @putByIdDirectPrivate(this, \"pulling\", false);\n" \ |
91 | " @putByIdDirectPrivate(this, \"strategy\", @validateAndNormalizeQueuingStrategy(size, highWaterMark));\n" \ |
92 | "\n" \ |
93 | " const controller = this;\n" \ |
94 | " @promiseInvokeOrNoopNoCatch(underlyingSource, \"start\", [this]).@then(() => {\n" \ |
95 | " @putByIdDirectPrivate(controller, \"started\", true);\n" \ |
96 | " @assert(!@getByIdDirectPrivate(controller, \"pulling\"));\n" \ |
97 | " @assert(!@getByIdDirectPrivate(controller, \"pullAgain\"));\n" \ |
98 | " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \ |
99 | " }, (error) => {\n" \ |
100 | " @readableStreamDefaultControllerError(controller, error);\n" \ |
101 | " });\n" \ |
102 | "\n" \ |
103 | " @putByIdDirectPrivate(this, \"cancel\", @readableStreamDefaultControllerCancel);\n" \ |
104 | "\n" \ |
105 | " @putByIdDirectPrivate(this, \"pull\", @readableStreamDefaultControllerPull);\n" \ |
106 | "\n" \ |
107 | " return this;\n" \ |
108 | "})\n" \ |
109 | ; |
110 | |
111 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
112 | const int s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeLength = 322; |
113 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerErrorCodeIntrinsic = JSC::NoIntrinsic; |
114 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerErrorCode = |
115 | "(function (controller, error)\n" \ |
116 | "{\n" \ |
117 | " \"use strict\";\n" \ |
118 | "\n" \ |
119 | " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \ |
120 | " if (@getByIdDirectPrivate(stream, \"state\") !== @streamReadable)\n" \ |
121 | " return;\n" \ |
122 | " @putByIdDirectPrivate(controller, \"queue\", @newQueue());\n" \ |
123 | " @readableStreamError(stream, error);\n" \ |
124 | "})\n" \ |
125 | ; |
126 | |
127 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamPipeToCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
128 | const int s_readableStreamInternalsReadableStreamPipeToCodeLength = 726; |
129 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamPipeToCodeIntrinsic = JSC::NoIntrinsic; |
130 | const char* const s_readableStreamInternalsReadableStreamPipeToCode = |
131 | "(function (stream, sink)\n" \ |
132 | "{\n" \ |
133 | " \"use strict\";\n" \ |
134 | " @assert(@isReadableStream(stream));\n" \ |
135 | "\n" \ |
136 | " const reader = new @ReadableStreamDefaultReader(stream);\n" \ |
137 | "\n" \ |
138 | " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise.@then(() => { }, (e) => { sink.error(e); });\n" \ |
139 | "\n" \ |
140 | " function doPipe() {\n" \ |
141 | " @readableStreamDefaultReaderRead(reader).@then(function(result) {\n" \ |
142 | " if (result.done) {\n" \ |
143 | " sink.close();\n" \ |
144 | " return;\n" \ |
145 | " }\n" \ |
146 | " try {\n" \ |
147 | " sink.enqueue(result.value);\n" \ |
148 | " } catch (e) {\n" \ |
149 | " sink.error(\"ReadableStream chunk enqueueing in the sink failed\");\n" \ |
150 | " return;\n" \ |
151 | " }\n" \ |
152 | " doPipe();\n" \ |
153 | " });\n" \ |
154 | " }\n" \ |
155 | " doPipe();\n" \ |
156 | "})\n" \ |
157 | ; |
158 | |
159 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
160 | const int s_readableStreamInternalsReadableStreamTeeCodeLength = 1346; |
161 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeeCodeIntrinsic = JSC::NoIntrinsic; |
162 | const char* const s_readableStreamInternalsReadableStreamTeeCode = |
163 | "(function (stream, shouldClone)\n" \ |
164 | "{\n" \ |
165 | " \"use strict\";\n" \ |
166 | "\n" \ |
167 | " @assert(@isReadableStream(stream));\n" \ |
168 | " @assert(typeof(shouldClone) === \"boolean\");\n" \ |
169 | "\n" \ |
170 | " const reader = new @ReadableStreamDefaultReader(stream);\n" \ |
171 | "\n" \ |
172 | " const teeState = {\n" \ |
173 | " closedOrErrored: false,\n" \ |
174 | " canceled1: false,\n" \ |
175 | " canceled2: false,\n" \ |
176 | " reason1: @undefined,\n" \ |
177 | " reason2: @undefined,\n" \ |
178 | " };\n" \ |
179 | "\n" \ |
180 | " teeState.cancelPromiseCapability = @newPromiseCapability(@InternalPromise);\n" \ |
181 | "\n" \ |
182 | " const pullFunction = @readableStreamTeePullFunction(teeState, reader, shouldClone);\n" \ |
183 | "\n" \ |
184 | " const branch1 = new @ReadableStream({\n" \ |
185 | " \"pull\": pullFunction,\n" \ |
186 | " \"cancel\": @readableStreamTeeBranch1CancelFunction(teeState, stream)\n" \ |
187 | " });\n" \ |
188 | " const branch2 = new @ReadableStream({\n" \ |
189 | " \"pull\": pullFunction,\n" \ |
190 | " \"cancel\": @readableStreamTeeBranch2CancelFunction(teeState, stream)\n" \ |
191 | " });\n" \ |
192 | "\n" \ |
193 | " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise.@then(@undefined, function(e) {\n" \ |
194 | " if (teeState.closedOrErrored)\n" \ |
195 | " return;\n" \ |
196 | " @readableStreamDefaultControllerError(branch1.@readableStreamController, e);\n" \ |
197 | " @readableStreamDefaultControllerError(branch2.@readableStreamController, e);\n" \ |
198 | " teeState.closedOrErrored = true;\n" \ |
199 | " });\n" \ |
200 | "\n" \ |
201 | " //\n" \ |
202 | " teeState.branch1 = branch1;\n" \ |
203 | " teeState.branch2 = branch2;\n" \ |
204 | "\n" \ |
205 | " return [branch1, branch2];\n" \ |
206 | "})\n" \ |
207 | ; |
208 | |
209 | const JSC::ConstructAbility s_readableStreamInternalsDoStructuredCloneCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
210 | const int s_readableStreamInternalsDoStructuredCloneCodeLength = 317; |
211 | static const JSC::Intrinsic s_readableStreamInternalsDoStructuredCloneCodeIntrinsic = JSC::NoIntrinsic; |
212 | const char* const s_readableStreamInternalsDoStructuredCloneCode = |
213 | "(function (object)\n" \ |
214 | "{\n" \ |
215 | " \"use strict\";\n" \ |
216 | "\n" \ |
217 | " //\n" \ |
218 | " //\n" \ |
219 | "\n" \ |
220 | " if (object instanceof @ArrayBuffer)\n" \ |
221 | " return @structuredCloneArrayBuffer(object);\n" \ |
222 | "\n" \ |
223 | " if (@ArrayBuffer.@isView(object))\n" \ |
224 | " return @structuredCloneArrayBufferView(object);\n" \ |
225 | "\n" \ |
226 | " @throwTypeError(\"structuredClone not implemented for: \" + object);\n" \ |
227 | "})\n" \ |
228 | ; |
229 | |
230 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeePullFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
231 | const int s_readableStreamInternalsReadableStreamTeePullFunctionCodeLength = 1133; |
232 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeePullFunctionCodeIntrinsic = JSC::NoIntrinsic; |
233 | const char* const s_readableStreamInternalsReadableStreamTeePullFunctionCode = |
234 | "(function (teeState, reader, shouldClone)\n" \ |
235 | "{\n" \ |
236 | " \"use strict\";\n" \ |
237 | "\n" \ |
238 | " return function() {\n" \ |
239 | " @Promise.prototype.@then.@call(@readableStreamDefaultReaderRead(reader), function(result) {\n" \ |
240 | " @assert(@isObject(result));\n" \ |
241 | " @assert(typeof result.done === \"boolean\");\n" \ |
242 | " if (result.done && !teeState.closedOrErrored) {\n" \ |
243 | " if (!teeState.canceled1)\n" \ |
244 | " @readableStreamDefaultControllerClose(teeState.branch1.@readableStreamController);\n" \ |
245 | " if (!teeState.canceled2)\n" \ |
246 | " @readableStreamDefaultControllerClose(teeState.branch2.@readableStreamController);\n" \ |
247 | " teeState.closedOrErrored = true;\n" \ |
248 | " }\n" \ |
249 | " if (teeState.closedOrErrored)\n" \ |
250 | " return;\n" \ |
251 | " if (!teeState.canceled1)\n" \ |
252 | " @readableStreamDefaultControllerEnqueue(teeState.branch1.@readableStreamController, result.value);\n" \ |
253 | " if (!teeState.canceled2)\n" \ |
254 | " @readableStreamDefaultControllerEnqueue(teeState.branch2.@readableStreamController, shouldClone ? @doStructuredClone(result.value) : result.value);\n" \ |
255 | " });\n" \ |
256 | " }\n" \ |
257 | "})\n" \ |
258 | ; |
259 | |
260 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
261 | const int s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeLength = 456; |
262 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCodeIntrinsic = JSC::NoIntrinsic; |
263 | const char* const s_readableStreamInternalsReadableStreamTeeBranch1CancelFunctionCode = |
264 | "(function (teeState, stream)\n" \ |
265 | "{\n" \ |
266 | " \"use strict\";\n" \ |
267 | "\n" \ |
268 | " return function(r) {\n" \ |
269 | " teeState.canceled1 = true;\n" \ |
270 | " teeState.reason1 = r;\n" \ |
271 | " if (teeState.canceled2) {\n" \ |
272 | " @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(\n" \ |
273 | " teeState.cancelPromiseCapability.@resolve,\n" \ |
274 | " teeState.cancelPromiseCapability.@reject);\n" \ |
275 | " }\n" \ |
276 | " return teeState.cancelPromiseCapability.@promise;\n" \ |
277 | " }\n" \ |
278 | "})\n" \ |
279 | ; |
280 | |
281 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
282 | const int s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeLength = 456; |
283 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCodeIntrinsic = JSC::NoIntrinsic; |
284 | const char* const s_readableStreamInternalsReadableStreamTeeBranch2CancelFunctionCode = |
285 | "(function (teeState, stream)\n" \ |
286 | "{\n" \ |
287 | " \"use strict\";\n" \ |
288 | "\n" \ |
289 | " return function(r) {\n" \ |
290 | " teeState.canceled2 = true;\n" \ |
291 | " teeState.reason2 = r;\n" \ |
292 | " if (teeState.canceled1) {\n" \ |
293 | " @readableStreamCancel(stream, [teeState.reason1, teeState.reason2]).@then(\n" \ |
294 | " teeState.cancelPromiseCapability.@resolve,\n" \ |
295 | " teeState.cancelPromiseCapability.@reject);\n" \ |
296 | " }\n" \ |
297 | " return teeState.cancelPromiseCapability.@promise;\n" \ |
298 | " }\n" \ |
299 | "})\n" \ |
300 | ; |
301 | |
302 | const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
303 | const int s_readableStreamInternalsIsReadableStreamCodeLength = 170; |
304 | static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamCodeIntrinsic = JSC::NoIntrinsic; |
305 | const char* const s_readableStreamInternalsIsReadableStreamCode = |
306 | "(function (stream)\n" \ |
307 | "{\n" \ |
308 | " \"use strict\";\n" \ |
309 | "\n" \ |
310 | " //\n" \ |
311 | " //\n" \ |
312 | " //\n" \ |
313 | " return @isObject(stream) && @getByIdDirectPrivate(stream, \"readableStreamController\") !== @undefined;\n" \ |
314 | "})\n" \ |
315 | ; |
316 | |
317 | const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDefaultReaderCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
318 | const int s_readableStreamInternalsIsReadableStreamDefaultReaderCodeLength = 145; |
319 | static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamDefaultReaderCodeIntrinsic = JSC::NoIntrinsic; |
320 | const char* const s_readableStreamInternalsIsReadableStreamDefaultReaderCode = |
321 | "(function (reader)\n" \ |
322 | "{\n" \ |
323 | " \"use strict\";\n" \ |
324 | "\n" \ |
325 | " //\n" \ |
326 | " //\n" \ |
327 | " //\n" \ |
328 | " return @isObject(reader) && !!@getByIdDirectPrivate(reader, \"readRequests\");\n" \ |
329 | "})\n" \ |
330 | ; |
331 | |
332 | const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDefaultControllerCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
333 | const int s_readableStreamInternalsIsReadableStreamDefaultControllerCodeLength = 168; |
334 | static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamDefaultControllerCodeIntrinsic = JSC::NoIntrinsic; |
335 | const char* const s_readableStreamInternalsIsReadableStreamDefaultControllerCode = |
336 | "(function (controller)\n" \ |
337 | "{\n" \ |
338 | " \"use strict\";\n" \ |
339 | "\n" \ |
340 | " //\n" \ |
341 | " //\n" \ |
342 | " //\n" \ |
343 | " //\n" \ |
344 | " return @isObject(controller) && !!@getByIdDirectPrivate(controller, \"underlyingSource\");\n" \ |
345 | "})\n" \ |
346 | ; |
347 | |
348 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamErrorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
349 | const int s_readableStreamInternalsReadableStreamErrorCodeLength = 1300; |
350 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamErrorCodeIntrinsic = JSC::NoIntrinsic; |
351 | const char* const s_readableStreamInternalsReadableStreamErrorCode = |
352 | "(function (stream, error)\n" \ |
353 | "{\n" \ |
354 | " \"use strict\";\n" \ |
355 | "\n" \ |
356 | " @assert(@isReadableStream(stream));\n" \ |
357 | " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable);\n" \ |
358 | " @putByIdDirectPrivate(stream, \"state\", @streamErrored);\n" \ |
359 | " @putByIdDirectPrivate(stream, \"storedError\", error);\n" \ |
360 | "\n" \ |
361 | " if (!@getByIdDirectPrivate(stream, \"reader\"))\n" \ |
362 | " return;\n" \ |
363 | "\n" \ |
364 | " const reader = @getByIdDirectPrivate(stream, \"reader\");\n" \ |
365 | "\n" \ |
366 | " if (@isReadableStreamDefaultReader(reader)) {\n" \ |
367 | " const requests = @getByIdDirectPrivate(reader, \"readRequests\");\n" \ |
368 | " for (let index = 0, length = requests.length; index < length; ++index)\n" \ |
369 | " requests[index].@reject.@call(@undefined, error);\n" \ |
370 | " @putByIdDirectPrivate(reader, \"readRequests\", []);\n" \ |
371 | " } else {\n" \ |
372 | " @assert(@isReadableStreamBYOBReader(reader));\n" \ |
373 | " const requests = @getByIdDirectPrivate(reader, \"readIntoRequests\");\n" \ |
374 | " for (let index = 0, length = requests.length; index < length; ++index)\n" \ |
375 | " requests[index].@reject.@call(@undefined, error);\n" \ |
376 | " @putByIdDirectPrivate(reader, \"readIntoRequests\", []);\n" \ |
377 | " }\n" \ |
378 | "\n" \ |
379 | " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@reject.@call(@undefined, error);\n" \ |
380 | " @putByIdDirectPrivate(@getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise, \"promiseIsHandled\", true);\n" \ |
381 | "})\n" \ |
382 | ; |
383 | |
384 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
385 | const int s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeLength = 1261; |
386 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCodeIntrinsic = JSC::NoIntrinsic; |
387 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerCallPullIfNeededCode = |
388 | "(function (controller)\n" \ |
389 | "{\n" \ |
390 | " \"use strict\";\n" \ |
391 | "\n" \ |
392 | " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \ |
393 | "\n" \ |
394 | " if (!@readableStreamDefaultControllerCanCloseOrEnqueue(controller))\n" \ |
395 | " return;\n" \ |
396 | " if (!@getByIdDirectPrivate(controller, \"started\"))\n" \ |
397 | " return;\n" \ |
398 | " if ((!@isReadableStreamLocked(stream) || !@getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\").length) && @readableStreamDefaultControllerGetDesiredSize(controller) <= 0)\n" \ |
399 | " return;\n" \ |
400 | "\n" \ |
401 | " if (@getByIdDirectPrivate(controller, \"pulling\")) {\n" \ |
402 | " @putByIdDirectPrivate(controller, \"pullAgain\", true);\n" \ |
403 | " return;\n" \ |
404 | " }\n" \ |
405 | "\n" \ |
406 | " @assert(!@getByIdDirectPrivate(controller, \"pullAgain\"));\n" \ |
407 | " @putByIdDirectPrivate(controller, \"pulling\", true);\n" \ |
408 | "\n" \ |
409 | " @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, \"underlyingSource\"), \"pull\", [controller]).@then(function() {\n" \ |
410 | " @putByIdDirectPrivate(controller, \"pulling\", false);\n" \ |
411 | " if (@getByIdDirectPrivate(controller, \"pullAgain\")) {\n" \ |
412 | " @putByIdDirectPrivate(controller, \"pullAgain\", false);\n" \ |
413 | " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \ |
414 | " }\n" \ |
415 | " }, function(error) {\n" \ |
416 | " @readableStreamDefaultControllerError(controller, error);\n" \ |
417 | " });\n" \ |
418 | "})\n" \ |
419 | ; |
420 | |
421 | const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamLockedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
422 | const int s_readableStreamInternalsIsReadableStreamLockedCodeLength = 136; |
423 | static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamLockedCodeIntrinsic = JSC::NoIntrinsic; |
424 | const char* const s_readableStreamInternalsIsReadableStreamLockedCode = |
425 | "(function (stream)\n" \ |
426 | "{\n" \ |
427 | " \"use strict\";\n" \ |
428 | "\n" \ |
429 | " @assert(@isReadableStream(stream));\n" \ |
430 | " return !!@getByIdDirectPrivate(stream, \"reader\");\n" \ |
431 | "})\n" \ |
432 | ; |
433 | |
434 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
435 | const int s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeLength = 416; |
436 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCodeIntrinsic = JSC::NoIntrinsic; |
437 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerGetDesiredSizeCode = |
438 | "(function (controller)\n" \ |
439 | "{\n" \ |
440 | " \"use strict\";\n" \ |
441 | "\n" \ |
442 | " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \ |
443 | " const state = @getByIdDirectPrivate(stream, \"state\");\n" \ |
444 | "\n" \ |
445 | " if (state === @streamErrored)\n" \ |
446 | " return null;\n" \ |
447 | " if (state === @streamClosed)\n" \ |
448 | " return 0;\n" \ |
449 | "\n" \ |
450 | " return @getByIdDirectPrivate(controller, \"strategy\").highWaterMark - @getByIdDirectPrivate(controller, \"queue\").size;\n" \ |
451 | "})\n" \ |
452 | ; |
453 | |
454 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
455 | const int s_readableStreamInternalsReadableStreamReaderGenericCancelCodeLength = 197; |
456 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamReaderGenericCancelCodeIntrinsic = JSC::NoIntrinsic; |
457 | const char* const s_readableStreamInternalsReadableStreamReaderGenericCancelCode = |
458 | "(function (reader, reason)\n" \ |
459 | "{\n" \ |
460 | " \"use strict\";\n" \ |
461 | "\n" \ |
462 | " const stream = @getByIdDirectPrivate(reader, \"ownerReadableStream\");\n" \ |
463 | " @assert(!!stream);\n" \ |
464 | " return @readableStreamCancel(stream, reason);\n" \ |
465 | "})\n" \ |
466 | ; |
467 | |
468 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
469 | const int s_readableStreamInternalsReadableStreamCancelCodeLength = 547; |
470 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamCancelCodeIntrinsic = JSC::NoIntrinsic; |
471 | const char* const s_readableStreamInternalsReadableStreamCancelCode = |
472 | "(function (stream, reason)\n" \ |
473 | "{\n" \ |
474 | " \"use strict\";\n" \ |
475 | "\n" \ |
476 | " @putByIdDirectPrivate(stream, \"disturbed\", true);\n" \ |
477 | " const state = @getByIdDirectPrivate(stream, \"state\");\n" \ |
478 | " if (state === @streamClosed)\n" \ |
479 | " return @Promise.@resolve();\n" \ |
480 | " if (state === @streamErrored)\n" \ |
481 | " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \ |
482 | " @readableStreamClose(stream);\n" \ |
483 | " return @getByIdDirectPrivate(stream, \"readableStreamController\").@cancel(@getByIdDirectPrivate(stream, \"readableStreamController\"), reason).@then(function() { });\n" \ |
484 | "})\n" \ |
485 | ; |
486 | |
487 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
488 | const int s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeLength = 224; |
489 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCancelCodeIntrinsic = JSC::NoIntrinsic; |
490 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerCancelCode = |
491 | "(function (controller, reason)\n" \ |
492 | "{\n" \ |
493 | " \"use strict\";\n" \ |
494 | "\n" \ |
495 | " @putByIdDirectPrivate(controller, \"queue\", @newQueue());\n" \ |
496 | " return @promiseInvokeOrNoop(@getByIdDirectPrivate(controller, \"underlyingSource\"), \"cancel\", [reason]);\n" \ |
497 | "})\n" \ |
498 | ; |
499 | |
500 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerPullCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
501 | const int s_readableStreamInternalsReadableStreamDefaultControllerPullCodeLength = 768; |
502 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerPullCodeIntrinsic = JSC::NoIntrinsic; |
503 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerPullCode = |
504 | "(function (controller)\n" \ |
505 | "{\n" \ |
506 | " \"use strict\";\n" \ |
507 | "\n" \ |
508 | " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \ |
509 | " if (@getByIdDirectPrivate(controller, \"queue\").content.length) {\n" \ |
510 | " const chunk = @dequeueValue(@getByIdDirectPrivate(controller, \"queue\"));\n" \ |
511 | " if (@getByIdDirectPrivate(controller, \"closeRequested\") && @getByIdDirectPrivate(controller, \"queue\").content.length === 0)\n" \ |
512 | " @readableStreamClose(stream);\n" \ |
513 | " else\n" \ |
514 | " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \ |
515 | " return @Promise.@resolve({value: chunk, done: false});\n" \ |
516 | " }\n" \ |
517 | " const pendingPromise = @readableStreamAddReadRequest(stream);\n" \ |
518 | " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \ |
519 | " return pendingPromise;\n" \ |
520 | "})\n" \ |
521 | ; |
522 | |
523 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
524 | const int s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeLength = 352; |
525 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCloseCodeIntrinsic = JSC::NoIntrinsic; |
526 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerCloseCode = |
527 | "(function (controller)\n" \ |
528 | "{\n" \ |
529 | " \"use strict\";\n" \ |
530 | "\n" \ |
531 | " @assert(@readableStreamDefaultControllerCanCloseOrEnqueue(controller));\n" \ |
532 | " @putByIdDirectPrivate(controller, \"closeRequested\", true);\n" \ |
533 | " if (@getByIdDirectPrivate(controller, \"queue\").content.length === 0)\n" \ |
534 | " @readableStreamClose(@getByIdDirectPrivate(controller, \"controlledReadableStream\"));\n" \ |
535 | "})\n" \ |
536 | ; |
537 | |
538 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
539 | const int s_readableStreamInternalsReadableStreamCloseCodeLength = 704; |
540 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamCloseCodeIntrinsic = JSC::NoIntrinsic; |
541 | const char* const s_readableStreamInternalsReadableStreamCloseCode = |
542 | "(function (stream)\n" \ |
543 | "{\n" \ |
544 | " \"use strict\";\n" \ |
545 | "\n" \ |
546 | " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamReadable);\n" \ |
547 | " @putByIdDirectPrivate(stream, \"state\", @streamClosed);\n" \ |
548 | " const reader = @getByIdDirectPrivate(stream, \"reader\");\n" \ |
549 | "\n" \ |
550 | " if (!reader)\n" \ |
551 | " return;\n" \ |
552 | "\n" \ |
553 | " if (@isReadableStreamDefaultReader(reader)) {\n" \ |
554 | " const requests = @getByIdDirectPrivate(reader, \"readRequests\");\n" \ |
555 | " for (let index = 0, length = requests.length; index < length; ++index)\n" \ |
556 | " requests[index].@resolve.@call(@undefined, {value:@undefined, done: true});\n" \ |
557 | " @putByIdDirectPrivate(reader, \"readRequests\", []);\n" \ |
558 | " }\n" \ |
559 | "\n" \ |
560 | " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@resolve.@call();\n" \ |
561 | "})\n" \ |
562 | ; |
563 | |
564 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamFulfillReadRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
565 | const int s_readableStreamInternalsReadableStreamFulfillReadRequestCodeLength = 204; |
566 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamFulfillReadRequestCodeIntrinsic = JSC::NoIntrinsic; |
567 | const char* const s_readableStreamInternalsReadableStreamFulfillReadRequestCode = |
568 | "(function (stream, chunk, done)\n" \ |
569 | "{\n" \ |
570 | " \"use strict\";\n" \ |
571 | "\n" \ |
572 | " @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\").@shift().@resolve.@call(@undefined, {value: chunk, done: done});\n" \ |
573 | "})\n" \ |
574 | ; |
575 | |
576 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
577 | const int s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeLength = 979; |
578 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCodeIntrinsic = JSC::NoIntrinsic; |
579 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerEnqueueCode = |
580 | "(function (controller, chunk)\n" \ |
581 | "{\n" \ |
582 | " \"use strict\";\n" \ |
583 | "\n" \ |
584 | " const stream = @getByIdDirectPrivate(controller, \"controlledReadableStream\");\n" \ |
585 | " @assert(@readableStreamDefaultControllerCanCloseOrEnqueue(controller));\n" \ |
586 | "\n" \ |
587 | " if (@isReadableStreamLocked(stream) && @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\").length) {\n" \ |
588 | " @readableStreamFulfillReadRequest(stream, chunk, false);\n" \ |
589 | " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \ |
590 | " return;\n" \ |
591 | " }\n" \ |
592 | "\n" \ |
593 | " try {\n" \ |
594 | " let chunkSize = 1;\n" \ |
595 | " if (@getByIdDirectPrivate(controller, \"strategy\").size !== @undefined)\n" \ |
596 | " chunkSize = @getByIdDirectPrivate(controller, \"strategy\").size(chunk);\n" \ |
597 | " @enqueueValueWithSize(@getByIdDirectPrivate(controller, \"queue\"), chunk, chunkSize);\n" \ |
598 | " }\n" \ |
599 | " catch(error) {\n" \ |
600 | " @readableStreamDefaultControllerError(controller, error);\n" \ |
601 | " throw error;\n" \ |
602 | " }\n" \ |
603 | " @readableStreamDefaultControllerCallPullIfNeeded(controller);\n" \ |
604 | "})\n" \ |
605 | ; |
606 | |
607 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultReaderReadCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
608 | const int s_readableStreamInternalsReadableStreamDefaultReaderReadCodeLength = 641; |
609 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultReaderReadCodeIntrinsic = JSC::NoIntrinsic; |
610 | const char* const s_readableStreamInternalsReadableStreamDefaultReaderReadCode = |
611 | "(function (reader)\n" \ |
612 | "{\n" \ |
613 | " \"use strict\";\n" \ |
614 | "\n" \ |
615 | " const stream = @getByIdDirectPrivate(reader, \"ownerReadableStream\");\n" \ |
616 | " @assert(!!stream);\n" \ |
617 | " const state = @getByIdDirectPrivate(stream, \"state\");\n" \ |
618 | "\n" \ |
619 | " @putByIdDirectPrivate(stream, \"disturbed\", true);\n" \ |
620 | " if (state === @streamClosed)\n" \ |
621 | " return @Promise.@resolve({value: @undefined, done: true});\n" \ |
622 | " if (state === @streamErrored)\n" \ |
623 | " return @Promise.@reject(@getByIdDirectPrivate(stream, \"storedError\"));\n" \ |
624 | " @assert(state === @streamReadable);\n" \ |
625 | "\n" \ |
626 | " return @getByIdDirectPrivate(stream, \"readableStreamController\").@pull(@getByIdDirectPrivate(stream, \"readableStreamController\"));\n" \ |
627 | "})\n" \ |
628 | ; |
629 | |
630 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamAddReadRequestCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
631 | const int s_readableStreamInternalsReadableStreamAddReadRequestCodeLength = 396; |
632 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamAddReadRequestCodeIntrinsic = JSC::NoIntrinsic; |
633 | const char* const s_readableStreamInternalsReadableStreamAddReadRequestCode = |
634 | "(function (stream)\n" \ |
635 | "{\n" \ |
636 | " \"use strict\";\n" \ |
637 | "\n" \ |
638 | " @assert(@isReadableStreamDefaultReader(@getByIdDirectPrivate(stream, \"reader\")));\n" \ |
639 | " @assert(@getByIdDirectPrivate(stream, \"state\") == @streamReadable);\n" \ |
640 | "\n" \ |
641 | " const readRequest = @newPromiseCapability(@Promise);\n" \ |
642 | " @getByIdDirectPrivate(@getByIdDirectPrivate(stream, \"reader\"), \"readRequests\").@push(readRequest);\n" \ |
643 | "\n" \ |
644 | " return readRequest.@promise;\n" \ |
645 | "})\n" \ |
646 | ; |
647 | |
648 | const JSC::ConstructAbility s_readableStreamInternalsIsReadableStreamDisturbedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
649 | const int s_readableStreamInternalsIsReadableStreamDisturbedCodeLength = 138; |
650 | static const JSC::Intrinsic s_readableStreamInternalsIsReadableStreamDisturbedCodeIntrinsic = JSC::NoIntrinsic; |
651 | const char* const s_readableStreamInternalsIsReadableStreamDisturbedCode = |
652 | "(function (stream)\n" \ |
653 | "{\n" \ |
654 | " \"use strict\";\n" \ |
655 | "\n" \ |
656 | " @assert(@isReadableStream(stream));\n" \ |
657 | " return @getByIdDirectPrivate(stream, \"disturbed\");\n" \ |
658 | "})\n" \ |
659 | ; |
660 | |
661 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
662 | const int s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeLength = 965; |
663 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamReaderGenericReleaseCodeIntrinsic = JSC::NoIntrinsic; |
664 | const char* const s_readableStreamInternalsReadableStreamReaderGenericReleaseCode = |
665 | "(function (reader)\n" \ |
666 | "{\n" \ |
667 | " \"use strict\";\n" \ |
668 | "\n" \ |
669 | " @assert(!!@getByIdDirectPrivate(reader, \"ownerReadableStream\"));\n" \ |
670 | " @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(reader, \"ownerReadableStream\"), \"reader\") === reader);\n" \ |
671 | "\n" \ |
672 | " if (@getByIdDirectPrivate(@getByIdDirectPrivate(reader, \"ownerReadableStream\"), \"state\") === @streamReadable)\n" \ |
673 | " @getByIdDirectPrivate(reader, \"closedPromiseCapability\").@reject.@call(@undefined, @makeTypeError(\"releasing lock of reader whose stream is still in readable state\"));\n" \ |
674 | " else\n" \ |
675 | " @putByIdDirectPrivate(reader, \"closedPromiseCapability\", { @promise: @newHandledRejectedPromise(@makeTypeError(\"reader released lock\")) });\n" \ |
676 | "\n" \ |
677 | " @putByIdDirectPrivate(@getByIdDirectPrivate(reader, \"closedPromiseCapability\").@promise, \"promiseIsHandled\", true);\n" \ |
678 | " @putByIdDirectPrivate(@getByIdDirectPrivate(reader, \"ownerReadableStream\"), \"reader\", @undefined);\n" \ |
679 | " @putByIdDirectPrivate(reader, \"ownerReadableStream\", @undefined);\n" \ |
680 | "})\n" \ |
681 | ; |
682 | |
683 | const JSC::ConstructAbility s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
684 | const int s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeLength = 229; |
685 | static const JSC::Intrinsic s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCodeIntrinsic = JSC::NoIntrinsic; |
686 | const char* const s_readableStreamInternalsReadableStreamDefaultControllerCanCloseOrEnqueueCode = |
687 | "(function (controller)\n" \ |
688 | "{\n" \ |
689 | " \"use strict\";\n" \ |
690 | "\n" \ |
691 | " return !@getByIdDirectPrivate(controller, \"closeRequested\") && @getByIdDirectPrivate(@getByIdDirectPrivate(controller, \"controlledReadableStream\"), \"state\") === @streamReadable;\n" \ |
692 | "})\n" \ |
693 | ; |
694 | |
695 | |
696 | #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ |
697 | JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ |
698 | {\ |
699 | JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ |
700 | return clientData->builtinFunctions().readableStreamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().readableStreamInternalsBuiltins().codeName##Source(), WTF::nullopt, s_##codeName##Intrinsic); \ |
701 | } |
702 | WEBCORE_FOREACH_READABLESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) |
703 | #undef DEFINE_BUILTIN_GENERATOR |
704 | |
705 | |
706 | } // namespace WebCore |
707 | |
708 | #endif // ENABLE(STREAMS_API) |
709 | |