⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 89946 in webkit


Ignore:
Timestamp:
Jun 28, 2011, 11:35:37 AM (15 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=55040
RegExp constructor returns the argument regexp instead of a new object

Reviewed by Oliver Hunt.

Per 15.10.3.1, our current behaviour is correct if called as a function,
but incorrect when called as a constructor.

Source/JavaScriptCore:

  • runtime/RegExpConstructor.cpp:

(JSC::constructRegExp):
(JSC::constructWithRegExpConstructor):

  • runtime/RegExpConstructor.h:

LayoutTests:

  • fast/regex/constructor-expected.txt: Added.
  • fast/regex/constructor.html: Added.
  • fast/regex/script-tests/constructor.js: Added.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r89936 r89946  
     12011-06-28  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=55040
     6        RegExp constructor returns the argument regexp instead of a new object
     7
     8        Per 15.10.3.1, our current behaviour is correct if called as a function,
     9        but incorrect when called as a constructor.
     10
     11        * fast/regex/constructor-expected.txt: Added.
     12        * fast/regex/constructor.html: Added.
     13        * fast/regex/script-tests/constructor.js: Added.
     14
    1152011-06-28  Jessie Berlin  <jberlin@apple.com>
    216
  • trunk/Source/JavaScriptCore/ChangeLog

    r89943 r89946  
     12011-06-28  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=55040
     6        RegExp constructor returns the argument regexp instead of a new object
     7
     8        Per 15.10.3.1, our current behaviour is correct if called as a function,
     9        but incorrect when called as a constructor.
     10
     11        * runtime/RegExpConstructor.cpp:
     12        (JSC::constructRegExp):
     13        (JSC::constructWithRegExpConstructor):
     14        * runtime/RegExpConstructor.h:
     15
    1162011-06-28  Luke Macpherson   <macpherson@chromium.org>
    217
  • trunk/Source/JavaScriptCore/runtime/RegExpConstructor.cpp

    r87445 r89946  
    294294
    295295// ECMA 15.10.4
    296 JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args)
     296JSObject* constructRegExp(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args, bool callAsConstructor)
    297297{
    298298    JSValue arg0 = args.at(0);
     
    302302        if (!arg1.isUndefined())
    303303            return throwError(exec, createTypeError(exec, "Cannot supply flags when constructing one RegExp from another."));
     304        // If called as a function, this just returns the first argument (see 15.10.3.1).
     305        if (callAsConstructor) {
     306            RegExp* regExp = static_cast<RegExpObject*>(asObject(arg0))->regExp();
     307            return new (exec) RegExpObject(globalObject, globalObject->regExpStructure(), regExp);
     308        }
    304309        return asObject(arg0);
    305310    }
     
    327332{
    328333    ArgList args(exec);
    329     return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args));
     334    return JSValue::encode(constructRegExp(exec, asInternalFunction(exec->callee())->globalObject(), args, true));
    330335}
    331336
  • trunk/Source/JavaScriptCore/runtime/RegExpConstructor.h

    r87327 r89946  
    9797    RegExpConstructor* asRegExpConstructor(JSValue);
    9898
    99     JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&);
     99    JSObject* constructRegExp(ExecState*, JSGlobalObject*, const ArgList&, bool callAsConstructor = false);
    100100
    101101    inline RegExpConstructor* asRegExpConstructor(JSValue value)
Note: See TracChangeset for help on using the changeset viewer.