Reformat JavaScript code in wxJSScriptWrapper

No real changes, but just use string concatenation instead of line
continuation backslashes and also replace hard TABs with spaces.

Notice that the code is still completely unreadable as JavaScript, but
this shouldn't be a problem as nobody will see it there anyhow, so it's
quite enough to have it more readable in its string form in C++.
This commit is contained in:
Vadim Zeitlin
2017-10-22 17:58:46 +02:00
parent 3907524098
commit d1c15bfe0e

View File

@@ -50,8 +50,13 @@ public:
// execution of this code. // execution of this code.
wxString GetWrappedCode() const wxString GetWrappedCode() const
{ {
return wxString::Format("try { var %s = eval(\"%s\"); true; } \ return wxString::Format
catch (e) { e.name + \": \" + e.message; }", m_outputVarName, m_escapedCode); (
"try { var %s = eval(\"%s\"); true; } "
"catch (e) { e.name + \": \" + e.message; }",
m_outputVarName,
m_escapedCode
);
} }
// Get code returning the result of the last successful execution of the // Get code returning the result of the last successful execution of the
@@ -59,84 +64,87 @@ public:
wxString GetOutputCode() const wxString GetOutputCode() const
{ {
#if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX__) #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX__)
return wxString::Format("if (typeof %s == 'object') \ return wxString::Format
JSON.stringify(%s); \ (
else if (typeof %s == 'undefined') \ "if (typeof %s == 'object') JSON.stringify(%s);"
'undefined'; \ "else if (typeof %s == 'undefined') 'undefined';"
else \ "else %s;",
%s;", m_outputVarName,
m_outputVarName, m_outputVarName, m_outputVarName, m_outputVarName); m_outputVarName,
m_outputVarName,
m_outputVarName
);
#elif wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE #elif wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE
return wxString::Format("try {(%s == null || typeof %s != 'object') ? String(%s) : JSON.stringify(%s);} \ return wxString::Format
catch (e) { \ (
try \ "try {"
{ \ "(%s == null || typeof %s != 'object') ? String(%s)"
function __wx$stringifyJSON(obj) \ ": JSON.stringify(%s);"
{ \ "}"
var objElements = []; \ "catch (e) {"
if (!(obj instanceof Object)) \ "try {"
return typeof obj === \"string\" \ "function __wx$stringifyJSON(obj) {"
? \'\"\' + obj + \'\"\' : \'\' + obj; \ "var objElements = [];"
else if (obj instanceof Array) \ "if (!(obj instanceof Object))"
{ \ "return typeof obj === \"string\""
if (obj[0] === undefined) \ "? \'\"\' + obj + \'\"\'"
return \'[]\'; \ ": \'\' + obj;"
else \ "else if (obj instanceof Array) {"
{ \ "if (obj[0] === undefined)"
var arr = []; \ "return \'[]\';"
for (var i = 0; i < obj.length; i++) \ "else {"
arr.push(__wx$stringifyJSON(obj[i])); \ "var arr = [];"
return \'[\' + arr + \']\'; \ "for (var i = 0; i < obj.length; i++)"
} \ "arr.push(__wx$stringifyJSON(obj[i]));"
} \ "return \'[\' + arr + \']\';"
else if (typeof obj === \"object\") \ "}"
{ \ "}"
if (obj instanceof Date) \ "else if (typeof obj === \"object\") {"
{ \ "if (obj instanceof Date) {"
if (!Date.prototype.toISOString) \ "if (!Date.prototype.toISOString) {"
{ \ "(function() {"
(function() \ "function pad(number) {"
{ \ "return number < 10"
function pad(number) \ "? '0' + number"
{ \ ": number;"
if (number < 10) \ "}"
return '0' + number; \ "Date.prototype.toISOString = function() {"
return number; \ "return this.getUTCFullYear() +"
} \ "'-' + pad(this.getUTCMonth() + 1) +"
\ "'-' + pad(this.getUTCDate()) +"
Date.prototype.toISOString = function() \ "'T' + pad(this.getUTCHours()) +"
{ \ "':' + pad(this.getUTCMinutes()) +"
return this.getUTCFullYear() + \ "':' + pad(this.getUTCSeconds()) +"
'-' + pad(this.getUTCMonth() + 1) + \ "'.' + (this.getUTCMilliseconds() / 1000)"
'-' + pad(this.getUTCDate()) + \ ".toFixed(3).slice(2, 5) + 'Z\"';"
'T' + pad(this.getUTCHours()) + \ "};"
':' + pad(this.getUTCMinutes()) + \ "}());"
':' + pad(this.getUTCSeconds()) + \ "}"
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) + \ "return '\"' + obj.toISOString(); + '\"'"
'Z\"'; \ "}"
}; \ "for (var key in obj)"
\ "{"
}()); \ "if (typeof obj[key] === \"function\")"
} \ "return \'{}\';"
return '\"' + obj.toISOString(); + '\"' \ "else {"
} \ "objElements.push(\'\"\'"
for (var key in obj) \ "+ key + \'\":\' +"
{ \ "__wx$stringifyJSON(obj[key]));"
if (typeof obj[key] === \"function\") \ "}"
return \'{}\'; \ "}"
else \ "return \'{\' + objElements + \'}\';"
objElements.push(\'\"\' \ "}"
+ key + \'\":\' + \ "}"
__wx$stringifyJSON(obj[key])); \ "__wx$stringifyJSON(%s);"
} \ "}"
return \'{\' + objElements + \'}\'; \ "catch (e) { e.name + \": \" + e.message; }"
} \ "}",
} \ m_outputVarName,
\ m_outputVarName,
__wx$stringifyJSON(%s); \ m_outputVarName,
} \ m_outputVarName,
catch (e) { e.name + \": \" + e.message; }}", m_outputVarName
m_outputVarName, m_outputVarName, m_outputVarName, m_outputVarName, m_outputVarName); );
#else #else
return m_outputVarName; return m_outputVarName;
#endif #endif