Commit 368c2f21 authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Update XRRigidTransform's constructor to throw as specced

Updates XRRigidTransform's constructor to throw a TypeError if it
receives a Position with a w component assigned to anything other than 1
and an InvalidStateError if the length of the Orientation component is 0

Bug: 977703
Change-Id: Ie75ddff1e1bafd55ea58844c074751aedf11fcdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1725319
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682370}
parent 39efff8e
......@@ -9,8 +9,15 @@
#include "third_party/blink/renderer/core/geometry/dom_point_init.h"
#include "third_party/blink/renderer/core/geometry/dom_point_read_only.h"
#include "third_party/blink/renderer/modules/xr/xr_utils.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/transforms/transformation_matrix.h"
namespace {
bool IsWithinEpsilon(double a, double b) {
return std::abs(a - b) < std::numeric_limits<double>::epsilon();
}
} // namespace
namespace blink {
// makes a deep copy of transformationMatrix
......@@ -59,7 +66,24 @@ XRRigidTransform::XRRigidTransform(DOMPointInit* position,
}
XRRigidTransform* XRRigidTransform::Create(DOMPointInit* position,
DOMPointInit* orientation) {
DOMPointInit* orientation,
ExceptionState& exception_state) {
if (position && !IsWithinEpsilon(1.0, position->w())) {
exception_state.ThrowTypeError("W component of position must be 1.0");
return nullptr;
}
if (orientation) {
if (IsWithinEpsilon(orientation->x(), 0.0) &&
IsWithinEpsilon(orientation->y(), 0.0) &&
IsWithinEpsilon(orientation->z(), 0.0) &&
IsWithinEpsilon(orientation->w(), 0.0)) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"Orientation's length cannot be 0");
return nullptr;
}
}
return MakeGarbageCollected<XRRigidTransform>(position, orientation);
}
......
......@@ -16,6 +16,7 @@ namespace blink {
class DOMPointInit;
class DOMPointReadOnly;
class ExceptionState;
class TransformationMatrix;
// MODULES_EXPORT is required for unit tests using XRRigidTransform (currently
......@@ -26,7 +27,9 @@ class MODULES_EXPORT XRRigidTransform : public ScriptWrappable {
public:
explicit XRRigidTransform(const TransformationMatrix&);
XRRigidTransform(DOMPointInit*, DOMPointInit*);
static XRRigidTransform* Create(DOMPointInit*, DOMPointInit*);
static XRRigidTransform* Create(DOMPointInit*,
DOMPointInit*,
ExceptionState&);
~XRRigidTransform() override = default;
......
......@@ -8,7 +8,8 @@
SecureContext,
Exposed=Window,
RuntimeEnabled=WebXR,
Constructor(optional DOMPointInit position, optional DOMPointInit orientation)
Constructor(optional DOMPointInit position, optional DOMPointInit orientation),
RaisesException=Constructor
] interface XRRigidTransform {
[SameObject] readonly attribute DOMPointReadOnly position;
[SameObject] readonly attribute DOMPointReadOnly orientation;
......
This is a testharness.js-based test.
FAIL XRRigidTransform constructor works assert_throws: Constructor should throw TypeError for non-1 position w values function "() => new XRRigidTransform(
coordDict([1.0, 2.0, 3.0, 0.5]),
coordDict([1.1, 2.1, 3.1, 1.0])
)" did not throw
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment