diff options
author | Keegan McAllister <kmcallister@mozilla.com> | 2013-09-18 15:23:03 -0700 |
---|---|---|
committer | Keegan McAllister <kmcallister@mozilla.com> | 2013-09-18 18:07:37 -0700 |
commit | 73c1a12f3014289002bdc637b7f3c3fc6bf0fb0d (patch) | |
tree | d165111723538e4e7550647e6b97262829621368 /src/components/script/dom/bindings/codegen/CodegenRust.py | |
parent | 4b0680a1362c06b502bd93f056851d01430c3ac0 (diff) | |
download | servo-73c1a12f3014289002bdc637b7f3c3fc6bf0fb0d.tar.gz servo-73c1a12f3014289002bdc637b7f3c3fc6bf0fb0d.zip |
bindings: Return errors in Result rather than setting an out parameter
Fixes #909.
Diffstat (limited to 'src/components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r-- | src/components/script/dom/bindings/codegen/CodegenRust.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index bbd5b9b8ee6..561466f00bf 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -2925,8 +2925,6 @@ class CGCallGenerator(CGThing): # Return values that go in outparams go here if resultOutParam: args.append(CGGeneric("result")) - if isFallible: - args.append(CGGeneric("&mut rv")) needsCx = (typeNeedsCx(returnType, True) or any(typeNeedsCx(a.type) for (a, _) in arguments) or @@ -2944,21 +2942,29 @@ class CGCallGenerator(CGThing): else: call = CGWrapper(call, pre="(*%s)." % object) call = CGList([call, CGWrapper(args, pre="(", post=");")]) - if result is not None: - if declareResult: - result = CGWrapper(result, pre="let mut result: ", post=";") - self.cgRoot.prepend(result) - if not resultOutParam: - call = CGWrapper(call, pre="result = ") + + if isFallible: + self.cgRoot.prepend(CGWrapper(result if result is not None else CGGeneric("()"), + pre="let mut result_fallible: Result<", post=",Error>;")) + + if result is not None and declareResult: + result = CGWrapper(result, pre="let mut result: ", post=";") + self.cgRoot.prepend(result) + + if isFallible: + call = CGWrapper(call, pre="result_fallible = ") + elif result is not None and not resultOutParam: + call = CGWrapper(call, pre="result = ") call = CGWrapper(call) self.cgRoot.append(call) if isFallible: - self.cgRoot.prepend(CGGeneric("let mut rv: ErrorResult = Ok(());")) - self.cgRoot.append(CGGeneric("if (rv.is_err()) {")) + self.cgRoot.append(CGGeneric("if (result_fallible.is_err()) {")) self.cgRoot.append(CGIndenter(errorReport)) self.cgRoot.append(CGGeneric("}")) + if result is not None and not resultOutParam: + self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();")) def define(self): return self.cgRoot.define() |