PageRenderTime 19ms CodeModel.GetById 5ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 27#ifndef BridgeJSC_h
 28#define BridgeJSC_h
 29
 30#if USE(JSC)
 31
 32#include <runtime/JSString.h>
 33#include <wtf/HashMap.h>
 34#include <wtf/RefCounted.h>
 35#include <wtf/Vector.h>
 36
 37namespace JSC  {
 38
 39class ArgList;
 40class Identifier;
 41class JSGlobalObject;
 42class PropertyNameArray;
 43class RuntimeObjectImp;
 44
 45namespace Bindings {
 46
 47class Instance;
 48class Method;
 49class RootObject;
 50
 51typedef Vector<Method*> MethodList;
 52
 53class Field {
 54public:
 55    virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0;
 56    virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const = 0;
 57
 58    virtual ~Field() { }
 59};
 60
 61class Class : public Noncopyable {
 62public:
 63    virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0;
 64    virtual Field* fieldNamed(const Identifier&, Instance*) const = 0;
 65    virtual JSValue fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); }
 66
 67    virtual ~Class() { }
 68};
 69
 70typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject);
 71
 72class Instance : public RefCounted<Instance> {
 73public:
 74    Instance(PassRefPtr<RootObject>);
 75
 76    static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func);
 77    static KJSDidExecuteFunctionPtr didExecuteFunction();
 78
 79    // These functions are called before and after the main entry points into
 80    // the native implementations.  They can be used to establish and cleanup
 81    // any needed state.
 82    void begin();
 83    void end();
 84
 85    virtual Class* getClass() const = 0;
 86    RuntimeObjectImp* createRuntimeObject(ExecState*);
 87    void willInvalidateRuntimeObject();
 88    void willDestroyRuntimeObject();
 89
 90    // Returns false if the value was not set successfully.
 91    virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; }
 92
 93    virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args) = 0;
 94
 95    virtual bool supportsInvokeDefaultMethod() const { return false; }
 96    virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); }
 97
 98    virtual bool supportsConstruct() const { return false; }
 99    virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); }
100
101    virtual void getPropertyNames(ExecState*, PropertyNameArray&) { }
102
103    virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0;
104
105    virtual JSValue valueOf(ExecState* exec) const = 0;
106
107    RootObject* rootObject() const;
108
109    virtual ~Instance();
110
111    virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&) { return false; }
112    virtual bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&) { return false; }
113    virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&) { }
114
115protected:
116    virtual void virtualBegin() { }
117    virtual void virtualEnd() { }
118    virtual RuntimeObjectImp* newRuntimeObject(ExecState*);
119
120    RefPtr<RootObject> m_rootObject;
121
122private:
123    RuntimeObjectImp* m_runtimeObject;
124};
125
126class Array : public Noncopyable {
127public:
128    Array(PassRefPtr<RootObject>);
129    virtual ~Array();
130
131    virtual void setValueAt(ExecState*, unsigned index, JSValue) const = 0;
132    virtual JSValue valueAt(ExecState*, unsigned index) const = 0;
133    virtual unsigned int getLength() const = 0;
134
135protected:
136    RefPtr<RootObject> m_rootObject;
137};
138
139const char* signatureForParameters(const ArgList&);
140
141typedef HashMap<RefPtr<UString::Rep>, MethodList*> MethodListMap;
142typedef HashMap<RefPtr<UString::Rep>, Method*> MethodMap;
143typedef HashMap<RefPtr<UString::Rep>, Field*> FieldMap;
144
145} // namespace Bindings
146
147} // namespace JSC
148
149#endif // USE(JSC)
150
151#endif