/tags/Doduo/JavaScriptCore/kjs/JSFunction.h

https://github.com/weissms/owb-mirror · C Header · 166 lines · 106 code · 34 blank · 26 comment · 0 complexity · d96b12137e4f1eb79c70295da8aee6e7 MD5 · raw file

  1. // -*- c-basic-offset: 2 -*-
  2. /*
  3. * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  4. * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
  5. * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
  6. * Copyright (C) 2007 Maks Orlovich
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Library General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Library General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Library General Public License
  19. * along with this library; see the file COPYING.LIB. If not, write to
  20. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. *
  23. */
  24. #ifndef JSFunction_h
  25. #define JSFunction_h
  26. #include "JSVariableObject.h"
  27. #include "SymbolTable.h"
  28. #include "nodes.h"
  29. #include "JSObject.h"
  30. namespace KJS {
  31. class FunctionBodyNode;
  32. class FunctionPrototype;
  33. class JSActivation;
  34. class JSGlobalObject;
  35. class InternalFunction : public JSObject {
  36. public:
  37. static const ClassInfo info;
  38. virtual const ClassInfo* classInfo() const { return &info; }
  39. const Identifier& functionName() const { return m_name; }
  40. protected:
  41. InternalFunction();
  42. InternalFunction(FunctionPrototype*, const Identifier&);
  43. private:
  44. virtual CallType getCallData(CallData&) = 0;
  45. virtual bool implementsHasInstance() const;
  46. Identifier m_name;
  47. };
  48. class JSFunction : public InternalFunction {
  49. public:
  50. JSFunction(ExecState*, const Identifier&, FunctionBodyNode*, ScopeChainNode*);
  51. virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
  52. virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
  53. virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
  54. JSObject* construct(ExecState*, const ArgList&);
  55. JSValue* call(ExecState*, JSValue* thisValue, const ArgList&);
  56. // Note: Returns a null identifier for any parameters that will never get set
  57. // due to a later parameter with the same name.
  58. const Identifier& getParameterName(int index);
  59. static const ClassInfo info;
  60. RefPtr<FunctionBodyNode> body;
  61. void setScope(const ScopeChain& s) { _scope = s; }
  62. ScopeChain& scope() { return _scope; }
  63. virtual void mark();
  64. private:
  65. virtual const ClassInfo* classInfo() const { return &info; }
  66. virtual ConstructType getConstructData(ConstructData&);
  67. virtual CallType getCallData(CallData&);
  68. ScopeChain _scope;
  69. static JSValue* argumentsGetter(ExecState*, const Identifier&, const PropertySlot&);
  70. static JSValue* callerGetter(ExecState*, const Identifier&, const PropertySlot&);
  71. static JSValue* lengthGetter(ExecState*, const Identifier&, const PropertySlot&);
  72. };
  73. class IndexToNameMap {
  74. public:
  75. IndexToNameMap(JSFunction*, const ArgList&);
  76. ~IndexToNameMap();
  77. Identifier& operator[](const Identifier& index);
  78. bool isMapped(const Identifier& index) const;
  79. void unMap(ExecState* exec, const Identifier& index);
  80. private:
  81. unsigned size;
  82. Identifier* _map;
  83. };
  84. class Arguments : public JSObject {
  85. public:
  86. Arguments(ExecState*, JSFunction* func, const ArgList& args, JSActivation* act);
  87. virtual void mark();
  88. virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
  89. virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
  90. virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
  91. virtual const ClassInfo* classInfo() const { return &info; }
  92. static const ClassInfo info;
  93. private:
  94. static JSValue* mappedIndexGetter(ExecState*, const Identifier&, const PropertySlot& slot);
  95. JSActivation* _activationObject;
  96. mutable IndexToNameMap indexToNameMap;
  97. };
  98. class PrototypeFunction : public InternalFunction {
  99. public:
  100. PrototypeFunction(ExecState*, int len, const Identifier&, NativeFunction);
  101. PrototypeFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, NativeFunction);
  102. private:
  103. virtual CallType getCallData(CallData&);
  104. const NativeFunction m_function;
  105. };
  106. class GlobalEvalFunction : public PrototypeFunction {
  107. public:
  108. GlobalEvalFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, NativeFunction, JSGlobalObject* expectedThisObject);
  109. JSGlobalObject* cachedGlobalObject() const { return m_cachedGlobalObject; }
  110. private:
  111. virtual void mark();
  112. JSGlobalObject* m_cachedGlobalObject;
  113. };
  114. // Global Functions
  115. JSValue* globalFuncEval(ExecState*, JSObject*, JSValue*, const ArgList&);
  116. JSValue* globalFuncParseInt(ExecState*, JSObject*, JSValue*, const ArgList&);
  117. JSValue* globalFuncParseFloat(ExecState*, JSObject*, JSValue*, const ArgList&);
  118. JSValue* globalFuncIsNaN(ExecState*, JSObject*, JSValue*, const ArgList&);
  119. JSValue* globalFuncIsFinite(ExecState*, JSObject*, JSValue*, const ArgList&);
  120. JSValue* globalFuncDecodeURI(ExecState*, JSObject*, JSValue*, const ArgList&);
  121. JSValue* globalFuncDecodeURIComponent(ExecState*, JSObject*, JSValue*, const ArgList&);
  122. JSValue* globalFuncEncodeURI(ExecState*, JSObject*, JSValue*, const ArgList&);
  123. JSValue* globalFuncEncodeURIComponent(ExecState*, JSObject*, JSValue*, const ArgList&);
  124. JSValue* globalFuncEscape(ExecState*, JSObject*, JSValue*, const ArgList&);
  125. JSValue* globalFuncUnescape(ExecState*, JSObject*, JSValue*, const ArgList&);
  126. #ifndef NDEBUG
  127. JSValue* globalFuncKJSPrint(ExecState*, JSObject*, JSValue*, const ArgList&);
  128. #endif
  129. static const double mantissaOverflowLowerBound = 9007199254740992.0;
  130. double parseIntOverflow(const char*, int length, int radix);
  131. } // namespace
  132. #endif