Skip to content

Commit

Permalink
Merge pull request #142 from Hixie/shadow
Browse files Browse the repository at this point in the history
Remove shadow trees and custom elements from sky/engine/.
  • Loading branch information
Hixie committed Jul 20, 2015
2 parents 5c6d38d + 6bcc09d commit f8e2c25
Show file tree
Hide file tree
Showing 112 changed files with 205 additions and 4,388 deletions.
6 changes: 0 additions & 6 deletions sky/engine/bindings/IDLExtendedAttributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ CallWith=ScriptState|ScriptArguments|ActiveWindow|FirstWindow|ThisValue
Constructor
Custom=|Getter|Setter|VisitDOMWrapper|Wrap|PropertyGetter|PropertyEnumerator|PropertyQuery
CustomConstructor
CustomElementCallbacks
Default=Undefined
DependentLifetime
DoNotCheckConstants
Expand All @@ -64,11 +63,6 @@ PartialInterfaceImplementedAs=*
PrivateDart
PutForwards=*
RaisesException=|Getter|Setter|Constructor
Reflect=|*
ReflectEmpty=*
ReflectInvalid=*
ReflectMissing=*
ReflectOnly=*
Replaceable
SetterCallWith=ExecutionContext|ScriptArguments|ActiveWindow|FirstWindow
SetWrapperReferenceFrom=*
Expand Down
25 changes: 7 additions & 18 deletions sky/engine/bindings/scripts/dart_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,19 @@ def getter_context(interface, attribute, context):
extended_attributes = attribute.extended_attributes

cpp_value = getter_expression(interface, attribute, context)
# Normally we can inline the function call into the return statement to
# avoid the overhead of using a Ref<> temporary, but for some cases
# (nullable types, EventHandler, [CachedAttribute], or if there are
# exceptions), we need to use a local variable.
# Normally we can inline the function call into the return
# statement to avoid the overhead of using a Ref<> temporary, but
# for some cases (nullable types, [CachedAttribute], or if there
# are exceptions), we need to use a local variable.
# FIXME: check if compilers are smart enough to inline this, and if so,
# always use a local variable (for readability and CG simplicity).
release = False
if (idl_type.is_nullable or
base_idl_type == 'EventHandler' or
'CachedAttribute' in extended_attributes or
'ReflectOnly' in extended_attributes or
context['is_getter_raises_exception']):
context['cpp_value_original'] = cpp_value
cpp_value = 'result'
# EventHandler has special handling
if base_idl_type != 'EventHandler' and idl_type.is_interface_type:
if idl_type.is_interface_type:
release = True

dart_set_return_value = \
Expand Down Expand Up @@ -229,16 +226,8 @@ def setter_expression(interface, attribute, context):
not attribute.is_static):
arguments.append('*receiver')
idl_type = attribute.idl_type
if idl_type.base_type == 'EventHandler':
getter_name = DartUtilities.scoped_name(interface, attribute, DartUtilities.cpp_name(attribute))
context['event_handler_getter_expression'] = '%s(%s)' % (
getter_name, ', '.join(arguments))
# FIXME(vsm): Do we need to support this? If so, what's our analogue of
# V8EventListenerList?
arguments.append('nullptr')
else:
attribute_name = dart_types.check_reserved_name(attribute.name)
arguments.append(attribute_name)
attribute_name = dart_types.check_reserved_name(attribute.name)
arguments.append(attribute_name)
if context['is_setter_raises_exception']:
arguments.append('es')

Expand Down
13 changes: 2 additions & 11 deletions sky/engine/bindings/scripts/dart_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,6 @@ def preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes):
# FIXME(vsm): V8 maps 'long long' and 'unsigned long long' to double
# as they are not representable in ECMAScript. Should we do the same?

# HTML5 says that unsigned reflected attributes should be in the range
# [0, 2^31). When a value isn't in this range, a default value (or 0)
# should be returned instead.
extended_attributes = extended_attributes or {}
if ('Reflect' in extended_attributes and
idl_type.base_type in ['unsigned long', 'unsigned short']):
cpp_value = cpp_value.replace('getUnsignedIntegralAttribute',
'getIntegralAttribute')
cpp_value = 'std::max(0, %s)' % cpp_value
return idl_type, cpp_value


Expand Down Expand Up @@ -645,8 +636,8 @@ def dart_conversion_type(idl_type, extended_attributes):
# TODO(terry): Remove ForMainWorld stuff.
'DOMWrapperForMainWorld': DART_FIX_ME,
# FIXME(vsm): V8 has a fast path. Do we?
'DOMWrapperFast': 'DartConverter<{implemented_as}*>::SetReturnValue(args, WTF::getPtr({cpp_value}), {auto_scope})',
'DOMWrapperDefault': 'DartConverter<{implemented_as}*>::SetReturnValue(args, WTF::getPtr({cpp_value}), {auto_scope})',
'DOMWrapperFast': '/*DOMWrapperFast*/ DartConverter<{implemented_as}*>::SetReturnValue(args, WTF::getPtr({cpp_value}), {auto_scope})',
'DOMWrapperDefault': '/*DOMWrapperDefault*/ DartConverter<{implemented_as}*>::SetReturnValue(args, WTF::getPtr({cpp_value}), {auto_scope})',
# Typed arrays don't have special Dart* classes for Dart.
'ArrayBuffer': 'Dart_SetReturnValue(args, DartUtilities::arrayBufferToDart({cpp_value}))',
'TypedList': 'Dart_SetReturnValue(args, DartUtilities::arrayBufferViewToDart({cpp_value}))',
Expand Down
9 changes: 2 additions & 7 deletions sky/engine/bindings/scripts/templates/attributes_cpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ ExceptionState es;
{% endif %}
{% if attribute.cached_attribute_validation_method or
attribute.is_getter_raises_exception or
attribute.is_nullable or
attribute.idl_type == 'EventHandler' %}
attribute.is_nullable %}
{{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_original}};
{% endif %}
{% if attribute.is_nullable %}
Expand All @@ -74,17 +73,14 @@ DART_UNIMPLEMENTED();
{% macro attribute_setter(cpp_class, attribute) %}
static void {{static_attribute_name(attribute, 'Setter')}}(Dart_NativeArguments args)
{
{% if attribute.idl_type == "EventHandler" or not attribute.cpp_setter %}
{% if not attribute.cpp_setter %}
{# TODO(terry): Need to fix properly. #}
// FIXME: proper implementation.
DART_UNIMPLEMENTED();
{% else %}
Dart_Handle exception = nullptr;
{
{{cpp_class}}* receiver = GetReceiver<{{cpp_class}}>(args);
{% if attribute.is_custom_element_callbacks %}
CustomElementCallbackScope deliveryScope;
{% endif %}
{% set attribute_name = attribute.name if not attribute.put_forwards else 'value' %}

{{attribute.local_cpp_type}} {{attribute.setter_lvalue}} = {{attribute.dart_value_to_local_cpp_value}};
Expand Down Expand Up @@ -151,7 +147,6 @@ if (result.isNull()) {
result = "{{reflect_empty}}";
{% else %}
if (result.isEmpty()) {
{# FIXME: should use [ReflectEmpty] instead; need to change IDL files #}
{% if reflect_missing %}
result = "{{reflect_missing}}";
{% else %}
Expand Down
3 changes: 0 additions & 3 deletions sky/engine/bindings/scripts/templates/interface_h.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ namespace {{dart_class}}Internal {
{% if has_event_constructor %}
void initialize{{interface_name}}ForDart({{interface_name}}Init&, const String&, const HashMap<String, Dart_Handle>&, Dart_Handle&);
{% endif %}
{% for method in methods if method.is_custom_element_callbacks and not method.suppressed %}
void {{method.name}}_{{method.number_of_arguments}}(Dart_NativeArguments);
{% endfor %}
{% for method in methods if method.is_custom or method.custom_dart_new %}
void {{static_method_name(method.name)}}(Dart_NativeArguments args);
{% if method.overload_index == 1 %}
Expand Down
3 changes: 0 additions & 3 deletions sky/engine/bindings/scripts/templates/methods_cpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ static void {{static_method_name(method.name, overload_index)}}(Dart_NativeArgum
{% if not method.is_static %}
{{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = GetReceiver<{{cpp_class}}>(args);
{% endif %}
{% if method.is_custom_element_callbacks %}
CustomElementCallbackScope deliveryScope;
{% endif %}
{% if arguments_count > 0 or
method.has_exception_state or
method.is_call_with_script_state or
Expand Down
32 changes: 4 additions & 28 deletions sky/engine/bindings/scripts/v8_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,12 @@ def attribute_context(interface, attribute):

idl_type.add_includes_for_type()

# [CustomElementCallbacks], [Reflect]
is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
is_reflect = 'Reflect' in extended_attributes
if is_custom_element_callbacks or is_reflect:
includes.add('sky/engine/core/dom/custom/custom_element_callback_scope.h')
# [TypeChecking]
has_type_checking_unrestricted = (
(has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or
has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')) and
idl_type.name in ('Float', 'Double'))

if (base_idl_type == 'EventHandler' and
interface.name in ['Window'] and
attribute.name == 'onerror'):
includes.add('bindings/core/v8/V8ErrorHandler.h')

context = {
'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True),
'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'),
Expand All @@ -82,7 +72,6 @@ def attribute_context(interface, attribute):
'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType
'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'),
'is_call_with_script_state': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'),
'is_custom_element_callbacks': is_custom_element_callbacks,
'is_getter_raises_exception': # [RaisesException]
'RaisesException' in extended_attributes and
extended_attributes['RaisesException'] in (None, 'Getter'),
Expand All @@ -94,16 +83,11 @@ def attribute_context(interface, attribute):
'is_partial_interface_member':
'PartialInterfaceImplementedAs' in extended_attributes,
'is_read_only': attribute.is_read_only,
'is_reflect': is_reflect,
'is_replaceable': 'Replaceable' in attribute.extended_attributes,
'is_static': attribute.is_static,
'is_url': 'URL' in extended_attributes,
'name': attribute.name,
'put_forwards': 'PutForwards' in extended_attributes,
'reflect_empty': extended_attributes.get('ReflectEmpty'),
'reflect_invalid': extended_attributes.get('ReflectInvalid', ''),
'reflect_missing': extended_attributes.get('ReflectMissing'),
'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly'),
'setter_callback': setter_callback_name(interface, attribute),
}

Expand Down Expand Up @@ -161,10 +145,9 @@ def getter_expression(interface, attribute, context):
def getter_base_name(interface, attribute, arguments):
extended_attributes = attribute.extended_attributes

if 'Reflect' not in extended_attributes:
return uncapitalize(cpp_name(attribute))
return uncapitalize(cpp_name(attribute))

content_attribute_name = extended_attributes['Reflect'] or attribute.name.lower()
content_attribute_name = attribute.name.lower()
if content_attribute_name in ['class', 'id']:
# Special-case for performance optimization.
return 'get%sAttribute' % content_attribute_name.capitalize()
Expand Down Expand Up @@ -254,18 +237,11 @@ def setter_context(interface, attribute, context):


def setter_base_name(interface, attribute, arguments):
if 'Reflect' not in attribute.extended_attributes:
return 'set%s' % capitalize(cpp_name(attribute))
arguments.append(scoped_content_attribute_name(interface, attribute))

base_idl_type = attribute.idl_type.base_type
if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES:
return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type]
return 'setAttribute'
return 'set%s' % capitalize(cpp_name(attribute))


def scoped_content_attribute_name(interface, attribute):
content_attribute_name = attribute.extended_attributes['Reflect'] or attribute.name.lower()
content_attribute_name = attribute.name.lower()
namespace = 'HTMLNames'
includes.add('gen/sky/core/%s.h' % namespace)
return '%s::%sAttr' % (namespace, content_attribute_name)
Expand Down
4 changes: 1 addition & 3 deletions sky/engine/bindings/scripts/v8_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def interface_context(interface):
return context


# [DeprecateAs], [Reflect]
# [DeprecateAs]
def constant_context(constant):
# (Blink-only) string literals are unquoted in tokenizer, must be re-quoted
# in C++.
Expand All @@ -296,8 +296,6 @@ def constant_context(constant):
'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'),
'idl_type': constant.idl_type.name,
'name': constant.name,
# FIXME: use 'reflected_name' as correct 'name'
'reflected_name': extended_attributes.get('Reflect', constant.name),
'value': value,
}

Expand Down
4 changes: 0 additions & 4 deletions sky/engine/bindings/scripts/v8_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def function_template():
is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
if is_call_with_script_state:
includes.add('bindings/core/v8/ScriptState.h')
is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
if is_custom_element_callbacks:
includes.add('sky/engine/core/dom/custom/custom_element_callback_scope.h')

is_raises_exception = 'RaisesException' in extended_attributes

Expand Down Expand Up @@ -135,7 +132,6 @@ def function_template():
'is_call_with_script_arguments': is_call_with_script_arguments,
'is_call_with_script_state': is_call_with_script_state,
'is_custom': 'Custom' in extended_attributes,
'is_custom_element_callbacks': is_custom_element_callbacks,
'is_explicit_nullable': idl_type.is_explicit_nullable,
'is_partial_interface_member':
'PartialInterfaceImplementedAs' in extended_attributes,
Expand Down
9 changes: 0 additions & 9 deletions sky/engine/bindings/scripts/v8_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,6 @@ def preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes):
if is_nullable:
idl_type = IdlNullableType(idl_type)
cpp_value = 'static_cast<double>(%s)' % cpp_value
# HTML5 says that unsigned reflected attributes should be in the range
# [0, 2^31). When a value isn't in this range, a default value (or 0)
# should be returned instead.
extended_attributes = extended_attributes or {}
if ('Reflect' in extended_attributes and
idl_type.base_type in ['unsigned long', 'unsigned short']):
cpp_value = cpp_value.replace('getUnsignedIntegralAttribute',
'getIntegralAttribute')
cpp_value = 'std::max(0, static_cast<int>(%s))' % cpp_value
return idl_type, cpp_value


Expand Down
86 changes: 1 addition & 85 deletions sky/engine/build/scripts/make_element_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,92 +36,8 @@

from make_qualified_names import MakeQualifiedNamesWriter


class MakeElementFactoryWriter(MakeQualifiedNamesWriter):
defaults = dict(MakeQualifiedNamesWriter.default_parameters, **{
'JSInterfaceName': None,
'Conditional': None,
'constructorNeedsCreatedByParser': None,
'interfaceName': None,
'noConstructor': None,
'noTypeHelpers': None,
'runtimeEnabled': None,
})
default_parameters = dict(MakeQualifiedNamesWriter.default_parameters, **{
'fallbackInterfaceName': '',
'fallbackJSInterfaceName': '',
})
filters = MakeQualifiedNamesWriter.filters

def __init__(self, in_file_paths):
super(MakeElementFactoryWriter, self).__init__(in_file_paths)

# FIXME: When we start using these element factories, we'll want to
# remove the "new" prefix and also have our base class generate
# *Names.h and *Names.cpp.
self._outputs.update({
(self.namespace + 'ElementFactory.h'): self.generate_factory_header,
(self.namespace + 'ElementFactory.cpp'): self.generate_factory_implementation,
('V8' + self.namespace + 'ElementWrapperFactory.h'): self.generate_wrapper_factory_header,
('V8' + self.namespace + 'ElementWrapperFactory.cpp'): self.generate_wrapper_factory_implementation,
})

fallback_interface = self.tags_in_file.parameters['fallbackInterfaceName'].strip('"')
fallback_js_interface = self.tags_in_file.parameters['fallbackJSInterfaceName'].strip('"') or fallback_interface

interface_counts = defaultdict(int)
tags = self._template_context['tags']
for tag in tags:
tag['has_js_interface'] = self._has_js_interface(tag)
tag['js_interface'] = self._js_interface(tag)
tag['interface'] = self._interface(tag)
interface_counts[tag['interface']] += 1

for tag in tags:
tag['multipleTagNames'] = (interface_counts[tag['interface']] > 1 or tag['interface'] == fallback_interface)

self._template_context.update({
'fallback_interface': fallback_interface,
'fallback_js_interface': fallback_js_interface,
})

@template_expander.use_jinja('ElementFactory.h.tmpl', filters=filters)
def generate_factory_header(self):
return self._template_context

@template_expander.use_jinja('ElementFactory.cpp.tmpl', filters=filters)
def generate_factory_implementation(self):
return self._template_context

@template_expander.use_jinja('ElementWrapperFactory.h.tmpl', filters=filters)
def generate_wrapper_factory_header(self):
return self._template_context

@template_expander.use_jinja('ElementWrapperFactory.cpp.tmpl', filters=filters)
def generate_wrapper_factory_implementation(self):
return self._template_context

def _interface(self, tag):
if tag['interfaceName']:
return tag['interfaceName']
name = name_utilities.upper_first(tag['name'])
# FIXME: We shouldn't hard-code HTML here.
if name == 'HTML':
name = 'Html'
dash = name.find('-')
while dash != -1:
name = name[:dash] + name[dash + 1].upper() + name[dash + 2:]
dash = name.find('-')
return '%s%sElement' % (self.namespace, name)

def _js_interface(self, tag):
if tag['JSInterfaceName']:
return tag['JSInterfaceName']
return self._interface(tag)

def _has_js_interface(self, tag):
return not tag['noConstructor'] and self._js_interface(tag) != ('%sElement' % self.namespace)

pass

if __name__ == "__main__":
in_generator.Maker(MakeElementFactoryWriter).main(sys.argv)
Loading

0 comments on commit f8e2c25

Please sign in to comment.