summaryrefslogtreecommitdiffstats
path: root/Source/JavaScriptCore/runtime/JSByteArray.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSByteArray.h')
-rw-r--r--Source/JavaScriptCore/runtime/JSByteArray.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/Source/JavaScriptCore/runtime/JSByteArray.h b/Source/JavaScriptCore/runtime/JSByteArray.h
index 44bae2d..6e91594 100644
--- a/Source/JavaScriptCore/runtime/JSByteArray.h
+++ b/Source/JavaScriptCore/runtime/JSByteArray.h
@@ -32,9 +32,11 @@
namespace JSC {
- class JSByteArray : public JSObject {
+ class JSByteArray : public JSNonFinalObject {
friend class JSGlobalData;
public:
+ typedef JSNonFinalObject Base;
+
bool canAccessIndex(unsigned i) { return i < m_storage->length(); }
JSValue getIndex(ExecState*, unsigned i)
{
@@ -45,18 +47,25 @@ namespace JSC {
void setIndex(unsigned i, int value)
{
ASSERT(canAccessIndex(i));
+ if (value & ~0xFF) {
+ if (value < 0)
+ value = 0;
+ else
+ value = 255;
+ }
m_storage->data()[i] = static_cast<unsigned char>(value);
}
-
+
void setIndex(unsigned i, double value)
{
ASSERT(canAccessIndex(i));
- // The largest integer value that a double can represent without loss of precision
- // is 2^53. long long is the smallest integral type that gives correct results
- // when casting numbers larger than 2^31 from a value of type double.
- m_storage->data()[i] = static_cast<unsigned char>(static_cast<long long>(value));
+ if (!(value > 0)) // Clamp NaN to 0
+ value = 0;
+ else if (value > 255)
+ value = 255;
+ m_storage->data()[i] = static_cast<unsigned char>(value + 0.5);
}
-
+
void setIndex(ExecState* exec, unsigned i, JSValue value)
{
double byteValue = value.toNumber(exec);
@@ -66,8 +75,8 @@ namespace JSC {
setIndex(i, byteValue);
}
- JSByteArray(ExecState* exec, NonNullPassRefPtr<Structure>, WTF::ByteArray* storage, const JSC::ClassInfo* = &s_defaultInfo);
- static PassRefPtr<Structure> createStructure(JSValue prototype);
+ JSByteArray(ExecState*, NonNullPassRefPtr<Structure>, WTF::ByteArray* storage);
+ static PassRefPtr<Structure> createStructure(JSValue prototype, const JSC::ClassInfo* = &s_defaultInfo);
virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);
virtual bool getOwnPropertySlot(JSC::ExecState*, unsigned propertyName, JSC::PropertySlot&);
@@ -77,9 +86,8 @@ namespace JSC {
virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
- virtual const ClassInfo* classInfo() const { return m_classInfo; }
static const ClassInfo s_defaultInfo;
-
+
size_t length() const { return m_storage->length(); }
WTF::ByteArray* storage() const { return m_storage.get(); }
@@ -94,15 +102,13 @@ namespace JSC {
private:
enum VPtrStealingHackType { VPtrStealingHack };
JSByteArray(VPtrStealingHackType)
- : JSObject(createStructure(jsNull()))
- , m_classInfo(0)
+ : JSNonFinalObject(createStructure(jsNull()))
{
}
RefPtr<WTF::ByteArray> m_storage;
- const ClassInfo* m_classInfo;
};
-
+
JSByteArray* asByteArray(JSValue value);
inline JSByteArray* asByteArray(JSValue value)
{