Skip to content

Commit 46f5790

Browse files
Jake ChampionJakeChampion
authored andcommitted
Throw a TypeError instead of an Error when value_to_buffer is handed a value which is not a buffer
1 parent c241586 commit 46f5790

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

c-dependencies/js-compute-runtime/error-numbers.msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@
4141
// clang-format off
4242
MSG_DEF(JSMSG_NOT_AN_ERROR, 0, JSEXN_ERR, "<Error #0 is reserved>")
4343
MSG_DEF(JSMSG_BUILTIN_CTOR_NO_NEW, 1, JSEXN_TYPEERR, "calling a builtin {0} constructor without new is forbidden")
44+
MSG_DEF(JSMSG_INVALID_BUFFER_ARG, 2, JSEXN_TYPEERR, "{0} must be of type ArrayBuffer or ArrayBufferView but got \"{1}\"")
4445
//clang-format on

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ SpecString encode(JSContext *cx, HandleValue val) {
177177
uint8_t *value_to_buffer(JSContext *cx, HandleValue val, const char *val_desc, size_t *len) {
178178
if (!val.isObject() ||
179179
!(JS_IsArrayBufferViewObject(&val.toObject()) || JS::IsArrayBufferObject(&val.toObject()))) {
180-
JS_ReportErrorUTF8(cx, "%s must be of type ArrayBuffer or ArrayBufferView", val_desc);
180+
JS_ReportErrorNumberUTF8(cx, GetErrorMessage, nullptr, JSMSG_INVALID_BUFFER_ARG, val_desc,
181+
val.type());
181182
return nullptr;
182183
}
183184

tests/wpt-harness/expectations/compression/compression-bad-chunks.tentative.any.js.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
{
22
"chunk of type undefined should error the stream for gzip": {
3-
"status": 1
3+
"status": 0
44
},
55
"chunk of type undefined should error the stream for deflate": {
6-
"status": 1
6+
"status": 0
77
},
88
"chunk of type undefined should error the stream for deflate-raw": {
99
"status": 1
1010
},
1111
"chunk of type null should error the stream for gzip": {
12-
"status": 1
12+
"status": 0
1313
},
1414
"chunk of type null should error the stream for deflate": {
15-
"status": 1
15+
"status": 0
1616
},
1717
"chunk of type null should error the stream for deflate-raw": {
1818
"status": 1
1919
},
2020
"chunk of type numeric should error the stream for gzip": {
21-
"status": 1
21+
"status": 0
2222
},
2323
"chunk of type numeric should error the stream for deflate": {
24-
"status": 1
24+
"status": 0
2525
},
2626
"chunk of type numeric should error the stream for deflate-raw": {
2727
"status": 1
2828
},
2929
"chunk of type object, not BufferSource should error the stream for gzip": {
30-
"status": 1
30+
"status": 0
3131
},
3232
"chunk of type object, not BufferSource should error the stream for deflate": {
33-
"status": 1
33+
"status": 0
3434
},
3535
"chunk of type object, not BufferSource should error the stream for deflate-raw": {
3636
"status": 1
3737
},
3838
"chunk of type array should error the stream for gzip": {
39-
"status": 1
39+
"status": 0
4040
},
4141
"chunk of type array should error the stream for deflate": {
42-
"status": 1
42+
"status": 0
4343
},
4444
"chunk of type array should error the stream for deflate-raw": {
4545
"status": 1

0 commit comments

Comments
 (0)