[GTK] Make script dialogs modal to the current web view only
[WebKit-https.git] / Source / JavaScriptCore / Scripts / wkbuiltins / builtins_generate_internals_wrapper_header.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2016 Apple Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 # THE POSSIBILITY OF SUCH DAMAGE.
25
26
27 import logging
28 from string import Template
29
30 from builtins_generator import BuiltinsGenerator, WK_lcfirst, WK_ucfirst
31 from builtins_templates import BuiltinsGeneratorTemplates as Templates
32
33 log = logging.getLogger('global')
34
35
36 class BuiltinsInternalsWrapperHeaderGenerator(BuiltinsGenerator):
37     def __init__(self, model):
38         BuiltinsGenerator.__init__(self, model)
39         self.internals = filter(lambda object: 'internal' in object.annotations, model.objects)
40
41     def output_filename(self):
42         return "%sJSBuiltinInternals.h" % self.model().framework.setting('namespace')
43
44     def generate_output(self):
45         args = {
46             'namespace': self.model().framework.setting('namespace'),
47         }
48
49         sections = []
50         sections.append(self.generate_license())
51         sections.append(Template(Templates.DoNotEditWarning).substitute(args))
52         sections.append(Template(Templates.HeaderIncludeGuard).substitute(args))
53         sections.append(self.generate_secondary_header_includes())
54
55         sections.append(Template(Templates.NamespaceTop).substitute(args))
56         sections.append(self.generate_section_for_object())
57         sections.append(Template(Templates.NamespaceBottom).substitute(args))
58
59         return "\n\n".join(sections)
60
61     def generate_secondary_header_includes(self):
62         header_includes = [
63             (["WebCore"], ("JavaScriptCore", "heap/WeakInlines.h")),
64             (["WebCore"], ("JavaScriptCore", "runtime/VM.h"))
65         ]
66         for object in self.internals:
67             header_includes.append((["WebCore"], ("WebCore", object.object_name + "Builtins.h")))
68
69         return '\n'.join(self.generate_includes_from_entries(header_includes))
70
71     def generate_section_for_object(self):
72         lines = ["class JSDOMGlobalObject;",
73                  "",
74                  "class JSBuiltinInternalFunctions {",
75                  "public:"]
76
77         lines.append("    explicit JSBuiltinInternalFunctions(JSC::VM&);")
78         lines.append(self.generate_methods())
79         lines.append(self.generate_accessors())
80         lines.append("private:")
81         lines.append(self.generate_members())
82         lines.append("};")
83         return '\n'.join(lines)
84
85     def accessor_name(self, object):
86         return WK_lcfirst(object.object_name)
87
88     def member_name(self, object):
89         return "m_" + self.accessor_name(object)
90
91     def member_type(self, object):
92         return WK_ucfirst(object.object_name) + "BuiltinFunctions"
93
94     def generate_methods(self):
95         return """
96     void visit(JSC::SlotVisitor&);
97     void initialize(JSDOMGlobalObject&);
98 """
99
100     def generate_accessors(self):
101         lines = []
102         for object in self.internals:
103             accessor = "    %s& %s() { return %s; }" % (self.member_type(object), self.accessor_name(object), self.member_name(object))
104             lines.append(BuiltinsGenerator.wrap_with_guard(object.annotations.get('conditional'), accessor))
105         lines.append("")
106         return '\n'.join(lines)
107
108     def generate_members(self):
109         lines = ["    JSC::VM& m_vm;"]
110         for object in self.internals:
111             member = "    %s %s;" % (self.member_type(object), self.member_name(object))
112             lines.append(BuiltinsGenerator.wrap_with_guard(object.annotations.get('conditional'), member))
113         return '\n'.join(lines)