| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Create strict mode function. Exception expected. | 57 // Create strict mode function. Exception expected. |
| 58 args[arguments.length] = "'use strict';"; | 58 args[arguments.length] = "'use strict';"; |
| 59 assertThrows(function() { | 59 assertThrows(function() { |
| 60 Function.apply(this, args); | 60 Function.apply(this, args); |
| 61 }, SyntaxError); | 61 }, SyntaxError); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Incorrect 'use strict' directive. | 64 // Incorrect 'use strict' directive. |
| 65 (function UseStrictEscape() { | 65 (function UseStrictEscape() { |
| 66 "use\\x20strict"; | 66 "use\\x20strict"; |
| 67 with ({}) {}; | 67 with ({}) {} |
| 68 })(); | 68 })(); |
| 69 | 69 |
| 70 // Incorrectly place 'use strict' directive. | 70 // Incorrectly place 'use strict' directive. |
| 71 assertThrows("function foo (x) 'use strict'; {}", SyntaxError); | 71 assertThrows("function foo (x) 'use strict'; {}", SyntaxError); |
| 72 | 72 |
| 73 // 'use strict' in non-directive position. | 73 // 'use strict' in non-directive position. |
| 74 (function UseStrictNonDirective() { | 74 (function UseStrictNonDirective() { |
| 75 void(0); | 75 void(0); |
| 76 "use strict"; | 76 "use strict"; |
| 77 with ({}) {}; | 77 with ({}) {} |
| 78 })(); | 78 })(); |
| 79 | 79 |
| 80 // Multiple directives, including "use strict". | 80 // Multiple directives, including "use strict". |
| 81 assertThrows('\ | 81 assertThrows('\ |
| 82 "directive 1";\ | 82 "directive 1";\ |
| 83 "another directive";\ | 83 "another directive";\ |
| 84 "use strict";\ | 84 "use strict";\ |
| 85 "directive after strict";\ | 85 "directive after strict";\ |
| 86 "and one more";\ | 86 "and one more";\ |
| 87 with({}) {}', SyntaxError); | 87 with({}) {}', SyntaxError); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 assertThrows('\ | 136 assertThrows('\ |
| 137 function foo(eval) {\ | 137 function foo(eval) {\ |
| 138 "use strict";\ | 138 "use strict";\ |
| 139 }', SyntaxError); | 139 }', SyntaxError); |
| 140 | 140 |
| 141 // Strict mode doesn't affect the outer stop of strict code. | 141 // Strict mode doesn't affect the outer stop of strict code. |
| 142 (function NotStrict(eval) { | 142 (function NotStrict(eval) { |
| 143 function Strict() { | 143 function Strict() { |
| 144 "use strict"; | 144 "use strict"; |
| 145 } | 145 } |
| 146 with ({}) {}; | 146 with ({}) {} |
| 147 })(); | 147 })(); |
| 148 | 148 |
| 149 // Octal literal | 149 // Octal literal |
| 150 CheckStrictMode("var x = 012"); | 150 CheckStrictMode("var x = 012"); |
| 151 CheckStrictMode("012"); | 151 CheckStrictMode("012"); |
| 152 CheckStrictMode("'Hello octal\\032'"); | 152 CheckStrictMode("'Hello octal\\032'"); |
| 153 CheckStrictMode("function octal() { return 012; }"); | 153 CheckStrictMode("function octal() { return 012; }"); |
| 154 CheckStrictMode("function octal() { return '\\032'; }"); | 154 CheckStrictMode("function octal() { return '\\032'; }"); |
| 155 | 155 |
| 156 (function ValidEscape() { | 156 (function ValidEscape() { |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 function nonstrict() { | 548 function nonstrict() { |
| 549 return typeof(this); | 549 return typeof(this); |
| 550 } | 550 } |
| 551 | 551 |
| 552 // Concat to avoid symbol. | 552 // Concat to avoid symbol. |
| 553 var strict_name = "str" + "ict"; | 553 var strict_name = "str" + "ict"; |
| 554 var nonstrict_name = "non" + "str" + "ict"; | 554 var nonstrict_name = "non" + "str" + "ict"; |
| 555 var strict_number = 17; | 555 var strict_number = 17; |
| 556 var nonstrict_number = 19; | 556 var nonstrict_number = 19; |
| 557 var strict_name_get = "str" + "ict" + "get"; | 557 var strict_name_get = "str" + "ict" + "get"; |
| 558 var nonstrict_name_get = "non" + "str" + "ict" + "get" | 558 var nonstrict_name_get = "non" + "str" + "ict" + "get"; |
| 559 var strict_number_get = 23; | 559 var strict_number_get = 23; |
| 560 var nonstrict_number_get = 29; | 560 var nonstrict_number_get = 29; |
| 561 | 561 |
| 562 function install(t) { | 562 function install(t) { |
| 563 t.prototype.strict = strict; | 563 t.prototype.strict = strict; |
| 564 t.prototype.nonstrict = nonstrict; | 564 t.prototype.nonstrict = nonstrict; |
| 565 t.prototype[strict_number] = strict; | 565 t.prototype[strict_number] = strict; |
| 566 t.prototype[nonstrict_number] = nonstrict; | 566 t.prototype[nonstrict_number] = nonstrict; |
| 567 Object.defineProperty(t.prototype, strict_name_get, | 567 Object.defineProperty(t.prototype, strict_name_get, |
| 568 { get: function() { return strict; }, | 568 { get: function() { return strict; }, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 585 delete t.prototype[nonstrict_number]; | 585 delete t.prototype[nonstrict_number]; |
| 586 delete t.prototype[strict_name_get]; | 586 delete t.prototype[strict_name_get]; |
| 587 delete t.prototype[nonstrict_name_get]; | 587 delete t.prototype[nonstrict_name_get]; |
| 588 delete t.prototype[strict_number_get]; | 588 delete t.prototype[strict_number_get]; |
| 589 delete t.prototype[nonstrict_number_get]; | 589 delete t.prototype[nonstrict_number_get]; |
| 590 } | 590 } |
| 591 | 591 |
| 592 // Set up fakes | 592 // Set up fakes |
| 593 install(String); | 593 install(String); |
| 594 install(Number); | 594 install(Number); |
| 595 install(Boolean) | 595 install(Boolean); |
| 596 | 596 |
| 597 function callStrict(o) { | 597 function callStrict(o) { |
| 598 return o.strict(); | 598 return o.strict(); |
| 599 } | 599 } |
| 600 function callNonStrict(o) { | 600 function callNonStrict(o) { |
| 601 return o.nonstrict(); | 601 return o.nonstrict(); |
| 602 } | 602 } |
| 603 function callKeyedStrict(o) { | 603 function callKeyedStrict(o) { |
| 604 return o[strict_name](); | 604 return o[strict_name](); |
| 605 } | 605 } |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 | 971 |
| 972 var o = {}; | 972 var o = {}; |
| 973 Object.defineProperty(o, 7, { value: 17 }); | 973 Object.defineProperty(o, 7, { value: 17 }); |
| 974 | 974 |
| 975 var seven_smi = 7; | 975 var seven_smi = 7; |
| 976 var seven_number = new Number(7); | 976 var seven_number = new Number(7); |
| 977 var seven_symbol = "7"; | 977 var seven_symbol = "7"; |
| 978 var seven_string = "-7-".substring(1,2); | 978 var seven_string = "-7-".substring(1,2); |
| 979 | 979 |
| 980 for (var i = 0; i < 10; i ++) { | 980 for (var i = 0; i < 10; i ++) { |
| 981 assertThrows(function() { o[seven_smi] = "value" }, TypeError); | 981 assertThrows(function() { o[seven_smi] = "value"; }, TypeError); |
| 982 assertThrows(function() { o[seven_number] = "value" }, TypeError); | 982 assertThrows(function() { o[seven_number] = "value"; }, TypeError); |
| 983 assertThrows(function() { o[seven_symbol] = "value" }, TypeError); | 983 assertThrows(function() { o[seven_symbol] = "value"; }, TypeError); |
| 984 assertThrows(function() { o[seven_string] = "value" }, TypeError); | 984 assertThrows(function() { o[seven_string] = "value"; }, TypeError); |
| 985 } | 985 } |
| 986 | 986 |
| 987 assertEquals(o[7], 17); | 987 assertEquals(o[7], 17); |
| 988 })(); | 988 })(); |
| 989 | 989 |
| 990 | 990 |
| 991 (function TestAssignmentToStringLength() { | 991 (function TestAssignmentToStringLength() { |
| 992 "use strict"; | 992 "use strict"; |
| 993 | 993 |
| 994 var str_val = "string"; | 994 var str_val = "string"; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 TypeError); | 1031 TypeError); |
| 1032 assertThrows(pill, TypeError); | 1032 assertThrows(pill, TypeError); |
| 1033 assertEquals(pill.prototype, (function(){}).prototype); | 1033 assertEquals(pill.prototype, (function(){}).prototype); |
| 1034 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); | 1034 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); |
| 1035 assertFalse(d.writable); | 1035 assertFalse(d.writable); |
| 1036 assertFalse(d.configurable); | 1036 assertFalse(d.configurable); |
| 1037 assertFalse(d.enumerable); | 1037 assertFalse(d.enumerable); |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 var descriptor = Object.getOwnPropertyDescriptor(func, name); | 1040 var descriptor = Object.getOwnPropertyDescriptor(func, name); |
| 1041 CheckPill(descriptor.get) | 1041 CheckPill(descriptor.get); |
| 1042 CheckPill(descriptor.set); | 1042 CheckPill(descriptor.set); |
| 1043 assertFalse(descriptor.enumerable); | 1043 assertFalse(descriptor.enumerable); |
| 1044 assertFalse(descriptor.configurable); | 1044 assertFalse(descriptor.configurable); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 | 1047 |
| 1048 (function TestStrictFunctionPills() { | 1048 (function TestStrictFunctionPills() { |
| 1049 function strict() { | 1049 function strict() { |
| 1050 "use strict"; | 1050 "use strict"; |
| 1051 } | 1051 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 function strict() { | 1100 function strict() { |
| 1101 "use strict"; | 1101 "use strict"; |
| 1102 return arguments; | 1102 return arguments; |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 var args = strict(); | 1105 var args = strict(); |
| 1106 CheckPillDescriptor(args, "caller"); | 1106 CheckPillDescriptor(args, "caller"); |
| 1107 CheckPillDescriptor(args, "callee"); | 1107 CheckPillDescriptor(args, "callee"); |
| 1108 | 1108 |
| 1109 args = strict(17, "value", strict); | 1109 args = strict(17, "value", strict); |
| 1110 assertEquals(17, args[0]) | 1110 assertEquals(17, args[0]); |
| 1111 assertEquals("value", args[1]) | 1111 assertEquals("value", args[1]); |
| 1112 assertEquals(strict, args[2]); | 1112 assertEquals(strict, args[2]); |
| 1113 CheckPillDescriptor(args, "caller"); | 1113 CheckPillDescriptor(args, "caller"); |
| 1114 CheckPillDescriptor(args, "callee"); | 1114 CheckPillDescriptor(args, "callee"); |
| 1115 | 1115 |
| 1116 function outer() { | 1116 function outer() { |
| 1117 "use strict"; | 1117 "use strict"; |
| 1118 function inner() { | 1118 function inner() { |
| 1119 return arguments; | 1119 return arguments; |
| 1120 } | 1120 } |
| 1121 return inner; | 1121 return inner; |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 var args = outer()(); | 1124 var args = outer()(); |
| 1125 CheckPillDescriptor(args, "caller"); | 1125 CheckPillDescriptor(args, "caller"); |
| 1126 CheckPillDescriptor(args, "callee"); | 1126 CheckPillDescriptor(args, "callee"); |
| 1127 | 1127 |
| 1128 args = outer()(17, "value", strict); | 1128 args = outer()(17, "value", strict); |
| 1129 assertEquals(17, args[0]) | 1129 assertEquals(17, args[0]); |
| 1130 assertEquals("value", args[1]) | 1130 assertEquals("value", args[1]); |
| 1131 assertEquals(strict, args[2]); | 1131 assertEquals(strict, args[2]); |
| 1132 CheckPillDescriptor(args, "caller"); | 1132 CheckPillDescriptor(args, "caller"); |
| 1133 CheckPillDescriptor(args, "callee"); | 1133 CheckPillDescriptor(args, "callee"); |
| 1134 })(); | 1134 })(); |
| 1135 | 1135 |
| 1136 | 1136 |
| 1137 (function TestNonStrictFunctionCallerPillSimple() { | 1137 (function TestNonStrictFunctionCallerPillSimple() { |
| 1138 function return_my_caller() { | 1138 function return_my_caller() { |
| 1139 return return_my_caller.caller; | 1139 return return_my_caller.caller; |
| 1140 } | 1140 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 assertEquals(test(i), true); | 1183 assertEquals(test(i), true); |
| 1184 } | 1184 } |
| 1185 })(); | 1185 })(); |
| 1186 | 1186 |
| 1187 | 1187 |
| 1188 (function TestStrictModeEval() { | 1188 (function TestStrictModeEval() { |
| 1189 "use strict"; | 1189 "use strict"; |
| 1190 eval("var eval_local = 10;"); | 1190 eval("var eval_local = 10;"); |
| 1191 assertThrows(function() { return eval_local; }, ReferenceError); | 1191 assertThrows(function() { return eval_local; }, ReferenceError); |
| 1192 })(); | 1192 })(); |
| OLD | NEW |