| 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 "WritableStreamInternalsBuiltins.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_writableStreamInternalsIsWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
| 49 | const int s_writableStreamInternalsIsWritableStreamCodeLength = 126; |
| 50 | static const JSC::Intrinsic s_writableStreamInternalsIsWritableStreamCodeIntrinsic = JSC::NoIntrinsic; |
| 51 | const char* const s_writableStreamInternalsIsWritableStreamCode = |
| 52 | "(function (stream)\n" \ |
| 53 | "{\n" \ |
| 54 | " \"use strict\";\n" \ |
| 55 | "\n" \ |
| 56 | " return @isObject(stream) && !!@getByIdDirectPrivate(stream, \"underlyingSink\");\n" \ |
| 57 | "})\n" \ |
| 58 | ; |
| 59 | |
| 60 | const JSC::ConstructAbility s_writableStreamInternalsSyncWritableStreamStateWithQueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
| 61 | const int s_writableStreamInternalsSyncWritableStreamStateWithQueueCodeLength = 809; |
| 62 | static const JSC::Intrinsic s_writableStreamInternalsSyncWritableStreamStateWithQueueCodeIntrinsic = JSC::NoIntrinsic; |
| 63 | const char* const s_writableStreamInternalsSyncWritableStreamStateWithQueueCode = |
| 64 | "(function (stream)\n" \ |
| 65 | "{\n" \ |
| 66 | " \"use strict\";\n" \ |
| 67 | "\n" \ |
| 68 | " const state = @getByIdDirectPrivate(stream, \"state\");\n" \ |
| 69 | " if (state === @streamClosing)\n" \ |
| 70 | " return;\n" \ |
| 71 | "\n" \ |
| 72 | " @assert(state === @streamWritable || state === @streamWaiting);\n" \ |
| 73 | "\n" \ |
| 74 | " const shouldApplyBackpressure = @getByIdDirectPrivate(stream, \"queue\").size > @getByIdDirectPrivate(stream, \"strategy\").highWaterMark;\n" \ |
| 75 | " if (shouldApplyBackpressure && state === @streamWritable) {\n" \ |
| 76 | " @putByIdDirectPrivate(stream, \"state\", @streamWaiting);\n" \ |
| 77 | " @putByIdDirectPrivate(stream, \"readyPromiseCapability\", @newPromiseCapability(@Promise));\n" \ |
| 78 | " }\n" \ |
| 79 | " if (!shouldApplyBackpressure && state === @streamWaiting) {\n" \ |
| 80 | " @putByIdDirectPrivate(stream, \"state\", @streamWritable);\n" \ |
| 81 | " @getByIdDirectPrivate(stream, \"readyPromiseCapability\").@resolve.@call();\n" \ |
| 82 | " }\n" \ |
| 83 | "})\n" \ |
| 84 | ; |
| 85 | |
| 86 | const JSC::ConstructAbility s_writableStreamInternalsErrorWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
| 87 | const int s_writableStreamInternalsErrorWritableStreamCodeLength = 771; |
| 88 | static const JSC::Intrinsic s_writableStreamInternalsErrorWritableStreamCodeIntrinsic = JSC::NoIntrinsic; |
| 89 | const char* const s_writableStreamInternalsErrorWritableStreamCode = |
| 90 | "(function (stream, e)\n" \ |
| 91 | "{\n" \ |
| 92 | " \"use strict\";\n" \ |
| 93 | "\n" \ |
| 94 | " const state = @getByIdDirectPrivate(stream, \"state\");\n" \ |
| 95 | " if (state === @streamClosed || state === @streamErrored)\n" \ |
| 96 | " return;\n" \ |
| 97 | " while (@getByIdDirectPrivate(stream, \"queue\").content.length > 0) {\n" \ |
| 98 | " const writeRecord = @dequeueValue(@getByIdDirectPrivate(stream, \"queue\"));\n" \ |
| 99 | " if (writeRecord !== \"close\")\n" \ |
| 100 | " writeRecord.promiseCapability.@reject.@call(@undefined, e);\n" \ |
| 101 | " }\n" \ |
| 102 | " @putByIdDirectPrivate(stream, \"storedError\", e);\n" \ |
| 103 | " if (state === @streamWaiting)\n" \ |
| 104 | " @getByIdDirectPrivate(stream, \"readyPromiseCapability\").@resolve.@call();\n" \ |
| 105 | " @getByIdDirectPrivate(stream, \"closedPromiseCapability\").@reject.@call(@undefined, e);\n" \ |
| 106 | " @putByIdDirectPrivate(stream, \"state\", @streamErrored);\n" \ |
| 107 | "})\n" \ |
| 108 | ; |
| 109 | |
| 110 | const JSC::ConstructAbility s_writableStreamInternalsCallOrScheduleWritableStreamAdvanceQueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
| 111 | const int s_writableStreamInternalsCallOrScheduleWritableStreamAdvanceQueueCodeLength = 264; |
| 112 | static const JSC::Intrinsic s_writableStreamInternalsCallOrScheduleWritableStreamAdvanceQueueCodeIntrinsic = JSC::NoIntrinsic; |
| 113 | const char* const s_writableStreamInternalsCallOrScheduleWritableStreamAdvanceQueueCode = |
| 114 | "(function (stream)\n" \ |
| 115 | "{\n" \ |
| 116 | " \"use strict\";\n" \ |
| 117 | "\n" \ |
| 118 | " if (!@getByIdDirectPrivate(stream, \"started\"))\n" \ |
| 119 | " @getByIdDirectPrivate(stream, \"startedPromise\").@then(function() { @writableStreamAdvanceQueue(stream); });\n" \ |
| 120 | " else\n" \ |
| 121 | " @writableStreamAdvanceQueue(stream);\n" \ |
| 122 | "})\n" \ |
| 123 | ; |
| 124 | |
| 125 | const JSC::ConstructAbility s_writableStreamInternalsWritableStreamAdvanceQueueCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
| 126 | const int s_writableStreamInternalsWritableStreamAdvanceQueueCodeLength = 1237; |
| 127 | static const JSC::Intrinsic s_writableStreamInternalsWritableStreamAdvanceQueueCodeIntrinsic = JSC::NoIntrinsic; |
| 128 | const char* const s_writableStreamInternalsWritableStreamAdvanceQueueCode = |
| 129 | "(function (stream)\n" \ |
| 130 | "{\n" \ |
| 131 | " \"use strict\";\n" \ |
| 132 | "\n" \ |
| 133 | " if (@getByIdDirectPrivate(stream, \"queue\").content.length === 0 || @getByIdDirectPrivate(stream, \"writing\"))\n" \ |
| 134 | " return;\n" \ |
| 135 | "\n" \ |
| 136 | " const writeRecord = @peekQueueValue(@getByIdDirectPrivate(stream, \"queue\"));\n" \ |
| 137 | " if (writeRecord === \"close\") {\n" \ |
| 138 | " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamClosing);\n" \ |
| 139 | " @dequeueValue(@getByIdDirectPrivate(stream, \"queue\"));\n" \ |
| 140 | " @assert(@getByIdDirectPrivate(stream, \"queue\").content.length === 0);\n" \ |
| 141 | " @closeWritableStream(stream);\n" \ |
| 142 | " return;\n" \ |
| 143 | " }\n" \ |
| 144 | "\n" \ |
| 145 | " @putByIdDirectPrivate(stream, \"writing\", true);\n" \ |
| 146 | " @promiseInvokeOrNoop(@getByIdDirectPrivate(stream, \"underlyingSink\"), \"write\", [writeRecord.chunk]).@then(\n" \ |
| 147 | " function() {\n" \ |
| 148 | " if (@getByIdDirectPrivate(stream, \"state\") === @streamErrored)\n" \ |
| 149 | " return;\n" \ |
| 150 | " @putByIdDirectPrivate(stream, \"writing\", false);\n" \ |
| 151 | " writeRecord.promiseCapability.@resolve.@call();\n" \ |
| 152 | " @dequeueValue(@getByIdDirectPrivate(stream, \"queue\"));\n" \ |
| 153 | " @syncWritableStreamStateWithQueue(stream);\n" \ |
| 154 | " @writableStreamAdvanceQueue(stream);\n" \ |
| 155 | " },\n" \ |
| 156 | " function(r) {\n" \ |
| 157 | " @errorWritableStream(stream, r);\n" \ |
| 158 | " }\n" \ |
| 159 | " );\n" \ |
| 160 | "})\n" \ |
| 161 | ; |
| 162 | |
| 163 | const JSC::ConstructAbility s_writableStreamInternalsCloseWritableStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |
| 164 | const int s_writableStreamInternalsCloseWritableStreamCodeLength = 654; |
| 165 | static const JSC::Intrinsic s_writableStreamInternalsCloseWritableStreamCodeIntrinsic = JSC::NoIntrinsic; |
| 166 | const char* const s_writableStreamInternalsCloseWritableStreamCode = |
| 167 | "(function (stream)\n" \ |
| 168 | "{\n" \ |
| 169 | " \"use strict\";\n" \ |
| 170 | "\n" \ |
| 171 | " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamClosing);\n" \ |
| 172 | " @promiseInvokeOrNoop(@getByIdDirectPrivate(stream, \"underlyingSink\"), \"close\").@then(\n" \ |
| 173 | " function() {\n" \ |
| 174 | " if (@getByIdDirectPrivate(stream, \"state\") === @streamErrored)\n" \ |
| 175 | " return;\n" \ |
| 176 | " @assert(@getByIdDirectPrivate(stream, \"state\") === @streamClosing);\n" \ |
| 177 | " @getByIdDirectPrivate(stream, \"closedPromiseCapability\").@resolve.@call();\n" \ |
| 178 | " @putByIdDirectPrivate(stream, \"state\", @streamClosed);\n" \ |
| 179 | " },\n" \ |
| 180 | " function(r) {\n" \ |
| 181 | " @errorWritableStream(stream, r);\n" \ |
| 182 | " }\n" \ |
| 183 | " );\n" \ |
| 184 | "})\n" \ |
| 185 | ; |
| 186 | |
| 187 | |
| 188 | #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ |
| 189 | JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ |
| 190 | {\ |
| 191 | JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ |
| 192 | return clientData->builtinFunctions().writableStreamInternalsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().writableStreamInternalsBuiltins().codeName##Source(), WTF::nullopt, s_##codeName##Intrinsic); \ |
| 193 | } |
| 194 | WEBCORE_FOREACH_WRITABLESTREAMINTERNALS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) |
| 195 | #undef DEFINE_BUILTIN_GENERATOR |
| 196 | |
| 197 | |
| 198 | } // namespace WebCore |
| 199 | |
| 200 | #endif // ENABLE(STREAMS_API) |
| 201 | |