When using something I have a strong need to understand things as deep as possible. I was struggling advanced javascript code using closures heavily. Almost every explanation I found was "example based". As I really need to know the internals to understand the problem I decided to dive into ECMA script specification to find parts related to closures. At first I searched ECMA-262 second edition published back in the last century (1998). Well ... It is really a history. Nothing related to or similar to closures could be found in this document. The I have tried the fifth edition published in 2009. BINGO!
No explanation of closures will follow in this post. I think the description in the spec is crystal clear and should be read by everyone who wants to understand what's going on when a nested function is used.
The shortcut for those who are curious is here: look for Clause 10.2 in the ECMAScript specification document (http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf). Its name is "Lexical enviroments". This clause describes how the javascript engine implements "the magic". Clause 13.2 is otyher usefull part describing function object instantiation.
Zobrazují se příspěvky se štítkemjavascript. Zobrazit všechny příspěvky
Zobrazují se příspěvky se štítkemjavascript. Zobrazit všechny příspěvky
čtvrtek 13. ledna 2011
pátek 27. února 2009
... throw exception from ActiveX to Javascript
Developing a simple ActiveX I was not able to find clear information how to propagate exception from C++ code to Javascript. I'm using ATL and there are no exceptions when using ATL code.
The solutin is to implement
Now an exception is thrown in Javascript in the form of Error object with message property, which maps to what was set by
That's all for today.
Example:
The solutin is to implement
ISupportErrorInfo
and act accordingly when it's the only method is called (apropriate code is generated by Visual Studio). Then when an error is to be reported after a method of ActiveX control returns, use functions CreateErrorInfo/SetErrorInfo
to fill the error information data and use E_FAIL
return code of the method.Now an exception is thrown in Javascript in the form of Error object with message property, which maps to what was set by
ICreateErrorInfo.SetDescription
.That's all for today.
Example:
void setException(BSTR msg){
ICreateErrorInfo * cErrInf;
CreateErrorInfo(&cErrInf);
if (cErrInf==NULL) return;
cErrInf->SetDescription(msg);
cErrInf->SetGUID(component_IID);
IErrorInfo *err;
cErrInf->QueryInterface(&err);
SetErrorInfo(0,err);
}
...
setException(L"error mesaage");
return E_FAIL;
}
Přihlásit se k odběru:
Příspěvky (Atom)