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

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

Issue 1140053002: Migrate error messages, part 11. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/isolate.cc ('k') | src/jsregexp.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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_JSON_PARSER_H_ 5 #ifndef V8_JSON_PARSER_H_
6 #define V8_JSON_PARSER_H_ 6 #define V8_JSON_PARSER_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/char-predicates-inl.h" 10 #include "src/char-predicates-inl.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 template <bool seq_one_byte> 206 template <bool seq_one_byte>
207 MaybeHandle<Object> JsonParser<seq_one_byte>::ParseJson() { 207 MaybeHandle<Object> JsonParser<seq_one_byte>::ParseJson() {
208 // Advance to the first character (possibly EOS) 208 // Advance to the first character (possibly EOS)
209 AdvanceSkipWhitespace(); 209 AdvanceSkipWhitespace();
210 Handle<Object> result = ParseJsonValue(); 210 Handle<Object> result = ParseJsonValue();
211 if (result.is_null() || c0_ != kEndOfString) { 211 if (result.is_null() || c0_ != kEndOfString) {
212 // Some exception (for example stack overflow) is already pending. 212 // Some exception (for example stack overflow) is already pending.
213 if (isolate_->has_pending_exception()) return Handle<Object>::null(); 213 if (isolate_->has_pending_exception()) return Handle<Object>::null();
214 214
215 // Parse failed. Current character is the unexpected token. 215 // Parse failed. Current character is the unexpected token.
216 const char* message;
217 Factory* factory = this->factory(); 216 Factory* factory = this->factory();
218 Handle<JSArray> array; 217 MessageTemplate::Template message;
218 Handle<String> argument;
219 219
220 switch (c0_) { 220 switch (c0_) {
221 case kEndOfString: 221 case kEndOfString:
222 message = "unexpected_eos"; 222 message = MessageTemplate::kUnexpectedEOS;
223 array = factory->NewJSArray(0);
224 break; 223 break;
225 case '-': 224 case '-':
226 case '0': 225 case '0':
227 case '1': 226 case '1':
228 case '2': 227 case '2':
229 case '3': 228 case '3':
230 case '4': 229 case '4':
231 case '5': 230 case '5':
232 case '6': 231 case '6':
233 case '7': 232 case '7':
234 case '8': 233 case '8':
235 case '9': 234 case '9':
236 message = "unexpected_token_number"; 235 message = MessageTemplate::kUnexpectedTokenNumber;
237 array = factory->NewJSArray(0);
238 break; 236 break;
239 case '"': 237 case '"':
240 message = "unexpected_token_string"; 238 message = MessageTemplate::kUnexpectedTokenString;
241 array = factory->NewJSArray(0);
242 break; 239 break;
243 default: 240 default:
244 message = "unexpected_token"; 241 message = MessageTemplate::kUnexpectedToken;
245 Handle<Object> name = factory->LookupSingleCharacterStringFromCode(c0_); 242 argument = factory->LookupSingleCharacterStringFromCode(c0_);
246 Handle<FixedArray> element = factory->NewFixedArray(1);
247 element->set(0, *name);
248 array = factory->NewJSArrayWithElements(element);
249 break; 243 break;
250 } 244 }
251 245
252 MessageLocation location(factory->NewScript(source_), 246 MessageLocation location(factory->NewScript(source_),
253 position_, 247 position_,
254 position_ + 1); 248 position_ + 1);
255 Handle<Object> error = factory->NewSyntaxError(message, array); 249 Handle<Object> error = factory->NewSyntaxError(message, argument);
256 return isolate()->template Throw<Object>(error, &location); 250 return isolate()->template Throw<Object>(error, &location);
257 } 251 }
258 return result; 252 return result;
259 } 253 }
260 254
261 255
262 // Parse any JSON value. 256 // Parse any JSON value.
263 template <bool seq_one_byte> 257 template <bool seq_one_byte>
264 Handle<Object> JsonParser<seq_one_byte>::ParseJsonValue() { 258 Handle<Object> JsonParser<seq_one_byte>::ParseJsonValue() {
265 StackLimitCheck stack_check(isolate_); 259 StackLimitCheck stack_check(isolate_);
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 834
841 DCHECK_EQ('"', c0_); 835 DCHECK_EQ('"', c0_);
842 // Advance past the last '"'. 836 // Advance past the last '"'.
843 AdvanceSkipWhitespace(); 837 AdvanceSkipWhitespace();
844 return result; 838 return result;
845 } 839 }
846 840
847 } } // namespace v8::internal 841 } } // namespace v8::internal
848 842
849 #endif // V8_JSON_PARSER_H_ 843 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698