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

Unified 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: Handled first round of comments 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/js/structured-clone.html
diff --git a/LayoutTests/fast/js/structured-clone.html b/LayoutTests/fast/js/structured-clone.html
index 6cd9c365878d5340ae30ced8ce4297c7a39f3dde..1263325deed2080c062d39a6d030589018da781c 100644
--- a/LayoutTests/fast/js/structured-clone.html
+++ b/LayoutTests/fast/js/structured-clone.html
@@ -119,4 +119,70 @@ promise_test(function() {
});
}, 'Verify: "Add a new property..." (dense arrays)');
+promise_test(function() {
+ var orig = {
+ emptySet: new Set,
+ set: new Set([1, 2, 3]),
+ emptyMap: new Map,
+ map: new Map([[1, 2], [3, 4]]),
+ };
+ return structuredClone(orig).then(function(clone) {
+ assert_true(clone.emptySet instanceof Set, 'Clone should be a Set');
+ assert_true(clone.emptyMap instanceof Map, 'Clone should be a Map');
+ assert_true(clone.set instanceof Set, 'Clone should be a Set');
+ assert_true(clone.map instanceof Map, 'Clone should be a Map');
+ assert_equals(clone.emptySet.size, 0, 'Clone should be the same size');
+ assert_equals(clone.emptyMap.size, 0, 'Clone should be the same size');
+ assert_equals(clone.set.size, orig.set.size, 'Clone should be the same size');
+ assert_equals(clone.map.size, orig.map.size, 'Clone should be the same size');
+ assert_true(clone.set.has(1) && clone.set.has(2) && clone.set.has(3), 'Cloned set should have the same keys');
+ assert_true(clone.map.get(1) == 2 && clone.map.get(3) == 4, 'Cloned map should have the same keys and values');
+ });
+}, 'Maps and Sets are cloned');
+
+promise_test(function() {
+ var set = new Set;
+ set.add(set);
+ var map = new Map;
+ map.set(map, map);
+ var orig = { map: map, set: set };
+ return structuredClone(orig).then(function(clone) {
+ assert_true(clone.set instanceof Set, 'Clone should be a Set');
+ assert_true(clone.map instanceof Map, 'Clone should be a Map');
+ assert_equals(clone.set, Array.from(clone.set)[0], 'Recursive sets should preserve identity');
+ assert_equals(clone.map, Array.from(clone.map)[0][0], 'Recursive maps should preserve identity');
+ assert_equals(clone.map, Array.from(clone.map)[0][1], 'Recursive maps should preserve identity');
+ });
+}, 'Cloning Maps and Sets preserve cycles');
+
+promise_test(function() {
+ var set = new Set;
+ var map = new Map;
+ var setMutator = {
+ get val() {
+ set.add('mutated');
+ return 'setMutator';
+ }
+ }
+ var mapMutator = {
+ get val() {
+ map.set('mutated', true);
+ return 'mapMutator';
+ }
+ }
+ set.add(setMutator);
+ map.set('mapMutator', mapMutator);
+ var orig = { map: map, set: set };
+ return structuredClone(orig).then(function(clone) {
+ assert_true(clone.set instanceof Set, 'Clone should be a Set');
+ assert_true(clone.map instanceof Map, 'Clone should be a Map');
+ assert_equals(orig.set.size, 2, 'Original set should have been mutated');
+ assert_equals(orig.map.size, 2, 'Original map should have been mutated');
+ assert_equals(clone.set.size, 1, 'Cloned set should not reflect mutation');
+ assert_equals(clone.map.size, 1, 'Cloned map should not reflect mutation');
+ assert_equals(Array.from(clone.set)[0].val, 'setMutator', 'Cloned set should contain getter return value');
+ assert_equals(clone.map.get('mapMutator').val, 'mapMutator', 'Cloned map should contain getter return value');
+ });
+}, 'Cloned Maps and Sets do not reflect mutations that occur during cloning');
+
</script>
« no previous file with comments | « no previous file | Source/bindings/core/v8/ScriptValueSerializer.h » ('j') | Source/bindings/core/v8/ScriptValueSerializer.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698