mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 13:34:38 +02:00
Merge pull request #359 from bocoup/String.raw
Add tests for String.raw
This commit is contained in:
commit
cdc6be9631
21
test/built-ins/String/raw/length.js
Normal file
21
test/built-ins/String/raw/length.js
Normal 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.4
|
||||||
|
description: >
|
||||||
|
String.raw.length value and property descriptor
|
||||||
|
info: >
|
||||||
|
String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
The length property of the raw function is 1.
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
String.raw.length, 1,
|
||||||
|
'The value of `String.raw.length` is `1`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(String.raw, 'length');
|
||||||
|
verifyNotWritable(String.raw, 'length');
|
||||||
|
verifyConfigurable(String.raw, 'length');
|
22
test/built-ins/String/raw/name.js
Normal file
22
test/built-ins/String/raw/name.js
Normal 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.4
|
||||||
|
description: >
|
||||||
|
String.raw.name value and property descriptor
|
||||||
|
info: >
|
||||||
|
String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
String.raw.name, 'raw',
|
||||||
|
'The value of `String.raw.name` is `"raw"`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyNotEnumerable(String.raw, 'name');
|
||||||
|
verifyNotWritable(String.raw, 'name');
|
||||||
|
verifyConfigurable(String.raw, 'name');
|
30
test/built-ins/String/raw/nextkey-is-symbol-throws.js
Normal file
30
test/built-ins/String/raw/nextkey-is-symbol-throws.js
Normal 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.4
|
||||||
|
description: >
|
||||||
|
Throws a TypeError if nextKey is Symbol
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
...
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
raw: {
|
||||||
|
length: 1,
|
||||||
|
'0': Symbol('')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw(obj);
|
||||||
|
});
|
17
test/built-ins/String/raw/raw.js
Normal file
17
test/built-ins/String/raw/raw.js
Normal 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.4
|
||||||
|
description: >
|
||||||
|
String.raw property descriptor
|
||||||
|
info: >
|
||||||
|
String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
verifyNotEnumerable(String, 'raw');
|
||||||
|
verifyWritable(String, 'raw');
|
||||||
|
verifyConfigurable(String, 'raw');
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw an empty Array
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: []
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length is -Infinity
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: -Infinity
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length isn't defined.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length isn't defined.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length is NaN
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: NaN
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length is false
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -0,0 +1,23 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length is null
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.sameValue(result, '');
|
@ -0,0 +1,43 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length is <= 0
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == 0');
|
||||||
|
|
||||||
|
result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: -1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == -1');
|
||||||
|
|
||||||
|
result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: -0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == -0');
|
||||||
|
|
||||||
|
result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: 0.32
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == 0.32');
|
@ -0,0 +1,36 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns empty string if template.raw.length is <= 0
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
9. If literalSegments ≤ 0, return the empty string.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: '0'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == "0"');
|
||||||
|
|
||||||
|
result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: '-1'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == "-1"');
|
||||||
|
|
||||||
|
result = String.raw({
|
||||||
|
raw: {
|
||||||
|
length: ''
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.sameValue(result, '', 'result is an empty string when length == ""');
|
@ -0,0 +1,26 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns the string value.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(String.raw`123\u0065`, '123\\u0065');
|
39
test/built-ins/String/raw/return-the-string-value.js
Normal file
39
test/built-ins/String/raw/return-the-string-value.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns the string value without substitutions arguments and limited to the
|
||||||
|
given length.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
raw: {
|
||||||
|
length: 5,
|
||||||
|
0: '\u0065',
|
||||||
|
1: '',
|
||||||
|
2: null,
|
||||||
|
3: undefined,
|
||||||
|
4: 123,
|
||||||
|
5: 'overpass the length'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(String.raw(obj), 'enullundefined123');
|
@ -0,0 +1,33 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt from nextKey.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
raw: {
|
||||||
|
length: 1,
|
||||||
|
'0': {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(obj);
|
||||||
|
});
|
46
test/built-ins/String/raw/returns-abrupt-from-next-key.js
Normal file
46
test/built-ins/String/raw/returns-abrupt-from-next-key.js
Normal 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt from nextKey.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
raw: {
|
||||||
|
length: 2
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(obj.raw, '0', {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
},
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
delete obj.raw['0'];
|
||||||
|
obj.raw['0'] = 'a';
|
||||||
|
Object.defineProperty(obj.raw, '1', {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(obj);
|
||||||
|
});
|
@ -0,0 +1,43 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns the abrupt from ToString(substitutions[nextIndex]) using a Symbol
|
||||||
|
value.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex].
|
||||||
|
g. Else, let next be the empty String.
|
||||||
|
h. Let nextSub be ToString(next).
|
||||||
|
i. ReturnIfAbrupt(nextSub).
|
||||||
|
j. Append in order the code unit elements of nextSub to the end of stringElements.
|
||||||
|
k. Let nextIndex be nextIndex + 1.
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var template = {
|
||||||
|
raw: ['a', 'b', 'c']
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw(template, '', Symbol(''));
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw(template, Symbol(''), '');
|
||||||
|
});
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Returns the abrupt from ToString(substitutions[nextIndex]).
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex].
|
||||||
|
g. Else, let next be the empty String.
|
||||||
|
h. Let nextSub be ToString(next).
|
||||||
|
i. ReturnIfAbrupt(nextSub).
|
||||||
|
j. Append in order the code unit elements of nextSub to the end of stringElements.
|
||||||
|
k. Let nextIndex be nextIndex + 1.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var template = {
|
||||||
|
raw: ['a', 'b', 'c']
|
||||||
|
};
|
||||||
|
var obj = {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(template, '', obj);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(template, obj, '');
|
||||||
|
});
|
@ -0,0 +1,36 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns the string value appending the substitutions on the same index order.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex].
|
||||||
|
g. Else, let next be the empty String.
|
||||||
|
h. Let nextSub be ToString(next).
|
||||||
|
i. ReturnIfAbrupt(nextSub).
|
||||||
|
j. Append in order the code unit elements of nextSub to the end of stringElements.
|
||||||
|
k. Let nextIndex be nextIndex + 1.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var template = {
|
||||||
|
raw: ['a', 'b', 'd', 'f']
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(String.raw(template, '', 'c', 'e'), 'abcdef');
|
||||||
|
assert.sameValue(String.raw(template, 1), 'a1bdf');
|
@ -0,0 +1,35 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Limit appended substitutions arguments to template.raw.length - 1.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
...
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var template = {
|
||||||
|
raw: ['a', 'c', 'e']
|
||||||
|
};
|
||||||
|
var obj = {
|
||||||
|
toString: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.sameValue(String.raw(template, 'b', 'd', obj), 'abcde');
|
@ -0,0 +1,29 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt completion from ToLength(template.raw.length).
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
1. Let substitutions be a List consisting of all of the arguments passed to
|
||||||
|
this function, starting with the second argument. If fewer than two arguments
|
||||||
|
were passed, the List is empty.
|
||||||
|
2. Let numberOfSubstitutions be the number of elements in substitutions.
|
||||||
|
3. Let cooked be ToObject(template).
|
||||||
|
4. ReturnIfAbrupt(cooked).
|
||||||
|
5. Let raw be ToObject(Get(cooked, "raw")).
|
||||||
|
6. ReturnIfAbrupt(raw).
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw({
|
||||||
|
raw: {
|
||||||
|
length: Symbol(1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
33
test/built-ins/String/raw/template-length-throws.js
Normal file
33
test/built-ins/String/raw/template-length-throws.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt completion from ToObject(template.raw.length).
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
1. Let substitutions be a List consisting of all of the arguments passed to
|
||||||
|
this function, starting with the second argument. If fewer than two arguments
|
||||||
|
were passed, the List is empty.
|
||||||
|
2. Let numberOfSubstitutions be the number of elements in substitutions.
|
||||||
|
3. Let cooked be ToObject(template).
|
||||||
|
4. ReturnIfAbrupt(cooked).
|
||||||
|
5. Let raw be ToObject(Get(cooked, "raw")).
|
||||||
|
6. ReturnIfAbrupt(raw).
|
||||||
|
7. Let literalSegments be ToLength(Get(raw, "length")).
|
||||||
|
8. ReturnIfAbrupt(literalSegments).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
raw: {}
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj.raw, 'length', {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(obj);
|
||||||
|
});
|
24
test/built-ins/String/raw/template-not-object-throws.js
Normal file
24
test/built-ins/String/raw/template-not-object-throws.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt completion from ToObject(template).
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
1. Let substitutions be a List consisting of all of the arguments passed to
|
||||||
|
this function, starting with the second argument. If fewer than two arguments
|
||||||
|
were passed, the List is empty.
|
||||||
|
2. Let numberOfSubstitutions be the number of elements in substitutions.
|
||||||
|
3. Let cooked be ToObject(template).
|
||||||
|
4. ReturnIfAbrupt(cooked).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw(undefined);
|
||||||
|
});
|
30
test/built-ins/String/raw/template-raw-not-object-throws.js
Normal file
30
test/built-ins/String/raw/template-raw-not-object-throws.js
Normal 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt completion from ToObject(template.raw).
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
1. Let substitutions be a List consisting of all of the arguments passed to
|
||||||
|
this function, starting with the second argument. If fewer than two arguments
|
||||||
|
were passed, the List is empty.
|
||||||
|
2. Let numberOfSubstitutions be the number of elements in substitutions.
|
||||||
|
3. Let cooked be ToObject(template).
|
||||||
|
4. ReturnIfAbrupt(cooked).
|
||||||
|
5. Let raw be ToObject(Get(cooked, "raw")).
|
||||||
|
6. ReturnIfAbrupt(raw).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw({
|
||||||
|
raw: undefined
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
String.raw({
|
||||||
|
raw: null
|
||||||
|
});
|
||||||
|
});
|
29
test/built-ins/String/raw/template-raw-throws.js
Normal file
29
test/built-ins/String/raw/template-raw-throws.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// 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.4
|
||||||
|
description: >
|
||||||
|
Returns abrupt completion from ToObject(template.raw).
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
1. Let substitutions be a List consisting of all of the arguments passed to
|
||||||
|
this function, starting with the second argument. If fewer than two arguments
|
||||||
|
were passed, the List is empty.
|
||||||
|
2. Let numberOfSubstitutions be the number of elements in substitutions.
|
||||||
|
3. Let cooked be ToObject(template).
|
||||||
|
4. ReturnIfAbrupt(cooked).
|
||||||
|
5. Let raw be ToObject(Get(cooked, "raw")).
|
||||||
|
6. ReturnIfAbrupt(raw).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var obj = {};
|
||||||
|
Object.defineProperty(obj, 'raw', {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
String.raw(obj);
|
||||||
|
});
|
@ -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.4
|
||||||
|
description: >
|
||||||
|
Returns the string value appending from the same index order using String.raw
|
||||||
|
as a tag function.
|
||||||
|
info: >
|
||||||
|
21.1.2.4 String.raw ( template , ...substitutions )
|
||||||
|
|
||||||
|
...
|
||||||
|
10. Let stringElements be a new List.
|
||||||
|
11. Let nextIndex be 0.
|
||||||
|
12. Repeat
|
||||||
|
a. Let nextKey be ToString(nextIndex).
|
||||||
|
b. Let nextSeg be ToString(Get(raw, nextKey)).
|
||||||
|
c. ReturnIfAbrupt(nextSeg).
|
||||||
|
d. Append in order the code unit elements of nextSeg to the end of
|
||||||
|
stringElements.
|
||||||
|
e. If nextIndex + 1 = literalSegments, then
|
||||||
|
i. Return the String value whose code units are, in order, the elements in
|
||||||
|
the List stringElements. If stringElements has no elements, the empty
|
||||||
|
string is returned.
|
||||||
|
f. If nextIndex < numberOfSubstitutions, let next be substitutions[nextIndex].
|
||||||
|
g. Else, let next be the empty String.
|
||||||
|
h. Let nextSub be ToString(next).
|
||||||
|
i. ReturnIfAbrupt(nextSub).
|
||||||
|
j. Append in order the code unit elements of nextSub to the end of stringElements.
|
||||||
|
k. Let nextIndex be nextIndex + 1.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(String.raw`1${2}3${4}5`, '12345');
|
Loading…
x
Reference in New Issue
Block a user