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):
arguments.append('*impl')
arguments.extend(extra_arguments)
idl_type = attribute.idl_type
if idl_type.base_type == 'EventHandler':
handler_type = 'kEventHandler'
if attribute.name == 'onerror':
handler_type = 'kOnErrorEventHandler'
elif attribute.name == 'onbeforeunload':
if idl_type.base_type in ('EventHandler', 'OnBeforeUnloadEventHandler',
'OnErrorEventHandler'):
if idl_type.base_type == 'EventHandler':
handler_type = 'kEventHandler'
elif idl_type.base_type == 'OnBeforeUnloadEventHandler':
handler_type = 'kOnBeforeUnloadEventHandler'
elif idl_type.base_type == 'OnErrorEventHandler':
handler_type = 'kOnErrorEventHandler'
arguments.append('JSEventHandler::CreateOrNull(' + 'v8_value, ' +
'JSEventHandler::HandlerType::' + handler_type + ')')
else:
......
......@@ -59,6 +59,8 @@ from v8_utilities import binding_header_filename, extended_attribute_value_conta
NON_WRAPPER_TYPES = frozenset([
'EventHandler',
'NodeFilter',
'OnBeforeUnloadEventHandler',
'OnErrorEventHandler',
])
TYPED_ARRAY_TYPES = frozenset([
'Float32Array',
......@@ -125,6 +127,8 @@ CPP_INTEGER_CONVERSION_RULES = {
}
CPP_SPECIAL_CONVERSION_RULES = {
'EventHandler': 'EventListener*',
'OnBeforeUnloadEventHandler': 'EventListener*',
'OnErrorEventHandler': 'EventListener*',
'Promise': 'ScriptPromise',
'ScriptValue': 'ScriptValue',
# FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345529
......@@ -1028,6 +1032,10 @@ V8_SET_RETURN_VALUE = {
'V8SetReturnValue(info, {cpp_value})',
'NodeFilter':
'V8SetReturnValue(info, {cpp_value})',
'OnBeforeUnloadEventHandler':
'V8SetReturnValue(info, {cpp_value})',
'OnErrorEventHandler':
'V8SetReturnValue(info, {cpp_value})',
'ScriptValue':
'V8SetReturnValue(info, {cpp_value})',
# Records.
......@@ -1101,7 +1109,9 @@ def v8_set_return_value(idl_type,
idl_type, cpp_value, extended_attributes)
this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
# 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'):
# Convert value to V8 and then use general V8SetReturnValue
cpp_value = idl_type.cpp_value_to_v8_value(
......@@ -1161,6 +1171,10 @@ CPP_VALUE_TO_V8_VALUE = {
'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})',
'NodeFilter':
'ToV8({cpp_value}, {creation_context}, {isolate})',
'OnBeforeUnloadEventHandler':
'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})',
'OnErrorEventHandler':
'JSEventHandler::AsV8Value({isolate}, impl, {cpp_value})',
'Record':
'ToV8({cpp_value}, {creation_context}, {isolate})',
'ScriptValue':
......
......@@ -55,8 +55,7 @@
attribute EventHandler ondurationchange;
attribute EventHandler onemptied;
attribute EventHandler onended;
// FIXME: onerror should be an OnErrorEventHandler.
attribute EventHandler onerror;
attribute OnErrorEventHandler onerror;
attribute EventHandler onfocus;
attribute EventHandler onformdata;
attribute EventHandler oninput;
......
......@@ -34,8 +34,7 @@
] interface mixin WindowEventHandlers {
attribute EventHandler onafterprint;
attribute EventHandler onbeforeprint;
// FIXME: onbeforeunload should be an OnBeforeUnloadEventHandler.
attribute EventHandler onbeforeunload;
attribute OnBeforeUnloadEventHandler onbeforeunload;
attribute EventHandler onhashchange;
attribute EventHandler onlanguagechange;
attribute EventHandler onmessage;
......
......@@ -34,8 +34,7 @@
readonly attribute WorkerGlobalScope self;
readonly attribute WorkerLocation location;
// TODO(foolip): onerror should be an OnErrorEventHandler.
attribute EventHandler onerror;
attribute OnErrorEventHandler onerror;
attribute EventHandler onlanguagechange;
[RuntimeEnabled=TimeZoneChangeEvent] attribute EventHandler ontimezonechange;
// 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