Home | History | Annotate | Download | only in custom
      1 /*
      2  * Copyright (C) 2010 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 
     33 #include "V8Console.h"
     34 
     35 #include "Console.h"
     36 #include "ScriptArguments.h"
     37 #include "ScriptCallStack.h"
     38 #include "ScriptCallStackFactory.h"
     39 #include "ScriptProfile.h"
     40 #include "V8Binding.h"
     41 #include "V8BindingMacros.h"
     42 #include "V8MemoryInfo.h"
     43 #include "V8Proxy.h"
     44 #include "V8ScriptProfile.h"
     45 
     46 namespace WebCore {
     47 
     48 typedef Vector<RefPtr<ScriptProfile> > ProfilesArray;
     49 
     50 #if ENABLE(JAVASCRIPT_DEBUGGER)
     51 v8::Handle<v8::Value> V8Console::profilesAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     52 {
     53     INC_STATS("DOM.Console.profilesAccessorGetter");
     54     Console* imp = V8Console::toNative(info.Holder());
     55     const ProfilesArray& profiles = imp->profiles();
     56     v8::Handle<v8::Array> result = v8::Array::New(profiles.size());
     57     int index = 0;
     58     ProfilesArray::const_iterator end = profiles.end();
     59     for (ProfilesArray::const_iterator iter = profiles.begin(); iter != end; ++iter)
     60         result->Set(v8::Integer::New(index++), toV8(iter->get()));
     61     return result;
     62 }
     63 #endif
     64 
     65 v8::Handle<v8::Value> V8Console::traceCallback(const v8::Arguments& args)
     66 {
     67     INC_STATS("DOM.Console.traceCallback");
     68     Console* imp = V8Console::toNative(args.Holder());
     69     RefPtr<ScriptCallStack> callStack(createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture));
     70     RefPtr<ScriptArguments> scriptArguments(createScriptArguments(args, 0));
     71     imp->trace(scriptArguments.release(), callStack);
     72     return v8::Handle<v8::Value>();
     73 }
     74 
     75 v8::Handle<v8::Value> V8Console::assertCallback(const v8::Arguments& args)
     76 {
     77     INC_STATS("DOM.Console.assertCallback");
     78     Console* imp = V8Console::toNative(args.Holder());
     79     RefPtr<ScriptCallStack> callStack(createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture));
     80     bool condition = args[0]->BooleanValue();
     81     RefPtr<ScriptArguments> scriptArguments(createScriptArguments(args, 1));
     82     imp->assertCondition(condition, scriptArguments.release(), callStack);
     83     return v8::Handle<v8::Value>();
     84 }
     85 
     86 #if ENABLE(JAVASCRIPT_DEBUGGER)
     87 v8::Handle<v8::Value> V8Console::profileCallback(const v8::Arguments& args)
     88 {
     89     INC_STATS("DOM.Console.profile");
     90     Console* imp = V8Console::toNative(args.Holder());
     91     RefPtr<ScriptCallStack> callStack(createScriptCallStack(1));
     92     if (!callStack)
     93         return v8::Undefined();
     94     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<WithUndefinedOrNullCheck>, title, args[0]);
     95     imp->profile(title, ScriptState::current(), callStack);
     96     return v8::Handle<v8::Value>();
     97 }
     98 
     99 v8::Handle<v8::Value> V8Console::profileEndCallback(const v8::Arguments& args)
    100 {
    101     INC_STATS("DOM.Console.profileEnd");
    102     Console* imp = V8Console::toNative(args.Holder());
    103     RefPtr<ScriptCallStack> callStack(createScriptCallStack(1));
    104     if (!callStack)
    105         return v8::Undefined();
    106     STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<WithUndefinedOrNullCheck>, title, args[0]);
    107     imp->profileEnd(title, ScriptState::current(), callStack);
    108     return v8::Handle<v8::Value>();
    109 }
    110 #endif
    111 
    112 v8::Handle<v8::Value> V8Console::memoryAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    113 {
    114     INC_STATS("DOM.Console.memoryAccessorGetter");
    115     Console* imp = V8Console::toNative(info.Holder());
    116     return toV8(imp->memory());
    117 }
    118 
    119 } // namespace WebCore
    120