summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js')
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js
new file mode 100644
index 0000000000..7db1e088fd
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js
@@ -0,0 +1,47 @@
+// Copyright (C) 2020 Sony Interactive Entertainment Inc. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.unshift
+description: >
+ Array#unshift throws TypeError upon attempting to modify a string
+info: |
+ Array.prototype.unshift ( ...items )
+ ...
+ 4. If argCount > 0, then
+ ...
+ c. Repeat, while k > 0,
+ ...
+ iv. If fromPresent is true, then
+ ...
+ 2. Perform ? Set(O, to, fromValue, true).
+ ...
+ ...
+ f. Repeat, while items is not empty
+ ...
+ Perform ? Set(O, ! ToString(j), E, true).
+ ...
+ 5. Perform ? Set(O, "length", len + argCount, true).
+
+ Set ( O, P, V, Throw )
+ ...
+ 4. Let success be ? O.[[Set]](P, V, O).
+ 5. If success is false and Throw is true, throw a TypeError exception.
+---*/
+
+assert.throws(TypeError, () => {
+ Array.prototype.unshift.call('');
+}, "Array.prototype.unshift.call('')");
+
+assert.throws(TypeError, () => {
+ Array.prototype.unshift.call('', 1);
+}, "Array.prototype.unshift.call('', 1)");
+
+assert.throws(TypeError, () => {
+ Array.prototype.unshift.call('abc');
+}, "Array.prototype.unshift.call('abc')");
+
+assert.throws(TypeError, () => {
+ Array.prototype.unshift.call('abc', 1);
+}, "Array.prototype.unshift.call('abc', 1)");
+
+reportCompare(0, 0);