Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1272697 - Part 1: Change ArrayBufferCopyData self-hosting intrins…
Browse files Browse the repository at this point in the history
…ic to take a start offset for the destination. r=lth

MozReview-Commit-ID: LroQFwbeAhi
  • Loading branch information
tschneidereit committed Feb 4, 2017
1 parent e25a9b0 commit 955486f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
6 changes: 2 additions & 4 deletions js/src/builtin/TypedArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* 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/. */

#include "TypedObjectConstants.h"

function ViewedArrayBufferIfReified(tarray) {
assert(IsTypedArray(tarray), "non-typed array asked for its buffer");

Expand Down Expand Up @@ -1650,7 +1648,7 @@ function ArrayBufferSlice(start, end) {
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);

// Steps 19-21.
ArrayBufferCopyData(new_, O, first | 0, newLen | 0, isWrapped);
ArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);

// Step 22.
return new_;
Expand Down Expand Up @@ -1736,7 +1734,7 @@ function SharedArrayBufferSlice(start, end) {
ThrowTypeError(JSMSG_SHORT_SHARED_ARRAY_BUFFER_RETURNED, newLen, actualLen);

// Steps 16-18.
SharedArrayBufferCopyData(new_, O, first | 0, newLen | 0, isWrapped);
SharedArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);

// Step 19.
return new_;
Expand Down
1 change: 1 addition & 0 deletions js/src/builtin/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "SelfHostingDefines.h"
#include "TypedObjectConstants.h"

// Assertions and debug printing, defined here instead of in the header above
// to make `assert` invisible to C++.
Expand Down
9 changes: 5 additions & 4 deletions js/src/vm/ArrayBufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,15 +1225,16 @@ ArrayBufferObject::finalize(FreeOp* fop, JSObject* obj)
}

/* static */ void
ArrayBufferObject::copyData(Handle<ArrayBufferObject*> toBuffer,
Handle<ArrayBufferObject*> fromBuffer,
uint32_t fromIndex, uint32_t count)
ArrayBufferObject::copyData(Handle<ArrayBufferObject*> toBuffer, uint32_t toIndex,
Handle<ArrayBufferObject*> fromBuffer, uint32_t fromIndex,
uint32_t count)
{
MOZ_ASSERT(toBuffer->byteLength() >= count);
MOZ_ASSERT(toBuffer->byteLength() >= toIndex + count);
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex);
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count);

memcpy(toBuffer->dataPointer(), fromBuffer->dataPointer() + fromIndex, count);
memcpy(toBuffer->dataPointer() + toIndex, fromBuffer->dataPointer() + fromIndex, count);
}

/* static */ void
Expand Down
6 changes: 3 additions & 3 deletions js/src/vm/ArrayBufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ class ArrayBufferObject : public ArrayBufferObjectMaybeShared
template<typename T>
static bool createTypedArrayFromBuffer(JSContext* cx, unsigned argc, Value* vp);

static void copyData(Handle<ArrayBufferObject*> toBuffer,
Handle<ArrayBufferObject*> fromBuffer,
uint32_t fromIndex, uint32_t count);
static void copyData(Handle<ArrayBufferObject*> toBuffer, uint32_t toIndex,
Handle<ArrayBufferObject*> fromBuffer, uint32_t fromIndex,
uint32_t count);

static void trace(JSTracer* trc, JSObject* obj);
static void objectMoved(JSObject* obj, const JSObject* old);
Expand Down
17 changes: 9 additions & 8 deletions js/src/vm/SelfHosting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,9 @@ static bool
intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
MOZ_ASSERT(args.length() == 5);
MOZ_ASSERT(args.length() == 6);

bool isWrapped = args[4].toBoolean();
bool isWrapped = args[5].toBoolean();
Rooted<T*> toBuffer(cx);
if (!isWrapped) {
toBuffer = &args[0].toObject().as<T>();
Expand All @@ -1027,11 +1027,12 @@ intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
}
toBuffer = toBufferObj.as<T>();
}
Rooted<T*> fromBuffer(cx, &args[1].toObject().as<T>());
uint32_t fromIndex = uint32_t(args[2].toInt32());
uint32_t count = uint32_t(args[3].toInt32());
uint32_t toIndex = uint32_t(args[1].toInt32());
Rooted<T*> fromBuffer(cx, &args[2].toObject().as<T>());
uint32_t fromIndex = uint32_t(args[3].toInt32());
uint32_t count = uint32_t(args[4].toInt32());

T::copyData(toBuffer, fromBuffer, fromIndex, count);
T::copyData(toBuffer, toIndex, fromBuffer, fromIndex, count);

args.rval().setUndefined();
return true;
Expand Down Expand Up @@ -2499,14 +2500,14 @@ static const JSFunctionSpec intrinsic_functions[] = {
intrinsic_PossiblyWrappedArrayBufferByteLength<ArrayBufferObject>, 1,0,
IntrinsicPossiblyWrappedArrayBufferByteLength),
JS_FN("ArrayBufferCopyData",
intrinsic_ArrayBufferCopyData<ArrayBufferObject>, 5,0),
intrinsic_ArrayBufferCopyData<ArrayBufferObject>, 6,0),

JS_FN("SharedArrayBufferByteLength",
intrinsic_ArrayBufferByteLength<SharedArrayBufferObject>, 1,0),
JS_FN("PossiblyWrappedSharedArrayBufferByteLength",
intrinsic_PossiblyWrappedArrayBufferByteLength<SharedArrayBufferObject>, 1,0),
JS_FN("SharedArrayBufferCopyData",
intrinsic_ArrayBufferCopyData<SharedArrayBufferObject>, 5,0),
intrinsic_ArrayBufferCopyData<SharedArrayBufferObject>, 6,0),
JS_FN("SharedArrayBuffersMemorySame",
intrinsic_SharedArrayBuffersMemorySame, 2,0),

Expand Down
9 changes: 5 additions & 4 deletions js/src/vm/SharedArrayObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ SharedArrayBufferObject::addSizeOfExcludingThis(JSObject* obj, mozilla::MallocSi
}

/* static */ void
SharedArrayBufferObject::copyData(Handle<SharedArrayBufferObject*> toBuffer,
Handle<SharedArrayBufferObject*> fromBuffer,
uint32_t fromIndex, uint32_t count)
SharedArrayBufferObject::copyData(Handle<SharedArrayBufferObject*> toBuffer, uint32_t toIndex,
Handle<SharedArrayBufferObject*> fromBuffer, uint32_t fromIndex,
uint32_t count)
{
MOZ_ASSERT(toBuffer->byteLength() >= count);
MOZ_ASSERT(toBuffer->byteLength() >= toIndex + count);
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex);
MOZ_ASSERT(fromBuffer->byteLength() >= fromIndex + count);

jit::AtomicOperations::memcpySafeWhenRacy(toBuffer->dataPointerShared(),
jit::AtomicOperations::memcpySafeWhenRacy(toBuffer->dataPointerShared() + toIndex,
fromBuffer->dataPointerShared() + fromIndex,
count);
}
Expand Down
6 changes: 3 additions & 3 deletions js/src/vm/SharedArrayObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class SharedArrayBufferObject : public ArrayBufferObjectMaybeShared
static void addSizeOfExcludingThis(JSObject* obj, mozilla::MallocSizeOf mallocSizeOf,
JS::ClassInfo* info);

static void copyData(Handle<SharedArrayBufferObject*> toBuffer,
Handle<SharedArrayBufferObject*> fromBuffer,
uint32_t fromIndex, uint32_t count);
static void copyData(Handle<SharedArrayBufferObject*> toBuffer, uint32_t toIndex,
Handle<SharedArrayBufferObject*> fromBuffer, uint32_t fromIndex,
uint32_t count);

SharedArrayRawBuffer* rawBufferObject() const;

Expand Down

0 comments on commit 955486f

Please sign in to comment.