The TypedArray buffer may be detached while evaluating custom
"separator" argument. The fix is to move the buffer check below this
point.
Found by Official ECMAScript Conformance Test Suite.
return NJS_OK;
}
+ if (njs_slow_path(njs_is_detached_buffer(array->buffer))) {
+ njs_type_error(vm, "detached buffer");
+ return NJS_ERROR;
+ }
+
njs_chb_init(&chain, vm->mem_pool);
length = njs_typed_array_to_chain(vm, &chain, array, separator);
" return a.map(q=>q/2).join('|') === '3|2|1'})"),
njs_str("true") },
+#ifdef NJS_TEST262
+ { njs_str("const arr = new Uint8Array([1,2,3]);"
+ "const sep = {toString(){$262.detachArrayBuffer(arr.buffer); return ','}};"
+ "arr.join(sep)"),
+ njs_str("TypeError: detached buffer") },
+#endif
+
{ njs_str("Uint8Array.prototype.reduce.call(1)"),
njs_str("TypeError: this is not a typed array") },