Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -54334,7 +54334,7 @@ static JSValue js_array_buffer_slice(JSContext *ctx,
goto fail;
}
/* must test again because of side effects */
if (abuf->detached) {
if (abuf->detached || abuf->byte_length < start + new_len) {
JS_ThrowTypeErrorDetachedArrayBuffer(ctx);
goto fail;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/test_builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ function test_typed_array()
try {
new TypedArray(); // extensible but not instantiable
} catch (e) {
assert(e instanceof TypeError);
assert(/cannot be called/.test(e.message));
caught = true;
}
Expand All @@ -598,6 +599,25 @@ function test_typed_array()
assert(a[0], 42);
buffer.transfer();
assert(a[0], undefined);

// https://github.com/quickjs-ng/quickjs/issues/1210
var buffer = new ArrayBuffer(16, {maxByteLength: 16});
var desc = Object.getOwnPropertyDescriptor(ArrayBuffer, Symbol.species);
assert(typeof desc.get, "function");
var get = function() {
buffer.resize(1);
return ArrayBuffer;
};
Object.defineProperty(ArrayBuffer, Symbol.species, {...desc, get});
let ex;
try {
buffer.slice();
} catch (ex_) {
ex = ex_;
}
Object.defineProperty(ArrayBuffer, Symbol.species, desc); // restore
assert(ex instanceof TypeError);
assert("ArrayBuffer is detached", ex.message);
}

function test_json()
Expand Down