| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 "octal\\032directive";\ | 162 "octal\\032directive";\ |
| 163 "use strict";\ | 163 "use strict";\ |
| 164 }', SyntaxError); | 164 }', SyntaxError); |
| 165 | 165 |
| 166 // Duplicate data properties. | 166 // Duplicate data properties. |
| 167 CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError); | 167 CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError); |
| 168 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError); | 168 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError); |
| 169 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError); | 169 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError); |
| 170 CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError); | 170 CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError); |
| 171 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError); | 171 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError); |
| 172 CheckStrictMode("var x = { 123: 1, 123.00000000000000000000000000000000000000000
000000000000000000000000001 : 2 }", SyntaxError); | 172 CheckStrictMode("var x = { \ |
| 173 123: 1, \ |
| 174 123.00000000000000000000000000000000000000000000000000000000000000000001: 2 \ |
| 175 }", SyntaxError); |
| 173 | 176 |
| 174 // Non-conflicting data properties. | 177 // Non-conflicting data properties. |
| 175 (function StrictModeNonDuplicate() { | 178 (function StrictModeNonDuplicate() { |
| 176 "use strict"; | 179 "use strict"; |
| 177 var x = { 123 : 1, "0123" : 2 }; | 180 var x = { 123 : 1, "0123" : 2 }; |
| 178 var x = { 123: 1, '123.0000000000000000000000000000000000000000000000000000000
0000000000001' : 2 } | 181 var x = { |
| 182 123: 1, |
| 183 '123.00000000000000000000000000000000000000000000000000000000000000000001': |
| 184 2 |
| 185 }; |
| 179 })(); | 186 })(); |
| 180 | 187 |
| 181 // Two getters (non-strict) | 188 // Two getters (non-strict) |
| 182 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError); | 189 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError); |
| 183 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError); | 190 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError); |
| 184 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError); | 191 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError); |
| 185 | 192 |
| 186 // Two setters (non-strict) | 193 // Two setters (non-strict) |
| 187 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError); | 194 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError); |
| 188 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError); | 195 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 207 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError); | 214 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError); |
| 208 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError); | 215 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError); |
| 209 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError); | 216 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError); |
| 210 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); | 217 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); |
| 211 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); | 218 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); |
| 212 | 219 |
| 213 // Assignment to eval or arguments | 220 // Assignment to eval or arguments |
| 214 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); | 221 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); |
| 215 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); | 222 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); |
| 216 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); | 223 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); |
| 217 CheckStrictMode("function strict() { print(arguments = undefined); }", SyntaxErr
or); | 224 CheckStrictMode("function strict() { print(arguments = undefined); }", |
| 225 SyntaxError); |
| 218 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); | 226 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); |
| 219 CheckStrictMode("function strict() { var x = arguments = undefined; }", SyntaxEr
ror); | 227 CheckStrictMode("function strict() { var x = arguments = undefined; }", |
| 228 SyntaxError); |
| 220 | 229 |
| 221 // Compound assignment to eval or arguments | 230 // Compound assignment to eval or arguments |
| 222 CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError); | 231 CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError); |
| 223 CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError); | 232 CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError); |
| 224 CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError); | 233 CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError); |
| 225 CheckStrictMode("function strict() { print(arguments %= undefined); }", SyntaxEr
ror); | 234 CheckStrictMode("function strict() { print(arguments %= undefined); }", |
| 226 CheckStrictMode("function strict() { var x = eval += undefined; }", SyntaxError)
; | 235 SyntaxError); |
| 227 CheckStrictMode("function strict() { var x = arguments -= undefined; }", SyntaxE
rror); | 236 CheckStrictMode("function strict() { var x = eval += undefined; }", |
| 237 SyntaxError); |
| 238 CheckStrictMode("function strict() { var x = arguments -= undefined; }", |
| 239 SyntaxError); |
| 228 CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError); | 240 CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError); |
| 229 CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError); | 241 CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError); |
| 230 CheckStrictMode("function strict() { print(eval >>>= undefined); }", SyntaxError
); | 242 CheckStrictMode("function strict() { print(eval >>>= undefined); }", |
| 231 CheckStrictMode("function strict() { print(arguments &= undefined); }", SyntaxEr
ror); | 243 SyntaxError); |
| 232 CheckStrictMode("function strict() { var x = eval ^= undefined; }", SyntaxError)
; | 244 CheckStrictMode("function strict() { print(arguments &= undefined); }", |
| 233 CheckStrictMode("function strict() { var x = arguments |= undefined; }", SyntaxE
rror); | 245 SyntaxError); |
| 246 CheckStrictMode("function strict() { var x = eval ^= undefined; }", |
| 247 SyntaxError); |
| 248 CheckStrictMode("function strict() { var x = arguments |= undefined; }", |
| 249 SyntaxError); |
| 234 | 250 |
| 235 // Postfix increment with eval or arguments | 251 // Postfix increment with eval or arguments |
| 236 CheckStrictMode("function strict() { eval++; }", SyntaxError); | 252 CheckStrictMode("function strict() { eval++; }", SyntaxError); |
| 237 CheckStrictMode("function strict() { arguments++; }", SyntaxError); | 253 CheckStrictMode("function strict() { arguments++; }", SyntaxError); |
| 238 CheckStrictMode("function strict() { print(eval++); }", SyntaxError); | 254 CheckStrictMode("function strict() { print(eval++); }", SyntaxError); |
| 239 CheckStrictMode("function strict() { print(arguments++); }", SyntaxError); | 255 CheckStrictMode("function strict() { print(arguments++); }", SyntaxError); |
| 240 CheckStrictMode("function strict() { var x = eval++; }", SyntaxError); | 256 CheckStrictMode("function strict() { var x = eval++; }", SyntaxError); |
| 241 CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError); | 257 CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError); |
| 242 | 258 |
| 243 // Postfix decrement with eval or arguments | 259 // Postfix decrement with eval or arguments |
| (...skipping 13 matching lines...) Expand all Loading... |
| 257 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); | 273 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); |
| 258 | 274 |
| 259 // Prefix decrement with eval or arguments | 275 // Prefix decrement with eval or arguments |
| 260 CheckStrictMode("function strict() { --eval; }", SyntaxError); | 276 CheckStrictMode("function strict() { --eval; }", SyntaxError); |
| 261 CheckStrictMode("function strict() { --arguments; }", SyntaxError); | 277 CheckStrictMode("function strict() { --arguments; }", SyntaxError); |
| 262 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); | 278 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); |
| 263 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); | 279 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); |
| 264 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); | 280 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); |
| 265 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); | 281 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); |
| 266 | 282 |
| 283 // Use of const in strict mode is disallowed in anticipation of ES Harmony. |
| 284 CheckStrictMode("const x = 0;", SyntaxError); |
| 285 CheckStrictMode("for (const x = 0; false;) {}", SyntaxError); |
| 286 CheckStrictMode("function strict() { const x = 0; }", SyntaxError); |
| 287 |
| 288 // Strict mode only allows functions in SourceElements |
| 289 CheckStrictMode("if (true) { function invalid() {} }", SyntaxError); |
| 290 CheckStrictMode("for (;false;) { function invalid() {} }", SyntaxError); |
| 291 CheckStrictMode("{ function invalid() {} }", SyntaxError); |
| 292 CheckStrictMode("try { function invalid() {} } catch(e) {}", SyntaxError); |
| 293 CheckStrictMode("try { } catch(e) { function invalid() {} }", SyntaxError); |
| 294 CheckStrictMode("function outer() {{ function invalid() {} }}", SyntaxError); |
| 295 |
| 296 // Delete of an unqualified identifier |
| 297 CheckStrictMode("delete unqualified;", SyntaxError); |
| 298 CheckStrictMode("function strict() { delete unqualified; }", SyntaxError); |
| 299 CheckStrictMode("function function_name() { delete function_name; }", |
| 300 SyntaxError); |
| 301 CheckStrictMode("function strict(parameter) { delete parameter; }", |
| 302 SyntaxError); |
| 303 CheckStrictMode("function strict() { var variable; delete variable; }", |
| 304 SyntaxError); |
| 305 CheckStrictMode("var variable; delete variable;", SyntaxError); |
| 306 |
| 307 (function TestStrictDelete() { |
| 308 "use strict"; |
| 309 // "delete this" is allowed in strict mode and should work. |
| 310 function strict_delete() { delete this; } |
| 311 strict_delete(); |
| 312 })(); |
| 313 |
| 267 // Prefix unary operators other than delete, ++, -- are valid in strict mode | 314 // Prefix unary operators other than delete, ++, -- are valid in strict mode |
| 268 (function StrictModeUnaryOperators() { | 315 (function StrictModeUnaryOperators() { |
| 269 "use strict"; | 316 "use strict"; |
| 270 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; | 317 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; |
| 271 var y = [void arguments, typeof arguments, | 318 var y = [void arguments, typeof arguments, |
| 272 +arguments, -arguments, ~arguments, !arguments]; | 319 +arguments, -arguments, ~arguments, !arguments]; |
| 273 })(); | 320 })(); |
| 274 | 321 |
| 275 // 7.6.1.2 Future Reserved Words | 322 // 7.6.1.2 Future Reserved Words |
| 276 var future_reserved_words = [ | 323 var future_reserved_words = [ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); | 358 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); |
| 312 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); | 359 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); |
| 313 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); | 360 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); |
| 314 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); | 361 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); |
| 315 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); | 362 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); |
| 316 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); | 363 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); |
| 317 | 364 |
| 318 // Function names and arguments when the body is strict | 365 // Function names and arguments when the body is strict |
| 319 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); | 366 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); |
| 320 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); | 367 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); |
| 321 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", Sy
ntaxError); | 368 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", |
| 369 SyntaxError); |
| 322 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); | 370 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); |
| 323 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); | 371 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); |
| 324 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", SyntaxErro
r); | 372 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", |
| 325 assertThrows("var foo = function (" + word + ") { 'use strict'; }", SyntaxErro
r); | 373 SyntaxError); |
| 374 assertThrows("var foo = function (" + word + ") { 'use strict'; }", |
| 375 SyntaxError); |
| 326 | 376 |
| 327 // get/set when the body is strict | 377 // get/set when the body is strict |
| 328 eval("var x = { get " + word + " () { 'use strict'; } };"); | 378 eval("var x = { get " + word + " () { 'use strict'; } };"); |
| 329 eval("var x = { set " + word + " (value) { 'use strict'; } };"); | 379 eval("var x = { set " + word + " (value) { 'use strict'; } };"); |
| 330 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", SyntaxErr
or); | 380 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", |
| 331 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", SyntaxErr
or); | 381 SyntaxError); |
| 382 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", |
| 383 SyntaxError); |
| 332 } | 384 } |
| 333 | 385 |
| 334 for (var i = 0; i < future_reserved_words.length; i++) { | 386 for (var i = 0; i < future_reserved_words.length; i++) { |
| 335 testFutureReservedWord(future_reserved_words[i]); | 387 testFutureReservedWord(future_reserved_words[i]); |
| 336 } | 388 } |
| 337 | 389 |
| 338 | 390 function testAssignToUndefined(should_throw) { |
| 391 "use strict"; |
| 392 try { |
| 393 possibly_undefined_variable_for_strict_mode_test = "should throw?"; |
| 394 } catch (e) { |
| 395 assertTrue(should_throw, "strict mode"); |
| 396 assertInstanceof(e, ReferenceError, "strict mode"); |
| 397 return; |
| 398 } |
| 399 assertFalse(should_throw, "strict mode"); |
| 400 } |
| 401 |
| 402 testAssignToUndefined(true); |
| 403 testAssignToUndefined(true); |
| 404 testAssignToUndefined(true); |
| 405 |
| 406 possibly_undefined_variable_for_strict_mode_test = "value"; |
| 407 |
| 408 testAssignToUndefined(false); |
| 409 testAssignToUndefined(false); |
| 410 testAssignToUndefined(false); |
| 411 |
| 412 delete possibly_undefined_variable_for_strict_mode_test; |
| 413 |
| 414 testAssignToUndefined(true); |
| 415 testAssignToUndefined(true); |
| 416 testAssignToUndefined(true); |
| 417 |
| 418 function repeat(n, f) { |
| 419 for (var i = 0; i < n; i ++) { f(); } |
| 420 } |
| 421 |
| 422 repeat(10, function() { testAssignToUndefined(true); }); |
| 423 possibly_undefined_variable_for_strict_mode_test = "value"; |
| 424 repeat(10, function() { testAssignToUndefined(false); }); |
| 425 delete possibly_undefined_variable_for_strict_mode_test; |
| 426 repeat(10, function() { testAssignToUndefined(true); }); |
| 427 possibly_undefined_variable_for_strict_mode_test = undefined; |
| 428 repeat(10, function() { testAssignToUndefined(false); }); |
| 429 |
| 430 (function testDeleteNonConfigurable() { |
| 431 function delete_property(o) { |
| 432 "use strict"; |
| 433 delete o.property; |
| 434 } |
| 435 function delete_element(o, i) { |
| 436 "use strict"; |
| 437 delete o[i]; |
| 438 } |
| 439 |
| 440 var object = {}; |
| 441 |
| 442 Object.defineProperty(object, "property", { value: "property_value" }); |
| 443 Object.defineProperty(object, "1", { value: "one" }); |
| 444 Object.defineProperty(object, 7, { value: "seven" }); |
| 445 Object.defineProperty(object, 3.14, { value: "pi" }); |
| 446 |
| 447 assertThrows(function() { delete_property(object); }, TypeError); |
| 448 assertEquals(object.property, "property_value"); |
| 449 assertThrows(function() { delete_element(object, "1"); }, TypeError); |
| 450 assertThrows(function() { delete_element(object, 1); }, TypeError); |
| 451 assertEquals(object[1], "one"); |
| 452 assertThrows(function() { delete_element(object, "7"); }, TypeError); |
| 453 assertThrows(function() { delete_element(object, 7); }, TypeError); |
| 454 assertEquals(object[7], "seven"); |
| 455 assertThrows(function() { delete_element(object, "3.14"); }, TypeError); |
| 456 assertThrows(function() { delete_element(object, 3.14); }, TypeError); |
| 457 assertEquals(object[3.14], "pi"); |
| 458 })(); |
| 459 |
| 460 // Not transforming this in Function.call and Function.apply. |
| 461 (function testThisTransformCallApply() { |
| 462 function non_strict() { |
| 463 return this; |
| 464 } |
| 465 function strict() { |
| 466 "use strict"; |
| 467 return this; |
| 468 } |
| 469 |
| 470 var global_object = (function() { return this; })(); |
| 471 var object = {}; |
| 472 |
| 473 // Non-strict call. |
| 474 assertTrue(non_strict.call(null) === global_object); |
| 475 assertTrue(non_strict.call(undefined) === global_object); |
| 476 assertEquals(typeof non_strict.call(7), "object"); |
| 477 assertEquals(typeof non_strict.call("Hello"), "object"); |
| 478 assertTrue(non_strict.call(object) === object); |
| 479 |
| 480 // Non-strict apply. |
| 481 assertTrue(non_strict.apply(null) === global_object); |
| 482 assertTrue(non_strict.apply(undefined) === global_object); |
| 483 assertEquals(typeof non_strict.apply(7), "object"); |
| 484 assertEquals(typeof non_strict.apply("Hello"), "object"); |
| 485 assertTrue(non_strict.apply(object) === object); |
| 486 |
| 487 // Strict call. |
| 488 assertTrue(strict.call(null) === null); |
| 489 assertTrue(strict.call(undefined) === undefined); |
| 490 assertEquals(typeof strict.call(7), "number"); |
| 491 assertEquals(typeof strict.call("Hello"), "string"); |
| 492 assertTrue(strict.call(object) === object); |
| 493 |
| 494 // Strict apply. |
| 495 assertTrue(strict.apply(null) === null); |
| 496 assertTrue(strict.apply(undefined) === undefined); |
| 497 assertEquals(typeof strict.apply(7), "number"); |
| 498 assertEquals(typeof strict.apply("Hello"), "string"); |
| 499 assertTrue(strict.apply(object) === object); |
| 500 })(); |
| 501 |
| 502 (function testThisTransform() { |
| 503 try { |
| 504 function strict() { |
| 505 "use strict"; |
| 506 return typeof(this); |
| 507 } |
| 508 function nonstrict() { |
| 509 return typeof(this); |
| 510 } |
| 511 |
| 512 // Concat to avoid symbol. |
| 513 var strict_name = "str" + "ict"; |
| 514 var nonstrict_name = "non" + "str" + "ict"; |
| 515 var strict_number = 17; |
| 516 var nonstrict_number = 19; |
| 517 var strict_name_get = "str" + "ict" + "get"; |
| 518 var nonstrict_name_get = "non" + "str" + "ict" + "get" |
| 519 var strict_number_get = 23; |
| 520 var nonstrict_number_get = 29; |
| 521 |
| 522 function install(t) { |
| 523 t.prototype.strict = strict; |
| 524 t.prototype.nonstrict = nonstrict; |
| 525 t.prototype[strict_number] = strict; |
| 526 t.prototype[nonstrict_number] = nonstrict; |
| 527 Object.defineProperty(t.prototype, strict_name_get, |
| 528 { get: function() { return strict; }, |
| 529 configurable: true }); |
| 530 Object.defineProperty(t.prototype, nonstrict_name_get, |
| 531 { get: function() { return nonstrict; }, |
| 532 configurable: true }); |
| 533 Object.defineProperty(t.prototype, strict_number_get, |
| 534 { get: function() { return strict; }, |
| 535 configurable: true }); |
| 536 Object.defineProperty(t.prototype, nonstrict_number_get, |
| 537 { get: function() { return nonstrict; }, |
| 538 configurable: true }); |
| 539 } |
| 540 |
| 541 function cleanup(t) { |
| 542 delete t.prototype.strict; |
| 543 delete t.prototype.nonstrict; |
| 544 delete t.prototype[strict_number]; |
| 545 delete t.prototype[nonstrict_number]; |
| 546 delete t.prototype[strict_name_get]; |
| 547 delete t.prototype[nonstrict_name_get]; |
| 548 delete t.prototype[strict_number_get]; |
| 549 delete t.prototype[nonstrict_number_get]; |
| 550 } |
| 551 |
| 552 // Set up fakes |
| 553 install(String); |
| 554 install(Number); |
| 555 install(Boolean) |
| 556 |
| 557 function callStrict(o) { |
| 558 return o.strict(); |
| 559 } |
| 560 function callNonStrict(o) { |
| 561 return o.nonstrict(); |
| 562 } |
| 563 function callKeyedStrict(o) { |
| 564 return o[strict_name](); |
| 565 } |
| 566 function callKeyedNonStrict(o) { |
| 567 return o[nonstrict_name](); |
| 568 } |
| 569 function callIndexedStrict(o) { |
| 570 return o[strict_number](); |
| 571 } |
| 572 function callIndexedNonStrict(o) { |
| 573 return o[nonstrict_number](); |
| 574 } |
| 575 function callStrictGet(o) { |
| 576 return o.strictget(); |
| 577 } |
| 578 function callNonStrictGet(o) { |
| 579 return o.nonstrictget(); |
| 580 } |
| 581 function callKeyedStrictGet(o) { |
| 582 return o[strict_name_get](); |
| 583 } |
| 584 function callKeyedNonStrictGet(o) { |
| 585 return o[nonstrict_name_get](); |
| 586 } |
| 587 function callIndexedStrictGet(o) { |
| 588 return o[strict_number_get](); |
| 589 } |
| 590 function callIndexedNonStrictGet(o) { |
| 591 return o[nonstrict_number_get](); |
| 592 } |
| 593 |
| 594 for (var i = 0; i < 10; i ++) { |
| 595 assertEquals(("hello").strict(), "string"); |
| 596 assertEquals(("hello").nonstrict(), "object"); |
| 597 assertEquals(("hello")[strict_name](), "string"); |
| 598 assertEquals(("hello")[nonstrict_name](), "object"); |
| 599 assertEquals(("hello")[strict_number](), "string"); |
| 600 assertEquals(("hello")[nonstrict_number](), "object"); |
| 601 |
| 602 assertEquals((10 + i).strict(), "number"); |
| 603 assertEquals((10 + i).nonstrict(), "object"); |
| 604 assertEquals((10 + i)[strict_name](), "number"); |
| 605 assertEquals((10 + i)[nonstrict_name](), "object"); |
| 606 assertEquals((10 + i)[strict_number](), "number"); |
| 607 assertEquals((10 + i)[nonstrict_number](), "object"); |
| 608 |
| 609 assertEquals((true).strict(), "boolean"); |
| 610 assertEquals((true).nonstrict(), "object"); |
| 611 assertEquals((true)[strict_name](), "boolean"); |
| 612 assertEquals((true)[nonstrict_name](), "object"); |
| 613 assertEquals((true)[strict_number](), "boolean"); |
| 614 assertEquals((true)[nonstrict_number](), "object"); |
| 615 |
| 616 assertEquals((false).strict(), "boolean"); |
| 617 assertEquals((false).nonstrict(), "object"); |
| 618 assertEquals((false)[strict_name](), "boolean"); |
| 619 assertEquals((false)[nonstrict_name](), "object"); |
| 620 assertEquals((false)[strict_number](), "boolean"); |
| 621 assertEquals((false)[nonstrict_number](), "object"); |
| 622 |
| 623 assertEquals(callStrict("howdy"), "string"); |
| 624 assertEquals(callNonStrict("howdy"), "object"); |
| 625 assertEquals(callKeyedStrict("howdy"), "string"); |
| 626 assertEquals(callKeyedNonStrict("howdy"), "object"); |
| 627 assertEquals(callIndexedStrict("howdy"), "string"); |
| 628 assertEquals(callIndexedNonStrict("howdy"), "object"); |
| 629 |
| 630 assertEquals(callStrict(17 + i), "number"); |
| 631 assertEquals(callNonStrict(17 + i), "object"); |
| 632 assertEquals(callKeyedStrict(17 + i), "number"); |
| 633 assertEquals(callKeyedNonStrict(17 + i), "object"); |
| 634 assertEquals(callIndexedStrict(17 + i), "number"); |
| 635 assertEquals(callIndexedNonStrict(17 + i), "object"); |
| 636 |
| 637 assertEquals(callStrict(true), "boolean"); |
| 638 assertEquals(callNonStrict(true), "object"); |
| 639 assertEquals(callKeyedStrict(true), "boolean"); |
| 640 assertEquals(callKeyedNonStrict(true), "object"); |
| 641 assertEquals(callIndexedStrict(true), "boolean"); |
| 642 assertEquals(callIndexedNonStrict(true), "object"); |
| 643 |
| 644 assertEquals(callStrict(false), "boolean"); |
| 645 assertEquals(callNonStrict(false), "object"); |
| 646 assertEquals(callKeyedStrict(false), "boolean"); |
| 647 assertEquals(callKeyedNonStrict(false), "object"); |
| 648 assertEquals(callIndexedStrict(false), "boolean"); |
| 649 assertEquals(callIndexedNonStrict(false), "object"); |
| 650 |
| 651 // All of the above, with getters |
| 652 assertEquals(("hello").strictget(), "string"); |
| 653 assertEquals(("hello").nonstrictget(), "object"); |
| 654 assertEquals(("hello")[strict_name_get](), "string"); |
| 655 assertEquals(("hello")[nonstrict_name_get](), "object"); |
| 656 assertEquals(("hello")[strict_number_get](), "string"); |
| 657 assertEquals(("hello")[nonstrict_number_get](), "object"); |
| 658 |
| 659 assertEquals((10 + i).strictget(), "number"); |
| 660 assertEquals((10 + i).nonstrictget(), "object"); |
| 661 assertEquals((10 + i)[strict_name_get](), "number"); |
| 662 assertEquals((10 + i)[nonstrict_name_get](), "object"); |
| 663 assertEquals((10 + i)[strict_number_get](), "number"); |
| 664 assertEquals((10 + i)[nonstrict_number_get](), "object"); |
| 665 |
| 666 assertEquals((true).strictget(), "boolean"); |
| 667 assertEquals((true).nonstrictget(), "object"); |
| 668 assertEquals((true)[strict_name_get](), "boolean"); |
| 669 assertEquals((true)[nonstrict_name_get](), "object"); |
| 670 assertEquals((true)[strict_number_get](), "boolean"); |
| 671 assertEquals((true)[nonstrict_number_get](), "object"); |
| 672 |
| 673 assertEquals((false).strictget(), "boolean"); |
| 674 assertEquals((false).nonstrictget(), "object"); |
| 675 assertEquals((false)[strict_name_get](), "boolean"); |
| 676 assertEquals((false)[nonstrict_name_get](), "object"); |
| 677 assertEquals((false)[strict_number_get](), "boolean"); |
| 678 assertEquals((false)[nonstrict_number_get](), "object"); |
| 679 |
| 680 assertEquals(callStrictGet("howdy"), "string"); |
| 681 assertEquals(callNonStrictGet("howdy"), "object"); |
| 682 assertEquals(callKeyedStrictGet("howdy"), "string"); |
| 683 assertEquals(callKeyedNonStrictGet("howdy"), "object"); |
| 684 assertEquals(callIndexedStrictGet("howdy"), "string"); |
| 685 assertEquals(callIndexedNonStrictGet("howdy"), "object"); |
| 686 |
| 687 assertEquals(callStrictGet(17 + i), "number"); |
| 688 assertEquals(callNonStrictGet(17 + i), "object"); |
| 689 assertEquals(callKeyedStrictGet(17 + i), "number"); |
| 690 assertEquals(callKeyedNonStrictGet(17 + i), "object"); |
| 691 assertEquals(callIndexedStrictGet(17 + i), "number"); |
| 692 assertEquals(callIndexedNonStrictGet(17 + i), "object"); |
| 693 |
| 694 assertEquals(callStrictGet(true), "boolean"); |
| 695 assertEquals(callNonStrictGet(true), "object"); |
| 696 assertEquals(callKeyedStrictGet(true), "boolean"); |
| 697 assertEquals(callKeyedNonStrictGet(true), "object"); |
| 698 assertEquals(callIndexedStrictGet(true), "boolean"); |
| 699 assertEquals(callIndexedNonStrictGet(true), "object"); |
| 700 |
| 701 assertEquals(callStrictGet(false), "boolean"); |
| 702 assertEquals(callNonStrictGet(false), "object"); |
| 703 assertEquals(callKeyedStrictGet(false), "boolean"); |
| 704 assertEquals(callKeyedNonStrictGet(false), "object"); |
| 705 assertEquals(callIndexedStrictGet(false), "boolean"); |
| 706 assertEquals(callIndexedNonStrictGet(false), "object"); |
| 707 |
| 708 } |
| 709 } finally { |
| 710 // Cleanup |
| 711 cleanup(String); |
| 712 cleanup(Number); |
| 713 cleanup(Boolean); |
| 714 } |
| 715 })(); |
| 716 |
| 717 |
| 718 (function ObjectEnvironment() { |
| 719 var o = {}; |
| 720 Object.defineProperty(o, "foo", { value: "FOO", writable: false }); |
| 721 assertThrows( |
| 722 function () { |
| 723 with (o) { |
| 724 (function() { |
| 725 "use strict"; |
| 726 foo = "Hello"; |
| 727 })(); |
| 728 } |
| 729 }, |
| 730 TypeError); |
| 731 })(); |
| 732 |
| 733 |
| 734 (function TestSetPropertyWithoutSetter() { |
| 735 var o = { get foo() { return "Yey"; } }; |
| 736 assertThrows( |
| 737 function broken() { |
| 738 "use strict"; |
| 739 o.foo = (0xBADBAD00 >> 1); |
| 740 }, |
| 741 TypeError); |
| 742 })(); |
| 743 |
| 744 |
| 745 (function TestSetPropertyNonConfigurable() { |
| 746 var frozen = Object.freeze({}); |
| 747 var sealed = Object.seal({}); |
| 748 |
| 749 function strict(o) { |
| 750 "use strict"; |
| 751 o.property = "value"; |
| 752 } |
| 753 |
| 754 assertThrows(function() { strict(frozen); }, TypeError); |
| 755 assertThrows(function() { strict(sealed); }, TypeError); |
| 756 })(); |
| 757 |
| 758 |
| 759 (function TestAssignmentToReadOnlyProperty() { |
| 760 "use strict"; |
| 761 |
| 762 var o = {}; |
| 763 Object.defineProperty(o, "property", { value: 7 }); |
| 764 |
| 765 assertThrows(function() { o.property = "new value"; }, TypeError); |
| 766 assertThrows(function() { o.property += 10; }, TypeError); |
| 767 assertThrows(function() { o.property -= 10; }, TypeError); |
| 768 assertThrows(function() { o.property *= 10; }, TypeError); |
| 769 assertThrows(function() { o.property /= 10; }, TypeError); |
| 770 assertThrows(function() { o.property++; }, TypeError); |
| 771 assertThrows(function() { o.property--; }, TypeError); |
| 772 assertThrows(function() { ++o.property; }, TypeError); |
| 773 assertThrows(function() { --o.property; }, TypeError); |
| 774 |
| 775 var name = "prop" + "erty"; // to avoid symbol path. |
| 776 assertThrows(function() { o[name] = "new value"; }, TypeError); |
| 777 assertThrows(function() { o[name] += 10; }, TypeError); |
| 778 assertThrows(function() { o[name] -= 10; }, TypeError); |
| 779 assertThrows(function() { o[name] *= 10; }, TypeError); |
| 780 assertThrows(function() { o[name] /= 10; }, TypeError); |
| 781 assertThrows(function() { o[name]++; }, TypeError); |
| 782 assertThrows(function() { o[name]--; }, TypeError); |
| 783 assertThrows(function() { ++o[name]; }, TypeError); |
| 784 assertThrows(function() { --o[name]; }, TypeError); |
| 785 |
| 786 assertEquals(o.property, 7); |
| 787 })(); |
| 788 |
| 789 |
| 790 (function TestAssignmentToReadOnlyLoop() { |
| 791 var name = "prop" + "erty"; // to avoid symbol path. |
| 792 var o = {}; |
| 793 Object.defineProperty(o, "property", { value: 7 }); |
| 794 |
| 795 function strict(o, name) { |
| 796 "use strict"; |
| 797 o[name] = "new value"; |
| 798 } |
| 799 |
| 800 for (var i = 0; i < 10; i ++) { |
| 801 try { |
| 802 strict(o, name); |
| 803 assertUnreachable(); |
| 804 } catch(e) { |
| 805 assertInstanceof(e, TypeError); |
| 806 } |
| 807 } |
| 808 })(); |
| 809 |
| 810 |
| 811 // Specialized KeyedStoreIC experiencing miss. |
| 812 (function testKeyedStoreICStrict() { |
| 813 var o = [9,8,7,6,5,4,3,2,1]; |
| 814 |
| 815 function test(o, i, v) { |
| 816 "use strict"; |
| 817 o[i] = v; |
| 818 } |
| 819 |
| 820 for (var i = 0; i < 10; i ++) { |
| 821 test(o, 5, 17); // start specialized for smi indices |
| 822 assertEquals(o[5], 17); |
| 823 test(o, "a", 19); |
| 824 assertEquals(o["a"], 19); |
| 825 test(o, "5", 29); |
| 826 assertEquals(o[5], 29); |
| 827 test(o, 100000, 31); |
| 828 assertEquals(o[100000], 31); |
| 829 } |
| 830 })(); |
| OLD | NEW |