• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "JSDOMWindowBase.h"
31 #include "runtime_object.h"
32 #include "runtime_root.h"
33 #include "runtime/JSLock.h"
34 #include "runtime/ObjectPrototype.h"
35 
36 
37 #if PLATFORM(QT)
38 #include "qt_instance.h"
39 #endif
40 
41 namespace JSC {
42 
43 namespace Bindings {
44 
Array(PassRefPtr<RootObject> rootObject)45 Array::Array(PassRefPtr<RootObject> rootObject)
46     : m_rootObject(rootObject)
47 {
48     ASSERT(m_rootObject);
49 }
50 
~Array()51 Array::~Array()
52 {
53 }
54 
Instance(PassRefPtr<RootObject> rootObject)55 Instance::Instance(PassRefPtr<RootObject> rootObject)
56     : m_rootObject(rootObject)
57     , m_runtimeObject(*WebCore::JSDOMWindowBase::commonJSGlobalData())
58 {
59     ASSERT(m_rootObject);
60 }
61 
~Instance()62 Instance::~Instance()
63 {
64     ASSERT(!m_runtimeObject);
65 }
66 
67 static KJSDidExecuteFunctionPtr s_didExecuteFunction;
68 
setDidExecuteFunction(KJSDidExecuteFunctionPtr func)69 void Instance::setDidExecuteFunction(KJSDidExecuteFunctionPtr func)
70 {
71     s_didExecuteFunction = func;
72 }
73 
didExecuteFunction()74 KJSDidExecuteFunctionPtr Instance::didExecuteFunction()
75 {
76     return s_didExecuteFunction;
77 }
78 
begin()79 void Instance::begin()
80 {
81     virtualBegin();
82 }
83 
end()84 void Instance::end()
85 {
86     virtualEnd();
87 }
88 
createRuntimeObject(ExecState * exec)89 JSObject* Instance::createRuntimeObject(ExecState* exec)
90 {
91     ASSERT(m_rootObject);
92     ASSERT(m_rootObject->isValid());
93     if (RuntimeObject* existingObject = m_runtimeObject.get())
94         return existingObject;
95 
96     JSLock lock(SilenceAssertionsOnly);
97     RuntimeObject* newObject = newRuntimeObject(exec);
98     m_runtimeObject.set(exec->globalData(), newObject, 0);
99     m_rootObject->addRuntimeObject(exec->globalData(), newObject);
100     return newObject;
101 }
102 
newRuntimeObject(ExecState * exec)103 RuntimeObject* Instance::newRuntimeObject(ExecState* exec)
104 {
105     JSLock lock(SilenceAssertionsOnly);
106 
107     // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
108     // We need to pass in the right global object for "i".
109     return new (exec) RuntimeObject(exec, exec->lexicalGlobalObject(), WebCore::deprecatedGetDOMStructure<RuntimeObject>(exec), this);
110 }
111 
willInvalidateRuntimeObject()112 void Instance::willInvalidateRuntimeObject()
113 {
114     m_runtimeObject.clear();
115 }
116 
rootObject() const117 RootObject* Instance::rootObject() const
118 {
119     return m_rootObject && m_rootObject->isValid() ? m_rootObject.get() : 0;
120 }
121 
122 } // namespace Bindings
123 
124 } // namespace JSC
125