最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why do I get "Can't execute code from a freed script" - Stack Overflow

programmeradmin1浏览0评论

First of all: Yes, I've read this answer... And, Yes, there's no meta after script (as I do not have any meta on my page), and, No, there's no timeout or ajax-request

I have following helper-method (Yes, I could have made a prototype-method ...):

function removeElementFromArray(array, pareMethod) {
    if (!array) {
        return;
    }
    if (!$.isFunction(pareMethod)) {
        return;
    }
    var index = getIndexOfElement(array, pareMethod);
    if (index < 0) {
        return;
    }
    array.splice(index, 1);
}
function getIndexOfElement(array, pareMethod) {
    if (!array) {
        return -1;
    }
    if (!$.isFunction(pareMethod)) {
        return -1;
    }
    for (var i = 0; i < array.length; i++) {
        var element = array[i];
        if (pareMethod(element)) {
            return i;
        }
    }
    return -1;
}

I am calling this with:

$foo.on('click', function () {
    removeElementFromArray(window.myArray, function (element) {
        return // some condition
    });
});

I am getting the exception "SCRIPT5011: Can't execute code from a freed script" (only in IE render-mode < 10) in following line:

array.splice(index, 1);

But not on the first call, but on any subsequent ones (for the same array) ...

But I can't think of a single reason why this exception occurs, as I am accessing the array in other lines as well in the callstack (as you can see, eg getIndexOfElement, where I iterate over the array).

Can anybody help me out?

First of all: Yes, I've read this answer... And, Yes, there's no meta after script (as I do not have any meta on my page), and, No, there's no timeout or ajax-request

I have following helper-method (Yes, I could have made a prototype-method ...):

function removeElementFromArray(array, pareMethod) {
    if (!array) {
        return;
    }
    if (!$.isFunction(pareMethod)) {
        return;
    }
    var index = getIndexOfElement(array, pareMethod);
    if (index < 0) {
        return;
    }
    array.splice(index, 1);
}
function getIndexOfElement(array, pareMethod) {
    if (!array) {
        return -1;
    }
    if (!$.isFunction(pareMethod)) {
        return -1;
    }
    for (var i = 0; i < array.length; i++) {
        var element = array[i];
        if (pareMethod(element)) {
            return i;
        }
    }
    return -1;
}

I am calling this with:

$foo.on('click', function () {
    removeElementFromArray(window.myArray, function (element) {
        return // some condition
    });
});

I am getting the exception "SCRIPT5011: Can't execute code from a freed script" (only in IE render-mode < 10) in following line:

array.splice(index, 1);

But not on the first call, but on any subsequent ones (for the same array) ...

But I can't think of a single reason why this exception occurs, as I am accessing the array in other lines as well in the callstack (as you can see, eg getIndexOfElement, where I iterate over the array).

Can anybody help me out?

Share Improve this question edited May 23, 2017 at 10:25 CommunityBot 11 silver badge asked Apr 5, 2013 at 9:32 user57508user57508 8
  • 2 Can you reproduce this in a fiddle ? – Denys Séguret Commented Apr 5, 2013 at 9:34
  • @dystroy good point! will try to! – user57508 Commented Apr 5, 2013 at 9:37
  • Are you sure none of your code change the splice function ? Is array a real array or an array-like object ? – Denys Séguret Commented Apr 5, 2013 at 9:38
  • @dystroy it's a real array, created with new Array(); and when I hover the splice prototype in the inspector, I get native code... – user57508 Commented Apr 5, 2013 at 9:47
  • 1 Then you definetely should take a look at this stackoverflow./questions/83132/… – Tommi Commented Apr 5, 2013 at 9:58
 |  Show 3 more ments

1 Answer 1

Reset to default 2

This question contains a good answers about iframes relationship. (Added as answer by OP suggestion).

发布评论

评论列表(0)

  1. 暂无评论