This project is read-only.

Issue with executing mathods of wrapped objects.

Jan 24, 2013 at 9:28 AM

I have an issue with executing JS code that uses methods of c# objects set as parameters.

I'm trying to implement DOM structure in my project and use v8 to run JS code. I've created Document class and set parameter 'document' to engine. When I call any property (e.g. var root = document.documentElement) everything works fine, property in C# class is called. But when I try methods (e.g. var div = document.getElementById('div')) then I get an error saying that IsJSObject check failed.

I've traced the code and found that issue with JavascriptInterop::UnwrapObject function. In case with methods second condition iValue->IsExternal() must be executed but first check iValue->IsObject() also yields true. So first branch is executed which is wrong one. I've switched conditions so IsExternal called first and everything works now.

But I'm not sure that this is proper solution. May be there is some meaning with existing checks order. Could you please tell me if my solution is valid or I have to find another one and checks order can not be changed?

Jan 24, 2013 at 10:54 PM

I'm not sure what cases are really being handled in UnwrapObject, but perhaps your problem would be resolved by removing the 'else'.  In that case the order would not change, but it would drop through to the iValue->IsExternal() test if the object->InternalFiedlCount() == 0.  Can you try that and tell me how it goes?

Jan 25, 2013 at 9:01 AM

Unfortunately it would not work. Check (object->InternalFieldCount() > 0) yields true for this case.

The problem occurs with objectInfo array that is wrapped in JavascriptExternal::GetMethod and unwrapped in JavascriptInterop::Invoker (very first line).