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

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

Issue 12212011: Make __proto__ a foreign callback on Object.prototype. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added regression test for issue 2441. Created 7 years, 10 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 | « src/factory.cc ('k') | src/objects.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 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 283 }
284 return ReportUnexpectedCharacter(); 284 return ReportUnexpectedCharacter();
285 } 285 }
286 return ReportUnexpectedCharacter(); 286 return ReportUnexpectedCharacter();
287 } 287 }
288 288
289 289
290 // Parse a JSON object. Position must be right at '{'. 290 // Parse a JSON object. Position must be right at '{'.
291 template <bool seq_ascii> 291 template <bool seq_ascii>
292 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { 292 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
293 Handle<Object> prototype;
294 Handle<JSObject> json_object = 293 Handle<JSObject> json_object =
295 factory()->NewJSObject(object_constructor(), pretenure_); 294 factory()->NewJSObject(object_constructor(), pretenure_);
296 ASSERT_EQ(c0_, '{'); 295 ASSERT_EQ(c0_, '{');
297 296
298 AdvanceSkipWhitespace(); 297 AdvanceSkipWhitespace();
299 if (c0_ != '}') { 298 if (c0_ != '}') {
300 do { 299 do {
301 if (c0_ != '"') return ReportUnexpectedCharacter(); 300 if (c0_ != '"') return ReportUnexpectedCharacter();
302 301
303 int start_position = position_; 302 int start_position = position_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 c0_ = '"'; 337 c0_ = '"';
339 #endif 338 #endif
340 339
341 Handle<String> key = ParseJsonSymbol(); 340 Handle<String> key = ParseJsonSymbol();
342 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); 341 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter();
343 342
344 AdvanceSkipWhitespace(); 343 AdvanceSkipWhitespace();
345 Handle<Object> value = ParseJsonValue(); 344 Handle<Object> value = ParseJsonValue();
346 if (value.is_null()) return ReportUnexpectedCharacter(); 345 if (value.is_null()) return ReportUnexpectedCharacter();
347 346
348 if (key->Equals(isolate()->heap()->Proto_symbol())) { 347 if (JSObject::TryTransitionToField(json_object, key)) {
349 prototype = value; 348 int index = json_object->LastAddedFieldIndex();
349 json_object->FastPropertyAtPut(index, *value);
350 } else { 350 } else {
351 if (JSObject::TryTransitionToField(json_object, key)) { 351 JSObject::SetLocalPropertyIgnoreAttributes(
352 int index = json_object->LastAddedFieldIndex(); 352 json_object, key, value, NONE);
353 json_object->FastPropertyAtPut(index, *value);
354 } else {
355 JSObject::SetLocalPropertyIgnoreAttributes(
356 json_object, key, value, NONE);
357 }
358 } 353 }
359 } while (MatchSkipWhiteSpace(',')); 354 } while (MatchSkipWhiteSpace(','));
360 if (c0_ != '}') { 355 if (c0_ != '}') {
361 return ReportUnexpectedCharacter(); 356 return ReportUnexpectedCharacter();
362 } 357 }
363 if (!prototype.is_null()) SetPrototype(json_object, prototype);
364 } 358 }
365 AdvanceSkipWhitespace(); 359 AdvanceSkipWhitespace();
366 return json_object; 360 return json_object;
367 } 361 }
368 362
369 // Parse a JSON array. Position must be right at '['. 363 // Parse a JSON array. Position must be right at '['.
370 template <bool seq_ascii> 364 template <bool seq_ascii>
371 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { 365 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
372 ZoneScope zone_scope(zone(), DELETE_ON_EXIT); 366 ZoneScope zone_scope(zone(), DELETE_ON_EXIT);
373 ZoneList<Handle<Object> > elements(4, zone()); 367 ZoneList<Handle<Object> > elements(4, zone());
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 698 }
705 ASSERT_EQ('"', c0_); 699 ASSERT_EQ('"', c0_);
706 // Advance past the last '"'. 700 // Advance past the last '"'.
707 AdvanceSkipWhitespace(); 701 AdvanceSkipWhitespace();
708 return result; 702 return result;
709 } 703 }
710 704
711 } } // namespace v8::internal 705 } } // namespace v8::internal
712 706
713 #endif // V8_JSON_PARSER_H_ 707 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698