Repository navigation
Conversation
Array::internal_set_extensible set elems.len_writable to the new [[Extensible]] value and the Array code used len_writable as a stand-in for [[Extensible]]. So Object.preventExtensions made "length" read-only: pop, shift, splice and setting length threw a TypeError, and a hole could not be filled when only length was read-only. Keep the two flags apart: [[Extensible]] lives in the backing object's shape, and adding an element past the end, into a hole, or through the unshift fast path now checks it. Template objects set their length to read-only explicitly since they relied on the old behaviour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes bug 4 from #1002 (bugs 1-3 are in #1003).
Array::internal_set_extensiblesetelems.len_writableto the new[[Extensible]]value, and the Array code then usedlen_writableas a stand-in for[[Extensible]](for exampleordinary_define_own_property_for_arraycheckedelements.writable()for "If extensible is false"). SoObject.preventExtensions(arr)also madelengthread-only:shift,splice,a.length = 1,push()/unshift()with no items andpop()on an empty array all threw too. The reverse case was also wrong:[1, , 3]with onlylengthmade read-only could not fill the hole.Change
internal_set_extensibleno longer toucheslen_writable.[[Extensible]]stays in the backing object's shape, as for other objects.internal_extensible: defining an index ≥ length, defining into a hole, and theunshiftfast path (it grows the array directly).ElementsVector::writable(), which had no other users.get_template_objectrelied on the old behaviour to get a read-onlylengthfor the frozen template and raw arrays. It now callsset_length_readonlyaftertry_prevent_extensions, sotagged-template/template-object.jsstill passes.Testing
nova_vm/tests/array_tests.rsrunstests/sources/arrayPreventExtensions.test.js: pop/shift/splice/length changes work, while push/unshift/index assignment/definePropertypast the end or into a hole still fail. It fails onmainand passes here. Every case matches Node. The one exception is V8, which saysObject.isFrozen(Object.preventExtensions([]))istrue; JSC and QuickJS sayfalse, as the spec does, and so does Nova.staging/sm/Array/length-01.jsnow passes (expectations and metrics updated). No other result changed. I ran the full suite once, then re-ran Array, Object, Reflect, Proxy, class, template and staging/sm Array/Object after the template fix.cargo test,cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.