Chromium Code Reviews| Index: src/json-parser.h |
| diff --git a/src/json-parser.h b/src/json-parser.h |
| index 1e7ebd8c9eb5f5656349d95de41483b9b2fec661..b7794dfe6c0f67a89c7c5b5c263c52c747871041 100644 |
| --- a/src/json-parser.h |
| +++ b/src/json-parser.h |
| @@ -43,15 +43,33 @@ namespace internal { |
| template <bool seq_ascii> |
| class JsonParser BASE_EMBEDDED { |
| public: |
| - static Handle<Object> Parse(Handle<String> source, Zone* zone) { |
| - return JsonParser().ParseJson(source, zone); |
| + static Handle<Object> Parse(Handle<String> source) { |
| + return JsonParser(source).ParseJson(); |
| } |
| static const int kEndOfString = -1; |
| private: |
| + explicit JsonParser(Handle<String> source) |
| + : source_(source), |
| + source_length_(source->length()), |
| + isolate_(source->map()->GetHeap()->isolate()), |
| + factory_(isolate_->factory()), |
| + zone_(isolate_), |
| + object_constructor_(isolate_->native_context()->object_function(), |
| + isolate_), |
| + position_(-1) { |
| + FlattenString(source_); |
| + pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED; |
| + |
| + // Optimized fast case where we only have ASCII characters. |
| + if (seq_ascii) { |
| + seq_source_ = Handle<SeqOneByteString>::cast(source_); |
| + } |
| + } |
| + |
| // Parse a string containing a single JSON value. |
| - Handle<Object> ParseJson(Handle<String> source, Zone* zone); |
| + Handle<Object> ParseJson(); |
| inline void Advance() { |
| position_++; |
| @@ -179,7 +197,6 @@ class JsonParser BASE_EMBEDDED { |
| inline Isolate* isolate() { return isolate_; } |
| inline Factory* factory() { return factory_; } |
| inline Handle<JSFunction> object_constructor() { return object_constructor_; } |
| - inline Zone* zone() const { return zone_; } |
| static const int kInitialSpecialStringLength = 1024; |
| static const int kPretenureTreshold = 100 * 1024; |
| @@ -193,32 +210,14 @@ class JsonParser BASE_EMBEDDED { |
| PretenureFlag pretenure_; |
| Isolate* isolate_; |
| Factory* factory_; |
| + Zone zone_; |
| Handle<JSFunction> object_constructor_; |
| uc32 c0_; |
| int position_; |
| - Zone* zone_; |
| }; |
| template <bool seq_ascii> |
| -Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source, |
| - Zone* zone) { |
| - isolate_ = source->map()->GetHeap()->isolate(); |
| - factory_ = isolate_->factory(); |
| - object_constructor_ = Handle<JSFunction>( |
| - isolate()->native_context()->object_function(), isolate()); |
| - zone_ = zone; |
| - FlattenString(source); |
| - source_ = source; |
| - source_length_ = source_->length(); |
| - pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED; |
| - |
| - // Optimized fast case where we only have ASCII characters. |
| - if (seq_ascii) { |
| - seq_source_ = Handle<SeqOneByteString>::cast(source_); |
| - } |
| - |
| - // Set initial position right before the string. |
| - position_ = -1; |
| +Handle<Object> JsonParser<seq_ascii>::ParseJson() { |
| // Advance to the first character (possibly EOS) |
| AdvanceSkipWhitespace(); |
| Handle<Object> result = ParseJsonValue(); |
| @@ -264,7 +263,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source, |
| break; |
| } |
| - MessageLocation location(factory->NewScript(source), |
| + MessageLocation location(factory->NewScript(source_), |
| position_, |
| position_ + 1); |
| Handle<Object> result = factory->NewSyntaxError(message, array); |
| @@ -323,8 +322,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { |
| Handle<JSObject> json_object = |
| factory()->NewJSObject(object_constructor(), pretenure_); |
| Handle<Map> map(json_object->map()); |
| - ZoneScope zone_scope(zone()); |
| - ZoneList<Handle<Object> > properties(8, zone()); |
| + ZoneList<Handle<Object> > properties(8, &zone_); |
|
danno
2013/06/26 13:06:58
here an else where, does it make sense to wrap zon
Benedikt Meurer
2013/06/26 13:34:39
Done.
|
| ASSERT_EQ(c0_, '{'); |
| bool transitioning = true; |
| @@ -420,7 +418,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { |
| value = factory()->NewHeapNumber( |
| Handle<Smi>::cast(value)->value()); |
| } |
| - properties.Add(value, zone()); |
| + properties.Add(value, &zone_); |
| map = target; |
| continue; |
| } else { |
| @@ -469,8 +467,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { |
| template <bool seq_ascii> |
| Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { |
| HandleScope scope(isolate()); |
| - ZoneScope zone_scope(zone()); |
| - ZoneList<Handle<Object> > elements(4, zone()); |
| + ZoneList<Handle<Object> > elements(4, &zone_); |
| ASSERT_EQ(c0_, '['); |
| AdvanceSkipWhitespace(); |
| @@ -478,7 +475,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { |
| do { |
| Handle<Object> element = ParseJsonValue(); |
| if (element.is_null()) return ReportUnexpectedCharacter(); |
| - elements.Add(element, zone()); |
| + elements.Add(element, &zone_); |
| } while (MatchSkipWhiteSpace(',')); |
| if (c0_ != ']') { |
| return ReportUnexpectedCharacter(); |