This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14443 - Introduce Text.isWhiteSpace?
Summary: Introduce Text.isWhiteSpace?
Status: RESOLVED WONTFIX
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-12 23:48 UTC by Anne
Modified: 2011-12-20 20:06 UTC (History)
7 users (show)

See Also:


Attachments

Description Anne 2011-10-12 23:48:27 UTC
Basically an attribute that returns whether the Text node consists solely of space characters.

(This is a slightly changed Text.isElementContentWhitespace (from its originaly definition anyway) with a better name.)
Comment 1 Simon Pieters 2011-10-13 06:06:04 UTC
Use case being? :-)
Comment 2 Erik Arvidsson 2011-10-23 20:31:57 UTC
I don't think it is worth polluting the API with something that seems not very common and which is quite easily done today.

/^\s*$/.test(textNode.data)

or

textNode.data.trim() === ''

If one really wants it than the following would also work:

Object.defineProperty(Text.prototype, 'isWhitespace', {
  get: function() {
    return /^\s*$/.test(this.data);
  },
  configurable: true,
  enumerable: true
});
Comment 3 Jonas Sicking (Not reading bugmail) 2011-10-23 21:26:50 UTC
Except that at least in Gecko we could write a significantly faster implementation than can be written in javascript. The reason is that we cache information about if a node is white-space only in order to speed up CSS rendering. I would have guessed that other engines does this too.

So if people actually write code like in your examples, then I think we should provide a faster built-in implementation.

The question is if people do write code like that. So far it appears that isn't the case so I'm happy to WONTFIX this bug until someone comes up with use cases.
Comment 4 Anne 2011-10-24 09:11:53 UTC
Last I checked CSS whitespace is different from HTML whitespace and both are totally different from JavaScript whitespace.
Comment 5 Anne 2011-12-20 20:06:11 UTC
WONTFIX per comment 3.