Changeset 87826 in webkit


Ignore:
Timestamp:
Jun 1, 2011 11:08:07 AM (13 years ago)
Author:
oliver@apple.com
Message:

2011-05-31 Oliver Hunt <oliver@apple.com>

Reviewed by Geoffrey Garen.

Freezing a function and its prototype causes browser to crash.
https://bugs.webkit.org/show_bug.cgi?id=61758

Add test to ensure correct behaviour

  • fast/js/preventExtensions-expected.txt:
  • fast/js/script-tests/preventExtensions.js: (f):

2011-05-31 Oliver Hunt <oliver@apple.com>

Reviewed by Geoffrey Garen.

Freezing a function and its prototype causes browser to crash.
https://bugs.webkit.org/show_bug.cgi?id=61758

Make JSObject::preventExtensions virtual so that we can override it
and instantiate all lazy

  • JavaScriptCore.exp:
  • runtime/JSFunction.cpp: (JSC::createPrototypeProperty): (JSC::JSFunction::preventExtensions): (JSC::JSFunction::getOwnPropertySlot):
  • runtime/JSFunction.h:
  • runtime/JSObject.h:
  • runtime/JSObject.cpp: (JSC::JSObject::seal): (JSC::JSObject::seal):
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r87822 r87826  
     12011-05-31  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Freezing a function and its prototype causes browser to crash.
     6        https://bugs.webkit.org/show_bug.cgi?id=61758
     7
     8        Add test to ensure correct behaviour
     9
     10        * fast/js/preventExtensions-expected.txt:
     11        * fast/js/script-tests/preventExtensions.js:
     12        (f):
     13
    1142011-05-19  Adrienne Walker  <enne@google.com>
    215
  • trunk/LayoutTests/fast/js/preventExtensions-expected.txt

    r80378 r87826  
    44
    55
     6PASS (new inextensible).prototypeExists is true
     7PASS (new sealed).prototypeExists is true
     8PASS (new frozen).prototypeExists is true
    69PASS test(obj()) is "(b:4)(c:3)E"
    710PASS test(preventExtensions(obj())) is "(b:4)"
  • trunk/LayoutTests/fast/js/script-tests/preventExtensions.js

    r80378 r87826  
    4444}
    4545
     46function inextensible(){}
     47function sealed(){}
     48function frozen(){};
     49preventExtensions(inextensible);
     50seal(sealed);
     51freeze(frozen);
     52new inextensible;
     53new sealed;
     54new frozen;
     55inextensible.prototype.prototypeExists = true;
     56sealed.prototype.prototypeExists = true;
     57frozen.prototype.prototypeExists = true;
     58
     59shouldBeTrue("(new inextensible).prototypeExists");
     60shouldBeTrue("(new sealed).prototypeExists");
     61shouldBeTrue("(new frozen).prototypeExists");
     62
    4663shouldBe('test(obj())', '"(b:4)(c:3)E"'); // extensible, can delete a, can modify b, and can add c
    4764shouldBe('test(preventExtensions(obj()))', '"(b:4)"'); // <nothing>, can delete a, can modify b, and CANNOT add c
  • trunk/Source/JavaScriptCore/ChangeLog

    r87799 r87826  
     12011-05-31  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Freezing a function and its prototype causes browser to crash.
     6        https://bugs.webkit.org/show_bug.cgi?id=61758
     7
     8        Make JSObject::preventExtensions virtual so that we can override it
     9        and instantiate all lazy
     10
     11        * JavaScriptCore.exp:
     12        * runtime/JSFunction.cpp:
     13        (JSC::createPrototypeProperty):
     14        (JSC::JSFunction::preventExtensions):
     15        (JSC::JSFunction::getOwnPropertySlot):
     16        * runtime/JSFunction.h:
     17        * runtime/JSObject.h:
     18        * runtime/JSObject.cpp:
     19        (JSC::JSObject::seal):
     20        (JSC::JSObject::seal):
     21
    1222011-06-01  Sheriff Bot  <webkit.review.bot@gmail.com>
    223
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r87653 r87826  
    299299__ZN3JSC8JSObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayENS_15EnumerationModeE
    300300__ZN3JSC8JSObject17defineOwnPropertyEPNS_9ExecStateERKNS_10IdentifierERNS_18PropertyDescriptorEb
     301__ZN3JSC8JSObject17preventExtensionsERNS_12JSGlobalDataE
    301302__ZN3JSC8JSObject17putDirectFunctionEPNS_9ExecStateEPNS_10JSFunctionEj
    302303__ZN3JSC8JSObject17putDirectFunctionEPNS_9ExecStateEPNS_16InternalFunctionEj
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r87653 r87826  
    256256    ?objectProtoFuncToString@JSC@@YI_JPAVExecState@1@@Z
    257257    ?parseDateFromNullTerminatedCharacters@WTF@@YANPBD@Z
     258    ?preventExtensions@JSObject@JSC@@UAEXAAVJSGlobalData@2@@Z
    258259    ?profiler@Profiler@JSC@@SAPAV12@XZ
    259260    ?protect@Heap@JSC@@QAEXVJSValue@2@@Z
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r86510 r87826  
    178178}
    179179
     180static inline WriteBarrierBase<Unknown>* createPrototypeProperty(JSGlobalData& globalData, JSGlobalObject* globalObject, JSFunction* function)
     181{
     182    ExecState* exec = globalObject->globalExec();
     183    if (WriteBarrierBase<Unknown>* location = function->getDirectLocation(globalData, exec->propertyNames().prototype))
     184        return location;
     185    JSObject* prototype = constructEmptyObject(exec, globalObject->emptyObjectStructure());
     186    prototype->putDirect(globalData, exec->propertyNames().constructor, function, DontEnum);
     187    function->putDirect(globalData, exec->propertyNames().prototype, prototype, DontDelete | DontEnum);
     188    return function->getDirectLocation(exec->globalData(), exec->propertyNames().prototype);
     189}
     190
     191void JSFunction::preventExtensions(JSGlobalData& globalData)
     192{
     193    createPrototypeProperty(globalData, scope()->globalObject.get(), this);
     194    JSObject::preventExtensions(globalData);
     195}
     196
    180197bool JSFunction::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
    181198{
     
    186203        WriteBarrierBase<Unknown>* location = getDirectLocation(exec->globalData(), propertyName);
    187204
    188         if (!location) {
    189             JSObject* prototype = constructEmptyObject(exec, scope()->globalObject->emptyObjectStructure());
    190             prototype->putDirect(exec->globalData(), exec->propertyNames().constructor, this, DontEnum);
    191             putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | DontEnum);
    192             location = getDirectLocation(exec->globalData(), propertyName);
    193         }
     205        if (!location)
     206            location = createPrototypeProperty(exec->globalData(), scope()->globalObject.get(), this);
    194207
    195208        slot.setValue(this, location->get(), offsetForLocation(location));
  • trunk/Source/JavaScriptCore/runtime/JSFunction.h

    r84556 r87826  
    9292        bool isHostFunctionNonInline() const;
    9393
     94        virtual void preventExtensions(JSGlobalData&);
    9495        virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
    9596        virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r86499 r87826  
    510510void JSObject::seal(JSGlobalData& globalData)
    511511{
     512    if (isSealed(globalData))
     513        return;
     514    preventExtensions(globalData);
    512515    setStructure(globalData, Structure::sealTransition(globalData, m_structure.get()));
    513516}
     
    515518void JSObject::freeze(JSGlobalData& globalData)
    516519{
     520    if (isFrozen(globalData))
     521        return;
     522    preventExtensions(globalData);
    517523    setStructure(globalData, Structure::freezeTransition(globalData, m_structure.get()));
    518524}
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r87527 r87826  
    212212        void seal(JSGlobalData&);
    213213        void freeze(JSGlobalData&);
    214         void preventExtensions(JSGlobalData&);
     214        virtual void preventExtensions(JSGlobalData&);
    215215        bool isSealed(JSGlobalData& globalData) { return m_structure->isSealed(globalData); }
    216216        bool isFrozen(JSGlobalData& globalData) { return m_structure->isFrozen(globalData); }
Note: See TracChangeset for help on using the changeset viewer.