hasJSFunctions returns false on every call, so a response that arrives carrying further JavaScript properties to execute is never processed and the flow declares itself complete after a single round.
|
var hasJSFunctions = function() { |
|
for (var i = i; i < json.javascriptProperties; i++) { |
|
var body = getFromJson(json.javascriptProperties[i]); |
|
if (body !== undefined && body.length > 0) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
Two things are wrong with the loop header:
var i = i initialises the index from itself. Hoisting means i exists but is undefined at that point, so it stays undefined.
- The bound is
json.javascriptProperties, the array itself, rather than json.javascriptProperties.length. The next line indexes into the same array, so the length is clearly what was intended.
The condition therefore evaluates undefined < ["device.javascripthardwareprofile", ...], both sides are coerced to primitives, and any comparison involving undefined or NaN is false. The body never runs. Correcting only the initialiser would not help either, since 0 < "device.javascript..." is also false.
Effect
The only caller is loadJSON:
if (hasJSFunctions()) {
// json updated so fire 'on change' functions
// before executing any new JS properties that
// have come back.
fireChangeFuncs(json);
process(resolve, reject);
} else {
failed = false;
completed = true;
fireChangeFuncs(json);
resolve(json);
}
Because the test is always false, the else branch is always taken. Multi-round evidence collection, where the first response asks the browser to gather more evidence and a second round of snippets has to run, never happens. device.javascripthardwareprofile is the case this path exists for.
Suggested fix
var hasJSFunctions = function() {
if (!json.javascriptProperties) {
return false;
}
for (var i = 0; i < json.javascriptProperties.length; i++) {
var body = getFromJson(json.javascriptProperties[i]);
if (body !== undefined && body.length > 0) {
return true;
}
}
return false;
}
Why this is worth its own change
Repairing the loop makes process() reachable from loadJSON for the first time, so a code path that has been dead in every shipped version starts running, in every language SDK that consumes this template. It has no test coverage today. Worth landing on its own, with a browser test covering a response that comes back with outstanding JavaScript properties, rather than riding along with an unrelated change.
hasJSFunctionsreturnsfalseon every call, so a response that arrives carrying further JavaScript properties to execute is never processed and the flow declares itself complete after a single round.javascript-templates/JavaScriptResource.mustache
Lines 347 to 355 in e92d03f
Two things are wrong with the loop header:
var i = iinitialises the index from itself. Hoisting meansiexists but isundefinedat that point, so it staysundefined.json.javascriptProperties, the array itself, rather thanjson.javascriptProperties.length. The next line indexes into the same array, so the length is clearly what was intended.The condition therefore evaluates
undefined < ["device.javascripthardwareprofile", ...], both sides are coerced to primitives, and any comparison involvingundefinedorNaNisfalse. The body never runs. Correcting only the initialiser would not help either, since0 < "device.javascript..."is alsofalse.Effect
The only caller is
loadJSON:Because the test is always
false, theelsebranch is always taken. Multi-round evidence collection, where the first response asks the browser to gather more evidence and a second round of snippets has to run, never happens.device.javascripthardwareprofileis the case this path exists for.Suggested fix
Why this is worth its own change
Repairing the loop makes
process()reachable fromloadJSONfor the first time, so a code path that has been dead in every shipped version starts running, in every language SDK that consumes this template. It has no test coverage today. Worth landing on its own, with a browser test covering a response that comes back with outstanding JavaScript properties, rather than riding along with an unrelated change.