summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/split/this-value-tostring-error.js
blob: a03b9ebaf7c7f383cf1b7d76d7ae93794f568313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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_, « _O_, _limit_ »).
  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);