<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>23418</bug_id>
          
          <creation_ts>2009-01-19 06:25:27 -0800</creation_ts>
          <short_desc>Regular expression literals are not being &quot;shared&quot; inside a function</short_desc>
          <delta_ts>2009-01-20 06:01:50 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>HasReduction, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>webkit</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>106243</commentid>
    <comment_count>0</comment_count>
    <who name="">webkit</who>
    <bug_when>2009-01-19 06:25:27 -0800</bug_when>
    <thetext>Try out the following code:

&gt;&gt;&gt;

var a = function()
{
   this.regexp = /WebKit/;
}

b = new a();
c = new a();

alert( b.regexp == c.regexp );

&lt;&lt;&lt;

It alerts &quot;false&quot; in WebKit (r39853) and IE. With FF and Opera instead, we have &quot;true&quot;, which I though was a browser bug.

But, after a check at the ECMA-262 specs, it looks like &quot;true&quot; is the correct thing:

&gt;&gt;&gt;

7.8.5 Regular Expression Literals

A regular expression literal is an input element that is converted to a RegExp object (section 15.10) when it is scanned. The object is created before evaluation of the containing program or function begins. Evaluation of the literal produces a reference to that object; it does not create a new object.

&lt;&lt;&lt;

I know it&apos;s weird, but webkit is buggy here, and it is always better to have browsers working in the same way.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106244</commentid>
    <comment_count>1</comment_count>
    <who name="">webkit</who>
    <bug_when>2009-01-19 06:28:02 -0800</bug_when>
    <thetext>Btw... one can easily fix the code by using the &quot;new Regex()&quot; syntax instead. But, this was hard to understand at a first glace.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106262</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2009-01-19 11:23:09 -0800</bug_when>
    <thetext>&lt;rdar://problem/6507230&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106267</commentid>
    <comment_count>3</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2009-01-19 11:45:20 -0800</bug_when>
    <thetext>The latest proposed version of the ECMA specification gives the nod to WebKit&apos;s/IE&apos;s behavior, calling the previous specification a bug:

[http://www.ecmascript.org/es4/spec/incompatibilities.pdf]

1.1. Evaluation of a RegExp Literal Results in a new RegExp 
Description 
In ES3 a regular expression literal like /a*b/mg denotes a single unique RegExp object that is created the 
first time the literal is encountered during evaluation.  In ES4 a new RegExp object is created every time 
the literal is encountered during evaluation. 
 
Rationale 
This is a bug fix.  The create-once behavior in ES3 is contrary to programmer expectation.3  If a RegExp 
object created by a literal is used for matching, its lastIndex property will be left in a non-initial state 
after a match; programmers who expect lastIndex to be reset to zero the next time the literal is evaluated 
(because they expect a new RegExp object to be created) will be surprised.  The bug bites even advanced 
programmers. 
 
Impact 
The changed behavior is observable because RegExp objects are mutable and the literal no longer 
corresponds to a single, unique object.  In practice the change is most observable in that the lastIndex 
property of the (new) RegExp object is in an initial state every time the literal is evaluated, as desired. 
 
Implementation precedent 
Internet Explorer 6 and Safari 3 create a new RegExp object every time the literal is encountered during 
evaluation. </thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106328</commentid>
    <comment_count>4</comment_count>
    <who name="">webkit</who>
    <bug_when>2009-01-20 05:41:41 -0800</bug_when>
    <thetext>I&apos;m partially happy on hearing that. Actually we have faced that ECMA bug, and then filled this ticket. It&apos;s good to see that things are to be changed, but we have also the current browser base to support.

So, it looks like I&apos;ll be filling a ticket at FF and Opera now ;)

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106330</commentid>
    <comment_count>5</comment_count>
    <who name="">webkit</who>
    <bug_when>2009-01-20 06:01:50 -0800</bug_when>
    <thetext>Ok... filled the tickets at FF and Opera:

https://bugzilla.mozilla.org/show_bug.cgi?id=474412
https://bugs.opera.com/browse/CORE-17776

Let&apos;s see what those guys have to say about it.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>