Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* JS Array interface. */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef jsarray_h |
michael@0 | 10 | #define jsarray_h |
michael@0 | 11 | |
michael@0 | 12 | #include "jsobj.h" |
michael@0 | 13 | #include "jspubtd.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace js { |
michael@0 | 16 | /* 2^32-2, inclusive */ |
michael@0 | 17 | const uint32_t MAX_ARRAY_INDEX = 4294967294u; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | inline bool |
michael@0 | 21 | js_IdIsIndex(jsid id, uint32_t *indexp) |
michael@0 | 22 | { |
michael@0 | 23 | if (JSID_IS_INT(id)) { |
michael@0 | 24 | int32_t i = JSID_TO_INT(id); |
michael@0 | 25 | JS_ASSERT(i >= 0); |
michael@0 | 26 | *indexp = (uint32_t)i; |
michael@0 | 27 | return true; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | if (MOZ_UNLIKELY(!JSID_IS_STRING(id))) |
michael@0 | 31 | return false; |
michael@0 | 32 | |
michael@0 | 33 | return js::StringIsArrayIndex(JSID_TO_ATOM(id), indexp); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | extern JSObject * |
michael@0 | 37 | js_InitArrayClass(JSContext *cx, js::HandleObject obj); |
michael@0 | 38 | |
michael@0 | 39 | extern bool |
michael@0 | 40 | js_InitContextBusyArrayTable(JSContext *cx); |
michael@0 | 41 | |
michael@0 | 42 | namespace js { |
michael@0 | 43 | |
michael@0 | 44 | class ArrayObject; |
michael@0 | 45 | |
michael@0 | 46 | /* Create a dense array with no capacity allocated, length set to 0. */ |
michael@0 | 47 | extern ArrayObject * JS_FASTCALL |
michael@0 | 48 | NewDenseEmptyArray(JSContext *cx, JSObject *proto = nullptr, |
michael@0 | 49 | NewObjectKind newKind = GenericObject); |
michael@0 | 50 | |
michael@0 | 51 | /* Create a dense array with length and capacity == 'length', initialized length set to 0. */ |
michael@0 | 52 | extern ArrayObject * JS_FASTCALL |
michael@0 | 53 | NewDenseAllocatedArray(ExclusiveContext *cx, uint32_t length, JSObject *proto = nullptr, |
michael@0 | 54 | NewObjectKind newKind = GenericObject); |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * Create a dense array with a set length, but without allocating space for the |
michael@0 | 58 | * contents. This is useful, e.g., when accepting length from the user. |
michael@0 | 59 | */ |
michael@0 | 60 | extern ArrayObject * JS_FASTCALL |
michael@0 | 61 | NewDenseUnallocatedArray(ExclusiveContext *cx, uint32_t length, JSObject *proto = nullptr, |
michael@0 | 62 | NewObjectKind newKind = GenericObject); |
michael@0 | 63 | |
michael@0 | 64 | /* Create a dense array with a copy of the dense array elements in src. */ |
michael@0 | 65 | extern ArrayObject * |
michael@0 | 66 | NewDenseCopiedArray(JSContext *cx, uint32_t length, HandleObject src, uint32_t elementOffset, JSObject *proto = nullptr); |
michael@0 | 67 | |
michael@0 | 68 | /* Create a dense array from the given array values, which must be rooted */ |
michael@0 | 69 | extern ArrayObject * |
michael@0 | 70 | NewDenseCopiedArray(JSContext *cx, uint32_t length, const Value *values, JSObject *proto = nullptr, |
michael@0 | 71 | NewObjectKind newKind = GenericObject); |
michael@0 | 72 | |
michael@0 | 73 | /* Create a dense array based on templateObject with the given length. */ |
michael@0 | 74 | extern ArrayObject * |
michael@0 | 75 | NewDenseAllocatedArrayWithTemplate(JSContext *cx, uint32_t length, JSObject *templateObject); |
michael@0 | 76 | |
michael@0 | 77 | /* |
michael@0 | 78 | * Determines whether a write to the given element on |obj| should fail because |
michael@0 | 79 | * |obj| is an Array with a non-writable length, and writing that element would |
michael@0 | 80 | * increase the length of the array. |
michael@0 | 81 | */ |
michael@0 | 82 | extern bool |
michael@0 | 83 | WouldDefinePastNonwritableLength(ThreadSafeContext *cx, |
michael@0 | 84 | HandleObject obj, uint32_t index, bool strict, |
michael@0 | 85 | bool *definesPast); |
michael@0 | 86 | |
michael@0 | 87 | /* |
michael@0 | 88 | * Canonicalize |vp| to a uint32_t value potentially suitable for use as an |
michael@0 | 89 | * array length. |
michael@0 | 90 | * |
michael@0 | 91 | * For parallel execution we can only canonicalize non-object values. |
michael@0 | 92 | */ |
michael@0 | 93 | template <ExecutionMode mode> |
michael@0 | 94 | extern bool |
michael@0 | 95 | CanonicalizeArrayLengthValue(typename ExecutionModeTraits<mode>::ContextType cx, |
michael@0 | 96 | HandleValue v, uint32_t *canonicalized); |
michael@0 | 97 | |
michael@0 | 98 | extern bool |
michael@0 | 99 | GetLengthProperty(JSContext *cx, HandleObject obj, uint32_t *lengthp); |
michael@0 | 100 | |
michael@0 | 101 | extern bool |
michael@0 | 102 | SetLengthProperty(JSContext *cx, HandleObject obj, double length); |
michael@0 | 103 | |
michael@0 | 104 | extern bool |
michael@0 | 105 | ObjectMayHaveExtraIndexedProperties(JSObject *obj); |
michael@0 | 106 | |
michael@0 | 107 | /* |
michael@0 | 108 | * Copy 'length' elements from aobj to vp. |
michael@0 | 109 | * |
michael@0 | 110 | * This function assumes 'length' is effectively the result of calling |
michael@0 | 111 | * js_GetLengthProperty on aobj. vp must point to rooted memory. |
michael@0 | 112 | */ |
michael@0 | 113 | extern bool |
michael@0 | 114 | GetElements(JSContext *cx, HandleObject aobj, uint32_t length, js::Value *vp); |
michael@0 | 115 | |
michael@0 | 116 | /* Natives exposed for optimization by the interpreter and JITs. */ |
michael@0 | 117 | |
michael@0 | 118 | extern bool |
michael@0 | 119 | array_sort(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 120 | |
michael@0 | 121 | extern bool |
michael@0 | 122 | array_push(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 123 | |
michael@0 | 124 | extern bool |
michael@0 | 125 | array_pop(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 126 | |
michael@0 | 127 | extern bool |
michael@0 | 128 | array_splice(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 129 | |
michael@0 | 130 | extern bool |
michael@0 | 131 | array_splice_impl(JSContext *cx, unsigned argc, js::Value *vp, bool pop); |
michael@0 | 132 | |
michael@0 | 133 | extern bool |
michael@0 | 134 | array_concat(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 135 | |
michael@0 | 136 | extern bool |
michael@0 | 137 | array_concat_dense(JSContext *cx, Handle<ArrayObject*> arr1, Handle<ArrayObject*> arr2, |
michael@0 | 138 | Handle<ArrayObject*> result); |
michael@0 | 139 | |
michael@0 | 140 | extern void |
michael@0 | 141 | ArrayShiftMoveElements(JSObject *obj); |
michael@0 | 142 | |
michael@0 | 143 | extern bool |
michael@0 | 144 | array_shift(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 145 | |
michael@0 | 146 | /* |
michael@0 | 147 | * Append the given (non-hole) value to the end of an array. The array must be |
michael@0 | 148 | * a newborn array -- that is, one which has not been exposed to script for |
michael@0 | 149 | * arbitrary manipulation. (This method optimizes on the assumption that |
michael@0 | 150 | * extending the array to accommodate the element will never make the array |
michael@0 | 151 | * sparse, which requires that the array be completely filled.) |
michael@0 | 152 | */ |
michael@0 | 153 | extern bool |
michael@0 | 154 | NewbornArrayPush(JSContext *cx, HandleObject obj, const Value &v); |
michael@0 | 155 | |
michael@0 | 156 | } /* namespace js */ |
michael@0 | 157 | |
michael@0 | 158 | #ifdef DEBUG |
michael@0 | 159 | extern bool |
michael@0 | 160 | js_ArrayInfo(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 161 | #endif |
michael@0 | 162 | |
michael@0 | 163 | /* Array constructor native. Exposed only so the JIT can know its address. */ |
michael@0 | 164 | bool |
michael@0 | 165 | js_Array(JSContext *cx, unsigned argc, js::Value *vp); |
michael@0 | 166 | |
michael@0 | 167 | #endif /* jsarray_h */ |