aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2013-08-28 19:41:08 -0400
committerJosh Matthews <josh@joshmatthews.net>2013-08-28 19:41:08 -0400
commit65c993e7e6c7e744a08fcedd63a64d0b43505c1d (patch)
tree73ea1f1863437448145fe7518f2fc8ad86584df2 /src
parente26a541eb2bc772c68e2a2adae2d7622823831fd (diff)
downloadservo-65c993e7e6c7e744a08fcedd63a64d0b43505c1d.tar.gz
servo-65c993e7e6c7e744a08fcedd63a64d0b43505c1d.zip
Generate bindings for HTMLSelectElement.
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/bindings/codegen/Bindings.conf1
-rw-r--r--src/components/script/dom/bindings/codegen/CodegenRust.py44
-rw-r--r--src/components/script/dom/bindings/codegen/HTMLSelectElement.webidl57
-rw-r--r--src/components/script/dom/bindings/element.rs2
-rw-r--r--src/components/script/dom/bindings/node.rs1
-rw-r--r--src/components/script/dom/bindings/proxyhandler.rs9
-rw-r--r--src/components/script/dom/element.rs1
-rw-r--r--src/components/script/dom/htmlselectelement.rs134
-rw-r--r--src/components/script/script.rc1
9 files changed, 228 insertions, 22 deletions
diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf
index 2e0debceb71..20fbbac8ed9 100644
--- a/src/components/script/dom/bindings/codegen/Bindings.conf
+++ b/src/components/script/dom/bindings/codegen/Bindings.conf
@@ -597,6 +597,7 @@ addHTMLElement('HTMLParamElement')
addHTMLElement('HTMLProgressElement')
addHTMLElement('HTMLQuoteElement')
addHTMLElement('HTMLScriptElement')
+addHTMLElement('HTMLSelectElement')
addHTMLElement('HTMLSourceElement')
addHTMLElement('HTMLSpanElement')
addHTMLElement('HTMLStyleElement')
diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py
index e524f927e47..6584990d042 100644
--- a/src/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/src/components/script/dom/bindings/codegen/CodegenRust.py
@@ -92,7 +92,7 @@ class CastableObjectUnwrapper():
codeOnFailure is the code to run if unwrapping fails.
"""
- def __init__(self, descriptor, source, target, codeOnFailure):
+ def __init__(self, descriptor, source, target, codeOnFailure, isOptional=False):
assert descriptor.castable
self.substitution = { "type" : descriptor.nativeType,
@@ -101,7 +101,8 @@ class CastableObjectUnwrapper():
"protoID" : "PrototypeList::id::" + descriptor.name + " as uint",
"source" : source,
"target" : target,
- "codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define() }
+ "codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define(),
+ "unwrapped_val" : "Some(val)" if isOptional else "val" }
if descriptor.hasXPConnectImpls:
# We don't use xpc_qsUnwrapThis because it will always throw on
# unwrap failure, whereas we want to control whether we throw or
@@ -123,7 +124,7 @@ class CastableObjectUnwrapper():
def __str__(self):
return string.Template(
"""match unwrap_object(${source}, ${prototype}, ${depth}) {
- Ok(val) => ${target} = val,
+ Ok(val) => ${target} = ${unwrapped_val},
Err(()) => {
${codeOnFailure}
}
@@ -141,10 +142,11 @@ class FailureFatalCastableObjectUnwrapper(CastableObjectUnwrapper):
"""
As CastableObjectUnwrapper, but defaulting to throwing if unwrapping fails
"""
- def __init__(self, descriptor, source, target):
+ def __init__(self, descriptor, source, target, isOptional):
CastableObjectUnwrapper.__init__(self, descriptor, source, target,
"return 0; //XXXjdm return Throw<%s>(cx, rv);" %
- toStringBool(not descriptor.workers))
+ toStringBool(not descriptor.workers),
+ isOptional)
class CGThing():
"""
@@ -229,9 +231,10 @@ class CGMethodCall(CGThing):
argCountCases.append(
CGCase(str(argCount), None, True))
else:
- pass
+ sigIndex = signatures.index(signature)
argCountCases.append(
- CGCase(str(argCount), getPerSignatureCall(signature)))
+ CGCase(str(argCount), getPerSignatureCall(signature,
+ signatureIndex=sigIndex)))
continue
distinguishingIndex = method.distinguishingIndexForArgCount(argCount)
@@ -302,7 +305,7 @@ class CGMethodCall(CGThing):
# above.
caseBody.append(CGGeneric("if JSVAL_IS_OBJECT(%s) {" %
(distinguishingArg)))
- for sig in interfacesSigs:
+ for idx, sig in enumerate(interfacesSigs):
caseBody.append(CGIndenter(CGGeneric("loop {")));
type = sig[1][distinguishingIndex].type
@@ -326,7 +329,7 @@ class CGMethodCall(CGThing):
# distinguishingIndex + 1, since we already converted
# distinguishingIndex.
caseBody.append(CGIndenter(
- getPerSignatureCall(sig, distinguishingIndex + 1), 4))
+ getPerSignatureCall(sig, distinguishingIndex + 1, idx), 4))
caseBody.append(CGIndenter(CGGeneric("}")))
caseBody.append(CGGeneric("}"))
@@ -926,12 +929,14 @@ for (uint32_t i = 0; i < length; ++i) {
descriptor,
"JSVAL_TO_OBJECT(${val})",
"${declName}",
- failureCode))
+ failureCode,
+ isOptional or argIsPointer or type.nullable()))
else:
templateBody += str(FailureFatalCastableObjectUnwrapper(
descriptor,
"JSVAL_TO_OBJECT(${val})",
- "${declName}"))
+ "${declName}",
+ isOptional or argIsPointer or type.nullable()))
elif descriptor.interface.isCallback() and False:
#XXXjdm unfinished
templateBody += str(CallbackObjectUnwrapper(
@@ -3532,8 +3537,8 @@ class CGProxySpecialOperation(CGPerSignatureCall):
templateValues = {
"declName": argument.identifier.name,
"holderName": argument.identifier.name + "_holder",
- "val": "desc->value",
- "valPtr": "&desc->value"
+ "val": "(*desc).value",
+ "valPtr": "&(*desc).value"
}
self.cgRoot.prepend(instantiateJSToNativeConversionTemplate(template, templateValues))
elif operation.isGetter():
@@ -3636,7 +3641,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
if not 'IndexedCreator' in self.descriptor.operations:
# FIXME need to check that this is a 'supported property index'
assert False
- setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, JSVAL_VOID, false);\n" +
+ setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
" return 1;\n" +
" }\n")
if self.descriptor.operations['NamedSetter']:
@@ -3644,7 +3649,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
if not 'NamedCreator' in self.descriptor.operations:
# FIXME need to check that this is a 'supported property name'
assert False
- setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, JSVAL_VOID, false);\n" +
+ setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
" return 1;\n" +
" }\n")
setOrIndexedGet += "}"
@@ -3710,7 +3715,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'proxy'),
Argument('jsid', 'id'),
Argument('*JSPropertyDescriptor', 'desc')]
- CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "bool", args)
+ CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args)
self.descriptor = descriptor
def getBody(self):
set = ""
@@ -3722,10 +3727,10 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
set += ("let index = GetArrayIndexFromId(cx, id);\n" +
"if index.is_some() {\n" +
" let index = index.unwrap();\n" +
- " let this: *%s = UnwrapProxy(proxy);\n" +
+ " let this: *mut %s = UnwrapProxy(proxy) as *mut %s;\n" +
CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() +
" return 1;\n" +
- "}\n") % (self.descriptor.concreteType)
+ "}\n") % (self.descriptor.concreteType, self.descriptor.concreteType)
elif self.descriptor.operations['IndexedGetter']:
set += ("if GetArrayIndexFromId(cx, id).is_some() {\n" +
" return 0;\n" +
@@ -3771,7 +3776,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" }\n" +
" return 1;\n"
"}\n") % (self.descriptor.concreteType, self.descriptor.name)
- return set + """return proxyhandler::defineProperty(%s);""" % ", ".join(a.name for a in self.args)
+ return set + """return proxyhandler::defineProperty_(%s);""" % ", ".join(a.name for a in self.args)
def definition_body(self):
return self.getBody()
@@ -4618,6 +4623,7 @@ class CGBindingRoot(CGThing):
'dom::bindings::codegen::*', #XXXjdm
'script_task::{JSPageInfo, page_from_context}',
'dom::bindings::utils::EnumEntry',
+ 'dom::bindings::proxyhandler',
'dom::bindings::proxyhandler::*',
'dom::document::AbstractDocument',
'dom::node::{AbstractNode, ScriptView}',
diff --git a/src/components/script/dom/bindings/codegen/HTMLSelectElement.webidl b/src/components/script/dom/bindings/codegen/HTMLSelectElement.webidl
new file mode 100644
index 00000000000..b99bf149280
--- /dev/null
+++ b/src/components/script/dom/bindings/codegen/HTMLSelectElement.webidl
@@ -0,0 +1,57 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/.
+ *
+ * The origin of this IDL file is
+ * http://www.whatwg.org/html/#the-select-element
+ */
+
+interface HTMLSelectElement : HTMLElement {
+ [SetterThrows, Pure]
+ attribute boolean autofocus;
+ [SetterThrows, Pure]
+ attribute boolean disabled;
+ [Pure]
+ readonly attribute HTMLFormElement? form;
+ [SetterThrows, Pure]
+ attribute boolean multiple;
+ [SetterThrows, Pure]
+ attribute DOMString name;
+ [SetterThrows, Pure]
+ attribute boolean required;
+ [SetterThrows, Pure]
+ attribute unsigned long size;
+
+ [Pure]
+ readonly attribute DOMString type;
+
+ /*[Constant]
+ readonly attribute HTMLOptionsCollection options;*/
+ [SetterThrows, Pure]
+ attribute unsigned long length;
+ getter Element? item(unsigned long index);
+ HTMLOptionElement? namedItem(DOMString name);
+ /*[Throws]
+ void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);*/
+ void remove(long index);
+ [Throws]
+ setter creator void (unsigned long index, HTMLOptionElement? option);
+
+// NYI: readonly attribute HTMLCollection selectedOptions;
+ [SetterThrows, Pure]
+ attribute long selectedIndex;
+ [Pure]
+ attribute DOMString value;
+
+ readonly attribute boolean willValidate;
+ readonly attribute ValidityState validity;
+ readonly attribute DOMString validationMessage;
+ boolean checkValidity();
+ void setCustomValidity(DOMString error);
+
+// NYI: readonly attribute NodeList labels;
+
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=20720
+ void remove();
+};
diff --git a/src/components/script/dom/bindings/element.rs b/src/components/script/dom/bindings/element.rs
index 9f3e6c209da..2df2ec0a3b9 100644
--- a/src/components/script/dom/bindings/element.rs
+++ b/src/components/script/dom/bindings/element.rs
@@ -417,6 +417,8 @@ generate_cacheable_wrapper!(HTMLQuoteElement, HTMLQuoteElementBinding::Wrap)
generate_binding_object!(HTMLQuoteElement)
generate_cacheable_wrapper!(HTMLScriptElement, HTMLScriptElementBinding::Wrap)
generate_binding_object!(HTMLScriptElement)
+generate_cacheable_wrapper!(HTMLSelectElement, HTMLSelectElementBinding::Wrap)
+generate_binding_object!(HTMLSelectElement)
generate_cacheable_wrapper!(HTMLSourceElement, HTMLSourceElementBinding::Wrap)
generate_binding_object!(HTMLSourceElement)
generate_cacheable_wrapper!(HTMLSpanElement, HTMLSpanElementBinding::Wrap)
diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs
index 0fdbf00901b..47c32742342 100644
--- a/src/components/script/dom/bindings/node.rs
+++ b/src/components/script/dom/bindings/node.rs
@@ -114,6 +114,7 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode<ScriptView>) -> *JSObject
ElementNodeTypeId(HTMLProgressElementTypeId) => generate_element!(HTMLProgressElement),
ElementNodeTypeId(HTMLQuoteElementTypeId) => generate_element!(HTMLQuoteElement),
ElementNodeTypeId(HTMLScriptElementTypeId) => generate_element!(HTMLScriptElement),
+ ElementNodeTypeId(HTMLSelectElementTypeId) => generate_element!(HTMLSelectElement),
ElementNodeTypeId(HTMLSourceElementTypeId) => generate_element!(HTMLSourceElement),
ElementNodeTypeId(HTMLSpanElementTypeId) => generate_element!(HTMLSpanElement),
ElementNodeTypeId(HTMLStyleElementTypeId) => generate_element!(HTMLStyleElement),
diff --git a/src/components/script/dom/bindings/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs
index 3128c27d727..b31f16da7f0 100644
--- a/src/components/script/dom/bindings/proxyhandler.rs
+++ b/src/components/script/dom/bindings/proxyhandler.rs
@@ -44,8 +44,8 @@ pub extern fn getPropertyDescriptor(cx: *JSContext, proxy: *JSObject, id: jsid,
}
}
-pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
- desc: *JSPropertyDescriptor) -> JSBool {
+pub fn defineProperty_(cx: *JSContext, proxy: *JSObject, id: jsid,
+ desc: *JSPropertyDescriptor) -> JSBool {
unsafe {
if ((*desc).attrs & JSPROP_GETTER) != 0 && (*desc).setter == JS_StrictPropertyStub {
/*return JS_ReportErrorFlagsAndNumber(cx,
@@ -66,6 +66,11 @@ pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
}
}
+pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid,
+ desc: *JSPropertyDescriptor) -> JSBool {
+ defineProperty_(cx, proxy, id, desc)
+}
+
pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString {
unsafe {
let name = str::raw::from_c_str(className);
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 22d00310b13..3799e751f0f 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -112,7 +112,6 @@ pub enum ElementTypeId {
// Regular old elements
//
-pub struct HTMLSelectElement { parent: HTMLElement }
pub struct HTMLSmallElement { parent: HTMLElement }
pub struct UnknownElement { parent: HTMLElement }
diff --git a/src/components/script/dom/htmlselectelement.rs b/src/components/script/dom/htmlselectelement.rs
new file mode 100644
index 00000000000..b3ef7871325
--- /dev/null
+++ b/src/components/script/dom/htmlselectelement.rs
@@ -0,0 +1,134 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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::{DOMString, ErrorResult, null_string};
+use dom::htmlelement::HTMLElement;
+use dom::node::{AbstractNode, ScriptView};
+use dom::validitystate::ValidityState;
+
+pub struct HTMLSelectElement {
+ parent: HTMLElement
+}
+
+impl HTMLSelectElement {
+ pub fn Autofocus(&self) -> bool {
+ false
+ }
+
+ pub fn SetAutofocus(&mut self, _autofocus: bool, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Disabled(&self) -> bool {
+ false
+ }
+
+ pub fn SetDisabled(&mut self, _disabled: bool, _rv: &mut ErrorResult) {
+ }
+
+ pub fn GetForm(&self) -> Option<AbstractNode<ScriptView>> {
+ None
+ }
+
+ pub fn Multiple(&self) -> bool {
+ false
+ }
+
+ pub fn SetMultiple(&mut self, _multiple: bool, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Name(&self) -> DOMString {
+ null_string
+ }
+
+ pub fn SetName(&mut self, _name: &DOMString, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Required(&self) -> bool {
+ false
+ }
+
+ pub fn SetRequired(&mut self, _multiple: bool, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Size(&self) -> u32 {
+ 0
+ }
+
+ pub fn SetSize(&mut self, _size: u32, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Type(&self) -> DOMString {
+ null_string
+ }
+
+ pub fn Length(&self) -> u32 {
+ 0
+ }
+
+ pub fn SetLength(&mut self, _length: u32, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Item(&self, _index: u32) -> Option<AbstractNode<ScriptView>> {
+ None
+ }
+
+ pub fn NamedItem(&self, _name: &DOMString) -> Option<AbstractNode<ScriptView>> {
+ None
+ }
+
+ pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<AbstractNode<ScriptView>> {
+ None
+ }
+
+ pub fn IndexedSetter(&mut self, _index: u32, _option: Option<AbstractNode<ScriptView>>, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Remove_(&self) {
+ }
+
+ pub fn Remove(&self, _index: i32) {
+ }
+
+ pub fn SelectedIndex(&self) -> i32 {
+ 0
+ }
+
+ pub fn SetSelectedIndex(&mut self, _index: i32, _rv: &mut ErrorResult) {
+ }
+
+ pub fn Value(&self) -> DOMString {
+ null_string
+ }
+
+ pub fn SetValue(&mut self, _value: &DOMString) {
+ }
+
+ pub fn WillValidate(&self) -> bool {
+ false
+ }
+
+ pub fn SetWillValidate(&mut self, _will_validate: bool) {
+ }
+
+ pub fn Validity(&self) -> @mut ValidityState {
+ @mut ValidityState::valid()
+ }
+
+ pub fn SetValidity(&mut self, _validity: @mut ValidityState) {
+ }
+
+ pub fn ValidationMessage(&self) -> DOMString {
+ null_string
+ }
+
+ pub fn SetValidationMessage(&mut self, _message: &DOMString, _rv: &mut ErrorResult) {
+ }
+
+ pub fn CheckValidity(&self) -> bool {
+ true
+ }
+
+ pub fn SetCustomValidity(&mut self, _error: &DOMString) {
+ }
+} \ No newline at end of file
diff --git a/src/components/script/script.rc b/src/components/script/script.rc
index 9b89a77a1f5..ac3e4d14148 100644
--- a/src/components/script/script.rc
+++ b/src/components/script/script.rc
@@ -99,6 +99,7 @@ pub mod dom {
pub mod htmlprogresselement;
pub mod htmlquoteelement;
pub mod htmlscriptelement;
+ pub mod htmlselectelement;
pub mod htmlspanelement;
pub mod htmlsourceelement;
pub mod htmlstyleelement;