Skip to content

Commit e424840

Browse files
committed
Updating error message return from unserializable JavaScript result in 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.
1 parent 0adb38f commit e424840

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cpp/iedriver/Script.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,12 @@ int Script::ConvertResultToJsonValue(IElementManager* element_manager,
573573
this->result_,
574574
value);
575575
if (status_code != WD_SUCCESS) {
576+
// Attempting to convert the VARIANT script result to a JSON value
577+
// has failed. As a last-ditch effort, attempt to use JSON.stringify()
578+
// to accomplish the same thing.
579+
// TODO: Check the return value for a cyclic reference error first, and
580+
// if that's the reason for the failure to convert, we can bypass this
581+
// script execution and just return that as the error reason.
576582
LOG(DEBUG) << "Script result could not be directly converted; "
577583
<< "attempting to use JSON.stringify()";
578584
std::wstring json_stringify_script = ANONYMOUS_FUNCTION_START;
@@ -600,6 +606,14 @@ int Script::ConvertResultToJsonValue(IElementManager* element_manager,
600606
*value = interim_value;
601607
}
602608
}
609+
} else {
610+
// If the call to JSON.stringify() fails, log the description of the
611+
// error thrown by that call as the reason for the script returning a
612+
// JavaScript error.
613+
if (stringify_script_wrapper.result().vt == VT_BSTR) {
614+
std::wstring error = stringify_script_wrapper.result().bstrVal;
615+
*value = StringUtilities::ToString(error);
616+
}
603617
}
604618
}
605619
return status_code;

0 commit comments

Comments
 (0)