2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "JSCustomVoidCallback.h"
33 #include "DOMWindow.h"
35 #include "kjs_binding.h"
36 #include "kjs_proxy.h"
37 #include "kjs_window.h"
44 JSCustomVoidCallback::JSCustomVoidCallback(JSObject* callback, Frame* frame)
45 : m_callback(callback)
50 void JSCustomVoidCallback::handleEvent()
55 KJSProxy* proxy = m_frame->scriptProxy();
59 ScriptInterpreter* interpreter = proxy->interpreter();
60 ExecState* exec = interpreter->globalExec();
64 JSValue* handleEventFuncValue = m_callback->get(exec, "handleEvent");
65 JSObject* handleEventFunc = 0;
66 if (handleEventFuncValue->isObject()) {
67 handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
68 if (!handleEventFunc->implementsCall())
72 if (!handleEventFunc && !m_callback->implementsCall()) {
73 // FIXME: Should an exception be thrown here?
77 RefPtr<JSCustomVoidCallback> protect(this);
81 interpreter->startTimeoutCheck();
83 handleEventFunc->call(exec, m_callback, args);
85 m_callback->call(exec, m_callback, args);
86 interpreter->stopTimeoutCheck();
88 if (exec->hadException()) {
89 JSObject* exception = exec->exception()->toObject(exec);
90 String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
91 int lineNumber = exception->get(exec, "line")->toInt32(exec);
92 String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
93 if (Interpreter::shouldPrintExceptions())
94 printf("VoidCallback: %s\n", message.utf8().data());
95 if (Page* page = m_frame->page())
96 page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
97 exec->clearException();
100 Document::updateDocumentsRendering();
103 VoidCallback* toVoidCallback(ExecState* exec, JSValue* value, bool& ok)
107 JSObject* object = value->getObject();
111 Frame* frame = Window::retrieveActive(exec)->impl()->frame();
116 return new JSCustomVoidCallback(object, frame);