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

Unified 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: Fixed compile error on linux 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 17502bce90e8a7c512affbf8318bcb19f1e11136..fe214d72a14f7d1a3dd0e6f4fb6bc778c4659ebc 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -49,12 +49,12 @@
#include "src/profiler/heap-snapshot-generator-inl.h"
#include "src/profiler/profile-generator-inl.h"
#include "src/profiler/sampler.h"
-#include "src/property.h"
#include "src/property-descriptor.h"
#include "src/property-details.h"
+#include "src/property.h"
#include "src/prototype.h"
-#include "src/runtime/runtime.h"
#include "src/runtime-profiler.h"
+#include "src/runtime/runtime.h"
#include "src/simulator.h"
#include "src/snapshot/natives.h"
#include "src/snapshot/snapshot.h"
@@ -66,7 +66,6 @@
#include "src/version.h"
#include "src/vm-state-inl.h"
-
namespace v8 {
#define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
@@ -2749,13 +2748,38 @@ MaybeLocal<Value> JSON::Parse(Isolate* v8_isolate, Local<String> json_string) {
RETURN_ESCAPED(result);
}
+MaybeLocal<Value> JSON::Parse(Local<Context> context,
+ Local<String> json_string) {
+ PREPARE_FOR_EXECUTION(context, "JSON::Parse", Value);
+ i::Handle<i::String> string = Utils::OpenHandle(*json_string);
+ i::Handle<i::String> source = i::String::Flatten(string);
+ auto maybe = source->IsSeqOneByteString()
+ ? i::JsonParser<true>::Parse(source)
+ : i::JsonParser<false>::Parse(source);
+ Local<Value> result;
+ has_pending_exception = !ToLocal<Value>(maybe, &result);
+ RETURN_ON_FAILED_EXECUTION(Value);
+ RETURN_ESCAPED(result);
+}
Local<Value> JSON::Parse(Local<String> json_string) {
- auto isolate = reinterpret_cast<v8::Isolate*>(
- Utils::OpenHandle(*json_string)->GetIsolate());
- RETURN_TO_LOCAL_UNCHECKED(Parse(isolate, json_string), Value);
+ RETURN_TO_LOCAL_UNCHECKED(Parse(Local<Context>(), json_string), Value);
haavardm 2016/04/15 12:31:58 Is using an empty context correct here? (alternati
}
+MaybeLocal<String> JSON::Stringify(Local<Context> context,
+ Local<Object> json_object) {
+ PREPARE_FOR_EXECUTION(context, "JSON::Stringify", String);
+ i::Handle<i::Object> object = Utils::OpenHandle(*json_object);
+ i::Handle<i::Object> maybe;
+ has_pending_exception =
+ !i::Runtime::BasicJsonStringify(isolate, object).ToHandle(&maybe);
+ RETURN_ON_FAILED_EXECUTION(String);
+ Local<String> result;
+ has_pending_exception =
+ !ToLocal<String>(i::Object::ToString(isolate, maybe), &result);
+ RETURN_ON_FAILED_EXECUTION(String);
+ RETURN_ESCAPED(result);
+}
// --- D a t a ---
« no previous file with comments | « include/v8.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698