Repository navigation
Conversation
…ek phase 1) Phase 1 of #5135. dnsconfig.js now runs on github.com/grafana/sobek instead of github.com/robertkrimen/otto + github.com/xddxdd/ottoext. * pkg/js/js.go, hash.go: port the runtime and Go builtins to sobek. * pkg/js/eventloop.go: a small event loop for setTimeout, setInterval, setImmediate and their clear functions, and for completing async Go work on the runtime's goroutine. Promises are native to sobek. * pkg/js/fetch.go, fetch.js: fetch() (with --allow-fetch), with the same API and quirks as ottoext's. * pkg/js/underscore-min.js: underscore.js 1.13.7 (MIT, with its license), previously embedded by otto, stays available as _. * helpers.js: record filepos now comes from _filepos(), which reads sobek's call stack, instead of parsing otto's Error().stack text. The positions are unchanged. * helpers.js is in strict mode, which otto ignored and sobek enforces. Declare the locals it assigned without var, and delete getENotationInt, locStringBuilder and locDMSBuilder, which were unused (LOC is built in Go). strict_test.go checks helpers.js for assignments to undeclared variables. * Tidy engine error messages: drop sobek's bytecode offsets and Go frame names, and a doubled "SyntaxError:" prefix. The IR produced for every parse test, and for a 29,000-line config, is byte-for-byte identical to otto's. That config is about 4x faster. User-visible changes: dnsconfig.js may use ES2015+ (let/const, arrow functions, template literals, classes, async/await, ...) and full JavaScript regular expressions; most errors now say the file, line and column; records made in timer or Promise callbacks get a real filepos instead of "<unknown>".
Open
6 of 12 tasks
otto's JSON.stringify wrote object keys in sorted order; sobek writes them in the order the config declares them, as JavaScript requires. Provider metadata (NewRegistrar, NewDnsProvider and SERVICE options) is kept as raw JSON, so print-ir showed nested keys such as BIND's default_soa in a different order than before. Sort the keys of that raw JSON after reading the config. Numbers keep their exact text, and "&" and "<" are not escaped. TestParsedFiles compares decoded JSON, so it cannot see key order; add TestMetadataKeysSorted, which checks the raw bytes, and a parse test with unsorted nested metadata.
TomOnTime
added a commit
that referenced
this pull request
Nov 29, 2026
…5144) Prep for #5141 (otto→sobek, #5135). ## Problem Provider metadata (the options passed to `NewRegistrar`, `NewDnsProvider` and `SERVICE`) is stored in the IR as the raw JSON that `JSON.stringify` produces, so its key order depends on the JavaScript engine: - **otto** (current) writes object keys in sorted order. - **sobek** (#5141) keeps the order the config uses, as the JavaScript spec requires. On a real config, `print-ir` from the sobek build therefore showed BIND's `default_soa` keys in a different order (`… retry, expire, minttl` instead of `expire, …, minttl, …, retry`). The values were identical. ## Fix `sortMetadataKeys` (in `pkg/js/js.go`) sorts the keys of that raw JSON at every level after the config is read. Numbers keep their exact text (`UseNumber`), `&` and `<` stay unescaped, and arrays keep their order. **With otto this changes nothing.** It makes the existing behavior explicit, so #5141 keeps the IR identical. ## Tests - `TestMetadataKeysSorted` checks the **raw bytes** of registrar, provider and per-domain (`SERVICE`) metadata. `TestParsedFiles` can't catch this, because it compares decoded JSON. On the sobek branch, this test fails without the fix and passes with it. - New parse test `075-provider-meta-key-order`, with unsorted nested metadata. - `TestSortJSONKeys` covers nesting, number text, HTML characters and arrays. - `go test ./pkg/js` passes and `golangci-lint run ./pkg/js/...` reports 0 issues. After this merges, I'll update #5141 from `main` and drop its copy of this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Conflicts: # pkg/js/engine_test.go
Deprecate underscore.js (#5142). After loading it, replace the global _ with a Proxy that prints a warning the first time a config uses it (reads a property, as in _.each, or calls it, as in _(list)); typeof _ does not count. _ keeps working as before. It will be removed in a release on or after 2028-11-29. The warning goes to stderr, not the printer (stdout), so that "print-ir > ir.json" still writes valid JSON. Docs: the code-tricks.md loop example now uses forEach instead of _.each, and a new "Replacing underscore.js" section lists plain JavaScript equivalents. The warning links to that page.
Reported in #4371: otto provided a console object and let `this` reach the global object in strict-mode functions; sobek does neither. - Add a console object matching otto's (log/debug/info/warn/error print to stdout; dir/time/timeEnd/trace/assert are no-ops). - CLI_DEFAULTS uses globalThis instead of `this`, which is undefined in strict mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Issue
This is phase 1 of switching from otto to sobek as our JavaScript interpreter. Phase 0 added tests. Phase 2 will do cleanups.
Resolution
otto fully replaced by sobek.
What users will notice:
Notes
Phase 1 of #5135.
dnsconfig.jsnow runs on grafana/sobek instead ofrobertkrimen/otto+xddxdd/ottoext. Both of those are removed fromgo.mod.Equivalence
print-ir --prettywith the otto build (main) and the sobek build on all 73 parse-test configs, a generated 29,000-line config (300 domains), and a reproduction of the key-order case below. All 75 outputs match. All parse-test JSON fixtures are unchanged, including every record'sfilepos.JSON.stringifywrites object keys in sorted order, and sobek keeps the config's order, as JavaScript requires. Provider metadata is kept as raw JSON, soprint-irshowed nested keys such as BIND'sdefault_soain a different order. This was found on a real config. It's fixed separately in chore(js): sort provider metadata keys explicitly (otto→sobek prep) #5144 (merged tomain, and merged into this branch), which sorts those keys explicitly so the IR doesn't depend on the engine.TestMetadataKeysSortedfrom chore(js): sort provider metadata keys explicitly (otto→sobek prep) #5144 checks the raw bytes and passes here.What changed
ottoext/timers+ottoext/looppkg/js/eventloop.go: one goroutine, a timer heap, async completions delivered over a channel. Same minimum delays (4 ms, and 10 ms for intervals). IncludessetImmediate.ottoext/promise(a JS polyfill)fetch()(--allow-fetch)ottoext/fetchpkg/js/fetch.go+fetch.js: the sameHeaders/Request/ResponseAPI with the same quirks (okis always true,statusTextis like"200 OK",typeis undefined). The HTTP request runs on a goroutine and the Promise is resolved on the loop._pkg/js/underscore-min.js(1.13.7, the same file) plus its MIT license. Still available to user scripts, but deprecated: see below.fileposnew Error().stack(helpers.js said "this will certainly break if we change to a different Javascript interpreter")_filepos(), written in Go, reads the outermost frame from sobek's call stack. sobek sometimes reports a call at its(, so the column is moved back to the start of the callee, which is what otto reported.Things found along the way
"use strict", but otto ignored it. sobek enforces it, and 20 assignments to undeclared variables threwReferenceError(inTTL("1h"),SPF_BUILDER,CAA_BUILDER,LOC_BUILDER_*, …). I declared them withvar.SPF_BUILDER/CAA_BUILDERused to set the globalsrandp, which overwrote any user variables with those names.getENotationInt,locStringBuilder,locDMSBuilder) are dead code, because LOC is built in Go. I deleted them rather than make them strict-safe.strict_test.goparses helpers.js with sobek's parser and fails on any assignment to a variable that isn't declared in scope. In strict mode those only throw when the line runs, so ordinary tests can miss them.REVCOMPAT bad modetest from Phase 0 only passed because of test order: the mode is process-wide and can be set once. It now just requires an error.go test -race -count=5 ./pkg/jspasses.clearTimeoutdata race no longer exists, so the Phase 0 race skips are removed.User-visible changes (suggested release note)
dnsconfig.jscan use modern JavaScript:let/const, arrow functions, template literals, destructuring, spread, classes,async/await,Array.prototype.includes,Object.entries, and full JS regular expressions, including lookahead. otto rejected these.Errors now say where the problem is:
(anonymous): Line 4:1 Unexpected end of inputSyntaxError: Unexpected end of input at syntax.js:4:1ReferenceError: 'AA' is not definedReferenceError: AA is not defined at undefined.js:2:25throwin a user scriptcustom problemcustom problem at throwstr.js:2:1required fileFile throws.js: ReferenceError: 'undefinedThing' is not definedFile throws.js: ReferenceError: undefinedThing is not defined at f (throws.js:2:10)sobek's bytecode offsets (
:2:25(12)), Go frame names (at github.com/…require-fm (native)) and a doubledSyntaxError:prefix are stripped (cleanJSError).Records created inside
setTimeout/Promise callbacks now get a realfilepos. otto reported<unknown>.About 4× faster. The 29,000-line config takes 0.28 s for
check, down from 1.12 s.underscore.js deprecation (#5142)
_is now aProxyaround underscore. The first time a config uses it (reading a property like_.each, or calling_(list)), dnscontrol prints this once per run:typeof _doesn't trigger it, and neither do helpers.js or fetch. Configs that don't use_see nothing, and_itself behaves exactly as before.printerwrites to stdout, which would have put the warning in front of the JSON fromprint-ir > ir.json.code-tricks.mdloop example usesforEachinstead of_.each, and a new "Replacing underscore.js" section lists plain JavaScript equivalents._(underscore.js) in dnsconfig.js is deprecated and will be removed in a release on or after 2028-11-29. DNSControl now prints a warning when a configuration uses it. See "Replacing underscore.js" in the docs."TestUnderscoreDeprecationWarning(once per run; not fortypeof, helpers, or configs without_; also inside callbacks).Costs
dlclark/regexp2/v2,go-sourcemap, andgoogle/pprofas indirect dependencies.Left for Phase 2 (#5135)
fetchquirks (ok,statusText,type). These would be behavior changes.currentDirectory/configDirectorywith per-run state.PANICstill callsos.Exit.documentation/getting-started/typescript.mdstill recommends"lib": ["es5"].validateIntegersin helpers.js, which is also unused.Testing
go test ./...passesgo test -race -count=5 ./pkg/jspassesgolangci-lint run ./pkg/js/... ./commands/...reports 0 issueshelpers.jsandfetch.jsTestUnderscoreDeprecationWarning,TestModernSyntax,TestFilePos,TestErrorsNameTheFile,TestCleanJSError,TestHelpersNoUndeclaredAssignments🤖 Generated with Claude Code