ES3 does not specify an error for this case as far as I can see, and
it does specify returning /(?:)/ (the empty-match regexp):
15.10.3 The RegExp Constructor Called as a Function
15.10.3.1 RegExp(pattern, flags)
If pattern is an object R whose [[Class]] property is "RegExp" and
flags is undefined, then return R unchanged. Otherwise call the RegExp
constructor (section 15.10.4.1), passing it the pattern and flags
arguments and return the object constructed by that constructor.
15.10.4 The RegExp Constructor
When RegExp is called as part of a new expression, it is a
constructor: it initialises the newly created object.
15.10.4.1 new RegExp(pattern, flags)
If pattern is an object R whose [[Class]] property is "RegExp" and
flags is undefined, then let P be the pattern used to construct R and
let F be the flags used to construct R. If pattern is an object R
whose [[Class]] property is "RegExp" and flags is not undefined, then
throw a TypeError exception. Otherwise, let P be the empty string if
pattern is undefined and ToString(pattern) otherwise, and let F be the
empty string if flags is undefined and ToString(flags) otherwise.
/be
On Jan 14, 2009, at 5:13 AM, Hallvord R. M. Steen wrote:
Hi,
Opera throws an error if you do
var foo = RegExp();
("new RegExp()" is OK though). I've noticed other engines do not
throw, so
for compatibility reasons we should perhaps fix it. However, I'm
inclined
to think it might simply be a mistake if a script ever does this - the
empty regexp object other engines return is after all pretty useless
for
anything, no? Hence, perhaps throwing makes sense? If so please
consider
standardising it. Apologies if this has already been covered, I
tried googling but found only tangentially related stuff about "/
regexp/()" syntax.
--
Hallvord R. M. Steen
Core JavaScript tester, Opera Software
http://www.opera.com/
Opera - simply the best Internet experience
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss