1// Copyright 2014 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Flags: --harmony-strings 6 7// Tests taken from: 8// https://github.com/mathiasbynens/String.fromCodePoint 9 10assertEquals(String.fromCodePoint.length, 1); 11assertEquals(String.propertyIsEnumerable("fromCodePoint"), false); 12 13assertEquals(String.fromCodePoint(""), "\0"); 14assertEquals(String.fromCodePoint(), ""); 15assertEquals(String.fromCodePoint(-0), "\0"); 16assertEquals(String.fromCodePoint(0), "\0"); 17assertEquals(String.fromCodePoint(0x1D306), "\uD834\uDF06"); 18assertEquals( 19 String.fromCodePoint(0x1D306, 0x61, 0x1D307), 20 "\uD834\uDF06a\uD834\uDF07"); 21assertEquals(String.fromCodePoint(0x61, 0x62, 0x1D307), "ab\uD834\uDF07"); 22assertEquals(String.fromCodePoint(false), "\0"); 23assertEquals(String.fromCodePoint(null), "\0"); 24 25assertThrows(function() { String.fromCodePoint("_"); }, RangeError); 26assertThrows(function() { String.fromCodePoint("+Infinity"); }, RangeError); 27assertThrows(function() { String.fromCodePoint("-Infinity"); }, RangeError); 28assertThrows(function() { String.fromCodePoint(-1); }, RangeError); 29assertThrows(function() { String.fromCodePoint(0x10FFFF + 1); }, RangeError); 30assertThrows(function() { String.fromCodePoint(3.14); }, RangeError); 31assertThrows(function() { String.fromCodePoint(3e-2); }, RangeError); 32assertThrows(function() { String.fromCodePoint(-Infinity); }, RangeError); 33assertThrows(function() { String.fromCodePoint(+Infinity); }, RangeError); 34assertThrows(function() { String.fromCodePoint(NaN); }, RangeError); 35assertThrows(function() { String.fromCodePoint(undefined); }, RangeError); 36assertThrows(function() { String.fromCodePoint({}); }, RangeError); 37assertThrows(function() { String.fromCodePoint(/./); }, RangeError); 38assertThrows(function() { String.fromCodePoint({ 39 valueOf: function() { throw Error(); } }); 40}, Error); 41assertThrows(function() { String.fromCodePoint({ 42 valueOf: function() { throw Error(); } }); 43}, Error); 44var tmp = 0x60; 45assertEquals(String.fromCodePoint({ 46 valueOf: function() { ++tmp; return tmp; } 47}), "a"); 48assertEquals(tmp, 0x61); 49 50var counter = Math.pow(2, 15) * 3 / 2; 51var result = []; 52while (--counter >= 0) { 53 result.push(0); // one code unit per symbol 54} 55String.fromCodePoint.apply(null, result); // must not throw 56 57var counter = Math.pow(2, 15) * 3 / 2; 58var result = []; 59while (--counter >= 0) { 60 result.push(0xFFFF + 1); // two code units per symbol 61} 62String.fromCodePoint.apply(null, result); // must not throw 63