“未捕获错误:DATA_CLONE_ERR:DOM 异常 25”由网络工作者抛出

发布于 2024-12-06 03:18:15 字数 1488 浏览 1 评论 0原文

所以我正在创建一个网络工作者:

var arrayit = function(obj) {
  return Array.prototype.slice.call(obj);
};
work = arrayit(images);
console.log(work);
//work = images.push.apply( images, array );
// Method : "load+scroll"
var worker = new Worker('jail_worker.js');
worker.postMessage(work)
worker.onmessage = function(event) {
  console.log("Worker said:" + event.data);
};

这就是图像:

$.jail.initialStack = this;
// Store the selector into 'triggerEl' data for the images selected
this.data('triggerEl', (options.selector) ? $(options.selector) : $window);
var images = this;

我认为我的问题与此有关:

http://dev.w3.org/html5/spec/Overview.html#safe-passing-of-structed-data

我该如何解决这个问题?如您所见,我尝试将主机对象切片为真实数组,但这不起作用。

这是我正在破解的文件的链接:

https://github.com/jtmkrueger/JAIL

更新---- ----------------------------------------------------------

这就是我的必须根据 @davin 接受的答案来做:

var arrayit = function(obj) {
  return Array.prototype.slice.call(obj);
};
imgArray = arrayit(images);
work = _.map(images, function(i){ return i.attributes[0].ownerElement.outerHTML; });

var worker = new Worker('jail_worker.js');
worker.postMessage(work)
worker.onmessage = function(event) {
  console.log("Worker said:" + event.data);
};

注意:我使用 underscore.js 来确保兼容性。

So I'm creating a web worker:

var arrayit = function(obj) {
  return Array.prototype.slice.call(obj);
};
work = arrayit(images);
console.log(work);
//work = images.push.apply( images, array );
// Method : "load+scroll"
var worker = new Worker('jail_worker.js');
worker.postMessage(work)
worker.onmessage = function(event) {
  console.log("Worker said:" + event.data);
};

Here's what images is:

$.jail.initialStack = this;
// Store the selector into 'triggerEl' data for the images selected
this.data('triggerEl', (options.selector) ? $(options.selector) : $window);
var images = this;

I think my problem has something to do with this:

http://dev.w3.org/html5/spec/Overview.html#safe-passing-of-structured-data

How can I get around this? as you can see, I tried slicing the host object into a real array, but that didn't work.

Here's a link to the file I'm hacking on:

https://github.com/jtmkrueger/JAIL

UPDATE--------------------------------------------------

This is what I had to do based on the accepted answer from @davin:

var arrayit = function(obj) {
  return Array.prototype.slice.call(obj);
};
imgArray = arrayit(images);
work = _.map(images, function(i){ return i.attributes[0].ownerElement.outerHTML; });

var worker = new Worker('jail_worker.js');
worker.postMessage(work)
worker.onmessage = function(event) {
  console.log("Worker said:" + event.data);
};

NOTE: I used underscore.js to assure compatibility.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如歌彻婉言 2024-12-13 03:18:15

最初的异常很可能是因为您尝试将主机对象传递给 Web Worker(很可能是 dom 元素)而引发的。您后续的尝试不会引发相同的错误。请记住两个关键点:不同线程之间不存在共享内存,并且 Web Worker 无法操作 DOM。

postMessage 支持将结构化数据传递给线程,并且将 在内部序列化(或以其他方式递归复制数据的)数据。序列化 DOM 元素通常会导致循环引用错误,因此最好的选择是映射要序列化的对象并提取要在 Web Worker 中重建的相关数据。

The original exception was most likely thrown because you tried passing a host object to the web worker (most likely a dom element). Your subsequent attempts don't throw the same error. Remember two key points: there isn't shared memory between the different threads, and the web workers can't manipulate the DOM.

postMessage supports passing structured data to threads, and will internally serialise (or in some other way copy the value of the data recursively) the data. Serialising DOM elements often results in circular reference errors, so your best bet is to map the object you want serialised and extract relevant data to be rebuilt in the web worker.

凤舞天涯 2024-12-13 03:18:15

当尝试将对象的键保存到 indexeddb 函数时,会重现未捕获的 DataCloneError:无法克隆对象。需要仔细检查保存的对象是否可序列化

Uncaught DataCloneError: An object could not be cloned was reproduced when tried save to indexeddb function as object's key. Need double recheck that saved object is serializable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文