mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
7e20285e70
The -*- file variable lines -*- establish per-file settings that Emacs will pick up. This patch makes the following changes to those lines (and touches nothing else): - Never set the buffer's mode. Years ago, Emacs did not have a good JavaScript mode, so it made sense to use Java or C++ mode in .js files. However, Emacs has had js-mode for years now; it's perfectly serviceable, and is available and enabled by default in all major Emacs packagings. Selecting a mode in the -*- file variable line -*- is almost always the wrong thing to do anyway. It overrides Emacs's default choice, which is (now) reasonable; and even worse, it overrides settings the user might have made in their '.emacs' file for that file extension. It's only useful when there's something specific about that particular file that makes a particular mode appropriate. - Correctly propagate settings that establish the correct indentation level for this file: c-basic-offset and js2-basic-offset should be js-indent-level. Whatever value they're given should be preserved; different parts of our tree use different indentation styles. - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil. Remove tab-width: settings, at least in files that don't contain tab characters. - Remove js2-mode settings that belong in the user's .emacs file, like js2-skip-preprocessor-directives.
112 lines
3.2 KiB
JavaScript
112 lines
3.2 KiB
JavaScript
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// functions common to Identity.jsm and MinimalIdentity.jsm
|
|
|
|
"use strict";
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
|
"checkDeprecated",
|
|
"checkRenamed",
|
|
"getRandomId",
|
|
"objectCopy",
|
|
"makeMessageObject",
|
|
];
|
|
|
|
const Cu = Components.utils;
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
|
|
"@mozilla.org/uuid-generator;1",
|
|
"nsIUUIDGenerator");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Logger",
|
|
"resource://gre/modules/identity/LogUtils.jsm");
|
|
|
|
function log(...aMessageArgs) {
|
|
Logger.log.apply(Logger, ["Identity"].concat(aMessageArgs));
|
|
}
|
|
|
|
function defined(item) {
|
|
return typeof item !== 'undefined';
|
|
}
|
|
|
|
var checkDeprecated = this.checkDeprecated = function checkDeprecated(aOptions, aField) {
|
|
if (defined(aOptions[aField])) {
|
|
log("WARNING: field is deprecated:", aField);
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
this.checkRenamed = function checkRenamed(aOptions, aOldName, aNewName) {
|
|
if (defined(aOptions[aOldName]) &&
|
|
defined(aOptions[aNewName])) {
|
|
let err = "You cannot provide both " + aOldName + " and " + aNewName;
|
|
Logger.reportError(err);
|
|
throw new Error(err);
|
|
}
|
|
|
|
if (checkDeprecated(aOptions, aOldName)) {
|
|
aOptions[aNewName] = aOptions[aOldName];
|
|
delete(aOptions[aOldName]);
|
|
}
|
|
};
|
|
|
|
this.getRandomId = function getRandomId() {
|
|
return uuidgen.generateUUID().toString();
|
|
};
|
|
|
|
/*
|
|
* copy source object into target, excluding private properties
|
|
* (those whose names begin with an underscore)
|
|
*/
|
|
this.objectCopy = function objectCopy(source, target){
|
|
let desc;
|
|
Object.getOwnPropertyNames(source).forEach(function(name) {
|
|
if (name[0] !== '_') {
|
|
desc = Object.getOwnPropertyDescriptor(source, name);
|
|
Object.defineProperty(target, name, desc);
|
|
}
|
|
});
|
|
};
|
|
|
|
this.makeMessageObject = function makeMessageObject(aRpCaller) {
|
|
let options = {};
|
|
|
|
options.id = aRpCaller.id;
|
|
options.origin = aRpCaller.origin;
|
|
|
|
// Backwards compatibility with Persona beta:
|
|
// loggedInUser can be undefined, null, or a string
|
|
options.loggedInUser = aRpCaller.loggedInUser;
|
|
|
|
// Special flag for internal calls for Persona in b2g
|
|
options._internal = aRpCaller._internal;
|
|
|
|
Object.keys(aRpCaller).forEach(function(option) {
|
|
// Duplicate the callerobject, scrubbing out functions and other
|
|
// internal variables (like _mm, the message manager object)
|
|
if (!Object.hasOwnProperty(this, option)
|
|
&& option[0] !== '_'
|
|
&& typeof aRpCaller[option] !== 'function') {
|
|
options[option] = aRpCaller[option];
|
|
}
|
|
});
|
|
|
|
// check validity of message structure
|
|
if ((typeof options.id === 'undefined') ||
|
|
(typeof options.origin === 'undefined')) {
|
|
let err = "id and origin required in relying-party message: " + JSON.stringify(options);
|
|
reportError(err);
|
|
throw new Error(err);
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|