|
|
|
|
@ -5,7 +5,8 @@ define([
|
|
|
|
|
'base/js/namespace',
|
|
|
|
|
'jquery',
|
|
|
|
|
'codemirror/lib/codemirror',
|
|
|
|
|
], function(IPython, $, CodeMirror){
|
|
|
|
|
'components/rsvp/rsvp.min',
|
|
|
|
|
], function(IPython, $, CodeMirror, rsvp){
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
IPython.load_extensions = function () {
|
|
|
|
|
@ -606,13 +607,41 @@ define([
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var WrappedError = function(message, error){
|
|
|
|
|
// Wrappable Error class
|
|
|
|
|
|
|
|
|
|
// The Error class doesn't actually act on `this`. Instead it always
|
|
|
|
|
// returns a new instance of Error. Here we capture that instance so we
|
|
|
|
|
// can apply it's properties to `this`.
|
|
|
|
|
var tmp = Error.apply(this, [message]);
|
|
|
|
|
|
|
|
|
|
// Copy the properties of the error over to this.
|
|
|
|
|
var properties = Object.getOwnPropertyNames(tmp);
|
|
|
|
|
for (var i = 0; i < properties.length; i++) {
|
|
|
|
|
this[properties[i]] = tmp[properties[i]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep a stack of the original error messages.
|
|
|
|
|
if (error instanceof WrappedError) {
|
|
|
|
|
this.error_stack = error.error_stack;
|
|
|
|
|
} else {
|
|
|
|
|
this.error_stack = [error];
|
|
|
|
|
}
|
|
|
|
|
this.error_stack.push(tmp);
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WrappedError.prototype = Object.create(Error.prototype, {});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var load_class = function(class_name, module_name, registry) {
|
|
|
|
|
// Tries to load a class
|
|
|
|
|
//
|
|
|
|
|
// Tries to load a class from a module using require.js, if a module
|
|
|
|
|
// is specified, otherwise tries to load a class from the global
|
|
|
|
|
// registry, if the global registry is provided.
|
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
|
return new rsvp.Promise(function(resolve, reject) {
|
|
|
|
|
|
|
|
|
|
// Try loading the view module using require.js
|
|
|
|
|
if (module_name) {
|
|
|
|
|
@ -638,13 +667,13 @@ define([
|
|
|
|
|
|
|
|
|
|
var resolve_dict = function(d) {
|
|
|
|
|
// Resolve a promiseful dictionary.
|
|
|
|
|
// Returns a single Promise.
|
|
|
|
|
// Returns a single rsvp.Promise.
|
|
|
|
|
var keys = Object.keys(d);
|
|
|
|
|
var values = [];
|
|
|
|
|
keys.forEach(function(key) {
|
|
|
|
|
values.push(d[key]);
|
|
|
|
|
});
|
|
|
|
|
return Promise.all(values).then(function(v) {
|
|
|
|
|
return rsvp.Promise.all(values).then(function(v) {
|
|
|
|
|
d = {};
|
|
|
|
|
for(var i=0; i<keys.length; i++) {
|
|
|
|
|
d[keys[i]] = v[i];
|
|
|
|
|
@ -681,15 +710,15 @@ define([
|
|
|
|
|
WrappedError.prototype = Object.create(Error.prototype, {});
|
|
|
|
|
|
|
|
|
|
var reject = function(message, log) {
|
|
|
|
|
// Creates a wrappable Promise rejection function.
|
|
|
|
|
// Creates a wrappable rsvp.Promise rejection function.
|
|
|
|
|
//
|
|
|
|
|
// Creates a function that returns a Promise.reject with a new WrappedError
|
|
|
|
|
// Creates a function that returns a rsvp.Promise.reject with a new WrappedError
|
|
|
|
|
// that has the provided message and wraps the original error that
|
|
|
|
|
// caused the promise to reject.
|
|
|
|
|
return function(error) {
|
|
|
|
|
var wrapped_error = new WrappedError(message, error);
|
|
|
|
|
if (log) console.error(wrapped_error);
|
|
|
|
|
return Promise.reject(wrapped_error);
|
|
|
|
|
return rsvp.Promise.reject(wrapped_error);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -722,9 +751,9 @@ define([
|
|
|
|
|
XHR_ERROR : XHR_ERROR,
|
|
|
|
|
wrap_ajax_error : wrap_ajax_error,
|
|
|
|
|
promising_ajax : promising_ajax,
|
|
|
|
|
WrappedError: WrappedError,
|
|
|
|
|
load_class: load_class,
|
|
|
|
|
resolve_dict: resolve_dict,
|
|
|
|
|
WrappedError: WrappedError,
|
|
|
|
|
reject: reject,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|