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)
Tracking
()
RESOLVED
FIXED
mozilla26
People
(Reporter: zer0, Assigned: baku)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 3 obsolete files)
|
8.91 KB,
patch
|
Details | Diff | Splinter Review |
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?
Comment 1•13 years ago
|
||
Andrea, can you take a look?
| Assignee | ||
Updated•13 years ago
|
Assignee: nobody → amarchesini
| Assignee | ||
Comment 2•13 years ago
|
||
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)
Comment 3•13 years ago
|
||
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)
| Assignee | ||
Comment 4•13 years ago
|
||
Attachment #783184 -
Flags: review?(mihai.sucan)
Comment 5•13 years ago
|
||
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)
| Assignee | ||
Comment 6•13 years ago
|
||
Good point. This is probably better.
Attachment #783184 -
Attachment is obsolete: true
Attachment #784404 -
Flags: review?(mihai.sucan)
Comment 7•13 years ago
|
||
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+
| Assignee | ||
Comment 8•13 years ago
|
||
Attachment #784404 -
Attachment is obsolete: true
Attachment #784437 -
Flags: review?(mihai.sucan)
Comment 9•12 years ago
|
||
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+
| Assignee | ||
Comment 10•12 years ago
|
||
| Assignee | ||
Comment 11•12 years ago
|
||
Attachment #784437 -
Attachment is obsolete: true
| Assignee | ||
Updated•12 years ago
|
Keywords: checkin-needed
Comment 12•12 years ago
|
||
Flags: in-testsuite+
Keywords: checkin-needed
Comment 13•12 years ago
|
||
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla26
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•