Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / base / Pose.cpp
blobddccd476ef8769c178792733e8d6c1581f6d1ea9
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(
16 Pose, (mParent),
17 (mPosition, mLinearVelocity, mLinearAcceleration, mOrientation,
18 mAngularVelocity, mAngularAcceleration))
20 Pose::Pose(nsISupports* aParent)
21 : mParent(aParent),
22 mPosition(nullptr),
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) {
39 if (!aVal) {
40 aRetVal.set(nullptr);
41 return;
44 if (!aObj) {
45 aObj = Float32Array::Create(aJSContext, creator, aValLength, aVal);
46 if (!aObj) {
47 aRv.NoteJSContextException(aJSContext);
48 return;
50 } else {
51 JS::AutoCheckCannotGC nogc;
52 bool isShared = false;
53 JS::Rooted<JSObject*> obj(aJSContext, aObj.get());
54 float* data = JS_GetFloat32ArrayData(obj, &isShared, nogc);
55 if (data) {
56 memcpy(data, aVal, aValLength * sizeof(float));
60 aRetVal.set(aObj);
63 } // namespace mozilla::dom