| Index: src/json-parser.h
|
| diff --git a/src/json-parser.h b/src/json-parser.h
|
| index 152bd637161a824d8aea9fac046498369419edb9..72c69100d1651baaa893257e0ace9ef43b1624b8 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,13 +197,14 @@ 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;
|
|
|
|
|
| private:
|
| + Zone* zone() { return &zone_; }
|
| +
|
| Handle<String> source_;
|
| int source_length_;
|
| Handle<SeqOneByteString> seq_source_;
|
| @@ -193,32 +212,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 +265,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,7 +324,6 @@ 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(), DELETE_ON_EXIT);
|
| ZoneList<Handle<Object> > properties(8, zone());
|
| ASSERT_EQ(c0_, '{');
|
|
|
| @@ -469,7 +469,6 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
|
| template <bool seq_ascii>
|
| Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
|
| HandleScope scope(isolate());
|
| - ZoneScope zone_scope(zone(), DELETE_ON_EXIT);
|
| ZoneList<Handle<Object> > elements(4, zone());
|
| ASSERT_EQ(c0_, '[');
|
|
|
|
|