OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --stack-size=100 --harmony --harmony-reflect | 5 // Flags: --stack-size=100 --harmony --harmony-reflect --harmony-arrays |
| 6 // Flags: --harmony-regexps |
6 | 7 |
7 function test(f, expected, type) { | 8 function test(f, expected, type) { |
8 try { | 9 try { |
9 f(); | 10 f(); |
10 } catch (e) { | 11 } catch (e) { |
11 assertInstanceof(e, type); | 12 assertInstanceof(e, type); |
12 assertEquals(expected, e.message); | 13 assertEquals(expected, e.message); |
13 return; | 14 return; |
14 } | 15 } |
15 assertUnreachable("Exception expected"); | 16 assertUnreachable("Exception expected"); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // kCalledOnNullOrUndefined | 60 // kCalledOnNullOrUndefined |
60 test(function() { | 61 test(function() { |
61 Array.prototype.shift.call(null); | 62 Array.prototype.shift.call(null); |
62 }, "Array.prototype.shift called on null or undefined", TypeError); | 63 }, "Array.prototype.shift called on null or undefined", TypeError); |
63 | 64 |
64 // kCannotConvertToPrimitive | 65 // kCannotConvertToPrimitive |
65 test(function() { | 66 test(function() { |
66 [].join(Object(Symbol(1))); | 67 [].join(Object(Symbol(1))); |
67 }, "Cannot convert object to primitive value", TypeError); | 68 }, "Cannot convert object to primitive value", TypeError); |
68 | 69 |
| 70 // kConstructorNotFunction |
| 71 test(function() { |
| 72 Uint16Array(1); |
| 73 }, "Constructor Uint16Array requires 'new'", TypeError); |
| 74 |
69 // kDateType | 75 // kDateType |
70 test(function() { | 76 test(function() { |
71 Date.prototype.setYear.call({}, 1); | 77 Date.prototype.setYear.call({}, 1); |
72 }, "this is not a Date object.", TypeError); | 78 }, "this is not a Date object.", TypeError); |
73 | 79 |
74 // kDefineDisallowed | 80 // kDefineDisallowed |
75 test(function() { | 81 test(function() { |
76 "use strict"; | 82 "use strict"; |
77 var o = {}; | 83 var o = {}; |
78 Object.preventExtensions(o); | 84 Object.preventExtensions(o); |
79 Object.defineProperty(o, "x", { value: 1 }); | 85 Object.defineProperty(o, "x", { value: 1 }); |
80 }, "Cannot define property:x, object is not extensible.", TypeError); | 86 }, "Cannot define property:x, object is not extensible.", TypeError); |
81 | 87 |
82 // kFirstArgumentNotRegExp | 88 // kFirstArgumentNotRegExp |
83 test(function() { | 89 test(function() { |
84 "a".startsWith(/a/); | 90 "a".startsWith(/a/); |
85 }, "First argument to String.prototype.startsWith " + | 91 }, "First argument to String.prototype.startsWith " + |
86 "must not be a regular expression", TypeError); | 92 "must not be a regular expression", TypeError); |
87 | 93 |
| 94 // kFlagsGetterNonObject |
| 95 test(function() { |
| 96 Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get.call(1); |
| 97 }, "RegExp.prototype.flags getter called on non-object 1", TypeError); |
| 98 |
88 // kFunctionBind | 99 // kFunctionBind |
89 test(function() { | 100 test(function() { |
90 Function.prototype.bind.call(1); | 101 Function.prototype.bind.call(1); |
91 }, "Bind must be called on a function", TypeError); | 102 }, "Bind must be called on a function", TypeError); |
92 | 103 |
93 // kGeneratorRunning | 104 // kGeneratorRunning |
94 test(function() { | 105 test(function() { |
95 var iter; | 106 var iter; |
96 function* generator() { yield iter.next(); } | 107 function* generator() { yield iter.next(); } |
97 var iter = generator(); | 108 var iter = generator(); |
(...skipping 17 matching lines...) Expand all Loading... |
115 var o = new f(); | 126 var o = new f(); |
116 f.prototype = 1; | 127 f.prototype = 1; |
117 o instanceof f; | 128 o instanceof f; |
118 }, "Function has non-object prototype '1' in instanceof check", TypeError); | 129 }, "Function has non-object prototype '1' in instanceof check", TypeError); |
119 | 130 |
120 // kInvalidInOperatorUse | 131 // kInvalidInOperatorUse |
121 test(function() { | 132 test(function() { |
122 1 in 1; | 133 1 in 1; |
123 }, "Cannot use 'in' operator to search for '1' in 1", TypeError); | 134 }, "Cannot use 'in' operator to search for '1' in 1", TypeError); |
124 | 135 |
| 136 // kIteratorResultNotAnObject |
| 137 test(function() { |
| 138 var obj = {}; |
| 139 obj[Symbol.iterator] = function() { return { next: function() { return 1 }}}; |
| 140 Array.from(obj); |
| 141 }, "Iterator result 1 is not an object", TypeError); |
| 142 |
| 143 // kIteratorValueNotAnObject |
| 144 test(function() { |
| 145 new Map([1]); |
| 146 }, "Iterator value 1 is not an entry object", TypeError); |
| 147 |
125 // kNotConstructor | 148 // kNotConstructor |
126 test(function() { | 149 test(function() { |
127 new Symbol(); | 150 new Symbol(); |
128 }, "Symbol is not a constructor", TypeError); | 151 }, "Symbol is not a constructor", TypeError); |
129 | 152 |
130 // kNotGeneric | 153 // kNotGeneric |
131 test(function() { | 154 test(function() { |
132 String.prototype.toString.call(1); | 155 String.prototype.toString.call(1); |
133 }, "String.prototype.toString is not generic", TypeError); | 156 }, "String.prototype.toString is not generic", TypeError); |
134 | 157 |
(...skipping 14 matching lines...) Expand all Loading... |
149 }, "Number.prototype.toString is not generic", TypeError); | 172 }, "Number.prototype.toString is not generic", TypeError); |
150 | 173 |
151 test(function() { | 174 test(function() { |
152 Number.prototype.valueOf.call({}); | 175 Number.prototype.valueOf.call({}); |
153 }, "Number.prototype.valueOf is not generic", TypeError); | 176 }, "Number.prototype.valueOf is not generic", TypeError); |
154 | 177 |
155 test(function() { | 178 test(function() { |
156 Function.prototype.toString.call(1); | 179 Function.prototype.toString.call(1); |
157 }, "Function.prototype.toString is not generic", TypeError); | 180 }, "Function.prototype.toString is not generic", TypeError); |
158 | 181 |
| 182 // kNotTypedArray |
| 183 test(function() { |
| 184 Uint16Array.prototype.forEach.call(1); |
| 185 }, "this is not a typed array.", TypeError); |
| 186 |
159 // kObjectGetterExpectingFunction | 187 // kObjectGetterExpectingFunction |
160 test(function() { | 188 test(function() { |
161 ({}).__defineGetter__("x", 0); | 189 ({}).__defineGetter__("x", 0); |
162 }, "Object.prototype.__defineGetter__: Expecting function", TypeError); | 190 }, "Object.prototype.__defineGetter__: Expecting function", TypeError); |
163 | 191 |
164 // kObjectGetterCallable | 192 // kObjectGetterCallable |
165 test(function() { | 193 test(function() { |
166 Object.defineProperty({}, "x", { get: 1 }); | 194 Object.defineProperty({}, "x", { get: 1 }); |
167 }, "Getter must be a function: 1", TypeError); | 195 }, "Getter must be a function: 1", TypeError); |
168 | 196 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 Number(1).toString(100); | 333 Number(1).toString(100); |
306 }, "toString() radix argument must be between 2 and 36", RangeError); | 334 }, "toString() radix argument must be between 2 and 36", RangeError); |
307 | 335 |
308 | 336 |
309 // === URIError === | 337 // === URIError === |
310 | 338 |
311 // kURIMalformed | 339 // kURIMalformed |
312 test(function() { | 340 test(function() { |
313 decodeURI("%%"); | 341 decodeURI("%%"); |
314 }, "URI malformed", URIError); | 342 }, "URI malformed", URIError); |
OLD | NEW |