Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/api.cc

Issue 1891203002: Expose JSON stringifier through V8 API (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "src/json-parser.h" 42 #include "src/json-parser.h"
43 #include "src/messages.h" 43 #include "src/messages.h"
44 #include "src/parsing/parser.h" 44 #include "src/parsing/parser.h"
45 #include "src/parsing/scanner-character-streams.h" 45 #include "src/parsing/scanner-character-streams.h"
46 #include "src/pending-compilation-error-handler.h" 46 #include "src/pending-compilation-error-handler.h"
47 #include "src/profiler/cpu-profiler.h" 47 #include "src/profiler/cpu-profiler.h"
48 #include "src/profiler/heap-profiler.h" 48 #include "src/profiler/heap-profiler.h"
49 #include "src/profiler/heap-snapshot-generator-inl.h" 49 #include "src/profiler/heap-snapshot-generator-inl.h"
50 #include "src/profiler/profile-generator-inl.h" 50 #include "src/profiler/profile-generator-inl.h"
51 #include "src/profiler/sampler.h" 51 #include "src/profiler/sampler.h"
52 #include "src/property.h"
53 #include "src/property-descriptor.h" 52 #include "src/property-descriptor.h"
54 #include "src/property-details.h" 53 #include "src/property-details.h"
54 #include "src/property.h"
55 #include "src/prototype.h" 55 #include "src/prototype.h"
56 #include "src/runtime-profiler.h"
56 #include "src/runtime/runtime.h" 57 #include "src/runtime/runtime.h"
57 #include "src/runtime-profiler.h"
58 #include "src/simulator.h" 58 #include "src/simulator.h"
59 #include "src/snapshot/natives.h" 59 #include "src/snapshot/natives.h"
60 #include "src/snapshot/snapshot.h" 60 #include "src/snapshot/snapshot.h"
61 #include "src/startup-data-util.h" 61 #include "src/startup-data-util.h"
62 #include "src/tracing/trace-event.h" 62 #include "src/tracing/trace-event.h"
63 #include "src/unicode-inl.h" 63 #include "src/unicode-inl.h"
64 #include "src/v8.h" 64 #include "src/v8.h"
65 #include "src/v8threads.h" 65 #include "src/v8threads.h"
66 #include "src/version.h" 66 #include "src/version.h"
67 #include "src/vm-state-inl.h" 67 #include "src/vm-state-inl.h"
68 68
69
70 namespace v8 { 69 namespace v8 {
71 70
72 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) 71 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
73 72
74 73
75 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) 74 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate))
76 75
77 76
78 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ 77 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \
79 bailout_value, HandleScopeClass, \ 78 bailout_value, HandleScopeClass, \
(...skipping 2662 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 i::Handle<i::String> source = i::String::Flatten(string); 2741 i::Handle<i::String> source = i::String::Flatten(string);
2743 auto maybe = source->IsSeqOneByteString() 2742 auto maybe = source->IsSeqOneByteString()
2744 ? i::JsonParser<true>::Parse(source) 2743 ? i::JsonParser<true>::Parse(source)
2745 : i::JsonParser<false>::Parse(source); 2744 : i::JsonParser<false>::Parse(source);
2746 Local<Value> result; 2745 Local<Value> result;
2747 has_pending_exception = !ToLocal<Value>(maybe, &result); 2746 has_pending_exception = !ToLocal<Value>(maybe, &result);
2748 RETURN_ON_FAILED_EXECUTION(Value); 2747 RETURN_ON_FAILED_EXECUTION(Value);
2749 RETURN_ESCAPED(result); 2748 RETURN_ESCAPED(result);
2750 } 2749 }
2751 2750
2751 MaybeLocal<Value> JSON::Parse(Local<Context> context,
2752 Local<String> json_string) {
2753 PREPARE_FOR_EXECUTION(context, "JSON::Parse", Value);
2754 i::Handle<i::String> string = Utils::OpenHandle(*json_string);
2755 i::Handle<i::String> source = i::String::Flatten(string);
2756 auto maybe = source->IsSeqOneByteString()
2757 ? i::JsonParser<true>::Parse(source)
haavardm 2016/04/15 10:44:49 Does |context| end up in source? or is a new empty
jochen (gone - plz use gerrit) 2016/04/15 10:50:11 the PREPARE_FOR_EXECUTION macro will create a pote
2758 : i::JsonParser<false>::Parse(source);
2759 Local<Value> result;
2760 has_pending_exception = !ToLocal<Value>(maybe, &result);
2761 RETURN_ON_FAILED_EXECUTION(Value);
2762 RETURN_ESCAPED(result);
2763 }
2752 2764
2753 Local<Value> JSON::Parse(Local<String> json_string) { 2765 Local<Value> JSON::Parse(Local<String> json_string) {
2754 auto isolate = reinterpret_cast<v8::Isolate*>( 2766 auto isolate = reinterpret_cast<v8::Isolate*>(
2755 Utils::OpenHandle(*json_string)->GetIsolate()); 2767 Utils::OpenHandle(*json_string)->GetIsolate());
2756 RETURN_TO_LOCAL_UNCHECKED(Parse(isolate, json_string), Value); 2768 RETURN_TO_LOCAL_UNCHECKED(Parse(isolate, json_string), Value);
2757 } 2769 }
2758 2770
2771 MaybeLocal<String> JSON::Stringify(Isolate* v8_isolate,
2772 Local<Object> json_object) {
2773 auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2774 PREPARE_FOR_EXECUTION_WITH_ISOLATE(isolate, "JSON::Stringify", String);
2775 i::Handle<i::Object> object = Utils::OpenHandle(*json_object);
2776 i::Handle<i::Object> maybe;
2777 has_pending_exception =
2778 !i::Runtime::BasicJsonStringify(isolate, object).ToHandle(&maybe);
2779 RETURN_ON_FAILED_EXECUTION(String);
2780 Local<String> result;
2781 has_pending_exception =
2782 !ToLocal<String>(i::Object::ToString(isolate, maybe), &result);
2783 RETURN_ON_FAILED_EXECUTION(String);
2784 RETURN_ESCAPED(result);
2785 }
2759 2786
2760 // --- D a t a --- 2787 // --- D a t a ---
2761 2788
2762 bool Value::FullIsUndefined() const { 2789 bool Value::FullIsUndefined() const {
2763 bool result = Utils::OpenHandle(this)->IsUndefined(); 2790 bool result = Utils::OpenHandle(this)->IsUndefined();
2764 DCHECK_EQ(result, QuickIsUndefined()); 2791 DCHECK_EQ(result, QuickIsUndefined());
2765 return result; 2792 return result;
2766 } 2793 }
2767 2794
2768 2795
(...skipping 6021 matching lines...) Expand 10 before | Expand all | Expand 10 after
8790 Address callback_address = 8817 Address callback_address =
8791 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8818 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8792 VMState<EXTERNAL> state(isolate); 8819 VMState<EXTERNAL> state(isolate);
8793 ExternalCallbackScope call_scope(isolate, callback_address); 8820 ExternalCallbackScope call_scope(isolate, callback_address);
8794 callback(info); 8821 callback(info);
8795 } 8822 }
8796 8823
8797 8824
8798 } // namespace internal 8825 } // namespace internal
8799 } // namespace v8 8826 } // namespace v8
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698