webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
runtime_array.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003, 2008 Apple 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 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 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 
26 #ifndef RUNTIME_ARRAY_H_
27 #define RUNTIME_ARRAY_H_
28 
29 #include "BridgeJSC.h"
30 #include "JSDOMBinding.h"
31 #include <runtime/ArrayPrototype.h>
32 
33 namespace JSC {
34 
35 class RuntimeArray : public JSArray {
36 public:
37  typedef JSArray Base;
38  static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | OverridesGetPropertyNames;
39 
41  {
42  // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
43  // We need to pass in the right global object for "array".
44  Structure* domStructure = WebCore::deprecatedGetDOMStructure<RuntimeArray>(exec);
45  RuntimeArray* runtimeArray = new (NotNull, allocateCell<RuntimeArray>(*exec->heap())) RuntimeArray(exec, domStructure);
46  runtimeArray->finishCreation(exec->vm(), array);
47  exec->vm().heap.addFinalizer(runtimeArray, destroy);
48  return runtimeArray;
49  }
50 
52  ~RuntimeArray();
53  static void destroy(JSCell*);
54  static const bool needsDestruction = false;
55 
58  static bool getOwnPropertySlotByIndex(JSObject*, ExecState*, unsigned, PropertySlot&);
60  static bool putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
61 
63  static bool deletePropertyByIndex(JSCell*, ExecState*, unsigned propertyName);
64 
65  unsigned getLength() const { return m_array->getLength(); }
66 
67  Bindings::Array* getConcreteArray() const { return m_array; }
68 
70 
72  {
73  return globalObject->arrayPrototype();
74  }
75 
77  {
78  return Structure::create(vm, globalObject, prototype, TypeInfo(DerivedArrayType, StructureFlags), info(), ArrayClass);
79  }
80 
81 protected:
83 
84 private:
86  static EncodedJSValue lengthGetter(ExecState*, EncodedJSValue, PropertyName);
87 
88  BindingsArray* m_array;
89 };
90 
91 } // namespace JSC
92 
93 #endif // RUNTIME_ARRAY_H_
JSArray Base
Definition: runtime_array.h:37
VM * vm() const
Definition: HeapCellInlines.h:63
static Structure * createStructure(VM &vm, JSGlobalObject *globalObject, JSValue prototype)
Definition: runtime_array.h:76
Definition: PropertyNameArray.h:48
Definition: JSCell.h:71
static const unsigned StructureFlags
Definition: runtime_array.h:38
DECLARE_INFO
Definition: runtime_array.h:69
JS_EXPORT_PRIVATE void addFinalizer(JSCell *, Finalizer)
Definition: Heap.cpp:2222
Definition: AirOpcode.h:4
static bool deletePropertyByIndex(JSCell *, ExecState *, unsigned propertyName)
Definition: runtime_array.cpp:154
~RuntimeArray()
Definition: runtime_array.cpp:53
def info(msg, args, kwargs)
Definition: __init__.py:1165
Definition: CallFrame.h:85
CFArrayRef array
Definition: AVFoundationCFSoftLinking.h:129
ArrayPrototype * arrayPrototype() const
Definition: JSGlobalObject.h:528
Definition: PropertySlot.h:74
Definition: ArrayPrototype.h:30
Definition: StdLibExtras.h:414
static void destroy(JSCell *)
Definition: runtime_array.cpp:58
static bool put(JSCell *, ExecState *, PropertyName, JSValue, PutPropertySlot &)
Definition: runtime_array.cpp:117
Definition: JSTypeInfo.h:55
Definition: Structure.h:128
Definition: JSObject.h:92
unsigned getLength() const
Definition: runtime_array.h:65
static const bool needsDestruction
Definition: runtime_array.h:54
static const unsigned StructureFlags
Definition: JSArray.h:40
Definition: VM.h:246
Definition: JSGlobalObject.h:205
Bindings::Array * getConcreteArray() const
Definition: runtime_array.h:67
Heap * heap()
Definition: CallFrame.h:124
static RuntimeArray * create(ExecState *exec, Bindings::Array *array)
Definition: runtime_array.h:40
static ArrayPrototype * createPrototype(VM &, JSGlobalObject *globalObject)
Definition: runtime_array.h:71
Definition: JSType.h:70
static Structure * create(VM &, JSGlobalObject *, JSValue prototype, const TypeInfo &, const ClassInfo *, IndexingType=NonArray, unsigned inlineCapacity=0)
Definition: StructureInlines.h:37
JSGlobalObject * globalObject() const
Definition: JSObject.h:770
static bool getOwnPropertySlot(JSObject *, ExecState *, PropertyName, PropertySlot &)
Definition: runtime_array.cpp:87
VM & vm() const
Definition: JSCellInlines.h:127
Bindings::Array BindingsArray
Definition: runtime_array.h:51
Definition: JSCJSValue.h:129
static bool deleteProperty(JSCell *, ExecState *, PropertyName)
Definition: runtime_array.cpp:149
Heap heap
Definition: VM.h:295
Definition: BridgeJSC.h:121
Definition: JSArray.h:33
int64_t EncodedJSValue
Definition: JSCJSValue.h:81
Definition: PropertyName.h:34
Definition: EnumerationMode.h:46
static bool getOwnPropertySlotByIndex(JSObject *, ExecState *, unsigned, PropertySlot &)
Definition: runtime_array.cpp:105
void finishCreation(VM &, Bindings::Array *)
Definition: runtime_array.cpp:46
virtual unsigned int getLength() const =0
static void getOwnPropertyNames(JSObject *, ExecState *, PropertyNameArray &, EnumerationMode)
Definition: runtime_array.cpp:74
Definition: PutPropertySlot.h:37
Definition: runtime_array.h:35
static bool putByIndex(JSCell *, ExecState *, unsigned propertyName, JSValue, bool shouldThrow)
Definition: runtime_array.cpp:135