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

Unified Diff: src/api.cc

Issue 21959003: Expose JSON parser through V8 API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 4 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') | test/cctest/test-api.cc » ('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 60627a39710443b4aef0b17ab570af6a1cc6c4bd..4c53977e707e101de372676770d77d4516e83c55 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -46,6 +46,7 @@
#include "heap-profiler.h"
#include "heap-snapshot-generator-inl.h"
#include "icu_util.h"
+#include "json-parser.h"
#include "messages.h"
#ifdef COMPRESS_STARTUP_DATA_BZ2
#include "natives.h"
@@ -2607,6 +2608,29 @@ bool StackFrame::IsConstructor() const {
}
+// --- J S O N ---
+
+Local<Object> JSON::Parse(Local<String> json_string) {
+ i::Isolate* isolate = i::Isolate::Current();
+ EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
+ ENTER_V8(isolate);
+ i::HandleScope scope(isolate);
+ i::Handle<i::String> source = i::Handle<i::String>(
+ Utils::OpenHandle(*json_string)->TryFlattenGetString());
Yang 2013/08/05 10:52:35 I would prefer FlattenGetString here. While you ar
+ EXCEPTION_PREAMBLE(isolate);
+ i::Handle<i::Object> result;
+ if (source->IsSeqOneByteString()) {
+ result = i::JsonParser<true>::Parse(source);
+ } else {
+ result = i::JsonParser<false>::Parse(source);
+ }
+ has_pending_exception = result.is_null();
+ EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
+ return Utils::ToLocal(
+ i::Handle<i::JSObject>::cast(scope.CloseAndEscape(result)));
+}
+
+
// --- D a t a ---
bool Value::FullIsUndefined() const {
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698