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

Side by Side Diff: test/mjsunit/es7/object-observe.js

Issue 265503002: Re-enable Object.observe and add enforcement for security invariants. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: cr comment Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/mjsunit/mjsunit.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 recordCreated = true; 106 recordCreated = true;
107 return "bar"; 107 return "bar";
108 }, 108 },
109 enumerable: true 109 enumerable: true
110 }) 110 })
111 111
112 112
113 // Object.observe 113 // Object.observe
114 assertThrows(function() { Object.observe("non-object", observer.callback); }, 114 assertThrows(function() { Object.observe("non-object", observer.callback); },
115 TypeError); 115 TypeError);
116 assertThrows(function() { Object.observe(this, observer.callback); },
117 TypeError);
116 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError); 118 assertThrows(function() { Object.observe(obj, nonFunction); }, TypeError);
117 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError); 119 assertThrows(function() { Object.observe(obj, frozenFunction); }, TypeError);
118 assertEquals(obj, Object.observe(obj, observer.callback, [1])); 120 assertEquals(obj, Object.observe(obj, observer.callback, [1]));
119 assertEquals(obj, Object.observe(obj, observer.callback, [true])); 121 assertEquals(obj, Object.observe(obj, observer.callback, [true]));
120 assertEquals(obj, Object.observe(obj, observer.callback, ['foo', null])); 122 assertEquals(obj, Object.observe(obj, observer.callback, ['foo', null]));
121 assertEquals(obj, Object.observe(obj, observer.callback, [undefined])); 123 assertEquals(obj, Object.observe(obj, observer.callback, [undefined]));
122 assertEquals(obj, Object.observe(obj, observer.callback, 124 assertEquals(obj, Object.observe(obj, observer.callback,
123 ['foo', 'bar', 'baz'])); 125 ['foo', 'bar', 'baz']));
124 assertEquals(obj, Object.observe(obj, observer.callback, [])); 126 assertEquals(obj, Object.observe(obj, observer.callback, []));
125 assertEquals(obj, Object.observe(obj, observer.callback, undefined)); 127 assertEquals(obj, Object.observe(obj, observer.callback, undefined));
126 assertEquals(obj, Object.observe(obj, observer.callback)); 128 assertEquals(obj, Object.observe(obj, observer.callback));
127 129
128 // Object.unobserve 130 // Object.unobserve
129 assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError); 131 assertThrows(function() { Object.unobserve(4, observer.callback); }, TypeError);
132 assertThrows(function() { Object.unobserve(this, observer.callback); },
133 TypeError);
130 assertThrows(function() { Object.unobserve(obj, nonFunction); }, TypeError); 134 assertThrows(function() { Object.unobserve(obj, nonFunction); }, TypeError);
131 assertEquals(obj, Object.unobserve(obj, observer.callback)); 135 assertEquals(obj, Object.unobserve(obj, observer.callback));
132 136
133 137
134 // Object.getNotifier 138 // Object.getNotifier
135 var notifier = Object.getNotifier(obj); 139 var notifier = Object.getNotifier(obj);
136 assertSame(notifier, Object.getNotifier(obj)); 140 assertSame(notifier, Object.getNotifier(obj));
137 assertEquals(null, Object.getNotifier(Object.freeze({}))); 141 assertEquals(null, Object.getNotifier(Object.freeze({})));
142 assertThrows(function() { Object.getNotifier(this) }, TypeError);
138 assertFalse(notifier.hasOwnProperty('notify')); 143 assertFalse(notifier.hasOwnProperty('notify'));
139 assertEquals([], Object.keys(notifier)); 144 assertEquals([], Object.keys(notifier));
140 var notifyDesc = Object.getOwnPropertyDescriptor(notifier.__proto__, 'notify'); 145 var notifyDesc = Object.getOwnPropertyDescriptor(notifier.__proto__, 'notify');
141 assertTrue(notifyDesc.configurable); 146 assertTrue(notifyDesc.configurable);
142 assertTrue(notifyDesc.writable); 147 assertTrue(notifyDesc.writable);
143 assertFalse(notifyDesc.enumerable); 148 assertFalse(notifyDesc.enumerable);
144 assertThrows(function() { notifier.notify({}); }, TypeError); 149 assertThrows(function() { notifier.notify({}); }, TypeError);
145 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError); 150 assertThrows(function() { notifier.notify({ type: 4 }); }, TypeError);
146 151
147 assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError) ; 152 assertThrows(function() { notifier.performChange(1, function(){}); }, TypeError) ;
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 observer.assertCallbackRecords([ 1072 observer.assertCallbackRecords([
1068 { object: obj, name: prop, type: "update", oldValue: 1 }, 1073 { object: obj, name: prop, type: "update", oldValue: 1 },
1069 { object: obj, name: prop, type: "update", oldValue: 4 }, 1074 { object: obj, name: prop, type: "update", oldValue: 4 },
1070 { object: obj, name: prop, type: "update", oldValue: 5 }, 1075 { object: obj, name: prop, type: "update", oldValue: 5 },
1071 { object: obj, name: prop, type: "update", oldValue: 6 }, 1076 { object: obj, name: prop, type: "update", oldValue: 6 },
1072 { object: obj, name: prop, type: "reconfigure" }, 1077 { object: obj, name: prop, type: "reconfigure" },
1073 ]); 1078 ]);
1074 Object.unobserve(obj, observer.callback); 1079 Object.unobserve(obj, observer.callback);
1075 } 1080 }
1076 1081
1082 // TODO(rafaelw) Enable when ES6 Proxies are implemented
1083 /*
1077 function createProxy(create, x) { 1084 function createProxy(create, x) {
1078 var handler = { 1085 var handler = {
1079 getPropertyDescriptor: function(k) { 1086 getPropertyDescriptor: function(k) {
1080 for (var o = this.target; o; o = Object.getPrototypeOf(o)) { 1087 for (var o = this.target; o; o = Object.getPrototypeOf(o)) {
1081 var desc = Object.getOwnPropertyDescriptor(o, k); 1088 var desc = Object.getOwnPropertyDescriptor(o, k);
1082 if (desc) return desc; 1089 if (desc) return desc;
1083 } 1090 }
1084 return undefined; 1091 return undefined;
1085 }, 1092 },
1086 getOwnPropertyDescriptor: function(k) { 1093 getOwnPropertyDescriptor: function(k) {
(...skipping 19 matching lines...) Expand all
1106 var got = changeRecords[i]; 1113 var got = changeRecords[i];
1107 var change = {object: handler.proxy, name: got.name, type: got.type}; 1114 var change = {object: handler.proxy, name: got.name, type: got.type};
1108 if ("oldValue" in got) change.oldValue = got.oldValue; 1115 if ("oldValue" in got) change.oldValue = got.oldValue;
1109 Object.getNotifier(handler.proxy).notify(change); 1116 Object.getNotifier(handler.proxy).notify(change);
1110 } 1117 }
1111 }, 1118 },
1112 }; 1119 };
1113 Object.observe(handler.target, handler.callback); 1120 Object.observe(handler.target, handler.callback);
1114 return handler.proxy = create(handler, x); 1121 return handler.proxy = create(handler, x);
1115 } 1122 }
1123 */
1116 1124
1117 var objects = [ 1125 var objects = [
1118 {}, 1126 {},
1119 [], 1127 [],
1120 this, // global object
1121 function(){}, 1128 function(){},
1122 (function(){ return arguments })(), 1129 (function(){ return arguments })(),
1123 (function(){ "use strict"; return arguments })(), 1130 (function(){ "use strict"; return arguments })(),
1124 Object(1), Object(true), Object("bla"), 1131 Object(1), Object(true), Object("bla"),
1125 new Date(), 1132 new Date(),
1126 Object, Function, Date, RegExp, 1133 Object, Function, Date, RegExp,
1127 new Set, new Map, new WeakMap, 1134 new Set, new Map, new WeakMap,
1128 new ArrayBuffer(10), new Int32Array(5), 1135 new ArrayBuffer(10), new Int32Array(5)
1129 createProxy(Proxy.create, null), 1136 // TODO(rafaelw) Enable when ES6 Proxies are implemented.
1130 createProxy(Proxy.createFunction, function(){}), 1137 // createProxy(Proxy.create, null),
1138 // createProxy(Proxy.createFunction, function(){}),
1131 ]; 1139 ];
1132 var properties = ["a", "1", 1, "length", "setPrototype", "name", "caller"]; 1140 var properties = ["a", "1", 1, "length", "setPrototype", "name", "caller"];
1133 1141
1134 // Cases that yield non-standard results. 1142 // Cases that yield non-standard results.
1135 function blacklisted(obj, prop) { 1143 function blacklisted(obj, prop) {
1136 return (obj instanceof Int32Array && prop == 1) || 1144 return (obj instanceof Int32Array && prop == 1) ||
1137 (obj instanceof Int32Array && prop === "length") || 1145 (obj instanceof Int32Array && prop === "length") ||
1138 (obj instanceof ArrayBuffer && prop == 1) 1146 (obj instanceof ArrayBuffer && prop == 1)
1139 } 1147 }
1140 1148
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 for (var n1 = 0; n1 < 3; ++n1) 1789 for (var n1 = 0; n1 < 3; ++n1)
1782 for (var n2 = 0; n2 < 3; ++n2) 1790 for (var n2 = 0; n2 < 3; ++n2)
1783 for (var i in mutation) 1791 for (var i in mutation)
1784 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); 1792 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2);
1785 1793
1786 for (var b1 = 0; b1 < 2; ++b1) 1794 for (var b1 = 0; b1 < 2; ++b1)
1787 for (var b2 = 0; b2 < 2; ++b2) 1795 for (var b2 = 0; b2 < 2; ++b2)
1788 for (var n = 0; n < 3; ++n) 1796 for (var n = 0; n < 3; ++n)
1789 for (var i in mutationByIncr) 1797 for (var i in mutationByIncr)
1790 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); 1798 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1);
OLDNEW
« no previous file with comments | « test/cctest/test-object-observe.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698