blob: 46dbcb39f73dfdb7c8fc09a7adf0e9de70abe8d0 [file] [log] [blame]
rjw48ebf262003-12-03 01:21:39 +00001/*
2 * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
mjsb64c50a2005-10-03 21:13:12 +000026#include "config.h"
rjw48ebf262003-12-03 01:21:39 +000027#include "context.h"
28#include "internal.h"
29#include "runtime_method.h"
30#include "runtime_object.h"
31
rjw139d4bb2003-12-18 02:49:17 +000032using namespace KJS::Bindings;
rjw48ebf262003-12-03 01:21:39 +000033using namespace KJS;
34
rjwda8be652004-02-13 22:39:36 +000035RuntimeMethodImp::RuntimeMethodImp(ExecState *exec, const Identifier &ident, Bindings::MethodList &m) : FunctionImp (exec, ident)
rjw48ebf262003-12-03 01:21:39 +000036{
rjwdad1fca2004-01-16 23:23:04 +000037 _methodList = m;
rjw48ebf262003-12-03 01:21:39 +000038}
39
40RuntimeMethodImp::~RuntimeMethodImp()
41{
42}
43
darinc13d2ca2005-08-08 04:07:46 +000044ValueImp *RuntimeMethodImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot)
rjw48ebf262003-12-03 01:21:39 +000045{
mjs70d74212005-08-07 06:17:49 +000046 RuntimeMethodImp *thisObj = static_cast<RuntimeMethodImp *>(slot.slotBase());
47
48 // Ick! There may be more than one method with this name. Arbitrarily
49 // just pick the first method. The fundamental problem here is that
50 // JavaScript doesn't have the notion of method overloading and
51 // Java does.
52 // FIXME: a better solution might be to give the maximum number of parameters
53 // of any method
54 return Number(thisObj->_methodList.methodAt(0)->numParameters());
55}
56
57bool RuntimeMethodImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
58{
rjw48ebf262003-12-03 01:21:39 +000059 if (propertyName == lengthPropertyName) {
mjs70d74212005-08-07 06:17:49 +000060 slot.setCustom(this, lengthGetter);
61 return true;
rjw48ebf262003-12-03 01:21:39 +000062 }
63
mjs70d74212005-08-07 06:17:49 +000064 return FunctionImp::getOwnPropertySlot(exec, propertyName, slot);
rjw48ebf262003-12-03 01:21:39 +000065}
66
67bool RuntimeMethodImp::implementsCall() const
68{
69 return true;
70}
71
darinc13d2ca2005-08-08 04:07:46 +000072ValueImp *RuntimeMethodImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args)
rjw48ebf262003-12-03 01:21:39 +000073{
rjwda8be652004-02-13 22:39:36 +000074 if (_methodList.length() > 0) {
rjw5ab21df2005-01-29 00:13:35 +000075 RuntimeObjectImp *imp;
76
77 // If thisObj is the DOM object for a plugin, get the corresponding
78 // runtime object from the DOM object.
darinc13d2ca2005-08-08 04:07:46 +000079 if (thisObj->classInfo() != &KJS::RuntimeObjectImp::info) {
80 ValueImp *runtimeObject = thisObj->get(exec, "__apple_runtime_object");
81 imp = static_cast<RuntimeObjectImp*>(runtimeObject);
rjw5ab21df2005-01-29 00:13:35 +000082 }
83 else {
darinc13d2ca2005-08-08 04:07:46 +000084 imp = static_cast<RuntimeObjectImp*>(thisObj);
rjw5ab21df2005-01-29 00:13:35 +000085 }
rjw48ebf262003-12-03 01:21:39 +000086 if (imp) {
rjwf57d1fd2004-01-16 18:59:26 +000087 Instance *instance = imp->getInternalInstance();
88
89 instance->begin();
90
darinc13d2ca2005-08-08 04:07:46 +000091 ValueImp *aValue = instance->invokeMethod(exec, _methodList, args);
rjwf57d1fd2004-01-16 18:59:26 +000092
93 instance->end();
94
95 return aValue;
rjw48ebf262003-12-03 01:21:39 +000096 }
97 }
98
99 return Undefined();
100}
101
102CodeType RuntimeMethodImp::codeType() const
103{
rjw48ebf262003-12-03 01:21:39 +0000104 return FunctionCode;
105}
106
107
108Completion RuntimeMethodImp::execute(ExecState *exec)
109{
rjw48ebf262003-12-03 01:21:39 +0000110 return Completion(Normal, Undefined());
111}
112