Skip to content

Commit e6c8f78

Browse files
authored
fix unscopables and add test for unscopables (#6608)
Fix array unscopables and update tests Also sign Contributor agreement Fix: #6607
1 parent 3b3aa9b commit e6c8f78

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

ContributionAgreement.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ This agreement has been signed by:
3838
|Sasha Syrotenko| Fly-Style|
3939
|Petr Penzin| ppenzin|
4040
|Yevhen Lukomskyi|ylukomskyi|
41+
|Evgeniy Istomin|MadProbe|

lib/Runtime/Library/JavascriptLibrary.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2104,11 +2104,13 @@ namespace Js
21042104

21052105
DynamicType* dynamicType = DynamicType::New(scriptContext, TypeIds_Object, library->nullValue, nullptr, NullTypeHandler<false>::GetDefaultInstance(), false);
21062106
DynamicObject* unscopablesList = DynamicObject::New(library->GetRecycler(), dynamicType);
2107-
unscopablesList->SetProperty(PropertyIds::find, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2108-
unscopablesList->SetProperty(PropertyIds::findIndex, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2109-
unscopablesList->SetProperty(PropertyIds::fill, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
21102107
unscopablesList->SetProperty(PropertyIds::copyWithin, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
21112108
unscopablesList->SetProperty(PropertyIds::entries, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2109+
unscopablesList->SetProperty(PropertyIds::fill, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2110+
unscopablesList->SetProperty(PropertyIds::find, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2111+
unscopablesList->SetProperty(PropertyIds::findIndex, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2112+
unscopablesList->SetProperty(PropertyIds::flat, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
2113+
unscopablesList->SetProperty(PropertyIds::flatMap, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
21122114
unscopablesList->SetProperty(PropertyIds::includes, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
21132115
unscopablesList->SetProperty(PropertyIds::keys, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);
21142116
unscopablesList->SetProperty(PropertyIds::values, JavascriptBoolean::ToVar(true, scriptContext), PropertyOperation_None, nullptr);

test/DebuggerCommon/ES6_proto_invalidation.js.dbg.baseline

+10-6
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,13 @@
439439
"name": "string forEach"
440440
},
441441
"Symbol.unscopables": {
442-
"find": "boolean true",
443-
"findIndex": "boolean true",
444-
"fill": "boolean true",
445442
"copyWithin": "boolean true",
446443
"entries": "boolean true",
444+
"fill": "boolean true",
445+
"find": "boolean true",
446+
"findIndex": "boolean true",
447+
"flat": "boolean true",
448+
"flatMap": "boolean true",
447449
"includes": "boolean true",
448450
"keys": "boolean true",
449451
"values": "boolean true"
@@ -666,11 +668,13 @@
666668
"name": "string forEach"
667669
},
668670
"Symbol.unscopables": {
669-
"find": "boolean true",
670-
"findIndex": "boolean true",
671-
"fill": "boolean true",
672671
"copyWithin": "boolean true",
673672
"entries": "boolean true",
673+
"fill": "boolean true",
674+
"find": "boolean true",
675+
"findIndex": "boolean true",
676+
"flat": "boolean true",
677+
"flatMap": "boolean true",
674678
"includes": "boolean true",
675679
"keys": "boolean true",
676680
"values": "boolean true"

test/es6/unscopablesWithScopeTest.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//-------------------------------------------------------------------------------------------------------
2-
// Copyright (C) Microsoft. All rights reserved.
2+
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
3+
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
34
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
45
//-------------------------------------------------------------------------------------------------------
56

@@ -13,6 +14,24 @@ var tests = [
1314
assert.isTrue(Array.prototype.hasOwnProperty(Symbol.unscopables), "Array should have Array.prototype[@@unscopables] property");
1415
}
1516
},
17+
{
18+
name: "Check if all excepted properties exist in Array.prototype[@@unscopables] and have corresponding values",
19+
body: function ()
20+
{
21+
22+
const unscopables = Array.prototype[Symbol.unscopables];
23+
24+
const list = ["copyWithin", "entries", "fill", "find", "findIndex", "flat", "flatMap", "includes", "keys", "values"];
25+
const length = list.length;
26+
27+
for (let index = 0; index < length; index++)
28+
{
29+
const propName = list[index];
30+
assert.areEqual(unscopables[propName], true, `Array.prototype[@@unscopables].${ propName } should equal true`);
31+
}
32+
33+
}
34+
},
1635
{
1736
name: "Global scope test on Arrays",
1837
body: function ()
@@ -26,6 +45,8 @@ var tests = [
2645
var includes = globalScope;
2746
var keys = globalScope;
2847
var values = globalScope;
48+
var flat = globalScope;
49+
var flatMap = globalScope;
2950
with([])
3051
{
3152
assert.areEqual(globalScope, find, "find property is not brought into scope by the with statement");
@@ -36,6 +57,8 @@ var tests = [
3657
assert.areEqual(globalScope, includes, "includes property is not brought into scope by the with statement");
3758
assert.areEqual(globalScope, keys, "keys property is not brought into scope by the with statement");
3859
assert.areEqual(globalScope, values, "values property is not brought into scope by the with statement");
60+
assert.areEqual(globalScope, flat, "flat property is not brought into scope by the with statement");
61+
assert.areEqual(globalScope, flatMap, "flatMap property is not brought into scope by the with statement");
3962
}
4063
}
4164
},
@@ -53,6 +76,8 @@ var tests = [
5376
var keys = globalScope;
5477
var values = globalScope;
5578
var slice = globalScope;
79+
var flat = globalScope;
80+
var flatMap = globalScope;
5681
var a = [];
5782
a[Symbol.unscopables]["slice"] = true;
5883
with(a)
@@ -66,6 +91,8 @@ var tests = [
6691
assert.areEqual(globalScope, keys, "keys property is not brought into scope by the with statement");
6792
assert.areEqual(globalScope, values, "values property is not brought into scope by the with statement");
6893
assert.areEqual(globalScope, slice, "slice property is not brought into scope by the with statement");
94+
assert.areEqual(globalScope, flat, "flat property is not brought into scope by the with statement");
95+
assert.areEqual(globalScope, flatMap, "flatMap property is not brought into scope by the with statement");
6996
}
7097
}
7198
},
@@ -236,6 +263,8 @@ var tests = [
236263
var includes = globalScope;
237264
var keys = globalScope;
238265
var values = globalScope;
266+
var flat = globalScope;
267+
var flatMap = globalScope;
239268
with([])
240269
{
241270
function foo()
@@ -254,6 +283,8 @@ var tests = [
254283
assert.areEqual(globalScope, includes, "includes property is not brought into scope by the with statement");
255284
assert.areEqual(globalScope, keys, "keys property is not brought into scope by the with statement");
256285
assert.areEqual(globalScope, values, "values property is not brought into scope by the with statement");
286+
assert.areEqual(globalScope, flat, "flat property is not brought into scope by the with statement");
287+
assert.areEqual(globalScope, flatMap, "flatMap property is not brought into scope by the with statement");
257288
}
258289
}
259290
}

0 commit comments

Comments
 (0)