Skip to content

Commit

Permalink
Do not rely on strict handling in setEdge (#31)
Browse files Browse the repository at this point in the history
Previously setEdge relied on "use strict" for handling args. It turns
out the PhantomJS doesn't handle "use strict" under some conditions,
causing code that used setEdge to fail. This change makes the argument
work regardless of whether "use strict" is used or not. There isn't a
good way to test this, unfortunately...
  • Loading branch information
cpettitt committed Oct 29, 2014
1 parent bbda5b9 commit f0cade1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,9 @@ Graph.prototype.setPath = function(vs, value) {
* setEdge(v, w, [value, [name]])
* setEdge({ v, w, [name] }, [value])
*/
Graph.prototype.setEdge = function(v, w, value, name) {
var valueSpecified = arguments.length > 2;

v = String(v);
w = String(w);
if (!_.isUndefined(name)) {
name = String(name);
}
Graph.prototype.setEdge = function() {
var v, w, name, value,
valueSpecified = false;

if (_.isPlainObject(arguments[0])) {
v = arguments[0].v;
Expand All @@ -321,6 +316,20 @@ Graph.prototype.setEdge = function(v, w, value, name) {
value = arguments[1];
valueSpecified = true;
}
} else {
v = arguments[0];
w = arguments[1];
name = arguments[3];
if (arguments.length > 2) {
value = arguments[2];
valueSpecified = true;
}
}

v = "" + v;
w = "" + w;
if (!_.isUndefined(name)) {
name = "" + name;
}

var e = edgeArgsToId(this._isDirected, v, w, name);
Expand Down

0 comments on commit f0cade1

Please sign in to comment.