Commit a3df8462 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Support notation of On{BeforeUnload,Error}EventHandler

The behavior of On{BeforeUnload,Error}EventHandler has already
been supported, but the notation in *.idl files has not yet
been supported.

This patch makes it possible to write them in *.idl files, and
helps the new bindings generator dintinguish error handler types.

Bug: 839389
Change-Id: I1cc52407f634bc6ecfd740cf488413901e75cc5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150352Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759547}
parent 3272243b
...@@ -644,12 +644,14 @@ def setter_expression(interface, attribute, context): ...@@ -644,12 +644,14 @@ def setter_expression(interface, attribute, context):
arguments.append('*impl') arguments.append('*impl')
arguments.extend(extra_arguments) arguments.extend(extra_arguments)
idl_type = attribute.idl_type idl_type = attribute.idl_type
if idl_type.base_type == 'EventHandler': if idl_type.base_type in ('EventHandler', 'OnBeforeUnloadEventHandler',
handler_type = 'kEventHandler' 'OnErrorEventHandler'):
if attribute.name == 'onerror': if idl_type.base_type == 'EventHandler':
handler_type = 'kOnErrorEventHandler' handler_type = 'kEventHandler'
elif attribute.name == 'onbeforeunload': elif idl_type.base_type == 'OnBeforeUnloadEventHandler':
handler_type = 'kOnBeforeUnloadEventHandler' handler_type = 'kOnBeforeUnloadEventHandler'
elif idl_type.base_type == 'OnErrorEventHandler':
handler_type = 'kOnErrorEventHandler'
arguments.append('JSEventHandler::CreateOrNull(' + 'v8_value, ' + arguments.append('JSEventHandler::CreateOrNull(' + 'v8_value, ' +
'JSEventHandler::HandlerType::' + handler_type + ')') 'JSEventHandler::HandlerType::' + handler_type + ')')
else: else:
......
...@@ -59,6 +59,8 @@ from v8_utilities import binding_header_filename, extended_attribute_value_conta ...@@ -59,6 +59,8 @@ from v8_utilities import binding_header_filename, extended_attribute_value_conta
NON_WRAPPER_TYPES = frozenset([ NON_WRAPPER_TYPES = frozenset([
'EventHandler', 'EventHandler',
'NodeFilter', 'NodeFilter',
'OnBeforeUnloadEventHandler',
'OnErrorEventHandler',
]) ])
TYPED_ARRAY_TYPES = frozenset([ TYPED_ARRAY_TYPES = frozenset([
'Float32Array', 'Float32Array',
...@@ -125,6 +127,8 @@ CPP_INTEGER_CONVERSION_RULES = { ...@@ -125,6 +127,8 @@ CPP_INTEGER_CONVERSION_RULES = {
} }
CPP_SPECIAL_CONVERSION_RULES = { CPP_SPECIAL_CONVERSION_RULES = {
'EventHandler': 'EventListener*', 'EventHandler': 'EventListener*',
'OnBeforeUnloadEventHandler': 'EventListener*',
'OnErrorEventHandler': 'EventListener*',
'Promise': 'ScriptPromise', 'Promise': 'ScriptPromise',
'ScriptValue': 'ScriptValue', 'ScriptValue': 'ScriptValue',
# FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345529 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345529
...@@ -1028,6 +1032,10 @@ V8_SET_RETURN_VALUE = { ...@@ -1028,6 +1032,10 @@ V8_SET_RETURN_VALUE = {
'V8SetReturnValue(info, {cpp_value})', 'V8SetReturnValue(info, {cpp_value})',
'NodeFilter': 'NodeFilter':
'V8SetReturnValue(info, {cpp_value})', 'V8SetReturnValue(info, {cpp_value})',
'OnBeforeUnloadEventHandler':
'V8SetReturnValue(info, {cpp_value})',
'OnErrorEventHandler':
'V8SetReturnValue(info, {cpp_value})',
'ScriptValue': 'ScriptValue':
'V8SetReturnValue(info, {cpp_value})', 'V8SetReturnValue(info, {cpp_value})',
# Records. # Records.
...@@ -1101,7 +1109,9 @@ def v8_set_return_value(idl_type, ...@@ -1101,7 +1109,9 @@ def v8_set_return_value(idl_type,
idl_type, cpp_value, extended_attributes) idl_type, cpp_value, extended_attributes)
this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
# SetReturn-specific overrides # SetReturn-specific overrides
if this_v8_conversion_type in ('EventHandler', 'NodeFilter', 'ScriptValue', if this_v8_conversion_type in ('EventHandler', 'NodeFilter',
'OnBeforeUnloadEventHandler',
'OnErrorEventHandler', 'ScriptValue',
'sequence', 'FrozenArray'): 'sequence', 'FrozenArray'):
# Convert value to V8 and then use general V8SetReturnValue # Convert value to V8 and then use general V8SetReturnValue
cpp_value = idl_type.cpp_value_to_v8_value( cpp_value = idl_type.cpp_value_to_v8_value(
...@@ -1161,6 +1171,10 @@ CPP_VALUE_TO_V8_VALUE = { ...@@ -1161,6 +1171,10 @@ CPP_VALUE_TO_V8_VALUE = {
'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})', 'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})',
'NodeFilter': 'NodeFilter':
'ToV8({cpp_value}, {creation_context}, {isolate})', 'ToV8({cpp_value}, {creation_context}, {isolate})',
'OnBeforeUnloadEventHandler':
'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})',
'OnErrorEventHandler':
'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})',
'Record': 'Record':
'ToV8({cpp_value}, {creation_context}, {isolate})', 'ToV8({cpp_value}, {creation_context}, {isolate})',
'ScriptValue': 'ScriptValue':
......
...@@ -55,8 +55,7 @@ ...@@ -55,8 +55,7 @@
attribute EventHandler ondurationchange; attribute EventHandler ondurationchange;
attribute EventHandler onemptied; attribute EventHandler onemptied;
attribute EventHandler onended; attribute EventHandler onended;
// FIXME: onerror should be an OnErrorEventHandler. attribute OnErrorEventHandler onerror;
attribute EventHandler onerror;
attribute EventHandler onfocus; attribute EventHandler onfocus;
attribute EventHandler onformdata; attribute EventHandler onformdata;
attribute EventHandler oninput; attribute EventHandler oninput;
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
] interface mixin WindowEventHandlers { ] interface mixin WindowEventHandlers {
attribute EventHandler onafterprint; attribute EventHandler onafterprint;
attribute EventHandler onbeforeprint; attribute EventHandler onbeforeprint;
// FIXME: onbeforeunload should be an OnBeforeUnloadEventHandler. attribute OnBeforeUnloadEventHandler onbeforeunload;
attribute EventHandler onbeforeunload;
attribute EventHandler onhashchange; attribute EventHandler onhashchange;
attribute EventHandler onlanguagechange; attribute EventHandler onlanguagechange;
attribute EventHandler onmessage; attribute EventHandler onmessage;
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
readonly attribute WorkerGlobalScope self; readonly attribute WorkerGlobalScope self;
readonly attribute WorkerLocation location; readonly attribute WorkerLocation location;
// TODO(foolip): onerror should be an OnErrorEventHandler. attribute OnErrorEventHandler onerror;
attribute EventHandler onerror;
attribute EventHandler onlanguagechange; attribute EventHandler onlanguagechange;
[RuntimeEnabled=TimeZoneChangeEvent] attribute EventHandler ontimezonechange; [RuntimeEnabled=TimeZoneChangeEvent] attribute EventHandler ontimezonechange;
// attribute EventHandler onoffline; // attribute EventHandler onoffline;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment