-
Notifications
You must be signed in to change notification settings - Fork 5k
node:domain: export constructible Domain class #39759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
95dbd43
b861c74
0f34f70
ff02959
fbbfcfd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,113 @@ const ObjectGetOwnPropertyNames = Object.getOwnPropertyNames; | |||||
| const { uncurryThis, SafeMap } = require("internal/primordials"); | ||||||
| const RegExpPrototypeExec = uncurryThis(RegExp.prototype.exec); | ||||||
|
|
||||||
| const ArrayPrototypePush = Array.prototype.push; | ||||||
| const ArrayPrototypeReverse = Array.prototype.reverse; | ||||||
|
|
||||||
| function areLinesEqual(actual, expected) { | ||||||
| return actual === expected; | ||||||
| } | ||||||
|
|
||||||
| // Myers diff (Node's internal/assert/myers_diff). Returns an array of | ||||||
| // [operation, value] pairs: -1 delete, 0 no-op, 1 insert. | ||||||
| function myersDiff(actual, expected) { | ||||||
| const actualLength = actual.length; | ||||||
| const expectedLength = expected.length; | ||||||
| const max = actualLength + expectedLength; | ||||||
| const v = new Int32Array(2 * max + 1); | ||||||
|
Comment on lines
+39
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '34,68p' src/js/node/util.ts
curl -fsSL https://raw.githubusercontent.com/nodejs/node/v24.11.0/lib/internal/assert/myers_diff.js | sed -n '32,45p'Repository: oven-sh/bun Length of output: 1643 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- util.ts imports and diff implementation ---'
sed -n '1,145p' src/js/node/util.ts
printf '%s\n' '--- ErrorCode usage in util.ts ---'
rg -n "ErrorCode|ERR_OUT_OF_RANGE|myersDiff|function diff|const diff" src/js/node/util.ts
printf '%s\n' '--- nearby callers and tests ---'
rg -n "myersDiff|diff\(" src test packages --glob '*.{ts,js,tsx,jsx}' | head -200Repository: oven-sh/bun Length of output: 12915 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- local internal myers diff ---'
sed -n '1,135p' src/js/internal/assert/myers_diff.ts
printf '%s\n' '--- util diff tests ---'
cat -n test/js/node/util/util-diff.test.ts
printf '%s\n' '--- error helper conventions ---'
rg -n '\$ERR_OUT_OF_RANGE\(' src/js/node src/js/internal | head -80
printf '%s\n' '--- upstream Node implementation ---'
curl -fsSL https://raw.githubusercontent.com/nodejs/node/v24.11.0/lib/internal/assert/myers_diff.js | sed -n '1,65p'
printf '%s\n' '--- Array.isArray capture conventions ---'
rg -n 'const (ArrayIsArray|ArrayIsArrayPrototype|ArrayIsArray)' src/js/node src/js/internal | head -80Repository: oven-sh/bun Length of output: 11429 Reject vector sizes outside the supported range. When 🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||
| const trace = []; | ||||||
|
|
||||||
| for (let diffLevel = 0; diffLevel <= max; diffLevel++) { | ||||||
| ArrayPrototypePush.call(trace, new Int32Array(v)); | ||||||
|
|
||||||
| for (let diagonalIndex = -diffLevel; diagonalIndex <= diffLevel; diagonalIndex += 2) { | ||||||
| const offset = diagonalIndex + max; | ||||||
| const previousOffset = v[offset - 1]; | ||||||
| const nextOffset = v[offset + 1]; | ||||||
| let x = | ||||||
| diagonalIndex === -diffLevel || (diagonalIndex !== diffLevel && previousOffset < nextOffset) | ||||||
| ? nextOffset | ||||||
| : previousOffset + 1; | ||||||
| let y = x - diagonalIndex; | ||||||
|
|
||||||
| while (x < actualLength && y < expectedLength && areLinesEqual(actual[x], expected[y])) { | ||||||
| x++; | ||||||
| y++; | ||||||
| } | ||||||
|
|
||||||
| v[offset] = x; | ||||||
|
|
||||||
| if (x >= actualLength && y >= expectedLength) { | ||||||
| return backtrack(trace, actual, expected); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| function backtrack(trace, actual, expected) { | ||||||
| const actualLength = actual.length; | ||||||
| const expectedLength = expected.length; | ||||||
| const max = actualLength + expectedLength; | ||||||
|
|
||||||
| let x = actualLength; | ||||||
| let y = expectedLength; | ||||||
| const result = []; | ||||||
|
|
||||||
| for (let diffLevel = trace.length - 1; diffLevel >= 0; diffLevel--) { | ||||||
| const v = trace[diffLevel]; | ||||||
| const diagonalIndex = x - y; | ||||||
| const offset = diagonalIndex + max; | ||||||
|
|
||||||
| let prevDiagonalIndex; | ||||||
| if ( | ||||||
| diagonalIndex === -diffLevel || | ||||||
| (diagonalIndex !== diffLevel && v[offset - 1] < v[offset + 1]) | ||||||
| ) { | ||||||
| prevDiagonalIndex = diagonalIndex + 1; | ||||||
| } else { | ||||||
| prevDiagonalIndex = diagonalIndex - 1; | ||||||
| } | ||||||
|
|
||||||
| const prevX = v[prevDiagonalIndex + max]; | ||||||
| const prevY = prevX - prevDiagonalIndex; | ||||||
|
|
||||||
| while (x > prevX && y > prevY) { | ||||||
| ArrayPrototypePush.call(result, [0, actual[x - 1]]); | ||||||
| x--; | ||||||
| y--; | ||||||
| } | ||||||
|
|
||||||
| if (diffLevel > 0) { | ||||||
| if (x > prevX) { | ||||||
| ArrayPrototypePush.call(result, [1, actual[--x]]); | ||||||
| } else { | ||||||
| ArrayPrototypePush.call(result, [-1, expected[--y]]); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return result; | ||||||
| } | ||||||
|
|
||||||
| function validateDiffInput(value, name) { | ||||||
| if (Array.isArray(value)) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Use a tamper-resistant array predicate. Line 116 resolves Proposed fix- if (Array.isArray(value)) {
+ if ($isArray(value)) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||
| for (let i = 0; i < value.length; i++) { | ||||||
| validateString(value[i], `${name}[${i}]`); | ||||||
| } | ||||||
| return; | ||||||
| } | ||||||
| validateString(value, name); | ||||||
| } | ||||||
|
|
||||||
| function diff(actual, expected) { | ||||||
| if (actual === expected) { | ||||||
| return []; | ||||||
| } | ||||||
| validateDiffInput(actual, "actual"); | ||||||
| validateDiffInput(expected, "expected"); | ||||||
| return ArrayPrototypeReverse.call(myersDiff(actual, expected)); | ||||||
| } | ||||||
|
|
||||||
| var cjs_exports; | ||||||
|
|
||||||
| function isBuffer(value) { | ||||||
|
|
@@ -698,6 +805,7 @@ cjs_exports = { | |||||
| debug: debuglog, | ||||||
| debuglog, | ||||||
| deprecate, | ||||||
| diff, | ||||||
| format, | ||||||
| styleText, | ||||||
| formatWithOptions, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4248,6 +4248,25 @@ JSC_DEFINE_HOST_FUNCTION(Process_stubEmptyFunction, (JSGlobalObject * globalObje | |
| return JSValue::encode(jsUndefined()); | ||
| } | ||
|
|
||
| JSC_DEFINE_CUSTOM_GETTER(processSourceMapsEnabled, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName)) | ||
| { | ||
| Zig::GlobalObject* globalObj = defaultGlobalObject(globalObject); | ||
| return JSValue::encode(jsBoolean(globalObj->processObject()->m_sourceMapsEnabled)); | ||
| } | ||
|
|
||
| JSC_DEFINE_CUSTOM_SETTER(setProcessSourceMapsEnabled, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::EncodedJSValue encodedValue, JSC::PropertyName propertyName)) | ||
| { | ||
| auto& vm = JSC::getVM(globalObject); | ||
| auto scope = DECLARE_THROW_SCOPE(vm); | ||
| JSValue value = JSValue::decode(encodedValue); | ||
| if (!value.isBoolean()) { | ||
| return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, "enabled"_s, "boolean"_s, value); | ||
| } | ||
| Zig::GlobalObject* globalObj = defaultGlobalObject(globalObject); | ||
| globalObj->processObject()->m_sourceMapsEnabled = value.toBoolean(globalObject); | ||
| return true; | ||
|
Comment on lines
+4257
to
+4267
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- target implementation ---'
sed -n '4225,4290p' src/jsc/bindings/BunProcess.cpp
printf '%s\n' '--- accessor registration ---'
sed -n '4895,4940p' src/jsc/bindings/BunProcess.cpp
printf '%s\n' '--- related symbols ---'
rg -n -C 3 'sourceMapsEnabled|setSourceMapsEnabled|setProcessSourceMapsEnabled|m_sourceMapsEnabled' src test tests 2>/dev/null || true
printf '%s\n' '--- review guidance files ---'
for f in REVIEW.md; do
if [ -f "$f" ]; then sed -n '1,240p' "$f"; fi
doneRepository: oven-sh/bun Length of output: 42021 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- binding table and surrounding setup ---'
sed -n '4820,4940p' src/jsc/bindings/BunProcess.cpp
printf '%s\n' '--- custom accessor declarations/usages ---'
rg -n -C 3 'CustomAccessor|JSC_DEFINE_CUSTOM_SETTER|setProcess.*Enabled|sourceMapsEnabled' src/jsc/bindings src | head -n 260
printf '%s\n' '--- focused regression test ---'
cat -n test/js/node/process/process-sourcemaps-enabled.test.ts
printf '%s\n' '--- Node compatibility guidance ---'
if [ -f .claude/docs/landing-prs.md ]; then
rg -n -C 5 'Node/Web compat|API design' .claude/docs/landing-prs.md | head -n 160
fiRepository: oven-sh/bun Length of output: 50367 🌐 Web query:
💡 Result: The Node.js Citations:
🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- analogous process accessors ---'
rg -n -C 8 'JSC_DEFINE_CUSTOM_(GETTER|SETTER)\((processTitle|processExitCode|processDebugPort|processArgv|processExecArgv)|^[[:space:]]+(title|exitCode|debugPort|argv|execArgv)[[:space:]]+' src/jsc/bindings/BunProcess.cpp
printf '%s\n' '--- generated binding artifacts tracked by git ---'
git ls-files '*Process*.lut.h' '*BunProcess*' | head -n 80
printf '%s\n' '--- standalone Node behavior ---'
if command -v node >/dev/null 2>&1; then
node - <<'JS'
const descriptor = Object.getOwnPropertyDescriptor(process, "sourceMapsEnabled");
console.log(JSON.stringify({
node: process.version,
descriptor: {
get: typeof descriptor?.get,
set: typeof descriptor?.set,
enumerable: descriptor?.enumerable,
configurable: descriptor?.configurable,
writable: descriptor?.writable,
valueType: typeof descriptor?.value,
},
before: process.sourceMapsEnabled,
}));
try {
process.sourceMapsEnabled = !process.sourceMapsEnabled;
console.log(JSON.stringify({
assignment: "completed",
after: process.sourceMapsEnabled,
}));
} catch (error) {
console.log(JSON.stringify({
assignment: "threw",
name: error?.name,
code: error?.code,
message: error?.message,
}));
}
JS
else
echo 'node executable unavailable'
fiRepository: oven-sh/bun Length of output: 10847 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- process LUT and binding-generation references ---'
rg --files | rg '(^|/)(Process[^/]*lut|.*lut.*|.*generate.*binding.*|.*bindings.*generate.*)$' | head -n 160
rg -n -C 4 'processObjectTable|CustomAccessor' --glob '!src/jsc/bindings/BunProcess.cpp' --glob '!vendor/**' . | head -n 260
printf '%s\n' '--- setter naming convention in generated-table inputs ---'
rg -n -C 3 '^[[:space:]]+[A-Za-z0-9_]+[[:space:]]+[A-Za-z0-9_]+[[:space:]]+CustomAccessor' src/jsc/bindings | head -n 160
printf '%s\n' '--- source map tests and descriptor assertions ---'
rg -n -C 5 'sourceMapsEnabled|setSourceMapsEnabled' test packages src | head -n 220Repository: oven-sh/bun Length of output: 50367 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
import re
from pathlib import Path
path = Path("src/jsc/bindings/BunProcess.cpp")
text = path.read_text()
table = text[text.index("`@begin` processObjectTable"):text.index("`@end`", text.index("`@begin` processObjectTable"))]
rows = []
for line in table.splitlines():
match = re.match(r"\s*([A-Za-z0-9_]+)\s+([A-Za-z0-9_]+)\s+CustomAccessor", line)
if match:
prop, getter = match.groups()
setter = "set" + prop[0].upper() + prop[1:]
rows.append((prop, getter, setter, setter in text))
for row in rows:
if row[0] in {"debugPort", "sourceMapsEnabled", "title"}:
print({
"property": row[0],
"getter": row[1],
"matching_setter": row[2],
"setter_symbol_declared": row[3],
})
PYRepository: oven-sh/bun Length of output: 531 🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
import re
from pathlib import Path
path = Path("src/jsc/bindings/BunProcess.cpp")
text = path.read_text()
start = text.index("`@begin` processObjectTable")
table = text[start:text.index("`@end`", start)]
for line in table.splitlines():
match = re.match(r"\s*(debugPort|sourceMapsEnabled|title)\s+([A-Za-z0-9_]+)\s+CustomAccessor", line)
if not match:
continue
prop, getter = match.groups()
setter = "setProcess" + prop[0].upper() + prop[1:]
print({
"property": prop,
"getter": getter,
"matching_setter": setter,
"setter_symbol_declared": bool(re.search(
rf"JSC_DEFINE_CUSTOM_SETTER\({re.escape(setter)}\b", text
)),
})
PY
printf '%s\n' '--- exact setter declarations ---'
rg -n 'JSC_DEFINE_CUSTOM_SETTER\(setProcess(DebugPort|SourceMapsEnabled|Title)\b' src/jsc/bindings/BunProcess.cppRepository: oven-sh/bun Length of output: 1114 Expose Remove 🤖 Prompt for AI AgentsSource: MCP tools |
||
| } | ||
|
|
||
| JSC_DEFINE_HOST_FUNCTION(Process_setSourceMapsEnabled, (JSC::JSGlobalObject * lexicalGlobalObject, JSC::CallFrame* callFrame)) | ||
| { | ||
| Zig::GlobalObject* globalObject = defaultGlobalObject(lexicalGlobalObject); | ||
|
|
@@ -4901,6 +4920,7 @@ extern "C" void Process__emitErrorEvent(Zig::GlobalObject* global, EncodedJSValu | |
| send constructProcessSend PropertyCallback | ||
| setSourceMapsEnabled Process_setSourceMapsEnabled Function 1 | ||
| setUncaughtExceptionCaptureCallback Process_setUncaughtExceptionCaptureCallback Function 1 | ||
| sourceMapsEnabled processSourceMapsEnabled CustomAccessor | ||
| stderr constructStderr PropertyCallback | ||
| stdin constructStdin PropertyCallback | ||
| stdout constructStdout PropertyCallback | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 571
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 5802
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 3161
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 2009
Make
Domaininstances preserve theDomainprototype.new Domain()currently returns anEventEmitterfromcreateDomain(). Therefore,d instanceof Domainis false andDomain.prototype.runis undefined. Refactor shared initialization sonew Domain(),create(), andcreateDomain()return actualDomaininstances while retainingEventEmitterbehavior. Test instance identity for all three entry points.🤖 Prompt for AI Agents