-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for String.prototype.indexOf first parameter type coercion
- Loading branch information
Showing
2 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/built-ins/String/prototype/indexOf/searchstring-tostring.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2017 Josh Wolfe. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-string.prototype.indexof | ||
description: String.prototype.indexOf type coercion for searchString parameter | ||
info: > | ||
String.prototype.indexOf ( searchString [ , position ] ) | ||
3. Let searchStr be ? ToString(searchString). | ||
includes: [typeCoercion.js] | ||
---*/ | ||
|
||
testCoercibleToString(function(value, expectedString) { | ||
if (expectedString.length === 0) { | ||
assert.sameValue(("x_x_x").indexOf(value), 0); | ||
} else { | ||
assert.sameValue(expectedString.indexOf("\x00"), -1, "sanity check"); | ||
assert.sameValue(("\x00\x00" + expectedString + "\x00\x00").indexOf(value), 2); | ||
} | ||
}); | ||
|
||
testNotCoercibleToString(function(error, value) { | ||
assert.throws(error, function() { "".indexOf(value); }); | ||
}); |