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

Side by Side Diff: third_party/WebKit/LayoutTests/resources/mojo-helpers.js

Issue 2642873002: Moves mojo.define -> gin.define. (Closed)
Patch Set: rebaseline Created 3 years, 11 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 /* 1 /*
2 * mojo-helpers contains extensions to testharness.js useful for consuming 2 * mojo-helpers contains extensions to testharness.js useful for consuming
3 * and mocking Mojo services directly within test code. 3 * and mocking Mojo services directly within test code.
4 */ 4 */
5 'use strict'; 5 'use strict';
6 6
7 // Fix up the global window.define, since all baked-in Mojo modules expect to 7 // Fix up the global window.define, since all baked-in Mojo modules expect to
8 // find it there. This define() also returns a promise to the module. 8 // find it there. This define() also returns a promise to the module.
9 let define = (function(){ 9 let define = (function(){
10 let moduleCache = new Map(); 10 let moduleCache = new Map();
11 11
12 return function(name, deps, factory) { 12 return function(name, deps, factory) {
13 let promise = moduleCache.get(name); 13 let promise = moduleCache.get(name);
14 if (promise === undefined) { 14 if (promise === undefined) {
15 // This promise must be cached as mojo.define will only call the factory 15 // This promise must be cached as gin.define will only call the factory
16 // function the first time the module is defined. 16 // function the first time the module is defined.
17 promise = new Promise(resolve => { 17 promise = new Promise(resolve => {
18 mojo.define(name, deps, (...modules) => { 18 gin.define(name, deps, (...modules) => {
19 let result = factory(...modules); 19 let result = factory(...modules);
20 resolve(result); 20 resolve(result);
21 return result; 21 return result;
22 }); 22 });
23 }); 23 });
24 moduleCache.set(name, promise); 24 moduleCache.set(name, promise);
25 } 25 }
26 return promise; 26 return promise;
27 } 27 }
28 })(); 28 })();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 let buffer, handles; 88 let buffer, handles;
89 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0)); 89 ({ result, buffer, handles } = mojo.core.readMessage(pipe, 0));
90 if (result !== mojo.core.RESULT_OK) { 90 if (result !== mojo.core.RESULT_OK) {
91 reject(result); 91 reject(result);
92 return; 92 return;
93 } 93 }
94 resolve({ buffer, handles }); 94 resolve({ buffer, handles });
95 }); 95 });
96 }); 96 });
97 }; 97 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698