Jelajahi Sumber

fix unscopables and add test for unscopables (#6608)

Fix array unscopables and update tests

Also sign Contributor agreement

Fix: #6607
MadProbe 5 tahun lalu
induk
melakukan
e6c8f78f50

+ 1 - 0
ContributionAgreement.md

@@ -38,3 +38,4 @@ This agreement has been signed by:
 |Sasha Syrotenko| Fly-Style|
 |Petr Penzin| ppenzin|
 |Yevhen Lukomskyi|ylukomskyi|
+|Evgeniy Istomin|MadProbe|

+ 5 - 3
lib/Runtime/Library/JavascriptLibrary.cpp

@@ -2104,11 +2104,13 @@ namespace Js
 
         DynamicType* dynamicType = DynamicType::New(scriptContext, TypeIds_Object, library->nullValue, nullptr, NullTypeHandler<false>::GetDefaultInstance(), false);
         DynamicObject* unscopablesList = DynamicObject::New(library->GetRecycler(), dynamicType);
-        unscopablesList->SetProperty(PropertyIds::find,       JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
-        unscopablesList->SetProperty(PropertyIds::findIndex,  JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
-        unscopablesList->SetProperty(PropertyIds::fill,       JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
         unscopablesList->SetProperty(PropertyIds::copyWithin, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
         unscopablesList->SetProperty(PropertyIds::entries,    JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
+        unscopablesList->SetProperty(PropertyIds::fill,       JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
+        unscopablesList->SetProperty(PropertyIds::find,       JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
+        unscopablesList->SetProperty(PropertyIds::findIndex,  JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
+        unscopablesList->SetProperty(PropertyIds::flat,       JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
+        unscopablesList->SetProperty(PropertyIds::flatMap,    JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
         unscopablesList->SetProperty(PropertyIds::includes,   JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
         unscopablesList->SetProperty(PropertyIds::keys,       JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
         unscopablesList->SetProperty(PropertyIds::values,     JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);

+ 10 - 6
test/DebuggerCommon/ES6_proto_invalidation.js.dbg.baseline

@@ -439,11 +439,13 @@
               "name": "string forEach"
             },
             "Symbol.unscopables": {
-              "find": "boolean true",
-              "findIndex": "boolean true",
-              "fill": "boolean true",
               "copyWithin": "boolean true",
               "entries": "boolean true",
+              "fill": "boolean true",
+              "find": "boolean true",
+              "findIndex": "boolean true",
+              "flat": "boolean true",
+              "flatMap": "boolean true",
               "includes": "boolean true",
               "keys": "boolean true",
               "values": "boolean true"
@@ -666,11 +668,13 @@
               "name": "string forEach"
             },
             "Symbol.unscopables": {
-              "find": "boolean true",
-              "findIndex": "boolean true",
-              "fill": "boolean true",
               "copyWithin": "boolean true",
               "entries": "boolean true",
+              "fill": "boolean true",
+              "find": "boolean true",
+              "findIndex": "boolean true",
+              "flat": "boolean true",
+              "flatMap": "boolean true",
               "includes": "boolean true",
               "keys": "boolean true",
               "values": "boolean true"

+ 32 - 1
test/es6/unscopablesWithScopeTest.js

@@ -1,5 +1,6 @@
 //-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
+// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
+// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 
@@ -13,6 +14,24 @@ var tests = [
             assert.isTrue(Array.prototype.hasOwnProperty(Symbol.unscopables), "Array should have Array.prototype[@@unscopables] property");
         }
     },
+    {
+        name: "Check if all excepted properties exist in Array.prototype[@@unscopables] and have corresponding values",
+        body: function () 
+        {
+            
+            const unscopables = Array.prototype[Symbol.unscopables];
+
+            const list = ["copyWithin", "entries", "fill", "find", "findIndex", "flat", "flatMap", "includes", "keys", "values"];
+            const length = list.length;
+
+            for (let index = 0; index < length; index++)
+            {
+                const propName = list[index];
+                assert.areEqual(unscopables[propName], true, `Array.prototype[@@unscopables].${ propName } should equal true`);
+            }
+
+        }
+    },
     {
         name: "Global scope test on Arrays",
         body: function ()
@@ -26,6 +45,8 @@ var tests = [
             var includes    = globalScope;
             var keys        = globalScope;
             var values      = globalScope;
+            var flat        = globalScope;
+            var flatMap     = globalScope;
             with([])
             {
                 assert.areEqual(globalScope, find,       "find property is not brought into scope by the with statement");
@@ -36,6 +57,8 @@ var tests = [
                 assert.areEqual(globalScope, includes,   "includes property is not brought into scope by the with statement");
                 assert.areEqual(globalScope, keys,       "keys property is not brought into scope by the with statement");
                 assert.areEqual(globalScope, values,     "values property is not brought into scope by the with statement");
+                assert.areEqual(globalScope, flat,       "flat property is not brought into scope by the with statement");
+                assert.areEqual(globalScope, flatMap,    "flatMap property is not brought into scope by the with statement");
             }
         }
     },
@@ -53,6 +76,8 @@ var tests = [
             var keys        = globalScope;
             var values      = globalScope;
             var slice       = globalScope;
+            var flat        = globalScope;
+            var flatMap     = globalScope;
             var a = [];
             a[Symbol.unscopables]["slice"] = true;
             with(a)
@@ -66,6 +91,8 @@ var tests = [
                 assert.areEqual(globalScope, keys,       "keys property is not brought into scope by the with statement");
                 assert.areEqual(globalScope, values,     "values property is not brought into scope by the with statement");
                 assert.areEqual(globalScope, slice,      "slice property is not brought into scope by the with statement");
+                assert.areEqual(globalScope, flat,       "flat property is not brought into scope by the with statement");
+                assert.areEqual(globalScope, flatMap,    "flatMap property is not brought into scope by the with statement");
             }
         }
     },
@@ -236,6 +263,8 @@ var tests = [
             var includes   = globalScope;
             var keys       = globalScope;
             var values     = globalScope;
+            var flat       = globalScope;
+            var flatMap    = globalScope;
             with([])
             {
                 function foo()
@@ -254,6 +283,8 @@ var tests = [
                                 assert.areEqual(globalScope, includes,   "includes property is not brought into scope by the with statement");
                                 assert.areEqual(globalScope, keys,       "keys property is not brought into scope by the with statement");
                                 assert.areEqual(globalScope, values,     "values property is not brought into scope by the with statement");
+                                assert.areEqual(globalScope, flat,       "flat property is not brought into scope by the with statement");
+                                assert.areEqual(globalScope, flatMap,    "flatMap property is not brought into scope by the with statement");
                             }
                         }
                     }