Changeset 44521 in webkit
- Timestamp:
- Jun 8, 2009 11:02:24 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r44518 r44521 1 2009-06-07 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 Bug 26249: Support JSON.stringify 6 <https://bugs.webkit.org/show_bug.cgi?id=26249> 7 8 Implement JSON.stringify. This patch handles all the semantics of the ES5 9 JSON.stringify function, including replacer functions and arrays and both 10 string and numeric gap arguments. 11 12 Currently uses a clamped recursive algorithm basically identical to the spec 13 description but with a few minor tweaks for performance and corrected semantics 14 discussed in the es-discuss mailing list. 15 16 * DerivedSources.make: 17 * GNUmakefile.am: 18 * JavaScriptCore.pri: 19 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: 20 * JavaScriptCore.xcodeproj/project.pbxproj: 21 * interpreter/CallFrame.h: 22 (JSC::ExecState::jsonTable): 23 * runtime/CommonIdentifiers.h: 24 add toJSON to the list of common identifiers 25 26 * runtime/JSGlobalData.cpp: 27 (JSC::JSGlobalData::JSGlobalData): 28 (JSC::JSGlobalData::~JSGlobalData): 29 * runtime/JSGlobalData.h: 30 * runtime/JSGlobalObject.cpp: 31 (JSC::JSGlobalObject::reset): 32 Add support for the JSON object lookup table 33 34 * runtime/JSONObject.cpp: Added. 35 (JSC::): 36 (JSC::JSONObject::getOwnPropertySlot): 37 (JSC::Stringifier::): 38 (JSC::Stringifier::Stringifier): 39 (JSC::Stringifier::stringify): 40 (JSC::Stringifier::appendString): 41 42 (JSC::Stringifier::StringKeyGenerator::StringKeyGenerator): 43 (JSC::Stringifier::StringKeyGenerator::getKey): 44 (JSC::Stringifier::IntKeyGenerator::IntKeyGenerator): 45 (JSC::Stringifier::IntKeyGenerator::getKey): 46 These KeyGenerator classes are used to abstract away the lazy evaluation of keys for 47 toJSON and replacer functions. 48 49 (JSC::Stringifier::toJSONValue): 50 (JSC::Stringifier::stringifyArray): 51 (JSC::Stringifier::stringifyObject): 52 (JSC::JSONProtoFuncStringify): 53 * runtime/JSONObject.h: Added. 54 (JSC::JSONObject:::JSObject): 55 (JSC::JSONObject::classInfo): 56 (JSC::JSONObject::createStructure): 57 1 58 2009-06-08 Mark Rowe <mrowe@apple.com> 2 59 -
trunk/JavaScriptCore/DerivedSources.make
r40187 r44521 41 41 DatePrototype.lut.h \ 42 42 Grammar.cpp \ 43 JSONObject.lut.h \ 43 44 Lexer.lut.h \ 44 45 MathObject.lut.h \ -
trunk/JavaScriptCore/GNUmakefile.am
r44516 r44521 36 36 JavaScriptCore/runtime/ArrayPrototype.lut.h \ 37 37 JavaScriptCore/runtime/DatePrototype.lut.h \ 38 JavaScriptCore/runtime/JSONObject.lut.h \ 38 39 JavaScriptCore/runtime/MathObject.lut.h \ 39 40 JavaScriptCore/runtime/NumberConstructor.lut.h \ … … 183 184 JavaScriptCore/runtime/JSNotAnObject.cpp \ 184 185 JavaScriptCore/runtime/JSNotAnObject.h \ 186 JavaScriptCore/runtime/JSONObject.cpp \ 187 JavaScriptCore/runtime/JSONObject.h \ 185 188 JavaScriptCore/runtime/JSPropertyNameIterator.cpp \ 186 189 JavaScriptCore/runtime/JSPropertyNameIterator.h \ … … 591 594 JavaScriptCore/runtime/ArrayPrototype.lut.h \ 592 595 JavaScriptCore/runtime/DatePrototype.lut.h \ 596 JavaScriptCore/runtime/JSONObject.lut.h \ 593 597 JavaScriptCore/runtime/MathObject.lut.h \ 594 598 JavaScriptCore/runtime/NumberConstructor.lut.h \ -
trunk/JavaScriptCore/JavaScriptCore.pri
r44508 r44521 111 111 runtime/JSActivation.cpp \ 112 112 runtime/JSNotAnObject.cpp \ 113 runtime/JSONObject.cpp \ 113 114 runtime/LiteralParser.cpp \ 114 115 runtime/TimeoutChecker.cpp \ -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
r44508 r44521 794 794 <File 795 795 RelativePath="..\..\runtime\JSNumberCell.h" 796 > 797 <File 798 RelativePath="..\..\runtime\JSONObject.cpp" 799 > 800 </File> 801 <File 802 RelativePath="..\..\runtime\JSONObject.h" 796 803 > 797 804 </File> -
trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r44514 r44521 199 199 A7E2EA6B0FB460CF00601F06 /* LiteralParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A7E2EA690FB460CF00601F06 /* LiteralParser.h */; }; 200 200 A7E2EA6C0FB460CF00601F06 /* LiteralParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E2EA6A0FB460CF00601F06 /* LiteralParser.cpp */; }; 201 A7F9935F0FD7325100A0B2D0 /* JSONObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F9935D0FD7325100A0B2D0 /* JSONObject.h */; }; 202 A7F993600FD7325100A0B2D0 /* JSONObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7F9935E0FD7325100A0B2D0 /* JSONObject.cpp */; }; 203 A7F9949B0FD746A300A0B2D0 /* JSONObject.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = A7F9949A0FD746A300A0B2D0 /* JSONObject.lut.h */; }; 201 204 BC02E90D0E1839DB000F9297 /* ErrorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = BC02E9050E1839DB000F9297 /* ErrorConstructor.h */; }; 202 205 BC02E90F0E1839DB000F9297 /* ErrorPrototype.h in Headers */ = {isa = PBXBuildFile; fileRef = BC02E9070E1839DB000F9297 /* ErrorPrototype.h */; }; … … 735 738 A7F8690E0F9584A100558697 /* CachedCall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedCall.h; sourceTree = "<group>"; }; 736 739 A7F869EC0F95C2EC00558697 /* CallFrameClosure.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallFrameClosure.h; sourceTree = "<group>"; }; 740 A7F9935D0FD7325100A0B2D0 /* JSONObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONObject.h; sourceTree = "<group>"; }; 741 A7F9935E0FD7325100A0B2D0 /* JSONObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSONObject.cpp; sourceTree = "<group>"; }; 742 A7F9949A0FD746A300A0B2D0 /* JSONObject.lut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSONObject.lut.h; path = /Users/oliver/builds/Debug/DerivedSources/JavaScriptCore/JSONObject.lut.h; sourceTree = "<absolute>"; }; 737 743 A8E894310CD0602400367179 /* JSCallbackObjectFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCallbackObjectFunctions.h; sourceTree = "<group>"; }; 738 744 A8E894330CD0603F00367179 /* JSGlobalObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSGlobalObject.h; sourceTree = "<group>"; }; … … 1143 1149 BC18C5230E16FC8A00B34460 /* ArrayPrototype.lut.h */, 1144 1150 BCD203E70E1718F4002C7E82 /* DatePrototype.lut.h */, 1151 A7F9949A0FD746A300A0B2D0 /* JSONObject.lut.h */, 1145 1152 BC18C5290E16FCC200B34460 /* MathObject.lut.h */, 1146 1153 BC2680E60E16D52300A06E92 /* NumberConstructor.lut.h */, … … 1463 1470 F692A8850255597D01FF60F7 /* UString.cpp */, 1464 1471 F692A8860255597D01FF60F7 /* UString.h */, 1472 A7F9935D0FD7325100A0B2D0 /* JSONObject.h */, 1473 A7F9935E0FD7325100A0B2D0 /* JSONObject.cpp */, 1465 1474 ); 1466 1475 path = runtime; … … 1847 1856 0BDFFAE00FC6192900D69EF4 /* CrossThreadRefCounted.h in Headers */, 1848 1857 0BDFFAE10FC6193100D69EF4 /* OwnFastMallocPtr.h in Headers */, 1858 A7F9935F0FD7325100A0B2D0 /* JSONObject.h in Headers */, 1859 A7F9949B0FD746A300A0B2D0 /* JSONObject.lut.h in Headers */, 1849 1860 86ADD1450FDDEA980006EEC2 /* ARMv7Assembler.h in Headers */, 1850 1861 86ADD1460FDDEA980006EEC2 /* MacroAssemblerARMv7.h in Headers */, … … 2210 2221 93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */, 2211 2222 BCDD51EB0FB8DF74004A8BDC /* JITOpcodes.cpp in Sources */, 2223 A7F993600FD7325100A0B2D0 /* JSONObject.cpp in Sources */, 2212 2224 ); 2213 2225 runOnlyForDeploymentPostprocessing = 0; -
trunk/JavaScriptCore/interpreter/CallFrame.h
r44344 r44521 90 90 static const HashTable* arrayTable(CallFrame* callFrame) { return callFrame->globalData().arrayTable; } 91 91 static const HashTable* dateTable(CallFrame* callFrame) { return callFrame->globalData().dateTable; } 92 static const HashTable* jsonTable(CallFrame* callFrame) { return callFrame->globalData().jsonTable; } 92 93 static const HashTable* mathTable(CallFrame* callFrame) { return callFrame->globalData().mathTable; } 93 94 static const HashTable* numberTable(CallFrame* callFrame) { return callFrame->globalData().numberTable; } -
trunk/JavaScriptCore/runtime/CommonIdentifiers.h
r44224 r44521 60 60 macro(toExponential) \ 61 61 macro(toFixed) \ 62 macro(toJSON) \ 62 63 macro(toLocaleString) \ 63 64 macro(toPrecision) \ -
trunk/JavaScriptCore/runtime/JSGlobalData.cpp
r44417 r44521 61 61 62 62 extern const HashTable arrayTable; 63 extern const HashTable jsonTable; 63 64 extern const HashTable dateTable; 64 65 extern const HashTable mathTable; … … 106 107 , arrayTable(fastNew<HashTable>(JSC::arrayTable)) 107 108 , dateTable(fastNew<HashTable>(JSC::dateTable)) 109 , jsonTable(fastNew<HashTable>(JSC::jsonTable)) 108 110 , mathTable(fastNew<HashTable>(JSC::mathTable)) 109 111 , numberTable(fastNew<HashTable>(JSC::numberTable)) … … 156 158 arrayTable->deleteTable(); 157 159 dateTable->deleteTable(); 160 jsonTable->deleteTable(); 158 161 mathTable->deleteTable(); 159 162 numberTable->deleteTable(); … … 167 170 fastDelete(const_cast<HashTable*>(arrayTable)); 168 171 fastDelete(const_cast<HashTable*>(dateTable)); 172 fastDelete(const_cast<HashTable*>(jsonTable)); 169 173 fastDelete(const_cast<HashTable*>(mathTable)); 170 174 fastDelete(const_cast<HashTable*>(numberTable)); -
trunk/JavaScriptCore/runtime/JSGlobalData.h
r44344 r44521 83 83 const HashTable* arrayTable; 84 84 const HashTable* dateTable; 85 const HashTable* jsonTable; 85 86 const HashTable* mathTable; 86 87 const HashTable* numberTable; -
trunk/JavaScriptCore/runtime/JSGlobalObject.cpp
r44076 r44521 51 51 #include "JSGlobalObjectFunctions.h" 52 52 #include "JSLock.h" 53 #include "JSONObject.h" 53 54 #include "Interpreter.h" 54 55 #include "MathObject.h" … … 319 320 GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete), 320 321 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) 322 324 }; 323 325 -
trunk/LayoutTests/ChangeLog
r44519 r44521 1 2009-06-07 Oliver Hunt <oliver@apple.com> 2 3 Reviewed by Sam Weinig. 4 5 Bug 26249: Support JSON.stringify 6 <https://bugs.webkit.org/show_bug.cgi?id=26249> 7 8 Add test coverage for JSON.stringify -- covers use of replacer function, 9 replacer array, no replacer, numeric and string gaps. Also tests call 10 sequencing (toJSON, toString, replacer functions, and getters). 11 12 * fast/js/JSON-stringify-expected.txt: Added. 13 * fast/js/JSON-stringify.html: Added. 14 * fast/js/resources/JSON-stringify.js: Added. 15 * fast/js/resources/json2-es5-compat.js: Added. 16 Modified version of json2.js to force strict es5 semantics on stringify 17 to allow us to compare our results to the expected without having to 18 stuff large arbitrary strings into the testcase 19 1 20 2009-06-08 Brady Eidson <beidson@apple.com> 2 21
Note: See TracChangeset
for help on using the changeset viewer.