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

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

Issue 181413002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-microtask-delivery.cc ('k') | test/cctest/test-platform.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 preparser.set_allow_lazy(true); 317 preparser.set_allow_lazy(true);
318 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 318 i::PreParser::PreParseResult result = preparser.PreParseProgram();
319 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 319 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
320 i::ScriptDataImpl data(log.ExtractData()); 320 i::ScriptDataImpl data(log.ExtractData());
321 // Data contains syntax error. 321 // Data contains syntax error.
322 CHECK(data.has_error()); 322 CHECK(data.has_error());
323 } 323 }
324 } 324 }
325 325
326 326
327 TEST(PreparsingObjectLiterals) {
328 // Regression test for a bug where the symbol stream produced by PreParser
329 // didn't match what Parser wanted to consume.
330 v8::Isolate* isolate = CcTest::isolate();
331 v8::HandleScope handles(isolate);
332 v8::Local<v8::Context> context = v8::Context::New(isolate);
333 v8::Context::Scope context_scope(context);
334 int marker;
335 CcTest::i_isolate()->stack_guard()->SetStackLimit(
336 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
337
338 {
339 const char* source = "var myo = {if: \"foo\"}; myo.if;";
340 v8::Local<v8::Value> result = PreCompileCompileRun(source);
341 CHECK(result->IsString());
342 v8::String::Utf8Value utf8(result);
343 CHECK_EQ("foo", *utf8);
344 }
345
346 {
347 const char* source = "var myo = {\"bar\": \"foo\"}; myo[\"bar\"];";
348 v8::Local<v8::Value> result = PreCompileCompileRun(source);
349 CHECK(result->IsString());
350 v8::String::Utf8Value utf8(result);
351 CHECK_EQ("foo", *utf8);
352 }
353
354 {
355 const char* source = "var myo = {1: \"foo\"}; myo[1];";
356 v8::Local<v8::Value> result = PreCompileCompileRun(source);
357 CHECK(result->IsString());
358 v8::String::Utf8Value utf8(result);
359 CHECK_EQ("foo", *utf8);
360 }
361 }
362
363 namespace v8 {
364 namespace internal {
365
366 void FakeWritingSymbolIdInPreParseData(i::CompleteParserRecorder* log,
367 int number) {
368 log->WriteNumber(number);
369 if (log->symbol_id_ < number + 1) {
370 log->symbol_id_ = number + 1;
371 }
372 }
373
374 }
375 }
376
377
378 TEST(StoringNumbersInPreParseData) {
379 // Symbol IDs are split into chunks of 7 bits for storing. This is a
380 // regression test for a bug where a symbol id was incorrectly stored if some
381 // of the chunks in the middle were all zeros.
382 i::CompleteParserRecorder log;
383 for (int i = 0; i < 18; ++i) {
384 FakeWritingSymbolIdInPreParseData(&log, 1 << i);
385 }
386 for (int i = 1; i < 18; ++i) {
387 FakeWritingSymbolIdInPreParseData(&log, (1 << i) + 1);
388 }
389 for (int i = 6; i < 18; ++i) {
390 FakeWritingSymbolIdInPreParseData(&log, (3 << i) + (5 << (i - 6)));
391 }
392 i::Vector<unsigned> store = log.ExtractData();
393 i::ScriptDataImpl script_data(store);
394 script_data.Initialize();
395 // Check that we get the same symbols back.
396 for (int i = 0; i < 18; ++i) {
397 CHECK_EQ(1 << i, script_data.GetSymbolIdentifier());
398 }
399 for (int i = 1; i < 18; ++i) {
400 CHECK_EQ((1 << i) + 1, script_data.GetSymbolIdentifier());
401 }
402 for (int i = 6; i < 18; ++i) {
403 CHECK_EQ((3 << i) + (5 << (i - 6)), script_data.GetSymbolIdentifier());
404 }
405 }
406
407
408 TEST(RegressChromium62639) { 327 TEST(RegressChromium62639) {
409 v8::V8::Initialize(); 328 v8::V8::Initialize();
410 i::Isolate* isolate = CcTest::i_isolate(); 329 i::Isolate* isolate = CcTest::i_isolate();
411 330
412 int marker; 331 int marker;
413 isolate->stack_guard()->SetStackLimit( 332 isolate->stack_guard()->SetStackLimit(
414 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 333 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
415 334
416 const char* program = "var x = 'something';\n" 335 const char* program = "var x = 'something';\n"
417 "escape: function() {}"; 336 "escape: function() {}";
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 kAllowHarmonyNumericLiterals 1101 kAllowHarmonyNumericLiterals
1183 }; 1102 };
1184 1103
1185 1104
1186 enum ParserSyncTestResult { 1105 enum ParserSyncTestResult {
1187 kSuccessOrError, 1106 kSuccessOrError,
1188 kSuccess, 1107 kSuccess,
1189 kError 1108 kError
1190 }; 1109 };
1191 1110
1192 template <typename Traits> 1111
1193 void SetParserFlags(i::ParserBase<Traits>* parser, 1112 void SetParserFlags(i::ParserBase* parser, i::EnumSet<ParserFlag> flags) {
1194 i::EnumSet<ParserFlag> flags) {
1195 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1113 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1196 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); 1114 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
1197 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1115 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1198 parser->set_allow_modules(flags.Contains(kAllowModules)); 1116 parser->set_allow_modules(flags.Contains(kAllowModules));
1199 parser->set_allow_generators(flags.Contains(kAllowGenerators)); 1117 parser->set_allow_generators(flags.Contains(kAllowGenerators));
1200 parser->set_allow_for_of(flags.Contains(kAllowForOf)); 1118 parser->set_allow_for_of(flags.Contains(kAllowForOf));
1201 parser->set_allow_harmony_numeric_literals( 1119 parser->set_allow_harmony_numeric_literals(
1202 flags.Contains(kAllowHarmonyNumericLiterals)); 1120 flags.Contains(kAllowHarmonyNumericLiterals));
1203 } 1121 }
1204 1122
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 v8::HandleScope handles(CcTest::isolate()); 1383 v8::HandleScope handles(CcTest::isolate());
1466 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 1384 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
1467 v8::Context::Scope context_scope(context); 1385 v8::Context::Scope context_scope(context);
1468 1386
1469 int marker; 1387 int marker;
1470 CcTest::i_isolate()->stack_guard()->SetStackLimit( 1388 CcTest::i_isolate()->stack_guard()->SetStackLimit(
1471 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 1389 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
1472 1390
1473 static const ParserFlag flags[] = { 1391 static const ParserFlag flags[] = {
1474 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators, 1392 kAllowLazy, kAllowHarmonyScoping, kAllowModules, kAllowGenerators,
1475 kAllowForOf, kAllowNativesSyntax 1393 kAllowForOf
1476 }; 1394 };
1477 for (int i = 0; context_data[i][0] != NULL; ++i) { 1395 for (int i = 0; context_data[i][0] != NULL; ++i) {
1478 for (int j = 0; statement_data[j] != NULL; ++j) { 1396 for (int j = 0; statement_data[j] != NULL; ++j) {
1479 int kPrefixLen = i::StrLength(context_data[i][0]); 1397 int kPrefixLen = i::StrLength(context_data[i][0]);
1480 int kStatementLen = i::StrLength(statement_data[j]); 1398 int kStatementLen = i::StrLength(statement_data[j]);
1481 int kSuffixLen = i::StrLength(context_data[i][1]); 1399 int kSuffixLen = i::StrLength(context_data[i][1]);
1482 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen; 1400 int kProgramSize = kPrefixLen + kStatementLen + kSuffixLen;
1483 1401
1484 // Plug the source code pieces together. 1402 // Plug the source code pieces together.
1485 i::ScopedVector<char> program(kProgramSize + 1); 1403 i::ScopedVector<char> program(kProgramSize + 1);
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 2006
2089 const char* statement_data[] = { 2007 const char* statement_data[] = {
2090 "try { } catch (e) { }", 2008 "try { } catch (e) { }",
2091 "try { } catch (e) { } finally { }", 2009 "try { } catch (e) { } finally { }",
2092 "try { } finally { }", 2010 "try { } finally { }",
2093 NULL 2011 NULL
2094 }; 2012 };
2095 2013
2096 RunParserSyncTest(context_data, statement_data, kSuccess); 2014 RunParserSyncTest(context_data, statement_data, kSuccess);
2097 } 2015 }
2098
2099
2100 TEST(ErrorsRegexpLiteral) {
2101 const char* context_data[][2] = {
2102 {"var r = ", ""},
2103 { NULL, NULL }
2104 };
2105
2106 const char* statement_data[] = {
2107 "/unterminated",
2108 NULL
2109 };
2110
2111 RunParserSyncTest(context_data, statement_data, kError);
2112 }
2113
2114
2115 TEST(NoErrorsRegexpLiteral) {
2116 const char* context_data[][2] = {
2117 {"var r = ", ""},
2118 { NULL, NULL }
2119 };
2120
2121 const char* statement_data[] = {
2122 "/foo/",
2123 "/foo/g",
2124 "/foo/whatever", // This is an error but not detected by the parser.
2125 NULL
2126 };
2127
2128 RunParserSyncTest(context_data, statement_data, kSuccess);
2129 }
2130
2131
2132 TEST(Intrinsics) {
2133 const char* context_data[][2] = {
2134 {"", ""},
2135 { NULL, NULL }
2136 };
2137
2138 const char* statement_data[] = {
2139 "%someintrinsic(arg)",
2140 NULL
2141 };
2142
2143 // Parsing will fail or succeed depending on whether we allow natives syntax
2144 // or not.
2145 RunParserSyncTest(context_data, statement_data, kSuccessOrError);
2146 }
2147
2148
2149 TEST(NoErrorsNewExpression) {
2150 const char* context_data[][2] = {
2151 {"", ""},
2152 {"var f =", ""},
2153 { NULL, NULL }
2154 };
2155
2156 const char* statement_data[] = {
2157 "new foo",
2158 "new foo();",
2159 "new foo(1);",
2160 "new foo(1, 2);",
2161 // The first () will be processed as a part of the NewExpression and the
2162 // second () will be processed as part of LeftHandSideExpression.
2163 "new foo()();",
2164 // The first () will be processed as a part of the inner NewExpression and
2165 // the second () will be processed as a part of the outer NewExpression.
2166 "new new foo()();",
2167 "new foo.bar;",
2168 "new foo.bar();",
2169 "new foo.bar.baz;",
2170 "new foo.bar().baz;",
2171 "new foo[bar];",
2172 "new foo[bar]();",
2173 "new foo[bar][baz];",
2174 "new foo[bar]()[baz];",
2175 "new foo[bar].baz(baz)()[bar].baz;",
2176 "new \"foo\"", // Runtime error
2177 "new 1", // Runtime error
2178 "new foo++",
2179 // This even runs:
2180 "(new new Function(\"this.x = 1\")).x;",
2181 "new new Test_Two(String, 2).v(0123).length;",
2182 NULL
2183 };
2184
2185 RunParserSyncTest(context_data, statement_data, kSuccess);
2186 }
2187
2188
2189 TEST(ErrorsNewExpression) {
2190 const char* context_data[][2] = {
2191 {"", ""},
2192 {"var f =", ""},
2193 { NULL, NULL }
2194 };
2195
2196 const char* statement_data[] = {
2197 "new foo bar",
2198 "new ) foo",
2199 "new ++foo",
2200 NULL
2201 };
2202
2203 RunParserSyncTest(context_data, statement_data, kError);
2204 }
OLDNEW
« no previous file with comments | « test/cctest/test-microtask-delivery.cc ('k') | test/cctest/test-platform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698