Skip to content

Commit 098b0b7

Browse files
committed
[GR-31575] Implementation of Resizable and Growable ArrayBuffers proposal.
PullRequest: js/3158
2 parents 5e3f1be + 25102e2 commit 098b0b7

32 files changed

+745
-409
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ See [release calendar](https://www.graalvm.org/release-calendar/) for release da
99
* Implemented the [Make eval-introduced global vars redeclarable](https://github.com/tc39/proposal-redeclarable-global-eval-vars) proposal.
1010
* Implemented the [Float16Array](https://github.com/tc39/proposal-float16array) proposal. It is available in ECMAScript staging mode (`--js.ecmascript-version=staging`).
1111
* Implemented the [Array.fromAsync](https://github.com/tc39/proposal-array-from-async) proposal. It is available in ECMAScript staging mode (`--js.ecmascript-version=staging`).
12+
* Implemented the [Resizable and Growable ArrayBuffers](https://github.com/tc39/proposal-resizablearraybuffer) proposal. It is available in ECMAScript staging mode (`--js.ecmascript-version=staging`).
1213
* Updated Node.js to version 20.13.1.
1314

1415
## Version 24.0.0

graal-js/src/com.oracle.truffle.js.test.external/src/com/oracle/truffle/js/test/external/test262/Test262Runnable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ public class Test262Runnable extends TestRunnable {
250250
"regexp-named-groups",
251251
"regexp-unicode-property-escapes",
252252
"regexp-v-flag",
253+
"resizable-arraybuffer",
253254
"rest-parameters",
254255
"set-methods",
255256
"string-trimming",
@@ -265,7 +266,6 @@ public class Test262Runnable extends TestRunnable {
265266
"IsHTMLDDA",
266267
"explicit-resource-management",
267268
"regexp-modifiers",
268-
"resizable-arraybuffer",
269269
"tail-call-optimization",
270270
});
271271
private static final Set<String> STAGING_FEATURES = featureSet(new String[]{
@@ -282,6 +282,7 @@ public class Test262Runnable extends TestRunnable {
282282
"decorators",
283283
"json-parse-with-source",
284284
"promise-with-resolvers",
285+
"resizable-arraybuffer",
285286
});
286287

287288
public Test262Runnable(TestSuite suite, TestFile testFile) {

graal-js/src/com.oracle.truffle.js.test.external/src/com/oracle/truffle/js/test/external/testv8/TestV8Runnable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public class TestV8Runnable extends TestRunnable {
9393
"--experimental-wasm-stringref",
9494
"--experimental-wasm-type-reflection",
9595
"--expose-fast-api",
96-
"--harmony-rab-gsab",
9796
"--harmony-struct",
9897
"--wasm-test-streaming"
9998
});
@@ -103,6 +102,7 @@ public class TestV8Runnable extends TestRunnable {
103102
"--harmony-array-grouping",
104103
"--harmony-intl-locale-info-func",
105104
"--harmony-json-parse-with-source",
105+
"--harmony-rab-gsab",
106106
"--harmony-shadow-realm",
107107
"--harmony-weak-refs-with-cleanup-some",
108108
"--js-promise-withresolvers",

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ArrayBufferPrototypeBuiltins.java

Lines changed: 164 additions & 58 deletions
Large diffs are not rendered by default.

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ArrayIteratorPrototypeBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected JSObject doArrayIterator(VirtualFrame frame, JSArrayIteratorObject ite
126126
long length;
127127
if (isTypedArrayProfile.profile(this, JSArrayBufferView.isJSArrayBufferView(array))) {
128128
JSTypedArrayObject typedArray = (JSTypedArrayObject) array;
129-
if (JSArrayBufferView.hasDetachedBuffer(typedArray, getContext())) {
129+
if (JSArrayBufferView.isOutOfBounds(typedArray, getContext())) {
130130
errorBranch.enter(this);
131131
throw Errors.createTypeError("Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer");
132132
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ArrayPrototypeBuiltins.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,10 @@ protected final ArraySpeciesConstructorNode getArraySpeciesConstructorNode() {
432432
return arraySpeciesCreateNode;
433433
}
434434

435-
protected final void checkHasDetachedBuffer(JSDynamicObject view) {
436-
if (JSArrayBufferView.hasDetachedBuffer(view, getContext())) {
435+
protected final void checkOutOfBounds(JSTypedArrayObject view) {
436+
if (JSArrayBufferView.isOutOfBounds(view, getContext())) {
437437
errorBranch.enter();
438-
throw Errors.createTypeErrorDetachedBuffer();
438+
throw Errors.createTypeErrorOutOfBoundsTypedArray();
439439
}
440440
}
441441

@@ -448,9 +448,9 @@ protected final JSTypedArrayObject validateTypedArray(Object obj) {
448448
throw Errors.createTypeErrorArrayBufferViewExpected();
449449
}
450450
JSTypedArrayObject typedArrayObject = (JSTypedArrayObject) obj;
451-
if (JSArrayBufferView.hasDetachedBuffer(typedArrayObject, getContext())) {
451+
if (JSArrayBufferView.isOutOfBounds(typedArrayObject, getContext())) {
452452
errorBranch.enter();
453-
throw Errors.createTypeErrorDetachedBuffer();
453+
throw Errors.createTypeErrorOutOfBoundsTypedArray();
454454
}
455455
return typedArrayObject;
456456
}
@@ -523,9 +523,9 @@ public final JSTypedArrayObject typedArrayCreate(Object constr, Object... args)
523523
throw Errors.createTypeErrorArrayBufferViewExpected();
524524
}
525525
JSTypedArrayObject newTypedArray = (JSTypedArrayObject) newObject;
526-
if (JSArrayBufferView.hasDetachedBuffer(newTypedArray, context)) {
526+
if (JSArrayBufferView.isOutOfBounds(newTypedArray, context)) {
527527
errorBranch.enter();
528-
throw Errors.createTypeErrorDetachedBuffer();
528+
throw Errors.createTypeErrorOutOfBoundsTypedArray();
529529
}
530530
if (args.length == 1 && JSRuntime.isNumber(args[0])) {
531531
if (newTypedArray.getLength() < JSRuntime.doubleValue((Number) args[0])) {
@@ -1002,7 +1002,8 @@ protected Object sliceGeneric(Object thisObj, Object begin, Object end,
10021002
Object resultArray = getArraySpeciesConstructorNode().createEmptyContainer(thisArrayObj, size);
10031003
if (sizeIsZero.profile(this, size > 0)) {
10041004
if (isTypedArrayImplementation) {
1005-
checkHasDetachedBuffer((JSDynamicObject) thisObj);
1005+
checkOutOfBounds((JSTypedArrayObject) thisObj);
1006+
endPos = Math.min(endPos, getLength(thisArrayObj));
10061007
}
10071008
forEachIndexCall(thisArrayObj, null, startPos, startPos, endPos, resultArray);
10081009
}
@@ -3065,7 +3066,8 @@ protected Object copyWithin(Object thisObj, Object target, Object start, Object
30653066
long expectedCount = count;
30663067
if (count > 0) {
30673068
if (isTypedArrayImplementation) {
3068-
checkHasDetachedBuffer((JSDynamicObject) thisObj);
3069+
checkOutOfBounds((JSTypedArrayObject) thisObj);
3070+
len = getLength(obj);
30693071
}
30703072

30713073
long direction;
@@ -3079,6 +3081,9 @@ protected Object copyWithin(Object thisObj, Object target, Object start, Object
30793081

30803082
while (count > 0) {
30813083
if (isTypedArrayImplementation || hasProperty(obj, from)) {
3084+
if (isTypedArrayImplementation && (from >= len || to >= len)) {
3085+
break;
3086+
}
30823087
Object fromVal = read(obj, from);
30833088
write(obj, to, fromVal);
30843089
} else {
@@ -3425,14 +3430,15 @@ protected Object withGeneric(Object thisObj, Object index, Object valueParam) {
34253430
}
34263431

34273432
if (isTypedArrayImplementation) {
3428-
if (JSArrayBufferView.isJSArrayBufferView(array) && JSArrayBufferView.isBigIntArrayBufferView((JSDynamicObject) array)) {
3433+
if (JSArrayBufferView.isBigIntArrayBufferView((JSDynamicObject) array)) {
34293434
value = toBigInt(value);
34303435
} else {
34313436
value = toNumber(value);
34323437
}
34333438
}
34343439

3435-
if (actualIndex >= len || actualIndex < 0) {
3440+
long lengthForCheck = isTypedArrayImplementation ? (JSArrayBufferView.isOutOfBounds((JSTypedArrayObject) array, getContext()) ? 0 : getLength(thisObj)) : len;
3441+
if (actualIndex >= lengthForCheck || actualIndex < 0) {
34363442
errorBranch.enter();
34373443
throw Errors.createRangeError("invalid index");
34383444
}

0 commit comments

Comments
 (0)