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.
26 #include "error_object.h"
28 #include "interpreter.h"
30 #include "operations.h"
31 #include "runtime_method.h"
32 #include "runtime_object.h"
40 using namespace Bindings;
42 const ClassInfo RuntimeObjectImp::info = {"RuntimeObject", 0, 0, 0};
44 RuntimeObjectImp::RuntimeObjectImp(ObjectImp *proto)
50 RuntimeObjectImp::~RuntimeObjectImp()
57 RuntimeObjectImp::RuntimeObjectImp(Bindings::Instance *i, bool oi) : ObjectImp ((ObjectImp *)0)
63 Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) const
65 Value result = Undefined();
69 Class *aClass = instance->getClass();
73 // See if the instance have a field with the specified name.
74 Field *aField = aClass->fieldNamed(propertyName.ascii(), instance);
76 result = instance->getValueOfField (exec, aField);
79 // Now check if a method with specified name exists, if so return a function object for
81 MethodList methodList = aClass->methodsNamed(propertyName.ascii(), instance);
82 if (methodList.length() > 0) {
83 result = Object (new RuntimeMethodImp(exec, propertyName, methodList));
87 if (result.type() == UndefinedType) {
88 // Try a fallback object.
89 result = aClass->fallbackObject (exec, instance, propertyName);
99 void RuntimeObjectImp::put(ExecState *exec, const Identifier &propertyName,
100 const Value &value, int attr)
104 // Set the value of the property.
105 Field *aField = instance->getClass()->fieldNamed(propertyName.ascii(), instance);
107 getInternalInstance()->setValueOfField(exec, aField, value);
110 getInternalInstance()->setValueOfUndefinedField(exec, propertyName, value);
116 bool RuntimeObjectImp::canPut(ExecState *exec, const Identifier &propertyName) const
120 Field *aField = instance->getClass()->fieldNamed(propertyName.ascii(), instance);
124 return aField ? true : false;
127 bool RuntimeObjectImp::hasProperty(ExecState *exec,
128 const Identifier &propertyName) const
132 Field *aField = instance->getClass()->fieldNamed(propertyName.ascii(), instance);
138 MethodList methodList = instance->getClass()->methodsNamed(propertyName.ascii(), instance);
142 if (methodList.length() > 0)
148 bool RuntimeObjectImp::deleteProperty(ExecState *exec,
149 const Identifier &propertyName)
151 // Can never remove a property of a RuntimeObject.
155 Value RuntimeObjectImp::defaultValue(ExecState *exec, Type hint) const
159 Value aValue = getInternalInstance()->defaultValue(hint);
166 bool RuntimeObjectImp::implementsCall() const
168 // Only true for default functions.
172 Value RuntimeObjectImp::call(ExecState *exec, Object &thisObj, const List &args)
176 Value aValue = getInternalInstance()->invokeDefaultMethod(exec, args);