-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
58 lines (37 loc) · 2.08 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
title: SharedArrayBuffer() コンストラクター
slug: Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/SharedArrayBuffer
---
{{JSRef}}
> **メモ:** `SharedArrayBuffer` は、 2018 年 1 月 5 日に [Spectre](https://meltdownattack.com/) への対策として、すべての主要ブラウザーで既定で無効化されました。 Chrome は、 Spectre スタイルの脆弱性から保護するためにサイトアイソレーション機能が有効になっているプラットフォームでは、 [v67 で再有効化しました](https://bugs.chromium.org/p/chromium/issues/detail?id=821270)。
**`SharedArrayBuffer()` コンストラクター**は {{jsxref("SharedArrayBuffer")}} オブジェクトを生成し、これは {{jsxref("ArrayBuffer")}} オブジェクトと似た、汎用的な、固定長の生のバイナリーデータバッファーを表します。
{{EmbedInteractiveExample("pages/js/sharedarraybuffer-constructor.html","shorter")}}
## 構文
```js
new SharedArrayBuffer();
new SharedArrayBuffer(length);
```
### 引数
- `length` {{optional_inline}}
- : 生成する配列バッファーの長さをバイト数で指定します。
### 返値
指定された長さの新しい `SharedArrayBuffer` オブジェクトです。中身は 0 で初期化されます。
## 例
### SharedArrayBuffer を生成するには常に new 演算子を使用する
`SharedArrayBuffer` コンストラクターは {{jsxref("Operators/new", "new")}} 演算子で構築する必要があります。 `SharedArrayBuffer` コンストラクターを `new` なしで呼び出すと、 {{jsxref("TypeError")}} が発生します。
```js example-bad
var sab = SharedArrayBuffer(1024);
// TypeError: calling a builtin SharedArrayBuffer constructor
// new がない形は禁止されています
```
```js example-good
var sab = new SharedArrayBuffer(1024);
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- {{jsxref("Atomics")}}
- {{jsxref("ArrayBuffer")}}
- [JavaScript の型付き配列](/ja/docs/Web/JavaScript/Typed_arrays)