/platform/external/webkit/WebCore/bridge/jsc/BridgeJSC.h

https://github.com/aharish/totoro-gb-opensource-update2 · C Header · 151 lines · 83 code · 39 blank · 29 comment · 0 complexity · 614a9991330856dfa5f2cb96fe41341f MD5 · raw file

  1. /*
  2. * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved.
  3. * Copyright 2010, The Android Open Source Project
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef BridgeJSC_h
  27. #define BridgeJSC_h
  28. #if USE(JSC)
  29. #include <runtime/JSString.h>
  30. #include <wtf/HashMap.h>
  31. #include <wtf/RefCounted.h>
  32. #include <wtf/Vector.h>
  33. namespace JSC {
  34. class ArgList;
  35. class Identifier;
  36. class JSGlobalObject;
  37. class PropertyNameArray;
  38. class RuntimeObjectImp;
  39. namespace Bindings {
  40. class Instance;
  41. class Method;
  42. class RootObject;
  43. typedef Vector<Method*> MethodList;
  44. class Field {
  45. public:
  46. virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0;
  47. virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const = 0;
  48. virtual ~Field() { }
  49. };
  50. class Class : public Noncopyable {
  51. public:
  52. virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0;
  53. virtual Field* fieldNamed(const Identifier&, Instance*) const = 0;
  54. virtual JSValue fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); }
  55. virtual ~Class() { }
  56. };
  57. typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject);
  58. class Instance : public RefCounted<Instance> {
  59. public:
  60. Instance(PassRefPtr<RootObject>);
  61. static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func);
  62. static KJSDidExecuteFunctionPtr didExecuteFunction();
  63. // These functions are called before and after the main entry points into
  64. // the native implementations. They can be used to establish and cleanup
  65. // any needed state.
  66. void begin();
  67. void end();
  68. virtual Class* getClass() const = 0;
  69. RuntimeObjectImp* createRuntimeObject(ExecState*);
  70. void willInvalidateRuntimeObject();
  71. void willDestroyRuntimeObject();
  72. // Returns false if the value was not set successfully.
  73. virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; }
  74. virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args) = 0;
  75. virtual bool supportsInvokeDefaultMethod() const { return false; }
  76. virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); }
  77. virtual bool supportsConstruct() const { return false; }
  78. virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); }
  79. virtual void getPropertyNames(ExecState*, PropertyNameArray&) { }
  80. virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0;
  81. virtual JSValue valueOf(ExecState* exec) const = 0;
  82. RootObject* rootObject() const;
  83. virtual ~Instance();
  84. virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&) { return false; }
  85. virtual bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&) { return false; }
  86. virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&) { }
  87. protected:
  88. virtual void virtualBegin() { }
  89. virtual void virtualEnd() { }
  90. virtual RuntimeObjectImp* newRuntimeObject(ExecState*);
  91. RefPtr<RootObject> m_rootObject;
  92. private:
  93. RuntimeObjectImp* m_runtimeObject;
  94. };
  95. class Array : public Noncopyable {
  96. public:
  97. Array(PassRefPtr<RootObject>);
  98. virtual ~Array();
  99. virtual void setValueAt(ExecState*, unsigned index, JSValue) const = 0;
  100. virtual JSValue valueAt(ExecState*, unsigned index) const = 0;
  101. virtual unsigned int getLength() const = 0;
  102. protected:
  103. RefPtr<RootObject> m_rootObject;
  104. };
  105. const char* signatureForParameters(const ArgList&);
  106. typedef HashMap<RefPtr<UString::Rep>, MethodList*> MethodListMap;
  107. typedef HashMap<RefPtr<UString::Rep>, Method*> MethodMap;
  108. typedef HashMap<RefPtr<UString::Rep>, Field*> FieldMap;
  109. } // namespace Bindings
  110. } // namespace JSC
  111. #endif // USE(JSC)
  112. #endif