diff options
Diffstat (limited to 'Source/WebCore/bindings/js')
236 files changed, 24529 insertions, 0 deletions
diff --git a/Source/WebCore/bindings/js/CachedScriptSourceProvider.h b/Source/WebCore/bindings/js/CachedScriptSourceProvider.h new file mode 100644 index 0000000..809a488 --- /dev/null +++ b/Source/WebCore/bindings/js/CachedScriptSourceProvider.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CachedScriptSourceProvider_h +#define CachedScriptSourceProvider_h + +#include "CachedResourceClient.h" +#include "CachedResourceHandle.h" +#include "CachedScript.h" +#include "JSDOMBinding.h" // for stringToUString +#include "ScriptSourceProvider.h" +#include <parser/SourceCode.h> + +namespace WebCore { + + class CachedScriptSourceProvider : public ScriptSourceProvider, public CachedResourceClient { + public: + static PassRefPtr<CachedScriptSourceProvider> create(CachedScript* cachedScript) { return adoptRef(new CachedScriptSourceProvider(cachedScript)); } + + virtual ~CachedScriptSourceProvider() + { + m_cachedScript->removeClient(this); + } + + JSC::UString getRange(int start, int end) const { return JSC::UString(m_cachedScript->script().characters() + start, end - start); } + const UChar* data() const { return m_cachedScript->script().characters(); } + int length() const { return m_cachedScript->script().length(); } + const String& source() const { return m_cachedScript->script(); } + + private: + CachedScriptSourceProvider(CachedScript* cachedScript) + : ScriptSourceProvider(stringToUString(cachedScript->url())) + , m_cachedScript(cachedScript) + { + m_cachedScript->addClient(this); + } + + CachedResourceHandle<CachedScript> m_cachedScript; + }; + + inline JSC::SourceCode makeSource(CachedScript* cachedScript) + { + return JSC::SourceCode(CachedScriptSourceProvider::create(cachedScript)); + } + +} // namespace WebCore + +#endif // CachedScriptSourceProvider_h diff --git a/Source/WebCore/bindings/js/DOMObjectHashTableMap.cpp b/Source/WebCore/bindings/js/DOMObjectHashTableMap.cpp new file mode 100644 index 0000000..bfcab0b --- /dev/null +++ b/Source/WebCore/bindings/js/DOMObjectHashTableMap.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "DOMObjectHashTableMap.h" + +#include "WebCoreJSClientData.h" + +using namespace JSC; + +namespace WebCore{ + +DOMObjectHashTableMap& DOMObjectHashTableMap::mapFor(JSGlobalData& globalData) +{ + JSGlobalData::ClientData* clientData = globalData.clientData; + ASSERT(clientData); + return static_cast<WebCoreJSClientData*>(clientData)->hashTableMap; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/DOMObjectHashTableMap.h b/Source/WebCore/bindings/js/DOMObjectHashTableMap.h new file mode 100644 index 0000000..4ddacb8 --- /dev/null +++ b/Source/WebCore/bindings/js/DOMObjectHashTableMap.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * Copyright (C) 2009 Google, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef DOMObjectHashTableMap_h +#define DOMObjectHashTableMap_h + +#include <runtime/Lookup.h> +#include <wtf/HashMap.h> + +namespace JSC { + class JSGlobalData; +} + +namespace WebCore { + +// Map from static HashTable instances to per-GlobalData ones. +class DOMObjectHashTableMap { +public: + static DOMObjectHashTableMap& mapFor(JSC::JSGlobalData&); + + ~DOMObjectHashTableMap() + { + HashMap<const JSC::HashTable*, JSC::HashTable>::iterator mapEnd = m_map.end(); + for (HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.begin(); iter != m_map.end(); ++iter) + iter->second.deleteTable(); + } + + const JSC::HashTable* get(const JSC::HashTable* staticTable) + { + HashMap<const JSC::HashTable*, JSC::HashTable>::iterator iter = m_map.find(staticTable); + if (iter != m_map.end()) + return &iter->second; + return &m_map.set(staticTable, JSC::HashTable(*staticTable)).first->second; + } + +private: + HashMap<const JSC::HashTable*, JSC::HashTable> m_map; +}; + +} // namespace WebCore + +#endif // DOMObjectHashTableMap_h diff --git a/Source/WebCore/bindings/js/DOMWrapperWorld.cpp b/Source/WebCore/bindings/js/DOMWrapperWorld.cpp new file mode 100644 index 0000000..13ee37a --- /dev/null +++ b/Source/WebCore/bindings/js/DOMWrapperWorld.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "DOMWrapperWorld.h" + +#include "JSDOMWindow.h" +#include "ScriptController.h" +#include "WebCoreJSClientData.h" + +using namespace JSC; + +namespace WebCore { + +DOMWrapperWorld::DOMWrapperWorld(JSC::JSGlobalData* globalData, bool isNormal) + : m_globalData(globalData) + , m_isNormal(isNormal) +{ + JSGlobalData::ClientData* clientData = m_globalData->clientData; + ASSERT(clientData); + static_cast<WebCoreJSClientData*>(clientData)->rememberWorld(this); +} + +DOMWrapperWorld::~DOMWrapperWorld() +{ + JSGlobalData::ClientData* clientData = m_globalData->clientData; + ASSERT(clientData); + static_cast<WebCoreJSClientData*>(clientData)->forgetWorld(this); + + // These items are created lazily. + while (!m_documentsWithWrapperCaches.isEmpty()) + (*m_documentsWithWrapperCaches.begin())->destroyWrapperCache(this); + + while (!m_scriptControllersWithWindowShells.isEmpty()) + (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this); +} + +void DOMWrapperWorld::clearWrappers() +{ + m_wrappers.clear(); + m_stringCache.clear(); + + // These items are created lazily. + while (!m_documentsWithWrapperCaches.isEmpty()) + (*m_documentsWithWrapperCaches.begin())->destroyWrapperCache(this); + + while (!m_scriptControllersWithWindowShells.isEmpty()) + (*m_scriptControllersWithWindowShells.begin())->destroyWindowShell(this); +} + +DOMWrapperWorld* normalWorld(JSC::JSGlobalData& globalData) +{ + JSGlobalData::ClientData* clientData = globalData.clientData; + ASSERT(clientData); + return static_cast<WebCoreJSClientData*>(clientData)->normalWorld(); +} + +DOMWrapperWorld* mainThreadNormalWorld() +{ + ASSERT(isMainThread()); + static DOMWrapperWorld* cachedNormalWorld = normalWorld(*JSDOMWindow::commonJSGlobalData()); + return cachedNormalWorld; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/DOMWrapperWorld.h b/Source/WebCore/bindings/js/DOMWrapperWorld.h new file mode 100644 index 0000000..5e7b551 --- /dev/null +++ b/Source/WebCore/bindings/js/DOMWrapperWorld.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * Copyright (C) 2009 Google, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef DOMWrapperWorld_h +#define DOMWrapperWorld_h + +#include "Document.h" +#include "JSDOMGlobalObject.h" +#include "JSDOMWrapper.h" +#include <runtime/WeakGCMap.h> +#include <wtf/Forward.h> + +namespace WebCore { + +class ScriptController; + +typedef JSC::WeakGCMap<void*, DOMObject*> DOMObjectWrapperMap; +typedef JSC::WeakGCMap<StringImpl*, JSC::JSString*> JSStringCache; + +class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> { +public: + static PassRefPtr<DOMWrapperWorld> create(JSC::JSGlobalData* globalData, bool isNormal = false) + { + return adoptRef(new DOMWrapperWorld(globalData, isNormal)); + } + ~DOMWrapperWorld(); + + // Free as much memory held onto by this world as possible. + void clearWrappers(); + + void didCreateWrapperCache(Document* document) { m_documentsWithWrapperCaches.add(document); } + void didDestroyWrapperCache(Document* document) { m_documentsWithWrapperCaches.remove(document); } + + void didCreateWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.add(scriptController); } + void didDestroyWindowShell(ScriptController* scriptController) { m_scriptControllersWithWindowShells.remove(scriptController); } + + // FIXME: can we make this private? + DOMObjectWrapperMap m_wrappers; + JSStringCache m_stringCache; + + bool isNormal() const { return m_isNormal; } + +protected: + DOMWrapperWorld(JSC::JSGlobalData*, bool isNormal); + +private: + JSC::JSGlobalData* m_globalData; + HashSet<Document*> m_documentsWithWrapperCaches; + HashSet<ScriptController*> m_scriptControllersWithWindowShells; + bool m_isNormal; +}; + +DOMWrapperWorld* normalWorld(JSC::JSGlobalData&); +DOMWrapperWorld* mainThreadNormalWorld(); +inline DOMWrapperWorld* debuggerWorld() { return mainThreadNormalWorld(); } +inline DOMWrapperWorld* pluginWorld() { return mainThreadNormalWorld(); } + +inline DOMWrapperWorld* currentWorld(JSC::ExecState* exec) +{ + return static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->world(); +} + +// From Document.h + +inline Document::JSWrapperCache* Document::getWrapperCache(DOMWrapperWorld* world) +{ + if (world->isNormal()) { + if (Document::JSWrapperCache* wrapperCache = m_normalWorldWrapperCache) + return wrapperCache; + ASSERT(!m_wrapperCacheMap.contains(world)); + } else if (Document::JSWrapperCache* wrapperCache = m_wrapperCacheMap.get(world)) + return wrapperCache; + return createWrapperCache(world); +} + +} // namespace WebCore + +#endif // DOMWrapperWorld_h diff --git a/Source/WebCore/bindings/js/GCController.cpp b/Source/WebCore/bindings/js/GCController.cpp new file mode 100644 index 0000000..f193b2e --- /dev/null +++ b/Source/WebCore/bindings/js/GCController.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GCController.h" + +#include "JSDOMWindow.h" +#include <runtime/JSGlobalData.h> +#include <runtime/JSLock.h> +#include <runtime/Collector.h> +#include <wtf/StdLibExtras.h> + +#if USE(PTHREADS) +#include <pthread.h> +#endif + +using namespace JSC; + +namespace WebCore { + +static void* collect(void*) +{ + JSLock lock(SilenceAssertionsOnly); + JSDOMWindow::commonJSGlobalData()->heap.collectAllGarbage(); + return 0; +} + +GCController& gcController() +{ + DEFINE_STATIC_LOCAL(GCController, staticGCController, ()); + return staticGCController; +} + +GCController::GCController() + : m_GCTimer(this, &GCController::gcTimerFired) +{ +} + +void GCController::garbageCollectSoon() +{ + if (!m_GCTimer.isActive()) + m_GCTimer.startOneShot(0); +} + +void GCController::gcTimerFired(Timer<GCController>*) +{ + collect(0); +} + +void GCController::garbageCollectNow() +{ + JSLock lock(SilenceAssertionsOnly); + if (!JSDOMWindow::commonJSGlobalData()->heap.isBusy()) + collect(0); +} + +void GCController::garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone) +{ +#if USE(PTHREADS) + pthread_t thread; + pthread_create(&thread, NULL, collect, NULL); + + if (waitUntilDone) + pthread_join(thread, NULL); +#endif +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/GCController.h b/Source/WebCore/bindings/js/GCController.h new file mode 100644 index 0000000..4c25407 --- /dev/null +++ b/Source/WebCore/bindings/js/GCController.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GCController_h +#define GCController_h + +#include <wtf/Noncopyable.h> +#include "Timer.h" + +namespace WebCore { + + class GCController : public Noncopyable { + friend GCController& gcController(); + + public: + void garbageCollectSoon(); + void garbageCollectNow(); // It's better to call garbageCollectSoon, unless you have a specific reason not to. + + void garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone); // Used for stress testing. + + private: + GCController(); // Use gcController() instead + void gcTimerFired(Timer<GCController>*); + + Timer<GCController> m_GCTimer; + }; + + // Function to obtain the global GC controller. + GCController& gcController(); + +} // namespace WebCore + +#endif // GCController_h diff --git a/Source/WebCore/bindings/js/IDBBindingUtilities.cpp b/Source/WebCore/bindings/js/IDBBindingUtilities.cpp new file mode 100644 index 0000000..638a23e --- /dev/null +++ b/Source/WebCore/bindings/js/IDBBindingUtilities.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "IDBBindingUtilities.h" + +#if ENABLE(INDEXED_DATABASE) + +#include "IDBKey.h" + +namespace WebCore { + +PassRefPtr<IDBKey> createIDBKeyFromValue(JSC::ExecState* exec, JSC::JSValue value) +{ + if (value.isNull()) + return IDBKey::create(); + if (value.isInt32()) + return IDBKey::create(value.toInt32(exec)); + if (value.isString()) + return IDBKey::create(ustringToString(value.toString(exec))); + // FIXME: Implement dates. + return 0; +} + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/bindings/js/IDBBindingUtilities.h b/Source/WebCore/bindings/js/IDBBindingUtilities.h new file mode 100644 index 0000000..7e72152 --- /dev/null +++ b/Source/WebCore/bindings/js/IDBBindingUtilities.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef IDBBindingUtilities_h +#define IDBBindingUtilities_h + +#if ENABLE(INDEXED_DATABASE) + +#include "ScriptValue.h" +#include <wtf/Forward.h> + +namespace WebCore { + +class IDBKey; + +PassRefPtr<IDBKey> createIDBKeyFromValue(JSC::ExecState*, JSC::JSValue); + +} + +#endif // ENABLE(INDEXED_DATABASE) + +#endif // IDBBindingUtilities_h diff --git a/Source/WebCore/bindings/js/JSArrayBufferCustom.cpp b/Source/WebCore/bindings/js/JSArrayBufferCustom.cpp new file mode 100644 index 0000000..68edc5c --- /dev/null +++ b/Source/WebCore/bindings/js/JSArrayBufferCustom.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSArrayBuffer.h" + +#include "ArrayBuffer.h" +#include "ExceptionCode.h" +#include <runtime/Error.h> + +namespace WebCore { + +using namespace JSC; + +EncodedJSValue JSC_HOST_CALL JSArrayBufferConstructor::constructJSArrayBuffer(ExecState* exec) +{ + JSArrayBufferConstructor* jsConstructor = static_cast<JSArrayBufferConstructor*>(exec->callee()); + + int length = 0; + if (exec->argumentCount() > 0) + length = exec->argument(0).toInt32(exec); // NaN/+inf/-inf returns 0, this is intended by WebIDL + RefPtr<ArrayBuffer> buffer; + if (length >= 0) + buffer = ArrayBuffer::create(static_cast<unsigned>(length), 1); + if (!buffer.get()) + return throwVMError(exec, createRangeError(exec, "ArrayBuffer size is not a small enough positive integer.")); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), buffer.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h b/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h new file mode 100644 index 0000000..e010406 --- /dev/null +++ b/Source/WebCore/bindings/js/JSArrayBufferViewHelper.h @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSArrayBufferViewHelper_h +#define JSArrayBufferViewHelper_h + +#include "ArrayBufferView.h" +#include "ExceptionCode.h" +#include "JSArrayBuffer.h" +#include "JSDOMBinding.h" +#include <interpreter/CallFrame.h> +#include <runtime/ArgList.h> +#include <runtime/Error.h> +#include <runtime/JSObject.h> +#include <runtime/JSValue.h> + +namespace WebCore { + +template <class T> +JSC::JSValue setWebGLArrayHelper(JSC::ExecState* exec, T* impl, T* (*conversionFunc)(JSC::JSValue)) +{ + if (exec->argumentCount() < 1) + return JSC::throwSyntaxError(exec); + + T* array = (*conversionFunc)(exec->argument(0)); + if (array) { + // void set(in WebGL<T>Array array, [Optional] in unsigned long offset); + unsigned offset = 0; + if (exec->argumentCount() == 2) + offset = exec->argument(1).toInt32(exec); + ExceptionCode ec = 0; + impl->set(array, offset, ec); + setDOMException(exec, ec); + return JSC::jsUndefined(); + } + + if (exec->argument(0).isObject()) { + // void set(in sequence<long> array, [Optional] in unsigned long offset); + JSC::JSObject* array = JSC::asObject(exec->argument(0)); + uint32_t offset = 0; + if (exec->argumentCount() == 2) + offset = exec->argument(1).toInt32(exec); + uint32_t length = array->get(exec, JSC::Identifier(exec, "length")).toInt32(exec); + if (offset > impl->length() + || offset + length > impl->length() + || offset + length < offset) + setDOMException(exec, INDEX_SIZE_ERR); + else { + for (uint32_t i = 0; i < length; i++) { + JSC::JSValue v = array->get(exec, i); + if (exec->hadException()) + return JSC::jsUndefined(); + impl->set(i + offset, v.toNumber(exec)); + } + } + + return JSC::jsUndefined(); + } + + return JSC::throwSyntaxError(exec); +} + +// Template function used by XXXArrayConstructors. +// If this returns 0, it will already have thrown a JavaScript exception. +template<class C, typename T> +PassRefPtr<C> constructArrayBufferViewWithArrayBufferArgument(JSC::ExecState* exec) +{ + RefPtr<ArrayBuffer> buffer = toArrayBuffer(exec->argument(0)); + if (!buffer) + return 0; + + unsigned offset = (exec->argumentCount() > 1) ? exec->argument(1).toUInt32(exec) : 0; + if ((buffer->byteLength() - offset) % sizeof(T)) + throwError(exec, createRangeError(exec, "ArrayBuffer length minus the byteOffset is not a multiple of the element size.")); + unsigned int length = (buffer->byteLength() - offset) / sizeof(T); + if (exec->argumentCount() > 2) + length = exec->argument(2).toUInt32(exec); + RefPtr<C> array = C::create(buffer, offset, length); + if (!array) + setDOMException(exec, INDEX_SIZE_ERR); + return array; +} + +template<typename T> +inline T convertArrayValue(JSC::ExecState* exec, JSC::JSValue v) +{ + // For integral types, NaN values must be converted to zero. + return static_cast<T>(v.toInteger(exec)); +} + +template<> +inline float convertArrayValue(JSC::ExecState* exec, JSC::JSValue v) +{ + return static_cast<float>(v.toNumber(exec)); +} + +template<> +inline double convertArrayValue(JSC::ExecState* exec, JSC::JSValue v) +{ + return static_cast<double>(v.toNumber(exec)); +} + +template<class C, typename T> +PassRefPtr<C> constructArrayBufferView(JSC::ExecState* exec) +{ + // There are 3 constructors: + // + // 1) (in int size) + // 2) (in ArrayBuffer buffer, [Optional] in int offset, [Optional] in unsigned int length) + // 3) (in sequence<T>) - This ends up being a JS "array-like" object + // + // For the 0 args case, just create a zero-length view. We could + // consider raising a SyntaxError for this case, but not all + // JavaScript DOM bindings can distinguish between "new + // <Type>Array()" and what occurs when a previously-constructed + // ArrayBufferView is returned to JavaScript; e.g., from + // "array.slice()". + if (exec->argumentCount() < 1) + return C::create(0); + + if (exec->argument(0).isNull()) { + // Invalid first argument + throwTypeError(exec); + return 0; + } + + if (exec->argument(0).isObject()) { + RefPtr<C> view = constructArrayBufferViewWithArrayBufferArgument<C, T>(exec); + if (view) + return view; + + JSC::JSObject* array = asObject(exec->argument(0)); + unsigned length = array->get(exec, JSC::Identifier(exec, "length")).toUInt32(exec); + void* tempValues; + if (!tryFastCalloc(length, sizeof(T)).getValue(tempValues)) { + JSC::throwError(exec, createError(exec, "Error")); + return 0; + } + + OwnFastMallocPtr<T> values(static_cast<T*>(tempValues)); + for (unsigned i = 0; i < length; ++i) { + JSC::JSValue v = array->get(exec, i); + values.get()[i] = convertArrayValue<T>(exec, v); + } + + RefPtr<C> result = C::create(values.get(), length); + if (!result) + setDOMException(exec, INDEX_SIZE_ERR); + return result; + } + + int length = exec->argument(0).toInt32(exec); + RefPtr<C> result; + if (length >= 0) + result = C::create(static_cast<unsigned>(length)); + if (!result) + throwError(exec, createRangeError(exec, "ArrayBufferView size is not a small enough positive integer.")); + return result; +} + +} // namespace WebCore + +#endif // JSArrayBufferViewHelper_h diff --git a/Source/WebCore/bindings/js/JSAttrCustom.cpp b/Source/WebCore/bindings/js/JSAttrCustom.cpp new file mode 100644 index 0000000..227582d --- /dev/null +++ b/Source/WebCore/bindings/js/JSAttrCustom.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSAttr.h" + +#include "Document.h" +#include "Element.h" +#include "HTMLNames.h" + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +void JSAttr::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + // Mark the element so that this will work to access the attribute even if the last + // other reference goes away. + if (Element* element = impl()->ownerElement()) + markDOMNodeWrapper(markStack, element->document(), element); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSAudioBufferSourceNodeCustom.cpp b/Source/WebCore/bindings/js/JSAudioBufferSourceNodeCustom.cpp new file mode 100644 index 0000000..8ca7f1f --- /dev/null +++ b/Source/WebCore/bindings/js/JSAudioBufferSourceNodeCustom.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WEB_AUDIO) + +#include "AudioBufferSourceNode.h" + +#include "AudioBuffer.h" +#include "JSAudioBuffer.h" +#include "JSAudioBufferSourceNode.h" + +using namespace JSC; + +namespace WebCore { + +void JSAudioBufferSourceNode::setBuffer(ExecState*, JSValue value) +{ + AudioBufferSourceNode* imp = static_cast<AudioBufferSourceNode*>(impl()); + imp->setBuffer(toAudioBuffer(value)); +} + +} // namespace WebCore + +#endif // ENABLE(WEB_AUDIO) diff --git a/Source/WebCore/bindings/js/JSAudioConstructor.cpp b/Source/WebCore/bindings/js/JSAudioConstructor.cpp new file mode 100644 index 0000000..1ea5ae4 --- /dev/null +++ b/Source/WebCore/bindings/js/JSAudioConstructor.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(VIDEO) + +#include "JSAudioConstructor.h" + +#include "HTMLAudioElement.h" +#include "JSHTMLAudioElement.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSAudioConstructor::s_info = { "AudioConstructor", 0, 0, 0 }; + +JSAudioConstructor::JSAudioConstructor(ExecState* exec, JSDOMGlobalObject* globalObject) + : DOMConstructorWithDocument(JSAudioConstructor::createStructure(globalObject->objectPrototype()), globalObject) +{ + putDirect(exec->propertyNames().prototype, JSHTMLAudioElementPrototype::self(exec, globalObject), None); + putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly | DontDelete | DontEnum); +} + +static EncodedJSValue JSC_HOST_CALL constructAudio(ExecState* exec) +{ + JSAudioConstructor* jsConstructor = static_cast<JSAudioConstructor*>(exec->callee()); + + Document* document = jsConstructor->document(); + if (!document) + return throwVMError(exec, createReferenceError(exec, "Audio constructor associated document is unavailable")); + + // Calling toJS on the document causes the JS document wrapper to be + // added to the window object. This is done to ensure that JSDocument::markChildren + // will be called, which will cause the audio element to be marked if necessary. + toJS(exec, jsConstructor->globalObject(), document); + + // FIXME: This converts an undefined argument to the string "undefined", but possibly we + // should treat it as if no argument was passed instead, by checking the value of exec->argument + // rather than looking at exec->argumentCount. + String src; + if (exec->argumentCount() > 0) + src = ustringToString(exec->argument(0).toString(exec)); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), + HTMLAudioElement::createForJSConstructor(document, src)))); +} + +ConstructType JSAudioConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructAudio; + return ConstructTypeHost; +} + +} // namespace WebCore + +#endif // ENABLE(VIDEO) diff --git a/Source/WebCore/bindings/js/JSAudioConstructor.h b/Source/WebCore/bindings/js/JSAudioConstructor.h new file mode 100644 index 0000000..3496897 --- /dev/null +++ b/Source/WebCore/bindings/js/JSAudioConstructor.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSAudioConstructor_h +#define JSAudioConstructor_h + +#if ENABLE(VIDEO) + +#include "JSDOMBinding.h" +#include "JSDocument.h" +#include <wtf/RefPtr.h> + +namespace WebCore { + + class JSAudioConstructor : public DOMConstructorWithDocument { + public: + JSAudioConstructor(JSC::ExecState*, JSDOMGlobalObject*); + + static const JSC::ClassInfo s_info; + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + }; + +} // namespace WebCore + +#endif // ENABLE(VIDEO) + +#endif // JSAudioConstructor_h diff --git a/Source/WebCore/bindings/js/JSAudioContextCustom.cpp b/Source/WebCore/bindings/js/JSAudioContextCustom.cpp new file mode 100644 index 0000000..04644bc --- /dev/null +++ b/Source/WebCore/bindings/js/JSAudioContextCustom.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WEB_AUDIO) + +#include "AudioContext.h" + +#include "JSAudioContext.h" +#include <runtime/Error.h> + +namespace WebCore { + +JSC::EncodedJSValue JSC_HOST_CALL JSAudioContextConstructor::constructJSAudioContext(JSC::ExecState* exec) +{ + JSAudioContextConstructor* jsConstructor = static_cast<JSAudioContextConstructor*>(exec->callee()); + if (!jsConstructor) + return throwError(exec, createReferenceError(exec, "AudioContext constructor callee is unavailable")); + + ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext(); + if (!scriptExecutionContext) + return throwError(exec, createReferenceError(exec, "AudioContext constructor script execution context is unavailable")); + + if (!scriptExecutionContext->isDocument()) + return throwError(exec, createReferenceError(exec, "AudioContext constructor called in a script execution context which is not a document")); + + Document* document = static_cast<Document*>(scriptExecutionContext); + + RefPtr<AudioContext> context = AudioContext::create(document); + return JSC::JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), context.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(WEB_AUDIO) diff --git a/Source/WebCore/bindings/js/JSAudioNodeCustom.cpp b/Source/WebCore/bindings/js/JSAudioNodeCustom.cpp new file mode 100644 index 0000000..67f33f2 --- /dev/null +++ b/Source/WebCore/bindings/js/JSAudioNodeCustom.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WEB_AUDIO) + +#include "JSAudioNode.h" + +#include "AudioNode.h" +#include <runtime/Error.h> + +namespace WebCore { + +JSC::JSValue JSAudioNode::connect(JSC::ExecState* exec) +{ + if (exec->argumentCount() < 1) + return throwError(exec, createSyntaxError(exec, "Not enough arguments")); + + unsigned outputIndex = 0; + unsigned inputIndex = 0; + + AudioNode* destinationNode = toAudioNode(exec->argument(0)); + if (!destinationNode) + return throwError(exec, createSyntaxError(exec, "Invalid destination node")); + + if (exec->argumentCount() > 1) + outputIndex = exec->argument(1).toInt32(exec); + + if (exec->argumentCount() > 2) + inputIndex = exec->argument(2).toInt32(exec); + + AudioNode* audioNode = static_cast<AudioNode*>(impl()); + bool success = audioNode->connect(destinationNode, outputIndex, inputIndex); + if (!success) + return throwError(exec, createSyntaxError(exec, "Invalid index parameter")); + + return JSC::jsUndefined(); +} + +JSC::JSValue JSAudioNode::disconnect(JSC::ExecState* exec) +{ + unsigned outputIndex = 0; + if (exec->argumentCount() > 0) + outputIndex = exec->argument(0).toInt32(exec); + + AudioNode* audioNode = static_cast<AudioNode*>(impl()); + audioNode->disconnect(outputIndex); + return JSC::jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(WEB_AUDIO) diff --git a/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp b/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp new file mode 100644 index 0000000..853e2ef --- /dev/null +++ b/Source/WebCore/bindings/js/JSBindingsAllInOne.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2009, 2010 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This all-in-one cpp file cuts down on template bloat to allow us to build our Windows release build. + +#include "DOMObjectHashTableMap.cpp" +#include "DOMWrapperWorld.cpp" +#include "GCController.cpp" +#include "JSAttrCustom.cpp" +#include "JSAudioConstructor.cpp" +#include "JSCDATASectionCustom.cpp" +#include "JSCSSFontFaceRuleCustom.cpp" +#include "JSCSSImportRuleCustom.cpp" +#include "JSCSSMediaRuleCustom.cpp" +#include "JSCSSPageRuleCustom.cpp" +#include "JSCSSRuleCustom.cpp" +#include "JSCSSRuleListCustom.cpp" +#include "JSCSSStyleDeclarationCustom.cpp" +#include "JSCSSStyleRuleCustom.cpp" +#include "JSCSSValueCustom.cpp" +#include "JSCallbackData.cpp" +#include "JSCanvasRenderingContext2DCustom.cpp" +#include "JSCanvasRenderingContextCustom.cpp" +#include "JSClipboardCustom.cpp" +#include "JSConsoleCustom.cpp" +#include "JSCoordinatesCustom.cpp" +#include "JSCustomPositionCallback.cpp" +#include "JSCustomPositionErrorCallback.cpp" +#include "JSCustomSQLStatementErrorCallback.cpp" +#include "JSCustomVoidCallback.cpp" +#include "JSCustomXPathNSResolver.cpp" +#include "JSDOMApplicationCacheCustom.cpp" +#include "JSDOMBinding.cpp" +#include "JSDOMFormDataCustom.cpp" +#include "JSDOMGlobalObject.cpp" +#include "JSDOMMimeTypeArrayCustom.cpp" +#include "JSDOMPluginArrayCustom.cpp" +#include "JSDOMPluginCustom.cpp" +#include "JSDOMStringMapCustom.cpp" +#include "JSDOMWindowBase.cpp" +#include "JSDOMWindowCustom.cpp" +#include "JSDOMWindowShell.cpp" +#include "JSDOMWrapper.cpp" +#include "JSDataGridColumnListCustom.cpp" +#include "JSDataGridDataSource.cpp" +#include "JSDebugWrapperSet.cpp" +#include "JSDedicatedWorkerContextCustom.cpp" +#include "JSDesktopNotificationsCustom.cpp" +#include "JSDeviceOrientationEventCustom.cpp" +#include "JSDocumentCustom.cpp" +#include "JSElementCustom.cpp" +#include "JSEventCustom.cpp" +#include "JSEventListener.cpp" +#include "JSEventSourceCustom.cpp" +#include "JSEventTarget.cpp" +#include "JSExceptionBase.cpp" +#include "JSGeolocationCustom.cpp" +#include "JSHTMLAllCollectionCustom.cpp" +#include "JSHTMLAppletElementCustom.cpp" +#include "JSHTMLCanvasElementCustom.cpp" +#include "JSHTMLCollectionCustom.cpp" +#include "JSHTMLDataGridElementCustom.cpp" +#include "JSHTMLDocumentCustom.cpp" +#include "JSHTMLElementCustom.cpp" +#include "JSHTMLEmbedElementCustom.cpp" +#include "JSHTMLFormElementCustom.cpp" +#include "JSHTMLFrameElementCustom.cpp" +#include "JSHTMLFrameSetElementCustom.cpp" +#include "JSHTMLInputElementCustom.cpp" +#include "JSHTMLLinkElementCustom.cpp" +#include "JSHTMLObjectElementCustom.cpp" +#include "JSHTMLOptionsCollectionCustom.cpp" +#include "JSHTMLOutputElementCustom.cpp" +#include "JSHTMLSelectElementCustom.cpp" +#include "JSHTMLStyleElementCustom.cpp" +#include "JSHistoryCustom.cpp" +#include "JSImageConstructor.cpp" +#include "JSImageDataCustom.cpp" +#include "JSInjectedScriptHostCustom.cpp" +#include "JSInspectorFrontendHostCustom.cpp" +#include "JSJavaScriptCallFrameCustom.cpp" +#include "JSLazyEventListener.cpp" +#include "JSLocationCustom.cpp" +#include "JSMainThreadExecState.cpp" +#include "JSMessageChannelCustom.cpp" +#include "JSMessageEventCustom.cpp" +#include "JSMessagePortCustom.cpp" +#include "JSNamedNodeMapCustom.cpp" +#include "JSNavigatorCustom.cpp" +#include "JSNodeCustom.cpp" +#include "JSNodeFilterCondition.cpp" +#include "JSNodeFilterCustom.cpp" +#include "JSNodeIteratorCustom.cpp" +#include "JSNodeListCustom.cpp" +#include "JSOptionConstructor.cpp" +#include "JSPluginElementFunctions.cpp" +#include "JSProcessingInstructionCustom.cpp" +#include "JSSQLResultSetRowListCustom.cpp" +#include "JSSQLTransactionCustom.cpp" +#include "JSSQLTransactionSyncCustom.cpp" +#include "JSSVGElementInstanceCustom.cpp" +#include "JSSVGLengthCustom.cpp" +#include "JSSVGPathSegCustom.cpp" +#include "JSScriptProfileNodeCustom.cpp" +#include "JSSharedWorkerCustom.cpp" +#include "JSStorageCustom.cpp" +#include "JSStyleSheetCustom.cpp" +#include "JSStyleSheetListCustom.cpp" +#include "JSTextCustom.cpp" +#include "JSTouchCustom.cpp" +#include "JSTouchListCustom.cpp" +#include "JSTreeWalkerCustom.cpp" +#include "JSWebKitCSSKeyframeRuleCustom.cpp" +#include "JSWebKitCSSKeyframesRuleCustom.cpp" +#include "JSWebKitCSSMatrixCustom.cpp" +#include "JSWebKitPointCustom.cpp" +#include "JSWebSocketCustom.cpp" +#include "JSWorkerContextBase.cpp" +#include "JSWorkerContextCustom.cpp" +#include "JSWorkerContextErrorHandler.cpp" +#include "JSWorkerCustom.cpp" +#include "JSXMLHttpRequestCustom.cpp" +#include "JSXMLHttpRequestUploadCustom.cpp" +#include "JSXSLTProcessorCustom.cpp" +#include "JavaScriptCallFrame.cpp" +#include "MemoryInfo.cpp" +#include "ScheduledAction.cpp" +#include "ScriptCachedFrameData.cpp" +#include "ScriptCallStackFactory.cpp" +#include "ScriptController.cpp" +#include "ScriptControllerWin.cpp" +#include "ScriptDebugServer.cpp" +#include "ScriptEventListener.cpp" +#include "ScriptFunctionCall.cpp" +#include "ScriptGCEvent.cpp" +#include "ScriptProfiler.cpp" +#include "ScriptState.cpp" +#include "SerializedScriptValue.cpp" +#include "WorkerScriptController.cpp" + diff --git a/Source/WebCore/bindings/js/JSCDATASectionCustom.cpp b/Source/WebCore/bindings/js/JSCDATASectionCustom.cpp new file mode 100644 index 0000000..c2738cc --- /dev/null +++ b/Source/WebCore/bindings/js/JSCDATASectionCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCDATASection.h" + +#include "CDATASection.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, CDATASection* section) +{ + if (!section) + return jsNull(); + + return CREATE_DOM_NODE_WRAPPER(exec, globalObject, CDATASection, section); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCSSFontFaceRuleCustom.cpp b/Source/WebCore/bindings/js/JSCSSFontFaceRuleCustom.cpp new file mode 100644 index 0000000..a08c180 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSFontFaceRuleCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSFontFaceRule.h" + +#include "CSSFontFaceRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSFontFaceRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSMutableStyleDeclaration* style = static_cast<CSSFontFaceRule*>(impl())->style()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), style); +} + +} diff --git a/Source/WebCore/bindings/js/JSCSSImportRuleCustom.cpp b/Source/WebCore/bindings/js/JSCSSImportRuleCustom.cpp new file mode 100644 index 0000000..3db517d --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSImportRuleCustom.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSImportRule.h" + +#include "CSSImportRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSImportRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSStyleSheet* sheet = static_cast<CSSImportRule*>(impl())->styleSheet()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), sheet); + + if (MediaList* media = static_cast<CSSImportRule*>(impl())->media()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), media); +} + +} diff --git a/Source/WebCore/bindings/js/JSCSSMediaRuleCustom.cpp b/Source/WebCore/bindings/js/JSCSSMediaRuleCustom.cpp new file mode 100644 index 0000000..b5230fc --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSMediaRuleCustom.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSMediaRule.h" + +#include "CSSMediaRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSMediaRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (MediaList* media = static_cast<CSSMediaRule*>(impl())->media()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), media); + + if (CSSRuleList* rules = static_cast<CSSMediaRule*>(impl())->cssRules()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), rules); +} + +} diff --git a/Source/WebCore/bindings/js/JSCSSPageRuleCustom.cpp b/Source/WebCore/bindings/js/JSCSSPageRuleCustom.cpp new file mode 100644 index 0000000..c7ac04b --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSPageRuleCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSPageRule.h" + +#include "CSSPageRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSPageRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSMutableStyleDeclaration* style = static_cast<CSSPageRule*>(impl())->style()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), style); +} + +} diff --git a/Source/WebCore/bindings/js/JSCSSRuleCustom.cpp b/Source/WebCore/bindings/js/JSCSSRuleCustom.cpp new file mode 100644 index 0000000..4d226d0 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSRuleCustom.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSRule.h" + +#include "CSSCharsetRule.h" +#include "CSSFontFaceRule.h" +#include "CSSImportRule.h" +#include "CSSMediaRule.h" +#include "CSSPageRule.h" +#include "CSSStyleRule.h" +#include "JSCSSCharsetRule.h" +#include "JSCSSFontFaceRule.h" +#include "JSCSSImportRule.h" +#include "JSCSSMediaRule.h" +#include "JSCSSPageRule.h" +#include "JSCSSStyleRule.h" +#include "JSWebKitCSSKeyframeRule.h" +#include "JSWebKitCSSKeyframesRule.h" +#include "WebKitCSSKeyframeRule.h" +#include "WebKitCSSKeyframesRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSStyleSheet* parentStyleSheet = impl()->parentStyleSheet()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), parentStyleSheet); + + if (CSSRule* parentRule = impl()->parentRule()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), parentRule); +} + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, CSSRule* rule) +{ + if (!rule) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec, rule); + if (wrapper) + return wrapper; + + switch (rule->type()) { + case CSSRule::STYLE_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSStyleRule, rule); + break; + case CSSRule::MEDIA_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSMediaRule, rule); + break; + case CSSRule::FONT_FACE_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSFontFaceRule, rule); + break; + case CSSRule::PAGE_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSPageRule, rule); + break; + case CSSRule::IMPORT_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSImportRule, rule); + break; + case CSSRule::CHARSET_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSCharsetRule, rule); + break; + case CSSRule::WEBKIT_KEYFRAME_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitCSSKeyframeRule, rule); + break; + case CSSRule::WEBKIT_KEYFRAMES_RULE: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitCSSKeyframesRule, rule); + break; + default: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSRule, rule); + } + + return wrapper; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCSSRuleListCustom.cpp b/Source/WebCore/bindings/js/JSCSSRuleListCustom.cpp new file mode 100644 index 0000000..be3a9a2 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSRuleListCustom.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2009 Apple Inc. All right reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSRuleList.h" + +#include "CSSRuleList.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSRuleList::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + CSSRuleList* list = impl(); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + unsigned length = list->length(); + for (unsigned i = 0; i < length; ++i) + markDOMObjectWrapper(markStack, globalData, list->item(i)); +} + +} diff --git a/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp new file mode 100644 index 0000000..1a448ee --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSStyleDeclarationCustom.h" + +#include "CSSMutableStyleDeclaration.h" +#include "CSSPrimitiveValue.h" +#include "CSSValue.h" +#include "PlatformString.h" +#include <runtime/StringObjectThatMasqueradesAsUndefined.h> +#include <runtime/StringPrototype.h> +#include <wtf/ASCIICType.h> +#include <wtf/text/AtomicString.h> + +using namespace JSC; +using namespace WTF; + +namespace WebCore { + +void JSCSSStyleDeclaration::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + CSSStyleDeclaration* declaration = impl(); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + if (CSSRule* parentRule = declaration->parentRule()) + markDOMObjectWrapper(markStack, globalData, parentRule); + + if (declaration->isMutableStyleDeclaration()) { + CSSMutableStyleDeclaration* mutableDeclaration = static_cast<CSSMutableStyleDeclaration*>(declaration); + CSSMutableStyleDeclaration::const_iterator end = mutableDeclaration->end(); + for (CSSMutableStyleDeclaration::const_iterator it = mutableDeclaration->begin(); it != end; ++it) + markDOMObjectWrapper(markStack, globalData, it->value()); + } +} + +// Check for a CSS prefix. +// Passed prefix is all lowercase. +// First character of the prefix within the property name may be upper or lowercase. +// Other characters in the prefix within the property name must be lowercase. +// The prefix within the property name must be followed by a capital letter. +static bool hasCSSPropertyNamePrefix(const Identifier& propertyName, const char* prefix) +{ +#ifndef NDEBUG + ASSERT(*prefix); + for (const char* p = prefix; *p; ++p) + ASSERT(isASCIILower(*p)); + ASSERT(propertyName.length()); +#endif + + if (toASCIILower(propertyName.characters()[0]) != prefix[0]) + return false; + + unsigned length = propertyName.length(); + for (unsigned i = 1; i < length; ++i) { + if (!prefix[i]) + return isASCIIUpper(propertyName.characters()[i]); + if (propertyName.characters()[i] != prefix[i]) + return false; + } + return false; +} + +static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0) +{ + if (hadPixelOrPosPrefix) + *hadPixelOrPosPrefix = false; + + unsigned length = propertyName.length(); + if (!length) + return String(); + + Vector<UChar> name; + name.reserveInitialCapacity(length); + + unsigned i = 0; + + if (hasCSSPropertyNamePrefix(propertyName, "css")) + i += 3; + else if (hasCSSPropertyNamePrefix(propertyName, "pixel")) { + i += 5; + if (hadPixelOrPosPrefix) + *hadPixelOrPosPrefix = true; + } else if (hasCSSPropertyNamePrefix(propertyName, "pos")) { + i += 3; + if (hadPixelOrPosPrefix) + *hadPixelOrPosPrefix = true; + } else if (hasCSSPropertyNamePrefix(propertyName, "webkit") + || hasCSSPropertyNamePrefix(propertyName, "khtml") + || hasCSSPropertyNamePrefix(propertyName, "apple")) + name.append('-'); + else { + if (isASCIIUpper(propertyName.characters()[0])) + return String(); + } + + name.append(toASCIILower(propertyName.characters()[i++])); + + for (; i < length; ++i) { + UChar c = propertyName.characters()[i]; + if (!isASCIIUpper(c)) + name.append(c); + else { + name.append('-'); + name.append(toASCIILower(c)); + } + } + + return String::adopt(name); +} + +static bool isCSSPropertyName(const Identifier& propertyName) +{ + return CSSStyleDeclaration::isPropertyName(cssPropertyName(propertyName)); +} + +bool JSCSSStyleDeclaration::canGetItemsForName(ExecState*, CSSStyleDeclaration*, const Identifier& propertyName) +{ + return isCSSPropertyName(propertyName); +} + +// FIXME: You can get these properties, and set them (see putDelegate below), +// but you should also be able to enumerate them. +JSValue JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSCSSStyleDeclaration* thisObj = static_cast<JSCSSStyleDeclaration*>(asObject(slotBase)); + + // Set up pixelOrPos boolean to handle the fact that + // pixelTop returns "CSS Top" as number value in unit pixels + // posTop returns "CSS top" as number value in unit pixels _if_ its a + // positioned element. if it is not a positioned element, return 0 + // from MSIE documentation FIXME: IMPLEMENT THAT (Dirk) + bool pixelOrPos; + String prop = cssPropertyName(propertyName, &pixelOrPos); + RefPtr<CSSValue> v = thisObj->impl()->getPropertyCSSValue(prop); + if (v) { + if (pixelOrPos && v->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) + return jsNumber(static_pointer_cast<CSSPrimitiveValue>(v)->getFloatValue(CSSPrimitiveValue::CSS_PX)); + return jsStringOrNull(exec, v->cssText()); + } + + // If the property is a shorthand property (such as "padding"), + // it can only be accessed using getPropertyValue. + + // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute. + if (propertyName == "filter") + return StringObjectThatMasqueradesAsUndefined::create(exec, stringToUString(thisObj->impl()->getPropertyValue(prop))); + + return jsString(exec, thisObj->impl()->getPropertyValue(prop)); +} + + +bool JSCSSStyleDeclaration::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot&) +{ + if (!isCSSPropertyName(propertyName)) + return false; + + bool pixelOrPos; + String prop = cssPropertyName(propertyName, &pixelOrPos); + String propValue = valueToStringWithNullCheck(exec, value); + if (pixelOrPos) + propValue += "px"; + ExceptionCode ec = 0; + impl()->setProperty(prop, propValue, ec); + setDOMException(exec, ec); + return true; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h new file mode 100644 index 0000000..32ecbe0 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSCSSStyleDeclarationCustom_h +#define JSCSSStyleDeclarationCustom_h + +#include "JSCSSStyleDeclaration.h" + +#endif // JSCSSStyleDeclarationCustom_h diff --git a/Source/WebCore/bindings/js/JSCSSStyleRuleCustom.cpp b/Source/WebCore/bindings/js/JSCSSStyleRuleCustom.cpp new file mode 100644 index 0000000..61745ec --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSStyleRuleCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSStyleRule.h" + +#include "CSSStyleRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSCSSStyleRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSMutableStyleDeclaration* style = static_cast<CSSStyleRule*>(impl())->style()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), style); +} + +} diff --git a/Source/WebCore/bindings/js/JSCSSValueCustom.cpp b/Source/WebCore/bindings/js/JSCSSValueCustom.cpp new file mode 100644 index 0000000..83c1d3a --- /dev/null +++ b/Source/WebCore/bindings/js/JSCSSValueCustom.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCSSValue.h" + +#include "CSSPrimitiveValue.h" +#include "CSSValueList.h" +#include "JSCSSPrimitiveValue.h" +#include "JSCSSValueList.h" +#include "JSWebKitCSSTransformValue.h" +#include "WebKitCSSTransformValue.h" + +#if ENABLE(SVG) +#include "JSSVGColor.h" +#include "JSSVGPaint.h" +#include "SVGColor.h" +#include "SVGPaint.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, CSSValue* value) +{ + if (!value) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec, value); + + if (wrapper) + return wrapper; + + if (value->isWebKitCSSTransformValue()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitCSSTransformValue, value); + else if (value->isValueList()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSValueList, value); +#if ENABLE(SVG) + else if (value->isSVGPaint()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPaint, value); + else if (value->isSVGColor()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGColor, value); +#endif + else if (value->isPrimitiveValue()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSPrimitiveValue, value); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSValue, value); + + return wrapper; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCallbackData.cpp b/Source/WebCore/bindings/js/JSCallbackData.cpp new file mode 100644 index 0000000..204c348 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCallbackData.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCallbackData.h" + +#include "Document.h" +#include "JSDOMBinding.h" +#include "JSMainThreadExecState.h" + +using namespace JSC; + +namespace WebCore { + +void JSCallbackData::deleteData(void* context) +{ + delete static_cast<JSCallbackData*>(context); +} + +JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedException) +{ + ASSERT(callback()); + ASSERT(globalObject()); + + ExecState* exec = globalObject()->globalExec(); + JSValue function = callback()->get(exec, Identifier(exec, "handleEvent")); + + CallData callData; + CallType callType = getCallData(function, callData); + if (callType == CallTypeNone) { + callType = callback()->getCallData(callData); + if (callType == CallTypeNone) + return JSValue(); + function = callback(); + } + + globalObject()->globalData().timeoutChecker.start(); + ScriptExecutionContext* context = globalObject()->scriptExecutionContext(); + // We will fail to get the context if the frame has been detached. + if (!context) + return JSValue(); + + bool contextIsDocument = context->isDocument(); + JSValue result = contextIsDocument + ? JSMainThreadExecState::call(exec, function, callType, callData, callback(), args) + : JSC::call(exec, function, callType, callData, callback(), args); + globalObject()->globalData().timeoutChecker.stop(); + + if (contextIsDocument) + Document::updateStyleForAllDocuments(); + + if (exec->hadException()) { + reportCurrentException(exec); + if (raisedException) + *raisedException = true; + return result; + } + + return result; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCallbackData.h b/Source/WebCore/bindings/js/JSCallbackData.h new file mode 100644 index 0000000..f7b8bfe --- /dev/null +++ b/Source/WebCore/bindings/js/JSCallbackData.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSCallbackData_h +#define JSCallbackData_h + +#include "JSDOMBinding.h" +#include "JSDOMGlobalObject.h" +#include "ScriptExecutionContext.h" +#include <runtime/JSObject.h> +#include <runtime/Protect.h> +#include <wtf/Threading.h> + +namespace WebCore { + +// We have to clean up this data on the context thread because unprotecting a +// JSObject on the wrong thread without synchronization would corrupt the heap +// (and synchronization would be slow). + +class JSCallbackData { +public: + static void deleteData(void*); + + JSCallbackData(JSC::JSObject* callback, JSDOMGlobalObject* globalObject) + : m_callback(callback) + , m_globalObject(globalObject) +#ifndef NDEBUG + , m_thread(currentThread()) +#endif + { + } + + ~JSCallbackData() + { + ASSERT(m_thread == currentThread()); + } + + JSC::JSObject* callback() { return m_callback.get(); } + JSDOMGlobalObject* globalObject() { return m_globalObject.get(); } + + JSC::JSValue invokeCallback(JSC::MarkedArgumentBuffer&, bool* raisedException = 0); + +private: + JSC::ProtectedPtr<JSC::JSObject> m_callback; + JSC::ProtectedPtr<JSDOMGlobalObject> m_globalObject; +#ifndef NDEBUG + ThreadIdentifier m_thread; +#endif +}; + +class DeleteCallbackDataTask : public ScriptExecutionContext::Task { +public: + static PassOwnPtr<DeleteCallbackDataTask> create(JSCallbackData* data) + { + return new DeleteCallbackDataTask(data); + } + + virtual void performTask(ScriptExecutionContext*) + { + delete m_data; + } + virtual bool isCleanupTask() const { return true; } +private: + + DeleteCallbackDataTask(JSCallbackData* data) : m_data(data) {} + + JSCallbackData* m_data; +}; + +} // namespace WebCore + +#endif // JSCallbackData_h diff --git a/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp b/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp new file mode 100644 index 0000000..3bbe9c7 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp @@ -0,0 +1,448 @@ +/* + * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSCanvasRenderingContext2D.h" + +#include "CanvasGradient.h" +#include "CanvasPattern.h" +#include "CanvasRenderingContext2D.h" +#include "CanvasStyle.h" +#include "ExceptionCode.h" +#include "FloatRect.h" +#include "HTMLCanvasElement.h" +#include "HTMLImageElement.h" +#include "HTMLVideoElement.h" +#include "ImageData.h" +#include "JSCanvasGradient.h" +#include "JSCanvasPattern.h" +#include "JSHTMLCanvasElement.h" +#include "JSHTMLImageElement.h" +#include "JSHTMLVideoElement.h" +#include "JSImageData.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +static JSValue toJS(ExecState* exec, CanvasStyle* style) +{ + if (style->canvasGradient()) + return toJS(exec, style->canvasGradient()); + if (style->canvasPattern()) + return toJS(exec, style->canvasPattern()); + return jsString(exec, style->color()); +} + +static PassRefPtr<CanvasStyle> toHTMLCanvasStyle(ExecState*, JSValue value) +{ + if (!value.isObject()) + return 0; + JSObject* object = asObject(value); + if (object->inherits(&JSCanvasGradient::s_info)) + return CanvasStyle::createFromGradient(static_cast<JSCanvasGradient*>(object)->impl()); + if (object->inherits(&JSCanvasPattern::s_info)) + return CanvasStyle::createFromPattern(static_cast<JSCanvasPattern*>(object)->impl()); + return 0; +} + +JSValue JSCanvasRenderingContext2D::strokeStyle(ExecState* exec) const +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + return toJS(exec, context->strokeStyle()); +} + +void JSCanvasRenderingContext2D::setStrokeStyle(ExecState* exec, JSValue value) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + if (value.isString()) { + context->setStrokeColor(ustringToString(asString(value)->value(exec))); + return; + } + context->setStrokeStyle(toHTMLCanvasStyle(exec, value)); +} + +JSValue JSCanvasRenderingContext2D::fillStyle(ExecState* exec) const +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + return toJS(exec, context->fillStyle()); +} + +void JSCanvasRenderingContext2D::setFillStyle(ExecState* exec, JSValue value) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + if (value.isString()) { + context->setFillColor(ustringToString(asString(value)->value(exec))); + return; + } + context->setFillStyle(toHTMLCanvasStyle(exec, value)); +} + +JSValue JSCanvasRenderingContext2D::setFillColor(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + // string arg = named color + // number arg = gray color + // string arg, number arg = named color, alpha + // number arg, number arg = gray color, alpha + // 4 args = r, g, b, a + // 5 args = c, m, y, k, a + switch (exec->argumentCount()) { + case 1: + if (exec->argument(0).isString()) + context->setFillColor(ustringToString(asString(exec->argument(0))->value(exec))); + else + context->setFillColor(exec->argument(0).toFloat(exec)); + break; + case 2: + if (exec->argument(0).isString()) + context->setFillColor(ustringToString(asString(exec->argument(0))->value(exec)), exec->argument(1).toFloat(exec)); + else + context->setFillColor(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec)); + break; + case 4: + context->setFillColor(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec)); + break; + case 5: + context->setFillColor(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)); + break; + default: + return throwSyntaxError(exec); + } + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::setStrokeColor(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + // string arg = named color + // number arg = gray color + // string arg, number arg = named color, alpha + // number arg, number arg = gray color, alpha + // 4 args = r, g, b, a + // 5 args = c, m, y, k, a + switch (exec->argumentCount()) { + case 1: + if (exec->argument(0).isString()) + context->setStrokeColor(ustringToString(asString(exec->argument(0))->value(exec))); + else + context->setStrokeColor(exec->argument(0).toFloat(exec)); + break; + case 2: + if (exec->argument(0).isString()) + context->setStrokeColor(ustringToString(asString(exec->argument(0))->value(exec)), exec->argument(1).toFloat(exec)); + else + context->setStrokeColor(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec)); + break; + case 4: + context->setStrokeColor(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec)); + break; + case 5: + context->setStrokeColor(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)); + break; + default: + return throwSyntaxError(exec); + } + + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::strokeRect(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + if (exec->argumentCount() <= 4) + context->strokeRect(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec)); + else + context->strokeRect(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)); + + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::drawImage(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + // DrawImage has three variants: + // drawImage(img, dx, dy) + // drawImage(img, dx, dy, dw, dh) + // drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh) + // Composite operation is specified with globalCompositeOperation. + // The img parameter can be a <img> or <canvas> element. + JSValue value = exec->argument(0); + if (value.isNull()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + if (!value.isObject()) + return throwTypeError(exec); + + JSObject* o = asObject(value); + ExceptionCode ec = 0; + if (o->inherits(&JSHTMLImageElement::s_info)) { + HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl()); + switch (exec->argumentCount()) { + case 3: + context->drawImage(imgElt, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec); + break; + case 5: + context->drawImage(imgElt, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec); + setDOMException(exec, ec); + break; + case 9: + context->drawImage(imgElt, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)), + FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), + exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec); + setDOMException(exec, ec); + break; + default: + return throwSyntaxError(exec); + } + } else if (o->inherits(&JSHTMLCanvasElement::s_info)) { + HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl()); + switch (exec->argumentCount()) { + case 3: + context->drawImage(canvas, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec); + setDOMException(exec, ec); + break; + case 5: + context->drawImage(canvas, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec); + setDOMException(exec, ec); + break; + case 9: + context->drawImage(canvas, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)), + FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), + exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec); + setDOMException(exec, ec); + break; + default: + return throwSyntaxError(exec); + } +#if ENABLE(VIDEO) + } else if (o->inherits(&JSHTMLVideoElement::s_info)) { + HTMLVideoElement* video = static_cast<HTMLVideoElement*>(static_cast<JSHTMLElement*>(o)->impl()); + switch (exec->argumentCount()) { + case 3: + context->drawImage(video, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec); + break; + case 5: + context->drawImage(video, exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), ec); + setDOMException(exec, ec); + break; + case 9: + context->drawImage(video, FloatRect(exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec)), + FloatRect(exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), + exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec)), ec); + setDOMException(exec, ec); + break; + default: + return throwSyntaxError(exec); + } +#endif + } else + return throwTypeError(exec); + + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::drawImageFromRect(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + JSValue value = exec->argument(0); + if (!value.isObject()) + return throwTypeError(exec); + JSObject* o = asObject(value); + + if (!o->inherits(&JSHTMLImageElement::s_info)) + return throwTypeError(exec); + context->drawImageFromRect(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl()), + exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), + exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), + exec->argument(7).toFloat(exec), exec->argument(8).toFloat(exec), + ustringToString(exec->argument(9).toString(exec))); + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::setShadow(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + switch (exec->argumentCount()) { + case 3: + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec)); + break; + case 4: + if (exec->argument(3).isString()) + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), ustringToString(asString(exec->argument(3))->value(exec))); + else + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec)); + break; + case 5: + if (exec->argument(3).isString()) + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), ustringToString(asString(exec->argument(3))->value(exec)), + exec->argument(4).toFloat(exec)); + else + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec), + exec->argument(4).toFloat(exec)); + break; + case 7: + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec), + exec->argument(4).toFloat(exec), exec->argument(5).toFloat(exec), + exec->argument(6).toFloat(exec)); + break; + case 8: + context->setShadow(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), + exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec), + exec->argument(4).toFloat(exec), exec->argument(5).toFloat(exec), + exec->argument(6).toFloat(exec), exec->argument(7).toFloat(exec)); + break; + default: + return throwSyntaxError(exec); + } + + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::createPattern(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + JSValue value = exec->argument(0); + if (!value.isObject()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + JSObject* o = asObject(value); + + if (o->inherits(&JSHTMLImageElement::s_info)) { + ExceptionCode ec; + JSValue pattern = toJS(exec, + context->createPattern(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(o)->impl()), + valueToStringWithNullCheck(exec, exec->argument(1)), ec).get()); + setDOMException(exec, ec); + return pattern; + } + if (o->inherits(&JSHTMLCanvasElement::s_info)) { + ExceptionCode ec; + JSValue pattern = toJS(exec, + context->createPattern(static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(o)->impl()), + valueToStringWithNullCheck(exec, exec->argument(1)), ec).get()); + setDOMException(exec, ec); + return pattern; + } + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::createImageData(ExecState* exec) +{ + // createImageData has two variants + // createImageData(ImageData) + // createImageData(width, height) + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + RefPtr<ImageData> imageData = 0; + + ExceptionCode ec = 0; + if (exec->argumentCount() == 1) + imageData = context->createImageData(toImageData(exec->argument(0)), ec); + else if (exec->argumentCount() == 2) + imageData = context->createImageData(exec->argument(0).toFloat(exec), exec->argument(1).toFloat(exec), ec); + + setDOMException(exec, ec); + return toJS(exec, globalObject(), WTF::getPtr(imageData)); +} + +JSValue JSCanvasRenderingContext2D::putImageData(ExecState* exec) +{ + // putImageData has two variants + // putImageData(ImageData, x, y) + // putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + ExceptionCode ec = 0; + if (exec->argumentCount() >= 7) + context->putImageData(toImageData(exec->argument(0)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), + exec->argument(3).toFloat(exec), exec->argument(4).toFloat(exec), exec->argument(5).toFloat(exec), exec->argument(6).toFloat(exec), ec); + else + context->putImageData(toImageData(exec->argument(0)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), ec); + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::fillText(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + // string arg = text to draw + // number arg = x + // number arg = y + // optional number arg = maxWidth + if (exec->argumentCount() < 3 || exec->argumentCount() > 4) + return throwSyntaxError(exec); + + if (exec->argumentCount() == 4) + context->fillText(ustringToString(exec->argument(0).toString(exec)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec)); + else + context->fillText(ustringToString(exec->argument(0).toString(exec)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec)); + return jsUndefined(); +} + +JSValue JSCanvasRenderingContext2D::strokeText(ExecState* exec) +{ + CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl()); + + // string arg = text to draw + // number arg = x + // number arg = y + // optional number arg = maxWidth + if (exec->argumentCount() < 3 || exec->argumentCount() > 4) + return throwSyntaxError(exec); + + if (exec->argumentCount() == 4) + context->strokeText(ustringToString(exec->argument(0).toString(exec)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec), exec->argument(3).toFloat(exec)); + else + context->strokeText(ustringToString(exec->argument(0).toString(exec)), exec->argument(1).toFloat(exec), exec->argument(2).toFloat(exec)); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCanvasRenderingContextCustom.cpp b/Source/WebCore/bindings/js/JSCanvasRenderingContextCustom.cpp new file mode 100644 index 0000000..df24eb7 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCanvasRenderingContextCustom.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCanvasRenderingContext.h" + +#include "CanvasRenderingContext2D.h" +#include "JSCanvasRenderingContext2D.h" +#if ENABLE(3D_CANVAS) +#include "WebGLRenderingContext.h" +#include "JSWebGLRenderingContext.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, CanvasRenderingContext* object) +{ + if (!object) + return jsUndefined(); + +#if ENABLE(3D_CANVAS) + if (object->is3d()) + return getDOMObjectWrapper<JSWebGLRenderingContext>(exec, globalObject, static_cast<WebGLRenderingContext*>(object)); +#endif + ASSERT(object->is2d()); + return getDOMObjectWrapper<JSCanvasRenderingContext2D>(exec, globalObject, static_cast<CanvasRenderingContext2D*>(object)); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSClipboardCustom.cpp b/Source/WebCore/bindings/js/JSClipboardCustom.cpp new file mode 100644 index 0000000..17c6640 --- /dev/null +++ b/Source/WebCore/bindings/js/JSClipboardCustom.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSClipboard.h" + +#include "Clipboard.h" +#include "Element.h" +#include "HTMLImageElement.h" +#include "HTMLNames.h" +#include "IntPoint.h" +#include "JSNode.h" +#include "Node.h" +#include "PlatformString.h" +#include <runtime/ArrayPrototype.h> +#include <runtime/Error.h> +#include <wtf/HashSet.h> +#include <wtf/text/StringHash.h> + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +JSValue JSClipboard::types(ExecState* exec) const +{ + Clipboard* clipboard = impl(); + + HashSet<String> types = clipboard->types(); + if (types.isEmpty()) + return jsNull(); + + MarkedArgumentBuffer list; + HashSet<String>::const_iterator end = types.end(); + for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it) + list.append(jsString(exec, stringToUString(*it))); + return constructArray(exec, list); +} + +JSValue JSClipboard::clearData(ExecState* exec) +{ + Clipboard* clipboard = impl(); + + if (!exec->argumentCount()) { + clipboard->clearAllData(); + return jsUndefined(); + } + + if (exec->argumentCount() == 1) { + clipboard->clearData(ustringToString(exec->argument(0).toString(exec))); + return jsUndefined(); + } + + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + return throwError(exec, createSyntaxError(exec, "clearData: Invalid number of arguments")); +} + +JSValue JSClipboard::getData(ExecState* exec) +{ + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + if (exec->argumentCount() != 1) + return throwError(exec, createSyntaxError(exec, "getData: Invalid number of arguments")); + + Clipboard* clipboard = impl(); + + bool success; + String result = clipboard->getData(ustringToString(exec->argument(0).toString(exec)), success); + if (!success) + return jsUndefined(); + + return jsString(exec, result); +} + +JSValue JSClipboard::setDragImage(ExecState* exec) +{ + Clipboard* clipboard = impl(); + + if (!clipboard->isForDragAndDrop()) + return jsUndefined(); + + // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. + if (exec->argumentCount() != 3) + return throwError(exec, createSyntaxError(exec, "setDragImage: Invalid number of arguments")); + + int x = exec->argument(1).toInt32(exec); + int y = exec->argument(2).toInt32(exec); + + // See if they passed us a node + Node* node = toNode(exec->argument(0)); + if (!node) + return throwTypeError(exec); + + // FIXME: This should probably be a TypeError. + if (!node->isElementNode()) + return throwError(exec, createSyntaxError(exec, "setDragImageFromElement: Invalid first argument")); + + if (static_cast<Element*>(node)->hasLocalName(imgTag) && !node->inDocument()) + clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y)); + else + clipboard->setDragImageElement(node, IntPoint(x, y)); + + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSConsoleCustom.cpp b/Source/WebCore/bindings/js/JSConsoleCustom.cpp new file mode 100644 index 0000000..6a4fb17 --- /dev/null +++ b/Source/WebCore/bindings/js/JSConsoleCustom.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "JSConsole.h" + +#include "Console.h" +#include "JSScriptProfile.h" +#include "ScriptCallStack.h" +#include "ScriptCallStackFactory.h" +#include "ScriptProfile.h" +#include <runtime/JSArray.h> +#include <wtf/OwnPtr.h> + +using namespace JSC; + +namespace WebCore { + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +typedef Vector<RefPtr<ScriptProfile> > ProfilesArray; + +JSValue JSConsole::profiles(ExecState* exec) const +{ + const ProfilesArray& profiles = impl()->profiles(); + MarkedArgumentBuffer list; + + ProfilesArray::const_iterator end = profiles.end(); + for (ProfilesArray::const_iterator iter = profiles.begin(); iter != end; ++iter) + list.append(toJS(exec, iter->get())); + + return constructArray(exec, list); +} + +JSValue JSConsole::profile(ExecState* exec) +{ + RefPtr<ScriptCallStack> callStack(createScriptCallStack(exec, 1)); + const String& title = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + impl()->profile(title, exec, callStack); + return jsUndefined(); +} + +JSValue JSConsole::profileEnd(ExecState* exec) +{ + RefPtr<ScriptCallStack> callStack(createScriptCallStack(exec, 1)); + const String& title = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + impl()->profileEnd(title, exec, callStack); + return jsUndefined(); +} + +#endif + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSConvolverNodeCustom.cpp b/Source/WebCore/bindings/js/JSConvolverNodeCustom.cpp new file mode 100644 index 0000000..db7e244 --- /dev/null +++ b/Source/WebCore/bindings/js/JSConvolverNodeCustom.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WEB_AUDIO) + +#include "ConvolverNode.h" + +#include "AudioBuffer.h" +#include "JSAudioBuffer.h" +#include "JSConvolverNode.h" + +using namespace JSC; + +namespace WebCore { + +void JSConvolverNode::setBuffer(ExecState*, JSValue value) +{ + ConvolverNode* imp = static_cast<ConvolverNode*>(impl()); + imp->setBuffer(toAudioBuffer(value)); +} + +} // namespace WebCore + +#endif // ENABLE(WEB_AUDIO) diff --git a/Source/WebCore/bindings/js/JSCoordinatesCustom.cpp b/Source/WebCore/bindings/js/JSCoordinatesCustom.cpp new file mode 100644 index 0000000..8ef34ad --- /dev/null +++ b/Source/WebCore/bindings/js/JSCoordinatesCustom.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCoordinates.h" + +#include "Coordinates.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSCoordinates::altitude(ExecState*) const +{ + Coordinates* imp = impl(); + if (!imp->canProvideAltitude()) + return jsNull(); + return jsNumber(imp->altitude()); +} + +JSValue JSCoordinates::altitudeAccuracy(ExecState*) const +{ + Coordinates* imp = impl(); + if (!imp->canProvideAltitudeAccuracy()) + return jsNull(); + return jsNumber(imp->altitudeAccuracy()); +} + +JSValue JSCoordinates::heading(ExecState*) const +{ + Coordinates* imp = impl(); + if (!imp->canProvideHeading()) + return jsNull(); + return jsNumber(imp->heading()); +} + +JSValue JSCoordinates::speed(ExecState*) const +{ + Coordinates* imp = impl(); + if (!imp->canProvideSpeed()) + return jsNull(); + return jsNumber(imp->speed()); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCustomPositionCallback.cpp b/Source/WebCore/bindings/js/JSCustomPositionCallback.cpp new file mode 100644 index 0000000..8990520 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomPositionCallback.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCustomPositionCallback.h" + +#if ENABLE(GEOLOCATION) + +#include "Frame.h" +#include "JSGeoposition.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomPositionCallback::JSCustomPositionCallback(JSObject* callback, JSDOMGlobalObject* globalObject) + : PositionCallback(globalObject->scriptExecutionContext()) + , m_data(callback, globalObject) +{ +} + +void JSCustomPositionCallback::handleEvent(Geoposition* geoposition) +{ + // ActiveDOMObject will null our pointer to the ScriptExecutionContext when it goes away. + if (!scriptExecutionContext()) + return; + + RefPtr<JSCustomPositionCallback> protect(this); + + JSC::JSLock lock(SilenceAssertionsOnly); + ExecState* exec = m_data.globalObject()->globalExec(); + MarkedArgumentBuffer args; + args.append(toJS(exec, deprecatedGlobalObjectForPrototype(exec), geoposition)); + m_data.invokeCallback(args); +} + +} // namespace WebCore + +#endif // ENABLE(GEOLOCATION) diff --git a/Source/WebCore/bindings/js/JSCustomPositionCallback.h b/Source/WebCore/bindings/js/JSCustomPositionCallback.h new file mode 100644 index 0000000..ad5528d --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomPositionCallback.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSCustomPositionCallback_h +#define JSCustomPositionCallback_h + +#include "JSCallbackData.h" +#include "PositionCallback.h" +#include <wtf/Forward.h> + +namespace WebCore { + +class Geoposition; +class JSDOMGlobalObject; + +class JSCustomPositionCallback : public PositionCallback { +public: + static PassRefPtr<JSCustomPositionCallback> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject) + { + return adoptRef(new JSCustomPositionCallback(callback, globalObject)); + } + +private: + JSCustomPositionCallback(JSC::JSObject* callback, JSDOMGlobalObject*); + + virtual void handleEvent(Geoposition*); + + JSCallbackData m_data; +}; + +} // namespace WebCore + +#endif // JSCustomPositionCallback_h diff --git a/Source/WebCore/bindings/js/JSCustomPositionErrorCallback.cpp b/Source/WebCore/bindings/js/JSCustomPositionErrorCallback.cpp new file mode 100644 index 0000000..1777387 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomPositionErrorCallback.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCustomPositionErrorCallback.h" + +#if ENABLE(GEOLOCATION) + +#include "Frame.h" +#include "JSPositionError.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomPositionErrorCallback::JSCustomPositionErrorCallback(JSObject* callback, JSDOMGlobalObject* globalObject) + : PositionErrorCallback(globalObject->scriptExecutionContext()) + , m_data(callback, globalObject) +{ +} + +void JSCustomPositionErrorCallback::handleEvent(PositionError* positionError) +{ + // ActiveDOMObject will null our pointer to the ScriptExecutionContext when it goes away. + if (!scriptExecutionContext()) + return; + + RefPtr<JSCustomPositionErrorCallback> protect(this); + + JSC::JSLock lock(SilenceAssertionsOnly); + ExecState* exec = m_data.globalObject()->globalExec(); + MarkedArgumentBuffer args; + args.append(toJS(exec, deprecatedGlobalObjectForPrototype(exec), positionError)); + + m_data.invokeCallback(args); +} + +} // namespace WebCore + +#endif // ENABLE(GEOLOCATION) diff --git a/Source/WebCore/bindings/js/JSCustomPositionErrorCallback.h b/Source/WebCore/bindings/js/JSCustomPositionErrorCallback.h new file mode 100644 index 0000000..59328ca --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomPositionErrorCallback.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSCustomPositionErrorCallback_h +#define JSCustomPositionErrorCallback_h + +#include "JSCallbackData.h" +#include "PositionErrorCallback.h" +#include <wtf/Forward.h> + +namespace WebCore { + +class PositionError; + +class JSCustomPositionErrorCallback : public PositionErrorCallback { +public: + static PassRefPtr<JSCustomPositionErrorCallback> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject) + { + return adoptRef(new JSCustomPositionErrorCallback(callback, globalObject)); + } + +private: + JSCustomPositionErrorCallback(JSC::JSObject* callback, JSDOMGlobalObject* globalObject); + virtual void handleEvent(PositionError*); + + JSCallbackData m_data; +}; + +} // namespace WebCore + +#endif // JSCustomPositionErrorCallback_h diff --git a/Source/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp b/Source/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp new file mode 100644 index 0000000..69c8865 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSSQLStatementErrorCallback.h" + +#if ENABLE(DATABASE) + +#include "JSSQLError.h" +#include "JSSQLTransaction.h" +#include "ScriptExecutionContext.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +bool JSSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error) +{ + if (!m_data || !m_data->globalObject() || !canInvokeCallback()) + return true; + + RefPtr<JSSQLStatementErrorCallback> protect(this); + + JSC::JSLock lock(SilenceAssertionsOnly); + + ExecState* exec = m_data->globalObject()->globalExec(); + MarkedArgumentBuffer args; + args.append(toJS(exec, transaction)); + args.append(toJS(exec, error)); + + bool raisedException = false; + JSValue result = m_data->invokeCallback(args, &raisedException); + if (raisedException) { + // The spec says: + // "If the error callback returns false, then move on to the next statement..." + // "Otherwise, the error callback did not return false, or there was no error callback" + // Therefore an exception and returning true are the same thing - so, return true on an exception + return true; + } + return result.toBoolean(exec); +} + +} + +#endif // ENABLE(DATABASE) diff --git a/Source/WebCore/bindings/js/JSCustomVoidCallback.cpp b/Source/WebCore/bindings/js/JSCustomVoidCallback.cpp new file mode 100644 index 0000000..96b5412 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomVoidCallback.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCustomVoidCallback.h" + +#include "Frame.h" +#include "JSCallbackData.h" +#include "JSDOMWindowCustom.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> +#include <wtf/MainThread.h> + +namespace WebCore { + +using namespace JSC; + +JSCustomVoidCallback::JSCustomVoidCallback(JSObject* callback, JSDOMGlobalObject* globalObject) + : m_data(new JSCallbackData(callback, globalObject)) + , m_scriptExecutionContext(globalObject->scriptExecutionContext()) +{ +} + +JSCustomVoidCallback::~JSCustomVoidCallback() +{ + if (m_scriptExecutionContext->isContextThread()) + delete m_data; + else + m_scriptExecutionContext->postTask(DeleteCallbackDataTask::create(m_data)); +#ifndef NDEBUG + m_data = 0; +#endif +} + +void JSCustomVoidCallback::handleEvent() +{ + ASSERT(m_data); + + RefPtr<JSCustomVoidCallback> protect(this); + + JSC::JSLock lock(SilenceAssertionsOnly); + MarkedArgumentBuffer args; + m_data->invokeCallback(args); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSCustomVoidCallback.h b/Source/WebCore/bindings/js/JSCustomVoidCallback.h new file mode 100644 index 0000000..8ffee48 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomVoidCallback.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSCustomVoidCallback_h +#define JSCustomVoidCallback_h + +#include "JSDOMGlobalObject.h" +#include "VoidCallback.h" +#include <runtime/Protect.h> +#include <wtf/Forward.h> + +namespace WebCore { + +class JSCallbackData; + +class JSCustomVoidCallback : public VoidCallback { +public: + static PassRefPtr<JSCustomVoidCallback> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject) + { + return adoptRef(new JSCustomVoidCallback(callback, globalObject)); + } + + virtual ~JSCustomVoidCallback(); + + virtual void handleEvent(); + +private: + JSCustomVoidCallback(JSC::JSObject* callback, JSDOMGlobalObject*); + + JSCallbackData* m_data; + ScriptExecutionContext* m_scriptExecutionContext; +}; + +} // namespace WebCore + +#endif // JSCustomVoidCallback_h diff --git a/Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp b/Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp new file mode 100644 index 0000000..e8e1369 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSCustomXPathNSResolver.h" + +#if ENABLE(XPATH) + +#include "Document.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "JSDOMWindowCustom.h" +#include "ScriptController.h" +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +PassRefPtr<JSCustomXPathNSResolver> JSCustomXPathNSResolver::create(JSC::ExecState* exec, JSC::JSValue value) +{ + if (value.isUndefinedOrNull()) + return 0; + + JSObject* resolverObject = value.getObject(); + if (!resolverObject) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return 0; + } + + return adoptRef(new JSCustomXPathNSResolver(resolverObject, asJSDOMWindow(exec->dynamicGlobalObject()))); +} + +JSCustomXPathNSResolver::JSCustomXPathNSResolver(JSObject* customResolver, JSDOMWindow* globalObject) + : m_customResolver(customResolver) + , m_globalObject(globalObject) +{ +} + +JSCustomXPathNSResolver::~JSCustomXPathNSResolver() +{ +} + +String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix) +{ + ASSERT(m_customResolver); + + JSLock lock(SilenceAssertionsOnly); + + ExecState* exec = m_globalObject->globalExec(); + + JSValue function = m_customResolver->get(exec, Identifier(exec, "lookupNamespaceURI")); + CallData callData; + CallType callType = getCallData(function, callData); + if (callType == CallTypeNone) { + callType = m_customResolver->getCallData(callData); + if (callType == CallTypeNone) { + // FIXME: Pass actual line number and source URL. + m_globalObject->impl()->console()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String()); + return String(); + } + function = m_customResolver; + } + + RefPtr<JSCustomXPathNSResolver> selfProtector(this); + + MarkedArgumentBuffer args; + args.append(jsString(exec, prefix)); + + m_globalObject->globalData().timeoutChecker.start(); + JSValue retval = JSC::call(exec, function, callType, callData, m_customResolver, args); + m_globalObject->globalData().timeoutChecker.stop(); + + String result; + if (exec->hadException()) + reportCurrentException(exec); + else { + if (!retval.isUndefinedOrNull()) + result = ustringToString(retval.toString(exec)); + } + + Document::updateStyleForAllDocuments(); + + return result; +} + +} // namespace WebCore + +#endif // ENABLE(XPATH) diff --git a/Source/WebCore/bindings/js/JSCustomXPathNSResolver.h b/Source/WebCore/bindings/js/JSCustomXPathNSResolver.h new file mode 100644 index 0000000..7d66494 --- /dev/null +++ b/Source/WebCore/bindings/js/JSCustomXPathNSResolver.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSCustomXPathNSResolver_h +#define JSCustomXPathNSResolver_h + +#if ENABLE(XPATH) + +#include "XPathNSResolver.h" +#include <runtime/JSValue.h> +#include <wtf/Forward.h> +#include <wtf/RefPtr.h> + +namespace JSC { + class ExecState; + class JSObject; +} + +namespace WebCore { + + class Frame; + class JSDOMWindow; + + class JSCustomXPathNSResolver : public XPathNSResolver { + public: + static PassRefPtr<JSCustomXPathNSResolver> create(JSC::ExecState*, JSC::JSValue); + + virtual ~JSCustomXPathNSResolver(); + + virtual String lookupNamespaceURI(const String& prefix); + + private: + JSCustomXPathNSResolver(JSC::JSObject*, JSDOMWindow*); + + // JSCustomXPathNSResolvers are always temporary, thus no need to GC protect the objects. + JSC::JSObject* m_customResolver; + JSDOMWindow* m_globalObject; + }; + +} // namespace WebCore + +#endif // ENABLE(XPATH) + +#endif // JSCustomXPathNSResolver_h diff --git a/Source/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp b/Source/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp new file mode 100644 index 0000000..263f2f9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMApplicationCacheCustom.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMApplicationCache.h" + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + +#include "DOMApplicationCache.h" +#include "DOMWindow.h" +#include "Event.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "JSDOMWindowCustom.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +#if ENABLE(APPLICATION_CACHE_DYNAMIC_ENTRIES) + +JSValue JSDOMApplicationCache::hasItem(ExecState* exec) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + const KURL& url = frame->loader()->completeURL(exec->argument(0).toString(exec)); + + ExceptionCode ec = 0; + bool result = impl()->hasItem(url, ec); + setDOMException(exec, ec); + return jsBoolean(result); +} + +JSValue JSDOMApplicationCache::add(ExecState* exec) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + const KURL& url = frame->loader()->completeURL(exec->argument(0).toString(exec)); + + ExceptionCode ec = 0; + impl()->add(url, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSDOMApplicationCache::remove(ExecState* exec) +{ + Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + if (!frame) + return jsUndefined(); + const KURL& url = frame->loader()->completeURL(exec->argument(0).toString(exec)); + + ExceptionCode ec = 0; + impl()->remove(url, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +#endif // ENABLE(APPLICATION_CACHE_DYNAMIC_ENTRIES) + +} // namespace WebCore + +#endif // ENABLE(OFFLINE_WEB_APPLICATIONS) diff --git a/Source/WebCore/bindings/js/JSDOMBinding.cpp b/Source/WebCore/bindings/js/JSDOMBinding.cpp new file mode 100644 index 0000000..72c7cd6 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMBinding.cpp @@ -0,0 +1,751 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMBinding.h" + +#include "debugger/DebuggerCallFrame.h" + +#include "ActiveDOMObject.h" +#include "DOMCoreException.h" +#include "DOMObjectHashTableMap.h" +#include "Document.h" +#include "EventException.h" +#include "ExceptionBase.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "HTMLAudioElement.h" +#include "HTMLCanvasElement.h" +#include "HTMLFrameElementBase.h" +#include "HTMLImageElement.h" +#include "HTMLLinkElement.h" +#include "HTMLNames.h" +#include "HTMLScriptElement.h" +#include "HTMLStyleElement.h" +#include "JSDOMCoreException.h" +#include "JSDOMWindowCustom.h" +#include "JSDebugWrapperSet.h" +#include "JSEventException.h" +#include "JSExceptionBase.h" +#include "JSMainThreadExecState.h" +#include "JSNode.h" +#include "JSRangeException.h" +#include "JSXMLHttpRequestException.h" +#include "KURL.h" +#include "MessagePort.h" +#include "ProcessingInstruction.h" +#include "RangeException.h" +#include "ScriptCachedFrameData.h" +#include "ScriptController.h" +#include "Settings.h" +#include "WebCoreJSClientData.h" +#include "XMLHttpRequestException.h" +#include <runtime/DateInstance.h> +#include <runtime/Error.h> +#include <runtime/JSFunction.h> +#include <runtime/PrototypeFunction.h> +#include <wtf/MathExtras.h> +#include <wtf/StdLibExtras.h> + +#if ENABLE(SVG) +#include "JSSVGException.h" +#include "SVGException.h" +#endif + +#if ENABLE(XPATH) +#include "JSXPathException.h" +#include "XPathException.h" +#endif + +#if ENABLE(DATABASE) +#include "JSSQLException.h" +#include "SQLException.h" +#endif + +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) +#include "FileException.h" +#include "JSFileException.h" +#endif + +#if ENABLE(INDEXED_DATABASE) +#include "IDBDatabaseException.h" +#include "JSIDBDatabaseException.h" +#endif + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +typedef Document::JSWrapperCache JSWrapperCache; +typedef Document::JSWrapperCacheMap JSWrapperCacheMap; + +class JSGlobalDataWorldIterator { +public: + JSGlobalDataWorldIterator(JSGlobalData* globalData) + : m_pos(static_cast<WebCoreJSClientData*>(globalData->clientData)->m_worldSet.begin()) + , m_end(static_cast<WebCoreJSClientData*>(globalData->clientData)->m_worldSet.end()) + { + } + + operator bool() + { + return m_pos != m_end; + } + + DOMWrapperWorld* operator*() + { + ASSERT(m_pos != m_end); + return *m_pos; + } + + DOMWrapperWorld* operator->() + { + ASSERT(m_pos != m_end); + return *m_pos; + } + + JSGlobalDataWorldIterator& operator++() + { + ++m_pos; + return *this; + } + +private: + HashSet<DOMWrapperWorld*>::iterator m_pos; + HashSet<DOMWrapperWorld*>::iterator m_end; +}; + +const JSC::HashTable* getHashTableForGlobalData(JSGlobalData& globalData, const JSC::HashTable* staticTable) +{ + return DOMObjectHashTableMap::mapFor(globalData).get(staticTable); +} + +bool hasCachedDOMObjectWrapperUnchecked(JSGlobalData* globalData, void* objectHandle) +{ + for (JSGlobalDataWorldIterator worldIter(globalData); worldIter; ++worldIter) { + if (worldIter->m_wrappers.uncheckedGet(objectHandle)) + return true; + } + return false; +} + +bool hasCachedDOMObjectWrapper(JSGlobalData* globalData, void* objectHandle) +{ + for (JSGlobalDataWorldIterator worldIter(globalData); worldIter; ++worldIter) { + if (worldIter->m_wrappers.get(objectHandle)) + return true; + } + return false; +} + +DOMObject* getCachedDOMObjectWrapper(JSC::ExecState* exec, void* objectHandle) +{ + return domObjectWrapperMapFor(exec).get(objectHandle); +} + +void cacheDOMObjectWrapper(JSC::ExecState* exec, void* objectHandle, DOMObject* wrapper) +{ + JSDebugWrapperSet::willCacheWrapper(wrapper); + domObjectWrapperMapFor(exec).set(objectHandle, wrapper); +} + +bool hasCachedDOMNodeWrapperUnchecked(Document* document, Node* node) +{ + if (!document) + return hasCachedDOMObjectWrapperUnchecked(JSDOMWindow::commonJSGlobalData(), node); + + JSWrapperCacheMap& wrapperCacheMap = document->wrapperCacheMap(); + for (JSWrapperCacheMap::iterator iter = wrapperCacheMap.begin(); iter != wrapperCacheMap.end(); ++iter) { + if (iter->second->uncheckedGet(node)) + return true; + } + return false; +} + +void forgetDOMObject(DOMObject* wrapper, void* objectHandle) +{ + JSC::JSGlobalData* globalData = Heap::heap(wrapper)->globalData(); + + // Check the normal world first! + JSGlobalData::ClientData* clientData = globalData->clientData; + ASSERT(clientData); + DOMObjectWrapperMap& wrappers = static_cast<WebCoreJSClientData*>(clientData)->normalWorld()->m_wrappers; + if (wrappers.uncheckedRemove(objectHandle, wrapper)) { + JSDebugWrapperSet::didUncacheWrapper(wrapper); + return; + } + + // We can't guarantee that a wrapper is in the cache when it uncaches itself, + // since a new wrapper may be cached before the old wrapper's destructor runs. + for (JSGlobalDataWorldIterator worldIter(globalData); worldIter; ++worldIter) { + if (worldIter->m_wrappers.uncheckedRemove(objectHandle, wrapper)) + break; + } + JSDebugWrapperSet::didUncacheWrapper(wrapper); +} + +void forgetDOMNode(JSNode* wrapper, Node* node, Document* document) +{ + node->clearWrapper(wrapper); + + if (!document) { + forgetDOMObject(wrapper, node); + return; + } + + // We can't guarantee that a wrapper is in the cache when it uncaches itself, + // since a new wrapper may be cached before the old wrapper's destructor runs. + JSWrapperCacheMap& wrapperCacheMap = document->wrapperCacheMap(); + for (JSWrapperCacheMap::iterator wrappersIter = wrapperCacheMap.begin(); wrappersIter != wrapperCacheMap.end(); ++wrappersIter) { + if (wrappersIter->second->uncheckedRemove(node, wrapper)) + break; + } + JSDebugWrapperSet::didUncacheWrapper(wrapper); +} + +void cacheDOMNodeWrapper(JSC::ExecState* exec, Document* document, Node* node, JSNode* wrapper) +{ + JSDebugWrapperSet::willCacheWrapper(wrapper); + + if (!document) + domObjectWrapperMapFor(exec).set(node, wrapper); + else + document->getWrapperCache(currentWorld(exec))->set(node, wrapper); + + if (currentWorld(exec)->isNormal()) + node->setWrapper(wrapper); +} + +static inline bool isObservableThroughDOM(JSNode* jsNode, DOMWrapperWorld* world) +{ + // Certain conditions implicitly make existence of a JS DOM node wrapper observable + // through the DOM, even if no explicit reference to it remains. + + Node* node = jsNode->impl(); + + if (node->inDocument()) { + // If a node is in the document, and its wrapper has custom properties, + // the wrapper is observable because future access to the node through the + // DOM must reflect those properties. + if (jsNode->hasCustomProperties()) + return true; + + // If a node is in the document, and has event listeners, its wrapper is + // observable because its wrapper is responsible for marking those event listeners. + if (node->hasEventListeners()) + return true; // Technically, we may overzealously mark a wrapper for a node that has only non-JS event listeners. Oh well. + + // If a node owns another object with a wrapper with custom properties, + // the wrapper must be treated as observable, because future access to + // those objects through the DOM must reflect those properties. + // FIXME: It would be better if this logic could be in the node next to + // the custom markChildren functions rather than here. + // Note that for some compound objects like stylesheets and CSSStyleDeclarations, + // we don't descend to check children for custom properties, and just conservatively + // keep the node wrappers protecting them alive. + if (node->isElementNode()) { + if (NamedNodeMap* attributes = static_cast<Element*>(node)->attributeMap()) { + if (DOMObject* wrapper = world->m_wrappers.uncheckedGet(attributes)) { + // FIXME: This check seems insufficient, because NamedNodeMap items can have custom properties themselves. + // Maybe it would be OK to just keep the wrapper alive, as it is done for CSSOM objects below. + if (wrapper->hasCustomProperties()) + return true; + } + } + if (node->isStyledElement()) { + if (CSSMutableStyleDeclaration* style = static_cast<StyledElement*>(node)->inlineStyleDecl()) { + if (world->m_wrappers.uncheckedGet(style)) + return true; + } + } + if (static_cast<Element*>(node)->hasTagName(canvasTag)) { + if (CanvasRenderingContext* context = static_cast<HTMLCanvasElement*>(node)->renderingContext()) { + if (DOMObject* wrapper = world->m_wrappers.uncheckedGet(context)) { + if (wrapper->hasCustomProperties()) + return true; + } + } + } else if (static_cast<Element*>(node)->hasTagName(linkTag)) { + if (StyleSheet* sheet = static_cast<HTMLLinkElement*>(node)->sheet()) { + if (world->m_wrappers.uncheckedGet(sheet)) + return true; + } + } else if (static_cast<Element*>(node)->hasTagName(styleTag)) { + if (StyleSheet* sheet = static_cast<HTMLStyleElement*>(node)->sheet()) { + if (world->m_wrappers.uncheckedGet(sheet)) + return true; + } + } + } else if (node->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) { + if (StyleSheet* sheet = static_cast<ProcessingInstruction*>(node)->sheet()) { + if (world->m_wrappers.uncheckedGet(sheet)) + return true; + } + } + } else { + // If a wrapper is the last reference to an image or script element + // that is loading but not in the document, the wrapper is observable + // because it is the only thing keeping the image element alive, and if + // the image element is destroyed, its load event will not fire. + // FIXME: The DOM should manage this issue without the help of JavaScript wrappers. + if (node->hasTagName(imgTag) && !static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent()) + return true; + if (node->hasTagName(scriptTag) && !static_cast<HTMLScriptElement*>(node)->haveFiredLoadEvent()) + return true; +#if ENABLE(VIDEO) + if (node->hasTagName(audioTag) && !static_cast<HTMLAudioElement*>(node)->paused()) + return true; +#endif + } + + // If a node is firing event listeners, its wrapper is observable because + // its wrapper is responsible for marking those event listeners. + if (node->isFiringEventListeners()) + return true; + + return false; +} + +void markDOMNodesForDocument(MarkStack& markStack, Document* document) +{ + JSWrapperCacheMap& wrapperCacheMap = document->wrapperCacheMap(); + for (JSWrapperCacheMap::iterator wrappersIter = wrapperCacheMap.begin(); wrappersIter != wrapperCacheMap.end(); ++wrappersIter) { + DOMWrapperWorld* world = wrappersIter->first; + JSWrapperCache* nodeDict = wrappersIter->second; + + JSWrapperCache::iterator nodeEnd = nodeDict->uncheckedEnd(); + for (JSWrapperCache::iterator nodeIt = nodeDict->uncheckedBegin(); nodeIt != nodeEnd; ++nodeIt) { + JSNode* jsNode = nodeIt->second; + if (isObservableThroughDOM(jsNode, world)) + markStack.append(jsNode); + } + } +} + +void markActiveObjectsForContext(MarkStack& markStack, JSGlobalData& globalData, ScriptExecutionContext* scriptExecutionContext) +{ + // If an element has pending activity that may result in event listeners being called + // (e.g. an XMLHttpRequest), we need to keep JS wrappers alive. + + const HashMap<ActiveDOMObject*, void*>& activeObjects = scriptExecutionContext->activeDOMObjects(); + HashMap<ActiveDOMObject*, void*>::const_iterator activeObjectsEnd = activeObjects.end(); + for (HashMap<ActiveDOMObject*, void*>::const_iterator iter = activeObjects.begin(); iter != activeObjectsEnd; ++iter) { + if (iter->first->hasPendingActivity()) { + // Generally, an active object with pending activity must have a wrapper to mark its listeners. + // However, some ActiveDOMObjects don't have JS wrappers. + markDOMObjectWrapper(markStack, globalData, iter->second); + } + } + + const HashSet<MessagePort*>& messagePorts = scriptExecutionContext->messagePorts(); + HashSet<MessagePort*>::const_iterator portsEnd = messagePorts.end(); + for (HashSet<MessagePort*>::const_iterator iter = messagePorts.begin(); iter != portsEnd; ++iter) { + // If the message port is remotely entangled, then always mark it as in-use because we can't determine reachability across threads. + if (!(*iter)->locallyEntangledPort() || (*iter)->hasPendingActivity()) + markDOMObjectWrapper(markStack, globalData, *iter); + } +} + +typedef std::pair<JSNode*, DOMWrapperWorld*> WrapperAndWorld; +typedef WTF::Vector<WrapperAndWorld, 8> WrapperSet; + +static inline void takeWrappers(Node* node, Document* document, WrapperSet& wrapperSet) +{ + if (document) { + JSWrapperCacheMap& wrapperCacheMap = document->wrapperCacheMap(); + for (JSWrapperCacheMap::iterator iter = wrapperCacheMap.begin(); iter != wrapperCacheMap.end(); ++iter) { + if (JSNode* wrapper = iter->second->take(node)) { + JSDebugWrapperSet::didUncacheWrapper(wrapper); + wrapperSet.append(WrapperAndWorld(wrapper, iter->first)); + } + } + } else { + for (JSGlobalDataWorldIterator worldIter(JSDOMWindow::commonJSGlobalData()); worldIter; ++worldIter) { + DOMWrapperWorld* world = *worldIter; + if (JSNode* wrapper = static_cast<JSNode*>(world->m_wrappers.take(node))) { + JSDebugWrapperSet::didUncacheWrapper(wrapper); + wrapperSet.append(WrapperAndWorld(wrapper, world)); + } + } + } +} + +void updateDOMNodeDocument(Node* node, Document* oldDocument, Document* newDocument) +{ + ASSERT(oldDocument != newDocument); + + WrapperSet wrapperSet; + takeWrappers(node, oldDocument, wrapperSet); + + for (unsigned i = 0; i < wrapperSet.size(); ++i) { + JSNode* wrapper = wrapperSet[i].first; + JSDebugWrapperSet::willCacheWrapper(wrapper); + if (newDocument) + newDocument->getWrapperCache(wrapperSet[i].second)->set(node, wrapper); + else + wrapperSet[i].second->m_wrappers.set(node, wrapper); + } +} + +void markDOMObjectWrapper(MarkStack& markStack, JSGlobalData& globalData, void* object) +{ + // FIXME: This could be changed to only mark wrappers that are "observable" + // as markDOMNodesForDocument does, allowing us to collect more wrappers, + // but doing this correctly would be challenging. + if (!object) + return; + + for (JSGlobalDataWorldIterator worldIter(&globalData); worldIter; ++worldIter) { + if (DOMObject* wrapper = worldIter->m_wrappers.uncheckedGet(object)) + markStack.append(wrapper); + } +} + +void markDOMNodeWrapper(MarkStack& markStack, Document* document, Node* node) +{ + if (document) { + JSWrapperCacheMap& wrapperCacheMap = document->wrapperCacheMap(); + for (JSWrapperCacheMap::iterator iter = wrapperCacheMap.begin(); iter != wrapperCacheMap.end(); ++iter) { + if (JSNode* wrapper = iter->second->uncheckedGet(node)) + markStack.append(wrapper); + } + return; + } + + for (JSGlobalDataWorldIterator worldIter(JSDOMWindow::commonJSGlobalData()); worldIter; ++worldIter) { + if (DOMObject* wrapper = worldIter->m_wrappers.uncheckedGet(node)) + markStack.append(wrapper); + } +} + +static void stringWrapperDestroyed(JSString* str, void* context) +{ + StringImpl* cacheKey = static_cast<StringImpl*>(context); + JSC::JSGlobalData* globalData = Heap::heap(str)->globalData(); + + // Check the normal world first! + JSGlobalData::ClientData* clientData = globalData->clientData; + ASSERT(clientData); + JSStringCache& cache = static_cast<WebCoreJSClientData*>(clientData)->normalWorld()->m_stringCache; + if (cache.uncheckedRemove(cacheKey, str)) { + cacheKey->deref(); + return; + } + + for (JSGlobalDataWorldIterator worldIter(globalData); worldIter; ++worldIter) { + if (worldIter->m_stringCache.uncheckedRemove(cacheKey, str)) + break; + } + + cacheKey->deref(); +} + +JSValue jsStringSlowCase(ExecState* exec, JSStringCache& stringCache, StringImpl* stringImpl) +{ + // If there is a stale entry, we have to explicitly remove it to avoid + // problems down the line. + if (JSString* wrapper = stringCache.uncheckedGet(stringImpl)) + stringCache.uncheckedRemove(stringImpl, wrapper); + + JSString* wrapper = jsStringWithFinalizer(exec, UString(stringImpl), stringWrapperDestroyed, stringImpl); + stringCache.set(stringImpl, wrapper); + // ref explicitly instead of using a RefPtr-keyed hashtable because the wrapper can + // outlive the cache, so the stringImpl has to match the wrapper's lifetime. + stringImpl->ref(); + return wrapper; +} + +JSValue jsStringOrNull(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsNull(); + return jsString(exec, s); +} + +JSValue jsOwnedStringOrNull(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsNull(); + return jsOwnedString(exec, stringToUString(s)); +} + +JSValue jsStringOrUndefined(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsUndefined(); + return jsString(exec, s); +} + +JSValue jsStringOrFalse(ExecState* exec, const String& s) +{ + if (s.isNull()) + return jsBoolean(false); + return jsString(exec, s); +} + +JSValue jsString(ExecState* exec, const KURL& url) +{ + return jsString(exec, url.string()); +} + +JSValue jsStringOrNull(ExecState* exec, const KURL& url) +{ + if (url.isNull()) + return jsNull(); + return jsString(exec, url.string()); +} + +JSValue jsStringOrUndefined(ExecState* exec, const KURL& url) +{ + if (url.isNull()) + return jsUndefined(); + return jsString(exec, url.string()); +} + +JSValue jsStringOrFalse(ExecState* exec, const KURL& url) +{ + if (url.isNull()) + return jsBoolean(false); + return jsString(exec, url.string()); +} + +AtomicStringImpl* findAtomicString(const Identifier& identifier) +{ + if (identifier.isNull()) + return 0; + StringImpl* impl = identifier.impl(); + ASSERT(impl->existingHash()); + return AtomicString::find(impl->characters(), impl->length(), impl->existingHash()); +} + +String valueToStringWithNullCheck(ExecState* exec, JSValue value) +{ + if (value.isNull()) + return String(); + return ustringToString(value.toString(exec)); +} + +String valueToStringWithUndefinedOrNullCheck(ExecState* exec, JSValue value) +{ + if (value.isUndefinedOrNull()) + return String(); + return ustringToString(value.toString(exec)); +} + +JSValue jsDateOrNull(ExecState* exec, double value) +{ + if (!isfinite(value)) + return jsNull(); + return new (exec) DateInstance(exec, value); +} + +double valueToDate(ExecState* exec, JSValue value) +{ + if (value.isNumber()) + return value.uncheckedGetNumber(); + if (!value.inherits(&DateInstance::info)) + return std::numeric_limits<double>::quiet_NaN(); + return static_cast<DateInstance*>(value.toObject(exec))->internalNumber(); +} + +void reportException(ExecState* exec, JSValue exception) +{ + if (exception.isObject() && asObject(exception)->exceptionType() == Terminated) + return; + + UString errorMessage = exception.toString(exec); + JSObject* exceptionObject = exception.toObject(exec); + int lineNumber = exceptionObject->get(exec, Identifier(exec, "line")).toInt32(exec); + UString exceptionSourceURL = exceptionObject->get(exec, Identifier(exec, "sourceURL")).toString(exec); + exec->clearException(); + + if (ExceptionBase* exceptionBase = toExceptionBase(exception)) + errorMessage = stringToUString(exceptionBase->message() + ": " + exceptionBase->description()); + + ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject())->scriptExecutionContext(); + ASSERT(scriptExecutionContext); + + // Crash data indicates null-dereference crashes at this point in the Safari 4 Public Beta. + // It's harmless to return here without reporting the exception to the log and the debugger in this case. + if (!scriptExecutionContext) + return; + + scriptExecutionContext->reportException(ustringToString(errorMessage), lineNumber, ustringToString(exceptionSourceURL)); +} + +void reportCurrentException(ExecState* exec) +{ + JSValue exception = exec->exception(); + exec->clearException(); + reportException(exec, exception); +} + +void setDOMException(ExecState* exec, ExceptionCode ec) +{ + if (!ec || exec->hadException()) + return; + + // FIXME: All callers to setDOMException need to pass in the right global object + // for now, we're going to assume the lexicalGlobalObject. Which is wrong in cases like this: + // frames[0].document.createElement(null, null); // throws an exception which should have the subframes prototypes. + JSDOMGlobalObject* globalObject = deprecatedGlobalObjectForPrototype(exec); + + ExceptionCodeDescription description; + getExceptionCodeDescription(ec, description); + + JSValue errorObject; + switch (description.type) { + case DOMExceptionType: + errorObject = toJS(exec, globalObject, DOMCoreException::create(description)); + break; + case RangeExceptionType: + errorObject = toJS(exec, globalObject, RangeException::create(description)); + break; + case EventExceptionType: + errorObject = toJS(exec, globalObject, EventException::create(description)); + break; + case XMLHttpRequestExceptionType: + errorObject = toJS(exec, globalObject, XMLHttpRequestException::create(description)); + break; +#if ENABLE(SVG) + case SVGExceptionType: + errorObject = toJS(exec, globalObject, SVGException::create(description).get()); + break; +#endif +#if ENABLE(XPATH) + case XPathExceptionType: + errorObject = toJS(exec, globalObject, XPathException::create(description)); + break; +#endif +#if ENABLE(DATABASE) + case SQLExceptionType: + errorObject = toJS(exec, globalObject, SQLException::create(description)); + break; +#endif +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) + case FileExceptionType: + errorObject = toJS(exec, globalObject, FileException::create(description)); + break; +#endif +#if ENABLE(INDEXED_DATABASE) + case IDBDatabaseExceptionType: + errorObject = toJS(exec, globalObject, IDBDatabaseException::create(description)); + break; +#endif + } + + ASSERT(errorObject); + throwError(exec, errorObject); +} + +DOMWindow* activeDOMWindow(ExecState* exec) +{ + return asJSDOMWindow(exec->lexicalGlobalObject())->impl(); +} + +DOMWindow* firstDOMWindow(ExecState* exec) +{ + return asJSDOMWindow(exec->dynamicGlobalObject())->impl(); +} + +bool checkNodeSecurity(ExecState* exec, Node* node) +{ + return node && allowsAccessFromFrame(exec, node->document()->frame()); +} + +bool allowsAccessFromFrame(ExecState* exec, Frame* frame) +{ + if (!frame) + return false; + JSDOMWindow* window = toJSDOMWindow(frame, currentWorld(exec)); + return window && window->allowsAccessFrom(exec); +} + +bool allowsAccessFromFrame(ExecState* exec, Frame* frame, String& message) +{ + if (!frame) + return false; + JSDOMWindow* window = toJSDOMWindow(frame, currentWorld(exec)); + return window && window->allowsAccessFrom(exec, message); +} + +void printErrorMessageForFrame(Frame* frame, const String& message) +{ + if (!frame) + return; + frame->domWindow()->printErrorMessage(message); +} + +// FIXME: We should remove or at least deprecate this function. Callers can use firstDOMWindow directly. +Frame* toDynamicFrame(ExecState* exec) +{ + return firstDOMWindow(exec)->frame(); +} + +// FIXME: We should remove this function. Callers can use ScriptController directly. +bool processingUserGesture() +{ + return ScriptController::processingUserGesture(); +} + +JSValue objectToStringFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, objectProtoFuncToString); +} + +Structure* getCachedDOMStructure(JSDOMGlobalObject* globalObject, const ClassInfo* classInfo) +{ + JSDOMStructureMap& structures = globalObject->structures(); + return structures.get(classInfo).get(); +} + +Structure* cacheDOMStructure(JSDOMGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, const ClassInfo* classInfo) +{ + JSDOMStructureMap& structures = globalObject->structures(); + ASSERT(!structures.contains(classInfo)); + return structures.set(classInfo, structure).first->second.get(); +} + +JSC::JSObject* toJSSequence(ExecState* exec, JSValue value, unsigned& length) +{ + JSObject* object = value.getObject(); + if (!object) { + throwTypeError(exec); + return 0; + } + JSValue lengthValue = object->get(exec, exec->propertyNames().length); + if (exec->hadException()) + return 0; + + if (lengthValue.isUndefinedOrNull()) { + throwTypeError(exec); + return 0; + } + + length = lengthValue.toUInt32(exec); + if (exec->hadException()) + return 0; + + return object; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMBinding.h b/Source/WebCore/bindings/js/JSDOMBinding.h new file mode 100644 index 0000000..52a1a71 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMBinding.h @@ -0,0 +1,341 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * Copyright (C) 2009 Google, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMBinding_h +#define JSDOMBinding_h + +#include "JSDOMGlobalObject.h" +#include "JSDOMWrapper.h" +#include "DOMWrapperWorld.h" +#include "Document.h" +#include <runtime/Completion.h> +#include <runtime/Lookup.h> +#include <runtime/WeakGCMap.h> +#include <wtf/Forward.h> +#include <wtf/Noncopyable.h> + +namespace JSC { + class JSGlobalData; + class DebuggerCallFrame; +} + +namespace WebCore { + + class Document; + class Frame; + class JSNode; + class KURL; + class Node; + class ScriptController; + class ScriptCachedFrameData; + + typedef int ExceptionCode; + + // FIXME: This class should collapse into DOMObject once all DOMObjects are + // updated to store a globalObject pointer. + class DOMObjectWithGlobalPointer : public DOMObject { + public: + JSDOMGlobalObject* globalObject() const + { + return static_cast<JSDOMGlobalObject*>(DOMObject::globalObject()); + } + + ScriptExecutionContext* scriptExecutionContext() const + { + // FIXME: Should never be 0, but can be due to bug 27640. + return globalObject()->scriptExecutionContext(); + } + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype) + { + return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount); + } + + protected: + DOMObjectWithGlobalPointer(NonNullPassRefPtr<JSC::Structure> structure, JSDOMGlobalObject* globalObject) + : DOMObject(globalObject, structure) + { + // FIXME: This ASSERT is valid, but fires in fast/dom/gc-6.html when trying to create + // new JavaScript objects on detached windows due to DOMWindow::document() + // needing to reach through the frame to get to the Document*. See bug 27640. + // ASSERT(globalObject->scriptExecutionContext()); + } + }; + + // Base class for all constructor objects in the JSC bindings. + class DOMConstructorObject : public DOMObjectWithGlobalPointer { + public: + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype) + { + return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount); + } + + protected: + static const unsigned StructureFlags = JSC::ImplementsHasInstance | JSC::OverridesMarkChildren | DOMObjectWithGlobalPointer::StructureFlags; + DOMConstructorObject(NonNullPassRefPtr<JSC::Structure> structure, JSDOMGlobalObject* globalObject) + : DOMObjectWithGlobalPointer(structure, globalObject) + { + } + }; + + // Constructors using this base class depend on being in a Document and + // can never be used from a WorkerContext. + class DOMConstructorWithDocument : public DOMConstructorObject { + public: + Document* document() const + { + return static_cast<Document*>(scriptExecutionContext()); + } + + protected: + DOMConstructorWithDocument(NonNullPassRefPtr<JSC::Structure> structure, JSDOMGlobalObject* globalObject) + : DOMConstructorObject(structure, globalObject) + { + ASSERT(globalObject->scriptExecutionContext()->isDocument()); + } + }; + + DOMObject* getCachedDOMObjectWrapper(JSC::ExecState*, void* objectHandle); + bool hasCachedDOMObjectWrapper(JSC::JSGlobalData*, void* objectHandle); + void cacheDOMObjectWrapper(JSC::ExecState*, void* objectHandle, DOMObject* wrapper); + void forgetDOMNode(JSNode* wrapper, Node* node, Document* document); + void forgetDOMObject(DOMObject* wrapper, void* objectHandle); + + JSNode* getCachedDOMNodeWrapper(JSC::ExecState*, Document*, Node*); + void cacheDOMNodeWrapper(JSC::ExecState*, Document*, Node*, JSNode* wrapper); + void updateDOMNodeDocument(Node*, Document* oldDocument, Document* newDocument); + + void markDOMNodesForDocument(JSC::MarkStack&, Document*); + void markActiveObjectsForContext(JSC::MarkStack&, JSC::JSGlobalData&, ScriptExecutionContext*); + void markDOMObjectWrapper(JSC::MarkStack&, JSC::JSGlobalData& globalData, void* object); + void markDOMNodeWrapper(JSC::MarkStack& markStack, Document* document, Node* node); + bool hasCachedDOMObjectWrapperUnchecked(JSC::JSGlobalData*, void* objectHandle); + bool hasCachedDOMNodeWrapperUnchecked(Document*, Node*); + + JSC::Structure* getCachedDOMStructure(JSDOMGlobalObject*, const JSC::ClassInfo*); + JSC::Structure* cacheDOMStructure(JSDOMGlobalObject*, NonNullPassRefPtr<JSC::Structure>, const JSC::ClassInfo*); + + inline JSDOMGlobalObject* deprecatedGlobalObjectForPrototype(JSC::ExecState* exec) + { + // FIXME: Callers to this function should be using the global object + // from which the object is being created, instead of assuming the lexical one. + // e.g. subframe.document.body should use the subframe's global object, not the lexical one. + return static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()); + } + + template<class WrapperClass> inline JSC::Structure* getDOMStructure(JSC::ExecState* exec, JSDOMGlobalObject* globalObject) + { + if (JSC::Structure* structure = getCachedDOMStructure(globalObject, &WrapperClass::s_info)) + return structure; + return cacheDOMStructure(globalObject, WrapperClass::createStructure(WrapperClass::createPrototype(exec, globalObject)), &WrapperClass::s_info); + } + template<class WrapperClass> inline JSC::Structure* deprecatedGetDOMStructure(JSC::ExecState* exec) + { + // FIXME: This function is wrong. It uses the wrong global object for creating the prototype structure. + return getDOMStructure<WrapperClass>(exec, deprecatedGlobalObjectForPrototype(exec)); + } + template<class WrapperClass> inline JSC::JSObject* getDOMPrototype(JSC::ExecState* exec, JSC::JSGlobalObject* globalObject) + { + return static_cast<JSC::JSObject*>(asObject(getDOMStructure<WrapperClass>(exec, static_cast<JSDOMGlobalObject*>(globalObject))->storedPrototype())); + } + #define CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, className, object) createDOMObjectWrapper<JS##className>(exec, globalObject, static_cast<className*>(object)) + template<class WrapperClass, class DOMClass> inline DOMObject* createDOMObjectWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* object) + { + ASSERT(object); + ASSERT(!getCachedDOMObjectWrapper(exec, object)); + // FIXME: new (exec) could use a different globalData than the globalData this wrapper is cached on. + WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec, globalObject), globalObject, object); + cacheDOMObjectWrapper(exec, object, wrapper); + return wrapper; + } + template<class WrapperClass, class DOMClass> inline JSC::JSValue getDOMObjectWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* object) + { + if (!object) + return JSC::jsNull(); + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, object)) + return wrapper; + return createDOMObjectWrapper<WrapperClass>(exec, globalObject, object); + } + + #define CREATE_DOM_NODE_WRAPPER(exec, globalObject, className, object) createDOMNodeWrapper<JS##className>(exec, globalObject, static_cast<className*>(object)) + template<class WrapperClass, class DOMClass> inline JSNode* createDOMNodeWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* node) + { + ASSERT(node); + ASSERT(!getCachedDOMNodeWrapper(exec, node->document(), node)); + WrapperClass* wrapper = new (exec) WrapperClass(getDOMStructure<WrapperClass>(exec, globalObject), globalObject, node); + // FIXME: The entire function can be removed, once we fix caching. + // This function is a one-off hack to make Nodes cache in the right global object. + cacheDOMNodeWrapper(exec, node->document(), node, wrapper); + return wrapper; + } + template<class WrapperClass, class DOMClass> inline JSC::JSValue getDOMNodeWrapper(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, DOMClass* node) + { + if (!node) + return JSC::jsNull(); + if (JSC::JSCell* wrapper = getCachedDOMNodeWrapper(exec, node->document(), node)) + return wrapper; + return createDOMNodeWrapper<WrapperClass>(exec, globalObject, node); + } + + const JSC::HashTable* getHashTableForGlobalData(JSC::JSGlobalData&, const JSC::HashTable* staticTable); + + void reportException(JSC::ExecState*, JSC::JSValue exception); + void reportCurrentException(JSC::ExecState*); + + // Convert a DOM implementation exception code into a JavaScript exception in the execution state. + void setDOMException(JSC::ExecState*, ExceptionCode); + + JSC::JSValue jsString(JSC::ExecState*, const String&); // empty if the string is null + JSC::JSValue jsStringSlowCase(JSC::ExecState*, JSStringCache&, StringImpl*); + JSC::JSValue jsString(JSC::ExecState*, const KURL&); // empty if the URL is null + inline JSC::JSValue jsString(JSC::ExecState* exec, const AtomicString& s) + { + return jsString(exec, s.string()); + } + + JSC::JSValue jsStringOrNull(JSC::ExecState*, const String&); // null if the string is null + JSC::JSValue jsStringOrNull(JSC::ExecState*, const KURL&); // null if the URL is null + + JSC::JSValue jsStringOrUndefined(JSC::ExecState*, const String&); // undefined if the string is null + JSC::JSValue jsStringOrUndefined(JSC::ExecState*, const KURL&); // undefined if the URL is null + + JSC::JSValue jsStringOrFalse(JSC::ExecState*, const String&); // boolean false if the string is null + JSC::JSValue jsStringOrFalse(JSC::ExecState*, const KURL&); // boolean false if the URL is null + + // See JavaScriptCore for explanation: Should be used for any string that is already owned by another + // object, to let the engine know that collecting the JSString wrapper is unlikely to save memory. + JSC::JSValue jsOwnedStringOrNull(JSC::ExecState*, const String&); + + String identifierToString(const JSC::Identifier&); + String ustringToString(const JSC::UString&); + JSC::UString stringToUString(const String&); + + AtomicString identifierToAtomicString(const JSC::Identifier&); + AtomicString ustringToAtomicString(const JSC::UString&); + AtomicStringImpl* findAtomicString(const JSC::Identifier&); + + String valueToStringWithNullCheck(JSC::ExecState*, JSC::JSValue); // null if the value is null + String valueToStringWithUndefinedOrNullCheck(JSC::ExecState*, JSC::JSValue); // null if the value is null or undefined + + inline int32_t finiteInt32Value(JSC::JSValue value, JSC::ExecState* exec, bool& okay) + { + double number = value.toNumber(exec); + okay = isfinite(number); + return JSC::toInt32(number); + } + + // Returns a Date instance for the specified value, or null if the value is NaN or infinity. + JSC::JSValue jsDateOrNull(JSC::ExecState*, double); + // NaN if the value can't be converted to a date. + double valueToDate(JSC::ExecState*, JSC::JSValue); + + // FIXME: These are a stop-gap until all toJS calls can be converted to pass a globalObject + template <typename T> + inline JSC::JSValue toJS(JSC::ExecState* exec, T* ptr) + { + return toJS(exec, deprecatedGlobalObjectForPrototype(exec), ptr); + } + template <typename T> + inline JSC::JSValue toJS(JSC::ExecState* exec, PassRefPtr<T> ptr) + { + return toJS(exec, deprecatedGlobalObjectForPrototype(exec), ptr.get()); + } + template <typename T> + inline JSC::JSValue toJSNewlyCreated(JSC::ExecState* exec, T* ptr) + { + return toJSNewlyCreated(exec, deprecatedGlobalObjectForPrototype(exec), ptr); + } + + template <typename T> + inline JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, PassRefPtr<T> ptr) + { + return toJS(exec, globalObject, ptr.get()); + } + + // Validates that the passed object is a sequence type per section 4.1.13 of the WebIDL spec. + JSC::JSObject* toJSSequence(JSC::ExecState*, JSC::JSValue, unsigned&); + + bool checkNodeSecurity(JSC::ExecState*, Node*); + + // Helpers for Window, History, and Location classes to implement cross-domain policy. + // Besides the cross-domain check, they need non-caching versions of staticFunctionGetter for + // because we do not want current property values involved at all. + // FIXME: These functions should be named frameAllowsAccessFrom, because the access is *to* the frame. + bool allowsAccessFromFrame(JSC::ExecState*, Frame*); + bool allowsAccessFromFrame(JSC::ExecState*, Frame*, String& message); + DOMWindow* activeDOMWindow(JSC::ExecState*); + DOMWindow* firstDOMWindow(JSC::ExecState*); + + void printErrorMessageForFrame(Frame*, const String& message); + JSC::JSValue objectToStringFunctionGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier& propertyName); + + Frame* toDynamicFrame(JSC::ExecState*); + bool processingUserGesture(); + + inline JSC::JSValue jsString(JSC::ExecState* exec, const String& s) + { + StringImpl* stringImpl = s.impl(); + if (!stringImpl || !stringImpl->length()) + return jsEmptyString(exec); + + if (stringImpl->length() == 1 && stringImpl->characters()[0] <= 0xFF) + return jsString(exec, stringToUString(s)); + + JSStringCache& stringCache = currentWorld(exec)->m_stringCache; + if (JSC::JSString* wrapper = stringCache.get(stringImpl)) + return wrapper; + + return jsStringSlowCase(exec, stringCache, stringImpl); + } + + inline DOMObjectWrapperMap& domObjectWrapperMapFor(JSC::ExecState* exec) + { + return currentWorld(exec)->m_wrappers; + } + + inline String ustringToString(const JSC::UString& u) + { + return u.impl(); + } + + inline JSC::UString stringToUString(const String& s) + { + return JSC::UString(s.impl()); + } + + inline String identifierToString(const JSC::Identifier& i) + { + return i.impl(); + } + + inline AtomicString ustringToAtomicString(const JSC::UString& u) + { + return AtomicString(u.impl()); + } + + inline AtomicString identifierToAtomicString(const JSC::Identifier& identifier) + { + return AtomicString(identifier.impl()); + } + +} // namespace WebCore + +#endif // JSDOMBinding_h diff --git a/Source/WebCore/bindings/js/JSDOMFormDataCustom.cpp b/Source/WebCore/bindings/js/JSDOMFormDataCustom.cpp new file mode 100644 index 0000000..2559e96 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMFormDataCustom.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMFormData.h" + +#include "DOMFormData.h" +#include "HTMLFormElement.h" +#include "JSBlob.h" +#include "JSHTMLFormElement.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +static HTMLFormElement* toHTMLFormElement(JSC::JSValue value) +{ + return value.inherits(&JSHTMLFormElement::s_info) ? static_cast<HTMLFormElement*>(static_cast<JSHTMLFormElement*>(asObject(value))->impl()) : 0; +} + +EncodedJSValue JSC_HOST_CALL JSDOMFormDataConstructor::constructJSDOMFormData(ExecState* exec) +{ + JSDOMFormDataConstructor* jsConstructor = static_cast<JSDOMFormDataConstructor*>(exec->callee()); + + HTMLFormElement* form = 0; + if (exec->argumentCount() > 0) + form = toHTMLFormElement(exec->argument(0)); + RefPtr<DOMFormData> domFormData = DOMFormData::create(form); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), domFormData.get()))); +} + +JSValue JSDOMFormData::append(ExecState* exec) +{ + if (exec->argumentCount() >= 2) { + String name = ustringToString(exec->argument(0).toString(exec)); + JSValue value = exec->argument(1); + if (value.inherits(&JSBlob::s_info)) + impl()->append(name, toBlob(value)); + else + impl()->append(name, ustringToString(value.toString(exec))); + } + + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp b/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp new file mode 100644 index 0000000..e0b5b89 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "config.h" +#include "JSDOMGlobalObject.h" + +#include "Document.h" +#include "JSDOMWindow.h" +#include "JSEventListener.h" + +#if ENABLE(WORKERS) +#include "JSWorkerContext.h" +#include "WorkerContext.h" +#endif + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSDOMGlobalObject::s_info = { "DOMGlobalObject", 0, 0, 0 }; + +JSDOMGlobalObject::JSDOMGlobalObject(NonNullPassRefPtr<Structure> structure, JSDOMGlobalObject::JSDOMGlobalObjectData* data, JSObject* thisValue) + : JSGlobalObject(structure, data, thisValue) +{ +} + +void JSDOMGlobalObject::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + JSDOMStructureMap::iterator end = structures().end(); + for (JSDOMStructureMap::iterator it = structures().begin(); it != end; ++it) + markStack.append(it->second->storedPrototype()); + + JSDOMConstructorMap::iterator end2 = constructors().end(); + for (JSDOMConstructorMap::iterator it2 = constructors().begin(); it2 != end2; ++it2) + markStack.append(it2->second); + + if (d()->m_injectedScript) + markStack.append(d()->m_injectedScript); +} + +void JSDOMGlobalObject::setCurrentEvent(Event* evt) +{ + d()->evt = evt; +} + +Event* JSDOMGlobalObject::currentEvent() const +{ + return d()->evt; +} + +void JSDOMGlobalObject::setInjectedScript(JSObject* injectedScript) +{ + d()->m_injectedScript = injectedScript; +} + +JSObject* JSDOMGlobalObject::injectedScript() const +{ + return d()->m_injectedScript; +} + +void JSDOMGlobalObject::destroyJSDOMGlobalObjectData(void* jsDOMGlobalObjectData) +{ + delete static_cast<JSDOMGlobalObjectData*>(jsDOMGlobalObjectData); +} + +JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, JSC::ExecState* exec) +{ + return toJSDOMWindow(document->frame(), currentWorld(exec)); +} + +JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, JSC::ExecState* exec) +{ + if (scriptExecutionContext->isDocument()) + return toJSDOMGlobalObject(static_cast<Document*>(scriptExecutionContext), exec); + +#if ENABLE(WORKERS) + if (scriptExecutionContext->isWorkerContext()) + return static_cast<WorkerContext*>(scriptExecutionContext)->script()->workerContextWrapper(); +#endif + + ASSERT_NOT_REACHED(); + return 0; +} + +JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld* world) +{ + return toJSDOMWindow(document->frame(), world); +} + +JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, DOMWrapperWorld* world) +{ + if (scriptExecutionContext->isDocument()) + return toJSDOMGlobalObject(static_cast<Document*>(scriptExecutionContext), world); + +#if ENABLE(WORKERS) + if (scriptExecutionContext->isWorkerContext()) + return static_cast<WorkerContext*>(scriptExecutionContext)->script()->workerContextWrapper(); +#endif + + ASSERT_NOT_REACHED(); + return 0; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMGlobalObject.h b/Source/WebCore/bindings/js/JSDOMGlobalObject.h new file mode 100644 index 0000000..8eb55c1 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMGlobalObject.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef JSDOMGlobalObject_h +#define JSDOMGlobalObject_h + +#include <runtime/JSGlobalObject.h> + +namespace WebCore { + + class Document; + class Event; + class DOMWrapperWorld; + class JSLazyEventListener; + class JSEventListener; + class ScriptExecutionContext; + + typedef HashMap<const JSC::ClassInfo*, RefPtr<JSC::Structure> > JSDOMStructureMap; + typedef HashMap<const JSC::ClassInfo*, JSC::JSObject*> JSDOMConstructorMap; + + class JSDOMGlobalObject : public JSC::JSGlobalObject { + typedef JSC::JSGlobalObject Base; + protected: + struct JSDOMGlobalObjectData; + + JSDOMGlobalObject(NonNullPassRefPtr<JSC::Structure>, JSDOMGlobalObjectData*, JSC::JSObject* thisValue); + + public: + JSDOMStructureMap& structures() { return d()->structures; } + JSDOMConstructorMap& constructors() const { return d()->constructors; } + + virtual ScriptExecutionContext* scriptExecutionContext() const = 0; + + // Make binding code generation easier. + JSDOMGlobalObject* globalObject() { return this; } + + void setCurrentEvent(Event*); + Event* currentEvent() const; + + void setInjectedScript(JSObject*); + JSObject* injectedScript() const; + + virtual void markChildren(JSC::MarkStack&); + + DOMWrapperWorld* world() { return d()->m_world.get(); } + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + protected: + struct JSDOMGlobalObjectData : public JSC::JSGlobalObject::JSGlobalObjectData { + JSDOMGlobalObjectData(DOMWrapperWorld* world, Destructor destructor = destroyJSDOMGlobalObjectData) + : JSGlobalObjectData(destructor) + , evt(0) + , m_world(world) + , m_injectedScript(0) + { + } + + JSDOMStructureMap structures; + JSDOMConstructorMap constructors; + + Event* evt; + RefPtr<DOMWrapperWorld> m_world; + JSObject* m_injectedScript; + }; + + private: + static void destroyJSDOMGlobalObjectData(void*); + + JSDOMGlobalObjectData* d() const { return static_cast<JSDOMGlobalObjectData*>(JSC::JSVariableObject::d); } + }; + + template<class ConstructorClass> + inline JSC::JSObject* getDOMConstructor(JSC::ExecState* exec, const JSDOMGlobalObject* globalObject) + { + if (JSC::JSObject* constructor = globalObject->constructors().get(&ConstructorClass::s_info)) + return constructor; + JSC::JSObject* constructor = new (exec) ConstructorClass(exec, const_cast<JSDOMGlobalObject*>(globalObject)); + ASSERT(!globalObject->constructors().contains(&ConstructorClass::s_info)); + globalObject->constructors().set(&ConstructorClass::s_info, constructor); + return constructor; + } + + JSDOMGlobalObject* toJSDOMGlobalObject(Document*, JSC::ExecState*); + JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext*, JSC::ExecState*); + + JSDOMGlobalObject* toJSDOMGlobalObject(Document*, DOMWrapperWorld*); + JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext*, DOMWrapperWorld*); + +} // namespace WebCore + +#endif // JSDOMGlobalObject_h diff --git a/Source/WebCore/bindings/js/JSDOMMimeTypeArrayCustom.cpp b/Source/WebCore/bindings/js/JSDOMMimeTypeArrayCustom.cpp new file mode 100644 index 0000000..0194962 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMMimeTypeArrayCustom.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMMimeTypeArray.h" + +#include "DOMMimeTypeArray.h" +#include "JSDOMMimeType.h" +#include <wtf/text/AtomicString.h> + +namespace WebCore { + +using namespace JSC; + +bool JSDOMMimeTypeArray::canGetItemsForName(ExecState*, DOMMimeTypeArray* mimeTypeArray, const Identifier& propertyName) +{ + return mimeTypeArray->canGetItemsForName(identifierToAtomicString(propertyName)); +} + +JSValue JSDOMMimeTypeArray::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSDOMMimeTypeArray* thisObj = static_cast<JSDOMMimeTypeArray*>(asObject(slotBase)); + return toJS(exec, thisObj->impl()->namedItem(identifierToAtomicString(propertyName))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMPluginArrayCustom.cpp b/Source/WebCore/bindings/js/JSDOMPluginArrayCustom.cpp new file mode 100644 index 0000000..20ce5e5 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMPluginArrayCustom.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMPluginArray.h" + +#include "DOMPluginArray.h" +#include "JSDOMPlugin.h" +#include <wtf/text/AtomicString.h> + +namespace WebCore { + +using namespace JSC; + +bool JSDOMPluginArray::canGetItemsForName(ExecState*, DOMPluginArray* pluginArray, const Identifier& propertyName) +{ + return pluginArray->canGetItemsForName(identifierToAtomicString(propertyName)); +} + +JSValue JSDOMPluginArray::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSDOMPluginArray* thisObj = static_cast<JSDOMPluginArray*>(asObject(slotBase)); + return toJS(exec, thisObj->impl()->namedItem(identifierToAtomicString(propertyName))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMPluginCustom.cpp b/Source/WebCore/bindings/js/JSDOMPluginCustom.cpp new file mode 100644 index 0000000..319cb3c --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMPluginCustom.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSDOMPlugin.h" + +#include "DOMPlugin.h" +#include "JSDOMMimeType.h" +#include <wtf/text/AtomicString.h> + +namespace WebCore { + +using namespace JSC; + +bool JSDOMPlugin::canGetItemsForName(ExecState*, DOMPlugin* plugin, const Identifier& propertyName) +{ + return plugin->canGetItemsForName(identifierToAtomicString(propertyName)); +} + +JSValue JSDOMPlugin::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSDOMPlugin* thisObj = static_cast<JSDOMPlugin*>(asObject(slotBase)); + return toJS(exec, thisObj->impl()->namedItem(identifierToAtomicString(propertyName))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp b/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp new file mode 100644 index 0000000..d1c1d69 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMStringMap.h" + +#include "DOMStringMap.h" +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +bool JSDOMStringMap::canGetItemsForName(ExecState*, DOMStringMap* impl, const Identifier& propertyName) +{ + return impl->contains(identifierToAtomicString(propertyName)); +} + +JSValue JSDOMStringMap::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSDOMStringMap* thisObj = static_cast<JSDOMStringMap*>(asObject(slotBase)); + return jsString(exec, thisObj->impl()->item(identifierToAtomicString(propertyName))); +} + +void JSDOMStringMap::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + Vector<String> names; + m_impl->getNames(names); + size_t length = names.size(); + for (size_t i = 0; i < length; ++i) + propertyNames.add(Identifier(exec, stringToUString(names[i]))); + + Base::getOwnPropertyNames(exec, propertyNames, mode); +} + +bool JSDOMStringMap::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only perform the custom delete if the object doesn't have a native property by this name. + // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check + // the native property slots manually. + PropertySlot slot; + if (getStaticValueSlot<JSDOMStringMap, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot)) + return false; + + JSValue prototype = this->prototype(); + if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName)) + return false; + + ExceptionCode ec = 0; + m_impl->deleteItem(identifierToString(propertyName), ec); + setDOMException(exec, ec); + + return true; +} + +bool JSDOMStringMap::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot&) +{ + // Only perform the custom put if the object doesn't have a native property by this name. + // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check + // the native property slots manually. + PropertySlot slot; + if (getStaticValueSlot<JSDOMStringMap, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot)) + return false; + + JSValue prototype = this->prototype(); + if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName)) + return false; + + String stringValue = ustringToString(value.toString(exec)); + if (exec->hadException()) + return true; + + ExceptionCode ec = 0; + impl()->setItem(identifierToString(propertyName), stringValue, ec); + setDOMException(exec, ec); + + return true; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMStringMapCustom.h b/Source/WebCore/bindings/js/JSDOMStringMapCustom.h new file mode 100644 index 0000000..095fd21 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMStringMapCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSDOMStringMapCustom_h +#define JSDOMStringMapCustom_h + +#include "JSDOMStringMap.h" + +#endif // JSDOMStringMapCustom_h diff --git a/Source/WebCore/bindings/js/JSDOMWindowBase.cpp b/Source/WebCore/bindings/js/JSDOMWindowBase.cpp new file mode 100644 index 0000000..68c0088 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWindowBase.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "config.h" +#include "JSDOMWindowBase.h" + +#include "Chrome.h" +#include "Console.h" +#include "DOMWindow.h" +#include "Frame.h" +#include "InspectorController.h" +#include "JSDOMWindowCustom.h" +#include "JSNode.h" +#include "Logging.h" +#include "Page.h" +#include "ScriptController.h" +#include "SecurityOrigin.h" +#include "Settings.h" +#include "WebCoreJSClientData.h" +#include <wtf/Threading.h> +#include <wtf/text/StringConcatenate.h> + +using namespace JSC; + +namespace WebCore { + +const ClassInfo JSDOMWindowBase::s_info = { "Window", &JSDOMGlobalObject::s_info, 0, 0 }; + +JSDOMWindowBase::JSDOMWindowBaseData::JSDOMWindowBaseData(PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell) + : JSDOMGlobalObjectData(shell->world(), destroyJSDOMWindowBaseData) + , impl(window) + , shell(shell) +{ +} + +JSDOMWindowBase::JSDOMWindowBase(NonNullPassRefPtr<Structure> structure, PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell) + : JSDOMGlobalObject(structure, new JSDOMWindowBaseData(window, shell), shell) +{ + GlobalPropertyInfo staticGlobals[] = { + GlobalPropertyInfo(Identifier(globalExec(), "document"), jsNull(), DontDelete | ReadOnly), + GlobalPropertyInfo(Identifier(globalExec(), "window"), d()->shell, DontDelete | ReadOnly) + }; + + addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals)); +} + +void JSDOMWindowBase::updateDocument() +{ + ASSERT(d()->impl->document()); + ExecState* exec = globalExec(); + symbolTablePutWithAttributes(Identifier(exec, "document"), toJS(exec, this, d()->impl->document()), DontDelete | ReadOnly); +} + +ScriptExecutionContext* JSDOMWindowBase::scriptExecutionContext() const +{ + return d()->impl->document(); +} + +String JSDOMWindowBase::crossDomainAccessErrorMessage(const JSGlobalObject* other) const +{ + return d()->shell->window()->impl()->crossDomainAccessErrorMessage(asJSDOMWindow(other)->impl()); +} + +void JSDOMWindowBase::printErrorMessage(const String& message) const +{ + printErrorMessageForFrame(impl()->frame(), message); +} + +ExecState* JSDOMWindowBase::globalExec() +{ + // We need to make sure that any script execution happening in this + // frame does not destroy it + if (Frame *frame = impl()->frame()) + frame->keepAlive(); + return Base::globalExec(); +} + +bool JSDOMWindowBase::supportsProfiling() const +{ +#if !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR) + return false; +#else + Frame* frame = impl()->frame(); + if (!frame) + return false; + + Page* page = frame->page(); + if (!page) + return false; + + return page->inspectorController()->profilerEnabled(); +#endif +} + +bool JSDOMWindowBase::supportsRichSourceInfo() const +{ +#if PLATFORM(ANDROID) + return true; +#elif !ENABLE(JAVASCRIPT_DEBUGGER) || !ENABLE(INSPECTOR) + return false; +#else + Frame* frame = impl()->frame(); + if (!frame) + return false; + + Page* page = frame->page(); + if (!page) + return false; + + bool enabled = page->inspectorController()->enabled(); + ASSERT(enabled || !debugger()); + ASSERT(enabled || !supportsProfiling()); + return enabled; +#endif +} + +bool JSDOMWindowBase::shouldInterruptScript() const +{ + ASSERT(impl()->frame()); + Page* page = impl()->frame()->page(); + + // See <rdar://problem/5479443>. We don't think that page can ever be NULL + // in this case, but if it is, we've gotten into a state where we may have + // hung the UI, with no way to ask the client whether to cancel execution. + // For now, our solution is just to cancel execution no matter what, + // ensuring that we never hang. We might want to consider other solutions + // if we discover problems with this one. + ASSERT(page); + if (!page) + return true; + + return page->chrome()->shouldInterruptJavaScript(); +} + +void JSDOMWindowBase::willRemoveFromWindowShell() +{ + setCurrentEvent(0); +} + +JSObject* JSDOMWindowBase::toThisObject(ExecState*) const +{ + return shell(); +} + +JSValue JSDOMWindowBase::toStrictThisObject(ExecState*) const +{ + return shell(); +} + +JSDOMWindowShell* JSDOMWindowBase::shell() const +{ + return d()->shell; +} + +JSGlobalData* JSDOMWindowBase::commonJSGlobalData() +{ + ASSERT(isMainThread()); + + static JSGlobalData* globalData = 0; + if (!globalData) { + globalData = JSGlobalData::createLeaked(ThreadStackTypeLarge).releaseRef(); + globalData->timeoutChecker.setTimeoutInterval(10000); // 10 seconds +#ifndef NDEBUG + globalData->exclusiveThread = currentThread(); +#endif + initNormalWorldClientData(globalData); + } + + return globalData; +} + +void JSDOMWindowBase::destroyJSDOMWindowBaseData(void* jsDOMWindowBaseData) +{ + delete static_cast<JSDOMWindowBaseData*>(jsDOMWindowBaseData); +} + +// JSDOMGlobalObject* is ignored, accessing a window in any context will +// use that DOMWindow's prototype chain. +JSValue toJS(ExecState* exec, JSDOMGlobalObject*, DOMWindow* domWindow) +{ + return toJS(exec, domWindow); +} + +JSValue toJS(ExecState* exec, DOMWindow* domWindow) +{ + if (!domWindow) + return jsNull(); + Frame* frame = domWindow->frame(); + if (!frame) + return jsNull(); + return frame->script()->windowShell(currentWorld(exec)); +} + +JSDOMWindow* toJSDOMWindow(Frame* frame, DOMWrapperWorld* world) +{ + if (!frame) + return 0; + return frame->script()->windowShell(world)->window(); +} + +JSDOMWindow* toJSDOMWindow(JSValue value) +{ + if (!value.isObject()) + return 0; + const ClassInfo* classInfo = asObject(value)->classInfo(); + if (classInfo == &JSDOMWindow::s_info) + return static_cast<JSDOMWindow*>(asObject(value)); + if (classInfo == &JSDOMWindowShell::s_info) + return static_cast<JSDOMWindowShell*>(asObject(value))->window(); + return 0; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMWindowBase.h b/Source/WebCore/bindings/js/JSDOMWindowBase.h new file mode 100644 index 0000000..fbef808 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWindowBase.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMWindowBase_h +#define JSDOMWindowBase_h + +#include "PlatformString.h" +#include "JSDOMBinding.h" +#include <runtime/Protect.h> +#include <wtf/Forward.h> +#include <wtf/HashMap.h> +#include <wtf/OwnPtr.h> + +namespace WebCore { + + class DOMWindow; + class Event; + class Frame; + class DOMWrapperWorld; + class JSDOMWindow; + class JSDOMWindowShell; + class JSLocation; + class JSEventListener; + class SecurityOrigin; + + class JSDOMWindowBasePrivate; + + class JSDOMWindowBase : public JSDOMGlobalObject { + typedef JSDOMGlobalObject Base; + protected: + JSDOMWindowBase(NonNullPassRefPtr<JSC::Structure>, PassRefPtr<DOMWindow>, JSDOMWindowShell*); + + public: + void updateDocument(); + + DOMWindow* impl() const { return d()->impl.get(); } + virtual ScriptExecutionContext* scriptExecutionContext() const; + + // Called just before removing this window from the JSDOMWindowShell. + void willRemoveFromWindowShell(); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + virtual JSC::ExecState* globalExec(); + virtual bool supportsProfiling() const; + virtual bool supportsRichSourceInfo() const; + virtual bool shouldInterruptScript() const; + + bool allowsAccessFrom(JSC::ExecState*) const; + bool allowsAccessFromNoErrorMessage(JSC::ExecState*) const; + bool allowsAccessFrom(JSC::ExecState*, String& message) const; + void printErrorMessage(const String&) const; + + // Don't call this version of allowsAccessFrom -- it's a slightly incorrect implementation used only by WebScriptObject + virtual bool allowsAccessFrom(const JSC::JSGlobalObject*) const; + + virtual JSC::JSObject* toThisObject(JSC::ExecState*) const; + virtual JSC::JSValue toStrictThisObject(JSC::ExecState*) const; + JSDOMWindowShell* shell() const; + + static JSC::JSGlobalData* commonJSGlobalData(); + + private: + struct JSDOMWindowBaseData : public JSDOMGlobalObjectData { + JSDOMWindowBaseData(PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell); + + RefPtr<DOMWindow> impl; + JSDOMWindowShell* shell; + }; + + bool allowsAccessFromPrivate(const JSC::JSGlobalObject*) const; + String crossDomainAccessErrorMessage(const JSC::JSGlobalObject*) const; + + static void destroyJSDOMWindowBaseData(void*); + + JSDOMWindowBaseData* d() const { return static_cast<JSDOMWindowBaseData*>(JSC::JSVariableObject::d); } + }; + + // Returns a JSDOMWindow or jsNull() + // JSDOMGlobalObject* is ignored, accessing a window in any context will + // use that DOMWindow's prototype chain. + JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, DOMWindow*); + JSC::JSValue toJS(JSC::ExecState*, DOMWindow*); + + // Returns JSDOMWindow or 0 + JSDOMWindow* toJSDOMWindow(Frame*, DOMWrapperWorld*); + JSDOMWindow* toJSDOMWindow(JSC::JSValue); + +} // namespace WebCore + +#endif // JSDOMWindowBase_h diff --git a/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp b/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp new file mode 100644 index 0000000..c8d8db6 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp @@ -0,0 +1,812 @@ +/* + * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSDOMWindowCustom.h" + +#include "Frame.h" +#include "HTMLCollection.h" +#include "HTMLDocument.h" +#include "History.h" +#include "JSAudioConstructor.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "JSEventSource.h" +#include "JSHTMLCollection.h" +#include "JSHistory.h" +#include "JSImageConstructor.h" +#include "JSLocation.h" +#include "JSMessageChannel.h" +#include "JSMessagePortCustom.h" +#include "JSOptionConstructor.h" +#include "JSWebKitCSSMatrix.h" +#include "JSWebKitPoint.h" +#include "JSWorker.h" +#include "JSXMLHttpRequest.h" +#include "JSXSLTProcessor.h" +#include "Location.h" +#include "MediaPlayer.h" +#include "ScheduledAction.h" +#include "Settings.h" +#include "SharedWorkerRepository.h" +#include <runtime/JSFunction.h> +#include <runtime/PrototypeFunction.h> + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) +#include "JSArrayBuffer.h" +#include "JSDataView.h" +#include "JSFloat32Array.h" +#include "JSInt16Array.h" +#include "JSInt32Array.h" +#include "JSInt8Array.h" +#include "JSUint16Array.h" +#include "JSUint32Array.h" +#include "JSUint8Array.h" +#endif + +#if ENABLE(SHARED_WORKERS) +#include "JSSharedWorker.h" +#endif + +#if ENABLE(WEB_AUDIO) +#include "JSAudioContext.h" +#endif + +#if ENABLE(WEB_SOCKETS) +#include "JSWebSocket.h" +#endif + +using namespace JSC; + +namespace WebCore { + +void JSDOMWindow::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + impl()->markJSEventListeners(markStack); + + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMObjectWrapper(markStack, globalData, impl()->optionalConsole()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalHistory()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalLocationbar()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalMenubar()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalNavigator()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalPersonalbar()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalScreen()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalScrollbars()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalSelection()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalStatusbar()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalToolbar()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalLocation()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalMedia()); +#if ENABLE(DOM_STORAGE) + markDOMObjectWrapper(markStack, globalData, impl()->optionalSessionStorage()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalLocalStorage()); +#endif +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + markDOMObjectWrapper(markStack, globalData, impl()->optionalApplicationCache()); +#endif +} + +template<NativeFunction nativeFunction, int length> +JSValue nonCachingStaticFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), length, propertyName, nativeFunction); +} + +static JSValue childFrameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + return toJS(exec, static_cast<JSDOMWindow*>(asObject(slotBase))->impl()->frame()->tree()->child(identifierToAtomicString(propertyName))->domWindow()); +} + +static JSValue indexGetter(ExecState* exec, JSValue slotBase, unsigned index) +{ + return toJS(exec, static_cast<JSDOMWindow*>(asObject(slotBase))->impl()->frame()->tree()->child(index)->domWindow()); +} + +static JSValue namedItemGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSDOMWindowBase* thisObj = static_cast<JSDOMWindow*>(asObject(slotBase)); + Document* document = thisObj->impl()->frame()->document(); + + ASSERT(thisObj->allowsAccessFrom(exec)); + ASSERT(document); + ASSERT(document->isHTMLDocument()); + + RefPtr<HTMLCollection> collection = document->windowNamedItems(identifierToString(propertyName)); + if (collection->length() == 1) + return toJS(exec, collection->firstItem()); + return toJS(exec, collection.get()); +} + +bool JSDOMWindow::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + // When accessing a Window cross-domain, functions are always the native built-in ones, and they + // are not affected by properties changed on the Window or anything in its prototype chain. + // This is consistent with the behavior of Firefox. + + const HashEntry* entry; + + // We don't want any properties other than "close" and "closed" on a closed window. + if (!impl()->frame()) { + // The following code is safe for cross-domain and same domain use. + // It ignores any custom properties that might be set on the DOMWindow (including a custom prototype). + entry = s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && !(entry->attributes() & Function) && entry->propertyGetter() == jsDOMWindowClosed) { + slot.setCustom(this, entry->propertyGetter()); + return true; + } + entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && (entry->attributes() & Function) && entry->function() == jsDOMWindowPrototypeFunctionClose) { + slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>); + return true; + } + + // FIXME: We should have a message here that explains why the property access/function call was + // not allowed. + slot.setUndefined(); + return true; + } + + // We need to check for cross-domain access here without printing the generic warning message + // because we always allow access to some function, just different ones depending whether access + // is allowed. + String errorMessage; + bool allowsAccess = allowsAccessFrom(exec, errorMessage); + + // Look for overrides before looking at any of our own properties, but ignore overrides completely + // if this is cross-domain access. + if (allowsAccess && JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) + return true; + + // We need this code here because otherwise JSDOMWindowBase will stop the search before we even get to the + // prototype due to the blanket same origin (allowsAccessFrom) check at the end of getOwnPropertySlot. + // Also, it's important to get the implementation straight out of the DOMWindow prototype regardless of + // what prototype is actually set on this object. + entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + if (entry->attributes() & Function) { + if (entry->function() == jsDOMWindowPrototypeFunctionBlur) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionBlur, 0>); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionClose) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionFocus) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionFocus, 0>); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionPostMessage) { + if (!allowsAccess) { + slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionPostMessage, 2>); + return true; + } + } else if (entry->function() == jsDOMWindowPrototypeFunctionShowModalDialog) { + if (!DOMWindow::canShowModalDialog(impl()->frame())) { + slot.setUndefined(); + return true; + } + } + } + } else { + // Allow access to toString() cross-domain, but always Object.prototype.toString. + if (propertyName == exec->propertyNames().toString) { + if (!allowsAccess) { + slot.setCustom(this, objectToStringFunctionGetter); + return true; + } + } + } + + entry = JSDOMWindow::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + slot.setCustom(this, entry->propertyGetter()); + return true; + } + + // Check for child frames by name before built-in properties to + // match Mozilla. This does not match IE, but some sites end up + // naming frames things that conflict with window properties that + // are in Moz but not IE. Since we have some of these, we have to do + // it the Moz way. + if (impl()->frame()->tree()->child(identifierToAtomicString(propertyName))) { + slot.setCustom(this, childFrameGetter); + return true; + } + + // Do prototype lookup early so that functions and attributes in the prototype can have + // precedence over the index and name getters. + JSValue proto = prototype(); + if (proto.isObject()) { + if (asObject(proto)->getPropertySlot(exec, propertyName, slot)) { + if (!allowsAccess) { + printErrorMessage(errorMessage); + slot.setUndefined(); + } + return true; + } + } + + // FIXME: Search the whole frame hierarchy somewhere around here. + // We need to test the correct priority order. + + // allow window[1] or parent[1] etc. (#56983) + bool ok; + unsigned i = propertyName.toArrayIndex(ok); + if (ok && i < impl()->frame()->tree()->childCount()) { + slot.setCustomIndex(this, i, indexGetter); + return true; + } + + if (!allowsAccess) { + printErrorMessage(errorMessage); + slot.setUndefined(); + return true; + } + + // Allow shortcuts like 'Image1' instead of document.images.Image1 + Document* document = impl()->frame()->document(); + if (document->isHTMLDocument()) { + AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName); + if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) { + slot.setCustom(this, namedItemGetter); + return true; + } + } + + return Base::getOwnPropertySlot(exec, propertyName, slot); +} + +bool JSDOMWindow::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + // Never allow cross-domain getOwnPropertyDescriptor + if (!allowsAccessFrom(exec)) + return false; + + const HashEntry* entry; + + // We don't want any properties other than "close" and "closed" on a closed window. + if (!impl()->frame()) { + // The following code is safe for cross-domain and same domain use. + // It ignores any custom properties that might be set on the DOMWindow (including a custom prototype). + entry = s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && !(entry->attributes() & Function) && entry->propertyGetter() == jsDOMWindowClosed) { + descriptor.setDescriptor(jsBoolean(true), ReadOnly | DontDelete | DontEnum); + return true; + } + entry = JSDOMWindowPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && (entry->attributes() & Function) && entry->function() == jsDOMWindowPrototypeFunctionClose) { + PropertySlot slot; + slot.setCustom(this, nonCachingStaticFunctionGetter<jsDOMWindowPrototypeFunctionClose, 0>); + descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum); + return true; + } + descriptor.setUndefined(); + return true; + } + + entry = JSDOMWindow::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + PropertySlot slot; + slot.setCustom(this, entry->propertyGetter()); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } + + // Check for child frames by name before built-in properties to + // match Mozilla. This does not match IE, but some sites end up + // naming frames things that conflict with window properties that + // are in Moz but not IE. Since we have some of these, we have to do + // it the Moz way. + if (impl()->frame()->tree()->child(identifierToAtomicString(propertyName))) { + PropertySlot slot; + slot.setCustom(this, childFrameGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum); + return true; + } + + bool ok; + unsigned i = propertyName.toArrayIndex(ok); + if (ok && i < impl()->frame()->tree()->childCount()) { + PropertySlot slot; + slot.setCustomIndex(this, i, indexGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum); + return true; + } + + // Allow shortcuts like 'Image1' instead of document.images.Image1 + Document* document = impl()->frame()->document(); + if (document->isHTMLDocument()) { + AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName); + if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) { + PropertySlot slot; + slot.setCustom(this, namedItemGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum); + return true; + } + } + + return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor); +} + +void JSDOMWindow::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + if (!impl()->frame()) + return; + + // Optimization: access JavaScript global variables directly before involving the DOM. + if (JSGlobalObject::hasOwnPropertyForWrite(exec, propertyName)) { + if (allowsAccessFrom(exec)) + JSGlobalObject::put(exec, propertyName, value, slot); + return; + } + + if (lookupPut<JSDOMWindow>(exec, propertyName, value, s_info.propHashTable(exec), this)) + return; + + if (allowsAccessFrom(exec)) + Base::put(exec, propertyName, value, slot); +} + +bool JSDOMWindow::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only allow deleting properties by frames in the same origin. + if (!allowsAccessFrom(exec)) + return false; + return Base::deleteProperty(exec, propertyName); +} + +void JSDOMWindow::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + // Only allow the window to enumerated by frames in the same origin. + if (!allowsAccessFrom(exec)) + return; + Base::getPropertyNames(exec, propertyNames, mode); +} + +void JSDOMWindow::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + // Only allow the window to enumerated by frames in the same origin. + if (!allowsAccessFrom(exec)) + return; + Base::getOwnPropertyNames(exec, propertyNames, mode); +} + +void JSDOMWindow::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes) +{ + // Only allow defining getters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return; + + // Don't allow shadowing location using defineGetter. + if (propertyName == "location") + return; + + Base::defineGetter(exec, propertyName, getterFunction, attributes); +} + +void JSDOMWindow::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes) +{ + // Only allow defining setters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return; + Base::defineSetter(exec, propertyName, setterFunction, attributes); +} + +bool JSDOMWindow::defineOwnProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor, bool shouldThrow) +{ + // Only allow defining properties in this way by frames in the same origin, as it allows setters to be introduced. + if (!allowsAccessFrom(exec)) + return false; + return Base::defineOwnProperty(exec, propertyName, descriptor, shouldThrow); +} + +JSValue JSDOMWindow::lookupGetter(ExecState* exec, const Identifier& propertyName) +{ + // Only allow looking-up getters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return jsUndefined(); + return Base::lookupGetter(exec, propertyName); +} + +JSValue JSDOMWindow::lookupSetter(ExecState* exec, const Identifier& propertyName) +{ + // Only allow looking-up setters by frames in the same origin. + if (!allowsAccessFrom(exec)) + return jsUndefined(); + return Base::lookupSetter(exec, propertyName); +} + +// Custom Attributes + +JSValue JSDOMWindow::history(ExecState* exec) const +{ + History* history = impl()->history(); + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, history)) + return wrapper; + + JSDOMWindow* window = const_cast<JSDOMWindow*>(this); + JSHistory* jsHistory = new (exec) JSHistory(getDOMStructure<JSHistory>(exec, window), window, history); + cacheDOMObjectWrapper(exec, history, jsHistory); + return jsHistory; +} + +JSValue JSDOMWindow::location(ExecState* exec) const +{ + Location* location = impl()->location(); + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, location)) + return wrapper; + + JSDOMWindow* window = const_cast<JSDOMWindow*>(this); + JSLocation* jsLocation = new (exec) JSLocation(getDOMStructure<JSLocation>(exec, window), window, location); + cacheDOMObjectWrapper(exec, location, jsLocation); + return jsLocation; +} + +void JSDOMWindow::setLocation(ExecState* exec, JSValue value) +{ +#if ENABLE(DASHBOARD_SUPPORT) + // To avoid breaking old widgets, make "var location =" in a top-level frame create + // a property named "location" instead of performing a navigation (<rdar://problem/5688039>). + if (Frame* activeFrame = activeDOMWindow(exec)->frame()) { + if (Settings* settings = activeFrame->settings()) { + if (settings->usesDashboardBackwardCompatibilityMode() && !activeFrame->tree()->parent()) { + if (allowsAccessFrom(exec)) + putDirect(Identifier(exec, "location"), value); + return; + } + } + } +#endif + + UString locationString = value.toString(exec); + if (exec->hadException()) + return; + + impl()->setLocation(ustringToString(locationString), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +JSValue JSDOMWindow::crypto(ExecState*) const +{ + return jsUndefined(); +} + +JSValue JSDOMWindow::event(ExecState* exec) const +{ + Event* event = currentEvent(); + if (!event) + return jsUndefined(); + return toJS(exec, event); +} + +#if ENABLE(EVENTSOURCE) +JSValue JSDOMWindow::eventSource(ExecState* exec) const +{ + return getDOMConstructor<JSEventSourceConstructor>(exec, this); +} +#endif + +JSValue JSDOMWindow::image(ExecState* exec) const +{ + return getDOMConstructor<JSImageConstructor>(exec, this); +} + +JSValue JSDOMWindow::option(ExecState* exec) const +{ + return getDOMConstructor<JSOptionConstructor>(exec, this); +} + +#if ENABLE(VIDEO) +JSValue JSDOMWindow::audio(ExecState* exec) const +{ + if (!MediaPlayer::isAvailable()) + return jsUndefined(); + return getDOMConstructor<JSAudioConstructor>(exec, this); +} +#endif + +JSValue JSDOMWindow::webKitPoint(ExecState* exec) const +{ + return getDOMConstructor<JSWebKitPointConstructor>(exec, this); +} + +JSValue JSDOMWindow::webKitCSSMatrix(ExecState* exec) const +{ + return getDOMConstructor<JSWebKitCSSMatrixConstructor>(exec, this); +} + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) +JSValue JSDOMWindow::arrayBuffer(ExecState* exec) const +{ + return getDOMConstructor<JSArrayBufferConstructor>(exec, this); +} + +JSValue JSDOMWindow::int8Array(ExecState* exec) const +{ + return getDOMConstructor<JSInt8ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::uint8Array(ExecState* exec) const +{ + return getDOMConstructor<JSUint8ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::int32Array(ExecState* exec) const +{ + return getDOMConstructor<JSInt32ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::uint32Array(ExecState* exec) const +{ + return getDOMConstructor<JSUint32ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::int16Array(ExecState* exec) const +{ + return getDOMConstructor<JSInt16ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::uint16Array(ExecState* exec) const +{ + return getDOMConstructor<JSUint16ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::float32Array(ExecState* exec) const +{ + return getDOMConstructor<JSFloat32ArrayConstructor>(exec, this); +} + +JSValue JSDOMWindow::dataView(ExecState* exec) const +{ + return getDOMConstructor<JSDataViewConstructor>(exec, this); +} +#endif + +JSValue JSDOMWindow::xmlHttpRequest(ExecState* exec) const +{ + return getDOMConstructor<JSXMLHttpRequestConstructor>(exec, this); +} + +#if ENABLE(XSLT) +JSValue JSDOMWindow::xsltProcessor(ExecState* exec) const +{ + return getDOMConstructor<JSXSLTProcessorConstructor>(exec, this); +} +#endif + +#if ENABLE(CHANNEL_MESSAGING) +JSValue JSDOMWindow::messageChannel(ExecState* exec) const +{ + return getDOMConstructor<JSMessageChannelConstructor>(exec, this); +} +#endif + +#if ENABLE(WORKERS) +JSValue JSDOMWindow::worker(ExecState* exec) const +{ + return getDOMConstructor<JSWorkerConstructor>(exec, this); +} +#endif + +#if ENABLE(SHARED_WORKERS) +JSValue JSDOMWindow::sharedWorker(ExecState* exec) const +{ + if (SharedWorkerRepository::isAvailable()) + return getDOMConstructor<JSSharedWorkerConstructor>(exec, this); + return jsUndefined(); +} +#endif + +#if ENABLE(WEB_AUDIO) +JSValue JSDOMWindow::webkitAudioContext(ExecState* exec) const +{ + return getDOMConstructor<JSAudioContextConstructor>(exec, this); +} +#endif + +#if ENABLE(WEB_SOCKETS) +JSValue JSDOMWindow::webSocket(ExecState* exec) const +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + Settings* settings = frame->settings(); + if (!settings) + return jsUndefined(); + return getDOMConstructor<JSWebSocketConstructor>(exec, this); +} +#endif + +// Custom functions + +JSValue JSDOMWindow::open(ExecState* exec) +{ + String urlString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + AtomicString frameName = exec->argument(1).isUndefinedOrNull() ? "_blank" : ustringToAtomicString(exec->argument(1).toString(exec)); + if (exec->hadException()) + return jsUndefined(); + String windowFeaturesString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<DOMWindow> openedWindow = impl()->open(urlString, frameName, windowFeaturesString, activeDOMWindow(exec), firstDOMWindow(exec)); + if (!openedWindow) + return jsUndefined(); + return toJS(exec, openedWindow.get()); +} + +class DialogHandler { +public: + explicit DialogHandler(ExecState* exec) + : m_exec(exec) + , m_globalObject(0) + { + } + + void dialogCreated(DOMWindow*); + JSValue returnValue() const; + +private: + ExecState* m_exec; + JSDOMWindow* m_globalObject; +}; + +inline void DialogHandler::dialogCreated(DOMWindow* dialog) +{ + // FIXME: This looks like a leak between the normal world and an isolated + // world if dialogArguments comes from an isolated world. + m_globalObject = toJSDOMWindow(dialog->frame(), normalWorld(m_exec->globalData())); + if (JSValue dialogArguments = m_exec->argument(1)) + m_globalObject->putDirect(Identifier(m_exec, "dialogArguments"), dialogArguments); +} + +inline JSValue DialogHandler::returnValue() const +{ + if (!m_globalObject) + return jsUndefined(); + Identifier identifier(m_exec, "returnValue"); + PropertySlot slot; + if (!m_globalObject->JSGlobalObject::getOwnPropertySlot(m_exec, identifier, slot)) + return jsUndefined(); + return slot.getValue(m_exec, identifier); +} + +static void setUpDialog(DOMWindow* dialog, void* handler) +{ + static_cast<DialogHandler*>(handler)->dialogCreated(dialog); +} + +JSValue JSDOMWindow::showModalDialog(ExecState* exec) +{ + String urlString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + String dialogFeaturesString = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + + DialogHandler handler(exec); + + impl()->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(exec), firstDOMWindow(exec), setUpDialog, &handler); + + return handler.returnValue(); +} + +JSValue JSDOMWindow::postMessage(ExecState* exec) +{ + PassRefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0)); + + if (exec->hadException()) + return jsUndefined(); + + MessagePortArray messagePorts; + if (exec->argumentCount() > 2) + fillMessagePortArray(exec, exec->argument(1), messagePorts); + if (exec->hadException()) + return jsUndefined(); + + String targetOrigin = valueToStringWithUndefinedOrNullCheck(exec, exec->argument((exec->argumentCount() == 2) ? 1 : 2)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + impl()->postMessage(message, &messagePorts, targetOrigin, activeDOMWindow(exec), ec); + setDOMException(exec, ec); + + return jsUndefined(); +} + +JSValue JSDOMWindow::setTimeout(ExecState* exec) +{ + OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, currentWorld(exec)); + if (exec->hadException()) + return jsUndefined(); + int delay = exec->argument(1).toInt32(exec); + + ExceptionCode ec = 0; + int result = impl()->setTimeout(action.release(), delay, ec); + setDOMException(exec, ec); + + return jsNumber(result); +} + +JSValue JSDOMWindow::setInterval(ExecState* exec) +{ + OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, currentWorld(exec)); + if (exec->hadException()) + return jsUndefined(); + int delay = exec->argument(1).toInt32(exec); + + ExceptionCode ec = 0; + int result = impl()->setInterval(action.release(), delay, ec); + setDOMException(exec, ec); + + return jsNumber(result); +} + +JSValue JSDOMWindow::addEventListener(ExecState* exec) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + JSValue listener = exec->argument(1); + if (!listener.isObject()) + return jsUndefined(); + + impl()->addEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)), exec->argument(2).toBoolean(exec)); + return jsUndefined(); +} + +JSValue JSDOMWindow::removeEventListener(ExecState* exec) +{ + Frame* frame = impl()->frame(); + if (!frame) + return jsUndefined(); + + JSValue listener = exec->argument(1); + if (!listener.isObject()) + return jsUndefined(); + + impl()->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)), JSEventListener::create(asObject(listener), this, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec)); + return jsUndefined(); +} + +DOMWindow* toDOMWindow(JSValue value) +{ + if (!value.isObject()) + return 0; + JSObject* object = asObject(value); + if (object->inherits(&JSDOMWindow::s_info)) + return static_cast<JSDOMWindow*>(object)->impl(); + if (object->inherits(&JSDOMWindowShell::s_info)) + return static_cast<JSDOMWindowShell*>(object)->impl(); + return 0; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMWindowCustom.h b/Source/WebCore/bindings/js/JSDOMWindowCustom.h new file mode 100644 index 0000000..a0e1b8f --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWindowCustom.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMWindowCustom_h +#define JSDOMWindowCustom_h + +#include "JSDOMWindow.h" +#include "JSDOMWindowShell.h" +#include <wtf/AlwaysInline.h> + +namespace WebCore { + +inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject) +{ + return static_cast<JSDOMWindow*>(globalObject); +} + +inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject) +{ + return static_cast<const JSDOMWindow*>(globalObject); +} + +inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const +{ + if (allowsAccessFromPrivate(other)) + return true; + printErrorMessage(crossDomainAccessErrorMessage(other)); + return false; +} + +inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec) const +{ + if (allowsAccessFromPrivate(exec->lexicalGlobalObject())) + return true; + printErrorMessage(crossDomainAccessErrorMessage(exec->lexicalGlobalObject())); + return false; +} + +inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const +{ + return allowsAccessFromPrivate(exec->lexicalGlobalObject()); +} + +inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec, String& message) const +{ + if (allowsAccessFromPrivate(exec->lexicalGlobalObject())) + return true; + message = crossDomainAccessErrorMessage(exec->lexicalGlobalObject()); + return false; +} + +ALWAYS_INLINE bool JSDOMWindowBase::allowsAccessFromPrivate(const JSGlobalObject* other) const +{ + const JSDOMWindow* originWindow = asJSDOMWindow(other); + const JSDOMWindow* targetWindow = d()->shell->window(); + + if (originWindow == targetWindow) + return true; + + const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin(); + const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin(); + + return originSecurityOrigin->canAccess(targetSecurityOrigin); +} + +} + +#endif // JSDOMWindowCustom_h diff --git a/Source/WebCore/bindings/js/JSDOMWindowShell.cpp b/Source/WebCore/bindings/js/JSDOMWindowShell.cpp new file mode 100644 index 0000000..65096b9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWindowShell.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMWindowShell.h" + +#include "Frame.h" +#include "JSDOMWindow.h" +#include "DOMWindow.h" +#include "ScriptController.h" +#include <runtime/JSObject.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSDOMWindowShell); + +const ClassInfo JSDOMWindowShell::s_info = { "JSDOMWindowShell", 0, 0, 0 }; + +JSDOMWindowShell::JSDOMWindowShell(PassRefPtr<DOMWindow> window, DOMWrapperWorld* world) + : Base(JSDOMWindowShell::createStructure(jsNull())) + , m_window(0) + , m_world(world) +{ + setWindow(window); +} + +JSDOMWindowShell::~JSDOMWindowShell() +{ +} + +void JSDOMWindowShell::setWindow(PassRefPtr<DOMWindow> domWindow) +{ + // Explicitly protect the global object's prototype so it isn't collected + // when we allocate the global object. (Once the global object is fully + // constructed, it can mark its own prototype.) + RefPtr<Structure> prototypeStructure = JSDOMWindowPrototype::createStructure(jsNull()); + ProtectedPtr<JSDOMWindowPrototype> prototype = new JSDOMWindowPrototype(0, prototypeStructure.release()); + + RefPtr<Structure> structure = JSDOMWindow::createStructure(prototype); + JSDOMWindow* jsDOMWindow = new (JSDOMWindow::commonJSGlobalData()) JSDOMWindow(structure.release(), domWindow, this); + prototype->putAnonymousValue(0, jsDOMWindow); + setWindow(jsDOMWindow); +} + +// ---- +// JSObject methods +// ---- + +void JSDOMWindowShell::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + if (m_window) + markStack.append(m_window); +} + +UString JSDOMWindowShell::className() const +{ + return m_window->className(); +} + +bool JSDOMWindowShell::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return m_window->getOwnPropertySlot(exec, propertyName, slot); +} + +bool JSDOMWindowShell::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + return m_window->getOwnPropertyDescriptor(exec, propertyName, descriptor); +} + +void JSDOMWindowShell::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + m_window->put(exec, propertyName, value, slot); +} + +void JSDOMWindowShell::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes) +{ + m_window->putWithAttributes(exec, propertyName, value, attributes); +} + +bool JSDOMWindowShell::defineOwnProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor, bool shouldThrow) +{ + return m_window->defineOwnProperty(exec, propertyName, descriptor, shouldThrow); +} + +bool JSDOMWindowShell::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + return m_window->deleteProperty(exec, propertyName); +} + +void JSDOMWindowShell::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + m_window->getPropertyNames(exec, propertyNames, mode); +} + +void JSDOMWindowShell::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + m_window->getOwnPropertyNames(exec, propertyNames, mode); +} + +void JSDOMWindowShell::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes) +{ + m_window->defineGetter(exec, propertyName, getterFunction, attributes); +} + +void JSDOMWindowShell::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes) +{ + m_window->defineSetter(exec, propertyName, setterFunction, attributes); +} + +JSValue JSDOMWindowShell::lookupGetter(ExecState* exec, const Identifier& propertyName) +{ + return m_window->lookupGetter(exec, propertyName); +} + +JSValue JSDOMWindowShell::lookupSetter(ExecState* exec, const Identifier& propertyName) +{ + return m_window->lookupSetter(exec, propertyName); +} + +JSObject* JSDOMWindowShell::unwrappedObject() +{ + return m_window; +} + +// ---- +// JSDOMWindow methods +// ---- + +DOMWindow* JSDOMWindowShell::impl() const +{ + return m_window->impl(); +} + +void* JSDOMWindowShell::operator new(size_t size) +{ + return JSDOMWindow::commonJSGlobalData()->heap.allocate(size); +} + +// ---- +// Conversion methods +// ---- + +JSValue toJS(ExecState* exec, Frame* frame) +{ + if (!frame) + return jsNull(); + return frame->script()->windowShell(currentWorld(exec)); +} + +JSDOMWindowShell* toJSDOMWindowShell(Frame* frame, DOMWrapperWorld* isolatedWorld) +{ + if (!frame) + return 0; + return frame->script()->windowShell(isolatedWorld); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMWindowShell.h b/Source/WebCore/bindings/js/JSDOMWindowShell.h new file mode 100644 index 0000000..888325d --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWindowShell.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSDOMWindowShell_h +#define JSDOMWindowShell_h + +#include "JSDOMWindow.h" +#include "JSDOMBinding.h" + +namespace WebCore { + + class DOMWindow; + class Frame; + + class JSDOMWindowShell : public JSC::JSObject { + typedef JSC::JSObject Base; + public: + JSDOMWindowShell(PassRefPtr<DOMWindow>, DOMWrapperWorld* world); + virtual ~JSDOMWindowShell(); + + JSDOMWindow* window() const { return m_window; } + void setWindow(JSDOMWindow* window) + { + ASSERT_ARG(window, window); + m_window = window; + setPrototype(window->prototype()); + } + void setWindow(PassRefPtr<DOMWindow>); + + static const JSC::ClassInfo s_info; + + DOMWindow* impl() const; + + void* operator new(size_t); + + static PassRefPtr<JSC::Structure> createStructure(JSC::JSValue prototype) + { + return JSC::Structure::create(prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount); + } + + DOMWrapperWorld* world() { return m_world.get(); } + + private: + static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | Base::StructureFlags; + + virtual void markChildren(JSC::MarkStack&); + virtual JSC::UString className() const; + virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&); + virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&); + virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&); + virtual void putWithAttributes(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, unsigned attributes); + virtual bool deleteProperty(JSC::ExecState*, const JSC::Identifier& propertyName); + virtual void getPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties); + virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties); + virtual void defineGetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes); + virtual void defineSetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes); + virtual bool defineOwnProperty(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&, bool shouldThrow); + virtual JSC::JSValue lookupGetter(JSC::ExecState*, const JSC::Identifier& propertyName); + virtual JSC::JSValue lookupSetter(JSC::ExecState*, const JSC::Identifier& propertyName); + virtual JSC::JSObject* unwrappedObject(); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + + JSDOMWindow* m_window; + RefPtr<DOMWrapperWorld> m_world; + }; + + JSC::JSValue toJS(JSC::ExecState*, Frame*); + JSDOMWindowShell* toJSDOMWindowShell(Frame*, DOMWrapperWorld*); + +} // namespace WebCore + +#endif // JSDOMWindowShell_h diff --git a/Source/WebCore/bindings/js/JSDOMWrapper.cpp b/Source/WebCore/bindings/js/JSDOMWrapper.cpp new file mode 100644 index 0000000..9548f2f --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWrapper.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDOMWrapper.h" + +#include "JSDebugWrapperSet.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +#ifndef NDEBUG + +DOMObject::~DOMObject() +{ + ASSERT(!JSDebugWrapperSet::shared().contains(this)); +} + +#endif + +bool DOMObject::defineOwnProperty(ExecState* exec, const Identifier&, PropertyDescriptor&, bool) +{ + throwError(exec, createTypeError(exec, "defineProperty is not supported on DOM Objects")); + return false; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDOMWrapper.h b/Source/WebCore/bindings/js/JSDOMWrapper.h new file mode 100644 index 0000000..2d09f01 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDOMWrapper.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * Copyright (C) 2009 Google, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSDOMWrapper_h +#define JSDOMWrapper_h + +#include <runtime/JSObjectWithGlobalObject.h> + +namespace WebCore { + +// FIXME: Rename to JSDOMWrapper. +class DOMObject : public JSC::JSObjectWithGlobalObject { +protected: + explicit DOMObject(JSC::JSGlobalObject* globalObject, NonNullPassRefPtr<JSC::Structure> structure) + : JSObjectWithGlobalObject(globalObject, structure) + { + } + + virtual bool defineOwnProperty(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&, bool); + +#ifndef NDEBUG + virtual ~DOMObject(); +#endif +}; + +} // namespace WebCore + +#endif // JSDOMWrapper_h diff --git a/Source/WebCore/bindings/js/JSDataGridColumnListCustom.cpp b/Source/WebCore/bindings/js/JSDataGridColumnListCustom.cpp new file mode 100644 index 0000000..cc41093 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDataGridColumnListCustom.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(DATAGRID) + +#include "JSDataGridColumnList.h" + +#include "DataGridColumn.h" +#include "DataGridColumnList.h" +#include "JSDataGridColumn.h" +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +bool JSDataGridColumnList::canGetItemsForName(ExecState*, DataGridColumnList* impl, const Identifier& propertyName) +{ + return impl->itemWithName(identifierToAtomicString(propertyName)); +} + +JSValue JSDataGridColumnList::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSDataGridColumnList* thisObj = static_cast<JSDataGridColumnList*>(asObject(slotBase)); + return toJS(exec, thisObj->globalObject(), thisObj->impl()->itemWithName(identifierToAtomicString(propertyName))); +} + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/bindings/js/JSDataGridDataSource.cpp b/Source/WebCore/bindings/js/JSDataGridDataSource.cpp new file mode 100644 index 0000000..02b4214 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDataGridDataSource.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(DATAGRID) + +#include "JSDataGridDataSource.h" + +#include "Document.h" +#include "Frame.h" +#include "HTMLDataGridElement.h" +#include "JSHTMLDataGridElement.h" +#include "JSDOMWindowBase.h" +#include <runtime/JSLock.h> + +using namespace JSC; + +namespace WebCore { + +JSDataGridDataSource::JSDataGridDataSource(JSC::JSValue dataSource, Frame* frame) + : m_dataSource(dataSource) + , m_frame(frame) +{ +} + +JSDataGridDataSource::~JSDataGridDataSource() +{ +} + +} // namespace WebCore + +#endif // ENABLE(DATAGRID) diff --git a/Source/WebCore/bindings/js/JSDataGridDataSource.h b/Source/WebCore/bindings/js/JSDataGridDataSource.h new file mode 100644 index 0000000..077ef8f --- /dev/null +++ b/Source/WebCore/bindings/js/JSDataGridDataSource.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSDataGridDataSource_h +#define JSDataGridDataSource_h + +#if ENABLE(DATAGRID) + +#include "DataGridDataSource.h" +#include <runtime/JSValue.h> +#include <runtime/Protect.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class Frame; +class HTMLDataGridElement; + +class JSDataGridDataSource : public DataGridDataSource { +public: + static PassRefPtr<JSDataGridDataSource> create(JSC::JSValue dataSource, Frame* frame) + { + return adoptRef(new JSDataGridDataSource(dataSource, frame)); + } + + virtual ~JSDataGridDataSource(); + + virtual bool isJSDataGridDataSource() const { return true; } + JSC::JSValue jsDataSource() const { return m_dataSource.get(); } + +private: + JSDataGridDataSource(JSC::JSValue, Frame*); + + JSC::ProtectedJSValue m_dataSource; + RefPtr<Frame> m_frame; +}; + +inline JSDataGridDataSource* asJSDataGridDataSource(DataGridDataSource* dataSource) +{ + ASSERT(dataSource->isJSDataGridDataSource()); + return static_cast<JSDataGridDataSource*>(dataSource); +} + +inline const JSDataGridDataSource* asJSDataGridDataSource(const DataGridDataSource* dataSource) +{ + ASSERT(dataSource->isJSDataGridDataSource()); + return static_cast<const JSDataGridDataSource*>(dataSource); +} + +} // namespace WebCore + +#endif // ENABLE(DATAGRID) +#endif // JSDataGridDataSource_h diff --git a/Source/WebCore/bindings/js/JSDataViewCustom.cpp b/Source/WebCore/bindings/js/JSDataViewCustom.cpp new file mode 100644 index 0000000..ba48374 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDataViewCustom.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSDataView.h" + +#include "DataView.h" +#include "ExceptionCode.h" +#include "JSArrayBufferViewHelper.h" +#include <wtf/MathExtras.h> + +using namespace JSC; + +namespace WebCore { + +enum DataViewAccessType { + AccessDataViewMemberAsInt8, + AccessDataViewMemberAsUint8, + AccessDataViewMemberAsFloat32, + AccessDataViewMemberAsFloat64 +}; + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, DataView* object) +{ + return getDOMObjectWrapper<JSDataView>(exec, globalObject, object); +} + +EncodedJSValue JSC_HOST_CALL JSDataViewConstructor::constructJSDataView(ExecState* exec) +{ + if (exec->argument(0).isNull() || !exec->argument(0).isObject()) + return throwVMTypeError(exec); + + RefPtr<DataView> view = constructArrayBufferViewWithArrayBufferArgument<DataView, char>(exec); + if (!view.get()) { + setDOMException(exec, INDEX_SIZE_ERR); + return JSValue::encode(jsUndefined()); + } + + JSDataViewConstructor* jsConstructor = static_cast<JSDataViewConstructor*>(exec->callee()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), view.get()))); +} + +static JSValue getDataViewMember(ExecState* exec, DataView* imp, DataViewAccessType type) +{ + if (exec->argumentCount() < 1) + return throwError(exec, createSyntaxError(exec, "Not enough arguments")); + ExceptionCode ec = 0; + unsigned byteOffset = exec->argument(0).toUInt32(exec); + if (exec->hadException()) + return jsUndefined(); + + bool littleEndian = false; + if (exec->argumentCount() > 1 && (type == AccessDataViewMemberAsFloat32 || type == AccessDataViewMemberAsFloat64)) { + littleEndian = exec->argument(1).toBoolean(exec); + if (exec->hadException()) + return jsUndefined(); + } + + JSC::JSValue result; + switch (type) { + case AccessDataViewMemberAsInt8: + result = jsNumber(imp->getInt8(byteOffset, ec)); + break; + case AccessDataViewMemberAsUint8: + result = jsNumber(imp->getUint8(byteOffset, ec)); + break; + case AccessDataViewMemberAsFloat32: + case AccessDataViewMemberAsFloat64: { + double value = (type == AccessDataViewMemberAsFloat32) ? imp->getFloat32(byteOffset, littleEndian, ec) : imp->getFloat64(byteOffset, littleEndian, ec); + result = isnan(value) ? JSValue(nonInlineNaN()) : jsNumber(value); + break; + } default: + ASSERT_NOT_REACHED(); + break; + } + setDOMException(exec, ec); + return result; +} + +JSValue JSDataView::getInt8(ExecState* exec) +{ + return getDataViewMember(exec, static_cast<DataView*>(impl()), AccessDataViewMemberAsInt8); +} + +JSValue JSDataView::getUint8(ExecState* exec) +{ + return getDataViewMember(exec, static_cast<DataView*>(impl()), AccessDataViewMemberAsUint8); +} + +JSValue JSDataView::getFloat32(ExecState* exec) +{ + return getDataViewMember(exec, static_cast<DataView*>(impl()), AccessDataViewMemberAsFloat32); +} + +JSValue JSDataView::getFloat64(ExecState* exec) +{ + return getDataViewMember(exec, static_cast<DataView*>(impl()), AccessDataViewMemberAsFloat64); +} + +static JSValue setDataViewMember(ExecState* exec, DataView* imp, DataViewAccessType type) +{ + if (exec->argumentCount() < 2) + return throwError(exec, createSyntaxError(exec, "Not enough arguments")); + ExceptionCode ec = 0; + unsigned byteOffset = exec->argument(0).toUInt32(exec); + if (exec->hadException()) + return jsUndefined(); + int value = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + + switch (type) { + case AccessDataViewMemberAsInt8: + imp->setInt8(byteOffset, static_cast<int8_t>(value), ec); + break; + case AccessDataViewMemberAsUint8: + imp->setUint8(byteOffset, static_cast<uint8_t>(value), ec); + break; + default: + ASSERT_NOT_REACHED(); + break; + } + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSDataView::setInt8(ExecState* exec) +{ + return setDataViewMember(exec, static_cast<DataView*>(impl()), AccessDataViewMemberAsInt8); +} + +JSValue JSDataView::setUint8(ExecState* exec) +{ + return setDataViewMember(exec, static_cast<DataView*>(impl()), AccessDataViewMemberAsUint8); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSDebugWrapperSet.cpp b/Source/WebCore/bindings/js/JSDebugWrapperSet.cpp new file mode 100644 index 0000000..b0d6ca9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDebugWrapperSet.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDebugWrapperSet.h" + +#include <wtf/StdLibExtras.h> + +#if ENABLE(WORKERS) +#include <wtf/ThreadSpecific.h> +#endif + +namespace WebCore { + +JSDebugWrapperSet& JSDebugWrapperSet::shared() +{ +#if ENABLE(WORKERS) + DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<JSDebugWrapperSet>, staticWrapperSet, ()); + return *staticWrapperSet; +#else + DEFINE_STATIC_LOCAL(JSDebugWrapperSet, staticWrapperSet, ()); + return staticWrapperSet; +#endif +} + +JSDebugWrapperSet::JSDebugWrapperSet() +{ +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSDebugWrapperSet.h b/Source/WebCore/bindings/js/JSDebugWrapperSet.h new file mode 100644 index 0000000..94b6f78 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDebugWrapperSet.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSDebugWrapperSet_h +#define JSDebugWrapperSet_h + +#include "JSDOMWrapper.h" +#include <wtf/HashSet.h> +#include <wtf/Noncopyable.h> + +namespace WebCore { + +// For debugging, keep a set of wrappers currently cached, and check that +// all are uncached before they are destroyed. This helps us catch bugs like: +// - wrappers being deleted without being removed from the cache +// - wrappers being cached twice + +class JSDebugWrapperSet : public Noncopyable { + friend class WTF::ThreadSpecific<JSDebugWrapperSet>; +public: + static JSDebugWrapperSet& shared(); + + void add(DOMObject* object) { m_wrapperSet.add(object); } + void remove(DOMObject* object) { m_wrapperSet.remove(object); } + bool contains(DOMObject* object) const { return m_wrapperSet.contains(object); } + + static void willCacheWrapper(DOMObject*); + static void didUncacheWrapper(DOMObject*); + +private: + JSDebugWrapperSet(); + + HashSet<DOMObject*> m_wrapperSet; +}; + +#ifdef NDEBUG + +inline void JSDebugWrapperSet::willCacheWrapper(DOMObject*) +{ +} + +inline void JSDebugWrapperSet::didUncacheWrapper(DOMObject*) +{ +} + +#else + +inline void JSDebugWrapperSet::willCacheWrapper(DOMObject* wrapper) +{ + ASSERT(!JSDebugWrapperSet::shared().contains(wrapper)); + JSDebugWrapperSet::shared().add(wrapper); +} + +inline void JSDebugWrapperSet::didUncacheWrapper(DOMObject* wrapper) +{ + if (!wrapper) + return; + ASSERT(JSDebugWrapperSet::shared().contains(wrapper)); + JSDebugWrapperSet::shared().remove(wrapper); +} + +#endif + +} // namespace WebCore + +#endif // JSDebugWrapperSet_h diff --git a/Source/WebCore/bindings/js/JSDedicatedWorkerContextCustom.cpp b/Source/WebCore/bindings/js/JSDedicatedWorkerContextCustom.cpp new file mode 100644 index 0000000..2222353 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDedicatedWorkerContextCustom.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009 Apple, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WORKERS) + +#include "JSDedicatedWorkerContext.h" + +#include "JSDOMBinding.h" +#include "JSMessagePortCustom.h" + +using namespace JSC; + +namespace WebCore { + +JSC::JSValue JSDedicatedWorkerContext::postMessage(JSC::ExecState* exec) +{ + return handlePostMessage(exec, impl()); +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/Source/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp b/Source/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp new file mode 100644 index 0000000..38334b9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDesktopNotificationsCustom.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(NOTIFICATIONS) + +#include "Document.h" +#include "JSCustomVoidCallback.h" +#include "JSEventListener.h" +#include "JSNotification.h" +#include "JSNotificationCenter.h" +#include "Notification.h" +#include "NotificationCenter.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSNotificationCenter::requestPermission(ExecState* exec) +{ + ScriptExecutionContext* context = impl()->context(); + + // Make sure that script execution context is valid. + if (!context) { + setDOMException(exec, INVALID_STATE_ERR); + return jsUndefined(); + } + + // Permission request is only valid from page context. + if (context->isWorkerContext()) + return throwSyntaxError(exec); + + if (!exec->argument(0).isObject()) + return throwTypeError(exec); + + PassRefPtr<JSCustomVoidCallback> callback = JSCustomVoidCallback::create(exec->argument(0).getObject(), toJSDOMGlobalObject(static_cast<Document*>(context), exec)); + + impl()->requestPermission(callback); + return jsUndefined(); +} + +} // namespace + +#endif // ENABLE(NOTIFICATIONS) diff --git a/Source/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp b/Source/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp new file mode 100644 index 0000000..503d64f --- /dev/null +++ b/Source/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDeviceMotionEvent.h" + +#if ENABLE(DEVICE_ORIENTATION) + +#include "DeviceMotionData.h" +#include "DeviceMotionEvent.h" + +using namespace JSC; + +namespace WebCore { + +static PassRefPtr<DeviceMotionData::Acceleration> readAccelerationArgument(JSValue value, ExecState* exec) +{ + if (value.isUndefinedOrNull()) + return 0; + + // Given the above test, this will always yield an object. + JSObject* object = value.toObject(exec); + + JSValue xValue = object->get(exec, Identifier(exec, "x")); + if (exec->hadException()) + return 0; + bool canProvideX = !xValue.isUndefinedOrNull(); + double x = xValue.toNumber(exec); + if (exec->hadException()) + return 0; + + JSValue yValue = object->get(exec, Identifier(exec, "y")); + if (exec->hadException()) + return 0; + bool canProvideY = !yValue.isUndefinedOrNull(); + double y = yValue.toNumber(exec); + if (exec->hadException()) + return 0; + + JSValue zValue = object->get(exec, Identifier(exec, "z")); + if (exec->hadException()) + return 0; + bool canProvideZ = !zValue.isUndefinedOrNull(); + double z = zValue.toNumber(exec); + if (exec->hadException()) + return 0; + + if (!canProvideX && !canProvideY && !canProvideZ) + return 0; + + return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y, canProvideZ, z); +} + +static PassRefPtr<DeviceMotionData::RotationRate> readRotationRateArgument(JSValue value, ExecState* exec) +{ + if (value.isUndefinedOrNull()) + return 0; + + // Given the above test, this will always yield an object. + JSObject* object = value.toObject(exec); + + JSValue alphaValue = object->get(exec, Identifier(exec, "alpha")); + if (exec->hadException()) + return 0; + bool canProvideAlpha = !alphaValue.isUndefinedOrNull(); + double alpha = alphaValue.toNumber(exec); + if (exec->hadException()) + return 0; + + JSValue betaValue = object->get(exec, Identifier(exec, "beta")); + if (exec->hadException()) + return 0; + bool canProvideBeta = !betaValue.isUndefinedOrNull(); + double beta = betaValue.toNumber(exec); + if (exec->hadException()) + return 0; + + JSValue gammaValue = object->get(exec, Identifier(exec, "gamma")); + if (exec->hadException()) + return 0; + bool canProvideGamma = !gammaValue.isUndefinedOrNull(); + double gamma = gammaValue.toNumber(exec); + if (exec->hadException()) + return 0; + + if (!canProvideAlpha && !canProvideBeta && !canProvideGamma) + return 0; + + return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma); +} + +static JSObject* createAccelerationObject(const DeviceMotionData::Acceleration* acceleration, ExecState* exec) +{ + JSObject* object = constructEmptyObject(exec); + object->putDirect(Identifier(exec, "x"), acceleration->canProvideX() ? jsNumber(acceleration->x()) : jsNull()); + object->putDirect(Identifier(exec, "y"), acceleration->canProvideY() ? jsNumber(acceleration->y()) : jsNull()); + object->putDirect(Identifier(exec, "z"), acceleration->canProvideZ() ? jsNumber(acceleration->z()) : jsNull()); + return object; +} + +static JSObject* createRotationRateObject(const DeviceMotionData::RotationRate* rotationRate, ExecState* exec) +{ + JSObject* object = constructEmptyObject(exec); + object->putDirect(Identifier(exec, "alpha"), rotationRate->canProvideAlpha() ? jsNumber(rotationRate->alpha()) : jsNull()); + object->putDirect(Identifier(exec, "beta"), rotationRate->canProvideBeta() ? jsNumber(rotationRate->beta()) : jsNull()); + object->putDirect(Identifier(exec, "gamma"), rotationRate->canProvideGamma() ? jsNumber(rotationRate->gamma()) : jsNull()); + return object; +} + +JSValue JSDeviceMotionEvent::acceleration(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->acceleration()) + return jsNull(); + return createAccelerationObject(imp->deviceMotionData()->acceleration(), exec); +} + +JSValue JSDeviceMotionEvent::accelerationIncludingGravity(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->accelerationIncludingGravity()) + return jsNull(); + return createAccelerationObject(imp->deviceMotionData()->accelerationIncludingGravity(), exec); +} + +JSValue JSDeviceMotionEvent::rotationRate(ExecState* exec) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->rotationRate()) + return jsNull(); + return createRotationRateObject(imp->deviceMotionData()->rotationRate(), exec); +} + +JSValue JSDeviceMotionEvent::interval(ExecState*) const +{ + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + if (!imp->deviceMotionData()->canProvideInterval()) + return jsNull(); + return jsNumber(imp->deviceMotionData()->interval()); +} + +JSValue JSDeviceMotionEvent::initDeviceMotionEvent(ExecState* exec) +{ + const String& type = ustringToString(exec->argument(0).toString(exec)); + bool bubbles = exec->argument(1).toBoolean(exec); + bool cancelable = exec->argument(2).toBoolean(exec); + + // If any of the parameters are null or undefined, mark them as not provided. + // Otherwise, use the standard JavaScript conversion. + RefPtr<DeviceMotionData::Acceleration> acceleration = readAccelerationArgument(exec->argument(3), exec); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<DeviceMotionData::Acceleration> accelerationIncludingGravity = readAccelerationArgument(exec->argument(4), exec); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<DeviceMotionData::RotationRate> rotationRate = readRotationRateArgument(exec->argument(5), exec); + if (exec->hadException()) + return jsUndefined(); + + bool intervalProvided = !exec->argument(6).isUndefinedOrNull(); + double interval = exec->argument(6).toNumber(exec); + RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval); + DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl()); + imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get()); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/Source/WebCore/bindings/js/JSDeviceOrientationEventCustom.cpp b/Source/WebCore/bindings/js/JSDeviceOrientationEventCustom.cpp new file mode 100644 index 0000000..c71364a --- /dev/null +++ b/Source/WebCore/bindings/js/JSDeviceOrientationEventCustom.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSDeviceOrientationEvent.h" + +#if ENABLE(DEVICE_ORIENTATION) + +#include "DeviceOrientation.h" +#include "DeviceOrientationEvent.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSDeviceOrientationEvent::alpha(ExecState*) const +{ + DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); + if (!imp->orientation()->canProvideAlpha()) + return jsNull(); + return jsNumber(imp->orientation()->alpha()); +} + +JSValue JSDeviceOrientationEvent::beta(ExecState*) const +{ + DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); + if (!imp->orientation()->canProvideBeta()) + return jsNull(); + return jsNumber(imp->orientation()->beta()); +} + +JSValue JSDeviceOrientationEvent::gamma(ExecState*) const +{ + DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); + if (!imp->orientation()->canProvideGamma()) + return jsNull(); + return jsNumber(imp->orientation()->gamma()); +} + +JSValue JSDeviceOrientationEvent::initDeviceOrientationEvent(ExecState* exec) +{ + const String& type = ustringToString(exec->argument(0).toString(exec)); + bool bubbles = exec->argument(1).toBoolean(exec); + bool cancelable = exec->argument(2).toBoolean(exec); + // If alpha, beta or gamma are null or undefined, mark them as not provided. + // Otherwise, use the standard JavaScript conversion. + bool alphaProvided = !exec->argument(3).isUndefinedOrNull(); + double alpha = exec->argument(3).toNumber(exec); + bool betaProvided = !exec->argument(4).isUndefinedOrNull(); + double beta = exec->argument(4).toNumber(exec); + bool gammaProvided = !exec->argument(5).isUndefinedOrNull(); + double gamma = exec->argument(5).toNumber(exec); + RefPtr<DeviceOrientation> orientation = DeviceOrientation::create(alphaProvided, alpha, betaProvided, beta, gammaProvided, gamma); + DeviceOrientationEvent* imp = static_cast<DeviceOrientationEvent*>(impl()); + imp->initDeviceOrientationEvent(type, bubbles, cancelable, orientation.get()); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(DEVICE_ORIENTATION) diff --git a/Source/WebCore/bindings/js/JSDirectoryEntryCustom.cpp b/Source/WebCore/bindings/js/JSDirectoryEntryCustom.cpp new file mode 100644 index 0000000..a0e0455 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDirectoryEntryCustom.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(FILE_SYSTEM) + +#include "JSDirectoryEntry.h" + +#include "JSDOMBinding.h" +#include "JSEntryCallback.h" +#include "JSErrorCallback.h" +#include "JSFlags.h" +#include <wtf/Assertions.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSDirectoryEntry::getFile(ExecState* exec) +{ + DirectoryEntry* imp = static_cast<DirectoryEntry*>(impl()); + const String& path = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + int argsCount = exec->argumentCount(); + if (argsCount <= 1) { + imp->getFile(path); + return jsUndefined(); + } + + RefPtr<Flags> flags; + if (!exec->argument(1).isNull() && !exec->argument(1).isUndefined() && exec->argument(1).isObject() && !exec->argument(1).inherits(&JSFlags::s_info)) { + JSObject* object = exec->argument(1).getObject(); + flags = Flags::create(); + JSValue jsCreate = object->get(exec, Identifier(exec, "create")); + flags->setCreate(jsCreate.toBoolean(exec)); + JSValue jsExclusive = object->get(exec, Identifier(exec, "exclusive")); + flags->setExclusive(jsExclusive.toBoolean(exec)); + } else + flags = toFlags(exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + RefPtr<EntryCallback> successCallback; + if (exec->argumentCount() > 2 && !exec->argument(2).isNull() && !exec->argument(2).isUndefined()) { + if (!exec->argument(2).isObject()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + successCallback = JSEntryCallback::create(asObject(exec->argument(2)), globalObject()); + } + RefPtr<ErrorCallback> errorCallback; + if (exec->argumentCount() > 3 && !exec->argument(3).isNull() && !exec->argument(3).isUndefined()) { + if (!exec->argument(3).isObject()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + errorCallback = JSErrorCallback::create(asObject(exec->argument(3)), globalObject()); + } + + imp->getFile(path, flags, successCallback, errorCallback); + return jsUndefined(); +} + +JSValue JSDirectoryEntry::getDirectory(ExecState* exec) +{ + DirectoryEntry* imp = static_cast<DirectoryEntry*>(impl()); + const String& path = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + int argsCount = exec->argumentCount(); + if (argsCount <= 1) { + imp->getDirectory(path); + return jsUndefined(); + } + + RefPtr<Flags> flags; + if (!exec->argument(1).isNull() && !exec->argument(1).isUndefined() && exec->argument(1).isObject() && !exec->argument(1).inherits(&JSFlags::s_info)) { + JSObject* object = exec->argument(1).getObject(); + flags = Flags::create(); + JSValue jsCreate = object->get(exec, Identifier(exec, "create")); + flags->setCreate(jsCreate.toBoolean(exec)); + JSValue jsExclusive = object->get(exec, Identifier(exec, "exclusive")); + flags->setExclusive(jsExclusive.toBoolean(exec)); + } else + flags = toFlags(exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + RefPtr<EntryCallback> successCallback; + if (exec->argumentCount() > 2 && !exec->argument(2).isNull() && !exec->argument(2).isUndefined()) { + if (!exec->argument(2).isObject()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + successCallback = JSEntryCallback::create(asObject(exec->argument(2)), globalObject()); + } + RefPtr<ErrorCallback> errorCallback; + if (exec->argumentCount() > 3 && !exec->argument(3).isNull() && !exec->argument(3).isUndefined()) { + if (!exec->argument(3).isObject()) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + errorCallback = JSErrorCallback::create(asObject(exec->argument(3)), globalObject()); + } + + imp->getDirectory(path, flags, successCallback, errorCallback); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(FILE_SYSTEM) diff --git a/Source/WebCore/bindings/js/JSDirectoryEntrySyncCustom.cpp b/Source/WebCore/bindings/js/JSDirectoryEntrySyncCustom.cpp new file mode 100644 index 0000000..ef14b79 --- /dev/null +++ b/Source/WebCore/bindings/js/JSDirectoryEntrySyncCustom.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(FILE_SYSTEM) + +#include "JSDirectoryEntrySync.h" + +#include "JSDOMBinding.h" +#include "JSEntryCallback.h" +#include "JSErrorCallback.h" +#include "JSFileEntrySync.h" +#include "JSFlags.h" +#include <wtf/Assertions.h> + +using namespace JSC; + +namespace WebCore { + +static PassRefPtr<Flags> getFlags(ExecState* exec, const JSValue& argument) +{ + if (argument.isNull() || argument.isUndefined() || !argument.isObject()) + return 0; + if (argument.inherits(&JSFlags::s_info)) + return toFlags(argument); + + RefPtr<Flags> flags; + JSObject* object = argument.getObject(); + flags = Flags::create(); + JSValue jsCreate = object->get(exec, Identifier(exec, "create")); + flags->setCreate(jsCreate.toBoolean(exec)); + JSValue jsExclusive = object->get(exec, Identifier(exec, "exclusive")); + flags->setExclusive(jsExclusive.toBoolean(exec)); + return flags; +} + +JSValue JSDirectoryEntrySync::getFile(ExecState* exec) +{ + DirectoryEntrySync* imp = static_cast<DirectoryEntrySync*>(impl()); + const String& path = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<Flags> flags = getFlags(exec, exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + JSC::JSValue result = toJS(exec, this->globalObject(), WTF::getPtr(imp->getFile(path, flags, ec))); + setDOMException(exec, ec); + return result; +} + +JSValue JSDirectoryEntrySync::getDirectory(ExecState* exec) +{ + DirectoryEntrySync* imp = static_cast<DirectoryEntrySync*>(impl()); + const String& path = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<Flags> flags = getFlags(exec, exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + JSC::JSValue result = toJS(exec, this->globalObject(), WTF::getPtr(imp->getDirectory(path, flags, ec))); + setDOMException(exec, ec); + return result; +} + +} // namespace WebCore + +#endif // ENABLE(FILE_SYSTEM) diff --git a/Source/WebCore/bindings/js/JSDocumentCustom.cpp b/Source/WebCore/bindings/js/JSDocumentCustom.cpp new file mode 100644 index 0000000..5f61e2a --- /dev/null +++ b/Source/WebCore/bindings/js/JSDocumentCustom.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSDocument.h" + +#include "ExceptionCode.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLDocument.h" +#include "JSCanvasRenderingContext2D.h" +#if ENABLE(3D_CANVAS) +#include "JSWebGLRenderingContext.h" +#endif +#include "JSDOMWindowCustom.h" +#include "JSHTMLDocument.h" +#include "JSLocation.h" +#include "Location.h" +#include "ScriptController.h" + +#if ENABLE(SVG) +#include "JSSVGDocument.h" +#include "SVGDocument.h" +#endif + +#include <wtf/GetPtr.h> + +using namespace JSC; + +namespace WebCore { + +void JSDocument::markChildren(MarkStack& markStack) +{ + JSNode::markChildren(markStack); + + Document* document = impl(); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMNodesForDocument(markStack, document); + markActiveObjectsForContext(markStack, globalData, document); + markDOMObjectWrapper(markStack, globalData, document->implementation()); + markDOMObjectWrapper(markStack, globalData, document->styleSheets()); + document->markCachedNodeLists(markStack, globalData); +} + +JSValue JSDocument::location(ExecState* exec) const +{ + Frame* frame = static_cast<Document*>(impl())->frame(); + if (!frame) + return jsNull(); + + Location* location = frame->domWindow()->location(); + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, location)) + return wrapper; + + JSLocation* jsLocation = new (exec) JSLocation(getDOMStructure<JSLocation>(exec, globalObject()), globalObject(), location); + cacheDOMObjectWrapper(exec, location, jsLocation); + return jsLocation; +} + +void JSDocument::setLocation(ExecState* exec, JSValue value) +{ + Frame* frame = static_cast<Document*>(impl())->frame(); + if (!frame) + return; + + String str = ustringToString(value.toString(exec)); + + Frame* lexicalFrame = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame(); + + // IE and Mozilla both resolve the URL relative to the source frame, + // not the target frame. + Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); + str = activeFrame->document()->completeURL(str).string(); + + frame->navigationScheduler()->scheduleLocationChange(lexicalFrame->document()->securityOrigin(), + str, activeFrame->loader()->outgoingReferrer(), !activeFrame->script()->anyPageIsProcessingUserGesture(), false); +} + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Document* document) +{ + if (!document) + return jsNull(); + + DOMObject* wrapper = getCachedDOMNodeWrapper(exec, document, document); + if (wrapper) + return wrapper; + + if (document->isHTMLDocument()) + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, HTMLDocument, document); +#if ENABLE(SVG) + else if (document->isSVGDocument()) + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, SVGDocument, document); +#endif + else + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Document, document); + + // Make sure the document is kept around by the window object, and works right with the + // back/forward cache. + if (!document->frame()) { + size_t nodeCount = 0; + for (Node* n = document; n; n = n->traverseNextNode()) + nodeCount++; + + exec->heap()->reportExtraMemoryCost(nodeCount * sizeof(Node)); + } + + return wrapper; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSElementCustom.cpp b/Source/WebCore/bindings/js/JSElementCustom.cpp new file mode 100644 index 0000000..3bfe110 --- /dev/null +++ b/Source/WebCore/bindings/js/JSElementCustom.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "config.h" +#include "JSElement.h" + +#include "Document.h" +#include "ExceptionCode.h" +#include "HTMLFrameElementBase.h" +#include "HTMLNames.h" +#include "JSAttr.h" +#include "JSDOMBinding.h" +#include "JSHTMLElementWrapperFactory.h" +#include "JSNodeList.h" +#include "NodeList.h" + +#if ENABLE(SVG) +#include "JSSVGElementWrapperFactory.h" +#include "SVGElement.h" +#endif + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +void JSElement::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + Element* element = impl(); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMObjectWrapper(markStack, globalData, element->attributeMap()); + markDOMObjectWrapper(markStack, globalData, element->optionalClassList()); + markDOMObjectWrapper(markStack, globalData, element->optionalDataset()); + + if (element->isStyledElement()) + markDOMObjectWrapper(markStack, globalData, static_cast<StyledElement*>(element)->inlineStyleDecl()); +} + +JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Element* element) +{ + if (!element) + return jsNull(); + + ASSERT(!getCachedDOMNodeWrapper(exec, element->document(), element)); + + JSNode* wrapper; + if (element->isHTMLElement()) + wrapper = createJSHTMLWrapper(exec, globalObject, static_cast<HTMLElement*>(element)); +#if ENABLE(SVG) + else if (element->isSVGElement()) + wrapper = createJSSVGWrapper(exec, globalObject, static_cast<SVGElement*>(element)); +#endif + else + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Element, element); + + return wrapper; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSEntryCustom.cpp b/Source/WebCore/bindings/js/JSEntryCustom.cpp new file mode 100644 index 0000000..59d7e3c --- /dev/null +++ b/Source/WebCore/bindings/js/JSEntryCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(FILE_SYSTEM) + +#include "JSEntry.h" + +#include "Entry.h" +#include "JSDOMBinding.h" +#include "JSDirectoryEntry.h" +#include "JSFileEntry.h" +#include <wtf/Assertions.h> + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Entry* entry) +{ + if (!entry) + return jsNull(); + + if (entry->isFile()) + return getDOMObjectWrapper<JSFileEntry>(exec, globalObject, static_cast<FileEntry*>(entry)); + + ASSERT(entry->isDirectory()); + return getDOMObjectWrapper<JSDirectoryEntry>(exec, globalObject, static_cast<DirectoryEntry*>(entry)); +} + +} // namespace WebCore + +#endif // ENABLE(FILE_SYSTEM) diff --git a/Source/WebCore/bindings/js/JSEntrySyncCustom.cpp b/Source/WebCore/bindings/js/JSEntrySyncCustom.cpp new file mode 100644 index 0000000..22f96ad --- /dev/null +++ b/Source/WebCore/bindings/js/JSEntrySyncCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(FILE_SYSTEM) + +#include "JSEntrySync.h" + +#include "EntrySync.h" +#include "JSDOMBinding.h" +#include "JSDirectoryEntrySync.h" +#include "JSFileEntrySync.h" +#include <wtf/Assertions.h> + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EntrySync* entry) +{ + if (!entry) + return jsNull(); + + if (entry->isFile()) + return getDOMObjectWrapper<JSFileEntrySync>(exec, globalObject, static_cast<FileEntrySync*>(entry)); + + ASSERT(entry->isDirectory()); + return getDOMObjectWrapper<JSDirectoryEntrySync>(exec, globalObject, static_cast<DirectoryEntrySync*>(entry)); +} + +} // namespace WebCore + +#endif // ENABLE(FILE_SYSTEM) diff --git a/Source/WebCore/bindings/js/JSEventCustom.cpp b/Source/WebCore/bindings/js/JSEventCustom.cpp new file mode 100644 index 0000000..fd80360 --- /dev/null +++ b/Source/WebCore/bindings/js/JSEventCustom.cpp @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSEvent.h" + +#include "Clipboard.h" +#include "CompositionEvent.h" +#include "CustomEvent.h" +#include "DeviceMotionEvent.h" +#include "DeviceOrientationEvent.h" +#include "Event.h" +#include "JSBeforeLoadEvent.h" +#include "JSClipboard.h" +#include "JSCustomEvent.h" +#include "JSCompositionEvent.h" +#include "JSDeviceMotionEvent.h" +#include "JSDeviceOrientationEvent.h" +#include "JSErrorEvent.h" +#include "JSHashChangeEvent.h" +#include "JSKeyboardEvent.h" +#include "JSMessageEvent.h" +#include "JSMouseEvent.h" +#include "JSMutationEvent.h" +#include "JSOverflowEvent.h" +#include "JSPageTransitionEvent.h" +#include "JSPopStateEvent.h" +#include "JSProgressEvent.h" +#include "JSSpeechInputEvent.h" +#include "JSTextEvent.h" +#include "JSUIEvent.h" +#include "JSWebKitAnimationEvent.h" +#include "JSWebKitTransitionEvent.h" +#include "JSWheelEvent.h" +#include "JSXMLHttpRequestProgressEvent.h" +#include "BeforeLoadEvent.h" +#include "ErrorEvent.h" +#include "HashChangeEvent.h" +#include "KeyboardEvent.h" +#include "MessageEvent.h" +#include "MouseEvent.h" +#include "MutationEvent.h" +#include "OverflowEvent.h" +#include "PageTransitionEvent.h" +#include "PopStateEvent.h" +#include "ProgressEvent.h" +#include "SpeechInputEvent.h" +#include "TextEvent.h" +#include "UIEvent.h" +#include "WebKitAnimationEvent.h" +#include "WebKitTransitionEvent.h" +#include "WheelEvent.h" +#include "XMLHttpRequestProgressEvent.h" +#include <runtime/JSLock.h> + +#if ENABLE(DOM_STORAGE) +#include "JSStorageEvent.h" +#include "StorageEvent.h" +#endif + +#if ENABLE(SVG) +#include "JSSVGZoomEvent.h" +#include "SVGZoomEvent.h" +#endif + +#if ENABLE(TOUCH_EVENTS) +#include "JSTouchEvent.h" +#include "TouchEvent.h" +#endif + +#if ENABLE(INDEXED_DATABASE) +#include "IDBErrorEvent.h" +#include "IDBSuccessEvent.h" +#include "JSIDBErrorEvent.h" +#include "JSIDBSuccessEvent.h" +#endif + +#if ENABLE(WEB_AUDIO) +#include "AudioProcessingEvent.h" +#include "JSAudioProcessingEvent.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValue JSEvent::clipboardData(ExecState* exec) const +{ + return impl()->isClipboardEvent() ? toJS(exec, globalObject(), impl()->clipboardData()) : jsUndefined(); +} + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Event* event) +{ + JSLock lock(SilenceAssertionsOnly); + + if (!event) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec, event); + if (wrapper) + return wrapper; + + if (event->isUIEvent()) { + if (event->isKeyboardEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, KeyboardEvent, event); + else if (event->isTextEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TextEvent, event); + else if (event->isMouseEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MouseEvent, event); + else if (event->isWheelEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WheelEvent, event); +#if ENABLE(SVG) + else if (event->isSVGZoomEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGZoomEvent, event); +#endif + else if (event->isCompositionEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CompositionEvent, event); +#if ENABLE(TOUCH_EVENTS) + else if (event->isTouchEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TouchEvent, event); +#endif + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, UIEvent, event); + } else if (event->isMutationEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MutationEvent, event); + else if (event->isOverflowEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, OverflowEvent, event); + else if (event->isMessageEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MessageEvent, event); + else if (event->isPageTransitionEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, PageTransitionEvent, event); + else if (event->isProgressEvent()) { + if (event->isXMLHttpRequestProgressEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, XMLHttpRequestProgressEvent, event); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ProgressEvent, event); + } else if (event->isBeforeLoadEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, BeforeLoadEvent, event); +#if ENABLE(DOM_STORAGE) + else if (event->isStorageEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, StorageEvent, event); +#endif +#if ENABLE(INDEXED_DATABASE) + else if (event->isIDBErrorEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, IDBErrorEvent, event); + else if (event->isIDBSuccessEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, IDBSuccessEvent, event); +#endif + else if (event->isWebKitAnimationEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitAnimationEvent, event); + else if (event->isWebKitTransitionEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitTransitionEvent, event); +#if ENABLE(WORKERS) + else if (event->isErrorEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ErrorEvent, event); +#endif + else if (event->isHashChangeEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, HashChangeEvent, event); + else if (event->isPopStateEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, PopStateEvent, event); + else if (event->isCustomEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CustomEvent, event); +#if ENABLE(DEVICE_ORIENTATION) + else if (event->isDeviceMotionEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, DeviceMotionEvent, event); + else if (event->isDeviceOrientationEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, DeviceOrientationEvent, event); +#endif +#if ENABLE(WEB_AUDIO) + else if (event->isAudioProcessingEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, AudioProcessingEvent, event); +#endif +#if ENABLE(INPUT_SPEECH) + else if (event->isSpeechInputEvent()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SpeechInputEvent, event); +#endif + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, Event, event); + + return wrapper; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSEventListener.cpp b/Source/WebCore/bindings/js/JSEventListener.cpp new file mode 100644 index 0000000..5604374 --- /dev/null +++ b/Source/WebCore/bindings/js/JSEventListener.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSEventListener.h" + +#include "Event.h" +#include "Frame.h" +#include "JSEvent.h" +#include "JSEventTarget.h" +#include "JSMainThreadExecState.h" +#include <runtime/JSLock.h> +#include <wtf/RefCountedLeakCounter.h> + +using namespace JSC; + +namespace WebCore { + +JSEventListener::JSEventListener(JSObject* function, JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld) + : EventListener(JSEventListenerType) + , m_jsFunction(function) + , m_isAttribute(isAttribute) + , m_isolatedWorld(isolatedWorld) +{ + if (wrapper) + m_wrapper = wrapper; +} + +JSEventListener::~JSEventListener() +{ +} + +JSObject* JSEventListener::initializeJSFunction(ScriptExecutionContext*) const +{ + ASSERT_NOT_REACHED(); + return 0; +} + +void JSEventListener::markJSFunction(MarkStack& markStack) +{ + if (m_jsFunction) + markStack.append(m_jsFunction); +} + +void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event) +{ + ASSERT(scriptExecutionContext); + if (!scriptExecutionContext || scriptExecutionContext->isJSExecutionTerminated()) + return; + + JSLock lock(SilenceAssertionsOnly); + + JSObject* jsFunction = this->jsFunction(scriptExecutionContext); + if (!jsFunction) + return; + + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, m_isolatedWorld.get()); + if (!globalObject) + return; + + if (scriptExecutionContext->isDocument()) { + JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject); + Frame* frame = window->impl()->frame(); + if (!frame) + return; + // The window must still be active in its frame. See <https://bugs.webkit.org/show_bug.cgi?id=21921>. + // FIXME: A better fix for this may be to change DOMWindow::frame() to not return a frame the detached window used to be in. + if (frame->domWindow() != window->impl()) + return; + // FIXME: Is this check needed for other contexts? + ScriptController* script = frame->script(); + if (!script->canExecuteScripts(AboutToExecuteScript) || script->isPaused()) + return; + } + + ExecState* exec = globalObject->globalExec(); + JSValue handleEventFunction = jsFunction->get(exec, Identifier(exec, "handleEvent")); + + CallData callData; + CallType callType = getCallData(handleEventFunction, callData); + if (callType == CallTypeNone) { + handleEventFunction = JSValue(); + callType = jsFunction->getCallData(callData); + } + + if (callType != CallTypeNone) { + ref(); + + MarkedArgumentBuffer args; + args.append(toJS(exec, globalObject, event)); + + Event* savedEvent = globalObject->currentEvent(); + globalObject->setCurrentEvent(event); + + JSGlobalData& globalData = globalObject->globalData(); + DynamicGlobalObjectScope globalObjectScope(exec, globalData.dynamicGlobalObject ? globalData.dynamicGlobalObject : globalObject); + + globalData.timeoutChecker.start(); + JSValue retval; + if (handleEventFunction) { + retval = scriptExecutionContext->isDocument() + ? JSMainThreadExecState::call(exec, handleEventFunction, callType, callData, jsFunction, args) + : JSC::call(exec, handleEventFunction, callType, callData, jsFunction, args); + } else { + JSValue currentTarget = toJS(exec, globalObject, event->currentTarget()); + retval = scriptExecutionContext->isDocument() + ? JSMainThreadExecState::call(exec, jsFunction, callType, callData, currentTarget, args) + : JSC::call(exec, jsFunction, callType, callData, currentTarget, args); + } + globalData.timeoutChecker.stop(); + + globalObject->setCurrentEvent(savedEvent); + + if (exec->hadException()) + reportCurrentException(exec); + else { + if (!retval.isUndefinedOrNull() && event->storesResultAsString()) + event->storeResult(ustringToString(retval.toString(exec))); + if (m_isAttribute) { + bool retvalbool; + if (retval.getBoolean(retvalbool) && !retvalbool) + event->preventDefault(); + } + } + + deref(); + } +} + +bool JSEventListener::virtualisAttribute() const +{ + return m_isAttribute; +} + +bool JSEventListener::operator==(const EventListener& listener) +{ + if (const JSEventListener* jsEventListener = JSEventListener::cast(&listener)) + return m_jsFunction == jsEventListener->m_jsFunction && m_isAttribute == jsEventListener->m_isAttribute; + return false; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSEventListener.h b/Source/WebCore/bindings/js/JSEventListener.h new file mode 100644 index 0000000..b15c589 --- /dev/null +++ b/Source/WebCore/bindings/js/JSEventListener.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSEventListener_h +#define JSEventListener_h + +#include "EventListener.h" +#include "JSDOMWindow.h" +#include <runtime/WeakGCPtr.h> + +namespace WebCore { + + class JSDOMGlobalObject; + + class JSEventListener : public EventListener { + public: + static PassRefPtr<JSEventListener> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld) + { + return adoptRef(new JSEventListener(listener, wrapper, isAttribute, isolatedWorld)); + } + + static const JSEventListener* cast(const EventListener* listener) + { + return listener->type() == JSEventListenerType + ? static_cast<const JSEventListener*>(listener) + : 0; + } + + virtual ~JSEventListener(); + + virtual bool operator==(const EventListener& other); + + // Returns true if this event listener was created for an event handler attribute, like "onload" or "onclick". + bool isAttribute() const { return m_isAttribute; } + + JSC::JSObject* jsFunction(ScriptExecutionContext*) const; + DOMWrapperWorld* isolatedWorld() const { return m_isolatedWorld.get(); } + + JSC::JSObject* wrapper() const { return m_wrapper.get(); } + void setWrapper(JSC::JSObject* wrapper) const { m_wrapper = wrapper; } + + private: + virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const; + virtual void markJSFunction(JSC::MarkStack&); + virtual void invalidateJSFunction(JSC::JSObject*); + virtual void handleEvent(ScriptExecutionContext*, Event*); + virtual bool virtualisAttribute() const; + + protected: + JSEventListener(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld); + + private: + mutable JSC::JSObject* m_jsFunction; + mutable JSC::WeakGCPtr<JSC::JSObject> m_wrapper; + + bool m_isAttribute; + RefPtr<DOMWrapperWorld> m_isolatedWorld; + }; + + inline JSC::JSObject* JSEventListener::jsFunction(ScriptExecutionContext* scriptExecutionContext) const + { + if (!m_jsFunction) + m_jsFunction = initializeJSFunction(scriptExecutionContext); + + // Verify that we have a valid wrapper protecting our function from + // garbage collection. + ASSERT(m_wrapper || !m_jsFunction); + if (!m_wrapper) + return 0; + + // Try to verify that m_jsFunction wasn't recycled. (Not exact, since an + // event listener can be almost anything, but this makes test-writing easier). + ASSERT(!m_jsFunction || static_cast<JSC::JSCell*>(m_jsFunction)->isObject()); + + return m_jsFunction; + } + + inline void JSEventListener::invalidateJSFunction(JSC::JSObject* wrapper) + { + m_wrapper.clear(wrapper); + } + + // Creates a JS EventListener for an "onXXX" event attribute. + inline PassRefPtr<JSEventListener> createJSAttributeEventListener(JSC::ExecState* exec, JSC::JSValue listener, JSC::JSObject* wrapper) + { + if (!listener.isObject()) + return 0; + + return JSEventListener::create(asObject(listener), wrapper, true, currentWorld(exec)); + } + + +} // namespace WebCore + +#endif // JSEventListener_h diff --git a/Source/WebCore/bindings/js/JSEventSourceCustom.cpp b/Source/WebCore/bindings/js/JSEventSourceCustom.cpp new file mode 100644 index 0000000..aa991dd --- /dev/null +++ b/Source/WebCore/bindings/js/JSEventSourceCustom.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2009 Ericsson AB. All rights reserved. + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Ericsson nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(EVENTSOURCE) + +#include "JSEventSource.h" + +#include "EventSource.h" +#include "ExceptionCode.h" +#include "ScriptExecutionContext.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +EncodedJSValue JSC_HOST_CALL JSEventSourceConstructor::constructJSEventSource(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); + + UString url = exec->argument(0).toString(exec); + if (exec->hadException()) + return JSValue::encode(JSValue()); + + JSEventSourceConstructor* jsConstructor = static_cast<JSEventSourceConstructor*>(exec->callee()); + ScriptExecutionContext* context = jsConstructor->scriptExecutionContext(); + if (!context) + return throwVMError(exec, createReferenceError(exec, "EventSource constructor associated document is unavailable")); + + ExceptionCode ec = 0; + RefPtr<EventSource> eventSource = EventSource::create(ustringToString(url), context, ec); + if (ec) { + setDOMException(exec, ec); + return JSValue::encode(JSValue()); + } + + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), eventSource.release()))); +} + +} // namespace WebCore + +#endif // ENABLE(EVENTSOURCE) diff --git a/Source/WebCore/bindings/js/JSEventTarget.cpp b/Source/WebCore/bindings/js/JSEventTarget.cpp new file mode 100644 index 0000000..04be175 --- /dev/null +++ b/Source/WebCore/bindings/js/JSEventTarget.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSEventTarget.h" + +#include "DOMWindow.h" +#include "Document.h" +#include "JSDOMWindow.h" +#include "JSDOMWindowShell.h" +#include "JSEventListener.h" +#include "JSMessagePort.h" +#include "JSNode.h" +#if ENABLE(SHARED_WORKERS) + +#include "JSSharedWorker.h" +#include "JSSharedWorkerContext.h" +#endif + +#include "JSXMLHttpRequest.h" +#include "JSXMLHttpRequestUpload.h" +#include "MessagePort.h" + +#if ENABLE(SHARED_WORKERS) +#include "SharedWorker.h" +#include "SharedWorkerContext.h" +#endif + +#include "XMLHttpRequest.h" +#include "XMLHttpRequestUpload.h" + +#if ENABLE(EVENTSOURCE) +#include "EventSource.h" +#include "JSEventSource.h" +#endif + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) +#include "DOMApplicationCache.h" +#include "JSDOMApplicationCache.h" +#endif + +#if ENABLE(SVG) +#include "SVGElementInstance.h" +#include "JSSVGElementInstance.h" +#endif + +#if ENABLE(WORKERS) +#include "DedicatedWorkerContext.h" +#include "JSDedicatedWorkerContext.h" +#include "JSWorker.h" +#include "Worker.h" +#endif + +#if ENABLE(NOTIFICATIONS) +#include "JSNotification.h" +#include "Notification.h" +#endif + +#if ENABLE(INDEXED_DATABASE) +#include "IDBRequest.h" +#include "JSIDBRequest.h" +#endif + +#if ENABLE(WEB_AUDIO) +#include "JSJavaScriptAudioNode.h" +#include "JavaScriptAudioNode.h" +#endif + +#if ENABLE(WEB_SOCKETS) +#include "JSWebSocket.h" +#include "WebSocket.h" +#endif + +#if ENABLE(BLOB) +#include "JSFileReader.h" +#include "FileReader.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, EventTarget* target) +{ + if (!target) + return jsNull(); + +#if ENABLE(EVENTSOURCE) + if (EventSource* eventSource = target->toEventSource()) + return toJS(exec, globalObject, eventSource); +#endif + +#if ENABLE(SVG) + // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node. + if (SVGElementInstance* instance = target->toSVGElementInstance()) + return toJS(exec, globalObject, instance); +#endif + + if (Node* node = target->toNode()) + return toJS(exec, globalObject, node); + + if (DOMWindow* domWindow = target->toDOMWindow()) + return toJS(exec, globalObject, domWindow); + + if (XMLHttpRequest* xhr = target->toXMLHttpRequest()) + return toJS(exec, globalObject, xhr); + + if (XMLHttpRequestUpload* upload = target->toXMLHttpRequestUpload()) + return toJS(exec, globalObject, upload); + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + if (DOMApplicationCache* cache = target->toDOMApplicationCache()) + return toJS(exec, globalObject, cache); +#endif + + if (MessagePort* messagePort = target->toMessagePort()) + return toJS(exec, globalObject, messagePort); + +#if ENABLE(WORKERS) + if (Worker* worker = target->toWorker()) + return toJS(exec, globalObject, worker); + + if (DedicatedWorkerContext* workerContext = target->toDedicatedWorkerContext()) + return toJSDOMGlobalObject(workerContext, exec); +#endif + +#if ENABLE(SHARED_WORKERS) + if (SharedWorker* sharedWorker = target->toSharedWorker()) + return toJS(exec, globalObject, sharedWorker); + + if (SharedWorkerContext* workerContext = target->toSharedWorkerContext()) + return toJSDOMGlobalObject(workerContext, exec); +#endif + +#if ENABLE(NOTIFICATIONS) + if (Notification* notification = target->toNotification()) + return toJS(exec, notification); +#endif + +#if ENABLE(INDEXED_DATABASE) + if (IDBRequest* idbRequest = target->toIDBRequest()) + return toJS(exec, idbRequest); +#endif + +#if ENABLE(WEB_AUDIO) + if (JavaScriptAudioNode* jsAudioNode = target->toJavaScriptAudioNode()) + return toJS(exec, globalObject, jsAudioNode); +#endif + +#if ENABLE(WEB_SOCKETS) + if (WebSocket* webSocket = target->toWebSocket()) + return toJS(exec, webSocket); +#endif + +#if ENABLE(BLOB) + if (FileReader* fileReader = target->toFileReader()) + return toJS(exec, globalObject, fileReader); +#endif + + ASSERT_NOT_REACHED(); + return jsNull(); +} + +EventTarget* toEventTarget(JSC::JSValue value) +{ + #define CONVERT_TO_EVENT_TARGET(type) \ + if (value.inherits(&JS##type::s_info)) \ + return static_cast<JS##type*>(asObject(value))->impl(); + + CONVERT_TO_EVENT_TARGET(Node) + CONVERT_TO_EVENT_TARGET(XMLHttpRequest) + CONVERT_TO_EVENT_TARGET(XMLHttpRequestUpload) + CONVERT_TO_EVENT_TARGET(MessagePort) + + if (value.inherits(&JSDOMWindowShell::s_info)) + return static_cast<JSDOMWindowShell*>(asObject(value))->impl(); + +#if ENABLE(EVENTSOURCE) + CONVERT_TO_EVENT_TARGET(EventSource) +#endif + +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + CONVERT_TO_EVENT_TARGET(DOMApplicationCache) +#endif + +#if ENABLE(SVG) + CONVERT_TO_EVENT_TARGET(SVGElementInstance) +#endif + +#if ENABLE(WORKERS) + CONVERT_TO_EVENT_TARGET(Worker) + CONVERT_TO_EVENT_TARGET(DedicatedWorkerContext) +#endif + +#if ENABLE(SHARED_WORKERS) + CONVERT_TO_EVENT_TARGET(SharedWorker) + CONVERT_TO_EVENT_TARGET(SharedWorkerContext) +#endif + +#if ENABLE(NOTIFICATIONS) + CONVERT_TO_EVENT_TARGET(Notification) +#endif + +#if ENABLE(WEB_SOCKETS) + CONVERT_TO_EVENT_TARGET(WebSocket) +#endif + + return 0; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSEventTarget.h b/Source/WebCore/bindings/js/JSEventTarget.h new file mode 100644 index 0000000..ddd8232 --- /dev/null +++ b/Source/WebCore/bindings/js/JSEventTarget.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSEventTarget_h +#define JSEventTarget_h + +#include <runtime/JSValue.h> + +namespace JSC { + class ExecState; +} + +namespace WebCore { + + class EventTarget; + class JSDOMGlobalObject; + + JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, EventTarget*); + EventTarget* toEventTarget(JSC::JSValue); + +} // namespace WebCore + +#endif // JSEventTarget_h diff --git a/Source/WebCore/bindings/js/JSExceptionBase.cpp b/Source/WebCore/bindings/js/JSExceptionBase.cpp new file mode 100644 index 0000000..44b38ec --- /dev/null +++ b/Source/WebCore/bindings/js/JSExceptionBase.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSExceptionBase.h" + +#include "JSDOMCoreException.h" +#include "JSEventException.h" +#include "JSRangeException.h" +#include "JSXMLHttpRequestException.h" +#if ENABLE(DATABASE) +#include "SQLException.h" +#include "JSSQLException.h" +#endif +#if ENABLE(SVG) +#include "JSSVGException.h" +#endif +#if ENABLE(XPATH) +#include "JSXPathException.h" +#endif + +namespace WebCore { + +ExceptionBase* toExceptionBase(JSC::JSValue value) +{ + if (DOMCoreException* domException = toDOMCoreException(value)) + return reinterpret_cast<ExceptionBase*>(domException); + if (RangeException* rangeException = toRangeException(value)) + return reinterpret_cast<ExceptionBase*>(rangeException); + if (EventException* eventException = toEventException(value)) + return reinterpret_cast<ExceptionBase*>(eventException); + if (XMLHttpRequestException* xmlHttpException = toXMLHttpRequestException(value)) + return reinterpret_cast<ExceptionBase*>(xmlHttpException); +#if ENABLE(SVG) + if (SVGException* svgException = toSVGException(value)) + return reinterpret_cast<ExceptionBase*>(svgException); +#endif +#if ENABLE(XPATH) + if (XPathException* pathException = toXPathException(value)) + return reinterpret_cast<ExceptionBase*>(pathException); +#endif +#if ENABLE(DATABASE) + if (SQLException* pathException = toSQLException(value)) + return reinterpret_cast<ExceptionBase*>(pathException); +#endif + + return 0; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSExceptionBase.h b/Source/WebCore/bindings/js/JSExceptionBase.h new file mode 100644 index 0000000..01c6ac2 --- /dev/null +++ b/Source/WebCore/bindings/js/JSExceptionBase.h @@ -0,0 +1,43 @@ +/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSExceptionBase_h
+#define JSExceptionBase_h
+
+namespace JSC {
+
+class JSValue;
+
+} // namespace JSC
+
+namespace WebCore {
+
+class ExceptionBase;
+
+ExceptionBase* toExceptionBase(JSC::JSValue);
+
+} // namespace WebCore
+
+#endif // JSExceptionBase_h
diff --git a/Source/WebCore/bindings/js/JSFileReaderCustom.cpp b/Source/WebCore/bindings/js/JSFileReaderCustom.cpp new file mode 100644 index 0000000..c771b63 --- /dev/null +++ b/Source/WebCore/bindings/js/JSFileReaderCustom.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(BLOB) + +#include "JSFileReader.h" + +#include "ArrayBuffer.h" +#include "FileReader.h" +#include "JSArrayBuffer.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSFileReader::result(ExecState* exec) const +{ + FileReader* imp = impl(); + if (imp->readType() == FileReaderLoader::ReadAsArrayBuffer) + return toJS(exec, globalObject(), WTF::getPtr(imp->arrayBufferResult())); + return jsOwnedStringOrNull(exec, imp->stringResult()); +} + +} // namespace WebCore + +#endif // ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSFloat32ArrayCustom.cpp b/Source/WebCore/bindings/js/JSFloat32ArrayCustom.cpp new file mode 100644 index 0000000..880d68c --- /dev/null +++ b/Source/WebCore/bindings/js/JSFloat32ArrayCustom.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSFloat32Array.h" + +#include "Float32Array.h" +#include "JSArrayBufferViewHelper.h" + +using namespace JSC; + +namespace WebCore { + +void JSFloat32Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<float>(value.toNumber(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Float32Array* object) +{ + return getDOMObjectWrapper<JSFloat32Array>(exec, globalObject, object); +} + +JSC::JSValue JSFloat32Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toFloat32Array); +} + +EncodedJSValue JSC_HOST_CALL JSFloat32ArrayConstructor::constructJSFloat32Array(ExecState* exec) +{ + JSFloat32ArrayConstructor* jsConstructor = static_cast<JSFloat32ArrayConstructor*>(exec->callee()); + RefPtr<Float32Array> array = constructArrayBufferView<Float32Array, float>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSGeolocationCustom.cpp b/Source/WebCore/bindings/js/JSGeolocationCustom.cpp new file mode 100644 index 0000000..1e40f86 --- /dev/null +++ b/Source/WebCore/bindings/js/JSGeolocationCustom.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSGeolocation.h" + +#if ENABLE(GEOLOCATION) + +#include "DOMWindow.h" +#include "ExceptionCode.h" +#include "Geolocation.h" +#include "JSCustomPositionCallback.h" +#include "JSCustomPositionErrorCallback.h" +#include "JSDOMWindow.h" +#include "PositionOptions.h" +#include <runtime/JSFunction.h> + +#if !ENABLE(CLIENT_BASED_GEOLOCATION) +#include "GeolocationService.h" +#endif + +using namespace JSC; +using namespace std; + +namespace WebCore { + +static PassRefPtr<PositionCallback> createPositionCallback(ExecState* exec, JSDOMGlobalObject* globalObject, JSValue value) +{ + // The spec specifies 'FunctionOnly' for this object. + // FIXME: This check disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow. + if (!value.inherits(&JSFunction::info)) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return 0; + } + + JSObject* object = asObject(value); + return JSCustomPositionCallback::create(object, globalObject); +} + +static PassRefPtr<PositionErrorCallback> createPositionErrorCallback(ExecState* exec, JSDOMGlobalObject* globalObject, JSValue value) +{ + // Argument is optional (hence undefined is allowed), and null is allowed. + if (value.isUndefinedOrNull()) + return 0; + + // The spec specifies 'FunctionOnly' for this object. + // FIXME: This check disallows callable objects created via JSC API. It's not clear what exactly the specification intends to allow. + if (!value.inherits(&JSFunction::info)) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return 0; + } + + JSObject* object = asObject(value); + return JSCustomPositionErrorCallback::create(object, globalObject); +} + +static PassRefPtr<PositionOptions> createPositionOptions(ExecState* exec, JSValue value) +{ + // Create default options. + RefPtr<PositionOptions> options = PositionOptions::create(); + + // Argument is optional (hence undefined is allowed), and null is allowed. + if (value.isUndefinedOrNull()) { + // Use default options. + return options.release(); + } + + // Given the above test, this will always yield an object. + JSObject* object = value.toObject(exec); + + // For all three properties, we apply the following ... + // - If the getter or the property's valueOf method throws an exception, we + // quit so as not to risk overwriting the exception. + // - If the value is absent or undefined, we don't override the default. + JSValue enableHighAccuracyValue = object->get(exec, Identifier(exec, "enableHighAccuracy")); + if (exec->hadException()) + return 0; + if (!enableHighAccuracyValue.isUndefined()) { + options->setEnableHighAccuracy(enableHighAccuracyValue.toBoolean(exec)); + if (exec->hadException()) + return 0; + } + + JSValue timeoutValue = object->get(exec, Identifier(exec, "timeout")); + if (exec->hadException()) + return 0; + if (!timeoutValue.isUndefined()) { + double timeoutNumber = timeoutValue.toNumber(exec); + if (exec->hadException()) + return 0; + // If the value is positive infinity, there's nothing to do. + if (!(isinf(timeoutNumber) && (timeoutNumber > 0))) { + // Wrap to int32 and force non-negative to match behavior of window.setTimeout. + options->setTimeout(max(0, timeoutValue.toInt32(exec))); + if (exec->hadException()) + return 0; + } + } + + JSValue maximumAgeValue = object->get(exec, Identifier(exec, "maximumAge")); + if (exec->hadException()) + return 0; + if (!maximumAgeValue.isUndefined()) { + double maximumAgeNumber = maximumAgeValue.toNumber(exec); + if (exec->hadException()) + return 0; + if (isinf(maximumAgeNumber) && (maximumAgeNumber > 0)) { + // If the value is positive infinity, clear maximumAge. + options->clearMaximumAge(); + } else { + // Wrap to int32 and force non-negative to match behavior of window.setTimeout. + options->setMaximumAge(max(0, maximumAgeValue.toInt32(exec))); + if (exec->hadException()) + return 0; + } + } + + return options.release(); +} + +JSValue JSGeolocation::getCurrentPosition(ExecState* exec) +{ + // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions + + RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + ASSERT(positionCallback); + + RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<PositionOptions> positionOptions = createPositionOptions(exec, exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + ASSERT(positionOptions); + + m_impl->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release()); + return jsUndefined(); +} + +JSValue JSGeolocation::watchPosition(ExecState* exec) +{ + // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions + + RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + ASSERT(positionCallback); + + RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<PositionOptions> positionOptions = createPositionOptions(exec, exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + ASSERT(positionOptions); + + int watchID = m_impl->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release()); + return jsNumber(watchID); +} + +} // namespace WebCore + +#endif // ENABLE(GEOLOCATION) diff --git a/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp b/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp new file mode 100644 index 0000000..64615b9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLAllCollection.h" + +#include "HTMLAllCollection.h" +#include "JSDOMBinding.h" +#include "JSHTMLAllCollection.h" +#include "JSNode.h" +#include "JSNodeList.h" +#include "Node.h" +#include "StaticNodeList.h" +#include <runtime/JSValue.h> +#include <wtf/Vector.h> +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +static JSValue getNamedItems(ExecState* exec, JSHTMLAllCollection* collection, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + collection->impl()->namedItems(identifierToAtomicString(propertyName), namedItems); + + if (namedItems.isEmpty()) + return jsUndefined(); + if (namedItems.size() == 1) + return toJS(exec, collection->globalObject(), namedItems[0].get()); + + // FIXME: HTML5 specifies that this should be a DynamicNodeList. + // FIXME: HTML5 specifies that non-HTMLOptionsCollection collections should return + // the first matching item instead of a NodeList. + return toJS(exec, collection->globalObject(), StaticNodeList::adopt(namedItems).get()); +} + +// HTMLCollections are strange objects, they support both get and call, +// so that document.forms.item(0) and document.forms(0) both work. +static EncodedJSValue JSC_HOST_CALL callHTMLAllCollection(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return JSValue::encode(jsUndefined()); + + // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case. + JSHTMLAllCollection* jsCollection = static_cast<JSHTMLAllCollection*>(exec->callee()); + HTMLAllCollection* collection = static_cast<HTMLAllCollection*>(jsCollection->impl()); + + // Also, do we need the TypeError test here ? + + if (exec->argumentCount() == 1) { + // Support for document.all(<index>) etc. + bool ok; + UString string = exec->argument(0).toString(exec); + unsigned index = Identifier::toUInt32(string, ok); + if (ok) + return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection->item(index))); + + // Support for document.images('<name>') etc. + return JSValue::encode(getNamedItems(exec, jsCollection, Identifier(exec, string))); + } + + // The second arg, if set, is the index of the item we want + bool ok; + UString string = exec->argument(0).toString(exec); + unsigned index = Identifier::toUInt32(exec->argument(1).toString(exec), ok); + if (ok) { + String pstr = ustringToString(string); + Node* node = collection->namedItem(pstr); + while (node) { + if (!index) + return JSValue::encode(toJS(exec, jsCollection->globalObject(), node)); + node = collection->nextNamedItem(pstr); + --index; + } + } + + return JSValue::encode(jsUndefined()); +} + +CallType JSHTMLAllCollection::getCallData(CallData& callData) +{ + callData.native.function = callHTMLAllCollection; + return CallTypeHost; +} + +bool JSHTMLAllCollection::canGetItemsForName(ExecState*, HTMLAllCollection* collection, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + collection->namedItems(identifierToAtomicString(propertyName), namedItems); + return !namedItems.isEmpty(); +} + +JSValue JSHTMLAllCollection::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSHTMLAllCollection* thisObj = static_cast<JSHTMLAllCollection*>(asObject(slotBase)); + return getNamedItems(exec, thisObj, propertyName); +} + +JSValue JSHTMLAllCollection::item(ExecState* exec) +{ + bool ok; + uint32_t index = Identifier::toUInt32(exec->argument(0).toString(exec), ok); + if (ok) + return toJS(exec, globalObject(), impl()->item(index)); + return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec))); +} + +JSValue JSHTMLAllCollection::namedItem(ExecState* exec) +{ + return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp new file mode 100644 index 0000000..2bff01a --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLAppletElementCustom.h" + +#include "HTMLAppletElement.h" +#include "JSPluginElementFunctions.h" + +namespace WebCore { + +using namespace JSC; + +bool JSHTMLAppletElement::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this); +} + +bool JSHTMLAppletElement::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + return runtimeObjectCustomGetOwnPropertyDescriptor(exec, propertyName, descriptor, this); +} + +bool JSHTMLAppletElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + return runtimeObjectCustomPut(exec, propertyName, value, this, slot); +} + +CallType JSHTMLAppletElement::getCallData(CallData& callData) +{ + return runtimeObjectGetCallData(this, callData); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLAppletElementCustom.h b/Source/WebCore/bindings/js/JSHTMLAppletElementCustom.h new file mode 100644 index 0000000..5df9a66 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLAppletElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSHTMLAppletElementCustom_h +#define JSHTMLAppletElementCustom_h + +#include "JSHTMLAppletElement.h" + +#endif // JSHTMLAppletElementCustom_h diff --git a/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp new file mode 100644 index 0000000..ae9115e --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLCanvasElement.h" + +#include "CanvasContextAttributes.h" +#include "HTMLCanvasElement.h" +#include "JSCanvasRenderingContext2D.h" +#if ENABLE(3D_CANVAS) +#include "JSWebGLRenderingContext.h" +#include "WebGLContextAttributes.h" +#endif +#include <wtf/GetPtr.h> + +using namespace JSC; + +namespace WebCore { + +void JSHTMLCanvasElement::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMObjectWrapper(markStack, globalData, canvas->renderingContext()); +} + +JSValue JSHTMLCanvasElement::getContext(ExecState* exec) +{ + HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); + const UString& contextId = exec->argument(0).toString(exec); + RefPtr<CanvasContextAttributes> attrs; +#if ENABLE(3D_CANVAS) + if (contextId == "experimental-webgl" || contextId == "webkit-3d") { + attrs = WebGLContextAttributes::create(); + WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*>(attrs.get()); + if (exec->argumentCount() > 1 && exec->argument(1).isObject()) { + JSObject* jsAttrs = exec->argument(1).getObject(); + Identifier alpha(exec, "alpha"); + if (jsAttrs->hasProperty(exec, alpha)) + webGLAttrs->setAlpha(jsAttrs->get(exec, alpha).toBoolean(exec)); + Identifier depth(exec, "depth"); + if (jsAttrs->hasProperty(exec, depth)) + webGLAttrs->setDepth(jsAttrs->get(exec, depth).toBoolean(exec)); + Identifier stencil(exec, "stencil"); + if (jsAttrs->hasProperty(exec, stencil)) + webGLAttrs->setStencil(jsAttrs->get(exec, stencil).toBoolean(exec)); + Identifier antialias(exec, "antialias"); + if (jsAttrs->hasProperty(exec, antialias)) + webGLAttrs->setAntialias(jsAttrs->get(exec, antialias).toBoolean(exec)); + Identifier premultipliedAlpha(exec, "premultipliedAlpha"); + if (jsAttrs->hasProperty(exec, premultipliedAlpha)) + webGLAttrs->setPremultipliedAlpha(jsAttrs->get(exec, premultipliedAlpha).toBoolean(exec)); + } + } +#endif + CanvasRenderingContext* context = canvas->getContext(ustringToString(contextId), attrs.get()); + if (!context) + return jsNull(); + return toJS(exec, globalObject(), WTF::getPtr(context)); +} + +JSValue JSHTMLCanvasElement::toDataURL(ExecState* exec) +{ + const String& type = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0)); + HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl()); + ExceptionCode ec = 0; + + JSC::JSValue result; + double quality; + double* qualityPtr = 0; + if (exec->argumentCount() > 1) { + JSValue v = exec->argument(1); + if (v.isNumber()) { + quality = v.toNumber(exec); + qualityPtr = &quality; + } + } + + result = jsString(exec, canvas->toDataURL(type, qualityPtr, ec)); + setDOMException(exec, ec); + return result; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp b/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp new file mode 100644 index 0000000..6b2f350 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLCollectionCustom.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSHTMLCollection.h" + +#include "HTMLCollection.h" +#include "HTMLOptionsCollection.h" +#include "HTMLAllCollection.h" +#include "JSDOMBinding.h" +#include "JSHTMLAllCollection.h" +#include "JSHTMLOptionsCollection.h" +#include "JSNode.h" +#include "JSNodeList.h" +#include "Node.h" +#include "StaticNodeList.h" +#include <wtf/Vector.h> +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +static JSValue getNamedItems(ExecState* exec, JSHTMLCollection* collection, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + collection->impl()->namedItems(identifierToAtomicString(propertyName), namedItems); + + if (namedItems.isEmpty()) + return jsUndefined(); + if (namedItems.size() == 1) + return toJS(exec, collection->globalObject(), namedItems[0].get()); + + // FIXME: HTML5 specifies that this should be a DynamicNodeList. + // FIXME: HTML5 specifies that non-HTMLOptionsCollection collections should return + // the first matching item instead of a NodeList. + return toJS(exec, collection->globalObject(), StaticNodeList::adopt(namedItems).get()); +} + +// HTMLCollections are strange objects, they support both get and call, +// so that document.forms.item(0) and document.forms(0) both work. +static EncodedJSValue JSC_HOST_CALL callHTMLCollection(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return JSValue::encode(jsUndefined()); + + // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case. + JSHTMLCollection* jsCollection = static_cast<JSHTMLCollection*>(exec->callee()); + HTMLCollection* collection = jsCollection->impl(); + + // Also, do we need the TypeError test here ? + + if (exec->argumentCount() == 1) { + // Support for document.all(<index>) etc. + bool ok; + UString string = exec->argument(0).toString(exec); + unsigned index = Identifier::toUInt32(string, ok); + if (ok) + return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection->item(index))); + + // Support for document.images('<name>') etc. + return JSValue::encode(getNamedItems(exec, jsCollection, Identifier(exec, string))); + } + + // The second arg, if set, is the index of the item we want + bool ok; + UString string = exec->argument(0).toString(exec); + unsigned index = Identifier::toUInt32(exec->argument(1).toString(exec), ok); + if (ok) { + String pstr = ustringToString(string); + Node* node = collection->namedItem(pstr); + while (node) { + if (!index) + return JSValue::encode(toJS(exec, jsCollection->globalObject(), node)); + node = collection->nextNamedItem(pstr); + --index; + } + } + + return JSValue::encode(jsUndefined()); +} + +CallType JSHTMLCollection::getCallData(CallData& callData) +{ + callData.native.function = callHTMLCollection; + return CallTypeHost; +} + +bool JSHTMLCollection::canGetItemsForName(ExecState*, HTMLCollection* collection, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + collection->namedItems(identifierToAtomicString(propertyName), namedItems); + return !namedItems.isEmpty(); +} + +JSValue JSHTMLCollection::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSHTMLCollection* thisObj = static_cast<JSHTMLCollection*>(asObject(slotBase)); + return getNamedItems(exec, thisObj, propertyName); +} + +JSValue JSHTMLCollection::item(ExecState* exec) +{ + bool ok; + uint32_t index = Identifier::toUInt32(exec->argument(0).toString(exec), ok); + if (ok) + return toJS(exec, globalObject(), impl()->item(index)); + return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec))); +} + +JSValue JSHTMLCollection::namedItem(ExecState* exec) +{ + return getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec))); +} + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, HTMLCollection* collection) +{ + if (!collection) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec, collection); + + if (wrapper) + return wrapper; + + switch (collection->type()) { + case SelectOptions: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, HTMLOptionsCollection, collection); + break; + case DocAll: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, HTMLAllCollection, collection); + break; + default: + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, HTMLCollection, collection); + break; + } + + return wrapper; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLDataGridElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLDataGridElementCustom.cpp new file mode 100644 index 0000000..a30f5e4 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLDataGridElementCustom.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(DATAGRID) + +#include "JSHTMLDataGridElement.h" + +#include "Document.h" +#include "HTMLDataGridElement.h" +#include "JSDataGridDataSource.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSHTMLDataGridElement::dataSource(ExecState*) const +{ + DataGridDataSource* dataSource = static_cast<HTMLDataGridElement*>(impl())->dataSource(); + if (dataSource && dataSource->isJSDataGridDataSource()) + return asJSDataGridDataSource(dataSource)->jsDataSource(); + return jsNull(); +} + +void JSHTMLDataGridElement::setDataSource(ExecState*, JSValue value) +{ + if (value.isNull()) { + static_cast<HTMLDataGridElement*>(impl())->setDataSource(0); + return; + } + + static_cast<HTMLDataGridElement*>(impl())->setDataSource(JSDataGridDataSource::create(value, impl()->document()->frame())); +} + +} // namespace WebCore + +#endif // ENABLE(DATAGRID) diff --git a/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp b/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp new file mode 100644 index 0000000..0b40ef0 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLDocument.h" + +#include "CharacterNames.h" +#include "Frame.h" +#include "HTMLAllCollection.h" +#include "HTMLBodyElement.h" +#include "HTMLCollection.h" +#include "HTMLDocument.h" +#include "HTMLElement.h" +#include "HTMLIFrameElement.h" +#include "HTMLNames.h" +#include "JSDOMWindow.h" +#include "JSDOMWindowCustom.h" +#include "JSDOMWindowShell.h" +#include "JSHTMLCollection.h" +#include "SegmentedString.h" +#include "DocumentParser.h" +#include <runtime/Error.h> +#include <runtime/JSCell.h> + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +bool JSHTMLDocument::canGetItemsForName(ExecState*, HTMLDocument* document, const Identifier& propertyName) +{ + AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName); + return atomicPropertyName && (document->hasNamedItem(atomicPropertyName) || document->hasExtraNamedItem(atomicPropertyName)); +} + +JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSHTMLDocument* thisObj = static_cast<JSHTMLDocument*>(asObject(slotBase)); + HTMLDocument* document = static_cast<HTMLDocument*>(thisObj->impl()); + + String name = identifierToString(propertyName); + RefPtr<HTMLCollection> collection = document->documentNamedItems(name); + + unsigned length = collection->length(); + if (!length) + return jsUndefined(); + + if (length == 1) { + Node* node = collection->firstItem(); + + Frame* frame; + if (node->hasTagName(iframeTag) && (frame = static_cast<HTMLIFrameElement*>(node)->contentFrame())) + return toJS(exec, frame); + + return toJS(exec, node); + } + + return toJS(exec, collection.get()); +} + +// Custom attributes + +JSValue JSHTMLDocument::all(ExecState* exec) const +{ + // If "all" has been overwritten, return the overwritten value + JSValue v = getDirect(Identifier(exec, "all")); + if (v) + return v; + + return toJS(exec, static_cast<HTMLDocument*>(impl())->all().get()); +} + +void JSHTMLDocument::setAll(ExecState* exec, JSValue value) +{ + // Add "all" to the property map. + putDirect(Identifier(exec, "all"), value); +} + +// Custom functions + +JSValue JSHTMLDocument::open(ExecState* exec) +{ + // For compatibility with other browsers, pass open calls with more than 2 parameters to the window. + if (exec->argumentCount() > 2) { + Frame* frame = static_cast<HTMLDocument*>(impl())->frame(); + if (frame) { + JSDOMWindowShell* wrapper = toJSDOMWindowShell(frame, currentWorld(exec)); + if (wrapper) { + JSValue function = wrapper->get(exec, Identifier(exec, "open")); + CallData callData; + CallType callType = ::getCallData(function, callData); + if (callType == CallTypeNone) + return throwTypeError(exec); + return JSC::call(exec, function, callType, callData, wrapper, ArgList(exec)); + } + } + return jsUndefined(); + } + + // document.open clobbers the security context of the document and + // aliases it with the active security context. + Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document(); + + // In the case of two parameters or fewer, do a normal document open. + static_cast<HTMLDocument*>(impl())->open(activeDocument); + return this; +} + +enum NewlineRequirement { DoNotAddNewline, DoAddNewline }; + +static inline void documentWrite(ExecState* exec, HTMLDocument* document, NewlineRequirement addNewline) +{ + // DOM only specifies single string argument, but browsers allow multiple or no arguments. + + size_t size = exec->argumentCount(); + + UString firstString = exec->argument(0).toString(exec); + SegmentedString segmentedString = ustringToString(firstString); + if (size != 1) { + if (!size) + segmentedString.clear(); + else { + for (size_t i = 1; i < size; ++i) { + UString subsequentString = exec->argument(i).toString(exec); + segmentedString.append(SegmentedString(ustringToString(subsequentString))); + } + } + } + if (addNewline) + segmentedString.append(SegmentedString(String(&newlineCharacter, 1))); + + Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document(); + document->write(segmentedString, activeDocument); +} + +JSValue JSHTMLDocument::write(ExecState* exec) +{ + documentWrite(exec, static_cast<HTMLDocument*>(impl()), DoNotAddNewline); + return jsUndefined(); +} + +JSValue JSHTMLDocument::writeln(ExecState* exec) +{ + documentWrite(exec, static_cast<HTMLDocument*>(impl()), DoAddNewline); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp new file mode 100644 index 0000000..4194657 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLElement.h" + +#include "Document.h" +#include "HTMLFormElement.h" + +namespace WebCore { + +using namespace JSC; + +void JSHTMLElement::pushEventHandlerScope(ExecState* exec, ScopeChain& scope) const +{ + HTMLElement* element = impl(); + + // The document is put on first, fall back to searching it only after the element and form. + scope.push(asObject(toJS(exec, globalObject(), element->ownerDocument()))); + + // The form is next, searched before the document, but after the element itself. + if (HTMLFormElement* form = element->form()) + scope.push(asObject(toJS(exec, globalObject(), form))); + + // The element is on top, searched first. + scope.push(asObject(toJS(exec, globalObject(), element))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp new file mode 100644 index 0000000..72e695b --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLEmbedElementCustom.h" + +#include "HTMLEmbedElement.h" +#include "JSPluginElementFunctions.h" + +namespace WebCore { + +using namespace JSC; + +bool JSHTMLEmbedElement::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this); +} + +bool JSHTMLEmbedElement::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + return runtimeObjectCustomGetOwnPropertyDescriptor(exec, propertyName, descriptor, this); +} + +bool JSHTMLEmbedElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + return runtimeObjectCustomPut(exec, propertyName, value, this, slot); +} + +CallType JSHTMLEmbedElement::getCallData(CallData& callData) +{ + return runtimeObjectGetCallData(this, callData); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLEmbedElementCustom.h b/Source/WebCore/bindings/js/JSHTMLEmbedElementCustom.h new file mode 100644 index 0000000..58833ae --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLEmbedElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSHTMLEmbedElementCustom_h +#define JSHTMLEmbedElementCustom_h + +#include "JSHTMLEmbedElement.h" + +#endif // JSHTMLEmbedElementCustom_h diff --git a/Source/WebCore/bindings/js/JSHTMLFormElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLFormElementCustom.cpp new file mode 100644 index 0000000..4dd0b81 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLFormElementCustom.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLFormElement.h" + +#include "Frame.h" +#include "HTMLCollection.h" +#include "HTMLFormElement.h" +#include "JSDOMWindowCustom.h" +#include "JSNodeList.h" +#include "StaticNodeList.h" + +using namespace JSC; + +namespace WebCore { + +bool JSHTMLFormElement::canGetItemsForName(ExecState*, HTMLFormElement* form, const Identifier& propertyName) +{ + Vector<RefPtr<Node> > namedItems; + form->getNamedElements(identifierToAtomicString(propertyName), namedItems); + return namedItems.size(); +} + +JSValue JSHTMLFormElement::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSHTMLElement* jsForm = static_cast<JSHTMLFormElement*>(asObject(slotBase)); + HTMLFormElement* form = static_cast<HTMLFormElement*>(jsForm->impl()); + + Vector<RefPtr<Node> > namedItems; + form->getNamedElements(identifierToAtomicString(propertyName), namedItems); + + if (namedItems.isEmpty()) + return jsUndefined(); + if (namedItems.size() == 1) + return toJS(exec, namedItems[0].get()); + + // FIXME: HTML5 specifies that this should be a RadioNodeList. + return toJS(exec, jsForm->globalObject(), StaticNodeList::adopt(namedItems).get()); +} + +} diff --git a/Source/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp new file mode 100644 index 0000000..5994167 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLFrameElement.h" + +#include "Document.h" +#include "HTMLFrameElement.h" +#include "HTMLNames.h" +#include "HTMLParserIdioms.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +static inline bool allowSettingJavascriptURL(ExecState* exec, HTMLFrameElement* imp, const String& value) +{ + if (protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(value))) { + Document* contentDocument = imp->contentDocument(); + if (contentDocument && !checkNodeSecurity(exec, contentDocument)) + return false; + } + return true; +} + +void JSHTMLFrameElement::setLocation(ExecState* exec, JSValue value) +{ + HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl()); + String locationValue = valueToStringWithNullCheck(exec, value); + + if (!allowSettingJavascriptURL(exec, imp, locationValue)) + return; + + imp->setLocation(locationValue); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp new file mode 100644 index 0000000..617aaff --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLFrameSetElement.h" + +#include "Document.h" +#include "HTMLCollection.h" +#include "HTMLFrameElement.h" +#include "HTMLFrameSetElement.h" +#include "HTMLNames.h" +#include "JSDOMWindow.h" +#include "JSDOMWindowShell.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +using namespace HTMLNames; + +bool JSHTMLFrameSetElement::canGetItemsForName(ExecState*, HTMLFrameSetElement* frameSet, const Identifier& propertyName) +{ + Node* frame = frameSet->children()->namedItem(identifierToAtomicString(propertyName)); + return frame && frame->hasTagName(frameTag); +} + +JSValue JSHTMLFrameSetElement::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slotBase)); + HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl()); + + Node* frame = element->children()->namedItem(identifierToAtomicString(propertyName)); + if (Document* doc = static_cast<HTMLFrameElement*>(frame)->contentDocument()) { + if (JSDOMWindowShell* window = toJSDOMWindowShell(doc->frame(), currentWorld(exec))) + return window; + } + + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLInputElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLInputElementCustom.cpp new file mode 100644 index 0000000..171a1f9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLInputElementCustom.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLInputElement.h" + +#include "HTMLInputElement.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSHTMLInputElement::selectionStart(ExecState* exec) const +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + return throwTypeError(exec); + + return jsNumber(input->selectionStart()); +} + +void JSHTMLInputElement::setSelectionStart(ExecState* exec, JSValue value) +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + throwTypeError(exec); + + input->setSelectionStart(value.toInt32(exec)); +} + +JSValue JSHTMLInputElement::selectionEnd(ExecState* exec) const +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + return throwTypeError(exec); + + return jsNumber(input->selectionEnd()); +} + +void JSHTMLInputElement::setSelectionEnd(ExecState* exec, JSValue value) +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + throwTypeError(exec); + + input->setSelectionEnd(value.toInt32(exec)); +} + +JSValue JSHTMLInputElement::setSelectionRange(ExecState* exec) +{ + HTMLInputElement* input = static_cast<HTMLInputElement*>(impl()); + if (!input->canHaveSelection()) + return throwTypeError(exec); + + int start = exec->argument(0).toInt32(exec); + int end = exec->argument(1).toInt32(exec); + + input->setSelectionRange(start, end); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLInputElementCustom.h b/Source/WebCore/bindings/js/JSHTMLInputElementCustom.h new file mode 100644 index 0000000..f5222d2 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLInputElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSHTMLInputElementCustom_h +#define JSHTMLInputElementCustom_h + +#include "JSHTMLInputElement.h" + +#endif // JSHTMLInputElementCustom_h diff --git a/Source/WebCore/bindings/js/JSHTMLLinkElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLLinkElementCustom.cpp new file mode 100644 index 0000000..8cc8d5f --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLLinkElementCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLLinkElement.h" + +#include "HTMLLinkElement.h" + +using namespace JSC; + +namespace WebCore { + +void JSHTMLLinkElement::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (StyleSheet* sheet = static_cast<HTMLLinkElement*>(impl())->sheet()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), sheet); +} + +} diff --git a/Source/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp new file mode 100644 index 0000000..c87b932 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLObjectElementCustom.h" + +#include "HTMLObjectElement.h" +#include "JSPluginElementFunctions.h" + +namespace WebCore { + +using namespace JSC; + +bool JSHTMLObjectElement::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this); +} + +bool JSHTMLObjectElement::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + return runtimeObjectCustomGetOwnPropertyDescriptor(exec, propertyName, descriptor, this); +} + +bool JSHTMLObjectElement::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + return runtimeObjectCustomPut(exec, propertyName, value, this, slot); +} + +CallType JSHTMLObjectElement::getCallData(CallData& callData) +{ + return runtimeObjectGetCallData(this, callData); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLObjectElementCustom.h b/Source/WebCore/bindings/js/JSHTMLObjectElementCustom.h new file mode 100644 index 0000000..38659f9 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLObjectElementCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSHTMLObjectElementCustom_h +#define JSHTMLObjectElementCustom_h + +#include "JSHTMLObjectElement.h" + +#endif // JSHTMLObjectElementCustom_h diff --git a/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp b/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp new file mode 100644 index 0000000..d169bc4 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSHTMLOptionsCollection.h" + +#include "ExceptionCode.h" +#include "HTMLNames.h" +#include "HTMLOptionElement.h" +#include "HTMLOptionsCollection.h" +#include "HTMLSelectElement.h" +#include "JSHTMLOptionElement.h" +#include "JSHTMLSelectElement.h" +#include "JSHTMLSelectElementCustom.h" + +#include <wtf/MathExtras.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSHTMLOptionsCollection::length(ExecState*) const +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + return jsNumber(imp->length()); +} + +void JSHTMLOptionsCollection::setLength(ExecState* exec, JSValue value) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + ExceptionCode ec = 0; + unsigned newLength = 0; + double lengthValue = value.toNumber(exec); + if (!isnan(lengthValue) && !isinf(lengthValue)) { + if (lengthValue < 0.0) + ec = INDEX_SIZE_ERR; + else if (lengthValue > static_cast<double>(UINT_MAX)) + newLength = UINT_MAX; + else + newLength = static_cast<unsigned>(lengthValue); + } + if (!ec) + imp->setLength(newLength, ec); + setDOMException(exec, ec); +} + +void JSHTMLOptionsCollection::indexSetter(ExecState* exec, unsigned index, JSValue value) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base()); + selectIndexSetter(base, exec, index, value); +} + +JSValue JSHTMLOptionsCollection::add(ExecState* exec) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + HTMLOptionElement* option = toHTMLOptionElement(exec->argument(0)); + ExceptionCode ec = 0; + if (exec->argumentCount() < 2) + imp->add(option, ec); + else { + bool ok; + int index = finiteInt32Value(exec->argument(1), exec, ok); + if (exec->hadException()) + return jsUndefined(); + if (!ok) + ec = TYPE_MISMATCH_ERR; + else + imp->add(option, index, ec); + } + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSHTMLOptionsCollection::remove(ExecState* exec) +{ + HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl()); + JSHTMLSelectElement* base = static_cast<JSHTMLSelectElement*>(asObject(toJS(exec, globalObject(), imp->base()))); + return base->remove(exec); +} + +} diff --git a/Source/WebCore/bindings/js/JSHTMLOutputElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLOutputElementCustom.cpp new file mode 100644 index 0000000..248a08e --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLOutputElementCustom.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLOutputElement.h" + +#include "HTMLOutputElement.h" +#include "JSDOMBinding.h" +#include "JSDOMSettableTokenList.h" +#include <wtf/GetPtr.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSHTMLOutputElement::htmlFor(ExecState* exec) const +{ + HTMLOutputElement* output = static_cast<HTMLOutputElement*>(impl()); + JSValue result = toJS(exec, globalObject(), WTF::getPtr(output->htmlFor())); + return result; +} + +void JSHTMLOutputElement::setHtmlFor(ExecState* exec, JSValue value) +{ + HTMLOutputElement* output = static_cast<HTMLOutputElement*>(impl()); + output->setFor(valueToStringWithNullCheck(exec, value)); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp new file mode 100644 index 0000000..2495c1e --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2007, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2007 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSHTMLSelectElementCustom.h" + +#include "ExceptionCode.h" +#include "HTMLNames.h" +#include "HTMLOptionElement.h" +#include "HTMLSelectElement.h" +#include "JSHTMLOptionElement.h" + +namespace WebCore { + +using namespace JSC; +using namespace HTMLNames; + +JSValue JSHTMLSelectElement::remove(ExecState* exec) +{ + HTMLSelectElement& select = *static_cast<HTMLSelectElement*>(impl()); + + // The remove function can take either an option object or the index of an option. + if (HTMLOptionElement* option = toHTMLOptionElement(exec->argument(0))) + select.remove(option); + else + select.remove(exec->argument(0).toInt32(exec)); + + return jsUndefined(); +} + +void selectIndexSetter(HTMLSelectElement* select, JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + if (value.isUndefinedOrNull()) + select->remove(index); + else { + ExceptionCode ec = 0; + HTMLOptionElement* option = toHTMLOptionElement(value); + if (!option) + ec = TYPE_MISMATCH_ERR; + else + select->setOption(index, option, ec); + setDOMException(exec, ec); + } +} + +void JSHTMLSelectElement::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + selectIndexSetter(static_cast<HTMLSelectElement*>(impl()), exec, index, value); +} + +} diff --git a/Source/WebCore/bindings/js/JSHTMLSelectElementCustom.h b/Source/WebCore/bindings/js/JSHTMLSelectElementCustom.h new file mode 100644 index 0000000..a449038 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLSelectElementCustom.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSHTMLSelectElementCustom_h +#define JSHTMLSelectElementCustom_h + +#include "JSHTMLSelectElement.h" + +namespace WebCore { + +void selectIndexSetter(HTMLSelectElement*, JSC::ExecState*, unsigned index, JSC::JSValue); + +} + +#endif diff --git a/Source/WebCore/bindings/js/JSHTMLStyleElementCustom.cpp b/Source/WebCore/bindings/js/JSHTMLStyleElementCustom.cpp new file mode 100644 index 0000000..9b0d1a7 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHTMLStyleElementCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHTMLStyleElement.h" + +#include "HTMLStyleElement.h" + +using namespace JSC; + +namespace WebCore { + +void JSHTMLStyleElement::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (StyleSheet* sheet = static_cast<HTMLStyleElement*>(impl())->sheet()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), sheet); +} + +} diff --git a/Source/WebCore/bindings/js/JSHistoryCustom.cpp b/Source/WebCore/bindings/js/JSHistoryCustom.cpp new file mode 100644 index 0000000..6a2f614 --- /dev/null +++ b/Source/WebCore/bindings/js/JSHistoryCustom.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSHistoryCustom.h" + +#include "Frame.h" +#include "History.h" +#include <runtime/JSFunction.h> +#include <runtime/PrototypeFunction.h> + +using namespace JSC; + +namespace WebCore { + +static JSValue nonCachingStaticBackFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, jsHistoryPrototypeFunctionBack); +} + +static JSValue nonCachingStaticForwardFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, jsHistoryPrototypeFunctionForward); +} + +static JSValue nonCachingStaticGoFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 1, propertyName, jsHistoryPrototypeFunctionGo); +} + +bool JSHistory::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + // When accessing History cross-domain, functions are always the native built-in ones. + // See JSDOMWindow::getOwnPropertySlotDelegate for additional details. + + // Our custom code is only needed to implement the Window cross-domain scheme, so if access is + // allowed, return false so the normal lookup will take place. + String message; + if (allowsAccessFromFrame(exec, impl()->frame(), message)) + return false; + + // Check for the few functions that we allow, even when called cross-domain. + const HashEntry* entry = JSHistoryPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + // Allow access to back(), forward() and go() from any frame. + if (entry->attributes() & Function) { + if (entry->function() == jsHistoryPrototypeFunctionBack) { + slot.setCustom(this, nonCachingStaticBackFunctionGetter); + return true; + } else if (entry->function() == jsHistoryPrototypeFunctionForward) { + slot.setCustom(this, nonCachingStaticForwardFunctionGetter); + return true; + } else if (entry->function() == jsHistoryPrototypeFunctionGo) { + slot.setCustom(this, nonCachingStaticGoFunctionGetter); + return true; + } + } + } else { + // Allow access to toString() cross-domain, but always Object.toString. + if (propertyName == exec->propertyNames().toString) { + slot.setCustom(this, objectToStringFunctionGetter); + return true; + } + } + + printErrorMessageForFrame(impl()->frame(), message); + slot.setUndefined(); + return true; +} + +bool JSHistory::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + if (!impl()->frame()) { + descriptor.setUndefined(); + return true; + } + + // Throw out all cross domain access + if (!allowsAccessFromFrame(exec, impl()->frame())) + return true; + + // Check for the few functions that we allow, even when called cross-domain. + const HashEntry* entry = JSHistoryPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry) { + PropertySlot slot; + // Allow access to back(), forward() and go() from any frame. + if (entry->attributes() & Function) { + if (entry->function() == jsHistoryPrototypeFunctionBack) { + slot.setCustom(this, nonCachingStaticBackFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } else if (entry->function() == jsHistoryPrototypeFunctionForward) { + slot.setCustom(this, nonCachingStaticForwardFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } else if (entry->function() == jsHistoryPrototypeFunctionGo) { + slot.setCustom(this, nonCachingStaticGoFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } + } + } else { + // Allow access to toString() cross-domain, but always Object.toString. + if (propertyName == exec->propertyNames().toString) { + PropertySlot slot; + slot.setCustom(this, objectToStringFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } + } + + descriptor.setUndefined(); + return true; +} + +bool JSHistory::putDelegate(ExecState* exec, const Identifier&, JSValue, PutPropertySlot&) +{ + // Only allow putting by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return true; + return false; +} + +bool JSHistory::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only allow deleting by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return false; + return Base::deleteProperty(exec, propertyName); +} + +void JSHistory::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + // Only allow the history object to enumerated by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return; + Base::getOwnPropertyNames(exec, propertyNames, mode); +} + +JSValue JSHistory::pushState(ExecState* exec) +{ + RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + String title = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + String url; + if (exec->argumentCount() > 2) { + url = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + } + + ExceptionCode ec = 0; + impl()->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, ec); + setDOMException(exec, ec); + + return jsUndefined(); +} + +JSValue JSHistory::replaceState(ExecState* exec) +{ + RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(exec, exec->argument(0)); + if (exec->hadException()) + return jsUndefined(); + + String title = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + String url; + if (exec->argumentCount() > 2) { + url = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + } + + ExceptionCode ec = 0; + impl()->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec); + setDOMException(exec, ec); + + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSHistoryCustom.h b/Source/WebCore/bindings/js/JSHistoryCustom.h new file mode 100644 index 0000000..40edc6f --- /dev/null +++ b/Source/WebCore/bindings/js/JSHistoryCustom.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSHistoryCustom_h +#define JSHistoryCustom_h + +#include "JSHistory.h" + +#endif // JSHistoryCustom_h + + diff --git a/Source/WebCore/bindings/js/JSIDBAnyCustom.cpp b/Source/WebCore/bindings/js/JSIDBAnyCustom.cpp new file mode 100644 index 0000000..506f15f --- /dev/null +++ b/Source/WebCore/bindings/js/JSIDBAnyCustom.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(INDEXED_DATABASE) + +#include "JSIDBAny.h" + +#include "IDBAny.h" +#include "IDBCursor.h" +#include "IDBDatabase.h" +#include "IDBFactory.h" +#include "IDBIndex.h" +#include "IDBKey.h" +#include "IDBObjectStore.h" +#include "JSIDBCursor.h" +#include "JSIDBDatabase.h" +#include "JSIDBFactory.h" +#include "JSIDBIndex.h" +#include "JSIDBKey.h" +#include "JSIDBObjectStore.h" +#include "JSIDBTransaction.h" +#include "SerializedScriptValue.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, IDBAny* idbAny) +{ + if (!idbAny) + return jsNull(); + + switch (idbAny->type()) { + case IDBAny::UndefinedType: + return jsUndefined(); + case IDBAny::NullType: + return jsNull(); + case IDBAny::IDBCursorType: + return toJS(exec, globalObject, idbAny->idbCursor()); + case IDBAny::IDBDatabaseType: + return toJS(exec, globalObject, idbAny->idbDatabase()); + case IDBAny::IDBFactoryType: + return toJS(exec, globalObject, idbAny->idbFactory()); + case IDBAny::IDBIndexType: + return toJS(exec, globalObject, idbAny->idbIndex()); + case IDBAny::IDBKeyType: + return toJS(exec, globalObject, idbAny->idbKey()); + case IDBAny::IDBObjectStoreType: + return toJS(exec, globalObject, idbAny->idbObjectStore()); + case IDBAny::IDBTransactionType: + return toJS(exec, globalObject, idbAny->idbTransaction()); + case IDBAny::SerializedScriptValueType: + return idbAny->serializedScriptValue()->deserialize(exec, globalObject); + } + + ASSERT_NOT_REACHED(); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(INDEXED_DATABASE) diff --git a/Source/WebCore/bindings/js/JSIDBKeyCustom.cpp b/Source/WebCore/bindings/js/JSIDBKeyCustom.cpp new file mode 100644 index 0000000..f0faef5 --- /dev/null +++ b/Source/WebCore/bindings/js/JSIDBKeyCustom.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(INDEXED_DATABASE) +#include "JSIDBKey.h" + +#include "IDBBindingUtilities.h" +#include "IDBKey.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject*, IDBKey* key) +{ + if (!key) + return jsNull(); + + switch (key->type()) { + case IDBKey::NullType: + return jsNull(); + case IDBKey::NumberType: + return jsNumber(key->number()); + case IDBKey::StringType: + return jsString(exec, key->string()); + // FIXME: Implement dates. + } + + ASSERT_NOT_REACHED(); + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(INDEXED_DATABASE) diff --git a/Source/WebCore/bindings/js/JSImageConstructor.cpp b/Source/WebCore/bindings/js/JSImageConstructor.cpp new file mode 100644 index 0000000..f2ad803 --- /dev/null +++ b/Source/WebCore/bindings/js/JSImageConstructor.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSImageConstructor.h" + +#include "HTMLImageElement.h" +#include "HTMLNames.h" +#include "JSHTMLImageElement.h" +#include "JSNode.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSImageConstructor); + +const ClassInfo JSImageConstructor::s_info = { "ImageConstructor", 0, 0, 0 }; + +JSImageConstructor::JSImageConstructor(ExecState* exec, JSDOMGlobalObject* globalObject) + : DOMConstructorWithDocument(JSImageConstructor::createStructure(globalObject->objectPrototype()), globalObject) +{ + putDirect(exec->propertyNames().prototype, JSHTMLImageElementPrototype::self(exec, globalObject), None); +} + +static EncodedJSValue JSC_HOST_CALL constructImage(ExecState* exec) +{ + JSImageConstructor* jsConstructor = static_cast<JSImageConstructor*>(exec->callee()); + Document* document = jsConstructor->document(); + if (!document) + return throwVMError(exec, createReferenceError(exec, "Image constructor associated document is unavailable")); + + // Calling toJS on the document causes the JS document wrapper to be + // added to the window object. This is done to ensure that JSDocument::markChildren + // will be called, which will cause the image element to be marked if necessary. + toJS(exec, jsConstructor->globalObject(), document); + int width; + int height; + int* optionalWidth = 0; + int* optionalHeight = 0; + if (exec->argumentCount() > 0) { + width = exec->argument(0).toInt32(exec); + optionalWidth = &width; + } + if (exec->argumentCount() > 1) { + height = exec->argument(1).toInt32(exec); + optionalHeight = &height; + } + + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), + HTMLImageElement::createForJSConstructor(document, optionalWidth, optionalHeight)))); +} + +ConstructType JSImageConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructImage; + return ConstructTypeHost; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSImageConstructor.h b/Source/WebCore/bindings/js/JSImageConstructor.h new file mode 100644 index 0000000..0525f5e --- /dev/null +++ b/Source/WebCore/bindings/js/JSImageConstructor.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 1999 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSImageConstructor_h +#define JSImageConstructor_h + +#include "JSDOMBinding.h" +#include "JSDocument.h" + +namespace WebCore { + + class JSImageConstructor : public DOMConstructorWithDocument { + public: + JSImageConstructor(JSC::ExecState*, JSDOMGlobalObject*); + + static const JSC::ClassInfo s_info; + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + }; + +} // namespace WebCore + +#endif // JSImageConstructor_h diff --git a/Source/WebCore/bindings/js/JSImageDataCustom.cpp b/Source/WebCore/bindings/js/JSImageDataCustom.cpp new file mode 100644 index 0000000..61c5112 --- /dev/null +++ b/Source/WebCore/bindings/js/JSImageDataCustom.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSImageData.h" + +#include "ImageData.h" +#include "PlatformString.h" + +#include <runtime/JSByteArray.h> +#include <wtf/StdLibExtras.h> + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, ImageData* imageData) +{ + if (!imageData) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec, imageData); + if (wrapper) + return wrapper; + + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ImageData, imageData); + Identifier dataName(exec, "data"); + DEFINE_STATIC_LOCAL(RefPtr<Structure>, cpaStructure, (JSByteArray::createStructure(jsNull()))); + static const ClassInfo cpaClassInfo = { "CanvasPixelArray", 0, 0, 0 }; + wrapper->putDirect(dataName, new (exec) JSByteArray(exec, cpaStructure, imageData->data()->data(), &cpaClassInfo), DontDelete | ReadOnly); + exec->heap()->reportExtraMemoryCost(imageData->data()->length()); + + return wrapper; +} + +} diff --git a/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp b/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp new file mode 100644 index 0000000..de72dea --- /dev/null +++ b/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSInjectedScriptHost.h" + +#if ENABLE(INSPECTOR) + +#include "Console.h" +#include "JSMainThreadExecState.h" +#if ENABLE(DATABASE) +#include "Database.h" +#include "JSDatabase.h" +#endif +#include "ExceptionCode.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "InjectedScript.h" +#include "InjectedScriptHost.h" +#include "InspectorController.h" +#include "InspectorValues.h" +#include "JSDOMWindow.h" +#include "JSDOMWindowCustom.h" +#include "JSNode.h" +#include "JSRange.h" +#include "Node.h" +#include "Page.h" +#if ENABLE(DOM_STORAGE) +#include "Storage.h" +#include "JSStorage.h" +#endif +#include "TextIterator.h" +#include "VisiblePosition.h" +#include <parser/SourceCode.h> +#include <runtime/JSArray.h> +#include <runtime/JSLock.h> +#include <wtf/RefPtr.h> +#include <wtf/Vector.h> + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include "JavaScriptCallFrame.h" +#include "JSJavaScriptCallFrame.h" +#include "ScriptDebugServer.h" +#endif + +using namespace JSC; + +namespace WebCore { + +ScriptObject InjectedScriptHost::createInjectedScript(const String& source, ScriptState* scriptState, long id) +{ + SourceCode sourceCode = makeSource(stringToUString(source)); + JSLock lock(SilenceAssertionsOnly); + JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); + JSValue globalThisValue = scriptState->globalThisValue(); + Completion comp = JSMainThreadExecState::evaluate(scriptState, globalObject->globalScopeChain(), sourceCode, globalThisValue); + if (comp.complType() != JSC::Normal && comp.complType() != JSC::ReturnValue) + return ScriptObject(); + JSValue functionValue = comp.value(); + CallData callData; + CallType callType = getCallData(functionValue, callData); + if (callType == CallTypeNone) + return ScriptObject(); + + MarkedArgumentBuffer args; + args.append(toJS(scriptState, globalObject, this)); + args.append(globalThisValue); + args.append(jsNumber(id)); + JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args); + if (result.isObject()) + return ScriptObject(scriptState, result.getObject()); + return ScriptObject(); +} + +void InjectedScriptHost::discardInjectedScript(ScriptState* scriptState) +{ + JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); + globalObject->setInjectedScript(0); +} + +#if ENABLE(JAVASCRIPT_DEBUGGER) +JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec) +{ + JavaScriptCallFrame* callFrame = ScriptDebugServer::shared().currentCallFrame(); + if (!callFrame || !callFrame->isValid()) + return jsUndefined(); + + JSLock lock(SilenceAssertionsOnly); + return toJS(exec, callFrame); +} +#endif + +JSValue JSInjectedScriptHost::nodeForId(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return jsUndefined(); + + Node* node = impl()->nodeForId(exec->argument(0).toInt32(exec)); + if (!node) + return jsUndefined(); + + InspectorController* ic = impl()->inspectorController(); + if (!ic) + return jsUndefined(); + + JSLock lock(SilenceAssertionsOnly); + return toJS(exec, node); +} + +JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return jsUndefined(); + + UString result = exec->argument(0).toThisObject(exec)->className(); + return jsString(exec, result); +} + +JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec) +{ + if (exec->argumentCount() < 3) + return jsUndefined(); + + Node* node = toNode(exec->argument(0)); + if (!node) + return jsUndefined(); + + bool withChildren = exec->argument(1).toBoolean(exec); + bool selectInUI = exec->argument(2).toBoolean(exec); + return jsNumber(impl()->pushNodePathToFrontend(node, withChildren, selectInUI)); +} + +#if ENABLE(DATABASE) +JSValue JSInjectedScriptHost::selectDatabase(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return jsUndefined(); + + Database* database = toDatabase(exec->argument(0)); + if (database) + impl()->selectDatabase(database); + return jsUndefined(); +} +#endif + +#if ENABLE(DOM_STORAGE) +JSValue JSInjectedScriptHost::selectDOMStorage(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return jsUndefined(); + InspectorController* ic = impl()->inspectorController(); + if (!ic) + return jsUndefined(); + + Storage* storage = toStorage(exec->argument(0)); + if (storage) + impl()->selectDOMStorage(storage); + return jsUndefined(); +} +#endif + +InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* scriptState) +{ + JSLock lock(SilenceAssertionsOnly); + JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); + JSObject* injectedScript = globalObject->injectedScript(); + if (injectedScript) + return InjectedScript(ScriptObject(scriptState, injectedScript)); + + if (!canAccessInspectedWindow(scriptState)) + return InjectedScript(); + + ASSERT(!m_injectedScriptSource.isEmpty()); + pair<long, ScriptObject> injectedScriptObject = injectScript(m_injectedScriptSource, scriptState); + globalObject->setInjectedScript(injectedScriptObject.second.jsObject()); + InjectedScript result(injectedScriptObject.second); + m_idToInjectedScript.set(injectedScriptObject.first, result); + return result; +} + +bool InjectedScriptHost::canAccessInspectedWindow(ScriptState* scriptState) +{ + JSLock lock(SilenceAssertionsOnly); + JSDOMWindow* inspectedWindow = toJSDOMWindow(scriptState->lexicalGlobalObject()); + if (!inspectedWindow) + return false; + return inspectedWindow->allowsAccessFromNoErrorMessage(scriptState); +} + +} // namespace WebCore + +#endif // ENABLE(INSPECTOR) diff --git a/Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp b/Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp new file mode 100644 index 0000000..ee79a38 --- /dev/null +++ b/Source/WebCore/bindings/js/JSInspectorFrontendHostCustom.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSInspectorFrontendHost.h" + +#if ENABLE(INSPECTOR) + +#include "ContextMenuItem.h" +#include "InspectorController.h" +#include "InspectorFrontendHost.h" +#include "JSEvent.h" +#include "MouseEvent.h" +#include "PlatformString.h" +#include <runtime/JSArray.h> +#include <runtime/JSLock.h> +#include <runtime/JSObject.h> +#include <wtf/Vector.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSInspectorFrontendHost::platform(ExecState* execState) +{ +#if PLATFORM(MAC) + DEFINE_STATIC_LOCAL(const String, platform, ("mac")); +#elif OS(WINDOWS) + DEFINE_STATIC_LOCAL(const String, platform, ("windows")); +#elif OS(LINUX) + DEFINE_STATIC_LOCAL(const String, platform, ("linux")); +#elif OS(FREEBSD) + DEFINE_STATIC_LOCAL(const String, platform, ("freebsd")); +#else + DEFINE_STATIC_LOCAL(const String, platform, ("unknown")); +#endif + return jsString(execState, platform); +} + +JSValue JSInspectorFrontendHost::port(ExecState* execState) +{ +#if PLATFORM(QT) + DEFINE_STATIC_LOCAL(const String, port, ("qt")); +#elif PLATFORM(GTK) + DEFINE_STATIC_LOCAL(const String, port, ("gtk")); +#elif PLATFORM(WX) + DEFINE_STATIC_LOCAL(const String, port, ("wx")); +#else + DEFINE_STATIC_LOCAL(const String, port, ("unknown")); +#endif + return jsString(execState, port); +} + +JSValue JSInspectorFrontendHost::showContextMenu(ExecState* exec) +{ + if (exec->argumentCount() < 2) + return jsUndefined(); +#if ENABLE(CONTEXT_MENUS) + Event* event = toEvent(exec->argument(0)); + + JSArray* array = asArray(exec->argument(1)); + Vector<ContextMenuItem*> items; + + for (size_t i = 0; i < array->length(); ++i) { + JSObject* item = asObject(array->getIndex(i)); + JSValue label = item->get(exec, Identifier(exec, "label")); + JSValue type = item->get(exec, Identifier(exec, "type")); + JSValue id = item->get(exec, Identifier(exec, "id")); + JSValue enabled = item->get(exec, Identifier(exec, "enabled")); + JSValue checked = item->get(exec, Identifier(exec, "checked")); + if (!type.isString()) + continue; + + String typeString = ustringToString(type.toString(exec)); + if (typeString == "separator") { + items.append(new ContextMenuItem(SeparatorType, + ContextMenuItemCustomTagNoAction, + String())); + } else { + ContextMenuAction typedId = static_cast<ContextMenuAction>(ContextMenuItemBaseCustomTag + id.toInt32(exec)); + ContextMenuItem* menuItem = new ContextMenuItem((typeString == "checkbox" ? CheckableActionType : ActionType), typedId, ustringToString(label.toString(exec))); + if (!enabled.isUndefined()) + menuItem->setEnabled(enabled.toBoolean(exec)); + if (!checked.isUndefined()) + menuItem->setChecked(checked.toBoolean(exec)); + items.append(menuItem); + } + } + + impl()->showContextMenu(event, items); +#endif + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(INSPECTOR) diff --git a/Source/WebCore/bindings/js/JSInt16ArrayCustom.cpp b/Source/WebCore/bindings/js/JSInt16ArrayCustom.cpp new file mode 100644 index 0000000..e08da8a --- /dev/null +++ b/Source/WebCore/bindings/js/JSInt16ArrayCustom.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSInt16Array.h" + +#include "Int16Array.h" +#include "JSArrayBufferViewHelper.h" + +using namespace JSC; + +namespace WebCore { + +void JSInt16Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<signed short>(value.toInt32(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Int16Array* object) +{ + return getDOMObjectWrapper<JSInt16Array>(exec, globalObject, object); +} + +JSC::JSValue JSInt16Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toInt16Array); +} + +EncodedJSValue JSC_HOST_CALL JSInt16ArrayConstructor::constructJSInt16Array(ExecState* exec) +{ + JSInt16ArrayConstructor* jsConstructor = static_cast<JSInt16ArrayConstructor*>(exec->callee()); + RefPtr<Int16Array> array = constructArrayBufferView<Int16Array, short>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSInt32ArrayCustom.cpp b/Source/WebCore/bindings/js/JSInt32ArrayCustom.cpp new file mode 100644 index 0000000..5aa64bb --- /dev/null +++ b/Source/WebCore/bindings/js/JSInt32ArrayCustom.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSInt32Array.h" + +#include "Int32Array.h" +#include "JSArrayBufferViewHelper.h" + +using namespace JSC; + +namespace WebCore { + +void JSInt32Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<signed int>(value.toInt32(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Int32Array* object) +{ + return getDOMObjectWrapper<JSInt32Array>(exec, globalObject, object); +} + +JSC::JSValue JSInt32Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toInt32Array); +} + +EncodedJSValue JSC_HOST_CALL JSInt32ArrayConstructor::constructJSInt32Array(ExecState* exec) +{ + JSInt32ArrayConstructor* jsConstructor = static_cast<JSInt32ArrayConstructor*>(exec->callee()); + RefPtr<Int32Array> array = constructArrayBufferView<Int32Array, int>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSInt8ArrayCustom.cpp b/Source/WebCore/bindings/js/JSInt8ArrayCustom.cpp new file mode 100644 index 0000000..b63de54 --- /dev/null +++ b/Source/WebCore/bindings/js/JSInt8ArrayCustom.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSInt8Array.h" + +#include "Int8Array.h" +#include "JSArrayBufferViewHelper.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +void JSInt8Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<signed char>(value.toInt32(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Int8Array* object) +{ + return getDOMObjectWrapper<JSInt8Array>(exec, globalObject, object); +} + +JSC::JSValue JSInt8Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toInt8Array); +} + +EncodedJSValue JSC_HOST_CALL JSInt8ArrayConstructor::constructJSInt8Array(ExecState* exec) +{ + JSInt8ArrayConstructor* jsConstructor = static_cast<JSInt8ArrayConstructor*>(exec->callee()); + RefPtr<Int8Array> array = constructArrayBufferView<Int8Array, signed char>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSJavaScriptAudioNodeCustom.cpp b/Source/WebCore/bindings/js/JSJavaScriptAudioNodeCustom.cpp new file mode 100644 index 0000000..9acabf3 --- /dev/null +++ b/Source/WebCore/bindings/js/JSJavaScriptAudioNodeCustom.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WEB_AUDIO) + +#include "JavaScriptAudioNode.h" + +#include "JSJavaScriptAudioNode.h" + +using namespace JSC; + +namespace WebCore { + +void JSJavaScriptAudioNode::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + static_cast<JavaScriptAudioNode*>(impl())->markJSEventListeners(markStack); +} + +} // namespace WebCore + +#endif // ENABLE(WEB_AUDIO) diff --git a/Source/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp b/Source/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp new file mode 100644 index 0000000..0f47b7b --- /dev/null +++ b/Source/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSJavaScriptCallFrame.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +#include "JavaScriptCallFrame.h" +#include <runtime/ArrayPrototype.h> +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSJavaScriptCallFrame::evaluate(ExecState* exec) +{ + JSValue exception; + JSValue result = impl()->evaluate(exec->argument(0).toString(exec), exception); + + if (exception) + throwError(exec, exception); + + return result; +} + +JSValue JSJavaScriptCallFrame::thisObject(ExecState*) const +{ + return impl()->thisObject() ? impl()->thisObject() : jsNull(); +} + +JSValue JSJavaScriptCallFrame::type(ExecState* exec) const +{ + switch (impl()->type()) { + case DebuggerCallFrame::FunctionType: + return jsString(exec, UString("function")); + case DebuggerCallFrame::ProgramType: + return jsString(exec, UString("program")); + } + + ASSERT_NOT_REACHED(); + return jsNull(); +} + +JSValue JSJavaScriptCallFrame::scopeChain(ExecState* exec) const +{ + if (!impl()->scopeChain()) + return jsNull(); + + const ScopeChainNode* scopeChain = impl()->scopeChain(); + ScopeChainIterator iter = scopeChain->begin(); + ScopeChainIterator end = scopeChain->end(); + + // we must always have something in the scope chain + ASSERT(iter != end); + + MarkedArgumentBuffer list; + do { + list.append(*iter); + ++iter; + } while (iter != end); + + return constructArray(exec, list); +} + +JSValue JSJavaScriptCallFrame::scopeType(ExecState* exec) +{ + if (!impl()->scopeChain()) + return jsUndefined(); + + if (!exec->argument(0).isInt32()) + return jsUndefined(); + int index = exec->argument(0).asInt32(); + + const ScopeChainNode* scopeChain = impl()->scopeChain(); + ScopeChainIterator end = scopeChain->end(); + + bool foundLocalScope = false; + for (ScopeChainIterator iter = scopeChain->begin(); iter != end; ++iter) { + JSObject* scope = *iter; + if (scope->isActivationObject()) { + if (!foundLocalScope) { + // First activation object is local scope, each successive activation object is closure. + if (!index) + return jsJavaScriptCallFrameLOCAL_SCOPE(exec, JSValue(), Identifier()); + foundLocalScope = true; + } else if (!index) + return jsJavaScriptCallFrameCLOSURE_SCOPE(exec, JSValue(), Identifier()); + } + + if (!index) { + // Last in the chain is global scope. + if (++iter == end) + return jsJavaScriptCallFrameGLOBAL_SCOPE(exec, JSValue(), Identifier()); + return jsJavaScriptCallFrameWITH_SCOPE(exec, JSValue(), Identifier()); + } + + --index; + } + return jsUndefined(); +} + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/Source/WebCore/bindings/js/JSLazyEventListener.cpp b/Source/WebCore/bindings/js/JSLazyEventListener.cpp new file mode 100644 index 0000000..1aad7df --- /dev/null +++ b/Source/WebCore/bindings/js/JSLazyEventListener.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSLazyEventListener.h" + +#include "Frame.h" +#include "JSNode.h" +#include <runtime/FunctionConstructor.h> +#include <runtime/JSFunction.h> +#include <runtime/JSLock.h> +#include <wtf/RefCountedLeakCounter.h> + +using namespace JSC; + +namespace WebCore { + +#ifndef NDEBUG +static WTF::RefCountedLeakCounter eventListenerCounter("JSLazyEventListener"); +#endif + +JSLazyEventListener::JSLazyEventListener(const String& functionName, const String& eventParameterName, const String& code, Node* node, const String& sourceURL, int lineNumber, JSObject* wrapper, DOMWrapperWorld* isolatedWorld) + : JSEventListener(0, wrapper, true, isolatedWorld) + , m_functionName(functionName) + , m_eventParameterName(eventParameterName) + , m_code(code) + , m_sourceURL(sourceURL) + , m_lineNumber(lineNumber) + , m_originalNode(node) +{ + // We don't retain the original node because we assume it + // will stay alive as long as this handler object is around + // and we need to avoid a reference cycle. If JS transfers + // this handler to another node, initializeJSFunction will + // be called and then originalNode is no longer needed. + + // A JSLazyEventListener can be created with a line number of zero when it is created with + // a setAttribute call from JavaScript, so make the line number 1 in that case. + if (m_lineNumber == 0) + m_lineNumber = 1; + +#ifndef NDEBUG + eventListenerCounter.increment(); +#endif +} + +JSLazyEventListener::~JSLazyEventListener() +{ +#ifndef NDEBUG + eventListenerCounter.decrement(); +#endif +} + +JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const +{ + ASSERT(executionContext); + ASSERT(executionContext->isDocument()); + if (!executionContext) + return 0; + + Frame* frame = static_cast<Document*>(executionContext)->frame(); + if (!frame) + return 0; + + ScriptController* scriptController = frame->script(); + if (!scriptController->canExecuteScripts(AboutToExecuteScript)) + return 0; + + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld()); + if (!globalObject) + return 0; + + if (executionContext->isDocument()) { + JSDOMWindow* window = static_cast<JSDOMWindow*>(globalObject); + Frame* frame = window->impl()->frame(); + if (!frame) + return 0; + // FIXME: Is this check needed for non-Document contexts? + ScriptController* script = frame->script(); + if (!script->canExecuteScripts(AboutToExecuteScript) || script->isPaused()) + return 0; + } + + ExecState* exec = globalObject->globalExec(); + + MarkedArgumentBuffer args; + args.append(jsNontrivialString(exec, stringToUString(m_eventParameterName))); + args.append(jsString(exec, m_code)); + + JSObject* jsFunction = constructFunction(exec, args, Identifier(exec, stringToUString(m_functionName)), stringToUString(m_sourceURL), m_lineNumber); // FIXME: is globalExec ok? + if (exec->hadException()) { + exec->clearException(); + return 0; + } + + JSFunction* listenerAsFunction = static_cast<JSFunction*>(jsFunction); + if (m_originalNode) { + if (!wrapper()) { + // Ensure that 'node' has a JavaScript wrapper to mark the event listener we're creating. + JSLock lock(SilenceAssertionsOnly); + // FIXME: Should pass the global object associated with the node + setWrapper(asObject(toJS(globalObject->globalExec(), globalObject, m_originalNode))); + } + + // Add the event's home element to the scope + // (and the document, and the form - see JSHTMLElement::eventHandlerScope) + ScopeChain scope = listenerAsFunction->scope(); + static_cast<JSNode*>(wrapper())->pushEventHandlerScope(exec, scope); + listenerAsFunction->setScope(scope); + } + + // Since we only parse once, there's no need to keep data used for parsing around anymore. + m_functionName = String(); + m_code = String(); + m_eventParameterName = String(); + m_sourceURL = String(); + return jsFunction; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSLazyEventListener.h b/Source/WebCore/bindings/js/JSLazyEventListener.h new file mode 100644 index 0000000..1b00b75 --- /dev/null +++ b/Source/WebCore/bindings/js/JSLazyEventListener.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSLazyEventListener_h +#define JSLazyEventListener_h + +#include "JSEventListener.h" +#include "PlatformString.h" + +namespace WebCore { + + class Node; + + class JSLazyEventListener : public JSEventListener { + public: + static PassRefPtr<JSLazyEventListener> create(const String& functionName, const String& eventParameterName, const String& code, Node* node, const String& sourceURL, int lineNumber, JSC::JSObject* wrapper, DOMWrapperWorld* isolatedWorld) + { + return adoptRef(new JSLazyEventListener(functionName, eventParameterName, code, node, sourceURL, lineNumber, wrapper, isolatedWorld)); + } + virtual ~JSLazyEventListener(); + + private: + JSLazyEventListener(const String& functionName, const String& eventParameterName, const String& code, Node*, const String& sourceURL, int lineNumber, JSC::JSObject* wrapper, DOMWrapperWorld* isolatedWorld); + + virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const; + virtual bool wasCreatedFromMarkup() const { return true; } + + mutable String m_functionName; + mutable String m_eventParameterName; + mutable String m_code; + mutable String m_sourceURL; + int m_lineNumber; + Node* m_originalNode; + }; + +} // namespace WebCore + +#endif // JSEventListener_h diff --git a/Source/WebCore/bindings/js/JSLocationCustom.cpp b/Source/WebCore/bindings/js/JSLocationCustom.cpp new file mode 100644 index 0000000..432155e --- /dev/null +++ b/Source/WebCore/bindings/js/JSLocationCustom.cpp @@ -0,0 +1,290 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reseved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "config.h" +#include "JSLocationCustom.h" + +#include "Location.h" +#include <runtime/JSFunction.h> +#include <runtime/PrototypeFunction.h> + +using namespace JSC; + +namespace WebCore { + +static JSValue nonCachingStaticReplaceFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 1, propertyName, jsLocationPrototypeFunctionReplace); +} + +static JSValue nonCachingStaticReloadFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 0, propertyName, jsLocationPrototypeFunctionReload); +} + +static JSValue nonCachingStaticAssignFunctionGetter(ExecState* exec, JSValue, const Identifier& propertyName) +{ + return new (exec) NativeFunctionWrapper(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->prototypeFunctionStructure(), 1, propertyName, jsLocationPrototypeFunctionAssign); +} + +bool JSLocation::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + Frame* frame = impl()->frame(); + if (!frame) { + slot.setUndefined(); + return true; + } + + // When accessing Location cross-domain, functions are always the native built-in ones. + // See JSDOMWindow::getOwnPropertySlotDelegate for additional details. + + // Our custom code is only needed to implement the Window cross-domain scheme, so if access is + // allowed, return false so the normal lookup will take place. + String message; + if (allowsAccessFromFrame(exec, frame, message)) + return false; + + // Check for the few functions that we allow, even when called cross-domain. + const HashEntry* entry = JSLocationPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + if (entry && (entry->attributes() & Function)) { + if (entry->function() == jsLocationPrototypeFunctionReplace) { + slot.setCustom(this, nonCachingStaticReplaceFunctionGetter); + return true; + } else if (entry->function() == jsLocationPrototypeFunctionReload) { + slot.setCustom(this, nonCachingStaticReloadFunctionGetter); + return true; + } else if (entry->function() == jsLocationPrototypeFunctionAssign) { + slot.setCustom(this, nonCachingStaticAssignFunctionGetter); + return true; + } + } + + // FIXME: Other implementers of the Window cross-domain scheme (Window, History) allow toString, + // but for now we have decided not to, partly because it seems silly to return "[Object Location]" in + // such cases when normally the string form of Location would be the URL. + + printErrorMessageForFrame(frame, message); + slot.setUndefined(); + return true; +} + +bool JSLocation::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + Frame* frame = impl()->frame(); + if (!frame) { + descriptor.setUndefined(); + return true; + } + + // throw out all cross domain access + if (!allowsAccessFromFrame(exec, frame)) + return true; + + // Check for the few functions that we allow, even when called cross-domain. + const HashEntry* entry = JSLocationPrototype::s_info.propHashTable(exec)->entry(exec, propertyName); + PropertySlot slot; + if (entry && (entry->attributes() & Function)) { + if (entry->function() == jsLocationPrototypeFunctionReplace) { + slot.setCustom(this, nonCachingStaticReplaceFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } else if (entry->function() == jsLocationPrototypeFunctionReload) { + slot.setCustom(this, nonCachingStaticReloadFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } else if (entry->function() == jsLocationPrototypeFunctionAssign) { + slot.setCustom(this, nonCachingStaticAssignFunctionGetter); + descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes()); + return true; + } + } + + // FIXME: Other implementers of the Window cross-domain scheme (Window, History) allow toString, + // but for now we have decided not to, partly because it seems silly to return "[Object Location]" in + // such cases when normally the string form of Location would be the URL. + + descriptor.setUndefined(); + return true; +} + +bool JSLocation::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + Frame* frame = impl()->frame(); + if (!frame) + return true; + + if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf) + return true; + + bool sameDomainAccess = allowsAccessFromFrame(exec, frame); + + const HashEntry* entry = JSLocation::s_info.propHashTable(exec)->entry(exec, propertyName); + if (!entry) { + if (sameDomainAccess) + JSObject::put(exec, propertyName, value, slot); + return true; + } + + // Cross-domain access to the location is allowed when assigning the whole location, + // but not when assigning the individual pieces, since that might inadvertently + // disclose other parts of the original location. + if (entry->propertyPutter() != setJSLocationHref && !sameDomainAccess) + return true; + + return false; +} + +bool JSLocation::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only allow deleting by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return false; + return Base::deleteProperty(exec, propertyName); +} + +void JSLocation::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + // Only allow the location object to enumerated by frames in the same origin. + if (!allowsAccessFromFrame(exec, impl()->frame())) + return; + Base::getOwnPropertyNames(exec, propertyNames, mode); +} + +void JSLocation::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes) +{ + if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf) + return; + Base::defineGetter(exec, propertyName, getterFunction, attributes); +} + +void JSLocation::setHref(ExecState* exec, JSValue value) +{ + UString href = value.toString(exec); + if (exec->hadException()) + return; + impl()->setHref(ustringToString(href), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +void JSLocation::setProtocol(ExecState* exec, JSValue value) +{ + UString protocol = value.toString(exec); + if (exec->hadException()) + return; + ExceptionCode ec = 0; + impl()->setProtocol(ustringToString(protocol), activeDOMWindow(exec), firstDOMWindow(exec), ec); + setDOMException(exec, ec); +} + +void JSLocation::setHost(ExecState* exec, JSValue value) +{ + UString host = value.toString(exec); + if (exec->hadException()) + return; + impl()->setHost(ustringToString(host), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +void JSLocation::setHostname(ExecState* exec, JSValue value) +{ + UString hostname = value.toString(exec); + if (exec->hadException()) + return; + impl()->setHostname(ustringToString(hostname), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +void JSLocation::setPort(ExecState* exec, JSValue value) +{ + UString port = value.toString(exec); + if (exec->hadException()) + return; + impl()->setPort(ustringToString(port), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +void JSLocation::setPathname(ExecState* exec, JSValue value) +{ + UString pathname = value.toString(exec); + if (exec->hadException()) + return; + impl()->setPathname(ustringToString(pathname), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +void JSLocation::setSearch(ExecState* exec, JSValue value) +{ + UString pathname = value.toString(exec); + if (exec->hadException()) + return; + impl()->setSearch(ustringToString(pathname), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +void JSLocation::setHash(ExecState* exec, JSValue value) +{ + UString hash = value.toString(exec); + if (exec->hadException()) + return; + impl()->setHash(ustringToString(hash), activeDOMWindow(exec), firstDOMWindow(exec)); +} + +JSValue JSLocation::replace(ExecState* exec) +{ + UString urlString = exec->argument(0).toString(exec); + if (exec->hadException()) + return jsUndefined(); + impl()->replace(ustringToString(urlString), activeDOMWindow(exec), firstDOMWindow(exec)); + return jsUndefined(); +} + +JSValue JSLocation::reload(ExecState* exec) +{ + impl()->reload(activeDOMWindow(exec)); + return jsUndefined(); +} + +JSValue JSLocation::assign(ExecState* exec) +{ + UString urlString = exec->argument(0).toString(exec); + if (exec->hadException()) + return jsUndefined(); + impl()->assign(ustringToString(urlString), activeDOMWindow(exec), firstDOMWindow(exec)); + return jsUndefined(); +} + +JSValue JSLocation::toString(ExecState* exec) +{ + Frame* frame = impl()->frame(); + if (!frame || !allowsAccessFromFrame(exec, frame)) + return jsUndefined(); + + return jsString(exec, impl()->toString()); +} + +bool JSLocationPrototype::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue, PutPropertySlot&) +{ + return (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf); +} + +void JSLocationPrototype::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes) +{ + if (propertyName == exec->propertyNames().toString || propertyName == exec->propertyNames().valueOf) + return; + Base::defineGetter(exec, propertyName, getterFunction, attributes); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSLocationCustom.h b/Source/WebCore/bindings/js/JSLocationCustom.h new file mode 100644 index 0000000..127871e --- /dev/null +++ b/Source/WebCore/bindings/js/JSLocationCustom.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSLocationCustom_h +#define JSLocationCustom_h + +#include "JSLocation.h" + +#endif // JSLocationCustom_h + + diff --git a/Source/WebCore/bindings/js/JSMainThreadExecState.cpp b/Source/WebCore/bindings/js/JSMainThreadExecState.cpp new file mode 100644 index 0000000..d679a58 --- /dev/null +++ b/Source/WebCore/bindings/js/JSMainThreadExecState.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSMainThreadExecState.h" + +namespace WebCore { + +JSC::ExecState* JSMainThreadExecState::s_mainThreadState = 0; + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSMainThreadExecState.h b/Source/WebCore/bindings/js/JSMainThreadExecState.h new file mode 100644 index 0000000..8193d7c --- /dev/null +++ b/Source/WebCore/bindings/js/JSMainThreadExecState.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSMainThreadExecState_h +#define JSMainThreadExecState_h + +#include <JSDOMBinding.h> +#ifndef NDEBUG +#include <wtf/MainThread.h> +#endif +#include <wtf/Noncopyable.h> + +namespace WebCore { + +class JSMainThreadExecState : public Noncopyable { +public: + static JSC::ExecState* currentState() + { + ASSERT(WTF::isMainThread()); + return s_mainThreadState; + }; + + static JSC::JSValue call(JSC::ExecState* exec, JSC::JSValue functionObject, JSC::CallType callType, const JSC::CallData& callData, JSC::JSValue thisValue, const JSC::ArgList& args) + { + JSMainThreadExecState currentState(exec); + return JSC::call(exec, functionObject, callType, callData, thisValue, args); + }; + + static JSC::Completion evaluate(JSC::ExecState* exec, JSC::ScopeChain& chain, const JSC::SourceCode& source, JSC::JSValue thisValue) + { + JSMainThreadExecState currentState(exec); + return JSC::evaluate(exec, chain, source, thisValue); + }; + +protected: + explicit JSMainThreadExecState(JSC::ExecState* exec) + : m_previousState(s_mainThreadState) + { + ASSERT(WTF::isMainThread()); + s_mainThreadState = exec; + }; + + ~JSMainThreadExecState() + { + ASSERT(WTF::isMainThread()); + s_mainThreadState = m_previousState; + } + +private: + static JSC::ExecState* s_mainThreadState; + JSC::ExecState* m_previousState; +}; + +// Null state prevents origin security checks. +class JSMainThreadNullState : private JSMainThreadExecState { +public: + explicit JSMainThreadNullState() : JSMainThreadExecState(0) {}; +}; + +} // namespace WebCore + +#endif // JSMainThreadExecState_h diff --git a/Source/WebCore/bindings/js/JSMessageChannelCustom.cpp b/Source/WebCore/bindings/js/JSMessageChannelCustom.cpp new file mode 100644 index 0000000..c2f5779 --- /dev/null +++ b/Source/WebCore/bindings/js/JSMessageChannelCustom.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSMessageChannel.h" + +#include "MessageChannel.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +void JSMessageChannel::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (MessagePort* port = m_impl->port1()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), port); + + if (MessagePort* port = m_impl->port2()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), port); +} + +EncodedJSValue JSC_HOST_CALL JSMessageChannelConstructor::constructJSMessageChannel(ExecState* exec) +{ + JSMessageChannelConstructor* jsConstructor = static_cast<JSMessageChannelConstructor*>(exec->callee()); + ScriptExecutionContext* context = jsConstructor->scriptExecutionContext(); + if (!context) + return throwVMError(exec, createReferenceError(exec, "MessageChannel constructor associated document is unavailable")); + + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), MessageChannel::create(context)))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSMessageEventCustom.cpp b/Source/WebCore/bindings/js/JSMessageEventCustom.cpp new file mode 100644 index 0000000..b3dabae --- /dev/null +++ b/Source/WebCore/bindings/js/JSMessageEventCustom.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSMessageEvent.h" + +#include "JSDOMBinding.h" +#include "JSDOMWindow.h" +#include "JSEventTarget.h" +#include "JSMessagePortCustom.h" +#include "MessageEvent.h" +#include <runtime/JSArray.h> + +using namespace JSC; + +namespace WebCore { + +JSValue JSMessageEvent::ports(ExecState* exec) const +{ + MessagePortArray* ports = static_cast<MessageEvent*>(impl())->ports(); + if (!ports || ports->isEmpty()) + return jsNull(); + + MarkedArgumentBuffer list; + for (size_t i = 0; i < ports->size(); i++) + list.append(toJS(exec, globalObject(), (*ports)[i].get())); + return constructArray(exec, list); +} + +JSC::JSValue JSMessageEvent::initMessageEvent(JSC::ExecState* exec) +{ + const UString& typeArg = exec->argument(0).toString(exec); + bool canBubbleArg = exec->argument(1).toBoolean(exec); + bool cancelableArg = exec->argument(2).toBoolean(exec); + PassRefPtr<SerializedScriptValue> dataArg = SerializedScriptValue::create(exec, exec->argument(3)); + const UString& originArg = exec->argument(4).toString(exec); + const UString& lastEventIdArg = exec->argument(5).toString(exec); + DOMWindow* sourceArg = toDOMWindow(exec->argument(6)); + OwnPtr<MessagePortArray> messagePorts; + if (!exec->argument(7).isUndefinedOrNull()) { + messagePorts = new MessagePortArray(); + fillMessagePortArray(exec, exec->argument(7), *messagePorts); + if (exec->hadException()) + return jsUndefined(); + } + + MessageEvent* event = static_cast<MessageEvent*>(this->impl()); + event->initMessageEvent(ustringToAtomicString(typeArg), canBubbleArg, cancelableArg, dataArg, ustringToString(originArg), ustringToString(lastEventIdArg), sourceArg, messagePorts.release()); + return jsUndefined(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSMessagePortCustom.cpp b/Source/WebCore/bindings/js/JSMessagePortCustom.cpp new file mode 100644 index 0000000..06b4178 --- /dev/null +++ b/Source/WebCore/bindings/js/JSMessagePortCustom.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSMessagePort.h" + +#include "Event.h" +#include "ExceptionCode.h" +#include "Frame.h" +#include "JSDOMGlobalObject.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "JSMessagePortCustom.h" +#include "MessagePort.h" +#include <runtime/Error.h> +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +void JSMessagePort::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + // If we have a locally entangled port, we can directly mark it as reachable. Ports that are remotely entangled are marked in-use by markActiveObjectsForContext(). + if (MessagePort* entangledPort = m_impl->locallyEntangledPort()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), entangledPort); + + m_impl->markJSEventListeners(markStack); +} + +JSC::JSValue JSMessagePort::postMessage(JSC::ExecState* exec) +{ + return handlePostMessage(exec, impl()); +} + +void fillMessagePortArray(JSC::ExecState* exec, JSC::JSValue value, MessagePortArray& portArray) +{ + // Convert from the passed-in JS array-like object to a MessagePortArray. + // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec. + if (value.isUndefinedOrNull()) { + portArray.resize(0); + return; + } + + // Validation of sequence types, per WebIDL spec 4.1.13. + unsigned length; + JSObject* object = toJSSequence(exec, value, length); + if (exec->hadException()) + return; + + portArray.resize(length); + for (unsigned i = 0 ; i < length; ++i) { + JSValue value = object->get(exec, i); + if (exec->hadException()) + return; + // Validation of non-null objects, per HTML5 spec 8.3.3. + if (value.isUndefinedOrNull()) { + setDOMException(exec, INVALID_STATE_ERR); + return; + } + + // Validation of Objects implementing an interface, per WebIDL spec 4.1.15. + RefPtr<MessagePort> port = toMessagePort(value); + if (!port) { + throwTypeError(exec); + return; + } + portArray[i] = port.release(); + } +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSMessagePortCustom.h b/Source/WebCore/bindings/js/JSMessagePortCustom.h new file mode 100644 index 0000000..8396ae1 --- /dev/null +++ b/Source/WebCore/bindings/js/JSMessagePortCustom.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSMessagePortCustom_h +#define JSMessagePortCustom_h + +#include "MessagePort.h" +#include <runtime/JSValue.h> +#include <wtf/Forward.h> + +namespace WebCore { + + typedef int ExceptionCode; + + // Helper function which pulls the values out of a JS sequence and into a MessagePortArray. + // Also validates the elements per sections 4.1.13 and 4.1.15 of the WebIDL spec and section 8.3.3 of the HTML5 spec. + // May generate an exception via the passed ExecState. + void fillMessagePortArray(JSC::ExecState*, JSC::JSValue, MessagePortArray&); + + // Helper function to convert from JS postMessage arguments to WebCore postMessage arguments. + template <typename T> + inline JSC::JSValue handlePostMessage(JSC::ExecState* exec, T* impl) + { + PassRefPtr<SerializedScriptValue> message = SerializedScriptValue::create(exec, exec->argument(0)); + MessagePortArray portArray; + fillMessagePortArray(exec, exec->argument(1), portArray); + if (exec->hadException()) + return JSC::jsUndefined(); + + ExceptionCode ec = 0; + impl->postMessage(message, &portArray, ec); + setDOMException(exec, ec); + return JSC::jsUndefined(); + } + +} +#endif // JSMessagePortCustom_h diff --git a/Source/WebCore/bindings/js/JSNamedNodeMapCustom.cpp b/Source/WebCore/bindings/js/JSNamedNodeMapCustom.cpp new file mode 100644 index 0000000..8df9304 --- /dev/null +++ b/Source/WebCore/bindings/js/JSNamedNodeMapCustom.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSNamedNodeMap.h" + +#include "JSNode.h" + +#include "Element.h" +#include "NamedNodeMap.h" + +using namespace JSC; + +namespace WebCore { + +bool JSNamedNodeMap::canGetItemsForName(ExecState*, NamedNodeMap* impl, const Identifier& propertyName) +{ + return impl->getNamedItem(identifierToString(propertyName)); +} + +JSValue JSNamedNodeMap::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSNamedNodeMap* thisObj = static_cast<JSNamedNodeMap*>(asObject(slotBase)); + return toJS(exec, thisObj->impl()->getNamedItem(identifierToString(propertyName))); +} + +void JSNamedNodeMap::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + // Mark the element so that this will work to access the attribute even if the last + // other reference goes away. + if (Element* element = impl()->element()) + markDOMNodeWrapper(markStack, element->document(), element); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSNavigatorCustom.cpp b/Source/WebCore/bindings/js/JSNavigatorCustom.cpp new file mode 100644 index 0000000..a190b60 --- /dev/null +++ b/Source/WebCore/bindings/js/JSNavigatorCustom.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org) + * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All Rights Reserved. + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSNavigator.h" + +#include "ExceptionCode.h" +#include "Navigator.h" +#include <runtime/InternalFunction.h> + +#if PLATFORM(ANDROID) +#include "JSCustomApplicationInstalledCallback.h" +#endif + +namespace WebCore { + +using namespace JSC; + +void JSNavigator::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + markDOMObjectWrapper(markStack, globalData, impl()->optionalGeolocation()); +} + +#if PLATFORM(ANDROID) && ENABLE(APPLICATION_INSTALLED) + +JSC::JSValue WebCore::JSNavigator::isApplicationInstalled(JSC::ExecState* exec) +{ + if (exec->argumentCount() < 2) { + setDOMException(exec, SYNTAX_ERR); + return jsUndefined(); + } + + if (!exec->argument(1).inherits(&InternalFunction::info)) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + String appName = ustringToString(exec->argument(0).toString(exec)); + + JSObject* object; + if (!(object = exec->argument(1).getObject())) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + RefPtr<ApplicationInstalledCallback> callback(JSCustomApplicationInstalledCallback::create( + object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject()))); + + if (!m_impl->isApplicationInstalled(appName, callback.release())) + setDOMException(exec, INVALID_STATE_ERR); + return jsUndefined(); +} + +#endif + +} diff --git a/Source/WebCore/bindings/js/JSNodeCustom.cpp b/Source/WebCore/bindings/js/JSNodeCustom.cpp new file mode 100644 index 0000000..a0963b8 --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeCustom.cpp @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSNode.h" + +#include "Attr.h" +#include "CDATASection.h" +#include "Comment.h" +#include "Document.h" +#include "DocumentFragment.h" +#include "DocumentType.h" +#include "Entity.h" +#include "EntityReference.h" +#include "ExceptionCode.h" +#include "HTMLElement.h" +#include "JSAttr.h" +#include "JSCDATASection.h" +#include "JSComment.h" +#include "JSDOMBinding.h" +#include "JSDocument.h" +#include "JSDocumentFragment.h" +#include "JSDocumentType.h" +#include "JSEntity.h" +#include "JSEntityReference.h" +#include "JSEventListener.h" +#include "JSHTMLElement.h" +#include "JSHTMLElementWrapperFactory.h" +#include "JSNotation.h" +#include "JSProcessingInstruction.h" +#include "JSText.h" +#include "Node.h" +#include "Notation.h" +#include "ProcessingInstruction.h" +#include "RegisteredEventListener.h" +#include "Text.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +#if ENABLE(SVG) +#include "JSSVGElementWrapperFactory.h" +#include "SVGElement.h" +#endif + +using namespace JSC; + +namespace WebCore { + +JSValue JSNode::insertBefore(ExecState* exec) +{ + Node* imp = static_cast<Node*>(impl()); + ExceptionCode ec = 0; + bool ok = imp->insertBefore(toNode(exec->argument(0)), toNode(exec->argument(1)), ec, true); + setDOMException(exec, ec); + if (ok) + return exec->argument(0); + return jsNull(); +} + +JSValue JSNode::replaceChild(ExecState* exec) +{ + Node* imp = static_cast<Node*>(impl()); + ExceptionCode ec = 0; + bool ok = imp->replaceChild(toNode(exec->argument(0)), toNode(exec->argument(1)), ec, true); + setDOMException(exec, ec); + if (ok) + return exec->argument(1); + return jsNull(); +} + +JSValue JSNode::removeChild(ExecState* exec) +{ + Node* imp = static_cast<Node*>(impl()); + ExceptionCode ec = 0; + bool ok = imp->removeChild(toNode(exec->argument(0)), ec); + setDOMException(exec, ec); + if (ok) + return exec->argument(0); + return jsNull(); +} + +JSValue JSNode::appendChild(ExecState* exec) +{ + Node* imp = static_cast<Node*>(impl()); + ExceptionCode ec = 0; + bool ok = imp->appendChild(toNode(exec->argument(0)), ec, true); + setDOMException(exec, ec); + if (ok) + return exec->argument(0); + return jsNull(); +} + +void JSNode::pushEventHandlerScope(ExecState*, ScopeChain&) const +{ +} + +void JSNode::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + Node* node = m_impl.get(); + node->markJSEventListeners(markStack); + + // Nodes in the document are kept alive by JSDocument::mark, so, if we're in + // the document, we need to mark the document, but we don't need to explicitly + // mark any other nodes. + if (node->inDocument()) { + // FIXME: Do we really want to call a virtual function, ownerDocument here, + // when the non-virtual inline function, document, is so much faster?! + if (Document* doc = node->ownerDocument()) + markDOMNodeWrapper(markStack, doc, doc); + return; + } + + // This is a node outside the document. + // Find the the root, and the highest ancestor with a wrapper. + Node* root = node; + Node* outermostNodeWithWrapper = node; + for (Node* current = m_impl.get(); current; current = current->parentNode()) { + root = current; + if (hasCachedDOMNodeWrapperUnchecked(current->document(), current)) + outermostNodeWithWrapper = current; + } + + // Only nodes that have no ancestors with wrappers mark the subtree. In the common + // case, the root of the detached subtree has a wrapper, so the tree will only + // get marked once. Nodes that aren't outermost need to mark the outermost + // in case it is otherwise unreachable. + // FIXME: In the non-common case of root not having a wrapper, this is still an O(n^2) algorithm, + // as we will traverse the whole tree as many times as there are nodes with wrappers in it. + if (node != outermostNodeWithWrapper) { + markDOMNodeWrapper(markStack, m_impl->document(), outermostNodeWithWrapper); + return; + } + + // Mark the whole tree subtree. + for (Node* nodeToMark = root; nodeToMark; nodeToMark = nodeToMark->traverseNextNode()) + markDOMNodeWrapper(markStack, m_impl->document(), nodeToMark); +} + +static ALWAYS_INLINE JSValue createWrapperInline(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node) +{ + ASSERT(node); + ASSERT(!getCachedDOMNodeWrapper(exec, node->document(), node)); + + JSNode* wrapper; + switch (node->nodeType()) { + case Node::ELEMENT_NODE: + if (node->isHTMLElement()) + wrapper = createJSHTMLWrapper(exec, globalObject, static_cast<HTMLElement*>(node)); +#if ENABLE(SVG) + else if (node->isSVGElement()) + wrapper = createJSSVGWrapper(exec, globalObject, static_cast<SVGElement*>(node)); +#endif + else + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Element, node); + break; + case Node::ATTRIBUTE_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Attr, node); + break; + case Node::TEXT_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Text, node); + break; + case Node::CDATA_SECTION_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, CDATASection, node); + break; + case Node::ENTITY_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Entity, node); + break; + case Node::PROCESSING_INSTRUCTION_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, ProcessingInstruction, node); + break; + case Node::COMMENT_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Comment, node); + break; + case Node::DOCUMENT_NODE: + // we don't want to cache the document itself in the per-document dictionary + return toJS(exec, globalObject, static_cast<Document*>(node)); + case Node::DOCUMENT_TYPE_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, DocumentType, node); + break; + case Node::NOTATION_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Notation, node); + break; + case Node::DOCUMENT_FRAGMENT_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, DocumentFragment, node); + break; + case Node::ENTITY_REFERENCE_NODE: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, EntityReference, node); + break; + default: + wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Node, node); + } + + return wrapper; +} + +JSValue createWrapper(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node) +{ + return createWrapperInline(exec, globalObject, node); +} + +JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Node* node) +{ + if (!node) + return jsNull(); + + return createWrapperInline(exec, globalObject, node); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSNodeCustom.h b/Source/WebCore/bindings/js/JSNodeCustom.h new file mode 100644 index 0000000..9d06ae6 --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeCustom.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSNodeCustom_h +#define JSNodeCustom_h + +#include "JSDOMBinding.h" +#include <wtf/AlwaysInline.h> + +namespace WebCore { + +inline JSNode* getCachedDOMNodeWrapper(JSC::ExecState* exec, Document* document, Node* node) +{ + if (currentWorld(exec)->isNormal()) { + ASSERT(node->wrapper() == (document ? document->getWrapperCache(currentWorld(exec))->get(node) : domObjectWrapperMapFor(exec).get(node))); + return static_cast<JSNode*>(node->wrapper()); + } + + if (document) + return document->getWrapperCache(currentWorld(exec))->get(node); + return static_cast<JSNode*>(domObjectWrapperMapFor(exec).get(node)); +} + +JSC::JSValue createWrapper(JSC::ExecState*, JSDOMGlobalObject*, Node*); + +inline JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Node* node) +{ + if (!node) + return JSC::jsNull(); + + JSNode* wrapper = getCachedDOMNodeWrapper(exec, node->document(), node); + if (wrapper) + return wrapper; + + return createWrapper(exec, globalObject, node); +} + +} + +#endif // JSDOMNodeCustom_h diff --git a/Source/WebCore/bindings/js/JSNodeFilterCondition.cpp b/Source/WebCore/bindings/js/JSNodeFilterCondition.cpp new file mode 100644 index 0000000..b269e5f --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeFilterCondition.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSNodeFilterCondition.h" + +#include "JSNode.h" +#include "JSNodeFilter.h" +#include "NodeFilter.h" +#include <runtime/Error.h> +#include <runtime/JSLock.h> + +namespace WebCore { + +using namespace JSC; + +ASSERT_CLASS_FITS_IN_CELL(JSNodeFilterCondition); + +JSNodeFilterCondition::JSNodeFilterCondition(JSValue filter) + : m_filter(filter) +{ +} + +void JSNodeFilterCondition::markAggregate(MarkStack& markStack) +{ + markStack.append(m_filter); +} + +short JSNodeFilterCondition::acceptNode(JSC::ExecState* exec, Node* filterNode) const +{ + JSLock lock(SilenceAssertionsOnly); + + if (!m_filter.isObject()) + return NodeFilter::FILTER_ACCEPT; + + // The exec argument here should only be null if this was called from a + // non-JavaScript language, and this is a JavaScript filter, and the document + // in question is not associated with the frame. In that case, we're going to + // behave incorrectly, and just reject nodes instead of calling the filter function. + // To fix that we'd need to come up with a way to find a suitable JavaScript + // execution context for the filter function to run in. + if (!exec) + return NodeFilter::FILTER_REJECT; + + JSValue function = m_filter; + CallData callData; + CallType callType = getCallData(function, callData); + if (callType == CallTypeNone) { + function = m_filter.get(exec, Identifier(exec, "acceptNode")); + callType = getCallData(function, callData); + if (callType == CallTypeNone) { + throwError(exec, createTypeError(exec, "NodeFilter object does not have an acceptNode function")); + return NodeFilter::FILTER_REJECT; + } + } + + MarkedArgumentBuffer args; + // FIXME: The node should have the prototype chain that came from its document, not + // whatever prototype chain might be on the window this filter came from. Bug 27662 + args.append(toJS(exec, deprecatedGlobalObjectForPrototype(exec), filterNode)); + if (exec->hadException()) + return NodeFilter::FILTER_REJECT; + + JSValue result = JSC::call(exec, function, callType, callData, m_filter, args); + if (exec->hadException()) + return NodeFilter::FILTER_REJECT; + + int intResult = result.toInt32(exec); + if (exec->hadException()) + return NodeFilter::FILTER_REJECT; + + return intResult; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSNodeFilterCondition.h b/Source/WebCore/bindings/js/JSNodeFilterCondition.h new file mode 100644 index 0000000..b96534a --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeFilterCondition.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSNodeFilterCondition_h +#define JSNodeFilterCondition_h + +#include "NodeFilterCondition.h" +#include <runtime/JSValue.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + + class Node; + + class JSNodeFilterCondition : public NodeFilterCondition { + public: + static PassRefPtr<JSNodeFilterCondition> create(JSC::JSValue filter) + { + return adoptRef(new JSNodeFilterCondition(filter)); + } + + private: + JSNodeFilterCondition(JSC::JSValue filter); + + virtual short acceptNode(ScriptState*, Node*) const; + virtual void markAggregate(JSC::MarkStack&); + + mutable JSC::JSValue m_filter; + }; + +} // namespace WebCore + +#endif // JSNodeFilterCondition_h diff --git a/Source/WebCore/bindings/js/JSNodeFilterCustom.cpp b/Source/WebCore/bindings/js/JSNodeFilterCustom.cpp new file mode 100644 index 0000000..bb90c4f --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeFilterCustom.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSNodeFilter.h" + +#include "JSNode.h" +#include "JSNodeFilterCondition.h" +#include "NodeFilter.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +void JSNodeFilter::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + impl()->markAggregate(markStack); +} + +PassRefPtr<NodeFilter> toNodeFilter(JSValue value) +{ + if (value.inherits(&JSNodeFilter::s_info)) + return static_cast<JSNodeFilter*>(asObject(value))->impl(); + + return NodeFilter::create(JSNodeFilterCondition::create(value)); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSNodeIteratorCustom.cpp b/Source/WebCore/bindings/js/JSNodeIteratorCustom.cpp new file mode 100644 index 0000000..7c858e5 --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeIteratorCustom.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSNodeIterator.h" + +#include "JSNode.h" +#include "Node.h" +#include "NodeFilter.h" +#include "NodeIterator.h" + +using namespace JSC; + +namespace WebCore { + +void JSNodeIterator::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (NodeFilter* filter = m_impl->filter()) + filter->markAggregate(markStack); +} + +} diff --git a/Source/WebCore/bindings/js/JSNodeListCustom.cpp b/Source/WebCore/bindings/js/JSNodeListCustom.cpp new file mode 100644 index 0000000..c81914c --- /dev/null +++ b/Source/WebCore/bindings/js/JSNodeListCustom.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSNodeList.h" + +#include "JSNode.h" +#include "Node.h" +#include "NodeList.h" +#include <wtf/text/AtomicString.h> + +using namespace JSC; + +namespace WebCore { + +// Need to support call so that list(0) works. +static EncodedJSValue JSC_HOST_CALL callNodeList(ExecState* exec) +{ + bool ok; + unsigned index = Identifier::toUInt32(exec->argument(0).toString(exec), ok); + if (!ok) + return JSValue::encode(jsUndefined()); + return JSValue::encode(toJS(exec, static_cast<JSNodeList*>(exec->callee())->impl()->item(index))); +} + +CallType JSNodeList::getCallData(CallData& callData) +{ + callData.native.function = callNodeList; + return CallTypeHost; +} + +bool JSNodeList::canGetItemsForName(ExecState*, NodeList* impl, const Identifier& propertyName) +{ + return impl->itemWithName(identifierToAtomicString(propertyName)); +} + +JSValue JSNodeList::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSNodeList* thisObj = static_cast<JSNodeList*>(asObject(slotBase)); + return toJS(exec, thisObj->impl()->itemWithName(identifierToAtomicString(propertyName))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSOptionConstructor.cpp b/Source/WebCore/bindings/js/JSOptionConstructor.cpp new file mode 100644 index 0000000..4ecfe58 --- /dev/null +++ b/Source/WebCore/bindings/js/JSOptionConstructor.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSOptionConstructor.h" + +#include "HTMLNames.h" +#include "HTMLOptionElement.h" +#include "JSHTMLOptionElement.h" +#include "ScriptExecutionContext.h" +#include "Text.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSOptionConstructor); + +const ClassInfo JSOptionConstructor::s_info = { "OptionConstructor", 0, 0, 0 }; + +JSOptionConstructor::JSOptionConstructor(ExecState* exec, JSDOMGlobalObject* globalObject) + : DOMConstructorWithDocument(JSOptionConstructor::createStructure(globalObject->objectPrototype()), globalObject) +{ + putDirect(exec->propertyNames().prototype, JSHTMLOptionElementPrototype::self(exec, globalObject), None); + putDirect(exec->propertyNames().length, jsNumber(4), ReadOnly | DontDelete | DontEnum); +} + +static EncodedJSValue JSC_HOST_CALL constructHTMLOptionElement(ExecState* exec) +{ + JSOptionConstructor* jsConstructor = static_cast<JSOptionConstructor*>(exec->callee()); + Document* document = jsConstructor->document(); + if (!document) + return throwVMError(exec, createReferenceError(exec, "Option constructor associated document is unavailable")); + + String data; + if ((exec->argumentCount() >= 1) && !exec->argument(0).isUndefined()) + data = ustringToString(exec->argument(0).toString(exec)); + + String value; + if ((exec->argumentCount() >= 2) && !exec->argument(1).isUndefined()) + value = ustringToString(exec->argument(1).toString(exec)); + bool defaultSelected = (exec->argumentCount() >= 3) && exec->argument(2).toBoolean(exec); + bool selected = (exec->argumentCount() >= 4) && exec->argument(3).toBoolean(exec); + + ExceptionCode ec = 0; + RefPtr<HTMLOptionElement> element = HTMLOptionElement::createForJSConstructor(document, data, value, defaultSelected, selected, ec); + if (ec) { + setDOMException(exec, ec); + return JSValue::encode(JSValue()); + } + + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), element.release()))); +} + +ConstructType JSOptionConstructor::getConstructData(ConstructData& constructData) +{ + constructData.native.function = constructHTMLOptionElement; + return ConstructTypeHost; +} + + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSOptionConstructor.h b/Source/WebCore/bindings/js/JSOptionConstructor.h new file mode 100644 index 0000000..246e7fa --- /dev/null +++ b/Source/WebCore/bindings/js/JSOptionConstructor.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef JSOptionConstructor_h +#define JSOptionConstructor_h + +#include "JSDOMBinding.h" +#include "JSDocument.h" +#include <wtf/RefPtr.h> + +namespace WebCore { + + class JSOptionConstructor : public DOMConstructorWithDocument { + public: + JSOptionConstructor(JSC::ExecState*, JSDOMGlobalObject*); + + static const JSC::ClassInfo s_info; + private: + virtual JSC::ConstructType getConstructData(JSC::ConstructData&); + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + }; + +} // namespace WebCore + +#endif // JSOptionConstructor_h diff --git a/Source/WebCore/bindings/js/JSPluginElementFunctions.cpp b/Source/WebCore/bindings/js/JSPluginElementFunctions.cpp new file mode 100644 index 0000000..893b967 --- /dev/null +++ b/Source/WebCore/bindings/js/JSPluginElementFunctions.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "JSPluginElementFunctions.h" + +#include "Bridge.h" +#include "HTMLNames.h" +#include "HTMLPlugInElement.h" +#include "JSHTMLElement.h" +#include "PluginViewBase.h" + +using namespace JSC; + +namespace WebCore { + +using namespace Bindings; +using namespace HTMLNames; + +// Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement. + +static inline bool isPluginElement(Node* node) +{ + return node->hasTagName(objectTag) || node->hasTagName(embedTag) || node->hasTagName(appletTag); +} + +Instance* pluginInstance(Node* node) +{ + if (!node) + return 0; + if (!isPluginElement(node)) + return 0; + + HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(node); + // The plugin element holds an owning reference, so we don't have to. + Instance* instance = plugInElement->getInstance().get(); + if (!instance || !instance->rootObject()) + return 0; + return instance; +} + +static JSObject* pluginScriptObjectFromPluginViewBase(HTMLPlugInElement* pluginElement, JSGlobalObject* globalObject) +{ + Widget* pluginWidget = pluginElement->pluginWidget(); + if (!pluginWidget) + return 0; + + if (!pluginWidget->isPluginViewBase()) + return 0; + + PluginViewBase* pluginViewBase = static_cast<PluginViewBase*>(pluginWidget); + return pluginViewBase->scriptObject(globalObject); +} + +static JSObject* pluginScriptObjectFromPluginViewBase(JSHTMLElement* jsHTMLElement) +{ + HTMLElement* element = jsHTMLElement->impl(); + if (!isPluginElement(element)) + return 0; + + HTMLPlugInElement* pluginElement = static_cast<HTMLPlugInElement*>(element); + return pluginScriptObjectFromPluginViewBase(pluginElement, jsHTMLElement->globalObject()); +} + +JSObject* pluginScriptObject(ExecState* exec, JSHTMLElement* jsHTMLElement) +{ + HTMLElement* element = jsHTMLElement->impl(); + if (!isPluginElement(element)) + return 0; + + HTMLPlugInElement* pluginElement = static_cast<HTMLPlugInElement*>(element); + + // First, see if we can ask the plug-in view for its script object. + if (JSObject* scriptObject = pluginScriptObjectFromPluginViewBase(pluginElement, jsHTMLElement->globalObject())) + return scriptObject; + + // Otherwise, fall back to getting the object from the instance. + + // The plugin element holds an owning reference, so we don't have to. + Instance* instance = pluginElement->getInstance().get(); + if (!instance || !instance->rootObject()) + return 0; + + return instance->createRuntimeObject(exec); +} + +JSValue runtimeObjectPropertyGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSHTMLElement* element = static_cast<JSHTMLElement*>(asObject(slotBase)); + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) + return jsUndefined(); + + return scriptObject->get(exec, propertyName); +} + +bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, JSHTMLElement* element) +{ + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) + return false; + + if (!scriptObject->hasProperty(exec, propertyName)) + return false; + slot.setCustom(element, runtimeObjectPropertyGetter); + return true; +} + +bool runtimeObjectCustomGetOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, JSHTMLElement* element) +{ + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) + return false; + if (!scriptObject->hasProperty(exec, propertyName)) + return false; + PropertySlot slot; + slot.setCustom(element, runtimeObjectPropertyGetter); + // While we don't know what the plugin allows, we do know that we prevent + // enumeration or deletion of properties, so we mark plugin properties + // as DontEnum | DontDelete + descriptor.setDescriptor(slot.getValue(exec, propertyName), DontEnum | DontDelete); + return true; +} + +bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue value, JSHTMLElement* element, PutPropertySlot& slot) +{ + JSObject* scriptObject = pluginScriptObject(exec, element); + if (!scriptObject) + return 0; + if (!scriptObject->hasProperty(exec, propertyName)) + return false; + scriptObject->put(exec, propertyName, value, slot); + return true; +} + +static EncodedJSValue JSC_HOST_CALL callPlugin(ExecState* exec) +{ + JSHTMLElement* element = static_cast<JSHTMLElement*>(exec->callee()); + + // Get the plug-in script object. + JSObject* scriptObject = pluginScriptObject(exec, element); + ASSERT(scriptObject); + + size_t argumentCount = exec->argumentCount(); + MarkedArgumentBuffer argumentList; + for (size_t i = 0; i < argumentCount; i++) + argumentList.append(exec->argument(i)); + + CallData callData; + CallType callType = getCallData(scriptObject, callData); + ASSERT(callType == CallTypeHost); + + // Call the object. + JSValue result = call(exec, scriptObject, callType, callData, exec->hostThisValue(), argumentList); + return JSValue::encode(result); +} + +CallType runtimeObjectGetCallData(JSHTMLElement* element, CallData& callData) +{ + // First, ask the plug-in view base for its runtime object. + if (JSObject* scriptObject = pluginScriptObjectFromPluginViewBase(element)) { + CallData scriptObjectCallData; + + if (scriptObject->getCallData(scriptObjectCallData) == CallTypeNone) + return CallTypeNone; + + callData.native.function = callPlugin; + return CallTypeHost; + } + + Instance* instance = pluginInstance(element->impl()); + if (!instance || !instance->supportsInvokeDefaultMethod()) + return CallTypeNone; + callData.native.function = callPlugin; + return CallTypeHost; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSPluginElementFunctions.h b/Source/WebCore/bindings/js/JSPluginElementFunctions.h new file mode 100644 index 0000000..15af59a --- /dev/null +++ b/Source/WebCore/bindings/js/JSPluginElementFunctions.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 1999 Harri Porten (porten@kde.org) + * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef JSPluginElementFunctions_h +#define JSPluginElementFunctions_h + +#include "JSDOMBinding.h" + +namespace JSC { +namespace Bindings { +class Instance; +} +} + +namespace WebCore { + + class HTMLElement; + class JSHTMLElement; + class Node; + + // Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement. + JSC::Bindings::Instance* pluginInstance(Node*); + JSC::JSObject* pluginScriptObject(JSC::ExecState* exec, JSHTMLElement* jsHTMLElement); + + JSC::JSValue runtimeObjectPropertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&); + bool runtimeObjectCustomGetOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&, JSHTMLElement*); + bool runtimeObjectCustomGetOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&, JSHTMLElement*); + bool runtimeObjectCustomPut(JSC::ExecState*, const JSC::Identifier&, JSC::JSValue, JSHTMLElement*, JSC::PutPropertySlot&); + JSC::CallType runtimeObjectGetCallData(JSHTMLElement*, JSC::CallData&); + +} // namespace WebCore + +#endif // JSPluginElementFunctions_h diff --git a/Source/WebCore/bindings/js/JSProcessingInstructionCustom.cpp b/Source/WebCore/bindings/js/JSProcessingInstructionCustom.cpp new file mode 100644 index 0000000..868e319 --- /dev/null +++ b/Source/WebCore/bindings/js/JSProcessingInstructionCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSProcessingInstruction.h" + +#include "ProcessingInstruction.h" + +using namespace JSC; + +namespace WebCore { + +void JSProcessingInstruction::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (StyleSheet* sheet = static_cast<ProcessingInstruction*>(impl())->sheet()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), sheet); +} + +} diff --git a/Source/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp b/Source/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp new file mode 100644 index 0000000..7274cd0 --- /dev/null +++ b/Source/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSSQLResultSetRowList.h" + +#if ENABLE(DATABASE) + +#include "ExceptionCode.h" +#include "SQLValue.h" +#include "SQLResultSetRowList.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSSQLResultSetRowList::item(ExecState* exec) +{ + bool indexOk; + int index = finiteInt32Value(exec->argument(0), exec, indexOk); + if (!indexOk) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + if (index < 0 || (unsigned)index >= m_impl->length()) { + setDOMException(exec, INDEX_SIZE_ERR); + return jsUndefined(); + } + + JSObject* object = constructEmptyObject(exec); + + unsigned numColumns = m_impl->columnNames().size(); + unsigned valuesIndex = index * numColumns; + for (unsigned i = 0; i < numColumns; i++) { + const SQLValue& value = m_impl->values()[valuesIndex + i]; + JSValue jsValue; + + switch (value.type()) { + case SQLValue::StringValue: + jsValue = jsString(exec, value.string()); + break; + case SQLValue::NullValue: + jsValue = jsNull(); + break; + case SQLValue::NumberValue: + jsValue = jsNumber(value.number()); + break; + default: + ASSERT_NOT_REACHED(); + } + + object->putDirect(Identifier(exec, stringToUString(m_impl->columnNames()[i])), jsValue, DontDelete | ReadOnly); + } + + return object; +} + +} + +#endif diff --git a/Source/WebCore/bindings/js/JSSQLTransactionCustom.cpp b/Source/WebCore/bindings/js/JSSQLTransactionCustom.cpp new file mode 100644 index 0000000..e32ea55 --- /dev/null +++ b/Source/WebCore/bindings/js/JSSQLTransactionCustom.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSSQLTransaction.h" + +#if ENABLE(DATABASE) + +#include "DOMWindow.h" +#include "ExceptionCode.h" +#include "JSSQLStatementCallback.h" +#include "JSSQLStatementErrorCallback.h" +#include "JSDOMWindowCustom.h" +#include "SQLTransaction.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSSQLTransaction::executeSql(ExecState* exec) +{ + if (!exec->argumentCount()) { + setDOMException(exec, SYNTAX_ERR); + return jsUndefined(); + } + + String sqlStatement = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return jsUndefined(); + + // Now assemble the list of SQL arguments + Vector<SQLValue> sqlValues; + if (!exec->argument(1).isUndefinedOrNull()) { + JSObject* object = exec->argument(1).getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + JSValue lengthValue = object->get(exec, exec->propertyNames().length); + if (exec->hadException()) + return jsUndefined(); + unsigned length = lengthValue.toUInt32(exec); + if (exec->hadException()) + return jsUndefined(); + + for (unsigned i = 0 ; i < length; ++i) { + JSValue value = object->get(exec, i); + if (exec->hadException()) + return jsUndefined(); + + if (value.isUndefinedOrNull()) + sqlValues.append(SQLValue()); + else if (value.isNumber()) + sqlValues.append(value.uncheckedGetNumber()); + else { + // Convert the argument to a string and append it + sqlValues.append(ustringToString(value.toString(exec))); + if (exec->hadException()) + return jsUndefined(); + } + } + } + + RefPtr<SQLStatementCallback> callback; + if (!exec->argument(2).isUndefinedOrNull()) { + JSObject* object = exec->argument(2).getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + callback = JSSQLStatementCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); + } + + RefPtr<SQLStatementErrorCallback> errorCallback; + if (!exec->argument(3).isUndefinedOrNull()) { + JSObject* object = exec->argument(3).getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + errorCallback = JSSQLStatementErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(globalObject())); + } + + ExceptionCode ec = 0; + m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec); + setDOMException(exec, ec); + + return jsUndefined(); +} + +} + +#endif // ENABLE(DATABASE) diff --git a/Source/WebCore/bindings/js/JSSQLTransactionSyncCustom.cpp b/Source/WebCore/bindings/js/JSSQLTransactionSyncCustom.cpp new file mode 100644 index 0000000..08f42e8 --- /dev/null +++ b/Source/WebCore/bindings/js/JSSQLTransactionSyncCustom.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSSQLTransactionSync.h" + +#if ENABLE(DATABASE) + +#include "ExceptionCode.h" +#include "JSSQLResultSet.h" +#include "SQLResultSet.h" +#include "SQLTransactionSync.h" +#include "SQLValue.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSSQLTransactionSync::executeSql(ExecState* exec) +{ + if (!exec->argumentCount()) { + setDOMException(exec, SYNTAX_ERR); + return jsUndefined(); + } + + String sqlStatement = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return jsUndefined(); + + // Now assemble the list of SQL arguments + Vector<SQLValue> sqlValues; + if (!exec->argument(1).isUndefinedOrNull()) { + JSObject* object = exec->argument(1).getObject(); + if (!object) { + setDOMException(exec, TYPE_MISMATCH_ERR); + return jsUndefined(); + } + + JSValue lengthValue = object->get(exec, exec->propertyNames().length); + if (exec->hadException()) + return jsUndefined(); + unsigned length = lengthValue.toUInt32(exec); + if (exec->hadException()) + return jsUndefined(); + + for (unsigned i = 0 ; i < length; ++i) { + JSValue value = object->get(exec, i); + if (exec->hadException()) + return jsUndefined(); + + if (value.isUndefinedOrNull()) + sqlValues.append(SQLValue()); + else if (value.isNumber()) + sqlValues.append(value.uncheckedGetNumber()); + else { + // Convert the argument to a string and append it + sqlValues.append(ustringToString(value.toString(exec))); + if (exec->hadException()) + return jsUndefined(); + } + } + } + + ExceptionCode ec = 0; + JSValue result = toJS(exec, globalObject(), WTF::getPtr(m_impl->executeSQL(sqlStatement, sqlValues, ec))); + setDOMException(exec, ec); + + return result; +} + +} + +#endif // ENABLE(DATABASE) diff --git a/Source/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp b/Source/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp new file mode 100644 index 0000000..dec4be0 --- /dev/null +++ b/Source/WebCore/bindings/js/JSSVGElementInstanceCustom.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2009 Apple, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSSVGElementInstance.h" + +#if ENABLE(SVG) +#include "SVGElementInstance.h" + +namespace WebCore { + +void JSSVGElementInstance::markChildren(JSC::MarkStack& markStack) +{ + Base::markChildren(markStack); + + // Mark the wrapper for our corresponding element, so it can mark its event handlers. + markDOMNodeWrapper(markStack, impl()->correspondingElement()->document(), impl()->correspondingElement()); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/bindings/js/JSSVGLengthCustom.cpp b/Source/WebCore/bindings/js/JSSVGLengthCustom.cpp new file mode 100644 index 0000000..5b668c4 --- /dev/null +++ b/Source/WebCore/bindings/js/JSSVGLengthCustom.cpp @@ -0,0 +1,100 @@ +/* + Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGLength.h" + +#include <runtime/Error.h> +#include "SVGAnimatedProperty.h" +#include "SVGException.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSSVGLength::value(ExecState* exec) const +{ + SVGLength& podImp = impl()->propertyReference(); + ExceptionCode ec = 0; + float value = podImp.value(impl()->contextElement(), ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + + return jsNumber(value); +} + +void JSSVGLength::setValue(ExecState* exec, JSValue value) +{ + if (impl()->role() == AnimValRole) { + setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR); + return; + } + + if (!value.isUndefinedOrNull() && !value.isNumber() && !value.isBoolean()) { + throwVMTypeError(exec); + return; + } + + SVGLength& podImp = impl()->propertyReference(); + + ExceptionCode ec = 0; + podImp.setValue(value.toFloat(exec), impl()->contextElement(), ec); + if (ec) { + setDOMException(exec, ec); + return; + } + + impl()->commitChange(); +} + +JSValue JSSVGLength::convertToSpecifiedUnits(ExecState* exec) +{ + if (impl()->role() == AnimValRole) { + setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR); + return jsUndefined(); + } + + SVGLength& podImp = impl()->propertyReference(); + + // Mimic the behaviour of RequiresAllArguments=Raise. + if (exec->argumentCount() < 1) + return throwError(exec, createSyntaxError(exec, "Not enough arguments")); + + unsigned short unitType = exec->argument(0).toUInt32(exec); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + podImp.convertToSpecifiedUnits(unitType, impl()->contextElement(), ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + + impl()->commitChange(); + return jsUndefined(); +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/bindings/js/JSSVGPathSegCustom.cpp b/Source/WebCore/bindings/js/JSSVGPathSegCustom.cpp new file mode 100644 index 0000000..f0aa86b --- /dev/null +++ b/Source/WebCore/bindings/js/JSSVGPathSegCustom.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "JSSVGPathSeg.h" + +#include "JSDOMBinding.h" +#include "JSSVGPathSegArcAbs.h" +#include "JSSVGPathSegArcRel.h" +#include "JSSVGPathSegClosePath.h" +#include "JSSVGPathSegCurvetoCubicAbs.h" +#include "JSSVGPathSegCurvetoCubicRel.h" +#include "JSSVGPathSegCurvetoCubicSmoothAbs.h" +#include "JSSVGPathSegCurvetoCubicSmoothRel.h" +#include "JSSVGPathSegCurvetoQuadraticAbs.h" +#include "JSSVGPathSegCurvetoQuadraticRel.h" +#include "JSSVGPathSegCurvetoQuadraticSmoothAbs.h" +#include "JSSVGPathSegCurvetoQuadraticSmoothRel.h" +#include "JSSVGPathSegLinetoAbs.h" +#include "JSSVGPathSegLinetoRel.h" +#include "JSSVGPathSegLinetoHorizontalAbs.h" +#include "JSSVGPathSegLinetoHorizontalRel.h" +#include "JSSVGPathSegLinetoVerticalAbs.h" +#include "JSSVGPathSegLinetoVerticalRel.h" +#include "JSSVGPathSegMovetoAbs.h" +#include "JSSVGPathSegMovetoRel.h" +#include "SVGPathSeg.h" +#include "SVGPathSegArc.h" +#include "SVGPathSegClosePath.h" +#include "SVGPathSegCurvetoCubic.h" +#include "SVGPathSegCurvetoCubicSmooth.h" +#include "SVGPathSegCurvetoQuadratic.h" +#include "SVGPathSegCurvetoQuadraticSmooth.h" +#include "SVGPathSegLineto.h" +#include "SVGPathSegLinetoHorizontal.h" +#include "SVGPathSegLinetoVertical.h" +#include "SVGPathSegMoveto.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, SVGPathSeg* object) +{ + if (!object) + return jsNull(); + + if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, object)) + return wrapper; + + switch (object->pathSegType()) { + case SVGPathSeg::PATHSEG_CLOSEPATH: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegClosePath, object); + case SVGPathSeg::PATHSEG_MOVETO_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegMovetoAbs, object); + case SVGPathSeg::PATHSEG_MOVETO_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegMovetoRel, object); + case SVGPathSeg::PATHSEG_LINETO_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoAbs, object); + case SVGPathSeg::PATHSEG_LINETO_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoRel, object); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicAbs, object); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicRel, object); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticAbs, object); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticRel, object); + case SVGPathSeg::PATHSEG_ARC_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegArcAbs, object); + case SVGPathSeg::PATHSEG_ARC_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegArcRel, object); + case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoHorizontalAbs, object); + case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoHorizontalRel, object); + case SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoVerticalAbs, object); + case SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoVerticalRel, object); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicSmoothAbs, object); + case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicSmoothRel, object); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticSmoothAbs, object); + case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticSmoothRel, object); + case SVGPathSeg::PATHSEG_UNKNOWN: + default: + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGPathSeg, object); + } +} + +} + +#endif // ENABLE(SVG) diff --git a/Source/WebCore/bindings/js/JSScriptProfileNodeCustom.cpp b/Source/WebCore/bindings/js/JSScriptProfileNodeCustom.cpp new file mode 100644 index 0000000..0c2a6a2 --- /dev/null +++ b/Source/WebCore/bindings/js/JSScriptProfileNodeCustom.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "JSScriptProfileNode.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include <profiler/ProfileNode.h> +#endif + +#include <runtime/JSArray.h> + +using namespace JSC; + +namespace WebCore { + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +JSValue JSScriptProfileNode::callUID(ExecState*) const +{ + JSValue result = jsNumber(impl()->callIdentifier().hash()); + return result; +} + +typedef Vector<RefPtr<ProfileNode> > ProfileNodesList; + +JSValue JSScriptProfileNode::children(ExecState* exec) const +{ + const ProfileNodesList& children = impl()->children(); + MarkedArgumentBuffer list; + + ProfileNodesList::const_iterator end = children.end(); + for (ProfileNodesList::const_iterator iter = children.begin(); iter != end; ++iter) + list.append(toJS(exec, iter->get())); + + return constructArray(exec, list); +} + +#endif + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSSharedWorkerCustom.cpp b/Source/WebCore/bindings/js/JSSharedWorkerCustom.cpp new file mode 100644 index 0000000..0d576e0 --- /dev/null +++ b/Source/WebCore/bindings/js/JSSharedWorkerCustom.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(SHARED_WORKERS) + +#include "JSSharedWorker.h" + +#include "JSDOMGlobalObject.h" +#include "JSDOMWindowCustom.h" +#include "SharedWorker.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +void JSSharedWorker::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (MessagePort* port = impl()->port()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), port); +} + +EncodedJSValue JSC_HOST_CALL JSSharedWorkerConstructor::constructJSSharedWorker(ExecState* exec) +{ + JSSharedWorkerConstructor* jsConstructor = static_cast<JSSharedWorkerConstructor*>(exec->callee()); + + if (exec->argumentCount() < 1) + return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); + + UString scriptURL = exec->argument(0).toString(exec); + UString name; + if (exec->argumentCount() > 1) + name = exec->argument(1).toString(exec); + + if (exec->hadException()) + return JSValue::encode(JSValue()); + + // FIXME: We need to use both the dynamic scope and the lexical scope (dynamic scope for resolving the worker URL) + DOMWindow* window = asJSDOMWindow(exec->lexicalGlobalObject())->impl(); + ExceptionCode ec = 0; + RefPtr<SharedWorker> worker = SharedWorker::create(ustringToString(scriptURL), ustringToString(name), window->document(), ec); + if (ec) { + setDOMException(exec, ec); + return JSValue::encode(JSValue()); + } + + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), worker.release()))); +} + +} // namespace WebCore + +#endif // ENABLE(SHARED_WORKERS) diff --git a/Source/WebCore/bindings/js/JSStorageCustom.cpp b/Source/WebCore/bindings/js/JSStorageCustom.cpp new file mode 100644 index 0000000..6a126b7 --- /dev/null +++ b/Source/WebCore/bindings/js/JSStorageCustom.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSStorageCustom.h" + +#if ENABLE(DOM_STORAGE) + +#include "PlatformString.h" +#include <runtime/PropertyNameArray.h> +#include "Storage.h" + +using namespace JSC; + +namespace WebCore { + +bool JSStorage::canGetItemsForName(ExecState*, Storage* impl, const Identifier& propertyName) +{ + return impl->contains(identifierToString(propertyName)); +} + +JSValue JSStorage::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSStorage* thisObj = static_cast<JSStorage*>(asObject(slotBase)); + return jsStringOrNull(exec, thisObj->impl()->getItem(identifierToString(propertyName))); +} + +bool JSStorage::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + // Only perform the custom delete if the object doesn't have a native property by this name. + // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check + // the native property slots manually. + PropertySlot slot; + if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot)) + return false; + + JSValue prototype = this->prototype(); + if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName)) + return false; + + m_impl->removeItem(identifierToString(propertyName)); + return true; +} + +void JSStorage::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + unsigned length = m_impl->length(); + for (unsigned i = 0; i < length; ++i) + propertyNames.add(Identifier(exec, stringToUString(m_impl->key(i)))); + + Base::getOwnPropertyNames(exec, propertyNames, mode); +} + +bool JSStorage::putDelegate(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot&) +{ + // Only perform the custom put if the object doesn't have a native property by this name. + // Since hasProperty() would end up calling canGetItemsForName() and be fooled, we need to check + // the native property slots manually. + PropertySlot slot; + if (getStaticValueSlot<JSStorage, Base>(exec, s_info.propHashTable(exec), this, propertyName, slot)) + return false; + + JSValue prototype = this->prototype(); + if (prototype.isObject() && asObject(prototype)->hasProperty(exec, propertyName)) + return false; + + String stringValue = ustringToString(value.toString(exec)); + if (exec->hadException()) + return true; + + ExceptionCode ec = 0; + impl()->setItem(identifierToString(propertyName), stringValue, ec); + setDOMException(exec, ec); + + return true; +} + +} // namespace WebCore + +#endif // ENABLE(DOM_STORAGE) diff --git a/Source/WebCore/bindings/js/JSStorageCustom.h b/Source/WebCore/bindings/js/JSStorageCustom.h new file mode 100644 index 0000000..45f62df --- /dev/null +++ b/Source/WebCore/bindings/js/JSStorageCustom.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSStorageCustom_h +#define JSStorageCustom_h + +#include "JSStorage.h" + +#endif // JSStorageCustom_h diff --git a/Source/WebCore/bindings/js/JSStyleSheetCustom.cpp b/Source/WebCore/bindings/js/JSStyleSheetCustom.cpp new file mode 100644 index 0000000..04c6561 --- /dev/null +++ b/Source/WebCore/bindings/js/JSStyleSheetCustom.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSStyleSheet.h" + +#include "CSSStyleSheet.h" +#include "Node.h" +#include "JSCSSStyleSheet.h" +#include "JSNode.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, StyleSheet* styleSheet) +{ + if (!styleSheet) + return jsNull(); + + DOMObject* wrapper = getCachedDOMObjectWrapper(exec, styleSheet); + if (wrapper) + return wrapper; + + if (styleSheet->isCSSStyleSheet()) + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CSSStyleSheet, styleSheet); + else + wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, StyleSheet, styleSheet); + + return wrapper; +} + +void JSStyleSheet::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + StyleSheet* sheet = impl(); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + unsigned length = sheet->length(); + for (unsigned i = 0; i < length; ++i) + markDOMObjectWrapper(markStack, globalData, sheet->item(i)); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSStyleSheetListCustom.cpp b/Source/WebCore/bindings/js/JSStyleSheetListCustom.cpp new file mode 100644 index 0000000..eb96a67 --- /dev/null +++ b/Source/WebCore/bindings/js/JSStyleSheetListCustom.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSStyleSheetList.h" + +#include "HTMLStyleElement.h" +#include "JSStyleSheet.h" +#include "StyleSheet.h" +#include "StyleSheetList.h" + +using namespace JSC; + +namespace WebCore { + +void JSStyleSheetList::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + StyleSheetList* list = impl(); + JSGlobalData& globalData = *Heap::heap(this)->globalData(); + + unsigned length = list->length(); + for (unsigned i = 0; i < length; ++i) + markDOMObjectWrapper(markStack, globalData, list->item(i)); +} + +bool JSStyleSheetList::canGetItemsForName(ExecState*, StyleSheetList* styleSheetList, const Identifier& propertyName) +{ + return styleSheetList->getNamedItem(identifierToString(propertyName)); +} + +JSValue JSStyleSheetList::nameGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName) +{ + JSStyleSheetList* thisObj = static_cast<JSStyleSheetList*>(asObject(slotBase)); + HTMLStyleElement* element = thisObj->impl()->getNamedItem(identifierToString(propertyName)); + ASSERT(element); + return toJS(exec, element->sheet()); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSTextCustom.cpp b/Source/WebCore/bindings/js/JSTextCustom.cpp new file mode 100644 index 0000000..2dc886d --- /dev/null +++ b/Source/WebCore/bindings/js/JSTextCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSText.h" + +#include "Text.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Text* text) +{ + if (!text) + return jsNull(); + + return CREATE_DOM_NODE_WRAPPER(exec, globalObject, Text, text); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSTouchCustom.cpp b/Source/WebCore/bindings/js/JSTouchCustom.cpp new file mode 100644 index 0000000..83c2b83 --- /dev/null +++ b/Source/WebCore/bindings/js/JSTouchCustom.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSTouch.h" + +#if ENABLE(TOUCH_EVENTS) + +#include "Touch.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, Touch* touch) +{ + if (!touch) + return jsNull(); + + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, Touch, touch); +} + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/bindings/js/JSTouchListCustom.cpp b/Source/WebCore/bindings/js/JSTouchListCustom.cpp new file mode 100644 index 0000000..22e0f95 --- /dev/null +++ b/Source/WebCore/bindings/js/JSTouchListCustom.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSTouchList.h" + +#if ENABLE(TOUCH_EVENTS) + +#include "TouchList.h" + +using namespace JSC; + +namespace WebCore { + +JSValue toJSNewlyCreated(ExecState* exec, JSDOMGlobalObject* globalObject, TouchList* touchList) +{ + if (!touchList) + return jsNull(); + + return CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TouchList, touchList); +} + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/bindings/js/JSTreeWalkerCustom.cpp b/Source/WebCore/bindings/js/JSTreeWalkerCustom.cpp new file mode 100644 index 0000000..0c1947f --- /dev/null +++ b/Source/WebCore/bindings/js/JSTreeWalkerCustom.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "JSTreeWalker.h" + +#include "JSNode.h" +#include "Node.h" +#include "NodeFilter.h" +#include "TreeWalker.h" + +using namespace JSC; + +namespace WebCore { + +void JSTreeWalker::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (NodeFilter* filter = m_impl->filter()) + filter->markAggregate(markStack); +} + +} diff --git a/Source/WebCore/bindings/js/JSUint16ArrayCustom.cpp b/Source/WebCore/bindings/js/JSUint16ArrayCustom.cpp new file mode 100644 index 0000000..6a024ee --- /dev/null +++ b/Source/WebCore/bindings/js/JSUint16ArrayCustom.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSUint16Array.h" + +#include "JSArrayBufferViewHelper.h" +#include "Uint16Array.h" + +using namespace JSC; + +namespace WebCore { + +void JSUint16Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<unsigned short>(value.toInt32(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Uint16Array* object) +{ + return getDOMObjectWrapper<JSUint16Array>(exec, globalObject, object); +} + +JSC::JSValue JSUint16Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toUint16Array); +} + +EncodedJSValue JSC_HOST_CALL JSUint16ArrayConstructor::constructJSUint16Array(ExecState* exec) +{ + JSUint16ArrayConstructor* jsConstructor = static_cast<JSUint16ArrayConstructor*>(exec->callee()); + RefPtr<Uint16Array> array = constructArrayBufferView<Uint16Array, unsigned short>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSUint32ArrayCustom.cpp b/Source/WebCore/bindings/js/JSUint32ArrayCustom.cpp new file mode 100644 index 0000000..34eb8de --- /dev/null +++ b/Source/WebCore/bindings/js/JSUint32ArrayCustom.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSUint32Array.h" + +#include "JSArrayBufferViewHelper.h" +#include "Uint32Array.h" + +using namespace JSC; + +namespace WebCore { + +void JSUint32Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<unsigned int>(value.toUInt32(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Uint32Array* object) +{ + return getDOMObjectWrapper<JSUint32Array>(exec, globalObject, object); +} + +JSC::JSValue JSUint32Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toUint32Array); +} + +EncodedJSValue JSC_HOST_CALL JSUint32ArrayConstructor::constructJSUint32Array(ExecState* exec) +{ + JSUint32ArrayConstructor* jsConstructor = static_cast<JSUint32ArrayConstructor*>(exec->callee()); + RefPtr<Uint32Array> array = constructArrayBufferView<Uint32Array, unsigned int>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSUint8ArrayCustom.cpp b/Source/WebCore/bindings/js/JSUint8ArrayCustom.cpp new file mode 100644 index 0000000..a9ed73f --- /dev/null +++ b/Source/WebCore/bindings/js/JSUint8ArrayCustom.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + +#include "JSUint8Array.h" + +#include "JSArrayBufferViewHelper.h" +#include "Uint8Array.h" + +using namespace JSC; + +namespace WebCore { + +void JSUint8Array::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) +{ + impl()->set(index, static_cast<unsigned char>(value.toInt32(exec))); +} + +JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, Uint8Array* object) +{ + return getDOMObjectWrapper<JSUint8Array>(exec, globalObject, object); +} + +JSC::JSValue JSUint8Array::set(JSC::ExecState* exec) +{ + return setWebGLArrayHelper(exec, impl(), toUint8Array); +} + +EncodedJSValue JSC_HOST_CALL JSUint8ArrayConstructor::constructJSUint8Array(ExecState* exec) +{ + JSUint8ArrayConstructor* jsConstructor = static_cast<JSUint8ArrayConstructor*>(exec->callee()); + RefPtr<Uint8Array> array = constructArrayBufferView<Uint8Array, unsigned char>(exec); + if (!array.get()) + // Exception has already been thrown. + return JSValue::encode(JSValue()); + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get()))); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) || ENABLE(BLOB) diff --git a/Source/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp b/Source/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp new file mode 100644 index 0000000..ed4a9ca --- /dev/null +++ b/Source/WebCore/bindings/js/JSWebGLRenderingContextCustom.cpp @@ -0,0 +1,702 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(3D_CANVAS) + +#include "JSWebGLRenderingContext.h" + +#include "WebKitLoseContext.h" +#include "ExceptionCode.h" +#include "HTMLCanvasElement.h" +#include "HTMLImageElement.h" +#include "JSWebKitLoseContext.h" +#include "JSHTMLCanvasElement.h" +#include "JSHTMLImageElement.h" +#include "JSImageData.h" +#include "JSOESTextureFloat.h" +#include "JSWebGLBuffer.h" +#include "JSFloat32Array.h" +#include "JSWebGLFramebuffer.h" +#include "JSInt32Array.h" +#include "JSWebGLProgram.h" +#include "JSWebGLRenderbuffer.h" +#include "JSWebGLShader.h" +#include "JSWebGLTexture.h" +#include "JSWebGLUniformLocation.h" +#include "JSUint8Array.h" +#include "JSWebKitCSSMatrix.h" +#include "NotImplemented.h" +#include "OESTextureFloat.h" +#include "WebGLBuffer.h" +#include "Float32Array.h" +#include "WebGLExtension.h" +#include "WebGLFramebuffer.h" +#include "WebGLGetInfo.h" +#include "Int32Array.h" +#include "WebGLProgram.h" +#include "WebGLRenderingContext.h" +#include <runtime/Error.h> +#include <runtime/JSArray.h> +#include <wtf/FastMalloc.h> +#include <wtf/OwnFastMallocPtr.h> + +#if ENABLE(VIDEO) +#include "HTMLVideoElement.h" +#include "JSHTMLVideoElement.h" +#endif + +using namespace JSC; + +namespace WebCore { + +static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, const WebGLGetInfo& info) +{ + switch (info.getType()) { + case WebGLGetInfo::kTypeBool: + return jsBoolean(info.getBool()); + case WebGLGetInfo::kTypeBoolArray: { + MarkedArgumentBuffer list; + const Vector<bool>& value = info.getBoolArray(); + for (size_t ii = 0; ii < value.size(); ++ii) + list.append(jsBoolean(value[ii])); + return constructArray(exec, list); + } + case WebGLGetInfo::kTypeFloat: + return jsNumber(info.getFloat()); + case WebGLGetInfo::kTypeLong: + return jsNumber(info.getLong()); + case WebGLGetInfo::kTypeNull: + return jsNull(); + case WebGLGetInfo::kTypeString: + return jsString(exec, info.getString()); + case WebGLGetInfo::kTypeUnsignedLong: + return jsNumber(info.getUnsignedLong()); + case WebGLGetInfo::kTypeWebGLBuffer: + return toJS(exec, globalObject, info.getWebGLBuffer()); + case WebGLGetInfo::kTypeWebGLFloatArray: + return toJS(exec, globalObject, info.getWebGLFloatArray()); + case WebGLGetInfo::kTypeWebGLFramebuffer: + return toJS(exec, globalObject, info.getWebGLFramebuffer()); + case WebGLGetInfo::kTypeWebGLIntArray: + return toJS(exec, globalObject, info.getWebGLIntArray()); + // FIXME: implement WebGLObjectArray + // case WebGLGetInfo::kTypeWebGLObjectArray: + case WebGLGetInfo::kTypeWebGLProgram: + return toJS(exec, globalObject, info.getWebGLProgram()); + case WebGLGetInfo::kTypeWebGLRenderbuffer: + return toJS(exec, globalObject, info.getWebGLRenderbuffer()); + case WebGLGetInfo::kTypeWebGLTexture: + return toJS(exec, globalObject, info.getWebGLTexture()); + case WebGLGetInfo::kTypeWebGLUnsignedByteArray: + return toJS(exec, globalObject, info.getWebGLUnsignedByteArray()); + default: + notImplemented(); + return jsUndefined(); + } +} + +enum ObjectType { + kBuffer, kRenderbuffer, kTexture, kVertexAttrib +}; + +static JSValue getObjectParameter(JSWebGLRenderingContext* obj, ExecState* exec, ObjectType objectType) +{ + if (exec->argumentCount() != 2) + return throwSyntaxError(exec); + + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(obj->impl()); + unsigned target = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + unsigned pname = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + WebGLGetInfo info; + switch (objectType) { + case kBuffer: + info = context->getBufferParameter(target, pname, ec); + break; + case kRenderbuffer: + info = context->getRenderbufferParameter(target, pname, ec); + break; + case kTexture: + info = context->getTexParameter(target, pname, ec); + break; + case kVertexAttrib: + // target => index + info = context->getVertexAttrib(target, pname, ec); + break; + default: + notImplemented(); + break; + } + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, obj->globalObject(), info); +} + +enum WhichProgramCall { + kProgramParameter, kUniform +}; + +static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, WebGLExtension* extension) +{ + if (!extension) + return jsNull(); + switch (extension->getName()) { + case WebGLExtension::WebKitLoseContextName: + return toJS(exec, globalObject, static_cast<WebKitLoseContext*>(extension)); + case WebGLExtension::OESTextureFloatName: + return toJS(exec, globalObject, static_cast<OESTextureFloat*>(extension)); + } + ASSERT_NOT_REACHED(); + return jsNull(); +} + +void JSWebGLRenderingContext::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + for (int i = 0; i < context->getNumberOfExtensions(); ++i) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), context->getExtensionNumber(i)); +} + +JSValue JSWebGLRenderingContext::getAttachedShaders(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return throwSyntaxError(exec); + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info)) + return throwTypeError(exec); + WebGLProgram* program = toWebGLProgram(exec->argument(0)); + if (exec->hadException()) + return jsNull(); + Vector<WebGLShader*> shaders; + bool succeed = context->getAttachedShaders(program, shaders, ec); + if (ec) { + setDOMException(exec, ec); + return jsNull(); + } + if (!succeed) + return jsNull(); + MarkedArgumentBuffer list; + for (size_t ii = 0; ii < shaders.size(); ++ii) + list.append(toJS(exec, globalObject(), shaders[ii])); + return constructArray(exec, list); +} + +JSValue JSWebGLRenderingContext::getExtension(ExecState* exec) +{ + if (exec->argumentCount() < 1) + return throwSyntaxError(exec); + + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + const String& name = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return jsUndefined(); + WebGLExtension* extension = context->getExtension(name); + return toJS(exec, globalObject(), extension); +} + +JSValue JSWebGLRenderingContext::getBufferParameter(ExecState* exec) +{ + return getObjectParameter(this, exec, kBuffer); +} + +JSValue JSWebGLRenderingContext::getFramebufferAttachmentParameter(ExecState* exec) +{ + if (exec->argumentCount() != 3) + return throwSyntaxError(exec); + + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + unsigned target = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + unsigned attachment = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + unsigned pname = exec->argument(2).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + WebGLGetInfo info = context->getFramebufferAttachmentParameter(target, attachment, pname, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), info); +} + +JSValue JSWebGLRenderingContext::getParameter(ExecState* exec) +{ + if (exec->argumentCount() != 1) + return throwSyntaxError(exec); + + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + unsigned pname = exec->argument(0).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + WebGLGetInfo info = context->getParameter(pname, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), info); +} + +JSValue JSWebGLRenderingContext::getProgramParameter(ExecState* exec) +{ + if (exec->argumentCount() != 2) + return throwSyntaxError(exec); + + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info)) + return throwTypeError(exec); + WebGLProgram* program = toWebGLProgram(exec->argument(0)); + unsigned pname = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + WebGLGetInfo info = context->getProgramParameter(program, pname, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), info); +} + +JSValue JSWebGLRenderingContext::getRenderbufferParameter(ExecState* exec) +{ + return getObjectParameter(this, exec, kRenderbuffer); +} + +JSValue JSWebGLRenderingContext::getShaderParameter(ExecState* exec) +{ + if (exec->argumentCount() != 2) + return throwSyntaxError(exec); + + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLShader::s_info)) + return throwTypeError(exec); + WebGLShader* shader = toWebGLShader(exec->argument(0)); + unsigned pname = exec->argument(1).toInt32(exec); + if (exec->hadException()) + return jsUndefined(); + WebGLGetInfo info = context->getShaderParameter(shader, pname, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), info); +} + +JSValue JSWebGLRenderingContext::getSupportedExtensions(ExecState* exec) +{ + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + if (context->isContextLost()) + return jsNull(); + Vector<String> value = context->getSupportedExtensions(); + MarkedArgumentBuffer list; + for (size_t ii = 0; ii < value.size(); ++ii) + list.append(jsString(exec, value[ii])); + return constructArray(exec, list); +} + +JSValue JSWebGLRenderingContext::getTexParameter(ExecState* exec) +{ + return getObjectParameter(this, exec, kTexture); +} + +JSValue JSWebGLRenderingContext::getUniform(ExecState* exec) +{ + if (exec->argumentCount() != 2) + return throwSyntaxError(exec); + + ExceptionCode ec = 0; + WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(impl()); + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLProgram::s_info)) + return throwTypeError(exec); + WebGLProgram* program = toWebGLProgram(exec->argument(0)); + if (exec->argumentCount() > 1 && !exec->argument(1).isUndefinedOrNull() && !exec->argument(1).inherits(&JSWebGLUniformLocation::s_info)) + return throwTypeError(exec); + WebGLUniformLocation* loc = toWebGLUniformLocation(exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + WebGLGetInfo info = context->getUniform(program, loc, ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), info); +} + +JSValue JSWebGLRenderingContext::getVertexAttrib(ExecState* exec) +{ + return getObjectParameter(this, exec, kVertexAttrib); +} + +template<typename T, size_t inlineCapacity> +bool toVector(JSC::ExecState* exec, JSC::JSValue value, Vector<T, inlineCapacity>& vector) +{ + if (!value.isObject()) + return false; + + JSC::JSObject* object = asObject(value); + int32_t length = object->get(exec, JSC::Identifier(exec, "length")).toInt32(exec); + vector.resize(length); + + for (int32_t i = 0; i < length; ++i) { + JSC::JSValue v = object->get(exec, i); + if (exec->hadException()) + return false; + vector[i] = static_cast<T>(v.toNumber(exec)); + } + + return true; +} + +enum DataFunctionToCall { + f_uniform1v, f_uniform2v, f_uniform3v, f_uniform4v, + f_vertexAttrib1v, f_vertexAttrib2v, f_vertexAttrib3v, f_vertexAttrib4v +}; + +enum DataFunctionMatrixToCall { + f_uniformMatrix2fv, f_uniformMatrix3fv, f_uniformMatrix4fv +}; + +static bool functionForUniform(DataFunctionToCall f) +{ + switch (f) { + case f_uniform1v: + case f_uniform2v: + case f_uniform3v: + case f_uniform4v: + return true; + break; + default: break; + } + return false; +} + +static JSC::JSValue dataFunctionf(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) +{ + if (exec->argumentCount() != 2) + return throwSyntaxError(exec); + + WebGLUniformLocation* location = 0; + long index = -1; + + if (functionForUniform(f)) { + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info)) + return throwTypeError(exec); + location = toWebGLUniformLocation(exec->argument(0)); + } else + index = exec->argument(0).toInt32(exec); + + if (exec->hadException()) + return jsUndefined(); + + RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + if (webGLArray) { + switch (f) { + case f_uniform1v: + context->uniform1fv(location, webGLArray.get(), ec); + break; + case f_uniform2v: + context->uniform2fv(location, webGLArray.get(), ec); + break; + case f_uniform3v: + context->uniform3fv(location, webGLArray.get(), ec); + break; + case f_uniform4v: + context->uniform4fv(location, webGLArray.get(), ec); + break; + case f_vertexAttrib1v: + context->vertexAttrib1fv(index, webGLArray.get()); + break; + case f_vertexAttrib2v: + context->vertexAttrib2fv(index, webGLArray.get()); + break; + case f_vertexAttrib3v: + context->vertexAttrib3fv(index, webGLArray.get()); + break; + case f_vertexAttrib4v: + context->vertexAttrib4fv(index, webGLArray.get()); + break; + } + + setDOMException(exec, ec); + return jsUndefined(); + } + + Vector<float, 64> array; + if (!toVector(exec, exec->argument(1), array)) + return throwTypeError(exec); + + switch (f) { + case f_uniform1v: + context->uniform1fv(location, array.data(), array.size(), ec); + break; + case f_uniform2v: + context->uniform2fv(location, array.data(), array.size(), ec); + break; + case f_uniform3v: + context->uniform3fv(location, array.data(), array.size(), ec); + break; + case f_uniform4v: + context->uniform4fv(location, array.data(), array.size(), ec); + break; + case f_vertexAttrib1v: + context->vertexAttrib1fv(index, array.data(), array.size()); + break; + case f_vertexAttrib2v: + context->vertexAttrib2fv(index, array.data(), array.size()); + break; + case f_vertexAttrib3v: + context->vertexAttrib3fv(index, array.data(), array.size()); + break; + case f_vertexAttrib4v: + context->vertexAttrib4fv(index, array.data(), array.size()); + break; + } + + setDOMException(exec, ec); + return jsUndefined(); +} + +static JSC::JSValue dataFunctioni(DataFunctionToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) +{ + if (exec->argumentCount() != 2) + return throwSyntaxError(exec); + + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info)) + return throwTypeError(exec); + WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0)); + + if (exec->hadException()) + return jsUndefined(); + + RefPtr<Int32Array> webGLArray = toInt32Array(exec->argument(1)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + if (webGLArray) { + switch (f) { + case f_uniform1v: + context->uniform1iv(location, webGLArray.get(), ec); + break; + case f_uniform2v: + context->uniform2iv(location, webGLArray.get(), ec); + break; + case f_uniform3v: + context->uniform3iv(location, webGLArray.get(), ec); + break; + case f_uniform4v: + context->uniform4iv(location, webGLArray.get(), ec); + break; + default: + break; + } + + setDOMException(exec, ec); + return jsUndefined(); + } + + + Vector<int, 64> array; + if (!toVector(exec, exec->argument(1), array)) + return throwTypeError(exec); + + switch (f) { + case f_uniform1v: + context->uniform1iv(location, array.data(), array.size(), ec); + break; + case f_uniform2v: + context->uniform2iv(location, array.data(), array.size(), ec); + break; + case f_uniform3v: + context->uniform3iv(location, array.data(), array.size(), ec); + break; + case f_uniform4v: + context->uniform4iv(location, array.data(), array.size(), ec); + break; + default: + break; + } + + setDOMException(exec, ec); + return jsUndefined(); +} + +static JSC::JSValue dataFunctionMatrix(DataFunctionMatrixToCall f, JSC::ExecState* exec, WebGLRenderingContext* context) +{ + if (exec->argumentCount() != 3) + return throwSyntaxError(exec); + + if (exec->argumentCount() > 0 && !exec->argument(0).isUndefinedOrNull() && !exec->argument(0).inherits(&JSWebGLUniformLocation::s_info)) + return throwTypeError(exec); + WebGLUniformLocation* location = toWebGLUniformLocation(exec->argument(0)); + + if (exec->hadException()) + return jsUndefined(); + + bool transpose = exec->argument(1).toBoolean(exec); + if (exec->hadException()) + return jsUndefined(); + + RefPtr<Float32Array> webGLArray = toFloat32Array(exec->argument(2)); + if (exec->hadException()) + return jsUndefined(); + + ExceptionCode ec = 0; + if (webGLArray) { + switch (f) { + case f_uniformMatrix2fv: + context->uniformMatrix2fv(location, transpose, webGLArray.get(), ec); + break; + case f_uniformMatrix3fv: + context->uniformMatrix3fv(location, transpose, webGLArray.get(), ec); + break; + case f_uniformMatrix4fv: + context->uniformMatrix4fv(location, transpose, webGLArray.get(), ec); + break; + } + + setDOMException(exec, ec); + return jsUndefined(); + } + + Vector<float, 64> array; + if (!toVector(exec, exec->argument(2), array)) + return throwTypeError(exec); + + switch (f) { + case f_uniformMatrix2fv: + context->uniformMatrix2fv(location, transpose, array.data(), array.size(), ec); + break; + case f_uniformMatrix3fv: + context->uniformMatrix3fv(location, transpose, array.data(), array.size(), ec); + break; + case f_uniformMatrix4fv: + context->uniformMatrix4fv(location, transpose, array.data(), array.size(), ec); + break; + } + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSC::JSValue JSWebGLRenderingContext::uniform1fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_uniform1v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform1iv(JSC::ExecState* exec) +{ + return dataFunctioni(f_uniform1v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform2fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_uniform2v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform2iv(JSC::ExecState* exec) +{ + return dataFunctioni(f_uniform2v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform3fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_uniform3v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform3iv(JSC::ExecState* exec) +{ + return dataFunctioni(f_uniform3v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform4fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_uniform4v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniform4iv(JSC::ExecState* exec) +{ + return dataFunctioni(f_uniform4v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniformMatrix2fv(JSC::ExecState* exec) +{ + return dataFunctionMatrix(f_uniformMatrix2fv, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniformMatrix3fv(JSC::ExecState* exec) +{ + return dataFunctionMatrix(f_uniformMatrix3fv, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::uniformMatrix4fv(JSC::ExecState* exec) +{ + return dataFunctionMatrix(f_uniformMatrix4fv, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::vertexAttrib1fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_vertexAttrib1v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::vertexAttrib2fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_vertexAttrib2v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::vertexAttrib3fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_vertexAttrib3v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +JSC::JSValue JSWebGLRenderingContext::vertexAttrib4fv(JSC::ExecState* exec) +{ + return dataFunctionf(f_vertexAttrib4v, exec, static_cast<WebGLRenderingContext*>(impl())); +} + +} // namespace WebCore + +#endif // ENABLE(3D_CANVAS) diff --git a/Source/WebCore/bindings/js/JSWebKitCSSKeyframeRuleCustom.cpp b/Source/WebCore/bindings/js/JSWebKitCSSKeyframeRuleCustom.cpp new file mode 100644 index 0000000..0eaebf1 --- /dev/null +++ b/Source/WebCore/bindings/js/JSWebKitCSSKeyframeRuleCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSWebKitCSSKeyframeRule.h" + +#include "WebKitCSSKeyframeRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSWebKitCSSKeyframeRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSMutableStyleDeclaration* style = static_cast<WebKitCSSKeyframeRule*>(impl())->style()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), style); +} + +} diff --git a/Source/WebCore/bindings/js/JSWebKitCSSKeyframesRuleCustom.cpp b/Source/WebCore/bindings/js/JSWebKitCSSKeyframesRuleCustom.cpp new file mode 100644 index 0000000..b590b6a --- /dev/null +++ b/Source/WebCore/bindings/js/JSWebKitCSSKeyframesRuleCustom.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSWebKitCSSKeyframesRule.h" + +#include "WebKitCSSKeyframesRule.h" + +using namespace JSC; + +namespace WebCore { + +void JSWebKitCSSKeyframesRule::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (CSSRuleList* rules = static_cast<WebKitCSSKeyframesRule*>(impl())->cssRules()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), rules); +} + +} diff --git a/Source/WebCore/bindings/js/JSWebKitCSSMatrixCustom.cpp b/Source/WebCore/bindings/js/JSWebKitCSSMatrixCustom.cpp new file mode 100644 index 0000000..0889dcf --- /dev/null +++ b/Source/WebCore/bindings/js/JSWebKitCSSMatrixCustom.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSWebKitCSSMatrix.h" + +#include "WebKitCSSMatrix.h" + +using namespace JSC; + +namespace WebCore { + +EncodedJSValue JSC_HOST_CALL JSWebKitCSSMatrixConstructor::constructJSWebKitCSSMatrix(ExecState* exec) +{ + JSWebKitCSSMatrixConstructor* jsConstructor = static_cast<JSWebKitCSSMatrixConstructor*>(exec->callee()); + String s; + if (exec->argumentCount() >= 1) + s = ustringToString(exec->argument(0).toString(exec)); + + ExceptionCode ec = 0; + RefPtr<WebKitCSSMatrix> matrix = WebKitCSSMatrix::create(s, ec); + setDOMException(exec, ec); + return JSValue::encode(CREATE_DOM_OBJECT_WRAPPER(exec, jsConstructor->globalObject(), WebKitCSSMatrix, matrix.get())); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSWebKitPointCustom.cpp b/Source/WebCore/bindings/js/JSWebKitPointCustom.cpp new file mode 100644 index 0000000..e1b20ce --- /dev/null +++ b/Source/WebCore/bindings/js/JSWebKitPointCustom.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSWebKitPoint.h" + +#include "WebKitPoint.h" + +using namespace JSC; + +namespace WebCore { + +EncodedJSValue JSC_HOST_CALL JSWebKitPointConstructor::constructJSWebKitPoint(ExecState* exec) +{ + JSWebKitPointConstructor* jsConstructor = static_cast<JSWebKitPointConstructor*>(exec->callee()); + + float x = 0; + float y = 0; + if (exec->argumentCount() >= 2) { + x = static_cast<float>(exec->argument(0).toNumber(exec)); + y = static_cast<float>(exec->argument(1).toNumber(exec)); + if (isnan(x)) + x = 0; + if (isnan(y)) + y = 0; + } + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), WebKitPoint::create(x, y)))); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSWebSocketCustom.cpp b/Source/WebCore/bindings/js/JSWebSocketCustom.cpp new file mode 100644 index 0000000..813c0d4 --- /dev/null +++ b/Source/WebCore/bindings/js/JSWebSocketCustom.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WEB_SOCKETS) + +#include "JSWebSocket.h" + +#include "KURL.h" +#include "JSEventListener.h" +#include "WebSocket.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +EncodedJSValue JSC_HOST_CALL JSWebSocketConstructor::constructJSWebSocket(ExecState* exec) +{ + JSWebSocketConstructor* jsConstructor = static_cast<JSWebSocketConstructor*>(exec->callee()); + ScriptExecutionContext* context = jsConstructor->scriptExecutionContext(); + if (!context) + return throwVMError(exec, createReferenceError(exec, "WebSocket constructor associated document is unavailable")); + + if (!exec->argumentCount()) + return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); + + String urlString = ustringToString(exec->argument(0).toString(exec)); + if (exec->hadException()) + return throwVMError(exec, createSyntaxError(exec, "wrong URL")); + KURL url = context->completeURL(urlString); + RefPtr<WebSocket> webSocket = WebSocket::create(context); + ExceptionCode ec = 0; + if (exec->argumentCount() < 2) + webSocket->connect(url, ec); + else { + String protocol = ustringToString(exec->argument(1).toString(exec)); + if (exec->hadException()) + return JSValue::encode(JSValue()); + webSocket->connect(url, protocol, ec); + } + setDOMException(exec, ec); + return JSValue::encode(CREATE_DOM_OBJECT_WRAPPER(exec, jsConstructor->globalObject(), WebSocket, webSocket.get())); +} + +} // namespace WebCore + +#endif diff --git a/Source/WebCore/bindings/js/JSWorkerContextBase.cpp b/Source/WebCore/bindings/js/JSWorkerContextBase.cpp new file mode 100644 index 0000000..effe488 --- /dev/null +++ b/Source/WebCore/bindings/js/JSWorkerContextBase.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "config.h" + +#if ENABLE(WORKERS) + +#include "JSWorkerContextBase.h" + +#include "JSDedicatedWorkerContext.h" +#include "JSSharedWorkerContext.h" +#include "JSWorkerContext.h" +#include "WorkerContext.h" + +using namespace JSC; + +namespace WebCore { + +ASSERT_CLASS_FITS_IN_CELL(JSWorkerContextBase); + +const ClassInfo JSWorkerContextBase::s_info = { "WorkerContext", &JSDOMGlobalObject::s_info, 0, 0 }; + +JSWorkerContextBase::JSWorkerContextBase(NonNullPassRefPtr<JSC::Structure> structure, PassRefPtr<WorkerContext> impl) + : JSDOMGlobalObject(structure, new JSDOMGlobalObjectData(normalWorld(*impl->script()->globalData())), this) + , m_impl(impl) +{ +} + +JSWorkerContextBase::~JSWorkerContextBase() +{ +} + +ScriptExecutionContext* JSWorkerContextBase::scriptExecutionContext() const +{ + return m_impl.get(); +} + +JSValue toJS(ExecState* exec, JSDOMGlobalObject*, WorkerContext* workerContext) +{ + return toJS(exec, workerContext); +} + +JSValue toJS(ExecState*, WorkerContext* workerContext) +{ + if (!workerContext) + return jsNull(); + WorkerScriptController* script = workerContext->script(); + if (!script) + return jsNull(); + JSWorkerContext* contextWrapper = script->workerContextWrapper(); + ASSERT(contextWrapper); + return contextWrapper; +} + +JSDedicatedWorkerContext* toJSDedicatedWorkerContext(JSValue value) +{ + if (!value.isObject()) + return 0; + const ClassInfo* classInfo = asObject(value)->classInfo(); + if (classInfo == &JSDedicatedWorkerContext::s_info) + return static_cast<JSDedicatedWorkerContext*>(asObject(value)); + return 0; +} + +#if ENABLE(SHARED_WORKERS) +JSSharedWorkerContext* toJSSharedWorkerContext(JSValue value) +{ + if (!value.isObject()) + return 0; + const ClassInfo* classInfo = asObject(value)->classInfo(); + if (classInfo == &JSSharedWorkerContext::s_info) + return static_cast<JSSharedWorkerContext*>(asObject(value)); + return 0; +} +#endif + +JSWorkerContext* toJSWorkerContext(JSValue value) +{ + JSWorkerContext* context = toJSDedicatedWorkerContext(value); +#if ENABLE(SHARED_WORKERS) + if (!context) + context = toJSSharedWorkerContext(value); +#endif + return context; +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/Source/WebCore/bindings/js/JSWorkerContextBase.h b/Source/WebCore/bindings/js/JSWorkerContextBase.h new file mode 100644 index 0000000..45238f1 --- /dev/null +++ b/Source/WebCore/bindings/js/JSWorkerContextBase.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef JSWorkerContextBase_h +#define JSWorkerContextBase_h + +#if ENABLE(WORKERS) + +#include "JSDOMGlobalObject.h" + +namespace WebCore { + + class JSDedicatedWorkerContext; + class JSSharedWorkerContext; + class JSWorkerContext; + class WorkerContext; + + class JSWorkerContextBase : public JSDOMGlobalObject { + typedef JSDOMGlobalObject Base; + public: + JSWorkerContextBase(NonNullPassRefPtr<JSC::Structure>, PassRefPtr<WorkerContext>); + virtual ~JSWorkerContextBase(); + + virtual const JSC::ClassInfo* classInfo() const { return &s_info; } + static const JSC::ClassInfo s_info; + + WorkerContext* impl() const { return m_impl.get(); } + virtual ScriptExecutionContext* scriptExecutionContext() const; + + private: + RefPtr<WorkerContext> m_impl; + }; + + // Returns a JSWorkerContext or jsNull() + // Always ignores the execState and passed globalObject, WorkerContext is itself a globalObject and will always use its own prototype chain. + JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, WorkerContext*); + JSC::JSValue toJS(JSC::ExecState*, WorkerContext*); + + JSDedicatedWorkerContext* toJSDedicatedWorkerContext(JSC::JSValue); + JSWorkerContext* toJSWorkerContext(JSC::JSValue); + +#if ENABLE(SHARED_WORKERS) + JSSharedWorkerContext* toJSSharedWorkerContext(JSC::JSValue); +#endif + +} // namespace WebCore + +#endif // ENABLE(WORKERS) + +#endif // JSWorkerContextBase_h diff --git a/Source/WebCore/bindings/js/JSWorkerContextCustom.cpp b/Source/WebCore/bindings/js/JSWorkerContextCustom.cpp new file mode 100644 index 0000000..8c1caef --- /dev/null +++ b/Source/WebCore/bindings/js/JSWorkerContextCustom.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WORKERS) + +#include "JSWorkerContext.h" + +#include "ExceptionCode.h" +#include "JSDOMBinding.h" +#include "JSDOMGlobalObject.h" +#include "JSEventListener.h" +#include "JSEventSource.h" +#include "JSMessageChannel.h" +#include "JSMessagePort.h" +#include "JSWorkerLocation.h" +#include "JSWorkerNavigator.h" +#include "JSXMLHttpRequest.h" +#include "ScheduledAction.h" +#include "WorkerContext.h" +#include "WorkerLocation.h" +#include "WorkerNavigator.h" +#include <interpreter/Interpreter.h> + +#if ENABLE(WEB_SOCKETS) +#include "JSWebSocket.h" +#endif + +using namespace JSC; + +namespace WebCore { + +void JSWorkerContext::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + JSGlobalData& globalData = this->globalData(); + + markActiveObjectsForContext(markStack, globalData, scriptExecutionContext()); + + markDOMObjectWrapper(markStack, globalData, impl()->optionalLocation()); + markDOMObjectWrapper(markStack, globalData, impl()->optionalNavigator()); + + impl()->markJSEventListeners(markStack); +} + +bool JSWorkerContext::getOwnPropertySlotDelegate(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + // Look for overrides before looking at any of our own properties. + if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) + return true; + return false; +} + +bool JSWorkerContext::getOwnPropertyDescriptorDelegate(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + // Look for overrides before looking at any of our own properties. + if (JSGlobalObject::getOwnPropertyDescriptor(exec, propertyName, descriptor)) + return true; + return false; +} + +#if ENABLE(EVENTSOURCE) +JSValue JSWorkerContext::eventSource(ExecState* exec) const +{ + return getDOMConstructor<JSEventSourceConstructor>(exec, this); +} +#endif + +JSValue JSWorkerContext::xmlHttpRequest(ExecState* exec) const +{ + return getDOMConstructor<JSXMLHttpRequestConstructor>(exec, this); +} + +#if ENABLE(WEB_SOCKETS) +JSValue JSWorkerContext::webSocket(ExecState* exec) const +{ + return getDOMConstructor<JSWebSocketConstructor>(exec, this); +} +#endif + +JSValue JSWorkerContext::importScripts(ExecState* exec) +{ + if (!exec->argumentCount()) + return jsUndefined(); + + Vector<String> urls; + for (unsigned i = 0; i < exec->argumentCount(); i++) { + urls.append(ustringToString(exec->argument(i).toString(exec))); + if (exec->hadException()) + return jsUndefined(); + } + ExceptionCode ec = 0; + + impl()->importScripts(urls, ec); + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSWorkerContext::setTimeout(ExecState* exec) +{ + OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, currentWorld(exec)); + if (exec->hadException()) + return jsUndefined(); + int delay = exec->argument(1).toInt32(exec); + return jsNumber(impl()->setTimeout(action.release(), delay)); +} + +JSValue JSWorkerContext::setInterval(ExecState* exec) +{ + OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, currentWorld(exec)); + if (exec->hadException()) + return jsUndefined(); + int delay = exec->argument(1).toInt32(exec); + return jsNumber(impl()->setInterval(action.release(), delay)); +} + + +#if ENABLE(CHANNEL_MESSAGING) +JSValue JSWorkerContext::messageChannel(ExecState* exec) const +{ + return getDOMConstructor<JSMessageChannelConstructor>(exec, this); +} +#endif + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp b/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp new file mode 100644 index 0000000..f7d2b02 --- /dev/null +++ b/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WORKERS) + +#include "JSWorkerContextErrorHandler.h" + +#include "ErrorEvent.h" +#include "Event.h" +#include "JSEvent.h" +#include <runtime/JSLock.h> + +using namespace JSC; + +namespace WebCore { + +JSWorkerContextErrorHandler::JSWorkerContextErrorHandler(JSObject* function, JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld) + : JSEventListener(function, wrapper, isAttribute, isolatedWorld) +{ +} + +JSWorkerContextErrorHandler::~JSWorkerContextErrorHandler() +{ +} + +void JSWorkerContextErrorHandler::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event) +{ + ASSERT(scriptExecutionContext); + if (!scriptExecutionContext) + return; + + JSLock lock(SilenceAssertionsOnly); + + JSObject* jsFunction = this->jsFunction(scriptExecutionContext); + if (!jsFunction) + return; + + JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, isolatedWorld()); + if (!globalObject) + return; + + ExecState* exec = globalObject->globalExec(); + + CallData callData; + CallType callType = jsFunction->getCallData(callData); + + if (callType != CallTypeNone) { + + ref(); + + Event* savedEvent = globalObject->currentEvent(); + globalObject->setCurrentEvent(event); + + ASSERT(event->isErrorEvent()); + ErrorEvent* errorEvent = static_cast<ErrorEvent*>(event); + + MarkedArgumentBuffer args; + args.append(jsString(exec, errorEvent->message())); + args.append(jsString(exec, errorEvent->filename())); + args.append(jsNumber(errorEvent->lineno())); + + JSGlobalData& globalData = globalObject->globalData(); + DynamicGlobalObjectScope globalObjectScope(exec, globalData.dynamicGlobalObject ? globalData.dynamicGlobalObject : globalObject); + + JSValue thisValue = globalObject->toThisObject(exec); + + globalData.timeoutChecker.start(); + JSValue returnValue = JSC::call(exec, jsFunction, callType, callData, thisValue, args); + globalData.timeoutChecker.stop(); + + globalObject->setCurrentEvent(savedEvent); + + if (exec->hadException()) + reportCurrentException(exec); + else { + bool retvalbool; + if (returnValue.getBoolean(retvalbool) && !retvalbool) + event->preventDefault(); + } + + deref(); + } +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h b/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h new file mode 100644 index 0000000..a188299 --- /dev/null +++ b/Source/WebCore/bindings/js/JSWorkerContextErrorHandler.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JSWorkerContextErrorHandler_h +#define JSWorkerContextErrorHandler_h + +#include "JSEventListener.h" + +namespace WebCore { + +class JSWorkerContextErrorHandler : public JSEventListener { +public: + static PassRefPtr<JSWorkerContextErrorHandler> create(JSC::JSObject* listener, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld) + { + return adoptRef(new JSWorkerContextErrorHandler(listener, wrapper, isAttribute, isolatedWorld)); + } + + virtual ~JSWorkerContextErrorHandler(); + +private: + JSWorkerContextErrorHandler(JSC::JSObject* function, JSC::JSObject* wrapper, bool isAttribute, DOMWrapperWorld* isolatedWorld); + virtual void handleEvent(ScriptExecutionContext*, Event*); +}; + +// Creates a JS EventListener for "onerror" event handler in worker context. It has custom implementation because +// unlike other event listeners it accepts three parameters. +inline PassRefPtr<JSWorkerContextErrorHandler> createJSWorkerContextErrorHandler(JSC::ExecState* exec, JSC::JSValue listener, JSC::JSObject* wrapper) +{ + if (!listener.isObject()) + return 0; + + return JSWorkerContextErrorHandler::create(asObject(listener), wrapper, true, currentWorld(exec)); +} + +} // namespace WebCore + +#endif // JSWorkerContextErrorHandler_h diff --git a/Source/WebCore/bindings/js/JSWorkerCustom.cpp b/Source/WebCore/bindings/js/JSWorkerCustom.cpp new file mode 100644 index 0000000..27580ae --- /dev/null +++ b/Source/WebCore/bindings/js/JSWorkerCustom.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(WORKERS) + +#include "JSWorker.h" + +#include "JSDOMGlobalObject.h" +#include "JSMessagePortCustom.h" +#include "Worker.h" +#include "JSDOMWindowCustom.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +JSC::JSValue JSWorker::postMessage(JSC::ExecState* exec) +{ + return handlePostMessage(exec, impl()); +} + +EncodedJSValue JSC_HOST_CALL JSWorkerConstructor::constructJSWorker(ExecState* exec) +{ + JSWorkerConstructor* jsConstructor = static_cast<JSWorkerConstructor*>(exec->callee()); + + if (!exec->argumentCount()) + return throwVMError(exec, createSyntaxError(exec, "Not enough arguments")); + + UString scriptURL = exec->argument(0).toString(exec); + if (exec->hadException()) + return JSValue::encode(JSValue()); + + // See section 4.8.2 step 14 of WebWorkers for why this is the lexicalGlobalObject. + DOMWindow* window = asJSDOMWindow(exec->lexicalGlobalObject())->impl(); + + ExceptionCode ec = 0; + RefPtr<Worker> worker = Worker::create(ustringToString(scriptURL), window->document(), ec); + if (ec) { + setDOMException(exec, ec); + return JSValue::encode(JSValue()); + } + + return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), worker.release()))); +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp b/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp new file mode 100644 index 0000000..a93db11 --- /dev/null +++ b/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSXMLHttpRequest.h" + +#include "ArrayBuffer.h" +#include "Blob.h" +#include "DOMFormData.h" +#include "DOMWindow.h" +#include "Document.h" +#include "Event.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "HTMLDocument.h" +#include "InspectorInstrumentation.h" +#include "JSArrayBuffer.h" +#include "JSBlob.h" +#include "JSDOMFormData.h" +#include "JSDOMWindowCustom.h" +#include "JSDocument.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "XMLHttpRequest.h" +#include <runtime/Error.h> +#include <interpreter/Interpreter.h> + +using namespace JSC; + +namespace WebCore { + +void JSXMLHttpRequest::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (XMLHttpRequestUpload* upload = m_impl->optionalUpload()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), upload); + + if (Document* responseDocument = m_impl->optionalResponseXML()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), responseDocument); + +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + if (ArrayBuffer* responseArrayBuffer = m_impl->optionalResponseArrayBuffer()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), responseArrayBuffer); +#endif + +#if ENABLE(XHR_RESPONSE_BLOB) + if (Blob* responseBlob = m_impl->optionalResponseBlob()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), responseBlob); +#endif + + m_impl->markJSEventListeners(markStack); +} + +// Custom functions +JSValue JSXMLHttpRequest::open(ExecState* exec) +{ + if (exec->argumentCount() < 2) + return throwError(exec, createSyntaxError(exec, "Not enough arguments")); + + const KURL& url = impl()->scriptExecutionContext()->completeURL(ustringToString(exec->argument(1).toString(exec))); + String method = ustringToString(exec->argument(0).toString(exec)); + + ExceptionCode ec = 0; + if (exec->argumentCount() >= 3) { + bool async = exec->argument(2).toBoolean(exec); + + if (exec->argumentCount() >= 4 && !exec->argument(3).isUndefined()) { + String user = valueToStringWithNullCheck(exec, exec->argument(3)); + + if (exec->argumentCount() >= 5 && !exec->argument(4).isUndefined()) { + String password = valueToStringWithNullCheck(exec, exec->argument(4)); + impl()->open(method, url, async, user, password, ec); + } else + impl()->open(method, url, async, user, ec); + } else + impl()->open(method, url, async, ec); + } else + impl()->open(method, url, ec); + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSXMLHttpRequest::send(ExecState* exec) +{ + InspectorInstrumentation::willSendXMLHttpRequest(impl()->scriptExecutionContext(), impl()->url()); + + ExceptionCode ec = 0; + if (!exec->argumentCount()) + impl()->send(ec); + else { + JSValue val = exec->argument(0); + if (val.isUndefinedOrNull()) + impl()->send(ec); + else if (val.inherits(&JSDocument::s_info)) + impl()->send(toDocument(val), ec); + else if (val.inherits(&JSBlob::s_info)) + impl()->send(toBlob(val), ec); + else if (val.inherits(&JSDOMFormData::s_info)) + impl()->send(toDOMFormData(val), ec); +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + else if (val.inherits(&JSArrayBuffer::s_info)) + impl()->send(toArrayBuffer(val), ec); +#endif + else + impl()->send(ustringToString(val.toString(exec)), ec); + } + + int signedLineNumber; + intptr_t sourceID; + UString sourceURL; + JSValue function; + exec->interpreter()->retrieveLastCaller(exec, signedLineNumber, sourceID, sourceURL, function); + impl()->setLastSendLineNumber(signedLineNumber >= 0 ? signedLineNumber : 0); + impl()->setLastSendURL(ustringToString(sourceURL)); + + setDOMException(exec, ec); + return jsUndefined(); +} + +JSValue JSXMLHttpRequest::responseText(ExecState* exec) const +{ + ExceptionCode ec = 0; + String text = impl()->responseText(ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return jsOwnedStringOrNull(exec, text); +} + +JSValue JSXMLHttpRequest::response(ExecState* exec) const +{ + switch (impl()->responseTypeCode()) { + case XMLHttpRequest::ResponseTypeDefault: + case XMLHttpRequest::ResponseTypeText: + return responseText(exec); + + case XMLHttpRequest::ResponseTypeDocument: + { + ExceptionCode ec = 0; + Document* document = impl()->responseXML(ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), document); + } + + case XMLHttpRequest::ResponseTypeBlob: +#if ENABLE(XHR_RESPONSE_BLOB) + { + ExceptionCode ec = 0; + Blob* blob = impl()->responseBlob(ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), blob); + } +#else + return jsUndefined(); +#endif + + case XMLHttpRequest::ResponseTypeArrayBuffer: +#if ENABLE(3D_CANVAS) || ENABLE(BLOB) + { + ExceptionCode ec = 0; + ArrayBuffer* arrayBuffer = impl()->responseArrayBuffer(ec); + if (ec) { + setDOMException(exec, ec); + return jsUndefined(); + } + return toJS(exec, globalObject(), arrayBuffer); + } +#else + return jsUndefined(); +#endif + } + + return jsUndefined(); +} + +EncodedJSValue JSC_HOST_CALL JSXMLHttpRequestConstructor::constructJSXMLHttpRequest(ExecState* exec) +{ + JSXMLHttpRequestConstructor* jsConstructor = static_cast<JSXMLHttpRequestConstructor*>(exec->callee()); + ScriptExecutionContext* context = jsConstructor->scriptExecutionContext(); + if (!context) + return throwVMError(exec, createReferenceError(exec, "XMLHttpRequest constructor associated document is unavailable")); + + RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context); + return JSValue::encode(CREATE_DOM_OBJECT_WRAPPER(exec, jsConstructor->globalObject(), XMLHttpRequest, xmlHttpRequest.get())); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp b/Source/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp new file mode 100644 index 0000000..091c380 --- /dev/null +++ b/Source/WebCore/bindings/js/JSXMLHttpRequestUploadCustom.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JSXMLHttpRequestUpload.h" + +#include "DOMWindow.h" +#include "Document.h" +#include "Event.h" +#include "Frame.h" +#include "JSDOMWindowCustom.h" +#include "JSEvent.h" +#include "JSEventListener.h" +#include "XMLHttpRequest.h" +#include "XMLHttpRequestUpload.h" +#include <runtime/Error.h> + +using namespace JSC; + +namespace WebCore { + +void JSXMLHttpRequestUpload::markChildren(MarkStack& markStack) +{ + Base::markChildren(markStack); + + if (XMLHttpRequest* xmlHttpRequest = m_impl->associatedXMLHttpRequest()) + markDOMObjectWrapper(markStack, *Heap::heap(this)->globalData(), xmlHttpRequest); + + m_impl->markJSEventListeners(markStack); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/JSXSLTProcessorCustom.cpp b/Source/WebCore/bindings/js/JSXSLTProcessorCustom.cpp new file mode 100644 index 0000000..3423272 --- /dev/null +++ b/Source/WebCore/bindings/js/JSXSLTProcessorCustom.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(XSLT) + +#include "JSXSLTProcessor.h" + +#include "Document.h" +#include "DocumentFragment.h" +#include "JSDocument.h" +#include "JSDocumentFragment.h" +#include "JSNode.h" +#include "Node.h" +#include "PlatformString.h" +#include "XSLTProcessor.h" +#include "JSDOMBinding.h" + +using namespace JSC; + +namespace WebCore { + +JSValue JSXSLTProcessor::importStylesheet(ExecState* exec) +{ + JSValue nodeVal = exec->argument(0); + if (nodeVal.inherits(&JSNode::s_info)) { + JSNode* node = static_cast<JSNode*>(asObject(nodeVal)); + impl()->importStylesheet(node->impl()); + return jsUndefined(); + } + // Throw exception? + return jsUndefined(); +} + +JSValue JSXSLTProcessor::transformToFragment(ExecState* exec) +{ + JSValue nodeVal = exec->argument(0); + JSValue docVal = exec->argument(1); + if (nodeVal.inherits(&JSNode::s_info) && docVal.inherits(&JSDocument::s_info)) { + WebCore::Node* node = static_cast<JSNode*>(asObject(nodeVal))->impl(); + Document* doc = static_cast<Document*>(static_cast<JSDocument*>(asObject(docVal))->impl()); + return toJS(exec, impl()->transformToFragment(node, doc).get()); + } + // Throw exception? + return jsUndefined(); +} + +JSValue JSXSLTProcessor::transformToDocument(ExecState* exec) +{ + JSValue nodeVal = exec->argument(0); + if (nodeVal.inherits(&JSNode::s_info)) { + JSNode* node = static_cast<JSNode*>(asObject(nodeVal)); + RefPtr<Document> resultDocument = impl()->transformToDocument(node->impl()); + if (resultDocument) + return toJS(exec, resultDocument.get()); + return jsUndefined(); + } + // Throw exception? + return jsUndefined(); +} + +JSValue JSXSLTProcessor::setParameter(ExecState* exec) +{ + if (exec->argument(1).isUndefinedOrNull() || exec->argument(2).isUndefinedOrNull()) + return jsUndefined(); // Throw exception? + String namespaceURI = ustringToString(exec->argument(0).toString(exec)); + String localName = ustringToString(exec->argument(1).toString(exec)); + String value = ustringToString(exec->argument(2).toString(exec)); + impl()->setParameter(namespaceURI, localName, value); + return jsUndefined(); +} + +JSValue JSXSLTProcessor::getParameter(ExecState* exec) +{ + if (exec->argument(1).isUndefinedOrNull()) + return jsUndefined(); + String namespaceURI = ustringToString(exec->argument(0).toString(exec)); + String localName = ustringToString(exec->argument(1).toString(exec)); + String value = impl()->getParameter(namespaceURI, localName); + return jsStringOrUndefined(exec, value); +} + +JSValue JSXSLTProcessor::removeParameter(ExecState* exec) +{ + if (exec->argument(1).isUndefinedOrNull()) + return jsUndefined(); + String namespaceURI = ustringToString(exec->argument(0).toString(exec)); + String localName = ustringToString(exec->argument(1).toString(exec)); + impl()->removeParameter(namespaceURI, localName); + return jsUndefined(); +} + +EncodedJSValue JSC_HOST_CALL JSXSLTProcessorConstructor::constructJSXSLTProcessor(ExecState* exec) +{ + JSXSLTProcessorConstructor* jsConstructor = static_cast<JSXSLTProcessorConstructor*>(exec->callee()); + return JSValue::encode(CREATE_DOM_OBJECT_WRAPPER(exec, jsConstructor->globalObject(), XSLTProcessor, XSLTProcessor::create().get())); +} + +} // namespace WebCore + +#endif // ENABLE(XSLT) diff --git a/Source/WebCore/bindings/js/JavaScriptCallFrame.cpp b/Source/WebCore/bindings/js/JavaScriptCallFrame.cpp new file mode 100644 index 0000000..c280d98 --- /dev/null +++ b/Source/WebCore/bindings/js/JavaScriptCallFrame.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "JavaScriptCallFrame.h" + +#include "JSDOMBinding.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) && USE(JSC) + +#include "PlatformString.h" +#include <debugger/DebuggerCallFrame.h> +#include <runtime/Completion.h> +#include <runtime/JSGlobalObject.h> +#include <runtime/JSLock.h> +#include <runtime/JSObject.h> +#include <runtime/JSValue.h> + +using namespace JSC; + +namespace WebCore { + +JavaScriptCallFrame::JavaScriptCallFrame(const DebuggerCallFrame& debuggerCallFrame, PassRefPtr<JavaScriptCallFrame> caller, intptr_t sourceID, int line) + : m_debuggerCallFrame(debuggerCallFrame) + , m_caller(caller) + , m_sourceID(sourceID) + , m_line(line) + , m_isValid(true) +{ +} + +JavaScriptCallFrame* JavaScriptCallFrame::caller() +{ + return m_caller.get(); +} + +const JSC::ScopeChainNode* JavaScriptCallFrame::scopeChain() const +{ + ASSERT(m_isValid); + if (!m_isValid) + return 0; + return m_debuggerCallFrame.scopeChain(); +} + +JSC::JSGlobalObject* JavaScriptCallFrame::dynamicGlobalObject() const +{ + ASSERT(m_isValid); + if (!m_isValid) + return 0; + return m_debuggerCallFrame.dynamicGlobalObject(); +} + +String JavaScriptCallFrame::functionName() const +{ + ASSERT(m_isValid); + if (!m_isValid) + return String(); + UString functionName = m_debuggerCallFrame.calculatedFunctionName(); + if (functionName.isEmpty()) + return String(); + return ustringToString(functionName); +} + +DebuggerCallFrame::Type JavaScriptCallFrame::type() const +{ + ASSERT(m_isValid); + if (!m_isValid) + return DebuggerCallFrame::ProgramType; + return m_debuggerCallFrame.type(); +} + +JSObject* JavaScriptCallFrame::thisObject() const +{ + ASSERT(m_isValid); + if (!m_isValid) + return 0; + return m_debuggerCallFrame.thisObject(); +} + +// Evaluate some JavaScript code in the scope of this frame. +JSValue JavaScriptCallFrame::evaluate(const UString& script, JSValue& exception) const +{ + ASSERT(m_isValid); + if (!m_isValid) + return jsNull(); + + JSLock lock(SilenceAssertionsOnly); + return m_debuggerCallFrame.evaluate(script, exception); +} + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/Source/WebCore/bindings/js/JavaScriptCallFrame.h b/Source/WebCore/bindings/js/JavaScriptCallFrame.h new file mode 100644 index 0000000..c23a43d --- /dev/null +++ b/Source/WebCore/bindings/js/JavaScriptCallFrame.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef JavaScriptCallFrame_h +#define JavaScriptCallFrame_h + +#if ENABLE(JAVASCRIPT_DEBUGGER) && USE(JSC) + +#include <debugger/DebuggerCallFrame.h> +#include <interpreter/CallFrame.h> +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + +class JavaScriptCallFrame : public RefCounted<JavaScriptCallFrame> { +public: + static PassRefPtr<JavaScriptCallFrame> create(const JSC::DebuggerCallFrame& debuggerCallFrame, PassRefPtr<JavaScriptCallFrame> caller, intptr_t sourceID, int line) + { + return adoptRef(new JavaScriptCallFrame(debuggerCallFrame, caller, sourceID, line)); + } + + void invalidate() + { + m_isValid = false; + m_debuggerCallFrame = 0; + } + + bool isValid() const { return m_isValid; } + + JavaScriptCallFrame* caller(); + + intptr_t sourceID() const { return m_sourceID; } + int line() const { return m_line; } + void update(const JSC::DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int line) + { + m_debuggerCallFrame = debuggerCallFrame; + m_line = line; + m_sourceID = sourceID; + m_isValid = true; + } + + String functionName() const; + JSC::DebuggerCallFrame::Type type() const; + const JSC::ScopeChainNode* scopeChain() const; + JSC::JSGlobalObject* dynamicGlobalObject() const; + + JSC::JSObject* thisObject() const; + JSC::JSValue evaluate(const JSC::UString& script, JSC::JSValue& exception) const; + +private: + JavaScriptCallFrame(const JSC::DebuggerCallFrame&, PassRefPtr<JavaScriptCallFrame> caller, intptr_t sourceID, int line); + + JSC::DebuggerCallFrame m_debuggerCallFrame; + RefPtr<JavaScriptCallFrame> m_caller; + intptr_t m_sourceID; + int m_line; + bool m_isValid; +}; + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) + +#endif // JavaScriptCallFrame_h diff --git a/Source/WebCore/bindings/js/OptionsObject.h b/Source/WebCore/bindings/js/OptionsObject.h new file mode 100644 index 0000000..34910c0 --- /dev/null +++ b/Source/WebCore/bindings/js/OptionsObject.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef OptionsObject_h +#define OptionsObject_h + +// FIXME: Implement. + +#endif // OptionsObject_h diff --git a/Source/WebCore/bindings/js/ScheduledAction.cpp b/Source/WebCore/bindings/js/ScheduledAction.cpp new file mode 100644 index 0000000..d6f8a38 --- /dev/null +++ b/Source/WebCore/bindings/js/ScheduledAction.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2006 Jon Shier (jshier@iastate.edu) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) + * Copyright (C) 2009 Google Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include "config.h" +#include "ScheduledAction.h" + +#include "DOMWindow.h" +#include "Document.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "JSDOMBinding.h" +#include "JSDOMWindow.h" +#include "JSMainThreadExecState.h" +#include "ScriptController.h" +#include "ScriptExecutionContext.h" +#include "ScriptSourceCode.h" +#include <runtime/JSLock.h> + +#if ENABLE(WORKERS) +#include "JSWorkerContext.h" +#include "WorkerContext.h" +#include "WorkerThread.h" +#endif + +using namespace JSC; + +namespace WebCore { + +PassOwnPtr<ScheduledAction> ScheduledAction::create(ExecState* exec, DOMWrapperWorld* isolatedWorld) +{ + JSValue v = exec->argument(0); + CallData callData; + if (getCallData(v, callData) == CallTypeNone) { + UString string = v.toString(exec); + if (exec->hadException()) + return 0; + return new ScheduledAction(ustringToString(string), isolatedWorld); + } + + return new ScheduledAction(exec, v, isolatedWorld); +} + +ScheduledAction::ScheduledAction(ExecState* exec, JSValue function, DOMWrapperWorld* isolatedWorld) + : m_function(function) + , m_isolatedWorld(isolatedWorld) +{ + // setTimeout(function, interval, arg0, arg1...). + // Start at 2 to skip function and interval. + for (size_t i = 2; i < exec->argumentCount(); ++i) + m_args.append(exec->argument(i)); +} + +void ScheduledAction::execute(ScriptExecutionContext* context) +{ + if (context->isDocument()) + execute(static_cast<Document*>(context)); +#if ENABLE(WORKERS) + else { + ASSERT(context->isWorkerContext()); + execute(static_cast<WorkerContext*>(context)); + } +#else + ASSERT(context->isDocument()); +#endif +} + +void ScheduledAction::executeFunctionInContext(JSGlobalObject* globalObject, JSValue thisValue, ScriptExecutionContext* context) +{ + ASSERT(m_function); + JSLock lock(SilenceAssertionsOnly); + + CallData callData; + CallType callType = getCallData(m_function.get(), callData); + if (callType == CallTypeNone) + return; + + ExecState* exec = globalObject->globalExec(); + + MarkedArgumentBuffer args; + size_t size = m_args.size(); + for (size_t i = 0; i < size; ++i) + args.append(m_args[i]); + + globalObject->globalData().timeoutChecker.start(); + if (context->isDocument()) + JSMainThreadExecState::call(exec, m_function, callType, callData, thisValue, args); + else + JSC::call(exec, m_function, callType, callData, thisValue, args); + globalObject->globalData().timeoutChecker.stop(); + + if (exec->hadException()) + reportCurrentException(exec); +} + +void ScheduledAction::execute(Document* document) +{ + JSDOMWindow* window = toJSDOMWindow(document->frame(), m_isolatedWorld.get()); + if (!window) + return; + + RefPtr<Frame> frame = window->impl()->frame(); + if (!frame || !frame->script()->canExecuteScripts(AboutToExecuteScript)) + return; + + frame->script()->setProcessingTimerCallback(true); + + if (m_function) { + executeFunctionInContext(window, window->shell(), document); + Document::updateStyleForAllDocuments(); + } else + frame->script()->executeScriptInWorld(m_isolatedWorld.get(), m_code); + + frame->script()->setProcessingTimerCallback(false); +} + +#if ENABLE(WORKERS) +void ScheduledAction::execute(WorkerContext* workerContext) +{ + // In a Worker, the execution should always happen on a worker thread. + ASSERT(workerContext->thread()->threadID() == currentThread()); + + WorkerScriptController* scriptController = workerContext->script(); + + if (m_function) { + JSWorkerContext* contextWrapper = scriptController->workerContextWrapper(); + executeFunctionInContext(contextWrapper, contextWrapper, workerContext); + } else { + ScriptSourceCode code(m_code, workerContext->url()); + scriptController->evaluate(code); + } +} +#endif // ENABLE(WORKERS) + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScheduledAction.h b/Source/WebCore/bindings/js/ScheduledAction.h new file mode 100644 index 0000000..6c9d0ba --- /dev/null +++ b/Source/WebCore/bindings/js/ScheduledAction.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2000 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ScheduledAction_h +#define ScheduledAction_h + +#include "PlatformString.h" +#include <JSDOMBinding.h> +#include <runtime/JSCell.h> +#include <runtime/Protect.h> +#include <wtf/PassOwnPtr.h> +#include <wtf/Vector.h> + +namespace JSC { + class JSGlobalObject; +} + +namespace WebCore { + + class Document; + class ScriptExecutionContext; + class WorkerContext; + + /* An action (either function or string) to be executed after a specified + * time interval, either once or repeatedly. Used for window.setTimeout() + * and window.setInterval() + */ + class ScheduledAction : public Noncopyable { + public: + static PassOwnPtr<ScheduledAction> create(JSC::ExecState*, DOMWrapperWorld* isolatedWorld); + + void execute(ScriptExecutionContext*); + + private: + ScheduledAction(JSC::ExecState*, JSC::JSValue function, DOMWrapperWorld* isolatedWorld); + ScheduledAction(const String& code, DOMWrapperWorld* isolatedWorld) + : m_code(code) + , m_isolatedWorld(isolatedWorld) + { + } + + void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValue thisValue, ScriptExecutionContext*); + void execute(Document*); +#if ENABLE(WORKERS) + void execute(WorkerContext*); +#endif + + JSC::ProtectedJSValue m_function; + Vector<JSC::ProtectedJSValue> m_args; + String m_code; + RefPtr<DOMWrapperWorld> m_isolatedWorld; + }; + +} // namespace WebCore + +#endif // ScheduledAction_h diff --git a/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp b/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp new file mode 100644 index 0000000..16f18d3 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptCachedFrameData.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2008, Google Inc. All rights reserved. + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptCachedFrameData.h" + +#include "Frame.h" +#include "GCController.h" +#include "Page.h" +#include "PageGroup.h" +#include <runtime/JSLock.h> +#include "ScriptController.h" + +using namespace JSC; + +namespace WebCore { + +ScriptCachedFrameData::ScriptCachedFrameData(Frame* frame) + : m_domWindow(0) +{ + JSLock lock(SilenceAssertionsOnly); + + ScriptController* scriptController = frame->script(); + ScriptController::ShellMap& windowShells = scriptController->m_windowShells; + + ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end(); + for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) { + JSDOMWindow* window = iter->second->window(); + m_windows.add(iter->first.get(), window); + m_domWindow = window->impl(); + } + + scriptController->attachDebugger(0); +} + +DOMWindow* ScriptCachedFrameData::domWindow() const +{ + return m_domWindow; +} + +ScriptCachedFrameData::~ScriptCachedFrameData() +{ + clear(); +} + +void ScriptCachedFrameData::restore(Frame* frame) +{ + JSLock lock(SilenceAssertionsOnly); + + ScriptController* scriptController = frame->script(); + ScriptController::ShellMap& windowShells = scriptController->m_windowShells; + + ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end(); + for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) { + DOMWrapperWorld* world = iter->first.get(); + JSDOMWindowShell* windowShell = iter->second.get(); + + if (JSDOMWindow* window = m_windows.get(world)) + windowShell->setWindow(window); + else { + windowShell->setWindow(frame->domWindow()); + + if (Page* page = frame->page()) { + scriptController->attachDebugger(windowShell, page->debugger()); + windowShell->window()->setProfileGroup(page->group().identifier()); + } + } + } +} + +void ScriptCachedFrameData::clear() +{ + if (m_windows.isEmpty()) + return; + + JSLock lock(SilenceAssertionsOnly); + m_windows.clear(); + gcController().garbageCollectSoon(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptCachedFrameData.h b/Source/WebCore/bindings/js/ScriptCachedFrameData.h new file mode 100644 index 0000000..15c23c5 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptCachedFrameData.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2008, Google Inc. All rights reserved. + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptCachedFrameData_h +#define ScriptCachedFrameData_h + +#include <runtime/Protect.h> + +namespace WebCore { + class Frame; + class JSDOMWindow; + class DOMWindow; + class DOMWrapperWorld; + + class ScriptCachedFrameData : public Noncopyable { + typedef HashMap< RefPtr<DOMWrapperWorld>, JSC::ProtectedPtr<JSDOMWindow> > JSDOMWindowSet; + + public: + ScriptCachedFrameData(Frame*); + ~ScriptCachedFrameData(); + + void restore(Frame*); + void clear(); + DOMWindow* domWindow() const; + + private: + JSDOMWindowSet m_windows; + DOMWindow* m_domWindow; + }; + +} // namespace WebCore + +#endif // ScriptCachedFrameData_h diff --git a/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp b/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp new file mode 100644 index 0000000..94cd127 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptCallStackFactory.h" + +#include "JSDOMBinding.h" +#include "ScriptArguments.h" +#include "ScriptCallFrame.h" +#include "ScriptCallStack.h" +#include "ScriptValue.h" +#include <interpreter/CallFrame.h> +#include <interpreter/Interpreter.h> +#include <runtime/ArgList.h> +#include <runtime/JSFunction.h> +#include <runtime/JSGlobalData.h> +#include <runtime/JSValue.h> +#include <runtime/UString.h> + +using namespace JSC; + +namespace WebCore { + +PassRefPtr<ScriptCallStack> createScriptCallStack(size_t, bool) +{ + return 0; +} + +PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize) +{ + Vector<ScriptCallFrame> frames; + CallFrame* callFrame = exec; + while (true) { + ASSERT(callFrame); + int signedLineNumber; + intptr_t sourceID; + UString urlString; + JSValue function; + + exec->interpreter()->retrieveLastCaller(callFrame, signedLineNumber, sourceID, urlString, function); + UString functionName; + if (function) + functionName = asFunction(function)->name(exec); + else { + // Caller is unknown, but if frames is empty we should still add the frame, because + // something called us, and gave us arguments. + if (!frames.isEmpty()) + break; + } + unsigned lineNumber = signedLineNumber >= 0 ? signedLineNumber : 0; + frames.append(ScriptCallFrame(ustringToString(functionName), ustringToString(urlString), lineNumber)); + if (!function || frames.size() == maxStackSize) + break; + callFrame = callFrame->callerFrame(); + } + return ScriptCallStack::create(frames); +} + +PassRefPtr<ScriptArguments> createScriptArguments(JSC::ExecState* exec, unsigned skipArgumentCount) +{ + Vector<ScriptValue> arguments; + size_t argumentCount = exec->argumentCount(); + for (size_t i = skipArgumentCount; i < argumentCount; ++i) + arguments.append(ScriptValue(exec->argument(i))); + return ScriptArguments::create(exec, arguments); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptCallStackFactory.h b/Source/WebCore/bindings/js/ScriptCallStackFactory.h new file mode 100644 index 0000000..2fb36ae --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptCallStackFactory.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptCallStackFactory_h +#define ScriptCallStackFactory_h + +#include <wtf/Forward.h> + +namespace JSC { +class ExecState; +} + +namespace WebCore { + +class ScriptArguments; +class ScriptCallStack; + +PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize, bool emptyStackIsAllowed); +PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState*, size_t maxStackSize); +PassRefPtr<ScriptArguments> createScriptArguments(JSC::ExecState*, unsigned skipArgumentCount); + +} // namespace WebCore + +#endif // ScriptCallStackFactory_h diff --git a/Source/WebCore/bindings/js/ScriptController.cpp b/Source/WebCore/bindings/js/ScriptController.cpp new file mode 100644 index 0000000..cf55080 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptController.cpp @@ -0,0 +1,520 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "ScriptController.h" + +#include "ScriptableDocumentParser.h" +#include "Event.h" +#include "EventNames.h" +#include "Frame.h" +#include "FrameLoaderClient.h" +#include "GCController.h" +#include "HTMLPlugInElement.h" +#include "InspectorInstrumentation.h" +#include "JSDocument.h" +#include "JSMainThreadExecState.h" +#include "NP_jsobject.h" +#include "Page.h" +#include "PageGroup.h" +#include "ScriptSourceCode.h" +#include "ScriptValue.h" +#include "Settings.h" +#include "StorageNamespace.h" +#include "UserGestureIndicator.h" +#include "WebCoreJSClientData.h" +#include "XSSAuditor.h" +#include "npruntime_impl.h" +#include "runtime_root.h" +#include <debugger/Debugger.h> +#include <runtime/InitializeThreading.h> +#include <runtime/JSLock.h> +#include <wtf/Threading.h> + +using namespace JSC; +using namespace std; + +namespace WebCore { + +void ScriptController::initializeThreading() +{ + JSC::initializeThreading(); + WTF::initializeMainThread(); +} + +ScriptController::ScriptController(Frame* frame) + : m_frame(frame) + , m_sourceURL(0) + , m_inExecuteScript(false) + , m_processingTimerCallback(false) + , m_paused(false) + , m_allowPopupsFromPlugin(false) +#if ENABLE(NETSCAPE_PLUGIN_API) + , m_windowScriptNPObject(0) +#endif +#if PLATFORM(MAC) + , m_windowScriptObject(0) +#endif + , m_XSSAuditor(new XSSAuditor(frame)) +{ +#if PLATFORM(MAC) && ENABLE(JAVA_BRIDGE) + static bool initializedJavaJSBindings; + if (!initializedJavaJSBindings) { + initializedJavaJSBindings = true; + initJavaJSBindings(); + } +#endif +} + +ScriptController::~ScriptController() +{ + disconnectPlatformScriptObjects(); + + if (m_cacheableBindingRootObject) { + m_cacheableBindingRootObject->invalidate(); + m_cacheableBindingRootObject = 0; + } + + // It's likely that destroying m_windowShells will create a lot of garbage. + if (!m_windowShells.isEmpty()) { + while (!m_windowShells.isEmpty()) + destroyWindowShell(m_windowShells.begin()->first.get()); + gcController().garbageCollectSoon(); + } +} + +void ScriptController::destroyWindowShell(DOMWrapperWorld* world) +{ + ASSERT(m_windowShells.contains(world)); + m_windowShells.remove(world); + world->didDestroyWindowShell(this); +} + +JSDOMWindowShell* ScriptController::createWindowShell(DOMWrapperWorld* world) +{ + ASSERT(!m_windowShells.contains(world)); + JSDOMWindowShell* windowShell = new JSDOMWindowShell(m_frame->domWindow(), world); + m_windowShells.add(world, windowShell); + world->didCreateWindowShell(this); + return windowShell; +} + +ScriptValue ScriptController::evaluateInWorld(const ScriptSourceCode& sourceCode, DOMWrapperWorld* world, ShouldAllowXSS shouldAllowXSS) +{ + const SourceCode& jsSourceCode = sourceCode.jsSourceCode(); + String sourceURL = ustringToString(jsSourceCode.provider()->url()); + + if (shouldAllowXSS == DoNotAllowXSS && !m_XSSAuditor->canEvaluate(sourceCode.source())) { + // This script is not safe to be evaluated. + return JSValue(); + } + + // evaluate code. Returns the JS return value or 0 + // if there was none, an error occurred or the type couldn't be converted. + + // inlineCode is true for <a href="javascript:doSomething()"> + // and false for <script>doSomething()</script>. Check if it has the + // expected value in all cases. + // See smart window.open policy for where this is used. + JSDOMWindowShell* shell = windowShell(world); + ExecState* exec = shell->window()->globalExec(); + const String* savedSourceURL = m_sourceURL; + m_sourceURL = &sourceURL; + + JSLock lock(SilenceAssertionsOnly); + + RefPtr<Frame> protect = m_frame; + + InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, sourceURL, sourceCode.startLine()); + + exec->globalData().timeoutChecker.start(); + Completion comp = JSMainThreadExecState::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), jsSourceCode, shell); + exec->globalData().timeoutChecker.stop(); + + InspectorInstrumentation::didEvaluateScript(cookie); + + // Evaluating the JavaScript could cause the frame to be deallocated + // so we start the keep alive timer here. + m_frame->keepAlive(); + + if (comp.complType() == Normal || comp.complType() == ReturnValue) { + m_sourceURL = savedSourceURL; + return comp.value(); + } + + if (comp.complType() == Throw || comp.complType() == Interrupted) + reportException(exec, comp.value()); + + m_sourceURL = savedSourceURL; + return JSValue(); +} + +ScriptValue ScriptController::evaluate(const ScriptSourceCode& sourceCode, ShouldAllowXSS shouldAllowXSS) +{ + return evaluateInWorld(sourceCode, mainThreadNormalWorld(), shouldAllowXSS); +} + +PassRefPtr<DOMWrapperWorld> ScriptController::createWorld() +{ + return DOMWrapperWorld::create(JSDOMWindow::commonJSGlobalData()); +} + +void ScriptController::getAllWorlds(Vector<DOMWrapperWorld*>& worlds) +{ + static_cast<WebCoreJSClientData*>(JSDOMWindow::commonJSGlobalData()->clientData)->getAllWorlds(worlds); +} + +void ScriptController::clearWindowShell(bool goingIntoPageCache) +{ + if (m_windowShells.isEmpty()) + return; + + JSLock lock(SilenceAssertionsOnly); + + for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) { + JSDOMWindowShell* windowShell = iter->second; + + // Clear the debugger from the current window before setting the new window. + attachDebugger(windowShell, 0); + + windowShell->window()->willRemoveFromWindowShell(); + windowShell->setWindow(m_frame->domWindow()); + + // An m_cacheableBindingRootObject persists between page navigations + // so needs to know about the new JSDOMWindow. + if (m_cacheableBindingRootObject) + m_cacheableBindingRootObject->updateGlobalObject(windowShell->window()); + + if (Page* page = m_frame->page()) { + attachDebugger(windowShell, page->debugger()); + windowShell->window()->setProfileGroup(page->group().identifier()); + } + } + + // It's likely that resetting our windows created a lot of garbage, unless + // it went in a back/forward cache. + if (!goingIntoPageCache) + gcController().garbageCollectSoon(); +} + +JSDOMWindowShell* ScriptController::initScript(DOMWrapperWorld* world) +{ + ASSERT(!m_windowShells.contains(world)); + + JSLock lock(SilenceAssertionsOnly); + + JSDOMWindowShell* windowShell = createWindowShell(world); + + windowShell->window()->updateDocument(); + + if (Page* page = m_frame->page()) { + attachDebugger(windowShell, page->debugger()); + windowShell->window()->setProfileGroup(page->group().identifier()); + } + + m_frame->loader()->dispatchDidClearWindowObjectInWorld(world); + + return windowShell; +} + +int ScriptController::eventHandlerLineNumber() const +{ + // JSC expects 1-based line numbers, so we must add one here to get it right. + ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser(); + if (parser) + return parser->lineNumber() + 1; + return 0; +} + +bool ScriptController::processingUserGesture() +{ + ExecState* exec = JSMainThreadExecState::currentState(); + Frame* frame = exec ? toDynamicFrame(exec) : 0; + // No script is running, so it is user-initiated unless the gesture stack + // explicitly says it is not. + if (!frame) + return UserGestureIndicator::getUserGestureState() != DefinitelyNotProcessingUserGesture; + + // FIXME: We check the plugin popup flag and javascript anchor navigation + // from the dynamic frame becuase they should only be initiated on the + // dynamic frame in which execution began if they do happen. + ScriptController* scriptController = frame->script(); + ASSERT(scriptController); + if (scriptController->allowPopupsFromPlugin() || scriptController->isJavaScriptAnchorNavigation()) + return true; + + // If a DOM event is being processed, check that it was initiated by the user + // and that it is in the whitelist of event types allowed to generate pop-ups. + if (JSDOMWindowShell* shell = scriptController->existingWindowShell(currentWorld(exec))) + if (Event* event = shell->window()->currentEvent()) + return event->fromUserGesture(); + + return UserGestureIndicator::processingUserGesture(); +} + +// FIXME: This seems like an insufficient check to verify a click on a javascript: anchor. +bool ScriptController::isJavaScriptAnchorNavigation() const +{ + // This is the <a href="javascript:window.open('...')> case -> we let it through + if (m_sourceURL && m_sourceURL->isNull() && !m_processingTimerCallback) + return true; + + // This is the <script>window.open(...)</script> case or a timer callback -> block it + return false; +} + +bool ScriptController::anyPageIsProcessingUserGesture() const +{ + Page* page = m_frame->page(); + if (!page) + return false; + + const HashSet<Page*>& pages = page->group().pages(); + HashSet<Page*>::const_iterator end = pages.end(); + for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { + for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) { + ScriptController* script = frame->script(); + + if (script->m_allowPopupsFromPlugin) + return true; + + const ShellMap::const_iterator iterEnd = m_windowShells.end(); + for (ShellMap::const_iterator iter = m_windowShells.begin(); iter != iterEnd; ++iter) { + JSDOMWindowShell* shell = iter->second.get(); + Event* event = shell->window()->currentEvent(); + if (event && event->fromUserGesture()) + return true; + } + + if (isJavaScriptAnchorNavigation()) + return true; + } + } + + return false; +} + +bool ScriptController::canAccessFromCurrentOrigin(Frame *frame) +{ + ExecState* exec = JSMainThreadExecState::currentState(); + if (exec) + return allowsAccessFromFrame(exec, frame); + // If the current state is 0 we're in a call path where the DOM security + // check doesn't apply (eg. parser). + return true; +} + +void ScriptController::attachDebugger(JSC::Debugger* debugger) +{ + for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) + attachDebugger(iter->second, debugger); +} + +void ScriptController::attachDebugger(JSDOMWindowShell* shell, JSC::Debugger* debugger) +{ + if (!shell) + return; + + JSDOMWindow* globalObject = shell->window(); + if (debugger) + debugger->attach(globalObject); + else if (JSC::Debugger* currentDebugger = globalObject->debugger()) + currentDebugger->detach(globalObject); +} + +void ScriptController::updateDocument() +{ + if (!m_frame->document()) + return; + + JSLock lock(SilenceAssertionsOnly); + for (ShellMap::iterator iter = m_windowShells.begin(); iter != m_windowShells.end(); ++iter) + iter->second->window()->updateDocument(); +} + +void ScriptController::updateSecurityOrigin() +{ + // Our bindings do not do anything in this case. +} + +Bindings::RootObject* ScriptController::cacheableBindingRootObject() +{ + if (!canExecuteScripts(NotAboutToExecuteScript)) + return 0; + + if (!m_cacheableBindingRootObject) { + JSLock lock(SilenceAssertionsOnly); + m_cacheableBindingRootObject = Bindings::RootObject::create(0, globalObject(pluginWorld())); + } + return m_cacheableBindingRootObject.get(); +} + +Bindings::RootObject* ScriptController::bindingRootObject() +{ + if (!canExecuteScripts(NotAboutToExecuteScript)) + return 0; + + if (!m_bindingRootObject) { + JSLock lock(SilenceAssertionsOnly); + m_bindingRootObject = Bindings::RootObject::create(0, globalObject(pluginWorld())); + } + return m_bindingRootObject.get(); +} + +PassRefPtr<Bindings::RootObject> ScriptController::createRootObject(void* nativeHandle) +{ + RootObjectMap::iterator it = m_rootObjects.find(nativeHandle); + if (it != m_rootObjects.end()) + return it->second; + + RefPtr<Bindings::RootObject> rootObject = Bindings::RootObject::create(nativeHandle, globalObject(pluginWorld())); + + m_rootObjects.set(nativeHandle, rootObject); + return rootObject.release(); +} + +#if ENABLE(INSPECTOR) +void ScriptController::setCaptureCallStackForUncaughtExceptions(bool) +{ +} +#endif + +#if ENABLE(NETSCAPE_PLUGIN_API) + +NPObject* ScriptController::windowScriptNPObject() +{ + if (!m_windowScriptNPObject) { + if (canExecuteScripts(NotAboutToExecuteScript)) { + // JavaScript is enabled, so there is a JavaScript window object. + // Return an NPObject bound to the window object. + JSC::JSLock lock(SilenceAssertionsOnly); + JSObject* win = windowShell(pluginWorld())->window(); + ASSERT(win); + Bindings::RootObject* root = bindingRootObject(); + m_windowScriptNPObject = _NPN_CreateScriptObject(0, win, root); + } else { + // JavaScript is not enabled, so we cannot bind the NPObject to the JavaScript window object. + // Instead, we create an NPObject of a different class, one which is not bound to a JavaScript object. + m_windowScriptNPObject = _NPN_CreateNoScriptObject(); + } + } + + return m_windowScriptNPObject; +} + +NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement* plugin) +{ + JSObject* object = jsObjectForPluginElement(plugin); + if (!object) + return _NPN_CreateNoScriptObject(); + + // Wrap the JSObject in an NPObject + return _NPN_CreateScriptObject(0, object, bindingRootObject()); +} + +#endif + +JSObject* ScriptController::jsObjectForPluginElement(HTMLPlugInElement* plugin) +{ + // Can't create JSObjects when JavaScript is disabled + if (!canExecuteScripts(NotAboutToExecuteScript)) + return 0; + + // Create a JSObject bound to this element + JSLock lock(SilenceAssertionsOnly); + JSDOMWindow* globalObj = globalObject(pluginWorld()); + // FIXME: is normal okay? - used for NP plugins? + JSValue jsElementValue = toJS(globalObj->globalExec(), globalObj, plugin); + if (!jsElementValue || !jsElementValue.isObject()) + return 0; + + return jsElementValue.getObject(); +} + +#if !PLATFORM(MAC) + +void ScriptController::updatePlatformScriptObjects() +{ +} + +void ScriptController::disconnectPlatformScriptObjects() +{ +} + +#endif + +void ScriptController::cleanupScriptObjectsForPlugin(void* nativeHandle) +{ + RootObjectMap::iterator it = m_rootObjects.find(nativeHandle); + + if (it == m_rootObjects.end()) + return; + + it->second->invalidate(); + m_rootObjects.remove(it); +} + +void ScriptController::clearScriptObjects() +{ + JSLock lock(SilenceAssertionsOnly); + + RootObjectMap::const_iterator end = m_rootObjects.end(); + for (RootObjectMap::const_iterator it = m_rootObjects.begin(); it != end; ++it) + it->second->invalidate(); + + m_rootObjects.clear(); + + if (m_bindingRootObject) { + m_bindingRootObject->invalidate(); + m_bindingRootObject = 0; + } + +#if ENABLE(NETSCAPE_PLUGIN_API) + if (m_windowScriptNPObject) { + // Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that we don't leak if a plugin fails to release the window + // script object properly. + // This shouldn't cause any problems for plugins since they should have already been stopped and destroyed at this point. + _NPN_DeallocateObject(m_windowScriptNPObject); + m_windowScriptNPObject = 0; + } +#endif +} + +ScriptValue ScriptController::executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture, ShouldAllowXSS shouldAllowXSS) +{ + ScriptSourceCode sourceCode(script, forceUserGesture ? KURL() : m_frame->document()->url()); + + if (!canExecuteScripts(AboutToExecuteScript) || isPaused()) + return ScriptValue(); + + bool wasInExecuteScript = m_inExecuteScript; + m_inExecuteScript = true; + + ScriptValue result = evaluateInWorld(sourceCode, world, shouldAllowXSS); + + if (!wasInExecuteScript) { + m_inExecuteScript = false; + Document::updateStyleForAllDocuments(); + } + + return result; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptController.h b/Source/WebCore/bindings/js/ScriptController.h new file mode 100644 index 0000000..413b88a --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptController.h @@ -0,0 +1,212 @@ +/* + * Copyright (C) 1999 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ScriptController_h +#define ScriptController_h + +#include "JSDOMWindowShell.h" +#include "ScriptControllerBase.h" +#include "ScriptInstance.h" +#include <runtime/Protect.h> +#include <wtf/Forward.h> +#include <wtf/RefPtr.h> + +#if PLATFORM(MAC) +#include <wtf/RetainPtr.h> + +#ifdef __OBJC__ +@class WebScriptObject; +#else +class WebScriptObject; +#endif +#endif + +struct NPObject; + +namespace JSC { + class JSGlobalObject; + + namespace Bindings { + class RootObject; + } +} + +namespace WebCore { + +class Event; +class EventListener; +class HTMLPlugInElement; +class Frame; +class Node; +class ScriptSourceCode; +class ScriptValue; +class Widget; +class XSSAuditor; + +typedef HashMap<void*, RefPtr<JSC::Bindings::RootObject> > RootObjectMap; + +class ScriptController { + friend class ScriptCachedFrameData; + typedef WTF::HashMap< RefPtr<DOMWrapperWorld>, JSC::ProtectedPtr<JSDOMWindowShell> > ShellMap; + +public: + ScriptController(Frame*); + ~ScriptController(); + + static PassRefPtr<DOMWrapperWorld> createWorld(); + + JSDOMWindowShell* createWindowShell(DOMWrapperWorld*); + void destroyWindowShell(DOMWrapperWorld*); + + JSDOMWindowShell* windowShell(DOMWrapperWorld* world) + { + ShellMap::iterator iter = m_windowShells.find(world); + return (iter != m_windowShells.end()) ? iter->second.get() : initScript(world); + } + JSDOMWindowShell* existingWindowShell(DOMWrapperWorld* world) const + { + ShellMap::const_iterator iter = m_windowShells.find(world); + return (iter != m_windowShells.end()) ? iter->second.get() : 0; + } + JSDOMWindow* globalObject(DOMWrapperWorld* world) + { + return windowShell(world)->window(); + } + + static void getAllWorlds(Vector<DOMWrapperWorld*>&); + + ScriptValue executeScript(const ScriptSourceCode&, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); + ScriptValue executeScript(const String& script, bool forceUserGesture = false, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); + ScriptValue executeScriptInWorld(DOMWrapperWorld* world, const String& script, bool forceUserGesture = false, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); + + // Returns true if argument is a JavaScript URL. + bool executeIfJavaScriptURL(const KURL&, ShouldReplaceDocumentIfJavaScriptURL shouldReplaceDocumentIfJavaScriptURL = ReplaceDocumentIfJavaScriptURL); + + // This function must be called from the main thread. It is safe to call it repeatedly. + // Darwin is an exception to this rule: it is OK to call this function from any thread, even reentrantly. + static void initializeThreading(); + + ScriptValue evaluate(const ScriptSourceCode&, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); + ScriptValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld*, ShouldAllowXSS shouldAllowXSS = DoNotAllowXSS); + + int eventHandlerLineNumber() const; + + void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; } + static bool processingUserGesture(); + bool anyPageIsProcessingUserGesture() const; + + static bool canAccessFromCurrentOrigin(Frame*); + bool canExecuteScripts(ReasonForCallingCanExecuteScripts); + + // Debugger can be 0 to detach any existing Debugger. + void attachDebugger(JSC::Debugger*); // Attaches/detaches in all worlds/window shells. + void attachDebugger(JSDOMWindowShell*, JSC::Debugger*); + + void setPaused(bool b) { m_paused = b; } + bool isPaused() const { return m_paused; } + + void setAllowPopupsFromPlugin(bool allowPopupsFromPlugin) { m_allowPopupsFromPlugin = allowPopupsFromPlugin; } + bool allowPopupsFromPlugin() const { return m_allowPopupsFromPlugin; } + + const String* sourceURL() const { return m_sourceURL; } // 0 if we are not evaluating any script + + void clearWindowShell(bool goingIntoPageCache = false); + void updateDocument(); + + void namedItemAdded(HTMLDocument*, const AtomicString&) { } + void namedItemRemoved(HTMLDocument*, const AtomicString&) { } + + // Notifies the ScriptController that the securityOrigin of the current + // document was modified. For example, this method is called when + // document.domain is set. This method is *not* called when a new document + // is attached to a frame because updateDocument() is called instead. + void updateSecurityOrigin(); + + void clearScriptObjects(); + void cleanupScriptObjectsForPlugin(void*); + + void updatePlatformScriptObjects(); + + PassScriptInstance createScriptInstanceForWidget(Widget*); + JSC::Bindings::RootObject* bindingRootObject(); + JSC::Bindings::RootObject* cacheableBindingRootObject(); + + PassRefPtr<JSC::Bindings::RootObject> createRootObject(void* nativeHandle); + +#if ENABLE(INSPECTOR) + static void setCaptureCallStackForUncaughtExceptions(bool); +#endif + +#if PLATFORM(MAC) +#if ENABLE(JAVA_BRIDGE) + static void initJavaJSBindings(); +#endif + WebScriptObject* windowScriptObject(); +#endif + + JSC::JSObject* jsObjectForPluginElement(HTMLPlugInElement*); + +#if ENABLE(NETSCAPE_PLUGIN_API) + NPObject* createScriptObjectForPluginElement(HTMLPlugInElement*); + NPObject* windowScriptNPObject(); +#endif + + XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); } + +private: + JSDOMWindowShell* initScript(DOMWrapperWorld* world); + + void disconnectPlatformScriptObjects(); + + bool isJavaScriptAnchorNavigation() const; + + ShellMap m_windowShells; + Frame* m_frame; + const String* m_sourceURL; + + bool m_inExecuteScript; + + bool m_processingTimerCallback; + bool m_paused; + bool m_allowPopupsFromPlugin; + + // The root object used for objects bound outside the context of a plugin, such + // as NPAPI plugins. The plugins using these objects prevent a page from being cached so they + // are safe to invalidate() when WebKit navigates away from the page that contains them. + RefPtr<JSC::Bindings::RootObject> m_bindingRootObject; + // Unlike m_bindingRootObject these objects are used in pages that are cached, so they are not invalidate()'d. + // This ensures they are still available when the page is restored. + RefPtr<JSC::Bindings::RootObject> m_cacheableBindingRootObject; + RootObjectMap m_rootObjects; +#if ENABLE(NETSCAPE_PLUGIN_API) + NPObject* m_windowScriptNPObject; +#endif +#if PLATFORM(MAC) + RetainPtr<WebScriptObject> m_windowScriptObject; +#endif + + // The XSSAuditor associated with this ScriptController. + OwnPtr<XSSAuditor> m_XSSAuditor; +}; + +} // namespace WebCore + +#endif // ScriptController_h diff --git a/Source/WebCore/bindings/js/ScriptControllerBrew.cpp b/Source/WebCore/bindings/js/ScriptControllerBrew.cpp new file mode 100644 index 0000000..d8d345a --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerBrew.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 Apple Computer, Inc. + * Copyright (C) 2009 Company 100, Inc. + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Bridge.h" +#include "PluginView.h" +#include "runtime_root.h" + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(WebCore::Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); + +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptControllerEfl.cpp b/Source/WebCore/bindings/js/ScriptControllerEfl.cpp new file mode 100644 index 0000000..fea172e --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerEfl.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * Copyright (C) 2009,2010 ProFUSION embedded systems + * Copyright (C) 2009,2010 Samsung Electronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "PluginView.h" + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} diff --git a/Source/WebCore/bindings/js/ScriptControllerGtk.cpp b/Source/WebCore/bindings/js/ScriptControllerGtk.cpp new file mode 100644 index 0000000..6ffae69 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerGtk.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com + * Copyright (C) 2007 Holger Hans Peter Freyther + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Bridge.h" +#include "PluginView.h" +#include "runtime_root.h" + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} diff --git a/Source/WebCore/bindings/js/ScriptControllerHaiku.cpp b/Source/WebCore/bindings/js/ScriptControllerHaiku.cpp new file mode 100644 index 0000000..a1f1590 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerHaiku.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2008 Apple Computer, Inc. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Bridge.h" +#include "PluginView.h" +#include "runtime_root.h" + + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} // namespace WebCore + diff --git a/Source/WebCore/bindings/js/ScriptControllerMac.mm b/Source/WebCore/bindings/js/ScriptControllerMac.mm new file mode 100644 index 0000000..7c29bfc --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerMac.mm @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import "ScriptController.h" + +#import "Bridge.h" +#import "DOMAbstractViewFrame.h" +#import "DOMWindow.h" +#import "Frame.h" +#import "FrameLoader.h" +#import "FrameLoaderClient.h" +#import "JSDOMWindow.h" +#import "WebScriptObjectPrivate.h" +#import "Widget.h" +#import "objc_instance.h" +#import "runtime_root.h" +#import <JavaScriptCore/APICast.h> +#import <runtime/JSLock.h> + +#if ENABLE(NETSCAPE_PLUGIN_API) +#import "c_instance.h" +#import "NP_jsobject.h" +#import "npruntime_impl.h" +#endif + +#if ENABLE(JAVA_BRIDGE) +#import "JavaInstanceJSC.h" +#endif + +@interface NSObject (WebPlugin) +- (id)objectForWebScript; +- (NPObject *)createPluginScriptableObject; +- (PassRefPtr<JSC::Bindings::Instance>)createPluginBindingsInstance:(PassRefPtr<JSC::Bindings::RootObject>)rootObject; +@end + +using namespace JSC::Bindings; + +namespace WebCore { + +PassScriptInstance ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + NSView* widgetView = widget->platformWidget(); + if (!widgetView) + return 0; + + RefPtr<RootObject> rootObject = createRootObject(widgetView); + + if ([widgetView respondsToSelector:@selector(createPluginBindingsInstance:)]) + return [widgetView createPluginBindingsInstance:rootObject.release()]; + + if ([widgetView respondsToSelector:@selector(objectForWebScript)]) { + id objectForWebScript = [widgetView objectForWebScript]; + if (!objectForWebScript) + return 0; + return JSC::Bindings::ObjcInstance::create(objectForWebScript, rootObject.release()); + } + + if ([widgetView respondsToSelector:@selector(createPluginScriptableObject)]) { +#if !ENABLE(NETSCAPE_PLUGIN_API) + return 0; +#else + NPObject* npObject = [widgetView createPluginScriptableObject]; + if (!npObject) + return 0; + RefPtr<Instance> instance = JSC::Bindings::CInstance::create(npObject, rootObject.release()); + // -createPluginScriptableObject returns a retained NPObject. The caller is expected to release it. + _NPN_ReleaseObject(npObject); + return instance.release(); +#endif + } + +#if ENABLE(JAVA_BRIDGE) + jobject applet = m_frame->loader()->client()->javaApplet(widgetView); + if (!applet) + return 0; + return JSC::Bindings::JavaInstance::create(applet, rootObject.release()); +#else + return 0; +#endif +} + +WebScriptObject* ScriptController::windowScriptObject() +{ + if (!canExecuteScripts(NotAboutToExecuteScript)) + return 0; + + if (!m_windowScriptObject) { + JSC::JSLock lock(JSC::SilenceAssertionsOnly); + JSC::Bindings::RootObject* root = bindingRootObject(); + m_windowScriptObject = [WebScriptObject scriptObjectForJSObject:toRef(windowShell(pluginWorld())) originRootObject:root rootObject:root]; + } + + ASSERT([m_windowScriptObject.get() isKindOfClass:[DOMAbstractView class]]); + return m_windowScriptObject.get(); +} + +void ScriptController::updatePlatformScriptObjects() +{ + if (m_windowScriptObject) { + JSC::Bindings::RootObject* root = bindingRootObject(); + [m_windowScriptObject.get() _setOriginRootObject:root andRootObject:root]; + } +} + +void ScriptController::disconnectPlatformScriptObjects() +{ + if (m_windowScriptObject) { + ASSERT([m_windowScriptObject.get() isKindOfClass:[DOMAbstractView class]]); + [(DOMAbstractView *)m_windowScriptObject.get() _disconnectFrame]; + } +} + +#if ENABLE(JAVA_BRIDGE) + +static pthread_t mainThread; + +static void updateStyleIfNeededForBindings(JSC::ExecState*, JSC::JSObject* rootObject) +{ + if (pthread_self() != mainThread) + return; + + if (!rootObject) + return; + + JSDOMWindow* window = static_cast<JSDOMWindow*>(rootObject); + if (!window) + return; + + Frame* frame = window->impl()->frame(); + if (!frame) + return; + + frame->document()->updateStyleIfNeeded(); +} + +void ScriptController::initJavaJSBindings() +{ + mainThread = pthread_self(); + JSC::Bindings::JavaJSObject::initializeJNIThreading(); + JSC::Bindings::Instance::setDidExecuteFunction(updateStyleIfNeededForBindings); +} + +#endif + +} diff --git a/Source/WebCore/bindings/js/ScriptControllerQt.cpp b/Source/WebCore/bindings/js/ScriptControllerQt.cpp new file mode 100644 index 0000000..ee7ceff --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerQt.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> + * Copyright (C) 2006 Zack Rusin <zack@kde.org> + * Copyright (C) 2006 George Staikos <staikos@kde.org> + * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2006 Rob Buis <buis@kde.org> + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Bridge.h" +#include "DOMWindow.h" +#include "PluginView.h" +#include "qt_instance.h" +#include "runtime_root.h" + +#include <QWidget> + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(WebCore::Widget* widget) +{ + if (widget->isPluginView()) { + PluginView* pluginView = static_cast<PluginView*>(widget); + return pluginView->bindingInstance(); + } + + QObject* object = widget->bindingObject(); + + if (!object) + object = widget->platformWidget(); + + if (!object) + return 0; + + return JSC::Bindings::QtInstance::getQtInstance(object, bindingRootObject(), QScriptEngine::QtOwnership); +} + +} +// vim: ts=4 sw=4 et diff --git a/Source/WebCore/bindings/js/ScriptControllerWin.cpp b/Source/WebCore/bindings/js/ScriptControllerWin.cpp new file mode 100644 index 0000000..e0a959e --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerWin.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008 Eric Seidel <eric@webkit.org> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Bridge.h" +#include "PluginView.h" + +using namespace JSC::Bindings; + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptControllerWx.cpp b/Source/WebCore/bindings/js/ScriptControllerWx.cpp new file mode 100644 index 0000000..1d7b4ca --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptControllerWx.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2008 Apple Computer, Inc. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptController.h" + +#include "Bridge.h" +#include "PluginView.h" +#include "runtime_root.h" + +namespace WebCore { + +PassRefPtr<JSC::Bindings::Instance> ScriptController::createScriptInstanceForWidget(Widget* widget) +{ + if (!widget->isPluginView()) + return 0; + + return static_cast<PluginView*>(widget)->bindingInstance(); +} + +} diff --git a/Source/WebCore/bindings/js/ScriptDebugServer.cpp b/Source/WebCore/bindings/js/ScriptDebugServer.cpp new file mode 100644 index 0000000..10df223 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptDebugServer.cpp @@ -0,0 +1,618 @@ +/* + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptDebugServer.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +#include "DOMWindow.h" +#include "EventLoop.h" +#include "Frame.h" +#include "FrameTree.h" +#include "FrameView.h" +#include "JSDOMWindowCustom.h" +#include "JavaScriptCallFrame.h" +#include "Page.h" +#include "PageGroup.h" +#include "PluginView.h" +#include "ScriptBreakpoint.h" +#include "ScriptController.h" +#include "ScriptDebugListener.h" +#include "ScrollView.h" +#include "Widget.h" +#include <debugger/DebuggerCallFrame.h> +#include <parser/SourceCode.h> +#include <runtime/JSLock.h> +#include <wtf/text/StringConcatenate.h> +#include <wtf/MainThread.h> +#include <wtf/StdLibExtras.h> +#include <wtf/UnusedParam.h> + +using namespace JSC; + +namespace WebCore { + +ScriptDebugServer& ScriptDebugServer::shared() +{ + DEFINE_STATIC_LOCAL(ScriptDebugServer, server, ()); + return server; +} + +ScriptDebugServer::ScriptDebugServer() + : m_callingListeners(false) + , m_pauseOnExceptionsState(DontPauseOnExceptions) + , m_pauseOnNextStatement(false) + , m_paused(false) + , m_pausedPage(0) + , m_doneProcessingDebuggerEvents(true) + , m_breakpointsActivated(true) + , m_pauseOnCallFrame(0) + , m_recompileTimer(this, &ScriptDebugServer::recompileAllJSFunctions) +{ +} + +ScriptDebugServer::~ScriptDebugServer() +{ + deleteAllValues(m_pageListenersMap); +} + +void ScriptDebugServer::addListener(ScriptDebugListener* listener, Page* page) +{ + ASSERT_ARG(listener, listener); + ASSERT_ARG(page, page); + + pair<PageListenersMap::iterator, bool> result = m_pageListenersMap.add(page, 0); + if (result.second) + result.first->second = new ListenerSet; + + ListenerSet* listeners = result.first->second; + listeners->add(listener); + + didAddListener(page); +} + +void ScriptDebugServer::removeListener(ScriptDebugListener* listener, Page* page) +{ + ASSERT_ARG(listener, listener); + ASSERT_ARG(page, page); + + PageListenersMap::iterator it = m_pageListenersMap.find(page); + if (it == m_pageListenersMap.end()) + return; + + ListenerSet* listeners = it->second; + listeners->remove(listener); + if (listeners->isEmpty()) { + m_pageListenersMap.remove(it); + delete listeners; + } + + didRemoveListener(page); +} + +void ScriptDebugServer::pageCreated(Page* page) +{ + ASSERT_ARG(page, page); + + if (!hasListenersInterestedInPage(page)) + return; + page->setDebugger(this); +} + +bool ScriptDebugServer::isDebuggerAlwaysEnabled() +{ + return false; +} + +bool ScriptDebugServer::hasListenersInterestedInPage(Page* page) +{ + ASSERT_ARG(page, page); + + return m_pageListenersMap.contains(page); +} + +String ScriptDebugServer::setBreakpoint(const String& sourceID, unsigned lineNumber, const String& condition, bool enabled, unsigned* actualLineNumber) +{ + intptr_t sourceIDValue = sourceID.toIntPtr(); + if (!sourceIDValue) + return ""; + BreakpointsMap::iterator it = m_breakpoints.find(sourceIDValue); + if (it == m_breakpoints.end()) + it = m_breakpoints.set(sourceIDValue, SourceBreakpoints()).first; + if (it->second.contains(lineNumber)) + return ""; + it->second.set(lineNumber, ScriptBreakpoint(enabled, condition)); + *actualLineNumber = lineNumber; + return makeString(sourceID, ":", String::number(lineNumber)); +} + +void ScriptDebugServer::removeBreakpoint(const String& breakpointId) +{ + Vector<String> tokens; + breakpointId.split(":", tokens); + if (tokens.size() != 2) + return; + bool success; + intptr_t sourceIDValue = tokens[0].toIntPtr(&success); + if (!success) + return; + unsigned lineNumber = tokens[1].toUInt(&success); + if (!success) + return; + BreakpointsMap::iterator it = m_breakpoints.find(sourceIDValue); + if (it != m_breakpoints.end()) + it->second.remove(lineNumber); +} + +bool ScriptDebugServer::hasBreakpoint(intptr_t sourceID, unsigned lineNumber) const +{ + if (!m_breakpointsActivated) + return false; + + BreakpointsMap::const_iterator it = m_breakpoints.find(sourceID); + if (it == m_breakpoints.end()) + return false; + SourceBreakpoints::const_iterator breakIt = it->second.find(lineNumber); + if (breakIt == it->second.end() || !breakIt->second.enabled) + return false; + + // An empty condition counts as no condition which is equivalent to "true". + if (breakIt->second.condition.isEmpty()) + return true; + + JSValue exception; + JSValue result = m_currentCallFrame->evaluate(stringToUString(breakIt->second.condition), exception); + if (exception) { + // An erroneous condition counts as "false". + return false; + } + return result.toBoolean(m_currentCallFrame->scopeChain()->globalObject->globalExec()); +} + +void ScriptDebugServer::clearBreakpoints() +{ + m_breakpoints.clear(); +} + +void ScriptDebugServer::setBreakpointsActivated(bool activated) +{ + m_breakpointsActivated = activated; +} + +void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pause) +{ + m_pauseOnExceptionsState = pause; +} + +void ScriptDebugServer::setPauseOnNextStatement(bool pause) +{ + m_pauseOnNextStatement = pause; +} + +void ScriptDebugServer::breakProgram() +{ + // FIXME(WK43332): implement this. +} + +void ScriptDebugServer::continueProgram() +{ + if (!m_paused) + return; + + m_pauseOnNextStatement = false; + m_doneProcessingDebuggerEvents = true; +} + +void ScriptDebugServer::stepIntoStatement() +{ + if (!m_paused) + return; + + m_pauseOnNextStatement = true; + m_doneProcessingDebuggerEvents = true; +} + +void ScriptDebugServer::stepOverStatement() +{ + if (!m_paused) + return; + + m_pauseOnCallFrame = m_currentCallFrame.get(); + m_doneProcessingDebuggerEvents = true; +} + +void ScriptDebugServer::stepOutOfFunction() +{ + if (!m_paused) + return; + + m_pauseOnCallFrame = m_currentCallFrame ? m_currentCallFrame->caller() : 0; + m_doneProcessingDebuggerEvents = true; +} + +bool ScriptDebugServer::editScriptSource(const String&, const String&, String&) +{ + // FIXME(40300): implement this. + return false; +} + +JavaScriptCallFrame* ScriptDebugServer::currentCallFrame() +{ + if (!m_paused) + return 0; + return m_currentCallFrame.get(); +} + +void ScriptDebugServer::dispatchDidPause(ScriptDebugListener* listener) +{ + ASSERT(m_paused); + ScriptState* state = m_currentCallFrame->scopeChain()->globalObject->globalExec(); + listener->didPause(state); +} + +void ScriptDebugServer::dispatchDidContinue(ScriptDebugListener* listener) +{ + listener->didContinue(); +} + +void ScriptDebugServer::dispatchDidParseSource(const ListenerSet& listeners, const JSC::SourceCode& source, ScriptWorldType worldType) +{ + String sourceID = ustringToString(JSC::UString::number(source.provider()->asID())); + String url = ustringToString(source.provider()->url()); + String data = ustringToString(JSC::UString(source.data(), source.length())); + int firstLine = source.firstLine(); + + Vector<ScriptDebugListener*> copy; + copyToVector(listeners, copy); + for (size_t i = 0; i < copy.size(); ++i) + copy[i]->didParseSource(sourceID, url, data, firstLine, worldType); +} + +void ScriptDebugServer::dispatchFailedToParseSource(const ListenerSet& listeners, const SourceCode& source, int errorLine, const String& errorMessage) +{ + String url = ustringToString(source.provider()->url()); + String data = ustringToString(JSC::UString(source.data(), source.length())); + int firstLine = source.firstLine(); + + Vector<ScriptDebugListener*> copy; + copyToVector(listeners, copy); + for (size_t i = 0; i < copy.size(); ++i) + copy[i]->failedToParseSource(url, data, firstLine, errorLine, errorMessage); +} + +static Page* toPage(JSGlobalObject* globalObject) +{ + ASSERT_ARG(globalObject, globalObject); + + JSDOMWindow* window = asJSDOMWindow(globalObject); + Frame* frame = window->impl()->frame(); + return frame ? frame->page() : 0; +} + +static ScriptWorldType currentWorldType(ExecState* exec) +{ + if (currentWorld(exec) == mainThreadNormalWorld()) + return MAIN_WORLD; + return EXTENSIONS_WORLD; +} + +void ScriptDebugServer::detach(JSGlobalObject* globalObject) +{ + // If we're detaching from the currently executing global object, manually tear down our + // stack, since we won't get further debugger callbacks to do so. Also, resume execution, + // since there's no point in staying paused once a window closes. + if (m_currentCallFrame && m_currentCallFrame->dynamicGlobalObject() == globalObject) { + m_currentCallFrame = 0; + m_pauseOnCallFrame = 0; + continueProgram(); + } + Debugger::detach(globalObject); +} + +void ScriptDebugServer::sourceParsed(ExecState* exec, const SourceCode& source, int errorLine, const UString& errorMessage) +{ + if (m_callingListeners) + return; + + Page* page = toPage(exec->lexicalGlobalObject()); + if (!page) + return; + + ScriptWorldType worldType = currentWorldType(exec); + + m_callingListeners = true; + + bool isError = errorLine != -1; + + if (ListenerSet* pageListeners = m_pageListenersMap.get(page)) { + ASSERT(!pageListeners->isEmpty()); + if (isError) + dispatchFailedToParseSource(*pageListeners, source, errorLine, ustringToString(errorMessage)); + else + dispatchDidParseSource(*pageListeners, source, worldType); + } + + m_callingListeners = false; +} + +void ScriptDebugServer::dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback) +{ + Vector<ScriptDebugListener*> copy; + copyToVector(listeners, copy); + for (size_t i = 0; i < copy.size(); ++i) + (this->*callback)(copy[i]); +} + +void ScriptDebugServer::dispatchFunctionToListeners(JavaScriptExecutionCallback callback, Page* page) +{ + if (m_callingListeners) + return; + + m_callingListeners = true; + + if (ListenerSet* pageListeners = m_pageListenersMap.get(page)) { + ASSERT(!pageListeners->isEmpty()); + dispatchFunctionToListeners(*pageListeners, callback); + } + + m_callingListeners = false; +} + +void ScriptDebugServer::setJavaScriptPaused(const PageGroup& pageGroup, bool paused) +{ + setMainThreadCallbacksPaused(paused); + + const HashSet<Page*>& pages = pageGroup.pages(); + + HashSet<Page*>::const_iterator end = pages.end(); + for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) + setJavaScriptPaused(*it, paused); +} + +void ScriptDebugServer::setJavaScriptPaused(Page* page, bool paused) +{ + ASSERT_ARG(page, page); + + page->setDefersLoading(paused); + + for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) + setJavaScriptPaused(frame, paused); +} + +void ScriptDebugServer::setJavaScriptPaused(Frame* frame, bool paused) +{ + ASSERT_ARG(frame, frame); + + if (!frame->script()->canExecuteScripts(NotAboutToExecuteScript)) + return; + + frame->script()->setPaused(paused); + + Document* document = frame->document(); + if (paused) + document->suspendActiveDOMObjects(ActiveDOMObject::JavaScriptDebuggerPaused); + else + document->resumeActiveDOMObjects(); + + setJavaScriptPaused(frame->view(), paused); +} + +void ScriptDebugServer::setJavaScriptPaused(FrameView* view, bool paused) +{ + if (!view) + return; + + const HashSet<RefPtr<Widget> >* children = view->children(); + ASSERT(children); + + HashSet<RefPtr<Widget> >::const_iterator end = children->end(); + for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) { + Widget* widget = (*it).get(); + if (!widget->isPluginView()) + continue; + static_cast<PluginView*>(widget)->setJavaScriptPaused(paused); + } +} + +void ScriptDebugServer::pauseIfNeeded(Page* page) +{ + if (m_paused) + return; + + if (!page || !hasListenersInterestedInPage(page)) + return; + + bool pauseNow = m_pauseOnNextStatement; + pauseNow |= (m_pauseOnCallFrame == m_currentCallFrame); + pauseNow |= (m_currentCallFrame->line() > 0 && hasBreakpoint(m_currentCallFrame->sourceID(), m_currentCallFrame->line())); + if (!pauseNow) + return; + + m_pauseOnCallFrame = 0; + m_pauseOnNextStatement = false; + m_paused = true; + m_pausedPage = page; + + dispatchFunctionToListeners(&ScriptDebugServer::dispatchDidPause, page); + + setJavaScriptPaused(page->group(), true); + + TimerBase::fireTimersInNestedEventLoop(); + + EventLoop loop; + m_doneProcessingDebuggerEvents = false; + while (!m_doneProcessingDebuggerEvents && !loop.ended()) + loop.cycle(); + + setJavaScriptPaused(page->group(), false); + + m_paused = false; + m_pausedPage = 0; + + dispatchFunctionToListeners(&ScriptDebugServer::dispatchDidContinue, page); +} + +void ScriptDebugServer::callEvent(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber) +{ + if (m_paused) + return; + + m_currentCallFrame = JavaScriptCallFrame::create(debuggerCallFrame, m_currentCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); +} + +void ScriptDebugServer::atStatement(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber) +{ + if (m_paused) + return; + + ASSERT(m_currentCallFrame); + if (!m_currentCallFrame) + return; + + m_currentCallFrame->update(debuggerCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); +} + +void ScriptDebugServer::returnEvent(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber) +{ + if (m_paused) + return; + + ASSERT(m_currentCallFrame); + if (!m_currentCallFrame) + return; + + m_currentCallFrame->update(debuggerCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); + + // detach may have been called during pauseIfNeeded + if (!m_currentCallFrame) + return; + + // Treat stepping over a return statement like stepping out. + if (m_currentCallFrame == m_pauseOnCallFrame) + m_pauseOnCallFrame = m_currentCallFrame->caller(); + m_currentCallFrame = m_currentCallFrame->caller(); +} + +void ScriptDebugServer::exception(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber, bool hasHandler) +{ + if (m_paused) + return; + + ASSERT(m_currentCallFrame); + if (!m_currentCallFrame) + return; + + if (m_pauseOnExceptionsState == PauseOnAllExceptions || (m_pauseOnExceptionsState == PauseOnUncaughtExceptions && !hasHandler)) + m_pauseOnNextStatement = true; + + m_currentCallFrame->update(debuggerCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); +} + +void ScriptDebugServer::willExecuteProgram(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber) +{ + if (m_paused) + return; + + m_currentCallFrame = JavaScriptCallFrame::create(debuggerCallFrame, m_currentCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); +} + +void ScriptDebugServer::didExecuteProgram(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber) +{ + if (m_paused) + return; + + ASSERT(m_currentCallFrame); + if (!m_currentCallFrame) + return; + + m_currentCallFrame->update(debuggerCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); + + // Treat stepping over the end of a program like stepping out. + if (m_currentCallFrame == m_pauseOnCallFrame) + m_pauseOnCallFrame = m_currentCallFrame->caller(); + m_currentCallFrame = m_currentCallFrame->caller(); +} + +void ScriptDebugServer::didReachBreakpoint(const DebuggerCallFrame& debuggerCallFrame, intptr_t sourceID, int lineNumber) +{ + if (m_paused) + return; + + ASSERT(m_currentCallFrame); + if (!m_currentCallFrame) + return; + + m_pauseOnNextStatement = true; + m_currentCallFrame->update(debuggerCallFrame, sourceID, lineNumber); + pauseIfNeeded(toPage(debuggerCallFrame.dynamicGlobalObject())); +} + +void ScriptDebugServer::recompileAllJSFunctionsSoon() +{ + m_recompileTimer.startOneShot(0); +} + +void ScriptDebugServer::recompileAllJSFunctions(Timer<ScriptDebugServer>*) +{ + JSLock lock(SilenceAssertionsOnly); + // If JavaScript stack is not empty postpone recompilation. + if (JSDOMWindow::commonJSGlobalData()->dynamicGlobalObject) + recompileAllJSFunctionsSoon(); + else + Debugger::recompileAllJSFunctions(JSDOMWindow::commonJSGlobalData()); +} + +void ScriptDebugServer::didAddListener(Page* page) +{ + recompileAllJSFunctionsSoon(); + page->setDebugger(this); +} + +void ScriptDebugServer::didRemoveListener(Page* page) +{ + if (hasListenersInterestedInPage(page)) + return; + + if (m_pausedPage == page) + m_doneProcessingDebuggerEvents = true; + + recompileAllJSFunctionsSoon(); + page->setDebugger(0); +} + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/Source/WebCore/bindings/js/ScriptDebugServer.h b/Source/WebCore/bindings/js/ScriptDebugServer.h new file mode 100644 index 0000000..81cd9ac --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptDebugServer.h @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptDebugServer_h +#define ScriptDebugServer_h + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +#include "ScriptDebugListener.h" +#include "PlatformString.h" +#include "ScriptBreakpoint.h" +#include "Timer.h" + +#include <debugger/Debugger.h> +#include <runtime/UString.h> +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/RefPtr.h> + +namespace JSC { +class DebuggerCallFrame; +class JSGlobalObject; +} +namespace WebCore { + +class Frame; +class FrameView; +class Page; +class PageGroup; +class ScriptDebugListener; +class JavaScriptCallFrame; + +class ScriptDebugServer : JSC::Debugger, public Noncopyable { +public: + static ScriptDebugServer& shared(); + + void addListener(ScriptDebugListener*, Page*); + void removeListener(ScriptDebugListener*, Page*); + + String setBreakpoint(const String& sourceID, unsigned lineNumber, const String& condition, bool enabled, unsigned* actualLineNumber); + void removeBreakpoint(const String& breakpointId); + void clearBreakpoints(); + void setBreakpointsActivated(bool activated); + void activateBreakpoints() { setBreakpointsActivated(true); } + void deactivateBreakpoints() { setBreakpointsActivated(false); } + + enum PauseOnExceptionsState { + DontPauseOnExceptions, + PauseOnAllExceptions, + PauseOnUncaughtExceptions + }; + PauseOnExceptionsState pauseOnExceptionsState() const { return m_pauseOnExceptionsState; } + void setPauseOnExceptionsState(PauseOnExceptionsState); + + void setPauseOnNextStatement(bool pause); + void breakProgram(); + void continueProgram(); + void stepIntoStatement(); + void stepOverStatement(); + void stepOutOfFunction(); + + bool editScriptSource(const String& sourceID, const String& newContent, String& newSourceOrErrorMessage); + + void recompileAllJSFunctionsSoon(); + void recompileAllJSFunctions(Timer<ScriptDebugServer>* = 0); + + JavaScriptCallFrame* currentCallFrame(); + + void pageCreated(Page*); + + bool isDebuggerAlwaysEnabled(); + +private: + typedef HashSet<ScriptDebugListener*> ListenerSet; + typedef void (ScriptDebugServer::*JavaScriptExecutionCallback)(ScriptDebugListener*); + + ScriptDebugServer(); + ~ScriptDebugServer(); + + bool hasBreakpoint(intptr_t sourceID, unsigned lineNumber) const; + bool hasListenersInterestedInPage(Page*); + + void setJavaScriptPaused(const PageGroup&, bool paused); + void setJavaScriptPaused(Page*, bool paused); + void setJavaScriptPaused(Frame*, bool paused); + void setJavaScriptPaused(FrameView*, bool paused); + + void dispatchFunctionToListeners(JavaScriptExecutionCallback, Page*); + void dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback); + void dispatchDidPause(ScriptDebugListener*); + void dispatchDidContinue(ScriptDebugListener*); + void dispatchDidParseSource(const ListenerSet& listeners, const JSC::SourceCode& source, enum ScriptWorldType); + void dispatchFailedToParseSource(const ListenerSet& listeners, const JSC::SourceCode& source, int errorLine, const String& errorMessage); + + void pauseIfNeeded(Page*); + + virtual void detach(JSC::JSGlobalObject*); + + virtual void sourceParsed(JSC::ExecState*, const JSC::SourceCode&, int errorLine, const JSC::UString& errorMsg); + virtual void callEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber); + virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int firstLine); + virtual void returnEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber); + virtual void exception(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber, bool hasHandler); + virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno); + virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno); + virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno); + + void didAddListener(Page*); + void didRemoveListener(Page*); + + typedef HashMap<Page*, ListenerSet*> PageListenersMap; + typedef HashMap<intptr_t, SourceBreakpoints> BreakpointsMap; + + PageListenersMap m_pageListenersMap; + bool m_callingListeners; + PauseOnExceptionsState m_pauseOnExceptionsState; + bool m_pauseOnNextStatement; + bool m_paused; + Page* m_pausedPage; + bool m_doneProcessingDebuggerEvents; + bool m_breakpointsActivated; + JavaScriptCallFrame* m_pauseOnCallFrame; + RefPtr<JavaScriptCallFrame> m_currentCallFrame; + BreakpointsMap m_breakpoints; + Timer<ScriptDebugServer> m_recompileTimer; +}; + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) + +#endif // ScriptDebugServer_h diff --git a/Source/WebCore/bindings/js/ScriptEventListener.cpp b/Source/WebCore/bindings/js/ScriptEventListener.cpp new file mode 100644 index 0000000..d2baf82 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptEventListener.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptEventListener.h" + +#include "Attribute.h" +#include "Document.h" +#include "EventListener.h" +#include "JSNode.h" +#include "Frame.h" +#include "XSSAuditor.h" +#include <runtime/JSLock.h> + +using namespace JSC; + +namespace WebCore { + +static const String& eventParameterName(bool isSVGEvent) +{ + DEFINE_STATIC_LOCAL(const String, eventString, ("event")); + DEFINE_STATIC_LOCAL(const String, evtString, ("evt")); + return isSVGEvent ? evtString : eventString; +} + +PassRefPtr<JSLazyEventListener> createAttributeEventListener(Node* node, Attribute* attr) +{ + ASSERT(node); + ASSERT(attr); + if (attr->isNull()) + return 0; + + int lineNumber = 1; + String sourceURL; + + // FIXME: We should be able to provide accurate source information for frameless documents, too (e.g. for importing nodes from XMLHttpRequest.responseXML). + if (Frame* frame = node->document()->frame()) { + ScriptController* scriptController = frame->script(); + if (!scriptController->canExecuteScripts(AboutToExecuteScript)) + return 0; + + if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { + // This script is not safe to execute. + return 0; + } + + lineNumber = scriptController->eventHandlerLineNumber(); + sourceURL = node->document()->url().string(); + } + + return JSLazyEventListener::create(attr->localName().string(), eventParameterName(node->isSVGElement()), attr->value(), node, sourceURL, lineNumber, 0, mainThreadNormalWorld()); +} + +PassRefPtr<JSLazyEventListener> createAttributeEventListener(Frame* frame, Attribute* attr) +{ + if (!frame) + return 0; + + ASSERT(attr); + if (attr->isNull()) + return 0; + + int lineNumber = 1; + String sourceURL; + + ScriptController* scriptController = frame->script(); + if (!scriptController->canExecuteScripts(AboutToExecuteScript)) + return 0; + + if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { + // This script is not safe to execute. + return 0; + } + + lineNumber = scriptController->eventHandlerLineNumber(); + sourceURL = frame->document()->url().string(); + JSObject* wrapper = toJSDOMWindow(frame, mainThreadNormalWorld()); + return JSLazyEventListener::create(attr->localName().string(), eventParameterName(frame->document()->isSVGDocument()), attr->value(), 0, sourceURL, lineNumber, wrapper, mainThreadNormalWorld()); +} + +String eventListenerHandlerBody(Document* document, EventListener* eventListener) +{ + const JSEventListener* jsListener = JSEventListener::cast(eventListener); + if (!jsListener) + return ""; + JSC::JSObject* jsFunction = jsListener->jsFunction(document); + if (!jsFunction) + return ""; + return ustringToString(jsFunction->toString(scriptStateFromNode(jsListener->isolatedWorld(), document))); +} + +bool eventListenerHandlerLocation(Document*, EventListener*, String&, int&) +{ + // FIXME: Add support for getting function location. + return false; +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptEventListener.h b/Source/WebCore/bindings/js/ScriptEventListener.h new file mode 100644 index 0000000..f96f31e --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptEventListener.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptEventListener_h +#define ScriptEventListener_h + +#include "JSLazyEventListener.h" +#include "ScriptState.h" + +#include <wtf/PassRefPtr.h> + +namespace WebCore { + + class Attribute; + class EventListener; + class Frame; + class Node; + + PassRefPtr<JSLazyEventListener> createAttributeEventListener(Node*, Attribute*); + PassRefPtr<JSLazyEventListener> createAttributeEventListener(Frame*, Attribute*); + String eventListenerHandlerBody(Document*, EventListener*); + bool eventListenerHandlerLocation(Document*, EventListener*, String& sourceName, int& lineNumber); +} // namespace WebCore + +#endif // ScriptEventListener_h diff --git a/Source/WebCore/bindings/js/ScriptFunctionCall.cpp b/Source/WebCore/bindings/js/ScriptFunctionCall.cpp new file mode 100644 index 0000000..f77c691 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptFunctionCall.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptFunctionCall.h" + +#include "JSDOMBinding.h" +#include "JSMainThreadExecState.h" +#include "ScriptValue.h" + +#include <runtime/JSLock.h> +#include <runtime/UString.h> + +using namespace JSC; + +namespace WebCore { + +void ScriptCallArgumentHandler::appendArgument(const ScriptObject& argument) +{ + if (argument.scriptState() != m_exec) { + ASSERT_NOT_REACHED(); + return; + } + m_arguments.append(argument.jsObject()); +} + +void ScriptCallArgumentHandler::appendArgument(const ScriptValue& argument) +{ + m_arguments.append(argument.jsValue()); +} + +void ScriptCallArgumentHandler::appendArgument(const String& argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsString(m_exec, argument)); +} + +void ScriptCallArgumentHandler::appendArgument(const JSC::UString& argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsString(m_exec, argument)); +} + +void ScriptCallArgumentHandler::appendArgument(const char* argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsString(m_exec, UString(argument))); +} + +void ScriptCallArgumentHandler::appendArgument(JSC::JSValue argument) +{ + m_arguments.append(argument); +} + +void ScriptCallArgumentHandler::appendArgument(long argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(long long argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(unsigned int argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(unsigned long argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(int argument) +{ + JSLock lock(SilenceAssertionsOnly); + m_arguments.append(jsNumber(argument)); +} + +void ScriptCallArgumentHandler::appendArgument(bool argument) +{ + m_arguments.append(jsBoolean(argument)); +} + +ScriptFunctionCall::ScriptFunctionCall(const ScriptObject& thisObject, const String& name) + : ScriptCallArgumentHandler(thisObject.scriptState()) + , m_thisObject(thisObject) + , m_name(name) +{ +} + +ScriptValue ScriptFunctionCall::call(bool& hadException, bool reportExceptions) +{ + JSObject* thisObject = m_thisObject.jsObject(); + + JSLock lock(SilenceAssertionsOnly); + + JSValue function = thisObject->get(m_exec, Identifier(m_exec, stringToUString(m_name))); + if (m_exec->hadException()) { + if (reportExceptions) + reportException(m_exec, m_exec->exception()); + + hadException = true; + return ScriptValue(); + } + + CallData callData; + CallType callType = getCallData(function, callData); + if (callType == CallTypeNone) + return ScriptValue(); + + JSValue result = JSMainThreadExecState::call(m_exec, function, callType, callData, thisObject, m_arguments); + if (m_exec->hadException()) { + if (reportExceptions) + reportException(m_exec, m_exec->exception()); + + hadException = true; + return ScriptValue(); + } + + return ScriptValue(result); +} + +ScriptValue ScriptFunctionCall::call() +{ + bool hadException = false; + return call(hadException); +} + +ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExceptions) +{ + JSObject* thisObject = m_thisObject.jsObject(); + + JSLock lock(SilenceAssertionsOnly); + + JSObject* constructor = asObject(thisObject->get(m_exec, Identifier(m_exec, stringToUString(m_name)))); + if (m_exec->hadException()) { + if (reportExceptions) + reportException(m_exec, m_exec->exception()); + + hadException = true; + return ScriptObject(); + } + + ConstructData constructData; + ConstructType constructType = constructor->getConstructData(constructData); + if (constructType == ConstructTypeNone) + return ScriptObject(); + + JSValue result = JSC::construct(m_exec, constructor, constructType, constructData, m_arguments); + if (m_exec->hadException()) { + if (reportExceptions) + reportException(m_exec, m_exec->exception()); + + hadException = true; + return ScriptObject(); + } + + return ScriptObject(m_exec, asObject(result)); +} + +ScriptCallback::ScriptCallback(ScriptState* state, ScriptValue function) + : ScriptCallArgumentHandler(state) + , m_function(function) +{ +} + +ScriptValue ScriptCallback::call() +{ + bool hadException; + return call(hadException); +} + +ScriptValue ScriptCallback::call(bool& hadException) +{ + JSLock lock(SilenceAssertionsOnly); + + CallData callData; + CallType callType = getCallData(m_function.jsValue(), callData); + if (callType == CallTypeNone) + return ScriptValue(); + + JSValue result = JSC::call(m_exec, m_function.jsValue(), callType, callData, m_function.jsValue(), m_arguments); + hadException = m_exec->hadException(); + + if (hadException) { + reportException(m_exec, m_exec->exception()); + return ScriptValue(); + } + + return ScriptValue(result); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptFunctionCall.h b/Source/WebCore/bindings/js/ScriptFunctionCall.h new file mode 100644 index 0000000..c7da858 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptFunctionCall.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptFunctionCall_h +#define ScriptFunctionCall_h + +#include "PlatformString.h" +#include "ScriptObject.h" +#include "ScriptState.h" + +#include <runtime/ArgList.h> + +namespace JSC { + class UString; + class JSValue; +} + +namespace WebCore { + class ScriptValue; + + class ScriptCallArgumentHandler { + public: + ScriptCallArgumentHandler(ScriptState* state) : m_exec(state) { } + + void appendArgument(const ScriptObject&); + void appendArgument(const ScriptValue&); + void appendArgument(const String&); + void appendArgument(const char*); + void appendArgument(const JSC::UString&); + void appendArgument(JSC::JSValue); + void appendArgument(long); + void appendArgument(long long); + void appendArgument(unsigned int); + void appendArgument(unsigned long); + void appendArgument(int); + void appendArgument(bool); + + protected: + JSC::MarkedArgumentBuffer m_arguments; + ScriptState* m_exec; + + private: + // MarkedArgumentBuffer must be stack allocated, so prevent heap + // alloc of ScriptFunctionCall as well. + void* operator new(size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); } + void* operator new[](size_t) { ASSERT_NOT_REACHED(); return reinterpret_cast<void*>(0xbadbeef); } + }; + + class ScriptFunctionCall : public ScriptCallArgumentHandler { + public: + ScriptFunctionCall(const ScriptObject& thisObject, const String& name); + ScriptValue call(bool& hadException, bool reportExceptions = true); + ScriptValue call(); + ScriptObject construct(bool& hadException, bool reportExceptions = true); + + protected: + ScriptObject m_thisObject; + String m_name; + }; + + class ScriptCallback : public ScriptCallArgumentHandler { + public: + ScriptCallback(ScriptState*, ScriptValue); + + ScriptValue call(); + ScriptValue call(bool& hadException); + + private: + ScriptValue m_function; + }; + +} // namespace WebCore + +#endif // ScriptFunctionCall diff --git a/Source/WebCore/bindings/js/ScriptGCEvent.cpp b/Source/WebCore/bindings/js/ScriptGCEvent.cpp new file mode 100644 index 0000000..4b39799 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptGCEvent.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptGCEvent.h" + +#if ENABLE(INSPECTOR) + +#include "JSDOMWindow.h" +#include <runtime/Collector.h> +#include <runtime/JSGlobalData.h> +#include <wtf/CurrentTime.h> + +namespace WebCore { + +using namespace JSC; + +void ScriptGCEvent::getHeapSize(size_t& usedHeapSize, size_t& totalHeapSize) +{ + JSGlobalData* globalData = JSDOMWindow::commonJSGlobalData(); + totalHeapSize = globalData->heap.size(); + usedHeapSize = totalHeapSize; +} +} // namespace WebCore + +#endif // !ENABLE(INSPECTOR) diff --git a/Source/WebCore/bindings/js/ScriptGCEvent.h b/Source/WebCore/bindings/js/ScriptGCEvent.h new file mode 100644 index 0000000..86d4f68 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptGCEvent.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptGCEvent_h +#define ScriptGCEvent_h + +#if ENABLE(INSPECTOR) + +namespace WebCore { + +class ScriptGCEventListener; + +class ScriptGCEvent +{ +public: + static void addEventListener(ScriptGCEventListener*) { } + static void removeEventListener(ScriptGCEventListener*) { } + static void getHeapSize(size_t& usedHeapSize, size_t& totalHeapSize); +}; + +} // namespace WebCore + +#endif // !ENABLE(INSPECTOR) +#endif // !defined(ScriptGCEvent_h) diff --git a/Source/WebCore/bindings/js/ScriptHeapSnapshot.h b/Source/WebCore/bindings/js/ScriptHeapSnapshot.h new file mode 100644 index 0000000..4c3d915 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptHeapSnapshot.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptHeapSnapshot_h +#define ScriptHeapSnapshot_h + +#include "InspectorValues.h" +#include "PlatformString.h" + +namespace WebCore { + +class ScriptHeapSnapshot : public RefCounted<ScriptHeapSnapshot> { +public: + class OutputStream { + public: + virtual ~OutputStream() { } + virtual void Write(const String& chunk) = 0; + virtual void Close() = 0; + }; + + virtual ~ScriptHeapSnapshot() { } + + String title() const { return ""; } + unsigned int uid() const { return 0; } + + void writeJSON(OutputStream*) { } + +private: + ScriptHeapSnapshot() { } +}; + +} // namespace WebCore + +#endif // ScriptHeapSnapshot_h diff --git a/Source/WebCore/bindings/js/ScriptInstance.h b/Source/WebCore/bindings/js/ScriptInstance.h new file mode 100644 index 0000000..0b3b59f --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptInstance.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptInstance_h +#define ScriptInstance_h + +#include "Bridge.h" +#include <wtf/RefPtr.h> + +namespace WebCore { + +typedef RefPtr<JSC::Bindings::Instance> ScriptInstance; +typedef PassRefPtr<JSC::Bindings::Instance> PassScriptInstance; + +} // namespace WebCore + +#endif // ScriptInstance_h diff --git a/Source/WebCore/bindings/js/ScriptObject.cpp b/Source/WebCore/bindings/js/ScriptObject.cpp new file mode 100644 index 0000000..e06eccb --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptObject.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptObject.h" + +#include "JSDOMBinding.h" + +#include <runtime/JSLock.h> + +#if ENABLE(INSPECTOR) +#include "JSInjectedScriptHost.h" +#include "JSInspectorFrontendHost.h" +#endif + +using namespace JSC; + +namespace WebCore { + +ScriptObject::ScriptObject(ScriptState* scriptState, JSObject* object) + : ScriptValue(object) + , m_scriptState(scriptState) +{ +} + +static bool handleException(ScriptState* scriptState) +{ + if (!scriptState->hadException()) + return true; + + reportException(scriptState, scriptState->exception()); + return false; +} + +bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, const ScriptObject& value) +{ + JSLock lock(SilenceAssertionsOnly); + scriptState->lexicalGlobalObject()->putDirect(Identifier(scriptState, name), value.jsObject()); + return handleException(scriptState); +} + +#if ENABLE(INSPECTOR) +bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, InspectorFrontendHost* value) +{ + JSLock lock(SilenceAssertionsOnly); + JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); + globalObject->putDirect(Identifier(scriptState, name), toJS(scriptState, globalObject, value)); + return handleException(scriptState); +} + +bool ScriptGlobalObject::set(ScriptState* scriptState, const char* name, InjectedScriptHost* value) +{ + JSLock lock(SilenceAssertionsOnly); + JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); + globalObject->putDirect(Identifier(scriptState, name), toJS(scriptState, globalObject, value)); + return handleException(scriptState); +} +#endif // ENABLE(INSPECTOR) + +bool ScriptGlobalObject::get(ScriptState* scriptState, const char* name, ScriptObject& value) +{ + JSLock lock(SilenceAssertionsOnly); + JSValue jsValue = scriptState->lexicalGlobalObject()->get(scriptState, Identifier(scriptState, name)); + if (!jsValue) + return false; + + if (!jsValue.isObject()) + return false; + + value = ScriptObject(scriptState, asObject(jsValue)); + return true; +} + +bool ScriptGlobalObject::remove(ScriptState* scriptState, const char* name) +{ + JSLock lock(SilenceAssertionsOnly); + scriptState->lexicalGlobalObject()->deleteProperty(scriptState, Identifier(scriptState, name)); + return handleException(scriptState); +} + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptObject.h b/Source/WebCore/bindings/js/ScriptObject.h new file mode 100644 index 0000000..f085e8b --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptObject.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptObject_h +#define ScriptObject_h + +#include "ScriptState.h" +#include "ScriptValue.h" + +#include <runtime/JSObject.h> +#include <runtime/Protect.h> + +namespace WebCore { + class InjectedScriptHost; + class InspectorFrontendHost; + + class ScriptObject : public ScriptValue { + public: + ScriptObject(ScriptState*, JSC::JSObject*); + ScriptObject() {} + JSC::JSObject* jsObject() const { return asObject(jsValue()); } + ScriptState* scriptState() const { return m_scriptState; } + + protected: + ScriptState* m_scriptState; + }; + + class ScriptGlobalObject { + public: + static bool set(ScriptState*, const char* name, const ScriptObject&); +#if ENABLE(INSPECTOR) + static bool set(ScriptState*, const char* name, InspectorFrontendHost*); + static bool set(ScriptState*, const char* name, InjectedScriptHost*); +#endif + static bool get(ScriptState*, const char* name, ScriptObject&); + static bool remove(ScriptState*, const char* name); + private: + ScriptGlobalObject() { } + }; + +} + +#endif // ScriptObject_h diff --git a/Source/WebCore/bindings/js/ScriptProfile.cpp b/Source/WebCore/bindings/js/ScriptProfile.cpp new file mode 100644 index 0000000..84451fb --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptProfile.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptProfile.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include "InspectorValues.h" +#include "JSDOMBinding.h" +#include <profiler/Profile.h> +#include <profiler/ProfileNode.h> + +namespace WebCore { + +PassRefPtr<ScriptProfile> ScriptProfile::create(PassRefPtr<JSC::Profile> profile) +{ + if (!profile) + return 0; + return adoptRef(new ScriptProfile(profile)); +} + +ScriptProfile::ScriptProfile(PassRefPtr<JSC::Profile> profile) + : m_profile(profile) +{ +} + +ScriptProfile::~ScriptProfile() +{ +} + +String ScriptProfile::title() const +{ + return ustringToString(m_profile->title()); +} + +unsigned int ScriptProfile::uid() const +{ + return m_profile->uid(); +} + +ScriptProfileNode* ScriptProfile::head() const +{ + return m_profile->head(); +} + +#if ENABLE(INSPECTOR) +static PassRefPtr<InspectorObject> buildInspectorObjectFor(const JSC::ProfileNode* node) +{ + RefPtr<InspectorObject> result = InspectorObject::create(); + + result->setString("functionName", ustringToString(node->functionName())); + result->setString("url", ustringToString(node->url())); + result->setNumber("lineNumber", node->lineNumber()); + result->setNumber("totalTime", node->totalTime()); + result->setNumber("selfTime", node->selfTime()); + result->setNumber("numberOfCalls", node->numberOfCalls()); + result->setBoolean("visible", node->visible()); + result->setNumber("callUID", node->callIdentifier().hash()); + + RefPtr<InspectorArray> childrenArray = InspectorArray::create(); + typedef Vector<RefPtr<JSC::ProfileNode> > ProfileNodesList; + const ProfileNodesList& children = node->children(); + ProfileNodesList::const_iterator end = children.end(); + for (ProfileNodesList::const_iterator iter = children.begin(); iter != end; ++iter) + childrenArray->pushObject(buildInspectorObjectFor(iter->get())); + result->setArray("children", childrenArray); + + return result; +} + +PassRefPtr<InspectorObject> ScriptProfile::buildInspectorObjectForHead() const +{ + return buildInspectorObjectFor(m_profile->head()); +} +#endif + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/Source/WebCore/bindings/js/ScriptProfile.h b/Source/WebCore/bindings/js/ScriptProfile.h new file mode 100644 index 0000000..0b38edc --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptProfile.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptProfile_h +#define ScriptProfile_h + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include "ScriptProfileNode.h" +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +namespace JSC { +class Profile; +} + +namespace WebCore { + +class InspectorObject; + +class ScriptProfile : public RefCounted<ScriptProfile> { +public: + static PassRefPtr<ScriptProfile> create(PassRefPtr<JSC::Profile> profile); + virtual ~ScriptProfile(); + + String title() const; + unsigned int uid() const; + ScriptProfileNode* head() const; + +#if ENABLE(INSPECTOR) + PassRefPtr<InspectorObject> buildInspectorObjectForHead() const; +#endif + +private: + ScriptProfile(PassRefPtr<JSC::Profile> profile); + + RefPtr<JSC::Profile> m_profile; +}; + + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) + +#endif // ScriptProfile_h diff --git a/Source/WebCore/bindings/js/ScriptProfileNode.h b/Source/WebCore/bindings/js/ScriptProfileNode.h new file mode 100644 index 0000000..b2edcbf --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptProfileNode.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptProfileNode_h +#define ScriptProfileNode_h + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include <profiler/ProfileNode.h> + +namespace WebCore { + +typedef JSC::ProfileNode ScriptProfileNode; + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) + +#endif // ScriptProfileNode_h diff --git a/Source/WebCore/bindings/js/ScriptProfiler.cpp b/Source/WebCore/bindings/js/ScriptProfiler.cpp new file mode 100644 index 0000000..62ae9ba --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptProfiler.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(JAVASCRIPT_DEBUGGER) + +#include "ScriptProfiler.h" + +#include "JSDOMBinding.h" +#include <profiler/Profiler.h> + +namespace WebCore { + +void ScriptProfiler::start(ScriptState* state, const String& title) +{ + JSC::Profiler::profiler()->startProfiling(state, stringToUString(title)); +} + +PassRefPtr<ScriptProfile> ScriptProfiler::stop(ScriptState* state, const String& title) +{ + RefPtr<JSC::Profile> profile = JSC::Profiler::profiler()->stopProfiling(state, stringToUString(title)); + return ScriptProfile::create(profile); +} + +bool ScriptProfiler::isProfilerAlwaysEnabled() +{ + return false; +} + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) diff --git a/Source/WebCore/bindings/js/ScriptProfiler.h b/Source/WebCore/bindings/js/ScriptProfiler.h new file mode 100644 index 0000000..05e7a25 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptProfiler.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptProfiler_h +#define ScriptProfiler_h + +#if ENABLE(JAVASCRIPT_DEBUGGER) +#include "ScriptHeapSnapshot.h" +#include "ScriptProfile.h" +#include "ScriptState.h" + +#include <wtf/Noncopyable.h> + +namespace WebCore { + +class ScriptProfiler : public Noncopyable { +public: + static void start(ScriptState* state, const String& title); + static PassRefPtr<ScriptProfile> stop(ScriptState* state, const String& title); + static PassRefPtr<ScriptHeapSnapshot> takeHeapSnapshot(const String&) { return 0; } + static bool isProfilerAlwaysEnabled(); +}; + +} // namespace WebCore + +#endif // ENABLE(JAVASCRIPT_DEBUGGER) + +#endif // ScriptProfiler_h diff --git a/Source/WebCore/bindings/js/ScriptSourceCode.h b/Source/WebCore/bindings/js/ScriptSourceCode.h new file mode 100644 index 0000000..092eeb8 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptSourceCode.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2008, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptSourceCode_h +#define ScriptSourceCode_h + +#include "CachedScriptSourceProvider.h" +#include "ScriptSourceProvider.h" +#include "StringSourceProvider.h" +#include "KURL.h" +#include <wtf/text/TextPosition.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class ScriptSourceCode { +public: + ScriptSourceCode(const String& source, const KURL& url = KURL(), const TextPosition1& startPosition = TextPosition1::minimumPosition()) + : m_provider(StringSourceProvider::create(source, url.isNull() ? String() : url.string())) + , m_code(m_provider, startPosition.m_line.oneBasedInt()) + , m_url(url) + { + } + + ScriptSourceCode(CachedScript* cs) + : m_provider(CachedScriptSourceProvider::create(cs)) + , m_code(m_provider) + { + } + + bool isEmpty() const { return m_code.length() == 0; } + + const JSC::SourceCode& jsSourceCode() const { return m_code; } + + const String& source() const { return m_provider->source(); } + + int startLine() const { return m_code.firstLine(); } + + const KURL& url() const { return m_url; } + +private: + RefPtr<ScriptSourceProvider> m_provider; + + JSC::SourceCode m_code; + + KURL m_url; + +}; + +} // namespace WebCore + +#endif // ScriptSourceCode_h diff --git a/Source/WebCore/bindings/js/ScriptSourceProvider.h b/Source/WebCore/bindings/js/ScriptSourceProvider.h new file mode 100644 index 0000000..de4e307 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptSourceProvider.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2009 Daniel Bates (dbates@intudata.com) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptSourceProvider_h +#define ScriptSourceProvider_h + +#include <parser/SourceProvider.h> +#include <wtf/Forward.h> + +namespace WebCore { + + class ScriptSourceProvider : public JSC::SourceProvider { + public: + ScriptSourceProvider(const JSC::UString& url) + : SourceProvider(url) + { + } + + virtual const String& source() const = 0; + }; + +} // namespace WebCore + +#endif // ScriptSourceProvider_h diff --git a/Source/WebCore/bindings/js/ScriptState.cpp b/Source/WebCore/bindings/js/ScriptState.cpp new file mode 100644 index 0000000..d6699f6 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptState.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptState.h" + +#include "Frame.h" +#include "JSDOMWindowBase.h" +#include "Node.h" +#include "Page.h" +#include <interpreter/CallFrame.h> +#include <runtime/JSGlobalObject.h> + +namespace WebCore { + +ScriptStateProtectedPtr::~ScriptStateProtectedPtr() +{ +} + +ScriptStateProtectedPtr::ScriptStateProtectedPtr(ScriptState* scriptState) + : m_globalObject(scriptState->lexicalGlobalObject()) +{ +} + +ScriptState* ScriptStateProtectedPtr::get() const +{ + if (m_globalObject) + return m_globalObject->globalExec(); + return 0; +} + + +ScriptState* mainWorldScriptState(Frame* frame) +{ + JSDOMWindowShell* shell = frame->script()->windowShell(mainThreadNormalWorld()); + return shell->window()->globalExec(); +} + +ScriptState* scriptStateFromNode(DOMWrapperWorld* world, Node* node) +{ + if (!node) + return 0; + Document* document = node->document(); + if (!document) + return 0; + Frame* frame = document->frame(); + if (!frame) + return 0; + if (!frame->script()->canExecuteScripts(NotAboutToExecuteScript)) + return 0; + return frame->script()->globalObject(world)->globalExec(); +} + +ScriptState* scriptStateFromPage(DOMWrapperWorld* world, Page* page) +{ + return page->mainFrame()->script()->globalObject(world)->globalExec(); +} + +} diff --git a/Source/WebCore/bindings/js/ScriptState.h b/Source/WebCore/bindings/js/ScriptState.h new file mode 100644 index 0000000..0c08611 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptState.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptState_h +#define ScriptState_h + +#include <runtime/Protect.h> +#include <wtf/Noncopyable.h> + +namespace JSC { +class ExecState; +class JSGlobalObject; +} + +namespace WebCore { +class DOMWrapperWorld; +class Frame; +class Node; +class Page; + +// The idea is to expose "state-like" methods (hadException, and any other +// methods where ExecState just dips into globalData) of JSC::ExecState as a +// separate abstraction. +// For now, the separation is purely by convention. +typedef JSC::ExecState ScriptState; + +class ScriptStateProtectedPtr : public Noncopyable { +public: + explicit ScriptStateProtectedPtr(ScriptState*); + ~ScriptStateProtectedPtr(); + ScriptState* get() const; +private: + JSC::ProtectedPtr<JSC::JSGlobalObject> m_globalObject; +}; + +ScriptState* mainWorldScriptState(Frame*); + +ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node*); +ScriptState* scriptStateFromPage(DOMWrapperWorld*, Page*); + +} // namespace WebCore + +#endif // ScriptState_h diff --git a/Source/WebCore/bindings/js/ScriptValue.cpp b/Source/WebCore/bindings/js/ScriptValue.cpp new file mode 100644 index 0000000..a2a72b6 --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptValue.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptValue.h" + +#include "InspectorValues.h" +#include "SerializedScriptValue.h" + +#include <JavaScriptCore/APICast.h> +#include <JavaScriptCore/JSValueRef.h> + +#include <runtime/JSLock.h> +#include <runtime/Protect.h> +#include <runtime/UString.h> + +using namespace JSC; + +namespace WebCore { + +bool ScriptValue::getString(ScriptState* scriptState, String& result) const +{ + if (!m_value) + return false; + JSLock lock(SilenceAssertionsOnly); + UString ustring; + if (!m_value.get().getString(scriptState, ustring)) + return false; + result = ustringToString(ustring); + return true; +} + +bool ScriptValue::isEqual(ScriptState* scriptState, const ScriptValue& anotherValue) const +{ + if (hasNoValue()) + return anotherValue.hasNoValue(); + + return JSValueIsEqual(toRef(scriptState), toRef(scriptState, jsValue()), toRef(scriptState, anotherValue.jsValue()), 0); +} + +bool ScriptValue::isNull() const +{ + if (!m_value) + return false; + return m_value.get().isNull(); +} + +bool ScriptValue::isUndefined() const +{ + if (!m_value) + return false; + return m_value.get().isUndefined(); +} + +bool ScriptValue::isObject() const +{ + if (!m_value) + return false; + return m_value.get().isObject(); +} + +bool ScriptValue::isFunction() const +{ + CallData callData; + return getCallData(m_value, callData) != CallTypeNone; +} + +PassRefPtr<SerializedScriptValue> ScriptValue::serialize(ScriptState* scriptState) +{ + return SerializedScriptValue::create(scriptState, jsValue()); +} + +ScriptValue ScriptValue::deserialize(ScriptState* scriptState, SerializedScriptValue* value) +{ + return ScriptValue(value->deserialize(scriptState, scriptState->lexicalGlobalObject())); +} + +#if ENABLE(INSPECTOR) +static PassRefPtr<InspectorValue> jsToInspectorValue(ScriptState* scriptState, JSValue value) +{ + if (!value) { + ASSERT_NOT_REACHED(); + return 0; + } + if (value.isNull() || value.isUndefined()) + return InspectorValue::null(); + if (value.isBoolean()) + return InspectorBasicValue::create(value.getBoolean()); + if (value.isNumber()) + return InspectorBasicValue::create(value.uncheckedGetNumber()); + if (value.isString()) { + UString s = value.getString(scriptState); + return InspectorString::create(String(s.characters(), s.length())); + } + if (value.isObject()) { + if (isJSArray(&scriptState->globalData(), value)) { + RefPtr<InspectorArray> inspectorArray = InspectorArray::create(); + JSArray* array = asArray(value); + unsigned length = array->length(); + for (unsigned i = 0; i < length; i++) { + JSValue element = array->getIndex(i); + RefPtr<InspectorValue> elementValue = jsToInspectorValue(scriptState, element); + if (!elementValue) { + ASSERT_NOT_REACHED(); + elementValue = InspectorValue::null(); + } + inspectorArray->pushValue(elementValue); + } + return inspectorArray; + } + RefPtr<InspectorObject> inspectorObject = InspectorObject::create(); + JSObject* object = value.getObject(); + PropertyNameArray propertyNames(scriptState); + object->getOwnPropertyNames(scriptState, propertyNames); + for (size_t i = 0; i < propertyNames.size(); i++) { + const Identifier& name = propertyNames[i]; + JSValue propertyValue = object->get(scriptState, name); + RefPtr<InspectorValue> inspectorValue = jsToInspectorValue(scriptState, propertyValue); + if (!inspectorValue) { + ASSERT_NOT_REACHED(); + inspectorValue = InspectorValue::null(); + } + inspectorObject->setValue(String(name.characters(), name.length()), inspectorValue); + } + return inspectorObject; + } + ASSERT_NOT_REACHED(); + return 0; +} + +PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const +{ + return jsToInspectorValue(scriptState, m_value.get()); +} +#endif // ENABLE(INSPECTOR) + +} // namespace WebCore diff --git a/Source/WebCore/bindings/js/ScriptValue.h b/Source/WebCore/bindings/js/ScriptValue.h new file mode 100644 index 0000000..5746c3f --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptValue.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2008, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptValue_h +#define ScriptValue_h + +#include "JSDOMBinding.h" +#include "PlatformString.h" +#include "ScriptState.h" +#include <runtime/JSValue.h> +#include <runtime/Protect.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class InspectorValue; +class SerializedScriptValue; + +class ScriptValue { +public: + ScriptValue(JSC::JSValue value = JSC::JSValue()) : m_value(value) {} + virtual ~ScriptValue() {} + + JSC::JSValue jsValue() const { return m_value.get(); } + bool getString(ScriptState*, String& result) const; + String toString(ScriptState* scriptState) const { return ustringToString(m_value.get().toString(scriptState)); } + bool isEqual(ScriptState*, const ScriptValue&) const; + bool isNull() const; + bool isUndefined() const; + bool isObject() const; + bool isFunction() const; + bool hasNoValue() const { return m_value == JSC::JSValue(); } + + bool operator==(const ScriptValue& other) const { return m_value == other.m_value; } + + PassRefPtr<SerializedScriptValue> serialize(ScriptState*); + static ScriptValue deserialize(ScriptState*, SerializedScriptValue*); + + static ScriptValue undefined() { return ScriptValue(JSC::jsUndefined()); } + +#if ENABLE(INSPECTOR) + PassRefPtr<InspectorValue> toInspectorValue(ScriptState*) const; +#endif + +private: + JSC::ProtectedJSValue m_value; +}; + +} // namespace WebCore + +#endif // ScriptValue_h diff --git a/Source/WebCore/bindings/js/ScriptWrappable.h b/Source/WebCore/bindings/js/ScriptWrappable.h new file mode 100644 index 0000000..c57796c --- /dev/null +++ b/Source/WebCore/bindings/js/ScriptWrappable.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2010, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ScriptWrappable_h +#define ScriptWrappable_h + +#include "JSDOMWrapper.h" +#include <runtime/WeakGCPtr.h> + +namespace WebCore { + +class ScriptWrappable { +public: + DOMObject* wrapper() const + { + return m_wrapper.get(); + } + + void setWrapper(DOMObject* wrapper) + { + m_wrapper = wrapper; + } + + void clearWrapper(DOMObject* wrapper) + { + m_wrapper.clear(wrapper); + } + +private: + JSC::WeakGCPtr<DOMObject> m_wrapper; +}; + +} // namespace WebCore + +#endif // ScriptWrappable_h diff --git a/Source/WebCore/bindings/js/SerializedScriptValue.cpp b/Source/WebCore/bindings/js/SerializedScriptValue.cpp new file mode 100644 index 0000000..b02a4bb --- /dev/null +++ b/Source/WebCore/bindings/js/SerializedScriptValue.cpp @@ -0,0 +1,1429 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "config.h" +#include "SerializedScriptValue.h" + +#include "Blob.h" +#include "File.h" +#include "FileList.h" +#include "ImageData.h" +#include "JSBlob.h" +#include "JSDOMGlobalObject.h" +#include "JSFile.h" +#include "JSFileList.h" +#include "JSImageData.h" +#include "SharedBuffer.h" +#include <limits> +#include <JavaScriptCore/APICast.h> +#include <runtime/DateInstance.h> +#include <runtime/Error.h> +#include <runtime/ExceptionHelpers.h> +#include <runtime/JSLock.h> +#include <runtime/PropertyNameArray.h> +#include <runtime/RegExp.h> +#include <runtime/RegExpObject.h> +#include <wtf/ByteArray.h> +#include <wtf/HashTraits.h> +#include <wtf/Vector.h> + +using namespace JSC; +using namespace std; + +#if CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN) +#define ASSUME_LITTLE_ENDIAN 0 +#else +#define ASSUME_LITTLE_ENDIAN 1 +#endif + +namespace WebCore { + +static const unsigned maximumFilterRecursion = 40000; + +enum WalkerState { StateUnknown, ArrayStartState, ArrayStartVisitMember, ArrayEndVisitMember, + ObjectStartState, ObjectStartVisitMember, ObjectEndVisitMember }; + +// These can't be reordered, and any new types must be added to the end of the list +enum SerializationTag { + ArrayTag = 1, + ObjectTag = 2, + UndefinedTag = 3, + NullTag = 4, + IntTag = 5, + ZeroTag = 6, + OneTag = 7, + FalseTag = 8, + TrueTag = 9, + DoubleTag = 10, + DateTag = 11, + FileTag = 12, + FileListTag = 13, + ImageDataTag = 14, + BlobTag = 15, + StringTag = 16, + EmptyStringTag = 17, + RegExpTag = 18, + ObjectReferenceTag = 19, + ErrorTag = 255 +}; + +/* CurrentVersion tracks the serialization version so that persistant stores + * are able to correctly bail out in the case of encountering newer formats. + * + * Initial version was 1. + * Version 2. added the ObjectReferenceTag and support for serialization of cyclic graphs. + */ +static const unsigned int CurrentVersion = 2; +static const unsigned int TerminatorTag = 0xFFFFFFFF; +static const unsigned int StringPoolTag = 0xFFFFFFFE; + +/* + * Object serialization is performed according to the following grammar, all tags + * are recorded as a single uint8_t. + * + * IndexType (used for the object pool and StringData's constant pool) is the + * minimum sized unsigned integer type required to represent the maximum index + * in the constant pool. + * + * SerializedValue :- <CurrentVersion:uint32_t> Value + * Value :- Array | Object | Terminal + * + * Array :- + * ArrayTag <length:uint32_t>(<index:uint32_t><value:Value>)* TerminatorTag + * + * Object :- + * ObjectTag (<name:StringData><value:Value>)* TerminatorTag + * + * Terminal :- + * UndefinedTag + * | NullTag + * | IntTag <value:int32_t> + * | ZeroTag + * | OneTag + * | DoubleTag <value:double> + * | DateTag <value:double> + * | String + * | EmptyStringTag + * | File + * | FileList + * | ImageData + * | Blob + * | ObjectReferenceTag <opIndex:IndexType> + * + * String :- + * EmptyStringTag + * StringTag StringData + * + * StringData :- + * StringPoolTag <cpIndex:IndexType> + * (not (TerminatorTag | StringPoolTag))<length:uint32_t><characters:UChar{length}> // Added to constant pool when seen, string length 0xFFFFFFFF is disallowed + * + * File :- + * FileTag FileData + * + * FileData :- + * <path:StringData> <url:StringData> <type:StringData> + * + * FileList :- + * FileListTag <length:uint32_t>(<file:FileData>){length} + * + * ImageData :- + * ImageDataTag <width:int32_t><height:int32_t><length:uint32_t><data:uint8_t{length}> + * + * Blob :- + * BlobTag <url:StringData><type:StringData><size:long long> + * + * RegExp :- + * RegExpTag <pattern:StringData><flags:StringData> + */ + +class CloneBase { +protected: + CloneBase(ExecState* exec) + : m_exec(exec) + , m_failed(false) + , m_timeoutChecker(exec->globalData().timeoutChecker) + { + } + + bool shouldTerminate() + { + return m_exec->hadException(); + } + + unsigned ticksUntilNextCheck() + { + return m_timeoutChecker.ticksUntilNextCheck(); + } + + bool didTimeOut() + { + return m_timeoutChecker.didTimeOut(m_exec); + } + + void throwStackOverflow() + { + throwError(m_exec, createStackOverflowError(m_exec)); + } + + void throwInterruptedException() + { + throwError(m_exec, createInterruptedExecutionException(&m_exec->globalData())); + } + + void fail() + { + ASSERT_NOT_REACHED(); + m_failed = true; + } + + ExecState* m_exec; + bool m_failed; + TimeoutChecker m_timeoutChecker; + MarkedArgumentBuffer m_gcBuffer; +}; + +class CloneSerializer : CloneBase { +public: + static bool serialize(ExecState* exec, JSValue value, Vector<uint8_t>& out) + { + CloneSerializer serializer(exec, out); + return serializer.serialize(value); + } + + static bool serialize(String s, Vector<uint8_t>& out) + { + writeLittleEndian(out, CurrentVersion); + if (s.isEmpty()) { + writeLittleEndian<uint8_t>(out, EmptyStringTag); + return true; + } + writeLittleEndian<uint8_t>(out, StringTag); + writeLittleEndian(out, s.length()); + return writeLittleEndian(out, s.impl()->characters(), s.length()); + } + +private: + CloneSerializer(ExecState* exec, Vector<uint8_t>& out) + : CloneBase(exec) + , m_buffer(out) + , m_emptyIdentifier(exec, UString("", 0)) + { + write(CurrentVersion); + } + + bool serialize(JSValue in); + + bool isArray(JSValue value) + { + if (!value.isObject()) + return false; + JSObject* object = asObject(value); + return isJSArray(&m_exec->globalData(), object) || object->inherits(&JSArray::info); + } + + bool startObjectInternal(JSObject* object) + { + // Record object for graph reconstruction + pair<ObjectPool::iterator, bool> iter = m_objectPool.add(object, m_objectPool.size()); + + // Handle duplicate references + if (!iter.second) { + write(ObjectReferenceTag); + ASSERT(static_cast<int32_t>(iter.first->second) < m_objectPool.size()); + writeObjectIndex(iter.first->second); + return false; + } + + m_gcBuffer.append(object); + return true; + } + + bool startObject(JSObject* object) + { + if (!startObjectInternal(object)) + return false; + write(ObjectTag); + return true; + } + + bool startArray(JSArray* array) + { + if (!startObjectInternal(array)) + return false; + + unsigned length = array->length(); + write(ArrayTag); + write(length); + return true; + } + + void endObject() + { + write(TerminatorTag); + } + + JSValue getSparseIndex(JSArray* array, unsigned propertyName, bool& hasIndex) + { + PropertySlot slot(array); + if (isJSArray(&m_exec->globalData(), array)) { + if (array->JSArray::getOwnPropertySlot(m_exec, propertyName, slot)) { + hasIndex = true; + return slot.getValue(m_exec, propertyName); + } + } else if (array->getOwnPropertySlot(m_exec, propertyName, slot)) { + hasIndex = true; + return slot.getValue(m_exec, propertyName); + } + hasIndex = false; + return jsNull(); + } + + JSValue getProperty(JSObject* object, const Identifier& propertyName) + { + PropertySlot slot(object); + if (object->getOwnPropertySlot(m_exec, propertyName, slot)) + return slot.getValue(m_exec, propertyName); + return JSValue(); + } + + void dumpImmediate(JSValue value) + { + if (value.isNull()) + write(NullTag); + else if (value.isUndefined()) + write(UndefinedTag); + else if (value.isNumber()) { + if (value.isInt32()) { + if (!value.asInt32()) + write(ZeroTag); + else if (value.asInt32() == 1) + write(OneTag); + else { + write(IntTag); + write(static_cast<uint32_t>(value.asInt32())); + } + } else { + write(DoubleTag); + write(value.asDouble()); + } + } else if (value.isBoolean()) { + if (value.isTrue()) + write(TrueTag); + else + write(FalseTag); + } + } + + void dumpString(UString str) + { + if (str.isEmpty()) + write(EmptyStringTag); + else { + write(StringTag); + write(str); + } + } + + bool dumpIfTerminal(JSValue value) + { + if (!value.isCell()) { + dumpImmediate(value); + return true; + } + + if (value.isString()) { + UString str = asString(value)->value(m_exec); + dumpString(str); + return true; + } + + if (value.isNumber()) { + write(DoubleTag); + write(value.uncheckedGetNumber()); + return true; + } + + if (value.isObject() && asObject(value)->inherits(&DateInstance::info)) { + write(DateTag); + write(asDateInstance(value)->internalNumber()); + return true; + } + + if (isArray(value)) + return false; + + if (value.isObject()) { + JSObject* obj = asObject(value); + if (obj->inherits(&JSFile::s_info)) { + write(FileTag); + write(toFile(obj)); + return true; + } + if (obj->inherits(&JSFileList::s_info)) { + FileList* list = toFileList(obj); + write(FileListTag); + unsigned length = list->length(); + write(length); + for (unsigned i = 0; i < length; i++) + write(list->item(i)); + return true; + } + if (obj->inherits(&JSBlob::s_info)) { + write(BlobTag); + Blob* blob = toBlob(obj); + write(blob->url()); + write(blob->type()); + write(blob->size()); + return true; + } + if (obj->inherits(&JSImageData::s_info)) { + ImageData* data = toImageData(obj); + write(ImageDataTag); + write(data->width()); + write(data->height()); + write(data->data()->length()); + write(data->data()->data()->data(), data->data()->length()); + return true; + } + if (obj->inherits(&RegExpObject::info)) { + RegExpObject* regExp = asRegExpObject(obj); + char flags[3]; + int flagCount = 0; + if (regExp->regExp()->global()) + flags[flagCount++] = 'g'; + if (regExp->regExp()->ignoreCase()) + flags[flagCount++] = 'i'; + if (regExp->regExp()->multiline()) + flags[flagCount++] = 'm'; + write(RegExpTag); + write(regExp->regExp()->pattern()); + write(UString(flags, flagCount)); + return true; + } + + CallData unusedData; + if (getCallData(value, unusedData) == CallTypeNone) + return false; + } + // Any other types are expected to serialize as null. + write(NullTag); + return true; + } + + void write(SerializationTag tag) + { + writeLittleEndian<uint8_t>(m_buffer, static_cast<uint8_t>(tag)); + } + + void write(uint8_t c) + { + writeLittleEndian(m_buffer, c); + } + +#if ASSUME_LITTLE_ENDIAN + template <typename T> static void writeLittleEndian(Vector<uint8_t>& buffer, T value) + { + if (sizeof(T) == 1) + buffer.append(value); + else + buffer.append(reinterpret_cast<uint8_t*>(&value), sizeof(value)); + } +#else + template <typename T> static void writeLittleEndian(Vector<uint8_t>& buffer, T value) + { + for (unsigned i = 0; i < sizeof(T); i++) { + buffer.append(value & 0xFF); + value >>= 8; + } + } +#endif + + template <typename T> static bool writeLittleEndian(Vector<uint8_t>& buffer, const T* values, uint32_t length) + { + if (length > numeric_limits<uint32_t>::max() / sizeof(T)) + return false; + +#if ASSUME_LITTLE_ENDIAN + buffer.append(reinterpret_cast<const uint8_t*>(values), length * sizeof(T)); +#else + for (unsigned i = 0; i < length; i++) { + T value = values[i]; + for (unsigned j = 0; j < sizeof(T); j++) { + buffer.append(static_cast<uint8_t>(value & 0xFF)); + value >>= 8; + } + } +#endif + return true; + } + + void write(uint32_t i) + { + writeLittleEndian(m_buffer, i); + } + + void write(double d) + { + union { + double d; + int64_t i; + } u; + u.d = d; + writeLittleEndian(m_buffer, u.i); + } + + void write(int32_t i) + { + writeLittleEndian(m_buffer, i); + } + + void write(unsigned long long i) + { + writeLittleEndian(m_buffer, i); + } + + void write(uint16_t ch) + { + writeLittleEndian(m_buffer, ch); + } + + void writeStringIndex(unsigned i) + { + writeConstantPoolIndex(m_constantPool, i); + } + + void writeObjectIndex(unsigned i) + { + writeConstantPoolIndex(m_objectPool, i); + } + + template <class T> void writeConstantPoolIndex(const T& constantPool, unsigned i) + { + ASSERT(static_cast<int32_t>(i) < constantPool.size()); + if (constantPool.size() <= 0xFF) + write(static_cast<uint8_t>(i)); + else if (constantPool.size() <= 0xFFFF) + write(static_cast<uint16_t>(i)); + else + write(static_cast<uint32_t>(i)); + } + + void write(const Identifier& ident) + { + UString str = ident.ustring(); + pair<StringConstantPool::iterator, bool> iter = m_constantPool.add(str.impl(), m_constantPool.size()); + if (!iter.second) { + write(StringPoolTag); + writeStringIndex(iter.first->second); + return; + } + + // This condition is unlikely to happen as they would imply an ~8gb + // string but we should guard against it anyway + if (str.length() >= StringPoolTag) { + fail(); + return; + } + + // Guard against overflow + if (str.length() > (numeric_limits<uint32_t>::max() - sizeof(uint32_t)) / sizeof(UChar)) { + fail(); + return; + } + + writeLittleEndian<uint32_t>(m_buffer, str.length()); + if (!writeLittleEndian<uint16_t>(m_buffer, reinterpret_cast<const uint16_t*>(str.characters()), str.length())) + fail(); + } + + void write(const UString& str) + { + if (str.isNull()) + write(m_emptyIdentifier); + else + write(Identifier(m_exec, str)); + } + + void write(const String& str) + { + if (str.isEmpty()) + write(m_emptyIdentifier); + else + write(Identifier(m_exec, str.impl())); + } + + void write(const File* file) + { + write(file->path()); + write(file->url()); + write(file->type()); + } + + void write(const uint8_t* data, unsigned length) + { + m_buffer.append(data, length); + } + + Vector<uint8_t>& m_buffer; + typedef HashMap<JSObject*, uint32_t> ObjectPool; + ObjectPool m_objectPool; + typedef HashMap<RefPtr<StringImpl>, uint32_t, IdentifierRepHash> StringConstantPool; + StringConstantPool m_constantPool; + Identifier m_emptyIdentifier; +}; + +bool CloneSerializer::serialize(JSValue in) +{ + Vector<uint32_t, 16> indexStack; + Vector<uint32_t, 16> lengthStack; + Vector<PropertyNameArray, 16> propertyStack; + Vector<JSObject*, 16> inputObjectStack; + Vector<JSArray*, 16> inputArrayStack; + Vector<WalkerState, 16> stateStack; + WalkerState state = StateUnknown; + JSValue inValue = in; + unsigned tickCount = ticksUntilNextCheck(); + while (1) { + switch (state) { + arrayStartState: + case ArrayStartState: { + ASSERT(isArray(inValue)); + if (inputObjectStack.size() + inputArrayStack.size() > maximumFilterRecursion) { + throwStackOverflow(); + return false; + } + + JSArray* inArray = asArray(inValue); + unsigned length = inArray->length(); + if (!startArray(inArray)) + break; + inputArrayStack.append(inArray); + indexStack.append(0); + lengthStack.append(length); + // fallthrough + } + arrayStartVisitMember: + case ArrayStartVisitMember: { + if (!--tickCount) { + if (didTimeOut()) { + throwInterruptedException(); + return false; + } + tickCount = ticksUntilNextCheck(); + } + + JSArray* array = inputArrayStack.last(); + uint32_t index = indexStack.last(); + if (index == lengthStack.last()) { + endObject(); + inputArrayStack.removeLast(); + indexStack.removeLast(); + lengthStack.removeLast(); + break; + } + if (array->canGetIndex(index)) + inValue = array->getIndex(index); + else { + bool hasIndex = false; + inValue = getSparseIndex(array, index, hasIndex); + if (!hasIndex) { + indexStack.last()++; + goto arrayStartVisitMember; + } + } + + write(index); + if (dumpIfTerminal(inValue)) { + indexStack.last()++; + goto arrayStartVisitMember; + } + stateStack.append(ArrayEndVisitMember); + goto stateUnknown; + } + case ArrayEndVisitMember: { + indexStack.last()++; + goto arrayStartVisitMember; + } + objectStartState: + case ObjectStartState: { + ASSERT(inValue.isObject()); + if (inputObjectStack.size() + inputArrayStack.size() > maximumFilterRecursion) { + throwStackOverflow(); + return false; + } + JSObject* inObject = asObject(inValue); + if (!startObject(inObject)) + break; + inputObjectStack.append(inObject); + indexStack.append(0); + propertyStack.append(PropertyNameArray(m_exec)); + inObject->getOwnPropertyNames(m_exec, propertyStack.last()); + // fallthrough + } + objectStartVisitMember: + case ObjectStartVisitMember: { + if (!--tickCount) { + if (didTimeOut()) { + throwInterruptedException(); + return false; + } + tickCount = ticksUntilNextCheck(); + } + + JSObject* object = inputObjectStack.last(); + uint32_t index = indexStack.last(); + PropertyNameArray& properties = propertyStack.last(); + if (index == properties.size()) { + endObject(); + inputObjectStack.removeLast(); + indexStack.removeLast(); + propertyStack.removeLast(); + break; + } + inValue = getProperty(object, properties[index]); + if (shouldTerminate()) + return false; + + if (!inValue) { + // Property was removed during serialisation + indexStack.last()++; + goto objectStartVisitMember; + } + write(properties[index]); + + if (shouldTerminate()) + return false; + + if (!dumpIfTerminal(inValue)) { + stateStack.append(ObjectEndVisitMember); + goto stateUnknown; + } + // fallthrough + } + case ObjectEndVisitMember: { + if (shouldTerminate()) + return false; + + indexStack.last()++; + goto objectStartVisitMember; + } + stateUnknown: + case StateUnknown: + if (dumpIfTerminal(inValue)) + break; + + if (isArray(inValue)) + goto arrayStartState; + goto objectStartState; + } + if (stateStack.isEmpty()) + break; + + state = stateStack.last(); + stateStack.removeLast(); + + if (!--tickCount) { + if (didTimeOut()) { + throwInterruptedException(); + return false; + } + tickCount = ticksUntilNextCheck(); + } + } + if (m_failed) + return false; + + return true; +} + +class CloneDeserializer : CloneBase { +public: + static String deserializeString(const Vector<uint8_t>& buffer) + { + const uint8_t* ptr = buffer.begin(); + const uint8_t* end = buffer.end(); + uint32_t version; + if (!readLittleEndian(ptr, end, version) || version > CurrentVersion) + return String(); + uint8_t tag; + if (!readLittleEndian(ptr, end, tag) || tag != StringTag) + return String(); + uint32_t length; + if (!readLittleEndian(ptr, end, length) || length >= StringPoolTag) + return String(); + UString str; + if (!readString(ptr, end, str, length)) + return String(); + return String(str.impl()); + } + + static JSValue deserialize(ExecState* exec, JSGlobalObject* globalObject, const Vector<uint8_t>& buffer) + { + if (!buffer.size()) + return jsNull(); + CloneDeserializer deserializer(exec, globalObject, buffer); + if (!deserializer.isValid()) { + deserializer.throwValidationError(); + return JSValue(); + } + return deserializer.deserialize(); + } + +private: + struct CachedString { + CachedString(const UString& string) + : m_string(string) + { + } + + JSValue jsString(ExecState* exec) + { + if (!m_jsString) + m_jsString = JSC::jsString(exec, m_string); + return m_jsString; + } + const UString& ustring() { return m_string; } + + private: + UString m_string; + JSValue m_jsString; + }; + + struct CachedStringRef { + CachedStringRef() + : m_base(0) + , m_index(0) + { + } + CachedStringRef(Vector<CachedString>* base, size_t index) + : m_base(base) + , m_index(index) + { + } + + CachedString* operator->() { ASSERT(m_base); return &m_base->at(m_index); } + + private: + Vector<CachedString>* m_base; + size_t m_index; + }; + + CloneDeserializer(ExecState* exec, JSGlobalObject* globalObject, const Vector<uint8_t>& buffer) + : CloneBase(exec) + , m_globalObject(globalObject) + , m_isDOMGlobalObject(globalObject->inherits(&JSDOMGlobalObject::s_info)) + , m_ptr(buffer.data()) + , m_end(buffer.data() + buffer.size()) + , m_version(0xFFFFFFFF) + { + if (!read(m_version)) + m_version = 0xFFFFFFFF; + } + + JSValue deserialize(); + + void throwValidationError() + { + throwError(m_exec, createTypeError(m_exec, "Unable to deserialize data.")); + } + + bool isValid() const { return m_version <= CurrentVersion; } + + template <typename T> bool readLittleEndian(T& value) + { + if (m_failed || !readLittleEndian(m_ptr, m_end, value)) { + fail(); + return false; + } + return true; + } +#if ASSUME_LITTLE_ENDIAN + template <typename T> static bool readLittleEndian(const uint8_t*& ptr, const uint8_t* end, T& value) + { + if (ptr > end - sizeof(value)) + return false; + + if (sizeof(T) == 1) + value = *ptr++; + else { +#if CPU(ARMV5_OR_LOWER) + // To protect misaligned memory access. + memcpy(&value, ptr, sizeof(T)); +#else + value = *reinterpret_cast<const T*>(ptr); +#endif + ptr += sizeof(T); + } + return true; + } +#else + template <typename T> static bool readLittleEndian(const uint8_t*& ptr, const uint8_t* end, T& value) + { + if (ptr > end - sizeof(value)) + return false; + + if (sizeof(T) == 1) + value = *ptr++; + else { + value = 0; + for (unsigned i = 0; i < sizeof(T); i++) + value += ((T)*ptr++) << (i * 8); + } + return true; + } +#endif + + bool read(uint32_t& i) + { + return readLittleEndian(i); + } + + bool read(int32_t& i) + { + return readLittleEndian(*reinterpret_cast<uint32_t*>(&i)); + } + + bool read(uint16_t& i) + { + return readLittleEndian(i); + } + + bool read(uint8_t& i) + { + return readLittleEndian(i); + } + + bool read(double& d) + { + union { + double d; + uint64_t i64; + } u; + if (!readLittleEndian(u.i64)) + return false; + d = u.d; + return true; + } + + bool read(unsigned long long& i) + { + return readLittleEndian(i); + } + + bool readStringIndex(uint32_t& i) + { + return readConstantPoolIndex(m_constantPool, i); + } + + template <class T> bool readConstantPoolIndex(const T& constantPool, uint32_t& i) + { + if (constantPool.size() <= 0xFF) { + uint8_t i8; + if (!read(i8)) + return false; + i = i8; + return true; + } + if (constantPool.size() <= 0xFFFF) { + uint16_t i16; + if (!read(i16)) + return false; + i = i16; + return true; + } + return read(i); + } + + static bool readString(const uint8_t*& ptr, const uint8_t* end, UString& str, unsigned length) + { + if (length >= numeric_limits<int32_t>::max() / sizeof(UChar)) + return false; + + unsigned size = length * sizeof(UChar); + if ((end - ptr) < static_cast<int>(size)) + return false; + +#if ASSUME_LITTLE_ENDIAN +#if CPU(ARMV5_OR_LOWER) + // To protect misaligned memory access. + Vector<UChar> alignedBuffer(length); + memcpy(alignedBuffer.data(), ptr, length * sizeof(UChar)); + str = UString::adopt(alignedBuffer); +#else + str = UString(reinterpret_cast<const UChar*>(ptr), length); +#endif + ptr += length * sizeof(UChar); +#else + Vector<UChar> buffer; + buffer.reserveCapacity(length); + for (unsigned i = 0; i < length; i++) { + uint16_t ch; + readLittleEndian(ptr, end, ch); + buffer.append(ch); + } + str = UString::adopt(buffer); +#endif + return true; + } + + bool readStringData(CachedStringRef& cachedString) + { + bool scratch; + return readStringData(cachedString, scratch); + } + + bool readStringData(CachedStringRef& cachedString, bool& wasTerminator) + { + if (m_failed) + return false; + uint32_t length = 0; + if (!read(length)) + return false; + if (length == TerminatorTag) { + wasTerminator = true; + return false; + } + if (length == StringPoolTag) { + unsigned index = 0; + if (!readStringIndex(index)) { + fail(); + return false; + } + if (index >= m_constantPool.size()) { + fail(); + return false; + } + cachedString = CachedStringRef(&m_constantPool, index); + return true; + } + UString str; + if (!readString(m_ptr, m_end, str, length)) { + fail(); + return false; + } + m_constantPool.append(str); + cachedString = CachedStringRef(&m_constantPool, m_constantPool.size() - 1); + return true; + } + + SerializationTag readTag() + { + if (m_ptr >= m_end) + return ErrorTag; + return static_cast<SerializationTag>(*m_ptr++); + } + + void putProperty(JSArray* array, unsigned index, JSValue value) + { + if (array->canSetIndex(index)) + array->setIndex(index, value); + else + array->put(m_exec, index, value); + } + + void putProperty(JSObject* object, const Identifier& property, JSValue value) + { + object->putDirect(property, value); + } + + bool readFile(RefPtr<File>& file) + { + CachedStringRef path; + if (!readStringData(path)) + return 0; + CachedStringRef url; + if (!readStringData(url)) + return 0; + CachedStringRef type; + if (!readStringData(type)) + return 0; + if (m_isDOMGlobalObject) + file = File::create(String(path->ustring().impl()), KURL(KURL(), String(url->ustring().impl())), String(type->ustring().impl())); + return true; + } + + JSValue readTerminal() + { + SerializationTag tag = readTag(); + switch (tag) { + case UndefinedTag: + return jsUndefined(); + case NullTag: + return jsNull(); + case IntTag: { + int32_t i; + if (!read(i)) + return JSValue(); + return jsNumber(i); + } + case ZeroTag: + return jsNumber(0); + case OneTag: + return jsNumber(1); + case FalseTag: + return jsBoolean(false); + case TrueTag: + return jsBoolean(true); + case DoubleTag: { + double d; + if (!read(d)) + return JSValue(); + return jsNumber(d); + } + case DateTag: { + double d; + if (!read(d)) + return JSValue(); + return new (m_exec) DateInstance(m_exec, m_globalObject->dateStructure(), d); + } + case FileTag: { + RefPtr<File> file; + if (!readFile(file)) + return JSValue(); + if (!m_isDOMGlobalObject) + return jsNull(); + return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), file.get()); + } + case FileListTag: { + unsigned length = 0; + if (!read(length)) + return JSValue(); + RefPtr<FileList> result = FileList::create(); + for (unsigned i = 0; i < length; i++) { + RefPtr<File> file; + if (!readFile(file)) + return JSValue(); + if (m_isDOMGlobalObject) + result->append(file.get()); + } + if (!m_isDOMGlobalObject) + return jsNull(); + return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get()); + } + case ImageDataTag: { + int32_t width; + if (!read(width)) + return JSValue(); + int32_t height; + if (!read(height)) + return JSValue(); + uint32_t length; + if (!read(length)) + return JSValue(); + if (m_end < ((uint8_t*)0) + length || m_ptr > m_end - length) { + fail(); + return JSValue(); + } + if (!m_isDOMGlobalObject) { + m_ptr += length; + return jsNull(); + } + RefPtr<ImageData> result = ImageData::create(IntSize(width, height)); + memcpy(result->data()->data()->data(), m_ptr, length); + m_ptr += length; + return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get()); + } + case BlobTag: { + CachedStringRef url; + if (!readStringData(url)) + return JSValue(); + CachedStringRef type; + if (!readStringData(type)) + return JSValue(); + unsigned long long size = 0; + if (!read(size)) + return JSValue(); + if (!m_isDOMGlobalObject) + return jsNull(); + return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), Blob::create(KURL(KURL(), url->ustring().impl()), String(type->ustring().impl()), size)); + } + case StringTag: { + CachedStringRef cachedString; + if (!readStringData(cachedString)) + return JSValue(); + return cachedString->jsString(m_exec); + } + case EmptyStringTag: + return jsEmptyString(&m_exec->globalData()); + case RegExpTag: { + CachedStringRef pattern; + if (!readStringData(pattern)) + return JSValue(); + CachedStringRef flags; + if (!readStringData(flags)) + return JSValue(); + RefPtr<RegExp> regExp = RegExp::create(&m_exec->globalData(), pattern->ustring(), flags->ustring()); + return new (m_exec) RegExpObject(m_exec->lexicalGlobalObject(), m_globalObject->regExpStructure(), regExp); + } + case ObjectReferenceTag: { + unsigned index = 0; + if (!readConstantPoolIndex(m_gcBuffer, index)) { + fail(); + return JSValue(); + } + return m_gcBuffer.at(index); + } + default: + m_ptr--; // Push the tag back + return JSValue(); + } + } + + JSGlobalObject* m_globalObject; + bool m_isDOMGlobalObject; + const uint8_t* m_ptr; + const uint8_t* m_end; + unsigned m_version; + Vector<CachedString> m_constantPool; +}; + +JSValue CloneDeserializer::deserialize() +{ + Vector<uint32_t, 16> indexStack; + Vector<Identifier, 16> propertyNameStack; + Vector<JSObject*, 16> outputObjectStack; + Vector<JSArray*, 16> outputArrayStack; + Vector<WalkerState, 16> stateStack; + WalkerState state = StateUnknown; + JSValue outValue; + + unsigned tickCount = ticksUntilNextCheck(); + while (1) { + switch (state) { + arrayStartState: + case ArrayStartState: { + uint32_t length; + if (!read(length)) { + fail(); + goto error; + } + JSArray* outArray = constructEmptyArray(m_exec, m_globalObject); + outArray->setLength(length); + m_gcBuffer.append(outArray); + outputArrayStack.append(outArray); + // fallthrough + } + arrayStartVisitMember: + case ArrayStartVisitMember: { + if (!--tickCount) { + if (didTimeOut()) { + throwInterruptedException(); + return JSValue(); + } + tickCount = ticksUntilNextCheck(); + } + + uint32_t index; + if (!read(index)) { + fail(); + goto error; + } + if (index == TerminatorTag) { + JSArray* outArray = outputArrayStack.last(); + outValue = outArray; + outputArrayStack.removeLast(); + break; + } + + if (JSValue terminal = readTerminal()) { + putProperty(outputArrayStack.last(), index, terminal); + goto arrayStartVisitMember; + } + if (m_failed) + goto error; + indexStack.append(index); + stateStack.append(ArrayEndVisitMember); + goto stateUnknown; + } + case ArrayEndVisitMember: { + JSArray* outArray = outputArrayStack.last(); + putProperty(outArray, indexStack.last(), outValue); + indexStack.removeLast(); + goto arrayStartVisitMember; + } + objectStartState: + case ObjectStartState: { + if (outputObjectStack.size() + outputArrayStack.size() > maximumFilterRecursion) { + throwStackOverflow(); + return JSValue(); + } + JSObject* outObject = constructEmptyObject(m_exec, m_globalObject); + m_gcBuffer.append(outObject); + outputObjectStack.append(outObject); + // fallthrough + } + objectStartVisitMember: + case ObjectStartVisitMember: { + if (!--tickCount) { + if (didTimeOut()) { + throwInterruptedException(); + return JSValue(); + } + tickCount = ticksUntilNextCheck(); + } + + CachedStringRef cachedString; + bool wasTerminator = false; + if (!readStringData(cachedString, wasTerminator)) { + if (!wasTerminator) + goto error; + JSObject* outObject = outputObjectStack.last(); + outValue = outObject; + outputObjectStack.removeLast(); + break; + } + + if (JSValue terminal = readTerminal()) { + putProperty(outputObjectStack.last(), Identifier(m_exec, cachedString->ustring()), terminal); + goto objectStartVisitMember; + } + stateStack.append(ObjectEndVisitMember); + propertyNameStack.append(Identifier(m_exec, cachedString->ustring())); + goto stateUnknown; + } + case ObjectEndVisitMember: { + putProperty(outputObjectStack.last(), propertyNameStack.last(), outValue); + propertyNameStack.removeLast(); + goto objectStartVisitMember; + } + stateUnknown: + case StateUnknown: + if (JSValue terminal = readTerminal()) { + outValue = terminal; + break; + } + SerializationTag tag = readTag(); + if (tag == ArrayTag) + goto arrayStartState; + if (tag == ObjectTag) + goto objectStartState; + goto error; + } + if (stateStack.isEmpty()) + break; + + state = stateStack.last(); + stateStack.removeLast(); + + if (!--tickCount) { + if (didTimeOut()) { + throwInterruptedException(); + return JSValue(); + } + tickCount = ticksUntilNextCheck(); + } + } + ASSERT(outValue); + ASSERT(!m_failed); + return outValue; +error: + fail(); + throwValidationError(); + return JSValue(); +} + + + +SerializedScriptValue::~SerializedScriptValue() +{ +} + +SerializedScriptValue::SerializedScriptValue(Vector<uint8_t>& buffer) +{ + m_data.swap(buffer); +} + +PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(ExecState* exec, JSValue value) +{ + Vector<uint8_t> buffer; + if (!CloneSerializer::serialize(exec, value, buffer)) + return 0; + return adoptRef(new SerializedScriptValue(buffer)); +} + +PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() +{ + Vector<uint8_t> buffer; + return adoptRef(new SerializedScriptValue(buffer)); +} + +PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(String string) +{ + Vector<uint8_t> buffer; + if (!CloneSerializer::serialize(string, buffer)) + return 0; + return adoptRef(new SerializedScriptValue(buffer)); +} + +PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(JSContextRef originContext, JSValueRef apiValue, JSValueRef* exception) +{ + JSLock lock(SilenceAssertionsOnly); + ExecState* exec = toJS(originContext); + JSValue value = toJS(exec, apiValue); + PassRefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::create(exec, value); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + return 0; + } + ASSERT(serializedValue); + return serializedValue; +} + +String SerializedScriptValue::toString() +{ + return CloneDeserializer::deserializeString(m_data); +} + +JSValue SerializedScriptValue::deserialize(ExecState* exec, JSGlobalObject* globalObject) +{ + return CloneDeserializer::deserialize(exec, globalObject, m_data); +} + +JSValueRef SerializedScriptValue::deserialize(JSContextRef destinationContext, JSValueRef* exception) +{ + JSLock lock(SilenceAssertionsOnly); + ExecState* exec = toJS(destinationContext); + JSValue value = deserialize(exec, exec->lexicalGlobalObject()); + if (exec->hadException()) { + if (exception) + *exception = toRef(exec, exec->exception()); + exec->clearException(); + return 0; + } + ASSERT(value); + return toRef(exec, value); +} + +SerializedScriptValue* SerializedScriptValue::nullValue() +{ + DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, emptyValue, (SerializedScriptValue::create())); + return emptyValue.get(); +} + +} diff --git a/Source/WebCore/bindings/js/SerializedScriptValue.h b/Source/WebCore/bindings/js/SerializedScriptValue.h new file mode 100644 index 0000000..94bc477 --- /dev/null +++ b/Source/WebCore/bindings/js/SerializedScriptValue.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef SerializedScriptValue_h +#define SerializedScriptValue_h + +#include "ScriptValue.h" +#include <wtf/Forward.h> + +typedef const struct OpaqueJSContext* JSContextRef; +typedef const struct OpaqueJSValue* JSValueRef; + +namespace WebCore { + +class SharedBuffer; + +class SerializedScriptValue : public RefCounted<SerializedScriptValue> { +public: + static PassRefPtr<SerializedScriptValue> create(JSC::ExecState* exec, JSC::JSValue value); + static PassRefPtr<SerializedScriptValue> create(JSContextRef, JSValueRef value, JSValueRef* exception); + static PassRefPtr<SerializedScriptValue> create(String string); + static PassRefPtr<SerializedScriptValue> adopt(Vector<uint8_t>& buffer) + { + return adoptRef(new SerializedScriptValue(buffer)); + } + + static PassRefPtr<SerializedScriptValue> create(); + static SerializedScriptValue* nullValue(); + + JSC::JSValue deserialize(JSC::ExecState* exec, JSC::JSGlobalObject* globalObject); + String toString(); + JSValueRef deserialize(JSContextRef, JSValueRef* exception); + const Vector<uint8_t>& data() { return m_data; } + + ~SerializedScriptValue(); + +private: + SerializedScriptValue(Vector<unsigned char>&); + Vector<unsigned char> m_data; +}; + +} + +#endif // SerializedScriptValue_h diff --git a/Source/WebCore/bindings/js/StringSourceProvider.h b/Source/WebCore/bindings/js/StringSourceProvider.h new file mode 100644 index 0000000..478c1d1 --- /dev/null +++ b/Source/WebCore/bindings/js/StringSourceProvider.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef StringSourceProvider_h +#define StringSourceProvider_h + +#include "JSDOMBinding.h" +#include "ScriptSourceProvider.h" +#include <parser/SourceCode.h> + +namespace WebCore { + + class StringSourceProvider : public ScriptSourceProvider { + public: + static PassRefPtr<StringSourceProvider> create(const String& source, const String& url) { return adoptRef(new StringSourceProvider(source, url)); } + + JSC::UString getRange(int start, int end) const { return JSC::UString(m_source.characters() + start, end - start); } + const UChar* data() const { return m_source.characters(); } + int length() const { return m_source.length(); } + const String& source() const { return m_source; } + + private: + StringSourceProvider(const String& source, const String& url) + : ScriptSourceProvider(stringToUString(url)) + , m_source(source) + { + } + + String m_source; + }; + + inline JSC::SourceCode makeSource(const String& source, const String& url = String(), int firstLine = 1) + { + return JSC::SourceCode(StringSourceProvider::create(source, url), firstLine); + } + +} // namespace WebCore + +#endif // StringSourceProvider_h diff --git a/Source/WebCore/bindings/js/WebCoreJSClientData.h b/Source/WebCore/bindings/js/WebCoreJSClientData.h new file mode 100644 index 0000000..5d03328 --- /dev/null +++ b/Source/WebCore/bindings/js/WebCoreJSClientData.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2007 Samuel Weinig <sam@webkit.org> + * Copyright (C) 2009 Google, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef WebCoreJSClientData_h +#define WebCoreJSClientData_h + +#include "DOMWrapperWorld.h" +#include "DOMObjectHashTableMap.h" +#include <wtf/Noncopyable.h> +#include <wtf/HashSet.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +class WebCoreJSClientData : public JSC::JSGlobalData::ClientData, public Noncopyable { + friend class JSGlobalDataWorldIterator; + friend void initNormalWorldClientData(JSC::JSGlobalData*); + +public: + virtual ~WebCoreJSClientData() + { + ASSERT(m_worldSet.contains(m_normalWorld.get())); + ASSERT(m_worldSet.size() == 1); + ASSERT(m_normalWorld->hasOneRef()); + m_normalWorld.clear(); + ASSERT(m_worldSet.isEmpty()); + } + + DOMWrapperWorld* normalWorld() { return m_normalWorld.get(); } + + void getAllWorlds(Vector<DOMWrapperWorld*>& worlds) + { + copyToVector(m_worldSet, worlds); + } + + void rememberWorld(DOMWrapperWorld* world) + { + ASSERT(!m_worldSet.contains(world)); + m_worldSet.add(world); + } + void forgetWorld(DOMWrapperWorld* world) + { + ASSERT(m_worldSet.contains(world)); + m_worldSet.remove(world); + } + + DOMObjectHashTableMap hashTableMap; + +private: + HashSet<DOMWrapperWorld*> m_worldSet; + RefPtr<DOMWrapperWorld> m_normalWorld; +}; + +inline void initNormalWorldClientData(JSC::JSGlobalData* globalData) +{ + WebCoreJSClientData* webCoreJSClientData = new WebCoreJSClientData; + globalData->clientData = webCoreJSClientData; // ~JSGlobalData deletes this pointer. + webCoreJSClientData->m_normalWorld = DOMWrapperWorld::create(globalData, true); +} + +} // namespace WebCore + +#endif // WebCoreJSClientData_h diff --git a/Source/WebCore/bindings/js/WorkerScriptController.cpp b/Source/WebCore/bindings/js/WorkerScriptController.cpp new file mode 100644 index 0000000..5872b2e --- /dev/null +++ b/Source/WebCore/bindings/js/WorkerScriptController.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "config.h" + +#if ENABLE(WORKERS) + +#include "WorkerScriptController.h" + +#include "JSDedicatedWorkerContext.h" +#include "JSSharedWorkerContext.h" +#include "ScriptSourceCode.h" +#include "ScriptValue.h" +#include "WebCoreJSClientData.h" +#include "WorkerContext.h" +#include "WorkerObjectProxy.h" +#include "WorkerThread.h" +#include <interpreter/Interpreter.h> +#include <runtime/Completion.h> +#include <runtime/Completion.h> +#include <runtime/Error.h> +#include <runtime/JSLock.h> + +using namespace JSC; + +namespace WebCore { + +WorkerScriptController::WorkerScriptController(WorkerContext* workerContext) + : m_globalData(JSGlobalData::create(ThreadStackTypeSmall)) + , m_workerContext(workerContext) + , m_executionForbidden(false) +{ + initNormalWorldClientData(m_globalData.get()); +} + +WorkerScriptController::~WorkerScriptController() +{ + m_workerContextWrapper = 0; // Unprotect the global object. + m_globalData->heap.destroy(); +} + +void WorkerScriptController::initScript() +{ + ASSERT(!m_workerContextWrapper); + + JSLock lock(SilenceAssertionsOnly); + + // Explicitly protect the global object's prototype so it isn't collected + // when we allocate the global object. (Once the global object is fully + // constructed, it can mark its own prototype.) + RefPtr<Structure> workerContextPrototypeStructure = JSWorkerContextPrototype::createStructure(jsNull()); + ProtectedPtr<JSWorkerContextPrototype> workerContextPrototype = new (m_globalData.get()) JSWorkerContextPrototype(0, workerContextPrototypeStructure.release()); + + if (m_workerContext->isDedicatedWorkerContext()) { + RefPtr<Structure> dedicatedContextPrototypeStructure = JSDedicatedWorkerContextPrototype::createStructure(workerContextPrototype); + ProtectedPtr<JSDedicatedWorkerContextPrototype> dedicatedContextPrototype = new (m_globalData.get()) JSDedicatedWorkerContextPrototype(0, dedicatedContextPrototypeStructure.release()); + RefPtr<Structure> structure = JSDedicatedWorkerContext::createStructure(dedicatedContextPrototype); + + m_workerContextWrapper = new (m_globalData.get()) JSDedicatedWorkerContext(structure.release(), m_workerContext->toDedicatedWorkerContext()); + workerContextPrototype->putAnonymousValue(0, m_workerContextWrapper); + dedicatedContextPrototype->putAnonymousValue(0, m_workerContextWrapper); +#if ENABLE(SHARED_WORKERS) + } else { + ASSERT(m_workerContext->isSharedWorkerContext()); + RefPtr<Structure> sharedContextPrototypeStructure = JSSharedWorkerContextPrototype::createStructure(workerContextPrototype); + ProtectedPtr<JSSharedWorkerContextPrototype> sharedContextPrototype = new (m_globalData.get()) JSSharedWorkerContextPrototype(0, sharedContextPrototypeStructure.release()); + RefPtr<Structure> structure = JSSharedWorkerContext::createStructure(sharedContextPrototype); + + m_workerContextWrapper = new (m_globalData.get()) JSSharedWorkerContext(structure.release(), m_workerContext->toSharedWorkerContext()); + workerContextPrototype->putAnonymousValue(0, m_workerContextWrapper); + sharedContextPrototype->putAnonymousValue(0, m_workerContextWrapper); +#endif + } +} + +ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode) +{ + { + MutexLocker lock(m_sharedDataMutex); + if (m_executionForbidden) + return JSValue(); + } + ScriptValue exception; + ScriptValue result = evaluate(sourceCode, &exception); + if (exception.jsValue()) { + JSLock lock(SilenceAssertionsOnly); + reportException(m_workerContextWrapper->globalExec(), exception.jsValue()); + } + return result; +} + +ScriptValue WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, ScriptValue* exception) +{ + { + MutexLocker lock(m_sharedDataMutex); + if (m_executionForbidden) + return JSValue(); + } + + initScriptIfNeeded(); + JSLock lock(SilenceAssertionsOnly); + + ExecState* exec = m_workerContextWrapper->globalExec(); + m_workerContextWrapper->globalData().timeoutChecker.start(); + Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode.jsSourceCode(), m_workerContextWrapper); + m_workerContextWrapper->globalData().timeoutChecker.stop(); + + if (comp.complType() == Normal || comp.complType() == ReturnValue) + return comp.value(); + + if (comp.complType() == Throw) + *exception = comp.value(); + return JSValue(); +} + +void WorkerScriptController::setException(ScriptValue exception) +{ + throwError(m_workerContextWrapper->globalExec(), exception.jsValue()); +} + +void WorkerScriptController::forbidExecution(ForbidExecutionOption option) +{ + // This function may be called from another thread. + // Mutex protection for m_executionForbidden is needed to guarantee that the value is synchronized between processors, because + // if it were not, the worker could re-enter JSC::evaluate(), but with timeout already reset. + // It is not critical for Terminator::m_shouldTerminate to be synchronized, we just rely on it reaching the worker thread's processor sooner or later. + MutexLocker lock(m_sharedDataMutex); + m_executionForbidden = true; + if (option == TerminateRunningScript) + m_globalData->terminator.terminateSoon(); +} + +} // namespace WebCore + +#endif // ENABLE(WORKERS) diff --git a/Source/WebCore/bindings/js/WorkerScriptController.h b/Source/WebCore/bindings/js/WorkerScriptController.h new file mode 100644 index 0000000..be7da4d --- /dev/null +++ b/Source/WebCore/bindings/js/WorkerScriptController.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef WorkerScriptController_h +#define WorkerScriptController_h + +#if ENABLE(WORKERS) + +#include <runtime/Protect.h> +#include <wtf/Forward.h> +#include <wtf/Noncopyable.h> +#include <wtf/Threading.h> + +namespace JSC { + class JSGlobalData; +} + +namespace WebCore { + + class JSWorkerContext; + class ScriptSourceCode; + class ScriptValue; + class WorkerContext; + + class WorkerScriptController : public Noncopyable { + public: + WorkerScriptController(WorkerContext*); + ~WorkerScriptController(); + + JSWorkerContext* workerContextWrapper() + { + initScriptIfNeeded(); + return m_workerContextWrapper; + } + + ScriptValue evaluate(const ScriptSourceCode&); + ScriptValue evaluate(const ScriptSourceCode&, ScriptValue* exception); + + void setException(ScriptValue); + + enum ForbidExecutionOption { TerminateRunningScript, LetRunningScriptFinish }; + void forbidExecution(ForbidExecutionOption); + bool isExecutionForbidden() const { return m_executionForbidden; } + + JSC::JSGlobalData* globalData() { return m_globalData.get(); } + + private: + void initScriptIfNeeded() + { + if (!m_workerContextWrapper) + initScript(); + } + void initScript(); + + RefPtr<JSC::JSGlobalData> m_globalData; + WorkerContext* m_workerContext; + JSC::ProtectedPtr<JSWorkerContext> m_workerContextWrapper; + + Mutex m_sharedDataMutex; + bool m_executionForbidden; + }; + +} // namespace WebCore + +#endif // ENABLE(WORKERS) + +#endif // WorkerScriptController_h |