blob: c93c9c7ff1394490395911a26375b5ac376a6151 [file] [log] [blame]
oliver@apple.com862c90b2009-06-10 00:37:01 +00001/*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26#ifndef JSONObject_h
27#define JSONObject_h
28
oliver@apple.com2346a3e2011-09-07 19:40:41 +000029#include "JSObject.h"
oliver@apple.com862c90b2009-06-10 00:37:01 +000030
31namespace JSC {
32
darin@apple.comc46cfaf2009-06-18 19:18:12 +000033 class Stringifier;
34
oliver@apple.com2346a3e2011-09-07 19:40:41 +000035 class JSONObject : public JSNonFinalObject {
oliver@apple.comfcacd3c2011-07-18 17:47:13 +000036 public:
oliver@apple.com2346a3e2011-09-07 19:40:41 +000037 typedef JSNonFinalObject Base;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000038
akling@apple.com1b4ebca2013-10-17 23:35:47 +000039 static JSONObject* create(VM& vm, Structure* structure)
oliver@apple.comfcacd3c2011-07-18 17:47:13 +000040 {
akling@apple.com1b4ebca2013-10-17 23:35:47 +000041 JSONObject* object = new (NotNull, allocateCell<JSONObject>(vm.heap)) JSONObject(vm, structure);
42 object->finishCreation(vm);
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000043 return object;
oliver@apple.comfcacd3c2011-07-18 17:47:13 +000044 }
45
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000046 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
oliver@apple.com862c90b2009-06-10 00:37:01 +000047 {
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000048 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
oliver@apple.com862c90b2009-06-10 00:37:01 +000049 }
oliver@apple.com41037162011-05-14 22:10:01 +000050
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000051 DECLARE_INFO;
darin@apple.comc46cfaf2009-06-18 19:18:12 +000052
oliver@apple.come9eda782009-10-17 01:06:40 +000053 protected:
akling@apple.com1b4ebca2013-10-17 23:35:47 +000054 void finishCreation(VM&);
oliver@apple.come9eda782009-10-17 01:06:40 +000055 static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags;
56
darin@apple.comc46cfaf2009-06-18 19:18:12 +000057 private:
akling@apple.com1b4ebca2013-10-17 23:35:47 +000058 JSONObject(VM&, Structure*);
barraclough@apple.comab7b6092013-07-31 19:03:05 +000059 static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
darin@apple.comc46cfaf2009-06-18 19:18:12 +000060
oliver@apple.com862c90b2009-06-10 00:37:01 +000061 };
62
rniwa@webkit.org89ac8962013-09-03 18:45:51 +000063 JS_EXPORT_PRIVATE JSValue JSONParse(ExecState*, const String&);
benjamin@webkit.orgcff06e42012-08-30 21:23:51 +000064 String JSONStringify(ExecState*, JSValue, unsigned indent);
oliver@apple.comba9acfd2010-03-18 20:51:23 +000065
oliver@apple.comd055db62013-10-02 19:11:04 +000066 void escapeStringToBuilder(StringBuilder&, const String&);
67
oliver@apple.com862c90b2009-06-10 00:37:01 +000068} // namespace JSC
69
70#endif // JSONObject_h