diff options
Diffstat (limited to 'src/components/script/dom/bindings/codegen')
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 107 |
1 files changed, 40 insertions, 67 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 0d9c8cbd96e..47c91614d52 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -907,32 +907,12 @@ for (uint32_t i = 0; i < length; ++i) { failureCode) return (template, declType, None, isOptional, None) - # This is an interface that we implement as a concrete class - # or an XPCOM interface. - - argIsPointer = type.nullable() - # Sequences and callbacks have to hold a strong ref to the thing being # passed down. forceOwningType = descriptor.interface.isCallback() or isMember typePtr = descriptor.nativeType - # Compute a few things: - # - declType is the type we want to return as the first element of our - # tuple. - # - holderType is the type we want to return as the third element - # of our tuple. - - # Set up some sensible defaults for these things insofar as we can. - holderType = None - initialValue = None - if argIsPointer or isOptional: - declType = "Option<" + typePtr + ">" - initialValue = "None" - else: - declType = typePtr - templateBody = "" if descriptor.castable: if descriptor.interface.isConsequential(): @@ -945,14 +925,14 @@ for (uint32_t i = 0; i < length; ++i) { "JSVAL_TO_OBJECT(${val})", "${declName}", failureCode, - isOptional or argIsPointer or type.nullable(), + isOptional or type.nullable(), preUnwrapped=preSuccess, postUnwrapped=postSuccess)) else: templateBody += str(FailureFatalCastableObjectUnwrapper( descriptor, "JSVAL_TO_OBJECT(${val})", "${declName}", - isOptional or argIsPointer or type.nullable())) + isOptional or type.nullable())) else: templateBody += ( "match unwrap_value::<" + typePtr + ">(&${val} as *JSVal, " @@ -969,10 +949,11 @@ for (uint32_t i = 0; i < length; ++i) { type, "${declName} = None", failureCode) - declType = CGGeneric(declType) - if holderType is not None: - holderType = CGGeneric(holderType) - return (templateBody, declType, holderType, isOptional, initialValue) + declType = CGGeneric(typePtr) + if type.nullable() or isOptional: + declType = CGWrapper(declType, pre="Option<", post=">") + + return (templateBody, declType, None, isOptional, "None" if isOptional else None) if type.isSpiderMonkeyInterface(): assert not isEnforceRange and not isClamp @@ -1162,10 +1143,18 @@ for (uint32_t i = 0; i < length; ++i) { if isMember: raise TypeError("Can't handle member 'any'; need to sort out " "rooting issues") - templateBody = "${declName} = ${val};" + + declType = CGGeneric("JSVal") + value = CGGeneric("${val}") + if isOptional: + declType = CGWrapper(declType, pre="Option<", post=">") + value = CGWrapper(value, pre="Some(", post=")") + + templateBody = "${declName} = %s;" % value.define() templateBody = handleDefaultNull(templateBody, "${declName} = JSVAL_NULL") - return (templateBody, CGGeneric("JSVal"), None, isOptional, "JSVAL_NULL") + + return (templateBody, declType, None, isOptional, "None" if isOptional else None) if type.isObject(): assert not isEnforceRange and not isClamp @@ -1238,51 +1227,35 @@ for (uint32_t i = 0; i < length; ++i) { if failureCode is None: failureCode = 'return 0' - if type.nullable(): - successVal = "v" - if preSuccess or postSuccess: - successVal = preSuccess + successVal + postSuccess - #XXXjdm support conversionBehavior here - template = ( - "match JSValConvertible::from_jsval(cx, ${val}) {\n" - " Ok(v) => ${declName} = %s,\n" - " Err(_) => %s\n" - "}" % (successVal, failureCode)) - - if defaultValue is not None and isinstance(defaultValue, IDLNullValue): - template = CGWrapper(CGIndenter(CGGeneric(template)), - pre="if ${haveValue} {\n", - post=("\n" - "} else {\n" - " ${declName} = None;\n" - "}")).define() + successVal = "v" + if preSuccess or postSuccess: + successVal = preSuccess + successVal + postSuccess + #XXXjdm support conversionBehavior here + template = ( + "match JSValConvertible::from_jsval(cx, ${val}) {\n" + " Ok(v) => ${declName} = %s,\n" + " Err(_) => %s\n" + "}" % (successVal, failureCode)) + if type.nullable(): declType = CGGeneric("Option<" + typeName + ">") else: - assert(defaultValue is None or - not isinstance(defaultValue, IDLNullValue)) - #XXXjdm conversionBehavior should be used - successVal = "v" - if preSuccess or postSuccess: - successVal = preSuccess + successVal + postSuccess - template = ( - "match JSValConvertible::from_jsval(cx, ${val}) {\n" - " Err(_) => %s,\n" - " Ok(v) => ${declName} = %s\n" - "}" % (failureCode, successVal)) declType = CGGeneric(typeName) - if (defaultValue is not None and - # We already handled IDLNullValue, so just deal with the other ones - not isinstance(defaultValue, IDLNullValue)): - tag = defaultValue.type.tag() - if tag in numericTags: - defaultStr = defaultValue.value + + if defaultValue is not None: + if isinstance(defaultValue, IDLNullValue): + assert type.nullable() + defaultStr = "None" else: - assert(tag == IDLType.Tags.bool) - defaultStr = toStringBool(defaultValue.value) + tag = defaultValue.type.tag() + if tag in numericTags: + defaultStr = defaultValue.value + else: + assert(tag == IDLType.Tags.bool) + defaultStr = toStringBool(defaultValue.value) - if type.nullable(): - defaultStr = "Some(%s)" % defaultStr + if type.nullable(): + defaultStr = "Some(%s)" % defaultStr template = CGWrapper(CGIndenter(CGGeneric(template)), pre="if ${haveValue} {\n", |