Skip to content

Commit

Permalink
add TextLength
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos committed Jun 15, 2018
1 parent 5c4f54c commit 0907940
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions components/script/dom/htmltextareaelement.rs
Expand Up @@ -263,6 +263,11 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}

// https://html.spec.whatwg.org/multipage/#dom-textarea-textlength
fn TextLength(&self) -> u32 {
self.textinput.borrow().utf16_len() as u32
}

// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
fn Labels(&self) -> DomRoot<NodeList> {
self.upcast::<HTMLElement>().labels()
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLTextAreaElement.webidl
Expand Up @@ -39,7 +39,7 @@ interface HTMLTextAreaElement : HTMLElement {
attribute DOMString defaultValue;
[CEReactions,TreatNullAs=EmptyString]
attribute DOMString value;
// readonly attribute unsigned long textLength;
readonly attribute unsigned long textLength;

// readonly attribute boolean willValidate;
// readonly attribute ValidityState validity;
Expand Down
10 changes: 10 additions & 0 deletions tests/wpt/metadata/MANIFEST.json
Expand Up @@ -346115,6 +346115,12 @@
{}
]
],
"html/semantics/forms/the-textarea-element/textarea-textLength.html": [
[
"/html/semantics/forms/the-textarea-element/textarea-textLength.html",
{}
]
],
"html/semantics/forms/the-textarea-element/textarea-type.html": [
[
"/html/semantics/forms/the-textarea-element/textarea-type.html",
Expand Down Expand Up @@ -583616,6 +583622,10 @@
"7b513a17599ea93eb430a81bbff8d5aa94d07c3c",
"manual"
],
"html/semantics/forms/the-textarea-element/textarea-textLength.html": [
"0f9b8cdaace12d4f4e7fbd57a90fcba7e826ced5",
"testharness"
],
"html/semantics/forms/the-textarea-element/textarea-type.html": [
"81a270bc3c9304f8b2e7dd526519f4eab7d94f45",
"testharness"
Expand Down
@@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<title>The textLengh IDL attribute</title>
<meta content="charset=utf-16">
<link rel="author" title="tigercosmos" href="mailto:phy.tiger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-textarea-textlength">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<textarea id="textarea"></textarea>
<script>
var textarea = document.getElementById("textarea");

test(function () {
textarea.value= "Hello, World!";
assert_equals(textarea.textLength, 13);

textarea.value = "\u4f60\u597d\uff0c\u4e16\u754c\uff01"; //你好,世界!
assert_equals(textarea.textLength, 6);
}, "Textarea's 'testLength' should work for utf-16.");
</script>

0 comments on commit 0907940

Please sign in to comment.