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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 28 matching lines...) Expand all
39 #include "conversions-inl.h" 39 #include "conversions-inl.h"
40 #include "counters.h" 40 #include "counters.h"
41 #include "cpu-profiler.h" 41 #include "cpu-profiler.h"
42 #include "debug.h" 42 #include "debug.h"
43 #include "deoptimizer.h" 43 #include "deoptimizer.h"
44 #include "execution.h" 44 #include "execution.h"
45 #include "global-handles.h" 45 #include "global-handles.h"
46 #include "heap-profiler.h" 46 #include "heap-profiler.h"
47 #include "heap-snapshot-generator-inl.h" 47 #include "heap-snapshot-generator-inl.h"
48 #include "icu_util.h" 48 #include "icu_util.h"
49 #include "json-parser.h"
49 #include "messages.h" 50 #include "messages.h"
50 #ifdef COMPRESS_STARTUP_DATA_BZ2 51 #ifdef COMPRESS_STARTUP_DATA_BZ2
51 #include "natives.h" 52 #include "natives.h"
52 #endif 53 #endif
53 #include "parser.h" 54 #include "parser.h"
54 #include "platform.h" 55 #include "platform.h"
55 #include "profile-generator-inl.h" 56 #include "profile-generator-inl.h"
56 #include "property-details.h" 57 #include "property-details.h"
57 #include "property.h" 58 #include "property.h"
58 #include "runtime.h" 59 #include "runtime.h"
(...skipping 2541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 2601 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2601 if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false; 2602 if (IsDeadCheck(isolate, "v8::StackFrame::IsConstructor()")) return false;
2602 ENTER_V8(isolate); 2603 ENTER_V8(isolate);
2603 i::HandleScope scope(isolate); 2604 i::HandleScope scope(isolate);
2604 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 2605 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
2605 i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor"); 2606 i::Handle<i::Object> is_constructor = GetProperty(self, "isConstructor");
2606 return is_constructor->IsTrue(); 2607 return is_constructor->IsTrue();
2607 } 2608 }
2608 2609
2609 2610
2611 // --- J S O N ---
2612
2613 Local<Object> JSON::Parse(Local<String> json_string) {
2614 i::Isolate* isolate = i::Isolate::Current();
2615 EnsureInitializedForIsolate(isolate, "v8::JSON::Parse");
2616 ENTER_V8(isolate);
2617 i::HandleScope scope(isolate);
2618 i::Handle<i::String> source = i::Handle<i::String>(
2619 Utils::OpenHandle(*json_string)->TryFlattenGetString());
Yang 2013/08/05 10:52:35 I would prefer FlattenGetString here. While you ar
2620 EXCEPTION_PREAMBLE(isolate);
2621 i::Handle<i::Object> result;
2622 if (source->IsSeqOneByteString()) {
2623 result = i::JsonParser<true>::Parse(source);
2624 } else {
2625 result = i::JsonParser<false>::Parse(source);
2626 }
2627 has_pending_exception = result.is_null();
2628 EXCEPTION_BAILOUT_CHECK(isolate, Local<Object>());
2629 return Utils::ToLocal(
2630 i::Handle<i::JSObject>::cast(scope.CloseAndEscape(result)));
2631 }
2632
2633
2610 // --- D a t a --- 2634 // --- D a t a ---
2611 2635
2612 bool Value::FullIsUndefined() const { 2636 bool Value::FullIsUndefined() const {
2613 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) { 2637 if (IsDeadCheck(i::Isolate::Current(), "v8::Value::IsUndefined()")) {
2614 return false; 2638 return false;
2615 } 2639 }
2616 bool result = Utils::OpenHandle(this)->IsUndefined(); 2640 bool result = Utils::OpenHandle(this)->IsUndefined();
2617 ASSERT_EQ(result, QuickIsUndefined()); 2641 ASSERT_EQ(result, QuickIsUndefined());
2618 return result; 2642 return result;
2619 } 2643 }
(...skipping 5516 matching lines...) Expand 10 before | Expand all | Expand 10 after
8136 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8160 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8137 Address callback_address = 8161 Address callback_address =
8138 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8162 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8139 VMState<EXTERNAL> state(isolate); 8163 VMState<EXTERNAL> state(isolate);
8140 ExternalCallbackScope call_scope(isolate, callback_address); 8164 ExternalCallbackScope call_scope(isolate, callback_address);
8141 return callback(info); 8165 return callback(info);
8142 } 8166 }
8143 8167
8144 8168
8145 } } // namespace v8::internal 8169 } } // namespace v8::internal
OLDNEW
« 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