From 33a4d394f6bbdefd8d4f10abed8740d48b49d908 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 2 Jul 2013 20:58:39 -0700 Subject: [PATCH] Bug 889146 (part 14) - Make DataViewObject::{byteLength,byteLengthValue,byteOffset,byteOffsetValue}() more sane. r=sfink. --HG-- extra : rebase_source : a55357844d1495333aaa7c6310110704cd394656 --- js/src/jstypedarray.cpp | 8 ++++---- js/src/jstypedarray.h | 38 +++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/js/src/jstypedarray.cpp b/js/src/jstypedarray.cpp index 6feaaf2d13b..0114fff1c5f 100644 --- a/js/src/jstypedarray.cpp +++ b/js/src/jstypedarray.cpp @@ -3813,15 +3813,15 @@ const JSFunctionSpec DataViewObject::jsfuncs[] = { JS_FS_END }; -template +template bool DataViewObject::getterImpl(JSContext *cx, CallArgs args) { - args.rval().set(ValueGetter(args.thisv().toObject().as())); + args.rval().set(ValueGetter(&args.thisv().toObject().as())); return true; } -template +template JSBool DataViewObject::getter(JSContext *cx, unsigned argc, Value *vp) { @@ -3829,7 +3829,7 @@ DataViewObject::getter(JSContext *cx, unsigned argc, Value *vp) return CallNonGenericMethod >(cx, args); } -template +template bool DataViewObject::defineGetter(JSContext *cx, PropertyName *name, HandleObject proto) { diff --git a/js/src/jstypedarray.h b/js/src/jstypedarray.h index fbde371d013..5b8d0214b2a 100644 --- a/js/src/jstypedarray.h +++ b/js/src/jstypedarray.h @@ -455,39 +455,39 @@ class DataViewObject : public ArrayBufferViewObject return v.isObject() && v.toObject().hasClass(&class_); } - template + template static bool getterImpl(JSContext *cx, CallArgs args); - template + template static JSBool getter(JSContext *cx, unsigned argc, Value *vp); - template + template static bool defineGetter(JSContext *cx, PropertyName *name, HandleObject proto); public: static Class class_; + static Value byteOffsetValue(DataViewObject *view) { + Value v = view->getReservedSlot(BYTEOFFSET_SLOT); + JS_ASSERT(v.toInt32() >= 0); + return v; + } + + static Value byteLengthValue(DataViewObject *view) { + Value v = view->getReservedSlot(BYTELENGTH_SLOT); + JS_ASSERT(v.toInt32() >= 0); + return v; + } + uint32_t byteOffset() const { - int32_t offset = getReservedSlot(BYTEOFFSET_SLOT).toInt32(); - JS_ASSERT(offset >= 0); - return static_cast(offset); + return byteOffsetValue(const_cast(this)).toInt32(); } uint32_t byteLength() const { - int32_t length = getReservedSlot(BYTELENGTH_SLOT).toInt32(); - JS_ASSERT(length >= 0); - return static_cast(length); - } - - static Value byteOffsetValue(DataViewObject &view) { - return Int32Value(view.byteOffset()); - } - - static Value byteLengthValue(DataViewObject &view) { - return Int32Value(view.byteLength()); + return byteLengthValue(const_cast(this)).toInt32(); } bool hasBuffer() const { @@ -498,8 +498,8 @@ class DataViewObject : public ArrayBufferViewObject return getReservedSlot(BUFFER_SLOT).toObject().as(); } - static Value bufferValue(DataViewObject &view) { - return view.hasBuffer() ? ObjectValue(view.arrayBuffer()) : UndefinedValue(); + static Value bufferValue(DataViewObject *view) { + return view->hasBuffer() ? ObjectValue(view->arrayBuffer()) : UndefinedValue(); } void *dataPointer() const {