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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 4639005: Preparsing now considers catch-blocks as inside a with. (Closed)
Patch Set: Upped version number of preparse data. Created 10 years, 1 month 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/preparser.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 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <string.h>
30 31
31 #include "v8.h" 32 #include "v8.h"
32 33
33 #include "token.h" 34 #include "token.h"
34 #include "scanner.h" 35 #include "scanner.h"
35 #include "parser.h" 36 #include "parser.h"
36 #include "utils.h" 37 #include "utils.h"
37 #include "execution.h" 38 #include "execution.h"
38 #include "scanner.h" 39 #include "scanner.h"
39 #include "preparser.h" 40 #include "preparser.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 CHECK(!data.has_error()); 271 CHECK(!data.has_error());
271 } 272 }
272 } 273 }
273 274
274 275
275 TEST(RegressChromium62639) { 276 TEST(RegressChromium62639) {
276 int marker; 277 int marker;
277 i::StackGuard::SetStackLimit( 278 i::StackGuard::SetStackLimit(
278 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 279 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
279 280
280 // Ensure that the source code is so big that it triggers preparsing.
281 char buffer[4096]; 281 char buffer[4096];
282 const char* program_template = "var x = '%01024d'; // filler\n" 282 const char* program_template = "var x = '%01024d'; // filler\n"
283 "escape: function() {}"; 283 "escape: function() {}";
284 // Fails parsing expecting an identifier after "function". 284 // Fails parsing expecting an identifier after "function".
285 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), 285 // Before fix, didn't check *ok after Expect(Token::Identifier, ok),
286 // and then used the invalid currently scanned literal. This always 286 // and then used the invalid currently scanned literal. This always
287 // failed in debug mode, and sometimes crashed in release mode. 287 // failed in debug mode, and sometimes crashed in release mode.
288 288
289 snprintf(buffer, sizeof(buffer), program_template, 0); 289 snprintf(buffer, sizeof(buffer), program_template, 0);
290 unibrow::Utf8InputBuffer<256> stream(buffer, strlen(buffer)); 290 unibrow::Utf8InputBuffer<256> stream(buffer, strlen(buffer));
291 i::ScriptDataImpl* data = 291 i::ScriptDataImpl* data =
292 i::ParserApi::PreParse(i::Handle<i::String>::null(), &stream, NULL); 292 i::ParserApi::PreParse(i::Handle<i::String>::null(), &stream, NULL);
293 CHECK(data->HasError()); 293 CHECK(data->HasError());
294 delete data; 294 delete data;
295 } 295 }
296
297
298 TEST(Regress928) {
299 // Preparsing didn't consider the catch clause of a try statement
300 // as with-content, which made it assume that a function inside
301 // the block could be lazily compiled, and an extra, unexpected,
302 // entry was added to the data.
303 int marker;
304 i::StackGuard::SetStackLimit(
305 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
306
307 const char* program =
308 "try { } catch (e) { var foo = function () { /* first */ } }"
309 "var bar = function () { /* second */ }";
310
311 unibrow::Utf8InputBuffer<256> stream(program, strlen(program));
312 i::ScriptDataImpl* data =
313 i::ParserApi::PartialPreParse(i::Handle<i::String>::null(),
314 &stream, NULL);
315 CHECK(!data->HasError());
316
317 data->Initialize();
318
319 int first_function = strstr(program, "function") - program;
320 int first_lbrace = first_function + strlen("function () ");
321 CHECK_EQ('{', program[first_lbrace]);
322 i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace);
323 CHECK(!entry1.is_valid());
324
325 int second_function = strstr(program + first_lbrace, "function") - program;
326 int second_lbrace = second_function + strlen("function () ");
327 CHECK_EQ('{', program[second_lbrace]);
328 i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace);
329 CHECK(entry2.is_valid());
330 CHECK_EQ('}', program[entry2.end_pos() - 1]);
331 delete data;
332 }
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698