Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/v8.h" |
| 6 | |
| 7 | #include "src/arguments.h" |
| 8 | #include "src/json-parser.h" |
| 9 | #include "src/json-stringifier.h" |
| 10 | #include "src/runtime/runtime-utils.h" |
| 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
| 15 | RUNTIME_FUNCTION(Runtime_QuoteJSONString) { |
| 16 | HandleScope scope(isolate); |
| 17 | CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
| 18 | DCHECK(args.length() == 1); |
| 19 | Handle<Object> result; |
| 20 | ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 21 | isolate, result, BasicJsonStringifier::StringifyString(isolate, string)); |
| 22 | return *result; |
| 23 | } |
| 24 | |
| 25 | |
| 26 | RUNTIME_FUNCTION(Runtime_BasicJSONStringify) { |
| 27 | HandleScope scope(isolate); |
| 28 | DCHECK(args.length() == 1); |
| 29 | CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 30 | BasicJsonStringifier stringifier(isolate); |
| 31 | Handle<Object> result; |
| 32 | ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 33 | stringifier.Stringify(object)); |
| 34 | return *result; |
| 35 | } |
| 36 | |
| 37 | |
| 38 | RUNTIME_FUNCTION(Runtime_ParseJson) { |
| 39 | HandleScope scope(isolate); |
| 40 | DCHECK(args.length() == 1); |
| 41 | CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| 42 | |
| 43 | source = String::Flatten(source); |
| 44 | // Optimized fast case where we only have Latin1 characters. |
| 45 | Handle<Object> result; |
| 46 | ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, |
| 47 | source->IsSeqOneByteString() |
| 48 | ? JsonParser<true>::Parse(source) |
| 49 | : JsonParser<false>::Parse(source)); |
| 50 | return *result; |
| 51 | } |
| 52 | } |
| 53 | } // namespace v8::internal |