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#pragma once
33
34#if ENABLE(STREAMS_API)
35
36#include <JavaScriptCore/BuiltinUtils.h>
37#include <JavaScriptCore/Identifier.h>
38#include <JavaScriptCore/JSFunction.h>
39#include <JavaScriptCore/UnlinkedFunctionExecutable.h>
40
41namespace JSC {
42class FunctionExecutable;
43}
44
45namespace WebCore {
46
47/* ReadableStream */
48extern const char* const s_readableStreamInitializeReadableStreamCode;
49extern const int s_readableStreamInitializeReadableStreamCodeLength;
50extern const JSC::ConstructAbility s_readableStreamInitializeReadableStreamCodeConstructAbility;
51extern const char* const s_readableStreamCancelCode;
52extern const int s_readableStreamCancelCodeLength;
53extern const JSC::ConstructAbility s_readableStreamCancelCodeConstructAbility;
54extern const char* const s_readableStreamGetReaderCode;
55extern const int s_readableStreamGetReaderCodeLength;
56extern const JSC::ConstructAbility s_readableStreamGetReaderCodeConstructAbility;
57extern const char* const s_readableStreamPipeThroughCode;
58extern const int s_readableStreamPipeThroughCodeLength;
59extern const JSC::ConstructAbility s_readableStreamPipeThroughCodeConstructAbility;
60extern const char* const s_readableStreamPipeToCode;
61extern const int s_readableStreamPipeToCodeLength;
62extern const JSC::ConstructAbility s_readableStreamPipeToCodeConstructAbility;
63extern const char* const s_readableStreamTeeCode;
64extern const int s_readableStreamTeeCodeLength;
65extern const JSC::ConstructAbility s_readableStreamTeeCodeConstructAbility;
66extern const char* const s_readableStreamLockedCode;
67extern const int s_readableStreamLockedCodeLength;
68extern const JSC::ConstructAbility s_readableStreamLockedCodeConstructAbility;
69
70#define WEBCORE_FOREACH_READABLESTREAM_BUILTIN_DATA(macro) \
71 macro(initializeReadableStream, readableStreamInitializeReadableStream, 2) \
72 macro(cancel, readableStreamCancel, 1) \
73 macro(getReader, readableStreamGetReader, 1) \
74 macro(pipeThrough, readableStreamPipeThrough, 2) \
75 macro(pipeTo, readableStreamPipeTo, 1) \
76 macro(tee, readableStreamTee, 0) \
77 macro(locked, readableStreamLocked, 0) \
78
79#define WEBCORE_BUILTIN_READABLESTREAM_INITIALIZEREADABLESTREAM 1
80#define WEBCORE_BUILTIN_READABLESTREAM_CANCEL 1
81#define WEBCORE_BUILTIN_READABLESTREAM_GETREADER 1
82#define WEBCORE_BUILTIN_READABLESTREAM_PIPETHROUGH 1
83#define WEBCORE_BUILTIN_READABLESTREAM_PIPETO 1
84#define WEBCORE_BUILTIN_READABLESTREAM_TEE 1
85#define WEBCORE_BUILTIN_READABLESTREAM_LOCKED 1
86
87#define WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(macro) \
88 macro(readableStreamInitializeReadableStreamCode, initializeReadableStream, static_cast<const char*>(nullptr), s_readableStreamInitializeReadableStreamCodeLength) \
89 macro(readableStreamCancelCode, cancel, static_cast<const char*>(nullptr), s_readableStreamCancelCodeLength) \
90 macro(readableStreamGetReaderCode, getReader, static_cast<const char*>(nullptr), s_readableStreamGetReaderCodeLength) \
91 macro(readableStreamPipeThroughCode, pipeThrough, static_cast<const char*>(nullptr), s_readableStreamPipeThroughCodeLength) \
92 macro(readableStreamPipeToCode, pipeTo, static_cast<const char*>(nullptr), s_readableStreamPipeToCodeLength) \
93 macro(readableStreamTeeCode, tee, static_cast<const char*>(nullptr), s_readableStreamTeeCodeLength) \
94 macro(readableStreamLockedCode, locked, "get locked", s_readableStreamLockedCodeLength) \
95
96#define WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(macro) \
97 macro(cancel) \
98 macro(getReader) \
99 macro(initializeReadableStream) \
100 macro(locked) \
101 macro(pipeThrough) \
102 macro(pipeTo) \
103 macro(tee) \
104
105#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \
106 JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
107
108WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
109#undef DECLARE_BUILTIN_GENERATOR
110
111class ReadableStreamBuiltinsWrapper : private JSC::WeakHandleOwner {
112public:
113 explicit ReadableStreamBuiltinsWrapper(JSC::VM* vm)
114 : m_vm(*vm)
115 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
116#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length), { }))
117 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
118#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
119 {
120 }
121
122#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
123 JSC::UnlinkedFunctionExecutable* name##Executable(); \
124 const JSC::SourceCode& name##Source() const { return m_##name##Source; }
125 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
126#undef EXPOSE_BUILTIN_EXECUTABLES
127
128 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
129
130 void exportNames();
131
132private:
133 JSC::VM& m_vm;
134
135 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
136
137#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \
138 JSC::SourceCode m_##name##Source;\
139 JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
140 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
141#undef DECLARE_BUILTIN_SOURCE_MEMBERS
142
143};
144
145#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \
146inline JSC::UnlinkedFunctionExecutable* ReadableStreamBuiltinsWrapper::name##Executable() \
147{\
148 if (!m_##name##Executable) {\
149 JSC::Identifier executableName = functionName##PublicName();\
150 if (overriddenName)\
151 executableName = JSC::Identifier::fromString(&m_vm, overriddenName);\
152 m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructAbility), this, &m_##name##Executable);\
153 }\
154 return m_##name##Executable.get();\
155}
156WEBCORE_FOREACH_READABLESTREAM_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
157#undef DEFINE_BUILTIN_EXECUTABLES
158
159inline void ReadableStreamBuiltinsWrapper::exportNames()
160{
161#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
162 WEBCORE_FOREACH_READABLESTREAM_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
163#undef EXPORT_FUNCTION_NAME
164}
165
166} // namespace WebCore
167
168#endif // ENABLE(STREAMS_API)
169