| 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 CheckPillDescriptor(func, name) { |
| 982 |
| 983 function CheckPill(pill) { |
| 984 assertEquals("function", typeof pill); |
| 985 assertInstanceof(pill, Function); |
| 986 assertThrows(function() { pill.property = "value"; }, TypeError); |
| 987 assertThrows(pill, TypeError); |
| 988 assertEquals(pill.prototype, (function(){}).prototype); |
| 989 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); |
| 990 assertFalse(d.writable); |
| 991 assertFalse(d.configurable); |
| 992 assertFalse(d.enumerable); |
| 993 } |
| 994 |
| 995 var descriptor = Object.getOwnPropertyDescriptor(func, name); |
| 996 CheckPill(descriptor.get) |
| 997 CheckPill(descriptor.set); |
| 998 assertFalse(descriptor.enumerable); |
| 999 assertFalse(descriptor.configurable); |
| 1000 } |
| 1001 |
| 1002 |
| 1003 (function TestStrictFunctionPills() { |
| 1004 function strict() { |
| 1005 "use strict"; |
| 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); |
| 1017 |
| 1018 CheckPillDescriptor(strict, "caller"); |
| 1019 CheckPillDescriptor(strict, "arguments"); |
| 1020 CheckPillDescriptor(another, "caller"); |
| 1021 CheckPillDescriptor(another, "arguments"); |
| 1022 CheckPillDescriptor(third, "caller"); |
| 1023 CheckPillDescriptor(third, "arguments"); |
| 1024 })(); |
| 1025 |
| 1026 |
| 1027 (function TestStrictFunctionWritablePrototype() { |
| 1028 "use strict"; |
| 1029 function TheClass() { |
| 1030 } |
| 1031 assertThrows(function() { TheClass.caller; }, TypeError); |
| 1032 assertThrows(function() { TheClass.arguments; }, TypeError); |
| 1033 |
| 1034 // Strict functions must have writable prototype. |
| 1035 TheClass.prototype = { |
| 1036 func: function() { return "func_value"; }, |
| 1037 get accessor() { return "accessor_value"; }, |
| 1038 property: "property_value", |
| 1039 }; |
| 1040 |
| 1041 var o = new TheClass(); |
| 1042 assertEquals(o.func(), "func_value"); |
| 1043 assertEquals(o.accessor, "accessor_value"); |
| 1044 assertEquals(o.property, "property_value"); |
| 1045 })(); |
| 1046 |
| 1047 |
| 1048 (function TestStrictArgumentPills() { |
| 1049 function strict() { |
| 1050 "use strict"; |
| 1051 return arguments; |
| 1052 } |
| 1053 |
| 1054 var args = strict(); |
| 1055 CheckPillDescriptor(args, "caller"); |
| 1056 CheckPillDescriptor(args, "callee"); |
| 1057 |
| 1058 args = strict(17, "value", strict); |
| 1059 assertEquals(17, args[0]) |
| 1060 assertEquals("value", args[1]) |
| 1061 assertEquals(strict, args[2]); |
| 1062 CheckPillDescriptor(args, "caller"); |
| 1063 CheckPillDescriptor(args, "callee"); |
| 1064 |
| 1065 function outer() { |
| 1066 "use strict"; |
| 1067 function inner() { |
| 1068 return arguments; |
| 1069 } |
| 1070 return inner; |
| 1071 } |
| 1072 |
| 1073 var args = outer()(); |
| 1074 CheckPillDescriptor(args, "caller"); |
| 1075 CheckPillDescriptor(args, "callee"); |
| 1076 |
| 1077 args = outer()(17, "value", strict); |
| 1078 assertEquals(17, args[0]) |
| 1079 assertEquals("value", args[1]) |
| 1080 assertEquals(strict, args[2]); |
| 1081 CheckPillDescriptor(args, "caller"); |
| 1082 CheckPillDescriptor(args, "callee"); |
| 1083 })(); |
| OLD | NEW |