mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:12:43 +00:00 
			
		
		
		
	 6e19ab2bbc
			
		
	
	
		6e19ab2bbc
		
	
	
	
	
		
			
			We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
		
			
				
	
	
		
			52 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <LibJS/Runtime/Object.h>
 | |
| 
 | |
| namespace JS {
 | |
| 
 | |
| class JSONObject final : public Object {
 | |
|     JS_OBJECT(JSONObject, Object);
 | |
| 
 | |
| public:
 | |
|     virtual void initialize(Realm&) override;
 | |
|     virtual ~JSONObject() override = default;
 | |
| 
 | |
|     // The base implementation of stringify is exposed because it is used by
 | |
|     // test-js to communicate between the JS tests and the C++ test runner.
 | |
|     static ThrowCompletionOr<DeprecatedString> stringify_impl(VM&, Value value, Value replacer, Value space);
 | |
| 
 | |
|     static Value parse_json_value(VM&, JsonValue const&);
 | |
| 
 | |
| private:
 | |
|     explicit JSONObject(Realm&);
 | |
| 
 | |
|     struct StringifyState {
 | |
|         FunctionObject* replacer_function { nullptr };
 | |
|         HashTable<Object*> seen_objects;
 | |
|         DeprecatedString indent { DeprecatedString::empty() };
 | |
|         DeprecatedString gap;
 | |
|         Optional<Vector<DeprecatedString>> property_list;
 | |
|     };
 | |
| 
 | |
|     // Stringify helpers
 | |
|     static ThrowCompletionOr<DeprecatedString> serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder);
 | |
|     static ThrowCompletionOr<DeprecatedString> serialize_json_object(VM&, StringifyState&, Object&);
 | |
|     static ThrowCompletionOr<DeprecatedString> serialize_json_array(VM&, StringifyState&, Object&);
 | |
|     static DeprecatedString quote_json_string(DeprecatedString);
 | |
| 
 | |
|     // Parse helpers
 | |
|     static Object* parse_json_object(VM&, JsonObject const&);
 | |
|     static Array* parse_json_array(VM&, JsonArray const&);
 | |
|     static ThrowCompletionOr<Value> internalize_json_property(VM&, Object* holder, PropertyKey const& name, FunctionObject& reviver);
 | |
| 
 | |
|     JS_DECLARE_NATIVE_FUNCTION(stringify);
 | |
|     JS_DECLARE_NATIVE_FUNCTION(parse);
 | |
| };
 | |
| 
 | |
| }
 |