]>
git.saurik.com Git - apple/javascriptcore.git/blob - bindings/runtime_object.cpp
c2cb3e86b8a06f5bf85575fe21cc73a9e8798d27
2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "runtime_object.h"
29 #include "error_object.h"
30 #include "operations.h"
31 #include "runtime_method.h"
32 #include "runtime_root.h"
35 using namespace Bindings
;
37 const ClassInfo
RuntimeObjectImp::info
= { "RuntimeObject", 0, 0 };
39 RuntimeObjectImp::RuntimeObjectImp(Bindings::Instance
*i
)
42 instance
->rootObject()->addRuntimeObject(this);
45 RuntimeObjectImp::~RuntimeObjectImp()
48 instance
->rootObject()->removeRuntimeObject(this);
51 void RuntimeObjectImp::invalidate()
57 JSValue
*RuntimeObjectImp::fallbackObjectGetter(ExecState
* exec
, JSObject
*, const Identifier
& propertyName
, const PropertySlot
& slot
)
59 RuntimeObjectImp
*thisObj
= static_cast<RuntimeObjectImp
*>(slot
.slotBase());
60 RefPtr
<Bindings::Instance
> instance
= thisObj
->instance
;
63 return throwInvalidAccessError(exec
);
67 Class
*aClass
= instance
->getClass();
68 JSValue
* result
= aClass
->fallbackObject(exec
, instance
.get(), propertyName
);
75 JSValue
*RuntimeObjectImp::fieldGetter(ExecState
* exec
, JSObject
*, const Identifier
& propertyName
, const PropertySlot
& slot
)
77 RuntimeObjectImp
*thisObj
= static_cast<RuntimeObjectImp
*>(slot
.slotBase());
78 RefPtr
<Bindings::Instance
> instance
= thisObj
->instance
;
81 return throwInvalidAccessError(exec
);
85 Class
*aClass
= instance
->getClass();
86 Field
* aField
= aClass
->fieldNamed(propertyName
, instance
.get());
87 JSValue
*result
= instance
->getValueOfField(exec
, aField
);
94 JSValue
*RuntimeObjectImp::methodGetter(ExecState
* exec
, JSObject
*, const Identifier
& propertyName
, const PropertySlot
& slot
)
96 RuntimeObjectImp
*thisObj
= static_cast<RuntimeObjectImp
*>(slot
.slotBase());
97 RefPtr
<Bindings::Instance
> instance
= thisObj
->instance
;
100 return throwInvalidAccessError(exec
);
104 Class
*aClass
= instance
->getClass();
105 MethodList methodList
= aClass
->methodsNamed(propertyName
, instance
.get());
106 JSValue
*result
= new RuntimeMethod(exec
, propertyName
, methodList
);
113 bool RuntimeObjectImp::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
116 throwInvalidAccessError(exec
);
122 Class
*aClass
= instance
->getClass();
125 // See if the instance has a field with the specified name.
126 Field
*aField
= aClass
->fieldNamed(propertyName
, instance
.get());
128 slot
.setCustom(this, fieldGetter
);
132 // Now check if a method with specified name exists, if so return a function object for
134 MethodList methodList
= aClass
->methodsNamed(propertyName
, instance
.get());
135 if (methodList
.size() > 0) {
136 slot
.setCustom(this, methodGetter
);
143 // Try a fallback object.
144 if (!aClass
->fallbackObject(exec
, instance
.get(), propertyName
)->isUndefined()) {
145 slot
.setCustom(this, fallbackObjectGetter
);
153 // don't call superclass, because runtime objects can't have custom properties or a prototype
157 void RuntimeObjectImp::put(ExecState
* exec
, const Identifier
& propertyName
, JSValue
* value
, int)
160 throwInvalidAccessError(exec
);
164 RefPtr
<Bindings::Instance
> protector(instance
);
167 // Set the value of the property.
168 Field
*aField
= instance
->getClass()->fieldNamed(propertyName
, instance
.get());
170 instance
->setValueOfField(exec
, aField
, value
);
171 else if (instance
->supportsSetValueOfUndefinedField())
172 instance
->setValueOfUndefinedField(exec
, propertyName
, value
);
177 bool RuntimeObjectImp::canPut(ExecState
* exec
, const Identifier
& propertyName
) const
180 throwInvalidAccessError(exec
);
186 Field
*aField
= instance
->getClass()->fieldNamed(propertyName
, instance
.get());
193 bool RuntimeObjectImp::deleteProperty(ExecState
*, const Identifier
&)
195 // Can never remove a property of a RuntimeObject.
199 JSValue
*RuntimeObjectImp::defaultValue(ExecState
* exec
, JSType hint
) const
202 return throwInvalidAccessError(exec
);
206 RefPtr
<Bindings::Instance
> protector(instance
);
209 result
= instance
->defaultValue(hint
);
216 bool RuntimeObjectImp::implementsCall() const
221 return instance
->implementsCall();
224 JSValue
*RuntimeObjectImp::callAsFunction(ExecState
* exec
, JSObject
*, const List
& args
)
227 return throwInvalidAccessError(exec
);
229 RefPtr
<Bindings::Instance
> protector(instance
);
232 JSValue
*aValue
= instance
->invokeDefaultMethod(exec
, args
);
239 void RuntimeObjectImp::getPropertyNames(ExecState
* exec
, PropertyNameArray
& propertyNames
)
242 throwInvalidAccessError(exec
);
247 instance
->getPropertyNames(exec
, propertyNames
);
251 JSObject
* RuntimeObjectImp::throwInvalidAccessError(ExecState
* exec
)
253 return throwError(exec
, ReferenceError
, "Trying to access object from destroyed plug-in.");