SharedArrayBuffer.prototype.slice()

翻译不完整。 请帮助我们翻译这篇文章!

SharedArrayBuffer.prototype.slice() 方法返回一个新的SharedArrayBuffer 副本,其内容是该SharedArrayBuffer的字节从begin开始(包含begin),直到end结束(不包含end)。如果beginend是负的,它指的是从数组末尾开始的索引。此方法与 Array.prototype.slice() 具有相同的算法。

语法

sab.slice()
sab.slice(begin)
sab.slice(begin, end)

参数

begin 可选
从零开始的索引,从该索引开始提取。
可以使用一个负索引,表示从序列末尾开始的偏移量。 slice(-2)提取序列中的最后两个元素。
If begin is undefined, slice begins from index 0.如果begin为undefined,slice则从索引为0处开始。
end 可选
从零开始的索引,在此索引之前终止提取。 slice 执行提取到索引为end的位置(不包含end)。
例如,slice(1,4)提取第二个元素到第四个元素(索引为1、2和3的元素)。
可以使用一个负索引,表示从序列末尾开始的偏移量。 slice(2,-1)提取序列中从第三个元素开始,到倒数第二个元素结束的全部元素。
如果省略end,则slice一直提取到序列的末尾(sab.byteLength)。

返回值

一个包含被提取出的元素的新 SharedArrayBuffer

例子

var sab = new SharedArrayBuffer(1024);
sab.slice();    // SharedArrayBuffer { byteLength: 1024 }
sab.slice(2);   // SharedArrayBuffer { byteLength: 1022 }
sab.slice(-2);  // SharedArrayBuffer { byteLength: 2 }
sab.slice(0, 1); // SharedArrayBuffer { byteLength: 1 }

规范

Specification Status Comment
ECMAScript (ECMA-262)
SharedArrayBuffer.prototype.slice
Living Standard Initial definition in ES2017.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
sliceChrome Full support 68
Full support 68
No support 60 — 63
Notes
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This was a temporary removal while mitigations were put in place.
Edge Full support 79
Full support 79
No support 16 — 17
Notes
Notes Support was removed to mitigate speculative execution side-channel attacks (Windows blog).
Firefox Full support 57
Notes Disabled
Full support 57
Notes Disabled
Notes Support was disabled by default to mitigate speculative execution side-channel attacks (Mozilla Security Blog).
Disabled From version 57: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 55 — 57
No support 46 — 55
Disabled
Disabled From version 46 until version 55 (exclusive): this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari No support 10.1 — 11WebView Android No support 60 — 63
Notes
No support 60 — 63
Notes
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This is intended as a temporary measure until other mitigations are in place.
Chrome Android No support 60 — 63
Notes
No support 60 — 63
Notes
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This is intended as a temporary measure until other mitigations are in place.
Firefox Android Full support 57
Notes Disabled
Full support 57
Notes Disabled
Notes Support was disabled by default to mitigate speculative execution side-channel attacks (Mozilla Security Blog).
Disabled From version 57: this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
No support 55 — 57
No support 46 — 55
Disabled
Disabled From version 46 until version 55 (exclusive): this feature is behind the javascript.options.shared_memory preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android No support NoSafari iOS No support 10.3 — 11Samsung Internet Android No support No
Notes
No support No
Notes
Notes Chrome disabled SharedArrayBuffer on January 5, 2018 to help reduce the efficacy of speculative side-channel attacks. This is intended as a temporary measure until other mitigations are in place.
nodejs Full support 8.10.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

相关链接