Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 const char* data() const { return data_; } | 187 const char* data() const { return data_; } |
| 188 size_t length() const { return length_; } | 188 size_t length() const { return length_; } |
| 189 | 189 |
| 190 private: | 190 private: |
| 191 const char* data_; | 191 const char* data_; |
| 192 size_t length_; | 192 size_t length_; |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 | 195 |
| 196 TEST(UsingCachedData) { | 196 TEST(UsingCachedData) { |
| 197 i::FLAG_harmony_arrow_functions = true; | |
| 197 v8::Isolate* isolate = CcTest::isolate(); | 198 v8::Isolate* isolate = CcTest::isolate(); |
| 198 v8::HandleScope handles(isolate); | 199 v8::HandleScope handles(isolate); |
| 199 v8::Local<v8::Context> context = v8::Context::New(isolate); | 200 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 200 v8::Context::Scope context_scope(context); | 201 v8::Context::Scope context_scope(context); |
| 201 int marker; | 202 int marker; |
| 202 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 203 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 203 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 204 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 204 | 205 |
| 205 // Source containing functions that might be lazily compiled and all types | 206 // Source containing functions that might be lazily compiled and all types |
| 206 // of symbols (string, propertyName, regexp). | 207 // of symbols (string, propertyName, regexp). |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 235 } | 236 } |
| 236 | 237 |
| 237 | 238 |
| 238 TEST(PreparseFunctionDataIsUsed) { | 239 TEST(PreparseFunctionDataIsUsed) { |
| 239 // This tests that we actually do use the function data generated by the | 240 // This tests that we actually do use the function data generated by the |
| 240 // preparser. | 241 // preparser. |
| 241 | 242 |
| 242 // Make preparsing work for short scripts. | 243 // Make preparsing work for short scripts. |
| 243 i::FLAG_min_preparse_length = 0; | 244 i::FLAG_min_preparse_length = 0; |
| 244 | 245 |
| 246 i::FLAG_harmony_arrow_functions = true; | |
| 245 v8::Isolate* isolate = CcTest::isolate(); | 247 v8::Isolate* isolate = CcTest::isolate(); |
| 246 v8::HandleScope handles(isolate); | 248 v8::HandleScope handles(isolate); |
| 247 v8::Local<v8::Context> context = v8::Context::New(isolate); | 249 v8::Local<v8::Context> context = v8::Context::New(isolate); |
| 248 v8::Context::Scope context_scope(context); | 250 v8::Context::Scope context_scope(context); |
| 249 int marker; | 251 int marker; |
| 250 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 252 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 251 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 253 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 252 | 254 |
| 253 const char* good_code = | 255 const char* good_code[] = { |
| 254 "function this_is_lazy() { var a; } function foo() { return 25; } foo();"; | 256 "function this_is_lazy() { var a; } function foo() { return 25; } foo();", |
| 257 NULL | |
|
marja
2014/06/17 11:47:38
What, why? What are the changes in this test?
| |
| 258 }; | |
| 255 | 259 |
| 256 // Insert a syntax error inside the lazy function. | 260 // Insert a syntax error inside the lazy function. |
| 257 const char* bad_code = | 261 const char* bad_code[] = { |
| 258 "function this_is_lazy() { if ( } function foo() { return 25; } foo();"; | 262 "function this_is_lazy() { if ( } function foo() { return 25; } foo();", |
| 263 NULL | |
| 264 }; | |
| 259 | 265 |
| 260 v8::ScriptCompiler::Source good_source(v8_str(good_code)); | 266 for (int i = 0; good_code[i]; i++) { |
|
marja
2014/06/17 11:47:38
Looping over an array that has only 1 non-trivial
| |
| 261 v8::ScriptCompiler::Compile(isolate, &good_source, | 267 v8::ScriptCompiler::Source good_source(v8_str(good_code[i])); |
| 262 v8::ScriptCompiler::kProduceDataToCache); | 268 v8::ScriptCompiler::Compile(isolate, &good_source, |
| 269 v8::ScriptCompiler::kProduceDataToCache); | |
| 263 | 270 |
| 264 const v8::ScriptCompiler::CachedData* cached_data = | 271 const v8::ScriptCompiler::CachedData* cached_data = |
| 265 good_source.GetCachedData(); | 272 good_source.GetCachedData(); |
| 266 CHECK(cached_data->data != NULL); | 273 CHECK(cached_data->data != NULL); |
| 267 CHECK_GT(cached_data->length, 0); | 274 CHECK_GT(cached_data->length, 0); |
| 268 | 275 |
| 269 // Now compile the erroneous code with the good preparse data. If the preparse | 276 // Now compile the erroneous code with the good preparse data. If the |
| 270 // data is used, the lazy function is skipped and it should compile fine. | 277 // preparse data is used, the lazy function is skipped and it should |
| 271 v8::ScriptCompiler::Source bad_source( | 278 // compile fine. |
| 272 v8_str(bad_code), new v8::ScriptCompiler::CachedData( | 279 v8::ScriptCompiler::Source bad_source( |
| 273 cached_data->data, cached_data->length)); | 280 v8_str(bad_code[i]), new v8::ScriptCompiler::CachedData( |
| 274 v8::Local<v8::Value> result = | 281 cached_data->data, cached_data->length)); |
| 275 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run(); | 282 v8::Local<v8::Value> result = |
| 276 CHECK(result->IsInt32()); | 283 v8::ScriptCompiler::Compile(isolate, &bad_source)->Run(); |
| 277 CHECK_EQ(25, result->Int32Value()); | 284 CHECK(result->IsInt32()); |
| 285 CHECK_EQ(25, result->Int32Value()); | |
| 286 } | |
| 278 } | 287 } |
| 279 | 288 |
| 280 | 289 |
| 281 TEST(StandAlonePreParser) { | 290 TEST(StandAlonePreParser) { |
| 282 v8::V8::Initialize(); | 291 v8::V8::Initialize(); |
| 283 | 292 |
| 284 int marker; | 293 int marker; |
| 285 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 294 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 286 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 295 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
| 287 | 296 |
| 288 const char* programs[] = { | 297 const char* programs[] = { |
| 289 "{label: 42}", | 298 "{label: 42}", |
| 290 "var x = 42;", | 299 "var x = 42;", |
| 291 "function foo(x, y) { return x + y; }", | 300 "function foo(x, y) { return x + y; }", |
| 292 "%ArgleBargle(glop);", | 301 "%ArgleBargle(glop);", |
| 293 "var x = new new Function('this.x = 42');", | 302 "var x = new new Function('this.x = 42');", |
| 303 "var f = (x, y) => x + y;", | |
| 294 NULL | 304 NULL |
| 295 }; | 305 }; |
| 296 | 306 |
| 297 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 307 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 298 for (int i = 0; programs[i]; i++) { | 308 for (int i = 0; programs[i]; i++) { |
| 299 const char* program = programs[i]; | 309 const char* program = programs[i]; |
| 300 i::Utf8ToUtf16CharacterStream stream( | 310 i::Utf8ToUtf16CharacterStream stream( |
| 301 reinterpret_cast<const i::byte*>(program), | 311 reinterpret_cast<const i::byte*>(program), |
| 302 static_cast<unsigned>(strlen(program))); | 312 static_cast<unsigned>(strlen(program))); |
| 303 i::CompleteParserRecorder log; | 313 i::CompleteParserRecorder log; |
| 304 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 314 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 305 scanner.Initialize(&stream); | 315 scanner.Initialize(&stream); |
| 306 | 316 |
| 307 i::PreParser preparser(&scanner, &log, stack_limit); | 317 i::PreParser preparser(&scanner, &log, stack_limit); |
| 308 preparser.set_allow_lazy(true); | 318 preparser.set_allow_lazy(true); |
| 309 preparser.set_allow_natives_syntax(true); | 319 preparser.set_allow_natives_syntax(true); |
| 320 preparser.set_allow_arrow_functions(true); | |
| 310 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 321 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 311 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 322 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 312 i::ScriptData data(log.ExtractData()); | 323 i::ScriptData data(log.ExtractData()); |
| 313 CHECK(!data.has_error()); | 324 CHECK(!data.has_error()); |
| 314 } | 325 } |
| 315 } | 326 } |
| 316 | 327 |
| 317 | 328 |
| 318 TEST(StandAlonePreParserNoNatives) { | 329 TEST(StandAlonePreParserNoNatives) { |
| 319 v8::V8::Initialize(); | 330 v8::V8::Initialize(); |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 " }", "\n" | 971 " }", "\n" |
| 961 " more;", i::BLOCK_SCOPE, i::STRICT }, | 972 " more;", i::BLOCK_SCOPE, i::STRICT }, |
| 962 { " start;\n" | 973 { " start;\n" |
| 963 " function fun", "(a,b) { infunction; }", " more;", | 974 " function fun", "(a,b) { infunction; }", " more;", |
| 964 i::FUNCTION_SCOPE, i::SLOPPY }, | 975 i::FUNCTION_SCOPE, i::SLOPPY }, |
| 965 { " start;\n" | 976 { " start;\n" |
| 966 " function fun", "(a,b) {\n" | 977 " function fun", "(a,b) {\n" |
| 967 " infunction;\n" | 978 " infunction;\n" |
| 968 " }", "\n" | 979 " }", "\n" |
| 969 " more;", i::FUNCTION_SCOPE, i::SLOPPY }, | 980 " more;", i::FUNCTION_SCOPE, i::SLOPPY }, |
| 970 { " (function fun", "(a,b) { infunction; }", ")();", | 981 // TODO(aperez): Change to use i::ARROW_SCOPE when implemented |
| 982 { " start;\n", "(a,b) => a + b", "; more;", | |
| 983 i::FUNCTION_SCOPE, i::SLOPPY }, | |
| 984 { " start;\n", "(a,b) => { return a+b; }", "\nmore;", | |
| 985 i::FUNCTION_SCOPE, i::SLOPPY }, | |
| 986 { " start;\n" | |
| 987 " (function fun", "(a,b) { infunction; }", ")();", | |
| 971 i::FUNCTION_SCOPE, i::SLOPPY }, | 988 i::FUNCTION_SCOPE, i::SLOPPY }, |
| 972 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;", | 989 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", " more;", |
| 973 i::BLOCK_SCOPE, i::STRICT }, | 990 i::BLOCK_SCOPE, i::STRICT }, |
| 974 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;", | 991 { " for ", "(let x = 1 ; x < 10; ++ x) { block; }", "; more;", |
| 975 i::BLOCK_SCOPE, i::STRICT }, | 992 i::BLOCK_SCOPE, i::STRICT }, |
| 976 { " for ", "(let x = 1 ; x < 10; ++ x) {\n" | 993 { " for ", "(let x = 1 ; x < 10; ++ x) {\n" |
| 977 " block;\n" | 994 " block;\n" |
| 978 " }", "\n" | 995 " }", "\n" |
| 979 " more;", i::BLOCK_SCOPE, i::STRICT }, | 996 " more;", i::BLOCK_SCOPE, i::STRICT }, |
| 980 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;", | 997 { " for ", "(let x = 1 ; x < 10; ++ x) statement;", " more;", |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1115 | 1132 |
| 1116 // Parse program source. | 1133 // Parse program source. |
| 1117 i::Handle<i::String> source = factory->NewStringFromUtf8( | 1134 i::Handle<i::String> source = factory->NewStringFromUtf8( |
| 1118 i::CStrVector(program.start())).ToHandleChecked(); | 1135 i::CStrVector(program.start())).ToHandleChecked(); |
| 1119 CHECK_EQ(source->length(), kProgramSize); | 1136 CHECK_EQ(source->length(), kProgramSize); |
| 1120 i::Handle<i::Script> script = factory->NewScript(source); | 1137 i::Handle<i::Script> script = factory->NewScript(source); |
| 1121 i::CompilationInfoWithZone info(script); | 1138 i::CompilationInfoWithZone info(script); |
| 1122 i::Parser parser(&info); | 1139 i::Parser parser(&info); |
| 1123 parser.set_allow_lazy(true); | 1140 parser.set_allow_lazy(true); |
| 1124 parser.set_allow_harmony_scoping(true); | 1141 parser.set_allow_harmony_scoping(true); |
| 1142 parser.set_allow_arrow_functions(true); | |
| 1125 info.MarkAsGlobal(); | 1143 info.MarkAsGlobal(); |
| 1126 info.SetStrictMode(source_data[i].strict_mode); | 1144 info.SetStrictMode(source_data[i].strict_mode); |
| 1127 parser.Parse(); | 1145 parser.Parse(); |
| 1128 CHECK(info.function() != NULL); | 1146 CHECK(info.function() != NULL); |
| 1129 | 1147 |
| 1130 // Check scope types and positions. | 1148 // Check scope types and positions. |
| 1131 i::Scope* scope = info.function()->scope(); | 1149 i::Scope* scope = info.function()->scope(); |
| 1132 CHECK(scope->is_global_scope()); | 1150 CHECK(scope->is_global_scope()); |
| 1133 CHECK_EQ(scope->start_position(), 0); | 1151 CHECK_EQ(scope->start_position(), 0); |
| 1134 CHECK_EQ(scope->end_position(), kProgramSize); | 1152 CHECK_EQ(scope->end_position(), kProgramSize); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 void SetParserFlags(i::ParserBase<Traits>* parser, | 1210 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1193 i::EnumSet<ParserFlag> flags) { | 1211 i::EnumSet<ParserFlag> flags) { |
| 1194 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1212 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1195 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); | 1213 parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax)); |
| 1196 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1214 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
| 1197 parser->set_allow_modules(flags.Contains(kAllowModules)); | 1215 parser->set_allow_modules(flags.Contains(kAllowModules)); |
| 1198 parser->set_allow_generators(flags.Contains(kAllowGenerators)); | 1216 parser->set_allow_generators(flags.Contains(kAllowGenerators)); |
| 1199 parser->set_allow_for_of(flags.Contains(kAllowForOf)); | 1217 parser->set_allow_for_of(flags.Contains(kAllowForOf)); |
| 1200 parser->set_allow_harmony_numeric_literals( | 1218 parser->set_allow_harmony_numeric_literals( |
| 1201 flags.Contains(kAllowHarmonyNumericLiterals)); | 1219 flags.Contains(kAllowHarmonyNumericLiterals)); |
| 1220 parser->set_allow_arrow_functions(i::FLAG_harmony_arrow_functions); | |
|
marja
2014/06/17 11:47:38
We'd probably like to run each existing ParserSync
| |
| 1202 } | 1221 } |
| 1203 | 1222 |
| 1204 | 1223 |
| 1205 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1224 void TestParserSyncWithFlags(i::Handle<i::String> source, |
| 1206 i::EnumSet<ParserFlag> flags, | 1225 i::EnumSet<ParserFlag> flags, |
| 1207 ParserSyncTestResult result) { | 1226 ParserSyncTestResult result) { |
| 1208 i::Isolate* isolate = CcTest::i_isolate(); | 1227 i::Isolate* isolate = CcTest::i_isolate(); |
| 1209 i::Factory* factory = isolate->factory(); | 1228 i::Factory* factory = isolate->factory(); |
| 1210 | 1229 |
| 1211 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1230 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1519 "var foo, eval;", | 1538 "var foo, eval;", |
| 1520 "var foo, arguments;", | 1539 "var foo, arguments;", |
| 1521 "try { } catch (eval) { }", | 1540 "try { } catch (eval) { }", |
| 1522 "try { } catch (arguments) { }", | 1541 "try { } catch (arguments) { }", |
| 1523 "function eval() { }", | 1542 "function eval() { }", |
| 1524 "function arguments() { }", | 1543 "function arguments() { }", |
| 1525 "function foo(eval) { }", | 1544 "function foo(eval) { }", |
| 1526 "function foo(arguments) { }", | 1545 "function foo(arguments) { }", |
| 1527 "function foo(bar, eval) { }", | 1546 "function foo(bar, eval) { }", |
| 1528 "function foo(bar, arguments) { }", | 1547 "function foo(bar, arguments) { }", |
| 1548 "(eval) => { }", | |
| 1549 "(arguments) => { }", | |
| 1550 "(foo, eval) => { }", | |
| 1551 "(foo, arguments) => { }", | |
| 1529 "eval = 1;", | 1552 "eval = 1;", |
| 1530 "arguments = 1;", | 1553 "arguments = 1;", |
| 1531 "var foo = eval = 1;", | 1554 "var foo = eval = 1;", |
| 1532 "var foo = arguments = 1;", | 1555 "var foo = arguments = 1;", |
| 1533 "++eval;", | 1556 "++eval;", |
| 1534 "++arguments;", | 1557 "++arguments;", |
| 1535 "eval++;", | 1558 "eval++;", |
| 1536 "arguments++;", | 1559 "arguments++;", |
| 1537 NULL | 1560 NULL |
| 1538 }; | 1561 }; |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2011 program, test_cases[i].functions, | 2034 program, test_cases[i].functions, |
| 2012 data->function_count()); | 2035 data->function_count()); |
| 2013 CHECK(false); | 2036 CHECK(false); |
| 2014 } | 2037 } |
| 2015 delete data; | 2038 delete data; |
| 2016 } | 2039 } |
| 2017 } | 2040 } |
| 2018 | 2041 |
| 2019 | 2042 |
| 2020 TEST(FunctionDeclaresItselfStrict) { | 2043 TEST(FunctionDeclaresItselfStrict) { |
| 2044 i::FLAG_harmony_arrow_functions = true; | |
| 2021 // Tests that we produce the right kinds of errors when a function declares | 2045 // Tests that we produce the right kinds of errors when a function declares |
| 2022 // itself strict (we cannot produce there errors as soon as we see the | 2046 // itself strict (we cannot produce there errors as soon as we see the |
| 2023 // offending identifiers, because we don't know at that point whether the | 2047 // offending identifiers, because we don't know at that point whether the |
| 2024 // function is strict or not). | 2048 // function is strict or not). |
| 2025 const char* context_data[][2] = { | 2049 const char* context_data[][2] = { |
| 2026 {"function eval() {", "}"}, | 2050 {"function eval() {", "}"}, |
| 2027 {"function arguments() {", "}"}, | 2051 {"function arguments() {", "}"}, |
| 2028 {"function yield() {", "}"}, | 2052 {"function yield() {", "}"}, |
| 2029 {"function interface() {", "}"}, | 2053 {"function interface() {", "}"}, |
| 2030 {"function foo(eval) {", "}"}, | 2054 {"function foo(eval) {", "}"}, |
| 2031 {"function foo(arguments) {", "}"}, | 2055 {"function foo(arguments) {", "}"}, |
| 2032 {"function foo(yield) {", "}"}, | 2056 {"function foo(yield) {", "}"}, |
| 2033 {"function foo(interface) {", "}"}, | 2057 {"function foo(interface) {", "}"}, |
| 2034 {"function foo(bar, eval) {", "}"}, | 2058 {"function foo(bar, eval) {", "}"}, |
| 2035 {"function foo(bar, arguments) {", "}"}, | 2059 {"function foo(bar, arguments) {", "}"}, |
| 2036 {"function foo(bar, yield) {", "}"}, | 2060 {"function foo(bar, yield) {", "}"}, |
| 2037 {"function foo(bar, interface) {", "}"}, | 2061 {"function foo(bar, interface) {", "}"}, |
| 2038 {"function foo(bar, bar) {", "}"}, | 2062 {"function foo(bar, bar) {", "}"}, |
| 2063 {"eval => {", "}"}, | |
|
marja
2014/06/17 11:47:38
You could have a separate test case for these, and
| |
| 2064 {"arguments => {", "}"}, | |
| 2065 {"yield => {", "}"}, | |
| 2066 {"interface => {", "}"}, | |
| 2067 {"(eval) => {", "}"}, | |
| 2068 {"(arguments) => {", "}"}, | |
| 2069 {"(yield) => {", "}"}, | |
| 2070 {"(interface) => {", "}"}, | |
| 2071 {"(eval, bar) => {", "}"}, | |
| 2072 {"(bar, eval) => {", "}"}, | |
| 2073 {"(bar, arguments) => {", "}"}, | |
| 2074 {"(bar, yield) => {", "}"}, | |
| 2075 {"(bar, interface) => {", "}"}, | |
| 2076 {"(bar, bar) => {", "}"}, | |
| 2039 { NULL, NULL } | 2077 { NULL, NULL } |
| 2040 }; | 2078 }; |
| 2041 | 2079 |
| 2042 const char* strict_statement_data[] = { | 2080 const char* strict_statement_data[] = { |
| 2043 "\"use strict\";", | 2081 "\"use strict\";", |
| 2044 NULL | 2082 NULL |
| 2045 }; | 2083 }; |
| 2046 | 2084 |
| 2047 const char* non_strict_statement_data[] = { | 2085 const char* non_strict_statement_data[] = { |
| 2048 ";", | 2086 ";", |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2543 v8::Local<v8::String> source = | 2581 v8::Local<v8::String> source = |
| 2544 v8::String::NewFromTwoByte(isolate, two_byte_source); | 2582 v8::String::NewFromTwoByte(isolate, two_byte_source); |
| 2545 v8::Local<v8::Value> result = CompileRun(source); | 2583 v8::Local<v8::Value> result = CompileRun(source); |
| 2546 CHECK(result->IsString()); | 2584 CHECK(result->IsString()); |
| 2547 v8::Local<v8::String> expected_name = | 2585 v8::Local<v8::String> expected_name = |
| 2548 v8::String::NewFromTwoByte(isolate, two_byte_name); | 2586 v8::String::NewFromTwoByte(isolate, two_byte_name); |
| 2549 CHECK(result->Equals(expected_name)); | 2587 CHECK(result->Equals(expected_name)); |
| 2550 i::DeleteArray(two_byte_source); | 2588 i::DeleteArray(two_byte_source); |
| 2551 i::DeleteArray(two_byte_name); | 2589 i::DeleteArray(two_byte_name); |
| 2552 } | 2590 } |
| 2591 | |
| 2592 | |
| 2593 TEST(ErrorsArrowFunctions) { | |
| 2594 // Tests that parser and preparser generate the same kind of errors | |
| 2595 // on invalid arrow function syntax. | |
| 2596 i::FLAG_harmony_arrow_functions = true; | |
| 2597 | |
| 2598 const char* context_data[][2] = { | |
| 2599 {"", ";"}, | |
| 2600 {"v = ", ";"}, | |
| 2601 {"bar ? (", ") : baz;"}, | |
| 2602 {"bar ? baz : (", ");"}, | |
| 2603 {"bar[", "];"}, | |
| 2604 {"bar, ", ";"}, | |
| 2605 {"", ", bar;"}, | |
| 2606 { NULL, NULL } | |
| 2607 }; | |
| 2608 | |
| 2609 const char* statement_data[] = { | |
| 2610 "=> 0", | |
| 2611 "=>", | |
| 2612 "() =>", | |
| 2613 "=> {}", | |
| 2614 ") => {}", | |
| 2615 ", => {}", | |
| 2616 "(,) => {}", | |
| 2617 "return => {}", | |
| 2618 "(a, if) => {}", | |
| 2619 "(a * b) => {}", | |
| 2620 "() => {'value': 42}", | |
| 2621 | |
| 2622 // Check that the early return introduced in ParsePrimaryExpression | |
| 2623 // does not accept stray closing parentheses. | |
| 2624 ")", | |
| 2625 ") => 0", | |
| 2626 "foo[()]", | |
| 2627 "()", | |
| 2628 | |
| 2629 // Parameter lists with extra parens should be recognized as errors. | |
| 2630 "(()) => 0", | |
| 2631 "((x)) => 0", | |
| 2632 "((x, y)) => 0", | |
| 2633 "(x, (y)) => 0", | |
| 2634 "((x, y, z)) => 0", | |
| 2635 "(x, (y, z)) => 0", | |
| 2636 "((x, y), z) => 0", | |
| 2637 | |
|
marja
2014/06/17 11:47:38
Do any of the cases bump into the "is not a variab
| |
| 2638 NULL | |
| 2639 }; | |
| 2640 | |
| 2641 RunParserSyncTest(context_data, statement_data, kError); | |
| 2642 } | |
| 2643 | |
| 2644 | |
| 2645 TEST(NoErrorsArrowFunctions) { | |
| 2646 // Tests that parser and preparser accept valid arrow functions syntax. | |
| 2647 i::FLAG_harmony_arrow_functions = true; | |
| 2648 | |
| 2649 const char* context_data[][2] = { | |
| 2650 {"", ";"}, | |
| 2651 {"bar ? (", ") : baz;"}, | |
| 2652 {"bar ? baz : (", ");"}, | |
| 2653 {"bar, ", ";"}, | |
| 2654 {"", ", bar;"}, | |
| 2655 { NULL, NULL } | |
| 2656 }; | |
| 2657 | |
| 2658 const char* statement_data[] = { | |
| 2659 "() => {}", | |
| 2660 "() => { return 42 }", | |
| 2661 "x => { return x; }", | |
| 2662 "(x) => { return x; }", | |
| 2663 "(x, y) => { return x + y; }", | |
| 2664 "(x, y, z) => { return x + y + z; }", | |
| 2665 "(x, y) => { x.a = y; }", | |
| 2666 "() => 42", | |
| 2667 "x => x", | |
| 2668 "x => x * x", | |
| 2669 "(x) => x", | |
| 2670 "(x) => x * x", | |
| 2671 "(x, y) => x + y", | |
| 2672 "(x, y, z) => x, y, z", | |
| 2673 "(x, y) => x.a = y", | |
| 2674 "() => ({'value': 42})", | |
| 2675 "x => y => x + y", | |
| 2676 "(x, y) => (u, v) => x*u + y*v", | |
| 2677 "(x, y) => z => z * (x + y)", | |
| 2678 "x => (y, z) => z * (x + y)", | |
| 2679 NULL | |
| 2680 }; | |
| 2681 | |
| 2682 RunParserSyncTest(context_data, statement_data, kSuccess); | |
| 2683 } | |
| OLD | NEW |