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

Side by Side Diff: src/js/caterpillar.js

Issue 1642833002: Stubbed runtime and app.runtime in caterpillar.js. Resolves #8. (Closed) Base URL: git@github.com:chromium/caterpillar.git@master
Patch Set: Response to CR Created 4 years, 10 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
« no previous file with comments | « src/caterpillar.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 Google Inc. All Rights Reserved. 1 // Copyright 2015 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 /** 15 /**
16 * Common utilities and types for Caterpillar. 16 * Common utilities and types for Caterpillar.
17 * 17 *
18 * Must be included before any Caterpillar polyfills. 18 * Must be included before any Caterpillar polyfills.
19 */ 19 */
20 20
21 'use strict'; 21 'use strict';
22 22
23 // Set up a namespace if one doesn't already exist. 23 // Set up a namespace if one doesn't already exist.
24 if (!('chrome' in self)) 24 if (!('chrome' in self))
25 self.chrome = {}; 25 self.chrome = {};
26 26
27 if (!chrome.caterpillar) 27 if (!chrome.caterpillar)
28 chrome.caterpillar = {}; 28 chrome.caterpillar = {};
29 29
30 // We need the chrome.runtime namespace to store errors in.
31 if (!chrome.runtime)
32 chrome.runtime = { lastError: null };
33
34 // Stub out chrome.app.runtime.onLaunched.addListener. All Chrome Apps call this
35 // method to launch the main window. Stubbing it means that background scripts
36 // that launch the main window can be re-used elsewhere without causing script
37 // errors.
38 chrome.app = {
39 runtime: {
40 onLaunched: {
41 addListener: function() {},
42 }
43 }
44 };
45
30 (function() { 46 (function() {
31 47
32 /** 48 /**
33 * Sets an error message in lastError if chrome.runtime is loaded. 49 * Sets an error message in chrome.runtime.lastError.
34 * 50 *
35 * @param {string} message The error message to set. 51 * @param {string} message The error message to set.
36 *
37 * @throws Error with given message if runtime is not loaded, and a warning that
38 * runtime isn't loaded.
39 */ 52 */
40 chrome.caterpillar.setError = function(message) { 53 chrome.caterpillar.setError = function(message) {
41 if (!chrome.runtime) {
42 console.warn('chrome.runtime not found; runtime errors may not be caught.');
43 throw new Error(message);
44 }
45 chrome.runtime.lastError = { 'message': message }; 54 chrome.runtime.lastError = { 'message': message };
46 }; 55 };
47 56
48 }).call(this); 57 }).call(this);
OLDNEW
« no previous file with comments | « src/caterpillar.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698