2
* Copyright (C) 2009 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#include "JSONObject.h"
29
#include "BooleanObject.h"
31
#include "ExceptionHelpers.h"
33
#include "LiteralParser.h"
34
#include "PropertyNameArray.h"
35
#include <wtf/MathExtras.h>
39
ASSERT_CLASS_FITS_IN_CELL(JSONObject);
41
static JSValue JSC_HOST_CALL JSONProtoFuncParse(ExecState*, JSObject*, JSValue, const ArgList&);
42
static JSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState*, JSObject*, JSValue, const ArgList&);
46
#include "JSONObject.lut.h"
50
// PropertyNameForFunctionCall objects must be on the stack, since the JSValue that they create is not marked.
51
class PropertyNameForFunctionCall {
53
PropertyNameForFunctionCall(const Identifier&);
54
PropertyNameForFunctionCall(unsigned);
56
JSValue value(ExecState*) const;
59
const Identifier* m_identifier;
61
mutable JSValue m_value;
64
class Stringifier : public Noncopyable {
66
Stringifier(ExecState*, JSValue replacer, JSValue space);
68
JSValue stringify(JSValue);
70
void markAggregate(MarkStack&);
73
typedef UString StringBuilder;
79
JSObject* object() const { return m_object; }
81
bool appendNextProperty(Stringifier&, StringBuilder&);
84
JSObject* const m_object;
89
RefPtr<PropertyNameArrayData> m_propertyNames;
94
static void appendQuotedString(StringBuilder&, const UString&);
96
JSValue toJSON(JSValue, const PropertyNameForFunctionCall&);
98
enum StringifyResult { StringifyFailed, StringifySucceeded, StringifyFailedDueToUndefinedValue };
99
StringifyResult appendStringifiedValue(StringBuilder&, JSValue, JSObject* holder, const PropertyNameForFunctionCall&);
101
bool willIndent() const;
104
void startNewLine(StringBuilder&) const;
106
Stringifier* const m_nextStringifierToMark;
107
ExecState* const m_exec;
108
const JSValue m_replacer;
109
bool m_usingArrayReplacer;
110
PropertyNameArray m_arrayReplacerPropertyNames;
111
CallType m_replacerCallType;
112
CallData m_replacerCallData;
115
HashSet<JSObject*> m_holderCycleDetector;
116
Vector<Holder, 16> m_holderStack;
117
UString m_repeatedGap;
121
// ------------------------------ helper functions --------------------------------
123
static inline JSValue unwrapBoxedPrimitive(ExecState* exec, JSValue value)
125
if (!value.isObject())
127
JSObject* object = asObject(value);
128
if (object->inherits(&NumberObject::info))
129
return jsNumber(exec, object->toNumber(exec));
130
if (object->inherits(&StringObject::info))
131
return jsString(exec, object->toString(exec));
132
if (object->inherits(&BooleanObject::info))
133
return object->toPrimitive(exec);
137
static inline UString gap(ExecState* exec, JSValue space)
139
const int maxGapLength = 10;
140
space = unwrapBoxedPrimitive(exec, space);
142
// If the space value is a number, create a gap string with that number of spaces.
144
if (space.getNumber(spaceCount)) {
146
if (spaceCount > maxGapLength)
147
count = maxGapLength;
148
else if (!(spaceCount > 0))
151
count = static_cast<int>(spaceCount);
152
UChar spaces[maxGapLength];
153
for (int i = 0; i < count; ++i)
155
return UString(spaces, count);
158
// If the space value is a string, use it as the gap string, otherwise use no gap string.
159
UString spaces = space.getString();
160
if (spaces.size() > maxGapLength) {
161
spaces = spaces.substr(0, maxGapLength);
166
// ------------------------------ PropertyNameForFunctionCall --------------------------------
168
inline PropertyNameForFunctionCall::PropertyNameForFunctionCall(const Identifier& identifier)
169
: m_identifier(&identifier)
173
inline PropertyNameForFunctionCall::PropertyNameForFunctionCall(unsigned number)
179
JSValue PropertyNameForFunctionCall::value(ExecState* exec) const
183
m_value = jsString(exec, m_identifier->ustring());
185
m_value = jsNumber(exec, m_number);
190
// ------------------------------ Stringifier --------------------------------
192
Stringifier::Stringifier(ExecState* exec, JSValue replacer, JSValue space)
193
: m_nextStringifierToMark(exec->globalData().firstStringifierToMark)
195
, m_replacer(replacer)
196
, m_usingArrayReplacer(false)
197
, m_arrayReplacerPropertyNames(exec)
198
, m_replacerCallType(CallTypeNone)
199
, m_gap(gap(exec, space))
201
exec->globalData().firstStringifierToMark = this;
203
if (!m_replacer.isObject())
206
if (asObject(m_replacer)->inherits(&JSArray::info)) {
207
m_usingArrayReplacer = true;
208
JSObject* array = asObject(m_replacer);
209
unsigned length = array->get(exec, exec->globalData().propertyNames->length).toUInt32(exec);
210
for (unsigned i = 0; i < length; ++i) {
211
JSValue name = array->get(exec, i);
212
if (exec->hadException())
215
UString propertyName;
216
if (name.getString(propertyName)) {
217
m_arrayReplacerPropertyNames.add(Identifier(exec, propertyName));
222
if (name.getNumber(value)) {
223
m_arrayReplacerPropertyNames.add(Identifier::from(exec, value));
227
if (name.isObject()) {
228
if (!asObject(name)->inherits(&NumberObject::info) && !asObject(name)->inherits(&StringObject::info))
230
propertyName = name.toString(exec);
231
if (exec->hadException())
233
m_arrayReplacerPropertyNames.add(Identifier(exec, propertyName));
239
m_replacerCallType = asObject(m_replacer)->getCallData(m_replacerCallData);
242
Stringifier::~Stringifier()
244
ASSERT(m_exec->globalData().firstStringifierToMark == this);
245
m_exec->globalData().firstStringifierToMark = m_nextStringifierToMark;
248
void Stringifier::markAggregate(MarkStack& markStack)
250
for (Stringifier* stringifier = this; stringifier; stringifier = stringifier->m_nextStringifierToMark) {
251
size_t size = m_holderStack.size();
252
for (size_t i = 0; i < size; ++i)
253
markStack.append(m_holderStack[i].object());
257
JSValue Stringifier::stringify(JSValue value)
259
JSObject* object = constructEmptyObject(m_exec);
260
if (m_exec->hadException())
263
PropertyNameForFunctionCall emptyPropertyName(m_exec->globalData().propertyNames->emptyIdentifier);
264
object->putDirect(m_exec->globalData().propertyNames->emptyIdentifier, value);
266
StringBuilder result;
267
if (appendStringifiedValue(result, value, object, emptyPropertyName) != StringifySucceeded)
268
return jsUndefined();
269
if (m_exec->hadException())
272
return jsString(m_exec, result);
275
void Stringifier::appendQuotedString(StringBuilder& builder, const UString& value)
277
int length = value.size();
279
// String length plus 2 for quote marks plus 8 so we can accomodate a few escaped characters.
280
builder.reserveCapacity(builder.size() + length + 2 + 8);
284
const UChar* data = value.data();
285
for (int i = 0; i < length; ++i) {
287
while (i < length && (data[i] > 0x1F && data[i] != '"' && data[i] != '\\'))
289
builder.append(data + start, i - start);
294
builder.append('\\');
298
builder.append('\\');
302
builder.append('\\');
306
builder.append('\\');
310
builder.append('\\');
314
builder.append('\\');
318
builder.append('\\');
319
builder.append('\\');
322
static const char hexDigits[] = "0123456789abcdef";
324
UChar hex[] = { '\\', 'u', hexDigits[(ch >> 12) & 0xF], hexDigits[(ch >> 8) & 0xF], hexDigits[(ch >> 4) & 0xF], hexDigits[ch & 0xF] };
325
builder.append(hex, sizeof(hex) / sizeof(UChar));
333
inline JSValue Stringifier::toJSON(JSValue value, const PropertyNameForFunctionCall& propertyName)
335
ASSERT(!m_exec->hadException());
336
if (!value.isObject() || !asObject(value)->hasProperty(m_exec, m_exec->globalData().propertyNames->toJSON))
339
JSValue toJSONFunction = asObject(value)->get(m_exec, m_exec->globalData().propertyNames->toJSON);
340
if (m_exec->hadException())
343
if (!toJSONFunction.isObject())
346
JSObject* object = asObject(toJSONFunction);
348
CallType callType = object->getCallData(callData);
349
if (callType == CallTypeNone)
352
JSValue list[] = { propertyName.value(m_exec) };
353
ArgList args(list, sizeof(list) / sizeof(JSValue));
354
return call(m_exec, object, callType, callData, value, args);
357
Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder& builder, JSValue value, JSObject* holder, const PropertyNameForFunctionCall& propertyName)
359
// Call the toJSON function.
360
value = toJSON(value, propertyName);
361
if (m_exec->hadException())
362
return StringifyFailed;
364
// Call the replacer function.
365
if (m_replacerCallType != CallTypeNone) {
366
JSValue list[] = { propertyName.value(m_exec), value };
367
ArgList args(list, sizeof(list) / sizeof(JSValue));
368
value = call(m_exec, m_replacer, m_replacerCallType, m_replacerCallData, holder, args);
369
if (m_exec->hadException())
370
return StringifyFailed;
373
if (value.isUndefined() && !holder->inherits(&JSArray::info))
374
return StringifyFailedDueToUndefinedValue;
376
if (value.isNull()) {
377
builder.append("null");
378
return StringifySucceeded;
381
value = unwrapBoxedPrimitive(m_exec, value);
383
if (m_exec->hadException())
384
return StringifyFailed;
386
if (value.isBoolean()) {
387
builder.append(value.getBoolean() ? "true" : "false");
388
return StringifySucceeded;
392
if (value.getString(stringValue)) {
393
appendQuotedString(builder, stringValue);
394
return StringifySucceeded;
398
if (value.getNumber(numericValue)) {
399
if (!isfinite(numericValue))
400
builder.append("null");
402
builder.append(UString::from(numericValue));
403
return StringifySucceeded;
406
if (!value.isObject())
407
return StringifyFailed;
409
JSObject* object = asObject(value);
412
if (object->getCallData(callData) != CallTypeNone) {
413
if (holder->inherits(&JSArray::info)) {
414
builder.append("null");
415
return StringifySucceeded;
417
return StringifyFailedDueToUndefinedValue;
420
// Handle cycle detection, and put the holder on the stack.
421
if (!m_holderCycleDetector.add(object).second) {
422
throwError(m_exec, TypeError, "JSON.stringify cannot serialize cyclic structures.");
423
return StringifyFailed;
425
bool holderStackWasEmpty = m_holderStack.isEmpty();
426
m_holderStack.append(object);
427
if (!holderStackWasEmpty)
428
return StringifySucceeded;
430
// If this is the outermost call, then loop to handle everything on the holder stack.
431
//TimeoutChecker localTimeoutChecker(*m_exec->globalData().timeoutChecker);
432
TimeoutChecker localTimeoutChecker;
433
localTimeoutChecker.copyTimeoutValues(m_exec->globalData().timeoutChecker);
434
localTimeoutChecker.reset();
435
unsigned tickCount = localTimeoutChecker.ticksUntilNextCheck();
437
while (m_holderStack.last().appendNextProperty(*this, builder)) {
438
if (m_exec->hadException())
439
return StringifyFailed;
441
if (localTimeoutChecker.didTimeOut(m_exec)) {
442
m_exec->setException(createInterruptedExecutionException(&m_exec->globalData()));
443
return StringifyFailed;
445
tickCount = localTimeoutChecker.ticksUntilNextCheck();
448
m_holderCycleDetector.remove(m_holderStack.last().object());
449
m_holderStack.removeLast();
450
} while (!m_holderStack.isEmpty());
451
return StringifySucceeded;
454
inline bool Stringifier::willIndent() const
456
return !m_gap.isEmpty();
459
inline void Stringifier::indent()
461
// Use a single shared string, m_repeatedGap, so we don't keep allocating new ones as we indent and unindent.
462
int newSize = m_indent.size() + m_gap.size();
463
if (newSize > m_repeatedGap.size())
464
m_repeatedGap.append(m_gap);
465
ASSERT(newSize <= m_repeatedGap.size());
466
m_indent = m_repeatedGap.substr(0, newSize);
469
inline void Stringifier::unindent()
471
ASSERT(m_indent.size() >= m_gap.size());
472
m_indent = m_repeatedGap.substr(0, m_indent.size() - m_gap.size());
475
inline void Stringifier::startNewLine(StringBuilder& builder) const
479
builder.append('\n');
480
builder.append(m_indent);
483
inline Stringifier::Holder::Holder(JSObject* object)
485
, m_isArray(object->inherits(&JSArray::info))
490
bool Stringifier::Holder::appendNextProperty(Stringifier& stringifier, StringBuilder& builder)
492
ASSERT(m_index <= m_size);
494
ExecState* exec = stringifier.m_exec;
496
// First time through, initialize.
499
m_isJSArray = isJSArray(&exec->globalData(), m_object);
500
m_size = m_object->get(exec, exec->globalData().propertyNames->length).toUInt32(exec);
503
if (stringifier.m_usingArrayReplacer)
504
m_propertyNames = stringifier.m_arrayReplacerPropertyNames.data();
506
PropertyNameArray objectPropertyNames(exec);
507
m_object->getPropertyNames(exec, objectPropertyNames);
508
m_propertyNames = objectPropertyNames.releaseData();
510
m_size = m_propertyNames->propertyNameVector().size();
513
stringifier.indent();
516
// Last time through, finish up and return false.
517
if (m_index == m_size) {
518
stringifier.unindent();
519
if (m_size && builder[builder.size() - 1] != '{')
520
stringifier.startNewLine(builder);
521
builder.append(m_isArray ? ']' : '}');
525
// Handle a single element of the array or object.
526
unsigned index = m_index++;
527
unsigned rollBackPoint = 0;
528
StringifyResult stringifyResult;
532
if (m_isJSArray && asArray(m_object)->canGetIndex(index))
533
value = asArray(m_object)->getIndex(index);
535
PropertySlot slot(m_object);
536
if (!m_object->getOwnPropertySlot(exec, index, slot))
538
if (exec->hadException())
540
value = slot.getValue(exec, index);
543
// Append the separator string.
546
stringifier.startNewLine(builder);
548
// Append the stringified value.
549
stringifyResult = stringifier.appendStringifiedValue(builder, value, m_object, index);
552
PropertySlot slot(m_object);
553
Identifier& propertyName = m_propertyNames->propertyNameVector()[index];
554
if (!m_object->getOwnPropertySlot(exec, propertyName, slot))
556
JSValue value = slot.getValue(exec, propertyName);
557
if (exec->hadException())
560
rollBackPoint = builder.size();
562
// Append the separator string.
563
if (builder[rollBackPoint - 1] != '{')
565
stringifier.startNewLine(builder);
567
// Append the property name.
568
appendQuotedString(builder, propertyName.ustring());
570
if (stringifier.willIndent())
573
// Append the stringified value.
574
stringifyResult = stringifier.appendStringifiedValue(builder, value, m_object, propertyName);
577
// From this point on, no access to the this pointer or to any members, because the
578
// Holder object may have moved if the call to stringify pushed a new Holder onto
581
switch (stringifyResult) {
582
case StringifyFailed:
583
builder.append("null");
585
case StringifySucceeded:
587
case StringifyFailedDueToUndefinedValue:
588
// This only occurs when get an undefined value for an object property.
589
// In this case we don't want the separator and property name that we
590
// already appended, so roll back.
591
builder = builder.substr(0, rollBackPoint);
598
// ------------------------------ JSONObject --------------------------------
600
const ClassInfo JSONObject::info = { "JSON", 0, 0, ExecState::jsonTable };
602
/* Source for JSONObject.lut.h
604
parse JSONProtoFuncParse DontEnum|Function 1
605
stringify JSONProtoFuncStringify DontEnum|Function 1
611
bool JSONObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
613
return getStaticFunctionSlot<JSObject>(exec, ExecState::jsonTable(exec), this, propertyName, slot);
616
bool JSONObject::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
618
return getStaticFunctionDescriptor<JSObject>(exec, ExecState::jsonTable(exec), this, propertyName, descriptor);
621
void JSONObject::markStringifiers(MarkStack& markStack, Stringifier* stringifier)
623
stringifier->markAggregate(markStack);
628
Walker(ExecState* exec, JSObject* function, CallType callType, CallData callData)
630
, m_function(function)
631
, m_callType(callType)
632
, m_callData(callData)
635
JSValue walk(JSValue unfiltered);
637
JSValue callReviver(JSObject* thisObj, JSValue property, JSValue unfiltered)
639
JSValue args[] = { property, unfiltered };
640
ArgList argList(args, 2);
641
return call(m_exec, m_function, m_callType, m_callData, thisObj, argList);
647
JSObject* m_function;
652
// We clamp recursion well beyond anything reasonable, but we also have a timeout check
653
// to guard against "infinite" execution by inserting arbitrarily large objects.
654
static const unsigned maximumFilterRecursion = 40000;
655
enum WalkerState { StateUnknown, ArrayStartState, ArrayStartVisitMember, ArrayEndVisitMember,
656
ObjectStartState, ObjectStartVisitMember, ObjectEndVisitMember };
657
NEVER_INLINE JSValue Walker::walk(JSValue unfiltered)
659
Vector<PropertyNameArray, 16> propertyStack;
660
Vector<uint32_t, 16> indexStack;
661
Vector<JSObject*, 16> objectStack;
662
Vector<JSArray*, 16> arrayStack;
664
Vector<WalkerState, 16> stateStack;
665
WalkerState state = StateUnknown;
666
JSValue inValue = unfiltered;
667
JSValue outValue = jsNull();
669
TimeoutChecker localTimeoutChecker;
670
localTimeoutChecker.copyTimeoutValues(m_exec->globalData().timeoutChecker);
671
localTimeoutChecker.reset();
672
unsigned tickCount = localTimeoutChecker.ticksUntilNextCheck();
676
case ArrayStartState: {
677
ASSERT(inValue.isObject());
678
ASSERT(isJSArray(&m_exec->globalData(), asObject(inValue)) || asObject(inValue)->inherits(&JSArray::info));
679
if (objectStack.size() + arrayStack.size() > maximumFilterRecursion) {
680
m_exec->setException(createStackOverflowError(m_exec));
681
return jsUndefined();
684
JSArray* array = asArray(inValue);
685
arrayStack.append(array);
686
indexStack.append(0);
689
arrayStartVisitMember:
690
case ArrayStartVisitMember: {
692
if (localTimeoutChecker.didTimeOut(m_exec)) {
693
m_exec->setException(createInterruptedExecutionException(&m_exec->globalData()));
694
return jsUndefined();
696
tickCount = localTimeoutChecker.ticksUntilNextCheck();
699
JSArray* array = arrayStack.last();
700
uint32_t index = indexStack.last();
701
if (index == array->length()) {
703
arrayStack.removeLast();
704
indexStack.removeLast();
707
if (isJSArray(&m_exec->globalData(), array) && array->canGetIndex(index))
708
inValue = array->getIndex(index);
711
if (array->getOwnPropertySlot(m_exec, index, slot))
712
inValue = slot.getValue(m_exec, index);
714
inValue = jsUndefined();
717
if (inValue.isObject()) {
718
stateStack.append(ArrayEndVisitMember);
724
case ArrayEndVisitMember: {
725
JSArray* array = arrayStack.last();
726
JSValue filteredValue = callReviver(array, jsString(m_exec, UString::from(indexStack.last())), outValue);
727
if (filteredValue.isUndefined())
728
array->deleteProperty(m_exec, indexStack.last());
730
if (isJSArray(&m_exec->globalData(), array) && array->canSetIndex(indexStack.last()))
731
array->setIndex(indexStack.last(), filteredValue);
733
array->put(m_exec, indexStack.last(), filteredValue);
735
if (m_exec->hadException())
738
goto arrayStartVisitMember;
741
case ObjectStartState: {
742
ASSERT(inValue.isObject());
743
ASSERT(!isJSArray(&m_exec->globalData(), asObject(inValue)) && !asObject(inValue)->inherits(&JSArray::info));
744
if (objectStack.size() + arrayStack.size() > maximumFilterRecursion) {
745
m_exec->setException(createStackOverflowError(m_exec));
746
return jsUndefined();
749
JSObject* object = asObject(inValue);
750
objectStack.append(object);
751
indexStack.append(0);
752
propertyStack.append(PropertyNameArray(m_exec));
753
object->getPropertyNames(m_exec, propertyStack.last());
756
objectStartVisitMember:
757
case ObjectStartVisitMember: {
759
if (localTimeoutChecker.didTimeOut(m_exec)) {
760
m_exec->setException(createInterruptedExecutionException(&m_exec->globalData()));
761
return jsUndefined();
763
tickCount = localTimeoutChecker.ticksUntilNextCheck();
766
JSObject* object = objectStack.last();
767
uint32_t index = indexStack.last();
768
PropertyNameArray& properties = propertyStack.last();
769
if (index == properties.size()) {
771
objectStack.removeLast();
772
indexStack.removeLast();
773
propertyStack.removeLast();
777
if (object->getOwnPropertySlot(m_exec, properties[index], slot))
778
inValue = slot.getValue(m_exec, properties[index]);
780
inValue = jsUndefined();
782
// The holder may be modified by the reviver function so any lookup may throw
783
if (m_exec->hadException())
786
if (inValue.isObject()) {
787
stateStack.append(ObjectEndVisitMember);
793
case ObjectEndVisitMember: {
794
JSObject* object = objectStack.last();
795
Identifier prop = propertyStack.last()[indexStack.last()];
796
PutPropertySlot slot;
797
JSValue filteredValue = callReviver(object, jsString(m_exec, prop.ustring()), outValue);
798
if (filteredValue.isUndefined())
799
object->deleteProperty(m_exec, prop);
801
object->put(m_exec, prop, filteredValue, slot);
802
if (m_exec->hadException())
805
goto objectStartVisitMember;
809
if (!inValue.isObject()) {
813
JSObject* object = asObject(inValue);
814
if (isJSArray(&m_exec->globalData(), object) || object->inherits(&JSArray::info))
815
goto arrayStartState;
816
goto objectStartState;
818
if (stateStack.isEmpty())
821
state = stateStack.last();
822
stateStack.removeLast();
825
if (localTimeoutChecker.didTimeOut(m_exec)) {
826
m_exec->setException(createInterruptedExecutionException(&m_exec->globalData()));
827
return jsUndefined();
829
tickCount = localTimeoutChecker.ticksUntilNextCheck();
832
JSObject* finalHolder = constructEmptyObject(m_exec);
833
PutPropertySlot slot;
834
finalHolder->put(m_exec, m_exec->globalData().propertyNames->emptyIdentifier, outValue, slot);
835
return callReviver(finalHolder, jsEmptyString(m_exec), outValue);
838
// ECMA-262 v5 15.12.2
839
JSValue JSC_HOST_CALL JSONProtoFuncParse(ExecState* exec, JSObject*, JSValue, const ArgList& args)
842
return throwError(exec, GeneralError, "JSON.parse requires at least one parameter");
843
JSValue value = args.at(0);
844
UString source = value.toString(exec);
845
if (exec->hadException())
848
LiteralParser jsonParser(exec, source, LiteralParser::StrictJSON);
849
JSValue unfiltered = jsonParser.tryLiteralParse();
851
return throwError(exec, SyntaxError, "Unable to parse JSON string");
856
JSValue function = args.at(1);
858
CallType callType = function.getCallData(callData);
859
if (callType == CallTypeNone)
861
return Walker(exec, asObject(function), callType, callData).walk(unfiltered);
864
// ECMA-262 v5 15.12.3
865
JSValue JSC_HOST_CALL JSONProtoFuncStringify(ExecState* exec, JSObject*, JSValue, const ArgList& args)
868
return throwError(exec, GeneralError, "No input to stringify");
869
JSValue value = args.at(0);
870
JSValue replacer = args.at(1);
871
JSValue space = args.at(2);
872
return Stringifier(exec, replacer, space).stringify(value);