Move JavaScript to root lib/ folder

This commit is contained in:
Kevin Sawicki 2016-03-07 17:12:09 -08:00
parent a9c40de393
commit 70aa9b06ee
56 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,66 @@
'use strict';
var slice = [].slice;
const v8Util = process.atomBinding('v8_util');
class CallbacksRegistry {
constructor() {
this.nextId = 0;
this.callbacks = {};
}
add(callback) {
// The callback is already added.
var filenameAndLine, id, location, match, ref, regexp, stackString;
id = v8Util.getHiddenValue(callback, 'callbackId');
if (id != null) {
return id;
}
id = ++this.nextId;
// Capture the location of the function and put it in the ID string,
// so that release errors can be tracked down easily.
regexp = /at (.*)/gi;
stackString = (new Error).stack;
while ((match = regexp.exec(stackString)) !== null) {
location = match[1];
if (location.indexOf('(native)') !== -1) {
continue;
}
if (location.indexOf('atom.asar') !== -1) {
continue;
}
ref = /([^\/^\)]*)\)?$/gi.exec(location);
filenameAndLine = ref[1];
break;
}
this.callbacks[id] = callback;
v8Util.setHiddenValue(callback, 'callbackId', id);
v8Util.setHiddenValue(callback, 'location', filenameAndLine);
return id;
}
get(id) {
var ref;
return (ref = this.callbacks[id]) != null ? ref : function() {};
}
call() {
var args, id, ref;
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
return (ref = this.get(id)).call.apply(ref, [global].concat(slice.call(args)));
}
apply() {
var args, id, ref;
id = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
return (ref = this.get(id)).apply.apply(ref, [global].concat(slice.call(args)));
}
remove(id) {
return delete this.callbacks[id];
}
}
module.exports = CallbacksRegistry;

View file

@ -0,0 +1,6 @@
if (process.platform === 'linux' && process.type === 'renderer') {
// On Linux we could not access clipboard in renderer process.
module.exports = require('electron').remote.clipboard;
} else {
module.exports = process.atomBinding('clipboard');
}

View file

@ -0,0 +1,94 @@
const os = require('os');
const path = require('path');
const spawn = require('child_process').spawn;
const electron = require('electron');
const binding = process.atomBinding('crash_reporter');
var CrashReporter = (function() {
function CrashReporter() {}
CrashReporter.prototype.start = function(options) {
var app, args, autoSubmit, companyName, deprecate, env, extra, ignoreSystemCrashHandler, start, submitURL;
if (options == null) {
options = {};
}
this.productName = options.productName, companyName = options.companyName, submitURL = options.submitURL, autoSubmit = options.autoSubmit, ignoreSystemCrashHandler = options.ignoreSystemCrashHandler, extra = options.extra;
// Deprecated.
deprecate = electron.deprecate;
if (options.submitUrl) {
if (submitURL == null) {
submitURL = options.submitUrl;
}
deprecate.warn('submitUrl', 'submitURL');
}
app = (process.type === 'browser' ? electron : electron.remote).app;
if (this.productName == null) {
this.productName = app.getName();
}
if (autoSubmit == null) {
autoSubmit = true;
}
if (ignoreSystemCrashHandler == null) {
ignoreSystemCrashHandler = false;
}
if (extra == null) {
extra = {};
}
if (extra._productName == null) {
extra._productName = this.productName;
}
if (extra._companyName == null) {
extra._companyName = companyName;
}
if (extra._version == null) {
extra._version = app.getVersion();
}
if (companyName == null) {
deprecate.log('companyName is now a required option to crashReporter.start');
return;
}
if (submitURL == null) {
deprecate.log('submitURL is now a required option to crashReporter.start');
return;
}
start = (function(_this) {
return function() {
return binding.start(_this.productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra);
};
})(this);
if (process.platform === 'win32') {
args = ["--reporter-url=" + submitURL, "--application-name=" + this.productName, "--v=1"];
env = {
ATOM_SHELL_INTERNAL_CRASH_SERVICE: 1
};
spawn(process.execPath, args, {
env: env,
detached: true
});
}
return start();
};
CrashReporter.prototype.getLastCrashReport = function() {
var reports;
reports = this.getUploadedReports();
if (reports.length > 0) {
return reports[0];
} else {
return null;
}
};
CrashReporter.prototype.getUploadedReports = function() {
var log, tmpdir;
tmpdir = process.platform === 'win32' ? os.tmpdir() : '/tmp';
log = process.platform === 'darwin' ? path.join(tmpdir, this.productName + " Crashes") : path.join(tmpdir, this.productName + " Crashes", 'uploads.log');
return binding._getUploadedReports(log);
};
return CrashReporter;
})();
module.exports = new CrashReporter;

114
lib/common/api/deprecate.js Normal file
View file

@ -0,0 +1,114 @@
// Deprecate a method.
var deprecate,
slice = [].slice;
deprecate = function(oldName, newName, fn) {
var warned;
warned = false;
return function() {
if (!(warned || process.noDeprecation)) {
warned = true;
deprecate.warn(oldName, newName);
}
return fn.apply(this, arguments);
};
};
// The method is renamed.
deprecate.rename = function(object, oldName, newName) {
var newMethod, warned;
warned = false;
newMethod = function() {
if (!(warned || process.noDeprecation)) {
warned = true;
deprecate.warn(oldName, newName);
}
return this[newName].apply(this, arguments);
};
if (typeof object === 'function') {
return object.prototype[oldName] = newMethod;
} else {
return object[oldName] = newMethod;
}
};
// Forward the method to member.
deprecate.member = function(object, method, member) {
var warned;
warned = false;
return object.prototype[method] = function() {
if (!(warned || process.noDeprecation)) {
warned = true;
deprecate.warn(method, member + "." + method);
}
return this[member][method].apply(this[member], arguments);
};
};
// Deprecate a property.
deprecate.property = function(object, property, method) {
return Object.defineProperty(object, property, {
get: function() {
var warned;
warned = false;
if (!(warned || process.noDeprecation)) {
warned = true;
deprecate.warn(property + " property", method + " method");
}
return this[method]();
}
});
};
// Deprecate an event.
deprecate.event = function(emitter, oldName, newName, fn) {
var warned;
warned = false;
return emitter.on(newName, function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
// there is listeners for old API.
if (this.listenerCount(oldName) > 0) {
if (!(warned || process.noDeprecation)) {
warned = true;
deprecate.warn("'" + oldName + "' event", "'" + newName + "' event");
}
if (fn != null) {
return fn.apply(this, arguments);
} else {
return this.emit.apply(this, [oldName].concat(slice.call(args)));
}
}
});
};
// Print deprecation warning.
deprecate.warn = function(oldName, newName) {
return deprecate.log(oldName + " is deprecated. Use " + newName + " instead.");
};
var deprecationHandler = null;
// Print deprecation message.
deprecate.log = function(message) {
if (typeof deprecationHandler === 'function') {
deprecationHandler(message);
} else if (process.throwDeprecation) {
throw new Error(message);
} else if (process.traceDeprecation) {
return console.trace(message);
} else {
return console.warn("(electron) " + message);
}
};
deprecate.setHandler = function(handler) {
deprecationHandler = handler;
};
deprecate.getHandler = function() {
return deprecationHandler;
};
module.exports = deprecate;

View file

@ -0,0 +1,11 @@
'use strict';
const deprecate = require('electron').deprecate;
exports.setHandler = function (deprecationHandler) {
deprecate.setHandler(deprecationHandler);
};
exports.getHandler = function () {
return deprecate.getHandler();
};

View file

@ -0,0 +1,65 @@
// Do not expose the internal modules to `require`.
const hideInternalModules = function() {
var globalPaths = require('module').globalPaths;
if (globalPaths.length === 3) {
// Remove the "common/api/lib" and "browser-or-renderer/api/lib".
return globalPaths.splice(0, 2);
}
};
// Attaches properties to |exports|.
exports.defineProperties = function(exports) {
return Object.defineProperties(exports, {
hideInternalModules: {
enumerable: true,
value: hideInternalModules
},
// Common modules, please sort with alphabet order.
clipboard: {
// Must be enumerable, otherwise it woulde be invisible to remote module.
enumerable: true,
get: function() {
return require('../clipboard');
}
},
crashReporter: {
enumerable: true,
get: function() {
return require('../crash-reporter');
}
},
deprecations: {
enumerable: true,
get: function() {
return require('../deprecations');
}
},
nativeImage: {
enumerable: true,
get: function() {
return require('../native-image');
}
},
shell: {
enumerable: true,
get: function() {
return require('../shell');
}
},
// The internal modules, invisible unless you know their names.
CallbacksRegistry: {
get: function() {
return require('../callbacks-registry');
}
},
deprecate: {
get: function() {
return require('../deprecate');
}
}
});
};

View file

@ -0,0 +1,7 @@
const deprecate = require('electron').deprecate;
const nativeImage = process.atomBinding('native_image');
// Deprecated.
deprecate.rename(nativeImage, 'createFromDataUrl', 'createFromDataURL');
module.exports = nativeImage;

1
lib/common/api/shell.js Normal file
View file

@ -0,0 +1 @@
module.exports = process.atomBinding('shell');