Commit fcc76ba6 authored by jl@opera.com's avatar jl@opera.com

IDL: Improve "argument needs v8::TryCatch" logic slightly

Enumeration types are effectively strings, and should thus be handled the
same, meaning they don't need a v8::TryCatch object.

This changes generated code for a few methods that take at least one
enumeration type argument, and don't otherwise need a v8::TryCatch, by
eliminating the unnecessary v8::TryCatch locals.

Also refactor slightly: pass in the IdlOperation object and check whether
the return type is Promise inside argument_needs_try_catch(), instead
of passing in that fact as an argument. This keeps the logic localized in
argument_needs_try_catch().

R=haraken@chromium.org
BUG=

Review URL: https://codereview.chromium.org/482713002

git-svn-id: svn://svn.chromium.org/blink/trunk@180459 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 0f32f3cf
...@@ -856,7 +856,7 @@ def sort_and_groupby(l, key=None): ...@@ -856,7 +856,7 @@ def sort_and_groupby(l, key=None):
# [Constructor] # [Constructor]
def constructor_context(interface, constructor): def constructor_context(interface, constructor):
arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(argument, return_promise=False) arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(constructor, argument)
for argument in constructor.arguments) for argument in constructor.arguments)
# [RaisesException=Constructor] # [RaisesException=Constructor]
......
...@@ -52,11 +52,12 @@ CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ ...@@ -52,11 +52,12 @@ CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([
]) ])
def argument_needs_try_catch(argument, return_promise): def argument_needs_try_catch(method, argument):
return_promise = method.idl_type and method.idl_type.name == 'Promise'
idl_type = argument.idl_type idl_type = argument.idl_type
base_type = idl_type.base_type base_type = idl_type.base_type
return not ( return not(
# These cases are handled by separate code paths in the # These cases are handled by separate code paths in the
# generate_argument() macro in Source/bindings/templates/methods.cpp. # generate_argument() macro in Source/bindings/templates/methods.cpp.
idl_type.is_callback_interface or idl_type.is_callback_interface or
...@@ -65,7 +66,8 @@ def argument_needs_try_catch(argument, return_promise): ...@@ -65,7 +66,8 @@ def argument_needs_try_catch(argument, return_promise):
# String and enumeration arguments converted using one of the # String and enumeration arguments converted using one of the
# TOSTRING_* macros except for _PROMISE variants in # TOSTRING_* macros except for _PROMISE variants in
# Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch. # Source/bindings/core/v8/V8BindingMacros.h don't use a v8::TryCatch.
(base_type == 'DOMString' and not argument.is_variadic and ((base_type == 'DOMString' or idl_type.is_enum) and
not argument.is_variadic and
not return_promise)) not return_promise))
...@@ -85,7 +87,6 @@ def method_context(interface, method): ...@@ -85,7 +87,6 @@ def method_context(interface, method):
idl_type = method.idl_type idl_type = method.idl_type
is_static = method.is_static is_static = method.is_static
name = method.name name = method.name
return_promise = idl_type.name == 'Promise'
idl_type.add_includes_for_type() idl_type.add_includes_for_type()
this_cpp_value = cpp_value(interface, method, len(arguments)) this_cpp_value = cpp_value(interface, method, len(arguments))
...@@ -126,7 +127,7 @@ def method_context(interface, method): ...@@ -126,7 +127,7 @@ def method_context(interface, method):
is_raises_exception = 'RaisesException' in extended_attributes is_raises_exception = 'RaisesException' in extended_attributes
arguments_need_try_catch = ( arguments_need_try_catch = (
any(argument_needs_try_catch(argument, return_promise) any(argument_needs_try_catch(method, argument)
for argument in arguments)) for argument in arguments))
return { return {
......
...@@ -6652,8 +6652,6 @@ static void voidMethodTestEnumArgMethod(const v8::FunctionCallbackInfo<v8::Value ...@@ -6652,8 +6652,6 @@ static void voidMethodTestEnumArgMethod(const v8::FunctionCallbackInfo<v8::Value
TestObject* impl = V8TestObject::toNative(info.Holder()); TestObject* impl = V8TestObject::toNative(info.Holder());
V8StringResource<> testEnumTypeArg; V8StringResource<> testEnumTypeArg;
{ {
v8::TryCatch block;
V8RethrowTryCatchScope rethrow(block);
TOSTRING_VOID_INTERNAL(testEnumTypeArg, info[0]); TOSTRING_VOID_INTERNAL(testEnumTypeArg, info[0]);
String string = testEnumTypeArg; String string = testEnumTypeArg;
if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) { if (!(string == "" || string == "EnumValue1" || string == "EnumValue2" || string == "EnumValue3")) {
......
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