Test the sequence of potentially abrupt steps in String.prototype.split

This commit is contained in:
Richard Gibson 2020-08-19 20:58:41 -04:00 committed by Rick Waldron
parent 2dd3e50064
commit 4f126a8ce9
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,22 @@
// 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 ToUint32 on the limit
info: |
1. If _limit_ is *undefined*, let _lim_ be 2<sup>32</sup> - 1; else let _lim_ be ? ToUint32(_limit_).
1. Let _R_ be ? ToString(_separator_).
1. If _lim_ = 0, return _A_.
---*/
var nonStringableSeparator = {};
nonStringableSeparator[Symbol.toPrimitive] = $DONOTEVALUATE;
nonStringableSeparator.toString = $DONOTEVALUATE;
nonStringableSeparator.valueOf = $DONOTEVALUATE;
var nonNumberableLimit = {};
nonStringableSeparator[Symbol.toPrimitive] = function() { throw new Test262Error(); };
assert.throws(Test262Error, function() {
"foo".split(nonStringableSeparator, nonNumberableLimit);
}, 'ToUint32 should be called on the limit before ToString on the separator.');

View File

@ -0,0 +1,16 @@
// 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 separator
info: |
1. Let _R_ be ? ToString(_separator_).
1. If _lim_ = 0, return _A_.
---*/
var nonStringableSeparator = {};
nonStringableSeparator.toString = function() { throw new Test262Error(); };
assert.throws(Test262Error, function() {
"foo".split(nonStringableSeparator, 0);
}, 'ToString should be called on the separator before checking if the limit is zero.');

View File

@ -0,0 +1,37 @@
// 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_).
---*/
var split = String.prototype.split;
var nonStringableReceiver = {};
nonStringableReceiver.toString = function() { throw new Test262Error(); };
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] = $DONOTEVALUATE;
nonStringableSeparator.toString = $DONOTEVALUATE;
nonStringableSeparator.valueOf = $DONOTEVALUATE;
assert.throws(Test262Error, function() {
split.call(nonStringableReceiver, nonStringableSeparator, Symbol());
}, 'ToString should be called on the receiver before processing the separator or limit.');