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

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

Issue 1681513002: [json parser] add position to error message. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix BUILD.gn Created 4 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
« no previous file with comments | « src/api.cc ('k') | src/messages.h » ('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_PARSING_JSON_PARSER_H_ 5 #ifndef V8_JSON_PARSER_H_
6 #define V8_PARSING_JSON_PARSER_H_ 6 #define V8_JSON_PARSER_H_
7 7
8 #include "src/char-predicates.h" 8 #include "src/char-predicates.h"
9 #include "src/conversions.h" 9 #include "src/conversions.h"
10 #include "src/debug/debug.h" 10 #include "src/debug/debug.h"
11 #include "src/factory.h" 11 #include "src/factory.h"
12 #include "src/messages.h" 12 #include "src/messages.h"
13 #include "src/parsing/scanner.h" 13 #include "src/parsing/scanner.h"
14 #include "src/parsing/token.h" 14 #include "src/parsing/token.h"
15 #include "src/transitions.h" 15 #include "src/transitions.h"
16 #include "src/types.h" 16 #include "src/types.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // Advance to the first character (possibly EOS) 210 // Advance to the first character (possibly EOS)
211 AdvanceSkipWhitespace(); 211 AdvanceSkipWhitespace();
212 Handle<Object> result = ParseJsonValue(); 212 Handle<Object> result = ParseJsonValue();
213 if (result.is_null() || c0_ != kEndOfString) { 213 if (result.is_null() || c0_ != kEndOfString) {
214 // Some exception (for example stack overflow) is already pending. 214 // Some exception (for example stack overflow) is already pending.
215 if (isolate_->has_pending_exception()) return Handle<Object>::null(); 215 if (isolate_->has_pending_exception()) return Handle<Object>::null();
216 216
217 // Parse failed. Current character is the unexpected token. 217 // Parse failed. Current character is the unexpected token.
218 Factory* factory = this->factory(); 218 Factory* factory = this->factory();
219 MessageTemplate::Template message; 219 MessageTemplate::Template message;
220 Handle<String> argument; 220 Handle<Object> arg1 = Handle<Smi>(Smi::FromInt(position_), isolate());
221 Handle<Object> arg2;
221 222
222 switch (c0_) { 223 switch (c0_) {
223 case kEndOfString: 224 case kEndOfString:
224 message = MessageTemplate::kUnexpectedEOS; 225 message = MessageTemplate::kJsonParseUnexpectedEOS;
225 break; 226 break;
226 case '-': 227 case '-':
227 case '0': 228 case '0':
228 case '1': 229 case '1':
229 case '2': 230 case '2':
230 case '3': 231 case '3':
231 case '4': 232 case '4':
232 case '5': 233 case '5':
233 case '6': 234 case '6':
234 case '7': 235 case '7':
235 case '8': 236 case '8':
236 case '9': 237 case '9':
237 message = MessageTemplate::kUnexpectedTokenNumber; 238 message = MessageTemplate::kJsonParseUnexpectedTokenNumber;
238 break; 239 break;
239 case '"': 240 case '"':
240 message = MessageTemplate::kUnexpectedTokenString; 241 message = MessageTemplate::kJsonParseUnexpectedTokenString;
241 break; 242 break;
242 default: 243 default:
243 message = MessageTemplate::kUnexpectedToken; 244 message = MessageTemplate::kJsonParseUnexpectedToken;
244 argument = factory->LookupSingleCharacterStringFromCode(c0_); 245 arg2 = arg1;
246 arg1 = factory->LookupSingleCharacterStringFromCode(c0_);
245 break; 247 break;
246 } 248 }
247 249
248 Handle<Script> script(factory->NewScript(source_)); 250 Handle<Script> script(factory->NewScript(source_));
249 // We should sent compile error event because we compile JSON object in 251 // We should sent compile error event because we compile JSON object in
250 // separated source file. 252 // separated source file.
251 isolate()->debug()->OnCompileError(script); 253 isolate()->debug()->OnCompileError(script);
252 MessageLocation location(script, position_, position_ + 1); 254 MessageLocation location(script, position_, position_ + 1);
253 Handle<Object> error = factory->NewSyntaxError(message, argument); 255 Handle<Object> error = factory->NewSyntaxError(message, arg1, arg2);
254 return isolate()->template Throw<Object>(error, &location); 256 return isolate()->template Throw<Object>(error, &location);
255 } 257 }
256 return result; 258 return result;
257 } 259 }
258 260
259 261
260 // Parse any JSON value. 262 // Parse any JSON value.
261 template <bool seq_one_byte> 263 template <bool seq_one_byte>
262 Handle<Object> JsonParser<seq_one_byte>::ParseJsonValue() { 264 Handle<Object> JsonParser<seq_one_byte>::ParseJsonValue() {
263 StackLimitCheck stack_check(isolate_); 265 StackLimitCheck stack_check(isolate_);
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 834
833 DCHECK_EQ('"', c0_); 835 DCHECK_EQ('"', c0_);
834 // Advance past the last '"'. 836 // Advance past the last '"'.
835 AdvanceSkipWhitespace(); 837 AdvanceSkipWhitespace();
836 return result; 838 return result;
837 } 839 }
838 840
839 } // namespace internal 841 } // namespace internal
840 } // namespace v8 842 } // namespace v8
841 843
842 #endif // V8_PARSING_JSON_PARSER_H_ 844 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698