Skip to content

Commit 177ee99

Browse files
author
Irina Yatsenko
committed
delete of nonconfigurable indexed property should throw in strict mode
(tested with TypedArray)
1 parent 9189a4b commit 177ee99

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4818,6 +4818,11 @@ namespace Js
48184818
#endif
48194819
}
48204820

4821+
if (result == FALSE && (propertyOperationFlags & PropertyOperation_StrictMode))
4822+
{
4823+
JavascriptError::ThrowCantDelete(propertyOperationFlags, scriptContext, GetPropertyDisplayNameForError(index, scriptContext)->GetString());
4824+
}
4825+
48214826
return scriptContext->GetLibrary()->CreateBoolean(result);
48224827
}
48234828

test/typedarray/delete.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
7+
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
8+
this.WScript.LoadScriptFile("util.js");
9+
}
10+
11+
var tests = [
12+
{
13+
name: "Typed arrays support delete of non-indexed properties",
14+
body: function () {
15+
const ta = Int8Array.of(42);
16+
17+
ta.non_indexed = 'whatever';
18+
assert.areEqual('whatever', ta.non_indexed, "ta.non_indexed is set to 'whatever'");
19+
20+
delete ta.non_indexed;
21+
assert.areEqual(undefined, ta.non_indexed, "ta.non_indexed has been deleted");
22+
}
23+
},
24+
{
25+
name: "delete of nonconfigurable non-indexed properties on Typed arrays",
26+
body: function () {
27+
const ta = Int8Array.of(42);
28+
var id = 'id';
29+
Object.defineProperty(ta, id, { value: 17, configurable: false });
30+
31+
delete ta[id];
32+
assert.areEqual(17, ta[id], "ta['id'] value after failed delete");
33+
34+
assert.throws(function () { 'use strict'; delete ta[id]; }, TypeError, "Should throw on delete of indexed property in typed array", "Calling delete on 'id' is not allowed in strict mode");
35+
}
36+
},
37+
{
38+
name: "Typed arrays don't support delete of indexed properties",
39+
body: function () {
40+
const ta = Int8Array.of(42);
41+
42+
delete ta[0];
43+
assert.areEqual(42, ta[0], "ta[0] value after failed delete");
44+
45+
assert.throws(function () { 'use strict'; delete ta[0]; }, TypeError, "Should throw on delete of indexed property in typed array", "Calling delete on '0' is not allowed in strict mode");
46+
}
47+
}
48+
];
49+
50+
testRunner.runTests(tests, { verbose: false /*so no need to provide baseline*/ });

test/typedarray/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,10 @@ Below test fails with difference in space. Investigate the cause and re-enable t
387387
<tags>typedarray</tags>
388388
</default>
389389
</test>
390+
<test>
391+
<default>
392+
<files>delete.js</files>
393+
<tags>typedarray</tags>
394+
</default>
395+
</test>
390396
</regress-exe>

0 commit comments

Comments
 (0)