Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: test/mjsunit/strict-mode.js

Issue 1027283004: [es6] do not add caller/arguments to ES6 function definitions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/harmony/object-literals-method.js ('k') | test/test262-es6/test262-es6.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 a = "c"; 1003 a = "c";
1004 b = "d"; 1004 b = "d";
1005 return [a, b, arguments[0], arguments[1]]; 1005 return [a, b, arguments[0], arguments[1]];
1006 } 1006 }
1007 1007
1008 assertEquals(["c", "d", "a", "b"], strict("a", "b")); 1008 assertEquals(["c", "d", "a", "b"], strict("a", "b"));
1009 assertEquals(["c", "d", "c", "d"], nonstrict("a", "b")); 1009 assertEquals(["c", "d", "c", "d"], nonstrict("a", "b"));
1010 })(); 1010 })();
1011 1011
1012 1012
1013 function CheckPillDescriptor(func, name) { 1013 function CheckFunctionPillDescriptor(func, name) {
1014 1014
1015 function CheckPill(pill) { 1015 function CheckPill(pill) {
1016 assertEquals("function", typeof pill); 1016 assertEquals("function", typeof pill);
1017 assertInstanceof(pill, Function);
1018 pill.property = "value";
1019 assertEquals(pill.value, undefined);
1020 assertThrows(function() { 'use strict'; pill.property = "value"; },
1021 TypeError);
1022 assertThrows(pill, TypeError);
1023 assertEquals(pill.prototype, (function(){}).prototype);
1024 var d = Object.getOwnPropertyDescriptor(pill, "prototype");
1025 assertFalse(d.writable);
1026 assertFalse(d.configurable);
1027 assertFalse(d.enumerable);
1028 }
1029
1030 // Poisoned accessors are no longer own properties
1031 func = Object.getPrototypeOf(func);
1032 var descriptor = Object.getOwnPropertyDescriptor(func, name);
1033 CheckPill(descriptor.get)
1034 CheckPill(descriptor.set);
1035 assertFalse(descriptor.enumerable);
1036 // In ES6, restricted function properties are configurable
1037 assertTrue(descriptor.configurable);
1038 }
1039
1040
1041 function CheckArgumentsPillDescriptor(func, name) {
1042
1043 function CheckPill(pill) {
1044 assertEquals("function", typeof pill);
1017 assertInstanceof(pill, Function); 1045 assertInstanceof(pill, Function);
1018 pill.property = "value"; 1046 pill.property = "value";
1019 assertEquals(pill.value, undefined); 1047 assertEquals(pill.value, undefined);
1020 assertThrows(function() { 'use strict'; pill.property = "value"; }, 1048 assertThrows(function() { 'use strict'; pill.property = "value"; },
1021 TypeError); 1049 TypeError);
1022 assertThrows(pill, TypeError); 1050 assertThrows(pill, TypeError);
1023 assertEquals(pill.prototype, (function(){}).prototype); 1051 assertEquals(pill.prototype, (function(){}).prototype);
1024 var d = Object.getOwnPropertyDescriptor(pill, "prototype"); 1052 var d = Object.getOwnPropertyDescriptor(pill, "prototype");
1025 assertFalse(d.writable); 1053 assertFalse(d.writable);
1026 assertFalse(d.configurable); 1054 assertFalse(d.configurable);
(...skipping 22 matching lines...) Expand all
1049 assertThrows(function() { another.arguments; }, TypeError); 1077 assertThrows(function() { another.arguments; }, TypeError);
1050 assertThrows(function() { another.caller = 42; }, TypeError); 1078 assertThrows(function() { another.caller = 42; }, TypeError);
1051 assertThrows(function() { another.arguments = 42; }, TypeError); 1079 assertThrows(function() { another.arguments = 42; }, TypeError);
1052 1080
1053 var third = (function() { "use strict"; return function() {}; })(); 1081 var third = (function() { "use strict"; return function() {}; })();
1054 assertThrows(function() { third.caller; }, TypeError); 1082 assertThrows(function() { third.caller; }, TypeError);
1055 assertThrows(function() { third.arguments; }, TypeError); 1083 assertThrows(function() { third.arguments; }, TypeError);
1056 assertThrows(function() { third.caller = 42; }, TypeError); 1084 assertThrows(function() { third.caller = 42; }, TypeError);
1057 assertThrows(function() { third.arguments = 42; }, TypeError); 1085 assertThrows(function() { third.arguments = 42; }, TypeError);
1058 1086
1059 CheckPillDescriptor(strict, "caller"); 1087 CheckFunctionPillDescriptor(strict, "caller");
1060 CheckPillDescriptor(strict, "arguments"); 1088 CheckFunctionPillDescriptor(strict, "arguments");
1061 CheckPillDescriptor(another, "caller"); 1089 CheckFunctionPillDescriptor(another, "caller");
1062 CheckPillDescriptor(another, "arguments"); 1090 CheckFunctionPillDescriptor(another, "arguments");
1063 CheckPillDescriptor(third, "caller"); 1091 CheckFunctionPillDescriptor(third, "caller");
1064 CheckPillDescriptor(third, "arguments"); 1092 CheckFunctionPillDescriptor(third, "arguments");
1065 })(); 1093 })();
1066 1094
1067 1095
1068 (function TestStrictFunctionWritablePrototype() { 1096 (function TestStrictFunctionWritablePrototype() {
1069 "use strict"; 1097 "use strict";
1070 function TheClass() { 1098 function TheClass() {
1071 } 1099 }
1072 assertThrows(function() { TheClass.caller; }, TypeError); 1100 assertThrows(function() { TheClass.caller; }, TypeError);
1073 assertThrows(function() { TheClass.arguments; }, TypeError); 1101 assertThrows(function() { TheClass.arguments; }, TypeError);
1074 1102
(...skipping 11 matching lines...) Expand all
1086 })(); 1114 })();
1087 1115
1088 1116
1089 (function TestStrictArgumentPills() { 1117 (function TestStrictArgumentPills() {
1090 function strict() { 1118 function strict() {
1091 "use strict"; 1119 "use strict";
1092 return arguments; 1120 return arguments;
1093 } 1121 }
1094 1122
1095 var args = strict(); 1123 var args = strict();
1096 CheckPillDescriptor(args, "caller"); 1124 CheckArgumentsPillDescriptor(args, "caller");
1097 CheckPillDescriptor(args, "callee"); 1125 CheckArgumentsPillDescriptor(args, "callee");
1098 1126
1099 args = strict(17, "value", strict); 1127 args = strict(17, "value", strict);
1100 assertEquals(17, args[0]) 1128 assertEquals(17, args[0])
1101 assertEquals("value", args[1]) 1129 assertEquals("value", args[1])
1102 assertEquals(strict, args[2]); 1130 assertEquals(strict, args[2]);
1103 CheckPillDescriptor(args, "caller"); 1131 CheckArgumentsPillDescriptor(args, "caller");
1104 CheckPillDescriptor(args, "callee"); 1132 CheckArgumentsPillDescriptor(args, "callee");
1105 1133
1106 function outer() { 1134 function outer() {
1107 "use strict"; 1135 "use strict";
1108 function inner() { 1136 function inner() {
1109 return arguments; 1137 return arguments;
1110 } 1138 }
1111 return inner; 1139 return inner;
1112 } 1140 }
1113 1141
1114 var args = outer()(); 1142 var args = outer()();
1115 CheckPillDescriptor(args, "caller"); 1143 CheckArgumentsPillDescriptor(args, "caller");
1116 CheckPillDescriptor(args, "callee"); 1144 CheckArgumentsPillDescriptor(args, "callee");
1117 1145
1118 args = outer()(17, "value", strict); 1146 args = outer()(17, "value", strict);
1119 assertEquals(17, args[0]) 1147 assertEquals(17, args[0])
1120 assertEquals("value", args[1]) 1148 assertEquals("value", args[1])
1121 assertEquals(strict, args[2]); 1149 assertEquals(strict, args[2]);
1122 CheckPillDescriptor(args, "caller"); 1150 CheckArgumentsPillDescriptor(args, "caller");
1123 CheckPillDescriptor(args, "callee"); 1151 CheckArgumentsPillDescriptor(args, "callee");
1124 })(); 1152 })();
1125 1153
1126 1154
1127 (function TestNonStrictFunctionCallerPillSimple() { 1155 (function TestNonStrictFunctionCallerPillSimple() {
1128 function return_my_caller() { 1156 function return_my_caller() {
1129 return return_my_caller.caller; 1157 return return_my_caller.caller;
1130 } 1158 }
1131 1159
1132 function strict() { 1160 function strict() {
1133 "use strict"; 1161 "use strict";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 assertSame(null, test(i)); 1226 assertSame(null, test(i));
1199 } 1227 }
1200 })(); 1228 })();
1201 1229
1202 1230
1203 (function TestStrictModeEval() { 1231 (function TestStrictModeEval() {
1204 "use strict"; 1232 "use strict";
1205 eval("var eval_local = 10;"); 1233 eval("var eval_local = 10;");
1206 assertThrows(function() { return eval_local; }, ReferenceError); 1234 assertThrows(function() { return eval_local; }, ReferenceError);
1207 })(); 1235 })();
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/object-literals-method.js ('k') | test/test262-es6/test262-es6.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698