Skip to content

Commit 75eda2b

Browse files
committed
Fixed ArrayBuffer with detached buffers.
1 parent 4c287fa commit 75eda2b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/njs_array_buffer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ njs_array_buffer_prototype_byte_length(njs_vm_t *vm, njs_value_t *args,
179179

180180
array = njs_array_buffer(value);
181181
if (njs_slow_path(njs_is_detached_buffer(array))) {
182-
njs_type_error(vm, "detached buffer");
183-
return NJS_ERROR;
182+
njs_set_number(retval, 0);
183+
return NJS_OK;
184184
}
185185

186186
njs_set_number(retval, array->size);
@@ -207,6 +207,11 @@ njs_array_buffer_prototype_slice(njs_vm_t *vm, njs_value_t *args,
207207
}
208208

209209
this = njs_array_buffer(value);
210+
if (njs_slow_path(njs_is_detached_buffer(this))) {
211+
njs_type_error(vm, "detached buffer");
212+
return NJS_ERROR;
213+
}
214+
210215
len = njs_array_buffer_size(this);
211216
end = len;
212217

src/test/njs_unit_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21574,9 +21574,9 @@ static njs_unit_test_t njs_backtraces_test[] =
2157421574

2157521575
{ njs_str("var ab = new ArrayBuffer(1);"
2157621576
"$262.detachArrayBuffer(ab);"
21577-
"ab.byteLength"),
21577+
"ab.slice(0)"),
2157821578
njs_str("TypeError: detached buffer\n"
21579-
" at ArrayBuffer.prototype.byteLength (native)\n"
21579+
" at ArrayBuffer.prototype.slice (native)\n"
2158021580
" at main (:1)\n") },
2158121581

2158221582
{ njs_str("Object.prototype()"),

0 commit comments

Comments
 (0)