Skip to content

Commit

Permalink
Updating error message return from unserializable JavaScript result i…
Browse files Browse the repository at this point in the history
…n IE

In the case where a user JavaScript execution completes successfully, but
the resulting option is not serializable via JSON (because of cyclical
references or similar), the error message that the execution errored due to
the failed serialization was being suppressed.
  • Loading branch information
jimevans committed Nov 11, 2018
1 parent 0adb38f commit e424840
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cpp/iedriver/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ int Script::ConvertResultToJsonValue(IElementManager* element_manager,
this->result_,
value);
if (status_code != WD_SUCCESS) {
// Attempting to convert the VARIANT script result to a JSON value
// has failed. As a last-ditch effort, attempt to use JSON.stringify()
// to accomplish the same thing.
// TODO: Check the return value for a cyclic reference error first, and
// if that's the reason for the failure to convert, we can bypass this
// script execution and just return that as the error reason.
LOG(DEBUG) << "Script result could not be directly converted; "
<< "attempting to use JSON.stringify()";
std::wstring json_stringify_script = ANONYMOUS_FUNCTION_START;
Expand Down Expand Up @@ -600,6 +606,14 @@ int Script::ConvertResultToJsonValue(IElementManager* element_manager,
*value = interim_value;
}
}
} else {
// If the call to JSON.stringify() fails, log the description of the
// error thrown by that call as the reason for the script returning a
// JavaScript error.
if (stringify_script_wrapper.result().vt == VT_BSTR) {
std::wstring error = stringify_script_wrapper.result().bstrVal;
*value = StringUtilities::ToString(error);
}
}
}
return status_code;
Expand Down

0 comments on commit e424840

Please sign in to comment.