[GTK] Make script dialogs modal to the current web view only
[WebKit-https.git] / Source / JavaScriptCore / Scripts / wkbuiltins / builtins_templates.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2014-2016 Apple Inc. All rights reserved.
4 # Copyright (C) 2015 Canon 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 # Builtins generator templates, which can be filled with string.Template.
28
29
30 class BuiltinsGeneratorTemplates:
31
32     DefaultCopyright = "2016 Apple Inc. All rights reserved."
33     LicenseText = (
34     """Redistribution and use in source and binary forms, with or without
35 modification, are permitted provided that the following conditions
36 are met:
37 1. Redistributions of source code must retain the above copyright
38    notice, this list of conditions and the following disclaimer.
39 2. Redistributions in binary form must reproduce the above copyright
40    notice, this list of conditions and the following disclaimer in the
41    documentation and/or other materials provided with the distribution.
42
43 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
44 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
45 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
47 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
53 THE POSSIBILITY OF SUCH DAMAGE.
54 """)
55
56     DoNotEditWarning = (
57     """// DO NOT EDIT THIS FILE. It is automatically generated from JavaScript files for
58 // builtins by the script: Source/JavaScriptCore/Scripts/generate-js-builtins.py""")
59
60     HeaderIncludeGuard = (
61     """#pragma once""")
62
63     NamespaceTop = (
64     """namespace ${namespace} {""")
65
66     NamespaceBottom = (
67     """} // namespace ${namespace}""")
68
69     CombinedHeaderStaticMacros = (
70     """#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \\
71     JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
72
73 ${macroPrefix}_FOREACH_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
74 #undef DECLARE_BUILTIN_GENERATOR""")
75
76     SeparateHeaderStaticMacros = (
77     """#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \\
78     JSC::FunctionExecutable* codeName##Generator(JSC::VM&);
79
80 ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR)
81 #undef DECLARE_BUILTIN_GENERATOR""")
82
83     CombinedJSCImplementationStaticMacros = (
84     """
85 #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \\
86 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
87 {\\
88     return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
89 }
90 ${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
91 #undef DEFINE_BUILTIN_GENERATOR
92 """)
93
94     SeparateJSCImplementationStaticMacros = (
95     """
96 #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \\
97 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
98 {\\
99     return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \
100 }
101 ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
102 #undef DEFINE_BUILTIN_GENERATOR
103 """)
104
105     CombinedWebCoreImplementationStaticMacros = (
106         """
107 #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \\
108 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
109 {\\
110     JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \\
111     return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \\
112 }
113 ${macroPrefix}_FOREACH_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
114 #undef DEFINE_BUILTIN_GENERATOR
115 """)
116
117     SeparateWebCoreImplementationStaticMacros = (
118         """
119 #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \\
120 JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \\
121 {\\
122     JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \\
123     return clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Executable()->link(vm, clientData->builtinFunctions().${objectNameLC}Builtins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \\
124 }
125 ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR)
126 #undef DEFINE_BUILTIN_GENERATOR
127 """)
128
129     SeparateHeaderWrapperBoilerplate = (
130     """class ${objectName}BuiltinsWrapper : private JSC::WeakHandleOwner {
131 public:
132     explicit ${objectName}BuiltinsWrapper(JSC::VM* vm)
133         : m_vm(*vm)
134         ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES)
135 #define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createFromLiteral(s_##name, length), { }))
136         ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS)
137 #undef INITIALIZE_BUILTIN_SOURCE_MEMBERS
138     {
139     }
140
141 #define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \\
142     JSC::UnlinkedFunctionExecutable* name##Executable(); \\
143     const JSC::SourceCode& name##Source() const { return m_##name##Source; }
144     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES)
145 #undef EXPOSE_BUILTIN_EXECUTABLES
146
147     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
148
149     void exportNames();
150
151 private:
152     JSC::VM& m_vm;
153
154     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES)
155
156 #define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \\
157     JSC::SourceCode m_##name##Source;\\
158     JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable;
159     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS)
160 #undef DECLARE_BUILTIN_SOURCE_MEMBERS
161
162 };
163
164 #define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \\
165 inline JSC::UnlinkedFunctionExecutable* ${objectName}BuiltinsWrapper::name##Executable() \\
166 {\\
167     if (!m_##name##Executable) {\\
168         JSC::Identifier executableName = functionName##PublicName();\\
169         if (overriddenName)\\
170             executableName = JSC::Identifier::fromString(&m_vm, overriddenName);\\
171         m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ConstructAbility), this, &m_##name##Executable);\\
172     }\\
173     return m_##name##Executable.get();\\
174 }
175 ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES)
176 #undef DEFINE_BUILTIN_EXECUTABLES
177
178 inline void ${objectName}BuiltinsWrapper::exportNames()
179 {
180 #define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
181     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME)
182 #undef EXPORT_FUNCTION_NAME
183 }""")
184
185     SeparateHeaderInternalFunctionsBoilerplate = (
186     """class ${objectName}BuiltinFunctions {
187 public:
188     explicit ${objectName}BuiltinFunctions(JSC::VM& vm) : m_vm(vm) { }
189
190     void init(JSC::JSGlobalObject&);
191     void visit(JSC::SlotVisitor&);
192
193 public:
194     JSC::VM& m_vm;
195
196 #define DECLARE_BUILTIN_SOURCE_MEMBERS(functionName) \\
197     JSC::WriteBarrier<JSC::JSFunction> m_##functionName##Function;
198     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_SOURCE_MEMBERS)
199 #undef DECLARE_BUILTIN_SOURCE_MEMBERS
200 };
201
202 inline void ${objectName}BuiltinFunctions::init(JSC::JSGlobalObject& globalObject)
203 {
204 #define EXPORT_FUNCTION(codeName, functionName, overriddenName, length)\\
205     m_##functionName##Function.set(m_vm, &globalObject, JSC::JSFunction::create(m_vm, codeName##Generator(m_vm), &globalObject));
206     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_CODE(EXPORT_FUNCTION)
207 #undef EXPORT_FUNCTION
208 }
209
210 inline void ${objectName}BuiltinFunctions::visit(JSC::SlotVisitor& visitor)
211 {
212 #define VISIT_FUNCTION(name) visitor.append(m_##name##Function);
213     ${macroPrefix}_FOREACH_${objectMacro}_BUILTIN_FUNCTION_NAME(VISIT_FUNCTION)
214 #undef VISIT_FUNCTION
215 }
216 """)