Skip to content

Commit f0cade1

Browse files
committed
Do not rely on strict handling in setEdge (#31)
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...
1 parent bbda5b9 commit f0cade1

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

lib/graph.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,9 @@ Graph.prototype.setPath = function(vs, value) {
304304
* setEdge(v, w, [value, [name]])
305305
* setEdge({ v, w, [name] }, [value])
306306
*/
307-
Graph.prototype.setEdge = function(v, w, value, name) {
308-
var valueSpecified = arguments.length > 2;
309-
310-
v = String(v);
311-
w = String(w);
312-
if (!_.isUndefined(name)) {
313-
name = String(name);
314-
}
307+
Graph.prototype.setEdge = function() {
308+
var v, w, name, value,
309+
valueSpecified = false;
315310

316311
if (_.isPlainObject(arguments[0])) {
317312
v = arguments[0].v;
@@ -321,6 +316,20 @@ Graph.prototype.setEdge = function(v, w, value, name) {
321316
value = arguments[1];
322317
valueSpecified = true;
323318
}
319+
} else {
320+
v = arguments[0];
321+
w = arguments[1];
322+
name = arguments[3];
323+
if (arguments.length > 2) {
324+
value = arguments[2];
325+
valueSpecified = true;
326+
}
327+
}
328+
329+
v = "" + v;
330+
w = "" + w;
331+
if (!_.isUndefined(name)) {
332+
name = "" + name;
324333
}
325334

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

0 commit comments

Comments
 (0)