mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
e1c4d9e76f
- Bug 1077318 - call out to C++ for ARMv6 sub-word atomics. r=luke (2810c3f93)
- Bug 1142593 - factor atomics into the platform layer. r=waldo (f5088b2af)
- Bug 1173642 - Import unimplemented ARM64 Ion components. r=efaust (2567975a1)
- Bug 1170107 part 1 - Call GetProperty/CallProperty from the interpreter and Baseline. r=bhackett (fe45a446a)
- Bug 1170107 part 2 - Don't allocate a wrapper object for (pure) primitive.foo operations. r=bhackett (8793d7d2d)
- Bug 1152079 - Remove Purify support files. r=froydnj (69836c373)
- Bug 1152079 - Remove references to deleted Purify files from moz.build. r=bustage (ebd68a5fa)
- Bug 1126089 - Assert we don't Destroy nsFrameLoader in destructor (r=smaug) (c0894ed2b)
- Bug 1250871 - only send messages to child scripts when the docShell is still around. r=smaug (ac2562f55)
- Bug 1168750 - SharedStubs: (part3) Make split between baseline only and shared stubs, r=jandem (21c89cffe)
- Bug 1168750 - SharedStubs: (part4) Track for which engine a stub needs to get compiled, r=jandem (a36eb943b)
- Bug 1168753 - SharedStubs: Simplification to push BaselineFrame* in stubs, r=jandem (4a26b318d)
- pointer style (e20a50c7e)
- Bug 1169391 - Use a ReservedRooted class for optimized Rooted use in vm/Interpreter.cpp, r=terrence (1b80a857d)
- Bug 1182865 - Relax assertion on the allowed class for home objects, r=efaust (33009a9fe)
- Bug 1154391 - Update import declarations to current ES6 spec r=shu (ad7042d54)
- Bug 1154391 - Update parsing of export declarations to match current ES6 spec r=shu (4b509d9ec)
- Bug 1169171 - Split PNK_DELETE into several different kinds for each of the syntactically distinct modes of |delete| operation, depending upon the syntax of the operand. r=efaust (5667265fc)
- Bug 1169511 - Split PNK_TYPEOF into one kind for application to names one kind for application to other expressions. r=efaust (91a1086d8)
- pointer style (0546201d8)
- Bug 1163851 - Remove the remaining two tests of |pc->parsingForInit|, replacing them with yet another argument provided by the caller. r=efaust (919903e1e)
- Bug 1163851 - |pc->parsingForInit| is dead. Long live |InHandling|! r=efaust (bf35fb405)
- Bug 1167030 - Suppress MSVC warning C4661 in js/src. r=luke (1d28ed1d2)
- Bug 1167845 - Rejigger {in,de}crement/assignment parsing to vet targets primarily through a single Parser::isValidSimpleAssignmentTarget method, so that this method can also be called outside the parser. r=efaust (87484d3fc)
- Bug 1166950 - Introduce a new FunctionKind for class-constructors. r=efaust (e9dd197e1)
- Bug 1166950 - Make generator methods constructors. r=efaust (e076cacd6)
- Bug 1167845 - Rename ParseHandler::isName to ParseHandler::maybeName. r=efaust (1e090741b)
- Bug 1141865 - Part 3: Parse new.target, add Reflect support, and tests. (r=jorendorff, r=shu) (9e0282870)
- Bug 1139759 - Self-host %TypedArray%.prototype.copyWithin. r=till (8beea5f7c)
- pointer style (0da72f30a)
- Bug 1139769 - Add TypedArrayBuffer, TypedArrayByteOffset, and TypedArrayElementShift intrinsics to safely get the relevant information for a typed array. r=till (b5847a441)
- pointer style (5486dd33d)
- Bug 1139769 - Self-host %TypedArray%.prototype.subarray. r=t (b10c55e93)
- pointer style (335ab6c87)
- Bug 1140752 - Land code to self-host %TypedArray%.prototype.set, but don't enable it yet, pending perf-testing. This shouldn't make any changes to the build, except in terms of adding more code to it and affecting binary layout. r=jandem, also much feedback from till that effectively amounts to a review as well (98050308d)
- Bug 1144692: Fix --disable-ion builds; r=h4writer (3be32046c)
- Bug 1148970 - Check for possibly incomplete type sets when double checking the correctness of argument type set information, r=jandem. (934130c2e)
- bug 1171125 - Fix nsStackWalk to build for iOS. r=froydnj (c076c4d22)
- Bug 1119980 - Use 'snprintf' instead of 'sprintf' to avoid a warning on Lollipop-based builds. r=froydnj (a000af66c)
- Bug 1146597 - Avoid unnecessary calls to maybeSweep under hasUnanalyzedPreliminaryObjects, r=jandem. (335ba3fc3)
- Bug 1162134 - IonMonkey MIPS: Fix build failure on MIPS (js/src/jit/CodeGenerator.cpp:6740:28: error: `obj' was not declared in this scope). r=bhackett (56824379b)
- Bug 1160884 followup - Add testcase. r=me (5495ad016)
- Bug 1141865 - Part 4: Remove LCallDirectEvalV in anticipation of register pressure with new.target in eval frames. (r=jandem) (cbb706356)
- Bug 1162242 - Part 1: Remove instances of #ifdef PR_LOGGING. r=froydnj PR_LOGGING is now always defined, we can remove #ifdefs checking for it. (878131a4a)
- revert pointer style for patch (a263375f1)
- Bug 1144097. Fix yet another is<ScopeObject>() assert. r=shu (96d516117)
- Bug 1145282. Reverse the sense of IsValidTerminatingScope and rename it to IsSyntacticScope. r=luke (3681fc831)
- Bug 1149897 - PerformanceStatsService data is not monotonic. r=jandem (927639ac6)
- Bug 1142457 - Compute stopwatch durations per thread on MacOS X. r=jandem, r=areinald (a52c388be)
556 lines
19 KiB
C++
556 lines
19 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef vm_ArrayBufferObject_h
|
|
#define vm_ArrayBufferObject_h
|
|
|
|
#include "jsobj.h"
|
|
|
|
#include "builtin/TypedObjectConstants.h"
|
|
#include "vm/Runtime.h"
|
|
|
|
typedef struct JSProperty JSProperty;
|
|
|
|
namespace js {
|
|
|
|
class ArrayBufferViewObject;
|
|
|
|
// The inheritance hierarchy for the various classes relating to typed arrays
|
|
// is as follows.
|
|
//
|
|
// - JSObject
|
|
// - ArrayBufferObjectMaybeShared
|
|
// - ArrayBufferObject
|
|
// - SharedArrayBufferObject
|
|
// - ArrayBufferViewObject
|
|
// - DataViewObject
|
|
// - TypedArrayObject (declared in vm/TypedArrayObject.h)
|
|
// - TypedArrayObjectTemplate
|
|
// - Int8ArrayObject
|
|
// - Uint8ArrayObject
|
|
// - ...
|
|
// - TypedObject (declared in builtin/TypedObject.h)
|
|
// - SharedTypedArrayObject (declared in vm/SharedTypedArrayObject.h)
|
|
// - SharedTypedArrayObjectTemplate
|
|
// - SharedInt8ArrayObject
|
|
// - SharedUint8ArrayObject
|
|
// - ...
|
|
//
|
|
// Note that |TypedArrayObjectTemplate| is just an implementation
|
|
// detail that makes implementing its various subclasses easier.
|
|
// Note that |TypedArrayObjectTemplate| and |SharedTypedArrayObjectTemplate| are
|
|
// just implementation details that make implementing their various subclasses easier.
|
|
//
|
|
// ArrayBufferObject and SharedArrayBufferObject are unrelated data types:
|
|
// the racy memory of the latter cannot substitute for the non-racy memory of
|
|
// the former; the non-racy memory of the former cannot be used with the atomics;
|
|
// the former can be neutered and the latter not; and they have different
|
|
// method suites. Hence they have been separated completely.
|
|
//
|
|
// Most APIs will only accept ArrayBufferObject. ArrayBufferObjectMaybeShared exists
|
|
// as a join point to allow APIs that can take or use either, notably AsmJS.
|
|
//
|
|
// As ArrayBufferObject and SharedArrayBufferObject are separated, so are the
|
|
// TypedArray hierarchies below the two. However, the TypedArrays have the
|
|
// same layout (see TypedArrayObject.h), so there is little code duplication.
|
|
//
|
|
// The possible data ownership and reference relationships with array buffers
|
|
// and related classes are enumerated below. These are the possible locations
|
|
// for typed data:
|
|
//
|
|
// (1) malloc'ed or mmap'ed data owned by an ArrayBufferObject.
|
|
// (2) Data allocated inline with an ArrayBufferObject.
|
|
// (3) Data allocated inline with a TypedArrayObject.
|
|
// (4) Data allocated inline with an InlineTypedObject.
|
|
//
|
|
// An ArrayBufferObject may point to any of these sources of data, except (3).
|
|
// All array buffer views may point to any of these sources of data, except
|
|
// that (3) may only be pointed to by the typed array the data is inline with.
|
|
//
|
|
// During a minor GC, (3) and (4) may move. During a compacting GC, (2), (3),
|
|
// and (4) may move.
|
|
|
|
class ArrayBufferObjectMaybeShared;
|
|
|
|
uint32_t AnyArrayBufferByteLength(const ArrayBufferObjectMaybeShared* buf);
|
|
uint8_t* AnyArrayBufferDataPointer(const ArrayBufferObjectMaybeShared* buf);
|
|
ArrayBufferObjectMaybeShared& AsAnyArrayBuffer(HandleValue val);
|
|
|
|
class ArrayBufferObjectMaybeShared : public NativeObject
|
|
{
|
|
public:
|
|
uint32_t byteLength() {
|
|
return AnyArrayBufferByteLength(this);
|
|
}
|
|
|
|
uint8_t* dataPointer() {
|
|
return AnyArrayBufferDataPointer(this);
|
|
}
|
|
};
|
|
|
|
/*
|
|
* ArrayBufferObject
|
|
*
|
|
* This class holds the underlying raw buffer that the various
|
|
* ArrayBufferViewObject subclasses (DataViewObject and the TypedArrays)
|
|
* access. It can be created explicitly and passed to an ArrayBufferViewObject
|
|
* subclass, or can be created lazily when it is first accessed for a
|
|
* TypedArrayObject or TypedObject that doesn't have an explicit buffer.
|
|
*
|
|
* ArrayBufferObject (or really the underlying memory) /is not racy/: the
|
|
* memory is private to a single worker.
|
|
*/
|
|
class ArrayBufferObject : public ArrayBufferObjectMaybeShared
|
|
{
|
|
static bool byteLengthGetterImpl(JSContext* cx, const CallArgs& args);
|
|
static bool fun_slice_impl(JSContext* cx, const CallArgs& args);
|
|
|
|
public:
|
|
static const uint8_t DATA_SLOT = 0;
|
|
static const uint8_t BYTE_LENGTH_SLOT = 1;
|
|
static const uint8_t FIRST_VIEW_SLOT = 2;
|
|
static const uint8_t FLAGS_SLOT = 3;
|
|
|
|
static const uint8_t RESERVED_SLOTS = 4;
|
|
|
|
static const size_t ARRAY_BUFFER_ALIGNMENT = 8;
|
|
|
|
static_assert(FLAGS_SLOT == JS_ARRAYBUFFER_FLAGS_SLOT,
|
|
"self-hosted code with burned-in constants must get the "
|
|
"right flags slot");
|
|
|
|
public:
|
|
|
|
enum OwnsState {
|
|
DoesntOwnData = 0,
|
|
OwnsData = 1,
|
|
};
|
|
|
|
enum BufferKind {
|
|
PLAIN = 0, // malloced or inline data
|
|
ASMJS_MALLOCED = 1,
|
|
ASMJS_MAPPED = 2,
|
|
MAPPED = 3,
|
|
|
|
KIND_MASK = 0x3
|
|
};
|
|
|
|
protected:
|
|
|
|
enum ArrayBufferFlags {
|
|
// The flags also store the BufferKind
|
|
BUFFER_KIND_MASK = BufferKind::KIND_MASK,
|
|
|
|
NEUTERED = 0x4,
|
|
|
|
// The dataPointer() is owned by this buffer and should be released
|
|
// when no longer in use. Releasing the pointer may be done by either
|
|
// freeing or unmapping it, and how to do this is determined by the
|
|
// buffer's other flags.
|
|
//
|
|
// Array buffers which do not own their data include buffers that
|
|
// allocate their data inline, and buffers that are created lazily for
|
|
// typed objects with inline storage, in which case the buffer points
|
|
// directly to the typed object's storage.
|
|
OWNS_DATA = 0x8,
|
|
|
|
// This array buffer was created lazily for a typed object with inline
|
|
// data. This implies both that the typed object owns the buffer's data
|
|
// and that the list of views sharing this buffer's data might be
|
|
// incomplete. Any missing views will be typed objects.
|
|
FOR_INLINE_TYPED_OBJECT = 0x10,
|
|
|
|
// Views of this buffer might include typed objects.
|
|
TYPED_OBJECT_VIEWS = 0x20
|
|
};
|
|
|
|
static_assert(JS_ARRAYBUFFER_NEUTERED_FLAG == NEUTERED,
|
|
"self-hosted code with burned-in constants must use the "
|
|
"correct NEUTERED bit value");
|
|
public:
|
|
|
|
class BufferContents {
|
|
uint8_t* data_;
|
|
BufferKind kind_;
|
|
|
|
friend class ArrayBufferObject;
|
|
|
|
BufferContents(uint8_t* data, BufferKind kind) : data_(data), kind_(kind) {
|
|
MOZ_ASSERT((kind_ & ~KIND_MASK) == 0);
|
|
}
|
|
|
|
public:
|
|
|
|
template<BufferKind Kind>
|
|
static BufferContents create(void* data)
|
|
{
|
|
return BufferContents(static_cast<uint8_t*>(data), Kind);
|
|
}
|
|
|
|
static BufferContents createPlain(void* data)
|
|
{
|
|
return BufferContents(static_cast<uint8_t*>(data), PLAIN);
|
|
}
|
|
|
|
uint8_t* data() const { return data_; }
|
|
BufferKind kind() const { return kind_; }
|
|
|
|
explicit operator bool() const { return data_ != nullptr; }
|
|
};
|
|
|
|
static const Class class_;
|
|
|
|
static const Class protoClass;
|
|
static const JSFunctionSpec jsfuncs[];
|
|
static const JSFunctionSpec jsstaticfuncs[];
|
|
|
|
static bool byteLengthGetter(JSContext* cx, unsigned argc, Value* vp);
|
|
|
|
static bool fun_slice(JSContext* cx, unsigned argc, Value* vp);
|
|
|
|
static bool fun_isView(JSContext* cx, unsigned argc, Value* vp);
|
|
#ifdef NIGHTLY_BUILD
|
|
static bool fun_transfer(JSContext* cx, unsigned argc, Value* vp);
|
|
#endif
|
|
|
|
static bool class_constructor(JSContext* cx, unsigned argc, Value* vp);
|
|
|
|
static ArrayBufferObject* create(JSContext* cx, uint32_t nbytes,
|
|
BufferContents contents,
|
|
OwnsState ownsState = OwnsData,
|
|
NewObjectKind newKind = GenericObject);
|
|
static ArrayBufferObject* create(JSContext* cx, uint32_t nbytes,
|
|
NewObjectKind newKind = GenericObject);
|
|
|
|
static JSObject* createSlice(JSContext* cx, Handle<ArrayBufferObject*> arrayBuffer,
|
|
uint32_t begin, uint32_t end);
|
|
|
|
static bool createDataViewForThisImpl(JSContext* cx, const CallArgs& args);
|
|
static bool createDataViewForThis(JSContext* cx, unsigned argc, Value* vp);
|
|
|
|
template<typename T>
|
|
static bool createTypedArrayFromBufferImpl(JSContext* cx, const CallArgs& args);
|
|
|
|
template<typename T>
|
|
static bool createTypedArrayFromBuffer(JSContext* cx, unsigned argc, Value* vp);
|
|
|
|
static void trace(JSTracer* trc, JSObject* obj);
|
|
static void objectMoved(JSObject* obj, const JSObject* old);
|
|
|
|
static BufferContents stealContents(JSContext* cx,
|
|
Handle<ArrayBufferObject*> buffer,
|
|
bool hasStealableContents);
|
|
|
|
bool hasStealableContents() const {
|
|
// Inline elements strictly adhere to the corresponding buffer.
|
|
if (!ownsData())
|
|
return false;
|
|
|
|
// Neutered contents aren't transferrable because we want a neutered
|
|
// array's contents to be backed by zeroed memory equal in length to
|
|
// the original buffer contents. Transferring these contents would
|
|
// allocate new ones based on the current byteLength, which is 0 for a
|
|
// neutered array -- not the original byteLength.
|
|
return !isNeutered();
|
|
}
|
|
|
|
// Return whether the buffer is allocated by js_malloc and should be freed
|
|
// with js_free.
|
|
bool hasMallocedContents() const {
|
|
return (ownsData() && isPlain()) || isAsmJSMalloced();
|
|
}
|
|
|
|
static void addSizeOfExcludingThis(JSObject* obj, mozilla::MallocSizeOf mallocSizeOf,
|
|
JS::ClassInfo* info);
|
|
|
|
// ArrayBufferObjects (strongly) store the first view added to them, while
|
|
// later views are (weakly) stored in the compartment's InnerViewTable
|
|
// below. Buffers usually only have one view, so this slot optimizes for
|
|
// the common case. Avoiding entries in the InnerViewTable saves memory and
|
|
// non-incrementalized sweep time.
|
|
ArrayBufferViewObject* firstView();
|
|
|
|
bool addView(JSContext* cx, JSObject* view);
|
|
|
|
void setNewOwnedData(FreeOp* fop, BufferContents newContents);
|
|
void changeContents(JSContext* cx, BufferContents newContents);
|
|
|
|
/*
|
|
* Ensure data is not stored inline in the object. Used when handing back a
|
|
* GC-safe pointer.
|
|
*/
|
|
static bool ensureNonInline(JSContext* cx, Handle<ArrayBufferObject*> buffer);
|
|
|
|
/* Neuter this buffer and all its views. */
|
|
static MOZ_WARN_UNUSED_RESULT bool
|
|
neuter(JSContext* cx, Handle<ArrayBufferObject*> buffer, BufferContents newContents);
|
|
|
|
private:
|
|
void neuterView(JSContext* cx, ArrayBufferViewObject* view,
|
|
BufferContents newContents);
|
|
void changeViewContents(JSContext* cx, ArrayBufferViewObject* view,
|
|
uint8_t* oldDataPointer, BufferContents newContents);
|
|
void setFirstView(ArrayBufferViewObject* view);
|
|
|
|
uint8_t* inlineDataPointer() const;
|
|
|
|
public:
|
|
uint8_t* dataPointer() const;
|
|
size_t byteLength() const;
|
|
BufferContents contents() const {
|
|
return BufferContents(dataPointer(), bufferKind());
|
|
}
|
|
bool hasInlineData() const {
|
|
return dataPointer() == inlineDataPointer();
|
|
}
|
|
|
|
void releaseData(FreeOp* fop);
|
|
|
|
/*
|
|
* Check if the arrayBuffer contains any data. This will return false for
|
|
* ArrayBuffer.prototype and neutered ArrayBuffers.
|
|
*/
|
|
bool hasData() const {
|
|
return getClass() == &class_;
|
|
}
|
|
|
|
BufferKind bufferKind() const { return BufferKind(flags() & BUFFER_KIND_MASK); }
|
|
bool isPlain() const { return bufferKind() == PLAIN; }
|
|
bool isAsmJSMapped() const { return bufferKind() == ASMJS_MAPPED; }
|
|
bool isAsmJSMalloced() const { return bufferKind() == ASMJS_MALLOCED; }
|
|
bool isAsmJS() const { return isAsmJSMapped() || isAsmJSMalloced(); }
|
|
bool isMapped() const { return bufferKind() == MAPPED; }
|
|
bool isNeutered() const { return flags() & NEUTERED; }
|
|
|
|
static bool prepareForAsmJS(JSContext* cx, Handle<ArrayBufferObject*> buffer,
|
|
bool usesSignalHandlers);
|
|
static bool prepareForAsmJSNoSignals(JSContext* cx, Handle<ArrayBufferObject*> buffer);
|
|
|
|
static void finalize(FreeOp* fop, JSObject* obj);
|
|
|
|
static BufferContents createMappedContents(int fd, size_t offset, size_t length);
|
|
|
|
static size_t offsetOfFlagsSlot() {
|
|
return getFixedSlotOffset(FLAGS_SLOT);
|
|
}
|
|
static size_t offsetOfDataSlot() {
|
|
return getFixedSlotOffset(DATA_SLOT);
|
|
}
|
|
|
|
static uint32_t neuteredFlag() { return NEUTERED; }
|
|
|
|
void setForInlineTypedObject() {
|
|
setFlags(flags() | FOR_INLINE_TYPED_OBJECT);
|
|
}
|
|
void setHasTypedObjectViews() {
|
|
setFlags(flags() | TYPED_OBJECT_VIEWS);
|
|
}
|
|
|
|
bool forInlineTypedObject() const { return flags() & FOR_INLINE_TYPED_OBJECT; }
|
|
|
|
protected:
|
|
void setDataPointer(BufferContents contents, OwnsState ownsState);
|
|
void setByteLength(size_t length);
|
|
|
|
uint32_t flags() const;
|
|
void setFlags(uint32_t flags);
|
|
|
|
bool ownsData() const { return flags() & OWNS_DATA; }
|
|
void setOwnsData(OwnsState owns) {
|
|
setFlags(owns ? (flags() | OWNS_DATA) : (flags() & ~OWNS_DATA));
|
|
}
|
|
|
|
bool hasTypedObjectViews() const { return flags() & TYPED_OBJECT_VIEWS; }
|
|
|
|
void setIsAsmJSMalloced() { setFlags((flags() & ~KIND_MASK) | ASMJS_MALLOCED); }
|
|
void setIsNeutered() { setFlags(flags() | NEUTERED); }
|
|
|
|
void initialize(size_t byteLength, BufferContents contents, OwnsState ownsState) {
|
|
setByteLength(byteLength);
|
|
setFlags(0);
|
|
setFirstView(nullptr);
|
|
setDataPointer(contents, ownsState);
|
|
}
|
|
};
|
|
|
|
/*
|
|
* ArrayBufferViewObject
|
|
*
|
|
* Common definitions shared by all array buffer views.
|
|
*/
|
|
|
|
class ArrayBufferViewObject : public JSObject
|
|
{
|
|
public:
|
|
static ArrayBufferObject* bufferObject(JSContext* cx, Handle<ArrayBufferViewObject*> obj);
|
|
|
|
void neuter(void* newData);
|
|
|
|
uint8_t* dataPointer();
|
|
void setDataPointer(uint8_t* data);
|
|
|
|
static void trace(JSTracer* trc, JSObject* obj);
|
|
};
|
|
|
|
bool
|
|
ToClampedIndex(JSContext* cx, HandleValue v, uint32_t length, uint32_t* out);
|
|
|
|
/*
|
|
* Tests for ArrayBufferObject, like obj->is<ArrayBufferObject>().
|
|
*/
|
|
bool IsArrayBuffer(HandleValue v);
|
|
bool IsArrayBuffer(HandleObject obj);
|
|
bool IsArrayBuffer(JSObject* obj);
|
|
ArrayBufferObject& AsArrayBuffer(HandleObject obj);
|
|
ArrayBufferObject& AsArrayBuffer(JSObject* obj);
|
|
|
|
extern uint32_t JS_FASTCALL
|
|
ClampDoubleToUint8(const double x);
|
|
|
|
struct uint8_clamped {
|
|
uint8_t val;
|
|
|
|
uint8_clamped() { }
|
|
uint8_clamped(const uint8_clamped& other) : val(other.val) { }
|
|
|
|
// invoke our assignment helpers for constructor conversion
|
|
explicit uint8_clamped(uint8_t x) { *this = x; }
|
|
explicit uint8_clamped(uint16_t x) { *this = x; }
|
|
explicit uint8_clamped(uint32_t x) { *this = x; }
|
|
explicit uint8_clamped(int8_t x) { *this = x; }
|
|
explicit uint8_clamped(int16_t x) { *this = x; }
|
|
explicit uint8_clamped(int32_t x) { *this = x; }
|
|
explicit uint8_clamped(double x) { *this = x; }
|
|
|
|
uint8_clamped& operator=(const uint8_clamped& x) {
|
|
val = x.val;
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(uint8_t x) {
|
|
val = x;
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(uint16_t x) {
|
|
val = (x > 255) ? 255 : uint8_t(x);
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(uint32_t x) {
|
|
val = (x > 255) ? 255 : uint8_t(x);
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(int8_t x) {
|
|
val = (x >= 0) ? uint8_t(x) : 0;
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(int16_t x) {
|
|
val = (x >= 0)
|
|
? ((x < 255)
|
|
? uint8_t(x)
|
|
: 255)
|
|
: 0;
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(int32_t x) {
|
|
val = (x >= 0)
|
|
? ((x < 255)
|
|
? uint8_t(x)
|
|
: 255)
|
|
: 0;
|
|
return *this;
|
|
}
|
|
|
|
uint8_clamped& operator=(const double x) {
|
|
val = uint8_t(ClampDoubleToUint8(x));
|
|
return *this;
|
|
}
|
|
|
|
operator uint8_t() const {
|
|
return val;
|
|
}
|
|
|
|
void staticAsserts() {
|
|
static_assert(sizeof(uint8_clamped) == 1,
|
|
"uint8_clamped must be layout-compatible with uint8_t");
|
|
}
|
|
};
|
|
|
|
/* Note that we can't use std::numeric_limits here due to uint8_clamped. */
|
|
template<typename T> inline bool TypeIsFloatingPoint() { return false; }
|
|
template<> inline bool TypeIsFloatingPoint<float>() { return true; }
|
|
template<> inline bool TypeIsFloatingPoint<double>() { return true; }
|
|
|
|
template<typename T> inline bool TypeIsUnsigned() { return false; }
|
|
template<> inline bool TypeIsUnsigned<uint8_t>() { return true; }
|
|
template<> inline bool TypeIsUnsigned<uint16_t>() { return true; }
|
|
template<> inline bool TypeIsUnsigned<uint32_t>() { return true; }
|
|
|
|
// Per-compartment table that manages the relationship between array buffers
|
|
// and the views that use their storage.
|
|
class InnerViewTable
|
|
{
|
|
public:
|
|
typedef Vector<ArrayBufferViewObject*, 1, SystemAllocPolicy> ViewVector;
|
|
|
|
friend class ArrayBufferObject;
|
|
|
|
private:
|
|
typedef HashMap<JSObject*,
|
|
ViewVector,
|
|
DefaultHasher<JSObject*>,
|
|
SystemAllocPolicy> Map;
|
|
|
|
// For all objects sharing their storage with some other view, this maps
|
|
// the object to the list of such views. All entries in this map are weak.
|
|
Map map;
|
|
|
|
// List of keys from innerViews where either the source or at least one
|
|
// target is in the nursery.
|
|
Vector<JSObject*, 0, SystemAllocPolicy> nurseryKeys;
|
|
|
|
// Whether nurseryKeys is a complete list.
|
|
bool nurseryKeysValid;
|
|
|
|
// Sweep an entry during GC, returning whether the entry should be removed.
|
|
bool sweepEntry(JSObject** pkey, ViewVector& views);
|
|
|
|
bool addView(JSContext* cx, ArrayBufferObject* obj, ArrayBufferViewObject* view);
|
|
ViewVector* maybeViewsUnbarriered(ArrayBufferObject* obj);
|
|
void removeViews(ArrayBufferObject* obj);
|
|
|
|
public:
|
|
InnerViewTable()
|
|
: nurseryKeysValid(true)
|
|
{}
|
|
|
|
// Remove references to dead objects in the table and update table entries
|
|
// to reflect moved objects.
|
|
void sweep(JSRuntime* rt);
|
|
void sweepAfterMinorGC(JSRuntime* rt);
|
|
|
|
bool needsSweepAfterMinorGC() {
|
|
return !nurseryKeys.empty() || !nurseryKeysValid;
|
|
}
|
|
|
|
size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf);
|
|
};
|
|
|
|
extern JSObject *
|
|
InitArrayBufferClass(JSContext *cx, HandleObject obj);
|
|
|
|
} // namespace js
|
|
|
|
template <>
|
|
bool
|
|
JSObject::is<js::ArrayBufferViewObject>() const;
|
|
|
|
#endif // vm_ArrayBufferObject_h
|