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