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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 a = "c"; | 971 a = "c"; |
972 b = "d"; | 972 b = "d"; |
973 return [a, b, arguments[0], arguments[1]]; | 973 return [a, b, arguments[0], arguments[1]]; |
974 } | 974 } |
975 | 975 |
976 assertEquals(["c", "d", "a", "b"], strict("a", "b")); | 976 assertEquals(["c", "d", "a", "b"], strict("a", "b")); |
977 assertEquals(["c", "d", "c", "d"], nonstrict("a", "b")); | 977 assertEquals(["c", "d", "c", "d"], nonstrict("a", "b")); |
978 })(); | 978 })(); |
979 | 979 |
980 | 980 |
981 (function TestStrictFunctionPills() { | 981 function CheckPillDescriptor(func, name) { |
982 function strict() { | |
983 "use strict"; | |
984 } | |
985 assertThrows(function() { strict.caller; }, TypeError); | |
986 assertThrows(function() { strict.arguments; }, TypeError); | |
987 | |
988 var another = new Function("'use strict'"); | |
989 assertThrows(function() { another.caller; }, TypeError); | |
990 assertThrows(function() { another.arguments; }, TypeError); | |
991 | |
992 var third = (function() { "use strict"; return function() {}; })(); | |
993 assertThrows(function() { third.caller; }, TypeError); | |
994 assertThrows(function() { third.arguments; }, TypeError); | |
995 | 982 |
996 function CheckPill(pill) { | 983 function CheckPill(pill) { |
997 assertEquals("function", typeof pill); | 984 assertEquals("function", typeof pill); |
998 assertInstanceof(pill, Function); | 985 assertInstanceof(pill, Function); |
999 assertThrows(function() { pill.property = "value"; }, TypeError); | 986 assertThrows(function() { pill.property = "value"; }, TypeError); |
1000 assertThrows(pill, TypeError); | 987 assertThrows(pill, TypeError); |
1001 assertEquals(pill.prototype, (function(){}).prototype); | 988 assertEquals(pill.prototype, (function(){}).prototype); |
1002 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); | 989 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); |
1003 assertFalse(d.writable); | 990 assertFalse(d.writable); |
1004 assertFalse(d.configurable); | 991 assertFalse(d.configurable); |
1005 assertFalse(d.enumerable); | 992 assertFalse(d.enumerable); |
1006 } | 993 } |
1007 | 994 |
1008 function CheckPillDescriptor(func, name) { | 995 var descriptor = Object.getOwnPropertyDescriptor(func, name); |
1009 var descriptor = Object.getOwnPropertyDescriptor(func, name); | 996 CheckPill(descriptor.get) |
1010 CheckPill(descriptor.get) | 997 CheckPill(descriptor.set); |
1011 CheckPill(descriptor.set); | 998 assertFalse(descriptor.enumerable); |
1012 assertFalse(descriptor.enumerable); | 999 assertFalse(descriptor.configurable); |
1013 assertFalse(descriptor.configurable); | 1000 } |
| 1001 |
| 1002 |
| 1003 (function TestStrictFunctionPills() { |
| 1004 function strict() { |
| 1005 "use strict"; |
1014 } | 1006 } |
| 1007 assertThrows(function() { strict.caller; }, TypeError); |
| 1008 assertThrows(function() { strict.arguments; }, TypeError); |
| 1009 |
| 1010 var another = new Function("'use strict'"); |
| 1011 assertThrows(function() { another.caller; }, TypeError); |
| 1012 assertThrows(function() { another.arguments; }, TypeError); |
| 1013 |
| 1014 var third = (function() { "use strict"; return function() {}; })(); |
| 1015 assertThrows(function() { third.caller; }, TypeError); |
| 1016 assertThrows(function() { third.arguments; }, TypeError); |
1015 | 1017 |
1016 CheckPillDescriptor(strict, "caller"); | 1018 CheckPillDescriptor(strict, "caller"); |
1017 CheckPillDescriptor(strict, "arguments"); | 1019 CheckPillDescriptor(strict, "arguments"); |
1018 CheckPillDescriptor(another, "caller"); | 1020 CheckPillDescriptor(another, "caller"); |
1019 CheckPillDescriptor(another, "arguments"); | 1021 CheckPillDescriptor(another, "arguments"); |
1020 CheckPillDescriptor(third, "caller"); | 1022 CheckPillDescriptor(third, "caller"); |
1021 CheckPillDescriptor(third, "arguments"); | 1023 CheckPillDescriptor(third, "arguments"); |
1022 })(); | 1024 })(); |
| 1025 |
| 1026 |
| 1027 (function TestStrictArgumentPills() { |
| 1028 function strict() { |
| 1029 "use strict"; |
| 1030 return arguments; |
| 1031 } |
| 1032 |
| 1033 var args = strict(); |
| 1034 CheckPillDescriptor(args, "caller"); |
| 1035 CheckPillDescriptor(args, "callee"); |
| 1036 |
| 1037 args = strict(17, "value", strict); |
| 1038 assertEquals(17, args[0]) |
| 1039 assertEquals("value", args[1]) |
| 1040 assertEquals(strict, args[2]); |
| 1041 CheckPillDescriptor(args, "caller"); |
| 1042 CheckPillDescriptor(args, "callee"); |
| 1043 |
| 1044 function outer() { |
| 1045 "use strict"; |
| 1046 function inner() { |
| 1047 return arguments; |
| 1048 } |
| 1049 return inner; |
| 1050 } |
| 1051 |
| 1052 var args = outer()(); |
| 1053 CheckPillDescriptor(args, "caller"); |
| 1054 CheckPillDescriptor(args, "callee"); |
| 1055 |
| 1056 args = outer()(17, "value", strict); |
| 1057 assertEquals(17, args[0]) |
| 1058 assertEquals("value", args[1]) |
| 1059 assertEquals(strict, args[2]); |
| 1060 CheckPillDescriptor(args, "caller"); |
| 1061 CheckPillDescriptor(args, "callee"); |
| 1062 })(); |
OLD | NEW |