Socket
Socket
Sign inDemoInstall

protoblast

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protoblast - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

10

CHANGELOG.md

@@ -0,1 +1,11 @@

## 0.5.2 (2018-03-02)
* Fix prototype pollution in `Object.merge`
* When a `next` method of `Function.parallel` or `Function.series` is called multiple times an error will be thrown
* `Informer#setCacheMethod` will no longer try to execute a callback if it's not defined
* If the argument for `Pledge#handleCallback` is truthy but not a function, an error will be thrown
* Throw an error when a `Pledge` is resolved with itself
* Fix the way `Pledge` handles rejections
* Add `Pledge#addProgressPart(parts)` and `Pledge#reportProgressPart(parts)` to facility progress reporting
## 0.5.1 (2018-02-24)

@@ -2,0 +12,0 @@

73

lib/function_flow.js

@@ -97,3 +97,3 @@ module.exports = function BlastFunctionFlow(Blast, Collection, Bound) {

* @since 0.1.2
* @version 0.5.1
* @version 0.5.2
*

@@ -123,2 +123,6 @@ * @param {Boolean} _forceAsync Force asynchronous behaviour [TRUE]

// Since there is a callback that also gets the error,
// make sure the pledge considers the error "caught"
pledge.catch(Function());
// Normalize parameters

@@ -189,3 +193,5 @@ if (typeof _forceAsync == 'boolean') {

part = 100 / length;
// Tell the pledge how many parts there are
// This includes the callback
pledge.addProgressPart(length + 1);
i = -1;

@@ -205,3 +211,3 @@

stop = true;
pledge.silentReject(err);
pledge.reject(err);
return callback(err);

@@ -219,3 +225,3 @@ }

// Report the progress
pledge.addProgress(part);
pledge.reportProgressPart(1);

@@ -226,4 +232,21 @@ // See if we need to do another task

var count = 0;
try {
tasks[next](handler);
tasks[next](function nextHandler(err, result) {
if (count == 1) {
stop = true;
err = new Error('Next handler has been called multiple times');
pledge.reject(err);
return callback(err);
} else if (count > 1) {
// Just ignore further calls
return;
}
count++;
return handler(err, result);
});
} catch (err) {

@@ -236,3 +259,3 @@

stop = true;
pledge.silentReject(err);
pledge.reject(err);
return callback(err);

@@ -269,3 +292,3 @@ }

* @since 0.1.2
* @version 0.5.1
* @version 0.5.2
*/

@@ -383,2 +406,6 @@ Blast.defineStatic('Function', 'parallel', function parallel(_forceAsync, _limit, _tasks, _callback) {

// Since there is a callback that also gets the error,
// make sure the pledge considers the error "caught"
pledge.catch(Function());
// If no tasks were given, call the callback

@@ -394,4 +421,7 @@ if (!length) {

started = 0;
part = 100 / length;
// Tell the pledge how many parts there are to begin with
// This includes the callback
pledge.addProgressPart(length + 1);
handler = function blastParallelHandler(i, err, result) {

@@ -411,3 +441,3 @@

stop = true;
pledge.silentReject(err);
pledge.reject(err);
return callback(err);

@@ -420,3 +450,3 @@ }

// Report the progress
pledge.addProgress(part);
pledge.reportProgressPart(1);

@@ -430,9 +460,25 @@ // If we need to start any other functions, do it now

scheduler(function scheduleNextTask() {
var count = 0;
try {
tasks[next](function nextHandler(err, val) {
handler(next, err, val);
if (count == 1) {
stop = true;
err = new Error('Next handler has been called multiple times');
pledge.reject(err);
return callback(err);
} else if (count > 1) {
// Just ignore further calls
return;
}
count++;
return handler(next, err, val);
});
} catch (err) {
stop = true;
pledge.silentReject(err);
pledge.reject(err);
return callback(err);

@@ -473,3 +519,3 @@ }

stop = true;
pledge.silentReject(err);
pledge.reject(err);
return callback(err);

@@ -498,2 +544,3 @@ }

pledge.reportProgress(100);
pledge.resolve(results);

@@ -500,0 +547,0 @@ }

14

lib/informer.js

@@ -174,9 +174,11 @@ module.exports = function BlastInformer(Blast, Collection) {

// use it to add this call
pledge.then(function doMethod(result) {
callback(null, result);
});
if (callback) {
pledge.then(function doMethod(result) {
callback(null, result);
});
pledge.catch(function doMethod(err) {
callback(err);
});
pledge.catch(function doMethod(err) {
callback(err);
});
}

@@ -183,0 +185,0 @@ // This return will only be called if it's not the first time

@@ -758,3 +758,3 @@ module.exports = function BlastObject(Blast, Collection, Bound, Obj) {

* @since 0.1.9
* @version 0.3.7
* @version 0.5.1
*

@@ -800,3 +800,3 @@ * @param {Object} target The object to inject the extension into

}
} else {
} else if (target.hasOwnProperty == null || target.hasOwnProperty(key)) {
if (Collection.Object.isSelfContained(extension[key])) {

@@ -803,0 +803,0 @@ target[key] = extension[key];

module.exports = function BlastPledge(Blast, Collection) {
var PENDING = 0,
RESOLVED = 1,
REJECTED = 2;
/**

@@ -34,3 +38,3 @@ * The Pledge Class

*/
Pledge.setProperty('state', 0);
Pledge.setProperty('state', PENDING);

@@ -49,2 +53,24 @@ /**

/**
* Progress parts can be used instead of manually adding percentages
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.5.2
* @version 0.5.2
*
* @type {Number}
*/
Pledge.setProperty('progress_parts', 0);
/**
* The finished number of progress parts
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.5.2
* @version 0.5.2
*
* @type {Number}
*/
Pledge.setProperty('progress_parts_finished', 0);
/**
* The pledge count

@@ -163,2 +189,60 @@ *

/**
* Add an amount of progress parts used for calculating the progress
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.5.2
* @version 0.5.2
*
* @param {Number} parts
*/
Pledge.setMethod(function addProgressPart(parts) {
if (parts == null) {
parts = 1;
}
this.progress_parts += parts;
this.calculateProgressParts();
});
/**
* Finish an amount of progress parts
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.5.2
* @version 0.5.2
*
* @param {Number} parts
*/
Pledge.setMethod(function reportProgressPart(parts) {
if (parts == null) {
parts = 1;
}
this.progress_parts_finished += parts;
this.calculateProgressParts();
});
/**
* Calculate the progress based on the progress parts
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.5.2
* @version 0.5.2
*/
Pledge.setMethod(function calculateProgressParts() {
var amount;
// Calculate how much is already finished
amount = this.progress_parts_finished / this.progress_parts;
// And multiply it to get a nice percentage number
amount = ~~(amount * 100);
this.reportProgress(amount);
});
/**
* Resolve with the given value

@@ -168,8 +252,9 @@ *

* @since 0.4.0
* @version 0.4.0
* @version 0.5.2
*/
Pledge.setMethod(function resolve(value) {
this.state = 1;
this._resolved_value = value;
if (value === this) {
throw new TypeError('A pledge cannot be resolved with itself.');
}

@@ -184,3 +269,3 @@ this._doResolve(value);

* @since 0.4.0
* @version 0.4.0
* @version 0.5.2
*/

@@ -199,2 +284,5 @@ Pledge.setMethod(function _doResolve(value) {

this.state = RESOLVED;
this._resolved_value = value;
if (this.sub_pledges !== 0) {

@@ -214,3 +302,3 @@ while (this._on_fulfilled.length) {

* @since 0.4.0
* @version 0.5.1
* @version 0.5.2
*

@@ -221,22 +309,10 @@ * @param {Error} reason

this.state = 2;
this._rejected_reason = reason;
var result = this._doReject(reason);
this._doReject(reason);
if (!result) {
throw reason;
}
});
/**
* Reject silently: don't throw if no listeners are available
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.4.0
* @version 0.5.1
*
* @param {Error} reason
*/
Pledge.setMethod(function silentReject(reason) {
this._doReject(reason, true);
});
/**
* Do the actual rejection

@@ -246,36 +322,33 @@ *

* @since 0.4.0
* @version 0.5.1
* @version 0.5.2
*
* @param {Error} reason
* @param {Boolean} silent Don't throw errors when no rejection listeners are available
*/
Pledge.setMethod(function _doReject(reason, silent) {
Pledge.setMethod(function _doReject(reason) {
var that = this;
var that = this,
caught_rejection = false;
if (reason && reason.then) {
if (silent && reason.silentReject) {
return reason.then(function onFulfilledReject(value) {
that.silentReject(value);
}, function onRejectedReject(reason) {
that.silentReject(reason);
});
} else {
return reason.then(function onFulfilledReject(value) {
that.reject(value);
}, function onRejectedReject(reason) {
that.reject(reason);
});
}
return reason.then(function onFulfilledReject(value) {
that.reject(value);
}, function onRejectedReject(reason) {
that.reject(reason);
});
}
this.state = REJECTED;
this._rejected_reason = reason;
if (this.sub_pledges !== 0) {
while (this._on_rejected.length) {
this._on_rejected.shift()(reason);
if (this._on_rejected.shift()(reason)) {
caught_rejection = true;
}
}
this._on_fulfilled.length = 0;
} else if (silent !== true) {
throw reason;
}
return caught_rejection;
});

@@ -288,3 +361,3 @@

* @since 0.4.0
* @version 0.4.0
* @version 0.5.2
*/

@@ -322,3 +395,4 @@ Pledge.setMethod(function then(on_fulfilled, on_rejected) {

var result;
var caught_rejection = false,
result;

@@ -328,2 +402,3 @@ try {

result = on_rejected(reason);
caught_rejection = true;
} else {

@@ -333,3 +408,5 @@ result = reason;

then_pledge.reject(result);
// This was wrong in earlier versions:
// you RESOLVE chained promises, not reject
then_pledge.resolve();
} catch (reason) {

@@ -339,7 +416,8 @@ then_pledge.reject(reason);

return caught_rejection;
});
if (this.state == 1) {
if (this.state == RESOLVED) {
this._doResolve(this._resolved_value);
} else if (this.state == 2) {
} else if (this.state == REJECTED) {
this._doReject(this._rejected_reason);

@@ -375,2 +453,6 @@ }

if (typeof callback != 'function') {
throw new Error('Unable to handle callback: not a function!');
}
this.then(function onResolved(value) {

@@ -377,0 +459,0 @@ callback(null, value);

{
"name": "protoblast",
"description": "Native object expansion library",
"version": "0.5.1",
"version": "0.5.2",
"author": "Jelle De Loecker <jelle@develry.be>",

@@ -6,0 +6,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc