Mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create

function typedArraySupport () {
try {
var arr = new Uint8Array(1)
arr.proto = {proto: Uint8Array.prototype, foo: function () { return 42 }} ** // 此行引发**
return arr.foo() === 42 && // typed array instances can be augmented
typeof arr.subarray === ‘function’ && // chrome 9-10 lack subarray
arr.subarray(1, 1).byteLength === 0 // ie10 has broken subarray
} catch (e) {
return false
}
}net.rar (9.4 KB)

异常的位置是require(“buffer”) 引发的。请官方同学帮忙看看

Q: 真机或模拟器运行时报错:“mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create”
A: 这是由于某些第三方库,或者项目中用到了 ES2015(ES6)的类继承语法,而 Babel 在转义这个语法时会调用到 SpiderMonkey 不太优化 API,所以 SpiderMonkey 给出了这个报错。

有什么办法看到是上层的什么代码引发的?我在bundle.project.js报异常(非用户级代码)的位置打印堆栈,依然看不到是哪里引发的。

另外,这个run very slowly 有多大影响,是否需要关心?

/**

  • If Buffer.TYPED_ARRAY_SUPPORT:

  • === true Use Uint8Array implementation (fastest)

  • === false Use Object implementation (most compatible, even IE6)

  • Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,

  • Opera 11.6+, iOS 4.2+.

  • Due to various browser bugs, sometimes the Object implementation will be used even

  • when the browser supports typed arrays.

  • Note:

    • Firefox 4-29 lacks support for adding new properties to Uint8Array instances,
  • See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
    
    • Chrome 9-10 is missing the TypedArray.prototype.subarray function.
    • IE10 has a broken TypedArray.prototype.subarray function which returns arrays of
  • incorrect length in some situations.
    
  • We detect these buggy browsers and set Buffer.TYPED_ARRAY_SUPPORT to false so they
    *** get the Object implementation, which is slower but behaves correctl**y.
    */

require(“buffer”) 这个buffer在哪里?

你可以检查下你的项目代码是不是用了ES6的继承

那是 node.js 自带的 buffer 吧?或者你看看是哪个脚本用到了 require buffer

代码没有显式的调用require buffer.,我猜测是由于用到了Uint8Array,所以编译时require了buffer?

不会的。可能是你引入了什么插件导致的。

test_project.rar (193.3 KB)

您好,我添加了一个附件。

hi 这个问题解决了吗?

no 官方不理我了

这是因为你的项目中使用了 Buffer。
Buffer 是 node.js 才有的,编译到 SpiderMonkey 前会由 browserify 提供 shim,buffer 的 shim 实现在 SpiderMonkey 中就会产生我前面说到的问题。总之,不要用 Buffer 就好。

楼主最后怎么解决的?我也碰到了