Ignore:
Timestamp:
Jun 18, 2009, 12:18:12 PM (16 years ago)
Author:
Darin Adler
Message:

JavaScriptCore:

2009-06-17 Darin Adler <Darin Adler>

Reviewed by Oliver Hunt.

Bug 26429: Make JSON.stringify non-recursive so it can handle objects
of arbitrary complexity
https://bugs.webkit.org/show_bug.cgi?id=26429

For marking I decided not to use gcProtect, because this is inside the engine
so it's easy enough to just do marking. And that darned gcProtect does locking!
Oliver tried to convince me to used MarkedArgumentBuffer, but the constructor
for that class says "FIXME: Remove all clients of this API, then remove this API."

  • runtime/Collector.cpp: (JSC::Heap::collect): Add a call to JSONObject::markStringifiers.
  • runtime/CommonIdentifiers.cpp: (JSC::CommonIdentifiers::CommonIdentifiers): Added emptyIdentifier.
  • runtime/CommonIdentifiers.h: Ditto.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): Initialize firstStringifierToMark to 0.
  • runtime/JSGlobalData.h: Added firstStringifierToMark.
  • runtime/JSONObject.cpp: Cut down the includes to the needed ones only. (JSC::unwrapNumberOrString): Added. Helper for unwrapping number and string objects to get their number and string values. (JSC::ReplacerPropertyName::ReplacerPropertyName): Added. The class is used to wrap an identifier or integer so we don't have to do any work unless we actually call a replacer. (JSC::ReplacerPropertyName::value): Added. (JSC::gap): Added. Helper function for the Stringifier constructor. (JSC::PropertyNameForFunctionCall::PropertyNameForFunctionCall): Added. The class is used to wrap an identifier or integer so we don't have to allocate a number or string until we actually call toJSON or a replacer. (JSC::PropertyNameForFunctionCall::asJSValue): Added. (JSC::Stringifier::Stringifier): Updated and moved out of the class definition. Added code to hook this into a singly linked list for marking. (JSC::Stringifier::~Stringifier): Remove from the singly linked list. (JSC::Stringifier::mark): Mark all the objects in the holder stacks. (JSC::Stringifier::stringify): Updated. (JSC::Stringifier::appendQuotedString): Tweaked and streamlined a bit. (JSC::Stringifier::toJSON): Renamed from toJSONValue. (JSC::Stringifier::appendStringifiedValue): Renamed from stringify. Added code to use the m_holderStack to do non-recursive stringify of objects and arrays. This code also uses the timeout checker since in pathological cases it could be slow even without calling into the JavaScript virtual machine. (JSC::Stringifier::willIndent): Added. (JSC::Stringifier::indent): Added. (JSC::Stringifier::unindent): Added. (JSC::Stringifier::startNewLine): Added. (JSC::Stringifier::Holder::Holder): Added. (JSC::Stringifier::Holder::appendNextProperty): Added. This is the function that handles the format of arrays and objects. (JSC::JSONObject::getOwnPropertySlot): Moved this down to the bottom of the file so the JSONObject class is not interleaved with the Stringifier class. (JSC::JSONObject::markStringifiers): Added. Calls mark. (JSC::JSONProtoFuncStringify): Streamlined the code here. The code to compute the gap string is now a separate function.
  • runtime/JSONObject.h: Made everything private. Added markStringifiers.

LayoutTests:

2009-06-17 Darin Adler <Darin Adler>

Reviewed by Oliver Hunt.

Bug 26429: Make JSON.stringify non-recursive so it can handle objects
of arbitrary complexity
https://bugs.webkit.org/show_bug.cgi?id=26429

  • fast/js/JSON-stringify-expected.txt: Updated.
  • fast/js/resources/JSON-stringify.js: Changed the infinite object and infinite array tests to instead just test something a fixed number of levels deep. Otherwise we end up with an infinite loop in the test, which would lead to the slow-script dialog in the production web browser. Also raised the number from 512 to 2048 since there's no fixed limit any more.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/JSONObject.h

    r44550 r44813  
    3131namespace JSC {
    3232
     33    class Stringifier;
     34
    3335    class JSONObject : public JSObject {
    3436    public:
    3537        JSONObject(PassRefPtr<Structure> structure)
    36             :JSObject(structure)
     38            : JSObject(structure)
    3739        {
    3840        }
    39 
    40         virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
    41 
    42         virtual const ClassInfo* classInfo() const { return &info; }
    43         static const ClassInfo info;
    4441
    4542        static PassRefPtr<Structure> createStructure(JSValue prototype)
     
    4744            return Structure::create(prototype, TypeInfo(ObjectType));
    4845        }
     46
     47        static void markStringifiers(Stringifier*);
     48
     49    private:
     50        virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     51
     52        virtual const ClassInfo* classInfo() const { return &info; }
     53        static const ClassInfo info;
    4954    };
    5055
Note: See TracChangeset for help on using the changeset viewer.