Commit d1b1b1fe authored by aroben@apple.com's avatar aroben@apple.com

Fix Bug 19134: Inspector should support console.assert

        <https://bugs.webkit.org/show_bug.cgi?id=19134>

        Reviewed by Tim Hatcher.

        Test: manual-tests/inspector/console-assert.html

        * bindings/js/JSConsoleCustom.cpp:
        (WebCore::JSConsole::assertCondition): Added.
        * bindings/scripts/CodeGeneratorJS.pm: Added parsing of the
        ImplementationFunction extended attribute, which allows you to
        override the name of the C++ function used to implement this method.
        * manual-tests/inspector/console-assert.html: Added.
        * page/Console.cpp:
        (WebCore::Console::assertCondition): Added.
        * page/Console.h:
        * page/Console.idl: Added assert().


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33946 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6f24f536
2008-05-19 Adam Roben <aroben@apple.com>
Fix Bug 19134: Inspector should support console.assert
<https://bugs.webkit.org/show_bug.cgi?id=19134>
Reviewed by Tim Hatcher.
Test: manual-tests/inspector/console-assert.html
* bindings/js/JSConsoleCustom.cpp:
(WebCore::JSConsole::assertCondition): Added.
* bindings/scripts/CodeGeneratorJS.pm: Added parsing of the
ImplementationFunction extended attribute, which allows you to
override the name of the C++ function used to implement this method.
* manual-tests/inspector/console-assert.html: Added.
* page/Console.cpp:
(WebCore::Console::assertCondition): Added.
* page/Console.h:
* page/Console.idl: Added assert().
2008-05-20 Alice Liu <alice.liu@apple.com>
Reviewed by Brady.
......@@ -56,6 +56,16 @@ JSValue* JSConsole::warn(ExecState* exec, const List& arguments)
return jsUndefined();
}
JSValue* JSConsole::assertCondition(ExecState* exec, const List& arguments)
{
List messageParameters;
for (unsigned i = 1; i < arguments.size(); ++i)
messageParameters.append(arguments[i]);
impl()->assertCondition(arguments[0]->toBoolean(exec), exec, messageParameters);
return jsUndefined();
}
JSValue* JSConsole::profile(ExecState* exec, const List& arguments)
{
impl()->profile(exec, arguments);
......
......@@ -449,7 +449,8 @@ sub GenerateHeader
push(@headerContent, "\n // Custom functions\n");
foreach my $function (@{$dataNode->functions}) {
if ($function->signature->extendedAttributes->{"Custom"}) {
push(@headerContent, " KJS::JSValue* " . $codeGenerator->WK_lcfirst($function->signature->name) . "(KJS::ExecState*, const KJS::List&);\n");
my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
push(@headerContent, " KJS::JSValue* " . $functionImplementationName . "(KJS::ExecState*, const KJS::List&);\n");
}
}
}
......@@ -1132,6 +1133,8 @@ sub GenerateImplementation
AddIncludesForType($function->signature->type);
my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementationFunction"} || $codeGenerator->WK_lcfirst($function->signature->name);
push(@implContent, "JSValue* ${functionName}(ExecState* exec, JSObject* thisObj, const List& args)\n");
push(@implContent, "{\n");
......@@ -1155,7 +1158,7 @@ sub GenerateImplementation
}
if ($function->signature->extendedAttributes->{"Custom"}) {
push(@implContent, " return castedThisObj->" . $codeGenerator->WK_lcfirst($function->signature->name) . "(exec, args);\n");
push(@implContent, " return castedThisObj->" . $functionImplementationName . "(exec, args);\n");
} else {
if ($podType) {
push(@implContent, " JSSVGPODTypeWrapper<$podType>* wrapper = castedThisObj->impl();\n");
......@@ -1182,7 +1185,7 @@ sub GenerateImplementation
}
my $paramIndex = 0;
my $functionString = "imp" . ($podType ? "." : "->") . $codeGenerator->WK_lcfirst($function->signature->name) . "(";
my $functionString = "imp" . ($podType ? "." : "->") . $functionImplementationName . "(";
my $hasOptionalArguments = 0;
......
<script>
function createClickHandler(result, str) {
return function() {
console.assert(result, "%s", str);
}
}
function load() {
var tests = [
"",
"false",
"null",
"document.body",
"!document.body",
"true"
];
for (var i = 0; i < tests.length; ++i) {
var test = tests[i];
var result;
try {
result = eval(test);
} catch(e) {
result = false;
}
var button = document.createElement("button");
button.innerText = "console.assert(" + test + "): should" + (result ? " not" : "") + " assert";
button.onclick = createClickHandler(result, test);
var p = document.createElement("p");
p.appendChild(button);
document.body.appendChild(p);
}
}
</script>
<body onload="load()">
<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=19134">Bug 19134: Inspector should support console.assert</a>.</p>
<p>To test, click the buttons below and look at the Inspector's Console.</p>
......@@ -129,6 +129,26 @@ void Console::log(ExecState* exec, const List& arguments)
page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, arguments, 0, url.string());
}
void Console::assertCondition(bool condition, ExecState* exec, const List& arguments)
{
if (condition)
return;
if (!m_frame)
return;
Page* page = m_frame->page();
if (!page)
return;
const KURL& url = m_frame->loader()->url();
// FIXME: <https://bugs.webkit.org/show_bug.cgi?id=19135> It would be nice to prefix assertion failures with a message like "Assertion failed: ".
// FIXME: <https://bugs.webkit.org/show_bug.cgi?id=19136> We should print a message even when arguments.isEmpty() is true.
page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, exec, arguments, 0, url.string());
}
void Console::profile(ExecState* exec, const List& arguments) const
{
Page* page = m_frame->page();
......
......@@ -70,6 +70,7 @@ namespace WebCore {
void info(KJS::ExecState*, const KJS::List& arguments);
void log(KJS::ExecState*, const KJS::List& arguments);
void warn(KJS::ExecState*, const KJS::List& arguments);
void assertCondition(bool condition, KJS::ExecState*, const KJS::List& arguments);
void profile(KJS::ExecState*, const KJS::List& arguments) const;
void profileEnd() const;
......
......@@ -33,6 +33,7 @@ module window {
[Custom] void info();
[Custom] void log();
[Custom] void warn();
[Custom, ImplementationFunction=assertCondition] void assert(in boolean condition);
[Custom] void profile(in DOMString title);
void profileEnd();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment