rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 26 | #include "config.h" |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 27 | #include "context.h" |
| 28 | #include "internal.h" |
| 29 | #include "runtime_method.h" |
| 30 | #include "runtime_object.h" |
| 31 | |
rjw | 139d4bb | 2003-12-18 02:49:17 +0000 | [diff] [blame] | 32 | using namespace KJS::Bindings; |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 33 | using namespace KJS; |
| 34 | |
rjw | da8be65 | 2004-02-13 22:39:36 +0000 | [diff] [blame] | 35 | RuntimeMethodImp::RuntimeMethodImp(ExecState *exec, const Identifier &ident, Bindings::MethodList &m) : FunctionImp (exec, ident) |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 36 | { |
rjw | dad1fca | 2004-01-16 23:23:04 +0000 | [diff] [blame] | 37 | _methodList = m; |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | RuntimeMethodImp::~RuntimeMethodImp() |
| 41 | { |
| 42 | } |
| 43 | |
darin | c13d2ca | 2005-08-08 04:07:46 +0000 | [diff] [blame] | 44 | ValueImp *RuntimeMethodImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot& slot) |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 45 | { |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 46 | 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 | |
| 57 | bool RuntimeMethodImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot) |
| 58 | { |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 59 | if (propertyName == lengthPropertyName) { |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 60 | slot.setCustom(this, lengthGetter); |
| 61 | return true; |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 62 | } |
| 63 | |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 64 | return FunctionImp::getOwnPropertySlot(exec, propertyName, slot); |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | bool RuntimeMethodImp::implementsCall() const |
| 68 | { |
| 69 | return true; |
| 70 | } |
| 71 | |
darin | c13d2ca | 2005-08-08 04:07:46 +0000 | [diff] [blame] | 72 | ValueImp *RuntimeMethodImp::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args) |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 73 | { |
rjw | da8be65 | 2004-02-13 22:39:36 +0000 | [diff] [blame] | 74 | if (_methodList.length() > 0) { |
rjw | 5ab21df | 2005-01-29 00:13:35 +0000 | [diff] [blame] | 75 | RuntimeObjectImp *imp; |
| 76 | |
| 77 | // If thisObj is the DOM object for a plugin, get the corresponding |
| 78 | // runtime object from the DOM object. |
darin | c13d2ca | 2005-08-08 04:07:46 +0000 | [diff] [blame] | 79 | if (thisObj->classInfo() != &KJS::RuntimeObjectImp::info) { |
| 80 | ValueImp *runtimeObject = thisObj->get(exec, "__apple_runtime_object"); |
| 81 | imp = static_cast<RuntimeObjectImp*>(runtimeObject); |
rjw | 5ab21df | 2005-01-29 00:13:35 +0000 | [diff] [blame] | 82 | } |
| 83 | else { |
darin | c13d2ca | 2005-08-08 04:07:46 +0000 | [diff] [blame] | 84 | imp = static_cast<RuntimeObjectImp*>(thisObj); |
rjw | 5ab21df | 2005-01-29 00:13:35 +0000 | [diff] [blame] | 85 | } |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 86 | if (imp) { |
rjw | f57d1fd | 2004-01-16 18:59:26 +0000 | [diff] [blame] | 87 | Instance *instance = imp->getInternalInstance(); |
| 88 | |
| 89 | instance->begin(); |
| 90 | |
darin | c13d2ca | 2005-08-08 04:07:46 +0000 | [diff] [blame] | 91 | ValueImp *aValue = instance->invokeMethod(exec, _methodList, args); |
rjw | f57d1fd | 2004-01-16 18:59:26 +0000 | [diff] [blame] | 92 | |
| 93 | instance->end(); |
| 94 | |
| 95 | return aValue; |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | return Undefined(); |
| 100 | } |
| 101 | |
| 102 | CodeType RuntimeMethodImp::codeType() const |
| 103 | { |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 104 | return FunctionCode; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | Completion RuntimeMethodImp::execute(ExecState *exec) |
| 109 | { |
rjw | 48ebf26 | 2003-12-03 01:21:39 +0000 | [diff] [blame] | 110 | return Completion(Normal, Undefined()); |
| 111 | } |
| 112 | |