jerryscript/tests/jerry/es.next/string-raw.js
Dániel Bátyai fde0d556ac
Re-target for ES.Next (#3901)
A list of changes:
- 'es2015-subset' profile is deprecated, and an 'es.next' profile is added.
- The default profile is changed to 'es.next'
- Renamed the JERRY_ES2015 guard to JERRY_ESNEXT
- Renamed JERRY_ES2015_BUILTIN_* guards to JERRY_BUILTIN_*
- Moved es2015 specific tests to a new 'es.next' subdirectory
- Updated docs, targets, and test runners to reflect these changes

Resolves #3737.

JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai@inf.u-szeged.hu
2020-06-12 17:55:00 +02:00

72 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function assertThrows(str, error) {
try {
eval(str);
assert(false);
} catch (e) {
if (typeof error === "function") {
assert(e instanceof error);
} else {
assert(e === error)
}
}
}
// https://www.ecma-international.org/ecma-262/6.0/#sec-string.raw 21.1.2.4
// Note: the string error messages represents the nth step of the routine
var abruptTests = [
["undefined", TypeError], // 3.
["{ get raw() { throw '5'; } }", '5'],
["{ raw : undefined }", TypeError], // 5.toObject
["{ raw : { get length() { throw '7.1'; } } }", '7.1'],
["{ raw : { length : { toString() { throw '7.2'; } } } }", '7.2'],
["{ raw : { length: 2, get '0'() { throw '12.b.1'} } }", '12.b.1'],
["{ raw : { length: 2, '0' : { toString() { throw '12.b.2';} } } }", '12.b.2'],
["{ raw : { length: 2, '0' : 1 } }, { toString() { throw '12.h';} }", '12.h'],
];
abruptTests.forEach(e => {
assertThrows("String.raw(" + e[0] + ")", e[1]);
});
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw
assert(String.raw`Hi\n${2+3}!` === 'Hi\\n5!');
assert(String.raw`Hi\u000A!` === 'Hi\\u000A!');
let name = 'Bob';
assert(String.raw`Hi\n${name}!` === "Hi\\nBob!");
let str = String.raw({
raw: ['foo', 'bar', 'baz']
}, 2 + 3, 'Java' + 'Script');
assert(str === "foo5barJavaScriptbaz");
assert(String.raw({ raw: 'test' }, 0, 1, 2) === "t0e1s2t");
var get = [];
var raw = new Proxy({length: 2, 0: '', 1: ''}, { get: function(o, k) { get.push(k); return o[k]; }});
var p = new Proxy({raw: raw}, { get: function(o, k) { get.push(k); return o[k]; }});
String.raw(p);
assert(get + '' === "raw,length,0,1");
assert(String.raw`\\` == "\\\\")
assert(String.raw`\`` == "\\`")
assert(String.raw`\
\
` == "\\\n\\\n")
assert(String.raw`\` == "\\\u2029")