source: webkit/trunk/JavaScriptCore/runtime/CommonIdentifiers.cpp@ 44813

Last change on this file since 44813 was 44813, checked in by Darin Adler, 16 years ago

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.
  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1/*
2 * Copyright (C) 2003, 2007, 2009 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#include "config.h"
22#include "CommonIdentifiers.h"
23
24namespace JSC {
25
26static const char* const nullCString = 0;
27
28#define INITIALIZE_PROPERTY_NAME(name) , name(globalData, #name)
29
30CommonIdentifiers::CommonIdentifiers(JSGlobalData* globalData)
31 : nullIdentifier(globalData, nullCString)
32 , emptyIdentifier(globalData, "")
33 , underscoreProto(globalData, "__proto__")
34 , thisIdentifier(globalData, "this")
35 JSC_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_PROPERTY_NAME)
36{
37}
38
39} // namespace JSC
Note: See TracBrowser for help on using the repository browser.