Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var ext = this.getExtensionByKey("factory", factoryName);
if (ext === undefined) {
throw new Error('When creating object "' + name +
'", there is no factory called "' + factoryName +
'" available."');
}
// If this is a child catalog and the extension is shared, then
// as the master/parent catalog to create the object.
if (this.parent && this.shareExtension(ext)) {
return this.instancesLoadPromises[name] = this.parent.createObject(name);
}
// Otherwise create a new loading promise (which is returned at the
// end of the function) and create the instance.
var pr = this.instancesLoadPromises[name] = new Promise();
var factoryArguments = descriptor.arguments || [];
var argumentPromises = [];
if (descriptor.objects) {
var objects = descriptor.objects;
for (var key in objects) {
var objectName = objects[key];
var ropr = this.createObject(objectName);
argumentPromises.push(ropr);
// key is changing, so we need to hang onto the
// current value
ropr.location = key;
ropr.then(function(obj) {
_setPath(factoryArguments, ropr.location, obj);
});
}
var ext = this.getExtensionByKey("factory", factoryName);
if (ext === undefined) {
throw new Error('When creating object "' + name +
'", there is no factory called "' + factoryName +
'" available."');
}
// If this is a child catalog and the extension is shared, then
// as the master/parent catalog to create the object.
if (this.parent && this.shareExtension(ext)) {
return this.instancesLoadPromises[name] = this.parent.createObject(name);
}
// Otherwise create a new loading promise (which is returned at the
// end of the function) and create the instance.
var pr = this.instancesLoadPromises[name] = new Promise();
var factoryArguments = descriptor.arguments || [];
var argumentPromises = [];
if (descriptor.objects) {
var objects = descriptor.objects;
for (var key in objects) {
var objectName = objects[key];
var ropr = this.createObject(objectName);
argumentPromises.push(ropr);
// key is changing, so we need to hang onto the
// current value
ropr.location = key;
ropr.then(function(obj) {
_setPath(factoryArguments, ropr.location, obj);
});
}
exports["test split then"] = function () {
var p = promiseModule.Promise();
var p2 = p.then(
function () {
return '1';
})
.then(
function () {
return '2';
});
var ok,ok2;
promiseModule.when(p, function(value) {
print("p " + value);
ok = value;
});
promiseModule.when(p2, function(value) {
ok2 = value;
exports.stringify = function(data) {
var pack_promise = exports.pack(data);
var stringify_promise = new Promise();
pack_promise.then(function(packed) {
stringify_promise.ok(JSON.stringify(packed));
});
return stringify_promise;
};
load: function(callback, property, catalog) {
catalog = catalog || exports.catalog;
var promise = new Promise();
var onComplete = function(func) {
if (callback) {
callback(func);
}
promise.resolve(func);
};
var pointerVal = this[property || 'pointer'];
if (util.isFunction(pointerVal)) {
onComplete(pointerVal);
return promise;
}
var pointerObj = _splitPointer(this.pluginName, pointerVal);
loadMetadataFromURL: function(url, type) {
var pr = new Promise();
proxy.xhr('GET', url, true).then(function(response) {
this.registerMetadata(JSON.parse(response));
pr.resolve();
}.bind(this), function(err) {
pr.reject(err);
});
return pr;
},
loadObjectForPropertyPath: function(path, context) {
var promise = new Promise();
var parts = /^([^:]+):([^#]+)#(.*)$/.exec(path);
if (parts === null) {
throw new Error("loadObjectForPropertyPath: malformed path: '" +
path + "'");
}
var pluginName = parts[1];
if (pluginName === "") {
if (util.none(context)) {
throw new Error("loadObjectForPropertyPath: no plugin name " +
"supplied and no context is present");
}
pluginName = context;
}
exports.xhr = function(method, url, async, beforeSendCallback) {
var pr = new Promise();
if (!bespin.proxy || !bespin.proxy.xhr) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState !== 4) {
return;
}
var status = req.status;
if (status !== 0 && status !== 200) {
var error = new Error(req.responseText + ' (Status ' + req.status + ")");
error.xhr = req;
pr.reject(error);
return;
}
loadObjectForPropertyPath: function(path, context) {
var promise = new Promise();
var parts = /^([^:]+):([^#]+)#(.*)$/.exec(path);
if (parts === null) {
throw new Error("loadObjectForPropertyPath: malformed path: '" +
path + "'");
}
var pluginName = parts[1];
if (pluginName === "") {
if (util.none(context)) {
throw new Error("loadObjectForPropertyPath: no plugin name " +
"supplied and no context is present");
}
pluginName = context;
}
exports.pack = function(input, reftracker) {
var promise = new Promise();
var t = typeof input;
if (typeof reftracker === 'undefined') {
var reftracker = new exports._ReferenceTracker();
}
var reference = reftracker.reference(input);
if (reference && reference.ref) {
promise.ok({'reference': reference.ref});
} else if (t === 'string' || t === 'number' || t === 'boolean') {
promise.ok(input);
} else if (t === 'undefined') {
promise.ok({'undefined': true});
} else if (input === null) {
promise.ok({'null': true});
} else if (input instanceof Date) {
promise.ok({'date': input.getTime()});
} else if (input instanceof RegExp) {