testing - #147
testing#147gurpreet319 wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical and moderate timer-wrapper issues remain.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Updates the JSDOM compatibility layer with enhanced timer wrappers and callback invocation support.
Changes:
- Adds reusable timer and clear-timer wrappers.
- Forwards callback arguments and logs callback errors.
- Supports
.call,.apply, and.bind.
File summaries
| File | Summary and findings |
|---|---|
src/jsc/modules/linkedjsdomwrapper.js |
Implements timer wrappers. Critical (1 vote): captures undefined JSDOM timer properties. Moderate (1 vote): removes empty-ID guards, causing spurious warnings. |
Review details
Suppressed comments (3)
src/jsc/modules/linkedjsdomwrapper.js:292
- This catch logs but swallows exceptions from timer callbacks. For
setInterval, the native dispatch therefore sees a successful wrapper and reschedules it, so a throwing callback repeats indefinitely and is no longer reported through normal JavaScript exception handling. Re-throw after logging (or otherwise cancel the repeating timer) to preserve callback failure semantics.
} catch (e) {
console.error(
"Timer callback error:",
e
src/jsc/modules/linkedjsdomwrapper.js:318
Function.prototype.applysupports an arbitrary number of timer arguments, and the native binding already forwards all arguments after the callback and delay. This new branch makes calls with more than five total arguments throw synchronously, so valid callbacks with additional parameters cannot be scheduled. Delegate to the originalFunction.prototype.applyinstead of imposing this limit.
default:
throw new Error(
"setTimeout/setInterval.apply: too many arguments"
);
}
src/jsc/modules/linkedjsdomwrapper.js:354
- The old clear wrappers skipped null/undefined IDs, but all four paths here now call the native binding directly. That binding logs a warning for an empty ID (
src/jsc/JavaScriptUtils.cpp:476-482), andnode-fetchcallsclearTimeout(reqTimeout)even when no request timeout was configured (src/jsc/modules/node-fetch.js:2574-2577), so ordinary failed requests will emit spurious warning logs. Restore the empty-ID guard and routeapply/call/bindthrough the guarded wrapper.
var wrapper = function (id) {
return nativeFn(id);
};
wrapper.apply = function (thisArg, args) {
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Four moderate issues must be addressed before approval.
Review details
Suppressed comments (4)
Previously missed (2) — in code that hasn't changed since the last review.
src/jsc/modules/linkedjsdomwrapper.js:280
createTimerWrapperhides the native argument validation by always passing its own closure tonativeFn. As a result,setTimeout(null, ...),setInterval(undefined, ...), and similar calls return a timer ID and silently no-op ininvokeCallback, whereas the native binding rejects non-function callbacks (JavaScriptUtils.cpp:422-429). Validate the callback before scheduling so invalid inputs do not appear to succeed.
src/jsc/modules/linkedjsdomwrapper.js:317- This artificial five-argument limit makes valid timer calls fail: the native binding explicitly accepts every argument after the delay and the wrapper itself stores arbitrary callback arguments.
wrapper.callandwrapper.bindalso reach this branch throughwrapper.apply, so callers passing six or more total timer arguments get a synchronous exception.
src/jsc/modules/linkedjsdomwrapper.js:366
- The returned bound clear function discards the arguments bound after
thisArg. ThereforeclearTimeout.bind(null, timerId)()(and the equivalentclearIntervalcall) invokesnativeFn(undefined)instead of clearingtimerId. Capture the bound arguments and pass them through when the returned function is called.
wrapper.bind = function () {
return function (id) {
return nativeFn(id);
};
};
src/jsc/modules/linkedjsdomwrapper.js:375
- This IIFE is invoked as
(window), so these assignments only replace the timers on the JSDOMwindow; the baresetTimeout/setInterval/clear functions installed on the execution global remain the native bindings. Consequently, callers usingsetTimeout.apply/call/bindor the new callback/error behavior through the global APIs do not receive this wrapper, unlike the old implementation. Install the same wrapped functions onglobalThisas well as onwindow.
global.setTimeout =
createTimerWrapper(nativeSetTimeout);
global.setInterval =
createTimerWrapper(nativeSetInterval);
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved timer-wrapper defects and the unrelated generated artifact must be addressed.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 4
- Review effort level: Lite
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved timer-wrapper defects and an unrelated history dump must be addressed.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (1)
src/jsc/modules/linkedjsdomwrapper.js:225
- These values are read from
window, but in the full JSDOM path the native timer bindings are installed on the execution global (JavaScriptContext::add), while the JSDOMwindowobject has no timer properties before this IIFE. Consequently all newly installed wrappers callundefinedforsetTimeout/setInterval(and the clear functions), so any timer used after this file throws. Capture the native functions from the execution-global bindings before replacing them.
var nativeSetTimeout = global.setTimeout;
var nativeClearTimeout = global.clearTimeout;
var nativeSetInterval = global.setInterval;
var nativeClearInterval = global.clearInterval;
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
| // Fixed bind() to preserve bound arguments | ||
| wrapper.bind = function (thisArg) { | ||
|
|
||
| var boundArgs = | ||
| Array.prototype.slice.call(arguments, 1); | ||
|
|
||
| return function () { | ||
|
|
||
| var args = boundArgs.concat( | ||
| Array.prototype.slice.call(arguments) | ||
| ); | ||
|
|
||
| return nativeFn.apply( | ||
| null, | ||
| args | ||
| ); | ||
| }; |
There was a problem hiding this comment.
🟡 Changes recommended
Three unresolved moderate timer-wrapper issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (2)
src/jsc/modules/linkedjsdomwrapper.js:225
utils.jsinitializesglobalas a separate empty object (utils/utils.js:20), while the native timer bindings are installed on the execution global inJavaScriptContext::registerUtils(src/jsc/JavaScriptContext.cpp:408-411). Consequently all four values captured here areundefined, and every wrapped timer later throws when it callsnativeFn(...); capture the native functions from the execution global (or the bare timer names) instead ofglobal/the JSDOM window.
var nativeSetTimeout = global.setTimeout;
var nativeClearTimeout = global.clearTimeout;
var nativeSetInterval = global.setInterval;
var nativeClearInterval = global.clearInterval;
src/jsc/modules/linkedjsdomwrapper.js:328
- The captured timer bindings are
rtFunctionWrapperhost-callable objects, not ordinary JavaScript functions (src/jsc/JavaScriptWrapper.cpp:195-223), so they do not provide the.applymethod this call assumes. As a result,clearTimeout.bind(...)()andclearInterval.bind(...)()throw instead of clearing the timer; invoke the native clear function directly with the first bound argument (the native API only consumes one id).
return nativeFn.apply(
null,
args.length ? args : [undefined]
);
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
| function invokeCallback(callback, args) { | ||
| callback.apply(global, args); | ||
| } |
No description provided.