From 5d1a0ee578df90b36a84107d11d69d9b7e532d1f Mon Sep 17 00:00:00 2001 From: Aneesh Divakarakurup Date: Thu, 2 Aug 2018 17:48:59 -0700 Subject: [PATCH] OS:18468078:Adding a check for the case where lambda method accessing super in global scope When a labmda method access super property in the global scope the currentnonlambdafunc will be nullptr. This should be a SyntaxError. --- lib/Parser/Parse.cpp | 2 +- test/Bugs/SuperAccessInGlobalLambda.baseline | 2 ++ test/Bugs/SuperAccessInGlobalLambda.js | 6 ++++++ test/Bugs/rlexe.xml | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/Bugs/SuperAccessInGlobalLambda.baseline create mode 100644 test/Bugs/SuperAccessInGlobalLambda.js diff --git a/lib/Parser/Parse.cpp b/lib/Parser/Parse.cpp index dc564109227..69159bcba42 100644 --- a/lib/Parser/Parse.cpp +++ b/lib/Parser/Parse.cpp @@ -12323,7 +12323,7 @@ IdentPtr Parser::ParseSuper(bool fAllowCall) { // Any super access is good within a class constructor } - else if ((this->m_grfscr & fscrEval) == fscrEval || currentNonLambdaFunc->superRestrictionState == SuperRestrictionState::PropertyAllowed) + else if ((this->m_grfscr & fscrEval) == fscrEval || (currentNonLambdaFunc != nullptr && currentNonLambdaFunc->superRestrictionState == SuperRestrictionState::PropertyAllowed)) { // Currently for eval cases during compile time we use propertyallowed and throw during runtime for error cases if (m_token.tk == tkLParen) diff --git a/test/Bugs/SuperAccessInGlobalLambda.baseline b/test/Bugs/SuperAccessInGlobalLambda.baseline new file mode 100644 index 00000000000..ccfaa95e867 --- /dev/null +++ b/test/Bugs/SuperAccessInGlobalLambda.baseline @@ -0,0 +1,2 @@ +SyntaxError: Invalid use of the 'super' keyword + at code (SuperAccessInGlobalLambda.js:6:12) diff --git a/test/Bugs/SuperAccessInGlobalLambda.js b/test/Bugs/SuperAccessInGlobalLambda.js new file mode 100644 index 00000000000..0207a223cba --- /dev/null +++ b/test/Bugs/SuperAccessInGlobalLambda.js @@ -0,0 +1,6 @@ +//------------------------------------------------------------------------------------------------------- +// Copyright (C) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. +//------------------------------------------------------------------------------------------------------- + +() => super.a; diff --git a/test/Bugs/rlexe.xml b/test/Bugs/rlexe.xml index a1043f241ec..6f951bdd6cf 100644 --- a/test/Bugs/rlexe.xml +++ b/test/Bugs/rlexe.xml @@ -523,4 +523,11 @@ -force:cachedScope + + + SuperAccessInGlobalLambda.js + SuperAccessInGlobalLambda.baseline + exclude_jshost + +