Pose.cpp (1955B)
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/. */ 6 7 #include "mozilla/dom/Pose.h" 8 9 #include "js/experimental/TypedData.h" // JS_GetFloat32ArrayData 10 #include "mozilla/ErrorResult.h" 11 #include "mozilla/HoldDropJSObjects.h" 12 #include "mozilla/dom/TypedArray.h" 13 14 namespace mozilla::dom { 15 16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS( 17 Pose, (mParent), 18 (mPosition, mLinearVelocity, mLinearAcceleration, mOrientation, 19 mAngularVelocity, mAngularAcceleration)) 20 21 Pose::Pose(nsISupports* aParent) 22 : mParent(aParent), 23 mPosition(nullptr), 24 mLinearVelocity(nullptr), 25 mLinearAcceleration(nullptr), 26 mOrientation(nullptr), 27 mAngularVelocity(nullptr), 28 mAngularAcceleration(nullptr) { 29 mozilla::HoldJSObjects(this); 30 } 31 32 Pose::~Pose() { mozilla::DropJSObjects(this); } 33 34 nsISupports* Pose::GetParentObject() const { return mParent; } 35 36 void Pose::SetFloat32Array(JSContext* aJSContext, nsWrapperCache* creator, 37 JS::MutableHandle<JSObject*> aRetVal, 38 JS::Heap<JSObject*>& aObj, float* aVal, 39 uint32_t aValLength, ErrorResult& aRv) { 40 if (!aVal) { 41 aRetVal.set(nullptr); 42 return; 43 } 44 45 if (!aObj) { 46 aObj = 47 Float32Array::Create(aJSContext, creator, Span(aVal, aValLength), aRv); 48 if (aRv.Failed()) { 49 return; 50 } 51 } else { 52 JS::AutoCheckCannotGC nogc; 53 bool isShared = false; 54 JS::Rooted<JSObject*> obj(aJSContext, aObj.get()); 55 float* data = JS_GetFloat32ArrayData(obj, &isShared, nogc); 56 if (data) { 57 memcpy(data, aVal, aValLength * sizeof(float)); 58 } 59 } 60 61 aRetVal.set(aObj); 62 } 63 64 } // namespace mozilla::dom