Ignore:
Timestamp:
Feb 27, 2012, 10:29:04 AM (13 years ago)
Author:
[email protected]
Message:

RegExp lastIndex should behave as a regular property
https://bugs.webkit.org/show_bug.cgi?id=79446

Reviewed by Sam Weinig.

lastIndex should be a regular data descriptor, with the attributes configurable:false,
enumerable:false, writable:true. As such, it should be possible to reconfigure writable
as false. If the lastIndex property is reconfigured to be read-only, we should respect
this correctly.

Source/JavaScriptCore:

  • runtime/CommonIdentifiers.h:
    • Removed some unused identifiers, added lastIndex.
  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::getOwnPropertySlot):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::RegExpObject::getOwnPropertyDescriptor):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::RegExpObject::deleteProperty):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::RegExpObject::getOwnPropertyNames):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::RegExpObject::getPropertyNames):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::reject):

  • helper function for defineOwnProperty.

(JSC::RegExpObject::defineOwnProperty):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::RegExpObject::put):

  • lastIndex is no longer a static value, provided specific handling.

(JSC::RegExpObject::match):

  • Pass setLastIndex an ExecState, so it can throw if read-only.
  • runtime/RegExpObject.h:

(JSC::RegExpObject::setLastIndex):

  • Pass setLastIndex an ExecState, so it can throw if read-only.

(RegExpObjectData):

  • Added lastIndexIsWritable.
  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncCompile):

  • Pass setLastIndex an ExecState, so it can throw if read-only.

LayoutTests:

  • fast/regex/lastIndex-expected.txt: Added.
  • fast/regex/lastIndex.html: Added.
  • fast/regex/script-tests/lastIndex.js: Added.
    • Added test cases for correct handling of lastIndex.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/RegExpObject.h

    r104900 r109008  
    4848        RegExp* regExp() const { return d->regExp.get(); }
    4949
    50         void setLastIndex(size_t lastIndex)
     50        void setLastIndex(ExecState* exec, size_t lastIndex)
    5151        {
    5252            d->lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
     53            if (LIKELY(d->lastIndexIsWritable))
     54                d->lastIndex.setWithoutWriteBarrier(jsNumber(lastIndex));
     55            else
     56                throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
    5357        }
    54         void setLastIndex(JSGlobalData& globalData, JSValue lastIndex)
     58        void setLastIndex(ExecState* exec, JSValue lastIndex, bool shouldThrow)
    5559        {
    56             d->lastIndex.set(globalData, this, lastIndex);
     60            if (LIKELY(d->lastIndexIsWritable))
     61                d->lastIndex.set(exec->globalData(), this, lastIndex);
     62            else if (shouldThrow)
     63                throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
    5764        }
    5865        JSValue getLastIndex() const
     
    8491        static void visitChildren(JSCell*, SlotVisitor&);
    8592
     93        JS_EXPORT_PRIVATE static bool deleteProperty(JSCell*, ExecState*, const Identifier& propertyName);
     94        JS_EXPORT_PRIVATE static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
     95        JS_EXPORT_PRIVATE static void getPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
     96        JS_EXPORT_PRIVATE static bool defineOwnProperty(JSObject*, ExecState*, const Identifier& propertyName, PropertyDescriptor&, bool shouldThrow);
     97
    8698    private:
    8799        bool match(ExecState*);
     
    92104            RegExpObjectData(JSGlobalData& globalData, RegExpObject* owner, RegExp* regExp)
    93105                : regExp(globalData, owner, regExp)
     106                , lastIndexIsWritable(true)
    94107            {
    95108                lastIndex.setWithoutWriteBarrier(jsNumber(0));
     
    98111            WriteBarrier<RegExp> regExp;
    99112            WriteBarrier<Unknown> lastIndex;
     113            bool lastIndexIsWritable;
    100114        };
    101115#if COMPILER(MSVC)
Note: See TracChangeset for help on using the changeset viewer.