mirror of https://github.com/tc39/test262.git
Improve is/toWellFormedString coverage.
This commit is contained in:
parent
06b982d2f0
commit
920a567b72
|
@ -11,7 +11,6 @@ info: |
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
features: [String.prototype.isWellFormed]
|
features: [String.prototype.isWellFormed]
|
||||||
---*/
|
---*/
|
||||||
assert.sameValue(typeof String.prototype.isWellFormed, 'function');
|
|
||||||
|
|
||||||
assert.sameValue(
|
assert.sameValue(
|
||||||
typeof String.prototype.isWellFormed,
|
typeof String.prototype.isWellFormed,
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.iswellformed
|
||||||
|
description: >
|
||||||
|
The method should coerce the receiver to a string.
|
||||||
|
info: |
|
||||||
|
String.prototype.isWellFormed ( )
|
||||||
|
|
||||||
|
2. Let S be ? ToString(O).
|
||||||
|
…
|
||||||
|
|
||||||
|
features: [String.prototype.isWellFormed]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
[true, Boolean.prototype],
|
||||||
|
[1, Number.prototype],
|
||||||
|
[1n, BigInt.prototype],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [v, proto] of tests) {
|
||||||
|
proto.toString = function() {
|
||||||
|
throw new Test262Error(`should not call toString on the prototype for ${typeof v}`);
|
||||||
|
}
|
||||||
|
let result = String.prototype.isWellFormed.call(v);
|
||||||
|
delete proto.toString;
|
||||||
|
assert.sameValue(result, true, `isWellFormed for ${typeof v}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
Symbol.prototype.toString = function() { throw new TypeError("should not call toString on the prototype for Symbol"); }
|
||||||
|
assert.throws(TypeError, () => String.prototype.isWellFormed.call(Symbol()), `Built-in result for Symbol`);
|
|
@ -11,10 +11,9 @@ info: |
|
||||||
includes: [propertyHelper.js]
|
includes: [propertyHelper.js]
|
||||||
features: [String.prototype.toWellFormed]
|
features: [String.prototype.toWellFormed]
|
||||||
---*/
|
---*/
|
||||||
assert.sameValue(typeof String.prototype.toWellFormed, 'function');
|
|
||||||
|
|
||||||
assert.sameValue(
|
assert.sameValue(
|
||||||
typeof String.prototype.isWellFormed,
|
typeof String.prototype.toWellFormed,
|
||||||
'function',
|
'function',
|
||||||
'The value of `typeof String.prototype.toWellFormed` is "function"'
|
'The value of `typeof String.prototype.toWellFormed` is "function"'
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.towellformed
|
||||||
|
description: >
|
||||||
|
The method should coerce the receiver to a string.
|
||||||
|
info: |
|
||||||
|
String.prototype.toWellFormed ( )
|
||||||
|
|
||||||
|
2. Let S be ? ToString(O).
|
||||||
|
…
|
||||||
|
|
||||||
|
features: [String.prototype.toWellFormed]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
[true, "true", Boolean.prototype],
|
||||||
|
[1, "1", Number.prototype],
|
||||||
|
[1n, "1", BigInt.prototype],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [v, expected, proto] of tests) {
|
||||||
|
proto.toString = function() {
|
||||||
|
throw new Test262Error(`should not call toString on the prototype for ${typeof v}`);
|
||||||
|
}
|
||||||
|
let result = String.prototype.toWellFormed.call(v);
|
||||||
|
delete proto.toString;
|
||||||
|
assert.sameValue(result, expected, `toWellFormed for ${typeof v}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
Symbol.prototype.toString = function() { throw new TypeError("should not call toString on the prototype for Symbol"); }
|
||||||
|
assert.throws(TypeError, () => String.prototype.toWellFormed.call(Symbol()), `Built-in result for Symbol`);
|
Loading…
Reference in New Issue