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

Side by Side Diff: src/json-parser.h

Issue 12880019: Create a new HandleScope for each JSON-parsed object to avoid excessive growth (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 284 }
285 return ReportUnexpectedCharacter(); 285 return ReportUnexpectedCharacter();
286 } 286 }
287 return ReportUnexpectedCharacter(); 287 return ReportUnexpectedCharacter();
288 } 288 }
289 289
290 290
291 // Parse a JSON object. Position must be right at '{'. 291 // Parse a JSON object. Position must be right at '{'.
292 template <bool seq_ascii> 292 template <bool seq_ascii>
293 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { 293 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
294 HandleScope scope(isolate());
294 Handle<JSObject> json_object = 295 Handle<JSObject> json_object =
295 factory()->NewJSObject(object_constructor(), pretenure_); 296 factory()->NewJSObject(object_constructor(), pretenure_);
296 ASSERT_EQ(c0_, '{'); 297 ASSERT_EQ(c0_, '{');
297 298
298 AdvanceSkipWhitespace(); 299 AdvanceSkipWhitespace();
299 if (c0_ != '}') { 300 if (c0_ != '}') {
300 do { 301 do {
301 if (c0_ != '"') return ReportUnexpectedCharacter(); 302 if (c0_ != '"') return ReportUnexpectedCharacter();
302 303
303 int start_position = position_; 304 int start_position = position_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } else { 352 } else {
352 JSObject::SetLocalPropertyIgnoreAttributes( 353 JSObject::SetLocalPropertyIgnoreAttributes(
353 json_object, key, value, NONE); 354 json_object, key, value, NONE);
354 } 355 }
355 } while (MatchSkipWhiteSpace(',')); 356 } while (MatchSkipWhiteSpace(','));
356 if (c0_ != '}') { 357 if (c0_ != '}') {
357 return ReportUnexpectedCharacter(); 358 return ReportUnexpectedCharacter();
358 } 359 }
359 } 360 }
360 AdvanceSkipWhitespace(); 361 AdvanceSkipWhitespace();
361 return json_object; 362 return scope.CloseAndEscape(json_object);
362 } 363 }
363 364
364 // Parse a JSON array. Position must be right at '['. 365 // Parse a JSON array. Position must be right at '['.
365 template <bool seq_ascii> 366 template <bool seq_ascii>
366 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { 367 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
368 HandleScope scope(isolate());
367 ZoneScope zone_scope(zone(), DELETE_ON_EXIT); 369 ZoneScope zone_scope(zone(), DELETE_ON_EXIT);
368 ZoneList<Handle<Object> > elements(4, zone()); 370 ZoneList<Handle<Object> > elements(4, zone());
369 ASSERT_EQ(c0_, '['); 371 ASSERT_EQ(c0_, '[');
370 372
371 AdvanceSkipWhitespace(); 373 AdvanceSkipWhitespace();
372 if (c0_ != ']') { 374 if (c0_ != ']') {
373 do { 375 do {
374 Handle<Object> element = ParseJsonValue(); 376 Handle<Object> element = ParseJsonValue();
375 if (element.is_null()) return ReportUnexpectedCharacter(); 377 if (element.is_null()) return ReportUnexpectedCharacter();
376 elements.Add(element, zone()); 378 elements.Add(element, zone());
377 } while (MatchSkipWhiteSpace(',')); 379 } while (MatchSkipWhiteSpace(','));
378 if (c0_ != ']') { 380 if (c0_ != ']') {
379 return ReportUnexpectedCharacter(); 381 return ReportUnexpectedCharacter();
380 } 382 }
381 } 383 }
382 AdvanceSkipWhitespace(); 384 AdvanceSkipWhitespace();
383 // Allocate a fixed array with all the elements. 385 // Allocate a fixed array with all the elements.
384 Handle<FixedArray> fast_elements = 386 Handle<FixedArray> fast_elements =
385 factory()->NewFixedArray(elements.length(), pretenure_); 387 factory()->NewFixedArray(elements.length(), pretenure_);
386 for (int i = 0, n = elements.length(); i < n; i++) { 388 for (int i = 0, n = elements.length(); i < n; i++) {
387 fast_elements->set(i, *elements[i]); 389 fast_elements->set(i, *elements[i]);
388 } 390 }
389 return factory()->NewJSArrayWithElements( 391 Handle<Object> json_array = factory()->NewJSArrayWithElements(
390 fast_elements, FAST_ELEMENTS, pretenure_); 392 fast_elements, FAST_ELEMENTS, pretenure_);
393 return scope.CloseAndEscape(json_array);
391 } 394 }
392 395
393 396
394 template <bool seq_ascii> 397 template <bool seq_ascii>
395 Handle<Object> JsonParser<seq_ascii>::ParseJsonNumber() { 398 Handle<Object> JsonParser<seq_ascii>::ParseJsonNumber() {
396 bool negative = false; 399 bool negative = false;
397 int beg_pos = position_; 400 int beg_pos = position_;
398 if (c0_ == '-') { 401 if (c0_ == '-') {
399 Advance(); 402 Advance();
400 negative = true; 403 negative = true;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 } 702 }
700 ASSERT_EQ('"', c0_); 703 ASSERT_EQ('"', c0_);
701 // Advance past the last '"'. 704 // Advance past the last '"'.
702 AdvanceSkipWhitespace(); 705 AdvanceSkipWhitespace();
703 return result; 706 return result;
704 } 707 }
705 708
706 } } // namespace v8::internal 709 } } // namespace v8::internal
707 710
708 #endif // V8_JSON_PARSER_H_ 711 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698