/* * Copyright (c) 2015 Igalia * Copyright (c) 2015 Igalia S.L. * Copyright (c) 2015 Igalia. * Copyright (c) 2015, 2016 Canon Inc. All rights reserved. * Copyright (c) 2015, 2016, 2017 Canon Inc. * Copyright (c) 2016, 2020 Apple Inc. All rights reserved. * Copyright (c) 2022 Codeblog Corp. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. * */ // DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for // builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py #include "config.h" #include "NodeEventsBuiltins.h" #include "WebCoreJSClientData.h" #include #include #include #include #include #include #include #include namespace WebCore { const JSC::ConstructAbility s_nodeEventsOnAsyncIteratorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_nodeEventsOnAsyncIteratorCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_nodeEventsOnAsyncIteratorCodeImplementationVisibility = JSC::ImplementationVisibility::Public; const int s_nodeEventsOnAsyncIteratorCodeLength = 4024; static const JSC::Intrinsic s_nodeEventsOnAsyncIteratorCodeIntrinsic = JSC::NoIntrinsic; const char* const s_nodeEventsOnAsyncIteratorCode = "(function (emitter, event, options) {\n" \ " \"use strict\";\n" \ "\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ "\n" \ " //\n" \ " var { Object, Number, console, Symbol } = globalThis;\n" \ " //\n" \ "\n" \ " function isUndefinedOrNull(value) {\n" \ " return value === undefined || value === null;\n" \ " }\n" \ "\n" \ " if (isUndefinedOrNull(options)) options = {};\n" \ "\n" \ " //\n" \ " var signal = options.signal;\n" \ " //\n" \ " //\n" \ "\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ "\n" \ " var highWatermark = options.highWatermark ?? Number.MAX_SAFE_INTEGER;\n" \ " if (highWatermark < 1) \n" \ " @throwRangeError(\"options.highWatermark must be >= 1\");\n" \ "\n" \ " var lowWatermark = options.lowWatermark ?? 1;\n" \ " if (lowWatermark < 1) \n" \ " @throwRangeError(\"options.lowWatermark must be >= 1\");\n" \ "\n" \ " var unconsumedEvents = @createFIFO();\n" \ " var unconsumedPromises = @createFIFO();\n" \ "\n" \ " var paused = false;\n" \ " var error = null;\n" \ " var finished = false;\n" \ " var size = 0;\n" \ " var listeners = [];\n" \ "\n" \ " //\n" \ " //\n" \ " //\n" \ "\n" \ " function eventHandler(value) {\n" \ " if (unconsumedPromises.isEmpty()) {\n" \ " size++;\n" \ " if (!paused && size > highWatermark) {\n" \ " paused = true;\n" \ " emitter.pause();\n" \ " }\n" \ " unconsumedEvents.push(value);\n" \ " } else unconsumedPromises.shift().@resolve.@call(undefined, [value]);\n" \ " }\n" \ "\n" \ " function closeHandler() {\n" \ " removeAllListeners(listeners);\n" \ " finished = true;\n" \ " while (!unconsumedPromises.isEmpty()) {\n" \ " unconsumedPromises.shift().@resolve.@call(undefined, [undefined]);\n" \ " }\n" \ " \n" \ " return @createFulfilledPromise([undefined]);\n" \ " }\n" \ "\n" \ " function errorHandler(err) {\n" \ " if (unconsumedPromises.isEmpty()) error = err;\n" \ " else unconsumedPromises.shift().@reject.@call(undefined, err);\n" \ " \n" \ " closeHandler();\n" \ " }\n" \ " \n" \ " function addEventListener(emitter, event, handler) {\n" \ " emitter.on(event, handler);\n" \ " listeners.push([emitter, event, handler]);\n" \ " //\n" \ " }\n" \ " \n" \ " function removeAllListeners() {\n" \ " var heldEmitter;\n" \ " while (listeners.length > 0) {\n" \ " //\n" \ " var entry = listeners.pop();\n" \ " var [emitter, event, handler] = entry;\n" \ " if (event === \"foo\") heldEmitter = emitter;\n" \ " console.log(emitter, event, handler);\n" \ " emitter.off(event, handler);\n" \ " }\n" \ " console.log(heldEmitter.listenerCount(\"foo\"));\n" \ " }\n" \ "\n" \ " var iterator = async function* NodeEventsOnAsyncIterator() {\n" \ " //\n" \ " while (!finished) {\n" \ " if (size) {\n" \ " var values = [];\n" \ " while (size) {\n" \ " values.push(unconsumedEvents.shift());\n" \ " size--;\n" \ " if (paused && size < lowWatermark) {\n" \ " emitter.resume();\n" \ " paused = false;\n" \ " break;\n" \ " }\n" \ " }\n" \ " yield @createFulfilledPromise(values);\n" \ " }\n" \ "\n" \ " //\n" \ " //\n" \ " //\n" \ " if (error) {\n" \ " throw error;\n" \ " }\n" \ "\n" \ " //\n" \ " if (finished) {\n" \ " console.log(\"FINISHED\")\n" \ " yield closeHandler();\n" \ " break;\n" \ " };\n" \ "\n" \ " //\n" \ " var nextEventPromiseCapability = @newPromiseCapability(@Promise);\n" \ " unconsumedPromises.push(nextEventPromiseCapability);\n" \ " yield nextEventPromiseCapability.@promise;\n" \ " }\n" \ " };\n" \ "\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ " //\n" \ "\n" \ " //\n" \ " addEventListener(emitter, event, eventHandler);\n" \ " if (event !== \"error\" && typeof emitter.on === \"function\") {\n" \ " addEventListener(emitter, \"error\", errorHandler);\n" \ " }\n" \ " var closeEvents = options?.close;\n" \ " if (closeEvents?.length) {\n" \ " for (var i = 0; i < closeEvents.length; i++) {\n" \ " addEventListener(emitter, closeEvents[i], closeHandler);\n" \ " }\n" \ " }\n" \ "\n" \ " //\n" \ " //\n" \ "\n" \ " return {\n" \ " throw: (err) => {\n" \ " if (err === undefined || err === null || !(err instanceof Error)) {\n" \ " @throwTypeError(\"The argument must be an instance of Error\");\n" \ " }\n" \ " errorHandler(err);\n" \ " },\n" \ " return: () => {\n" \ " console.log(\"we're here\");\n" \ " return closeHandler();\n" \ " },\n" \ " next: () => iterator.next(),\n" \ " [Symbol.asyncIterator]: iterator,\n" \ " };\n" \ "})\n" \ ; #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ {\ JSVMClientData* clientData = static_cast(vm.clientData); \ return clientData->builtinFunctions().nodeEventsBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().nodeEventsBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ } WEBCORE_FOREACH_NODEEVENTS_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) #undef DEFINE_BUILTIN_GENERATOR } // namespace WebCore