07-24-2023, 09:46 AM
I am currently trying to run Q promise library from JScript/CScript from command prompt. But it seems that JScript is throwing an error when it tries to execute/eval the code.
Code:
function createXMLHTTPObject() {
var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++) {
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}
var loadScript = function(url){
var script= createXMLHTTPObject();
script.Open("GET",url,false);
script.Send()
var response = eval(script.responseText);
}
//execute Q library
loadScript("http://jquery-for-admins.googlecode.com/svn/trunk/jq4a.js");
loadScript("http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js");
loadScript("http://cdnjs.cloudflare.com/ajax/libs/q.js/1.0.1/q.js");
This is the execution code from cmd:
wscript //x script.js
The code above could execute jquery4admin and json2.min.js. But for some reasons it couldn't execute the Q library. So the question is: Is there any other promise library that support JScript/CScript? If it is not possible then I will just run all XHR in synchronous mode.
Update:
the error was actually within q.js, when I tried to declare the deferred object and resolve it, visual studio debugger basically break and stopped at this line of code:
`// old browsers
requestTick = function () {
setTimeout(flush, 0);
};`
And this is what visual studio says:
> Unhandled exception at line 618, column 13 in eval code
>
> 0x800a138f - Microsoft JScript runtime error: Object expected
Thanks
Code:
function createXMLHTTPObject() {
var XMLHttpFactories = [
function () {return new XMLHttpRequest()},
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];
var xmlhttp = false;
for (var i=0;i<XMLHttpFactories.length;i++) {
try {
xmlhttp = XMLHttpFactories[i]();
}
catch (e) {
continue;
}
break;
}
return xmlhttp;
}
var loadScript = function(url){
var script= createXMLHTTPObject();
script.Open("GET",url,false);
script.Send()
var response = eval(script.responseText);
}
//execute Q library
loadScript("http://jquery-for-admins.googlecode.com/svn/trunk/jq4a.js");
loadScript("http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js");
loadScript("http://cdnjs.cloudflare.com/ajax/libs/q.js/1.0.1/q.js");
This is the execution code from cmd:
wscript //x script.js
The code above could execute jquery4admin and json2.min.js. But for some reasons it couldn't execute the Q library. So the question is: Is there any other promise library that support JScript/CScript? If it is not possible then I will just run all XHR in synchronous mode.
Update:
the error was actually within q.js, when I tried to declare the deferred object and resolve it, visual studio debugger basically break and stopped at this line of code:
`// old browsers
requestTick = function () {
setTimeout(flush, 0);
};`
And this is what visual studio says:
> Unhandled exception at line 618, column 13 in eval code
>
> 0x800a138f - Microsoft JScript runtime error: Object expected
Thanks