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// Tests taken from: 6// https://github.com/mathiasbynens/String.fromCodePoint 7 8assertEquals(String.fromCodePoint.length, 1); 9assertEquals(String.propertyIsEnumerable("fromCodePoint"), false); 10 11assertEquals(String.fromCodePoint(""), "\0"); 12assertEquals(String.fromCodePoint(), ""); 13assertEquals(String.fromCodePoint(-0), "\0"); 14assertEquals(String.fromCodePoint(0), "\0"); 15assertEquals(String.fromCodePoint(0x1D306), "\uD834\uDF06"); 16assertEquals( 17 String.fromCodePoint(0x1D306, 0x61, 0x1D307), 18 "\uD834\uDF06a\uD834\uDF07"); 19assertEquals(String.fromCodePoint(0x61, 0x62, 0x1D307), "ab\uD834\uDF07"); 20assertEquals(String.fromCodePoint(false), "\0"); 21assertEquals(String.fromCodePoint(null), "\0"); 22 23assertThrows(function() { String.fromCodePoint("_"); }, RangeError); 24assertThrows(function() { String.fromCodePoint("+Infinity"); }, RangeError); 25assertThrows(function() { String.fromCodePoint("-Infinity"); }, RangeError); 26assertThrows(function() { String.fromCodePoint(-1); }, RangeError); 27assertThrows(function() { String.fromCodePoint(0x10FFFF + 1); }, RangeError); 28assertThrows(function() { String.fromCodePoint(3.14); }, RangeError); 29assertThrows(function() { String.fromCodePoint(3e-2); }, RangeError); 30assertThrows(function() { String.fromCodePoint(-Infinity); }, RangeError); 31assertThrows(function() { String.fromCodePoint(+Infinity); }, RangeError); 32assertThrows(function() { String.fromCodePoint(NaN); }, RangeError); 33assertThrows(function() { String.fromCodePoint(undefined); }, RangeError); 34assertThrows(function() { String.fromCodePoint({}); }, RangeError); 35assertThrows(function() { String.fromCodePoint(/./); }, RangeError); 36assertThrows(function() { String.fromCodePoint({ 37 valueOf: function() { throw Error(); } }); 38}, Error); 39assertThrows(function() { String.fromCodePoint({ 40 valueOf: function() { throw Error(); } }); 41}, Error); 42var tmp = 0x60; 43assertEquals(String.fromCodePoint({ 44 valueOf: function() { ++tmp; return tmp; } 45}), "a"); 46assertEquals(tmp, 0x61); 47 48var counter = Math.pow(2, 15) * 3 / 2; 49var result = []; 50while (--counter >= 0) { 51 result.push(0); // one code unit per symbol 52} 53String.fromCodePoint.apply(null, result); // must not throw 54 55var counter = Math.pow(2, 15) * 3 / 2; 56var result = []; 57while (--counter >= 0) { 58 result.push(0xFFFF + 1); // two code units per symbol 59} 60String.fromCodePoint.apply(null, result); // must not throw 61