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 1704223002: Remove strong mode support from Scope and Variable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove test-parsing test Created 4 years, 10 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
« no previous file with comments | « src/parsing/parser-base.h ('k') | test/mjsunit/strong/declaration-after-use.js » ('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 6640 matching lines...) Expand 10 before | Expand all | Expand 10 after
6651 CHECK(!try_catch.HasCaught()); 6651 CHECK(!try_catch.HasCaught());
6652 6652
6653 const char* script2 = 6653 const char* script2 =
6654 "\"use strong\"; \n" 6654 "\"use strong\"; \n"
6655 "my_var; \n"; 6655 "my_var; \n";
6656 CompileRun(v8_str(script2)); 6656 CompileRun(v8_str(script2));
6657 CHECK(!try_catch.HasCaught()); 6657 CHECK(!try_catch.HasCaught());
6658 } 6658 }
6659 6659
6660 6660
6661 TEST(StrongModeFreeVariablesNotDeclared) {
6662 i::FLAG_strong_mode = true;
6663 v8::V8::Initialize();
6664 v8::HandleScope scope(CcTest::isolate());
6665 v8::Context::Scope context_scope(v8::Context::New(CcTest::isolate()));
6666 v8::TryCatch try_catch(CcTest::isolate());
6667
6668 // Test that referencing unintroduced variables in sloppy mode is ok.
6669 const char* script1 =
6670 "if (false) { \n"
6671 " not_there1; \n"
6672 "} \n";
6673 CompileRun(v8_str(script1));
6674 CHECK(!try_catch.HasCaught());
6675
6676 // But not in strong mode.
6677 {
6678 const char* script2 =
6679 "\"use strong\"; \n"
6680 "if (false) { \n"
6681 " not_there2; \n"
6682 "} \n";
6683 v8::TryCatch try_catch2(CcTest::isolate());
6684 v8_compile(v8_str(script2));
6685 CHECK(try_catch2.HasCaught());
6686 v8::String::Utf8Value exception(try_catch2.Exception());
6687 CHECK_EQ(0,
6688 strcmp(
6689 "ReferenceError: In strong mode, using an undeclared global "
6690 "variable 'not_there2' is not allowed",
6691 *exception));
6692 }
6693
6694 // Check that the variable reference is detected inside a strong function too,
6695 // even if the script scope is not strong.
6696 {
6697 const char* script3 =
6698 "(function not_lazy() { \n"
6699 " \"use strong\"; \n"
6700 " if (false) { \n"
6701 " not_there3; \n"
6702 " } \n"
6703 "})(); \n";
6704 v8::TryCatch try_catch2(CcTest::isolate());
6705 v8_compile(v8_str(script3));
6706 CHECK(try_catch2.HasCaught());
6707 v8::String::Utf8Value exception(try_catch2.Exception());
6708 CHECK_EQ(0,
6709 strcmp(
6710 "ReferenceError: In strong mode, using an undeclared global "
6711 "variable 'not_there3' is not allowed",
6712 *exception));
6713 }
6714 }
6715
6716 static const ParserFlag kAllDestructuringFlags[] = { 6661 static const ParserFlag kAllDestructuringFlags[] = {
6717 kAllowHarmonyDestructuring, kAllowHarmonyDestructuringAssignment, 6662 kAllowHarmonyDestructuring, kAllowHarmonyDestructuringAssignment,
6718 kAllowHarmonyDefaultParameters}; 6663 kAllowHarmonyDefaultParameters};
6719 6664
6720 TEST(DestructuringPositiveTests) { 6665 TEST(DestructuringPositiveTests) {
6721 i::FLAG_harmony_destructuring_bind = true; 6666 i::FLAG_harmony_destructuring_bind = true;
6722 6667
6723 const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, 6668 const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
6724 {"var ", " = {};"}, 6669 {"var ", " = {};"},
6725 {"'use strict'; const ", " = {};"}, 6670 {"'use strict'; const ", " = {};"},
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
8036 { NULL, NULL } 7981 { NULL, NULL }
8037 }; 7982 };
8038 const char* error_data[] = { 7983 const char* error_data[] = {
8039 "var x = new.target", 7984 "var x = new.target",
8040 "function f() { return new.t\\u0061rget; }", 7985 "function f() { return new.t\\u0061rget; }",
8041 NULL 7986 NULL
8042 }; 7987 };
8043 // clang-format on 7988 // clang-format on
8044 RunParserSyncTest(context_data, error_data, kError); 7989 RunParserSyncTest(context_data, error_data, kError);
8045 } 7990 }
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | test/mjsunit/strong/declaration-after-use.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698