console: fix issues with frozen intrinsics#54070
Merged
nodejs-github-bot merged 2 commits intonodejs:mainfrom Jul 30, 2024
Merged
console: fix issues with frozen intrinsics#54070nodejs-github-bot merged 2 commits intonodejs:mainfrom
nodejs-github-bot merged 2 commits intonodejs:mainfrom
Conversation
BridgeAR
approved these changes
Jul 27, 2024
| this[kInternalTimeLogImpl] = FunctionPrototypeBind(timeLogImpl, this); | ||
|
|
||
| timeLog(this._times, kTraceConsoleCategory, 'console.timeLog()', kNone, this[kInternalTimeLogImpl], label, `time::${label}`, data); | ||
| timeLog(this._times, kTraceConsoleCategory, 'console.timeLog()', kNone, (label, formatted, args) => timeLogImpl(this, label, formatted, args), label, `time::${label}`, data); |
Member
There was a problem hiding this comment.
I believe it would be possible to add the timeLogImpl to the instance during construction time.
That way it is not required to recreate the function on each call.
Member
Author
There was a problem hiding this comment.
I tried adding inside the constructor but I always get undefined.
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index 6c34a9eded..8d88d429b0 100644
--- a/lib/internal/console/constructor.js
+++ b/lib/internal/console/constructor.js
@@ -90,6 +90,7 @@ const kBindStreamsEager = Symbol('kBindStreamsEager');
const kBindStreamsLazy = Symbol('kBindStreamsLazy');
const kUseStdout = Symbol('kUseStdout');
const kUseStderr = Symbol('kUseStderr');
+const kInternalTimeLogImpl = Symbol('kInternalTimeLogImpl');
const optionsMap = new SafeWeakMap();
function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
@@ -155,6 +156,8 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
});
});
+ this[kInternalTimeLogImpl] = FunctionPrototypeBind(timeLogImpl, this);
+
this[kBindStreamsEager](stdout, stderr);
this[kBindProperties](ignoreErrors, colorMode, groupIndentation);
}
@@ -371,11 +374,11 @@ function createWriteErrorHandler(instance, streamSymbol) {
};
}
-function timeLogImpl(consoleRef, label, formatted, args) {
+function timeLogImpl(label, formatted, args) {
if (args === undefined) {
- consoleRef.log('%s: %s', label, formatted);
+ this.log('%s: %s', label, formatted);
} else {
- consoleRef.log('%s: %s', label, formatted, ...new SafeArrayIterator(args));
+ this.log('%s: %s', label, formatted, ...new SafeArrayIterator(args));
}
}
@@ -406,11 +409,11 @@ const consoleMethods = {
},
timeEnd(label = 'default') {
- timeEnd(this._times, kTraceConsoleCategory, 'console.timeEnd()', kNone, (label, formatted, args) => timeLogImpl(this, label, formatted, args), label, `time::${label}`);
+ timeEnd(this._times, kTraceConsoleCategory, 'console.timeEnd()', kNone, this[kInternalTimeLogImpl], label, `time::${label}`);
},
timeLog(label = 'default', ...data) {
- timeLog(this._times, kTraceConsoleCategory, 'console.timeLog()', kNone, (label, formatted, args) => timeLogImpl(this, label, formatted, args), label, `time::${label}`, data);
+ timeLog(this._times, kTraceConsoleCategory, 'console.timeLog()', kNone, this[kInternalTimeLogImpl], label, `time::${label}`, data);
},
trace: function trace(...args) {node:internal/util/debuglog:206
logImp(label, formatted, args);
^
TypeError <Object <Object <[Object: null prototype] {}>>>: logImp is not a function
at timeLogImpl (node:internal/util/debuglog:206:5)
at timeLog (node:internal/util/debuglog:313:5)
at console.timeLog (node:internal/console/constructor:423:5)
at Object.<anonymous> (/home/h4ad/Projects/opensource/node-copy-4/test/parallel/test-console-with-frozen-intrinsics.js:18:9)
benjamingr
approved these changes
Jul 27, 2024
Collaborator
Contributor
Failed to start CI⚠ Something was pushed to the Pull Request branch since the last approving review. ℹ request-ci label was added by a Collaborator after the last push event. - Validating Jenkins credentials ✔ Jenkins credentials valid - Starting PR CI job ✘ Failed to start PR CI: 400 Bad Requesthttps://github.com/nodejs/node/actions/runs/10134591301 |
Collaborator
Collaborator
Collaborator
Commit Queue failed- Loading data for nodejs/node/pull/54070 ✔ Done loading data for nodejs/node/pull/54070 ----------------------------------- PR info ------------------------------------ Title console: fix issues with frozen intrinsics (#54070) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch H4ad:fix/frozen-intrinsics -> nodejs:main Labels console, author ready, needs-ci, commit-queue-squash Commits 2 - console: fix issues with frozen intrinsics - remove method that does not exist Committers 2 - Vinícius Lourenço <contact@viniciusl.com.br> - GitHub <noreply@github.com> PR-URL: https://github.com/nodejs/node/pull/54070 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/54070 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - remove method that does not exist ℹ This PR was created on Sat, 27 Jul 2024 16:14:40 GMT ✔ Approvals: 2 ✔ - Ruben Bridgewater (@BridgeAR) (TSC): https://github.com/nodejs/node/pull/54070#pullrequestreview-2203209471 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/54070#pullrequestreview-2203227532 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-07-29T21:15:24Z: https://ci.nodejs.org/job/node-test-pull-request/60731/ - Querying data for job/node-test-pull-request/60731/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/10153125854 |
jakecastelli
approved these changes
Jul 30, 2024
Collaborator
|
Landed in 890760b |
targos
pushed a commit
that referenced
this pull request
Jul 30, 2024
PR-URL: #54070 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Merged
RafaelGSS
pushed a commit
that referenced
this pull request
Aug 5, 2024
PR-URL: #54070 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
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 #54057
I also added a fix for
kGroupIndentthat was also broken for frozen intrinsics.