OLD | NEW |
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 253 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
254 for (int i = 0; programs[i]; i++) { | 254 for (int i = 0; programs[i]; i++) { |
255 const char* program = programs[i]; | 255 const char* program = programs[i]; |
256 i::Utf8ToUC16CharacterStream stream( | 256 i::Utf8ToUC16CharacterStream stream( |
257 reinterpret_cast<const i::byte*>(program), | 257 reinterpret_cast<const i::byte*>(program), |
258 static_cast<unsigned>(strlen(program))); | 258 static_cast<unsigned>(strlen(program))); |
259 i::CompleteParserRecorder log; | 259 i::CompleteParserRecorder log; |
260 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); | 260 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
261 scanner.Initialize(&stream); | 261 scanner.Initialize(&stream); |
262 | 262 |
| 263 int flags = v8::preparser::PreParser::kAllowLazy | |
| 264 v8::preparser::PreParser::kAllowNativesSyntax; |
263 v8::preparser::PreParser::PreParseResult result = | 265 v8::preparser::PreParser::PreParseResult result = |
264 v8::preparser::PreParser::PreParseProgram(&scanner, | 266 v8::preparser::PreParser::PreParseProgram(&scanner, |
265 &log, | 267 &log, |
266 true, | 268 flags, |
267 stack_limit); | 269 stack_limit); |
268 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 270 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
269 i::ScriptDataImpl data(log.ExtractData()); | 271 i::ScriptDataImpl data(log.ExtractData()); |
270 CHECK(!data.has_error()); | 272 CHECK(!data.has_error()); |
271 } | 273 } |
272 } | 274 } |
273 | 275 |
274 | 276 |
| 277 TEST(StandAlonePreParserNoNatives) { |
| 278 v8::V8::Initialize(); |
| 279 |
| 280 int marker; |
| 281 i::Isolate::Current()->stack_guard()->SetStackLimit( |
| 282 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 283 |
| 284 const char* programs[] = { |
| 285 "%ArgleBargle(glop);", |
| 286 "var x = %_IsSmi(42);", |
| 287 NULL |
| 288 }; |
| 289 |
| 290 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
| 291 for (int i = 0; programs[i]; i++) { |
| 292 const char* program = programs[i]; |
| 293 i::Utf8ToUC16CharacterStream stream( |
| 294 reinterpret_cast<const i::byte*>(program), |
| 295 static_cast<unsigned>(strlen(program))); |
| 296 i::CompleteParserRecorder log; |
| 297 i::JavaScriptScanner scanner(i::Isolate::Current()->unicode_cache()); |
| 298 scanner.Initialize(&stream); |
| 299 |
| 300 // Flags don't allow natives syntax. |
| 301 int flags = v8::preparser::PreParser::kAllowLazy; |
| 302 v8::preparser::PreParser::PreParseResult result = |
| 303 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 304 &log, |
| 305 flags, |
| 306 stack_limit); |
| 307 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
| 308 i::ScriptDataImpl data(log.ExtractData()); |
| 309 // Data contains syntax error. |
| 310 CHECK(data.has_error()); |
| 311 } |
| 312 } |
| 313 |
| 314 |
275 TEST(RegressChromium62639) { | 315 TEST(RegressChromium62639) { |
276 v8::V8::Initialize(); | 316 v8::V8::Initialize(); |
277 | 317 |
278 int marker; | 318 int marker; |
279 i::Isolate::Current()->stack_guard()->SetStackLimit( | 319 i::Isolate::Current()->stack_guard()->SetStackLimit( |
280 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 320 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
281 | 321 |
282 const char* program = "var x = 'something';\n" | 322 const char* program = "var x = 'something';\n" |
283 "escape: function() {}"; | 323 "escape: function() {}"; |
284 // Fails parsing expecting an identifier after "function". | 324 // Fails parsing expecting an identifier after "function". |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); | 739 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]"); |
700 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); | 740 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]"); |
701 // Escaped ']'s wont end the character class. | 741 // Escaped ']'s wont end the character class. |
702 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); | 742 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]"); |
703 // Escaped slashes are not terminating. | 743 // Escaped slashes are not terminating. |
704 TestScanRegExp("/\\//flipperwald", "\\/"); | 744 TestScanRegExp("/\\//flipperwald", "\\/"); |
705 // Starting with '=' works too. | 745 // Starting with '=' works too. |
706 TestScanRegExp("/=/", "="); | 746 TestScanRegExp("/=/", "="); |
707 TestScanRegExp("/=?/", "=?"); | 747 TestScanRegExp("/=?/", "=?"); |
708 } | 748 } |
OLD | NEW |