Skip to content

Commit

Permalink
[GR-62027] Fixes of the setting/testing of the integrity level.
Browse files Browse the repository at this point in the history
PullRequest: js/3413
  • Loading branch information
iamstolis committed Feb 9, 2025
2 parents a4375db + 4ce91e7 commit 12493aa
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
*/

load("assert.js");

[[], new Array(100)].forEach(function (array) {
assertFalse(Object.isSealed(array));
assertFalse(Object.isFrozen(array));

Object.preventExtensions(array);

assertTrue(Object.isSealed(array));
assertFalse(Object.isFrozen(array)); // length is writable still

Object.defineProperty(array, 'length', { writable: false });

assertTrue(Object.isSealed(array));
assertTrue(Object.isFrozen(array));
});

var array = [,42];
Object.preventExtensions(array);
assertFalse(Object.isSealed(array)); // has array[1]
assertFalse(Object.isFrozen(array));
delete array[1];
assertTrue(Object.isSealed(array));
assertFalse(Object.isFrozen(array)); // length is writable still
Object.defineProperty(array, 'length', { length: 2, writable: false });
assertTrue(Object.isSealed(array));
assertTrue(Object.isFrozen(array));
18 changes: 9 additions & 9 deletions graal-js/src/com.oracle.truffle.js.test/js/object_freeze_seal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
Expand Down Expand Up @@ -82,15 +82,15 @@ assertTrue(Object.isExtensible(ta));
assertFalse(Object.isSealed(ta));
assertFalse(Object.isFrozen(ta));

Object.seal(ta);
try { Object.seal(ta); } catch {}
assertFalse(Object.isExtensible(ta));
assertTrue(Object.isSealed(ta));
assertFalse(Object.isSealed(ta));
assertFalse(Object.isFrozen(ta));
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "0")), `{"value":0,"writable":true,"enumerable":true,"configurable":true}`);

try { Object.freeze(ta); } catch {}
assertFalse(Object.isExtensible(ta));
assertTrue(Object.isSealed(ta));
assertFalse(Object.isSealed(ta));
assertFalse(Object.isFrozen(ta));
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "0")), `{"value":0,"writable":true,"enumerable":true,"configurable":true}`);

Expand All @@ -101,16 +101,16 @@ assertTrue(Object.isExtensible(ta));
assertFalse(Object.isSealed(ta));
assertFalse(Object.isFrozen(ta));

Object.seal(ta);
try { Object.seal(ta); } catch {}
assertFalse(Object.isExtensible(ta));
assertTrue(Object.isSealed(ta));
assertFalse(Object.isSealed(ta));
assertFalse(Object.isFrozen(ta));
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "0")), `{"value":0,"writable":true,"enumerable":true,"configurable":true}`);
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "x")), `{"value":42,"writable":true,"enumerable":true,"configurable":false}`);
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "x")), `{"value":42,"writable":true,"enumerable":true,"configurable":true}`);

try { Object.freeze(ta); } catch {}
assertFalse(Object.isExtensible(ta));
assertTrue(Object.isSealed(ta));
assertFalse(Object.isSealed(ta));
assertFalse(Object.isFrozen(ta));
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "0")), `{"value":0,"writable":true,"enumerable":true,"configurable":true}`);
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "x")), `{"value":42,"writable":true,"enumerable":true,"configurable":false}`);
assertEqual(JSON.stringify(Object.getOwnPropertyDescriptor(ta, "x")), `{"value":42,"writable":true,"enumerable":true,"configurable":true}`);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -107,7 +107,8 @@ public final void setArray(Object array) {
@Override
public final boolean testIntegrityLevel(boolean frozen) {
DynamicArray array = (DynamicArray) getArrayType();
boolean arrayIs = frozen ? array.isFrozen() : array.isSealed();
boolean arrayIs = (frozen ? array.isFrozen() : array.isSealed()) ||
(!array.isExtensible() && array.firstElementIndex(this) > array.lastElementIndex(this));
return arrayIs && JSNonProxy.testIntegrityLevelFast(this, frozen);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -532,9 +532,18 @@ public static boolean setIntegrityLevelFast(JSDynamicObject thisObj, boolean fre
public static boolean testIntegrityLevelFast(JSDynamicObject obj, boolean frozen) {
int objectFlags = JSDynamicObject.getObjectFlags(obj);
if (frozen) {
return (objectFlags & JSShape.FROZEN_FLAG) != 0;
if ((objectFlags & JSShape.FROZEN_FLAG) != 0) {
return true;
}
} else {
return (objectFlags & JSShape.SEALED_FLAG) != 0;
if ((objectFlags & JSShape.SEALED_FLAG) != 0) {
return true;
}
}
if ((objectFlags & JSShape.NOT_EXTENSIBLE_FLAG) != 0) {
return testSealedProperties(obj) && (!frozen || testFrozenProperties(obj));
} else {
return false;
}
}

Expand Down Expand Up @@ -565,10 +574,12 @@ public static boolean ordinaryPreventExtensions(JSDynamicObject thisObj, int ext
return true;
}

@TruffleBoundary
private static boolean testSealedProperties(JSDynamicObject thisObj) {
return JSDynamicObject.testProperties(thisObj, p -> p.isHidden() || (p.getFlags() & JSAttributes.NOT_CONFIGURABLE) != 0);
}

@TruffleBoundary
private static boolean testFrozenProperties(JSDynamicObject thisObj) {
return JSDynamicObject.testProperties(thisObj, p -> p.isHidden() || (p.getFlags() & JSProperty.ACCESSOR) != 0 || (p.getFlags() & JSAttributes.NOT_WRITABLE) != 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -180,7 +180,7 @@ public boolean isArrayElementInsertable(@SuppressWarnings("unused") long index)

@Override
public boolean testIntegrityLevel(boolean frozen) {
if (frozen && getArraySize() > 0) {
if (getArraySize() > 0) {
return false;
}
return JSNonProxy.testIntegrityLevelFast(this, frozen);
Expand All @@ -189,7 +189,7 @@ public boolean testIntegrityLevel(boolean frozen) {
@Override
public boolean setIntegrityLevel(boolean freeze, boolean doThrow) {
preventExtensions(doThrow);
if (freeze && getArraySize() > 0) {
if (getArraySize() > 0) {
throw Errors.createTypeErrorCannotRedefineTypedArrayElement();
}
JSNonProxy.setIntegrityLevelFast(this, freeze);
Expand Down
16 changes: 4 additions & 12 deletions graal-js/test/test262.json
Original file line number Diff line number Diff line change
Expand Up @@ -3644,6 +3644,10 @@
"COMPILE_IMMEDIATELY" : "SKIP"
},
"comment" : "Long-running in compile mode"
}, {
"filePath" : "staging/built-ins/Object/seal/seal-variable-length-typed-arrays.js",
"status" : "FAIL",
"comment" : "Off-spec: expects Object.seal(fixed length TA backed by GSAB) not to throw. It throws because it has configurable integer properties that cannot be redefined to be non-configurable."
}, {
"filePath" : "staging/Intl402/Temporal/old/addition-across-lunisolar-leap-months.js",
"status" : "FAIL",
Expand Down Expand Up @@ -3978,10 +3982,6 @@
"minVersion" : 24
},
"comment" : "requires Unicode 16.0"
}, {
"filePath" : "staging/sm/Symbol/property-reflection.js",
"status" : "FAIL",
"comment" : "new failures 2025-01-23"
}, {
"filePath" : "staging/sm/Temporal/Calendar/compare-to-datetimeformat.js",
"status" : "FAIL",
Expand Down Expand Up @@ -4040,10 +4040,6 @@
"minVersion" : 16
},
"comment" : "expects uint8array-base64 to be enabled"
}, {
"filePath" : "staging/sm/TypedArray/seal-and-freeze.js",
"status" : "FAIL",
"comment" : "new failures 2025-01-23"
}, {
"filePath" : "staging/sm/TypedArray/sort-negative-nan.js",
"ecmaVersion" : {
Expand All @@ -4060,10 +4056,6 @@
"filePath" : "staging/sm/TypedArray/test-integrity-level-detached.js",
"status" : "FAIL",
"comment" : "new failures 2025-01-23"
}, {
"filePath" : "staging/sm/TypedArray/test-integrity-level.js",
"status" : "FAIL",
"comment" : "new failures 2025-01-23"
}, {
"filePath" : "staging/sm/TypedArray/toString.js",
"ecmaVersion" : {
Expand Down
8 changes: 8 additions & 0 deletions graal-js/test/testV8.json
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@
}, {
"filePath" : "mjsunit/number-tostring-big-integer.js",
"status" : "FAIL"
}, {
"filePath" : "mjsunit/object-seal.js",
"status" : "FAIL",
"comment" : "Obsolete test, see https://github.com/v8/v8/commit/58fe43dd2fbb2b3c4fad55f8c40bd0daa78612a7#diff-8c4973d7623f46ba59c9c0fa41083040ac0b33cf160ebfc89ecf2151f12309a1"
}, {
"filePath" : "mjsunit/opt-elements-kind.js",
"status" : "SKIP",
Expand Down Expand Up @@ -1363,6 +1367,10 @@
"filePath" : "mjsunit/regress/regress-948307.js",
"runInIsolation" : true,
"comment" : "test with (expected) high memory usage that might influence other tests"
}, {
"filePath" : "mjsunit/regress/regress-95920.js",
"status" : "FAIL",
"comment" : "Obsolete test, see https://github.com/v8/v8/commit/58fe43dd2fbb2b3c4fad55f8c40bd0daa78612a7#diff-3463c63ce3409b70aa17c9e8cd3af8429d2dd1764c57219229b28d3f6aa31d6e"
}, {
"filePath" : "mjsunit/regress/regress-crbug-100859.js",
"runInIsolation" : true,
Expand Down

0 comments on commit 12493aa

Please sign in to comment.