From ef0ccd3e1539165935795c12d1480c766f26b3a9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 7 Jun 2014 17:38:35 +0200 Subject: [PATCH] Add support for undefined default values for 'any'. This also updates TestBinding to take into account the automatic default for optional 'any' arguments and dictionary members. --- .../script/dom/bindings/codegen/CodegenRust.py | 14 ++++++++++++-- src/components/script/dom/testbinding.rs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 14d558958dc..40c9e3b87ba 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -518,7 +518,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, if not isinstance(defaultValue, IDLNullValue): raise TypeError("Can't handle non-null default value here") - assert type.nullable() or type.isAny() or type.isDictionary() + assert type.nullable() or type.isDictionary() return nullValue # A helper function for wrapping up the template body for @@ -752,7 +752,17 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, assert not isEnforceRange and not isClamp declType = CGGeneric("JSVal") - return handleOptional("${val}", declType, handleDefaultNull("NullValue()")) + + if defaultValue is None: + default = None + elif isinstance(defaultValue, IDLNullValue): + default = "NullValue()" + elif isinstance(defaultValue, IDLUndefinedValue): + default = "UndefinedValue()" + else: + raise TypeError("Can't handle non-null, non-undefined default value here") + + return handleOptional("${val}", declType, default) if type.isObject(): raise TypeError("Can't handle object arguments yet") diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 852b7443418..984c67ee3e0 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -180,7 +180,7 @@ pub trait TestBindingMethods { fn PassOptionalInterface(&self, _: Option>) {} fn PassOptionalUnion(&self, _: Option) {} fn PassOptionalUnion2(&self, _: Option) {} - fn PassOptionalAny(&self, _: *mut JSContext, _: Option) {} + fn PassOptionalAny(&self, _: *mut JSContext, _: JSVal) {} fn PassOptionalNullableBoolean(&self, _: Option>) {} fn PassOptionalNullableByte(&self, _: Option>) {}