Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: setTimeout fails after upgrade [93]

$
0
0
I just upgraded from version 5.4.2 to 5.4.3 and script code that once worked now fails with the error "Object doesn't support this property or method". I am using V8.

I added a host object that is a Timer
```
Engine.AddHostType("ScriptTimer", GetType(ScriptTimer))
```

My ScriptTimer looks like this (VB.Net)
```
Public Module ScriptTimer
Public Function Create(func As Object, delay As Double, period As Double, args As Object)
Try
Dim callback As System.Threading.TimerCallback = New System.Threading.TimerCallback(
Sub()
Try
func.apply(Nothing, args)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub)
Return New System.Threading.Timer(callback, Nothing, Convert.ToInt64(delay), Convert.ToInt64(period))
Catch ex As Exception
Console.WriteLine(ex.Message)
Return ex
End Try
End Function
End Module
```

And this is the script that fails.
```
function createTimer(periodic, func, delay) {
var period = periodic ? delay : -1;
var args = Array.prototype.slice.call(arguments, 3);
return ScriptTimer.Create(func, delay, period, args);
}

setTimeout = createTimer.bind(null, false);
```
Comments: Hi again, It's great to hear that your issue is resolved! ​ >BTW: Should this same setTimeout function work in the ClearScript JScript engine? ​ Not quite; there are two problems. First, JScript doesn't appear to support [Function.prototype.bind()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind), so you'd need to provide your own implementation or eliminate its usage. A deeper issue is that Windows script engines have thread affinity, so you'd have to modify your timer implementation to invoke the callback on the correct thread. Good luck!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles



Latest Images