Convert all source files to JavaScript
This commit is contained in:
parent
403870a27e
commit
1f9691ae13
144 changed files with 11211 additions and 7301 deletions
|
@ -1,45 +0,0 @@
|
|||
v8Util = process.atomBinding 'v8_util'
|
||||
|
||||
module.exports =
|
||||
class CallbacksRegistry
|
||||
constructor: ->
|
||||
@nextId = 0
|
||||
@callbacks = {}
|
||||
|
||||
add: (callback) ->
|
||||
### The callback is already added. ###
|
||||
id = v8Util.getHiddenValue callback, 'callbackId'
|
||||
return id if id?
|
||||
|
||||
id = ++@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)) isnt null
|
||||
[x, location] = match
|
||||
continue if location.indexOf('(native)') isnt -1
|
||||
continue if location.indexOf('atom.asar') isnt -1
|
||||
[x, filenameAndLine] = /([^/^\)]*)\)?$/gi.exec(location)
|
||||
break
|
||||
|
||||
@callbacks[id] = callback
|
||||
v8Util.setHiddenValue callback, 'callbackId', id
|
||||
v8Util.setHiddenValue callback, 'location', filenameAndLine
|
||||
id
|
||||
|
||||
get: (id) ->
|
||||
@callbacks[id] ? ->
|
||||
|
||||
call: (id, args...) ->
|
||||
@get(id).call global, args...
|
||||
|
||||
apply: (id, args...) ->
|
||||
@get(id).apply global, args...
|
||||
|
||||
remove: (id) ->
|
||||
delete @callbacks[id]
|
68
atom/common/api/lib/callbacks-registry.js
Normal file
68
atom/common/api/lib/callbacks-registry.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
var CallbacksRegistry, v8Util,
|
||||
slice = [].slice;
|
||||
|
||||
v8Util = process.atomBinding('v8_util');
|
||||
|
||||
module.exports = CallbacksRegistry = (function() {
|
||||
function CallbacksRegistry() {
|
||||
this.nextId = 0;
|
||||
this.callbacks = {};
|
||||
}
|
||||
|
||||
CallbacksRegistry.prototype.add = function(callback) {
|
||||
|
||||
/* The callback is already added. */
|
||||
var filenameAndLine, id, location, match, ref, regexp, stackString, x;
|
||||
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) {
|
||||
x = match[0], location = match[1];
|
||||
if (location.indexOf('(native)') !== -1) {
|
||||
continue;
|
||||
}
|
||||
if (location.indexOf('atom.asar') !== -1) {
|
||||
continue;
|
||||
}
|
||||
ref = /([^\/^\)]*)\)?$/gi.exec(location), x = ref[0], filenameAndLine = ref[1];
|
||||
break;
|
||||
}
|
||||
this.callbacks[id] = callback;
|
||||
v8Util.setHiddenValue(callback, 'callbackId', id);
|
||||
v8Util.setHiddenValue(callback, 'location', filenameAndLine);
|
||||
return id;
|
||||
};
|
||||
|
||||
CallbacksRegistry.prototype.get = function(id) {
|
||||
var ref;
|
||||
return (ref = this.callbacks[id]) != null ? ref : function() {};
|
||||
};
|
||||
|
||||
CallbacksRegistry.prototype.call = function() {
|
||||
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)));
|
||||
};
|
||||
|
||||
CallbacksRegistry.prototype.apply = function() {
|
||||
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)));
|
||||
};
|
||||
|
||||
CallbacksRegistry.prototype.remove = function(id) {
|
||||
return delete this.callbacks[id];
|
||||
};
|
||||
|
||||
return CallbacksRegistry;
|
||||
|
||||
})();
|
|
@ -1,5 +0,0 @@
|
|||
if process.platform is 'linux' and process.type is 'renderer'
|
||||
### On Linux we could not access clipboard in renderer process. ###
|
||||
module.exports = require('electron').remote.clipboard
|
||||
else
|
||||
module.exports = process.atomBinding 'clipboard'
|
7
atom/common/api/lib/clipboard.js
Normal file
7
atom/common/api/lib/clipboard.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
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');
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
fs = require 'fs'
|
||||
os = require 'os'
|
||||
path = require 'path'
|
||||
{spawn} = require 'child_process'
|
||||
|
||||
electron = require 'electron'
|
||||
binding = process.atomBinding 'crash_reporter'
|
||||
|
||||
class CrashReporter
|
||||
start: (options={}) ->
|
||||
{@productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra} = options
|
||||
|
||||
### Deprecated. ###
|
||||
{deprecate} = electron
|
||||
if options.submitUrl
|
||||
submitURL ?= options.submitUrl
|
||||
deprecate.warn 'submitUrl', 'submitURL'
|
||||
|
||||
{app} = if process.type is 'browser' then electron else electron.remote
|
||||
|
||||
@productName ?= app.getName()
|
||||
autoSubmit ?= true
|
||||
ignoreSystemCrashHandler ?= false
|
||||
extra ?= {}
|
||||
|
||||
extra._productName ?= @productName
|
||||
extra._companyName ?= companyName
|
||||
extra._version ?= app.getVersion()
|
||||
|
||||
unless companyName?
|
||||
deprecate.log('companyName is now a required option to crashReporter.start')
|
||||
return
|
||||
|
||||
unless submitURL?
|
||||
deprecate.log('submitURL is now a required option to crashReporter.start')
|
||||
return
|
||||
|
||||
start = => binding.start @productName, companyName, submitURL, autoSubmit, ignoreSystemCrashHandler, extra
|
||||
|
||||
if process.platform is 'win32'
|
||||
args = [
|
||||
"--reporter-url=#{submitURL}"
|
||||
"--application-name=#{@productName}"
|
||||
"--v=1"
|
||||
]
|
||||
env = ATOM_SHELL_INTERNAL_CRASH_SERVICE: 1
|
||||
|
||||
spawn process.execPath, args, {env, detached: true}
|
||||
start()
|
||||
|
||||
getLastCrashReport: ->
|
||||
reports = this.getUploadedReports()
|
||||
if reports.length > 0 then reports[0] else null
|
||||
|
||||
getUploadedReports: ->
|
||||
tmpdir =
|
||||
if process.platform is 'win32'
|
||||
os.tmpdir()
|
||||
else
|
||||
'/tmp'
|
||||
log =
|
||||
if process.platform is 'darwin'
|
||||
path.join tmpdir, "#{@productName} Crashes"
|
||||
else
|
||||
path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
|
||||
binding._getUploadedReports log
|
||||
|
||||
crashRepoter = new CrashReporter
|
||||
module.exports = crashRepoter
|
104
atom/common/api/lib/crash-reporter.js
Normal file
104
atom/common/api/lib/crash-reporter.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
var CrashReporter, binding, crashRepoter, electron, fs, os, path, spawn;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
os = require('os');
|
||||
|
||||
path = require('path');
|
||||
|
||||
spawn = require('child_process').spawn;
|
||||
|
||||
electron = require('electron');
|
||||
|
||||
binding = process.atomBinding('crash_reporter');
|
||||
|
||||
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;
|
||||
|
||||
})();
|
||||
|
||||
crashRepoter = new CrashReporter;
|
||||
|
||||
module.exports = crashRepoter;
|
|
@ -1,69 +0,0 @@
|
|||
### Deprecate a method. ###
|
||||
deprecate = (oldName, newName, fn) ->
|
||||
warned = false
|
||||
->
|
||||
unless warned or process.noDeprecation
|
||||
warned = true
|
||||
deprecate.warn oldName, newName
|
||||
fn.apply this, arguments
|
||||
|
||||
### The method is renamed. ###
|
||||
deprecate.rename = (object, oldName, newName) ->
|
||||
warned = false
|
||||
newMethod = ->
|
||||
unless warned or process.noDeprecation
|
||||
warned = true
|
||||
deprecate.warn oldName, newName
|
||||
this[newName].apply this, arguments
|
||||
if typeof object is 'function'
|
||||
object.prototype[oldName] = newMethod
|
||||
else
|
||||
object[oldName] = newMethod
|
||||
|
||||
### Forward the method to member. ###
|
||||
deprecate.member = (object, method, member) ->
|
||||
warned = false
|
||||
object.prototype[method] = ->
|
||||
unless warned or process.noDeprecation
|
||||
warned = true
|
||||
deprecate.warn method, "#{member}.#{method}"
|
||||
this[member][method].apply this[member], arguments
|
||||
|
||||
### Deprecate a property. ###
|
||||
deprecate.property = (object, property, method) ->
|
||||
Object.defineProperty object, property,
|
||||
get: ->
|
||||
warned = false
|
||||
unless warned or process.noDeprecation
|
||||
warned = true
|
||||
deprecate.warn "#{property} property", "#{method} method"
|
||||
this[method]()
|
||||
|
||||
### Deprecate an event. ###
|
||||
deprecate.event = (emitter, oldName, newName, fn) ->
|
||||
warned = false
|
||||
emitter.on newName, (args...) ->
|
||||
### there is listeners for old API. ###
|
||||
if @listenerCount(oldName) > 0
|
||||
unless warned or process.noDeprecation
|
||||
warned = true
|
||||
deprecate.warn "'#{oldName}' event", "'#{newName}' event"
|
||||
if fn?
|
||||
fn.apply this, arguments
|
||||
else
|
||||
@emit oldName, args...
|
||||
|
||||
### Print deprecation warning. ###
|
||||
deprecate.warn = (oldName, newName) ->
|
||||
deprecate.log "#{oldName} is deprecated. Use #{newName} instead."
|
||||
|
||||
### Print deprecation message. ###
|
||||
deprecate.log = (message) ->
|
||||
if process.throwDeprecation
|
||||
throw new Error(message)
|
||||
else if process.traceDeprecation
|
||||
console.trace message
|
||||
else
|
||||
console.warn "(electron) #{message}"
|
||||
|
||||
module.exports = deprecate
|
115
atom/common/api/lib/deprecate.js
Normal file
115
atom/common/api/lib/deprecate.js
Normal file
|
@ -0,0 +1,115 @@
|
|||
|
||||
/* 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.");
|
||||
};
|
||||
|
||||
|
||||
/* Print deprecation message. */
|
||||
|
||||
deprecate.log = function(message) {
|
||||
if (process.throwDeprecation) {
|
||||
throw new Error(message);
|
||||
} else if (process.traceDeprecation) {
|
||||
return console.trace(message);
|
||||
} else {
|
||||
return console.warn("(electron) " + message);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = deprecate;
|
|
@ -1,29 +0,0 @@
|
|||
### Do not expose the internal modules to `require`. ###
|
||||
exports.hideInternalModules = ->
|
||||
{globalPaths} = require 'module'
|
||||
if globalPaths.length is 3
|
||||
### Remove the "common/api/lib" and "browser-or-renderer/api/lib". ###
|
||||
globalPaths.splice 0, 2
|
||||
|
||||
### Attaches properties to |exports|. ###
|
||||
exports.defineProperties = (exports) ->
|
||||
Object.defineProperties exports,
|
||||
### Common modules, please sort with alphabet order. ###
|
||||
clipboard:
|
||||
### Must be enumerable, otherwise it woulde be invisible to remote module. ###
|
||||
enumerable: true
|
||||
get: -> require '../clipboard'
|
||||
crashReporter:
|
||||
enumerable: true
|
||||
get: -> require '../crash-reporter'
|
||||
nativeImage:
|
||||
enumerable: true
|
||||
get: -> require '../native-image'
|
||||
shell:
|
||||
enumerable: true
|
||||
get: -> require '../shell'
|
||||
### The internal modules, invisible unless you know their names. ###
|
||||
CallbacksRegistry:
|
||||
get: -> require '../callbacks-registry'
|
||||
deprecate:
|
||||
get: -> require '../deprecate'
|
59
atom/common/api/lib/exports/electron.js
Normal file
59
atom/common/api/lib/exports/electron.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
/* Do not expose the internal modules to `require`. */
|
||||
exports.hideInternalModules = function() {
|
||||
var globalPaths;
|
||||
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, {
|
||||
|
||||
/* 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');
|
||||
}
|
||||
},
|
||||
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');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
|
@ -1,7 +0,0 @@
|
|||
{deprecate} = require 'electron'
|
||||
nativeImage = process.atomBinding 'native_image'
|
||||
|
||||
### Deprecated. ###
|
||||
deprecate.rename nativeImage, 'createFromDataUrl', 'createFromDataURL'
|
||||
|
||||
module.exports = nativeImage
|
12
atom/common/api/lib/native-image.js
Normal file
12
atom/common/api/lib/native-image.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
var deprecate, nativeImage;
|
||||
|
||||
deprecate = require('electron').deprecate;
|
||||
|
||||
nativeImage = process.atomBinding('native_image');
|
||||
|
||||
|
||||
/* Deprecated. */
|
||||
|
||||
deprecate.rename(nativeImage, 'createFromDataUrl', 'createFromDataURL');
|
||||
|
||||
module.exports = nativeImage;
|
|
@ -1 +0,0 @@
|
|||
module.exports = process.atomBinding 'shell'
|
1
atom/common/api/lib/shell.js
Normal file
1
atom/common/api/lib/shell.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = process.atomBinding('shell');
|
Loading…
Add table
Add a link
Reference in a new issue