• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// check properties
16
17function length_configurable()
18{
19  function is_es51() {
20    return (typeof g === "function");
21    { function g() {} }
22  }
23  return is_es51() ? false : true;
24}
25
26assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').configurable === length_configurable());
27
28assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').enumerable === false);
29
30assert(Object.getOwnPropertyDescriptor(String.prototype.charCodeAt, 'length').writable === false);
31
32assert(String.prototype.charCodeAt.length === 1);
33
34// check empty string
35assert(isNaN(String.prototype.charCodeAt.call(new String())));
36
37// check Object with NaN pos
38assert(String.prototype.charCodeAt.call({}) === 91);
39
40// simple checks
41assert("hello world!".charCodeAt(0) === 104);
42
43assert("hello world!".charCodeAt(1) === 101);
44
45assert("HELLO WORLD".charCodeAt(10) === 68);
46
47// check +-Inf
48assert(isNaN("hello world!".charCodeAt(-Infinity)));
49
50assert(isNaN("hello world!".charCodeAt(Infinity)));
51
52assert("hello world!".charCodeAt(11) === 33);
53
54assert(isNaN("hello world!".charCodeAt(12)));
55
56// check unicode
57assert("hello\u000B\u000C\u0020\u00A0world!".charCodeAt(8) === 160);
58
59assert("hello\uD834\uDF06world!".charCodeAt(6) === 57094);
60
61assert("hell\u006F\u006F w\u006F\u006Frld!".charCodeAt(8) === 111);
62
63assert(isNaN("\u00A9\u006F".charCodeAt(2)));
64
65// check negative
66assert(isNaN("hello world!".charCodeAt(-1)));
67
68assert(isNaN("hello world!".charCodeAt(-9999999)));
69
70assert("hello world!".charCodeAt(-0) === 104);
71
72// check undefined
73assert("hello world!".charCodeAt(undefined) === 104);
74
75// check booleans
76assert("hello world!".charCodeAt(true) === 101);
77
78assert("hello world!".charCodeAt(false) === 104);
79
80// check index above uint32_t
81assert(isNaN("hello world!".charCodeAt(4294967299)));
82
83// check coercible - undefined
84try {
85  assert(isNaN(String.prototype.charCodeAt.call(undefined)));
86  assert(false);
87} catch (e) {
88  assert(e instanceof TypeError);
89}
90
91// check coercible - null
92try {
93  assert(isNaN(String.prototype.charCodeAt.call(null, 0)));
94  assert(false);
95} catch (e) {
96  assert(e instanceof TypeError);
97}
98
99// check coercible - Boolean
100assert(String.prototype.charCodeAt.call(true, 1) === 114);
101assert(String.prototype.charCodeAt.call(true) === 116);
102
103// check coercible - Object
104var test_object = {firstName:"John", lastName:"Doe"};
105assert(String.prototype.charCodeAt.call(test_object, 1) === 111);
106
107// check coercible - Number
108assert(String.prototype.charCodeAt.call(123, 2) === 51);
109