oliver@apple.com | 862c90b | 2009-06-10 00:37:01 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 2346a3e | 2011-09-07 19:40:41 +0000 | [diff] [blame] | 29 | #include "JSObject.h" |
oliver@apple.com | 862c90b | 2009-06-10 00:37:01 +0000 | [diff] [blame] | 30 | |
| 31 | namespace JSC { |
| 32 | |
darin@apple.com | c46cfaf | 2009-06-18 19:18:12 +0000 | [diff] [blame] | 33 | class Stringifier; |
| 34 | |
oliver@apple.com | 2346a3e | 2011-09-07 19:40:41 +0000 | [diff] [blame] | 35 | class JSONObject : public JSNonFinalObject { |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 36 | public: |
oliver@apple.com | 2346a3e | 2011-09-07 19:40:41 +0000 | [diff] [blame] | 37 | typedef JSNonFinalObject Base; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 38 | |
akling@apple.com | 1b4ebca | 2013-10-17 23:35:47 +0000 | [diff] [blame] | 39 | static JSONObject* create(VM& vm, Structure* structure) |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 40 | { |
akling@apple.com | 1b4ebca | 2013-10-17 23:35:47 +0000 | [diff] [blame] | 41 | JSONObject* object = new (NotNull, allocateCell<JSONObject>(vm.heap)) JSONObject(vm, structure); |
| 42 | object->finishCreation(vm); |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 43 | return object; |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 44 | } |
| 45 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 46 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
oliver@apple.com | 862c90b | 2009-06-10 00:37:01 +0000 | [diff] [blame] | 47 | { |
fpizlo@apple.com | 10ae2d0 | 2013-08-14 02:41:47 +0000 | [diff] [blame] | 48 | return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); |
oliver@apple.com | 862c90b | 2009-06-10 00:37:01 +0000 | [diff] [blame] | 49 | } |
oliver@apple.com | 4103716 | 2011-05-14 22:10:01 +0000 | [diff] [blame] | 50 | |
fpizlo@apple.com | 10ae2d0 | 2013-08-14 02:41:47 +0000 | [diff] [blame] | 51 | DECLARE_INFO; |
darin@apple.com | c46cfaf | 2009-06-18 19:18:12 +0000 | [diff] [blame] | 52 | |
oliver@apple.com | e9eda78 | 2009-10-17 01:06:40 +0000 | [diff] [blame] | 53 | protected: |
akling@apple.com | 1b4ebca | 2013-10-17 23:35:47 +0000 | [diff] [blame] | 54 | void finishCreation(VM&); |
oliver@apple.com | e9eda78 | 2009-10-17 01:06:40 +0000 | [diff] [blame] | 55 | static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags; |
| 56 | |
darin@apple.com | c46cfaf | 2009-06-18 19:18:12 +0000 | [diff] [blame] | 57 | private: |
akling@apple.com | 1b4ebca | 2013-10-17 23:35:47 +0000 | [diff] [blame] | 58 | JSONObject(VM&, Structure*); |
barraclough@apple.com | ab7b609 | 2013-07-31 19:03:05 +0000 | [diff] [blame] | 59 | static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); |
darin@apple.com | c46cfaf | 2009-06-18 19:18:12 +0000 | [diff] [blame] | 60 | |
oliver@apple.com | 862c90b | 2009-06-10 00:37:01 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
rniwa@webkit.org | 89ac896 | 2013-09-03 18:45:51 +0000 | [diff] [blame] | 63 | JS_EXPORT_PRIVATE JSValue JSONParse(ExecState*, const String&); |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 64 | String JSONStringify(ExecState*, JSValue, unsigned indent); |
oliver@apple.com | ba9acfd | 2010-03-18 20:51:23 +0000 | [diff] [blame] | 65 | |
oliver@apple.com | d055db6 | 2013-10-02 19:11:04 +0000 | [diff] [blame] | 66 | void escapeStringToBuilder(StringBuilder&, const String&); |
| 67 | |
oliver@apple.com | 862c90b | 2009-06-10 00:37:01 +0000 | [diff] [blame] | 68 | } // namespace JSC |
| 69 | |
| 70 | #endif // JSONObject_h |