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.prototype.codePointAt 7 8assertEquals(String.prototype.codePointAt.length, 1); 9assertEquals(String.prototype.propertyIsEnumerable("codePointAt"), false); 10 11// String that starts with a BMP symbol 12assertEquals("abc\uD834\uDF06def".codePointAt(""), 0x61); 13assertEquals("abc\uD834\uDF06def".codePointAt("_"), 0x61); 14assertEquals("abc\uD834\uDF06def".codePointAt(), 0x61); 15assertEquals("abc\uD834\uDF06def".codePointAt(-Infinity), undefined); 16assertEquals("abc\uD834\uDF06def".codePointAt(-1), undefined); 17assertEquals("abc\uD834\uDF06def".codePointAt(-0), 0x61); 18assertEquals("abc\uD834\uDF06def".codePointAt(0), 0x61); 19assertEquals("abc\uD834\uDF06def".codePointAt(3), 0x1D306); 20assertEquals("abc\uD834\uDF06def".codePointAt(4), 0xDF06); 21assertEquals("abc\uD834\uDF06def".codePointAt(5), 0x64); 22assertEquals("abc\uD834\uDF06def".codePointAt(42), undefined); 23assertEquals("abc\uD834\uDF06def".codePointAt(Infinity), undefined); 24assertEquals("abc\uD834\uDF06def".codePointAt(Infinity), undefined); 25assertEquals("abc\uD834\uDF06def".codePointAt(NaN), 0x61); 26assertEquals("abc\uD834\uDF06def".codePointAt(false), 0x61); 27assertEquals("abc\uD834\uDF06def".codePointAt(null), 0x61); 28assertEquals("abc\uD834\uDF06def".codePointAt(undefined), 0x61); 29 30// String that starts with an astral symbol 31assertEquals("\uD834\uDF06def".codePointAt(""), 0x1D306); 32assertEquals("\uD834\uDF06def".codePointAt("1"), 0xDF06); 33assertEquals("\uD834\uDF06def".codePointAt("_"), 0x1D306); 34assertEquals("\uD834\uDF06def".codePointAt(), 0x1D306); 35assertEquals("\uD834\uDF06def".codePointAt(-1), undefined); 36assertEquals("\uD834\uDF06def".codePointAt(-0), 0x1D306); 37assertEquals("\uD834\uDF06def".codePointAt(0), 0x1D306); 38assertEquals("\uD834\uDF06def".codePointAt(1), 0xDF06); 39assertEquals("\uD834\uDF06def".codePointAt(42), undefined); 40assertEquals("\uD834\uDF06def".codePointAt(false), 0x1D306); 41assertEquals("\uD834\uDF06def".codePointAt(null), 0x1D306); 42assertEquals("\uD834\uDF06def".codePointAt(undefined), 0x1D306); 43 44// Lone high surrogates 45assertEquals("\uD834abc".codePointAt(""), 0xD834); 46assertEquals("\uD834abc".codePointAt("_"), 0xD834); 47assertEquals("\uD834abc".codePointAt(), 0xD834); 48assertEquals("\uD834abc".codePointAt(-1), undefined); 49assertEquals("\uD834abc".codePointAt(-0), 0xD834); 50assertEquals("\uD834abc".codePointAt(0), 0xD834); 51assertEquals("\uD834abc".codePointAt(false), 0xD834); 52assertEquals("\uD834abc".codePointAt(NaN), 0xD834); 53assertEquals("\uD834abc".codePointAt(null), 0xD834); 54assertEquals("\uD834abc".codePointAt(undefined), 0xD834); 55 56// Lone low surrogates 57assertEquals("\uDF06abc".codePointAt(""), 0xDF06); 58assertEquals("\uDF06abc".codePointAt("_"), 0xDF06); 59assertEquals("\uDF06abc".codePointAt(), 0xDF06); 60assertEquals("\uDF06abc".codePointAt(-1), undefined); 61assertEquals("\uDF06abc".codePointAt(-0), 0xDF06); 62assertEquals("\uDF06abc".codePointAt(0), 0xDF06); 63assertEquals("\uDF06abc".codePointAt(false), 0xDF06); 64assertEquals("\uDF06abc".codePointAt(NaN), 0xDF06); 65assertEquals("\uDF06abc".codePointAt(null), 0xDF06); 66assertEquals("\uDF06abc".codePointAt(undefined), 0xDF06); 67 68assertThrows(function() { 69 String.prototype.codePointAt.call(undefined); 70}, TypeError); 71assertThrows(function() { 72 String.prototype.codePointAt.call(undefined, 4); 73}, TypeError); 74assertThrows(function() { 75 String.prototype.codePointAt.call(null); 76}, TypeError); 77assertThrows(function() { 78 String.prototype.codePointAt.call(null, 4); 79}, TypeError); 80assertEquals(String.prototype.codePointAt.call(42, 0), 0x34); 81assertEquals(String.prototype.codePointAt.call(42, 1), 0x32); 82assertEquals(String.prototype.codePointAt.call({ 83 toString: function() { return "abc"; } 84}, 2), 0x63); 85var tmp = 0; 86assertEquals(String.prototype.codePointAt.call({ 87 toString: function() { ++tmp; return String(tmp); } 88}, 0), 0x31); 89assertEquals(tmp, 1); 90