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

Side by Side Diff: LayoutTests/fast/js/structured-clone.html

Issue 1205973002: Support structured cloning of ES'15 Map and Set (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add new test for Map/Set serialization format Created 5 years, 6 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 | « no previous file | LayoutTests/fast/storage/resources/serialized-script-value.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE HTML> 1 <!DOCTYPE HTML>
2 <script src="../../resources/testharness.js"></script> 2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script> 3 <script src="../../resources/testharnessreport.js"></script>
4 <script> 4 <script>
5 function promise_test(func, name, properties) { 5 function promise_test(func, name, properties) {
6 properties = properties || {}; 6 properties = properties || {};
7 var test = async_test(name, properties); 7 var test = async_test(name, properties);
8 Promise.resolve(test.step(func, test, test)) 8 Promise.resolve(test.step(func, test, test))
9 .then(function() { test.done(); }) 9 .then(function() { test.done(); })
10 .catch(test.step_func(function(value) { throw value; })); 10 .catch(test.step_func(function(value) { throw value; }));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 assert_true(orig.hasOwnProperty(name)); 112 assert_true(orig.hasOwnProperty(name));
113 113
114 return structuredClone(orig).then(function(clone) { 114 return structuredClone(orig).then(function(clone) {
115 assert_true(Array.isArray(clone), 'Clone should be an Array'); 115 assert_true(Array.isArray(clone), 'Clone should be an Array');
116 assert_false(setter_called, 'Setter should not be called by cloning algo rithm.'); 116 assert_false(setter_called, 'Setter should not be called by cloning algo rithm.');
117 assert_true(clone.hasOwnProperty(name), 'Cloning algorithm should add an own property.') 117 assert_true(clone.hasOwnProperty(name), 'Cloning algorithm should add an own property.')
118 assert_equals(clone[name], orig[name], 'Property value should match'); 118 assert_equals(clone[name], orig[name], 'Property value should match');
119 }); 119 });
120 }, 'Verify: "Add a new property..." (dense arrays)'); 120 }, 'Verify: "Add a new property..." (dense arrays)');
121 121
122 promise_test(function() {
123 var orig = {
124 emptySet: new Set,
125 set: new Set([1, 2, 3]),
126 emptyMap: new Map,
127 map: new Map([[1, 2], [3, 4]]),
128 };
129 return structuredClone(orig).then(function(clone) {
130 assert_true(clone.emptySet instanceof Set, 'Clone should be a Set');
131 assert_true(clone.emptyMap instanceof Map, 'Clone should be a Map');
132 assert_true(clone.set instanceof Set, 'Clone should be a Set');
133 assert_true(clone.map instanceof Map, 'Clone should be a Map');
134 assert_equals(clone.emptySet.size, 0, 'Clone should be the same size');
135 assert_equals(clone.emptyMap.size, 0, 'Clone should be the same size');
136 assert_equals(clone.set.size, orig.set.size, 'Clone should be the same s ize');
137 assert_equals(clone.map.size, orig.map.size, 'Clone should be the same s ize');
138 assert_true(clone.set.has(1) && clone.set.has(2) && clone.set.has(3), 'C loned set should have the same keys');
139 assert_true(clone.map.get(1) == 2 && clone.map.get(3) == 4, 'Cloned map should have the same keys and values');
140 });
141 }, 'Maps and Sets are cloned');
142
143 promise_test(function() {
144 var set = new Set;
145 set.add(set);
146 var map = new Map;
147 map.set(map, map);
148 var orig = { map: map, set: set };
149 return structuredClone(orig).then(function(clone) {
150 assert_true(clone.set instanceof Set, 'Clone should be a Set');
151 assert_true(clone.map instanceof Map, 'Clone should be a Map');
152 assert_equals(clone.set, Array.from(clone.set)[0], 'Recursive sets shoul d preserve identity');
153 assert_equals(clone.map, Array.from(clone.map)[0][0], 'Recursive maps sh ould preserve identity');
154 assert_equals(clone.map, Array.from(clone.map)[0][1], 'Recursive maps sh ould preserve identity');
155 });
156 }, 'Cloning Maps and Sets preserve cycles');
157
158 promise_test(function() {
159 var set = new Set;
160 var map = new Map;
161 var setMutator = {
162 get val() {
163 set.add('mutated');
164 return 'setMutator';
165 }
166 }
167 var mapMutator = {
168 get val() {
169 map.set('mutated', true);
170 return 'mapMutator';
171 }
172 }
173 set.add(setMutator);
174 map.set('mapMutator', mapMutator);
175 var orig = { map: map, set: set };
176 return structuredClone(orig).then(function(clone) {
177 assert_true(clone.set instanceof Set, 'Clone should be a Set');
178 assert_true(clone.map instanceof Map, 'Clone should be a Map');
179 assert_equals(orig.set.size, 2, 'Original set should have been mutated') ;
180 assert_equals(orig.map.size, 2, 'Original map should have been mutated') ;
181 assert_equals(clone.set.size, 1, 'Cloned set should not reflect mutation ');
182 assert_equals(clone.map.size, 1, 'Cloned map should not reflect mutation ');
183 assert_equals(Array.from(clone.set)[0].val, 'setMutator', 'Cloned set sh ould contain getter return value');
184 assert_equals(clone.map.get('mapMutator').val, 'mapMutator', 'Cloned map should contain getter return value');
185 });
186 }, 'Cloned Maps and Sets do not reflect mutations that occur during cloning');
187
188 promise_test(function() {
189 var map = new Map([['key', function(){}]]);
190 return structuredClone(map).then(function(clone) {
191 assert_unreached('Should have thrown an exception');
192 }).catch(function(ex) {
193 assert_true(ex instanceof DOMException, 'Should throw a DOMException');
194 assert_equals(ex.code, DOMException.DATA_CLONE_ERR, 'Should be a DataClo neError');
195 });
196 }, 'Cloning Maps should fail if they contain non-cloneable things');
197
198 promise_test(function() {
199 var set = new Set([function(){}]);
200 return structuredClone(set).then(function(clone) {
201 assert_unreached('Should have thrown an exception');
202 }).catch(function(ex) {
203 assert_true(ex instanceof DOMException, 'Should throw a DOMException');
204 assert_equals(ex.code, DOMException.DATA_CLONE_ERR, 'Should be a DataClo neError');
205 });
206 }, 'Cloning Sets should fail if they contain non-cloneable things');
207
122 </script> 208 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/storage/resources/serialized-script-value.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698