aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorValerie R Young <spectranaut@riseup.net>2017-10-06 16:49:21 -0400
committerRick Waldron <waldron.rick@gmail.com>2018-01-25 14:10:41 -0500
commit56d57956a02d634d0cdbb808b2958068551676f0 (patch)
treeae1c5c067d4105042d272016f457c50de3832456 /test
parent2b7df61dd64bac257c897ae420db34df527590f1 (diff)
Add this value object testing to trimEnd
Diffstat (limited to 'test')
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js57
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js34
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-err.js36
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js74
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-returns-object-err.js38
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js51
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-err.js53
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js93
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-tostring-returns-object-err.js56
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js52
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-err.js54
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js91
-rw-r--r--test/built-ins/String/prototype/trimEnd/this-value-object-valueof-returns-object-err.js57
13 files changed, 746 insertions, 0 deletions
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js
new file mode 100644
index 000000000..4aebe8458
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js
@@ -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); },
+);
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js
new file mode 100644
index 000000000..7ef1a2c1f
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-call-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-err.js
new file mode 100644
index 000000000..f0bb5bf48
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js
new file mode 100644
index 000000000..df52f8a24
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-meth-priority.js
@@ -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.'
+);
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-returns-object-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-returns-object-err.js
new file mode 100644
index 000000000..b67fe117a
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-toprimitive-returns-object-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js
new file mode 100644
index 000000000..f7ed44d10
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-call-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-err.js
new file mode 100644
index 000000000..40c2b9bcc
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js
new file mode 100644
index 000000000..06d82538f
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-meth-priority.js
@@ -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.'
+);
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-returns-object-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-returns-object-err.js
new file mode 100644
index 000000000..e47539fad
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-tostring-returns-object-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js
new file mode 100644
index 000000000..ccd451674
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-call-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-err.js
new file mode 100644
index 000000000..386398aeb
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-err.js
@@ -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);
+});
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js
new file mode 100644
index 000000000..778846c07
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-meth-priority.js
@@ -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.'
+);
diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-returns-object-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-returns-object-err.js
new file mode 100644
index 000000000..c16666607
--- /dev/null
+++ b/test/built-ins/String/prototype/trimEnd/this-value-object-valueof-returns-object-err.js
@@ -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);
+});