Changeset 44550 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Jun 9, 2009, 5:37:01 PM (16 years ago)
Author:
[email protected]
Message:

Bug 26249: Support JSON.stringify
<https://bugs.webkit.org/show_bug.cgi?id=26249>

Reviewed by Sam Weinig.

Implement JSON.stringify. This patch handles all the semantics of the ES5
JSON.stringify function, including replacer functions and arrays and both
string and numeric gap arguments.

Currently uses a clamped recursive algorithm basically identical to the spec
description but with a few minor tweaks for performance and corrected semantics
discussed in the es-discuss mailing list.

Location:
trunk/JavaScriptCore/runtime
Files:
2 added
4 edited

Legend:

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

    r44522 r44550  
    6060    macro(toExponential) \
    6161    macro(toFixed) \
     62    macro(toJSON) \
    6263    macro(toLocaleString) \
    6364    macro(toPrecision) \
  • trunk/JavaScriptCore/runtime/JSGlobalData.cpp

    r44522 r44550  
    6161
    6262extern const HashTable arrayTable;
     63extern const HashTable jsonTable;
    6364extern const HashTable dateTable;
    6465extern const HashTable mathTable;
     
    106107    , arrayTable(fastNew<HashTable>(JSC::arrayTable))
    107108    , dateTable(fastNew<HashTable>(JSC::dateTable))
     109    , jsonTable(fastNew<HashTable>(JSC::jsonTable))
    108110    , mathTable(fastNew<HashTable>(JSC::mathTable))
    109111    , numberTable(fastNew<HashTable>(JSC::numberTable))
     
    156158    arrayTable->deleteTable();
    157159    dateTable->deleteTable();
     160    jsonTable->deleteTable();
    158161    mathTable->deleteTable();
    159162    numberTable->deleteTable();
     
    167170    fastDelete(const_cast<HashTable*>(arrayTable));
    168171    fastDelete(const_cast<HashTable*>(dateTable));
     172    fastDelete(const_cast<HashTable*>(jsonTable));
    169173    fastDelete(const_cast<HashTable*>(mathTable));
    170174    fastDelete(const_cast<HashTable*>(numberTable));
  • trunk/JavaScriptCore/runtime/JSGlobalData.h

    r44522 r44550  
    8383        const HashTable* arrayTable;
    8484        const HashTable* dateTable;
     85        const HashTable* jsonTable;
    8586        const HashTable* mathTable;
    8687        const HashTable* numberTable;
  • trunk/JavaScriptCore/runtime/JSGlobalObject.cpp

    r44522 r44550  
    5151#include "JSGlobalObjectFunctions.h"
    5252#include "JSLock.h"
     53#include "JSONObject.h"
    5354#include "Interpreter.h"
    5455#include "MathObject.h"
     
    319320        GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete),
    320321        GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete),
    321         GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete)
     322        GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete),
     323        GlobalPropertyInfo(Identifier(exec, "JSON"), new (exec) JSONObject(JSONObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete)
    322324    };
    323325
Note: See TracChangeset for help on using the changeset viewer.