Welcome to MSDN Blogs Sign in | Join | Help

IE8 JScript Debugger - Under the Hood

I have posted about the JScript Debugger Design for IE8 Developers Tools on the JScript Team blog (here). Hope it is nice read up for you. I would be writing more on Debugger very soon. Stay tuned.

Posted by Sheetal Kamat | 3 Comments

JScript Debugger Functionality in IE8

Deepak, Program Manager, from our JScript Team has blogged here in detail about the functionalities the Script Debugger in the IE8 Developer Tools provide. He has also links to the other resources like white paper etc in his blog. This would be interesting read for all the web developers looking at in built script debugger in IE8.
Posted by Sheetal Kamat | 1 Comments

IE8 Beta1 is available

IE8 Beta1 is now available here.

It has remarkable script improvements in JScript performance. It also features handy JScript Debugger for developers.

I will soon be writing more about JScript Debugger - what went into designing this debugger the way it is, features etc. So stay tuned.

Mean while you can read up on what are few improvements related to performance.

Posted by Sheetal Kamat | 2 Comments

Passing more than one parameter to the script callback

Passing more than one parameter to JScript function isn’t difficult at all after knowing how to pass the parameter. But there is only one trickier part here. I haven’t investigated why this is trickier but it is this way and one must know this other wise the results can be confusing.

 

Lets say out function foo takes parameter a, b and c and just alerts the values one by one.

function foo(a, b, c)

{

    alert("a = " + a);

    alert("b = " + b);

    alert("c = " + c);

}

 

Now as earlier we need to use dispParams to pass the parameters. But the trickier part here is the order in which the parameters need to be passed. You need to pass in parameters in exactly opposite order as expected. That is the array of parameter arguments should be in order c, b, a.

 

So we define one VARIANTARG here as :

// Parameters in exactly opposite order.

VARIANTARG param[3];

param[0].vt = VT_INT;

param[0].intVal = 10; // c

param[1].vt = VT_INT;

param[1].intVal = 20; // b

param[2].vt = VT_INT;

param[2].intVal = 30; // a

 

Then intialise it in dispParams as

DISPPARAMS dispParams = {

      param, // paramters

      NULL, // Named Parameters = JScript doesn't understand this

      3, // no. of parameters

      0 }; // no. of named parameters

 

That’s it. Calling Invoke now would call the function with parameters

m_disp->Invoke(

      DISPID_VALUE,

      IID_NULL,

      LOCALE_USER_DEFAULT,

      DISPATCH_METHOD,

      &dispParams,

      NULL,

      NULL,

      NULL);

Posted by Sheetal Kamat | 2 Comments
Filed under: , ,

Attachment(s): Sample.zip

Using Return Value of the Script Callback

To use the return value of the JScript Function we need to pass parameter VARIANT *pVarResult to the Invoke Method of the IDispatch.

 

Lets implement an adder that takes one integer as parameter and return the result as paramter + 1.

function adder(a)

{

    alert("a = " + a);

    return a + 1;

}

 

We have already seen how to pass a parameter using dispParams to JScript Function. Now we just need to define result variant to store the result and then invoke the Invoke on the dispatch.

VARIANT result;

 

Call to the invoke

m_disp->Invoke(

      DISPID_VALUE,

      IID_NULL,

      LOCALE_USER_DEFAULT,

      DISPATCH_METHOD,

      &dispParams,

      &result,

      NULL,

      NULL);

 

Attached code contains the complete adder code.

Posted by Sheetal Kamat | 1 Comments
Filed under: , ,

Attachment(s): Adder.zip

Passing Parameter to the Script Callback

Earlier post talked about how to call a callback script from the COM component. What if one wants to call a function that takes parameter say alerter.

function alerter(b)

{

    alert("b = " + b);

}

 

Now to call this function we need to use other parameters of Invoke method of IDispatch which we had initialised to default.

DISPPARARMS dispParams that we intialised earlier with default value needs attention here. It takes the variant arguments, and named arguments. JScript does not support named arguments. So we can only use variant arg parameter.

 

So we define one VARIANTARG with interger value here.

VARIANTARG param;

param.vt = VT_INT;

param.intVal = 10;

 

And then intialise it in dispParams as

DISPPARAMS dispParams = {

&param, // paramters

      NULL, // Named Parameters = JScript doesn't understand this

      1, // no. of parameters

      0 }; // no. of named parameters

 

That’s it. Calling Invoke now would call the alerter.

m_disp->Invoke(

      DISPID_VALUE,

      IID_NULL,

      LOCALE_USER_DEFAULT,

      DISPATCH_METHOD,

      &dispParams,

      NULL,

      NULL,

      NULL);

 

Next post we will see how to use return value.

Posted by Sheetal Kamat | 1 Comments
Filed under: , ,

Attachment(s): Alerter.zip

Script CallBack from COM

Earlier we saw how to call a function on COM class from JScript. But what if one wants to call a function say a callback which is in JScript from COM? Lets see how to achieve this in this post.

 

To make COM and JScript interoperable and allow COM component to call JScript function we need to pass JScript function to the COM component so that COM component receives it as IDispatch. Later to invoke this function, Invoke method on this IDispatch can be used.

 

How? Here is step by step explanation

 

Callback function:

function scriptCallBack()

{

    alert("In script callback");

}

 

Sending callback function to ActiveXObject:

x.SetCallBack(scriptCallBack);

 

COM function in class Test that implements SetCallBack:

STDMETHODIMP CTest::SetCallBack(IDispatch* disp)

{

      m_disp = disp;

      m_disp->AddRef();

      return S_OK;

}

 

COM function that calls CallBack:

STDMETHODIMP CTest::SomeFuncThatCallsCallBack(void)

{

      // Do Something

 

      // Call the callback

      if(m_disp)

      {

            DISPPARAMS dispParams = { NULL, NULL, 0, 0 };

            m_disp->Invoke(

                  DISPID_VALUE,

                  IID_NULL,

                  LOCALE_USER_DEFAULT,

                  DISPATCH_METHOD,

                  &dispParams,

                  NULL,

                  NULL,

                  NULL);

      }

 

      return S_OK;

}

 

Now this works perfectly fine, To test it I write the JScript code:

x.SomeFuncThatCallsCallBack();

 

Attached is the sample code

Posted by Sheetal Kamat | 1 Comments
Filed under: , ,

Attachment(s): Sample.zip

Calling functions of COM object from JScript

After earlier post on instantiating COM class, let’s move ahead with invoking the functions over this COM object.

 

To be able to invoke functions on the instantiated COM function through JScript, we need to add the method to the ITest interface which is derived from IDispatch.

Lets start with a example of a COM function Func1 which takes 2 parameters and returns the product of two numbers.

 

First step is to add the method for ITest interface:

I added this through ATL wizard, its much simpler that way. Note that return value is indicated as retval.

[id(1), helpstring("method Func1")] HRESULT Func1([in] FLOAT a, [in] FLOAT b, [out,retval] FLOAT* result);

 

Implementing this function on Test class:

STDMETHODIMP CTest::Func1(FLOAT a, FLOAT b, FLOAT* result)

{

      *result = a * b;

      return S_OK;

}

 

To call this method from JScript now we just need to pass in the parameters and store the result the way we normally do in JScript.

var result = x.Func1(10, 20);

 

What if you wants the function that returns array. It becomes really tricky but here is how one can achieve it.

To start with we need to add a method to ITest that would have retVal of VARIANT*

[id(2), helpstring("method Func2")] HRESULT Func2([out,retval] VARIANT* arrayVal);

 

After this here is how we implement the SafeArray in the func2.

Creation of the array:

SAFEARRAY * psa;

SAFEARRAYBOUND rgsabound[1];

rgsabound[0].lLbound = 0;

rgsabound[0].cElements = 5;

psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);

 

Populating data within this array:

VARIANT  HUGEP *pInteger;

SafeArrayAccessData(psa, (void HUGEP**)&pInteger);

for (int i = 0; i < psa->rgsabound->cElements; i++)

{

      pInteger[i].intVal = i;

      pInteger[i].vt = VT_INT;

}

SafeArrayUnaccessData(psa);

 

Now note that JScript can return or receive arrays of VARIANTs only. That was the reason the the method defined is with returnVal type of VARIANT.

VARIANT var;

var.vt = VT_ARRAY | VT_VARIANT;

var.parray = psa;

*arrayVal = var;

 

Now story does not end here. It is  even more trickier to use this array in Jscript. The variable needs to be converted to VB array first and then we need to use toArray method on this to actually get JScript Array. Here is how:

var array1 = x.Func2();

var array2 = new VBArray(array1);

var actualArray = array2.toArray(); 

 

For more information on VARIANTs you can check out this MSDN link:

http://msdn2.microsoft.com/en-us/library/ms221627.aspx

 

There is also a nice post on MSDN for JScript Types and COM types at:

http://blogs.msdn.com/ericlippert/archive/2004/07/14/183241.aspx

Posted by Sheetal Kamat | 4 Comments
Filed under: , ,

Attachment(s): Sample.zip

Interoperability of JScript with COM

Recently I worked on using COM component in JScript. I couldn't find one stop solution or example for this and so thought for writing series of posts regarding this.

 

Instantiating a COM class.

COM class should implement IDispatch and be registered with ProgID, so that JScript can invoke it using ActiveXObject semantics.

 

I used ATL library to create a ATL project called Sample and then added the Test which implements IDispatch and has progID = “Sample.Test”

 

Register this class using command

regsvr32 <path>Sample.dll

 

Now this class can be instantiated in JScript using:

var x = new ActiveXObject(“Sample.Test”);

 

Methods of Class Test can be invoked now using variable x.

I will talk about different mechanisms for passing parameters to and fro in next Posts.

 

Attached Zip contains the sample code.

Posted by Sheetal Kamat | 1 Comments
Filed under: , ,

Attachment(s): Sample.zip

Debugging a script debugger

Its kind of pain to debug a debugger. One thing for sure. If you want to debug VS debugger for C++,C# etc languages then it would be bit simple(I think) as everything takes place in VS itself. So its just question of attaching to another VS which is kind of well established method here. But when it comes to debugging a script debugger it gets hard. Debugging takes place through VS but actual engine runs in IE. So just attaching to VS doesn't solve the purpose. You have to attach to IE. Now things get complicated here. Reason IE is invoked by VS which you are already debugging. So you need to attach to this IE using some other version of the VS. Basically you need unregsiter RET csm.dll and register CHK csm.dll so that you don't face problem in attaching to IE which is invoked by VS.

So the final setup looks like this:

Unregister RET csm.dll using regsvr32 /u <path for RET csm.dll>

Register CHK csm.dll using regsvr32 <path for CHK csm.dll>

CHK VS has venus project in which you can set bp in script etc. Pressing F5 invokes IE and breaks at previosly set BP. (You will need to check off option from Tools -> Internet Options -> Advanced -> Disable Script Debugging to enable script debugging)

In RET VS you need to attach to IE and CHK VS.

And you are ready to debug script debugging. Happy Debugging!!

Posted by Sheetal Kamat | 3 Comments
Filed under:

Building 2 at IDC

The new building at IDC is ready and from monday it will be occupied. I got a chance to get glimpses of  the building. Its looking great. Amazing colour combination. I liked use of bright colours. It feels so much energized there. Cafe is almost same as Building 1 but then apart  from counters near wall they have come up with some counters in the middle of cafe as well. I am already happy with the cafe service here. We get so much of variety unlike so many other companies. Food quiality is much better. And now that cafe in building 2 would open from monday, it would give some more variety in the food. In all cafe is the place which will impress any visitor. There were ballons everywhere in the walkway between two buildings, some flowers decoration. and yummy cake. All in all it was looking very pleasant and cheerful atmosphere. Hope to see new faces, make new friends  now.

Posted by Sheetal Kamat | 5 Comments
Filed under:

Change in Blog Title

Since I am going to work on Jscript Engine now, the blog is no longer solely for Object Test Bench. Hence Changing the name. I would be involved in Jscript debugging support and Intellisense. So now on expect blogs on experience about Jscript transitioning, problems faced, how we overcome them etc as well here.

Getting rid of un-necessary rebuild messages while working with OTB

In VS2005, if you are trying to work with OTB and you think you are getting unnecessary rebuild messages or create instance in windows application is starting form itself, you can check

Tools -> Options -> Project and Solution -> General -> Show advanced Build configuration.

This should resolve all the above problems.

Posted by Sheetal Kamat | 1 Comments
Filed under:

Attachment(s): Options.JPG

Interesting decision about the design

Recently Neela reported down one interesting issue.

Consider a class class1 with following two methods:

public void test(String str)

public void test(String[] str)

Now if user creates object of class1 (say object1) on OTB and then selects method test(String) from the context sensitive menu and enters parameter as 'null' what should we do. In normal cases call like object1.test(null) is going to give compiling error as the call is ambiguous between method test(String) and test(String[]).

But we had two problems to think of.

1. User has specifically selected method and wants method test(String) to be executed with parameter null.

2. From debugger perspective it is just a call like debugger its just a call as test(null)

Hence we should somehow execute method test(String) or should fail the method with the error as ambigous call.

If we would have allowed successful execution of method it would mean to user that method test(String) when passed parameter as null would succeed and he/she would expect the same behaviour when he adds a code like object1.test(null); into the main method. But thats not true. So surely this was going to mislead and confuse user. Hence finally we decided to throw error as ambigous method call. With this now user knows that invocation of test(String) method with null parameter is not correct. (Though user can pass variable str of type String which is null)

Posted by Sheetal Kamat | 2 Comments
Filed under:
 
Page view tracker