String.fromCodePoint

This commit is contained in:
Leonardo Balter 2015-07-02 12:24:53 -04:00
parent 0027a6b6bf
commit 57b7d13781
10 changed files with 290 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
Return abrupt from ToNumber(next).
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
features: [Symbol]
---*/
assert.throws(TypeError, function() {
String.fromCodePoint(Symbol());
});
assert.throws(TypeError, function() {
String.fromCodePoint(42, Symbol());
});

View File

@ -0,0 +1,46 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
Throw a RangeError if an argument is not equal to its Integer representation.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
d. If SameValue(nextCP, ToInteger(nextCP)) is false, throw a RangeError
exception.
...
---*/
assert.throws(RangeError, function() {
String.fromCodePoint(3.14);
});
assert.throws(RangeError, function() {
String.fromCodePoint(42, 3.14);
});
assert.throws(RangeError, function() {
String.fromCodePoint('3.14');
});
// ToNumber(undefined) returns NaN.
assert.throws(RangeError, function() {
String.fromCodePoint(undefined);
});
assert.throws(RangeError, function() {
String.fromCodePoint('_1');
});
assert.throws(RangeError, function() {
String.fromCodePoint('1a');
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
Return abrupt from ToNumber(next).
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
---*/
var obj = {};
Object.defineProperty(obj, 'item', {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
String.fromCodePoint({
valueOf: function() {
throw new Test262Error();
}
});
});
assert.throws(Test262Error, function() {
String.fromCodePoint(42, {
valueOf: function() {
throw new Test262Error();
}
});
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
The the arguments list is empty, an empty string is returned.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
...
5. Repeat while nextIndex < length
...
f. Append the elements of the UTF16Encoding (10.1.1) of nextCP to the end of
elements.
g. Let nextIndex be nextIndex + 1.
6. Return the String value whose elements are, in order, the elements in the
List elements. If length is 0, the empty string is returned.
---*/
assert.sameValue(String.fromCodePoint(), '');

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
String.fromCodePoint property descriptor
info: >
String.fromCodePoint ( ...codePoints )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
verifyNotEnumerable(String, 'fromCodePoint');
verifyWritable(String, 'fromCodePoint');
verifyConfigurable(String, 'fromCodePoint');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
The length property of the String.fromCodePoint constructor is 1.
includes: [propertyHelper.js]
---*/
assert.sameValue(
String.fromCodePoint.length, 1,
'The value of `String.fromCodePoint.length` is `1`'
);
verifyNotEnumerable(String.fromCodePoint, 'length');
verifyNotWritable(String.fromCodePoint, 'length');
verifyConfigurable(String.fromCodePoint, 'length');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
String.fromCodePoint.name
info: >
String.fromCodePoint ( ...codePoints )
17 ECMAScript Standard Built-in Objects
includes: [propertyHelper.js]
---*/
assert.sameValue(
String.fromCodePoint.name, 'fromCodePoint',
'The value of `String.fromCodePoint.name` is "fromCodePoint"'
);
verifyNotEnumerable(String.fromCodePoint, 'name');
verifyNotWritable(String.fromCodePoint, 'name');
verifyConfigurable(String.fromCodePoint, 'name');

View File

@ -0,0 +1,38 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
Throw a RangeError if an argument is < 0 or > 0x10FFFF.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
2. Let length be the number of elements in codePoints.
3. Let elements be a new List.
4. Let nextIndex be 0.
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
c. ReturnIfAbrupt(nextCP).
d. If SameValue(nextCP, ToInteger(nextCP)) is false, throw a RangeError
exception.
e. If nextCP < 0 or nextCP > 0x10FFFF, throw a RangeError exception.
...
---*/
assert.throws(RangeError, function() {
String.fromCodePoint(-1);
});
assert.throws(RangeError, function() {
String.fromCodePoint(1, -1);
});
assert.throws(RangeError, function() {
String.fromCodePoint(1114112);
});
assert.throws(RangeError, function() {
String.fromCodePoint(Infinity);
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
Returns the String value whose elements are, in order, the code unit for the
numbers in the arguments list.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
...
5. Repeat while nextIndex < length
...
f. Append the elements of the UTF16Encoding (10.1.1) of nextCP to the end of
elements.
g. Let nextIndex be nextIndex + 1.
6. Return the String value whose elements are, in order, the elements in the
List elements. If length is 0, the empty string is returned.
---*/
assert.sameValue(String.fromCodePoint(0), '\x00');
assert.sameValue(String.fromCodePoint(42), '*');
assert.sameValue(String.fromCodePoint(65, 90), 'AZ');
assert.sameValue(String.fromCodePoint(0x404), '\u0404');
assert.sameValue(String.fromCodePoint(0x2F804), '\uD87E\uDC04');
assert.sameValue(String.fromCodePoint(194564), '\uD87E\uDC04');
assert.sameValue(
String.fromCodePoint(0x1D306, 0x61, 0x1D307),
'\uD834\uDF06a\uD834\uDF07'
);
assert.sameValue(String.fromCodePoint(1114111), '\uDBFF\uDFFF');

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.2.2
description: >
Returns the String value with the code unit for the given coerced types.
info: >
String.fromCodePoint ( ...codePoints )
1. Let codePoints be a List containing the arguments passed to this function.
...
5. Repeat while nextIndex < length
a. Let next be codePoints[nextIndex].
b. Let nextCP be ToNumber(next).
...
6. Return the String value whose elements are, in order, the elements in the
List elements. If length is 0, the empty string is returned.
Ref: 7.1.3 ToNumber ( argument )
---*/
assert.sameValue(String.fromCodePoint(null), '\x00');
assert.sameValue(String.fromCodePoint(false), '\x00');
assert.sameValue(String.fromCodePoint(true), '\x01');
assert.sameValue(String.fromCodePoint('42'), '\x2A');
assert.sameValue(String.fromCodePoint('042'), '\x2A');
assert.sameValue(
String.fromCodePoint({ valueOf: function() { return 31; } }),
'\x1F'
);