Skip to content

Commit 1510211

Browse files
Constellationmnutt
authored andcommitted
[JSC] Update ArrayBuffer#resize's detach check timing
https://bugs.webkit.org/show_bug.cgi?id=259076 rdar://112041092 Reviewed by Mark Lam. Change the order of detach check according to the latest spec[1], but this only changes the type of error (from RangeError to TypeError). [1]: tc39/ecma262#3116 * JSTests/stress/arraybuffer-resizable-resize-update.js: Added. (shouldThrow): * Source/JavaScriptCore/runtime/JSArrayBufferPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): Canonical link: https://commits.webkit.org/265935@main
1 parent 6eb8d1e commit 1510211

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function shouldThrow(func, errorMessage) {
2+
var errorThrown = false;
3+
var error = null;
4+
try {
5+
func();
6+
} catch (e) {
7+
errorThrown = true;
8+
error = e;
9+
}
10+
if (!errorThrown)
11+
throw new Error('not thrown');
12+
if (String(error) !== errorMessage)
13+
throw new Error(`bad error: ${String(error)}`);
14+
}
15+
16+
let buffer = new ArrayBuffer(16, {maxByteLength: 16});
17+
shouldThrow(() => {
18+
buffer.resize({
19+
valueOf() {
20+
$.detachArrayBuffer(buffer);
21+
return 0;
22+
}
23+
});
24+
}, `TypeError: Receiver is detached`);

Source/JavaScriptCore/runtime/JSArrayBufferPrototype.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ JSC_DEFINE_HOST_FUNCTION(arrayBufferProtoFuncResize, (JSGlobalObject* globalObje
278278
if (UNLIKELY(!thisObject->impl()->isResizableOrGrowableShared()))
279279
return throwVMTypeError(globalObject, scope, "ArrayBuffer is not resizable"_s);
280280

281-
if (UNLIKELY(thisObject->impl()->isDetached()))
282-
return throwVMTypeError(globalObject, scope, "Receiver is detached"_s);
283-
284281
double newLength = callFrame->argument(0).toIntegerOrInfinity(globalObject);
285282
RETURN_IF_EXCEPTION(scope, { });
286283

284+
if (UNLIKELY(thisObject->impl()->isDetached()))
285+
return throwVMTypeError(globalObject, scope, "Receiver is detached"_s);
286+
287287
if (!std::isfinite(newLength) || newLength < 0)
288288
return throwVMRangeError(globalObject, scope, "new length is out of range"_s);
289289
size_t newByteLength = static_cast<size_t>(newLength);

0 commit comments

Comments
 (0)