refactor: six duplication consolidations from the hygiene backlog#1268
Merged
Conversation
…ons parse The SHA-family digest switch was inlined 4x (pbkdf2Sync/hkdfSync + the async pbkdf2/hkdf) and the scrypt N/r/p options parse (incl. the power-of-2 check) 2x. Now ParseKdfDigest (deliberately narrower than CryptoAlgorithms.ParseHashName — the .NET KDF primitives take only the SHA family) and ParseScryptOptions, with the per-API error-message prefixes preserved. 447 crypto tests pass.
…ubclass factories CloneTypedArray dispatched through two 11-arm typeName switches hard-coding every SharpTS*Array constructor, even though the source is already a concrete SharpTSTypedArray whose virtual CreateView factories encode the same mapping. Internal CreateViewFrom bridges expose those factories; both switches (and their DataCloneError default arms, which were unreachable for a real instance) are gone. A future element type can no longer silently miss the clone path. 268 clone/typed-array/worker tests pass.
…drivers CompileModuleFile and CompileSingleFile duplicated the ~70-line emission tail verbatim (temp-DLL + Guid path, ILCompiler construction, Save, --verify, AppHost single-file bundling with the explicit-bundler error handler, runtimeconfig generation, SharpTS.dll/external-reference co-location) — a bundling or co-location fix could land in one copy only. Both now route through EmitCompiledAssembly, which takes the one differing step (CompileModules vs Compile) as a delegate. Smoke-verified both branches end-to-end: --compile to DLL runs via dotnet; --compile --target exe bundles (built-in bundler) and the EXE runs.
…ver ladder The three built-ins each hand-rolled the same ordered 8-branch receiver dispatch (object, hole-skipping array, class instance, plain dictionary, Math singleton #288, function/arrow expandos #314, other callables, throw), differing only in the projection. One EnumerateOwnEnumerable iterator now encodes the ladder; keys/values/entries project key, value, or [key, value] pair. ~150 lines to ~85, and the array hole-skip loop exists once. 191 Object/lodash tests pass.
…serializers
StringifyDictionary/StringifyObject/StringifyInstance were ~65-line
copies (a comment admitted it) of the same body: circular seen-guard,
empty-{} shortcut, pretty stepIndent, per-entry mark/serialize/
rewind-on-undefined, finally-remove. One StringifyJsonObject core now
takes (keys, read); keys are snapshot up front and values read lazily —
the spec's OwnPropertyKeys-then-Get order — which also drops
StringifyObject's filtered-Dictionary allocation on the allowedKeys
path. ~195 lines to ~95. 193 JSON tests pass; Test262 built-ins/JSON is
in the baseline run below.
…d extraction FromObject / FromAnyObject(reflection) / FromDictionary / FromIDictionary each hand-repeated the value/get/set/writable/enumerable/configurable extraction (~35 lines apiece, with visible probe drift). One Populate (has, read) core now runs it; each variant supplies only its probe/read pair. FromObject keeps its HasProperty-OR-HasSetter probe on the value/get/set arms — the #801 omitted-vs-explicitly-undefined distinction that feeds defineProperty/decorators. 171 descriptor/ decorator tests pass.
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.
Continues the audit backlog after #1266/#1267. Six independent consolidations, one commit each, all behavior-preserving:
Runtime
EnumerateOwnEnumerableiterator now encodes it; each built-in is a 3-line projection. The array hole-skip loop exists once.StringifyDictionary/StringifyObject/StringifyInstancewere ~65-line copies (the code commented on its own duplication). OneStringifyJsonObject(keys, read)core keeps the circular guard /{}shortcut / pretty indent / rewind-on-undefined dance; keys snapshot + lazyGetmatches the spec's OwnPropertyKeys-then-Get order and drops the filtered-Dictionary allocation.Populate(has, read)core, with FromObject keeping its HasProperty-OR-HasSetter probe (Object.defineProperty/ToPropertyDescriptor doesn't read a descriptor object's INHERITED fields through its prototype #801 omitted-vs-explicitly-undefined).CreateViewfactories via internal bridges, so the typed-array subclass set is the single source of that mapping.ParseKdfDigestis deliberately narrower thanCryptoAlgorithms.ParseHashName— the .NET KDF primitives take only the SHA family); per-API error prefixes preserved.CLI
CompileModuleFile/CompileSingleFileduplicated the ~70-line EXE/DLL emission tail verbatim (temp-DLL, Save, --verify, AppHost bundling + explicit-bundler error handler, runtimeconfig, SharpTS.dll co-location). Both now route throughEmitCompiledAssemblywith the one differing compile step as a delegate. Smoke-verified end-to-end:--compileto DLL runs under dotnet;--compile --target exebundles (built-in bundler) and the EXE runs.Verification
built-ins/JSONandbuilt-ins/Object, directly covering the two riskiest items)