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

Side by Side Diff: src/parser.cc

Issue 7004016: JSON.parse improvement. Call "LookupSymbol" rather than "NewString"... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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/parser.h ('k') | 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 4066 matching lines...) Expand 10 before | Expand all | Expand 10 after
4077 if (scanner_.is_literal_ascii()) { 4077 if (scanner_.is_literal_ascii()) {
4078 return isolate()->factory()->NewStringFromAscii( 4078 return isolate()->factory()->NewStringFromAscii(
4079 scanner_.literal_ascii_string()); 4079 scanner_.literal_ascii_string());
4080 } else { 4080 } else {
4081 return isolate()->factory()->NewStringFromTwoByte( 4081 return isolate()->factory()->NewStringFromTwoByte(
4082 scanner_.literal_uc16_string()); 4082 scanner_.literal_uc16_string());
4083 } 4083 }
4084 } 4084 }
4085 4085
4086 4086
4087 Handle<String> JsonParser::GetSymbol() {
4088 int literal_length = scanner_.literal_length();
4089 if (literal_length == 0) {
4090 return isolate()->factory()->empty_string();
4091 }
4092 if (scanner_.is_literal_ascii()) {
4093 return isolate()->factory()->LookupAsciiSymbol(
4094 scanner_.literal_ascii_string());
4095 } else {
4096 return isolate()->factory()->LookupTwoByteSymbol(
4097 scanner_.literal_uc16_string());
4098 }
4099 }
4100
4101
4087 // Parse any JSON value. 4102 // Parse any JSON value.
4088 Handle<Object> JsonParser::ParseJsonValue() { 4103 Handle<Object> JsonParser::ParseJsonValue() {
4089 Token::Value token = scanner_.Next(); 4104 Token::Value token = scanner_.Next();
4090 switch (token) { 4105 switch (token) {
4091 case Token::STRING: 4106 case Token::STRING:
4092 return GetString(); 4107 return GetString();
4093 case Token::NUMBER: 4108 case Token::NUMBER:
4094 return isolate()->factory()->NewNumber(scanner_.number()); 4109 return isolate()->factory()->NewNumber(scanner_.number());
4095 case Token::FALSE_LITERAL: 4110 case Token::FALSE_LITERAL:
4096 return isolate()->factory()->false_value(); 4111 return isolate()->factory()->false_value();
(...skipping 21 matching lines...) Expand all
4118 scanner_.Next(); 4133 scanner_.Next();
4119 } else { 4134 } else {
4120 if (StackLimitCheck(isolate()).HasOverflowed()) { 4135 if (StackLimitCheck(isolate()).HasOverflowed()) {
4121 stack_overflow_ = true; 4136 stack_overflow_ = true;
4122 return Handle<Object>::null(); 4137 return Handle<Object>::null();
4123 } 4138 }
4124 do { 4139 do {
4125 if (scanner_.Next() != Token::STRING) { 4140 if (scanner_.Next() != Token::STRING) {
4126 return ReportUnexpectedToken(); 4141 return ReportUnexpectedToken();
4127 } 4142 }
4128 Handle<String> key = GetString(); 4143 Handle<String> key = GetSymbol();
4129 if (scanner_.Next() != Token::COLON) { 4144 if (scanner_.Next() != Token::COLON) {
4130 return ReportUnexpectedToken(); 4145 return ReportUnexpectedToken();
4131 } 4146 }
4132 Handle<Object> value = ParseJsonValue(); 4147 Handle<Object> value = ParseJsonValue();
4133 if (value.is_null()) return Handle<Object>::null(); 4148 if (value.is_null()) return Handle<Object>::null();
4134 uint32_t index; 4149 uint32_t index;
4135 if (key->AsArrayIndex(&index)) { 4150 if (key->AsArrayIndex(&index)) {
4136 SetOwnElement(json_object, index, value, kNonStrictMode); 4151 SetOwnElement(json_object, index, value, kNonStrictMode);
4137 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { 4152 } else if (key->Equals(isolate()->heap()->Proto_symbol())) {
4138 // We can't remove the __proto__ accessor since it's hardcoded 4153 // We can't remove the __proto__ accessor since it's hardcoded
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
5155 info->is_global(), 5170 info->is_global(),
5156 info->StrictMode()); 5171 info->StrictMode());
5157 } 5172 }
5158 } 5173 }
5159 5174
5160 info->SetFunction(result); 5175 info->SetFunction(result);
5161 return (result != NULL); 5176 return (result != NULL);
5162 } 5177 }
5163 5178
5164 } } // namespace v8::internal 5179 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698