Skip to content

Commit

Permalink
Add FormData constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Nov 24, 2013
1 parent 94df5d1 commit 73e6756
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -945,8 +945,10 @@ def handleNull(templateBody, setToNullVar, extraConditionForNull=""):

# Set up some sensible defaults for these things insofar as we can.
holderType = None
if argIsPointer:
initialValue = None
if argIsPointer or isOptional:
declType = "Option<" + typePtr + ">"
initialValue = "None"
else:
declType = typePtr

Expand Down Expand Up @@ -995,7 +997,7 @@ def handleNull(templateBody, setToNullVar, extraConditionForNull=""):
declType = CGGeneric(declType)
if holderType is not None:
holderType = CGGeneric(holderType)
return (templateBody, declType, holderType, isOptional, None)
return (templateBody, declType, holderType, isOptional, initialValue)

if type.isSpiderMonkeyInterface():
assert not isEnforceRange and not isClamp
Expand Down
2 changes: 1 addition & 1 deletion src/components/script/dom/bindings/codegen/FormData.webidl
Expand Up @@ -7,7 +7,7 @@
* http://xhr.spec.whatwg.org
*/

/*[Constructor(optional HTMLFormElement form)]*/
[Constructor(optional HTMLFormElement form)]
interface FormData {
void append(DOMString name, Blob value, optional DOMString filename);
void append(DOMString name, DOMString value);
Expand Down
16 changes: 12 additions & 4 deletions src/components/script/dom/formdata.rs
Expand Up @@ -2,10 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::{Fallible, Reflectable, Reflector, reflect_dom_object};
use dom::bindings::utils::DOMString;
use dom::bindings::codegen::FormDataBinding;
use dom::blob::Blob;
use dom::node::{AbstractNode, ScriptView};
use dom::window::Window;

use std::hashmap::HashMap;
Expand All @@ -19,19 +20,26 @@ pub struct FormData {
data: HashMap<~str, FormDatum>,
reflector_: Reflector,
window: @mut Window,
form: Option<AbstractNode<ScriptView>>
}

impl FormData {
pub fn new_inherited(window: @mut Window) -> FormData {
pub fn new_inherited(form: Option<AbstractNode<ScriptView>>, window: @mut Window) -> FormData {
FormData {
data: HashMap::new(),
reflector_: Reflector::new(),
window: window,
form: form
}
}

pub fn new(window: @mut Window) -> @mut FormData {
reflect_dom_object(@mut FormData::new_inherited(window), window, FormDataBinding::Wrap)
pub fn new(form: Option<AbstractNode<ScriptView>>, window: @mut Window) -> @mut FormData {
reflect_dom_object(@mut FormData::new_inherited(form, window), window, FormDataBinding::Wrap)
}

pub fn Constructor(window: @mut Window,
form: Option<AbstractNode<ScriptView>>) -> Fallible<@mut FormData> {
Ok(FormData::new(form, window))
}

pub fn Append(&mut self, name: DOMString, value: @mut Blob, filename: Option<DOMString>) {
Expand Down

5 comments on commit 73e6756

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at evilpie@73e6756

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging evilpie/servo/formdata = 73e6756 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evilpie/servo/formdata = 73e6756 merged ok, testing candidate = 4caf2b5

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4caf2b5

Please sign in to comment.