Skip to content

Commit c185485

Browse files
gibson042ptomato
authored andcommitted
[immutable-arraybuffer] DataView.prototype.set$Type
1 parent 04eaeb9 commit c185485

File tree

11 files changed

+550
-0
lines changed

11 files changed

+550
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setbigint64
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setBigInt64 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getBigInt64(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getBigInt64(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setBigInt64(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setbiguint64
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setBigUint64 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getBigUint64(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getBigUint64(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setBigUint64(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setfloat16
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setFloat16 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getFloat16(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getFloat16(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setFloat16(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setfloat32
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setFloat32 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getFloat32(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getFloat32(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setFloat32(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setfloat64
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setFloat64 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getFloat64(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getFloat64(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setFloat64(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setint16
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getInt16(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getInt16(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setInt16(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-dataview.prototype.setint32
6+
description: >
7+
Throws a TypeError exception when the backing buffer is immutable
8+
info: |
9+
DataView.prototype.setInt32 ( byteOffset, value [ , littleEndian ] )
10+
1. Let view be the this value.
11+
2. Return ? SetViewValue(view, byteOffset, true, ~uint8~, value).
12+
13+
SetViewValue ( view, requestIndex, isLittleEndian, type, value )
14+
1. Perform ? RequireInternalSlot(view, [[DataView]]).
15+
2. Assert: view has a [[ViewedArrayBuffer]] internal slot.
16+
3. If IsImmutableBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
17+
4. Let getIndex be ? ToIndex(requestIndex).
18+
5. If IsBigIntElementType(type) is true, let numberValue be ? ToBigInt(value).
19+
6. Otherwise, let numberValue be ? ToNumber(value).
20+
features: [DataView, immutable-arraybuffer]
21+
includes: [compareArray.js]
22+
---*/
23+
24+
var iab = (new ArrayBuffer(8)).transferToImmutable();
25+
var view = new DataView(iab);
26+
27+
var calls = [];
28+
var byteOffset = {
29+
valueOf() {
30+
calls.push("byteOffset.valueOf");
31+
return 0;
32+
}
33+
};
34+
var value = {
35+
valueOf() {
36+
calls.push("value.valueOf");
37+
return "1";
38+
}
39+
};
40+
41+
assert.sameValue(
42+
view.getInt32(byteOffset),
43+
(new DataView(new ArrayBuffer(8))).getInt32(byteOffset),
44+
"read an initial zero"
45+
);
46+
calls = [];
47+
assert.throws(TypeError, function() {
48+
view.setInt32(byteOffset, value);
49+
});
50+
assert.compareArray(calls, [], "Must verify mutability before reading arguments.");

0 commit comments

Comments
 (0)