OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 | 250 |
251 const char* programs[] = { | 251 const char* programs[] = { |
252 "{label: 42}", | 252 "{label: 42}", |
253 "var x = 42;", | 253 "var x = 42;", |
254 "function foo(x, y) { return x + y; }", | 254 "function foo(x, y) { return x + y; }", |
255 "native function foo(); return %ArgleBargle(glop);", | 255 "native function foo(); return %ArgleBargle(glop);", |
256 "var x = new new Function('this.x = 42');", | 256 "var x = new new Function('this.x = 42');", |
257 NULL | 257 NULL |
258 }; | 258 }; |
259 | 259 |
| 260 uintptr_t stack_limit = i::StackGuard::real_climit(); |
260 for (int i = 0; programs[i]; i++) { | 261 for (int i = 0; programs[i]; i++) { |
261 const char* program = programs[i]; | 262 const char* program = programs[i]; |
262 unibrow::Utf8InputBuffer<256> stream(program, strlen(program)); | 263 unibrow::Utf8InputBuffer<256> stream(program, strlen(program)); |
263 i::CompleteParserRecorder log; | 264 i::CompleteParserRecorder log; |
264 i::V8JavaScriptScanner scanner; | 265 i::V8JavaScriptScanner scanner; |
265 scanner.Initialize(i::Handle<i::String>::null(), &stream); | 266 scanner.Initialize(i::Handle<i::String>::null(), &stream); |
266 v8::preparser::PreParser preparser; | 267 |
267 bool result = preparser.PreParseProgram(&scanner, &log, true); | 268 v8::preparser::PreParser::PreParseResult result = |
268 CHECK(result); | 269 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 270 &log, |
| 271 true, |
| 272 stack_limit); |
| 273 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
269 i::ScriptDataImpl data(log.ExtractData()); | 274 i::ScriptDataImpl data(log.ExtractData()); |
270 CHECK(!data.has_error()); | 275 CHECK(!data.has_error()); |
271 } | 276 } |
272 } | 277 } |
273 | 278 |
274 | 279 |
275 TEST(RegressChromium62639) { | 280 TEST(RegressChromium62639) { |
276 int marker; | 281 int marker; |
277 i::StackGuard::SetStackLimit( | 282 i::StackGuard::SetStackLimit( |
278 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 283 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 CHECK(!entry1.is_valid()); | 325 CHECK(!entry1.is_valid()); |
321 | 326 |
322 int second_function = strstr(program + first_lbrace, "function") - program; | 327 int second_function = strstr(program + first_lbrace, "function") - program; |
323 int second_lbrace = second_function + strlen("function () "); | 328 int second_lbrace = second_function + strlen("function () "); |
324 CHECK_EQ('{', program[second_lbrace]); | 329 CHECK_EQ('{', program[second_lbrace]); |
325 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); | 330 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace); |
326 CHECK(entry2.is_valid()); | 331 CHECK(entry2.is_valid()); |
327 CHECK_EQ('}', program[entry2.end_pos() - 1]); | 332 CHECK_EQ('}', program[entry2.end_pos() - 1]); |
328 delete data; | 333 delete data; |
329 } | 334 } |
| 335 |
| 336 |
| 337 TEST(PreParseOverflow) { |
| 338 int marker; |
| 339 i::StackGuard::SetStackLimit( |
| 340 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 341 |
| 342 size_t kProgramSize = 1024 * 1024; |
| 343 i::SmartPointer<char> program( |
| 344 reinterpret_cast<char*>(malloc(kProgramSize + 1))); |
| 345 memset(*program, '(', kProgramSize); |
| 346 program[kProgramSize] = '\0'; |
| 347 |
| 348 uintptr_t stack_limit = i::StackGuard::real_climit(); |
| 349 |
| 350 unibrow::Utf8InputBuffer<256> stream(*program, strlen(*program)); |
| 351 i::CompleteParserRecorder log; |
| 352 i::V8JavaScriptScanner scanner; |
| 353 scanner.Initialize(i::Handle<i::String>::null(), &stream); |
| 354 |
| 355 |
| 356 v8::preparser::PreParser::PreParseResult result = |
| 357 v8::preparser::PreParser::PreParseProgram(&scanner, |
| 358 &log, |
| 359 true, |
| 360 stack_limit); |
| 361 CHECK_EQ(v8::preparser::PreParser::kPreParseStackOverflow, result); |
| 362 } |
OLD | NEW |