mirror of https://github.com/tc39/test262.git
Add this value object testing to trimEnd
This commit is contained in:
parent
2b7df61dd6
commit
56d57956a0
57
test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js
vendored
Normal file
57
test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
This value is an object which cannot be converted to a primitive
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
6. Throw a TypeError exception.
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
toString: undefined,
|
||||||
|
valueOf: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
// If trimEnd is called on an object with neither Symbol.toPrimitive, toString
|
||||||
|
// nor valueOf defined, then a TypeError exception should be thrown.
|
||||||
|
assert.throws(
|
||||||
|
TypeError,
|
||||||
|
function() { String.prototype.trimEnd.call(thisVal); },
|
||||||
|
);
|
34
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js
vendored
Normal file
34
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when getting Symbol.toPrimitive method
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
|
||||||
|
...
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
get [Symbol.toPrimitive]() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
36
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-err.js
vendored
Normal file
36
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-err.js
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when Symbol.toPrimitive abrupt completes.
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
...
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
74
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js
vendored
Normal file
74
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js
vendored
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Priority of Symbol[toPrimitive] when converting object to string for trimming
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
...
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
|
||||||
|
var toPrimitiveAccessed = 0;
|
||||||
|
var toStringAccessed = 0;
|
||||||
|
var valueOfAccessed = 0;
|
||||||
|
var thisVal = {
|
||||||
|
get [Symbol.toPrimitive]() {
|
||||||
|
toPrimitiveAccessed += 1;
|
||||||
|
return function() { return '42 '; };
|
||||||
|
},
|
||||||
|
get toString() {
|
||||||
|
toStringAccessed += 1;
|
||||||
|
return function() { return ''; };
|
||||||
|
},
|
||||||
|
get valueOf() {
|
||||||
|
valueOfAccessed += 1;
|
||||||
|
return function() { return ''; };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test that thisVal[Symbol.toPrimitive] has been called.
|
||||||
|
|
||||||
|
var result = String.prototype.trimEnd.call(thisVal);
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
toPrimitiveAccessed,
|
||||||
|
1,
|
||||||
|
'thisVal[Symbol.toPrimitive] expected to have been accessed.'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
'42',
|
||||||
|
'thisVal[Symbol.toPrimitive] expected to have been called.',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test that thisVal.toString and thisVal.valueOf have not been accessedo
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
toStringAccessed,
|
||||||
|
0,
|
||||||
|
'thisVal.toString should not have been accessed.'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
valueOfAccessed,
|
||||||
|
0,
|
||||||
|
'thisVal.valueOf should not have been accessed.'
|
||||||
|
);
|
38
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-returns-object-err.js
vendored
Normal file
38
test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-returns-object-err.js
vendored
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when Symbol.toPrimitive returns an object
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If arguement is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
...
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: function() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
51
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js
vendored
Normal file
51
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when getting toString method
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
get toString() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
53
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-err.js
vendored
Normal file
53
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-err.js
vendored
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when toString called and abrupt completes.
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
93
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js
vendored
Normal file
93
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js
vendored
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Priority of toString when converting object to string for trimming
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
...
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toPrimitiveAccessed = 0;
|
||||||
|
var toStringAccessed = 0;
|
||||||
|
var valueOfAccessed = 0;
|
||||||
|
var thisVal = {
|
||||||
|
get [Symbol.toPrimitive]() {
|
||||||
|
toPrimitiveAccessed +=1;
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
get toString() {
|
||||||
|
toStringAccessed += 1;
|
||||||
|
return function() { return '42 '; };
|
||||||
|
},
|
||||||
|
get valueOf() {
|
||||||
|
valueOfAccessed += 1;
|
||||||
|
return function() { return ''; };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test that toString is called when Symbol.toPrimitive is undefined.
|
||||||
|
|
||||||
|
var result = String.prototype.trimEnd.call(thisVal)
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
toPrimitiveAccessed,
|
||||||
|
1,
|
||||||
|
'thisVal.toString expected to have been accessed.'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
'42',
|
||||||
|
'thisVal.toString expected to have been called.',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test that thisVal[toPrimitive] has been accessed.
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
toPrimitiveAccessed,
|
||||||
|
1,
|
||||||
|
'thisVal[Symbol.toPrimitive should have been accessed.'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test that thisVal.valueOf has not been accessed.
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
valueOfAccessed,
|
||||||
|
0,
|
||||||
|
'thisVal.valueOf should not have been accessed.'
|
||||||
|
);
|
56
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-returns-object-err.js
vendored
Normal file
56
test/built-ins/String/prototype/trimEnd/this-value-object-tostring-returns-object-err.js
vendored
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when toString called and returns an object
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
6. Throw a TypeError exception.
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
toString: function() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
52
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js
vendored
Normal file
52
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when getting valueOf method
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
toString: undefined,
|
||||||
|
get valueOf() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
54
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-err.js
vendored
Normal file
54
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-err.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when valueOf called and abrupt completes.
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
toString: undefined,
|
||||||
|
valueOf: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
91
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js
vendored
Normal file
91
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js
vendored
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Priority of valueOf when converting object to string for trimming
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
...
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var toPrimitiveAccessed = 0;
|
||||||
|
var toStringAccessed = 0;
|
||||||
|
var valueOfAccessed = 0;
|
||||||
|
var thisVal = {
|
||||||
|
get [Symbol.toPrimitive]() {
|
||||||
|
toPrimitiveAccessed += 1;
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
get toString() {
|
||||||
|
toStringAccessed += 1;
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
get valueOf() {
|
||||||
|
valueOfAccessed += 1;
|
||||||
|
return function() { return '42 '; };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test that valueOf is called when Symbol.toPrimitive and toString are both
|
||||||
|
// undefined.
|
||||||
|
|
||||||
|
var result = String.prototype.trimEnd.call(thisVal);
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
valueOfAccessed,
|
||||||
|
1,
|
||||||
|
'thisVal.toString expected to have been accessed.'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
result,
|
||||||
|
'42',
|
||||||
|
'thisVal.valueOf expected to have been called.',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test that thisVal[toPrimitive] and thisVal.toString has been accessed.
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
toPrimitiveAccessed,
|
||||||
|
1,
|
||||||
|
'thisVal[Symbol.toPrimitive should have been accessed.'
|
||||||
|
);
|
||||||
|
assert.sameValue(
|
||||||
|
toStringAccessed,
|
||||||
|
1,
|
||||||
|
'thisVal[Symbol.toString should have been accessed.'
|
||||||
|
);
|
57
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-returns-object-err.js
vendored
Normal file
57
test/built-ins/String/prototype/trimEnd/this-value-object-valueof-returns-object-err.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-string.prototype.trimEnd
|
||||||
|
description: >
|
||||||
|
Abrupt completion when valueOf called and returns an object
|
||||||
|
info: |
|
||||||
|
Runtime Semantics: TrimString ( string, where )
|
||||||
|
1. Let str be ? RequireObjectCoercible(string).
|
||||||
|
2. Let S be ? ToString(str).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToString ( argument )
|
||||||
|
If argument is Object:
|
||||||
|
1. Let primValue be ? ToPrimitive(argument, hint String).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToPrimitive ( input [, PreferredType ])
|
||||||
|
...
|
||||||
|
b. Else if PreferredType is hint String, let hint be "string".
|
||||||
|
...
|
||||||
|
d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive)
|
||||||
|
e. If exoticToPrim is not undefined, then
|
||||||
|
i. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
iii. Throw a TypeError exception.
|
||||||
|
f. If hint is "default", set hint to "number".
|
||||||
|
g. Return ? OrdinaryToPrimitive(input, hint).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryToPrimitive( O, hint )
|
||||||
|
...
|
||||||
|
3. If hint is "string", then
|
||||||
|
a. Let methodNames be « "toString", "valueOf" ».
|
||||||
|
...
|
||||||
|
5. For each name in methodNames in List order, do
|
||||||
|
a. Let method be ? Get(O, name).
|
||||||
|
b. If IsCallable(method) is true, then
|
||||||
|
i. Let result be ? Call(method, O).
|
||||||
|
ii. If Type(result) is not Object, return result.
|
||||||
|
6. Throw a TypeError exception.
|
||||||
|
features: [string-trimming, Symbol.toPrimitive]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
|
||||||
|
var thisVal = {
|
||||||
|
[Symbol.toPrimitive]: undefined,
|
||||||
|
toString: undefined,
|
||||||
|
valueOf: function() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.prototype.trimEnd.call(thisVal);
|
||||||
|
});
|
Loading…
Reference in New Issue