Bug 157286

Summary: Make console a namespace object (like Math/JSON), allowing functions to be called unbound
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: JavaScriptCoreAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, bburg, commit-queue, fpizlo, ggaren, joepeck, keith_miller, mark.lam, mattbaker, nvasilyev, saam, timothy, wdm, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 157304    
Bug Blocks:    
Attachments:
Description Flags
[PATCH] Proposed Fix
none
[PATCH] Proposed Fix none

Description Joseph Pecoraro 2016-05-02 16:44:06 PDT
* SUMMARY
Make console a namespace object (like Math/JSON), allowing it to be called unbound

The evolving Console standard is pushing this direction:
<https://github.com/whatwg/console/issues/3>

This would improve a lot of scenarios where it currently throws a type error unless bound with a Console instance. This has been a long time feature request (bug 20141).

Example scenarios where it would throw:

    [1, 2, 3].forEach(console.log);
    var log = console.log; log("value");

Current workaround is to bind `console.log.bind(console)`. This will make that workaround unnecessary.

* STEPS TO REPRODUCE
1. js> var log = console.log; log("test")
  => TypeError, expected it to work

* NOTES
• At the same time we can make `console` more interoperable with other browsers:
  - `console` is enumerable in `window` in Firefox and Chrome, but not Safari. Lets make it enumerable.
  - `console.toString()` is "[object Console]" in Safari and Firefox, but not Chrome Canary... I'm going to Keeping "[object Console]" for now, since it has been around for quite a while. Spec discussion seems to suggest future "namespace" objects don't need this special treatment and should be "[object Object]" like normal objects (<https://github.com/tc39/ecma262/issues/495>). Console has been around long enough that it could qualify as legacy, so I'm going to keep it for now. This may change after discussion.
Comment 1 Radar WebKit Bug Importer 2016-05-02 16:47:22 PDT
<rdar://problem/26052830>
Comment 2 Joseph Pecoraro 2016-05-02 16:54:11 PDT
Created attachment 277945 [details]
[PATCH] Proposed Fix
Comment 3 Joseph Pecoraro 2016-05-02 16:58:55 PDT
Created attachment 277946 [details]
[PATCH] Proposed Fix

Better ChangeLog.
Comment 4 Joseph Pecoraro 2016-05-02 17:09:17 PDT
Comment on attachment 277946 [details]
[PATCH] Proposed Fix

Wait on commit-queue for bots to run all tests. I ran them but I want to be sure they pass on the bots.
Comment 5 WebKit Commit Bot 2016-05-02 17:50:50 PDT
Comment on attachment 277946 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 277946

Committed r200350: <http://trac.webkit.org/changeset/200350>
Comment 6 WebKit Commit Bot 2016-05-02 17:50:54 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 Darin Adler 2016-05-02 18:07:48 PDT
*** Bug 20141 has been marked as a duplicate of this bug. ***
Comment 8 Alex Christensen 2016-05-03 00:37:07 PDT
I see this new error in JSC tests after this patch:
undefined:1:37: JS ERROR Error: cyclic __proto__ value
https://build.webkit.org/builders/Apple%20Yosemite%20LLINT%20CLoop%20%28BuildAndTest%29/builds/15606/steps/webkit-jsc-cloop-test/logs/stdio
Comment 9 WebKit Commit Bot 2016-05-03 00:40:26 PDT
Re-opened since this is blocked by bug 157304
Comment 10 Joseph Pecoraro 2016-05-03 01:28:13 PDT
(In reply to comment #8)
> I see this new error in JSC tests after this patch:
> undefined:1:37: JS ERROR Error: cyclic __proto__ value
> https://build.webkit.org/builders/
> Apple%20Yosemite%20LLINT%20CLoop%20%28BuildAndTest%29/builds/15606/steps/
> webkit-jsc-cloop-test/logs/stdio

The actual failure was:

> assertTrue failed: 'Property count == 1'
> assertTrue failed: 'First property name is doSomething'

This was because we made `console` Enumerable at the top level. Changing back to `DontEnum` will match our previous behavior, and we can revisit this later if needed. If we are to be like other builtin's `Math`, `JSON`, `Reflect`, they are not enumerable at the top level, so maybe we should just go that route.

As for the cyclic thing, I am not certain if that is a failure or not.
Comment 11 Joseph Pecoraro 2016-05-03 01:47:12 PDT
I'm having trouble running the jsc tests in general. Just attempting to run them hangs my machine. I can confirm the testapi tests pass, but I can't run the broad range of jsc tests at the moment.
Comment 12 Joseph Pecoraro 2016-05-03 01:56:49 PDT
(In reply to comment #11)
> I'm having trouble running the jsc tests in general. Just attempting to run
> them hangs my machine. I can confirm the testapi tests pass, but I can't run
> the broad range of jsc tests at the moment.

I found my problem, the test runner was spawning 24 threads. Forcing --child-processes=8 made things run much much smoother.
Comment 13 Joseph Pecoraro 2016-05-03 02:19:41 PDT
Attempted a fix in:
<http://trac.webkit.org/changeset/200367>

I accidentally referenced the wrong r### in the ChangeLog though =(. All run-javascriptcore-tests passed locally for me after this change (I saw the same testate failure before the fix).
Comment 14 Joseph Pecoraro 2016-05-03 03:00:02 PDT
(In reply to comment #13)
> Attempted a fix in:
> <http://trac.webkit.org/changeset/200367>

The bots look greener. I'm going to re-close this.