Closed Bug 896535 Opened 13 years ago Closed 12 years ago

Promise: `then(console.log)` is not working as expected

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla26

People

(Reporter: zer0, Assigned: baku)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 3 obsolete files)

Sorry for the Summary, feel free to change with something more appropriate. The following code is working as expected, logging `42`: new Promise(r => r.resolve(42)).then(x => console.log(x)); But: new Promise(r => r.resolve(42)).then(console.log); Doesn't log anything. Notice that `log` is already bound to `console`, but also this code: new Promise(r => r.resolve(42)).then(console.log.bind(console)) Gives the same result: 42 is not logged. Am I missing something in the Promise specs?
Andrea, can you take a look?
Assignee: nobody → amarchesini
Ok, this is fun. The reason why it doesn't work is because console.log generates the stack trace here: https://mxr.mozilla.org/mozilla-central/source/dom/base/ConsoleAPI.js#401 but the callee of console.log() is C++ so stack array is empty. and https://mxr.mozilla.org/mozilla-central/source/dom/base/ConsoleAPI.js#263 'frame' is undefined. I know that there is a plan for changing the way we calculate the stack trace and this depends by bug 767938. I need a feedback from ConsoleAPI developers.
Depends on: 767938
Flags: needinfo?(mihai.sucan)
If there's no JS frame in the stack being built by getStackTrace(), then please make a patch for _processQueuedItem() to accept such situations. This should be accepted - the code should not fail if, for some reason, we cannot determine the frames for a console API call. Thank you!
Flags: needinfo?(mihai.sucan)
Attached patch console.patch (obsolete) — Splinter Review
Attachment #783184 - Flags: review?(mihai.sucan)
Comment on attachment 783184 [details] [diff] [review] console.patch Review of attachment 783184 [details] [diff] [review]: ----------------------------------------------------------------- Thank you for the patch! The Console API is used for web apps and we do not want to expose non-JavaScript frames in the stackframes list. What I suggested is we update _processQueuedItem() to not throw when the stackframes array is empty. Could we do that?
Attachment #783184 - Flags: review?(mihai.sucan)
Attached patch console.patch (obsolete) — Splinter Review
Good point. This is probably better.
Attachment #783184 - Attachment is obsolete: true
Attachment #784404 - Flags: review?(mihai.sucan)
Comment on attachment 784404 [details] [diff] [review] console.patch Review of attachment 784404 [details] [diff] [review]: ----------------------------------------------------------------- Patch looks good. Thanks for the quick update! Can you please write a test? ::: dom/base/ConsoleAPI.js @@ +266,5 @@ > + } else { > + frame = { > + filename: '', > + lineNumber: 0, > + functionName: '[native code]', Let's leave the function name empty. [native code] is usually displayed when you try toString() on functions. nit: please use double quotes for consistency with the file.
Attachment #784404 - Flags: review?(mihai.sucan) → feedback+
Attached patch console.patch (obsolete) — Splinter Review
Attachment #784404 - Attachment is obsolete: true
Attachment #784437 - Flags: review?(mihai.sucan)
Comment on attachment 784437 [details] [diff] [review] console.patch Review of attachment 784437 [details] [diff] [review]: ----------------------------------------------------------------- Patch look good. Thank you! ::: dom/tests/browser/browser_ConsoleAPITests.js @@ +86,5 @@ > + try { > + testNativeCallback(aSubject.wrappedJSObject); > + } catch (ex) { > + // XXX Exceptions in this function currently aren't reported, because of > + // some XPConnect weirdness, so report them manually Do we have a bug about this? @@ +100,5 @@ > +function testNativeCallback(aMessageObject) { > + is(aMessageObject.level, "log", "expected level received"); > + is(aMessageObject.filename, "", "BBfilename matches"); > + is(aMessageObject.lineNumber, 0, "BBlineNumber matches"); > + is(aMessageObject.functionName, "", "BBfunctionName matches"); Why "BB" prefix for these messages? ::: dom/tests/browser/test-console-api.html @@ +47,5 @@ > console.groupEnd("b", "group"); > } > + > + function nativeCallback() { > + SpecialPowers.setBoolPref("dom.promise.enabled", true); Do we need to reset the preference once the test ends?
Attachment #784437 - Flags: review?(mihai.sucan) → review+
Blocks: 906593
Attached patch console.patchSplinter Review
Attachment #784437 - Attachment is obsolete: true
Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla26
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: