1 /* 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright 2010, The Android Open Source Project 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include "config.h" 28 #include "BridgeJSC.h" 29 30 #include "runtime_object.h" 31 #include "runtime_root.h" 32 #include <runtime/JSLock.h> 33 34 #if PLATFORM(QT) 35 #include "qt_instance.h" 36 #endif 37 38 namespace JSC { 39 40 namespace Bindings { 41 42 Array::Array(PassRefPtr<RootObject> rootObject) 43 : m_rootObject(rootObject) 44 { 45 ASSERT(m_rootObject); 46 } 47 48 Array::~Array() 49 { 50 } 51 52 Instance::Instance(PassRefPtr<RootObject> rootObject) 53 : m_rootObject(rootObject) 54 , m_runtimeObject(0) 55 { 56 ASSERT(m_rootObject); 57 } 58 59 Instance::~Instance() 60 { 61 ASSERT(!m_runtimeObject); 62 } 63 64 static KJSDidExecuteFunctionPtr s_didExecuteFunction; 65 66 void Instance::setDidExecuteFunction(KJSDidExecuteFunctionPtr func) 67 { 68 s_didExecuteFunction = func; 69 } 70 71 KJSDidExecuteFunctionPtr Instance::didExecuteFunction() 72 { 73 return s_didExecuteFunction; 74 } 75 76 void Instance::begin() 77 { 78 virtualBegin(); 79 } 80 81 void Instance::end() 82 { 83 virtualEnd(); 84 } 85 86 RuntimeObjectImp* Instance::createRuntimeObject(ExecState* exec) 87 { 88 ASSERT(m_rootObject); 89 ASSERT(m_rootObject->isValid()); 90 if (m_runtimeObject) 91 return m_runtimeObject; 92 JSLock lock(SilenceAssertionsOnly); 93 m_runtimeObject = newRuntimeObject(exec); 94 m_rootObject->addRuntimeObject(m_runtimeObject); 95 return m_runtimeObject; 96 } 97 98 RuntimeObjectImp* Instance::newRuntimeObject(ExecState* exec) 99 { 100 JSLock lock(SilenceAssertionsOnly); 101 return new (exec)RuntimeObjectImp(exec, this); 102 } 103 104 void Instance::willDestroyRuntimeObject() 105 { 106 ASSERT(m_rootObject); 107 ASSERT(m_rootObject->isValid()); 108 ASSERT(m_runtimeObject); 109 m_rootObject->removeRuntimeObject(m_runtimeObject); 110 m_runtimeObject = 0; 111 } 112 113 void Instance::willInvalidateRuntimeObject() 114 { 115 ASSERT(m_runtimeObject); 116 m_runtimeObject = 0; 117 } 118 119 RootObject* Instance::rootObject() const 120 { 121 return m_rootObject && m_rootObject->isValid() ? m_rootObject.get() : 0; 122 } 123 124 } // namespace Bindings 125 126 } // namespace JSC 127