summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js')
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js b/js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js
new file mode 100644
index 0000000000..a03b9ebaf7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js
@@ -0,0 +1,48 @@
+// Copyright (C) 2020 Richard Gibson. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-string.prototype.split
+description: Abrupt completion from ToString on the "this" value
+info: |
+ 1. Let _O_ be ? RequireObjectCoercible(*this* value).
+ 1. If _separator_ is neither *undefined* nor *null*, then
+ 1. Let _splitter_ be ? GetMethod(_separator_, @@split).
+ 1. If _splitter_ is not *undefined*, then
+ 1. Return ? Call(_splitter_, _separator_, &laquo; _O_, _limit_ &raquo;).
+ 1. Let _S_ be ? ToString(_O_).
+features: [Symbol, Symbol.split, Symbol.toPrimitive]
+---*/
+
+function ExpectedError(message) {
+ this.message = message || "";
+}
+ExpectedError.prototype.toString = function () {
+ return "ExpectedError: " + this.message;
+};
+
+var split = String.prototype.split;
+
+var nonStringableReceiver = {};
+nonStringableReceiver.toString = function() { throw new ExpectedError("receiver.toString"); };
+
+var splitter = {};
+splitter[Symbol.split] = function() {};
+
+try {
+ split.call(nonStringableReceiver, splitter, Symbol());
+} catch (e) {
+ assert.sameValue(e, undefined,
+ 'ToString should not be called on the receiver when the separator has a @@split method.');
+}
+
+var nonStringableSeparator = {};
+nonStringableSeparator[Symbol.toPrimitive] =
+ function() { throw new Test262Error("separator[Symbol.toPrimitive]"); };
+nonStringableSeparator.toString = function() { throw new Test262Error("separator.toString"); };
+nonStringableSeparator.valueOf = function() { throw new Test262Error("separator.valueOf"); };
+
+assert.throws(ExpectedError, function() {
+ split.call(nonStringableReceiver, nonStringableSeparator, Symbol());
+}, 'ToString should be called on the receiver before processing the separator or limit.');
+
+reportCompare(0, 0);