1 | /* |
2 | * Copyright (c) 2015 Canon Inc. |
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 "WritableStreamBuiltins.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_writableStreamInitializeWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
49 | const int s_writableStreamInitializeWritableStreamCodeLength = 1561; |
50 | static const JSC::Intrinsic s_writableStreamInitializeWritableStreamCodeIntrinsic = JSC::NoIntrinsic; |
51 | const char* const s_writableStreamInitializeWritableStreamCode = |
52 | "(function (underlyingSink, strategy)\n" \ |
53 | "{\n" \ |
54 | " \"use strict\";\n" \ |
55 | "\n" \ |
56 | " if (underlyingSink === @undefined)\n" \ |
57 | " underlyingSink = { };\n" \ |
58 | " if (strategy === @undefined)\n" \ |
59 | " strategy = { highWaterMark: 0, size: function() { return 1; } };\n" \ |
60 | "\n" \ |
61 | " if (!@isObject(underlyingSink))\n" \ |
62 | " @throwTypeError(\"WritableStream constructor takes an object as first argument\");\n" \ |
63 | "\n" \ |
64 | " if (!@isObject(strategy))\n" \ |
65 | " @throwTypeError(\"WritableStream constructor takes an object as second argument, if any\");\n" \ |
66 | "\n" \ |
67 | " @putByIdDirectPrivate(this, \"underlyingSink\", underlyingSink);\n" \ |
68 | " @putByIdDirectPrivate(this, \"closedPromiseCapability\", @newPromiseCapability(@Promise));\n" \ |
69 | " @putByIdDirectPrivate(this, \"readyPromiseCapability\", { @promise: @Promise.@resolve() });\n" \ |
70 | " @putByIdDirectPrivate(this, \"queue\", @newQueue());\n" \ |
71 | " @putByIdDirectPrivate(this, \"state\", @streamWritable);\n" \ |
72 | " @putByIdDirectPrivate(this, \"started\", false);\n" \ |
73 | " @putByIdDirectPrivate(this, \"writing\", false);\n" \ |
74 | "\n" \ |
75 | " @putByIdDirectPrivate(this, \"strategy\", @validateAndNormalizeQueuingStrategy(strategy.size, strategy.highWaterMark));\n" \ |
76 | "\n" \ |
77 | " @syncWritableStreamStateWithQueue(this);\n" \ |
78 | "\n" \ |
79 | " const errorFunction = (e) => {\n" \ |
80 | " @errorWritableStream(this, e);\n" \ |
81 | " };\n" \ |
82 | " @putByIdDirectPrivate(this, \"startedPromise\", @promiseInvokeOrNoopNoCatch(underlyingSink, \"start\", [errorFunction]));\n" \ |
83 | " @getByIdDirectPrivate(this, \"startedPromise\").@then(() => {\n" \ |
84 | " @putByIdDirectPrivate(this, \"started\", true);\n" \ |
85 | " @putByIdDirectPrivate(this, \"startedPromise\", @undefined);\n" \ |
86 | " }, errorFunction);\n" \ |
87 | "\n" \ |
88 | " return this;\n" \ |
89 | "})\n" \ |
90 | ; |
91 | |
92 | const JSC::ConstructAbility s_writableStreamAbortCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
93 | const int s_writableStreamAbortCodeLength = 633; |
94 | static const JSC::Intrinsic s_writableStreamAbortCodeIntrinsic = JSC::NoIntrinsic; |
95 | const char* const s_writableStreamAbortCode = |
96 | "(function (reason)\n" \ |
97 | "{\n" \ |
98 | " \"use strict\";\n" \ |
99 | "\n" \ |
100 | " if (!@isWritableStream(this))\n" \ |
101 | " return @Promise.@reject(@makeTypeError(\"The WritableStream.abort method can only be used on instances of WritableStream\"));\n" \ |
102 | "\n" \ |
103 | " const state = @getByIdDirectPrivate(this, \"state\");\n" \ |
104 | " if (state === @streamClosed)\n" \ |
105 | " return @Promise.@resolve();\n" \ |
106 | "\n" \ |
107 | " if (state === @streamErrored)\n" \ |
108 | " return @Promise.@reject(@getByIdDirectPrivate(this, \"storedError\"));\n" \ |
109 | "\n" \ |
110 | " @errorWritableStream(this, reason);\n" \ |
111 | "\n" \ |
112 | " return @promiseInvokeOrFallbackOrNoop(@getByIdDirectPrivate(this, \"underlyingSink\"), \"abort\", [reason], \"close\", []).@then(function() { });\n" \ |
113 | "})\n" \ |
114 | ; |
115 | |
116 | const JSC::ConstructAbility s_writableStreamCloseCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
117 | const int s_writableStreamCloseCodeLength = 922; |
118 | static const JSC::Intrinsic s_writableStreamCloseCodeIntrinsic = JSC::NoIntrinsic; |
119 | const char* const s_writableStreamCloseCode = |
120 | "(function ()\n" \ |
121 | "{\n" \ |
122 | " \"use strict\";\n" \ |
123 | "\n" \ |
124 | " if (!@isWritableStream(this))\n" \ |
125 | " return @Promise.@reject(@makeTypeError(\"The WritableStream.close method can only be used on instances of WritableStream\"));\n" \ |
126 | "\n" \ |
127 | " const state = @getByIdDirectPrivate(this, \"state\");\n" \ |
128 | " if (state === @streamClosed || state === @streamClosing)\n" \ |
129 | " return @Promise.@reject(@makeTypeError(\"Cannot close a WritableString that is closed or closing\"));\n" \ |
130 | "\n" \ |
131 | " if (state === @streamErrored)\n" \ |
132 | " return @Promise.@reject(@getByIdDirectPrivate(this, \"storedError\"));\n" \ |
133 | "\n" \ |
134 | " if (state === @streamWaiting)\n" \ |
135 | " @getByIdDirectPrivate(this, \"readyPromiseCapability\").@resolve.@call();\n" \ |
136 | "\n" \ |
137 | " @putByIdDirectPrivate(this, \"state\", @streamClosing);\n" \ |
138 | " @enqueueValueWithSize(@getByIdDirectPrivate(this, \"queue\"), \"close\", 0);\n" \ |
139 | " @callOrScheduleWritableStreamAdvanceQueue(this);\n" \ |
140 | "\n" \ |
141 | " return @getByIdDirectPrivate(this, \"closedPromiseCapability\").@promise;\n" \ |
142 | "})\n" \ |
143 | ; |
144 | |
145 | const JSC::ConstructAbility s_writableStreamWriteCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
146 | const int s_writableStreamWriteCodeLength = 1365; |
147 | static const JSC::Intrinsic s_writableStreamWriteCodeIntrinsic = JSC::NoIntrinsic; |
148 | const char* const s_writableStreamWriteCode = |
149 | "(function (chunk)\n" \ |
150 | "{\n" \ |
151 | " \"use strict\";\n" \ |
152 | "\n" \ |
153 | " if (!@isWritableStream(this))\n" \ |
154 | " return @Promise.@reject(@makeTypeError(\"The WritableStream.write method can only be used on instances of WritableStream\"));\n" \ |
155 | "\n" \ |
156 | " const state = @getByIdDirectPrivate(this, \"state\");\n" \ |
157 | " if (state === @streamClosed || state === @streamClosing)\n" \ |
158 | " return @Promise.@reject(@makeTypeError(\"Cannot write on a WritableString that is closed or closing\"));\n" \ |
159 | "\n" \ |
160 | " if (state === @streamErrored)\n" \ |
161 | " return @Promise.@reject(this.@storedError);\n" \ |
162 | "\n" \ |
163 | " @assert(state === @streamWritable || state === @streamWaiting);\n" \ |
164 | "\n" \ |
165 | " let chunkSize = 1;\n" \ |
166 | " if (@getByIdDirectPrivate(this, \"strategy\").size !== @undefined) {\n" \ |
167 | " try {\n" \ |
168 | " chunkSize = @getByIdDirectPrivate(this, \"strategy\").size.@call(@undefined, chunk);\n" \ |
169 | " } catch(e) {\n" \ |
170 | " @errorWritableStream(this, e);\n" \ |
171 | " return @Promise.@reject(e);\n" \ |
172 | " }\n" \ |
173 | " }\n" \ |
174 | "\n" \ |
175 | " const promiseCapability = @newPromiseCapability(@Promise);\n" \ |
176 | " try {\n" \ |
177 | " @enqueueValueWithSize(@getByIdDirectPrivate(this, \"queue\"), { promiseCapability: promiseCapability, chunk: chunk }, chunkSize);\n" \ |
178 | " } catch (e) {\n" \ |
179 | " @errorWritableStream(this, e);\n" \ |
180 | " return @Promise.@reject(e);\n" \ |
181 | " }\n" \ |
182 | "\n" \ |
183 | " @syncWritableStreamStateWithQueue(this);\n" \ |
184 | " @callOrScheduleWritableStreamAdvanceQueue(this);\n" \ |
185 | "\n" \ |
186 | " return promiseCapability.@promise;\n" \ |
187 | "})\n" \ |
188 | ; |
189 | |
190 | const JSC::ConstructAbility s_writableStreamClosedCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
191 | const int s_writableStreamClosedCodeLength = 231; |
192 | static const JSC::Intrinsic s_writableStreamClosedCodeIntrinsic = JSC::NoIntrinsic; |
193 | const char* const s_writableStreamClosedCode = |
194 | "(function ()\n" \ |
195 | "{\n" \ |
196 | " \"use strict\";\n" \ |
197 | "\n" \ |
198 | " if (!@isWritableStream(this))\n" \ |
199 | " return @Promise.@reject(@makeGetterTypeError(\"WritableStream\", \"closed\"));\n" \ |
200 | "\n" \ |
201 | " return @getByIdDirectPrivate(this, \"closedPromiseCapability\").@promise;\n" \ |
202 | "})\n" \ |
203 | ; |
204 | |
205 | const JSC::ConstructAbility s_writableStreamReadyCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
206 | const int s_writableStreamReadyCodeLength = 229; |
207 | static const JSC::Intrinsic s_writableStreamReadyCodeIntrinsic = JSC::NoIntrinsic; |
208 | const char* const s_writableStreamReadyCode = |
209 | "(function ()\n" \ |
210 | "{\n" \ |
211 | " \"use strict\";\n" \ |
212 | "\n" \ |
213 | " if (!@isWritableStream(this))\n" \ |
214 | " return @Promise.@reject(@makeGetterTypeError(\"WritableStream\", \"ready\"));\n" \ |
215 | "\n" \ |
216 | " return @getByIdDirectPrivate(this, \"readyPromiseCapability\").@promise;\n" \ |
217 | "})\n" \ |
218 | ; |
219 | |
220 | const JSC::ConstructAbility s_writableStreamStateCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
221 | const int s_writableStreamStateCodeLength = 513; |
222 | static const JSC::Intrinsic s_writableStreamStateCodeIntrinsic = JSC::NoIntrinsic; |
223 | const char* const s_writableStreamStateCode = |
224 | "(function ()\n" \ |
225 | "{\n" \ |
226 | " \"use strict\";\n" \ |
227 | "\n" \ |
228 | " if (!@isWritableStream(this))\n" \ |
229 | " @throwTypeError(\"The WritableStream.state getter can only be used on instances of WritableStream\");\n" \ |
230 | "\n" \ |
231 | " switch(@getByIdDirectPrivate(this, \"state\")) {\n" \ |
232 | " case @streamClosed:\n" \ |
233 | " return \"closed\";\n" \ |
234 | " case @streamClosing:\n" \ |
235 | " return \"closing\";\n" \ |
236 | " case @streamErrored:\n" \ |
237 | " return \"errored\";\n" \ |
238 | " case @streamWaiting:\n" \ |
239 | " return \"waiting\";\n" \ |
240 | " case @streamWritable:\n" \ |
241 | " return \"writable\";\n" \ |
242 | " }\n" \ |
243 | "\n" \ |
244 | " @assert(false);\n" \ |
245 | "})\n" \ |
246 | ; |
247 | |
248 | |
249 | #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ |
250 | JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ |
251 | {\ |
252 | JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ |
253 | return clientData->builtinFunctions().writableStreamBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().writableStreamBuiltins().codeName##Source(), WTF::nullopt, s_##codeName##Intrinsic); \ |
254 | } |
255 | WEBCORE_FOREACH_WRITABLESTREAM_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) |
256 | #undef DEFINE_BUILTIN_GENERATOR |
257 | |
258 | |
259 | } // namespace WebCore |
260 | |
261 | #endif // ENABLE(STREAMS_API) |
262 | |