1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "js/experimental/TypedData.h" // JS_GetFloat32ArrayData
8 #include "mozilla/ErrorResult.h"
9 #include "mozilla/HoldDropJSObjects.h"
10 #include "mozilla/dom/TypedArray.h"
11 #include "mozilla/dom/Pose.h"
13 namespace mozilla::dom
{
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(
17 (mPosition
, mLinearVelocity
, mLinearAcceleration
, mOrientation
,
18 mAngularVelocity
, mAngularAcceleration
))
20 Pose::Pose(nsISupports
* aParent
)
23 mLinearVelocity(nullptr),
24 mLinearAcceleration(nullptr),
25 mOrientation(nullptr),
26 mAngularVelocity(nullptr),
27 mAngularAcceleration(nullptr) {
28 mozilla::HoldJSObjects(this);
31 Pose::~Pose() { mozilla::DropJSObjects(this); }
33 nsISupports
* Pose::GetParentObject() const { return mParent
; }
35 void Pose::SetFloat32Array(JSContext
* aJSContext
, nsWrapperCache
* creator
,
36 JS::MutableHandle
<JSObject
*> aRetVal
,
37 JS::Heap
<JSObject
*>& aObj
, float* aVal
,
38 uint32_t aValLength
, ErrorResult
& aRv
) {
45 aObj
= Float32Array::Create(aJSContext
, creator
, aValLength
, aVal
);
47 aRv
.NoteJSContextException(aJSContext
);
51 JS::AutoCheckCannotGC nogc
;
52 bool isShared
= false;
53 JS::Rooted
<JSObject
*> obj(aJSContext
, aObj
.get());
54 float* data
= JS_GetFloat32ArrayData(obj
, &isShared
, nogc
);
56 memcpy(data
, aVal
, aValLength
* sizeof(float));
63 } // namespace mozilla::dom