根据V8 Stack Trace API ,存在本地或未知位置错误。使用 vanilla js 是否可能产生这些错误?
最佳答案
使用 Vanilla JS 时,您可能会在 native
处收到错误,如下所示:
> try { String.fromCodePoint(-42); } catch(e) { console.log(e.stack);}
RangeError: Invalid code point -42
at Function.fromCodePoint (native)
at <anonymous>:1:14
在V8中,部分功能是用JS实现的。例如,String.fromCodePoint 在这里 https://github.com/v8/v8/blob/5.2-lkgr/src/js/string.js#L784 。其他功能都是用C++实现的。我相信,如果错误是在 JS 函数中抛出的,那么它是 native 的。如果该函数是在 C++ 中实现的,则错误不在 native 处。
这是来自 encodeURI
的错误,该错误是在 C++ 中实现的 ( https://github.com/v8/v8/blob/master/src/uri.cc#L180 )。
> try { encodeURI('\uDFFF'); } catch(e) { console.log(e.stack);}
URIError: URI malformed
at <anonymous>:1:7
关于javascript - 使用 native 或未知堆栈帧位置创建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38860801/