Bug 114406 - Calling console.{log, info, error, ...} should not require this === console
Summary: Calling console.{log, info, error, ...} should not require this === console
Status: RESOLVED DUPLICATE of bug 20141
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-10 19:07 PDT by Victor Costan
Modified: 2013-04-10 23:57 PDT (History)
7 users (show)

See Also:


Attachments
Patch (35.82 KB, patch)
2013-04-10 19:27 PDT, Victor Costan
no flags Details | Formatted Diff | Diff
Patch (35.82 KB, patch)
2013-04-10 20:22 PDT, Victor Costan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Victor Costan 2013-04-10 19:07:47 PDT
This is a bug for a patch that I will attach very soon.

In a nutshell, this change will make the code below not throw an exception:

f = console.log;
f("Hello world");

This comes in handy when debugging asynchronous code in the Web Inspector, because console.log can be passed as a callback that prints its arguments. For example, given a node.js-style asynchronous function perform(action, error, callback) can be called as follows in the Inspector, for quick debugging.

perform(action, console.warn, console.log);

In order to achieve this, the patch introduces the [LenientThis] WebKitIDL attribute, which is heavily inspired from the LenientThis WebIDL.
http://www.w3.org/TR/WebIDL/#LenientThis

I implemented LenientThis for methods.  I figured the only way to not require a specific type for "this" is to completely ignore the value, so a LenientThis method calls a static method in WebCore. A LenientMethod is similar to a static method, but it can be accessed as a property of the interface instances, instead of being a property of the interface object. I hope this makes sense, and I look forward to feedback.
Comment 1 Victor Costan 2013-04-10 19:27:19 PDT
Created attachment 197464 [details]
Patch
Comment 2 WebKit Commit Bot 2013-04-10 19:29:22 PDT
Attachment 197464 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'LayoutTests/ChangeLog', u'LayoutTests/fast/dom/Window/console-unbound-functions-expected.txt', u'LayoutTests/fast/dom/Window/console-unbound-functions.html', u'Source/WebCore/ChangeLog', u'Source/WebCore/bindings/scripts/CodeGeneratorJS.pm', u'Source/WebCore/bindings/scripts/IDLAttributes.txt', u'Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp', u'Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h', u'Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp', u'Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.h', u'Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp', u'Source/WebCore/bindings/scripts/test/JS/JSTestObj.h', u'Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h', u'Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm', u'Source/WebCore/bindings/scripts/test/TestObj.idl', u'Source/WebCore/page/Console.cpp', u'Source/WebCore/page/Console.h', u'Source/WebCore/page/Console.idl']" exit_code: 1
Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h:188:  The parameter name "str" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 18 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Darin Adler 2013-04-10 19:44:52 PDT
Comment on attachment 197464 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=197464&action=review

> Source/WebCore/page/Console.idl:62
> -    [CallWith=ScriptArguments|ScriptState] void clear();
> +    [CallWith=ScriptArguments|ScriptState] static void clear();

Why is this different from the others? Was this an earlier syntax you had experimented with?
Comment 4 Victor Costan 2013-04-10 20:22:03 PDT
Created attachment 197499 [details]
Patch
Comment 5 Victor Costan 2013-04-10 20:26:56 PDT
Darin, thank you so much for catching that! Yes, I tried static first, hoping it would work.

I'm really sorry about this omission, I was so happy when I got the IDL generator working that I forgot to double-check my Console changes. :(

Also, should I worry about the style error in the generated code?
Comment 6 WebKit Commit Bot 2013-04-10 20:31:30 PDT
Attachment 197499 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'LayoutTests/ChangeLog', u'LayoutTests/fast/dom/Window/console-unbound-functions-expected.txt', u'LayoutTests/fast/dom/Window/console-unbound-functions.html', u'Source/WebCore/ChangeLog', u'Source/WebCore/bindings/scripts/CodeGeneratorJS.pm', u'Source/WebCore/bindings/scripts/IDLAttributes.txt', u'Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp', u'Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h', u'Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp', u'Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.h', u'Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp', u'Source/WebCore/bindings/scripts/test/JS/JSTestObj.h', u'Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h', u'Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm', u'Source/WebCore/bindings/scripts/test/TestObj.idl', u'Source/WebCore/page/Console.cpp', u'Source/WebCore/page/Console.h', u'Source/WebCore/page/Console.idl']" exit_code: 1
Source/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h:188:  The parameter name "str" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 18 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Alexey Proskuryakov 2013-04-10 22:02:10 PDT
Is this the same as bug 20141?
Comment 8 Alexey Proskuryakov 2013-04-10 22:04:51 PDT
If you agree, I think that it would be better to dupe this to older bug, and to move the patch there.
Comment 9 Victor Costan 2013-04-10 23:37:09 PDT
Thank you for pointing this out, Alexey! Should I add the description of my patch as a comment in #20141?

*** This bug has been marked as a duplicate of bug 20141 ***
Comment 10 Alexey Proskuryakov 2013-04-10 23:54:46 PDT
> Should I add the description of my patch as a comment in #20141?

Sure, bug 20141 should have enough information to learn what's going on.