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

Side by Side Diff: gin/test/expect.js

Issue 654843005: Mojo JS Bindings: add support for associative arrays (Mojo map type) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected validation for array map values Created 6 years, 2 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define(function() { 5 define(function() {
6 // Equality function based on isEqual in 6 // Equality function based on isEqual in
7 // Underscore.js 1.5.2 7 // Underscore.js 1.5.2
8 // http://underscorejs.org 8 // http://underscorejs.org
9 // (c) 2009-2013 Jeremy Ashkenas, 9 // (c) 2009-2013 Jeremy Ashkenas,
10 // DocumentCloud, 10 // DocumentCloud,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 var aCtor = a.constructor, bCtor = b.constructor; 75 var aCtor = a.constructor, bCtor = b.constructor;
76 if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) && 76 if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) &&
77 isFunction(bCtor) && (bCtor instanceof bCtor)) 77 isFunction(bCtor) && (bCtor instanceof bCtor))
78 && ('constructor' in a && 'constructor' in b)) { 78 && ('constructor' in a && 'constructor' in b)) {
79 return false; 79 return false;
80 } 80 }
81 // Add the first object to the stack of traversed objects. 81 // Add the first object to the stack of traversed objects.
82 aStack.push(a); 82 aStack.push(a);
83 bStack.push(b); 83 bStack.push(b);
84 var size = 0, result = true; 84 var size = 0, result = true;
85 // Recursively compare objects and arrays. 85 // Recursively compare Maps, objects and arrays.
86 if (className == '[object Array]' || isArrayBufferClass(className)) { 86 if (className == '[object Array]' || isArrayBufferClass(className)) {
87 // Compare array lengths to determine if a deep comparison is necessary. 87 // Compare array lengths to determine if a deep comparison is necessary.
88 size = a.length; 88 size = a.length;
89 result = size == b.length; 89 result = size == b.length;
90 if (result) { 90 if (result) {
91 // Deep compare the contents, ignoring non-numeric properties. 91 // Deep compare the contents, ignoring non-numeric properties.
92 while (size--) { 92 while (size--) {
93 if (!(result = eq(a[size], b[size], aStack, bStack))) 93 if (!(result = eq(a[size], b[size], aStack, bStack)))
94 break; 94 break;
95 } 95 }
96 } 96 }
97 } else if (className == '[object Map]') {
98 result = a.size == b.size;
99 if (result) {
100 var entries = a.entries();
101 for (var e = entries.next(); result && !e.done; e = entries.next()) {
102 var key = e.value[0];
103 var value = e.value[1];
104 result = b.has(key) && eq(value, b.get(key), aStack, bStack);
105 }
106 }
97 } else { 107 } else {
98 // Deep compare objects. 108 // Deep compare objects.
99 for (var key in a) { 109 for (var key in a) {
100 if (has(a, key)) { 110 if (has(a, key)) {
101 // Count the expected number of properties. 111 // Count the expected number of properties.
102 size++; 112 size++;
103 // Deep compare each member. 113 // Deep compare each member.
104 if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack))) 114 if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack)))
105 break; 115 break;
106 } 116 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 var bound = predicates[name].bind(null, actual); 290 var bound = predicates[name].bind(null, actual);
281 this[name] = check(bound); 291 this[name] = check(bound);
282 this.not[name] = check(negate(bound)); 292 this.not[name] = check(negate(bound));
283 }, this); 293 }, this);
284 } 294 }
285 295
286 return function(actual) { 296 return function(actual) {
287 return new Condition(actual); 297 return new Condition(actual);
288 }; 298 };
289 }); 299 });
OLDNEW
« no previous file with comments | « no previous file | mojo/public/html/convert_amd_modules_to_html.py » ('j') | mojo/public/js/bindings/struct_unittests.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698