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 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 | 969 |
970 function nonstrict(a, b) { | 970 function nonstrict(a, b) { |
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 |
| 980 |
| 981 (function TestStrictFunctionPills() { |
| 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 |
| 996 function CheckPill(pill) { |
| 997 assertEquals("function", typeof pill); |
| 998 assertInstanceof(pill, Function); |
| 999 assertThrows(function() { pill.property = "value"; }, TypeError); |
| 1000 assertThrows(pill, TypeError); |
| 1001 assertEquals(pill.prototype, (function(){}).prototype); |
| 1002 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); |
| 1003 assertFalse(d.writable); |
| 1004 assertFalse(d.configurable); |
| 1005 assertFalse(d.enumerable); |
| 1006 } |
| 1007 |
| 1008 function CheckPillDescriptor(func, name) { |
| 1009 var descriptor = Object.getOwnPropertyDescriptor(func, name); |
| 1010 CheckPill(descriptor.get) |
| 1011 CheckPill(descriptor.set); |
| 1012 assertFalse(descriptor.enumerable); |
| 1013 assertFalse(descriptor.configurable); |
| 1014 } |
| 1015 |
| 1016 CheckPillDescriptor(strict, "caller"); |
| 1017 CheckPillDescriptor(strict, "arguments"); |
| 1018 CheckPillDescriptor(another, "caller"); |
| 1019 CheckPillDescriptor(another, "arguments"); |
| 1020 CheckPillDescriptor(third, "caller"); |
| 1021 CheckPillDescriptor(third, "arguments"); |
| 1022 })(); |
| 1023 |
| 1024 |
| 1025 (function TestStrictFunctionWritablePrototype() { |
| 1026 "use strict"; |
| 1027 function TheClass() { |
| 1028 } |
| 1029 assertThrows(function() { TheClass.caller; }, TypeError); |
| 1030 assertThrows(function() { TheClass.arguments; }, TypeError); |
| 1031 |
| 1032 // Strict functions must have writable prototype. |
| 1033 TheClass.prototype = { |
| 1034 func: function() { return "func_value"; }, |
| 1035 get accessor() { return "accessor_value"; }, |
| 1036 property: "property_value", |
| 1037 }; |
| 1038 |
| 1039 var o = new TheClass(); |
| 1040 assertEquals(o.func(), "func_value"); |
| 1041 assertEquals(o.accessor, "accessor_value"); |
| 1042 assertEquals(o.property, "property_value"); |
| 1043 })(); |
OLD | NEW |